41 std::stringstream ret;
42 for (
const uint8_t c : str) {
43 if (c <= 32 || c >= 128 || c ==
'%') {
44 ret <<
'%' <<
HexStr({&c, 1});
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));
69 std::string &strAddr, std::string &strLabel)
71 bool fLabelFound =
false;
73 spk_man->GetKey(keyid, key);
75 const auto *address_book_entry = pwallet->FindAddressBookEntry(dest);
76 if (address_book_entry) {
77 if (!strAddr.empty()) {
88 pwallet->m_default_address_type),
99 int64_t scanned_time =
wallet.RescanFromTime(time_begin, reserver, update);
100 if (
wallet.IsAbortingRescan()) {
102 }
else if (scanned_time > time_begin) {
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();
171 std::string strLabel =
"";
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");
190 if (fRescan && !reserver.
reserve()) {
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 =
318 std::string strLabel;
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");
338 if (fRescan && !reserver.
reserve()) {
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};
383 strLabel, scripts,
false ,
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");
467 size_t txnIndex = vIndex[it - vMatch.begin()];
470 CWalletTx::Status::CONFIRMED, height,
474 if (pwallet->
IsMine(*tx_ref)) {
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);
518 std::vector<TxId> txIdsOut;
523 "Could not properly delete the transaction.");
526 if (txIdsOut.empty()) {
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 =
578 std::string strLabel;
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");
598 if (fRescan && !reserver.
reserve()) {
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");
618 std::set<CScript> script_pub_keys;
626 strLabel, script_pub_keys,
true ,
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.");
692 int64_t nTimeBegin = 0;
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");
710 int64_t nFilesize = std::max<int64_t>(1, file.tellg());
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] ==
'#') {
739 std::vector<std::string> vstr =
SplitString(line,
' ');
740 if (vstr.size() < 2) {
746 std::string strLabel;
748 for (
size_t nStr = 2; nStr < vstr.size(); nStr++) {
749 if (vstr[nStr].front() ==
'#') {
752 if (vstr[nStr] ==
"change=1") {
755 if (vstr[nStr] ==
"reserve=1") {
758 if (vstr[nStr].substr(0, 6) ==
"label=") {
765 std::make_tuple(key, nTime, fLabel, strLabel));
766 }
else if (
IsHex(vstr[0])) {
767 std::vector<uint8_t> vData(
ParseHex(vstr[0]));
768 CScript script = CScript(vData.begin(), vData.end());
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());
787 for (
const auto &key_tuple : keys) {
790 std::max(50, std::min<int>(75, 100 * progress / total) +
793 const CKey &key = std::get<0>(key_tuple);
794 int64_t time = std::get<1>(key_tuple);
795 bool has_label = std::get<2>(key_tuple);
796 std::string label = std::get<3>(key_tuple);
808 "Error importing key for %s\n",
819 nTimeBegin = std::min(nTimeBegin, time);
822 for (
const auto &script_pair : scripts) {
825 std::max(50, std::min<int>(75, 100 * progress / total) +
828 const CScript &script = script_pair.first;
829 int64_t time = script_pair.second;
838 nTimeBegin = std::min(nTimeBegin, time);
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");
905 if (!spk_man.
GetKey(keyid, vchSecret)) {
907 "Private key for address " + strAddress +
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");
985 std::map<CKeyID, int64_t> mapKeyBirth;
986 wallet.GetKeyBirthTimes(mapKeyBirth);
988 int64_t block_time = 0;
998 const std::map<CKeyID, int64_t> &mapKeyPool =
1000 std::set<CScriptID> scripts = spk_man.
GetCScripts();
1003 std::vector<std::pair<int64_t, CKeyID>> vKeyBirth;
1004 for (
const auto &entry : mapKeyBirth) {
1005 vKeyBirth.push_back(std::make_pair(entry.second, entry.first));
1007 mapKeyBirth.clear();
1008 std::sort(vKeyBirth.begin(), vKeyBirth.end());
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 =
1036 it != vKeyBirth.end(); it++) {
1037 const CKeyID &keyid = it->second;
1039 std::string strAddr;
1040 std::string strLabel;
1042 if (spk_man.
GetKey(keyid, key)) {
1045 keyid, strAddr, strLabel)) {
1046 file <<
strprintf(
"label=%s", strLabel);
1047 }
else if (keyid == seed_id) {
1049 }
else if (mapKeyPool.count(keyid)) {
1050 file <<
"reserve=1";
1051 }
else if (spk_man.mapKeyMetadata[keyid].hdKeypath ==
"s") {
1052 file <<
"inactivehdseed=1";
1057 " # addr=%s%s\n", strAddr,
1058 (spk_man.mapKeyMetadata[keyid].has_key_origin
1066 for (
const CScriptID &scriptid : scripts) {
1068 std::string create_time =
"0";
1069 std::string address =
1072 auto it = spk_man.m_script_metadata.find(scriptid);
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());
1149 utxo.
pushKV(
"vout", o.i);
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;
1194 switch (script_type) {
1196 CPubKey pubkey(solverdata[0]);
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) {
1227 CPubKey pubkey(solverdata[i]);
1233 return "unspendable script";
1236 return "unrecognized script";
1242 std::map<CKeyID, CPubKey> &pubkey_map, std::map<CKeyID, CKey> &privkey_map,
1243 std::set<CScript> &script_pub_keys,
bool &have_solving_data,
1244 const UniValue &data, std::vector<CKeyID> &ordered_pubkeys) {
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 =
1258 isScript ? scriptPubKey.
get_str() : scriptPubKey[
"address"].
get_str();
1261 const std::string &strRedeemScript =
1262 data.
exists(
"redeemscript") ? data[
"redeemscript"].
get_str() :
"";
1267 const bool internal =
1269 const bool watchOnly =
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.");
1302 script_pub_keys.emplace(script);
1305 if (strRedeemScript.size()) {
1306 if (!
IsHex(strRedeemScript)) {
1308 "Invalid redeem script \"" + strRedeemScript +
1309 "\": must be hex string");
1311 auto parsed_redeemscript =
ParseHex(strRedeemScript);
1313 parsed_redeemscript.begin(), parsed_redeemscript.end());
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");
1321 auto parsed_pubkey =
ParseHex(str);
1322 CPubKey pubkey(parsed_pubkey);
1326 "\" is not a valid public key");
1328 pubkey_map.emplace(pubkey.
GetID(), pubkey);
1329 ordered_pubkeys.push_back(pubkey.
GetID());
1331 for (
size_t i = 0; i < keys.
size(); ++i) {
1332 const auto &str = keys[i].
get_str();
1336 "Invalid private key encoding");
1340 if (pubkey_map.count(
id)) {
1341 pubkey_map.erase(
id);
1343 privkey_map.emplace(
id, key);
1348 import_data.
redeemscript || pubkey_map.size() || privkey_map.size();
1349 if (have_solving_data) {
1355 bool spendable = std::all_of(
1357 [&](
const std::pair<CKeyID, bool> &used_key) {
1358 return privkey_map.count(used_key.first) > 0;
1360 if (!watchOnly && !spendable) {
1361 warnings.
push_back(
"Some private keys are missing, outputs "
1362 "will be considered watchonly. If this is "
1363 "intentional, specify the watchonly flag.");
1365 if (watchOnly && spendable) {
1367 "All private keys are provided, outputs will be considered "
1368 "spendable. If this is intentional, do not specify the "
1373 if (
error.empty()) {
1374 for (
const auto &require_key : import_data.
used_keys) {
1375 if (!require_key.second) {
1380 if (pubkey_map.count(require_key.first) == 0 &&
1381 privkey_map.count(require_key.first) == 0) {
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.");
1393 privkey_map.clear();
1394 have_solving_data =
false;
1401 "Ignoring redeemscript as this is not a P2SH script.");
1403 for (
auto it = privkey_map.begin(); it != privkey_map.end();) {
1405 if (import_data.
used_keys.count(oldit->first) == 0) {
1406 warnings.
push_back(
"Ignoring irrelevant private key.");
1407 privkey_map.erase(oldit);
1410 for (
auto it = pubkey_map.begin(); it != pubkey_map.end();) {
1412 auto key_data_it = import_data.
used_keys.find(oldit->first);
1413 if (key_data_it == import_data.
used_keys.end() ||
1414 !key_data_it->second) {
1415 warnings.
push_back(
"Ignoring public key \"" +
1417 "\" as it doesn't appear inside P2PKH.");
1418 pubkey_map.erase(oldit);
1428 std::map<CKeyID, CPubKey> &pubkey_map,
1429 std::map<CKeyID, CKey> &privkey_map,
1430 std::set<CScript> &script_pub_keys,
1431 bool &have_solving_data,
1433 std::vector<CKeyID> &ordered_pubkeys) {
1436 const std::string &descriptor = data[
"desc"].
get_str();
1445 have_solving_data = parsed_desc->IsSolvable();
1446 const bool watch_only =
1449 int64_t range_start = 0, range_end = 0;
1450 if (!parsed_desc->IsRange() && data.
exists(
"range")) {
1453 "Range should not be specified for an un-ranged descriptor");
1454 }
else if (parsed_desc->IsRange()) {
1455 if (!data.
exists(
"range")) {
1458 "Descriptor is ranged, please specify the range");
1468 for (
int i = range_start; i <= range_end; ++i) {
1470 std::vector<CScript> scripts_temp;
1471 parsed_desc->Expand(i, keys, scripts_temp, out_keys);
1472 std::copy(scripts_temp.begin(), scripts_temp.end(),
1473 std::inserter(script_pub_keys, script_pub_keys.end()));
1474 for (
const auto &key_pair : out_keys.
pubkeys) {
1475 ordered_pubkeys.push_back(key_pair.first);
1478 for (
const auto &x : out_keys.
scripts) {
1482 parsed_desc->ExpandPrivate(i, keys, out_keys);
1485 std::inserter(pubkey_map, pubkey_map.end()));
1486 std::copy(out_keys.
keys.begin(), out_keys.
keys.end(),
1487 std::inserter(privkey_map, privkey_map.end()));
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");
1504 if (!pubkey_map.count(
id)) {
1505 warnings.
push_back(
"Ignoring irrelevant private key.");
1507 privkey_map.emplace(
id, key);
1518 std::all_of(pubkey_map.begin(), pubkey_map.end(),
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; });
1526 if (!watch_only && !spendable) {
1528 "Some private keys are missing, outputs will be considered "
1529 "watchonly. If this is intentional, specify the watchonly flag.");
1531 if (watch_only && spendable) {
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.");
1541 const int64_t timestamp)
1547 const bool internal =
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() :
"";
1556 const bool add_keypool =
1557 data.exists(
"keypool") ? data[
"keypool"].get_bool() :
false;
1563 "Keys can only be imported to the keypool when "
1564 "private keys are disabled");
1568 std::map<CKeyID, CPubKey> pubkey_map;
1569 std::map<CKeyID, CKey> privkey_map;
1570 std::set<CScript> script_pub_keys;
1571 std::vector<CKeyID> ordered_pubkeys;
1572 bool have_solving_data;
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")) {
1580 pwallet, import_data, pubkey_map, privkey_map, script_pub_keys,
1581 have_solving_data, data, ordered_pubkeys);
1582 }
else if (data.exists(
"desc")) {
1584 import_data, pubkey_map, privkey_map, script_pub_keys,
1585 have_solving_data, data, ordered_pubkeys);
1589 "Either a descriptor or scriptPubKey must be provided.");
1595 !privkey_map.empty()) {
1597 "Cannot import private keys to a wallet with "
1598 "private keys disabled");
1602 for (
const CScript &script : script_pub_keys) {
1605 "The wallet already contains the private "
1606 "key for this address or script (\"" +
1612 pwallet->MarkDirty();
1613 if (!pwallet->ImportScripts(import_data.
import_scripts, timestamp)) {
1615 "Error adding script to wallet");
1617 if (!pwallet->ImportPrivKeys(privkey_map, timestamp)) {
1620 if (!pwallet->ImportPubKeys(ordered_pubkeys, pubkey_map,
1622 internal, timestamp)) {
1624 "Error adding address to wallet");
1626 if (!pwallet->ImportScriptPubKeys(label, script_pub_keys,
1627 have_solving_data, !internal,
1630 "Error adding address to wallet");
1636 result.
pushKV(
"error", e);
1643 if (warnings.
size()) {
1644 result.
pushKV(
"warnings", warnings);
1650 if (data.
exists(
"timestamp")) {
1651 const UniValue ×tamp = data[
"timestamp"];
1652 if (timestamp.
isNum()) {
1653 return timestamp.
getInt<int64_t>();
1654 }
else if (timestamp.
isStr() && timestamp.
get_str() ==
"now") {
1658 strprintf(
"Expected number or \"now\" timestamp "
1659 "value for key. got type %s",
1663 "Missing required timestamp field for key");
1667 const int64_t objectTimestamp,
1668 const int64_t blockTimestamp) {
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 =
1855 const UniValue &requests = mainRequest.params[0];
1858 bool fRescan =
true;
1860 if (!mainRequest.params[1].isNull()) {
1861 const UniValue &options = mainRequest.params[1];
1863 if (options.
exists(
"rescan")) {
1864 fRescan = options[
"rescan"].
get_bool();
1869 if (fRescan && !reserver.
reserve()) {
1871 "Wallet is currently rescanning. Abort "
1872 "existing rescan or wait.");
1876 bool fRunScan =
false;
1877 int64_t nLowestTimestamp = 0;
1886 FoundBlock().time(nLowestTimestamp).mtpTime(now)));
1891 const int64_t minimumTimestamp = 1;
1894 const int64_t timestamp = std::max(
1905 if (result[
"success"].get_bool()) {
1910 if (timestamp < nLowestTimestamp) {
1911 nLowestTimestamp = timestamp;
1915 if (fRescan && fRunScan && requests.
size()) {
1917 nLowestTimestamp, reserver,
true );
1925 "Rescan aborted by user.");
1927 if (scannedTime > nLowestTimestamp) {
1928 std::vector<UniValue> results =
response.getValues();
1938 results.at(i).exists(
"error")) {
1950 response.push_back(std::move(result));
1964 const int64_t timestamp)
1970 if (!data.exists(
"desc")) {
1974 const std::string &descriptor = data[
"desc"].get_str();
1976 data.exists(
"active") ? data[
"active"].get_bool() :
false;
1977 const bool internal =
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");
1997 }
else if (parsed_desc->IsRange()) {
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>();
2015 if (next_index < range_start || next_index >= range_end) {
2017 "next_index is out of range");
2023 if (active && !parsed_desc->IsRange()) {
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");
2041 if (active && !parsed_desc->IsSingleType()) {
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;
2058 if (!parsed_desc->Expand(0, keys, scripts, expand_keys)) {
2061 "Cannot expand descriptor. Probably because of hardened "
2062 "derivations without private keys provided");
2064 parsed_desc->ExpandPrivate(0, keys, expand_keys);
2067 bool have_all_privkeys = !expand_keys.
keys.empty();
2068 for (
const auto &entry : expand_keys.
origins) {
2069 const CKeyID &key_id = entry.first;
2071 if (!expand_keys.
GetKey(key_id, key)) {
2072 have_all_privkeys =
false;
2079 if (keys.
keys.empty()) {
2082 "Cannot import descriptor without private keys to a wallet "
2083 "with private keys enabled");
2085 if (!have_all_privkeys) {
2087 "Not all private keys provided. Some wallet functionality "
2088 "may return unexpected errors");
2093 range_end, next_index);
2096 auto existing_spk_manager =
2097 pwallet->GetDescriptorScriptPubKeyMan(w_desc);
2098 if (existing_spk_manager &&
2099 !existing_spk_manager->CanUpdateToWalletDescriptor(w_desc,
error)) {
2105 pwallet->AddWalletDescriptor(w_desc, keys, label, internal);
2106 if (spk_manager ==
nullptr) {
2109 strprintf(
"Could not add descriptor '%s'", descriptor));
2116 "Unknown output type, cannot set descriptor to active.");
2118 pwallet->AddActiveScriptPubKeyMan(
2119 spk_manager->GetID(), *w_desc.
descriptor->GetOutputType(),
2124 pwallet->DeactivateScriptPubKeyMan(
2125 spk_manager->GetID(), *w_desc.
descriptor->GetOutputType(),
2133 result.
pushKV(
"error", e);
2135 if (warnings.
size()) {
2136 result.
pushKV(
"warnings", warnings);
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.");
2267 const UniValue &requests = main_request.params[0];
2268 const int64_t minimum_timestamp = 1;
2270 int64_t lowest_timestamp = 0;
2271 bool rescan =
false;
2279 FoundBlock().time(lowest_timestamp).mtpTime(now)));
2284 const int64_t timestamp = std::max(
2290 if (lowest_timestamp > timestamp) {
2291 lowest_timestamp = timestamp;
2296 if (!rescan && result[
"success"].get_bool()) {
2306 lowest_timestamp, reserver,
true );
2314 "Rescan aborted by user.");
2317 if (scanned_time > lowest_timestamp) {
2318 std::vector<UniValue> results =
response.getValues();
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.",
2464 auto wallet_file = wallet_path /
"wallet.dat";
2466 fs::copy_file(backup_file, wallet_file, fs::copy_options::none);
2468 auto [
wallet, warnings] =
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.
CKeyID seed_id
seed hash160
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...
CBlockHeader header
Public only for unit testing.
A mutable version of CTransaction.
TxId GetId() const
Compute the id and hash of this CMutableTransaction.
uint256 ExtractMatches(std::vector< uint256 > &vMatch, std::vector< size_t > &vnIndex)
Extract the matching txid's represented by this partial merkle tree and their respective indices with...
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())
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)
virtual bool GetCScript(const CScriptID &hash, CScript &redeemScriptOut) const override
virtual std::set< CScriptID > GetCScripts() const
RecursiveMutex cs_KeyStore
const CHDChain & GetHDChain() const
bool GetKey(const CKeyID &address, CKey &keyOut) const override
const std::map< CKeyID, int64_t > & GetAllReserveKeys() const
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.
std::shared_ptr< Descriptor > descriptor
RAII object to check and reserve a wallet rescan.
Path class wrapper to block calls to the fs::path(std::string) implicit constructor and the fs::path:...
std::string u8string() const
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
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, std::pair< CPubKey, KeyOriginInfo > > origins
bool GetKey(const CKeyID &keyid, CKey &key) const override
std::map< CKeyID, CPubKey > pubkeys
std::map< CKeyID, CKey > keys
std::map< CScriptID, CScript > scripts
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.