Bech32 addresses in dumpwallet

Output bech32 addresses in dumpwallet if address type is not as legacy
This commit is contained in:
fivepiece
2018-01-31 17:48:20 +02:00
parent 895fbd768f
commit 45eea40aa8
2 changed files with 42 additions and 7 deletions

View File

@@ -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)) {