Skip to content

Commit e783197

Browse files
committed
refactor: replace RegisterWalletRPCCommands with GetWalletRPCCommands
1 parent 55b4c65 commit e783197

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

src/interfaces/wallet.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <interfaces/handler.h>
1010
#include <policy/fees.h>
1111
#include <primitives/transaction.h>
12+
#include <rpc/server.h>
1213
#include <script/standard.h>
1314
#include <support/allocators/secure.h>
1415
#include <sync.h>
@@ -487,7 +488,9 @@ class WalletClientImpl : public ChainClient
487488
void registerRpcs() override
488489
{
489490
g_rpc_chain = &m_chain;
490-
return RegisterWalletRPCCommands(m_chain, m_rpc_handlers);
491+
for (const CRPCCommand& command : GetWalletRPCCommands()) {
492+
m_rpc_handlers.emplace_back(m_chain.handleRpc(command));
493+
}
491494
}
492495
bool verify() override { return VerifyWallets(m_chain, m_wallet_filenames); }
493496
bool load() override { return LoadWallets(m_chain, m_wallet_filenames); }

src/wallet/rpcwallet.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4263,7 +4263,7 @@ UniValue removeprunedfunds(const JSONRPCRequest& request);
42634263
UniValue importmulti(const JSONRPCRequest& request);
42644264
UniValue importdescriptors(const JSONRPCRequest& request);
42654265

4266-
void RegisterWalletRPCCommands(interfaces::Chain& chain, std::vector<std::unique_ptr<interfaces::Handler>>& handlers)
4266+
Span<const CRPCCommand> GetWalletRPCCommands()
42674267
{
42684268
// clang-format off
42694269
static const CRPCCommand commands[] =
@@ -4329,9 +4329,7 @@ static const CRPCCommand commands[] =
43294329
{ "wallet", "walletprocesspsbt", &walletprocesspsbt, {"psbt","sign","sighashtype","bip32derivs"} },
43304330
};
43314331
// clang-format on
4332-
4333-
for (unsigned int vcidx = 0; vcidx < ARRAYLEN(commands); vcidx++)
4334-
handlers.emplace_back(chain.handleRpc(commands[vcidx]));
4332+
return MakeSpan(commands);
43354333
}
43364334

43374335
interfaces::Chain* g_rpc_chain = nullptr;

src/wallet/rpcwallet.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55
#ifndef BITCOIN_WALLET_RPCWALLET_H
66
#define BITCOIN_WALLET_RPCWALLET_H
77

8+
#include <span.h>
9+
810
#include <memory>
911
#include <string>
1012
#include <vector>
1113

12-
class CRPCTable;
14+
class CRPCCommand;
1315
class CWallet;
1416
class JSONRPCRequest;
1517
class LegacyScriptPubKeyMan;
@@ -19,16 +21,14 @@ class CTransaction;
1921

2022
namespace interfaces {
2123
class Chain;
22-
class Handler;
2324
}
2425

2526
//! Pointer to chain interface that needs to be declared as a global to be
2627
//! accessible loadwallet and createwallet methods. Due to limitations of the
2728
//! RPC framework, there's currently no direct way to pass in state to RPC
2829
//! methods without globals.
2930
extern interfaces::Chain* g_rpc_chain;
30-
31-
void RegisterWalletRPCCommands(interfaces::Chain& chain, std::vector<std::unique_ptr<interfaces::Handler>>& handlers);
31+
Span<const CRPCCommand> GetWalletRPCCommands();
3232

3333
/**
3434
* Figures out what wallet, if any, to use for a JSONRPCRequest.

0 commit comments

Comments
 (0)