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.");
110 auto &chain{
wallet.chain()};
111 if (!chain.havePruned()) {
116 const bool found{chain.findFirstBlockWithTimeAndHeight(
121 if (found && !chain.hasBlocks(tip_hash, height)) {
125 "Pruned blocks from height %d required to import keys. Use RPC "
126 "call getblockchaininfo to determine your pruned height.",
134 "Adds a private key (as returned by dumpprivkey) to your wallet. "
135 "Requires a new wallet backup.\n"
136 "Hint: use importmulti to import more than one private key.\n"
137 "\nNote: This call can take minutes to complete if rescan is true, "
138 "during that time, other rpc calls\n"
139 "may report that the imported key exists but related transactions are "
140 "still missing, leading to temporarily incorrect/bogus balances and "
141 "unspent outputs until rescan completes.\n"
142 "Note: Use \"getwalletinfo\" to query the scanning progress.\n"
143 "Note: This command is only compatible with legacy wallets. Use "
144 "\"importdescriptors\" with \"combo(X)\" for descriptor wallets.\n",
147 "The private key (see dumpprivkey)"},
150 "current label if address exists, otherwise \"\""},
151 "An optional label"},
153 "Rescan the wallet for transactions"},
157 "\nDump a private key\n" +
159 "\nImport the private key with rescan\n" +
161 "\nImport using a label and without rescan\n" +
163 "\nImport using default blank label and without rescan\n" +
165 "\nAs a JSON-RPC call\n" +
166 HelpExampleRpc(
"importprivkey",
"\"mykey\", \"testing\", false")},
169 std::shared_ptr<CWallet>
const wallet =
179 "Cannot import private keys to a wallet with "
180 "private keys disabled");
192 std::string strSecret = request.params[0].get_str();
193 std::string strLabel =
"";
194 if (!request.params[1].isNull()) {
195 strLabel = request.params[1].get_str();
199 if (!request.params[2].isNull()) {
200 fRescan = request.params[2].get_bool();
209 "Rescan is disabled when blocks are pruned");
212 if (fRescan && !reserver.
reserve()) {
215 "Wallet is currently rescanning. Abort existing "
222 "Invalid private key encoding");
235 if (!request.params[1].isNull() ||
244 "Error adding key to wallet");
260 "Stops current wallet rescan triggered by an RPC call, e.g. by an "
261 "importprivkey call.\n"
262 "Note: Use \"getwalletinfo\" to query the scanning progress.\n",
265 "Whether the abort was successful"},
268 "\nAbort the running wallet rescan\n" +
270 "\nAs a JSON-RPC call\n" +
274 std::shared_ptr<CWallet>
const wallet =
293 "Adds an address or script (in hex) that can be watched as if it "
294 "were in your wallet but cannot be used to spend. Requires a new "
296 "\nNote: This call can take minutes to complete if rescan is true, "
297 "during that time, other rpc calls\n"
298 "may report that the imported address exists but related transactions "
299 "are still missing, leading to temporarily incorrect/bogus balances "
300 "and unspent outputs until rescan completes.\n"
301 "If you have the full public key, you should call importpubkey instead "
303 "Hint: use importmulti to import more than one address.\n"
304 "\nNote: If you import a non-standard raw script in hex form, outputs "
305 "sending to it will be treated\n"
306 "as change, and not show up in many RPCs.\n"
307 "Note: Use \"getwalletinfo\" to query the scanning progress.\n"
308 "Note: This command is only compatible with legacy wallets. Use "
309 "\"importdescriptors\" for descriptor wallets.\n",
312 "The Bitcoin address (or hex-encoded script)"},
314 "An optional label"},
316 "Rescan the wallet for transactions"},
318 "Add the P2SH version of the script as well"},
322 "\nImport an address with rescan\n" +
324 "\nImport using a label without rescan\n" +
325 HelpExampleCli(
"importaddress",
"\"myaddress\" \"testing\" false") +
326 "\nAs a JSON-RPC call\n" +
328 "\"myaddress\", \"testing\", false")},
331 std::shared_ptr<CWallet>
const wallet =
340 std::string strLabel;
341 if (!request.params[1].isNull()) {
342 strLabel = request.params[1].get_str();
347 if (!request.params[2].isNull()) {
348 fRescan = request.params[2].get_bool();
356 "Rescan is disabled when blocks are pruned");
360 if (fRescan && !reserver.
reserve()) {
362 "Wallet is currently rescanning. Abort "
363 "existing rescan or wait.");
368 if (!request.params[3].isNull()) {
369 fP2SH = request.params[3].get_bool();
376 request.params[0].get_str(),
wallet->GetChainParams());
381 "Cannot use the p2sh flag with an address - "
382 "use a script instead");
391 }
else if (
IsHex(request.params[0].get_str())) {
392 std::vector<uint8_t> data(
393 ParseHex(request.params[0].get_str()));
394 CScript redeem_script(data.begin(), data.end());
396 std::set<CScript> scripts = {redeem_script};
405 strLabel, scripts,
false ,
409 "Invalid Bitcoin address or script");
428 "Imports funds without rescan. Corresponding address or script must "
429 "previously be included in wallet. Aimed towards pruned wallets. The "
430 "end-user is responsible to import additional transactions that "
431 "subsequently spend the imported outputs or rescan after the point in "
432 "the blockchain the transaction is included.\n",
435 "A raw transaction in hex funding an already-existing address in "
438 "The hex output from gettxoutproof that contains the transaction"},
444 std::shared_ptr<CWallet>
const wallet =
452 if (!
DecodeHexTx(tx, request.params[0].get_str())) {
465 std::vector<uint256> vMatch;
466 std::vector<size_t> vIndex;
470 "Something wrong with merkleblock");
479 "Block not found in chain");
482 std::vector<uint256>::const_iterator it;
483 if ((it = std::find(vMatch.begin(), vMatch.end(), txid)) ==
486 "Transaction given doesn't exist in proof");
489 size_t txnIndex = vIndex[it - vMatch.begin()];
492 CWalletTx::Status::CONFIRMED, height,
496 if (pwallet->
IsMine(*tx_ref)) {
503 "No addresses in wallet correspond to included transaction");
511 "Deletes the specified transaction from the wallet. Meant for use "
512 "with pruned wallets and as a companion to importprunedfunds. This "
513 "will affect wallet balances.\n",
516 "The hex-encoded id of the transaction you are deleting"},
520 "\"a8d0c0184dde994a09ec054286f1ce581bebf4644"
521 "6a512166eae7628734ea0a5\"") +
522 "\nAs a JSON-RPC call\n" +
524 "\"a8d0c0184dde994a09ec054286f1ce581bebf4644"
525 "6a512166eae7628734ea0a5\"")},
528 std::shared_ptr<CWallet>
const wallet =
538 std::vector<TxId> txIds;
539 txIds.push_back(txid);
540 std::vector<TxId> txIdsOut;
545 "Could not properly delete the transaction.");
548 if (txIdsOut.empty()) {
550 "Transaction does not exist in wallet.");
561 "Adds a public key (in hex) that can be watched as if it were in "
562 "your wallet but cannot be used to spend. Requires a new wallet "
564 "Hint: use importmulti to import more than one public key.\n"
565 "\nNote: This call can take minutes to complete if rescan is true, "
566 "during that time, other rpc calls\n"
567 "may report that the imported pubkey exists but related transactions "
568 "are still missing, leading to temporarily incorrect/bogus balances "
569 "and unspent outputs until rescan completes.\n"
570 "Note: Use \"getwalletinfo\" to query the scanning progress.\n"
571 "Note: This command is only compatible with legacy wallets. Use "
572 "\"importdescriptors\" with \"combo(X)\" for descriptor wallets.\n",
575 "The hex-encoded public key"},
577 "An optional label"},
579 "Rescan the wallet for transactions"},
583 "\nImport a public key with rescan\n" +
585 "\nImport using a label without rescan\n" +
586 HelpExampleCli(
"importpubkey",
"\"mypubkey\" \"testing\" false") +
587 "\nAs a JSON-RPC call\n" +
588 HelpExampleRpc(
"importpubkey",
"\"mypubkey\", \"testing\", false")},
591 std::shared_ptr<CWallet>
const wallet =
600 std::string strLabel;
601 if (!request.params[1].isNull()) {
602 strLabel = request.params[1].get_str();
607 if (!request.params[2].isNull()) {
608 fRescan = request.params[2].get_bool();
616 "Rescan is disabled when blocks are pruned");
620 if (fRescan && !reserver.
reserve()) {
622 "Wallet is currently rescanning. Abort "
623 "existing rescan or wait.");
626 if (!
IsHex(request.params[0].get_str())) {
628 "Pubkey must be a hex string");
630 std::vector<uint8_t> data(
ParseHex(request.params[0].get_str()));
634 "Pubkey is not a valid public key");
640 std::set<CScript> script_pub_keys;
648 strLabel, script_pub_keys,
true ,
672 "Imports keys from a wallet dump file (see dumpwallet). Requires a "
673 "new wallet backup to include imported keys.\n"
674 "Note: Use \"getwalletinfo\" to query the scanning progress.\n"
675 "Note: This command is only compatible with legacy wallets.\n",
683 "\nImport the wallet\n" +
685 "\nImport using the json rpc call\n" +
689 std::shared_ptr<CWallet>
const wallet =
701 "Wallet is currently rescanning. Abort "
702 "existing rescan or wait.");
705 int64_t nTimeBegin = 0;
713 file.open(
fs::u8path(request.params[0].get_str()),
714 std::ios::in | std::ios::ate);
715 if (!file.is_open()) {
717 "Cannot open wallet dump file");
723 int64_t nFilesize = std::max<int64_t>(1, file.tellg());
724 file.seekg(0, file.beg);
734 strprintf(
"%s " +
_(
"Importing...").translated,
737 std::vector<std::tuple<CKey, int64_t, bool, std::string>> keys;
738 std::vector<std::pair<CScript, int64_t>> scripts;
739 while (file.good()) {
743 std::min<int>(50, 100 *
double(file.tellg()) /
747 std::getline(file, line);
748 if (line.empty() || line[0] ==
'#') {
752 std::vector<std::string> vstr =
SplitString(line,
' ');
753 if (vstr.size() < 2) {
759 std::string strLabel;
761 for (
size_t nStr = 2; nStr < vstr.size(); nStr++) {
762 if (vstr[nStr].front() ==
'#') {
765 if (vstr[nStr] ==
"change=1") {
768 if (vstr[nStr] ==
"reserve=1") {
771 if (vstr[nStr].substr(0, 6) ==
"label=") {
777 nTimeBegin = std::min(nTimeBegin, nTime);
779 std::make_tuple(key, nTime, fLabel, strLabel));
780 }
else if (
IsHex(vstr[0])) {
781 std::vector<uint8_t> vData(
ParseHex(vstr[0]));
782 CScript script = CScript(vData.begin(), vData.end());
784 if (birth_time > 0) {
785 nTimeBegin = std::min(nTimeBegin, birth_time);
788 std::pair<CScript, int64_t>(script, birth_time));
800 "Importing wallets is disabled when "
801 "private keys are disabled");
803 double total = double(keys.size() + scripts.size());
805 for (
const auto &key_tuple : keys) {
808 std::max(50, std::min<int>(75, 100 * progress / total) +
811 const CKey &key = std::get<0>(key_tuple);
812 int64_t time = std::get<1>(key_tuple);
813 bool has_label = std::get<2>(key_tuple);
814 std::string label = std::get<3>(key_tuple);
826 "Error importing key for %s\n",
838 for (
const auto &script_pair : scripts) {
841 std::max(50, std::min<int>(75, 100 * progress / total) +
844 const CScript &script = script_pair.first;
845 int64_t time = script_pair.second;
861 pwallet->chain().showProgress(
"", 100,
false);
863 pwallet->MarkDirty();
867 "Error adding some keys/scripts to wallet");
878 "Reveals the private key corresponding to 'address'.\n"
879 "Then the importprivkey can be used with this output\n"
880 "Note: This command is only compatible with legacy wallets.\n",
883 "The bitcoin address for the private key"},
891 std::shared_ptr<CWallet>
const wallet =
905 std::string strAddress = request.params[0].get_str();
910 "Invalid Bitcoin address");
913 if (keyid.IsNull()) {
915 "Address does not refer to a key");
918 if (!spk_man.
GetKey(keyid, vchSecret)) {
920 "Private key for address " + strAddress +
931 "Dumps all wallet keys in a human-readable format to a server-side "
932 "file. This does not allow overwriting existing files.\n"
933 "Imported scripts are included in the dumpsfile, but corresponding "
934 "addresses may not be added automatically by importwallet.\n"
935 "Note that if your wallet contains keys which are not derived from "
936 "your HD seed (e.g. imported keys), these are not covered by\n"
937 "only backing up the seed itself, and must be backed up too (e.g. "
938 "ensure you back up the whole dumpfile).\n"
939 "Note: This command is only compatible with legacy wallets.\n",
942 "The filename with path (absolute path recommended)"},
949 "The filename with full absolute path"},
955 std::shared_ptr<CWallet>
const pwallet =
968 wallet.BlockUntilSyncedToCurrentChain();
986 " already exists. If you are "
987 "sure this is what you want, "
988 "move it out of the way first");
993 if (!file.is_open()) {
995 "Cannot open wallet dump file");
998 std::map<CKeyID, int64_t> mapKeyBirth;
999 wallet.GetKeyBirthTimes(mapKeyBirth);
1001 int64_t block_time = 0;
1011 const std::map<CKeyID, int64_t> &mapKeyPool =
1013 std::set<CScriptID> scripts = spk_man.
GetCScripts();
1016 std::vector<std::pair<int64_t, CKeyID>> vKeyBirth;
1017 for (
const auto &entry : mapKeyBirth) {
1018 vKeyBirth.push_back(std::make_pair(entry.second, entry.first));
1020 mapKeyBirth.clear();
1021 std::sort(vKeyBirth.begin(), vKeyBirth.end());
1026 file <<
strprintf(
"# * Created on %s\n",
1028 file <<
strprintf(
"# * Best block at time of backup was %i (%s),\n",
1029 wallet.GetLastBlockHeight(),
1030 wallet.GetLastBlockHash().ToString());
1039 if (spk_man.
GetKey(seed_id, seed)) {
1043 file <<
"# extended private masterkey: "
1047 for (std::vector<std::pair<int64_t, CKeyID>>::const_iterator it =
1049 it != vKeyBirth.end(); it++) {
1050 const CKeyID &keyid = it->second;
1052 std::string strAddr;
1053 std::string strLabel;
1055 if (spk_man.
GetKey(keyid, key)) {
1058 keyid, strAddr, strLabel)) {
1059 file <<
strprintf(
"label=%s", strLabel);
1060 }
else if (keyid == seed_id) {
1062 }
else if (mapKeyPool.count(keyid)) {
1063 file <<
"reserve=1";
1064 }
else if (spk_man.mapKeyMetadata[keyid].hdKeypath ==
"s") {
1065 file <<
"inactivehdseed=1";
1070 " # addr=%s%s\n", strAddr,
1071 (spk_man.mapKeyMetadata[keyid].has_key_origin
1079 for (
const CScriptID &scriptid : scripts) {
1081 std::string create_time =
"0";
1082 std::string address =
1085 auto it = spk_man.m_script_metadata.find(scriptid);
1086 if (it != spk_man.m_script_metadata.end()) {
1092 file <<
strprintf(
" # addr=%s\n", address);
1096 file <<
"# End of dump\n";
1110 "dump all the UTXO tracked by the wallet.\n",
1119 "The list of UTXO corresponding to this address.",
1126 "The transaction id"},
1130 "The output's amount"},
1139 std::shared_ptr<CWallet>
const pwallet =
1150 wallet.BlockUntilSyncedToCurrentChain();
1159 for (
const auto &o : p.second) {
1161 utxo.
pushKV(
"txid", o.tx->GetId().ToString());
1162 utxo.
pushKV(
"vout", o.i);
1163 utxo.
pushKV(
"depth", o.nDepth);
1164 utxo.
pushKV(
"value", o.tx->tx->vout[o.i].nValue);
1204 std::vector<std::vector<uint8_t>> solverdata;
1207 switch (script_type) {
1209 CPubKey pubkey(solverdata[0]);
1221 "Trying to nest P2SH inside another P2SH");
1229 return "missing redeemscript";
1232 return "redeemScript does not match the scriptPubKey";
1239 for (
size_t i = 1; i + 1 < solverdata.size(); ++i) {
1240 CPubKey pubkey(solverdata[i]);
1246 return "unspendable script";
1249 return "unrecognized script";
1255 std::map<CKeyID, CPubKey> &pubkey_map, std::map<CKeyID, CKey> &privkey_map,
1256 std::set<CScript> &script_pub_keys,
bool &have_solving_data,
1257 const UniValue &data, std::vector<CKeyID> &ordered_pubkeys) {
1262 const UniValue &scriptPubKey = data[
"scriptPubKey"];
1265 scriptPubKey.
exists(
"address"))) {
1267 "scriptPubKey must be string with script or JSON "
1268 "with address string");
1270 const std::string &output =
1271 isScript ? scriptPubKey.
get_str() : scriptPubKey[
"address"].
get_str();
1274 const std::string &strRedeemScript =
1275 data.
exists(
"redeemscript") ? data[
"redeemscript"].
get_str() :
"";
1280 const bool internal =
1282 const bool watchOnly =
1285 if (data.
exists(
"range")) {
1288 "Range should not be specified for a non-descriptor import");
1298 "Invalid address \"" + output +
"\"");
1302 if (!
IsHex(output)) {
1304 "Invalid scriptPubKey \"" + output +
"\"");
1306 std::vector<uint8_t> vData(
ParseHex(output));
1307 script = CScript(vData.begin(), vData.end());
1311 "Internal must be set to true for "
1312 "nonstandard scriptPubKey imports.");
1315 script_pub_keys.emplace(script);
1318 if (strRedeemScript.size()) {
1319 if (!
IsHex(strRedeemScript)) {
1321 "Invalid redeem script \"" + strRedeemScript +
1322 "\": must be hex string");
1324 auto parsed_redeemscript =
ParseHex(strRedeemScript);
1326 parsed_redeemscript.begin(), parsed_redeemscript.end());
1328 for (
size_t i = 0; i < pubKeys.
size(); ++i) {
1329 const auto &str = pubKeys[i].
get_str();
1332 "Pubkey \"" + str +
"\" must be a hex string");
1334 auto parsed_pubkey =
ParseHex(str);
1335 CPubKey pubkey(parsed_pubkey);
1339 "\" is not a valid public key");
1341 pubkey_map.emplace(pubkey.
GetID(), pubkey);
1342 ordered_pubkeys.push_back(pubkey.
GetID());
1344 for (
size_t i = 0; i < keys.
size(); ++i) {
1345 const auto &str = keys[i].
get_str();
1349 "Invalid private key encoding");
1353 if (pubkey_map.count(
id)) {
1354 pubkey_map.erase(
id);
1356 privkey_map.emplace(
id, key);
1361 import_data.
redeemscript || pubkey_map.size() || privkey_map.size();
1362 if (have_solving_data) {
1368 bool spendable = std::all_of(
1370 [&](
const std::pair<CKeyID, bool> &used_key) {
1371 return privkey_map.count(used_key.first) > 0;
1373 if (!watchOnly && !spendable) {
1374 warnings.
push_back(
"Some private keys are missing, outputs "
1375 "will be considered watchonly. If this is "
1376 "intentional, specify the watchonly flag.");
1378 if (watchOnly && spendable) {
1380 "All private keys are provided, outputs will be considered "
1381 "spendable. If this is intentional, do not specify the "
1386 if (
error.empty()) {
1387 for (
const auto &require_key : import_data.
used_keys) {
1388 if (!require_key.second) {
1393 if (pubkey_map.count(require_key.first) == 0 &&
1394 privkey_map.count(require_key.first) == 0) {
1395 error =
"some required keys are missing";
1400 if (!
error.empty()) {
1402 ". If this is intentional, don't provide "
1403 "any keys, pubkeys or redeemscript.");
1406 privkey_map.clear();
1407 have_solving_data =
false;
1414 "Ignoring redeemscript as this is not a P2SH script.");
1416 for (
auto it = privkey_map.begin(); it != privkey_map.end();) {
1418 if (import_data.
used_keys.count(oldit->first) == 0) {
1419 warnings.
push_back(
"Ignoring irrelevant private key.");
1420 privkey_map.erase(oldit);
1423 for (
auto it = pubkey_map.begin(); it != pubkey_map.end();) {
1425 auto key_data_it = import_data.
used_keys.find(oldit->first);
1426 if (key_data_it == import_data.
used_keys.end() ||
1427 !key_data_it->second) {
1428 warnings.
push_back(
"Ignoring public key \"" +
1430 "\" as it doesn't appear inside P2PKH.");
1431 pubkey_map.erase(oldit);
1441 std::map<CKeyID, CPubKey> &pubkey_map,
1442 std::map<CKeyID, CKey> &privkey_map,
1443 std::set<CScript> &script_pub_keys,
1444 bool &have_solving_data,
1446 std::vector<CKeyID> &ordered_pubkeys) {
1449 const std::string &descriptor = data[
"desc"].
get_str();
1458 have_solving_data = parsed_desc->IsSolvable();
1459 const bool watch_only =
1462 int64_t range_start = 0, range_end = 0;
1463 if (!parsed_desc->IsRange() && data.
exists(
"range")) {
1466 "Range should not be specified for an un-ranged descriptor");
1467 }
else if (parsed_desc->IsRange()) {
1468 if (!data.
exists(
"range")) {
1471 "Descriptor is ranged, please specify the range");
1481 for (
int i = range_start; i <= range_end; ++i) {
1483 std::vector<CScript> scripts_temp;
1484 parsed_desc->Expand(i, keys, scripts_temp, out_keys);
1485 std::copy(scripts_temp.begin(), scripts_temp.end(),
1486 std::inserter(script_pub_keys, script_pub_keys.end()));
1487 for (
const auto &key_pair : out_keys.
pubkeys) {
1488 ordered_pubkeys.push_back(key_pair.first);
1491 for (
const auto &x : out_keys.
scripts) {
1495 parsed_desc->ExpandPrivate(i, keys, out_keys);
1498 std::inserter(pubkey_map, pubkey_map.end()));
1499 std::copy(out_keys.
keys.begin(), out_keys.
keys.end(),
1500 std::inserter(privkey_map, privkey_map.end()));
1505 for (
size_t i = 0; i < priv_keys.
size(); ++i) {
1506 const auto &str = priv_keys[i].
get_str();
1510 "Invalid private key encoding");
1517 if (!pubkey_map.count(
id)) {
1518 warnings.
push_back(
"Ignoring irrelevant private key.");
1520 privkey_map.emplace(
id, key);
1531 std::all_of(pubkey_map.begin(), pubkey_map.end(),
1532 [&](
const std::pair<CKeyID, CPubKey> &used_key) {
1533 return privkey_map.count(used_key.first) > 0;
1537 [&](
const std::pair<
CKeyID, std::pair<CPubKey, KeyOriginInfo>>
1538 &entry) { return privkey_map.count(entry.first) > 0; });
1539 if (!watch_only && !spendable) {
1541 "Some private keys are missing, outputs will be considered "
1542 "watchonly. If this is intentional, specify the watchonly flag.");
1544 if (watch_only && spendable) {
1545 warnings.
push_back(
"All private keys are provided, outputs will be "
1546 "considered spendable. If this is intentional, do "
1547 "not specify the watchonly flag.");
1554 const int64_t timestamp)
1560 const bool internal =
1561 data.exists(
"internal") ? data[
"internal"].get_bool() :
false;
1563 if (internal && data.exists(
"label")) {
1565 "Internal addresses should not have a label");
1567 const std::string &label =
1568 data.exists(
"label") ? data[
"label"].get_str() :
"";
1569 const bool add_keypool =
1570 data.exists(
"keypool") ? data[
"keypool"].get_bool() :
false;
1576 "Keys can only be imported to the keypool when "
1577 "private keys are disabled");
1581 std::map<CKeyID, CPubKey> pubkey_map;
1582 std::map<CKeyID, CKey> privkey_map;
1583 std::set<CScript> script_pub_keys;
1584 std::vector<CKeyID> ordered_pubkeys;
1585 bool have_solving_data;
1587 if (data.exists(
"scriptPubKey") && data.exists(
"desc")) {
1590 "Both a descriptor and a scriptPubKey should not be provided.");
1591 }
else if (data.exists(
"scriptPubKey")) {
1593 pwallet, import_data, pubkey_map, privkey_map, script_pub_keys,
1594 have_solving_data, data, ordered_pubkeys);
1595 }
else if (data.exists(
"desc")) {
1597 import_data, pubkey_map, privkey_map, script_pub_keys,
1598 have_solving_data, data, ordered_pubkeys);
1602 "Either a descriptor or scriptPubKey must be provided.");
1608 !privkey_map.empty()) {
1610 "Cannot import private keys to a wallet with "
1611 "private keys disabled");
1615 for (
const CScript &script : script_pub_keys) {
1618 "The wallet already contains the private "
1619 "key for this address or script (\"" +
1625 pwallet->MarkDirty();
1626 if (!pwallet->ImportScripts(import_data.
import_scripts, timestamp)) {
1628 "Error adding script to wallet");
1630 if (!pwallet->ImportPrivKeys(privkey_map, timestamp)) {
1633 if (!pwallet->ImportPubKeys(ordered_pubkeys, pubkey_map,
1635 internal, timestamp)) {
1637 "Error adding address to wallet");
1639 if (!pwallet->ImportScriptPubKeys(label, script_pub_keys,
1640 have_solving_data, !internal,
1643 "Error adding address to wallet");
1649 result.
pushKV(
"error", e);
1656 if (warnings.
size()) {
1657 result.
pushKV(
"warnings", warnings);
1663 if (data.
exists(
"timestamp")) {
1664 const UniValue ×tamp = data[
"timestamp"];
1665 if (timestamp.
isNum()) {
1666 return timestamp.
getInt<int64_t>();
1667 }
else if (timestamp.
isStr() && timestamp.
get_str() ==
"now") {
1671 strprintf(
"Expected number or \"now\" timestamp "
1672 "value for key. got type %s",
1676 "Missing required timestamp field for key");
1680 const int64_t objectTimestamp,
1681 const int64_t blockTimestamp,
1682 const bool have_pruned,
1683 const bool has_assumed_valid_chain) {
1684 std::string error_msg{
1685 strprintf(
"Rescan failed for %s with creation timestamp %d. There "
1686 "was an error reading a block from time %d, which is after "
1687 "or within %d seconds of key creation, and could contain "
1688 "transactions pertaining to the %s. As a result, "
1689 "transactions and coins using this %s may not appear "
1695 "This error could be caused by pruning or data corruption "
1696 "(see bitcoind log for details) and could be dealt with by "
1697 "downloading and rescanning the relevant blocks (see -reindex "
1698 "option and rescanblockchain RPC).");
1699 }
else if (has_assumed_valid_chain) {
1701 "This error is likely caused by an in-progress assumeutxo "
1702 "background sync. Check logs or getchainstates RPC for assumeutxo "
1703 "background sync progress and try again later.");
1706 "This error could potentially be caused by data corruption. If "
1707 "the issue persists you may want to reindex (see -reindex "
1716 "Import addresses/scripts (with private or public keys, redeem "
1717 "script (P2SH)), optionally rescanning the blockchain from the "
1718 "earliest creation time of the imported scripts. Requires a new wallet "
1720 "If an address/script is imported without all of the private keys "
1721 "required to spend from that address, it will be watchonly. The "
1722 "'watchonly' option must be set to true in this case or a warning will "
1724 "Conversely, if all the private keys are provided and the "
1725 "address/script is spendable, the watchonly option must be set to "
1726 "false, or a warning will be returned.\n"
1727 "Note: Use \"getwalletinfo\" to query the scanning progress.\n"
1728 "Note: This command is only compatible with legacy wallets. Use "
1729 "\"importdescriptors\" for descriptor wallets.\n",
1734 "Data to be imported",
1743 "Descriptor to import. If using descriptor, do not "
1744 "also provide address/scriptPubKey, scripts, or "
1748 "Type of scriptPubKey (string for script, json for "
1749 "address). Should not be provided if using a "
1753 "\"address\":\"<address>\" }",
1756 "Creation time of the key expressed in " +
1759 "or the string \"now\" to substitute the current "
1760 "synced blockchain time. The timestamp of the "
1762 "key will determine how far back blockchain "
1763 "rescans need to begin for missing wallet "
1765 "\"now\" can be specified to bypass scanning, "
1766 "for keys which are known to never have been "
1768 "0 can be specified to scan the entire "
1769 "blockchain. Blocks up to 2 hours before the "
1771 "creation time of all keys being imported by the "
1772 "importmulti call will be scanned.",
1774 "integer / string"}}},
1777 "Allowed only if the scriptPubKey is a P2SH "
1778 "address/scriptPubKey"},
1782 "Array of strings giving pubkeys to import. They "
1783 "must occur in P2PKH scripts. They are not required "
1784 "when the private key is also provided (see the "
1785 "\"keys\" argument).",
1793 "Array of strings giving private keys to import. The "
1794 "corresponding public keys must occur in the output "
1802 "If a ranged descriptor is used, this specifies the "
1803 "end or the range (in the form [begin,end]) to "
1807 "Stating whether matching outputs should be treated "
1808 "as not incoming payments (also known as change)"},
1811 "Stating whether matching outputs should be "
1812 "considered watchonly."},
1814 "Label to assign to the address, only allowed with "
1817 "Stating whether imported public keys should be "
1818 "added to the keypool for when users request new "
1819 "addresses. Only allowed when wallet private keys "
1831 "Stating if should rescan the blockchain after all imports"},
1837 "Response is an array with the same size as the input that "
1838 "has the execution result",
1864 "'[{ \"scriptPubKey\": { \"address\": \"<my address>\" }, "
1865 "\"timestamp\":1455191478 }, "
1866 "{ \"scriptPubKey\": { \"address\": \"<my 2nd address>\" "
1868 "\"label\": \"example 2\", \"timestamp\": 1455191480 }]'") +
1871 "'[{ \"scriptPubKey\": { \"address\": \"<my address>\" }, "
1872 "\"timestamp\":1455191478 }]' '{ \"rescan\": false}'")
1877 std::shared_ptr<CWallet>
const wallet =
1886 const UniValue &requests = mainRequest.params[0];
1889 bool fRescan =
true;
1891 if (!mainRequest.params[1].isNull()) {
1892 const UniValue &options = mainRequest.params[1];
1894 if (options.
exists(
"rescan")) {
1895 fRescan = options[
"rescan"].
get_bool();
1900 if (fRescan && !reserver.
reserve()) {
1902 "Wallet is currently rescanning. Abort "
1903 "existing rescan or wait.");
1907 bool fRunScan =
false;
1908 int64_t nLowestTimestamp = 0;
1917 FoundBlock().time(nLowestTimestamp).mtpTime(now)));
1922 const int64_t minimumTimestamp = 1;
1925 const int64_t timestamp = std::max(
1936 if (result[
"success"].get_bool()) {
1941 if (timestamp < nLowestTimestamp) {
1942 nLowestTimestamp = timestamp;
1946 if (fRescan && fRunScan && requests.
size()) {
1948 nLowestTimestamp, reserver,
true );
1956 "Rescan aborted by user.");
1958 if (scannedTime > nLowestTimestamp) {
1959 std::vector<UniValue> results =
response.getValues();
1969 results.at(i).exists(
"error")) {
1984 response.push_back(std::move(result));
1998 const int64_t timestamp)
2004 if (!data.exists(
"desc")) {
2008 const std::string &descriptor = data[
"desc"].get_str();
2010 data.exists(
"active") ? data[
"active"].get_bool() :
false;
2011 const bool internal =
2012 data.exists(
"internal") ? data[
"internal"].get_bool() :
false;
2013 const std::string &label =
2014 data.exists(
"label") ? data[
"label"].get_str() :
"";
2026 int64_t range_start = 0, range_end = 1, next_index = 0;
2027 if (!parsed_desc->IsRange() && data.exists(
"range")) {
2030 "Range should not be specified for an un-ranged descriptor");
2031 }
else if (parsed_desc->IsRange()) {
2032 if (data.exists(
"range")) {
2034 range_start = range.first;
2037 range_end = range.second + 1;
2040 "Range not given, using default keypool range");
2044 next_index = range_start;
2046 if (data.exists(
"next_index")) {
2047 next_index = data[
"next_index"].getInt<int64_t>();
2049 if (next_index < range_start || next_index >= range_end) {
2051 "next_index is out of range");
2057 if (active && !parsed_desc->IsRange()) {
2059 "Active descriptors must be ranged");
2063 if (data.exists(
"range") && data.exists(
"label")) {
2065 "Ranged descriptors should not have a label");
2069 if (internal && data.exists(
"label")) {
2071 "Internal addresses should not have a label");
2075 if (active && !parsed_desc->IsSingleType()) {
2077 "Combo descriptors cannot be set to active");
2082 !keys.
keys.empty()) {
2084 "Cannot import private keys to a wallet with "
2085 "private keys disabled");
2091 std::vector<CScript> scripts;
2092 if (!parsed_desc->Expand(0, keys, scripts, expand_keys)) {
2095 "Cannot expand descriptor. Probably because of hardened "
2096 "derivations without private keys provided");
2098 parsed_desc->ExpandPrivate(0, keys, expand_keys);
2101 bool have_all_privkeys = !expand_keys.
keys.empty();
2102 for (
const auto &entry : expand_keys.
origins) {
2103 const CKeyID &key_id = entry.first;
2105 if (!expand_keys.
GetKey(key_id, key)) {
2106 have_all_privkeys =
false;
2113 if (keys.
keys.empty()) {
2116 "Cannot import descriptor without private keys to a wallet "
2117 "with private keys enabled");
2119 if (!have_all_privkeys) {
2121 "Not all private keys provided. Some wallet functionality "
2122 "may return unexpected errors");
2127 range_end, next_index);
2130 auto existing_spk_manager =
2131 pwallet->GetDescriptorScriptPubKeyMan(w_desc);
2132 if (existing_spk_manager &&
2133 !existing_spk_manager->CanUpdateToWalletDescriptor(w_desc,
error)) {
2139 pwallet->AddWalletDescriptor(w_desc, keys, label, internal);
2140 if (spk_manager ==
nullptr) {
2143 strprintf(
"Could not add descriptor '%s'", descriptor));
2150 "Unknown output type, cannot set descriptor to active.");
2152 pwallet->AddActiveScriptPubKeyMan(
2153 spk_manager->GetID(), *w_desc.
descriptor->GetOutputType(),
2158 pwallet->DeactivateScriptPubKeyMan(
2159 spk_manager->GetID(), *w_desc.
descriptor->GetOutputType(),
2167 result.
pushKV(
"error", e);
2169 if (warnings.
size()) {
2170 result.
pushKV(
"warnings", warnings);
2177 "importdescriptors",
2178 "Import descriptors. This will trigger a rescan of the blockchain "
2179 "based on the earliest timestamp of all descriptors being imported. "
2180 "Requires a new wallet backup.\n"
2181 "\nNote: This call can take over an hour to complete if using an early "
2182 "timestamp; during that time, other rpc calls\n"
2183 "may report that the imported keys, addresses or scripts exist but "
2184 "related transactions are still missing.\n",
2189 "Data to be imported",
2198 "Descriptor to import."},
2200 "Set this descriptor to be the active descriptor for "
2201 "the corresponding output type/externality"},
2204 "If a ranged descriptor is used, this specifies the "
2205 "end or the range (in the form [begin,end]) to "
2209 "If a ranged descriptor is set to active, this "
2210 "specifies the next index to generate addresses "
2213 "Time from which to start rescanning the blockchain "
2214 "for this descriptor, in " +
2217 "Use the string \"now\" to substitute the "
2218 "current synced blockchain time.\n"
2219 "\"now\" can be specified to bypass scanning, "
2220 "for outputs which are known to never have been "
2222 "0 can be specified to scan the entire "
2223 "blockchain. Blocks up to 2 hours before the "
2224 "earliest timestamp\n"
2225 "of all descriptors being imported will be "
2228 "integer / string"}}},
2231 "Whether matching outputs should be treated as not "
2232 "incoming payments (e.g. change)"},
2234 "Label to assign to the address, only allowed with "
2243 "Response is an array with the same size as the input that "
2244 "has the execution result",
2269 "'[{ \"desc\": \"<my descriptor>\", "
2270 "\"timestamp\":1455191478, \"internal\": true }, "
2271 "{ \"desc\": \"<my desccriptor 2>\", \"label\": "
2272 "\"example 2\", \"timestamp\": 1455191480 }]'") +
2274 "importdescriptors",
2275 "'[{ \"desc\": \"<my descriptor>\", \"timestamp\":1455191478, "
2276 "\"active\": true, \"range\": [0,100], \"label\": \"<my "
2277 "cashaddr wallet>\" }]'")},
2280 std::shared_ptr<CWallet>
const wallet =
2290 "importdescriptors is not available for "
2291 "non-descriptor wallets");
2297 "Wallet is currently rescanning. Abort "
2298 "existing rescan or wait.");
2301 const UniValue &requests = main_request.params[0];
2302 const int64_t minimum_timestamp = 1;
2304 int64_t lowest_timestamp = 0;
2305 bool rescan =
false;
2313 FoundBlock().time(lowest_timestamp).mtpTime(now)));
2318 const int64_t timestamp = std::max(
2324 if (lowest_timestamp > timestamp) {
2325 lowest_timestamp = timestamp;
2330 if (!rescan && result[
"success"].get_bool()) {
2340 lowest_timestamp, reserver,
true );
2348 "Rescan aborted by user.");
2351 if (scanned_time > lowest_timestamp) {
2352 std::vector<UniValue> results =
response.getValues();
2357 for (
unsigned int i = 0; i < requests.
size(); ++i) {
2366 results.at(i).exists(
"error")) {
2382 response.push_back(std::move(result));
2396 "Safely copies current wallet file to destination, which can be a "
2397 "directory or a path with filename.\n",
2400 "The destination directory or file"},
2407 std::shared_ptr<CWallet>
const wallet =
2417 pwallet->BlockUntilSyncedToCurrentChain();
2421 std::string strDest = request.params[0].get_str();
2424 "Error: Wallet backup failed!");
2435 "\nRestore and loads a wallet from backup.\n",
2438 "The name that will be applied to the restored wallet"},
2440 "The backup file that will be used to restore the wallet."},
2442 "Save wallet name to persistent settings and load on startup. "
2443 "True to add wallet to startup list, false to remove, null to "
2444 "leave unchanged."},
2451 "The wallet name if restored successfully."},
2453 "Warning message if wallet was not loaded cleanly."},
2457 "\"testwallet\" \"home\\backups\\backup-file.bak\"") +
2460 "\"testwallet\" \"home\\backups\\backup-file.bak\"") +
2463 {{
"wallet_name",
"testwallet"},
2464 {
"backup_file",
"home\\backups\\backup-file.bak\""},
2465 {
"load_on_startup",
true}}) +
2468 {{
"wallet_name",
"testwallet"},
2469 {
"backup_file",
"home\\backups\\backup-file.bak\""},
2470 {
"load_on_startup",
true}})},
2478 std::string wallet_name = request.params[0].get_str();
2480 std::optional<bool> load_on_start =
2481 request.params[2].isNull()
2483 : std::optional<bool>(request.params[2].get_bool());
2487 std::vector<bilingual_str> warnings;
2489 const std::shared_ptr<CWallet>
wallet =
2490 RestoreWallet(context, backup_file, wallet_name, load_on_start,
2491 status,
error, 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 std::string GetRescanErrorMessage(const std::string &object, const int64_t objectTimestamp, const int64_t blockTimestamp, const bool have_pruned, const bool has_assumed_valid_chain)
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)
static void EnsureBlockDataFromTime(const CWallet &wallet, int64_t timestamp)
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)
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.
virtual bool hasAssumedValidChain()=0
Return true if an assumed-valid chain is in use.
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 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 path PathFromString(const std::string &string)
Convert byte string to path object.
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)
A BlockHash is a unqiue identifier for a block.
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
Optional argument for which the default value is omitted from help text 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 WITH_LOCK(cs, code)
Run code while locking a mutex.
#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)
void HandleWalletError(const std::shared_ptr< CWallet > wallet, DatabaseStatus &status, bilingual_str &error)
WalletContext & EnsureWalletContext(const std::any &context)
std::shared_ptr< CWallet > RestoreWallet(WalletContext &context, const fs::path &backup_file, const std::string &wallet_name, std::optional< bool > load_on_start, DatabaseStatus &status, bilingual_str &error, std::vector< bilingual_str > &warnings)
@ WALLET_FLAG_DISABLE_PRIVATE_KEYS
@ WALLET_FLAG_DESCRIPTORS
Indicate that this wallet supports DescriptorScriptPubKeyMan.