5 #ifndef BITCOIN_TEST_FUZZ_UTIL_WALLET_H 6 #define BITCOIN_TEST_FUZZ_UTIL_WALLET_H 31 auto height{*
Assert(chain.getHeight())};
32 wallet->SetLastBlockProcessed(height, chain.getBlockHash(height));
34 wallet->m_keypool_size = 1;
40 const std::vector<std::string> DESCS{
47 for (
const std::string& desc_fmt : DESCS) {
48 for (
bool internal : {
true,
false}) {
53 auto parsed_desc = std::move(
Parse(descriptor, keys, error,
false).at(0));
56 assert(parsed_desc->IsRange());
57 assert(parsed_desc->IsSingleType());
62 auto spk_manager{
wallet->AddWalletDescriptor(w_desc, keys,
"",
internal)};
64 wallet->AddActiveScriptPubKeyMan(spk_manager->GetID(), *
Assert(w_desc.descriptor->GetOutputType()),
internal);
84 std::set<int> subtract_fee_from_outputs;
86 for (
size_t i{}; i < tx.
vout.size(); ++i) {
88 subtract_fee_from_outputs.insert(i);
92 std::vector<CRecipient> recipients;
93 for (
size_t idx = 0; idx < tx.
vout.size(); idx++) {
97 CRecipient recipient = {dest, tx_out.
nValue, subtract_fee_from_outputs.count(idx) == 1};
98 recipients.push_back(recipient);
111 fuzzed_data_provider, [&] { r =
true; }, [&] { r =
false; }, [&] { r = std::nullopt; });
134 #endif // BITCOIN_TEST_FUZZ_UTIL_WALLET_H
static UniValue Parse(std::string_view raw)
Parse string to UniValue or throw runtime_error if string contains invalid JSON.
Wraps a descriptor wallet for fuzzing.
FuzzedWallet(interfaces::Chain &chain, const std::string &name, const std::string &seed_insecure)
void FundTx(FuzzedDataProvider &fuzzed_data_provider, CMutableTransaction tx)
CTxDestination destChange
Custom change destination, if not set an address is generated.
void ImportDescriptors(const std::string &seed_insecure)
std::map< CKeyID, CKey > keys
bool fAllowWatchOnly
Includes watch only addresses which are solvable.
int64_t GetVirtualTransactionSize(int64_t nWeight, int64_t nSigOpCost, unsigned int bytes_per_sigop)
Compute the virtual transaction size (weight reinterpreted as bytes).
static constexpr auto OUTPUT_TYPES
std::optional< OutputType > m_change_type
Override the default change type if set, ignored if destChange is set.
int64_t CAmount
Amount in satoshis (Can be negative)
bool ExtractDestination(const CScript &scriptPubKey, CTxDestination &addressRet)
Parse a scriptPubKey for the destination.
Indicate that this wallet supports DescriptorScriptPubKeyMan.
bool fOverrideFeeRate
Override automatic min/max checks on fee, m_feerate must be set if true.
An output of a transaction.
std::vector< CTxOut > vout
Descriptor with some wallet metadata.
CFeeRate GetMinimumFeeRate(const CWallet &wallet, const CCoinControl &coin_control, FeeCalculation *feeCalc)
Estimate the minimum fee rate considering user set parameters and the required fee.
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a Bitcoin scriptPubKey for the given CTxDestination.
std::unique_ptr< WalletDatabase > CreateMockableWalletDatabase(MockableData records)
Interface giving clients (wallet processes, maybe other analysis tools in the future) ability to acce...
Serialized script, used inside transaction inputs and outputs.
CreatedTransactionResult FundTransaction(CWallet &wallet, const CMutableTransaction &tx, const std::vector< CRecipient > &recipients, const UniValue &options, CCoinControl &coinControl, bool override_min_fee)
bool m_include_unsafe_inputs
If false, only safe inputs will be used.
std::variant< CNoDestination, PubKeyDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessV1Taproot, PayToAnchor, WitnessUnknown > CTxDestination
A txout script categorized into standard templates.
bool m_allow_other_inputs
If true, the selection process can add extra unselected inputs from the wallet while requires all sel...
Fee rate in satoshis per kilovirtualbyte: CAmount / kvB.
CScript GetScriptPubKey(FuzzedDataProvider &fuzzed_data_provider)
A mutable version of CTransaction.
size_t CallOneOf(FuzzedDataProvider &fuzzed_data_provider, Callables... callables)
The basic transaction that is broadcasted on the network and contained in blocks. ...
std::shared_ptr< CWallet > wallet
T ConsumeIntegralInRange(T min, T max)
T PickValueInArray(const T(&array)[size])
std::optional< bool > m_signal_bip125_rbf
Override the wallet's m_signal_rbf if set.
std::optional< CFeeRate > m_feerate
Override the wallet's m_pay_tx_fee if set.
CTxDestination GetDestination(FuzzedDataProvider &fuzzed_data_provider)
#define Assert(val)
Identity function.