5#ifndef BITCOIN_TEST_FUZZ_UTIL_WALLET_H
6#define BITCOIN_TEST_FUZZ_UTIL_WALLET_H
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}) {
49 const auto descriptor{(
strprintf)(desc_fmt,
"[5aa9973a/66h/4h/2h]" + seed_insecure,
int{internal})};
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; });
bool ExtractDestination(const CScript &scriptPubKey, CTxDestination &addressRet)
Parse a scriptPubKey for the destination.
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a Bitcoin scriptPubKey for the given CTxDestination.
std::variant< CNoDestination, PubKeyDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessV1Taproot, PayToAnchor, WitnessUnknown > CTxDestination
A txout script categorized into standard templates.
int64_t CAmount
Amount in satoshis (Can be negative)
#define Assert(val)
Identity function.
Fee rate in satoshis per kilovirtualbyte: CAmount / kvB.
Serialized script, used inside transaction inputs and outputs.
The basic transaction that is broadcasted on the network and contained in blocks.
An output of a transaction.
T ConsumeIntegralInRange(T min, T max)
T PickValueInArray(const T(&array)[size])
Interface giving clients (wallet processes, maybe other analysis tools in the future) ability to acce...
virtual std::optional< int > getHeight()=0
Get current chain height, not including genesis block (returns 0 if chain only contains genesis block...
virtual uint256 getBlockHash(int height)=0
Get block hash. Height must be valid or this function will abort.
std::optional< bool > m_signal_bip125_rbf
Override the wallet's m_signal_rbf if set.
std::optional< OutputType > m_change_type
Override the default change type if set, ignored if destChange is set.
bool m_allow_other_inputs
If true, the selection process can add extra unselected inputs from the wallet while requires all sel...
bool fOverrideFeeRate
Override automatic min/max checks on fee, m_feerate must be set if true.
std::optional< CFeeRate > m_feerate
Override the wallet's m_pay_tx_fee if set.
bool m_include_unsafe_inputs
If false, only safe inputs will be used.
bool fAllowWatchOnly
Includes watch only addresses which are solvable.
CTxDestination destChange
Custom change destination, if not set an address is generated.
Descriptor with some wallet metadata.
static UniValue Parse(std::string_view raw)
Parse string to UniValue or throw runtime_error if string contains invalid JSON.
CreatedTransactionResult FundTransaction(CWallet &wallet, const CMutableTransaction &tx, const std::vector< CRecipient > &recipients, const UniValue &options, CCoinControl &coinControl, bool override_min_fee)
CFeeRate GetMinimumFeeRate(const CWallet &wallet, const CCoinControl &coin_control, FeeCalculation *feeCalc)
Estimate the minimum fee rate considering user set parameters and the required fee.
std::unique_ptr< WalletDatabase > CreateMockableWalletDatabase(MockableData records)
@ WALLET_FLAG_DESCRIPTORS
Indicate that this wallet supports DescriptorScriptPubKeyMan.
static constexpr auto OUTPUT_TYPES
int64_t GetVirtualTransactionSize(int64_t nWeight, int64_t nSigOpCost, unsigned int bytes_per_sigop)
Compute the virtual transaction size (weight reinterpreted as bytes).
A mutable version of CTransaction.
std::vector< CTxOut > vout
std::map< CKeyID, CKey > keys
Wraps a descriptor wallet for fuzzing.
void FundTx(FuzzedDataProvider &fuzzed_data_provider, CMutableTransaction tx)
FuzzedWallet(interfaces::Chain &chain, const std::string &name, const std::string &seed_insecure)
void ImportDescriptors(const std::string &seed_insecure)
CScript GetScriptPubKey(FuzzedDataProvider &fuzzed_data_provider)
CTxDestination GetDestination(FuzzedDataProvider &fuzzed_data_provider)
std::shared_ptr< CWallet > wallet
size_t CallOneOf(FuzzedDataProvider &fuzzed_data_provider, Callables... callables)