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).
This commit is contained in:
parent
0a4cb86976
commit
198fd7b0bd
3 changed files with 31 additions and 21 deletions
18
main.cpp
18
main.cpp
|
@ -407,18 +407,20 @@ int CWalletTx::GetRequestCount() const
|
||||||
return nRequests;
|
return nRequests;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CWalletTx::GetAmounts(int64& nGenerated, list<pair<string, int64> >& listReceived,
|
void CWalletTx::GetAmounts(int64& nGeneratedImmature, int64& nGeneratedMature, list<pair<string, int64> >& listReceived,
|
||||||
list<pair<string, int64> >& listSent, int64& nFee, string& strSentAccount) const
|
list<pair<string, int64> >& listSent, int64& nFee, string& strSentAccount) const
|
||||||
{
|
{
|
||||||
nGenerated = nFee = 0;
|
nGeneratedImmature = nGeneratedMature = nFee = 0;
|
||||||
listReceived.clear();
|
listReceived.clear();
|
||||||
listSent.clear();
|
listSent.clear();
|
||||||
strSentAccount = strFromAccount;
|
strSentAccount = strFromAccount;
|
||||||
|
|
||||||
if (IsCoinBase())
|
if (IsCoinBase())
|
||||||
{
|
{
|
||||||
if (GetDepthInMainChain() >= COINBASE_MATURITY)
|
if (GetBlocksToMaturity() > 0)
|
||||||
nGenerated = GetCredit();
|
nGeneratedImmature = CTransaction::GetCredit();
|
||||||
|
else
|
||||||
|
nGeneratedMature = GetCredit();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -466,15 +468,15 @@ void CWalletTx::GetAccountAmounts(const string& strAccount, int64& nGenerated, i
|
||||||
{
|
{
|
||||||
nGenerated = nReceived = nSent = nFee = 0;
|
nGenerated = nReceived = nSent = nFee = 0;
|
||||||
|
|
||||||
int64 allGenerated, allFee;
|
int64 allGeneratedImmature, allGeneratedMature, allFee;
|
||||||
allGenerated = allFee = 0;
|
allGeneratedImmature = allGeneratedMature = allFee = 0;
|
||||||
string strSentAccount;
|
string strSentAccount;
|
||||||
list<pair<string, int64> > listReceived;
|
list<pair<string, int64> > listReceived;
|
||||||
list<pair<string, int64> > listSent;
|
list<pair<string, int64> > listSent;
|
||||||
GetAmounts(allGenerated, listReceived, listSent, allFee, strSentAccount);
|
GetAmounts(allGeneratedImmature, allGeneratedMature, listReceived, listSent, allFee, strSentAccount);
|
||||||
|
|
||||||
if (strAccount == "")
|
if (strAccount == "")
|
||||||
nGenerated = allGenerated;
|
nGenerated = allGeneratedMature;
|
||||||
if (strAccount == strSentAccount)
|
if (strAccount == strSentAccount)
|
||||||
{
|
{
|
||||||
foreach(const PAIRTYPE(string,int64)& s, listSent)
|
foreach(const PAIRTYPE(string,int64)& s, listSent)
|
||||||
|
|
2
main.h
2
main.h
|
@ -882,7 +882,7 @@ public:
|
||||||
return nChangeCached;
|
return nChangeCached;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GetAmounts(int64& nGenerated, list<pair<string /* address */, int64> >& listReceived,
|
void GetAmounts(int64& nGeneratedImmature, int64& nGeneratedMature, list<pair<string /* address */, int64> >& listReceived,
|
||||||
list<pair<string /* address */, int64> >& listSent, int64& nFee, string& strSentAccount) const;
|
list<pair<string /* address */, int64> >& listSent, int64& nFee, string& strSentAccount) const;
|
||||||
|
|
||||||
void GetAccountAmounts(const string& strAccount, int64& nGenerated, int64& nReceived,
|
void GetAccountAmounts(const string& strAccount, int64& nGenerated, int64& nReceived,
|
||||||
|
|
32
rpc.cpp
32
rpc.cpp
|
@ -649,12 +649,12 @@ Value getbalance(const Array& params, bool fHelp)
|
||||||
for (map<uint256, CWalletTx>::iterator it = mapWallet.begin(); it != mapWallet.end(); ++it)
|
for (map<uint256, CWalletTx>::iterator it = mapWallet.begin(); it != mapWallet.end(); ++it)
|
||||||
{
|
{
|
||||||
const CWalletTx& wtx = (*it).second;
|
const CWalletTx& wtx = (*it).second;
|
||||||
int64 allGenerated, allFee;
|
int64 allGeneratedImmature, allGeneratedMature, allFee;
|
||||||
allGenerated = allFee = 0;
|
allGeneratedImmature = allGeneratedMature = allFee = 0;
|
||||||
string strSentAccount;
|
string strSentAccount;
|
||||||
list<pair<string, int64> > listReceived;
|
list<pair<string, int64> > listReceived;
|
||||||
list<pair<string, int64> > listSent;
|
list<pair<string, int64> > listSent;
|
||||||
wtx.GetAmounts(allGenerated, listReceived, listSent, allFee, strSentAccount);
|
wtx.GetAmounts(allGeneratedImmature, allGeneratedMature, listReceived, listSent, allFee, strSentAccount);
|
||||||
foreach(const PAIRTYPE(string,int64)& r, listReceived)
|
foreach(const PAIRTYPE(string,int64)& r, listReceived)
|
||||||
{
|
{
|
||||||
nBalance += r.second;
|
nBalance += r.second;
|
||||||
|
@ -664,7 +664,7 @@ Value getbalance(const Array& params, bool fHelp)
|
||||||
foreach(const PAIRTYPE(string,int64)& r, listSent)
|
foreach(const PAIRTYPE(string,int64)& r, listSent)
|
||||||
nBalance -= r.second;
|
nBalance -= r.second;
|
||||||
nBalance -= allFee;
|
nBalance -= allFee;
|
||||||
nBalance += allGenerated;
|
nBalance += allGeneratedMature;
|
||||||
}
|
}
|
||||||
printf("Found %d accounts\n", vAccounts.size());
|
printf("Found %d accounts\n", vAccounts.size());
|
||||||
return ValueFromAmount(nBalance);
|
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)
|
void ListTransactions(const CWalletTx& wtx, const string& strAccount, int nMinDepth, bool fLong, Array& ret)
|
||||||
{
|
{
|
||||||
int64 nGenerated, nFee;
|
int64 nGeneratedImmature, nGeneratedMature, nFee;
|
||||||
string strSentAccount;
|
string strSentAccount;
|
||||||
list<pair<string, int64> > listReceived;
|
list<pair<string, int64> > listReceived;
|
||||||
list<pair<string, int64> > listSent;
|
list<pair<string, int64> > listSent;
|
||||||
wtx.GetAmounts(nGenerated, listReceived, listSent, nFee, strSentAccount);
|
wtx.GetAmounts(nGeneratedImmature, nGeneratedMature, listReceived, listSent, nFee, strSentAccount);
|
||||||
|
|
||||||
bool fAllAccounts = (strAccount == string("*"));
|
bool fAllAccounts = (strAccount == string("*"));
|
||||||
|
|
||||||
// Generated blocks assigned to account ""
|
// Generated blocks assigned to account ""
|
||||||
if (nGenerated != 0 && (fAllAccounts || strAccount == ""))
|
if ((nGeneratedMature+nGeneratedImmature) != 0 && (fAllAccounts || strAccount == ""))
|
||||||
{
|
{
|
||||||
Object entry;
|
Object entry;
|
||||||
entry.push_back(Pair("account", string("")));
|
entry.push_back(Pair("account", string("")));
|
||||||
entry.push_back(Pair("category", "generate"));
|
if (nGeneratedImmature)
|
||||||
entry.push_back(Pair("amount", ValueFromAmount(nGenerated)));
|
{
|
||||||
|
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)
|
if (fLong)
|
||||||
WalletTxToJSON(wtx, entry);
|
WalletTxToJSON(wtx, entry);
|
||||||
ret.push_back(entry);
|
ret.push_back(entry);
|
||||||
|
@ -1159,17 +1167,17 @@ Value listaccounts(const Array& params, bool fHelp)
|
||||||
for (map<uint256, CWalletTx>::iterator it = mapWallet.begin(); it != mapWallet.end(); ++it)
|
for (map<uint256, CWalletTx>::iterator it = mapWallet.begin(); it != mapWallet.end(); ++it)
|
||||||
{
|
{
|
||||||
const CWalletTx& wtx = (*it).second;
|
const CWalletTx& wtx = (*it).second;
|
||||||
int64 nGenerated, nFee;
|
int64 nGeneratedImmature, nGeneratedMature, nFee;
|
||||||
string strSentAccount;
|
string strSentAccount;
|
||||||
list<pair<string, int64> > listReceived;
|
list<pair<string, int64> > listReceived;
|
||||||
list<pair<string, int64> > listSent;
|
list<pair<string, int64> > listSent;
|
||||||
wtx.GetAmounts(nGenerated, listReceived, listSent, nFee, strSentAccount);
|
wtx.GetAmounts(nGeneratedImmature, nGeneratedMature, listReceived, listSent, nFee, strSentAccount);
|
||||||
mapAccountBalances[strSentAccount] -= nFee;
|
mapAccountBalances[strSentAccount] -= nFee;
|
||||||
foreach(const PAIRTYPE(string, int64)& s, listSent)
|
foreach(const PAIRTYPE(string, int64)& s, listSent)
|
||||||
mapAccountBalances[strSentAccount] -= s.second;
|
mapAccountBalances[strSentAccount] -= s.second;
|
||||||
if (wtx.GetDepthInMainChain() >= nMinDepth)
|
if (wtx.GetDepthInMainChain() >= nMinDepth)
|
||||||
{
|
{
|
||||||
mapAccountBalances[""] += nGenerated;
|
mapAccountBalances[""] += nGeneratedMature;
|
||||||
foreach(const PAIRTYPE(string, int64)& r, listReceived)
|
foreach(const PAIRTYPE(string, int64)& r, listReceived)
|
||||||
if (mapAddressBook.count(r.first))
|
if (mapAddressBook.count(r.first))
|
||||||
mapAccountBalances[mapAddressBook[r.first]] += r.second;
|
mapAccountBalances[mapAddressBook[r.first]] += r.second;
|
||||||
|
|
Loading…
Reference in a new issue