Add EnsureLegacyScriptPubKeyMan and use in rpcwallet.cpp

This also fixes unused variable warnings in rpcdump.cpp
This commit is contained in:
Russell Yanofsky
2019-11-05 10:13:43 -05:00
parent e204dc11b5
commit b07b07cd87
3 changed files with 27 additions and 31 deletions

View File

@@ -87,15 +87,6 @@ static void RescanWallet(CWallet& wallet, const WalletRescanReserver& reserver,
}
}
static LegacyScriptPubKeyMan& GetLegacyScriptPubKeyMan(CWallet& wallet)
{
LegacyScriptPubKeyMan* spk_man = wallet.GetLegacyScriptPubKeyMan();
if (!spk_man) {
throw JSONRPCError(RPC_WALLET_ERROR, "This type of wallet does not support this command");
}
return *spk_man;
}
UniValue importprivkey(const JSONRPCRequest& request)
{
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
@@ -134,7 +125,7 @@ UniValue importprivkey(const JSONRPCRequest& request)
throw JSONRPCError(RPC_WALLET_ERROR, "Cannot import private keys to a wallet with private keys disabled");
}
LegacyScriptPubKeyMan& spk_man = GetLegacyScriptPubKeyMan(*wallet);
EnsureLegacyScriptPubKeyMan(*wallet);
WalletRescanReserver reserver(pwallet);
bool fRescan = true;
@@ -262,7 +253,7 @@ UniValue importaddress(const JSONRPCRequest& request)
},
}.Check(request);
LegacyScriptPubKeyMan& spk_man = GetLegacyScriptPubKeyMan(*pwallet);
EnsureLegacyScriptPubKeyMan(*pwallet);
std::string strLabel;
if (!request.params[1].isNull())
@@ -465,7 +456,7 @@ UniValue importpubkey(const JSONRPCRequest& request)
},
}.Check(request);
LegacyScriptPubKeyMan& spk_man = GetLegacyScriptPubKeyMan(*wallet);
EnsureLegacyScriptPubKeyMan(*wallet);
std::string strLabel;
if (!request.params[1].isNull())
@@ -549,7 +540,7 @@ UniValue importwallet(const JSONRPCRequest& request)
},
}.Check(request);
LegacyScriptPubKeyMan& spk_man = GetLegacyScriptPubKeyMan(*wallet);
EnsureLegacyScriptPubKeyMan(*wallet);
if (pwallet->chain().havePruned()) {
// Exit early and print an error.
@@ -708,7 +699,7 @@ UniValue dumpprivkey(const JSONRPCRequest& request)
},
}.Check(request);
LegacyScriptPubKeyMan& spk_man = GetLegacyScriptPubKeyMan(*wallet);
LegacyScriptPubKeyMan& spk_man = EnsureLegacyScriptPubKeyMan(*wallet);
auto locked_chain = pwallet->chain().lock();
LOCK(pwallet->cs_wallet);
@@ -759,7 +750,7 @@ UniValue dumpwallet(const JSONRPCRequest& request)
},
}.Check(request);
LegacyScriptPubKeyMan& spk_man = GetLegacyScriptPubKeyMan(*wallet);
LegacyScriptPubKeyMan& spk_man = EnsureLegacyScriptPubKeyMan(*wallet);
auto locked_chain = pwallet->chain().lock();
LOCK(pwallet->cs_wallet);
@@ -1346,7 +1337,7 @@ UniValue importmulti(const JSONRPCRequest& mainRequest)
RPCTypeCheck(mainRequest.params, {UniValue::VARR, UniValue::VOBJ});
LegacyScriptPubKeyMan& spk_man = GetLegacyScriptPubKeyMan(*wallet);
EnsureLegacyScriptPubKeyMan(*wallet);
const UniValue& requests = mainRequest.params[0];