diff options
author | Russell Yanofsky <russ@yanofsky.org> | 2020-05-28 02:13:19 -0400 |
---|---|---|
committer | Russell Yanofsky <russ@yanofsky.org> | 2020-05-28 02:13:19 -0400 |
commit | 4a7253ab6c3bb323581cea54573529c2f823f035 (patch) | |
tree | 026a1a071a230352a7673f5be38ba1c1b8935550 /src/interfaces | |
parent | e783197bf0f7429f80fea94b44c59857bc8cfef9 (diff) |
Remove g_rpc_chain global
Replace with RPC request reference to new WalletContext struct similar to the
existing NodeContext struct and reference.
This PR is a followup to 25ad2c623af30056ffb36dcd203a52edda2b170f
https://github.com/bitcoin/bitcoin/pull/18740 removing the g_rpc_node global.
Some later PRs will follow this up and move more wallet globals to the
WalletContext struct.
Co-authored-by: João Barbosa <joao.paulo.barbosa@gmail.com>
Diffstat (limited to 'src/interfaces')
-rw-r--r-- | src/interfaces/wallet.cpp | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/src/interfaces/wallet.cpp b/src/interfaces/wallet.cpp index 9e5b357f69..7b907b2a0b 100644 --- a/src/interfaces/wallet.cpp +++ b/src/interfaces/wallet.cpp @@ -16,7 +16,9 @@ #include <ui_interface.h> #include <uint256.h> #include <util/check.h> +#include <util/ref.h> #include <util/system.h> +#include <wallet/context.h> #include <wallet/feebumper.h> #include <wallet/fees.h> #include <wallet/ismine.h> @@ -482,18 +484,21 @@ class WalletClientImpl : public ChainClient { public: WalletClientImpl(Chain& chain, std::vector<std::string> wallet_filenames) - : m_chain(chain), m_wallet_filenames(std::move(wallet_filenames)) + : m_wallet_filenames(std::move(wallet_filenames)) { + m_context.chain = &chain; } void registerRpcs() override { - g_rpc_chain = &m_chain; for (const CRPCCommand& command : GetWalletRPCCommands()) { - m_rpc_handlers.emplace_back(m_chain.handleRpc(command)); + m_rpc_commands.emplace_back(command.category, command.name, [this, &command](const JSONRPCRequest& request, UniValue& result, bool last_handler) { + return command.actor({request, m_context}, result, last_handler); + }, command.argNames, command.unique_id); + m_rpc_handlers.emplace_back(m_context.chain->handleRpc(m_rpc_commands.back())); } } - bool verify() override { return VerifyWallets(m_chain, m_wallet_filenames); } - bool load() override { return LoadWallets(m_chain, m_wallet_filenames); } + bool verify() override { return VerifyWallets(*m_context.chain, m_wallet_filenames); } + bool load() override { return LoadWallets(*m_context.chain, m_wallet_filenames); } void start(CScheduler& scheduler) override { return StartWallets(scheduler); } void flush() override { return FlushWallets(); } void stop() override { return StopWallets(); } @@ -508,9 +513,10 @@ public: } ~WalletClientImpl() override { UnloadWallets(); } - Chain& m_chain; + WalletContext m_context; std::vector<std::string> m_wallet_filenames; std::vector<std::unique_ptr<Handler>> m_rpc_handlers; + std::list<CRPCCommand> m_rpc_commands; }; } // namespace |