diff --git a/src/wallet/spend.cpp b/src/wallet/spend.cpp index c287f8dec9..b2cc5c68ef 100644 --- a/src/wallet/spend.cpp +++ b/src/wallet/spend.cpp @@ -1480,7 +1480,7 @@ util::Result FundTransaction(CWallet& wallet, const CM preset_txin.SetScriptWitness(txin.scriptWitness); } - CAmount nGasFee = wallet.GetTxGasFee(tx); + CAmount nGasFee = wallet.GetTxGasFee(vecSend); auto res = CreateTransaction(wallet, vecSend, change_pos, coinControl, false, nGasFee); if (!res) { return res; diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index f4aa2b90d4..00b238b9be 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -5666,4 +5666,15 @@ CAmount CWallet::GetTxGasFee(const CMutableTransaction& tx) } return 0; } + +CAmount CWallet::GetTxGasFee(const std::vector& vecSend) +{ + CMutableTransaction txNew; + for (const auto& recipient : vecSend) + { + CTxOut txout(recipient.nAmount, GetScriptForDestination(recipient.dest)); + txNew.vout.push_back(txout); + } + return GetTxGasFee(txNew); +} } // namespace wallet diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index 2906fee47f..a3d7ba47b6 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -770,6 +770,7 @@ class CWallet final : public WalletStorage, public interfaces::Chain::Notificati EXCLUSIVE_LOCKS_REQUIRED(cs_wallet); CAmount GetTxGasFee(const CMutableTransaction& tx); + CAmount GetTxGasFee(const std::vector& vecSend); bool ImportScripts(const std::set scripts, int64_t timestamp) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet); bool ImportPrivKeys(const std::map& privkey_map, const int64_t timestamp) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);