diff options
author | João Barbosa <joao.paulo.barbosa@gmail.com> | 2018-02-02 01:57:29 +0000 |
---|---|---|
committer | João Barbosa <joao.paulo.barbosa@gmail.com> | 2018-02-02 01:58:24 +0000 |
commit | c409b1adac59329b78b8c48f131f8ca032988412 (patch) | |
tree | c971a045e0c28a2e62d04576f358550666d0fe6a /src/wallet/rpcwallet.cpp | |
parent | 41363fe11df529556c2d44132caa86fe8b08cbbf (diff) |
[rpc] Reduce scope of cs_main and cs_wallet locks in listtransactions
Diffstat (limited to 'src/wallet/rpcwallet.cpp')
-rw-r--r-- | src/wallet/rpcwallet.cpp | 29 |
1 files changed, 16 insertions, 13 deletions
diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 9364d18d30..33790d3490 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -1794,8 +1794,6 @@ UniValue listtransactions(const JSONRPCRequest& request) // the user could have gotten from another RPC command prior to now pwallet->BlockUntilSyncedToCurrentChain(); - LOCK2(cs_main, pwallet->cs_wallet); - std::string strAccount = "*"; if (!request.params[0].isNull()) strAccount = request.params[0].get_str(); @@ -1817,20 +1815,25 @@ UniValue listtransactions(const JSONRPCRequest& request) UniValue ret(UniValue::VARR); - const CWallet::TxItems & txOrdered = pwallet->wtxOrdered; - - // iterate backwards until we have nCount items to return: - for (CWallet::TxItems::const_reverse_iterator it = txOrdered.rbegin(); it != txOrdered.rend(); ++it) { - CWalletTx *const pwtx = (*it).second.first; - if (pwtx != nullptr) - ListTransactions(pwallet, *pwtx, strAccount, 0, true, ret, filter); - CAccountingEntry *const pacentry = (*it).second.second; - if (pacentry != nullptr) - AcentryToJSON(*pacentry, strAccount, ret); + LOCK2(cs_main, pwallet->cs_wallet); + + const CWallet::TxItems & txOrdered = pwallet->wtxOrdered; - if ((int)ret.size() >= (nCount+nFrom)) break; + // iterate backwards until we have nCount items to return: + for (CWallet::TxItems::const_reverse_iterator it = txOrdered.rbegin(); it != txOrdered.rend(); ++it) + { + CWalletTx *const pwtx = (*it).second.first; + if (pwtx != nullptr) + ListTransactions(pwallet, *pwtx, strAccount, 0, true, ret, filter); + CAccountingEntry *const pacentry = (*it).second.second; + if (pacentry != nullptr) + AcentryToJSON(*pacentry, strAccount, ret); + + if ((int)ret.size() >= (nCount+nFrom)) break; + } } + // ret is newest to oldest if (nFrom > (int)ret.size()) |