Skip to content

Commit 18b8ee1

Browse files
jonasschnellilaanwj
authored andcommitted
[Wallet] add HD xpriv to dumpwallet
Github-Pull: #8206 Rebased-From: 77c912d21c8cd153f4503c65225a5a46990cc85a
1 parent cfd1280 commit 18b8ee1

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

src/wallet/rpcdump.cpp

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -602,19 +602,42 @@ UniValue dumpwallet(const UniValue& params, bool fHelp)
602602
file << strprintf("# * Best block at time of backup was %i (%s),\n", chainActive.Height(), chainActive.Tip()->GetBlockHash().ToString());
603603
file << strprintf("# mined on %s\n", EncodeDumpTime(chainActive.Tip()->GetBlockTime()));
604604
file << "\n";
605+
606+
// add the base58check encoded extended master if the wallet uses HD
607+
CKeyID masterKeyID = pwalletMain->GetHDChain().masterKeyID;
608+
if (!masterKeyID.IsNull())
609+
{
610+
CKey key;
611+
if (pwalletMain->GetKey(masterKeyID, key))
612+
{
613+
CExtKey masterKey;
614+
masterKey.SetMaster(key.begin(), key.size());
615+
616+
CBitcoinExtKey b58extkey;
617+
b58extkey.SetKey(masterKey);
618+
619+
file << "# extended private masterkey: " << b58extkey.ToString() << "\n\n";
620+
}
621+
}
605622
for (std::vector<std::pair<int64_t, CKeyID> >::const_iterator it = vKeyBirth.begin(); it != vKeyBirth.end(); it++) {
606623
const CKeyID &keyid = it->second;
607624
std::string strTime = EncodeDumpTime(it->first);
608625
std::string strAddr = CBitcoinAddress(keyid).ToString();
609626
CKey key;
610627
if (pwalletMain->GetKey(keyid, key)) {
628+
file << strprintf("%s %s ", CBitcoinSecret(key).ToString(), strTime);
611629
if (pwalletMain->mapAddressBook.count(keyid)) {
612-
file << strprintf("%s %s label=%s # addr=%s\n", CBitcoinSecret(key).ToString(), strTime, EncodeDumpString(pwalletMain->mapAddressBook[keyid].name), strAddr);
630+
file << strprintf("label=%s", EncodeDumpString(pwalletMain->mapAddressBook[keyid].name));
631+
} else if (keyid == masterKeyID) {
632+
file << "hdmaster=1";
613633
} else if (setKeyPool.count(keyid)) {
614-
file << strprintf("%s %s reserve=1 # addr=%s\n", CBitcoinSecret(key).ToString(), strTime, strAddr);
634+
file << "reserve=1";
635+
} else if (pwalletMain->mapKeyMetadata[keyid].hdKeypath == "m") {
636+
file << "inactivehdmaster=1";
615637
} else {
616-
file << strprintf("%s %s change=1 # addr=%s\n", CBitcoinSecret(key).ToString(), strTime, strAddr);
638+
file << "change=1";
617639
}
640+
file << strprintf(" # addr=%s%s\n", strAddr, (pwalletMain->mapKeyMetadata[keyid].hdKeypath.size() > 0 ? " hdkeypath="+pwalletMain->mapKeyMetadata[keyid].hdKeypath : ""));
618641
}
619642
}
620643
file << "\n";

src/wallet/wallet.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -899,10 +899,10 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface
899899

900900
/* Set the HD chain model (chain child index counters) */
901901
bool SetHDChain(const CHDChain& chain, bool memonly);
902+
const CHDChain& GetHDChain() { return hdChain; }
902903

903904
/* Set the current HD master key (will reset the chain child index counters) */
904905
bool SetHDMasterKey(const CKey& key);
905-
const CHDChain& GetHDChain() { return hdChain; }
906906
};
907907

908908
/** A key allocated from the key pool. */

0 commit comments

Comments
 (0)