Skip to content

Commit 961b9e4

Browse files
committed
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.
1 parent 0652ee7 commit 961b9e4

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/wallet/scriptpubkeyman.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -382,14 +382,22 @@ std::vector<WalletDestination> LegacyScriptPubKeyMan::MarkUnusedAddresses(const
382382
if (it != mapKeyMetadata.end()){
383383
CKeyMetadata meta = it->second;
384384
if (!meta.hd_seed_id.IsNull() && meta.hd_seed_id != m_hd_chain.seed_id) {
385-
if (meta.key_origin.path.size() < 3) {
386-
WalletLogPrintf("%s: Adding inactive seed keys failed, insufficient path size: %d, has_key_origin: %s\n",
385+
std::vector<uint32_t> path;
386+
if (meta.has_key_origin) {
387+
path = meta.key_origin.path;
388+
} else if (!ParseHDKeypath(meta.hdKeypath, path)) {
389+
WalletLogPrintf("%s: Adding inactive seed keys failed, invalid hdKeypath: %s\n",
387390
__func__,
388-
meta.key_origin.path.size(),
391+
meta.hdKeypath);
392+
}
393+
if (path.size() != 3) {
394+
WalletLogPrintf("%s: Adding inactive seed keys failed, invalid path size: %d, has_key_origin: %s\n",
395+
__func__,
396+
path.size(),
389397
meta.has_key_origin);
390398
} else {
391-
bool internal = (meta.key_origin.path[1] & ~BIP32_HARDENED_KEY_LIMIT) != 0;
392-
int64_t index = meta.key_origin.path[2] & ~BIP32_HARDENED_KEY_LIMIT;
399+
bool internal = (path[1] & ~BIP32_HARDENED_KEY_LIMIT) != 0;
400+
int64_t index = path[2] & ~BIP32_HARDENED_KEY_LIMIT;
393401

394402
if (!TopUpInactiveHDChain(meta.hd_seed_id, index, internal)) {
395403
WalletLogPrintf("%s: Adding inactive seed keys failed\n", __func__);

0 commit comments

Comments
 (0)