Browse Source

Add vout to ListTransactions output

0.10
Cozz Lovan 11 years ago
parent
commit
1b4568cb0f
  1. 57
      src/rpcwallet.cpp
  2. 32
      src/wallet.cpp
  3. 10
      src/wallet.h

57
src/rpcwallet.cpp

@ -641,16 +641,16 @@ Value getbalance(const Array& params, bool fHelp)
int64_t allFee; int64_t allFee;
string strSentAccount; string strSentAccount;
list<pair<CTxDestination, int64_t> > listReceived; list<COutputEntry> listReceived;
list<pair<CTxDestination, int64_t> > listSent; list<COutputEntry> listSent;
wtx.GetAmounts(listReceived, listSent, allFee, strSentAccount, filter); wtx.GetAmounts(listReceived, listSent, allFee, strSentAccount, filter);
if (wtx.GetDepthInMainChain() >= nMinDepth) if (wtx.GetDepthInMainChain() >= nMinDepth)
{ {
BOOST_FOREACH(const PAIRTYPE(CTxDestination,int64_t)& r, listReceived) BOOST_FOREACH(const COutputEntry& r, listReceived)
nBalance += r.second; nBalance += r.amount;
} }
BOOST_FOREACH(const PAIRTYPE(CTxDestination,int64_t)& r, listSent) BOOST_FOREACH(const COutputEntry& s, listSent)
nBalance -= r.second; nBalance -= s.amount;
nBalance -= allFee; nBalance -= allFee;
} }
return ValueFromAmount(nBalance); return ValueFromAmount(nBalance);
@ -1133,8 +1133,8 @@ void ListTransactions(const CWalletTx& wtx, const string& strAccount, int nMinDe
{ {
int64_t nFee; int64_t nFee;
string strSentAccount; string strSentAccount;
list<pair<CTxDestination, int64_t> > listReceived; list<COutputEntry> listReceived;
list<pair<CTxDestination, int64_t> > listSent; list<COutputEntry> listSent;
wtx.GetAmounts(listReceived, listSent, nFee, strSentAccount, filter); wtx.GetAmounts(listReceived, listSent, nFee, strSentAccount, filter);
@ -1144,15 +1144,16 @@ void ListTransactions(const CWalletTx& wtx, const string& strAccount, int nMinDe
// Sent // Sent
if ((!listSent.empty() || nFee != 0) && (fAllAccounts || strAccount == strSentAccount)) if ((!listSent.empty() || nFee != 0) && (fAllAccounts || strAccount == strSentAccount))
{ {
BOOST_FOREACH(const PAIRTYPE(CTxDestination, int64_t)& s, listSent) BOOST_FOREACH(const COutputEntry& s, listSent)
{ {
Object entry; Object entry;
if(involvesWatchonly || (::IsMine(*pwalletMain, s.first) & ISMINE_WATCH_ONLY)) if(involvesWatchonly || (::IsMine(*pwalletMain, s.destination) & ISMINE_WATCH_ONLY))
entry.push_back(Pair("involvesWatchonly", true)); entry.push_back(Pair("involvesWatchonly", true));
entry.push_back(Pair("account", strSentAccount)); entry.push_back(Pair("account", strSentAccount));
MaybePushAddress(entry, s.first); MaybePushAddress(entry, s.destination);
entry.push_back(Pair("category", "send")); entry.push_back(Pair("category", "send"));
entry.push_back(Pair("amount", ValueFromAmount(-s.second))); entry.push_back(Pair("amount", ValueFromAmount(-s.amount)));
entry.push_back(Pair("vout", s.vout));
entry.push_back(Pair("fee", ValueFromAmount(-nFee))); entry.push_back(Pair("fee", ValueFromAmount(-nFee)));
if (fLong) if (fLong)
WalletTxToJSON(wtx, entry); WalletTxToJSON(wtx, entry);
@ -1163,18 +1164,18 @@ void ListTransactions(const CWalletTx& wtx, const string& strAccount, int nMinDe
// Received // Received
if (listReceived.size() > 0 && wtx.GetDepthInMainChain() >= nMinDepth) if (listReceived.size() > 0 && wtx.GetDepthInMainChain() >= nMinDepth)
{ {
BOOST_FOREACH(const PAIRTYPE(CTxDestination, int64_t)& r, listReceived) BOOST_FOREACH(const COutputEntry& r, listReceived)
{ {
string account; string account;
if (pwalletMain->mapAddressBook.count(r.first)) if (pwalletMain->mapAddressBook.count(r.destination))
account = pwalletMain->mapAddressBook[r.first].name; account = pwalletMain->mapAddressBook[r.destination].name;
if (fAllAccounts || (account == strAccount)) if (fAllAccounts || (account == strAccount))
{ {
Object entry; Object entry;
if(involvesWatchonly || (::IsMine(*pwalletMain, r.first) & ISMINE_WATCH_ONLY)) if(involvesWatchonly || (::IsMine(*pwalletMain, r.destination) & ISMINE_WATCH_ONLY))
entry.push_back(Pair("involvesWatchonly", true)); entry.push_back(Pair("involvesWatchonly", true));
entry.push_back(Pair("account", account)); entry.push_back(Pair("account", account));
MaybePushAddress(entry, r.first); MaybePushAddress(entry, r.destination);
if (wtx.IsCoinBase()) if (wtx.IsCoinBase())
{ {
if (wtx.GetDepthInMainChain() < 1) if (wtx.GetDepthInMainChain() < 1)
@ -1188,7 +1189,8 @@ void ListTransactions(const CWalletTx& wtx, const string& strAccount, int nMinDe
{ {
entry.push_back(Pair("category", "receive")); entry.push_back(Pair("category", "receive"));
} }
entry.push_back(Pair("amount", ValueFromAmount(r.second))); entry.push_back(Pair("amount", ValueFromAmount(r.amount)));
entry.push_back(Pair("vout", r.vout));
if (fLong) if (fLong)
WalletTxToJSON(wtx, entry); WalletTxToJSON(wtx, entry);
ret.push_back(entry); ret.push_back(entry);
@ -1240,6 +1242,7 @@ Value listtransactions(const Array& params, bool fHelp)
" \"amount\": x.xxx, (numeric) The amount in btc. This is negative for the 'send' category, and for the\n" " \"amount\": x.xxx, (numeric) The amount in btc. This is negative for the 'send' category, and for the\n"
" 'move' category for moves outbound. It is positive for the 'receive' category,\n" " 'move' category for moves outbound. It is positive for the 'receive' category,\n"
" and for the 'move' category for inbound funds.\n" " and for the 'move' category for inbound funds.\n"
" \"vout\" : n, (numeric) the vout value\n"
" \"fee\": x.xxx, (numeric) The amount of the fee in btc. This is negative and only available for the \n" " \"fee\": x.xxx, (numeric) The amount of the fee in btc. This is negative and only available for the \n"
" 'send' category of transactions.\n" " 'send' category of transactions.\n"
" \"confirmations\": n, (numeric) The number of confirmations for the transaction. Available for 'send' and \n" " \"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)
const CWalletTx& wtx = (*it).second; const CWalletTx& wtx = (*it).second;
int64_t nFee; int64_t nFee;
string strSentAccount; string strSentAccount;
list<pair<CTxDestination, int64_t> > listReceived; list<COutputEntry> listReceived;
list<pair<CTxDestination, int64_t> > listSent; list<COutputEntry> listSent;
int nDepth = wtx.GetDepthInMainChain(); int nDepth = wtx.GetDepthInMainChain();
if (wtx.GetBlocksToMaturity() > 0 || nDepth < 0) if (wtx.GetBlocksToMaturity() > 0 || nDepth < 0)
continue; continue;
wtx.GetAmounts(listReceived, listSent, nFee, strSentAccount, includeWatchonly); wtx.GetAmounts(listReceived, listSent, nFee, strSentAccount, includeWatchonly);
mapAccountBalances[strSentAccount] -= nFee; mapAccountBalances[strSentAccount] -= nFee;
BOOST_FOREACH(const PAIRTYPE(CTxDestination, int64_t)& s, listSent) BOOST_FOREACH(const COutputEntry& s, listSent)
mapAccountBalances[strSentAccount] -= s.second; mapAccountBalances[strSentAccount] -= s.amount;
if (nDepth >= nMinDepth) if (nDepth >= nMinDepth)
{ {
BOOST_FOREACH(const PAIRTYPE(CTxDestination, int64_t)& r, listReceived) BOOST_FOREACH(const COutputEntry& r, listReceived)
if (pwalletMain->mapAddressBook.count(r.first)) if (pwalletMain->mapAddressBook.count(r.destination))
mapAccountBalances[pwalletMain->mapAddressBook[r.first].name] += r.second; mapAccountBalances[pwalletMain->mapAddressBook[r.destination].name] += r.amount;
else else
mapAccountBalances[""] += r.second; mapAccountBalances[""] += r.amount;
} }
} }
@ -1424,6 +1427,7 @@ Value listsinceblock(const Array& params, bool fHelp)
" \"category\":\"send|receive\", (string) The transaction category. 'send' has negative amounts, 'receive' has positive amounts.\n" " \"category\":\"send|receive\", (string) The transaction category. 'send' has negative amounts, 'receive' has positive amounts.\n"
" \"amount\": x.xxx, (numeric) The amount in btc. This is negative for the 'send' category, and for the 'move' category for moves \n" " \"amount\": x.xxx, (numeric) The amount in btc. This is negative for the 'send' category, and for the 'move' category for moves \n"
" outbound. It is positive for the 'receive' category, and for the 'move' category for inbound funds.\n" " outbound. It is positive for the 'receive' category, and for the 'move' category for inbound funds.\n"
" \"vout\" : n, (numeric) the vout value\n"
" \"fee\": x.xxx, (numeric) The amount of the fee in btc. This is negative and only available for the 'send' category of transactions.\n" " \"fee\": x.xxx, (numeric) The amount of the fee in btc. This is negative and only available for the 'send' category of transactions.\n"
" \"confirmations\": n, (numeric) The number of confirmations for the transaction. Available for 'send' and 'receive' category of transactions.\n" " \"confirmations\": n, (numeric) The number of confirmations for the transaction. Available for 'send' and 'receive' category of transactions.\n"
" \"blockhash\": \"hashvalue\", (string) The block hash containing the transaction. Available for 'send' and 'receive' category of transactions.\n" " \"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)
" \"address\" : \"bitcoinaddress\", (string) The bitcoin address involved in the transaction\n" " \"address\" : \"bitcoinaddress\", (string) The bitcoin address involved in the transaction\n"
" \"category\" : \"send|receive\", (string) The category, either 'send' or 'receive'\n" " \"category\" : \"send|receive\", (string) The category, either 'send' or 'receive'\n"
" \"amount\" : x.xxx (numeric) The amount in btc\n" " \"amount\" : x.xxx (numeric) The amount in btc\n"
" \"vout\" : n, (numeric) the vout value\n"
" }\n" " }\n"
" ,...\n" " ,...\n"
" ],\n" " ],\n"

32
src/wallet.cpp

@ -798,8 +798,8 @@ int CWalletTx::GetRequestCount() const
return nRequests; return nRequests;
} }
void CWalletTx::GetAmounts(list<pair<CTxDestination, int64_t> >& listReceived, void CWalletTx::GetAmounts(list<COutputEntry>& listReceived,
list<pair<CTxDestination, int64_t> >& listSent, int64_t& nFee, string& strSentAccount, const isminefilter& filter) const list<COutputEntry>& listSent, int64_t& nFee, string& strSentAccount, const isminefilter& filter) const
{ {
nFee = 0; nFee = 0;
listReceived.clear(); listReceived.clear();
@ -815,10 +815,10 @@ void CWalletTx::GetAmounts(list<pair<CTxDestination, int64_t> >& listReceived,
} }
// Sent/received. // Sent/received.
BOOST_FOREACH(const CTxOut& txout, vout) for (int i = 0; i < vout.size(); ++i)
{ {
const CTxOut& txout = vout[i];
isminetype fIsMine = pwallet->IsMine(txout); isminetype fIsMine = pwallet->IsMine(txout);
// Only need to handle txouts if AT LEAST one of these is true: // Only need to handle txouts if AT LEAST one of these is true:
// 1) they debit from us (sent) // 1) they debit from us (sent)
// 2) the output is to us (received) // 2) the output is to us (received)
@ -840,13 +840,15 @@ void CWalletTx::GetAmounts(list<pair<CTxDestination, int64_t> >& listReceived,
address = CNoDestination(); address = CNoDestination();
} }
COutputEntry output = {address, txout.nValue, i};
// If we are debited by the transaction, add the output as a "sent" entry // If we are debited by the transaction, add the output as a "sent" entry
if (nDebit > 0) if (nDebit > 0)
listSent.push_back(make_pair(address, txout.nValue)); listSent.push_back(output);
// If we are receiving the output, add it as a "received" entry // If we are receiving the output, add it as a "received" entry
if (fIsMine & filter) if (fIsMine & filter)
listReceived.push_back(make_pair(address, txout.nValue)); listReceived.push_back(output);
} }
} }
@ -858,29 +860,29 @@ void CWalletTx::GetAccountAmounts(const string& strAccount, int64_t& nReceived,
int64_t allFee; int64_t allFee;
string strSentAccount; string strSentAccount;
list<pair<CTxDestination, int64_t> > listReceived; list<COutputEntry> listReceived;
list<pair<CTxDestination, int64_t> > listSent; list<COutputEntry> listSent;
GetAmounts(listReceived, listSent, allFee, strSentAccount, filter); GetAmounts(listReceived, listSent, allFee, strSentAccount, filter);
if (strAccount == strSentAccount) if (strAccount == strSentAccount)
{ {
BOOST_FOREACH(const PAIRTYPE(CTxDestination,int64_t)& s, listSent) BOOST_FOREACH(const COutputEntry& s, listSent)
nSent += s.second; nSent += s.amount;
nFee = allFee; nFee = allFee;
} }
{ {
LOCK(pwallet->cs_wallet); LOCK(pwallet->cs_wallet);
BOOST_FOREACH(const PAIRTYPE(CTxDestination,int64_t)& r, listReceived) BOOST_FOREACH(const COutputEntry& r, listReceived)
{ {
if (pwallet->mapAddressBook.count(r.first)) if (pwallet->mapAddressBook.count(r.destination))
{ {
map<CTxDestination, CAddressBookData>::const_iterator mi = pwallet->mapAddressBook.find(r.first); map<CTxDestination, CAddressBookData>::const_iterator mi = pwallet->mapAddressBook.find(r.destination);
if (mi != pwallet->mapAddressBook.end() && (*mi).second.name == strAccount) if (mi != pwallet->mapAddressBook.end() && (*mi).second.name == strAccount)
nReceived += r.second; nReceived += r.amount;
} }
else if (strAccount.empty()) else if (strAccount.empty())
{ {
nReceived += r.second; nReceived += r.amount;
} }
} }
} }

10
src/wallet.h

@ -467,6 +467,12 @@ static void WriteOrderPos(const int64_t& nOrderPos, mapValue_t& mapValue)
mapValue["n"] = i64tostr(nOrderPos); mapValue["n"] = i64tostr(nOrderPos);
} }
struct COutputEntry
{
CTxDestination destination;
int64_t amount;
int vout;
};
/** A transaction with a bunch of additional info that only the owner cares about. /** A transaction with a bunch of additional info that only the owner cares about.
* It includes any unrecorded transactions needed to link it back to the block chain. * It includes any unrecorded transactions needed to link it back to the block chain.
@ -761,8 +767,8 @@ public:
return nChangeCached; return nChangeCached;
} }
void GetAmounts(std::list<std::pair<CTxDestination, int64_t> >& listReceived, void GetAmounts(std::list<COutputEntry>& listReceived,
std::list<std::pair<CTxDestination, int64_t> >& listSent, int64_t& nFee, std::string& strSentAccount, const isminefilter& filter) const; std::list<COutputEntry>& listSent, int64_t& nFee, std::string& strSentAccount, const isminefilter& filter) const;
void GetAccountAmounts(const std::string& strAccount, int64_t& nReceived, void GetAccountAmounts(const std::string& strAccount, int64_t& nReceived,
int64_t& nSent, int64_t& nFee, const isminefilter& filter) const; int64_t& nSent, int64_t& nFee, const isminefilter& filter) const;

Loading…
Cancel
Save