From 45eea40aa88f047111a9b1151fe4d1bad5c560e2 Mon Sep 17 00:00:00 2001 From: fivepiece Date: Wed, 31 Jan 2018 17:48:20 +0200 Subject: Bech32 addresses in dumpwallet Output bech32 addresses in dumpwallet if address type is not as legacy --- src/wallet/rpcdump.cpp | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp index 0b021f9fe0..03fb824e7a 100644 --- a/src/wallet/rpcdump.cpp +++ b/src/wallet/rpcdump.cpp @@ -71,6 +71,28 @@ std::string DecodeDumpString(const std::string &str) { return ret.str(); } +bool GetWalletAddressesForKey(CWallet * const pwallet, const CKeyID &keyid, std::string &strAddr, std::string &strLabel) +{ + bool fLabelFound = false; + CKey key; + pwallet->GetKey(keyid, key); + for (const auto& dest : GetAllDestinationsForKey(key.GetPubKey())) { + if (pwallet->mapAddressBook.count(dest)) { + if (!strAddr.empty()) { + strAddr += ","; + } + strAddr += EncodeDestination(dest); + strLabel = EncodeDumpString(pwallet->mapAddressBook[dest].name); + fLabelFound = true; + } + } + if (!fLabelFound) { + strAddr = EncodeDestination(GetDestinationForKey(key.GetPubKey(), g_address_type)); + } + return fLabelFound; +} + + UniValue importprivkey(const JSONRPCRequest& request) { CWallet * const pwallet = GetWalletForJSONRPCRequest(request); @@ -729,12 +751,13 @@ UniValue dumpwallet(const JSONRPCRequest& request) for (std::vector >::const_iterator it = vKeyBirth.begin(); it != vKeyBirth.end(); it++) { const CKeyID &keyid = it->second; std::string strTime = EncodeDumpTime(it->first); - std::string strAddr = EncodeDestination(keyid); + std::string strAddr; + std::string strLabel; CKey key; if (pwallet->GetKey(keyid, key)) { file << strprintf("%s %s ", CBitcoinSecret(key).ToString(), strTime); - if (pwallet->mapAddressBook.count(keyid)) { - file << strprintf("label=%s", EncodeDumpString(pwallet->mapAddressBook[keyid].name)); + if (GetWalletAddressesForKey(pwallet, keyid, strAddr, strLabel)) { + file << strprintf("label=%s", strLabel); } else if (keyid == masterKeyID) { file << "hdmaster=1"; } else if (mapKeyPool.count(keyid)) { -- cgit v1.2.3