6 #include <chainparams.h> 22 #include <util/time.h> 24 #include <validation.h> 45 void initialize_spkm()
47 static const auto testing_setup{MakeNoLogFileContext<const TestingSetup>()};
57 if (!desc_str.has_value())
return std::nullopt;
62 std::vector<std::unique_ptr<Descriptor>> parsed_descs =
Parse(desc_str.value(), keys, error,
false);
63 if (parsed_descs.empty())
return std::nullopt;
65 WalletDescriptor w_desc{std::move(parsed_descs.at(0)), 0, 0, 1, 1};
66 return std::make_pair(w_desc, keys);
71 LOCK(keystore.cs_wallet);
72 auto spk_manager_res = keystore.AddWalletDescriptor(wallet_desc, keys,
"",
false);
73 if (!spk_manager_res)
return nullptr;
74 return &spk_manager_res.value().get();
85 CWallet&
wallet{*wallet_ptr};
89 wallet.SetLastBlockProcessed(chainstate.m_chain.Height(), chainstate.m_chain.Tip()->GetBlockHash());
94 if (!wallet_desc.has_value())
return;
96 if (spk_manager ==
nullptr)
return;
100 if (!wallet_desc.has_value()) {
104 if (spk_manager->CanUpdateToWalletDescriptor(wallet_desc->first, error)) {
106 if (new_spk_manager !=
nullptr) spk_manager = new_spk_manager;
110 bool good_data{
true};
116 if (spk_manager->IsMine(
script)) {
117 assert(spk_manager->GetScriptPubKeys().contains(
script));
121 auto spks{spk_manager->GetScriptPubKeys()};
122 for (
const CScript& spk : spks) {
123 assert(spk_manager->IsMine(spk));
129 *std::get_if<PKHash>(&dest) :
132 (void)spk_manager->SignMessage(
msg, pk_hash, str_sig);
133 (void)spk_manager->GetMetadata(dest);
138 auto spks{spk_manager->GetScriptPubKeys()};
141 (void)spk_manager->MarkUnusedAddresses(spk);
145 LOCK(spk_manager->cs_desc_man);
146 auto wallet_desc{spk_manager->GetWalletDescriptor()};
147 if (wallet_desc.descriptor->IsSingleType()) {
148 auto output_type{wallet_desc.descriptor->GetOutputType()};
149 if (output_type.has_value()) {
150 auto dest{spk_manager->GetNewDestination(*output_type)};
153 assert(spk_manager->IsHDEnabled());
169 std::map<int, bilingual_str> input_errors;
170 (void)spk_manager->SignTransaction(tx_to, coins, sighash, input_errors);
173 std::optional<PartiallySignedTransaction> opt_psbt{ConsumeDeserializable<PartiallySignedTransaction>(
fuzzed_data_provider)};
178 auto psbt{*opt_psbt};
181 if (sighash_type == 151) sighash_type = std::nullopt;
185 (void)spk_manager->FillPSBT(psbt, txdata, sighash_type,
sign, bip32derivs,
nullptr, finalize);
190 std::string descriptor;
192 (void)spk_manager->GetEndRange();
193 (void)spk_manager->GetKeyPoolSize();
static UniValue Parse(std::string_view raw, ParamFormat format=ParamFormat::JSON)
Parse string to UniValue or throw runtime_error if string contains invalid JSON.
bool IsTooExpensive(std::span< const uint8_t > buffer)
Deriving "expensive" descriptors will consume useful fuzz compute. The compute is better spent on a s...
constexpr auto MakeUCharSpan(const V &v) -> decltype(UCharSpanCast(std::span
Like the std::span constructor, but for (const) unsigned char member types only.
bool IsValidDestination(const CTxDestination &dest)
Check whether a CTxDestination corresponds to one with an address.
FUZZ_TARGET(coin_grinder)
std::map< COutPoint, Coin > ConsumeCoins(FuzzedDataProvider &fuzzed_data_provider) noexcept
CScript ConsumeScript(FuzzedDataProvider &fuzzed_data_provider, const bool maybe_p2wsh) noexcept
#define LIMITED_WHILE(condition, limit)
Can be used to limit a theoretically unbounded loop.
const TestingSetup * g_setup
Chainstate stores and provides an API to update our local knowledge of the current best chain...
bool ExtractDestination(const CScript &scriptPubKey, CTxDestination &addressRet)
Parse a scriptPubKey for the destination.
wallet::DescriptorScriptPubKeyMan * CreateDescriptor(CWallet &keystore, const std::string &desc_str, const bool success)
std::string ConsumeRandomLengthString(size_t max_length)
Indicate that this wallet supports DescriptorScriptPubKeyMan.
void Init()
When initializing the target, populate the list of keys.
is a home for public enum and struct type definitions that are used by internally by wallet code...
NodeSeconds ConsumeTime(FuzzedDataProvider &fuzzed_data_provider, const std::optional< int64_t > &min, const std::optional< int64_t > &max) noexcept
std::optional< std::string > GetDescriptor(std::string_view mocked_desc) const
Get an actual descriptor string from a descriptor string whose keys were mocked.
static int sign(const secp256k1_context *ctx, struct signer_secrets *signer_secrets, struct signer *signer, const secp256k1_musig_keyagg_cache *cache, const unsigned char *msg32, unsigned char *sig64)
void SeedRandomStateForTest(SeedRand seedtype)
Seed the global RNG state for testing and log the seed value.
std::unique_ptr< WalletDatabase > CreateMockableWalletDatabase(MockableData records)
Converts a mocked descriptor string to a valid one.
Serialized script, used inside transaction inputs and outputs.
FuzzedDataProvider & fuzzed_data_provider
std::variant< CNoDestination, PubKeyDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessV1Taproot, PayToAnchor, WitnessUnknown > CTxDestination
A txout script categorized into standard templates.
void SetMockTime(int64_t nMockTimeIn)
DEPRECATED Use SetMockTime with chrono type.
A mutable version of CTransaction.
size_t CallOneOf(FuzzedDataProvider &fuzzed_data_provider, Callables... callables)
auto & PickValue(FuzzedDataProvider &fuzzed_data_provider, Collection &col)
MockedDescriptorConverter MOCKED_DESC_CONVERTER
The converter of mocked descriptors, needs to be initialized when the target is.
uint160 ConsumeUInt160(FuzzedDataProvider &fuzzed_data_provider) noexcept
T ConsumeIntegralInRange(T min, T max)
Seed with a compile time constant of zeros.
Testing setup that configures a complete environment.
void SelectParams(const ChainType chain)
Sets the params returned by Params() to those for the given chain type.
static constexpr TransactionSerParams TX_WITH_WITNESS
PrecomputedTransactionData PrecomputePSBTData(const PartiallySignedTransaction &psbt)
Compute a PrecomputedTransactionData object from a psbt.