mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-03-25 23:16:16 +01:00
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
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user