File tree Expand file tree Collapse file tree 1 file changed +6
-10
lines changed Expand file tree Collapse file tree 1 file changed +6
-10
lines changed Original file line number Diff line number Diff line change @@ -187,19 +187,15 @@ UniValue importprivkey(const JSONRPCRequest& request)
187
187
}
188
188
}
189
189
190
- // Don't throw error in case a key is already there
191
- if (pwallet->HaveKey ( vchAddress)) {
192
- return NullUniValue ;
190
+ // Use timestamp of 1 to scan the whole chain
191
+ if (! pwallet->ImportPrivKeys ({{ vchAddress, key}}, 1 )) {
192
+ throw JSONRPCError (RPC_WALLET_ERROR, " Error adding key to wallet " ) ;
193
193
}
194
194
195
- // whenever a key is imported, we need to scan the whole chain
196
- pwallet->UpdateTimeFirstKey (1 );
197
- pwallet->mapKeyMetadata [vchAddress].nCreateTime = 1 ;
198
-
199
- if (!pwallet->AddKeyPubKey (key, pubkey)) {
200
- throw JSONRPCError (RPC_WALLET_ERROR, " Error adding key to wallet" );
195
+ // Add the wpkh script for this key if possible
196
+ if (pubkey.IsCompressed ()) {
197
+ pwallet->ImportScripts ({GetScriptForDestination (WitnessV0KeyHash (vchAddress))});
201
198
}
202
- pwallet->LearnAllRelatedScripts (pubkey);
203
199
}
204
200
}
205
201
if (fRescan ) {
You can’t perform that action at this time.
0 commit comments