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",
123 "The private key (see dumpprivkey)"},
126 "current label if address exists, otherwise \"\""},
127 "An optional label"},
129 "Rescan the wallet for transactions"},
133 "\nDump a private key\n" +
135 "\nImport the private key with rescan\n" +
137 "\nImport using a label and without rescan\n" +
139 "\nImport using default blank label and without rescan\n" +
141 "\nAs a JSON-RPC call\n" +
142 HelpExampleRpc(
"importprivkey",
"\"mykey\", \"testing\", false")},
145 std::shared_ptr<CWallet>
const wallet =
155 "Cannot import private keys to a wallet with "
156 "private keys disabled");
168 std::string strSecret = request.params[0].get_str();
169 std::string strLabel =
"";
170 if (!request.params[1].isNull()) {
171 strLabel = request.params[1].get_str();
175 if (!request.params[2].isNull()) {
176 fRescan = request.params[2].get_bool();
185 "Rescan is disabled when blocks are pruned");
188 if (fRescan && !reserver.
reserve()) {
191 "Wallet is currently rescanning. Abort existing "
198 "Invalid private key encoding");
211 if (!request.params[1].isNull() ||
220 "Error adding key to wallet");
236 "Stops current wallet rescan triggered by an RPC call, e.g. by an "
237 "importprivkey call.\n"
238 "Note: Use \"getwalletinfo\" to query the scanning progress.\n",
241 "Whether the abort was successful"},
244 "\nAbort the running wallet rescan\n" +
246 "\nAs a JSON-RPC call\n" +
250 std::shared_ptr<CWallet>
const wallet =
269 "Adds an address or script (in hex) that can be watched as if it "
270 "were in your wallet but cannot be used to spend. Requires a new "
272 "\nNote: This call can take minutes to complete if rescan is true, "
273 "during that time, other rpc calls\n"
274 "may report that the imported address exists but related transactions "
275 "are still missing, leading to temporarily incorrect/bogus balances "
276 "and unspent outputs until rescan completes.\n"
277 "If you have the full public key, you should call importpubkey instead "
279 "Hint: use importmulti to import more than one address.\n"
280 "\nNote: If you import a non-standard raw script in hex form, outputs "
281 "sending to it will be treated\n"
282 "as change, and not show up in many RPCs.\n"
283 "Note: Use \"getwalletinfo\" to query the scanning progress.\n",
286 "The Bitcoin address (or hex-encoded script)"},
288 "An optional label"},
290 "Rescan the wallet for transactions"},
292 "Add the P2SH version of the script as well"},
296 "\nImport an address with rescan\n" +
298 "\nImport using a label without rescan\n" +
299 HelpExampleCli(
"importaddress",
"\"myaddress\" \"testing\" false") +
300 "\nAs a JSON-RPC call\n" +
302 "\"myaddress\", \"testing\", false")},
305 std::shared_ptr<CWallet>
const wallet =
314 std::string strLabel;
315 if (!request.params[1].isNull()) {
316 strLabel = request.params[1].get_str();
321 if (!request.params[2].isNull()) {
322 fRescan = request.params[2].get_bool();
330 "Rescan is disabled when blocks are pruned");
334 if (fRescan && !reserver.
reserve()) {
336 "Wallet is currently rescanning. Abort "
337 "existing rescan or wait.");
342 if (!request.params[3].isNull()) {
343 fP2SH = request.params[3].get_bool();
350 request.params[0].get_str(),
wallet->GetChainParams());
355 "Cannot use the p2sh flag with an address - "
356 "use a script instead");
365 }
else if (
IsHex(request.params[0].get_str())) {
366 std::vector<uint8_t> data(
367 ParseHex(request.params[0].get_str()));
368 CScript redeem_script(data.begin(), data.end());
370 std::set<CScript> scripts = {redeem_script};
379 strLabel, scripts,
false ,
383 "Invalid Bitcoin address or script");
402 "Imports funds without rescan. Corresponding address or script must "
403 "previously be included in wallet. Aimed towards pruned wallets. The "
404 "end-user is responsible to import additional transactions that "
405 "subsequently spend the imported outputs or rescan after the point in "
406 "the blockchain the transaction is included.\n",
409 "A raw transaction in hex funding an already-existing address in "
412 "The hex output from gettxoutproof that contains the transaction"},
418 std::shared_ptr<CWallet>
const wallet =
426 if (!
DecodeHexTx(tx, request.params[0].get_str())) {
439 std::vector<uint256> vMatch;
440 std::vector<size_t> vIndex;
444 "Something wrong with merkleblock");
453 "Block not found in chain");
456 std::vector<uint256>::const_iterator it;
457 if ((it = std::find(vMatch.begin(), vMatch.end(), txid)) ==
460 "Transaction given doesn't exist in proof");
463 size_t txnIndex = vIndex[it - vMatch.begin()];
466 CWalletTx::Status::CONFIRMED, height,
470 if (pwallet->
IsMine(*tx_ref)) {
477 "No addresses in wallet correspond to included transaction");
485 "Deletes the specified transaction from the wallet. Meant for use "
486 "with pruned wallets and as a companion to importprunedfunds. This "
487 "will affect wallet balances.\n",
490 "The hex-encoded id of the transaction you are deleting"},
494 "\"a8d0c0184dde994a09ec054286f1ce581bebf4644"
495 "6a512166eae7628734ea0a5\"") +
496 "\nAs a JSON-RPC call\n" +
498 "\"a8d0c0184dde994a09ec054286f1ce581bebf4644"
499 "6a512166eae7628734ea0a5\"")},
502 std::shared_ptr<CWallet>
const wallet =
512 std::vector<TxId> txIds;
513 txIds.push_back(txid);
514 std::vector<TxId> txIdsOut;
519 "Could not properly delete the transaction.");
522 if (txIdsOut.empty()) {
524 "Transaction does not exist in wallet.");
535 "Adds a public key (in hex) that can be watched as if it were in "
536 "your wallet but cannot be used to spend. Requires a new wallet "
538 "Hint: use importmulti to import more than one public key.\n"
539 "\nNote: This call can take minutes to complete if rescan is true, "
540 "during that time, other rpc calls\n"
541 "may report that the imported pubkey exists but related transactions "
542 "are still missing, leading to temporarily incorrect/bogus balances "
543 "and unspent outputs until rescan completes.\n"
544 "Note: Use \"getwalletinfo\" to query the scanning progress.\n",
547 "The hex-encoded public key"},
549 "An optional label"},
551 "Rescan the wallet for transactions"},
555 "\nImport a public key with rescan\n" +
557 "\nImport using a label without rescan\n" +
558 HelpExampleCli(
"importpubkey",
"\"mypubkey\" \"testing\" false") +
559 "\nAs a JSON-RPC call\n" +
560 HelpExampleRpc(
"importpubkey",
"\"mypubkey\", \"testing\", false")},
563 std::shared_ptr<CWallet>
const wallet =
572 std::string strLabel;
573 if (!request.params[1].isNull()) {
574 strLabel = request.params[1].get_str();
579 if (!request.params[2].isNull()) {
580 fRescan = request.params[2].get_bool();
588 "Rescan is disabled when blocks are pruned");
592 if (fRescan && !reserver.
reserve()) {
594 "Wallet is currently rescanning. Abort "
595 "existing rescan or wait.");
598 if (!
IsHex(request.params[0].get_str())) {
600 "Pubkey must be a hex string");
602 std::vector<uint8_t> data(
ParseHex(request.params[0].get_str()));
606 "Pubkey is not a valid public key");
612 std::set<CScript> script_pub_keys;
620 strLabel, script_pub_keys,
true ,
644 "Imports keys from a wallet dump file (see dumpwallet). Requires a "
645 "new wallet backup to include imported keys.\n"
646 "Note: Use \"getwalletinfo\" to query the scanning progress.\n",
654 "\nImport the wallet\n" +
656 "\nImport using the json rpc call\n" +
660 std::shared_ptr<CWallet>
const wallet =
675 "Importing wallets is disabled when blocks are pruned");
681 "Wallet is currently rescanning. Abort "
682 "existing rescan or wait.");
685 int64_t nTimeBegin = 0;
693 file.open(
fs::u8path(request.params[0].get_str()),
694 std::ios::in | std::ios::ate);
695 if (!file.is_open()) {
697 "Cannot open wallet dump file");
703 int64_t nFilesize = std::max<int64_t>(1, file.tellg());
704 file.seekg(0, file.beg);
714 strprintf(
"%s " +
_(
"Importing...").translated,
717 std::vector<std::tuple<CKey, int64_t, bool, std::string>> keys;
718 std::vector<std::pair<CScript, int64_t>> scripts;
719 while (file.good()) {
723 std::min<int>(50, 100 *
double(file.tellg()) /
727 std::getline(file, line);
728 if (line.empty() || line[0] ==
'#') {
732 std::vector<std::string> vstr =
SplitString(line,
' ');
733 if (vstr.size() < 2) {
739 std::string strLabel;
741 for (
size_t nStr = 2; nStr < vstr.size(); nStr++) {
742 if (vstr[nStr].front() ==
'#') {
745 if (vstr[nStr] ==
"change=1") {
748 if (vstr[nStr] ==
"reserve=1") {
751 if (vstr[nStr].substr(0, 6) ==
"label=") {
758 std::make_tuple(key, nTime, fLabel, strLabel));
759 }
else if (
IsHex(vstr[0])) {
760 std::vector<uint8_t> vData(
ParseHex(vstr[0]));
764 std::pair<CScript, int64_t>(script, birth_time));
775 "Importing wallets is disabled when "
776 "private keys are disabled");
778 double total = double(keys.size() + scripts.size());
780 for (
const auto &key_tuple : keys) {
783 std::max(50, std::min<int>(75, 100 * progress / total) +
786 const CKey &key = std::get<0>(key_tuple);
787 int64_t time = std::get<1>(key_tuple);
788 bool has_label = std::get<2>(key_tuple);
789 std::string label = std::get<3>(key_tuple);
801 "Error importing key for %s\n",
812 nTimeBegin = std::min(nTimeBegin, time);
815 for (
const auto &script_pair : scripts) {
818 std::max(50, std::min<int>(75, 100 * progress / total) +
821 const CScript &script = script_pair.first;
822 int64_t time = script_pair.second;
831 nTimeBegin = std::min(nTimeBegin, time);
841 pwallet->chain().showProgress(
"", 100,
false);
843 pwallet->MarkDirty();
847 "Error adding some keys/scripts to wallet");
858 "Reveals the private key corresponding to 'address'.\n"
859 "Then the importprivkey can be used with this output\n",
862 "The bitcoin address for the private key"},
870 std::shared_ptr<CWallet>
const wallet =
884 std::string strAddress = request.params[0].get_str();
889 "Invalid Bitcoin address");
892 if (keyid.IsNull()) {
894 "Address does not refer to a key");
897 if (!spk_man.
GetKey(keyid, vchSecret)) {
899 "Private key for address " + strAddress +
910 "Dumps all wallet keys in a human-readable format to a server-side "
911 "file. This does not allow overwriting existing files.\n"
912 "Imported scripts are included in the dumpsfile, but corresponding "
913 "addresses may not be added automatically by importwallet.\n"
914 "Note that if your wallet contains keys which are not derived from "
915 "your HD seed (e.g. imported keys), these are not covered by\n"
916 "only backing up the seed itself, and must be backed up too (e.g. "
917 "ensure you back up the whole dumpfile).\n",
920 "The filename with path (absolute path recommended)"},
927 "The filename with full absolute path"},
933 std::shared_ptr<CWallet>
const pwallet =
946 wallet.BlockUntilSyncedToCurrentChain();
964 " already exists. If you are "
965 "sure this is what you want, "
966 "move it out of the way first");
971 if (!file.is_open()) {
973 "Cannot open wallet dump file");
976 std::map<CKeyID, int64_t> mapKeyBirth;
977 wallet.GetKeyBirthTimes(mapKeyBirth);
979 int64_t block_time = 0;
989 const std::map<CKeyID, int64_t> &mapKeyPool =
991 std::set<CScriptID> scripts = spk_man.
GetCScripts();
994 std::vector<std::pair<int64_t, CKeyID>> vKeyBirth;
995 for (
const auto &entry : mapKeyBirth) {
996 vKeyBirth.push_back(std::make_pair(entry.second, entry.first));
999 std::sort(vKeyBirth.begin(), vKeyBirth.end());
1004 file <<
strprintf(
"# * Created on %s\n",
1006 file <<
strprintf(
"# * Best block at time of backup was %i (%s),\n",
1007 wallet.GetLastBlockHeight(),
1008 wallet.GetLastBlockHash().ToString());
1017 if (spk_man.
GetKey(seed_id, seed)) {
1021 file <<
"# extended private masterkey: "
1025 for (std::vector<std::pair<int64_t, CKeyID>>::const_iterator it =
1027 it != vKeyBirth.end(); it++) {
1028 const CKeyID &keyid = it->second;
1030 std::string strAddr;
1031 std::string strLabel;
1033 if (spk_man.
GetKey(keyid, key)) {
1036 keyid, strAddr, strLabel)) {
1037 file <<
strprintf(
"label=%s", strLabel);
1038 }
else if (keyid == seed_id) {
1040 }
else if (mapKeyPool.count(keyid)) {
1041 file <<
"reserve=1";
1042 }
else if (spk_man.mapKeyMetadata[keyid].hdKeypath ==
"s") {
1043 file <<
"inactivehdseed=1";
1048 " # addr=%s%s\n", strAddr,
1049 (spk_man.mapKeyMetadata[keyid].has_key_origin
1057 for (
const CScriptID &scriptid : scripts) {
1059 std::string create_time =
"0";
1060 std::string address =
1063 auto it = spk_man.m_script_metadata.find(scriptid);
1064 if (it != spk_man.m_script_metadata.end()) {
1070 file <<
strprintf(
" # addr=%s\n", address);
1074 file <<
"# End of dump\n";
1088 "dump all the UTXO tracked by the wallet.\n",
1097 "The list of UTXO corresponding to this address.",
1104 "The transaction id"},
1108 "The output's amount"},
1117 std::shared_ptr<CWallet>
const pwallet =
1128 wallet.BlockUntilSyncedToCurrentChain();
1137 for (
const auto &o : p.second) {
1139 utxo.
pushKV(
"txid", o.tx->GetId().ToString());
1140 utxo.
pushKV(
"vout", o.i);
1141 utxo.
pushKV(
"depth", o.nDepth);
1142 utxo.
pushKV(
"value", o.tx->tx->vout[o.i].nValue);
1182 std::vector<std::vector<uint8_t>> solverdata;
1185 switch (script_type) {
1187 CPubKey pubkey(solverdata[0]);
1199 "Trying to nest P2SH inside another P2SH");
1207 return "missing redeemscript";
1210 return "redeemScript does not match the scriptPubKey";
1217 for (
size_t i = 1; i + 1 < solverdata.size(); ++i) {
1218 CPubKey pubkey(solverdata[i]);
1224 return "unspendable script";
1227 return "unrecognized script";
1233 std::map<CKeyID, CPubKey> &pubkey_map, std::map<CKeyID, CKey> &privkey_map,
1234 std::set<CScript> &script_pub_keys,
bool &have_solving_data,
1235 const UniValue &data, std::vector<CKeyID> &ordered_pubkeys) {
1240 const UniValue &scriptPubKey = data[
"scriptPubKey"];
1243 scriptPubKey.
exists(
"address"))) {
1245 "scriptPubKey must be string with script or JSON "
1246 "with address string");
1248 const std::string &output =
1249 isScript ? scriptPubKey.
get_str() : scriptPubKey[
"address"].
get_str();
1252 const std::string &strRedeemScript =
1253 data.
exists(
"redeemscript") ? data[
"redeemscript"].
get_str() :
"";
1258 const bool internal =
1260 const bool watchOnly =
1263 if (data.
exists(
"range")) {
1266 "Range should not be specified for a non-descriptor import");
1276 "Invalid address \"" + output +
"\"");
1280 if (!
IsHex(output)) {
1282 "Invalid scriptPubKey \"" + output +
"\"");
1284 std::vector<uint8_t> vData(
ParseHex(output));
1285 script =
CScript(vData.begin(), vData.end());
1289 "Internal must be set to true for "
1290 "nonstandard scriptPubKey imports.");
1293 script_pub_keys.emplace(script);
1296 if (strRedeemScript.size()) {
1297 if (!
IsHex(strRedeemScript)) {
1299 "Invalid redeem script \"" + strRedeemScript +
1300 "\": must be hex string");
1302 auto parsed_redeemscript =
ParseHex(strRedeemScript);
1304 parsed_redeemscript.begin(), parsed_redeemscript.end());
1306 for (
size_t i = 0; i < pubKeys.
size(); ++i) {
1307 const auto &str = pubKeys[i].
get_str();
1310 "Pubkey \"" + str +
"\" must be a hex string");
1312 auto parsed_pubkey =
ParseHex(str);
1313 CPubKey pubkey(parsed_pubkey);
1317 "\" is not a valid public key");
1319 pubkey_map.emplace(pubkey.
GetID(), pubkey);
1320 ordered_pubkeys.push_back(pubkey.
GetID());
1322 for (
size_t i = 0; i < keys.
size(); ++i) {
1323 const auto &str = keys[i].
get_str();
1327 "Invalid private key encoding");
1331 if (pubkey_map.count(
id)) {
1332 pubkey_map.erase(
id);
1334 privkey_map.emplace(
id, key);
1339 import_data.
redeemscript || pubkey_map.size() || privkey_map.size();
1340 if (have_solving_data) {
1346 bool spendable = std::all_of(
1348 [&](
const std::pair<CKeyID, bool> &used_key) {
1349 return privkey_map.count(used_key.first) > 0;
1351 if (!watchOnly && !spendable) {
1352 warnings.
push_back(
"Some private keys are missing, outputs "
1353 "will be considered watchonly. If this is "
1354 "intentional, specify the watchonly flag.");
1356 if (watchOnly && spendable) {
1358 "All private keys are provided, outputs will be considered "
1359 "spendable. If this is intentional, do not specify the "
1364 if (
error.empty()) {
1365 for (
const auto &require_key : import_data.
used_keys) {
1366 if (!require_key.second) {
1371 if (pubkey_map.count(require_key.first) == 0 &&
1372 privkey_map.count(require_key.first) == 0) {
1373 error =
"some required keys are missing";
1378 if (!
error.empty()) {
1380 ". If this is intentional, don't provide "
1381 "any keys, pubkeys or redeemscript.");
1384 privkey_map.clear();
1385 have_solving_data =
false;
1392 "Ignoring redeemscript as this is not a P2SH script.");
1394 for (
auto it = privkey_map.begin(); it != privkey_map.end();) {
1396 if (import_data.
used_keys.count(oldit->first) == 0) {
1397 warnings.
push_back(
"Ignoring irrelevant private key.");
1398 privkey_map.erase(oldit);
1401 for (
auto it = pubkey_map.begin(); it != pubkey_map.end();) {
1403 auto key_data_it = import_data.
used_keys.find(oldit->first);
1404 if (key_data_it == import_data.
used_keys.end() ||
1405 !key_data_it->second) {
1406 warnings.
push_back(
"Ignoring public key \"" +
1408 "\" as it doesn't appear inside P2PKH.");
1409 pubkey_map.erase(oldit);
1419 std::map<CKeyID, CPubKey> &pubkey_map,
1420 std::map<CKeyID, CKey> &privkey_map,
1421 std::set<CScript> &script_pub_keys,
1422 bool &have_solving_data,
1424 std::vector<CKeyID> &ordered_pubkeys) {
1427 const std::string &descriptor = data[
"desc"].
get_str();
1436 have_solving_data = parsed_desc->IsSolvable();
1437 const bool watch_only =
1440 int64_t range_start = 0, range_end = 0;
1441 if (!parsed_desc->IsRange() && data.
exists(
"range")) {
1444 "Range should not be specified for an un-ranged descriptor");
1445 }
else if (parsed_desc->IsRange()) {
1446 if (!data.
exists(
"range")) {
1449 "Descriptor is ranged, please specify the range");
1459 for (
int i = range_start; i <= range_end; ++i) {
1461 std::vector<CScript> scripts_temp;
1462 parsed_desc->Expand(i, keys, scripts_temp, out_keys);
1463 std::copy(scripts_temp.begin(), scripts_temp.end(),
1464 std::inserter(script_pub_keys, script_pub_keys.end()));
1465 for (
const auto &key_pair : out_keys.
pubkeys) {
1466 ordered_pubkeys.push_back(key_pair.first);
1469 for (
const auto &x : out_keys.
scripts) {
1473 parsed_desc->ExpandPrivate(i, keys, out_keys);
1476 std::inserter(pubkey_map, pubkey_map.end()));
1477 std::copy(out_keys.
keys.begin(), out_keys.
keys.end(),
1478 std::inserter(privkey_map, privkey_map.end()));
1483 for (
size_t i = 0; i < priv_keys.
size(); ++i) {
1484 const auto &str = priv_keys[i].
get_str();
1488 "Invalid private key encoding");
1495 if (!pubkey_map.count(
id)) {
1496 warnings.
push_back(
"Ignoring irrelevant private key.");
1498 privkey_map.emplace(
id, key);
1509 std::all_of(pubkey_map.begin(), pubkey_map.end(),
1510 [&](
const std::pair<CKeyID, CPubKey> &used_key) {
1511 return privkey_map.count(used_key.first) > 0;
1515 [&](
const std::pair<
CKeyID, std::pair<CPubKey, KeyOriginInfo>>
1516 &entry) { return privkey_map.count(entry.first) > 0; });
1517 if (!watch_only && !spendable) {
1519 "Some private keys are missing, outputs will be considered "
1520 "watchonly. If this is intentional, specify the watchonly flag.");
1522 if (watch_only && spendable) {
1523 warnings.
push_back(
"All private keys are provided, outputs will be "
1524 "considered spendable. If this is intentional, do "
1525 "not specify the watchonly flag.");
1532 const int64_t timestamp)
1538 const bool internal =
1539 data.exists(
"internal") ? data[
"internal"].get_bool() :
false;
1541 if (
internal && data.exists(
"label")) {
1543 "Internal addresses should not have a label");
1545 const std::string &label =
1546 data.exists(
"label") ? data[
"label"].get_str() :
"";
1547 const bool add_keypool =
1548 data.exists(
"keypool") ? data[
"keypool"].get_bool() :
false;
1554 "Keys can only be imported to the keypool when "
1555 "private keys are disabled");
1559 std::map<CKeyID, CPubKey> pubkey_map;
1560 std::map<CKeyID, CKey> privkey_map;
1561 std::set<CScript> script_pub_keys;
1562 std::vector<CKeyID> ordered_pubkeys;
1563 bool have_solving_data;
1565 if (data.exists(
"scriptPubKey") && data.exists(
"desc")) {
1568 "Both a descriptor and a scriptPubKey should not be provided.");
1569 }
else if (data.exists(
"scriptPubKey")) {
1571 pwallet, import_data, pubkey_map, privkey_map, script_pub_keys,
1572 have_solving_data, data, ordered_pubkeys);
1573 }
else if (data.exists(
"desc")) {
1575 import_data, pubkey_map, privkey_map, script_pub_keys,
1576 have_solving_data, data, ordered_pubkeys);
1580 "Either a descriptor or scriptPubKey must be provided.");
1586 !privkey_map.empty()) {
1588 "Cannot import private keys to a wallet with "
1589 "private keys disabled");
1593 for (
const CScript &script : script_pub_keys) {
1596 "The wallet already contains the private "
1597 "key for this address or script (\"" +
1603 pwallet->MarkDirty();
1604 if (!pwallet->ImportScripts(import_data.
import_scripts, timestamp)) {
1606 "Error adding script to wallet");
1608 if (!pwallet->ImportPrivKeys(privkey_map, timestamp)) {
1611 if (!pwallet->ImportPubKeys(ordered_pubkeys, pubkey_map,
1613 internal, timestamp)) {
1615 "Error adding address to wallet");
1617 if (!pwallet->ImportScriptPubKeys(label, script_pub_keys,
1618 have_solving_data, !
internal,
1621 "Error adding address to wallet");
1627 result.
pushKV(
"error", e);
1634 if (warnings.
size()) {
1635 result.
pushKV(
"warnings", warnings);
1641 if (data.
exists(
"timestamp")) {
1642 const UniValue ×tamp = data[
"timestamp"];
1643 if (timestamp.
isNum()) {
1644 return timestamp.
getInt<int64_t>();
1645 }
else if (timestamp.
isStr() && timestamp.
get_str() ==
"now") {
1649 strprintf(
"Expected number or \"now\" timestamp "
1650 "value for key. got type %s",
1654 "Missing required timestamp field for key");
1658 const int64_t objectTimestamp,
1659 const int64_t blockTimestamp) {
1661 "Rescan failed for %s with creation timestamp %d. There was an error "
1662 "reading a block from time %d, which is after or within %d seconds of "
1663 "key creation, and could contain transactions pertaining to the %s. As "
1664 "a result, transactions and coins using this %s may not appear in "
1665 "the wallet. This error could be caused by pruning or data corruption "
1666 "(see bitcoind log for details) and could be dealt with by downloading "
1667 "and rescanning the relevant blocks (see -reindex and -rescan "
1676 "Import addresses/scripts (with private or public keys, redeem "
1677 "script (P2SH)), optionally rescanning the blockchain from the "
1678 "earliest creation time of the imported scripts. Requires a new wallet "
1680 "If an address/script is imported without all of the private keys "
1681 "required to spend from that address, it will be watchonly. The "
1682 "'watchonly' option must be set to true in this case or a warning will "
1684 "Conversely, if all the private keys are provided and the "
1685 "address/script is spendable, the watchonly option must be set to "
1686 "false, or a warning will be returned.\n"
1687 "Note: Use \"getwalletinfo\" to query the scanning progress.\n",
1692 "Data to be imported",
1701 "Descriptor to import. If using descriptor, do not "
1702 "also provide address/scriptPubKey, scripts, or "
1706 "Type of scriptPubKey (string for script, json for "
1707 "address). Should not be provided if using a "
1711 "\"address\":\"<address>\" }",
1714 "Creation time of the key expressed in " +
1717 "or the string \"now\" to substitute the current "
1718 "synced blockchain time. The timestamp of the "
1720 "key will determine how far back blockchain "
1721 "rescans need to begin for missing wallet "
1723 "\"now\" can be specified to bypass scanning, "
1724 "for keys which are known to never have been "
1726 "0 can be specified to scan the entire "
1727 "blockchain. Blocks up to 2 hours before the "
1729 "creation time of all keys being imported by the "
1730 "importmulti call will be scanned.",
1732 "integer / string"}}},
1735 "Allowed only if the scriptPubKey is a P2SH "
1736 "address/scriptPubKey"},
1740 "Array of strings giving pubkeys to import. They "
1741 "must occur in P2PKH scripts. They are not required "
1742 "when the private key is also provided (see the "
1743 "\"keys\" argument).",
1751 "Array of strings giving private keys to import. The "
1752 "corresponding public keys must occur in the output "
1760 "If a ranged descriptor is used, this specifies the "
1761 "end or the range (in the form [begin,end]) to "
1765 "Stating whether matching outputs should be treated "
1766 "as not incoming payments (also known as change)"},
1769 "Stating whether matching outputs should be "
1770 "considered watchonly."},
1772 "Label to assign to the address, only allowed with "
1775 "Stating whether imported public keys should be "
1776 "added to the keypool for when users request new "
1777 "addresses. Only allowed when wallet private keys "
1789 "Stating if should rescan the blockchain after all imports"},
1795 "Response is an array with the same size as the input that "
1796 "has the execution result",
1822 "'[{ \"scriptPubKey\": { \"address\": \"<my address>\" }, "
1823 "\"timestamp\":1455191478 }, "
1824 "{ \"scriptPubKey\": { \"address\": \"<my 2nd address>\" "
1826 "\"label\": \"example 2\", \"timestamp\": 1455191480 }]'") +
1829 "'[{ \"scriptPubKey\": { \"address\": \"<my address>\" }, "
1830 "\"timestamp\":1455191478 }]' '{ \"rescan\": false}'")
1835 std::shared_ptr<CWallet>
const wallet =
1844 const UniValue &requests = mainRequest.params[0];
1847 bool fRescan =
true;
1849 if (!mainRequest.params[1].isNull()) {
1850 const UniValue &options = mainRequest.params[1];
1852 if (options.
exists(
"rescan")) {
1853 fRescan = options[
"rescan"].
get_bool();
1858 if (fRescan && !reserver.
reserve()) {
1860 "Wallet is currently rescanning. Abort "
1861 "existing rescan or wait.");
1865 bool fRunScan =
false;
1866 int64_t nLowestTimestamp = 0;
1875 FoundBlock().time(nLowestTimestamp).mtpTime(now)));
1880 const int64_t minimumTimestamp = 1;
1883 const int64_t timestamp = std::max(
1894 if (result[
"success"].get_bool()) {
1899 if (timestamp < nLowestTimestamp) {
1900 nLowestTimestamp = timestamp;
1904 if (fRescan && fRunScan && requests.
size()) {
1906 nLowestTimestamp, reserver,
true );
1914 "Rescan aborted by user.");
1916 if (scannedTime > nLowestTimestamp) {
1917 std::vector<UniValue> results =
response.getValues();
1927 results.at(i).exists(
"error")) {
1939 response.push_back(std::move(result));
1953 const int64_t timestamp)
1959 if (!data.exists(
"desc")) {
1963 const std::string &descriptor = data[
"desc"].get_str();
1965 data.exists(
"active") ? data[
"active"].get_bool() :
false;
1966 const bool internal =
1967 data.exists(
"internal") ? data[
"internal"].get_bool() :
false;
1968 const std::string &label =
1969 data.exists(
"label") ? data[
"label"].get_str() :
"";
1981 int64_t range_start = 0, range_end = 1, next_index = 0;
1982 if (!parsed_desc->IsRange() && data.exists(
"range")) {
1985 "Range should not be specified for an un-ranged descriptor");
1986 }
else if (parsed_desc->IsRange()) {
1987 if (data.exists(
"range")) {
1989 range_start = range.first;
1992 range_end = range.second + 1;
1995 "Range not given, using default keypool range");
1999 next_index = range_start;
2001 if (data.exists(
"next_index")) {
2002 next_index = data[
"next_index"].getInt<int64_t>();
2004 if (next_index < range_start || next_index >= range_end) {
2006 "next_index is out of range");
2012 if (active && !parsed_desc->IsRange()) {
2014 "Active descriptors must be ranged");
2018 if (data.exists(
"range") && data.exists(
"label")) {
2020 "Ranged descriptors should not have a label");
2024 if (
internal && data.exists(
"label")) {
2026 "Internal addresses should not have a label");
2030 if (active && !parsed_desc->IsSingleType()) {
2032 "Combo descriptors cannot be set to active");
2037 !keys.
keys.empty()) {
2039 "Cannot import private keys to a wallet with "
2040 "private keys disabled");
2046 std::vector<CScript> scripts;
2047 if (!parsed_desc->Expand(0, keys, scripts, expand_keys)) {
2050 "Cannot expand descriptor. Probably because of hardened "
2051 "derivations without private keys provided");
2053 parsed_desc->ExpandPrivate(0, keys, expand_keys);
2056 bool have_all_privkeys = !expand_keys.
keys.empty();
2057 for (
const auto &entry : expand_keys.
origins) {
2058 const CKeyID &key_id = entry.first;
2060 if (!expand_keys.
GetKey(key_id, key)) {
2061 have_all_privkeys =
false;
2068 if (keys.
keys.empty()) {
2071 "Cannot import descriptor without private keys to a wallet "
2072 "with private keys enabled");
2074 if (!have_all_privkeys) {
2076 "Not all private keys provided. Some wallet functionality "
2077 "may return unexpected errors");
2082 range_end, next_index);
2085 auto existing_spk_manager =
2086 pwallet->GetDescriptorScriptPubKeyMan(w_desc);
2087 if (existing_spk_manager &&
2088 !existing_spk_manager->CanUpdateToWalletDescriptor(w_desc,
error)) {
2094 pwallet->AddWalletDescriptor(w_desc, keys, label,
internal);
2095 if (spk_manager ==
nullptr) {
2098 strprintf(
"Could not add descriptor '%s'", descriptor));
2105 "Unknown output type, cannot set descriptor to active.");
2107 pwallet->AddActiveScriptPubKeyMan(
2108 spk_manager->GetID(), *w_desc.
descriptor->GetOutputType(),
2113 pwallet->DeactivateScriptPubKeyMan(
2114 spk_manager->GetID(), *w_desc.
descriptor->GetOutputType(),
2122 result.
pushKV(
"error", e);
2124 if (warnings.
size()) {
2125 result.
pushKV(
"warnings", warnings);
2132 "importdescriptors",
2133 "Import descriptors. This will trigger a rescan of the blockchain "
2134 "based on the earliest timestamp of all descriptors being imported. "
2135 "Requires a new wallet backup.\n"
2136 "\nNote: This call can take over an hour to complete if using an early "
2137 "timestamp; during that time, other rpc calls\n"
2138 "may report that the imported keys, addresses or scripts exist but "
2139 "related transactions are still missing.\n",
2144 "Data to be imported",
2153 "Descriptor to import."},
2155 "Set this descriptor to be the active descriptor for "
2156 "the corresponding output type/externality"},
2159 "If a ranged descriptor is used, this specifies the "
2160 "end or the range (in the form [begin,end]) to "
2164 "If a ranged descriptor is set to active, this "
2165 "specifies the next index to generate addresses "
2168 "Time from which to start rescanning the blockchain "
2169 "for this descriptor, in " +
2172 "Use the string \"now\" to substitute the "
2173 "current synced blockchain time.\n"
2174 "\"now\" can be specified to bypass scanning, "
2175 "for outputs which are known to never have been "
2177 "0 can be specified to scan the entire "
2178 "blockchain. Blocks up to 2 hours before the "
2179 "earliest timestamp\n"
2180 "of all descriptors being imported will be "
2183 "integer / string"}}},
2186 "Whether matching outputs should be treated as not "
2187 "incoming payments (e.g. change)"},
2189 "Label to assign to the address, only allowed with "
2198 "Response is an array with the same size as the input that "
2199 "has the execution result",
2224 "'[{ \"desc\": \"<my descriptor>\", "
2225 "\"timestamp\":1455191478, \"internal\": true }, "
2226 "{ \"desc\": \"<my desccriptor 2>\", \"label\": "
2227 "\"example 2\", \"timestamp\": 1455191480 }]'") +
2229 "importdescriptors",
2230 "'[{ \"desc\": \"<my descriptor>\", \"timestamp\":1455191478, "
2231 "\"active\": true, \"range\": [0,100], \"label\": \"<my "
2232 "cashaddr wallet>\" }]'")},
2235 std::shared_ptr<CWallet>
const wallet =
2245 "importdescriptors is not available for "
2246 "non-descriptor wallets");
2252 "Wallet is currently rescanning. Abort "
2253 "existing rescan or wait.");
2256 const UniValue &requests = main_request.params[0];
2257 const int64_t minimum_timestamp = 1;
2259 int64_t lowest_timestamp = 0;
2260 bool rescan =
false;
2268 FoundBlock().time(lowest_timestamp).mtpTime(now)));
2273 const int64_t timestamp = std::max(
2279 if (lowest_timestamp > timestamp) {
2280 lowest_timestamp = timestamp;
2285 if (!rescan && result[
"success"].get_bool()) {
2295 lowest_timestamp, reserver,
true );
2303 "Rescan aborted by user.");
2306 if (scanned_time > lowest_timestamp) {
2307 std::vector<UniValue> results =
response.getValues();
2312 for (
unsigned int i = 0; i < requests.
size(); ++i) {
2321 results.at(i).exists(
"error")) {
2334 response.push_back(std::move(result));
2348 "Safely copies current wallet file to destination, which can be a "
2349 "directory or a path with filename.\n",
2352 "The destination directory or file"},
2359 std::shared_ptr<CWallet>
const wallet =
2369 pwallet->BlockUntilSyncedToCurrentChain();
2373 std::string strDest = request.params[0].get_str();
2376 "Error: Wallet backup failed!");
2387 "\nRestore and loads a wallet from backup.\n",
2390 "The name that will be applied to the restored wallet"},
2392 "The backup file that will be used to restore the wallet."},
2395 "Save wallet name to persistent settings and load on startup. "
2396 "True to add wallet to startup list, false to remove, null to "
2397 "leave unchanged."},
2404 "The wallet name if restored successfully."},
2406 "Warning message if wallet was not loaded cleanly."},
2410 "\"testwallet\" \"home\\backups\\backup-file.bak\"") +
2413 "\"testwallet\" \"home\\backups\\backup-file.bak\"") +
2416 {{
"wallet_name",
"testwallet"},
2417 {
"backup_file",
"home\\backups\\backup-file.bak\""},
2418 {
"load_on_startup",
true}}) +
2421 {{
"wallet_name",
"testwallet"},
2422 {
"backup_file",
"home\\backups\\backup-file.bak\""},
2423 {
"load_on_startup",
true}})},
2433 "Backup file does not exist");
2436 std::string wallet_name = request.params[0].get_str();
2443 "Wallet name already exists.");
2448 strprintf(
"Failed to create database path "
2449 "'%s'. Database already exists.",
2453 auto wallet_file = wallet_path /
"wallet.dat";
2455 fs::copy_file(backup_file, wallet_file, fs::copy_options::none);
2457 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()
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()
Span< const CRPCCommand > GetWalletDumpRPCCommands()
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.
const uint8_t * begin() const
unsigned int size() const
Simple read-only vector-like interface.
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())
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)
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::vector< uint8_t > ParseHexV(const UniValue &v, std::string strName)
std::string HelpExampleCli(const std::string &methodname, const std::string &args)
std::string HelpExampleRpcNamed(const std::string &methodname, const RPCArgList &args)
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.
std::string HexStr(const Span< const uint8_t > s)
Convert a span of bytes to a lower-case hexadecimal string.
bool IsHex(const std::string &str)
Returns true if each character in str is a hex character, and has an even number of hex digits.
std::vector< uint8_t > ParseHex(const char *psz)
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(const uint8_t *seed, unsigned int nSeedLen)
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 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 char * uvTypeName(UniValue::VType t)
const UniValue NullUniValue
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.