From 692de95bb7e1cfdc03c96b2118cc028254c8a2ac Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Wed, 21 Nov 2018 18:20:31 +0800 Subject: [PATCH] unlock locked utxo before fetching unspents, then relock them. --- src/wallet/rpcwallet.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index b075c22d3..00222f116 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -1058,6 +1058,11 @@ UniValue cleanwallettransactions(const UniValue& params, bool fHelp) } else { + // get all locked utxos to relock them later. + vector vLockedUTXO; + pwalletMain->ListLockedCoins(vLockedUTXO); + // unlock all coins so that the following call containes all utxos. + pwalletMain->UnlockAllCoins(); // listunspent call... this gets us all the txids that are unspent, we search this list for the oldest tx, vector vecOutputs; assert(pwalletMain != NULL); @@ -1068,7 +1073,11 @@ UniValue cleanwallettransactions(const UniValue& params, bool fHelp) if ( out.nDepth > oldestTxDepth ) oldestTxDepth = out.nDepth; } - oldestTxDepth = oldestTxDepth + 1; // add extra 10 blocks just for safety. + oldestTxDepth = oldestTxDepth + 1; // add extra block just for safety. + // lock all the previouly locked coins. + BOOST_FOREACH(COutPoint &outpt, vOutpts) { + pwalletMain->LockCoin(outpt); + } // then add all txs in the wallet before this block to the list to remove. for (map::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it)