Bitcoin Core  27.99.0
P2P Digital Currency
util.h
Go to the documentation of this file.
1 // Copyright (c) 2017-2022 The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
5 #ifndef BITCOIN_WALLET_RPC_UTIL_H
6 #define BITCOIN_WALLET_RPC_UTIL_H
7 
8 #include <rpc/util.h>
9 #include <script/script.h>
10 #include <wallet/wallet.h>
11 
12 #include <any>
13 #include <memory>
14 #include <string>
15 #include <vector>
16 
17 class JSONRPCRequest;
18 class UniValue;
19 struct bilingual_str;
20 
21 namespace wallet {
22 class LegacyScriptPubKeyMan;
23 enum class DatabaseStatus;
24 struct WalletContext;
25 
26 extern const std::string HELP_REQUIRING_PASSPHRASE;
27 
28 static const RPCResult RESULT_LAST_PROCESSED_BLOCK { RPCResult::Type::OBJ, "lastprocessedblock", "hash and height of the block this information was generated on",{
29  {RPCResult::Type::STR_HEX, "hash", "hash of the block this information was generated on"},
30  {RPCResult::Type::NUM, "height", "height of the block this information was generated on"}}
31 };
32 
39 std::shared_ptr<CWallet> GetWalletForJSONRPCRequest(const JSONRPCRequest& request);
40 bool GetWalletNameFromJSONRPCRequest(const JSONRPCRequest& request, std::string& wallet_name);
41 
42 void EnsureWalletIsUnlocked(const CWallet&);
43 WalletContext& EnsureWalletContext(const std::any& context);
44 LegacyScriptPubKeyMan& EnsureLegacyScriptPubKeyMan(CWallet& wallet, bool also_create = false);
45 const LegacyScriptPubKeyMan& EnsureConstLegacyScriptPubKeyMan(const CWallet& wallet);
46 
47 bool GetAvoidReuseFlag(const CWallet& wallet, const UniValue& param);
48 bool ParseIncludeWatchonly(const UniValue& include_watchonly, const CWallet& wallet);
49 std::string LabelFromValue(const UniValue& value);
51 void PushParentDescriptors(const CWallet& wallet, const CScript& script_pubkey, UniValue& entry);
52 
53 void HandleWalletError(const std::shared_ptr<CWallet> wallet, DatabaseStatus& status, bilingual_str& error);
54 int64_t ParseISO8601DateTime(const std::string& str);
55 void AppendLastProcessedBlock(UniValue& entry, const CWallet& wallet) EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet);
56 } // namespace wallet
57 
58 #endif // BITCOIN_WALLET_RPC_UTIL_H
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:414
void AppendLastProcessedBlock(UniValue &entry, const CWallet &wallet) EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet)
Definition: util.cpp:181
std::shared_ptr< CWallet > GetWalletForJSONRPCRequest(const JSONRPCRequest &request)
Figures out what wallet, if any, to use for a JSONRPCRequest.
Definition: util.cpp:72
static const RPCResult RESULT_LAST_PROCESSED_BLOCK
Definition: util.h:28
bool GetWalletNameFromJSONRPCRequest(const JSONRPCRequest &request, std::string &wallet_name)
Definition: util.cpp:62
void HandleWalletError(const std::shared_ptr< CWallet > wallet, DatabaseStatus &status, bilingual_str &error)
Definition: util.cpp:154
void EnsureWalletIsUnlocked(const CWallet &wallet)
Definition: util.cpp:96
const LegacyScriptPubKeyMan & EnsureConstLegacyScriptPubKeyMan(const CWallet &wallet)
Definition: util.cpp:125
const std::string HELP_REQUIRING_PASSPHRASE
Definition: util.cpp:20
void PushParentDescriptors(const CWallet &wallet, const CScript &script_pubkey, UniValue &entry)
Fetch parent descriptors of this scriptPubKey.
Definition: util.cpp:145
LegacyScriptPubKeyMan & EnsureLegacyScriptPubKeyMan(CWallet &wallet, bool also_create)
Definition: util.cpp:113
WalletContext & EnsureWalletContext(const std::any &context)
Definition: util.cpp:103
std::string LabelFromValue(const UniValue &value)
Definition: util.cpp:134
bool ParseIncludeWatchonly(const UniValue &include_watchonly, const CWallet &wallet)
Used by RPC commands that have an include_watchonly parameter.
Definition: util.cpp:51
int64_t ParseISO8601DateTime(const std::string &str)
Definition: util.cpp:22
bool GetAvoidReuseFlag(const CWallet &wallet, const UniValue &param)
Definition: util.cpp:36
DatabaseStatus
Definition: db.h:196
@ STR_HEX
Special string with only hex chars.
Bilingual messages:
Definition: translation.h:18
#define EXCLUSIVE_LOCKS_REQUIRED(...)
Definition: threadsafety.h:49