aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJonas Schnelli <dev@jonasschnelli.ch>2018-11-13 14:51:34 +0700
committerJonas Schnelli <dev@jonasschnelli.ch>2018-11-13 14:52:01 +0700
commitb60f4e3f095124a71394d6b2aafaedca2be6c1ad (patch)
tree07d76cc438ce18d7ae555d7e16d994baf32fb9e8 /src
parent47ed24cf8aa7be3b778731b1f140ad9941157933 (diff)
parenta6b5ec18ff39ef3ccd19ec0e6db9ae00602d8938 (diff)
downloadbitcoin-b60f4e3f095124a71394d6b2aafaedca2be6c1ad.tar.xz
Merge #13381: RPC: creates possibility to preserve labels on importprivkey
a6b5ec18f rpc: creates possibility to preserve labels on importprivkey (marcoagner) Pull request description: Closes #13087. As discussed in the issue, this is a feature request instead of a bug report since the behaviour was as intended (i.e. label with default: `''`). With this, the old behaviour is kept while the possibility to achieve the preservation of labels, as expected in the open issue, is added. Tree-SHA512: b33be50e1e7f62f7ddfae953177ba0926e2d848961f9fac7501c2b513322c0cb95787745d07d137488267bad1104ecfdbe800c6747f94162eb07c976835c1386
Diffstat (limited to 'src')
-rw-r--r--src/wallet/rpcdump.cpp11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp
index e1e4fc51fe..7dbe0c8462 100644
--- a/src/wallet/rpcdump.cpp
+++ b/src/wallet/rpcdump.cpp
@@ -113,7 +113,7 @@ UniValue importprivkey(const JSONRPCRequest& request)
"Hint: use importmulti to import more than one private key.\n"
"\nArguments:\n"
"1. \"privkey\" (string, required) The private key (see dumpprivkey)\n"
- "2. \"label\" (string, optional, default=\"\") An optional label\n"
+ "2. \"label\" (string, optional, default=current label if address exists, otherwise \"\") An optional label\n"
"3. rescan (boolean, optional, default=true) Rescan the wallet for transactions\n"
"\nNote: This call can take over an hour to complete if rescan is true, during that time, other rpc calls\n"
"may report that the imported key exists but related transactions are still missing, leading to temporarily incorrect/bogus balances and unspent outputs until rescan completes.\n"
@@ -163,9 +163,14 @@ UniValue importprivkey(const JSONRPCRequest& request)
CKeyID vchAddress = pubkey.GetID();
{
pwallet->MarkDirty();
- // We don't know which corresponding address will be used; label them all
+
+ // We don't know which corresponding address will be used;
+ // label all new addresses, and label existing addresses if a
+ // label was passed.
for (const auto& dest : GetAllDestinationsForKey(pubkey)) {
- pwallet->SetAddressBook(dest, strLabel, "receive");
+ if (!request.params[1].isNull() || pwallet->mapAddressBook.count(dest) == 0) {
+ pwallet->SetAddressBook(dest, strLabel, "receive");
+ }
}
// Don't throw error in case a key is already there