From 78fea33cde0fc7331e87b8af52fc3fe690d0d0bf Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Fri, 18 Mar 2022 21:53:12 +0000 Subject: [PATCH] wallet: Add seedfp to transparent keys in dumpwallet / z_exportwallet Also refactors Sapling key export logic to match. Sapling key exports already have hdkeypath and seedfp (in a different spot in the line). Sprout key exports are unmodified, because we have removed the ability to generate new Sprout keys, so there will never be HD Sprout keys. --- src/wallet/rpcdump.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp index 496c8a7de..727696eb9 100644 --- a/src/wallet/rpcdump.cpp +++ b/src/wallet/rpcdump.cpp @@ -649,6 +649,7 @@ UniValue dumpwallet_impl(const UniValue& params, bool fDumpZKeys) std::string strAddr = keyIO.EncodeDestination(keyid); CKey key; if (pwalletMain->GetKey(keyid, key)) { + CKeyMetadata keyMeta = pwalletMain->mapKeyMetadata[keyid]; file << strprintf("%s %s ", keyIO.EncodeSecret(key), strTime); if (pwalletMain->mapAddressBook.count(keyid)) { file << strprintf("label=%s", EncodeDumpString(pwalletMain->mapAddressBook[keyid].name)); @@ -657,7 +658,11 @@ UniValue dumpwallet_impl(const UniValue& params, bool fDumpZKeys) } else { file << "change=1"; } - file << strprintf(" # addr=%s%s\n", strAddr, (pwalletMain->mapKeyMetadata[keyid].hdKeypath.size() > 0 ? " hdkeypath="+pwalletMain->mapKeyMetadata[keyid].hdKeypath : "")); + file << strprintf(" # addr=%s", strAddr); + if (!(keyMeta.hdKeypath.empty() || keyMeta.seedFp.IsNull())) { + file << strprintf(" hdkeypath=%s seedfp=%s", keyMeta.hdKeypath, keyMeta.seedFp.GetHex()); + } + file << "\n"; } } file << "\n"; @@ -686,12 +691,12 @@ UniValue dumpwallet_impl(const UniValue& params, bool fDumpZKeys) auto ivk = extsk.expsk.full_viewing_key().in_viewing_key(); CKeyMetadata keyMeta = pwalletMain->mapSaplingZKeyMetadata[ivk]; std::string strTime = EncodeDumpTime(keyMeta.nCreateTime); + file << strprintf("%s %s", keyIO.EncodeSpendingKey(extsk), strTime); // Keys imported with z_importkey do not have zip32 metadata - if (keyMeta.hdKeypath.empty() || keyMeta.seedFp.IsNull()) { - file << strprintf("%s %s # zaddr=%s\n", keyIO.EncodeSpendingKey(extsk), strTime, keyIO.EncodePaymentAddress(addr)); - } else { - file << strprintf("%s %s %s %s # zaddr=%s\n", keyIO.EncodeSpendingKey(extsk), strTime, keyMeta.hdKeypath, keyMeta.seedFp.GetHex(), keyIO.EncodePaymentAddress(addr)); + if (!(keyMeta.hdKeypath.empty() || keyMeta.seedFp.IsNull())) { + file << strprintf(" %s %s", keyMeta.hdKeypath, keyMeta.seedFp.GetHex()); } + file << strprintf(" # zaddr=%s\n", keyIO.EncodePaymentAddress(addr)); } } file << "\n";