Skip to content

Commit 10dc3c7

Browse files
committed
Merge branch 'bugfix_unknownoutputs' of git://github.com/luke-jr/bitcoin
Conflicts: src/wallet.cpp Fixed LogPrint/printf merge conflict.
2 parents 0c1222f + cc6cfab commit 10dc3c7

File tree

2 files changed

+28
-8
lines changed

2 files changed

+28
-8
lines changed

src/rpcwallet.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -968,6 +968,13 @@ Value listreceivedbyaccount(const Array& params, bool fHelp)
968968
return ListReceived(params, true);
969969
}
970970

971+
static void MaybePushAddress(Object & entry, const CTxDestination &dest)
972+
{
973+
CBitcoinAddress addr;
974+
if (addr.Set(dest))
975+
entry.push_back(Pair("address", addr.ToString()));
976+
}
977+
971978
void ListTransactions(const CWalletTx& wtx, const string& strAccount, int nMinDepth, bool fLong, Array& ret)
972979
{
973980
int64 nFee;
@@ -986,7 +993,7 @@ void ListTransactions(const CWalletTx& wtx, const string& strAccount, int nMinDe
986993
{
987994
Object entry;
988995
entry.push_back(Pair("account", strSentAccount));
989-
entry.push_back(Pair("address", CBitcoinAddress(s.first).ToString()));
996+
MaybePushAddress(entry, s.first);
990997
entry.push_back(Pair("category", "send"));
991998
entry.push_back(Pair("amount", ValueFromAmount(-s.second)));
992999
entry.push_back(Pair("fee", ValueFromAmount(-nFee)));
@@ -1008,7 +1015,7 @@ void ListTransactions(const CWalletTx& wtx, const string& strAccount, int nMinDe
10081015
{
10091016
Object entry;
10101017
entry.push_back(Pair("account", account));
1011-
entry.push_back(Pair("address", CBitcoinAddress(r.first).ToString()));
1018+
MaybePushAddress(entry, r.first);
10121019
if (wtx.IsCoinBase())
10131020
{
10141021
if (wtx.GetDepthInMainChain() < 1)

src/wallet.cpp

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -654,22 +654,35 @@ void CWalletTx::GetAmounts(list<pair<CTxDestination, int64> >& listReceived,
654654
// Sent/received.
655655
BOOST_FOREACH(const CTxOut& txout, vout)
656656
{
657+
bool fIsMine;
658+
// Only need to handle txouts if AT LEAST one of these is true:
659+
// 1) they debit from us (sent)
660+
// 2) the output is to us (received)
661+
if (nDebit > 0)
662+
{
663+
// Don't report 'change' txouts
664+
if (pwallet->IsChange(txout))
665+
continue;
666+
fIsMine = pwallet->IsMine(txout);
667+
}
668+
else if (!(fIsMine = pwallet->IsMine(txout)))
669+
continue;
670+
671+
// In either case, we need to get the destination address
657672
CTxDestination address;
658-
vector<unsigned char> vchPubKey;
659673
if (!ExtractDestination(txout.scriptPubKey, address))
660674
{
661675
LogPrintf("CWalletTx::GetAmounts: Unknown transaction type found, txid %s\n",
662676
this->GetHash().ToString().c_str());
677+
address = CNoDestination();
663678
}
664679

665-
// Don't report 'change' txouts
666-
if (nDebit > 0 && pwallet->IsChange(txout))
667-
continue;
668-
680+
// If we are debited by the transaction, add the output as a "sent" entry
669681
if (nDebit > 0)
670682
listSent.push_back(make_pair(address, txout.nValue));
671683

672-
if (pwallet->IsMine(txout))
684+
// If we are receiving the output, add it as a "received" entry
685+
if (fIsMine)
673686
listReceived.push_back(make_pair(address, txout.nValue));
674687
}
675688

0 commit comments

Comments
 (0)