Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Report immature coinbase txns in listtransactions #138

Merged
merged 1 commit into from
Apr 12, 2011
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -407,18 +407,20 @@ int CWalletTx::GetRequestCount() const
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
{
nGenerated = nFee = 0;
nGeneratedImmature = nGeneratedMature = nFee = 0;
listReceived.clear();
listSent.clear();
strSentAccount = strFromAccount;

if (IsCoinBase())
{
if (GetDepthInMainChain() >= COINBASE_MATURITY)
nGenerated = GetCredit();
if (GetBlocksToMaturity() > 0)
nGeneratedImmature = CTransaction::GetCredit();
else
nGeneratedMature = GetCredit();
return;
}

Expand Down Expand Up @@ -466,15 +468,15 @@ void CWalletTx::GetAccountAmounts(const string& strAccount, int64& nGenerated, i
{
nGenerated = nReceived = nSent = nFee = 0;

int64 allGenerated, allFee;
allGenerated = allFee = 0;
int64 allGeneratedImmature, allGeneratedMature, allFee;
allGeneratedImmature = allGeneratedMature = allFee = 0;
string strSentAccount;
list<pair<string, int64> > listReceived;
list<pair<string, int64> > listSent;
GetAmounts(allGenerated, listReceived, listSent, allFee, strSentAccount);
GetAmounts(allGeneratedImmature, allGeneratedMature, listReceived, listSent, allFee, strSentAccount);

if (strAccount == "")
nGenerated = allGenerated;
nGenerated = allGeneratedMature;
if (strAccount == strSentAccount)
{
foreach(const PAIRTYPE(string,int64)& s, listSent)
Expand Down
2 changes: 1 addition & 1 deletion main.h
Original file line number Diff line number Diff line change
Expand Up @@ -882,7 +882,7 @@ class CWalletTx : public CMerkleTx
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;

void GetAccountAmounts(const string& strAccount, int64& nGenerated, int64& nReceived,
Expand Down
32 changes: 20 additions & 12 deletions rpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -649,12 +649,12 @@ Value getbalance(const Array& params, bool fHelp)
for (map<uint256, CWalletTx>::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<pair<string, int64> > listReceived;
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)
{
nBalance += r.second;
Expand All @@ -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);
Expand Down Expand Up @@ -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<pair<string, int64> > listReceived;
list<pair<string, int64> > 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);
Expand Down Expand Up @@ -1159,17 +1167,17 @@ Value listaccounts(const Array& params, bool fHelp)
for (map<uint256, CWalletTx>::iterator it = mapWallet.begin(); it != mapWallet.end(); ++it)
{
const CWalletTx& wtx = (*it).second;
int64 nGenerated, nFee;
int64 nGeneratedImmature, nGeneratedMature, nFee;
string strSentAccount;
list<pair<string, int64> > listReceived;
list<pair<string, int64> > 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;
Expand Down