30 wallet->SetupDescriptorScriptPubKeyMans();
36 auto& desc = descs.at(0);
38 Assert(
wallet->AddWalletDescriptor(w_desc, provider,
"",
false));
53 std::vector<bilingual_str> _warnings;
69 std::vector<bilingual_str> warnings;
78 std::vector<bilingual_str> warnings;
93 std::vector<bilingual_str> warnings;
101 wallet->chain().waitForNotificationsIfTipChanged({});
102 wallet->m_chain_notifications_handler.reset();
108 return std::make_unique<MockableDatabase>(
dynamic_cast<MockableDatabase&
>(database).m_records);
138 const auto& [key_data, value_data] = *
m_cursor;
140 value.
write(value_data);
151 const auto& it =
m_records.find(key_data);
156 value.
write(it->second);
167 auto [it, inserted] =
m_records.emplace(key_data, value_data);
168 if (!inserted && overwrite) {
169 it->second = value_data;
201 auto& key = it->first;
202 if (key.size() <
prefix.size() || std::search(key.begin(), key.end(),
prefix.begin(),
prefix.end()) != key.begin()) {
213 return std::make_unique<MockableDatabase>(records);
227 auto parsed_descs =
Parse(desc_str, keys, error,
false);
228 Assert(success == (!parsed_descs.empty()));
229 if (!success)
return nullptr;
230 auto& desc = parsed_descs.at(0);
232 const int64_t range_start = 0, range_end = 1, next_index = 0, timestamp = 1;
234 WalletDescriptor w_desc(std::move(desc), timestamp, range_start, range_end, next_index);
238 return &spkm.value().get();
void write(std::span< const value_type > src)
static UniValue Parse(std::string_view raw, ParamFormat format=ParamFormat::JSON)
Parse string to UniValue or throw runtime_error if string contains invalid JSON.
Status Next(DataStream &key, DataStream &value) override
static std::shared_ptr< CWallet > LoadExisting(WalletContext &context, const std::string &name, std::unique_ptr< WalletDatabase > database, bilingual_str &error, std::vector< bilingual_str > &warnings)
An in-memory indexed chain of blocks.
std::map< SerializeData, SerializeData, std::less<> > MockableData
int Height() const
Return the maximal height in the chain.
RecursiveMutex cs_wallet
Main wallet lock.
MockableCursor(const MockableData &records, bool pass)
CBlockIndex * Genesis() const
Returns the index entry for the genesis block of this chain, or nullptr if none.
MockableData::const_iterator m_cursor
RAII object to check and reserve a wallet rescan.
std::shared_ptr< CWallet > TestLoadWallet(std::unique_ptr< WalletDatabase > database, WalletContext &context)
bool reserve(bool with_passphrase=false)
CTxDestination getNewDestination(CWallet &w, OutputType output_type)
Returns a new destination, of an specific type, from the wallet.
std::unique_ptr< WalletDatabase > DuplicateMockDatabase(WalletDatabase &database)
MockableData::const_iterator m_cursor_end
uint256 GetBlockHash() const
void WaitForDeleteWallet(std::shared_ptr< CWallet > &&wallet)
Explicitly delete the wallet.
std::shared_ptr< CWallet > TestCreateWallet(std::unique_ptr< WalletDatabase > database, WalletContext &context, uint64_t create_flags)
wallet::DescriptorScriptPubKeyMan * CreateDescriptor(CWallet &keystore, const std::string &desc_str, const bool success)
Double ended buffer combining vector and stream-like interfaces.
std::vector< std::byte, zero_after_free_allocator< std::byte > > SerializeData
Byte-vector that clears its contents before deletion.
util::Result< std::reference_wrapper< DescriptorScriptPubKeyMan > > AddWalletDescriptor(WalletDescriptor &desc, const FlatSigningProvider &signing_provider, const std::string &label, bool internal) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Add a descriptor to the wallet, return a ScriptPubKeyMan & associated output type.
bool EraseKey(DataStream &&key) override
void NotifyWalletLoaded(WalletContext &context, const std::shared_ptr< CWallet > &wallet)
static std::shared_ptr< CWallet > CreateNew(WalletContext &context, const std::string &name, std::unique_ptr< WalletDatabase > database, uint64_t wallet_creation_flags, bilingual_str &error, std::vector< bilingual_str > &warnings)
Indicate that this wallet supports DescriptorScriptPubKeyMan.
A CWallet maintains a set of transactions and balances, and provides the ability to create new transa...
MockableDatabase & GetMockableDatabase(CWallet &wallet)
Descriptor with some wallet metadata.
bool WriteKey(DataStream &&key, DataStream &&value, bool overwrite=true) override
std::unique_ptr< CWallet > CreateSyncedWallet(interfaces::Chain &chain, CChain &cchain, const CKey &key)
std::unique_ptr< WalletDatabase > CreateMockableWalletDatabase(MockableData records)
A WalletDatabase whose contents and return values can be modified as needed for testing.
Interface giving clients (wallet processes, maybe other analysis tools in the future) ability to acce...
void TestUnloadWallet(std::shared_ptr< CWallet > &&wallet)
bool ReadKey(DataStream &&key, DataStream &value) override
std::variant< CNoDestination, PubKeyDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessV1Taproot, PayToAnchor, WitnessUnknown > CTxDestination
A txout script categorized into standard templates.
CBlockIndex * Tip() const
Returns the index entry for the tip of this chain, or nullptr if none.
WalletContext struct containing references to state shared between CWallet instances, like the reference to the chain interface, and the list of opened wallets.
interfaces::Chain * chain
std::string EncodeDestination(const CTxDestination &dest)
An encapsulated private key.
bool HasKey(DataStream &&key) override
RPCHelpMan getnewaddress()
std::string EncodeSecret(const CKey &key)
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate...
util::Result< CTxDestination > GetNewDestination(OutputType type, const std::string &label)
bool ErasePrefix(std::span< const std::byte > prefix) override
An instance of this class represents one database.
std::unique_ptr< WalletDatabase > MakeWalletDatabase(const std::string &name, const DatabaseOptions &options, DatabaseStatus &status, bilingual_str &error_string)
#define Assert(val)
Identity function.