5#include <bitcoin-build-config.h>
25 "Returns a new Bitcoin address for receiving payments.\n"
26 "If 'label' is specified, it is added to the address book \n"
27 "so payments received with the address will be associated with 'label'.\n",
29 {
"label",
RPCArg::Type::STR,
RPCArg::Default{
""},
"The label name for the address to be linked to. It can also be set to the empty string \"\" to represent the default label. The label does not need to exist, it will be created if there is no label by the given name."},
44 LOCK(pwallet->cs_wallet);
46 if (!pwallet->CanGetAddresses()) {
54 if (!request.params[1].isNull()) {
75 "getrawchangeaddress",
76 "Returns a new Bitcoin address, for receiving change.\n"
77 "This is for use with raw transactions, NOT normal use.\n",
93 LOCK(pwallet->cs_wallet);
95 if (!pwallet->CanGetAddresses(
true)) {
100 if (!request.params[0].isNull()) {
122 "Sets the label associated with the given address.\n",
137 LOCK(pwallet->cs_wallet);
146 if (pwallet->IsMine(dest)) {
160 "listaddressgroupings",
161 "Lists groups of addresses which have had their common ownership\n"
162 "made public by common use as inputs or as the resulting change\n"
163 "in past transactions\n",
190 pwallet->BlockUntilSyncedToCurrentChain();
192 LOCK(pwallet->cs_wallet);
221 "Refills each descriptor keypool in the wallet up to the specified number of new keys.\n"
237 LOCK(pwallet->cs_wallet);
241 if (!request.params[0].isNull()) {
242 if (request.params[0].getInt<
int>() < 0)
244 kpSize = (
unsigned int)request.params[0].getInt<
int>();
248 pwallet->TopUpKeyPool(
kpSize);
250 if (pwallet->GetKeyPoolSize() <
kpSize) {
253 pwallet->RefreshAllTXOs();
286 obj.pushKV(
"embedded", std::move(
subobj));
295 obj.pushKV(
"pubkeys", std::move(pubkeys));
344 hasher.Write(
id.begin(), 32).Finalize(hash.
begin());
361 std::unique_ptr<SigningProvider>
provider =
nullptr;
378 "The output script type. Only if isscript is true and the redeemscript is known. Possible\n"
379 "types: nonstandard, pubkey, pubkeyhash, scripthash, multisig, nulldata, witness_v0_keyhash,\n"
380 "witness_v0_scripthash, witness_unknown."},
383 "Array of pubkeys associated with the known redeemscript (only if script is multisig).",
388 "The number of signatures required to spend multisig output (only if script is multisig)."},
390 "The hex value of the raw public key for single-key addresses (possibly embedded in P2SH or P2WSH)."},
405 "Information about the address embedded in P2SH or P2WSH, if relevant and known.",
417 "Return information about the given bitcoin address.\n"
418 "Some of the information will only be present if the address is in the active wallet.\n",
429 {
RPCResult::Type::BOOL,
"solvable",
"If we know how to spend coins sent to this address, ignoring the possible lack of private keys."},
430 {
RPCResult::Type::STR,
"desc",
true,
"A descriptor for spending coins sent to this address (only when solvable)."},
431 {
RPCResult::Type::STR,
"parent_desc",
true,
"The descriptor used to derive this address if this is a descriptor wallet"},
437 {
RPCResult::Type::STR,
"script",
true,
"The output script type. Only if isscript is true and the redeemscript is known. Possible\n"
438 "types: nonstandard, pubkey, pubkeyhash, scripthash, multisig, nulldata, witness_v0_keyhash,\n"
439 "witness_v0_scripthash, witness_unknown."},
441 {
RPCResult::Type::ARR,
"pubkeys",
true,
"Array of pubkeys associated with the known redeemscript (only if script is multisig).",
445 {
RPCResult::Type::NUM,
"sigsrequired",
true,
"The number of signatures required to spend multisig output (only if script is multisig)."},
446 {
RPCResult::Type::STR_HEX,
"pubkey",
true,
"The hex value of the raw public key for single-key addresses (possibly embedded in P2SH or P2WSH)."},
448 "Information about the address embedded in P2SH or P2WSH, if relevant and known.",
451 "Includes all getaddressinfo output fields for the embedded address, excluding metadata (timestamp, hdkeypath, hdseedid)\n"
452 "and relation to the wallet (ismine)."
459 {
RPCResult::Type::ARR,
"labels",
"Array of labels associated with the address. Currently limited to one label but returned\n"
460 "as an array to keep the API stable if multiple labels are enabled in the future.",
475 LOCK(pwallet->cs_wallet);
494 ret.pushKV(
"scriptPubKey",
HexStr(scriptPubKey));
496 std::unique_ptr<SigningProvider>
provider = pwallet->GetSolvingProvider(scriptPubKey);
498 bool mine = pwallet->IsMine(dest);
503 bool solvable =
inferred->IsSolvable();
504 ret.pushKV(
"solvable", solvable);
509 ret.pushKV(
"solvable",
false);
512 const auto&
spk_mans = pwallet->GetScriptPubKeyMans(scriptPubKey);
525 ret.pushKV(
"iswatchonly",
false);
533 if (
const std::unique_ptr<CKeyMetadata>
meta =
spk_man->GetMetadata(dest)) {
534 ret.pushKV(
"timestamp",
meta->nCreateTime);
535 if (
meta->has_key_origin) {
539 ret.pushKV(
"hdseedid",
meta->hd_seed_id.GetHex());
540 ret.pushKV(
"hdmasterfingerprint",
HexStr(
meta->key_origin.fingerprint));
565 "getaddressesbylabel",
566 "Returns the list of addresses assigned the specified label.\n",
575 {
RPCResult::Type::STR,
"purpose",
"Purpose of address (\"send\" for sending address, \"receive\" for receiving address)"},
588 LOCK(pwallet->cs_wallet);
610 ret.pushKVEnd(address, std::move(value));
627 "Returns the list of all labels, or labels that are assigned to addresses with a specific purpose.\n",
638 "\nList all labels\n"
640 "\nList labels that have receiving addresses\n"
642 "\nList labels that have sending addresses\n"
644 "\nAs a JSON-RPC call\n"
652 LOCK(pwallet->cs_wallet);
654 std::optional<AddressPurpose> purpose;
655 if (!request.params[0].isNull()) {
656 std::string
purpose_str = request.params[0].get_str();
666 std::set<std::string>
label_set = pwallet->ListAddrBookLabels(purpose);
679#ifdef ENABLE_EXTERNAL_SIGNER
683 "walletdisplayaddress",
684 "Display address on an external signer for verification.",
714 result.
pushKV(
"address", request.params[0].get_str());
CScriptID ToScriptID(const ScriptHash &script_hash)
bool ExtractDestination(const CScript &scriptPubKey, CTxDestination &addressRet)
Parse a scriptPubKey for the destination.
bool IsValidDestination(const CTxDestination &dest)
Check whether a CTxDestination corresponds to one with an address.
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a Bitcoin scriptPubKey for the given CTxDestination.
CKeyID ToKeyID(const PKHash &key_hash)
std::variant< CNoDestination, PubKeyDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessV1Taproot, PayToAnchor, WitnessUnknown > CTxDestination
A txout script categorized into standard templates.
std::string WriteHDKeypath(const std::vector< uint32_t > &keypath, bool apostrophe)
Write HD keypaths as strings.
#define CHECK_NONFATAL(condition)
Identity function.
A reference to a CKey: the Hash160 of its serialized public key.
An encapsulated public key.
A hasher class for RIPEMD-160.
Serialized script, used inside transaction inputs and outputs.
A reference to a CScript: the Hash160 of its serialization.
An interface to be implemented by keystores that support signing.
virtual bool GetCScript(const CScriptID &scriptid, CScript &script) const
virtual bool GetPubKey(const CKeyID &address, CPubKey &pubkey) const
void push_back(UniValue val)
void pushKV(std::string key, UniValue val)
constexpr unsigned char * begin()
A CWallet maintains a set of transactions and balances, and provides the ability to create new transa...
RecursiveMutex cs_wallet
Main wallet lock.
util::Result< void > DisplayAddress(const CTxDestination &dest) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Display address on an external signer.
UniValue operator()(const PayToAnchor &id) const
UniValue operator()(const PKHash &pkhash) const
UniValue operator()(const WitnessV0ScriptHash &id) const
UniValue operator()(const WitnessV1Taproot &id) const
const SigningProvider *const provider
UniValue operator()(const WitnessV0KeyHash &id) const
UniValue operator()(const WitnessUnknown &id) const
DescribeWalletAddressVisitor(const SigningProvider *_provider)
void ProcessSubScript(const CScript &subscript, UniValue &obj) const
UniValue operator()(const CNoDestination &dest) const
UniValue operator()(const ScriptHash &scripthash) const
UniValue operator()(const PubKeyDestination &dest) const
UniValue ValueFromAmount(const CAmount amount)
const std::string CURRENCY_UNIT
std::string HexStr(const std::span< const uint8_t > s)
Convert a span of bytes to a lower-case hexadecimal string.
CTxDestination DecodeDestination(const std::string &str, std::string &error_msg, std::vector< int > *error_locations)
std::string EncodeDestination(const CTxDestination &dest)
bilingual_str ErrorString(const Result< T > &result)
std::string ToString(const T &t)
Locale-independent version of std::to_string.
static std::vector< RPCResult > GetAddressInfoEmbeddedFields(bool include_nested)
static std::vector< RPCResult > GetAddressInfoBaseFields()
constexpr unsigned int DEFAULT_KEYPOOL_SIZE
Default for -keypool.
std::shared_ptr< CWallet > GetWalletForJSONRPCRequest(const JSONRPCRequest &request)
Figures out what wallet, if any, to use for a JSONRPCRequest.
bool ScriptIsChange(const CWallet &wallet, const CScript &script)
void EnsureWalletIsUnlocked(const CWallet &wallet)
const std::string HELP_REQUIRING_PASSPHRASE
RPCMethod getaddressinfo()
RPCMethod walletdisplayaddress()
RPCMethod listaddressgroupings()
RPCMethod keypoolrefill()
std::string LabelFromValue(const UniValue &value)
static UniValue DescribeWalletAddress(const CWallet &wallet, const CTxDestination &dest)
std::string PurposeToString(AddressPurpose p)
RPCMethod getaddressesbylabel()
std::map< CTxDestination, CAmount > GetAddressBalances(const CWallet &wallet)
RPCMethod getrawchangeaddress()
std::optional< AddressPurpose > PurposeFromString(std::string_view s)
RPCMethod getnewaddress()
std::set< std::set< CTxDestination > > GetAddressGroupings(const CWallet &wallet)
std::optional< OutputType > ParseOutputType(std::string_view type)
std::string FormatAllOutputTypes()
UniValue JSONRPCError(int code, const std::string &message)
@ RPC_WALLET_INVALID_LABEL_NAME
Invalid label name.
@ RPC_MISC_ERROR
General application defined errors.
@ RPC_INVALID_PARAMETER
Invalid, missing or duplicate parameter.
@ RPC_WALLET_ERROR
Wallet errors.
@ RPC_WALLET_KEYPOOL_RAN_OUT
Keypool ran out, call keypoolrefill first.
@ RPC_INVALID_ADDRESS_OR_KEY
Invalid address or key.
std::string HelpExampleCli(const std::string &methodname, const std::string &args)
std::vector< RPCResult > ElideGroup(std::vector< RPCResult > fields, std::string summary)
Stamp elision onto an entire vector of RPCResult fields at once.
std::string HelpExampleRpc(const std::string &methodname, const std::string &args)
const std::string UNIX_EPOCH_TIME
String used to describe UNIX epoch time in documentation, factored out to a constant for consistency.
const std::string EXAMPLE_ADDRESS[2]
Example bech32 addresses for the RPCExamples help documentation.
UniValue DescribeAddress(const CTxDestination &dest)
std::unique_ptr< Descriptor > InferDescriptor(const CScript &script, const SigningProvider &provider)
Find a descriptor for the specified script, using information from provider where possible.
TxoutType Solver(const CScript &scriptPubKey, std::vector< std::vector< unsigned char > > &vSolutionsRet)
Parse a scriptPubKey and identify script type for standard scripts.
std::string GetTxnOutputType(TxoutType t)
Get the name of a TxoutType as a string.
std::string DefaultHint
Hint for default value.
@ OMITTED
Optional argument for which the default value is omitted from help text for one of two reasons:
@ NUM_TIME
Special numeric to denote unix epoch time.
@ ARR_FIXED
Special array that has a fixed number of entries.
@ OBJ_DYN
Special dictionary with keys that are not literals.
@ STR_HEX
Special string with only hex chars.
@ STR_AMOUNT
Special string to represent a floating point amount.
CTxDestination subtype to encode any future Witness version.
FuzzedDataProvider provider
constexpr auto Ticks(Dur2 d)
Helper to count the seconds of a duration/time_point.