@@ -914,19 +914,15 @@ CWalletTx* CWallet::AddToWallet(CTransactionRef tx, const CWalletTx::Confirmatio
914914 CWalletTx& wtx = (*ret.first ).second ;
915915 bool fInsertedNew = ret.second ;
916916 bool fUpdated = update_wtx && update_wtx (wtx, fInsertedNew );
917+ std::set<COutPoint> candidates;
917918 if (fInsertedNew ) {
918919 wtx.m_confirm = confirm;
919920 wtx.nTimeReceived = GetTime ();
920921 wtx.nOrderPos = IncOrderPosNext (&batch);
921922 wtx.m_it_wtxOrdered = wtxOrdered.insert (std::make_pair (wtx.nOrderPos , &wtx));
922923 wtx.nTimeSmart = ComputeTimeSmart (wtx);
923924 AddToSpends (hash, &batch);
924-
925- // TODO: refactor duplicated code between CWallet::AddToWallet and CWallet::AutoLockMasternodeCollaterals
926- auto candidates{AddWalletUTXOs (wtx.tx , /* ret_dups=*/ true )};
927- for (const auto & utxo : ListProTxCoins (candidates)) {
928- LockCoin (utxo, &batch);
929- }
925+ candidates = AddWalletUTXOs (wtx.tx , /* ret_dups=*/ true );
930926 }
931927
932928 if (!fInsertedNew )
@@ -942,15 +938,12 @@ CWalletTx* CWallet::AddToWallet(CTransactionRef tx, const CWalletTx::Confirmatio
942938 assert (wtx.m_confirm .hashBlock == confirm.hashBlock );
943939 assert (wtx.m_confirm .block_height == confirm.block_height );
944940 }
945-
946- // TODO: refactor duplicated code with case fInstertedNew
947- auto candidates{AddWalletUTXOs (wtx.tx , /* ret_dups=*/ false )};
941+ candidates = AddWalletUTXOs (wtx.tx , /* ret_dups=*/ false );
948942 if (!candidates.empty ()) fUpdated = true ;
949- for (const auto & utxo : ListProTxCoins (candidates)) {
950- LockCoin (utxo, &batch);
951- }
952943 }
953944
945+ LockProTxCoins (candidates, &batch);
946+
954947 // // debug print
955948 WalletLogPrintf (" AddToWallet %s %s%s\n " , hash.ToString (), (fInsertedNew ? " new" : " " ), (fUpdated ? " update" : " " ));
956949
@@ -4058,9 +4051,7 @@ void CWallet::AutoLockMasternodeCollaterals()
40584051 candidates.insert (tx_utxos.begin (), tx_utxos.end ());
40594052 }
40604053 WalletBatch batch (GetDatabase ());
4061- for (const auto & utxo : ListProTxCoins (candidates)) {
4062- LockCoin (utxo, &batch);
4063- }
4054+ LockProTxCoins (candidates, &batch);
40644055}
40654056
40664057DBErrors CWallet::ZapSelectTx (std::vector<uint256>& vHashIn, std::vector<uint256>& vHashOut)
@@ -4516,6 +4507,14 @@ std::vector<COutPoint> CWallet::ListProTxCoins(const std::set<COutPoint>& utxos)
45164507 return m_chain->listMNCollaterials (candidates);
45174508}
45184509
4510+ void CWallet::LockProTxCoins (const std::set<COutPoint>& utxos, WalletBatch* batch)
4511+ {
4512+ AssertLockHeld (cs_wallet);
4513+ for (const auto & utxo : ListProTxCoins (utxos)) {
4514+ LockCoin (utxo, batch);
4515+ }
4516+ }
4517+
45194518/* * @} */ // end of Actions
45204519
45214520void CWallet::GetKeyBirthTimes (std::map<CKeyID, int64_t >& mapKeyBirth) const {
0 commit comments