refactor: replace RegisterWalletRPCCommands with GetWalletRPCCommands

pull/19096/head
Russell Yanofsky 5 years ago
parent 55b4c65bd1
commit e783197bf0

@ -9,6 +9,7 @@
#include <interfaces/handler.h> #include <interfaces/handler.h>
#include <policy/fees.h> #include <policy/fees.h>
#include <primitives/transaction.h> #include <primitives/transaction.h>
#include <rpc/server.h>
#include <script/standard.h> #include <script/standard.h>
#include <support/allocators/secure.h> #include <support/allocators/secure.h>
#include <sync.h> #include <sync.h>
@ -487,7 +488,9 @@ public:
void registerRpcs() override void registerRpcs() override
{ {
g_rpc_chain = &m_chain; g_rpc_chain = &m_chain;
return RegisterWalletRPCCommands(m_chain, m_rpc_handlers); for (const CRPCCommand& command : GetWalletRPCCommands()) {
m_rpc_handlers.emplace_back(m_chain.handleRpc(command));
}
} }
bool verify() override { return VerifyWallets(m_chain, m_wallet_filenames); } bool verify() override { return VerifyWallets(m_chain, m_wallet_filenames); }
bool load() override { return LoadWallets(m_chain, m_wallet_filenames); } bool load() override { return LoadWallets(m_chain, m_wallet_filenames); }

@ -4263,7 +4263,7 @@ UniValue removeprunedfunds(const JSONRPCRequest& request);
UniValue importmulti(const JSONRPCRequest& request); UniValue importmulti(const JSONRPCRequest& request);
UniValue importdescriptors(const JSONRPCRequest& request); UniValue importdescriptors(const JSONRPCRequest& request);
void RegisterWalletRPCCommands(interfaces::Chain& chain, std::vector<std::unique_ptr<interfaces::Handler>>& handlers) Span<const CRPCCommand> GetWalletRPCCommands()
{ {
// clang-format off // clang-format off
static const CRPCCommand commands[] = static const CRPCCommand commands[] =
@ -4329,9 +4329,7 @@ static const CRPCCommand commands[] =
{ "wallet", "walletprocesspsbt", &walletprocesspsbt, {"psbt","sign","sighashtype","bip32derivs"} }, { "wallet", "walletprocesspsbt", &walletprocesspsbt, {"psbt","sign","sighashtype","bip32derivs"} },
}; };
// clang-format on // clang-format on
return MakeSpan(commands);
for (unsigned int vcidx = 0; vcidx < ARRAYLEN(commands); vcidx++)
handlers.emplace_back(chain.handleRpc(commands[vcidx]));
} }
interfaces::Chain* g_rpc_chain = nullptr; interfaces::Chain* g_rpc_chain = nullptr;

@ -5,11 +5,13 @@
#ifndef BITCOIN_WALLET_RPCWALLET_H #ifndef BITCOIN_WALLET_RPCWALLET_H
#define BITCOIN_WALLET_RPCWALLET_H #define BITCOIN_WALLET_RPCWALLET_H
#include <span.h>
#include <memory> #include <memory>
#include <string> #include <string>
#include <vector> #include <vector>
class CRPCTable; class CRPCCommand;
class CWallet; class CWallet;
class JSONRPCRequest; class JSONRPCRequest;
class LegacyScriptPubKeyMan; class LegacyScriptPubKeyMan;
@ -19,7 +21,6 @@ class CTransaction;
namespace interfaces { namespace interfaces {
class Chain; class Chain;
class Handler;
} }
//! Pointer to chain interface that needs to be declared as a global to be //! Pointer to chain interface that needs to be declared as a global to be
@ -27,8 +28,7 @@ class Handler;
//! RPC framework, there's currently no direct way to pass in state to RPC //! RPC framework, there's currently no direct way to pass in state to RPC
//! methods without globals. //! methods without globals.
extern interfaces::Chain* g_rpc_chain; extern interfaces::Chain* g_rpc_chain;
Span<const CRPCCommand> GetWalletRPCCommands();
void RegisterWalletRPCCommands(interfaces::Chain& chain, std::vector<std::unique_ptr<interfaces::Handler>>& handlers);
/** /**
* Figures out what wallet, if any, to use for a JSONRPCRequest. * Figures out what wallet, if any, to use for a JSONRPCRequest.

Loading…
Cancel
Save