From 198fd7b0bd5a99db4e45009c422a66c0b1285767 Mon Sep 17 00:00:00 2001 From: Gavin Andresen Date: Sun, 27 Mar 2011 14:56:18 -0400 Subject: Report immature coinbase transactions in listtransactions Report coin generation transactions as 'category':'immature' until they have 120 confirmations (when they are reported as 'category':'generate', as before). If the block they are in is not part of the main chain (you lost a 'block race'), then they are reported as 'category':'orphan' (with 0 confirmations). --- rpc.cpp | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) (limited to 'rpc.cpp') diff --git a/rpc.cpp b/rpc.cpp index a7b3b80d9..cf8390da3 100644 --- a/rpc.cpp +++ b/rpc.cpp @@ -649,12 +649,12 @@ Value getbalance(const Array& params, bool fHelp) for (map::iterator it = mapWallet.begin(); it != mapWallet.end(); ++it) { const CWalletTx& wtx = (*it).second; - int64 allGenerated, allFee; - allGenerated = allFee = 0; + int64 allGeneratedImmature, allGeneratedMature, allFee; + allGeneratedImmature = allGeneratedMature = allFee = 0; string strSentAccount; list > listReceived; list > listSent; - wtx.GetAmounts(allGenerated, listReceived, listSent, allFee, strSentAccount); + wtx.GetAmounts(allGeneratedImmature, allGeneratedMature, listReceived, listSent, allFee, strSentAccount); foreach(const PAIRTYPE(string,int64)& r, listReceived) { nBalance += r.second; @@ -664,7 +664,7 @@ Value getbalance(const Array& params, bool fHelp) foreach(const PAIRTYPE(string,int64)& r, listSent) nBalance -= r.second; nBalance -= allFee; - nBalance += allGenerated; + nBalance += allGeneratedMature; } printf("Found %d accounts\n", vAccounts.size()); return ValueFromAmount(nBalance); @@ -993,21 +993,29 @@ Value listreceivedbyaccount(const Array& params, bool fHelp) void ListTransactions(const CWalletTx& wtx, const string& strAccount, int nMinDepth, bool fLong, Array& ret) { - int64 nGenerated, nFee; + int64 nGeneratedImmature, nGeneratedMature, nFee; string strSentAccount; list > listReceived; list > listSent; - wtx.GetAmounts(nGenerated, listReceived, listSent, nFee, strSentAccount); + wtx.GetAmounts(nGeneratedImmature, nGeneratedMature, listReceived, listSent, nFee, strSentAccount); bool fAllAccounts = (strAccount == string("*")); // Generated blocks assigned to account "" - if (nGenerated != 0 && (fAllAccounts || strAccount == "")) + if ((nGeneratedMature+nGeneratedImmature) != 0 && (fAllAccounts || strAccount == "")) { Object entry; entry.push_back(Pair("account", string(""))); - entry.push_back(Pair("category", "generate")); - entry.push_back(Pair("amount", ValueFromAmount(nGenerated))); + if (nGeneratedImmature) + { + entry.push_back(Pair("category", wtx.GetDepthInMainChain() ? "immature" : "orphan")); + entry.push_back(Pair("amount", ValueFromAmount(nGeneratedImmature))); + } + else + { + entry.push_back(Pair("category", "generate")); + entry.push_back(Pair("amount", ValueFromAmount(nGeneratedMature))); + } if (fLong) WalletTxToJSON(wtx, entry); ret.push_back(entry); @@ -1159,17 +1167,17 @@ Value listaccounts(const Array& params, bool fHelp) for (map::iterator it = mapWallet.begin(); it != mapWallet.end(); ++it) { const CWalletTx& wtx = (*it).second; - int64 nGenerated, nFee; + int64 nGeneratedImmature, nGeneratedMature, nFee; string strSentAccount; list > listReceived; list > listSent; - wtx.GetAmounts(nGenerated, listReceived, listSent, nFee, strSentAccount); + wtx.GetAmounts(nGeneratedImmature, nGeneratedMature, listReceived, listSent, nFee, strSentAccount); mapAccountBalances[strSentAccount] -= nFee; foreach(const PAIRTYPE(string, int64)& s, listSent) mapAccountBalances[strSentAccount] -= s.second; if (wtx.GetDepthInMainChain() >= nMinDepth) { - mapAccountBalances[""] += nGenerated; + mapAccountBalances[""] += nGeneratedMature; foreach(const PAIRTYPE(string, int64)& r, listReceived) if (mapAddressBook.count(r.first)) mapAccountBalances[mapAddressBook[r.first]] += r.second; -- cgit v1.2.3