Add vout to ListTransactions output
This commit is contained in:
parent
2c0f019bfc
commit
1b4568cb0f
3 changed files with 56 additions and 43 deletions
|
@ -641,16 +641,16 @@ Value getbalance(const Array& params, bool fHelp)
|
|||
|
||||
int64_t allFee;
|
||||
string strSentAccount;
|
||||
list<pair<CTxDestination, int64_t> > listReceived;
|
||||
list<pair<CTxDestination, int64_t> > listSent;
|
||||
list<COutputEntry> listReceived;
|
||||
list<COutputEntry> listSent;
|
||||
wtx.GetAmounts(listReceived, listSent, allFee, strSentAccount, filter);
|
||||
if (wtx.GetDepthInMainChain() >= nMinDepth)
|
||||
{
|
||||
BOOST_FOREACH(const PAIRTYPE(CTxDestination,int64_t)& r, listReceived)
|
||||
nBalance += r.second;
|
||||
BOOST_FOREACH(const COutputEntry& r, listReceived)
|
||||
nBalance += r.amount;
|
||||
}
|
||||
BOOST_FOREACH(const PAIRTYPE(CTxDestination,int64_t)& r, listSent)
|
||||
nBalance -= r.second;
|
||||
BOOST_FOREACH(const COutputEntry& s, listSent)
|
||||
nBalance -= s.amount;
|
||||
nBalance -= allFee;
|
||||
}
|
||||
return ValueFromAmount(nBalance);
|
||||
|
@ -1133,8 +1133,8 @@ void ListTransactions(const CWalletTx& wtx, const string& strAccount, int nMinDe
|
|||
{
|
||||
int64_t nFee;
|
||||
string strSentAccount;
|
||||
list<pair<CTxDestination, int64_t> > listReceived;
|
||||
list<pair<CTxDestination, int64_t> > listSent;
|
||||
list<COutputEntry> listReceived;
|
||||
list<COutputEntry> listSent;
|
||||
|
||||
wtx.GetAmounts(listReceived, listSent, nFee, strSentAccount, filter);
|
||||
|
||||
|
@ -1144,15 +1144,16 @@ void ListTransactions(const CWalletTx& wtx, const string& strAccount, int nMinDe
|
|||
// Sent
|
||||
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;
|
||||
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("account", strSentAccount));
|
||||
MaybePushAddress(entry, s.first);
|
||||
MaybePushAddress(entry, s.destination);
|
||||
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)));
|
||||
if (fLong)
|
||||
WalletTxToJSON(wtx, entry);
|
||||
|
@ -1163,18 +1164,18 @@ void ListTransactions(const CWalletTx& wtx, const string& strAccount, int nMinDe
|
|||
// Received
|
||||
if (listReceived.size() > 0 && wtx.GetDepthInMainChain() >= nMinDepth)
|
||||
{
|
||||
BOOST_FOREACH(const PAIRTYPE(CTxDestination, int64_t)& r, listReceived)
|
||||
BOOST_FOREACH(const COutputEntry& r, listReceived)
|
||||
{
|
||||
string account;
|
||||
if (pwalletMain->mapAddressBook.count(r.first))
|
||||
account = pwalletMain->mapAddressBook[r.first].name;
|
||||
if (pwalletMain->mapAddressBook.count(r.destination))
|
||||
account = pwalletMain->mapAddressBook[r.destination].name;
|
||||
if (fAllAccounts || (account == strAccount))
|
||||
{
|
||||
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("account", account));
|
||||
MaybePushAddress(entry, r.first);
|
||||
MaybePushAddress(entry, r.destination);
|
||||
if (wtx.IsCoinBase())
|
||||
{
|
||||
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("amount", ValueFromAmount(r.second)));
|
||||
entry.push_back(Pair("amount", ValueFromAmount(r.amount)));
|
||||
entry.push_back(Pair("vout", r.vout));
|
||||
if (fLong)
|
||||
WalletTxToJSON(wtx, 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"
|
||||
" 'move' category for moves outbound. It is positive for the 'receive' category,\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"
|
||||
" 'send' category of transactions.\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;
|
||||
int64_t nFee;
|
||||
string strSentAccount;
|
||||
list<pair<CTxDestination, int64_t> > listReceived;
|
||||
list<pair<CTxDestination, int64_t> > listSent;
|
||||
list<COutputEntry> listReceived;
|
||||
list<COutputEntry> listSent;
|
||||
int nDepth = wtx.GetDepthInMainChain();
|
||||
if (wtx.GetBlocksToMaturity() > 0 || nDepth < 0)
|
||||
continue;
|
||||
wtx.GetAmounts(listReceived, listSent, nFee, strSentAccount, includeWatchonly);
|
||||
mapAccountBalances[strSentAccount] -= nFee;
|
||||
BOOST_FOREACH(const PAIRTYPE(CTxDestination, int64_t)& s, listSent)
|
||||
mapAccountBalances[strSentAccount] -= s.second;
|
||||
BOOST_FOREACH(const COutputEntry& s, listSent)
|
||||
mapAccountBalances[strSentAccount] -= s.amount;
|
||||
if (nDepth >= nMinDepth)
|
||||
{
|
||||
BOOST_FOREACH(const PAIRTYPE(CTxDestination, int64_t)& r, listReceived)
|
||||
if (pwalletMain->mapAddressBook.count(r.first))
|
||||
mapAccountBalances[pwalletMain->mapAddressBook[r.first].name] += r.second;
|
||||
BOOST_FOREACH(const COutputEntry& r, listReceived)
|
||||
if (pwalletMain->mapAddressBook.count(r.destination))
|
||||
mapAccountBalances[pwalletMain->mapAddressBook[r.destination].name] += r.amount;
|
||||
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"
|
||||
" \"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"
|
||||
" \"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"
|
||||
" \"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"
|
||||
|
@ -1528,6 +1532,7 @@ Value gettransaction(const Array& params, bool fHelp)
|
|||
" \"address\" : \"bitcoinaddress\", (string) The bitcoin address involved in the transaction\n"
|
||||
" \"category\" : \"send|receive\", (string) The category, either 'send' or 'receive'\n"
|
||||
" \"amount\" : x.xxx (numeric) The amount in btc\n"
|
||||
" \"vout\" : n, (numeric) the vout value\n"
|
||||
" }\n"
|
||||
" ,...\n"
|
||||
" ],\n"
|
||||
|
|
|
@ -798,8 +798,8 @@ int CWalletTx::GetRequestCount() const
|
|||
return nRequests;
|
||||
}
|
||||
|
||||
void CWalletTx::GetAmounts(list<pair<CTxDestination, int64_t> >& listReceived,
|
||||
list<pair<CTxDestination, int64_t> >& listSent, int64_t& nFee, string& strSentAccount, const isminefilter& filter) const
|
||||
void CWalletTx::GetAmounts(list<COutputEntry>& listReceived,
|
||||
list<COutputEntry>& listSent, int64_t& nFee, string& strSentAccount, const isminefilter& filter) const
|
||||
{
|
||||
nFee = 0;
|
||||
listReceived.clear();
|
||||
|
@ -815,10 +815,10 @@ void CWalletTx::GetAmounts(list<pair<CTxDestination, int64_t> >& listReceived,
|
|||
}
|
||||
|
||||
// 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);
|
||||
|
||||
// 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)
|
||||
|
@ -840,13 +840,15 @@ void CWalletTx::GetAmounts(list<pair<CTxDestination, int64_t> >& listReceived,
|
|||
address = CNoDestination();
|
||||
}
|
||||
|
||||
COutputEntry output = {address, txout.nValue, i};
|
||||
|
||||
// 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));
|
||||
listSent.push_back(output);
|
||||
|
||||
// If we are receiving the output, add it as a "received" entry
|
||||
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;
|
||||
string strSentAccount;
|
||||
list<pair<CTxDestination, int64_t> > listReceived;
|
||||
list<pair<CTxDestination, int64_t> > listSent;
|
||||
list<COutputEntry> listReceived;
|
||||
list<COutputEntry> listSent;
|
||||
GetAmounts(listReceived, listSent, allFee, strSentAccount, filter);
|
||||
|
||||
if (strAccount == strSentAccount)
|
||||
{
|
||||
BOOST_FOREACH(const PAIRTYPE(CTxDestination,int64_t)& s, listSent)
|
||||
nSent += s.second;
|
||||
BOOST_FOREACH(const COutputEntry& s, listSent)
|
||||
nSent += s.amount;
|
||||
nFee = allFee;
|
||||
}
|
||||
{
|
||||
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)
|
||||
nReceived += r.second;
|
||||
nReceived += r.amount;
|
||||
}
|
||||
else if (strAccount.empty())
|
||||
{
|
||||
nReceived += r.second;
|
||||
nReceived += r.amount;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
10
src/wallet.h
10
src/wallet.h
|
@ -467,6 +467,12 @@ static void WriteOrderPos(const int64_t& nOrderPos, mapValue_t& mapValue)
|
|||
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.
|
||||
* It includes any unrecorded transactions needed to link it back to the block chain.
|
||||
|
@ -761,8 +767,8 @@ public:
|
|||
return nChangeCached;
|
||||
}
|
||||
|
||||
void GetAmounts(std::list<std::pair<CTxDestination, int64_t> >& listReceived,
|
||||
std::list<std::pair<CTxDestination, int64_t> >& listSent, int64_t& nFee, std::string& strSentAccount, const isminefilter& filter) const;
|
||||
void GetAmounts(std::list<COutputEntry>& listReceived,
|
||||
std::list<COutputEntry>& listSent, int64_t& nFee, std::string& strSentAccount, const isminefilter& filter) const;
|
||||
|
||||
void GetAccountAmounts(const std::string& strAccount, int64_t& nReceived,
|
||||
int64_t& nSent, int64_t& nFee, const isminefilter& filter) const;
|
||||
|
|
Loading…
Reference in a new issue