diff options
author | Gavin Andresen <gavinandresen@gmail.com> | 2011-01-18 14:46:46 -0500 |
---|---|---|
committer | Gavin Andresen <gavinandresen@gmail.com> | 2011-01-18 14:46:46 -0500 |
commit | c9f70b381dc8ee4197fd5b3d4d20f302632da0ed (patch) | |
tree | c9de69cd651024487fed16ec890e20ef1e721202 /main.cpp | |
parent | 86c2bdfd5d7773e94dda258c52d2dd056fcfb261 (diff) | |
parent | b4671902f2c5aa1c95be547a61b0a72b8a3025de (diff) |
Merge branch 'integration' into FIXES
Diffstat (limited to 'main.cpp')
-rw-r--r-- | main.cpp | 55 |
1 files changed, 37 insertions, 18 deletions
@@ -395,9 +395,12 @@ int CWalletTx::GetRequestCount() const } void CWalletTx::GetAmounts(int64& nGenerated, list<pair<string, int64> >& listReceived, - int64& nSent, int64& nFee, string& strSentAccount) const + list<pair<string, int64> >& listSent, int64& nFee, string& strSentAccount) const { - nGenerated = nSent = nFee = 0; + nGenerated = nFee = 0; + listReceived.clear(); + listSent.clear(); + strSentAccount = strFromAccount; if (IsCoinBase()) { @@ -406,24 +409,38 @@ void CWalletTx::GetAmounts(int64& nGenerated, list<pair<string, int64> >& listRe return; } - // Received. Standard client will never generate a send-to-multiple-recipients, + // Compute fee: + int64 nDebit = GetDebit(); + if (nDebit > 0) // debit>0 means we signed/sent this transaction + { + int64 nValueOut = GetValueOut(); + nFee = nDebit - nValueOut; + } + + // Sent/received. Standard client will never generate a send-to-multiple-recipients, // but non-standard clients might (so return a list of address/amount pairs) foreach(const CTxOut& txout, vout) { + string address; + uint160 hash160; vector<unsigned char> vchPubKey; - if (ExtractPubKey(txout.scriptPubKey, true, vchPubKey)) - listReceived.push_back(make_pair(PubKeyToAddress(vchPubKey), txout.nValue)); - } + if (ExtractHash160(txout.scriptPubKey, hash160)) + address = Hash160ToAddress(hash160); + else if (ExtractPubKey(txout.scriptPubKey, false, vchPubKey)) + address = PubKeyToAddress(vchPubKey); + else + address = " unknown "; // some type of weird non-standard transaction? - // Sent - int64 nDebit = GetDebit(); - if (nDebit > 0) - { - int64 nValueOut = GetValueOut(); - nFee = nDebit - nValueOut; - nSent = nValueOut - GetChange(); - strSentAccount = strFromAccount; + if (nDebit > 0 && txout.IsChange()) + continue; + + if (nDebit > 0) + listSent.push_back(make_pair(address, txout.nValue)); + + if (txout.IsMine()) + listReceived.push_back(make_pair(address, txout.nValue)); } + } void CWalletTx::GetAccountAmounts(const string& strAccount, int64& nGenerated, int64& nReceived, @@ -431,17 +448,19 @@ void CWalletTx::GetAccountAmounts(const string& strAccount, int64& nGenerated, i { nGenerated = nReceived = nSent = nFee = 0; - int64 allGenerated, allSent, allFee; - allGenerated = allSent = allFee = 0; + int64 allGenerated, allFee; + allGenerated = allFee = 0; string strSentAccount; list<pair<string, int64> > listReceived; - GetAmounts(allGenerated, listReceived, allSent, allFee, strSentAccount); + list<pair<string, int64> > listSent; + GetAmounts(allGenerated, listReceived, listSent, allFee, strSentAccount); if (strAccount == "") nGenerated = allGenerated; if (strAccount == strSentAccount) { - nSent = allSent; + foreach(const PAIRTYPE(string,int64)& s, listSent) + nSent += s.second; nFee = allFee; } CRITICAL_BLOCK(cs_mapAddressBook) |