@@ -74,59 +74,6 @@ struct FuzzedWallet {
7474 }
7575 }
7676 CScript GetScriptPubKey (FuzzedDataProvider& fuzzed_data_provider) { return GetScriptForDestination (GetDestination (fuzzed_data_provider)); }
77- void FundTx (FuzzedDataProvider& fuzzed_data_provider, CMutableTransaction tx)
78- {
79- // The fee of "tx" is 0, so this is the total input and output amount
80- const CAmount total_amt{
81- std::accumulate (tx.vout .begin (), tx.vout .end (), CAmount{}, [](CAmount t, const CTxOut& out) { return t + out.nValue ; })};
82- const uint32_t tx_size (GetVirtualTransactionSize (CTransaction{tx}));
83- std::set<int > subtract_fee_from_outputs;
84- if (fuzzed_data_provider.ConsumeBool ()) {
85- for (size_t i{}; i < tx.vout .size (); ++i) {
86- if (fuzzed_data_provider.ConsumeBool ()) {
87- subtract_fee_from_outputs.insert (i);
88- }
89- }
90- }
91- std::vector<CRecipient> recipients;
92- for (size_t idx = 0 ; idx < tx.vout .size (); idx++) {
93- const CTxOut& tx_out = tx.vout [idx];
94- CTxDestination dest;
95- ExtractDestination (tx_out.scriptPubKey , dest);
96- CRecipient recipient = {dest, tx_out.nValue , subtract_fee_from_outputs.count (idx) == 1 };
97- recipients.push_back (recipient);
98- }
99- CCoinControl coin_control;
100- coin_control.m_allow_other_inputs = fuzzed_data_provider.ConsumeBool ();
101- CallOneOf (
102- fuzzed_data_provider, [&] { coin_control.destChange = GetDestination (fuzzed_data_provider); },
103- [&] { coin_control.m_change_type .emplace (fuzzed_data_provider.PickValueInArray (OUTPUT_TYPES)); },
104- [&] { /* no op (leave uninitialized) */ });
105- coin_control.fAllowWatchOnly = fuzzed_data_provider.ConsumeBool ();
106- coin_control.m_include_unsafe_inputs = fuzzed_data_provider.ConsumeBool ();
107- {
108- auto & r{coin_control.m_signal_bip125_rbf };
109- CallOneOf (
110- fuzzed_data_provider, [&] { r = true ; }, [&] { r = false ; }, [&] { r = std::nullopt ; });
111- }
112- coin_control.m_feerate = CFeeRate{
113- // A fee of this range should cover all cases
114- fuzzed_data_provider.ConsumeIntegralInRange <CAmount>(0 , 2 * total_amt),
115- tx_size,
116- };
117- if (fuzzed_data_provider.ConsumeBool ()) {
118- *coin_control.m_feerate += GetMinimumFeeRate (*wallet, coin_control, nullptr );
119- }
120- coin_control.fOverrideFeeRate = fuzzed_data_provider.ConsumeBool ();
121- // Add solving data (m_external_provider and SelectExternal)?
122-
123- int change_position{fuzzed_data_provider.ConsumeIntegralInRange <int >(-1 , tx.vout .size () - 1 )};
124- bilingual_str error;
125- // Clear tx.vout since it is not meant to be used now that we are passing outputs directly.
126- // This sets us up for a future PR to completely remove tx from the function signature in favor of passing inputs directly
127- tx.vout .clear ();
128- (void )FundTransaction (*wallet, tx, recipients, change_position, /* lockUnspents=*/ false , coin_control);
129- }
13077};
13178}
13279
0 commit comments