mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-25 10:43:19 -03:00
Have importprivkey use CWallet's ImportPrivKeys, ImportScripts, and ImportScriptPubKeys
Behavior changes: * If we already have the key, it's wpkh script will still be added, although it should already be there
This commit is contained in:
parent
fae7a5befd
commit
c6a8274247
1 changed files with 7 additions and 11 deletions
|
@ -187,19 +187,15 @@ UniValue importprivkey(const JSONRPCRequest& request)
|
|||
}
|
||||
}
|
||||
|
||||
// Don't throw error in case a key is already there
|
||||
if (pwallet->HaveKey(vchAddress)) {
|
||||
return NullUniValue;
|
||||
}
|
||||
|
||||
// whenever a key is imported, we need to scan the whole chain
|
||||
pwallet->UpdateTimeFirstKey(1);
|
||||
pwallet->mapKeyMetadata[vchAddress].nCreateTime = 1;
|
||||
|
||||
if (!pwallet->AddKeyPubKey(key, pubkey)) {
|
||||
// Use timestamp of 1 to scan the whole chain
|
||||
if (!pwallet->ImportPrivKeys({{vchAddress, key}}, 1)) {
|
||||
throw JSONRPCError(RPC_WALLET_ERROR, "Error adding key to wallet");
|
||||
}
|
||||
pwallet->LearnAllRelatedScripts(pubkey);
|
||||
|
||||
// Add the wpkh script for this key if possible
|
||||
if (pubkey.IsCompressed()) {
|
||||
pwallet->ImportScripts({GetScriptForDestination(WitnessV0KeyHash(vchAddress))});
|
||||
}
|
||||
}
|
||||
}
|
||||
if (fRescan) {
|
||||
|
|
Loading…
Add table
Reference in a new issue