aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGavin Andresen <gavinandresen@gmail.com>2011-04-12 17:31:31 -0400
committerGavin Andresen <gavinandresen@gmail.com>2011-04-12 17:31:31 -0400
commit485dda9774b574a82fd23dc9650dd2cbcab2a391 (patch)
treed8df066ef0d7f6fde81d38adf61cb514933ab705
parentd89d456655f03159a32e6a4a9df22bfe02d403d6 (diff)
parent198fd7b0bd5a99db4e45009c422a66c0b1285767 (diff)
downloadbitcoin-485dda9774b574a82fd23dc9650dd2cbcab2a391.tar.xz
Merge branch 'listimmature' of /Users/gavin/src/gavin_btc
-rw-r--r--main.cpp18
-rw-r--r--main.h2
-rw-r--r--rpc.cpp32
3 files changed, 31 insertions, 21 deletions
diff --git a/main.cpp b/main.cpp
index 1c2292badb..c7ae47f69e 100644
--- a/main.cpp
+++ b/main.cpp
@@ -411,18 +411,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;
}
@@ -470,15 +472,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)
diff --git a/main.h b/main.h
index 7becd08462..355ef5313f 100644
--- a/main.h
+++ b/main.h
@@ -994,7 +994,7 @@ public:
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,
diff --git a/rpc.cpp b/rpc.cpp
index d527f9b35a..93df5c22a4 100644
--- a/rpc.cpp
+++ b/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)
{
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;
@@ -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<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);
@@ -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;