2121#include < util/fees.h>
2222#include < util/system.h>
2323#include < util/moneystr.h>
24+ #include < util/ref.h>
2425#include < util/string.h>
2526#include < util/translation.h>
2627#include < util/url.h>
2728#include < util/validation.h>
2829#include < util/vector.h>
2930#include < validation.h>
3031#include < wallet/coincontrol.h>
32+ #include < wallet/context.h>
3133#include < wallet/psbtwallet.h>
3234#include < wallet/rpcwallet.h>
3335#include < wallet/wallet.h>
@@ -93,6 +95,14 @@ void EnsureWalletIsUnlocked(CWallet * const pwallet)
9395 }
9496}
9597
98+ WalletContext& EnsureWalletContext (const util::Ref& context)
99+ {
100+ if (!context.Has <WalletContext>()) {
101+ throw JSONRPCError (RPC_INTERNAL_ERROR, " Wallet context not found" );
102+ }
103+ return context.Get <WalletContext>();
104+ }
105+
96106static void WalletTxToJSON (interfaces::Chain& chain, interfaces::Chain::Lock& locked_chain, const CWalletTx& wtx, UniValue& entry)
97107{
98108 AssertLockHeld (cs_main); // for mapBlockIndex
@@ -2714,6 +2724,7 @@ static UniValue loadwallet(const JSONRPCRequest& request)
27142724 },
27152725 }.ToString ());
27162726
2727+ WalletContext& context = EnsureWalletContext (request.context );
27172728 WalletLocation location (request.params [0 ].get_str ());
27182729
27192730 if (!location.Exists ()) {
@@ -2728,7 +2739,7 @@ static UniValue loadwallet(const JSONRPCRequest& request)
27282739
27292740 bilingual_str error;
27302741 std::vector<bilingual_str> warnings;
2731- std::shared_ptr<CWallet> const wallet = LoadWallet (*g_rpc_chain , location, error, warnings);
2742+ std::shared_ptr<CWallet> const wallet = LoadWallet (*context. chain , location, error, warnings);
27322743 if (!wallet) throw JSONRPCError (RPC_WALLET_ERROR, error.original );
27332744
27342745 UniValue obj (UniValue::VOBJ);
@@ -2766,6 +2777,7 @@ static UniValue createwallet(const JSONRPCRequest& request)
27662777 throw std::runtime_error (help.ToString ());
27672778 }
27682779
2780+ WalletContext& context = EnsureWalletContext (request.context );
27692781 uint64_t flags = 0 ;
27702782 if (!request.params [1 ].isNull () && request.params [1 ].get_bool ()) {
27712783 flags |= WALLET_FLAG_DISABLE_PRIVATE_KEYS;
@@ -2787,7 +2799,7 @@ static UniValue createwallet(const JSONRPCRequest& request)
27872799
27882800 bilingual_str error;
27892801 std::shared_ptr<CWallet> wallet;
2790- WalletCreationStatus status = CreateWallet (*g_rpc_chain , passphrase, flags, request.params [0 ].get_str (), error, warnings, wallet);
2802+ WalletCreationStatus status = CreateWallet (*context. chain , passphrase, flags, request.params [0 ].get_str (), error, warnings, wallet);
27912803 switch (status) {
27922804 case WalletCreationStatus::CREATION_FAILED:
27932805 throw JSONRPCError (RPC_WALLET_ERROR, error.original );
@@ -3990,10 +4002,7 @@ static const CRPCCommand commands[] =
39904002};
39914003// clang-format on
39924004
3993- void RegisterWalletRPCCommands (interfaces::Chain& chain, std::vector<std::unique_ptr<interfaces::Handler>>& handlers )
4005+ Span< const CRPCCommand> GetWalletRPCCommands ( )
39944006{
3995- for (unsigned int vcidx = 0 ; vcidx < ARRAYLEN (commands); vcidx++)
3996- handlers.emplace_back (chain.handleRpc (commands[vcidx]));
4007+ return MakeSpan (commands);
39974008}
3998-
3999- interfaces::Chain* g_rpc_chain = nullptr ;
0 commit comments