@@ -124,6 +124,15 @@ void EnsureWalletIsUnlocked(const CWallet* pwallet)
124124 }
125125}
126126
127+ LegacyScriptPubKeyMan& EnsureLegacyScriptPubKeyMan (CWallet& wallet)
128+ {
129+ LegacyScriptPubKeyMan* spk_man = wallet.GetLegacyScriptPubKeyMan ();
130+ if (!spk_man) {
131+ throw JSONRPCError (RPC_WALLET_ERROR, " This type of wallet does not support this command" );
132+ }
133+ return *spk_man;
134+ }
135+
127136static void WalletTxToJSON (interfaces::Chain& chain, interfaces::Chain::Lock& locked_chain, const CWalletTx& wtx, UniValue& entry)
128137{
129138 int confirms = wtx.GetDepthInMainChain (locked_chain);
@@ -966,10 +975,7 @@ static UniValue addmultisigaddress(const JSONRPCRequest& request)
966975 },
967976 }.Check (request);
968977
969- LegacyScriptPubKeyMan* spk_man = pwallet->GetLegacyScriptPubKeyMan ();
970- if (!spk_man) {
971- throw JSONRPCError (RPC_WALLET_ERROR, " This type of wallet does not support this command" );
972- }
978+ LegacyScriptPubKeyMan& spk_man = EnsureLegacyScriptPubKeyMan (*pwallet);
973979
974980 auto locked_chain = pwallet->chain ().lock ();
975981 LOCK (pwallet->cs_wallet );
@@ -987,7 +993,7 @@ static UniValue addmultisigaddress(const JSONRPCRequest& request)
987993 if (IsHex (keys_or_addrs[i].get_str ()) && (keys_or_addrs[i].get_str ().length () == 66 || keys_or_addrs[i].get_str ().length () == 130 )) {
988994 pubkeys.push_back (HexToPubKey (keys_or_addrs[i].get_str ()));
989995 } else {
990- pubkeys.push_back (AddrToPubKey (spk_man, keys_or_addrs[i].get_str ()));
996+ pubkeys.push_back (AddrToPubKey (& spk_man, keys_or_addrs[i].get_str ()));
991997 }
992998 }
993999
@@ -1000,7 +1006,7 @@ static UniValue addmultisigaddress(const JSONRPCRequest& request)
10001006
10011007 // Construct using pay-to-script-hash:
10021008 CScript inner;
1003- CTxDestination dest = AddAndGetMultisigDestination (required, pubkeys, output_type, * spk_man, inner);
1009+ CTxDestination dest = AddAndGetMultisigDestination (required, pubkeys, output_type, spk_man, inner);
10041010 pwallet->SetAddressBook (dest, label, " send" );
10051011
10061012 UniValue result (UniValue::VOBJ);
@@ -3933,10 +3939,7 @@ UniValue sethdseed(const JSONRPCRequest& request)
39333939 },
39343940 }.Check (request);
39353941
3936- LegacyScriptPubKeyMan* spk_man = pwallet->GetLegacyScriptPubKeyMan ();
3937- if (!spk_man) {
3938- throw JSONRPCError (RPC_WALLET_ERROR, " This type of wallet does not support this command" );
3939- }
3942+ LegacyScriptPubKeyMan& spk_man = EnsureLegacyScriptPubKeyMan (*pwallet);
39403943
39413944 if (pwallet->chain ().isInitialBlockDownload ()) {
39423945 throw JSONRPCError (RPC_CLIENT_IN_INITIAL_DOWNLOAD, " Cannot set a new HD seed while still in Initial Block Download" );
@@ -3963,22 +3966,22 @@ UniValue sethdseed(const JSONRPCRequest& request)
39633966
39643967 CPubKey master_pub_key;
39653968 if (request.params [1 ].isNull ()) {
3966- master_pub_key = spk_man-> GenerateNewSeed ();
3969+ master_pub_key = spk_man. GenerateNewSeed ();
39673970 } else {
39683971 CKey key = DecodeSecret (request.params [1 ].get_str ());
39693972 if (!key.IsValid ()) {
39703973 throw JSONRPCError (RPC_INVALID_ADDRESS_OR_KEY, " Invalid private key" );
39713974 }
39723975
3973- if (HaveKey (* spk_man, key)) {
3976+ if (HaveKey (spk_man, key)) {
39743977 throw JSONRPCError (RPC_INVALID_ADDRESS_OR_KEY, " Already have this key (either as an HD seed or as a loose private key)" );
39753978 }
39763979
3977- master_pub_key = spk_man-> DeriveNewSeed (key);
3980+ master_pub_key = spk_man. DeriveNewSeed (key);
39783981 }
39793982
3980- spk_man-> SetHDSeed (master_pub_key);
3981- if (flush_key_pool) spk_man-> NewKeyPool ();
3983+ spk_man. SetHDSeed (master_pub_key);
3984+ if (flush_key_pool) spk_man. NewKeyPool ();
39823985
39833986 return NullUniValue;
39843987}
0 commit comments