diff --git a/src/interfaces/wallet.cpp b/src/interfaces/wallet.cpp --- a/src/interfaces/wallet.cpp +++ b/src/interfaces/wallet.cpp @@ -28,8 +28,7 @@ class PendingWalletTxImpl : public PendingWalletTx { public: - explicit PendingWalletTxImpl(CWallet &wallet) - : m_wallet(wallet), m_dest(&wallet) {} + explicit PendingWalletTxImpl(CWallet &wallet) : m_wallet(wallet) {} const CTransaction &get() override { return *m_tx; } @@ -39,8 +38,7 @@ LOCK(m_wallet.cs_wallet); CValidationState state; if (!m_wallet.CommitTransaction(m_tx, std::move(value_map), - std::move(order_form), m_dest, - state)) { + std::move(order_form), state)) { reject_reason = state.GetRejectReason(); return false; } @@ -49,7 +47,6 @@ CTransactionRef m_tx; CWallet &m_wallet; - ReserveDestination m_dest; }; //! Construct wallet tx struct. @@ -247,9 +244,9 @@ auto locked_chain = m_wallet->chain().lock(); LOCK(m_wallet->cs_wallet); auto pending = std::make_unique(*m_wallet); - if (!m_wallet->CreateTransaction( - *locked_chain, recipients, pending->m_tx, pending->m_dest, - fee, change_pos, fail_reason, coin_control, sign)) { + if (!m_wallet->CreateTransaction(*locked_chain, recipients, + pending->m_tx, fee, change_pos, + fail_reason, coin_control, sign)) { return {}; } return pending; diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -355,7 +355,6 @@ CScript scriptPubKey = GetScriptForDestination(address); // Create and send the transaction - ReserveDestination reservedest(pwallet); Amount nFeeRequired; std::string strError; std::vector vecSend; @@ -365,9 +364,8 @@ CCoinControl coinControl; CTransactionRef tx; - if (!pwallet->CreateTransaction(locked_chain, vecSend, tx, reservedest, - nFeeRequired, nChangePosRet, strError, - coinControl)) { + if (!pwallet->CreateTransaction(locked_chain, vecSend, tx, nFeeRequired, + nChangePosRet, strError, coinControl)) { if (!fSubtractFeeFromAmount && nValue + nFeeRequired > curBalance) { strError = strprintf("Error: This transaction requires a " "transaction fee of at least %s", @@ -377,7 +375,7 @@ } CValidationState state; if (!pwallet->CommitTransaction(tx, std::move(mapValue), {} /* orderForm */, - reservedest, state)) { + state)) { strError = strprintf("Error: The transaction was rejected! Reason given: %s", FormatStateMessage(state)); @@ -1053,21 +1051,20 @@ std::shuffle(vecSend.begin(), vecSend.end(), FastRandomContext()); // Send - ReserveDestination changedest(pwallet); Amount nFeeRequired = Amount::zero(); int nChangePosRet = -1; std::string strFailReason; CTransactionRef tx; CCoinControl coinControl; - bool fCreated = pwallet->CreateTransaction( - *locked_chain, vecSend, tx, changedest, nFeeRequired, nChangePosRet, - strFailReason, coinControl); + bool fCreated = + pwallet->CreateTransaction(*locked_chain, vecSend, tx, nFeeRequired, + nChangePosRet, strFailReason, coinControl); if (!fCreated) { throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, strFailReason); } CValidationState state; if (!pwallet->CommitTransaction(tx, std::move(mapValue), {} /* orderForm */, - changedest, state)) { + state)) { strFailReason = strprintf("Transaction commit failed:: %s", FormatStateMessage(state)); throw JSONRPCError(RPC_WALLET_ERROR, strFailReason); diff --git a/src/wallet/test/wallet_tests.cpp b/src/wallet/test/wallet_tests.cpp --- a/src/wallet/test/wallet_tests.cpp +++ b/src/wallet/test/wallet_tests.cpp @@ -392,19 +392,17 @@ CWalletTx &AddTx(CRecipient recipient) { CTransactionRef tx; - ReserveDestination reservedest(wallet.get()); Amount fee; int changePos = -1; std::string error; CCoinControl dummy; { auto locked_chain = m_chain->lock(); - BOOST_CHECK(wallet->CreateTransaction(*locked_chain, {recipient}, - tx, reservedest, fee, - changePos, error, dummy)); + BOOST_CHECK(wallet->CreateTransaction( + *locked_chain, {recipient}, tx, fee, changePos, error, dummy)); } CValidationState state; - BOOST_CHECK(wallet->CommitTransaction(tx, {}, {}, reservedest, state)); + BOOST_CHECK(wallet->CommitTransaction(tx, {}, {}, state)); CMutableTransaction blocktx; { LOCK(wallet->cs_wallet); diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -278,8 +278,8 @@ /** * A wrapper to reserve an address from a wallet * - * ReserveDestination is used to reserve an address. It is passed around - * during the CreateTransaction/CommitTransaction procedure. + * ReserveDestination is used to reserve an address. + * It is currently only used inside of CreateTransaction. * * Instantiating a ReserveDestination does not reserve an address. To do so, * GetReservedDestination() needs to be called on the object. Once an address @@ -1299,14 +1299,13 @@ */ bool CreateTransaction(interfaces::Chain::Lock &locked_chain, const std::vector &vecSend, - CTransactionRef &tx, ReserveDestination &reservedest, - Amount &nFeeRet, int &nChangePosInOut, - std::string &strFailReason, + CTransactionRef &tx, Amount &nFeeRet, + int &nChangePosInOut, std::string &strFailReason, const CCoinControl &coin_control, bool sign = true); bool CommitTransaction( CTransactionRef tx, mapValue_t mapValue, std::vector> orderForm, - ReserveDestination &reservedest, CValidationState &state); + CValidationState &state); bool DummySignTx(CMutableTransaction &txNew, const std::set &txouts, bool use_max_sig = false) const { diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -3154,9 +3154,8 @@ auto locked_chain = chain().lock(); LOCK(cs_wallet); - ReserveDestination reservedest(this); CTransactionRef tx_new; - if (!CreateTransaction(*locked_chain, vecSend, tx_new, reservedest, nFeeRet, + if (!CreateTransaction(*locked_chain, vecSend, tx_new, nFeeRet, nChangePosInOut, strFailReason, coinControl, false)) { return false; @@ -3272,12 +3271,12 @@ bool CWallet::CreateTransaction(interfaces::Chain::Lock &locked_chainIn, const std::vector &vecSend, - CTransactionRef &tx, - ReserveDestination &reservedest, - Amount &nFeeRet, int &nChangePosInOut, + CTransactionRef &tx, Amount &nFeeRet, + int &nChangePosInOut, std::string &strFailReason, const CCoinControl &coinControl, bool sign) { Amount nValue = Amount::zero(); + ReserveDestination reservedest(this); int nChangePosRequest = nChangePosInOut; unsigned int nSubtractFeeFromAmount = 0; for (const auto &recipient : vecSend) { @@ -3660,7 +3659,7 @@ bool CWallet::CommitTransaction( CTransactionRef tx, mapValue_t mapValue, std::vector> orderForm, - ReserveDestination &reservedest, CValidationState &state) { + CValidationState &state) { auto locked_chain = chain().lock(); LOCK(cs_wallet); @@ -3673,9 +3672,6 @@ WalletLogPrintfToBeContinued("CommitTransaction:\n%s", wtxNew.tx->ToString()); - // Take key pair from key pool so it won't be used again. - reservedest.KeepDestination(); - // Add tx to wallet, because if it has change it's also ours, otherwise just // for transaction history. AddToWallet(wtxNew);