Enable time locked transactions to be recognized in the wallet

This commit is contained in:
miketout
2018-05-07 15:58:53 -07:00
parent 68334c8dae
commit fab1429d48
3 changed files with 34 additions and 28 deletions

View File

@@ -133,8 +133,9 @@ QString TransactionDesc::toHTML(CWallet *wallet, CWalletTx &wtx, TransactionReco
// Coinbase // Coinbase
// //
CAmount nUnmatured = 0; CAmount nUnmatured = 0;
BOOST_FOREACH(const CTxOut& txout, wtx.vout) for (int i = 0; i < wtx.vout.size(); i++)
nUnmatured += wallet->GetCredit(txout, ISMINE_ALL); nUnmatured += wallet->GetCredit(wtx, i, ISMINE_ALL);
strHTML += "<b>" + tr("Credit") + ":</b> "; strHTML += "<b>" + tr("Credit") + ":</b> ";
if (wtx.IsInMainChain()) if (wtx.IsInMainChain())
strHTML += BitcoinUnits::formatHtmlWithUnit(unit, nUnmatured)+ " (" + tr("matures in %n more block(s)", "", wtx.GetBlocksToMaturity()) + ")"; strHTML += BitcoinUnits::formatHtmlWithUnit(unit, nUnmatured)+ " (" + tr("matures in %n more block(s)", "", wtx.GetBlocksToMaturity()) + ")";
@@ -159,9 +160,9 @@ QString TransactionDesc::toHTML(CWallet *wallet, CWalletTx &wtx, TransactionReco
} }
isminetype fAllToMe = ISMINE_SPENDABLE; isminetype fAllToMe = ISMINE_SPENDABLE;
BOOST_FOREACH(const CTxOut& txout, wtx.vout) for (int i = 0; i < wtx.vout.size(); i++)
{ {
isminetype mine = wallet->IsMine(txout); isminetype mine = wallet->IsMine(wtx, i);
if(fAllToMe > mine) fAllToMe = mine; if(fAllToMe > mine) fAllToMe = mine;
} }
@@ -173,10 +174,11 @@ QString TransactionDesc::toHTML(CWallet *wallet, CWalletTx &wtx, TransactionReco
// //
// Debit // Debit
// //
BOOST_FOREACH(const CTxOut& txout, wtx.vout) for (int i = 0; i < wtx.vout.size(); i++)
{ {
const CTxOut& txout = wtx.vout[i];
// Ignore change // Ignore change
isminetype toSelf = wallet->IsMine(txout); isminetype toSelf = wallet->IsMine(wtx, i);
if ((toSelf == ISMINE_SPENDABLE) && (fAllFromMe == ISMINE_SPENDABLE)) if ((toSelf == ISMINE_SPENDABLE) && (fAllFromMe == ISMINE_SPENDABLE))
continue; continue;
@@ -224,9 +226,9 @@ QString TransactionDesc::toHTML(CWallet *wallet, CWalletTx &wtx, TransactionReco
BOOST_FOREACH(const CTxIn& txin, wtx.vin) BOOST_FOREACH(const CTxIn& txin, wtx.vin)
if (wallet->IsMine(txin)) if (wallet->IsMine(txin))
strHTML += "<b>" + tr("Debit") + ":</b> " + BitcoinUnits::formatHtmlWithUnit(unit, -wallet->GetDebit(txin, ISMINE_ALL)) + "<br>"; strHTML += "<b>" + tr("Debit") + ":</b> " + BitcoinUnits::formatHtmlWithUnit(unit, -wallet->GetDebit(txin, ISMINE_ALL)) + "<br>";
BOOST_FOREACH(const CTxOut& txout, wtx.vout) for (int i = 0; i < wtx.vout.size(); i++)
if (wallet->IsMine(txout)) if (wallet->IsMine(wtx, i))
strHTML += "<b>" + tr("Credit") + ":</b> " + BitcoinUnits::formatHtmlWithUnit(unit, wallet->GetCredit(txout, ISMINE_ALL)) + "<br>"; strHTML += "<b>" + tr("Credit") + ":</b> " + BitcoinUnits::formatHtmlWithUnit(unit, wallet->GetCredit(wtx, i, ISMINE_ALL)) + "<br>";
} }
} }
@@ -281,9 +283,9 @@ QString TransactionDesc::toHTML(CWallet *wallet, CWalletTx &wtx, TransactionReco
BOOST_FOREACH(const CTxIn& txin, wtx.vin) BOOST_FOREACH(const CTxIn& txin, wtx.vin)
if(wallet->IsMine(txin)) if(wallet->IsMine(txin))
strHTML += "<b>" + tr("Debit") + ":</b> " + BitcoinUnits::formatHtmlWithUnit(unit, -wallet->GetDebit(txin, ISMINE_ALL)) + "<br>"; strHTML += "<b>" + tr("Debit") + ":</b> " + BitcoinUnits::formatHtmlWithUnit(unit, -wallet->GetDebit(txin, ISMINE_ALL)) + "<br>";
BOOST_FOREACH(const CTxOut& txout, wtx.vout) for (int i = 0; i < wtx.vout.size(); i++)
if(wallet->IsMine(txout)) if (wallet->IsMine(wtx, i))
strHTML += "<b>" + tr("Credit") + ":</b> " + BitcoinUnits::formatHtmlWithUnit(unit, wallet->GetCredit(txout, ISMINE_ALL)) + "<br>"; strHTML += "<b>" + tr("Credit") + ":</b> " + BitcoinUnits::formatHtmlWithUnit(unit, wallet->GetCredit(wtx, i, ISMINE_ALL)) + "<br>";
strHTML += "<br><b>" + tr("Transaction") + ":</b><br>"; strHTML += "<br><b>" + tr("Transaction") + ":</b><br>";
strHTML += GUIUtil::HtmlEscape(wtx.ToString(), true); strHTML += GUIUtil::HtmlEscape(wtx.ToString(), true);
@@ -310,8 +312,8 @@ QString TransactionDesc::toHTML(CWallet *wallet, CWalletTx &wtx, TransactionReco
strHTML += QString::fromStdString(CBitcoinAddress(address).ToString()); strHTML += QString::fromStdString(CBitcoinAddress(address).ToString());
} }
strHTML = strHTML + " " + tr("Amount") + "=" + BitcoinUnits::formatHtmlWithUnit(unit, vout.nValue); strHTML = strHTML + " " + tr("Amount") + "=" + BitcoinUnits::formatHtmlWithUnit(unit, vout.nValue);
strHTML = strHTML + " IsMine=" + (wallet->IsMine(vout) & ISMINE_SPENDABLE ? tr("true") : tr("false")) + "</li>"; strHTML = strHTML + " IsMine=" + (wallet->IsMine(prev, prevout.n) & ISMINE_SPENDABLE ? tr("true") : tr("false")) + "</li>";
strHTML = strHTML + " IsWatchOnly=" + (wallet->IsMine(vout) & ISMINE_WATCH_ONLY ? tr("true") : tr("false")) + "</li>"; strHTML = strHTML + " IsWatchOnly=" + (wallet->IsMine(prev, prevout.n) & ISMINE_WATCH_ONLY ? tr("true") : tr("false")) + "</li>";
} }
} }
} }

View File

@@ -1395,7 +1395,7 @@ isminetype CWallet::IsMine(const CTxIn &txin) const
{ {
const CWalletTx& prev = (*mi).second; const CWalletTx& prev = (*mi).second;
if (txin.prevout.n < prev.vout.size()) if (txin.prevout.n < prev.vout.size())
return IsMine(prev.vout[txin.prevout.n]); return IsMine(prev, txin.prevout.n);
} }
} }
return ISMINE_NO; return ISMINE_NO;
@@ -1410,7 +1410,7 @@ CAmount CWallet::GetDebit(const CTxIn &txin, const isminefilter& filter) const
{ {
const CWalletTx& prev = (*mi).second; const CWalletTx& prev = (*mi).second;
if (txin.prevout.n < prev.vout.size()) if (txin.prevout.n < prev.vout.size())
if (IsMine(prev.vout[txin.prevout.n]) & filter) if (IsMine(prev, txin.prevout.n) & filter)
return prev.vout[txin.prevout.n].nValue; // komodo_interest? return prev.vout[txin.prevout.n].nValue; // komodo_interest?
} }
} }
@@ -1487,7 +1487,7 @@ unsigned int HaveKeys(const vector<valtype>& pubkeys, const CKeyStore& keystore)
// special case handling for non-standard/Verus OP_RETURN script outputs, which need the transaction // special case handling for non-standard/Verus OP_RETURN script outputs, which need the transaction
// to determine ownership // to determine ownership
isminetype CWallet::IsMine(const CTransaction& tx, uint32_t voutNum) isminetype CWallet::IsMine(const CTransaction& tx, uint32_t voutNum) const
{ {
vector<valtype> vSolutions; vector<valtype> vSolutions;
txnouttype whichType; txnouttype whichType;
@@ -1608,14 +1608,19 @@ CAmount CWallet::GetDebit(const CTransaction& tx, const isminefilter& filter) co
return nDebit; return nDebit;
} }
CAmount CWallet::GetCredit(const CTransaction& tx, int32_t voutNum, const isminefilter& filter) const
{
if (voutNum >= tx.vout.size() || !MoneyRange(tx.vout[voutNum].nValue))
throw std::runtime_error("CWallet::GetCredit(): value out of range");
return ((IsMine(tx, voutNum) & filter) ? tx.vout[voutNum].nValue : 0);
}
CAmount CWallet::GetCredit(const CTransaction& tx, const isminefilter& filter) const CAmount CWallet::GetCredit(const CTransaction& tx, const isminefilter& filter) const
{ {
CAmount nCredit = 0; CAmount nCredit = 0;
BOOST_FOREACH(const CTxOut& txout, tx.vout) for (int i = 0; i < tx.vout.size(); i++)
{ {
nCredit += GetCredit(txout, filter); nCredit += GetCredit(tx, i, filter);
if (!MoneyRange(nCredit))
throw std::runtime_error("CWallet::GetCredit(): value out of range");
} }
return nCredit; return nCredit;
} }
@@ -2119,8 +2124,7 @@ CAmount CWalletTx::GetAvailableCredit(bool fUseCache) const
{ {
if (!pwallet->IsSpent(hashTx, i)) if (!pwallet->IsSpent(hashTx, i))
{ {
const CTxOut &txout = vout[i]; nCredit += pwallet->GetCredit(*this, i, ISMINE_SPENDABLE);
nCredit += pwallet->GetCredit(txout, ISMINE_SPENDABLE);
if (!MoneyRange(nCredit)) if (!MoneyRange(nCredit))
throw std::runtime_error("CWalletTx::GetAvailableCredit() : value out of range"); throw std::runtime_error("CWalletTx::GetAvailableCredit() : value out of range");
} }
@@ -2162,8 +2166,7 @@ CAmount CWalletTx::GetAvailableWatchOnlyCredit(const bool& fUseCache) const
{ {
if (!pwallet->IsSpent(GetHash(), i)) if (!pwallet->IsSpent(GetHash(), i))
{ {
const CTxOut &txout = vout[i]; nCredit += pwallet->GetCredit(*this, i, ISMINE_WATCH_ONLY);
nCredit += pwallet->GetCredit(txout, ISMINE_WATCH_ONLY);
if (!MoneyRange(nCredit)) if (!MoneyRange(nCredit))
throw std::runtime_error("CWalletTx::GetAvailableCredit() : value out of range"); throw std::runtime_error("CWalletTx::GetAvailableCredit() : value out of range");
} }
@@ -2392,9 +2395,9 @@ void CWallet::AvailableCoins(vector<COutput>& vCoins, bool fOnlyConfirmed, const
if (nDepth < 0) if (nDepth < 0)
continue; continue;
for (unsigned int i = 0; i < pcoin->vout.size(); i++) for (int i = 0; i < pcoin->vout.size(); i++)
{ {
isminetype mine = IsMine(pcoin->vout[i]); isminetype mine = IsMine(*pcoin, i);
if (!(IsSpent(wtxid, i)) && mine != ISMINE_NO && if (!(IsSpent(wtxid, i)) && mine != ISMINE_NO &&
!IsLockedCoin((*it).first, i) && (pcoin->vout[i].nValue > 0 || fIncludeZeroValue) && !IsLockedCoin((*it).first, i) && (pcoin->vout[i].nValue > 0 || fIncludeZeroValue) &&
(!coinControl || !coinControl->HasSelected() || coinControl->IsSelected((*it).first, i))) (!coinControl || !coinControl->HasSelected() || coinControl->IsSelected((*it).first, i)))

View File

@@ -1050,7 +1050,7 @@ public:
isminetype IsMine(const CTxIn& txin) const; isminetype IsMine(const CTxIn& txin) const;
CAmount GetDebit(const CTxIn& txin, const isminefilter& filter) const; CAmount GetDebit(const CTxIn& txin, const isminefilter& filter) const;
isminetype IsMine(const CTxOut& txout) const; isminetype IsMine(const CTxOut& txout) const;
isminetype IsMine(const CTransaction& tx, uint32_t voutNum); isminetype IsMine(const CTransaction& tx, uint32_t voutNum) const;
CAmount GetCredit(const CTxOut& txout, const isminefilter& filter) const; CAmount GetCredit(const CTxOut& txout, const isminefilter& filter) const;
bool IsChange(const CTxOut& txout) const; bool IsChange(const CTxOut& txout) const;
CAmount GetChange(const CTxOut& txout) const; CAmount GetChange(const CTxOut& txout) const;
@@ -1058,6 +1058,7 @@ public:
/** should probably be renamed to IsRelevantToMe */ /** should probably be renamed to IsRelevantToMe */
bool IsFromMe(const CTransaction& tx) const; bool IsFromMe(const CTransaction& tx) const;
CAmount GetDebit(const CTransaction& tx, const isminefilter& filter) const; CAmount GetDebit(const CTransaction& tx, const isminefilter& filter) const;
CAmount GetCredit(const CTransaction& tx, int32_t voutNum, const isminefilter& filter) const;
CAmount GetCredit(const CTransaction& tx, const isminefilter& filter) const; CAmount GetCredit(const CTransaction& tx, const isminefilter& filter) const;
CAmount GetChange(const CTransaction& tx) const; CAmount GetChange(const CTransaction& tx) const;
void ChainTip(const CBlockIndex *pindex, const CBlock *pblock, ZCIncrementalMerkleTree tree, bool added); void ChainTip(const CBlockIndex *pindex, const CBlock *pblock, ZCIncrementalMerkleTree tree, bool added);