Skip to content

Commit

Permalink
Merge branch 'bugfix_unknownoutputs' of git://github.com/luke-jr/bitcoin
Browse files Browse the repository at this point in the history
Conflicts:
	src/wallet.cpp
Fixed LogPrint/printf merge conflict.
  • Loading branch information
gavinandresen committed Oct 22, 2013
2 parents 0c1222f + cc6cfab commit 10dc3c7
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
11 changes: 9 additions & 2 deletions src/rpcwallet.cpp
Expand Up @@ -968,6 +968,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;
Expand All @@ -986,7 +993,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)));
Expand All @@ -1008,7 +1015,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)
Expand Down
25 changes: 19 additions & 6 deletions src/wallet.cpp
Expand Up @@ -654,22 +654,35 @@ void CWalletTx::GetAmounts(list<pair<CTxDestination, int64> >& 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<unsigned char> vchPubKey;
if (!ExtractDestination(txout.scriptPubKey, address))
{
LogPrintf("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));
}

Expand Down

0 comments on commit 10dc3c7

Please sign in to comment.