@@ -1594,14 +1594,15 @@ bool CWallet::ImportScriptPubKeys(const std::string& label, const std::set<CScri
15941594 return true ;
15951595}
15961596
1597- int64_t CalculateMaximumSignedTxSize (const CTransaction &tx, const CWallet *wallet, bool use_max_sig)
1597+ // Returns pair of vsize and weight
1598+ std::pair<int64_t , int64_t > CalculateMaximumSignedTxSize (const CTransaction &tx, const CWallet *wallet, bool use_max_sig)
15981599{
15991600 std::vector<CTxOut> txouts;
16001601 for (const CTxIn& input : tx.vin ) {
16011602 const auto mi = wallet->mapWallet .find (input.prevout .hash );
16021603 // Can not estimate size without knowing the input details
16031604 if (mi == wallet->mapWallet .end ()) {
1604- return - 1 ;
1605+ return std::make_pair (- 1 , - 1 ) ;
16051606 }
16061607 assert (input.prevout .n < mi->second .tx ->vout .size ());
16071608 txouts.emplace_back (mi->second .tx ->vout [input.prevout .n ]);
@@ -1610,13 +1611,16 @@ int64_t CalculateMaximumSignedTxSize(const CTransaction &tx, const CWallet *wall
16101611}
16111612
16121613// txouts needs to be in the order of tx.vin
1613- int64_t CalculateMaximumSignedTxSize (const CTransaction &tx, const CWallet *wallet, const std::vector<CTxOut>& txouts, bool use_max_sig)
1614+ std::pair< int64_t , int64_t > CalculateMaximumSignedTxSize (const CTransaction &tx, const CWallet *wallet, const std::vector<CTxOut>& txouts, bool use_max_sig)
16141615{
16151616 CMutableTransaction txNew (tx);
16161617 if (!wallet->DummySignTx (txNew, txouts, use_max_sig)) {
1617- return - 1 ;
1618+ return std::make_pair (- 1 , - 1 ) ;
16181619 }
1619- return GetVirtualTransactionSize (CTransaction (txNew));
1620+ CTransaction ctx (txNew);
1621+ int64_t vsize = GetVirtualTransactionSize (ctx);
1622+ int64_t weight = GetTransactionWeight (ctx);
1623+ return std::make_pair (vsize, weight);
16201624}
16211625
16221626int CalculateMaximumSignedInputSize (const CTxOut& txout, const CWallet* wallet, bool use_max_sig)
@@ -2770,6 +2774,7 @@ bool CWallet::CreateTransactionInternal(
27702774 CMutableTransaction txNew;
27712775 FeeCalculation feeCalc;
27722776 CAmount nFeeNeeded;
2777+ std::pair<int64_t , int64_t > tx_sizes;
27732778 int nBytes;
27742779 {
27752780 std::set<CInputCoin> setCoins;
@@ -2952,7 +2957,8 @@ bool CWallet::CreateTransactionInternal(
29522957 txNew.vin .push_back (CTxIn (coin.outpoint ,CScript ()));
29532958 }
29542959
2955- nBytes = CalculateMaximumSignedTxSize (CTransaction (txNew), this , coin_control.fAllowWatchOnly );
2960+ tx_sizes = CalculateMaximumSignedTxSize (CTransaction (txNew), this , coin_control.fAllowWatchOnly );
2961+ nBytes = tx_sizes.first ;
29562962 if (nBytes < 0 ) {
29572963 error = _ (" Signing transaction failed" );
29582964 return false ;
0 commit comments