From 961b9e4e40019a87eaa11c8a9c3305870f7a6d75 Mon Sep 17 00:00:00 2001 From: Andrew Chow Date: Mon, 18 Oct 2021 14:43:26 -0400 Subject: wallet: Parse hdKeypath if key_origin is not available When topping up an inactive HD chain, either key_origin will be available and we can use the path given there, or we need to figure out the path from the string hdKeypath. --- src/wallet/scriptpubkeyman.cpp | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'src/wallet/scriptpubkeyman.cpp') diff --git a/src/wallet/scriptpubkeyman.cpp b/src/wallet/scriptpubkeyman.cpp index 5a9755d32b..7cca5fba20 100644 --- a/src/wallet/scriptpubkeyman.cpp +++ b/src/wallet/scriptpubkeyman.cpp @@ -382,14 +382,22 @@ std::vector LegacyScriptPubKeyMan::MarkUnusedAddresses(const if (it != mapKeyMetadata.end()){ CKeyMetadata meta = it->second; if (!meta.hd_seed_id.IsNull() && meta.hd_seed_id != m_hd_chain.seed_id) { - if (meta.key_origin.path.size() < 3) { - WalletLogPrintf("%s: Adding inactive seed keys failed, insufficient path size: %d, has_key_origin: %s\n", + std::vector path; + if (meta.has_key_origin) { + path = meta.key_origin.path; + } else if (!ParseHDKeypath(meta.hdKeypath, path)) { + WalletLogPrintf("%s: Adding inactive seed keys failed, invalid hdKeypath: %s\n", __func__, - meta.key_origin.path.size(), + meta.hdKeypath); + } + if (path.size() != 3) { + WalletLogPrintf("%s: Adding inactive seed keys failed, invalid path size: %d, has_key_origin: %s\n", + __func__, + path.size(), meta.has_key_origin); } else { - bool internal = (meta.key_origin.path[1] & ~BIP32_HARDENED_KEY_LIMIT) != 0; - int64_t index = meta.key_origin.path[2] & ~BIP32_HARDENED_KEY_LIMIT; + bool internal = (path[1] & ~BIP32_HARDENED_KEY_LIMIT) != 0; + int64_t index = path[2] & ~BIP32_HARDENED_KEY_LIMIT; if (!TopUpInactiveHDChain(meta.hd_seed_id, index, internal)) { WalletLogPrintf("%s: Adding inactive seed keys failed\n", __func__); -- cgit v1.2.3