41 std::stringstream
ret;
53 std::stringstream
ret;
54 for (
unsigned int pos = 0; pos < str.length(); pos++) {
56 if (
c ==
'%' && pos + 2 < str.length()) {
57 c = (((str[pos + 1] >> 6) * 9 + ((str[pos + 1] -
'0') & 15)) << 4) |
58 ((str[pos + 2] >> 6) * 9 + ((str[pos + 2] -
'0') & 15));
88 pwallet->m_default_address_type),
100 if (
wallet.IsAbortingRescan()) {
104 "Rescan was unable to fully rescan the blockchain. "
105 "Some transactions may be missing.");
112 "Adds a private key (as returned by dumpprivkey) to your wallet. "
113 "Requires a new wallet backup.\n"
114 "Hint: use importmulti to import more than one private key.\n"
115 "\nNote: This call can take minutes to complete if rescan is true, "
116 "during that time, other rpc calls\n"
117 "may report that the imported key exists but related transactions are "
118 "still missing, leading to temporarily incorrect/bogus balances and "
119 "unspent outputs until rescan completes.\n"
120 "Note: Use \"getwalletinfo\" to query the scanning progress.\n"
121 "Note: This command is only compatible with legacy wallets. Use "
122 "\"importdescriptors\" with \"combo(X)\" for descriptor wallets.\n",
125 "The private key (see dumpprivkey)"},
128 "current label if address exists, otherwise \"\""},
129 "An optional label"},
131 "Rescan the wallet for transactions"},
135 "\nDump a private key\n" +
137 "\nImport the private key with rescan\n" +
139 "\nImport using a label and without rescan\n" +
141 "\nImport using default blank label and without rescan\n" +
143 "\nAs a JSON-RPC call\n" +
144 HelpExampleRpc(
"importprivkey",
"\"mykey\", \"testing\", false")},
147 std::shared_ptr<CWallet>
const wallet =
157 "Cannot import private keys to a wallet with "
158 "private keys disabled");
170 std::string
strSecret = request.params[0].get_str();
172 if (!request.params[1].isNull()) {
173 strLabel = request.params[1].get_str();
177 if (!request.params[2].isNull()) {
178 fRescan = request.params[2].get_bool();
187 "Rescan is disabled when blocks are pruned");
193 "Wallet is currently rescanning. Abort existing "
200 "Invalid private key encoding");
213 if (!request.params[1].isNull() ||
222 "Error adding key to wallet");
238 "Stops current wallet rescan triggered by an RPC call, e.g. by an "
239 "importprivkey call.\n"
240 "Note: Use \"getwalletinfo\" to query the scanning progress.\n",
243 "Whether the abort was successful"},
246 "\nAbort the running wallet rescan\n" +
248 "\nAs a JSON-RPC call\n" +
252 std::shared_ptr<CWallet>
const wallet =
271 "Adds an address or script (in hex) that can be watched as if it "
272 "were in your wallet but cannot be used to spend. Requires a new "
274 "\nNote: This call can take minutes to complete if rescan is true, "
275 "during that time, other rpc calls\n"
276 "may report that the imported address exists but related transactions "
277 "are still missing, leading to temporarily incorrect/bogus balances "
278 "and unspent outputs until rescan completes.\n"
279 "If you have the full public key, you should call importpubkey instead "
281 "Hint: use importmulti to import more than one address.\n"
282 "\nNote: If you import a non-standard raw script in hex form, outputs "
283 "sending to it will be treated\n"
284 "as change, and not show up in many RPCs.\n"
285 "Note: Use \"getwalletinfo\" to query the scanning progress.\n"
286 "Note: This command is only compatible with legacy wallets. Use "
287 "\"importdescriptors\" for descriptor wallets.\n",
290 "The Bitcoin address (or hex-encoded script)"},
292 "An optional label"},
294 "Rescan the wallet for transactions"},
296 "Add the P2SH version of the script as well"},
300 "\nImport an address with rescan\n" +
302 "\nImport using a label without rescan\n" +
303 HelpExampleCli(
"importaddress",
"\"myaddress\" \"testing\" false") +
304 "\nAs a JSON-RPC call\n" +
306 "\"myaddress\", \"testing\", false")},
309 std::shared_ptr<CWallet>
const wallet =
319 if (!request.params[1].isNull()) {
320 strLabel = request.params[1].get_str();
325 if (!request.params[2].isNull()) {
326 fRescan = request.params[2].get_bool();
334 "Rescan is disabled when blocks are pruned");
340 "Wallet is currently rescanning. Abort "
341 "existing rescan or wait.");
346 if (!request.params[3].isNull()) {
347 fP2SH = request.params[3].get_bool();
354 request.params[0].get_str(),
wallet->GetChainParams());
359 "Cannot use the p2sh flag with an address - "
360 "use a script instead");
369 }
else if (
IsHex(request.params[0].get_str())) {
370 std::vector<uint8_t> data(
371 ParseHex(request.params[0].get_str()));
372 CScript redeem_script(data.begin(), data.end());
374 std::set<CScript> scripts = {redeem_script};
387 "Invalid Bitcoin address or script");
406 "Imports funds without rescan. Corresponding address or script must "
407 "previously be included in wallet. Aimed towards pruned wallets. The "
408 "end-user is responsible to import additional transactions that "
409 "subsequently spend the imported outputs or rescan after the point in "
410 "the blockchain the transaction is included.\n",
413 "A raw transaction in hex funding an already-existing address in "
416 "The hex output from gettxoutproof that contains the transaction"},
422 std::shared_ptr<CWallet>
const wallet =
430 if (!
DecodeHexTx(tx, request.params[0].get_str())) {
443 std::vector<uint256>
vMatch;
444 std::vector<size_t>
vIndex;
448 "Something wrong with merkleblock");
457 "Block not found in chain");
460 std::vector<uint256>::const_iterator it;
461 if ((it = std::find(
vMatch.begin(),
vMatch.end(), txid)) ==
464 "Transaction given doesn't exist in proof");
481 "No addresses in wallet correspond to included transaction");
489 "Deletes the specified transaction from the wallet. Meant for use "
490 "with pruned wallets and as a companion to importprunedfunds. This "
491 "will affect wallet balances.\n",
494 "The hex-encoded id of the transaction you are deleting"},
498 "\"a8d0c0184dde994a09ec054286f1ce581bebf4644"
499 "6a512166eae7628734ea0a5\"") +
500 "\nAs a JSON-RPC call\n" +
502 "\"a8d0c0184dde994a09ec054286f1ce581bebf4644"
503 "6a512166eae7628734ea0a5\"")},
506 std::shared_ptr<CWallet>
const wallet =
516 std::vector<TxId>
txIds;
517 txIds.push_back(txid);
523 "Could not properly delete the transaction.");
528 "Transaction does not exist in wallet.");
539 "Adds a public key (in hex) that can be watched as if it were in "
540 "your wallet but cannot be used to spend. Requires a new wallet "
542 "Hint: use importmulti to import more than one public key.\n"
543 "\nNote: This call can take minutes to complete if rescan is true, "
544 "during that time, other rpc calls\n"
545 "may report that the imported pubkey exists but related transactions "
546 "are still missing, leading to temporarily incorrect/bogus balances "
547 "and unspent outputs until rescan completes.\n"
548 "Note: Use \"getwalletinfo\" to query the scanning progress.\n"
549 "Note: This command is only compatible with legacy wallets. Use "
550 "\"importdescriptors\" with \"combo(X)\" for descriptor wallets.\n",
553 "The hex-encoded public key"},
555 "An optional label"},
557 "Rescan the wallet for transactions"},
561 "\nImport a public key with rescan\n" +
563 "\nImport using a label without rescan\n" +
564 HelpExampleCli(
"importpubkey",
"\"mypubkey\" \"testing\" false") +
565 "\nAs a JSON-RPC call\n" +
566 HelpExampleRpc(
"importpubkey",
"\"mypubkey\", \"testing\", false")},
569 std::shared_ptr<CWallet>
const wallet =
579 if (!request.params[1].isNull()) {
580 strLabel = request.params[1].get_str();
585 if (!request.params[2].isNull()) {
586 fRescan = request.params[2].get_bool();
594 "Rescan is disabled when blocks are pruned");
600 "Wallet is currently rescanning. Abort "
601 "existing rescan or wait.");
604 if (!
IsHex(request.params[0].get_str())) {
606 "Pubkey must be a hex string");
608 std::vector<uint8_t> data(
ParseHex(request.params[0].get_str()));
612 "Pubkey is not a valid public key");
650 "Imports keys from a wallet dump file (see dumpwallet). Requires a "
651 "new wallet backup to include imported keys.\n"
652 "Note: Use \"getwalletinfo\" to query the scanning progress.\n"
653 "Note: This command is only compatible with legacy wallets.\n",
661 "\nImport the wallet\n" +
663 "\nImport using the json rpc call\n" +
667 std::shared_ptr<CWallet>
const wallet =
682 "Importing wallets is disabled when blocks are pruned");
688 "Wallet is currently rescanning. Abort "
689 "existing rescan or wait.");
700 file.open(
fs::u8path(request.params[0].get_str()),
701 std::ios::in | std::ios::ate);
702 if (!file.is_open()) {
704 "Cannot open wallet dump file");
711 file.seekg(0, file.beg);
721 strprintf(
"%s " +
_(
"Importing...").translated,
724 std::vector<std::tuple<CKey, int64_t, bool, std::string>> keys;
725 std::vector<std::pair<CScript, int64_t>> scripts;
726 while (file.good()) {
730 std::min<int>(50, 100 *
double(file.tellg()) /
734 std::getline(file, line);
735 if (line.empty() || line[0] ==
'#') {
740 if (
vstr.size() < 2) {
771 std::pair<CScript, int64_t>(script,
birth_time));
782 "Importing wallets is disabled when "
783 "private keys are disabled");
785 double total =
double(keys.size() + scripts.size());
790 std::max(50, std::min<int>(75, 100 * progress / total) +
796 std::string label = std::get<3>(
key_tuple);
808 "Error importing key for %s\n",
825 std::max(50, std::min<int>(75, 100 * progress / total) +
848 pwallet->chain().showProgress(
"", 100,
false);
850 pwallet->MarkDirty();
854 "Error adding some keys/scripts to wallet");
865 "Reveals the private key corresponding to 'address'.\n"
866 "Then the importprivkey can be used with this output\n"
867 "Note: This command is only compatible with legacy wallets.\n",
870 "The bitcoin address for the private key"},
878 std::shared_ptr<CWallet>
const wallet =
892 std::string
strAddress = request.params[0].get_str();
897 "Invalid Bitcoin address");
900 if (
keyid.IsNull()) {
902 "Address does not refer to a key");
918 "Dumps all wallet keys in a human-readable format to a server-side "
919 "file. This does not allow overwriting existing files.\n"
920 "Imported scripts are included in the dumpsfile, but corresponding "
921 "addresses may not be added automatically by importwallet.\n"
922 "Note that if your wallet contains keys which are not derived from "
923 "your HD seed (e.g. imported keys), these are not covered by\n"
924 "only backing up the seed itself, and must be backed up too (e.g. "
925 "ensure you back up the whole dumpfile).\n"
926 "Note: This command is only compatible with legacy wallets.\n",
929 "The filename with path (absolute path recommended)"},
936 "The filename with full absolute path"},
942 std::shared_ptr<CWallet>
const pwallet =
955 wallet.BlockUntilSyncedToCurrentChain();
973 " already exists. If you are "
974 "sure this is what you want, "
975 "move it out of the way first");
980 if (!file.is_open()) {
982 "Cannot open wallet dump file");
1000 std::set<CScriptID> scripts =
spk_man.GetCScripts();
1003 std::vector<std::pair<int64_t, CKeyID>>
vKeyBirth;
1005 vKeyBirth.push_back(std::make_pair(entry.second, entry.first));
1013 file <<
strprintf(
"# * Created on %s\n",
1015 file <<
strprintf(
"# * Best block at time of backup was %i (%s),\n",
1016 wallet.GetLastBlockHeight(),
1017 wallet.GetLastBlockHash().ToString());
1026 if (
spk_man.GetKey(seed_id, seed)) {
1030 file <<
"# extended private masterkey: "
1034 for (std::vector<std::pair<int64_t, CKeyID>>::const_iterator it =
1047 }
else if (
keyid == seed_id) {
1050 file <<
"reserve=1";
1051 }
else if (
spk_man.mapKeyMetadata[
keyid].hdKeypath ==
"s") {
1052 file <<
"inactivehdseed=1";
1069 std::string address =
1073 if (it !=
spk_man.m_script_metadata.end()) {
1079 file <<
strprintf(
" # addr=%s\n", address);
1083 file <<
"# End of dump\n";
1097 "dump all the UTXO tracked by the wallet.\n",
1106 "The list of UTXO corresponding to this address.",
1113 "The transaction id"},
1117 "The output's amount"},
1126 std::shared_ptr<CWallet>
const pwallet =
1137 wallet.BlockUntilSyncedToCurrentChain();
1146 for (
const auto &
o :
p.second) {
1148 utxo.
pushKV(
"txid",
o.tx->GetId().ToString());
1150 utxo.
pushKV(
"depth",
o.nDepth);
1151 utxo.
pushKV(
"value",
o.tx->tx->vout[
o.i].nValue);
1191 std::vector<std::vector<uint8_t>>
solverdata;
1208 "Trying to nest P2SH inside another P2SH");
1216 return "missing redeemscript";
1219 return "redeemScript does not match the scriptPubKey";
1226 for (
size_t i = 1; i + 1 <
solverdata.size(); ++i) {
1233 return "unspendable script";
1236 return "unrecognized script";
1249 const UniValue &scriptPubKey = data[
"scriptPubKey"];
1252 scriptPubKey.
exists(
"address"))) {
1254 "scriptPubKey must be string with script or JSON "
1255 "with address string");
1257 const std::string &output =
1262 data.
exists(
"redeemscript") ? data[
"redeemscript"].
get_str() :
"";
1272 if (data.
exists(
"range")) {
1275 "Range should not be specified for a non-descriptor import");
1285 "Invalid address \"" + output +
"\"");
1289 if (!
IsHex(output)) {
1291 "Invalid scriptPubKey \"" + output +
"\"");
1293 std::vector<uint8_t> vData(
ParseHex(output));
1294 script =
CScript(vData.begin(), vData.end());
1298 "Internal must be set to true for "
1299 "nonstandard scriptPubKey imports.");
1309 "\": must be hex string");
1312 import_data.redeemscript = std::make_unique<CScript>(
1315 for (
size_t i = 0; i <
pubKeys.size(); ++i) {
1316 const auto &str =
pubKeys[i].get_str();
1319 "Pubkey \"" + str +
"\" must be a hex string");
1326 "\" is not a valid public key");
1331 for (
size_t i = 0; i < keys.
size(); ++i) {
1332 const auto &str = keys[i].
get_str();
1336 "Invalid private key encoding");
1357 [&](
const std::pair<CKeyID, bool> &
used_key) {
1358 return privkey_map.count(used_key.first) > 0;
1361 warnings.push_back(
"Some private keys are missing, outputs "
1362 "will be considered watchonly. If this is "
1363 "intentional, specify the watchonly flag.");
1367 "All private keys are provided, outputs will be considered "
1368 "spendable. If this is intentional, do not specify the "
1373 if (
error.empty()) {
1382 error =
"some required keys are missing";
1387 if (!
error.empty()) {
1389 ". If this is intentional, don't provide "
1390 "any keys, pubkeys or redeemscript.");
1401 "Ignoring redeemscript as this is not a P2SH script.");
1406 warnings.push_back(
"Ignoring irrelevant private key.");
1415 warnings.push_back(
"Ignoring public key \"" +
1417 "\" as it doesn't appear inside P2PKH.");
1436 const std::string &descriptor = data[
"desc"].
get_str();
1449 int64_t range_start = 0, range_end = 0;
1453 "Range should not be specified for an un-ranged descriptor");
1455 if (!data.
exists(
"range")) {
1458 "Descriptor is ranged, please specify the range");
1468 for (
int i = range_start; i <= range_end; ++i) {
1478 for (
const auto &x :
out_keys.scripts) {
1492 for (
size_t i = 0; i <
priv_keys.size(); ++i) {
1493 const auto &str =
priv_keys[i].get_str();
1497 "Invalid private key encoding");
1505 warnings.push_back(
"Ignoring irrelevant private key.");
1519 [&](
const std::pair<CKeyID, CPubKey> &
used_key) {
1520 return privkey_map.count(used_key.first) > 0;
1524 [&](
const std::pair<
CKeyID, std::pair<CPubKey, KeyOriginInfo>>
1525 &entry) { return privkey_map.count(entry.first) > 0; });
1528 "Some private keys are missing, outputs will be considered "
1529 "watchonly. If this is intentional, specify the watchonly flag.");
1532 warnings.push_back(
"All private keys are provided, outputs will be "
1533 "considered spendable. If this is intentional, do "
1534 "not specify the watchonly flag.");
1548 data.exists(
"internal") ? data[
"internal"].get_bool() :
false;
1550 if (
internal && data.exists(
"label")) {
1552 "Internal addresses should not have a label");
1554 const std::string &label =
1555 data.exists(
"label") ? data[
"label"].get_str() :
"";
1557 data.exists(
"keypool") ? data[
"keypool"].get_bool() :
false;
1563 "Keys can only be imported to the keypool when "
1564 "private keys are disabled");
1574 if (data.exists(
"scriptPubKey") && data.exists(
"desc")) {
1577 "Both a descriptor and a scriptPubKey should not be provided.");
1578 }
else if (data.exists(
"scriptPubKey")) {
1582 }
else if (data.exists(
"desc")) {
1589 "Either a descriptor or scriptPubKey must be provided.");
1597 "Cannot import private keys to a wallet with "
1598 "private keys disabled");
1605 "The wallet already contains the private "
1606 "key for this address or script (\"" +
1612 pwallet->MarkDirty();
1615 "Error adding script to wallet");
1624 "Error adding address to wallet");
1630 "Error adding address to wallet");
1650 if (data.
exists(
"timestamp")) {
1658 strprintf(
"Expected number or \"now\" timestamp "
1659 "value for key. got type %s",
1663 "Missing required timestamp field for key");
1670 "Rescan failed for %s with creation timestamp %d. There was an error "
1671 "reading a block from time %d, which is after or within %d seconds of "
1672 "key creation, and could contain transactions pertaining to the %s. As "
1673 "a result, transactions and coins using this %s may not appear in "
1674 "the wallet. This error could be caused by pruning or data corruption "
1675 "(see bitcoind log for details) and could be dealt with by downloading "
1676 "and rescanning the relevant blocks (see -reindex and -rescan "
1685 "Import addresses/scripts (with private or public keys, redeem "
1686 "script (P2SH)), optionally rescanning the blockchain from the "
1687 "earliest creation time of the imported scripts. Requires a new wallet "
1689 "If an address/script is imported without all of the private keys "
1690 "required to spend from that address, it will be watchonly. The "
1691 "'watchonly' option must be set to true in this case or a warning will "
1693 "Conversely, if all the private keys are provided and the "
1694 "address/script is spendable, the watchonly option must be set to "
1695 "false, or a warning will be returned.\n"
1696 "Note: Use \"getwalletinfo\" to query the scanning progress.\n"
1697 "Note: This command is only compatible with legacy wallets. Use "
1698 "\"importdescriptors\" for descriptor wallets.\n",
1703 "Data to be imported",
1712 "Descriptor to import. If using descriptor, do not "
1713 "also provide address/scriptPubKey, scripts, or "
1717 "Type of scriptPubKey (string for script, json for "
1718 "address). Should not be provided if using a "
1722 "\"address\":\"<address>\" }",
1725 "Creation time of the key expressed in " +
1728 "or the string \"now\" to substitute the current "
1729 "synced blockchain time. The timestamp of the "
1731 "key will determine how far back blockchain "
1732 "rescans need to begin for missing wallet "
1734 "\"now\" can be specified to bypass scanning, "
1735 "for keys which are known to never have been "
1737 "0 can be specified to scan the entire "
1738 "blockchain. Blocks up to 2 hours before the "
1740 "creation time of all keys being imported by the "
1741 "importmulti call will be scanned.",
1743 "integer / string"}}},
1746 "Allowed only if the scriptPubKey is a P2SH "
1747 "address/scriptPubKey"},
1751 "Array of strings giving pubkeys to import. They "
1752 "must occur in P2PKH scripts. They are not required "
1753 "when the private key is also provided (see the "
1754 "\"keys\" argument).",
1762 "Array of strings giving private keys to import. The "
1763 "corresponding public keys must occur in the output "
1771 "If a ranged descriptor is used, this specifies the "
1772 "end or the range (in the form [begin,end]) to "
1776 "Stating whether matching outputs should be treated "
1777 "as not incoming payments (also known as change)"},
1780 "Stating whether matching outputs should be "
1781 "considered watchonly."},
1783 "Label to assign to the address, only allowed with "
1786 "Stating whether imported public keys should be "
1787 "added to the keypool for when users request new "
1788 "addresses. Only allowed when wallet private keys "
1800 "Stating if should rescan the blockchain after all imports"},
1806 "Response is an array with the same size as the input that "
1807 "has the execution result",
1833 "'[{ \"scriptPubKey\": { \"address\": \"<my address>\" }, "
1834 "\"timestamp\":1455191478 }, "
1835 "{ \"scriptPubKey\": { \"address\": \"<my 2nd address>\" "
1837 "\"label\": \"example 2\", \"timestamp\": 1455191480 }]'") +
1840 "'[{ \"scriptPubKey\": { \"address\": \"<my address>\" }, "
1841 "\"timestamp\":1455191478 }]' '{ \"rescan\": false}'")
1846 std::shared_ptr<CWallet>
const wallet =
1863 if (options.
exists(
"rescan")) {
1871 "Wallet is currently rescanning. Abort "
1872 "existing rescan or wait.");
1905 if (result[
"success"].get_bool()) {
1925 "Rescan aborted by user.");
1938 results.at(i).exists(
"error")) {
1950 response.push_back(std::move(result));
1970 if (!data.exists(
"desc")) {
1974 const std::string &descriptor = data[
"desc"].get_str();
1976 data.exists(
"active") ? data[
"active"].get_bool() :
false;
1978 data.exists(
"internal") ? data[
"internal"].get_bool() :
false;
1979 const std::string &label =
1980 data.exists(
"label") ? data[
"label"].get_str() :
"";
1992 int64_t range_start = 0, range_end = 1, next_index = 0;
1993 if (!
parsed_desc->IsRange() && data.exists(
"range")) {
1996 "Range should not be specified for an un-ranged descriptor");
1998 if (data.exists(
"range")) {
2000 range_start =
range.first;
2003 range_end =
range.second + 1;
2006 "Range not given, using default keypool range");
2010 next_index = range_start;
2012 if (data.exists(
"next_index")) {
2013 next_index = data[
"next_index"].getInt<
int64_t>();
2017 "next_index is out of range");
2025 "Active descriptors must be ranged");
2029 if (data.exists(
"range") && data.exists(
"label")) {
2031 "Ranged descriptors should not have a label");
2035 if (
internal && data.exists(
"label")) {
2037 "Internal addresses should not have a label");
2043 "Combo descriptors cannot be set to active");
2048 !keys.
keys.empty()) {
2050 "Cannot import private keys to a wallet with "
2051 "private keys disabled");
2057 std::vector<CScript> scripts;
2061 "Cannot expand descriptor. Probably because of hardened "
2062 "derivations without private keys provided");
2079 if (keys.
keys.empty()) {
2082 "Cannot import descriptor without private keys to a wallet "
2083 "with private keys enabled");
2087 "Not all private keys provided. Some wallet functionality "
2088 "may return unexpected errors");
2093 range_end, next_index);
2097 pwallet->GetDescriptorScriptPubKeyMan(
w_desc);
2109 strprintf(
"Could not add descriptor '%s'", descriptor));
2114 if (!
w_desc.descriptor->GetOutputType()) {
2116 "Unknown output type, cannot set descriptor to active.");
2118 pwallet->AddActiveScriptPubKeyMan(
2123 if (
w_desc.descriptor->GetOutputType()) {
2124 pwallet->DeactivateScriptPubKeyMan(
2143 "importdescriptors",
2144 "Import descriptors. This will trigger a rescan of the blockchain "
2145 "based on the earliest timestamp of all descriptors being imported. "
2146 "Requires a new wallet backup.\n"
2147 "\nNote: This call can take over an hour to complete if using an early "
2148 "timestamp; during that time, other rpc calls\n"
2149 "may report that the imported keys, addresses or scripts exist but "
2150 "related transactions are still missing.\n",
2155 "Data to be imported",
2164 "Descriptor to import."},
2166 "Set this descriptor to be the active descriptor for "
2167 "the corresponding output type/externality"},
2170 "If a ranged descriptor is used, this specifies the "
2171 "end or the range (in the form [begin,end]) to "
2175 "If a ranged descriptor is set to active, this "
2176 "specifies the next index to generate addresses "
2179 "Time from which to start rescanning the blockchain "
2180 "for this descriptor, in " +
2183 "Use the string \"now\" to substitute the "
2184 "current synced blockchain time.\n"
2185 "\"now\" can be specified to bypass scanning, "
2186 "for outputs which are known to never have been "
2188 "0 can be specified to scan the entire "
2189 "blockchain. Blocks up to 2 hours before the "
2190 "earliest timestamp\n"
2191 "of all descriptors being imported will be "
2194 "integer / string"}}},
2197 "Whether matching outputs should be treated as not "
2198 "incoming payments (e.g. change)"},
2200 "Label to assign to the address, only allowed with "
2209 "Response is an array with the same size as the input that "
2210 "has the execution result",
2235 "'[{ \"desc\": \"<my descriptor>\", "
2236 "\"timestamp\":1455191478, \"internal\": true }, "
2237 "{ \"desc\": \"<my desccriptor 2>\", \"label\": "
2238 "\"example 2\", \"timestamp\": 1455191480 }]'") +
2240 "importdescriptors",
2241 "'[{ \"desc\": \"<my descriptor>\", \"timestamp\":1455191478, "
2242 "\"active\": true, \"range\": [0,100], \"label\": \"<my "
2243 "cashaddr wallet>\" }]'")},
2246 std::shared_ptr<CWallet>
const wallet =
2256 "importdescriptors is not available for "
2257 "non-descriptor wallets");
2263 "Wallet is currently rescanning. Abort "
2264 "existing rescan or wait.");
2271 bool rescan =
false;
2296 if (!rescan && result[
"success"].get_bool()) {
2314 "Rescan aborted by user.");
2323 for (
unsigned int i = 0; i <
requests.size(); ++i) {
2332 results.at(i).exists(
"error")) {
2345 response.push_back(std::move(result));
2359 "Safely copies current wallet file to destination, which can be a "
2360 "directory or a path with filename.\n",
2363 "The destination directory or file"},
2370 std::shared_ptr<CWallet>
const wallet =
2380 pwallet->BlockUntilSyncedToCurrentChain();
2384 std::string
strDest = request.params[0].get_str();
2387 "Error: Wallet backup failed!");
2398 "\nRestore and loads a wallet from backup.\n",
2401 "The name that will be applied to the restored wallet"},
2403 "The backup file that will be used to restore the wallet."},
2406 "Save wallet name to persistent settings and load on startup. "
2407 "True to add wallet to startup list, false to remove, null to "
2408 "leave unchanged."},
2415 "The wallet name if restored successfully."},
2417 "Warning message if wallet was not loaded cleanly."},
2421 "\"testwallet\" \"home\\backups\\backup-file.bak\"") +
2424 "\"testwallet\" \"home\\backups\\backup-file.bak\"") +
2427 {{
"wallet_name",
"testwallet"},
2428 {
"backup_file",
"home\\backups\\backup-file.bak\""},
2429 {
"load_on_startup",
true}}) +
2432 {{
"wallet_name",
"testwallet"},
2433 {
"backup_file",
"home\\backups\\backup-file.bak\""},
2434 {
"load_on_startup",
true}})},
2444 "Backup file does not exist");
2447 std::string
wallet_name = request.params[0].get_str();
2454 "Wallet name already exists.");
2459 strprintf(
"Failed to create database path "
2460 "'%s'. Database already exists.",
static RPCHelpMan dumpcoins()
RPCHelpMan importprivkey()
static const int64_t TIMESTAMP_MIN
RPCHelpMan importdescriptors()
static void RescanWallet(CWallet &wallet, const WalletRescanReserver &reserver, int64_t time_begin=TIMESTAMP_MIN, bool update=true)
static std::string RecurseImportData(const CScript &script, ImportData &import_data, const ScriptContext script_ctx)
RPCHelpMan importaddress()
RPCHelpMan importwallet()
Span< const CRPCCommand > GetWalletDumpRPCCommands()
static UniValue ProcessImportLegacy(CWallet *const pwallet, ImportData &import_data, std::map< CKeyID, CPubKey > &pubkey_map, std::map< CKeyID, CKey > &privkey_map, std::set< CScript > &script_pub_keys, bool &have_solving_data, const UniValue &data, std::vector< CKeyID > &ordered_pubkeys)
RPCHelpMan importpubkey()
static std::string EncodeDumpString(const std::string &str)
static bool GetWalletAddressesForKey(const Config &config, LegacyScriptPubKeyMan *spk_man, const CWallet *const pwallet, const CKeyID &keyid, std::string &strAddr, std::string &strLabel) EXCLUSIVE_LOCKS_REQUIRED(pwallet -> cs_wallet)
static std::string DecodeDumpString(const std::string &str)
RPCHelpMan importprunedfunds()
RPCHelpMan restorewallet()
static UniValue ProcessImportDescriptor(ImportData &import_data, std::map< CKeyID, CPubKey > &pubkey_map, std::map< CKeyID, CKey > &privkey_map, std::set< CScript > &script_pub_keys, bool &have_solving_data, const UniValue &data, std::vector< CKeyID > &ordered_pubkeys)
@ TOP
Top-level scriptPubKey.
static UniValue ProcessImport(CWallet *const pwallet, const UniValue &data, const int64_t timestamp) EXCLUSIVE_LOCKS_REQUIRED(pwallet -> cs_wallet)
RPCHelpMan backupwallet()
static UniValue ProcessDescriptorImport(CWallet *const pwallet, const UniValue &data, const int64_t timestamp) EXCLUSIVE_LOCKS_REQUIRED(pwallet -> cs_wallet)
RPCHelpMan removeprunedfunds()
static int64_t GetImportTimestamp(const UniValue &data, int64_t now)
static std::string GetRescanErrorMessage(const std::string &object, const int64_t objectTimestamp, const int64_t blockTimestamp)
std::string WriteHDKeypath(const std::vector< uint32_t > &keypath)
Write HD keypaths as strings.
static constexpr int64_t TIMESTAMP_WINDOW
Timestamp window used as a grace period by code that compares external timestamps (such as timestamps...
#define CHECK_NONFATAL(condition)
Identity function.
int64_t GetIntArg(const std::string &strArg, int64_t nDefault) const
Return integer argument or default value.
Double ended buffer combining vector and stream-like interfaces.
An encapsulated secp256k1 private key.
bool IsValid() const
Check whether this private key is valid.
CPubKey GetPubKey() const
Compute the public key from a private key.
bool VerifyPubKey(const CPubKey &vchPubKey) const
Verify thoroughly whether a private key and a public key match.
A reference to a CKey: the Hash160 of its serialized public key.
Used to create a Merkle proof (usually from a subset of transactions), which consists of a block head...
A mutable version of CTransaction.
TxId GetId() const
Compute the id and hash of this CMutableTransaction.
An encapsulated public key.
CKeyID GetID() const
Get the KeyID of this public key (hash of its serialization)
bool IsFullyValid() const
fully validate whether this is a valid public key (more expensive than IsValid())
Serialized script, used inside transaction inputs and outputs.
A reference to a CScript: the Hash160 of its serialization (see script.h)
A CWallet maintains a set of transactions and balances, and provides the ability to create new transa...
BlockHash GetLastBlockHash() const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
void ConnectScriptPubKeyManNotifiers()
Connect the signals from ScriptPubKeyMans to the signals in CWallet.
const std::string GetDisplayName() const override
Returns a bracketed wallet name for displaying in logs, will return [default wallet] if the wallet ha...
void WalletLogPrintf(std::string fmt, Params... parameters) const
Prepends the wallet name in logging output to ease debugging in multi-wallet use cases.
bool IsAbortingRescan() const
interfaces::Chain & chain() const
Interface for accessing chain state.
bool BackupWallet(const std::string &strDest) const
const CAddressBookData * FindAddressBookEntry(const CTxDestination &, bool allow_change=false) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
A Span is an object that can refer to a contiguous sequence of objects.
void push_back(UniValue val)
const std::string & get_str() const
enum VType getType() const
const std::vector< UniValue > & getValues() const
const UniValue & get_array() const
bool exists(const std::string &key) const
void pushKV(std::string key, UniValue val)
Descriptor with some wallet metadata.
RAII object to check and reserve a wallet rescan.
unsigned int size() const
Path class wrapper to block calls to the fs::path(std::string) implicit constructor and the fs::path:...
virtual bool findAncestorByHash(const BlockHash &block_hash, const BlockHash &ancestor_hash, const FoundBlock &ancestor_out={})=0
Return whether block descends from a specified ancestor, and optionally return ancestor information.
virtual bool findBlock(const BlockHash &hash, const FoundBlock &block={})=0
Return whether node has the block and optionally return block metadata or contents.
virtual void showProgress(const std::string &title, int progress, bool resume_possible)=0
Send progress indicator.
virtual bool havePruned()=0
Check if any block has been pruned.
Helper for findBlock to selectively return pieces of block data.
static UniValue Parse(std::string_view raw)
Parse string to UniValue or throw runtime_error if string contains invalid JSON.
const std::string CLIENT_BUILD
const std::string CLIENT_NAME
bool DecodeHexTx(CMutableTransaction &tx, const std::string &strHexTx)
bool TryCreateDirectories(const fs::path &p)
Ignores exceptions thrown by create_directories if the requested directory exists.
bool SetAddressBook(const CTxDestination &address, const std::string &strName, const std::string &purpose)
DBErrors ZapSelectTx(std::vector< TxId > &txIdsIn, std::vector< TxId > &txIdsOut) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
bool ImportPubKeys(const std::vector< CKeyID > &ordered_pubkeys, const std::map< CKeyID, CPubKey > &pubkey_map, const std::map< CKeyID, std::pair< CPubKey, KeyOriginInfo > > &key_origins, const bool add_keypool, const bool internal, const int64_t timestamp) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
bool ImportScripts(const std::set< CScript > scripts, int64_t timestamp) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
CWalletTx * AddToWallet(CTransactionRef tx, const CWalletTx::Confirmation &confirm, const UpdateWalletTxFn &update_wtx=nullptr, bool fFlushOnClose=true)
bool ImportPrivKeys(const std::map< CKeyID, CKey > &privkey_map, const int64_t timestamp) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
isminetype IsMine(const CTxDestination &dest) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
bool ImportScriptPubKeys(const std::string &label, const std::set< CScript > &script_pub_keys, const bool have_solving_data, const bool apply_label, const int64_t timestamp) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
const CChainParams & GetChainParams() const override
void ReacceptWalletTransactions() EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
bool IsWalletFlagSet(uint64_t flag) const override
Check if a certain wallet flag is set.
int64_t RescanFromTime(int64_t startTime, const WalletRescanReserver &reserver, bool update)
Scan active chain for relevant transactions after importing keys.
std::string EncodeDestination(const CTxDestination &dest, const Config &config)
std::string EncodeExtKey(const CExtKey &key)
std::string EncodeSecret(const CKey &key)
CTxDestination DecodeDestination(const std::string &addr, const CChainParams ¶ms)
CKey DecodeSecret(const std::string &str)
bool error(const char *fmt, const Args &...args)
static path absolute(const path &p)
static path u8path(const std::string &utf8_str)
static bool exists(const path &p)
static bool copy_file(const path &from, const path &to, copy_options options)
static std::string PathToString(const path &path)
Convert path object to byte string.
static path PathFromString(const std::string &string)
Convert byte string to path object.
fs::path AbsPathJoin(const fs::path &base, const fs::path &path)
Helper function for joining two paths.
CTxDestination GetDestinationForKey(const CPubKey &key, OutputType type)
Get a destination of the requested type (if possible) to the specified key.
std::vector< CTxDestination > GetAllDestinationsForKey(const CPubKey &key)
Get all destinations (potentially) supported by the wallet for the given key.
static CTransactionRef MakeTransactionRef()
std::shared_ptr< const CTransaction > CTransactionRef
T GetRand(T nMax=std::numeric_limits< T >::max()) noexcept
Generate a uniform random integer of type T in the range [0..nMax) nMax defaults to std::numeric_limi...
UniValue JSONRPCError(int code, const std::string &message)
@ RPC_MISC_ERROR
General application defined errors std::exception thrown in command handling.
@ RPC_TYPE_ERROR
Unexpected type was passed as parameter.
@ RPC_INVALID_PARAMETER
Invalid, missing or duplicate parameter.
@ RPC_WALLET_ERROR
Wallet errors Unspecified problem with wallet (key not found etc.)
@ RPC_DESERIALIZATION_ERROR
Error parsing or validating structure in raw format.
@ RPC_INVALID_ADDRESS_OR_KEY
Invalid address or key.
std::pair< int64_t, int64_t > ParseDescriptorRange(const UniValue &value)
Parse a JSON range specified as int64, or [int64, int64].
std::string HelpExampleCli(const std::string &methodname, const std::string &args)
std::string HelpExampleRpcNamed(const std::string &methodname, const RPCArgList &args)
std::vector< uint8_t > ParseHexV(const UniValue &v, std::string strName)
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.
uint256 ParseHashV(const UniValue &v, std::string strName)
Utilities: convert hex-encoded values (throws error if not hex).
std::string HelpExampleCliNamed(const std::string &methodname, const RPCArgList &args)
static const unsigned int DEFAULT_KEYPOOL_SIZE
Default for -keypool.
CKeyID GetKeyForDestination(const SigningProvider &store, const CTxDestination &dest)
Return the CKeyID of the key involved in a script (if there is a unique one).
std::map< CTxDestination, std::vector< COutput > > ListCoins(const CWallet &wallet)
Return list of available coins and locked coins grouped by non-change output address.
bool ExtractDestination(const CScript &scriptPubKey, CTxDestination &addressRet)
Parse a standard scriptPubKey for the destination address.
TxoutType Solver(const CScript &scriptPubKey, std::vector< std::vector< uint8_t > > &vSolutionsRet)
Parse a scriptPubKey and identify script type for standard scripts.
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.
std::variant< CNoDestination, PKHash, ScriptHash > CTxDestination
A txout script template with a specific destination.
auto Join(const std::vector< T > &list, const BaseType &separator, UnaryOp unary_op) -> decltype(unary_op(list.at(0)))
Join a list of items.
std::vector< std::string > SplitString(std::string_view str, char sep)
void SetSeed(Span< const std::byte > seed)
Confirmation includes tx status and a triplet of {block height/block hash/tx index in block} at which...
std::map< CKeyID, CKey > keys
std::unique_ptr< CScript > redeemscript
Provided redeemScript; will be moved to import_scripts if relevant.
std::map< CKeyID, bool > used_keys
Import these private keys if available (the value indicates whether if the key is required for solvab...
std::set< CScript > import_scripts
std::map< CKeyID, std::pair< CPubKey, KeyOriginInfo > > key_origins
@ RANGE
Special type that is a NUM or [NUM,NUM].
@ STR_HEX
Special type that is a STR with only hex chars.
@ OBJ_NAMED_PARAMS
Special type that behaves almost exactly like OBJ, defining an options object with a list of pre-defi...
std::string DefaultHint
Hint for default value.
@ OMITTED
The arg is optional for one of two reasons:
std::vector< std::string > type_str
Should be empty unless it is supposed to override the auto-generated type strings.
std::string oneline_description
Should be empty unless it is supposed to override the auto-generated summary line.
@ ELISION
Special type to denote elision (...)
@ 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.
A TxId is the identifier of a transaction.
WalletContext struct containing references to state shared between CWallet instances,...
#define EXCLUSIVE_LOCKS_REQUIRED(...)
int64_t GetTime()
DEPRECATED Use either ClockType::now() or Now<TimePointType>() if a cast is needed.
int64_t ParseISO8601DateTime(const std::string &str)
std::string FormatISO8601DateTime(int64_t nTime)
ISO 8601 formatting is preferred.
bilingual_str _(const char *psz)
Translation function.
bilingual_str Untranslated(std::string original)
Mark a bilingual_str as untranslated.
const UniValue NullUniValue
const char * uvTypeName(UniValue::VType t)
std::string HexStr(const Span< const uint8_t > s)
Convert a span of bytes to a lower-case hexadecimal string.
template std::vector< std::byte > ParseHex(std::string_view)
bool IsHex(std::string_view str)
Returns true if each character in str is a hex character, and has an even number of hex digits.
static const int PROTOCOL_VERSION
network protocol versioning
void EnsureWalletIsUnlocked(const CWallet *pwallet)
std::shared_ptr< CWallet > GetWalletForJSONRPCRequest(const JSONRPCRequest &request)
Figures out what wallet, if any, to use for a JSONRPCRequest.
LegacyScriptPubKeyMan & EnsureLegacyScriptPubKeyMan(CWallet &wallet, bool also_create)
WalletContext & EnsureWalletContext(const std::any &context)
std::tuple< std::shared_ptr< CWallet >, std::vector< bilingual_str > > LoadWalletHelper(WalletContext &context, UniValue load_on_start_param, const std::string wallet_name)
fs::path GetWalletDir()
Get the path of the wallet directory.
@ WALLET_FLAG_DISABLE_PRIVATE_KEYS
@ WALLET_FLAG_DESCRIPTORS
Indicate that this wallet supports DescriptorScriptPubKeyMan.