mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-06-08 05:39:38 +02:00
Avoid using g_rpc_node global in wallet code
Wallet code should use interfaces::Chain and not directly access to node state. Add a g_rpc_chain replacement global for wallet code to use, and move g_rpc_node definition to a libbitcoin_server source file so there are link errors if wallet code tries to access it.
This commit is contained in:
@@ -2574,7 +2574,7 @@ static UniValue loadwallet(const JSONRPCRequest& request)
|
||||
|
||||
std::string error;
|
||||
std::vector<std::string> warning;
|
||||
std::shared_ptr<CWallet> const wallet = LoadWallet(*g_rpc_node->chain, location, error, warning);
|
||||
std::shared_ptr<CWallet> const wallet = LoadWallet(*g_rpc_chain, location, error, warning);
|
||||
if (!wallet) throw JSONRPCError(RPC_WALLET_ERROR, error);
|
||||
|
||||
UniValue obj(UniValue::VOBJ);
|
||||
@@ -2700,7 +2700,7 @@ static UniValue createwallet(const JSONRPCRequest& request)
|
||||
|
||||
std::string error;
|
||||
std::shared_ptr<CWallet> wallet;
|
||||
WalletCreationStatus status = CreateWallet(*g_rpc_node->chain, passphrase, flags, request.params[0].get_str(), error, warnings, wallet);
|
||||
WalletCreationStatus status = CreateWallet(*g_rpc_chain, passphrase, flags, request.params[0].get_str(), error, warnings, wallet);
|
||||
switch (status) {
|
||||
case WalletCreationStatus::CREATION_FAILED:
|
||||
throw JSONRPCError(RPC_WALLET_ERROR, error);
|
||||
@@ -4231,3 +4231,5 @@ void RegisterWalletRPCCommands(interfaces::Chain& chain, std::vector<std::unique
|
||||
for (unsigned int vcidx = 0; vcidx < ARRAYLEN(commands); vcidx++)
|
||||
handlers.emplace_back(chain.handleRpc(commands[vcidx]));
|
||||
}
|
||||
|
||||
interfaces::Chain* g_rpc_chain = nullptr;
|
||||
|
||||
@@ -21,6 +21,12 @@ class Chain;
|
||||
class Handler;
|
||||
}
|
||||
|
||||
//! Pointer to chain interface that needs to be declared as a global to be
|
||||
//! accessible loadwallet and createwallet methods. Due to limitations of the
|
||||
//! RPC framework, there's currently no direct way to pass in state to RPC
|
||||
//! methods without globals.
|
||||
extern interfaces::Chain* g_rpc_chain;
|
||||
|
||||
void RegisterWalletRPCCommands(interfaces::Chain& chain, std::vector<std::unique_ptr<interfaces::Handler>>& handlers);
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user