@@ -117,8 +117,9 @@ static std::optional<int64_t> GetSignedTxinWeight(const CWallet* wallet, const C
117117 const bool can_grind_r)
118118{
119119 // If weight was provided, use that.
120- if (coin_control && coin_control->HasInputWeight (txin.prevout )) {
121- return coin_control->GetInputWeight (txin.prevout );
120+ std::optional<int64_t > weight;
121+ if (coin_control && (weight = coin_control->GetInputWeight (txin.prevout ))) {
122+ return weight.value ();
122123 }
123124
124125 // Otherwise, use the maximum satisfaction size provided by the descriptor.
@@ -261,15 +262,20 @@ util::Result<PreSelectedInputs> FetchSelectedInputs(const CWallet& wallet, const
261262 const bool can_grind_r = wallet.CanGrindR ();
262263 std::map<COutPoint, CAmount> map_of_bump_fees = wallet.chain ().calculateIndividualBumpFees (coin_control.ListSelected (), coin_selection_params.m_effective_feerate );
263264 for (const COutPoint& outpoint : coin_control.ListSelected ()) {
264- int input_bytes = -1 ;
265+ int64_t input_bytes = coin_control.GetInputWeight (outpoint).value_or (-1 );
266+ if (input_bytes != -1 ) {
267+ input_bytes = GetVirtualTransactionSize (input_bytes, 0 , 0 );
268+ }
265269 CTxOut txout;
266270 if (auto ptr_wtx = wallet.GetWalletTx (outpoint.hash )) {
267271 // Clearly invalid input, fail
268272 if (ptr_wtx->tx ->vout .size () <= outpoint.n ) {
269273 return util::Error{strprintf (_ (" Invalid pre-selected input %s" ), outpoint.ToString ())};
270274 }
271275 txout = ptr_wtx->tx ->vout .at (outpoint.n );
272- input_bytes = CalculateMaximumSignedInputSize (txout, &wallet, &coin_control);
276+ if (input_bytes == -1 ) {
277+ input_bytes = CalculateMaximumSignedInputSize (txout, &wallet, &coin_control);
278+ }
273279 } else {
274280 // The input is external. We did not find the tx in mapWallet.
275281 const auto out{coin_control.GetExternalOutput (outpoint)};
@@ -284,11 +290,6 @@ util::Result<PreSelectedInputs> FetchSelectedInputs(const CWallet& wallet, const
284290 input_bytes = CalculateMaximumSignedInputSize (txout, outpoint, &coin_control.m_external_provider , can_grind_r, &coin_control);
285291 }
286292
287- // If available, override calculated size with coin control specified size
288- if (coin_control.HasInputWeight (outpoint)) {
289- input_bytes = GetVirtualTransactionSize (coin_control.GetInputWeight (outpoint), 0 , 0 );
290- }
291-
292293 if (input_bytes == -1 ) {
293294 return util::Error{strprintf (_ (" Not solvable pre-selected input %s" ), outpoint.ToString ())}; // Not solvable, can't estimate size for fee
294295 }
0 commit comments