MCPcopy Create free account
hub / github.com/ElementsProject/elements / SetupDescriptorGeneration

Method SetupDescriptorGeneration

src/wallet/scriptpubkeyman.cpp:1941–2010  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1939}
1940
1941bool DescriptorScriptPubKeyMan::SetupDescriptorGeneration(const CExtKey& master_key, OutputType addr_type, bool internal)
1942{
1943 LOCK(cs_desc_man);
1944 assert(m_storage.IsWalletFlagSet(WALLET_FLAG_DESCRIPTORS));
1945
1946 // Ignore when there is already a descriptor
1947 if (m_wallet_descriptor.descriptor) {
1948 return false;
1949 }
1950
1951 int64_t creation_time = GetTime();
1952
1953 std::string xpub = EncodeExtPubKey(master_key.Neuter());
1954
1955 // Build descriptor string
1956 std::string desc_prefix;
1957 std::string desc_suffix = "/*)";
1958 switch (addr_type) {
1959 case OutputType::LEGACY: {
1960 desc_prefix = "pkh(" + xpub + "/44'";
1961 break;
1962 }
1963 case OutputType::P2SH_SEGWIT: {
1964 desc_prefix = "sh(wpkh(" + xpub + "/49'";
1965 desc_suffix += ")";
1966 break;
1967 }
1968 case OutputType::BECH32: {
1969 desc_prefix = "wpkh(" + xpub + "/84'";
1970 break;
1971 }
1972 case OutputType::BECH32M: {
1973 desc_prefix = "tr(" + xpub + "/86'";
1974 break;
1975 }
1976 } // no default case, so the compiler can warn about missing cases
1977 assert(!desc_prefix.empty());
1978
1979 // Mainnet derives at 0', testnet and regtest derive at 1'
1980 if (Params().IsTestChain()) {
1981 desc_prefix += "/1'";
1982 } else {
1983 desc_prefix += "/0'";
1984 }
1985
1986 std::string internal_path = internal ? "/1" : "/0";
1987 std::string desc_str = desc_prefix + "/0'" + internal_path + desc_suffix;
1988
1989 // Make the descriptor
1990 FlatSigningProvider keys;
1991 std::string error;
1992 std::unique_ptr<Descriptor> desc = Parse(desc_str, keys, error, false);
1993 WalletDescriptor w_desc(std::move(desc), creation_time, 0, 0, 0);
1994 m_wallet_descriptor = w_desc;
1995
1996 // Store the master private key, and descriptor
1997 WalletBatch batch(m_storage.GetDatabase());
1998 if (!AddDescriptorKeyWithDB(batch, master_key.key, master_key.key.GetPubKey())) {

Callers 1

Calls 11

GetTimeFunction · 0.85
EncodeExtPubKeyFunction · 0.85
ParseFunction · 0.85
IsWalletFlagSetMethod · 0.80
NeuterMethod · 0.80
IsTestChainMethod · 0.80
UnsetBlankWalletFlagMethod · 0.80
ParamsClass · 0.50
emptyMethod · 0.45
GetPubKeyMethod · 0.45
WriteDescriptorMethod · 0.45

Tested by

no test coverage detected