27 "You need to rescan the blockchain in order to correctly mark used " 28 "destinations in the past. Until this is done, some destinations may " 29 "be considered unused, even if the opposite is the case."},
43 "Returns an object containing various wallet state info.\n",
57 {
RPCResult::Type::NUM,
"keypoolsize",
"how many new keys are pre-generated (only counts external keys)"},
58 {
RPCResult::Type::NUM,
"keypoolsize_hd_internal",
true,
"how many new keys are pre-generated for internal use (used for change outputs, only appears if the wallet is using this feature, otherwise external keys are used)"},
59 {
RPCResult::Type::NUM_TIME,
"unlocked_until",
true,
"the " +
UNIX_EPOCH_TIME +
" until which the wallet is unlocked for transfers, or 0 if the wallet is locked (only present for passphrase-encrypted wallets)"},
62 {
RPCResult::Type::BOOL,
"private_keys_enabled",
"false if privatekeys are disabled for this wallet (enforced watch-only wallet)"},
63 {
RPCResult::Type::BOOL,
"avoid_reuse",
"whether this wallet tracks clean/dirty coins in terms of reuse"},
64 {
RPCResult::Type::OBJ,
"scanning",
"current scanning details, or false if no scan is in progress",
69 {
RPCResult::Type::BOOL,
"descriptors",
"whether this wallet uses descriptors for scriptPubKey management"},
70 {
RPCResult::Type::BOOL,
"external_signer",
"whether this wallet is configured to use an external signer such as a hardware wallet"},
71 {
RPCResult::Type::BOOL,
"blank",
"Whether this wallet intentionally does not contain any keys, scripts, or descriptors"},
72 {
RPCResult::Type::NUM_TIME,
"birthtime",
true,
"The start time for blocks scanning. It could be modified by (re)importing any descriptor with an earlier timestamp."},
87 pwallet->BlockUntilSyncedToCurrentChain();
89 LOCK(pwallet->cs_wallet);
93 size_t kpExternalSize = pwallet->KeypoolCountExternalKeys();
95 obj.
pushKV(
"walletname", pwallet->GetName());
96 obj.
pushKV(
"walletversion", pwallet->GetVersion());
97 obj.
pushKV(
"format", pwallet->GetDatabase().Format());
101 obj.
pushKV(
"txcount", (
int)pwallet->mapWallet.size());
102 const auto kp_oldest = pwallet->GetOldestKeyPoolTime();
103 if (kp_oldest.has_value()) {
104 obj.
pushKV(
"keypoololdest", kp_oldest.value());
106 obj.
pushKV(
"keypoolsize", (int64_t)kpExternalSize);
117 obj.
pushKV(
"keypoolsize_hd_internal", (int64_t)(pwallet->GetKeyPoolSize() - kpExternalSize));
119 if (pwallet->IsCrypted()) {
120 obj.
pushKV(
"unlocked_until", pwallet->nRelockTime);
125 if (pwallet->IsScanning()) {
127 scanning.
pushKV(
"duration", Ticks<std::chrono::seconds>(pwallet->ScanningDuration()));
128 scanning.
pushKV(
"progress", pwallet->ScanningProgress());
129 obj.
pushKV(
"scanning", scanning);
131 obj.
pushKV(
"scanning",
false);
136 if (int64_t birthtime = pwallet->GetBirthTime(); birthtime !=
UNKNOWN_TIME) {
137 obj.
pushKV(
"birthtime", birthtime);
149 "Returns a list of wallets in the wallet directory.\n",
172 wallet.pushKV(
"name", path.u8string());
177 result.
pushKV(
"wallets", wallets);
186 "Returns a list of currently loaded wallets.\n" 187 "For full information on the wallet, use \"getwalletinfo\"\n",
217 "\nLoads a wallet from a wallet file or directory." 218 "\nNote that all wallet command-line options used when starting bitcoind will be" 219 "\napplied to the new wallet.\n",
228 {
RPCResult::Type::ARR,
"warnings",
true,
"Warning messages, if any, related to loading the wallet.",
241 const std::string
name(request.params[0].get_str());
246 options.require_existing =
true;
248 std::vector<bilingual_str> warnings;
249 std::optional<bool> load_on_start = request.params[1].isNull() ? std::nullopt : std::optional<bool>(request.params[1].get_bool());
276 flags += (
flags ==
"" ?
"" :
", ") + it.first;
279 "\nChange the state of the given wallet flag for a wallet.\n",
301 std::string flag_str = request.params[0].get_str();
302 bool value = request.params[1].isNull() || request.params[1].get_bool();
316 if (pwallet->IsWalletFlagSet(flag) == value) {
320 res.pushKV(
"flag_name", flag_str);
321 res.pushKV(
"flag_state", value);
324 pwallet->SetWalletFlag(flag);
326 pwallet->UnsetWalletFlag(flag);
342 "\nCreates and loads a new wallet.\n",
348 {
"avoid_reuse",
RPCArg::Type::BOOL,
RPCArg::Default{
false},
"Keep track of coin reuse, and treat dirty and clean coins differently with privacy considerations in mind."},
349 {
"descriptors",
RPCArg::Type::BOOL,
RPCArg::Default{
true},
"Create a native descriptor wallet. The wallet will use descriptors internally to handle address creation." 350 " Setting to \"false\" will create a legacy wallet; This is only possible with the -deprecatedrpc=create_bdb setting because, the legacy wallet type is being deprecated and" 351 " support for creating and opening legacy wallets will be removed in the future."},
353 {
"external_signer",
RPCArg::Type::BOOL,
RPCArg::Default{
false},
"Use an external signer such as a hardware wallet. Requires -signer to be configured. Wallet creation will fail if keys cannot be fetched. Requires disable_private_keys and descriptors set to true."},
358 {
RPCResult::Type::STR,
"name",
"The wallet name if created successfully. If the wallet was created using a full path, the wallet_name will be the full path."},
359 {
RPCResult::Type::ARR,
"warnings",
true,
"Warning messages, if any, related to creating and loading the wallet.",
368 +
HelpExampleCliNamed(
"createwallet", {{
"wallet_name",
"descriptors"}, {
"avoid_reuse",
true}, {
"descriptors",
true}, {
"load_on_startup",
true}})
369 +
HelpExampleRpcNamed(
"createwallet", {{
"wallet_name",
"descriptors"}, {
"avoid_reuse",
true}, {
"descriptors",
true}, {
"load_on_startup",
true}})
375 if (!request.params[1].isNull() && request.params[1].get_bool()) {
379 if (!request.params[2].isNull() && request.params[2].get_bool()) {
383 passphrase.reserve(100);
384 std::vector<bilingual_str> warnings;
385 if (!request.params[3].isNull()) {
386 passphrase = std::string_view{request.params[3].get_str()};
387 if (passphrase.empty()) {
389 warnings.emplace_back(
Untranslated(
"Empty string given as passphrase, wallet will not be encrypted."));
393 if (!request.params[4].isNull() && request.params[4].get_bool()) {
396 if (
self.Arg<bool>(5)) {
402 if (!
context.chain->rpcEnableDeprecated(
"create_bdb")) {
404 " In this release it can be re-enabled temporarily with the -deprecatedrpc=create_bdb setting.");
407 if (!request.params[7].isNull() && request.params[7].get_bool()) {
408 #ifdef ENABLE_EXTERNAL_SIGNER 428 std::optional<bool> load_on_start = request.params[6].isNull() ? std::nullopt : std::optional<bool>(request.params[6].get_bool());
447 "Unloads the wallet referenced by the request endpoint, otherwise unloads the wallet specified in the argument.\n" 448 "Specifying the wallet name on a wallet endpoint is invalid.",
450 {
"wallet_name",
RPCArg::Type::STR,
RPCArg::DefaultHint{
"the wallet name from the RPC endpoint"},
"The name of the wallet to unload. If provided both here and in the RPC endpoint, the two must be identical."},
454 {
RPCResult::Type::ARR,
"warnings",
true,
"Warning messages, if any, related to unloading the wallet.",
465 std::string wallet_name;
467 if (!(request.params[0].isNull() || request.params[0].get_str() == wallet_name)) {
471 wallet_name = request.params[0].get_str();
480 std::vector<bilingual_str> warnings;
490 std::optional<bool> load_on_start{
self.MaybeArg<
bool>(1)};
509 "\nSet or generate a new HD wallet seed. Non-HD wallets will not be upgraded to being a HD wallet. Wallets that are already\n" 510 "HD will have a new HD seed set so that new keys added to the keypool will be derived from this new seed.\n" 511 "\nNote that you will need to MAKE A NEW BACKUP of your wallet after setting the HD wallet seed." +
HELP_REQUIRING_PASSPHRASE +
512 "Note: This command is only compatible with legacy wallets.\n",
514 {
"newkeypool",
RPCArg::Type::BOOL,
RPCArg::Default{
true},
"Whether to flush old unused addresses, including change addresses, from the keypool and regenerate it.\n" 515 "If true, the next address from getnewaddress and change address from getrawchangeaddress will be from this new seed.\n" 516 "If false, addresses (including change addresses if the wallet already had HD Chain Split enabled) from the existing\n" 517 "keypool will be used until it has been depleted."},
519 "The seed value can be retrieved using the dumpwallet command. It is the private key marked hdseed=1"},
542 if (!pwallet->CanSupportFeature(
FEATURE_HD)) {
543 throw JSONRPCError(
RPC_WALLET_ERROR,
"Cannot set an HD seed on a non-HD wallet. Use the upgradewallet RPC in order to upgrade a non-HD wallet to HD");
548 bool flush_key_pool =
true;
549 if (!request.params[0].isNull()) {
550 flush_key_pool = request.params[0].get_bool();
554 if (request.params[1].isNull()) {
580 "\nUpgrade the wallet. Upgrades to the latest version if no version number is specified.\n" 581 "New keys may be generated and a new wallet backup will need to be made.",
607 if (!request.params[0].isNull()) {
608 version = request.params[0].getInt<
int>();
611 const int previous_version{pwallet->GetVersion()};
612 const bool wallet_upgraded{pwallet->UpgradeWallet(version,
error)};
613 const int current_version{pwallet->GetVersion()};
616 if (wallet_upgraded) {
617 if (previous_version == current_version) {
618 result =
"Already at latest version. Wallet version unchanged.";
620 result =
strprintf(
"Wallet upgraded successfully from version %i to version %i.", previous_version, current_version);
625 obj.
pushKV(
"wallet_name", pwallet->GetName());
626 obj.
pushKV(
"previous_version", previous_version);
627 obj.
pushKV(
"current_version", current_version);
628 if (!result.empty()) {
629 obj.
pushKV(
"result", result);
642 "\nCalculate the balance change resulting in the signing and broadcasting of the given transaction(s).\n",
674 if (request.params[1].isObject()) {
675 UniValue options = request.params[1];
682 include_watchonly = options[
"include_watchonly"];
690 const auto& txs = request.params[0].get_array();
692 std::map<COutPoint, CAmount> new_utxos;
693 std::set<COutPoint> spent;
695 for (
size_t i = 0; i < txs.size(); ++i) {
697 if (!
DecodeHexTx(mtx, txs[i].get_str(),
true,
true)) {
702 std::map<COutPoint, Coin> coins;
706 wallet.chain().findCoins(coins);
710 for (
const auto& txin : mtx.
vin) {
711 const auto& outpoint = txin.
prevout;
712 if (spent.count(outpoint)) {
715 if (new_utxos.count(outpoint)) {
716 changes -= new_utxos.at(outpoint);
717 new_utxos.erase(outpoint);
719 if (coins.at(outpoint).IsSpent()) {
722 changes -=
wallet.GetDebit(txin, filter);
724 spent.insert(outpoint);
732 const auto& hash = mtx.
GetHash();
733 for (
size_t i = 0; i < mtx.
vout.size(); ++i) {
734 const auto& txout = mtx.
vout[i];
735 bool is_mine = 0 < (
wallet.IsMine(txout) & filter);
736 changes += new_utxos[
COutPoint(hash, i)] = is_mine ? txout.nValue : 0;
751 "EXPERIMENTAL warning: This call may not work as expected and may be changed in future releases\n" 752 "\nMigrate the wallet to a descriptor wallet.\n" 753 "A new wallet backup will need to be made.\n" 754 "\nThe migration process will create a backup of the wallet before migrating. This backup\n" 755 "file will be named <wallet name>-<timestamp>.legacy.bak and can be found in the directory\n" 756 "for this wallet. In the event of an incorrect migration, the backup can be restored using restorewallet." 757 "\nEncrypted wallets must have the passphrase provided as an argument to this call.",
759 {
"wallet_name",
RPCArg::Type::STR,
RPCArg::DefaultHint{
"the wallet name from the RPC endpoint"},
"The name of the wallet to migrate. If provided both here and in the RPC endpoint, the two must be identical."},
766 {
RPCResult::Type::STR,
"watchonly_name",
true,
"The name of the migrated wallet containing the watchonly scripts"},
767 {
RPCResult::Type::STR,
"solvables_name",
true,
"The name of the migrated wallet containing solvable but not watched scripts"},
777 std::string wallet_name;
779 if (!(request.params[0].isNull() || request.params[0].get_str() == wallet_name)) {
783 if (request.params[0].isNull()) {
786 wallet_name = request.params[0].get_str();
790 wallet_pass.reserve(100);
791 if (!request.params[1].isNull()) {
792 wallet_pass = std::string_view{request.params[1].get_str()};
802 r.pushKV(
"wallet_name", res->wallet_name);
803 if (res->watchonly_wallet) {
804 r.pushKV(
"watchonly_name", res->watchonly_wallet->GetName());
806 if (res->solvables_wallet) {
807 r.pushKV(
"solvables_name", res->solvables_wallet->GetName());
809 r.pushKV(
"backup_path", res->backup_path.u8string());
827 #ifdef ENABLE_EXTERNAL_SIGNER 829 #endif // ENABLE_EXTERNAL_SIGNER 953 #ifdef ENABLE_EXTERNAL_SIGNER 955 #endif // ENABLE_EXTERNAL_SIGNER
RPCHelpMan importaddress()
RPCHelpMan importwallet()
void push_back(UniValue val)
void ReadDatabaseArgs(const ArgsManager &args, DatabaseOptions &options)
RPCHelpMan listlockunspent()
static RPCHelpMan listwalletdir()
RPCHelpMan simulaterawtransaction()
static RPCHelpMan setwalletflag()
std::string HelpExampleRpcNamed(const std::string &methodname, const RPCArgList &args)
const CHDChain & GetHDChain() const
void RPCTypeCheckObj(const UniValue &o, const std::map< std::string, UniValueType > &typesExpected, bool fAllowNull, bool fStrict)
RPCHelpMan restorewallet()
bool NewKeyPool()
Mark old keypool keys as used, and generate all new keys.
static RPCHelpMan loadwallet()
RecursiveMutex cs_KeyStore
RPCHelpMan walletpassphrase()
CPubKey GetPubKey() const
Compute the public key from a private key.
RPCHelpMan sendtoaddress()
RPCHelpMan getreceivedbylabel()
bilingual_str Untranslated(std::string original)
Mark a bilingual_str as untranslated.
std::shared_ptr< CWallet > LoadWallet(WalletContext &context, const std::string &name, std::optional< bool > load_on_start, const DatabaseOptions &options, DatabaseStatus &status, bilingual_str &error, std::vector< bilingual_str > &warnings)
RPCHelpMan listtransactions()
RPCHelpMan abandontransaction()
#define CHECK_NONFATAL(condition)
Identity function.
Special type that behaves almost exactly like OBJ, defining an options object with a list of pre-defi...
static RPCHelpMan sethdseed()
std::basic_string< char, std::char_traits< char >, secure_allocator< char > > SecureString
bool ParseIncludeWatchonly(const UniValue &include_watchonly, const CWallet &wallet)
Used by RPC commands that have an include_watchonly parameter.
void SetHDSeed(const CPubKey &key)
RAII object to check and reserve a wallet rescan.
Balance GetBalance(const CWallet &wallet, const int min_depth, bool avoid_reuse)
static const RPCResult RESULT_LAST_PROCESSED_BLOCK
bool reserve(bool with_passphrase=false)
RPCHelpMan getaddressinfo()
const unsigned char * begin() const
fs::path GetWalletDir()
Get the path of the wallet directory.
This same wallet is already loaded.
CKeyID GetID() const
Get the KeyID of this public key (hash of its serialization)
Flag set when a wallet contains no HD seed and no private keys, scripts, addresses, and other watch only things, and is therefore "blank.".
Invalid, missing or duplicate parameter.
static constexpr uint64_t MUTABLE_WALLET_FLAGS
static RPCHelpMan getwalletinfo()
static RPCHelpMan unloadwallet()
RPCHelpMan rescanblockchain()
RPCHelpMan walletdisplayaddress()
void HandleWalletError(const std::shared_ptr< CWallet > wallet, DatabaseStatus &status, bilingual_str &error)
RPCHelpMan walletcreatefundedpsbt()
int64_t CAmount
Amount in satoshis (Can be negative)
Special type that is a STR with only hex chars.
RPCHelpMan walletpassphrasechange()
Indicates that the wallet needs an external signer.
std::string HelpExampleRpc(const std::string &methodname, const std::string &args)
RPCHelpMan fundrawtransaction()
static constexpr int64_t UNKNOWN_TIME
Constant representing an unknown spkm creation time.
std::underlying_type< isminetype >::type isminefilter
used for bitflags of isminetype
UniValue JSONRPCError(int code, const std::string &message)
RPCHelpMan signrawtransactionwithwallet()
Special string with only hex chars.
SecureString create_passphrase
RPCHelpMan listsinceblock()
bool RemoveWallet(WalletContext &context, const std::shared_ptr< CWallet > &wallet, std::optional< bool > load_on_start)
RPCHelpMan walletprocesspsbt()
An input of a transaction.
static RPCHelpMan createwallet()
RPCHelpMan listreceivedbylabel()
An encapsulated public key.
WalletContext & EnsureWalletContext(const std::any &context)
RPCHelpMan listdescriptors()
Indicate that this wallet supports DescriptorScriptPubKeyMan.
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 HelpExampleCliNamed(const std::string &methodname, const RPCArgList &args)
void PushWarnings(const UniValue &warnings, UniValue &obj)
Push warning messages to an RPC "warnings" field as a JSON array of strings.
bool IsCompressed() const
Check whether the public key corresponding to this private key is (to be) compressed.
void ReadDatabaseArgs(const ArgsManager &args, DBOptions &options)
Invalid wallet specified.
An outpoint - a combination of a transaction hash and an index n into its vout.
static const std::map< std::string, WalletFlags > WALLET_FLAG_MAP
std::string HelpExampleCli(const std::string &methodname, const std::string &args)
std::vector< CTxOut > vout
constexpr bool IsNull() const
void Set(const T pbegin, const T pend, bool fCompressedIn)
Initialize using begin and end iterators to byte data.
void UnloadWallet(std::shared_ptr< CWallet > &&wallet)
Explicitly unload and delete the wallet.
const std::string HELP_REQUIRING_PASSPHRASE
util::Result< MigrationResult > MigrateLegacyToDescriptor(const std::string &wallet_name, const SecureString &passphrase, WalletContext &context)
Do all steps to migrate a legacy wallet to a descriptor wallet.
Special numeric to denote unix epoch time.
RPCHelpMan listreceivedbyaddress()
RPCHelpMan importdescriptors()
LegacyScriptPubKeyMan & EnsureLegacyScriptPubKeyMan(CWallet &wallet, bool also_create)
RPCHelpMan encryptwallet()
std::shared_ptr< CWallet > GetWallet(WalletContext &context, const std::string &name)
RPCHelpMan importpubkey()
Failed to encrypt the wallet.
Optional argument for which the default value is omitted from help text for one of two reasons: ...
CPubKey DeriveNewSeed(const CKey &key)
RPCHelpMan getunconfirmedbalance()
std::vector< std::shared_ptr< CWallet > > GetWallets(WalletContext &context)
uint256 GetHash() const
Compute the hash of this CMutableTransaction.
An interface to be implemented by keystores that support signing.
RPCHelpMan importprunedfunds()
Special string to represent a floating point amount.
void AppendLastProcessedBlock(UniValue &entry, const CWallet &wallet) EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet)
bool error(const char *fmt, const Args &... args)
void pushKV(std::string key, UniValue val)
CPubKey GenerateNewSeed()
RPCHelpMan gettransaction()
const unsigned char * end() const
RPCHelpMan getaddressesbylabel()
RPCHelpMan importprivkey()
A reference to a CKey: the Hash160 of its serialized public key.
bool DecodeHexTx(CMutableTransaction &tx, const std::string &hex_tx, bool try_no_witness=false, bool try_witness=true)
std::string GetHex() const
bool HaveKey(const SigningProvider &wallet, const CKey &key)
Checks if a CKey is in the given CWallet compressed or otherwise.
UniValue ValueFromAmount(const CAmount amount)
WalletContext struct containing references to state shared between CWallet instances, like the reference to the chain interface, and the list of opened wallets.
void EnsureWalletIsUnlocked(const CWallet &wallet)
bilingual_str ErrorString(const Result< T > &result)
RPCHelpMan keypoolrefill()
A mutable version of CTransaction.
RPCHelpMan getreceivedbyaddress()
std::vector< fs::path > ListDatabases(const fs::path &wallet_dir)
Recursively list database paths in directory.
RPCHelpMan listaddressgroupings()
RPCHelpMan removeprunedfunds()
An encapsulated private key.
Span< const CRPCCommand > GetWalletRPCCommands()
A Span is an object that can refer to a contiguous sequence of objects.
std::shared_ptr< CWallet > wallet
RPCErrorCode
Bitcoin RPC error codes.
RPCHelpMan backupwallet()
CKey DecodeSecret(const std::string &str)
static RPCHelpMan migratewallet()
std::shared_ptr< CWallet > CreateWallet(WalletContext &context, const std::string &name, std::optional< bool > load_on_start, DatabaseOptions &options, DatabaseStatus &status, bilingual_str &error, std::vector< bilingual_str > &warnings)
RPCHelpMan getnewaddress()
static RPCHelpMan listwallets()
CKeyID seed_id
seed hash160
RPCHelpMan getrawchangeaddress()
static RPCHelpMan upgradewallet()
Wrapper for UniValue::VType, which includes typeAny: Used to denote don't care type.
std::shared_ptr< CWallet > GetWalletForJSONRPCRequest(const JSONRPCRequest &request)
Figures out what wallet, if any, to use for a JSONRPCRequest.
static const std::map< uint64_t, std::string > WALLET_FLAG_CAVEATS
bool GetWalletNameFromJSONRPCRequest(const JSONRPCRequest &request, std::string &wallet_name)
Error parsing or validating structure in raw format.
const std::string UNIX_EPOCH_TIME
String used to describe UNIX epoch time in documentation, factored out to a constant for consistency...
RPCHelpMan addmultisigaddress()
bool IsValid() const
Check whether this private key is valid.