aboutsummaryrefslogtreecommitdiff
path: root/main.cpp
diff options
context:
space:
mode:
authorgavinandresen <gavinandresen@1a98c847-1fd6-4fd8-948a-caf3550aa51b>2010-12-16 01:06:03 +0000
committergavinandresen <gavinandresen@1a98c847-1fd6-4fd8-948a-caf3550aa51b>2010-12-16 01:06:03 +0000
commit809ee795927f0b9110a5b6e83845f42e3394451d (patch)
treea906fe04ac63e46d82793d893b8aa69960de6df7 /main.cpp
parent629e37dde1fa93f6ce31544d1ebb5ee5c19052cb (diff)
New RPC command: listaccounts. New RPC setting -rpctimeout. And listtransactions '*'
git-svn-id: https://bitcoin.svn.sourceforge.net/svnroot/bitcoin/trunk@203 1a98c847-1fd6-4fd8-948a-caf3550aa51b
Diffstat (limited to 'main.cpp')
-rw-r--r--main.cpp57
1 files changed, 57 insertions, 0 deletions
diff --git a/main.cpp b/main.cpp
index 1d9b35b534..8db6c394e8 100644
--- a/main.cpp
+++ b/main.cpp
@@ -394,6 +394,63 @@ int CWalletTx::GetRequestCount() const
return nRequests;
}
+void CWalletTx::GetAmounts(int64& nGenerated, list<pair<string, int64> >& listReceived,
+ int64& nSent, int64& nFee, string& strSentAccount) const
+{
+ nGenerated = nSent = nFee = 0;
+
+ if (IsCoinBase())
+ {
+ if (GetBlocksToMaturity() == 0)
+ nGenerated = GetCredit();
+ return;
+ }
+
+ // 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)
+ {
+ vector<unsigned char> vchPubKey;
+ if (ExtractPubKey(txout.scriptPubKey, true, vchPubKey))
+ listReceived.push_back(make_pair(PubKeyToAddress(vchPubKey), txout.nValue));
+ }
+
+ // Sent
+ int64 nDebit = GetDebit();
+ if (nDebit > 0)
+ {
+ int64 nValueOut = GetValueOut();
+ nFee = nDebit - nValueOut;
+ nSent = nValueOut - GetChange();
+ strSentAccount = strFromAccount;
+ }
+}
+
+void CWalletTx::GetAccountAmounts(const string& strAccount, int64& nGenerated, int64& nReceived,
+ int64& nSent, int64& nFee) const
+{
+ nGenerated = nReceived = nSent = nFee = 0;
+
+ int64 allGenerated, allSent, allFee;
+ allGenerated = allSent = allFee = 0;
+ string strSentAccount;
+ list<pair<string, int64> > listReceived;
+ GetAmounts(allGenerated, listReceived, allSent, allFee, strSentAccount);
+
+ if (strAccount == "")
+ nGenerated = allGenerated;
+ if (strAccount == strSentAccount)
+ {
+ nSent = allSent;
+ nFee = allFee;
+ }
+ CRITICAL_BLOCK(cs_mapAddressBook)
+ {
+ foreach(const PAIRTYPE(string,int64)& r, listReceived)
+ if (mapAddressBook.count(r.first) && mapAddressBook[r.first] == strAccount)
+ nReceived += r.second;
+ }
+}