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.
This commit is contained in:
Andrew Chow 2021-10-18 14:43:26 -04:00
parent 0652ee73ec
commit 961b9e4e40

View File

@ -382,14 +382,22 @@ std::vector<WalletDestination> 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<uint32_t> 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__);