@@ -2609,17 +2609,17 @@ bool CWallet::FundTransaction(CMutableTransaction& tx, CAmount& nFeeRet, int& nC
26092609 auto locked_chain = chain ().lock ();
26102610 LOCK (cs_wallet);
26112611
2612- CReserveKey reservekey (this );
2612+ ReserveDestination reservedest (this );
26132613 CTransactionRef tx_new;
2614- if (!CreateTransaction (*locked_chain, vecSend, tx_new, reservekey , nFeeRet, nChangePosInOut, strFailReason, coinControl, false )) {
2614+ if (!CreateTransaction (*locked_chain, vecSend, tx_new, reservedest , nFeeRet, nChangePosInOut, strFailReason, coinControl, false )) {
26152615 return false ;
26162616 }
26172617
26182618 if (nChangePosInOut != -1 ) {
26192619 tx.vout .insert (tx.vout .begin () + nChangePosInOut, tx_new->vout [nChangePosInOut]);
26202620 // We don't have the normal Create/Commit cycle, and don't want to risk
26212621 // reusing change, so just remove the key from the keypool here.
2622- reservekey. KeepKey ();
2622+ reservedest. KeepDestination ();
26232623 }
26242624
26252625 // Copy output sizes from new transaction; they may have had the fee
@@ -2730,7 +2730,7 @@ OutputType CWallet::TransactionChangeType(OutputType change_type, const std::vec
27302730 return m_default_address_type;
27312731}
27322732
2733- bool CWallet::CreateTransaction (interfaces::Chain::Lock& locked_chain, const std::vector<CRecipient>& vecSend, CTransactionRef& tx, CReserveKey& reservekey , CAmount& nFeeRet,
2733+ bool CWallet::CreateTransaction (interfaces::Chain::Lock& locked_chain, const std::vector<CRecipient>& vecSend, CTransactionRef& tx, ReserveDestination& reservedest , CAmount& nFeeRet,
27342734 int & nChangePosInOut, std::string& strFailReason, const CCoinControl& coin_control, bool sign)
27352735{
27362736 CAmount nValue = 0 ;
@@ -2771,7 +2771,7 @@ bool CWallet::CreateTransaction(interfaces::Chain::Lock& locked_chain, const std
27712771 CoinSelectionParams coin_selection_params; // Parameters for coin selection, init with dummy
27722772
27732773 // Create change script that will be used if we need change
2774- // TODO: pass in scriptChange instead of reservekey so
2774+ // TODO: pass in scriptChange instead of reservedest so
27752775 // change transaction isn't always pay-to-bitcoin-address
27762776 CScript scriptChange;
27772777
@@ -2791,19 +2791,16 @@ bool CWallet::CreateTransaction(interfaces::Chain::Lock& locked_chain, const std
27912791 strFailReason = _ (" Can't generate a change-address key. No keys in the internal keypool and can't generate any keys." );
27922792 return false ;
27932793 }
2794- CPubKey vchPubKey ;
2795- bool ret ;
2796- ret = reservekey. GetReservedKey (vchPubKey , true );
2794+ CTxDestination dest ;
2795+ const OutputType change_type = TransactionChangeType (coin_control. m_change_type ? *coin_control. m_change_type : m_default_change_type, vecSend) ;
2796+ bool ret = reservedest. GetReservedDestination (change_type, dest , true );
27972797 if (!ret)
27982798 {
2799- strFailReason = _ ( " Keypool ran out, please call keypoolrefill first" ) ;
2799+ strFailReason = " Keypool ran out, please call keypoolrefill first" ;
28002800 return false ;
28012801 }
28022802
2803- const OutputType change_type = TransactionChangeType (coin_control.m_change_type ? *coin_control.m_change_type : m_default_change_type, vecSend);
2804-
2805- LearnRelatedScripts (vchPubKey, change_type);
2806- scriptChange = GetScriptForDestination (GetDestinationForKey (vchPubKey, change_type));
2803+ scriptChange = GetScriptForDestination (dest);
28072804 }
28082805 CTxOut change_prototype_txout (0 , scriptChange);
28092806 coin_selection_params.change_output_size = GetSerializeSize (change_prototype_txout);
@@ -3024,7 +3021,7 @@ bool CWallet::CreateTransaction(interfaces::Chain::Lock& locked_chain, const std
30243021 }
30253022 }
30263023
3027- if (nChangePosInOut == -1 ) reservekey. ReturnKey (); // Return any reserved key if we don't have change
3024+ if (nChangePosInOut == -1 ) reservedest. ReturnDestination (); // Return any reserved address if we don't have change
30283025
30293026 // Shuffle selected coins and fill in final vin
30303027 txNew.vin .clear ();
@@ -3097,7 +3094,7 @@ bool CWallet::CreateTransaction(interfaces::Chain::Lock& locked_chain, const std
30973094/* *
30983095 * Call after CreateTransaction unless you want to abort
30993096 */
3100- bool CWallet::CommitTransaction (CTransactionRef tx, mapValue_t mapValue, std::vector<std::pair<std::string, std::string>> orderForm, CReserveKey& reservekey , CValidationState& state)
3097+ bool CWallet::CommitTransaction (CTransactionRef tx, mapValue_t mapValue, std::vector<std::pair<std::string, std::string>> orderForm, ReserveDestination& reservedest , CValidationState& state)
31013098{
31023099 {
31033100 auto locked_chain = chain ().lock ();
@@ -3112,7 +3109,7 @@ bool CWallet::CommitTransaction(CTransactionRef tx, mapValue_t mapValue, std::ve
31123109 WalletLogPrintf (" CommitTransaction:\n %s" , wtxNew.tx ->ToString ()); /* Continued */
31133110 {
31143111 // Take key pair from key pool so it won't be used again
3115- reservekey. KeepKey ();
3112+ reservedest. KeepDestination ();
31163113
31173114 // Add tx to wallet, because if it has change it's also ours,
31183115 // otherwise just for transaction history.
@@ -3713,7 +3710,7 @@ std::set<CTxDestination> CWallet::GetLabelAddresses(const std::string& label) co
37133710 return result;
37143711}
37153712
3716- bool CReserveKey::GetReservedKey (CPubKey& pubkey , bool internal)
3713+ bool ReserveDestination::GetReservedDestination ( const OutputType type, CTxDestination& dest , bool internal)
37173714{
37183715 if (!pwallet->CanGetAddresses (internal)) {
37193716 return false ;
@@ -3729,25 +3726,29 @@ bool CReserveKey::GetReservedKey(CPubKey& pubkey, bool internal)
37293726 fInternal = keypool.fInternal ;
37303727 }
37313728 assert (vchPubKey.IsValid ());
3732- pubkey = vchPubKey;
3729+ pwallet->LearnRelatedScripts (vchPubKey, type);
3730+ address = GetDestinationForKey (vchPubKey, type);
3731+ dest = address;
37333732 return true ;
37343733}
37353734
3736- void CReserveKey::KeepKey ()
3735+ void ReserveDestination::KeepDestination ()
37373736{
37383737 if (nIndex != -1 )
37393738 pwallet->KeepKey (nIndex);
37403739 nIndex = -1 ;
37413740 vchPubKey = CPubKey ();
3741+ address = CNoDestination ();
37423742}
37433743
3744- void CReserveKey::ReturnKey ()
3744+ void ReserveDestination::ReturnDestination ()
37453745{
37463746 if (nIndex != -1 ) {
37473747 pwallet->ReturnKey (nIndex, fInternal , vchPubKey);
37483748 }
37493749 nIndex = -1 ;
37503750 vchPubKey = CPubKey ();
3751+ address = CNoDestination ();
37513752}
37523753
37533754void CWallet::MarkReserveKeysAsUsed (int64_t keypool_id)
0 commit comments