@@ -729,10 +729,21 @@ bool CWallet::CreateTransactionInternal(
729
729
assert (nChangePosInOut != -1 );
730
730
auto change_position = txNew.vout .insert (txNew.vout .begin () + nChangePosInOut, newTxOut);
731
731
732
- // Dummy fill vin for maximum size estimation
732
+ // Shuffle selected coins and fill in final vin
733
+ std::vector<CInputCoin> selected_coins (setCoins.begin (), setCoins.end ());
734
+ Shuffle (selected_coins.begin (), selected_coins.end (), FastRandomContext ());
735
+
736
+ // Note how the sequence number is set to non-maxint so that
737
+ // the nLockTime set above actually works.
733
738
//
734
- for (const auto & coin : setCoins) {
735
- txNew.vin .push_back (CTxIn (coin.outpoint ,CScript ()));
739
+ // BIP125 defines opt-in RBF as any nSequence < maxint-1, so
740
+ // we use the highest possible value in that range (maxint-2)
741
+ // to avoid conflicting with other possible uses of nSequence,
742
+ // and in the spirit of "smallest possible change from prior
743
+ // behavior."
744
+ const uint32_t nSequence = coin_control.m_signal_bip125_rbf .value_or (m_signal_rbf) ? MAX_BIP125_RBF_SEQUENCE : (CTxIn::SEQUENCE_FINAL - 1 );
745
+ for (const auto & coin : selected_coins) {
746
+ txNew.vin .push_back (CTxIn (coin.outpoint , CScript (), nSequence));
736
747
}
737
748
738
749
// Calculate the transaction fee
@@ -813,24 +824,6 @@ bool CWallet::CreateTransactionInternal(
813
824
return false ;
814
825
}
815
826
816
- // Shuffle selected coins and fill in final vin
817
- txNew.vin .clear ();
818
- std::vector<CInputCoin> selected_coins (setCoins.begin (), setCoins.end ());
819
- Shuffle (selected_coins.begin (), selected_coins.end (), FastRandomContext ());
820
-
821
- // Note how the sequence number is set to non-maxint so that
822
- // the nLockTime set above actually works.
823
- //
824
- // BIP125 defines opt-in RBF as any nSequence < maxint-1, so
825
- // we use the highest possible value in that range (maxint-2)
826
- // to avoid conflicting with other possible uses of nSequence,
827
- // and in the spirit of "smallest possible change from prior
828
- // behavior."
829
- const uint32_t nSequence = coin_control.m_signal_bip125_rbf .value_or (m_signal_rbf) ? MAX_BIP125_RBF_SEQUENCE : (CTxIn::SEQUENCE_FINAL - 1 );
830
- for (const auto & coin : selected_coins) {
831
- txNew.vin .push_back (CTxIn (coin.outpoint , CScript (), nSequence));
832
- }
833
-
834
827
if (sign && !SignTransaction (txNew)) {
835
828
error = _ (" Signing transaction failed" );
836
829
return false ;
0 commit comments