22 "\nReturns a new Bitcoin address for receiving payments.\n" 23 "If 'label' is specified, it is added to the address book \n" 24 "so payments received with the address will be associated with 'label'.\n",
26 {
"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."},
27 {
"address_type",
RPCArg::Type::STR,
RPCArg::DefaultHint{
"set by -addresstype"},
"The address type to use. Options are \"legacy\", \"p2sh-segwit\", \"bech32\", and \"bech32m\"."},
41 LOCK(pwallet->cs_wallet);
43 if (!pwallet->CanGetAddresses()) {
50 OutputType output_type = pwallet->m_default_address_type;
51 if (!request.params[1].isNull()) {
52 std::optional<OutputType> parsed =
ParseOutputType(request.params[1].get_str());
58 output_type = parsed.value();
61 auto op_dest = pwallet->GetNewDestination(output_type, label);
74 "\nReturns a new Bitcoin address, for receiving change.\n" 75 "This is for use with raw transactions, NOT normal use.\n",
77 {
"address_type",
RPCArg::Type::STR,
RPCArg::DefaultHint{
"set by -changetype"},
"The address type to use. Options are \"legacy\", \"p2sh-segwit\", \"bech32\", and \"bech32m\"."},
91 LOCK(pwallet->cs_wallet);
93 if (!pwallet->CanGetAddresses(
true)) {
97 OutputType output_type = pwallet->m_default_change_type.value_or(pwallet->m_default_address_type);
98 if (!request.params[0].isNull()) {
99 std::optional<OutputType> parsed =
ParseOutputType(request.params[0].get_str());
105 output_type = parsed.value();
108 auto op_dest = pwallet->GetNewChangeDestination(output_type);
121 "\nSets the label associated with the given address.\n",
136 LOCK(pwallet->cs_wallet);
145 if (pwallet->IsMine(dest)) {
159 "\nLists groups of addresses which have had their common ownership\n" 160 "made public by common use as inputs or as the resulting change\n" 161 "in past transactions\n",
188 pwallet->BlockUntilSyncedToCurrentChain();
190 LOCK(pwallet->cs_wallet);
202 const auto* address_book_entry = pwallet->FindAddressBookEntry(address);
203 if (address_book_entry) {
204 addressInfo.
push_back(address_book_entry->GetLabel());
211 return jsonGroupings;
219 "\nAdd an nrequired-to-sign multisignature address to the wallet. Requires a new wallet backup.\n" 220 "Each key is a Bitcoin address or hex-encoded public key.\n" 221 "This functionality is only intended for use with non-watchonly addresses.\n" 222 "See `importaddress` for watchonly p2sh address support.\n" 223 "If 'label' is specified, assign address to that label.\n" 224 "Note: This command is only compatible with legacy wallets.\n",
241 {
RPCResult::Type::ARR,
"warnings",
true,
"Any warnings resulting from the creation of this multisig",
248 "\nAdd a multisig address from 2 addresses\n" 250 "\nAs a JSON-RPC call\n" 264 int required = request.params[0].getInt<
int>();
268 std::vector<CPubKey> pubkeys;
269 for (
unsigned int i = 0; i < keys_or_addrs.size(); ++i) {
270 if (
IsHex(keys_or_addrs[i].get_str()) && (keys_or_addrs[i].get_str().length() == 66 || keys_or_addrs[i].get_str().length() == 130)) {
273 pubkeys.push_back(
AddrToPubKey(spk_man, keys_or_addrs[i].get_str()));
277 OutputType output_type = pwallet->m_default_address_type;
278 if (!request.params[3].isNull()) {
279 std::optional<OutputType> parsed =
ParseOutputType(request.params[3].get_str());
285 output_type = parsed.value();
299 result.
pushKV(
"descriptor", descriptor->ToString());
302 if (descriptor->GetOutputType() != output_type) {
304 warnings.
push_back(
"Unable to make chosen address type, please ensure no uncompressed public keys are present.");
316 "\nFills the keypool."+
335 LOCK(pwallet->cs_wallet);
338 unsigned int kpSize = 0;
339 if (!request.params[0].isNull()) {
340 if (request.params[0].getInt<
int>() < 0)
342 kpSize = (
unsigned int)request.params[0].
getInt<
int>();
346 pwallet->TopUpKeyPool(kpSize);
348 if (pwallet->GetKeyPoolSize() < kpSize) {
360 "\nEntirely clears and refills the keypool.\n" 361 "WARNING: On non-HD wallets, this will require a new backup immediately, to include the new keys.\n" 362 "When restoring a backup of an HD wallet created before the newkeypool command is run, funds received to\n" 363 "new addresses may not appear automatically. They have not been lost, but the wallet may not find them.\n" 364 "This can be fixed by running the newkeypool command on the backup and then rescanning, so the wallet\n" 365 "re-generates the required keys." +
378 LOCK(pwallet->cs_wallet);
397 std::vector<std::vector<unsigned char>> solutions_data;
408 UniValue wallet_detail = std::visit(*
this, embedded);
413 if (subobj.
exists(
"pubkey")) obj.
pushKV(
"pubkey", subobj[
"pubkey"]);
414 obj.
pushKV(
"embedded", std::move(subobj));
417 obj.
pushKV(
"sigsrequired", solutions_data[0][0]);
419 for (
size_t i = 1; i < solutions_data.size() - 1; ++i) {
420 CPubKey key(solutions_data[i].begin(), solutions_data[i].end());
423 obj.
pushKV(
"pubkeys", std::move(pubkeys));
486 std::unique_ptr<SigningProvider> provider =
nullptr;
487 provider =
wallet.GetSolvingProvider(script);
496 "\nReturn information about the given bitcoin address.\n" 497 "Some of the information will only be present if the address is in the active wallet.\n",
508 {
RPCResult::Type::BOOL,
"solvable",
"If we know how to spend coins sent to this address, ignoring the possible lack of private keys."},
509 {
RPCResult::Type::STR,
"desc",
true,
"A descriptor for spending coins sent to this address (only when solvable)."},
510 {
RPCResult::Type::STR,
"parent_desc",
true,
"The descriptor used to derive this address if this is a descriptor wallet"},
516 {
RPCResult::Type::STR,
"script",
true,
"The output script type. Only if isscript is true and the redeemscript is known. Possible\n" 517 "types: nonstandard, pubkey, pubkeyhash, scripthash, multisig, nulldata, witness_v0_keyhash,\n" 518 "witness_v0_scripthash, witness_unknown."},
520 {
RPCResult::Type::ARR,
"pubkeys",
true,
"Array of pubkeys associated with the known redeemscript (only if script is multisig).",
524 {
RPCResult::Type::NUM,
"sigsrequired",
true,
"The number of signatures required to spend multisig output (only if script is multisig)."},
525 {
RPCResult::Type::STR_HEX,
"pubkey",
true,
"The hex value of the raw public key for single-key addresses (possibly embedded in P2SH or P2WSH)."},
526 {
RPCResult::Type::OBJ,
"embedded",
true,
"Information about the address embedded in P2SH or P2WSH, if relevant and known.",
528 {
RPCResult::Type::ELISION,
"",
"Includes all getaddressinfo output fields for the embedded address, excluding metadata (timestamp, hdkeypath, hdseedid)\n" 529 "and relation to the wallet (ismine, iswatchonly)."},
536 {
RPCResult::Type::ARR,
"labels",
"Array of labels associated with the address. Currently limited to one label but returned\n" 537 "as an array to keep the API stable if multiple labels are enabled in the future.",
552 LOCK(pwallet->cs_wallet);
554 std::string error_msg;
560 if (error_msg.empty()) error_msg =
"Invalid address";
568 ret.pushKV(
"address", currentAddress);
571 ret.pushKV(
"scriptPubKey",
HexStr(scriptPubKey));
573 std::unique_ptr<SigningProvider> provider = pwallet->GetSolvingProvider(scriptPubKey);
580 bool solvable = inferred->IsSolvable();
581 ret.pushKV(
"solvable", solvable);
583 ret.pushKV(
"desc", inferred->ToString());
586 ret.pushKV(
"solvable",
false);
589 const auto& spk_mans = pwallet->GetScriptPubKeyMans(scriptPubKey);
592 if (spk_mans.size()) spk_man = *spk_mans.begin();
596 std::string desc_str;
598 ret.pushKV(
"parent_desc", desc_str);
610 if (
const std::unique_ptr<CKeyMetadata> meta = spk_man->GetMetadata(dest)) {
611 ret.pushKV(
"timestamp", meta->nCreateTime);
612 if (meta->has_key_origin) {
616 ret.pushKV(
"hdseedid", meta->hd_seed_id.GetHex());
617 ret.pushKV(
"hdmasterfingerprint",
HexStr(meta->key_origin.fingerprint));
628 const auto* address_book_entry = pwallet->FindAddressBookEntry(dest);
629 if (address_book_entry) {
630 labels.
push_back(address_book_entry->GetLabel());
632 ret.pushKV(
"labels", std::move(labels));
642 "\nReturns the list of addresses assigned the specified label.\n",
651 {
RPCResult::Type::STR,
"purpose",
"Purpose of address (\"send\" for sending address, \"receive\" for receiving address)"},
664 LOCK(pwallet->cs_wallet);
670 std::set<std::string> addresses;
671 pwallet->ForEachAddrBookEntry([&](
const CTxDestination& _dest,
const std::string& _label,
bool _is_change,
const std::optional<AddressPurpose>& _purpose) {
672 if (_is_change)
return;
673 if (_label == label) {
678 bool unique = addresses.emplace(address).second;
686 ret.pushKVEnd(address, value);
702 "\nReturns the list of all labels, or labels that are assigned to addresses with a specific purpose.\n",
713 "\nList all labels\n" 715 "\nList labels that have receiving addresses\n" 717 "\nList labels that have sending addresses\n" 719 "\nAs a JSON-RPC call\n" 727 LOCK(pwallet->cs_wallet);
729 std::optional<AddressPurpose> purpose;
730 if (!request.params[0].isNull()) {
731 std::string purpose_str = request.params[0].get_str();
732 if (!purpose_str.empty()) {
741 std::set<std::string> label_set = pwallet->ListAddrBookLabels(purpose);
744 for (
const std::string&
name : label_set) {
754 #ifdef ENABLE_EXTERNAL_SIGNER 758 "walletdisplayaddress",
759 "Display address on an external signer for verification.",
790 result.
pushKV(
"address", request.params[0].get_str());
795 #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 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.
bool NewKeyPool()
Mark old keypool keys as used, and generate all new keys.
std::map< CTxDestination, CAmount > GetAddressBalances(const CWallet &wallet)
RecursiveMutex cs_KeyStore
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.
bool IsHex(std::string_view str)
static const unsigned int DEFAULT_KEYPOOL_SIZE
Default for -keypool.
std::string PurposeToString(AddressPurpose p)
CPubKey HexToPubKey(const std::string &hex_in)
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.
const UniValue & get_array() const
RPCHelpMan getaddressinfo()
UniValue operator()(const WitnessV1Taproot &id) const
Invalid, missing or duplicate parameter.
constexpr unsigned char * begin()
void ProcessSubScript(const CScript &subscript, UniValue &obj) const
RPCHelpMan walletdisplayaddress()
bool DisplayAddress(const CTxDestination &dest) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Display address on an external signer.
CTxDestination AddAndGetMultisigDestination(const int required, const std::vector< CPubKey > &pubkeys, OutputType type, FillableSigningProvider &keystore, CScript &script_out)
std::string HelpExampleRpc(const std::string &methodname, const std::string &args)
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.
std::string HexStr(const Span< const uint8_t > s)
Convert a span of bytes to a lower-case hexadecimal string.
const SigningProvider *const provider
CTxDestination subtype to encode any future Witness version.
bool exists(const std::string &key) const
std::optional< OutputType > ParseOutputType(const std::string &type)
Special array that has a fixed number of entries.
UniValue operator()(const PubKeyDestination &dest) const
An encapsulated public key.
isminetype
IsMine() return codes, which depend on ScriptPubKeyMan implementation.
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.
void PushWarnings(const UniValue &warnings, UniValue &obj)
Push warning messages to an RPC "warnings" field as a JSON array of strings.
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
LegacyScriptPubKeyMan & EnsureLegacyScriptPubKeyMan(CWallet &wallet, bool also_create)
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::variant< CNoDestination, PubKeyDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessV1Taproot, WitnessUnknown > CTxDestination
A txout script categorized into standard templates.
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
std::unique_ptr< Descriptor > InferDescriptor(const CScript &script, const SigningProvider &provider)
Find a descriptor for the specified script, using information from provider where possible...
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)
bool GetDescriptorString(std::string &out, const bool priv) const
Serialized script, used inside transaction inputs and outputs.
RPCHelpMan getaddressesbylabel()
A reference to a CKey: the Hash160 of its serialized public key.
UniValue ValueFromAmount(const CAmount amount)
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.
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
CPubKey AddrToPubKey(const FillableSigningProvider &keystore, const std::string &addr_in)
RPCHelpMan getrawchangeaddress()
CKeyID ToKeyID(const PKHash &key_hash)
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...
RPCHelpMan addmultisigaddress()
A hasher class for RIPEMD-160.
Special type to denote elision (...)
bool IsCompressed() const
Check whether this is a compressed public key.