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.
This commit is contained in:
Jack Grigg 2022-03-18 21:53:12 +00:00
parent eaf8eb40f4
commit 78fea33cde
1 changed files with 10 additions and 5 deletions

View File

@ -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";