|
|
|
@ -476,20 +476,7 @@ int64 GetAccountBalance(CWalletDB& walletdb, const string& strAccount, int nMinD
@@ -476,20 +476,7 @@ int64 GetAccountBalance(CWalletDB& walletdb, const string& strAccount, int nMinD
|
|
|
|
|
{ |
|
|
|
|
int64 nBalance = 0; |
|
|
|
|
|
|
|
|
|
// Tally wallet transactions
|
|
|
|
|
for (map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it) |
|
|
|
|
{ |
|
|
|
|
const CWalletTx& wtx = (*it).second; |
|
|
|
|
int64 nReceived, nSent, nFee; |
|
|
|
|
wtx.GetAccountAmounts(strAccount, nReceived, nSent, nFee); |
|
|
|
|
|
|
|
|
|
if (nReceived != 0 && wtx.GetDepthInMainChain() >= nMinDepth) |
|
|
|
|
nBalance += nReceived; |
|
|
|
|
nBalance -= nSent + nFee; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Tally internal accounting entries
|
|
|
|
|
nBalance += walletdb.GetAccountCreditDebit(strAccount); |
|
|
|
|
//if (nReceived != 0 && wtx.GetDepthInMainChain() >= nMinDepth)
|
|
|
|
|
|
|
|
|
|
return nBalance; |
|
|
|
|
} |
|
|
|
@ -516,37 +503,7 @@ Value getbalance(const Array& params, bool fHelp)
@@ -516,37 +503,7 @@ Value getbalance(const Array& params, bool fHelp)
|
|
|
|
|
if (params.size() > 1) |
|
|
|
|
nMinDepth = params[1].get_int(); |
|
|
|
|
|
|
|
|
|
if (params[0].get_str() == "*") { |
|
|
|
|
// Calculate total balance a different way from GetBalance()
|
|
|
|
|
// (GetBalance() sums up all unspent TxOuts)
|
|
|
|
|
// getbalance and getbalance '*' 0 should return the same number
|
|
|
|
|
int64 nBalance = 0; |
|
|
|
|
for (map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it) |
|
|
|
|
{ |
|
|
|
|
const CWalletTx& wtx = (*it).second; |
|
|
|
|
if (!wtx.IsConfirmed()) |
|
|
|
|
continue; |
|
|
|
|
|
|
|
|
|
int64 allFee; |
|
|
|
|
string strSentAccount; |
|
|
|
|
list<pair<CTxDestination, int64> > listReceived; |
|
|
|
|
list<pair<CTxDestination, int64> > listSent; |
|
|
|
|
wtx.GetAmounts(listReceived, listSent, allFee, strSentAccount); |
|
|
|
|
if (wtx.GetDepthInMainChain() >= nMinDepth) |
|
|
|
|
{ |
|
|
|
|
BOOST_FOREACH(const PAIRTYPE(CTxDestination,int64)& r, listReceived) |
|
|
|
|
nBalance += r.second; |
|
|
|
|
} |
|
|
|
|
BOOST_FOREACH(const PAIRTYPE(CTxDestination,int64)& r, listSent) |
|
|
|
|
nBalance -= r.second; |
|
|
|
|
nBalance -= allFee; |
|
|
|
|
} |
|
|
|
|
return ValueFromAmount(nBalance); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
string strAccount = AccountFromValue(params[0]); |
|
|
|
|
|
|
|
|
|
int64 nBalance = GetAccountBalance(strAccount, nMinDepth); |
|
|
|
|
|
|
|
|
|
return ValueFromAmount(nBalance); |
|
|
|
|
} |
|
|
|
@ -955,64 +912,29 @@ Value listreceivedbyaccount(const Array& params, bool fHelp)
@@ -955,64 +912,29 @@ Value listreceivedbyaccount(const Array& params, bool fHelp)
|
|
|
|
|
|
|
|
|
|
void ListTransactions(const CWalletTx& wtx, const string& strAccount, int nMinDepth, bool fLong, Array& ret) |
|
|
|
|
{ |
|
|
|
|
int64 nFee; |
|
|
|
|
string strSentAccount; |
|
|
|
|
list<pair<CTxDestination, int64> > listReceived; |
|
|
|
|
list<pair<CTxDestination, int64> > listSent; |
|
|
|
|
|
|
|
|
|
wtx.GetAmounts(listReceived, listSent, nFee, strSentAccount); |
|
|
|
|
|
|
|
|
|
bool fAllAccounts = (strAccount == string("*")); |
|
|
|
|
|
|
|
|
|
// Sent
|
|
|
|
|
if ((!listSent.empty() || nFee != 0) && (fAllAccounts || strAccount == strSentAccount)) |
|
|
|
|
{ |
|
|
|
|
BOOST_FOREACH(const PAIRTYPE(CTxDestination, int64)& s, listSent) |
|
|
|
|
//if ((fAllAccounts || strAccount == strSentAccount))
|
|
|
|
|
{ |
|
|
|
|
Object entry; |
|
|
|
|
entry.push_back(Pair("account", strSentAccount)); |
|
|
|
|
entry.push_back(Pair("address", CBitcoinAddress(s.first).ToString())); |
|
|
|
|
entry.push_back(Pair("category", "send")); |
|
|
|
|
entry.push_back(Pair("amount", ValueFromAmount(-s.second))); |
|
|
|
|
entry.push_back(Pair("fee", ValueFromAmount(-nFee))); |
|
|
|
|
//entry.push_back(Pair("account", strSentAccount));
|
|
|
|
|
//entry.push_back(Pair("address", CBitcoinAddress(s.first).ToString()));
|
|
|
|
|
if (fLong) |
|
|
|
|
WalletTxToJSON(wtx, entry); |
|
|
|
|
ret.push_back(entry); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Received
|
|
|
|
|
if (listReceived.size() > 0 && wtx.GetDepthInMainChain() >= nMinDepth) |
|
|
|
|
{ |
|
|
|
|
BOOST_FOREACH(const PAIRTYPE(CTxDestination, int64)& r, listReceived) |
|
|
|
|
{ |
|
|
|
|
string account; |
|
|
|
|
if (pwalletMain->mapAddressBook.count(r.first)) |
|
|
|
|
account = pwalletMain->mapAddressBook[r.first]; |
|
|
|
|
if (fAllAccounts || (account == strAccount)) |
|
|
|
|
if (wtx.GetDepthInMainChain() >= nMinDepth) |
|
|
|
|
{ |
|
|
|
|
Object entry; |
|
|
|
|
entry.push_back(Pair("account", account)); |
|
|
|
|
entry.push_back(Pair("address", CBitcoinAddress(r.first).ToString())); |
|
|
|
|
if (wtx.IsSpamMessage()) |
|
|
|
|
{ |
|
|
|
|
if (wtx.GetDepthInMainChain() < 1) |
|
|
|
|
entry.push_back(Pair("category", "orphan")); |
|
|
|
|
else if (wtx.GetBlocksToMaturity() > 0) |
|
|
|
|
entry.push_back(Pair("category", "immature")); |
|
|
|
|
else |
|
|
|
|
entry.push_back(Pair("category", "generate")); |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
entry.push_back(Pair("category", "receive")); |
|
|
|
|
entry.push_back(Pair("amount", ValueFromAmount(r.second))); |
|
|
|
|
//entry.push_back(Pair("account", account));
|
|
|
|
|
//entry.push_back(Pair("address", CBitcoinAddress(r.first).ToString()));
|
|
|
|
|
if (fLong) |
|
|
|
|
WalletTxToJSON(wtx, entry); |
|
|
|
|
ret.push_back(entry); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void AcentryToJSON(const CAccountingEntry& acentry, const string& strAccount, Array& ret) |
|
|
|
|
{ |
|
|
|
@ -1109,21 +1031,9 @@ Value listaccounts(const Array& params, bool fHelp)
@@ -1109,21 +1031,9 @@ Value listaccounts(const Array& params, bool fHelp)
|
|
|
|
|
for (map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it) |
|
|
|
|
{ |
|
|
|
|
const CWalletTx& wtx = (*it).second; |
|
|
|
|
int64 nFee; |
|
|
|
|
string strSentAccount; |
|
|
|
|
list<pair<CTxDestination, int64> > listReceived; |
|
|
|
|
list<pair<CTxDestination, int64> > listSent; |
|
|
|
|
wtx.GetAmounts(listReceived, listSent, nFee, strSentAccount); |
|
|
|
|
mapAccountBalances[strSentAccount] -= nFee; |
|
|
|
|
BOOST_FOREACH(const PAIRTYPE(CTxDestination, int64)& s, listSent) |
|
|
|
|
mapAccountBalances[strSentAccount] -= s.second; |
|
|
|
|
|
|
|
|
|
if (wtx.GetDepthInMainChain() >= nMinDepth) |
|
|
|
|
{ |
|
|
|
|
BOOST_FOREACH(const PAIRTYPE(CTxDestination, int64)& r, listReceived) |
|
|
|
|
if (pwalletMain->mapAddressBook.count(r.first)) |
|
|
|
|
mapAccountBalances[pwalletMain->mapAddressBook[r.first]] += r.second; |
|
|
|
|
else |
|
|
|
|
mapAccountBalances[""] += r.second; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -1217,14 +1127,7 @@ Value gettransaction(const Array& params, bool fHelp)
@@ -1217,14 +1127,7 @@ Value gettransaction(const Array& params, bool fHelp)
|
|
|
|
|
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid or non-wallet transaction id"); |
|
|
|
|
const CWalletTx& wtx = pwalletMain->mapWallet[hash]; |
|
|
|
|
|
|
|
|
|
int64 nCredit = wtx.GetCredit(); |
|
|
|
|
int64 nDebit = wtx.GetDebit(); |
|
|
|
|
int64 nNet = nCredit - nDebit; |
|
|
|
|
int64 nFee = (wtx.IsFromMe() ? GetValueOut(wtx) - nDebit : 0); |
|
|
|
|
|
|
|
|
|
entry.push_back(Pair("amount", ValueFromAmount(nNet - nFee))); |
|
|
|
|
if (wtx.IsFromMe()) |
|
|
|
|
entry.push_back(Pair("fee", ValueFromAmount(nFee))); |
|
|
|
|
//entry.push_back(Pair("amount", ValueFromAmount(nNet - nFee)));
|
|
|
|
|
|
|
|
|
|
WalletTxToJSON(wtx, entry); |
|
|
|
|
|
|
|
|
|