From 513719c5f860a5758411331d5ced0bb50c5c5054 Mon Sep 17 00:00:00 2001 From: Andrew Chow Date: Tue, 6 Nov 2018 09:47:49 -0500 Subject: Add option to importmulti add an imported pubkey to the keypool Adds a new option to importmulti where the pubkeys specified in the import object can be added to the keypool. This only works if the wallet has private keys disabled. --- src/wallet/rpcdump.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/wallet') diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp index 5ceba39704..30555886f7 100644 --- a/src/wallet/rpcdump.cpp +++ b/src/wallet/rpcdump.cpp @@ -1207,6 +1207,12 @@ static UniValue ProcessImport(CWallet * const pwallet, const UniValue& data, con throw JSONRPCError(RPC_INVALID_PARAMETER, "Internal addresses should not have a label"); } const std::string& label = data.exists("label") ? data["label"].get_str() : ""; + const bool add_keypool = data.exists("keypool") ? data["keypool"].get_bool() : false; + + // Add to keypool only works with privkeys disabled + if (add_keypool && !pwallet->IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS)) { + throw JSONRPCError(RPC_INVALID_PARAMETER, "Keys can only be imported to the keypool when private keys are disabled"); + } ImportData import_data; std::map pubkey_map; @@ -1267,6 +1273,11 @@ static UniValue ProcessImport(CWallet * const pwallet, const UniValue& data, con pwallet->AddKeyOrigin(pubkey, key_orig_it->second); } pwallet->mapKeyMetadata[id].nCreateTime = timestamp; + + // Add to keypool only works with pubkeys + if (add_keypool) { + pwallet->AddKeypoolPubkey(pubkey, internal); + } } for (const CScript& script : script_pub_keys) { -- cgit v1.2.3