Skip to content

Commit ec2792d

Browse files
committed
refactor: use const LegacyScriptPubKeyMan references in dump{privkey,wallet} RPCs
1 parent 29905c0 commit ec2792d

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

src/wallet/rpcdump.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ static std::string DecodeDumpString(const std::string &str) {
5757
return ret.str();
5858
}
5959

60-
static bool GetWalletAddressesForKey(LegacyScriptPubKeyMan* spk_man, const CWallet& wallet, const CKeyID& keyid, std::string& strAddr, std::string& strLabel) EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet)
60+
static bool GetWalletAddressesForKey(const LegacyScriptPubKeyMan* spk_man, const CWallet& wallet, const CKeyID& keyid, std::string& strAddr, std::string& strLabel) EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet)
6161
{
6262
bool fLabelFound = false;
6363
CKey key;
@@ -684,7 +684,7 @@ RPCHelpMan dumpprivkey()
684684
std::shared_ptr<CWallet> const pwallet = GetWalletForJSONRPCRequest(request);
685685
if (!pwallet) return NullUniValue;
686686

687-
LegacyScriptPubKeyMan& spk_man = EnsureLegacyScriptPubKeyMan(*pwallet);
687+
const LegacyScriptPubKeyMan& spk_man = EnsureConstLegacyScriptPubKeyMan(*pwallet);
688688

689689
LOCK2(pwallet->cs_wallet, spk_man.cs_KeyStore);
690690

@@ -735,7 +735,7 @@ RPCHelpMan dumpwallet()
735735
if (!pwallet) return NullUniValue;
736736

737737
CWallet& wallet = *pwallet;
738-
LegacyScriptPubKeyMan& spk_man = EnsureLegacyScriptPubKeyMan(wallet);
738+
const LegacyScriptPubKeyMan& spk_man = EnsureConstLegacyScriptPubKeyMan(wallet);
739739

740740
// Make sure the results are valid at least up to the most recent block
741741
// the user could have gotten from another RPC command prior to now

src/wallet/rpcwallet.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,15 @@ LegacyScriptPubKeyMan& EnsureLegacyScriptPubKeyMan(CWallet& wallet, bool also_cr
150150
return *spk_man;
151151
}
152152

153+
const LegacyScriptPubKeyMan& EnsureConstLegacyScriptPubKeyMan(const CWallet& wallet)
154+
{
155+
const LegacyScriptPubKeyMan* spk_man = wallet.GetLegacyScriptPubKeyMan();
156+
if (!spk_man) {
157+
throw JSONRPCError(RPC_WALLET_ERROR, "This type of wallet does not support this command");
158+
}
159+
return *spk_man;
160+
}
161+
153162
static void WalletTxToJSON(const CWallet& wallet, const CWalletTx& wtx, UniValue& entry)
154163
{
155164
interfaces::Chain& chain = wallet.chain();

src/wallet/rpcwallet.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ std::shared_ptr<CWallet> GetWalletForJSONRPCRequest(const JSONRPCRequest& reques
3434
void EnsureWalletIsUnlocked(const CWallet&);
3535
WalletContext& EnsureWalletContext(const std::any& context);
3636
LegacyScriptPubKeyMan& EnsureLegacyScriptPubKeyMan(CWallet& wallet, bool also_create = false);
37+
const LegacyScriptPubKeyMan& EnsureConstLegacyScriptPubKeyMan(const CWallet& wallet);
3738

3839
RPCHelpMan getaddressinfo();
3940
RPCHelpMan signrawtransactionwithwallet();

0 commit comments

Comments
 (0)