|
|
@ -476,20 +476,7 @@ int64 GetAccountBalance(CWalletDB& walletdb, const string& strAccount, int nMinD |
|
|
|
{ |
|
|
|
{ |
|
|
|
int64 nBalance = 0; |
|
|
|
int64 nBalance = 0; |
|
|
|
|
|
|
|
|
|
|
|
// Tally wallet transactions
|
|
|
|
//if (nReceived != 0 && wtx.GetDepthInMainChain() >= nMinDepth)
|
|
|
|
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); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return nBalance; |
|
|
|
return nBalance; |
|
|
|
} |
|
|
|
} |
|
|
@ -516,37 +503,7 @@ Value getbalance(const Array& params, bool fHelp) |
|
|
|
if (params.size() > 1) |
|
|
|
if (params.size() > 1) |
|
|
|
nMinDepth = params[1].get_int(); |
|
|
|
nMinDepth = params[1].get_int(); |
|
|
|
|
|
|
|
|
|
|
|
if (params[0].get_str() == "*") { |
|
|
|
int64 nBalance = 0; |
|
|
|
// 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); |
|
|
|
return ValueFromAmount(nBalance); |
|
|
|
} |
|
|
|
} |
|
|
@ -955,62 +912,27 @@ Value listreceivedbyaccount(const Array& params, bool fHelp) |
|
|
|
|
|
|
|
|
|
|
|
void ListTransactions(const CWalletTx& wtx, const string& strAccount, int nMinDepth, bool fLong, Array& ret) |
|
|
|
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("*")); |
|
|
|
bool fAllAccounts = (strAccount == string("*")); |
|
|
|
|
|
|
|
|
|
|
|
// Sent
|
|
|
|
// Sent
|
|
|
|
if ((!listSent.empty() || nFee != 0) && (fAllAccounts || strAccount == strSentAccount)) |
|
|
|
//if ((fAllAccounts || strAccount == strSentAccount))
|
|
|
|
{ |
|
|
|
{ |
|
|
|
BOOST_FOREACH(const PAIRTYPE(CTxDestination, int64)& s, listSent) |
|
|
|
Object entry; |
|
|
|
{ |
|
|
|
//entry.push_back(Pair("account", strSentAccount));
|
|
|
|
Object entry; |
|
|
|
//entry.push_back(Pair("address", CBitcoinAddress(s.first).ToString()));
|
|
|
|
entry.push_back(Pair("account", strSentAccount)); |
|
|
|
if (fLong) |
|
|
|
entry.push_back(Pair("address", CBitcoinAddress(s.first).ToString())); |
|
|
|
WalletTxToJSON(wtx, entry); |
|
|
|
entry.push_back(Pair("category", "send")); |
|
|
|
ret.push_back(entry); |
|
|
|
entry.push_back(Pair("amount", ValueFromAmount(-s.second))); |
|
|
|
|
|
|
|
entry.push_back(Pair("fee", ValueFromAmount(-nFee))); |
|
|
|
|
|
|
|
if (fLong) |
|
|
|
|
|
|
|
WalletTxToJSON(wtx, entry); |
|
|
|
|
|
|
|
ret.push_back(entry); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Received
|
|
|
|
if (wtx.GetDepthInMainChain() >= nMinDepth) |
|
|
|
if (listReceived.size() > 0 && wtx.GetDepthInMainChain() >= nMinDepth) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
BOOST_FOREACH(const PAIRTYPE(CTxDestination, int64)& r, listReceived) |
|
|
|
Object entry; |
|
|
|
{ |
|
|
|
//entry.push_back(Pair("account", account));
|
|
|
|
string account; |
|
|
|
//entry.push_back(Pair("address", CBitcoinAddress(r.first).ToString()));
|
|
|
|
if (pwalletMain->mapAddressBook.count(r.first)) |
|
|
|
if (fLong) |
|
|
|
account = pwalletMain->mapAddressBook[r.first]; |
|
|
|
WalletTxToJSON(wtx, entry); |
|
|
|
if (fAllAccounts || (account == strAccount)) |
|
|
|
ret.push_back(entry); |
|
|
|
{ |
|
|
|
|
|
|
|
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))); |
|
|
|
|
|
|
|
if (fLong) |
|
|
|
|
|
|
|
WalletTxToJSON(wtx, entry); |
|
|
|
|
|
|
|
ret.push_back(entry); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -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) |
|
|
|
for (map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it) |
|
|
|
{ |
|
|
|
{ |
|
|
|
const CWalletTx& wtx = (*it).second; |
|
|
|
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) |
|
|
|
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) |
|
|
|
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid or non-wallet transaction id"); |
|
|
|
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid or non-wallet transaction id"); |
|
|
|
const CWalletTx& wtx = pwalletMain->mapWallet[hash]; |
|
|
|
const CWalletTx& wtx = pwalletMain->mapWallet[hash]; |
|
|
|
|
|
|
|
|
|
|
|
int64 nCredit = wtx.GetCredit(); |
|
|
|
//entry.push_back(Pair("amount", ValueFromAmount(nNet - nFee)));
|
|
|
|
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))); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
WalletTxToJSON(wtx, entry); |
|
|
|
WalletTxToJSON(wtx, entry); |
|
|
|
|
|
|
|
|
|
|
|