Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/rpcwallet.cpp
Show First 20 Lines • Show All 1,688 Lines • ▼ Show 20 Lines | if (request.fHelp || request.params.size() > 4) { | ||||
} | } | ||||
.ToString()); | .ToString()); | ||||
} | } | ||||
// Make sure the results are valid at least up to the most recent block | // Make sure the results are valid at least up to the most recent block | ||||
// the user could have gotten from another RPC command prior to now | // the user could have gotten from another RPC command prior to now | ||||
pwallet->BlockUntilSyncedToCurrentChain(); | pwallet->BlockUntilSyncedToCurrentChain(); | ||||
auto locked_chain = pwallet->chain().lock(); | |||||
LOCK(pwallet->cs_wallet); | |||||
const std::string *filter_label = nullptr; | const std::string *filter_label = nullptr; | ||||
if (!request.params[0].isNull() && request.params[0].get_str() != "*") { | if (!request.params[0].isNull() && request.params[0].get_str() != "*") { | ||||
filter_label = &request.params[0].get_str(); | filter_label = &request.params[0].get_str(); | ||||
if (filter_label->empty()) { | if (filter_label->empty()) { | ||||
throw JSONRPCError( | throw JSONRPCError( | ||||
RPC_INVALID_PARAMETER, | RPC_INVALID_PARAMETER, | ||||
"Label argument must be a valid label name or \"*\"."); | "Label argument must be a valid label name or \"*\"."); | ||||
} | } | ||||
Show All 16 Lines | UniValue listtransactions(const Config &config, const JSONRPCRequest &request) { | ||||
if (nCount < 0) { | if (nCount < 0) { | ||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Negative count"); | throw JSONRPCError(RPC_INVALID_PARAMETER, "Negative count"); | ||||
} | } | ||||
if (nFrom < 0) { | if (nFrom < 0) { | ||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Negative from"); | throw JSONRPCError(RPC_INVALID_PARAMETER, "Negative from"); | ||||
} | } | ||||
UniValue ret(UniValue::VARR); | UniValue ret(UniValue::VARR); | ||||
{ | |||||
auto locked_chain = pwallet->chain().lock(); | |||||
LOCK(pwallet->cs_wallet); | |||||
const CWallet::TxItems &txOrdered = pwallet->wtxOrdered; | const CWallet::TxItems &txOrdered = pwallet->wtxOrdered; | ||||
// iterate backwards until we have nCount items to return: | // iterate backwards until we have nCount items to return: | ||||
for (CWallet::TxItems::const_reverse_iterator it = txOrdered.rbegin(); | for (CWallet::TxItems::const_reverse_iterator it = txOrdered.rbegin(); | ||||
it != txOrdered.rend(); ++it) { | it != txOrdered.rend(); ++it) { | ||||
CWalletTx *const pwtx = (*it).second; | CWalletTx *const pwtx = (*it).second; | ||||
ListTransactions(*locked_chain, pwallet, *pwtx, 0, true, ret, filter, | ListTransactions(*locked_chain, pwallet, *pwtx, 0, true, ret, | ||||
filter_label); | filter, filter_label); | ||||
if ((int)ret.size() >= (nCount + nFrom)) { | if (int(ret.size()) >= (nCount + nFrom)) { | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
} | |||||
// ret is newest to oldest | // ret is newest to oldest | ||||
if (nFrom > (int)ret.size()) { | if (nFrom > (int)ret.size()) { | ||||
nFrom = ret.size(); | nFrom = ret.size(); | ||||
} | } | ||||
if ((nFrom + nCount) > (int)ret.size()) { | if ((nFrom + nCount) > (int)ret.size()) { | ||||
nCount = ret.size() - nFrom; | nCount = ret.size() - nFrom; | ||||
▲ Show 20 Lines • Show All 3,064 Lines • Show Last 20 Lines |