mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-03-30 18:35:54 +02:00
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 25ad2c623a
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>
This commit is contained in:
@@ -21,12 +21,14 @@
|
||||
#include <util/fees.h>
|
||||
#include <util/message.h> // For MessageSign()
|
||||
#include <util/moneystr.h>
|
||||
#include <util/ref.h>
|
||||
#include <util/string.h>
|
||||
#include <util/system.h>
|
||||
#include <util/translation.h>
|
||||
#include <util/url.h>
|
||||
#include <util/vector.h>
|
||||
#include <wallet/coincontrol.h>
|
||||
#include <wallet/context.h>
|
||||
#include <wallet/feebumper.h>
|
||||
#include <wallet/rpcwallet.h>
|
||||
#include <wallet/wallet.h>
|
||||
@@ -121,6 +123,14 @@ void EnsureWalletIsUnlocked(const CWallet* pwallet)
|
||||
}
|
||||
}
|
||||
|
||||
WalletContext& EnsureWalletContext(const util::Ref& context)
|
||||
{
|
||||
if (!context.Has<WalletContext>()) {
|
||||
throw JSONRPCError(RPC_INTERNAL_ERROR, "Wallet context not found");
|
||||
}
|
||||
return context.Get<WalletContext>();
|
||||
}
|
||||
|
||||
// also_create should only be set to true only when the RPC is expected to add things to a blank wallet and make it no longer blank
|
||||
LegacyScriptPubKeyMan& EnsureLegacyScriptPubKeyMan(CWallet& wallet, bool also_create)
|
||||
{
|
||||
@@ -2584,6 +2594,7 @@ static UniValue loadwallet(const JSONRPCRequest& request)
|
||||
},
|
||||
}.Check(request);
|
||||
|
||||
WalletContext& context = EnsureWalletContext(request.context);
|
||||
WalletLocation location(request.params[0].get_str());
|
||||
|
||||
if (!location.Exists()) {
|
||||
@@ -2598,7 +2609,7 @@ static UniValue loadwallet(const JSONRPCRequest& request)
|
||||
|
||||
bilingual_str error;
|
||||
std::vector<bilingual_str> warnings;
|
||||
std::shared_ptr<CWallet> const wallet = LoadWallet(*g_rpc_chain, location, error, warnings);
|
||||
std::shared_ptr<CWallet> const wallet = LoadWallet(*context.chain, location, error, warnings);
|
||||
if (!wallet) throw JSONRPCError(RPC_WALLET_ERROR, error.original);
|
||||
|
||||
UniValue obj(UniValue::VOBJ);
|
||||
@@ -2702,6 +2713,7 @@ static UniValue createwallet(const JSONRPCRequest& request)
|
||||
},
|
||||
}.Check(request);
|
||||
|
||||
WalletContext& context = EnsureWalletContext(request.context);
|
||||
uint64_t flags = 0;
|
||||
if (!request.params[1].isNull() && request.params[1].get_bool()) {
|
||||
flags |= WALLET_FLAG_DISABLE_PRIVATE_KEYS;
|
||||
@@ -2731,7 +2743,7 @@ static UniValue createwallet(const JSONRPCRequest& request)
|
||||
|
||||
bilingual_str error;
|
||||
std::shared_ptr<CWallet> wallet;
|
||||
WalletCreationStatus status = CreateWallet(*g_rpc_chain, passphrase, flags, request.params[0].get_str(), error, warnings, wallet);
|
||||
WalletCreationStatus status = CreateWallet(*context.chain, passphrase, flags, request.params[0].get_str(), error, warnings, wallet);
|
||||
switch (status) {
|
||||
case WalletCreationStatus::CREATION_FAILED:
|
||||
throw JSONRPCError(RPC_WALLET_ERROR, error.original);
|
||||
@@ -4331,5 +4343,3 @@ static const CRPCCommand commands[] =
|
||||
// clang-format on
|
||||
return MakeSpan(commands);
|
||||
}
|
||||
|
||||
interfaces::Chain* g_rpc_chain = nullptr;
|
||||
|
||||
Reference in New Issue
Block a user