20 "\nReturns a new Bitcoin address for receiving payments.\n"
21 "If 'label' is specified, it is added to the address book \n"
22 "so payments received with the address will be associated with 'label'.\n",
24 {
"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."},
25 {
"address_type",
RPCArg::Type::STR,
RPCArg::DefaultHint{
"set by -addresstype"},
"The address type to use. Options are \"legacy\", \"p2sh-segwit\", \"bech32\", and \"bech32m\"."},
39 LOCK(pwallet->cs_wallet);
41 if (!pwallet->CanGetAddresses()) {
48 OutputType output_type = pwallet->m_default_address_type;
49 if (!request.params[1].isNull()) {
50 std::optional<OutputType> parsed =
ParseOutputType(request.params[1].get_str());
56 output_type = parsed.value();
59 auto op_dest = pwallet->GetNewDestination(output_type, label);
72 "\nReturns a new Bitcoin address, for receiving change.\n"
73 "This is for use with raw transactions, NOT normal use.\n",
75 {
"address_type",
RPCArg::Type::STR,
RPCArg::DefaultHint{
"set by -changetype"},
"The address type to use. Options are \"legacy\", \"p2sh-segwit\", \"bech32\", and \"bech32m\"."},
89 LOCK(pwallet->cs_wallet);
91 if (!pwallet->CanGetAddresses(
true)) {
95 OutputType output_type = pwallet->m_default_change_type.value_or(pwallet->m_default_address_type);
96 if (!request.params[0].isNull()) {
97 std::optional<OutputType> parsed =
ParseOutputType(request.params[0].get_str());
103 output_type = parsed.value();
106 auto op_dest = pwallet->GetNewChangeDestination(output_type);
119 "\nSets the label associated with the given address.\n",
134 LOCK(pwallet->cs_wallet);
143 if (pwallet->IsMine(dest)) {
144 pwallet->SetAddressBook(dest, label,
"receive");
146 pwallet->SetAddressBook(dest, label,
"send");
157 "\nLists groups of addresses which have had their common ownership\n"
158 "made public by common use as inputs or as the resulting change\n"
159 "in past transactions\n",
186 pwallet->BlockUntilSyncedToCurrentChain();
188 LOCK(pwallet->cs_wallet);
200 const auto* address_book_entry = pwallet->FindAddressBookEntry(address);
201 if (address_book_entry) {
202 addressInfo.
push_back(address_book_entry->GetLabel());
209 return jsonGroupings;
217 "\nAdd an nrequired-to-sign multisignature address to the wallet. Requires a new wallet backup.\n"
218 "Each key is a Bitcoin address or hex-encoded public key.\n"
219 "This functionality is only intended for use with non-watchonly addresses.\n"
220 "See `importaddress` for watchonly p2sh address support.\n"
221 "If 'label' is specified, assign address to that label.\n",
238 {
RPCResult::Type::ARR,
"warnings",
true,
"Any warnings resulting from the creation of this multisig",
245 "\nAdd a multisig address from 2 addresses\n"
247 "\nAs a JSON-RPC call\n"
261 int required = request.params[0].getInt<
int>();
265 std::vector<CPubKey> pubkeys;
266 for (
unsigned int i = 0; i < keys_or_addrs.size(); ++i) {
267 if (
IsHex(keys_or_addrs[i].get_str()) && (keys_or_addrs[i].get_str().length() == 66 || keys_or_addrs[i].get_str().length() == 130)) {
270 pubkeys.push_back(
AddrToPubKey(spk_man, keys_or_addrs[i].get_str()));
274 OutputType output_type = pwallet->m_default_address_type;
275 if (!request.params[3].isNull()) {
276 std::optional<OutputType> parsed =
ParseOutputType(request.params[3].get_str());
282 output_type = parsed.value();
288 pwallet->SetAddressBook(dest, label,
"send");
296 result.
pushKV(
"descriptor", descriptor->ToString());
299 if (descriptor->GetOutputType() != output_type) {
301 warnings.
push_back(
"Unable to make chosen address type, please ensure no uncompressed public keys are present.");
303 if (!warnings.
empty()) result.
pushKV(
"warnings", warnings);
313 "\nFills the keypool."+
332 LOCK(pwallet->cs_wallet);
335 unsigned int kpSize = 0;
336 if (!request.params[0].isNull()) {
337 if (request.params[0].getInt<
int>() < 0)
339 kpSize = (
unsigned int)request.params[0].getInt<
int>();
343 pwallet->TopUpKeyPool(kpSize);
345 if (pwallet->GetKeyPoolSize() < kpSize) {
357 "\nEntirely clears and refills the keypool.\n"
358 "WARNING: On non-HD wallets, this will require a new backup immediately, to include the new keys.\n"
359 "When restoring a backup of an HD wallet created before the newkeypool command is run, funds received to\n"
360 "new addresses may not appear automatically. They have not been lost, but the wallet may not find them.\n"
361 "This can be fixed by running the newkeypool command on the backup and then rescanning, so the wallet\n"
362 "re-generates the required keys." +
375 LOCK(pwallet->cs_wallet);
394 std::vector<std::vector<unsigned char>> solutions_data;
405 UniValue wallet_detail = std::visit(*
this, embedded);
410 if (subobj.
exists(
"pubkey")) obj.
pushKV(
"pubkey", subobj[
"pubkey"]);
411 obj.
pushKV(
"embedded", std::move(subobj));
414 obj.
pushKV(
"sigsrequired", solutions_data[0][0]);
416 for (
size_t i = 1; i < solutions_data.size() - 1; ++i) {
417 CPubKey key(solutions_data[i].begin(), solutions_data[i].end());
420 obj.
pushKV(
"pubkeys", std::move(pubkeys));
483 std::unique_ptr<SigningProvider> provider =
nullptr;
484 provider =
wallet.GetSolvingProvider(script);
493 "\nReturn information about the given bitcoin address.\n"
494 "Some of the information will only be present if the address is in the active wallet.\n",
505 {
RPCResult::Type::BOOL,
"solvable",
"If we know how to spend coins sent to this address, ignoring the possible lack of private keys."},
506 {
RPCResult::Type::STR,
"desc",
true,
"A descriptor for spending coins sent to this address (only when solvable)."},
507 {
RPCResult::Type::STR,
"parent_desc",
true,
"The descriptor used to derive this address if this is a descriptor wallet"},
513 {
RPCResult::Type::STR,
"script",
true,
"The output script type. Only if isscript is true and the redeemscript is known. Possible\n"
514 "types: nonstandard, pubkey, pubkeyhash, scripthash, multisig, nulldata, witness_v0_keyhash,\n"
515 "witness_v0_scripthash, witness_unknown."},
517 {
RPCResult::Type::ARR,
"pubkeys",
true,
"Array of pubkeys associated with the known redeemscript (only if script is multisig).",
521 {
RPCResult::Type::NUM,
"sigsrequired",
true,
"The number of signatures required to spend multisig output (only if script is multisig)."},
522 {
RPCResult::Type::STR_HEX,
"pubkey",
true,
"The hex value of the raw public key for single-key addresses (possibly embedded in P2SH or P2WSH)."},
523 {
RPCResult::Type::OBJ,
"embedded",
true,
"Information about the address embedded in P2SH or P2WSH, if relevant and known.",
525 {
RPCResult::Type::ELISION,
"",
"Includes all getaddressinfo output fields for the embedded address, excluding metadata (timestamp, hdkeypath, hdseedid)\n"
526 "and relation to the wallet (ismine, iswatchonly)."},
533 {
RPCResult::Type::ARR,
"labels",
"Array of labels associated with the address. Currently limited to one label but returned\n"
534 "as an array to keep the API stable if multiple labels are enabled in the future.",
549 LOCK(pwallet->cs_wallet);
551 std::string error_msg;
557 if (error_msg.empty()) error_msg =
"Invalid address";
565 ret.pushKV(
"address", currentAddress);
568 ret.pushKV(
"scriptPubKey",
HexStr(scriptPubKey));
570 std::unique_ptr<SigningProvider> provider = pwallet->GetSolvingProvider(scriptPubKey);
577 bool solvable = inferred->IsSolvable();
578 ret.pushKV(
"solvable", solvable);
580 ret.pushKV(
"desc", inferred->ToString());
583 ret.pushKV(
"solvable",
false);
586 const auto& spk_mans = pwallet->GetScriptPubKeyMans(scriptPubKey);
589 if (spk_mans.size()) spk_man = *spk_mans.begin();
593 std::string desc_str;
595 ret.pushKV(
"parent_desc", desc_str);
607 if (
const std::unique_ptr<CKeyMetadata> meta = spk_man->GetMetadata(dest)) {
608 ret.pushKV(
"timestamp", meta->nCreateTime);
609 if (meta->has_key_origin) {
611 ret.pushKV(
"hdseedid", meta->hd_seed_id.GetHex());
612 ret.pushKV(
"hdmasterfingerprint",
HexStr(meta->key_origin.fingerprint));
623 const auto* address_book_entry = pwallet->FindAddressBookEntry(dest);
624 if (address_book_entry) {
625 labels.
push_back(address_book_entry->GetLabel());
627 ret.pushKV(
"labels", std::move(labels));
637 "\nReturns the list of addresses assigned the specified label.\n",
646 {
RPCResult::Type::STR,
"purpose",
"Purpose of address (\"send\" for sending address, \"receive\" for receiving address)"},
659 LOCK(pwallet->cs_wallet);
665 std::set<std::string> addresses;
666 pwallet->ForEachAddrBookEntry([&](
const CTxDestination& _dest,
const std::string& _label,
const std::string& _purpose,
bool _is_change) {
667 if (_is_change)
return;
668 if (_label == label) {
673 bool unique = addresses.emplace(address).second;
680 value.
pushKV(
"purpose", _purpose);
681 ret.__pushKV(address, value);
697 "\nReturns the list of all labels, or labels that are assigned to addresses with a specific purpose.\n",
708 "\nList all labels\n"
710 "\nList labels that have receiving addresses\n"
712 "\nList labels that have sending addresses\n"
714 "\nAs a JSON-RPC call\n"
722 LOCK(pwallet->cs_wallet);
725 if (!request.params[0].isNull()) {
726 purpose = request.params[0].get_str();
730 std::set<std::string> label_set = pwallet->ListAddrBookLabels(purpose);
733 for (
const std::string&
name : label_set) {
743 #ifdef ENABLE_EXTERNAL_SIGNER
747 "walletdisplayaddress",
748 "Display address on an external signer for verification.",
779 result.
pushKV(
"address", request.params[0].get_str());
std::string WriteHDKeypath(const std::vector< uint32_t > &keypath)
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.
bool IsCompressed() const
Check whether this is a compressed public key.
A hasher class for RIPEMD-160.
CRIPEMD160 & Write(const unsigned char *data, size_t len)
void Finalize(unsigned char hash[OUTPUT_SIZE])
Serialized script, used inside transaction inputs and outputs.
A reference to a CScript: the Hash160 of its serialization (see script.h)
RecursiveMutex cs_KeyStore
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 pushKVs(UniValue obj)
const UniValue & get_array() const
bool exists(const std::string &key) 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...
RecursiveMutex cs_wallet
Main wallet lock.
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
bool GetDescriptorString(std::string &out, const bool priv) const
bool NewKeyPool()
Mark old keypool keys as used, and generate all new keys.
UniValue ValueFromAmount(const CAmount amount)
std::unique_ptr< Descriptor > InferDescriptor(const CScript &script, const SigningProvider &provider)
Find a descriptor for the specified script, using information from provider where possible.
const std::string CURRENCY_UNIT
bool DisplayAddress(const CTxDestination &dest) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Display address on an external signer.
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::shared_ptr< CWallet > GetWalletForJSONRPCRequest(const JSONRPCRequest &request)
Figures out what wallet, if any, to use for a JSONRPCRequest.
RPCHelpMan keypoolrefill()
bool ScriptIsChange(const CWallet &wallet, const CScript &script)
void EnsureWalletIsUnlocked(const CWallet &wallet)
const std::string HELP_REQUIRING_PASSPHRASE
RPCHelpMan walletdisplayaddress()
LegacyScriptPubKeyMan & EnsureLegacyScriptPubKeyMan(CWallet &wallet, bool also_create)
RPCHelpMan addmultisigaddress()
RPCHelpMan listaddressgroupings()
static const unsigned int DEFAULT_KEYPOOL_SIZE
Default for -keypool.
std::string LabelFromValue(const UniValue &value)
isminetype
IsMine() return codes, which depend on ScriptPubKeyMan implementation.
static UniValue DescribeWalletAddress(const CWallet &wallet, const CTxDestination &dest)
RPCHelpMan getrawchangeaddress()
RPCHelpMan getaddressinfo()
std::map< CTxDestination, CAmount > GetAddressBalances(const CWallet &wallet)
RPCHelpMan getaddressesbylabel()
@ WALLET_FLAG_DISABLE_PRIVATE_KEYS
RPCHelpMan getnewaddress()
std::set< std::set< CTxDestination > > GetAddressGroupings(const CWallet &wallet)
std::optional< OutputType > ParseOutputType(const std::string &type)
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)
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)
const std::string UNIX_EPOCH_TIME
String used to describe UNIX epoch time in documentation, factored out to a constant for consistency.
CPubKey HexToPubKey(const std::string &hex_in)
const std::string EXAMPLE_ADDRESS[2]
Example bech32 addresses for the RPCExamples help documentation.
CPubKey AddrToPubKey(const FillableSigningProvider &keystore, const std::string &addr_in)
UniValue DescribeAddress(const CTxDestination &dest)
TxoutType Solver(const CScript &scriptPubKey, std::vector< std::vector< unsigned char >> &vSolutionsRet)
Parse a scriptPubKey and identify script type for standard scripts.
bool ExtractDestination(const CScript &scriptPubKey, CTxDestination &addressRet)
Parse a standard scriptPubKey for the destination address.
std::string GetTxnOutputType(TxoutType t)
Get the name of a TxoutType as a string.
bool IsValidDestination(const CTxDestination &dest)
Check whether a CTxDestination is a CNoDestination.
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a Bitcoin scriptPubKey for the given CTxDestination.
CKeyID ToKeyID(const PKHash &key_hash)
std::variant< CNoDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessV1Taproot, WitnessUnknown > CTxDestination
A txout script template with a specific destination.
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:
@ ELISION
Special type to denote elision (...)
@ 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.
std::string HexStr(const Span< const uint8_t > s)
Convert a span of bytes to a lower-case hexadecimal string.
bool IsHex(std::string_view str)