diff options
author | fivepiece <fivepiece@users.noreply.github.com> | 2018-01-31 17:48:20 +0200 |
---|---|---|
committer | Wladimir J. van der Laan <laanwj@gmail.com> | 2018-02-08 10:07:45 +0100 |
commit | 758a41e100453fcb417c536adcba725ae8ef2180 (patch) | |
tree | 955c8610463235169d52d61e6c65fd4617f126a6 /src | |
parent | 3f5012beb6161c60290155974b6ba6e67e68779f (diff) | |
download | bitcoin-758a41e100453fcb417c536adcba725ae8ef2180.tar.xz |
Bech32 addresses in dumpwallet
Output bech32 addresses in dumpwallet if address type is not as legacy
Github-Pull: #12315
Rebased-From: 45eea40aa88f047111a9b1151fe4d1bad5c560e2
Tree-SHA512: 3426292ddaeaafebc25fe84802011f5569a0cbb47fcc3209e7f00f64fc6eb1e637732722bbd02dce8d46be87d0f3687ce8370e71e9286bf7d00afc0a895faecb
Diffstat (limited to 'src')
-rw-r--r-- | src/wallet/rpcdump.cpp | 29 |
1 files changed, 26 insertions, 3 deletions
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<std::pair<int64_t, CKeyID> >::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)) { |