Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/rpcwallet.cpp
Show First 20 Lines • Show All 127 Lines • ▼ Show 20 Lines | static void WalletTxToJSON(const CWalletTx &wtx, UniValue &entry) { | ||||
UniValue conflicts(UniValue::VARR); | UniValue conflicts(UniValue::VARR); | ||||
for (const uint256 &conflict : wtx.GetConflicts()) { | for (const uint256 &conflict : wtx.GetConflicts()) { | ||||
conflicts.push_back(conflict.GetHex()); | conflicts.push_back(conflict.GetHex()); | ||||
} | } | ||||
entry.pushKV("walletconflicts", conflicts); | entry.pushKV("walletconflicts", conflicts); | ||||
entry.pushKV("time", wtx.GetTxTime()); | entry.pushKV("time", wtx.GetTxTime()); | ||||
entry.pushKV("timereceived", (int64_t)wtx.nTimeReceived); | entry.pushKV("timereceived", (int64_t)wtx.nTimeReceived); | ||||
for (const std::pair<std::string, std::string> &item : wtx.mapValue) { | for (const std::pair<const std::string, std::string> &item : wtx.mapValue) { | ||||
entry.pushKV(item.first, item.second); | entry.pushKV(item.first, item.second); | ||||
} | } | ||||
} | } | ||||
static std::string LabelFromValue(const UniValue &value) { | static std::string LabelFromValue(const UniValue &value) { | ||||
std::string label = value.get_str(); | std::string label = value.get_str(); | ||||
if (label == "*") { | if (label == "*") { | ||||
throw JSONRPCError(RPC_WALLET_INVALID_LABEL_NAME, "Invalid label name"); | throw JSONRPCError(RPC_WALLET_INVALID_LABEL_NAME, "Invalid label name"); | ||||
▲ Show 20 Lines • Show All 294 Lines • ▼ Show 20 Lines | static UniValue getaddressesbyaccount(const Config &config, | ||||
} | } | ||||
LOCK2(cs_main, pwallet->cs_wallet); | LOCK2(cs_main, pwallet->cs_wallet); | ||||
std::string strAccount = LabelFromValue(request.params[0]); | std::string strAccount = LabelFromValue(request.params[0]); | ||||
// Find all addresses that have the given account | // Find all addresses that have the given account | ||||
UniValue ret(UniValue::VARR); | UniValue ret(UniValue::VARR); | ||||
for (const std::pair<CTxDestination, CAddressBookData> &item : | for (const std::pair<const CTxDestination, CAddressBookData> &item : | ||||
pwallet->mapAddressBook) { | pwallet->mapAddressBook) { | ||||
const CTxDestination &dest = item.first; | const CTxDestination &dest = item.first; | ||||
const std::string &strName = item.second.name; | const std::string &strName = item.second.name; | ||||
if (strName == strAccount) { | if (strName == strAccount) { | ||||
ret.push_back(EncodeDestination(dest, config)); | ret.push_back(EncodeDestination(dest, config)); | ||||
} | } | ||||
} | } | ||||
▲ Show 20 Lines • Show All 343 Lines • ▼ Show 20 Lines | static UniValue getreceivedbyaddress(const Config &config, | ||||
// Minimum confirmations | // Minimum confirmations | ||||
int nMinDepth = 1; | int nMinDepth = 1; | ||||
if (!request.params[1].isNull()) { | if (!request.params[1].isNull()) { | ||||
nMinDepth = request.params[1].get_int(); | nMinDepth = request.params[1].get_int(); | ||||
} | } | ||||
// Tally | // Tally | ||||
Amount nAmount = Amount::zero(); | Amount nAmount = Amount::zero(); | ||||
for (const std::pair<uint256, CWalletTx> &pairWtx : pwallet->mapWallet) { | for (const std::pair<const uint256, CWalletTx> &pairWtx : | ||||
pwallet->mapWallet) { | |||||
const CWalletTx &wtx = pairWtx.second; | const CWalletTx &wtx = pairWtx.second; | ||||
CValidationState state; | CValidationState state; | ||||
if (wtx.IsCoinBase() || !ContextualCheckTransactionForCurrentBlock( | if (wtx.IsCoinBase() || !ContextualCheckTransactionForCurrentBlock( | ||||
config, *wtx.tx, state)) { | config, *wtx.tx, state)) { | ||||
continue; | continue; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 57 Lines • ▼ Show 20 Lines | static UniValue getreceivedbylabel(const Config &config, | ||||
} | } | ||||
// Get the set of pub keys assigned to label | // Get the set of pub keys assigned to label | ||||
std::string label = LabelFromValue(request.params[0]); | std::string label = LabelFromValue(request.params[0]); | ||||
std::set<CTxDestination> setAddress = pwallet->GetLabelAddresses(label); | std::set<CTxDestination> setAddress = pwallet->GetLabelAddresses(label); | ||||
// Tally | // Tally | ||||
Amount nAmount = Amount::zero(); | Amount nAmount = Amount::zero(); | ||||
for (const std::pair<uint256, CWalletTx> &pairWtx : pwallet->mapWallet) { | for (const std::pair<const uint256, CWalletTx> &pairWtx : | ||||
pwallet->mapWallet) { | |||||
const CWalletTx &wtx = pairWtx.second; | const CWalletTx &wtx = pairWtx.second; | ||||
CValidationState state; | CValidationState state; | ||||
if (wtx.IsCoinBase() || !ContextualCheckTransactionForCurrentBlock( | if (wtx.IsCoinBase() || !ContextualCheckTransactionForCurrentBlock( | ||||
config, *wtx.tx, state)) { | config, *wtx.tx, state)) { | ||||
continue; | continue; | ||||
} | } | ||||
for (const CTxOut &txout : wtx.tx->vout) { | for (const CTxOut &txout : wtx.tx->vout) { | ||||
▲ Show 20 Lines • Show All 628 Lines • ▼ Show 20 Lines | if (!by_label && params.size() > 3) { | ||||
} | } | ||||
filtered_address = | filtered_address = | ||||
DecodeDestination(params[3].get_str(), config.GetChainParams()); | DecodeDestination(params[3].get_str(), config.GetChainParams()); | ||||
has_filtered_address = true; | has_filtered_address = true; | ||||
} | } | ||||
// Tally | // Tally | ||||
std::map<CTxDestination, tallyitem> mapTally; | std::map<CTxDestination, tallyitem> mapTally; | ||||
for (const std::pair<uint256, CWalletTx> &pairWtx : pwallet->mapWallet) { | for (const std::pair<const uint256, CWalletTx> &pairWtx : | ||||
pwallet->mapWallet) { | |||||
const CWalletTx &wtx = pairWtx.second; | const CWalletTx &wtx = pairWtx.second; | ||||
CValidationState state; | CValidationState state; | ||||
if (wtx.IsCoinBase() || !ContextualCheckTransactionForCurrentBlock( | if (wtx.IsCoinBase() || !ContextualCheckTransactionForCurrentBlock( | ||||
config, *wtx.tx, state)) { | config, *wtx.tx, state)) { | ||||
continue; | continue; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 577 Lines • ▼ Show 20 Lines | static UniValue listaccounts(const Config &config, | ||||
} | } | ||||
isminefilter includeWatchonly = ISMINE_SPENDABLE; | isminefilter includeWatchonly = ISMINE_SPENDABLE; | ||||
if (request.params.size() > 1 && request.params[1].get_bool()) { | if (request.params.size() > 1 && request.params[1].get_bool()) { | ||||
includeWatchonly = includeWatchonly | ISMINE_WATCH_ONLY; | includeWatchonly = includeWatchonly | ISMINE_WATCH_ONLY; | ||||
} | } | ||||
std::map<std::string, Amount> mapAccountBalances; | std::map<std::string, Amount> mapAccountBalances; | ||||
for (const std::pair<CTxDestination, CAddressBookData> &entry : | for (const std::pair<const CTxDestination, CAddressBookData> &entry : | ||||
pwallet->mapAddressBook) { | pwallet->mapAddressBook) { | ||||
// This address belongs to me | // This address belongs to me | ||||
if (IsMine(*pwallet, entry.first) & includeWatchonly) { | if (IsMine(*pwallet, entry.first) & includeWatchonly) { | ||||
mapAccountBalances[entry.second.name] = Amount::zero(); | mapAccountBalances[entry.second.name] = Amount::zero(); | ||||
} | } | ||||
} | } | ||||
for (const std::pair<uint256, CWalletTx> &pairWtx : pwallet->mapWallet) { | for (const std::pair<const uint256, CWalletTx> &pairWtx : | ||||
pwallet->mapWallet) { | |||||
const CWalletTx &wtx = pairWtx.second; | const CWalletTx &wtx = pairWtx.second; | ||||
Amount 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.IsImmatureCoinBase() || nDepth < 0) { | if (wtx.IsImmatureCoinBase() || nDepth < 0) { | ||||
continue; | continue; | ||||
Show All 17 Lines | static UniValue listaccounts(const Config &config, | ||||
} | } | ||||
const std::list<CAccountingEntry> &acentries = pwallet->laccentries; | const std::list<CAccountingEntry> &acentries = pwallet->laccentries; | ||||
for (const CAccountingEntry &entry : acentries) { | for (const CAccountingEntry &entry : acentries) { | ||||
mapAccountBalances[entry.strAccount] += entry.nCreditDebit; | mapAccountBalances[entry.strAccount] += entry.nCreditDebit; | ||||
} | } | ||||
UniValue ret(UniValue::VOBJ); | UniValue ret(UniValue::VOBJ); | ||||
for (const std::pair<std::string, Amount> &accountBalance : | for (const std::pair<const std::string, Amount> &accountBalance : | ||||
mapAccountBalances) { | mapAccountBalances) { | ||||
ret.pushKV(accountBalance.first, | ret.pushKV(accountBalance.first, | ||||
ValueFromAmount(accountBalance.second)); | ValueFromAmount(accountBalance.second)); | ||||
} | } | ||||
return ret; | return ret; | ||||
} | } | ||||
static UniValue listsinceblock(const Config &config, | static UniValue listsinceblock(const Config &config, | ||||
▲ Show 20 Lines • Show All 153 Lines • ▼ Show 20 Lines | static UniValue listsinceblock(const Config &config, | ||||
bool include_removed = | bool include_removed = | ||||
(request.params[3].isNull() || request.params[3].get_bool()); | (request.params[3].isNull() || request.params[3].get_bool()); | ||||
int depth = pindex ? (1 + chainActive.Height() - pindex->nHeight) : -1; | int depth = pindex ? (1 + chainActive.Height() - pindex->nHeight) : -1; | ||||
UniValue transactions(UniValue::VARR); | UniValue transactions(UniValue::VARR); | ||||
for (const std::pair<uint256, CWalletTx> &pairWtx : pwallet->mapWallet) { | for (const std::pair<const uint256, CWalletTx> &pairWtx : | ||||
pwallet->mapWallet) { | |||||
CWalletTx tx = pairWtx.second; | CWalletTx tx = pairWtx.second; | ||||
if (depth == -1 || tx.GetDepthInMainChain() < depth) { | if (depth == -1 || tx.GetDepthInMainChain() < depth) { | ||||
ListTransactions(pwallet, tx, "*", 0, true, transactions, filter); | ListTransactions(pwallet, tx, "*", 0, true, transactions, filter); | ||||
} | } | ||||
} | } | ||||
// when a reorg'd block is requested, we also list any relevant transactions | // when a reorg'd block is requested, we also list any relevant transactions | ||||
▲ Show 20 Lines • Show All 2,022 Lines • Show Last 20 Lines |