Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/rpcwallet.cpp
Show First 20 Lines • Show All 869 Lines • ▼ Show 20 Lines | static UniValue getbalance(const Config &config, | ||||
if (request.params[0].get_str() == "*") { | if (request.params[0].get_str() == "*") { | ||||
// Calculate total balance in a very different way from GetBalance(). | // Calculate total balance in a very different way from GetBalance(). | ||||
// The biggest difference is that GetBalance() sums up all unspent | // The biggest difference is that GetBalance() sums up all unspent | ||||
// TxOuts paying to the wallet, while this sums up both spent and | // TxOuts paying to the wallet, while this sums up both spent and | ||||
// unspent TxOuts paying to the wallet, and then subtracts the values of | // unspent TxOuts paying to the wallet, and then subtracts the values of | ||||
// TxIns spending from the wallet. This also has fewer restrictions on | // TxIns spending from the wallet. This also has fewer restrictions on | ||||
// which unconfirmed transactions are considered trusted. | // which unconfirmed transactions are considered trusted. | ||||
CAmount nBalance = 0; | Amount nBalance = 0; | ||||
for (std::map<uint256, CWalletTx>::iterator it = | for (std::map<uint256, CWalletTx>::iterator it = | ||||
pwalletMain->mapWallet.begin(); | pwalletMain->mapWallet.begin(); | ||||
it != pwalletMain->mapWallet.end(); ++it) { | it != pwalletMain->mapWallet.end(); ++it) { | ||||
const CWalletTx &wtx = (*it).second; | const CWalletTx &wtx = (*it).second; | ||||
CValidationState state; | CValidationState state; | ||||
if (!ContextualCheckTransactionForCurrentBlock( | if (!ContextualCheckTransactionForCurrentBlock( | ||||
config, wtx, state, | config, wtx, state, | ||||
config.GetChainParams().GetConsensus()) || | config.GetChainParams().GetConsensus()) || | ||||
wtx.GetBlocksToMaturity() > 0 || | wtx.GetBlocksToMaturity() > 0 || | ||||
wtx.GetDepthInMainChain() < 0) { | wtx.GetDepthInMainChain() < 0) { | ||||
continue; | continue; | ||||
} | } | ||||
CAmount allFee; | Amount allFee; | ||||
std::string strSentAccount; | std::string strSentAccount; | ||||
std::list<COutputEntry> listReceived; | std::list<COutputEntry> listReceived; | ||||
std::list<COutputEntry> listSent; | std::list<COutputEntry> listSent; | ||||
wtx.GetAmounts(listReceived, listSent, allFee, strSentAccount, | wtx.GetAmounts(listReceived, listSent, allFee, strSentAccount, | ||||
filter); | filter); | ||||
if (wtx.GetDepthInMainChain() >= nMinDepth) { | if (wtx.GetDepthInMainChain() >= nMinDepth) { | ||||
for (const COutputEntry &r : listReceived) { | for (const COutputEntry &r : listReceived) { | ||||
nBalance += r.amount; | nBalance += r.amount; | ||||
▲ Show 20 Lines • Show All 689 Lines • ▼ Show 20 Lines | static void MaybePushAddress(UniValue &entry, const CTxDestination &dest) { | ||||
if (IsValidDestination(dest)) { | if (IsValidDestination(dest)) { | ||||
entry.push_back(Pair("address", EncodeDestination(dest))); | entry.push_back(Pair("address", EncodeDestination(dest))); | ||||
} | } | ||||
} | } | ||||
void ListTransactions(const CWalletTx &wtx, const std::string &strAccount, | void ListTransactions(const CWalletTx &wtx, const std::string &strAccount, | ||||
int nMinDepth, bool fLong, UniValue &ret, | int nMinDepth, bool fLong, UniValue &ret, | ||||
const isminefilter &filter) { | const isminefilter &filter) { | ||||
CAmount nFee; | Amount nFee; | ||||
std::string strSentAccount; | std::string strSentAccount; | ||||
std::list<COutputEntry> listReceived; | std::list<COutputEntry> listReceived; | ||||
std::list<COutputEntry> listSent; | std::list<COutputEntry> listSent; | ||||
wtx.GetAmounts(listReceived, listSent, nFee, strSentAccount, filter); | wtx.GetAmounts(listReceived, listSent, nFee, strSentAccount, filter); | ||||
bool fAllAccounts = (strAccount == std::string("*")); | bool fAllAccounts = (strAccount == std::string("*")); | ||||
bool involvesWatchonly = wtx.IsFromMe(ISMINE_WATCH_ONLY); | bool involvesWatchonly = wtx.IsFromMe(ISMINE_WATCH_ONLY); | ||||
// Sent | // Sent | ||||
if ((!listSent.empty() || nFee != 0) && | if ((!listSent.empty() || nFee != Amount(0)) && | ||||
(fAllAccounts || strAccount == strSentAccount)) { | (fAllAccounts || strAccount == strSentAccount)) { | ||||
for (const COutputEntry &s : listSent) { | for (const COutputEntry &s : listSent) { | ||||
UniValue entry(UniValue::VOBJ); | UniValue entry(UniValue::VOBJ); | ||||
if (involvesWatchonly || | if (involvesWatchonly || | ||||
(::IsMine(*pwalletMain, s.destination) & ISMINE_WATCH_ONLY)) { | (::IsMine(*pwalletMain, s.destination) & ISMINE_WATCH_ONLY)) { | ||||
entry.push_back(Pair("involvesWatchonly", true)); | entry.push_back(Pair("involvesWatchonly", true)); | ||||
} | } | ||||
entry.push_back(Pair("account", strSentAccount)); | entry.push_back(Pair("account", strSentAccount)); | ||||
MaybePushAddress(entry, s.destination); | MaybePushAddress(entry, s.destination); | ||||
entry.push_back(Pair("category", "send")); | entry.push_back(Pair("category", "send")); | ||||
entry.push_back(Pair("amount", ValueFromAmount(-s.amount))); | entry.push_back(Pair("amount", ValueFromAmount(-s.amount))); | ||||
if (pwalletMain->mapAddressBook.count(s.destination)) { | if (pwalletMain->mapAddressBook.count(s.destination)) { | ||||
entry.push_back(Pair( | entry.push_back(Pair( | ||||
"label", pwalletMain->mapAddressBook[s.destination].name)); | "label", pwalletMain->mapAddressBook[s.destination].name)); | ||||
} | } | ||||
entry.push_back(Pair("vout", s.vout)); | entry.push_back(Pair("vout", s.vout)); | ||||
entry.push_back(Pair("fee", ValueFromAmount(-nFee))); | entry.push_back(Pair("fee", ValueFromAmount(-1 * nFee))); | ||||
if (fLong) { | if (fLong) { | ||||
WalletTxToJSON(wtx, entry); | WalletTxToJSON(wtx, entry); | ||||
} | } | ||||
entry.push_back(Pair("abandoned", wtx.isAbandoned())); | entry.push_back(Pair("abandoned", wtx.isAbandoned())); | ||||
ret.push_back(entry); | ret.push_back(entry); | ||||
} | } | ||||
} | } | ||||
▲ Show 20 Lines • Show All 296 Lines • ▼ Show 20 Lines | for (const std::pair<CTxDestination, CAddressBookData> &entry : | ||||
mapAccountBalances[entry.second.name] = 0; | mapAccountBalances[entry.second.name] = 0; | ||||
} | } | ||||
} | } | ||||
for (std::map<uint256, CWalletTx>::iterator it = | for (std::map<uint256, CWalletTx>::iterator it = | ||||
pwalletMain->mapWallet.begin(); | pwalletMain->mapWallet.begin(); | ||||
it != pwalletMain->mapWallet.end(); ++it) { | it != pwalletMain->mapWallet.end(); ++it) { | ||||
const CWalletTx &wtx = (*it).second; | const CWalletTx &wtx = (*it).second; | ||||
CAmount nFee; | Amount nFee; | ||||
std::string strSentAccount; | std::string strSentAccount; | ||||
std::list<COutputEntry> listReceived; | std::list<COutputEntry> listReceived; | ||||
std::list<COutputEntry> listSent; | std::list<COutputEntry> listSent; | ||||
int nDepth = wtx.GetDepthInMainChain(); | int nDepth = wtx.GetDepthInMainChain(); | ||||
if (wtx.GetBlocksToMaturity() > 0 || nDepth < 0) { | if (wtx.GetBlocksToMaturity() > 0 || nDepth < 0) { | ||||
continue; | continue; | ||||
} | } | ||||
wtx.GetAmounts(listReceived, listSent, nFee, strSentAccount, | wtx.GetAmounts(listReceived, listSent, nFee, strSentAccount, | ||||
includeWatchonly); | includeWatchonly); | ||||
mapAccountBalances[strSentAccount] -= nFee; | mapAccountBalances[strSentAccount] -= nFee.GetSatoshis(); | ||||
for (const COutputEntry &s : listSent) { | for (const COutputEntry &s : listSent) { | ||||
mapAccountBalances[strSentAccount] -= s.amount; | mapAccountBalances[strSentAccount] -= s.amount; | ||||
} | } | ||||
if (nDepth >= nMinDepth) { | if (nDepth >= nMinDepth) { | ||||
for (const COutputEntry &r : listReceived) { | for (const COutputEntry &r : listReceived) { | ||||
if (pwalletMain->mapAddressBook.count(r.destination)) { | if (pwalletMain->mapAddressBook.count(r.destination)) { | ||||
mapAccountBalances | mapAccountBalances | ||||
[pwalletMain->mapAddressBook[r.destination].name] += | [pwalletMain->mapAddressBook[r.destination].name] += | ||||
▲ Show 20 Lines • Show All 1,431 Lines • Show Last 20 Lines |