MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / ExportDescriptors

Function ExportDescriptors

src/wallet/export.cpp:17–43  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

15
16namespace wallet {
17util::Expected<std::vector<WalletDescInfo>, std::string> ExportDescriptors(const CWallet& wallet, bool export_private)
18{
19 AssertLockHeld(wallet.cs_wallet);
20 std::vector<WalletDescInfo> wallet_descriptors;
21 for (const auto& spk_man : wallet.GetAllScriptPubKeyMans()) {
22 const auto desc_spk_man = dynamic_cast<DescriptorScriptPubKeyMan*>(spk_man);
23 if (!desc_spk_man) {
24 return util::Unexpected{"Unexpected ScriptPubKey manager type."};
25 }
26 LOCK(desc_spk_man->cs_desc_man);
27 const auto& wallet_descriptor = desc_spk_man->GetWalletDescriptor();
28 std::string descriptor;
29 if (!Assume(desc_spk_man->GetDescriptorString(descriptor, export_private))) {
30 return util::Unexpected{"Can't get descriptor string."};
31 }
32 const bool is_range = wallet_descriptor.descriptor->IsRange();
33 wallet_descriptors.emplace_back(
34 descriptor,
35 wallet_descriptor.creation_time,
36 wallet.IsActiveScriptPubKeyMan(*desc_spk_man),
37 wallet.IsInternalScriptPubKeyMan(desc_spk_man),
38 is_range ? std::optional(std::make_pair(wallet_descriptor.range_start, wallet_descriptor.range_end)) : std::nullopt,
39 wallet_descriptor.next_index
40 );
41 }
42 return wallet_descriptors;
43}
44
45util::Result<std::string> ExportWatchOnlyWallet(const CWallet& wallet, const fs::path& destination, WalletContext& context)
46{

Callers 2

ExportWatchOnlyWalletFunction · 0.85
listdescriptorsFunction · 0.85

Calls 7

GetWalletDescriptorMethod · 0.80
GetDescriptorStringMethod · 0.80
IsRangeMethod · 0.45
emplace_backMethod · 0.45

Tested by

no test coverage detected