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()) {
53 OutputType output_type = pwallet->m_default_address_type;
54 if (!request.params[1].isNull()) {
55 std::optional<OutputType> parsed =
ParseOutputType(request.params[1].get_str());
59 output_type = parsed.value();
62 auto op_dest = pwallet->GetNewDestination(output_type, label);
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)) {
99 OutputType output_type = pwallet->m_default_change_type.value_or(pwallet->m_default_address_type);
100 if (!request.params[0].isNull()) {
101 std::optional<OutputType> parsed =
ParseOutputType(request.params[0].get_str());
105 output_type = parsed.value();
108 auto op_dest = pwallet->GetNewChangeDestination(output_type);
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);
204 const auto* address_book_entry = pwallet->FindAddressBookEntry(address);
205 if (address_book_entry) {
206 addressInfo.
push_back(address_book_entry->GetLabel());
209 jsonGrouping.
push_back(std::move(addressInfo));
211 jsonGroupings.
push_back(std::move(jsonGrouping));
213 return jsonGroupings;
221 "Refills each descriptor keypool in the wallet up to the specified number of new keys.\n" 237 LOCK(pwallet->cs_wallet);
240 unsigned int kpSize = 0;
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();
269 std::vector<std::vector<unsigned char>> solutions_data;
280 UniValue wallet_detail = std::visit(*
this, embedded);
281 subobj.
pushKVs(std::move(wallet_detail));
285 if (subobj.
exists(
"pubkey")) obj.
pushKV(
"pubkey", subobj[
"pubkey"]);
286 obj.
pushKV(
"embedded", std::move(subobj));
289 obj.
pushKV(
"sigsrequired", solutions_data[0][0]);
291 for (
size_t i = 1; i < solutions_data.size() - 1; ++i) {
292 CPubKey key(solutions_data[i].begin(), solutions_data[i].end());
295 obj.
pushKV(
"pubkeys", std::move(pubkeys));
361 std::unique_ptr<SigningProvider> provider =
nullptr;
372 "Return information about the given bitcoin address.\n" 373 "Some of the information will only be present if the address is in the active wallet.\n",
384 {
RPCResult::Type::BOOL,
"solvable",
"If we know how to spend coins sent to this address, ignoring the possible lack of private keys."},
385 {
RPCResult::Type::STR,
"desc",
true,
"A descriptor for spending coins sent to this address (only when solvable)."},
386 {
RPCResult::Type::STR,
"parent_desc",
true,
"The descriptor used to derive this address if this is a descriptor wallet"},
392 {
RPCResult::Type::STR,
"script",
true,
"The output script type. Only if isscript is true and the redeemscript is known. Possible\n" 393 "types: nonstandard, pubkey, pubkeyhash, scripthash, multisig, nulldata, witness_v0_keyhash,\n" 394 "witness_v0_scripthash, witness_unknown."},
396 {
RPCResult::Type::ARR,
"pubkeys",
true,
"Array of pubkeys associated with the known redeemscript (only if script is multisig).",
400 {
RPCResult::Type::NUM,
"sigsrequired",
true,
"The number of signatures required to spend multisig output (only if script is multisig)."},
401 {
RPCResult::Type::STR_HEX,
"pubkey",
true,
"The hex value of the raw public key for single-key addresses (possibly embedded in P2SH or P2WSH)."},
402 {
RPCResult::Type::OBJ,
"embedded",
true,
"Information about the address embedded in P2SH or P2WSH, if relevant and known.",
404 {
RPCResult::Type::ELISION,
"",
"Includes all getaddressinfo output fields for the embedded address, excluding metadata (timestamp, hdkeypath, hdseedid)\n" 405 "and relation to the wallet (ismine)."},
412 {
RPCResult::Type::ARR,
"labels",
"Array of labels associated with the address. Currently limited to one label but returned\n" 413 "as an array to keep the API stable if multiple labels are enabled in the future.",
428 LOCK(pwallet->cs_wallet);
430 std::string error_msg;
436 if (error_msg.empty()) error_msg =
"Invalid address";
444 ret.pushKV(
"address", currentAddress);
447 ret.pushKV(
"scriptPubKey",
HexStr(scriptPubKey));
449 std::unique_ptr<SigningProvider> provider = pwallet->GetSolvingProvider(scriptPubKey);
451 bool mine = pwallet->IsMine(dest);
452 ret.pushKV(
"ismine", mine);
456 bool solvable = inferred->IsSolvable();
457 ret.pushKV(
"solvable", solvable);
459 ret.pushKV(
"desc", inferred->ToString());
462 ret.pushKV(
"solvable",
false);
465 const auto& spk_mans = pwallet->GetScriptPubKeyMans(scriptPubKey);
468 if (spk_mans.size()) spk_man = *spk_mans.begin();
472 std::string desc_str;
474 ret.pushKV(
"parent_desc", desc_str);
478 ret.pushKV(
"iswatchonly",
false);
486 if (
const std::unique_ptr<CKeyMetadata> meta = spk_man->GetMetadata(dest)) {
487 ret.pushKV(
"timestamp", meta->nCreateTime);
488 if (meta->has_key_origin) {
492 ret.pushKV(
"hdseedid", meta->hd_seed_id.GetHex());
493 ret.pushKV(
"hdmasterfingerprint",
HexStr(meta->key_origin.fingerprint));
504 const auto* address_book_entry = pwallet->FindAddressBookEntry(dest);
505 if (address_book_entry) {
506 labels.
push_back(address_book_entry->GetLabel());
508 ret.pushKV(
"labels", std::move(labels));
518 "getaddressesbylabel",
519 "Returns the list of addresses assigned the specified label.\n",
528 {
RPCResult::Type::STR,
"purpose",
"Purpose of address (\"send\" for sending address, \"receive\" for receiving address)"},
541 LOCK(pwallet->cs_wallet);
547 std::set<std::string> addresses;
548 pwallet->ForEachAddrBookEntry([&](
const CTxDestination& _dest,
const std::string& _label,
bool _is_change,
const std::optional<AddressPurpose>& _purpose) {
549 if (_is_change)
return;
550 if (_label == label) {
555 bool unique = addresses.emplace(address).second;
563 ret.pushKVEnd(address, std::move(value));
580 "Returns the list of all labels, or labels that are assigned to addresses with a specific purpose.\n",
591 "\nList all labels\n" 593 "\nList labels that have receiving addresses\n" 595 "\nList labels that have sending addresses\n" 597 "\nAs a JSON-RPC call\n" 605 LOCK(pwallet->cs_wallet);
607 std::optional<AddressPurpose> purpose;
608 if (!request.params[0].isNull()) {
609 std::string purpose_str = request.params[0].get_str();
610 if (!purpose_str.empty()) {
619 std::set<std::string> label_set = pwallet->ListAddrBookLabels(purpose);
622 for (
const std::string&
name : label_set) {
632 #ifdef ENABLE_EXTERNAL_SIGNER 636 "walletdisplayaddress",
637 "Display address on an external signer for verification.",
667 result.pushKV(
"address", request.params[0].get_str());
672 #endif // ENABLE_EXTERNAL_SIGNER
void push_back(UniValue val)
static UniValue DescribeWalletAddress(const CWallet &wallet, const CTxDestination &dest)
Keypool ran out, call keypoolrefill first.
UniValue ValueFromAmount(const CAmount amount)
UniValue operator()(const ScriptHash &scripthash) const
bool IsValidDestination(const CTxDestination &dest)
Check whether a CTxDestination corresponds to one with an address.
std::string WriteHDKeypath(const std::vector< uint32_t > &keypath, bool apostrophe)
Write HD keypaths as strings.
std::map< CTxDestination, CAmount > GetAddressBalances(const CWallet &wallet)
void pushKVs(UniValue obj)
TxoutType Solver(const CScript &scriptPubKey, std::vector< std::vector< unsigned char >> &vSolutionsRet)
Parse a scriptPubKey and identify script type for standard scripts.
std::optional< AddressPurpose > PurposeFromString(std::string_view s)
#define CHECK_NONFATAL(condition)
Identity function.
static const unsigned int DEFAULT_KEYPOOL_SIZE
Default for -keypool.
std::string PurposeToString(AddressPurpose p)
RecursiveMutex cs_wallet
Main wallet lock.
UniValue DescribeAddress(const CTxDestination &dest)
const std::string EXAMPLE_ADDRESS[2]
Example bech32 addresses for the RPCExamples help documentation.
RPCHelpMan getaddressinfo()
UniValue operator()(const PayToAnchor &id) const
UniValue operator()(const WitnessV1Taproot &id) const
std::unique_ptr< Descriptor > InferDescriptor(const CScript &script, const SigningProvider &provider)
Find a descriptor for the specified script, using information from provider where possible...
Invalid, missing or duplicate parameter.
bool GetDescriptorString(std::string &out, bool priv) const
constexpr unsigned char * begin()
void ProcessSubScript(const CScript &subscript, UniValue &obj) const
RPCHelpMan walletdisplayaddress()
util::Result< void > DisplayAddress(const CTxDestination &dest) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Display address on an external signer.
std::string HelpExampleRpc(const std::string &methodname, const std::string &args)
std::string FormatAllOutputTypes()
UniValue JSONRPCError(int code, const std::string &message)
Special string with only hex chars.
UniValue operator()(const WitnessUnknown &id) const
std::string LabelFromValue(const UniValue &value)
virtual bool GetPubKey(const CKeyID &address, CPubKey &pubkey) const
bool ExtractDestination(const CScript &scriptPubKey, CTxDestination &addressRet)
Parse a scriptPubKey for the destination.
const SigningProvider *const provider
CTxDestination subtype to encode any future Witness version.
bool exists(const std::string &key) const
Special array that has a fixed number of entries.
UniValue operator()(const PubKeyDestination &dest) const
An encapsulated public key.
const std::string CURRENCY_UNIT
A CWallet maintains a set of transactions and balances, and provides the ability to create new transa...
General application defined errors.
std::string DefaultHint
Hint for default value.
std::string HelpExampleCli(const std::string &methodname, const std::string &args)
const std::string HELP_REQUIRING_PASSPHRASE
Special numeric to denote unix epoch time.
std::set< std::set< CTxDestination > > GetAddressGroupings(const CWallet &wallet)
virtual bool GetCScript(const CScriptID &scriptid, CScript &script) const
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a Bitcoin scriptPubKey for the given CTxDestination.
bool ScriptIsChange(const CWallet &wallet, const CScript &script)
CRIPEMD160 & Write(const unsigned char *data, size_t len)
std::string GetTxnOutputType(TxoutType t)
Get the name of a TxoutType as a string.
Optional argument for which the default value is omitted from help text for one of two reasons: ...
UniValue operator()(const PKHash &pkhash) const
An interface to be implemented by keystores that support signing.
UniValue operator()(const CNoDestination &dest) const
Special string to represent a floating point amount.
DescribeWalletAddressVisitor(const SigningProvider *_provider)
void pushKV(std::string key, UniValue val)
Serialized script, used inside transaction inputs and outputs.
std::variant< CNoDestination, PubKeyDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessV1Taproot, PayToAnchor, WitnessUnknown > CTxDestination
A txout script categorized into standard templates.
RPCHelpMan getaddressesbylabel()
A reference to a CKey: the Hash160 of its serialized public key.
void EnsureWalletIsUnlocked(const CWallet &wallet)
CScriptID ToScriptID(const ScriptHash &script_hash)
bilingual_str ErrorString(const Result< T > &result)
RPCHelpMan keypoolrefill()
A reference to a CScript: the Hash160 of its serialization.
std::string EncodeDestination(const CTxDestination &dest)
RPCHelpMan listaddressgroupings()
UniValue operator()(const WitnessV0KeyHash &id) const
Special dictionary with keys that are not literals.
std::optional< OutputType > ParseOutputType(std::string_view type)
void Finalize(unsigned char hash[OUTPUT_SIZE])
CTxDestination DecodeDestination(const std::string &str, std::string &error_msg, std::vector< int > *error_locations)
RPCHelpMan getnewaddress()
UniValue operator()(const WitnessV0ScriptHash &id) const
std::string HexStr(const std::span< const uint8_t > s)
Convert a span of bytes to a lower-case hexadecimal string.
RPCHelpMan getrawchangeaddress()
CKeyID ToKeyID(const PKHash &key_hash)
std::string ToString(const T &t)
Locale-independent version of std::to_string.
std::shared_ptr< CWallet > GetWalletForJSONRPCRequest(const JSONRPCRequest &request)
Figures out what wallet, if any, to use for a JSONRPCRequest.
const std::string UNIX_EPOCH_TIME
String used to describe UNIX epoch time in documentation, factored out to a constant for consistency...
A hasher class for RIPEMD-160.
Special type to denote elision (...)
bool IsCompressed() const
Check whether this is a compressed public key.