Skip to content

Commit 1b4568c

Browse files
committed
Add vout to ListTransactions output
1 parent 2c0f019 commit 1b4568c

File tree

3 files changed

+56
-43
lines changed

3 files changed

+56
-43
lines changed

src/rpcwallet.cpp

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -641,16 +641,16 @@ Value getbalance(const Array& params, bool fHelp)
641641

642642
int64_t allFee;
643643
string strSentAccount;
644-
list<pair<CTxDestination, int64_t> > listReceived;
645-
list<pair<CTxDestination, int64_t> > listSent;
644+
list<COutputEntry> listReceived;
645+
list<COutputEntry> listSent;
646646
wtx.GetAmounts(listReceived, listSent, allFee, strSentAccount, filter);
647647
if (wtx.GetDepthInMainChain() >= nMinDepth)
648648
{
649-
BOOST_FOREACH(const PAIRTYPE(CTxDestination,int64_t)& r, listReceived)
650-
nBalance += r.second;
649+
BOOST_FOREACH(const COutputEntry& r, listReceived)
650+
nBalance += r.amount;
651651
}
652-
BOOST_FOREACH(const PAIRTYPE(CTxDestination,int64_t)& r, listSent)
653-
nBalance -= r.second;
652+
BOOST_FOREACH(const COutputEntry& s, listSent)
653+
nBalance -= s.amount;
654654
nBalance -= allFee;
655655
}
656656
return ValueFromAmount(nBalance);
@@ -1133,8 +1133,8 @@ void ListTransactions(const CWalletTx& wtx, const string& strAccount, int nMinDe
11331133
{
11341134
int64_t nFee;
11351135
string strSentAccount;
1136-
list<pair<CTxDestination, int64_t> > listReceived;
1137-
list<pair<CTxDestination, int64_t> > listSent;
1136+
list<COutputEntry> listReceived;
1137+
list<COutputEntry> listSent;
11381138

11391139
wtx.GetAmounts(listReceived, listSent, nFee, strSentAccount, filter);
11401140

@@ -1144,15 +1144,16 @@ void ListTransactions(const CWalletTx& wtx, const string& strAccount, int nMinDe
11441144
// Sent
11451145
if ((!listSent.empty() || nFee != 0) && (fAllAccounts || strAccount == strSentAccount))
11461146
{
1147-
BOOST_FOREACH(const PAIRTYPE(CTxDestination, int64_t)& s, listSent)
1147+
BOOST_FOREACH(const COutputEntry& s, listSent)
11481148
{
11491149
Object entry;
1150-
if(involvesWatchonly || (::IsMine(*pwalletMain, s.first) & ISMINE_WATCH_ONLY))
1150+
if(involvesWatchonly || (::IsMine(*pwalletMain, s.destination) & ISMINE_WATCH_ONLY))
11511151
entry.push_back(Pair("involvesWatchonly", true));
11521152
entry.push_back(Pair("account", strSentAccount));
1153-
MaybePushAddress(entry, s.first);
1153+
MaybePushAddress(entry, s.destination);
11541154
entry.push_back(Pair("category", "send"));
1155-
entry.push_back(Pair("amount", ValueFromAmount(-s.second)));
1155+
entry.push_back(Pair("amount", ValueFromAmount(-s.amount)));
1156+
entry.push_back(Pair("vout", s.vout));
11561157
entry.push_back(Pair("fee", ValueFromAmount(-nFee)));
11571158
if (fLong)
11581159
WalletTxToJSON(wtx, entry);
@@ -1163,18 +1164,18 @@ void ListTransactions(const CWalletTx& wtx, const string& strAccount, int nMinDe
11631164
// Received
11641165
if (listReceived.size() > 0 && wtx.GetDepthInMainChain() >= nMinDepth)
11651166
{
1166-
BOOST_FOREACH(const PAIRTYPE(CTxDestination, int64_t)& r, listReceived)
1167+
BOOST_FOREACH(const COutputEntry& r, listReceived)
11671168
{
11681169
string account;
1169-
if (pwalletMain->mapAddressBook.count(r.first))
1170-
account = pwalletMain->mapAddressBook[r.first].name;
1170+
if (pwalletMain->mapAddressBook.count(r.destination))
1171+
account = pwalletMain->mapAddressBook[r.destination].name;
11711172
if (fAllAccounts || (account == strAccount))
11721173
{
11731174
Object entry;
1174-
if(involvesWatchonly || (::IsMine(*pwalletMain, r.first) & ISMINE_WATCH_ONLY))
1175+
if(involvesWatchonly || (::IsMine(*pwalletMain, r.destination) & ISMINE_WATCH_ONLY))
11751176
entry.push_back(Pair("involvesWatchonly", true));
11761177
entry.push_back(Pair("account", account));
1177-
MaybePushAddress(entry, r.first);
1178+
MaybePushAddress(entry, r.destination);
11781179
if (wtx.IsCoinBase())
11791180
{
11801181
if (wtx.GetDepthInMainChain() < 1)
@@ -1188,7 +1189,8 @@ void ListTransactions(const CWalletTx& wtx, const string& strAccount, int nMinDe
11881189
{
11891190
entry.push_back(Pair("category", "receive"));
11901191
}
1191-
entry.push_back(Pair("amount", ValueFromAmount(r.second)));
1192+
entry.push_back(Pair("amount", ValueFromAmount(r.amount)));
1193+
entry.push_back(Pair("vout", r.vout));
11921194
if (fLong)
11931195
WalletTxToJSON(wtx, entry);
11941196
ret.push_back(entry);
@@ -1240,6 +1242,7 @@ Value listtransactions(const Array& params, bool fHelp)
12401242
" \"amount\": x.xxx, (numeric) The amount in btc. This is negative for the 'send' category, and for the\n"
12411243
" 'move' category for moves outbound. It is positive for the 'receive' category,\n"
12421244
" and for the 'move' category for inbound funds.\n"
1245+
" \"vout\" : n, (numeric) the vout value\n"
12431246
" \"fee\": x.xxx, (numeric) The amount of the fee in btc. This is negative and only available for the \n"
12441247
" 'send' category of transactions.\n"
12451248
" \"confirmations\": n, (numeric) The number of confirmations for the transaction. Available for 'send' and \n"
@@ -1375,22 +1378,22 @@ Value listaccounts(const Array& params, bool fHelp)
13751378
const CWalletTx& wtx = (*it).second;
13761379
int64_t nFee;
13771380
string strSentAccount;
1378-
list<pair<CTxDestination, int64_t> > listReceived;
1379-
list<pair<CTxDestination, int64_t> > listSent;
1381+
list<COutputEntry> listReceived;
1382+
list<COutputEntry> listSent;
13801383
int nDepth = wtx.GetDepthInMainChain();
13811384
if (wtx.GetBlocksToMaturity() > 0 || nDepth < 0)
13821385
continue;
13831386
wtx.GetAmounts(listReceived, listSent, nFee, strSentAccount, includeWatchonly);
13841387
mapAccountBalances[strSentAccount] -= nFee;
1385-
BOOST_FOREACH(const PAIRTYPE(CTxDestination, int64_t)& s, listSent)
1386-
mapAccountBalances[strSentAccount] -= s.second;
1388+
BOOST_FOREACH(const COutputEntry& s, listSent)
1389+
mapAccountBalances[strSentAccount] -= s.amount;
13871390
if (nDepth >= nMinDepth)
13881391
{
1389-
BOOST_FOREACH(const PAIRTYPE(CTxDestination, int64_t)& r, listReceived)
1390-
if (pwalletMain->mapAddressBook.count(r.first))
1391-
mapAccountBalances[pwalletMain->mapAddressBook[r.first].name] += r.second;
1392+
BOOST_FOREACH(const COutputEntry& r, listReceived)
1393+
if (pwalletMain->mapAddressBook.count(r.destination))
1394+
mapAccountBalances[pwalletMain->mapAddressBook[r.destination].name] += r.amount;
13921395
else
1393-
mapAccountBalances[""] += r.second;
1396+
mapAccountBalances[""] += r.amount;
13941397
}
13951398
}
13961399

@@ -1424,6 +1427,7 @@ Value listsinceblock(const Array& params, bool fHelp)
14241427
" \"category\":\"send|receive\", (string) The transaction category. 'send' has negative amounts, 'receive' has positive amounts.\n"
14251428
" \"amount\": x.xxx, (numeric) The amount in btc. This is negative for the 'send' category, and for the 'move' category for moves \n"
14261429
" outbound. It is positive for the 'receive' category, and for the 'move' category for inbound funds.\n"
1430+
" \"vout\" : n, (numeric) the vout value\n"
14271431
" \"fee\": x.xxx, (numeric) The amount of the fee in btc. This is negative and only available for the 'send' category of transactions.\n"
14281432
" \"confirmations\": n, (numeric) The number of confirmations for the transaction. Available for 'send' and 'receive' category of transactions.\n"
14291433
" \"blockhash\": \"hashvalue\", (string) The block hash containing the transaction. Available for 'send' and 'receive' category of transactions.\n"
@@ -1528,6 +1532,7 @@ Value gettransaction(const Array& params, bool fHelp)
15281532
" \"address\" : \"bitcoinaddress\", (string) The bitcoin address involved in the transaction\n"
15291533
" \"category\" : \"send|receive\", (string) The category, either 'send' or 'receive'\n"
15301534
" \"amount\" : x.xxx (numeric) The amount in btc\n"
1535+
" \"vout\" : n, (numeric) the vout value\n"
15311536
" }\n"
15321537
" ,...\n"
15331538
" ],\n"

src/wallet.cpp

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -798,8 +798,8 @@ int CWalletTx::GetRequestCount() const
798798
return nRequests;
799799
}
800800

801-
void CWalletTx::GetAmounts(list<pair<CTxDestination, int64_t> >& listReceived,
802-
list<pair<CTxDestination, int64_t> >& listSent, int64_t& nFee, string& strSentAccount, const isminefilter& filter) const
801+
void CWalletTx::GetAmounts(list<COutputEntry>& listReceived,
802+
list<COutputEntry>& listSent, int64_t& nFee, string& strSentAccount, const isminefilter& filter) const
803803
{
804804
nFee = 0;
805805
listReceived.clear();
@@ -815,10 +815,10 @@ void CWalletTx::GetAmounts(list<pair<CTxDestination, int64_t> >& listReceived,
815815
}
816816

817817
// Sent/received.
818-
BOOST_FOREACH(const CTxOut& txout, vout)
818+
for (int i = 0; i < vout.size(); ++i)
819819
{
820+
const CTxOut& txout = vout[i];
820821
isminetype fIsMine = pwallet->IsMine(txout);
821-
822822
// Only need to handle txouts if AT LEAST one of these is true:
823823
// 1) they debit from us (sent)
824824
// 2) the output is to us (received)
@@ -840,13 +840,15 @@ void CWalletTx::GetAmounts(list<pair<CTxDestination, int64_t> >& listReceived,
840840
address = CNoDestination();
841841
}
842842

843+
COutputEntry output = {address, txout.nValue, i};
844+
843845
// If we are debited by the transaction, add the output as a "sent" entry
844846
if (nDebit > 0)
845-
listSent.push_back(make_pair(address, txout.nValue));
847+
listSent.push_back(output);
846848

847849
// If we are receiving the output, add it as a "received" entry
848850
if (fIsMine & filter)
849-
listReceived.push_back(make_pair(address, txout.nValue));
851+
listReceived.push_back(output);
850852
}
851853

852854
}
@@ -858,29 +860,29 @@ void CWalletTx::GetAccountAmounts(const string& strAccount, int64_t& nReceived,
858860

859861
int64_t allFee;
860862
string strSentAccount;
861-
list<pair<CTxDestination, int64_t> > listReceived;
862-
list<pair<CTxDestination, int64_t> > listSent;
863+
list<COutputEntry> listReceived;
864+
list<COutputEntry> listSent;
863865
GetAmounts(listReceived, listSent, allFee, strSentAccount, filter);
864866

865867
if (strAccount == strSentAccount)
866868
{
867-
BOOST_FOREACH(const PAIRTYPE(CTxDestination,int64_t)& s, listSent)
868-
nSent += s.second;
869+
BOOST_FOREACH(const COutputEntry& s, listSent)
870+
nSent += s.amount;
869871
nFee = allFee;
870872
}
871873
{
872874
LOCK(pwallet->cs_wallet);
873-
BOOST_FOREACH(const PAIRTYPE(CTxDestination,int64_t)& r, listReceived)
875+
BOOST_FOREACH(const COutputEntry& r, listReceived)
874876
{
875-
if (pwallet->mapAddressBook.count(r.first))
877+
if (pwallet->mapAddressBook.count(r.destination))
876878
{
877-
map<CTxDestination, CAddressBookData>::const_iterator mi = pwallet->mapAddressBook.find(r.first);
879+
map<CTxDestination, CAddressBookData>::const_iterator mi = pwallet->mapAddressBook.find(r.destination);
878880
if (mi != pwallet->mapAddressBook.end() && (*mi).second.name == strAccount)
879-
nReceived += r.second;
881+
nReceived += r.amount;
880882
}
881883
else if (strAccount.empty())
882884
{
883-
nReceived += r.second;
885+
nReceived += r.amount;
884886
}
885887
}
886888
}

src/wallet.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,12 @@ static void WriteOrderPos(const int64_t& nOrderPos, mapValue_t& mapValue)
467467
mapValue["n"] = i64tostr(nOrderPos);
468468
}
469469

470+
struct COutputEntry
471+
{
472+
CTxDestination destination;
473+
int64_t amount;
474+
int vout;
475+
};
470476

471477
/** A transaction with a bunch of additional info that only the owner cares about.
472478
* It includes any unrecorded transactions needed to link it back to the block chain.
@@ -761,8 +767,8 @@ class CWalletTx : public CMerkleTx
761767
return nChangeCached;
762768
}
763769

764-
void GetAmounts(std::list<std::pair<CTxDestination, int64_t> >& listReceived,
765-
std::list<std::pair<CTxDestination, int64_t> >& listSent, int64_t& nFee, std::string& strSentAccount, const isminefilter& filter) const;
770+
void GetAmounts(std::list<COutputEntry>& listReceived,
771+
std::list<COutputEntry>& listSent, int64_t& nFee, std::string& strSentAccount, const isminefilter& filter) const;
766772

767773
void GetAccountAmounts(const std::string& strAccount, int64_t& nReceived,
768774
int64_t& nSent, int64_t& nFee, const isminefilter& filter) const;

0 commit comments

Comments
 (0)