16 #include <boost/date_time/posix_time/posix_time.hpp>
20 const std::string
HELP_REQUIRING_PASSPHRASE{
"\nRequires wallet passphrase to be set with walletpassphrase call if wallet is encrypted.\n"};
24 static const boost::posix_time::ptime epoch = boost::posix_time::from_time_t(0);
25 static const std::locale loc(std::locale::classic(),
26 new boost::posix_time::time_input_facet(
"%Y-%m-%dT%H:%M:%SZ"));
27 std::istringstream iss(str);
29 boost::posix_time::ptime ptime(boost::date_time::not_a_date_time);
31 if (ptime.is_not_a_date_time() || epoch > ptime)
33 return (ptime - epoch).total_seconds();
38 bool avoid_reuse = param.
isNull() ? can_avoid_reuse : param.
get_bool();
40 if (avoid_reuse && !can_avoid_reuse) {
53 if (include_watchonly.
isNull()) {
77 std::string wallet_name;
79 std::shared_ptr<CWallet> pwallet =
GetWallet(context, wallet_name);
90 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)");
93 "Wallet file not specified (must request wallet RPC through /wallet/<filename> uri-path).");
105 auto wallet_context = util::AnyPtr<WalletContext>(context);
106 if (!wallet_context) {
109 return *wallet_context;
116 if (!spk_man && also_create) {
117 spk_man =
wallet.GetOrCreateLegacyScriptPubKeyMan();
139 const std::string& label{value.
get_str()};
148 for (
const auto& desc:
wallet.GetWalletDescriptors(script_pubkey)) {
149 parent_descs.
push_back(desc.descriptor->ToString());
151 entry.
pushKV(
"parent_descs", parent_descs);
185 lastprocessedblock.pushKV(
"hash",
wallet.GetLastBlockHash().GetHex());
186 lastprocessedblock.pushKV(
"height",
wallet.GetLastBlockHeight());
187 entry.pushKV(
"lastprocessedblock", lastprocessedblock);
UrlDecodeFn *const URL_DECODE
#define CHECK_NONFATAL(condition)
Identity function.
Serialized script, used inside transaction inputs and outputs.
enum JSONRPCRequest::Mode mode
void push_back(UniValue val)
const std::string & get_str() const
void pushKV(std::string key, UniValue val)
A CWallet maintains a set of transactions and balances, and provides the ability to create new transa...
void AppendLastProcessedBlock(UniValue &entry, const CWallet &wallet) EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_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)
void HandleWalletError(const std::shared_ptr< CWallet > wallet, DatabaseStatus &status, bilingual_str &error)
void EnsureWalletIsUnlocked(const CWallet &wallet)
const LegacyScriptPubKeyMan & EnsureConstLegacyScriptPubKeyMan(const CWallet &wallet)
const std::string HELP_REQUIRING_PASSPHRASE
void PushParentDescriptors(const CWallet &wallet, const CScript &script_pubkey, UniValue &entry)
Fetch parent descriptors of this scriptPubKey.
LegacyScriptPubKeyMan & EnsureLegacyScriptPubKeyMan(CWallet &wallet, bool also_create)
WalletContext & EnsureWalletContext(const std::any &context)
std::string LabelFromValue(const UniValue &value)
bool ParseIncludeWatchonly(const UniValue &include_watchonly, const CWallet &wallet)
Used by RPC commands that have an include_watchonly parameter.
int64_t ParseISO8601DateTime(const std::string &str)
bool GetAvoidReuseFlag(const CWallet &wallet, const UniValue ¶m)
@ WALLET_FLAG_AVOID_REUSE
@ WALLET_FLAG_DISABLE_PRIVATE_KEYS
std::shared_ptr< CWallet > GetWallet(WalletContext &context, const std::string &name)
static const std::string WALLET_ENDPOINT_BASE
@ FAILED_INVALID_BACKUP_FILE
std::shared_ptr< CWallet > GetDefaultWallet(WalletContext &context, size_t &count)
std::shared_ptr< CWallet > wallet
UniValue JSONRPCError(int code, const std::string &message)
RPCErrorCode
Bitcoin RPC error codes.
@ RPC_WALLET_NOT_SPECIFIED
No wallet specified (error when there are multiple wallets loaded)
@ RPC_WALLET_INVALID_LABEL_NAME
Invalid label name.
@ RPC_WALLET_UNLOCK_NEEDED
Enter the wallet passphrase with walletpassphrase first.
@ RPC_WALLET_ALREADY_EXISTS
There is already a wallet with the same name.
@ RPC_INVALID_PARAMETER
Invalid, missing or duplicate parameter.
@ RPC_WALLET_ERROR
Wallet errors.
@ RPC_WALLET_ALREADY_LOADED
This same wallet is already loaded.
@ RPC_WALLET_NOT_FOUND
Invalid wallet specified.
WalletContext struct containing references to state shared between CWallet instances,...
static const std::string empty_string
#define EXCLUSIVE_LOCKS_REQUIRED(...)