@@ -124,6 +124,15 @@ void EnsureWalletIsUnlocked(const CWallet* pwallet)
124
124
}
125
125
}
126
126
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
+
127
136
static void WalletTxToJSON (interfaces::Chain& chain, interfaces::Chain::Lock& locked_chain, const CWalletTx& wtx, UniValue& entry)
128
137
{
129
138
int confirms = wtx.GetDepthInMainChain (locked_chain);
@@ -966,10 +975,7 @@ static UniValue addmultisigaddress(const JSONRPCRequest& request)
966
975
},
967
976
}.Check (request);
968
977
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);
973
979
974
980
auto locked_chain = pwallet->chain ().lock ();
975
981
LOCK (pwallet->cs_wallet );
@@ -987,7 +993,7 @@ static UniValue addmultisigaddress(const JSONRPCRequest& request)
987
993
if (IsHex (keys_or_addrs[i].get_str ()) && (keys_or_addrs[i].get_str ().length () == 66 || keys_or_addrs[i].get_str ().length () == 130 )) {
988
994
pubkeys.push_back (HexToPubKey (keys_or_addrs[i].get_str ()));
989
995
} 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 ()));
991
997
}
992
998
}
993
999
@@ -1000,7 +1006,7 @@ static UniValue addmultisigaddress(const JSONRPCRequest& request)
1000
1006
1001
1007
// Construct using pay-to-script-hash:
1002
1008
CScript inner;
1003
- CTxDestination dest = AddAndGetMultisigDestination (required, pubkeys, output_type, * spk_man, inner);
1009
+ CTxDestination dest = AddAndGetMultisigDestination (required, pubkeys, output_type, spk_man, inner);
1004
1010
pwallet->SetAddressBook (dest, label, " send" );
1005
1011
1006
1012
UniValue result (UniValue::VOBJ);
@@ -3933,10 +3939,7 @@ UniValue sethdseed(const JSONRPCRequest& request)
3933
3939
},
3934
3940
}.Check (request);
3935
3941
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);
3940
3943
3941
3944
if (pwallet->chain ().isInitialBlockDownload ()) {
3942
3945
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)
3963
3966
3964
3967
CPubKey master_pub_key;
3965
3968
if (request.params [1 ].isNull ()) {
3966
- master_pub_key = spk_man-> GenerateNewSeed ();
3969
+ master_pub_key = spk_man. GenerateNewSeed ();
3967
3970
} else {
3968
3971
CKey key = DecodeSecret (request.params [1 ].get_str ());
3969
3972
if (!key.IsValid ()) {
3970
3973
throw JSONRPCError (RPC_INVALID_ADDRESS_OR_KEY, " Invalid private key" );
3971
3974
}
3972
3975
3973
- if (HaveKey (* spk_man, key)) {
3976
+ if (HaveKey (spk_man, key)) {
3974
3977
throw JSONRPCError (RPC_INVALID_ADDRESS_OR_KEY, " Already have this key (either as an HD seed or as a loose private key)" );
3975
3978
}
3976
3979
3977
- master_pub_key = spk_man-> DeriveNewSeed (key);
3980
+ master_pub_key = spk_man. DeriveNewSeed (key);
3978
3981
}
3979
3982
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 ();
3982
3985
3983
3986
return NullUniValue;
3984
3987
}
0 commit comments