diff options
| author | Andrew Chow <[email protected]> | 2019-06-27 17:53:08 -0400 |
|---|---|---|
| committer | Andrew Chow <[email protected]> | 2019-07-18 20:35:51 -0400 |
| commit | c6a827424711333f6f66cf5f9d79e0e6884769de (patch) | |
| tree | f3c89fe62d3003a3ec2db08a3d3cfdea92387fe8 /src | |
| parent | Log when an import is being skipped because we already have it (diff) | |
| download | discoin-c6a827424711333f6f66cf5f9d79e0e6884769de.tar.xz discoin-c6a827424711333f6f66cf5f9d79e0e6884769de.zip | |
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
Diffstat (limited to 'src')
| -rw-r--r-- | src/wallet/rpcdump.cpp | 16 |
1 files changed, 6 insertions, 10 deletions
diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp index 506b7c4be..7f192e936 100644 --- a/src/wallet/rpcdump.cpp +++ b/src/wallet/rpcdump.cpp @@ -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; + // 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"); } - // 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)) { - throw JSONRPCError(RPC_WALLET_ERROR, "Error adding key to wallet"); + // Add the wpkh script for this key if possible + if (pubkey.IsCompressed()) { + pwallet->ImportScripts({GetScriptForDestination(WitnessV0KeyHash(vchAddress))}); } - pwallet->LearnAllRelatedScripts(pubkey); } } if (fRescan) { |