@@ -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
@@ -4059,9 +4052,7 @@ void CWallet::AutoLockMasternodeCollaterals()
40594052 candidates.insert (tx_utxos.begin (), tx_utxos.end ());
40604053 }
40614054 WalletBatch batch (GetDatabase ());
4062- for (const auto & utxo : ListProTxCoins (candidates)) {
4063- LockCoin (utxo, &batch);
4064- }
4055+ LockProTxCoins (candidates, &batch);
40654056}
40664057
40674058DBErrors CWallet::ZapSelectTx (std::vector<uint256>& vHashIn, std::vector<uint256>& vHashOut)
@@ -4521,6 +4512,14 @@ std::vector<COutPoint> CWallet::ListProTxCoins(const std::set<COutPoint>& utxos)
45214512 return m_chain->listMNCollaterials (candidates);
45224513}
45234514
4515+ void CWallet::LockProTxCoins (const std::set<COutPoint>& utxos, WalletBatch* batch)
4516+ {
4517+ AssertLockHeld (cs_wallet);
4518+ for (const auto & utxo : ListProTxCoins (utxos)) {
4519+ LockCoin (utxo, batch);
4520+ }
4521+ }
4522+
45244523/* * @} */ // end of Actions
45254524
45264525void CWallet::GetKeyBirthTimes (std::map<CKeyID, int64_t >& mapKeyBirth) const {
0 commit comments