mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-02-24 06:19:11 +00:00
Add a new function called EnsureUniqueWalletNamet that returns the selected wallet name across the RPC request endpoint and wallet_name. Supports the case where the wallet_name argument may be omitted—either when using a wallet endpoint, or when not provided at all. In the latter case, if no wallet endpoint is used, an error is raised. Internally reuses the existing implementation to avoid redundant URL decoding and logic duplication. This is a preparatory change for upcoming refactoring of unloadwallet and migratewallet, which will adopt EnsureUniqueWalletName for improved clarity and consistency.
60 lines
2.3 KiB
C++
60 lines
2.3 KiB
C++
// Copyright (c) 2017-present The Bitcoin Core developers
|
|
// Distributed under the MIT software license, see the accompanying
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
#ifndef BITCOIN_WALLET_RPC_UTIL_H
|
|
#define BITCOIN_WALLET_RPC_UTIL_H
|
|
|
|
#include <rpc/util.h>
|
|
#include <script/script.h>
|
|
#include <wallet/wallet.h>
|
|
|
|
#include <any>
|
|
#include <memory>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
class JSONRPCRequest;
|
|
class UniValue;
|
|
struct bilingual_str;
|
|
|
|
namespace wallet {
|
|
class LegacyScriptPubKeyMan;
|
|
enum class DatabaseStatus;
|
|
struct WalletContext;
|
|
|
|
extern const std::string HELP_REQUIRING_PASSPHRASE;
|
|
|
|
static const RPCResult RESULT_LAST_PROCESSED_BLOCK { RPCResult::Type::OBJ, "lastprocessedblock", "hash and height of the block this information was generated on",{
|
|
{RPCResult::Type::STR_HEX, "hash", "hash of the block this information was generated on"},
|
|
{RPCResult::Type::NUM, "height", "height of the block this information was generated on"}}
|
|
};
|
|
|
|
/**
|
|
* Figures out what wallet, if any, to use for a JSONRPCRequest.
|
|
*
|
|
* @param[in] request JSONRPCRequest that wishes to access a wallet
|
|
* @return nullptr if no wallet should be used, or a pointer to the CWallet
|
|
*/
|
|
std::shared_ptr<CWallet> GetWalletForJSONRPCRequest(const JSONRPCRequest& request);
|
|
bool GetWalletNameFromJSONRPCRequest(const JSONRPCRequest& request, std::string& wallet_name);
|
|
/**
|
|
* Ensures that a wallet name is specified across the endpoint and wallet_name.
|
|
* Throws `RPC_INVALID_PARAMETER` if none or different wallet names are specified.
|
|
*/
|
|
std::string EnsureUniqueWalletName(const JSONRPCRequest& request, const std::string* wallet_name);
|
|
|
|
void EnsureWalletIsUnlocked(const CWallet&);
|
|
WalletContext& EnsureWalletContext(const std::any& context);
|
|
|
|
bool GetAvoidReuseFlag(const CWallet& wallet, const UniValue& param);
|
|
std::string LabelFromValue(const UniValue& value);
|
|
//! Fetch parent descriptors of this scriptPubKey.
|
|
void PushParentDescriptors(const CWallet& wallet, const CScript& script_pubkey, UniValue& entry);
|
|
|
|
void HandleWalletError(const std::shared_ptr<CWallet> wallet, DatabaseStatus& status, bilingual_str& error);
|
|
void AppendLastProcessedBlock(UniValue& entry, const CWallet& wallet) EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet);
|
|
} // namespace wallet
|
|
|
|
#endif // BITCOIN_WALLET_RPC_UTIL_H
|