15 #include <string_view> 20 const std::string
HELP_REQUIRING_PASSPHRASE{
"\nRequires wallet passphrase to be set with walletpassphrase call if wallet is encrypted.\n"};
24 bool avoid_reuse = param.
isNull() ? can_avoid_reuse : param.
get_bool();
26 if (avoid_reuse && !can_avoid_reuse) {
35 std::string endpoint_wallet;
38 if (wallet_name && *wallet_name != endpoint_wallet) {
40 "The RPC endpoint wallet and the wallet name parameter specify different wallets");
42 return endpoint_wallet;
48 "Either the RPC endpoint wallet or the wallet name parameter must be provided");
51 return std::string{*wallet_name};
69 std::string wallet_name;
71 std::shared_ptr<CWallet> pwallet =
GetWallet(context, wallet_name);
82 RPC_WALLET_NOT_FOUND,
"No wallet is loaded. Load a wallet using loadwallet or create a new one with createwallet. (Note: A default wallet is no longer automatically created)");
85 "Multiple wallets are loaded. Please select which wallet to use by requesting the RPC through the /wallet/<walletname> URI path.");
97 auto wallet_context = util::AnyPtr<WalletContext>(context);
98 if (!wallet_context) {
101 return *wallet_context;
106 static const std::string empty_string;
107 if (value.
isNull())
return empty_string;
109 const std::string& label{value.
get_str()};
118 for (
const auto& desc:
wallet.GetWalletDescriptors(script_pubkey)) {
119 std::string desc_str;
121 if (!
CHECK_NONFATAL(desc.descriptor->ToNormalizedString(dummy_provider, desc_str, &desc.cache)))
continue;
124 entry.
pushKV(
"parent_descs", std::move(parent_descs));
163 lastprocessedblock.pushKV(
"hash",
wallet.GetLastBlockHash().GetHex());
164 lastprocessedblock.pushKV(
"height",
wallet.GetLastBlockHeight());
165 entry.
pushKV(
"lastprocessedblock", std::move(lastprocessedblock));
No wallet specified (error when there are multiple wallets loaded)
void push_back(UniValue val)
Enter the wallet passphrase with walletpassphrase first.
#define CHECK_NONFATAL(condition)
Identity function.
const std::string & get_str() const
std::string UrlDecode(std::string_view url_encoded)
This same wallet is already loaded.
Invalid, missing or duplicate parameter.
void HandleWalletError(const std::shared_ptr< CWallet > &wallet, DatabaseStatus &status, bilingual_str &error)
UniValue JSONRPCError(int code, const std::string &message)
std::string LabelFromValue(const UniValue &value)
enum JSONRPCRequest::Mode mode
std::string EnsureUniqueWalletName(const JSONRPCRequest &request, std::optional< std::string_view > wallet_name)
Ensures that a wallet name is specified across the endpoint and wallet_name.
WalletContext & EnsureWalletContext(const std::any &context)
A CWallet maintains a set of transactions and balances, and provides the ability to create new transa...
Invalid wallet specified.
const std::string HELP_REQUIRING_PASSPHRASE
std::shared_ptr< CWallet > GetWallet(WalletContext &context, const std::string &name)
Failed to encrypt the wallet.
void pushKV(std::string key, UniValue val)
Serialized script, used inside transaction inputs and outputs.
WalletContext struct containing references to state shared between CWallet instances, like the reference to the chain interface, and the list of opened wallets.
bool GetAvoidReuseFlag(const CWallet &wallet, const UniValue ¶m)
void EnsureWalletIsUnlocked(const CWallet &wallet)
There is already a wallet with the same name.
RPCErrorCode
Bitcoin RPC error codes.
void PushParentDescriptors(const CWallet &wallet, const CScript &script_pubkey, UniValue &entry)
Fetch parent descriptors of this scriptPubKey.
std::shared_ptr< CWallet > GetDefaultWallet(WalletContext &context, size_t &count)
static const std::string WALLET_ENDPOINT_BASE
void AppendLastProcessedBlock(UniValue &entry, const CWallet &wallet)
std::shared_ptr< CWallet > GetWalletForJSONRPCRequest(const JSONRPCRequest &request)
Figures out what wallet, if any, to use for a JSONRPCRequest.
bool GetWalletNameFromJSONRPCRequest(const JSONRPCRequest &request, std::string &wallet_name)