From 96ed68217626ad07b0d8d9ea6e4871b092535963 Mon Sep 17 00:00:00 2001 From: Luke Dashjr Date: Sat, 22 Sep 2012 03:20:14 +0000 Subject: [PATCH 1/2] Bugfix: Avoid trying to parse outputs that aren't relevant to CWalletTx::GetAmounts This fixes a warning when an output we aren't concerned with can't be parsed. --- src/wallet.cpp | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/wallet.cpp b/src/wallet.cpp index 488787f96..76f3df602 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -673,22 +673,35 @@ void CWalletTx::GetAmounts(list >& listReceived, // Sent/received. BOOST_FOREACH(const CTxOut& txout, vout) { + bool fIsMine; + // Only need to handle txouts if AT LEAST one of these is true: + // 1) they debit from us (sent) + // 2) the output is to us (received) + if (nDebit > 0) + { + // Don't report 'change' txouts + if (pwallet->IsChange(txout)) + continue; + fIsMine = pwallet->IsMine(txout); + } + else if (!(fIsMine = pwallet->IsMine(txout))) + continue; + + // In either case, we need to get the destination address CTxDestination address; - vector vchPubKey; if (!ExtractDestination(txout.scriptPubKey, address)) { printf("CWalletTx::GetAmounts: Unknown transaction type found, txid %s\n", this->GetHash().ToString().c_str()); + address = CNoDestination(); } - // Don't report 'change' txouts - if (nDebit > 0 && pwallet->IsChange(txout)) - continue; - + // If we are debited by the transaction, add the output as a "sent" entry if (nDebit > 0) listSent.push_back(make_pair(address, txout.nValue)); - if (pwallet->IsMine(txout)) + // If we are receiving the output, add it as a "received" entry + if (fIsMine) listReceived.push_back(make_pair(address, txout.nValue)); } From cc6cfab38fcdd4ec3e4784e01c4407a129289f77 Mon Sep 17 00:00:00 2001 From: Luke Dashjr Date: Sat, 22 Sep 2012 03:22:34 +0000 Subject: [PATCH 2/2] Bugfix: Supress "address" key in transaction details, when the destination isn't recognized Previously, it would pass corrupt/random through base58. --- src/rpcwallet.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/rpcwallet.cpp b/src/rpcwallet.cpp index 5388bd4d8..23ea52f5b 100644 --- a/src/rpcwallet.cpp +++ b/src/rpcwallet.cpp @@ -953,6 +953,13 @@ Value listreceivedbyaccount(const Array& params, bool fHelp) return ListReceived(params, true); } +static void MaybePushAddress(Object & entry, const CTxDestination &dest) +{ + CBitcoinAddress addr; + if (addr.Set(dest)) + entry.push_back(Pair("address", addr.ToString())); +} + void ListTransactions(const CWalletTx& wtx, const string& strAccount, int nMinDepth, bool fLong, Array& ret) { int64 nFee; @@ -971,7 +978,7 @@ void ListTransactions(const CWalletTx& wtx, const string& strAccount, int nMinDe { Object entry; entry.push_back(Pair("account", strSentAccount)); - entry.push_back(Pair("address", CBitcoinAddress(s.first).ToString())); + MaybePushAddress(entry, s.first); entry.push_back(Pair("category", "send")); entry.push_back(Pair("amount", ValueFromAmount(-s.second))); entry.push_back(Pair("fee", ValueFromAmount(-nFee))); @@ -993,7 +1000,7 @@ void ListTransactions(const CWalletTx& wtx, const string& strAccount, int nMinDe { Object entry; entry.push_back(Pair("account", account)); - entry.push_back(Pair("address", CBitcoinAddress(r.first).ToString())); + MaybePushAddress(entry, r.first); if (wtx.IsCoinBase()) { if (wtx.GetDepthInMainChain() < 1)