40 std::stringstream ret;
41 for (
const uint8_t c : str) {
42 if (c <= 32 || c >= 128 || c ==
'%') {
43 ret <<
'%' <<
HexStr({&c, 1});
52 std::stringstream ret;
53 for (
unsigned int pos = 0; pos < str.length(); pos++) {
55 if (c ==
'%' && pos + 2 < str.length()) {
56 c = (((str[pos + 1] >> 6) * 9 + ((str[pos + 1] -
'0') & 15)) << 4) |
57 ((str[pos + 2] >> 6) * 9 + ((str[pos + 2] -
'0') & 15));
68 std::string &strAddr, std::string &strLabel)
70 bool fLabelFound =
false;
72 spk_man->GetKey(keyid, key);
74 const auto *address_book_entry = pwallet->FindAddressBookEntry(dest);
75 if (address_book_entry) {
76 if (!strAddr.empty()) {
87 pwallet->m_default_address_type),
98 int64_t scanned_time =
wallet.RescanFromTime(time_begin, reserver, update);
99 if (
wallet.IsAbortingRescan()) {
101 }
else if (scanned_time > time_begin) {
103 "Rescan was unable to fully rescan the blockchain. "
104 "Some transactions may be missing.");
111 "Adds a private key (as returned by dumpprivkey) to your wallet. "
112 "Requires a new wallet backup.\n"
113 "Hint: use importmulti to import more than one private key.\n"
114 "\nNote: This call can take minutes to complete if rescan is true, "
115 "during that time, other rpc calls\n"
116 "may report that the imported key exists but related transactions are "
117 "still missing, leading to temporarily incorrect/bogus balances and "
118 "unspent outputs until rescan completes.\n"
119 "Note: Use \"getwalletinfo\" to query the scanning progress.\n",
122 "The private key (see dumpprivkey)"},
125 "current label if address exists, otherwise \"\""},
126 "An optional label"},
128 "Rescan the wallet for transactions"},
132 "\nDump a private key\n" +
134 "\nImport the private key with rescan\n" +
136 "\nImport using a label and without rescan\n" +
138 "\nImport using default blank label and without rescan\n" +
140 "\nAs a JSON-RPC call\n" +
141 HelpExampleRpc(
"importprivkey",
"\"mykey\", \"testing\", false")},
144 std::shared_ptr<CWallet>
const wallet =
154 "Cannot import private keys to a wallet with "
155 "private keys disabled");
167 std::string strSecret = request.params[0].get_str();
168 std::string strLabel =
"";
169 if (!request.params[1].isNull()) {
170 strLabel = request.params[1].get_str();
174 if (!request.params[2].isNull()) {
175 fRescan = request.params[2].get_bool();
184 "Rescan is disabled when blocks are pruned");
187 if (fRescan && !reserver.
reserve()) {
190 "Wallet is currently rescanning. Abort existing "
197 "Invalid private key encoding");
210 if (!request.params[1].isNull() ||
219 "Error adding key to wallet");
235 "Stops current wallet rescan triggered by an RPC call, e.g. by an "
236 "importprivkey call.\n"
237 "Note: Use \"getwalletinfo\" to query the scanning progress.\n",
240 "Whether the abort was successful"},
243 "\nAbort the running wallet rescan\n" +
245 "\nAs a JSON-RPC call\n" +
249 std::shared_ptr<CWallet>
const wallet =
268 "Adds an address or script (in hex) that can be watched as if it "
269 "were in your wallet but cannot be used to spend. Requires a new "
271 "\nNote: This call can take minutes to complete if rescan is true, "
272 "during that time, other rpc calls\n"
273 "may report that the imported address exists but related transactions "
274 "are still missing, leading to temporarily incorrect/bogus balances "
275 "and unspent outputs until rescan completes.\n"
276 "If you have the full public key, you should call importpubkey instead "
278 "Hint: use importmulti to import more than one address.\n"
279 "\nNote: If you import a non-standard raw script in hex form, outputs "
280 "sending to it will be treated\n"
281 "as change, and not show up in many RPCs.\n"
282 "Note: Use \"getwalletinfo\" to query the scanning progress.\n",
285 "The Bitcoin address (or hex-encoded script)"},
287 "An optional label"},
289 "Rescan the wallet for transactions"},
291 "Add the P2SH version of the script as well"},
295 "\nImport an address with rescan\n" +
297 "\nImport using a label without rescan\n" +
298 HelpExampleCli(
"importaddress",
"\"myaddress\" \"testing\" false") +
299 "\nAs a JSON-RPC call\n" +
301 "\"myaddress\", \"testing\", false")},
304 std::shared_ptr<CWallet>
const wallet =
313 std::string strLabel;
314 if (!request.params[1].isNull()) {
315 strLabel = request.params[1].get_str();
320 if (!request.params[2].isNull()) {
321 fRescan = request.params[2].get_bool();
329 "Rescan is disabled when blocks are pruned");
333 if (fRescan && !reserver.
reserve()) {
335 "Wallet is currently rescanning. Abort "
336 "existing rescan or wait.");
341 if (!request.params[3].isNull()) {
342 fP2SH = request.params[3].get_bool();
349 request.params[0].get_str(),
wallet->GetChainParams());
354 "Cannot use the p2sh flag with an address - "
355 "use a script instead");
364 }
else if (
IsHex(request.params[0].get_str())) {
365 std::vector<uint8_t> data(
366 ParseHex(request.params[0].get_str()));
367 CScript redeem_script(data.begin(), data.end());
369 std::set<CScript> scripts = {redeem_script};
378 strLabel, scripts,
false ,
382 "Invalid Bitcoin address or script");
401 "Imports funds without rescan. Corresponding address or script must "
402 "previously be included in wallet. Aimed towards pruned wallets. The "
403 "end-user is responsible to import additional transactions that "
404 "subsequently spend the imported outputs or rescan after the point in "
405 "the blockchain the transaction is included.\n",
408 "A raw transaction in hex funding an already-existing address in "
411 "The hex output from gettxoutproof that contains the transaction"},
417 std::shared_ptr<CWallet>
const wallet =
425 if (!
DecodeHexTx(tx, request.params[0].get_str())) {
438 std::vector<uint256> vMatch;
439 std::vector<size_t> vIndex;
443 "Something wrong with merkleblock");
452 "Block not found in chain");
455 std::vector<uint256>::const_iterator it;
456 if ((it = std::find(vMatch.begin(), vMatch.end(), txid)) ==
459 "Transaction given doesn't exist in proof");
462 size_t txnIndex = vIndex[it - vMatch.begin()];
465 CWalletTx::Status::CONFIRMED, height,
469 if (pwallet->
IsMine(*tx_ref)) {
476 "No addresses in wallet correspond to included transaction");
484 "Deletes the specified transaction from the wallet. Meant for use "
485 "with pruned wallets and as a companion to importprunedfunds. This "
486 "will affect wallet balances.\n",
489 "The hex-encoded id of the transaction you are deleting"},
493 "\"a8d0c0184dde994a09ec054286f1ce581bebf4644"
494 "6a512166eae7628734ea0a5\"") +
495 "\nAs a JSON-RPC call\n" +
497 "\"a8d0c0184dde994a09ec054286f1ce581bebf4644"
498 "6a512166eae7628734ea0a5\"")},
501 std::shared_ptr<CWallet>
const wallet =
511 std::vector<TxId> txIds;
512 txIds.push_back(txid);
513 std::vector<TxId> txIdsOut;
518 "Could not properly delete the transaction.");
521 if (txIdsOut.empty()) {
523 "Transaction does not exist in wallet.");
534 "Adds a public key (in hex) that can be watched as if it were in "
535 "your wallet but cannot be used to spend. Requires a new wallet "
537 "Hint: use importmulti to import more than one public key.\n"
538 "\nNote: This call can take minutes to complete if rescan is true, "
539 "during that time, other rpc calls\n"
540 "may report that the imported pubkey exists but related transactions "
541 "are still missing, leading to temporarily incorrect/bogus balances "
542 "and unspent outputs until rescan completes.\n"
543 "Note: Use \"getwalletinfo\" to query the scanning progress.\n",
546 "The hex-encoded public key"},
548 "An optional label"},
550 "Rescan the wallet for transactions"},
554 "\nImport a public key with rescan\n" +
556 "\nImport using a label without rescan\n" +
557 HelpExampleCli(
"importpubkey",
"\"mypubkey\" \"testing\" false") +
558 "\nAs a JSON-RPC call\n" +
559 HelpExampleRpc(
"importpubkey",
"\"mypubkey\", \"testing\", false")},
562 std::shared_ptr<CWallet>
const wallet =
571 std::string strLabel;
572 if (!request.params[1].isNull()) {
573 strLabel = request.params[1].get_str();
578 if (!request.params[2].isNull()) {
579 fRescan = request.params[2].get_bool();
587 "Rescan is disabled when blocks are pruned");
591 if (fRescan && !reserver.
reserve()) {
593 "Wallet is currently rescanning. Abort "
594 "existing rescan or wait.");
597 if (!
IsHex(request.params[0].get_str())) {
599 "Pubkey must be a hex string");
601 std::vector<uint8_t> data(
ParseHex(request.params[0].get_str()));
605 "Pubkey is not a valid public key");
611 std::set<CScript> script_pub_keys;
619 strLabel, script_pub_keys,
true ,
643 "Imports keys from a wallet dump file (see dumpwallet). Requires a "
644 "new wallet backup to include imported keys.\n"
645 "Note: Use \"getwalletinfo\" to query the scanning progress.\n",
653 "\nImport the wallet\n" +
655 "\nImport using the json rpc call\n" +
659 std::shared_ptr<CWallet>
const wallet =
674 "Importing wallets is disabled when blocks are pruned");
680 "Wallet is currently rescanning. Abort "
681 "existing rescan or wait.");
684 int64_t nTimeBegin = 0;
692 file.open(
fs::u8path(request.params[0].get_str()),
693 std::ios::in | std::ios::ate);
694 if (!file.is_open()) {
696 "Cannot open wallet dump file");
702 int64_t nFilesize = std::max<int64_t>(1, file.tellg());
703 file.seekg(0, file.beg);
713 strprintf(
"%s " +
_(
"Importing...").translated,
716 std::vector<std::tuple<CKey, int64_t, bool, std::string>> keys;
717 std::vector<std::pair<CScript, int64_t>> scripts;
718 while (file.good()) {
722 std::min<int>(50, 100 *
double(file.tellg()) /
726 std::getline(file, line);
727 if (line.empty() || line[0] ==
'#') {
731 std::vector<std::string> vstr =
SplitString(line,
' ');
732 if (vstr.size() < 2) {
738 std::string strLabel;
740 for (
size_t nStr = 2; nStr < vstr.size(); nStr++) {
741 if (vstr[nStr].front() ==
'#') {
744 if (vstr[nStr] ==
"change=1") {
747 if (vstr[nStr] ==
"reserve=1") {
750 if (vstr[nStr].substr(0, 6) ==
"label=") {
757 std::make_tuple(key, nTime, fLabel, strLabel));
758 }
else if (
IsHex(vstr[0])) {
759 std::vector<uint8_t> vData(
ParseHex(vstr[0]));
763 std::pair<CScript, int64_t>(script, birth_time));
774 "Importing wallets is disabled when "
775 "private keys are disabled");
777 double total = double(keys.size() + scripts.size());
779 for (
const auto &key_tuple : keys) {
782 std::max(50, std::min<int>(75, 100 * progress / total) +
785 const CKey &key = std::get<0>(key_tuple);
786 int64_t time = std::get<1>(key_tuple);
787 bool has_label = std::get<2>(key_tuple);
788 std::string label = std::get<3>(key_tuple);
800 "Error importing key for %s\n",
811 nTimeBegin = std::min(nTimeBegin, time);
814 for (
const auto &script_pair : scripts) {
817 std::max(50, std::min<int>(75, 100 * progress / total) +
820 const CScript &script = script_pair.first;
821 int64_t time = script_pair.second;
830 nTimeBegin = std::min(nTimeBegin, time);
840 pwallet->chain().showProgress(
"", 100,
false);
842 pwallet->MarkDirty();
846 "Error adding some keys/scripts to wallet");
857 "Reveals the private key corresponding to 'address'.\n"
858 "Then the importprivkey can be used with this output\n",
861 "The bitcoin address for the private key"},
869 std::shared_ptr<CWallet>
const wallet =
883 std::string strAddress = request.params[0].get_str();
888 "Invalid Bitcoin address");
891 if (keyid.IsNull()) {
893 "Address does not refer to a key");
896 if (!spk_man.
GetKey(keyid, vchSecret)) {
898 "Private key for address " + strAddress +
909 "Dumps all wallet keys in a human-readable format to a server-side "
910 "file. This does not allow overwriting existing files.\n"
911 "Imported scripts are included in the dumpsfile, but corresponding "
912 "addresses may not be added automatically by importwallet.\n"
913 "Note that if your wallet contains keys which are not derived from "
914 "your HD seed (e.g. imported keys), these are not covered by\n"
915 "only backing up the seed itself, and must be backed up too (e.g. "
916 "ensure you back up the whole dumpfile).\n",
919 "The filename with path (absolute path recommended)"},
926 "The filename with full absolute path"},
932 std::shared_ptr<CWallet>
const pwallet =
945 wallet.BlockUntilSyncedToCurrentChain();
963 " already exists. If you are "
964 "sure this is what you want, "
965 "move it out of the way first");
970 if (!file.is_open()) {
972 "Cannot open wallet dump file");
975 std::map<CKeyID, int64_t> mapKeyBirth;
976 wallet.GetKeyBirthTimes(mapKeyBirth);
978 int64_t block_time = 0;
988 const std::map<CKeyID, int64_t> &mapKeyPool =
990 std::set<CScriptID> scripts = spk_man.
GetCScripts();
993 std::vector<std::pair<int64_t, CKeyID>> vKeyBirth;
994 for (
const auto &entry : mapKeyBirth) {
995 vKeyBirth.push_back(std::make_pair(entry.second, entry.first));
998 std::sort(vKeyBirth.begin(), vKeyBirth.end());
1003 file <<
strprintf(
"# * Created on %s\n",
1005 file <<
strprintf(
"# * Best block at time of backup was %i (%s),\n",
1006 wallet.GetLastBlockHeight(),
1007 wallet.GetLastBlockHash().ToString());
1016 if (spk_man.
GetKey(seed_id, seed)) {
1020 file <<
"# extended private masterkey: "
1024 for (std::vector<std::pair<int64_t, CKeyID>>::const_iterator it =
1026 it != vKeyBirth.end(); it++) {
1027 const CKeyID &keyid = it->second;
1029 std::string strAddr;
1030 std::string strLabel;
1032 if (spk_man.
GetKey(keyid, key)) {
1035 keyid, strAddr, strLabel)) {
1036 file <<
strprintf(
"label=%s", strLabel);
1037 }
else if (keyid == seed_id) {
1039 }
else if (mapKeyPool.count(keyid)) {
1040 file <<
"reserve=1";
1041 }
else if (spk_man.mapKeyMetadata[keyid].hdKeypath ==
"s") {
1042 file <<
"inactivehdseed=1";
1047 " # addr=%s%s\n", strAddr,
1048 (spk_man.mapKeyMetadata[keyid].has_key_origin
1056 for (
const CScriptID &scriptid : scripts) {
1058 std::string create_time =
"0";
1059 std::string address =
1062 auto it = spk_man.m_script_metadata.find(scriptid);
1063 if (it != spk_man.m_script_metadata.end()) {
1069 file <<
strprintf(
" # addr=%s\n", address);
1073 file <<
"# End of dump\n";
1087 "dump all the UTXO tracked by the wallet.\n",
1096 "The list of UTXO corresponding to this address.",
1103 "The transaction id"},
1107 "The output's amount"},
1116 std::shared_ptr<CWallet>
const pwallet =
1127 wallet.BlockUntilSyncedToCurrentChain();
1136 for (
const auto &o : p.second) {
1138 utxo.
pushKV(
"txid", o.tx->GetId().ToString());
1139 utxo.
pushKV(
"vout", o.i);
1140 utxo.
pushKV(
"depth", o.nDepth);
1141 utxo.
pushKV(
"value", o.tx->tx->vout[o.i].nValue);
1181 std::vector<std::vector<uint8_t>> solverdata;
1184 switch (script_type) {
1186 CPubKey pubkey(solverdata[0]);
1198 "Trying to nest P2SH inside another P2SH");
1206 return "missing redeemscript";
1209 return "redeemScript does not match the scriptPubKey";
1216 for (
size_t i = 1; i + 1 < solverdata.size(); ++i) {
1217 CPubKey pubkey(solverdata[i]);
1223 return "unspendable script";
1226 return "unrecognized script";
1232 std::map<CKeyID, CPubKey> &pubkey_map, std::map<CKeyID, CKey> &privkey_map,
1233 std::set<CScript> &script_pub_keys,
bool &have_solving_data,
1234 const UniValue &data, std::vector<CKeyID> &ordered_pubkeys) {
1239 const UniValue &scriptPubKey = data[
"scriptPubKey"];
1242 scriptPubKey.
exists(
"address"))) {
1244 "scriptPubKey must be string with script or JSON "
1245 "with address string");
1247 const std::string &output =
1248 isScript ? scriptPubKey.
get_str() : scriptPubKey[
"address"].
get_str();
1251 const std::string &strRedeemScript =
1252 data.
exists(
"redeemscript") ? data[
"redeemscript"].
get_str() :
"";
1257 const bool internal =
1259 const bool watchOnly =
1262 if (data.
exists(
"range")) {
1265 "Range should not be specified for a non-descriptor import");
1275 "Invalid address \"" + output +
"\"");
1279 if (!
IsHex(output)) {
1281 "Invalid scriptPubKey \"" + output +
"\"");
1283 std::vector<uint8_t> vData(
ParseHex(output));
1284 script =
CScript(vData.begin(), vData.end());
1288 "Internal must be set to true for "
1289 "nonstandard scriptPubKey imports.");
1292 script_pub_keys.emplace(script);
1295 if (strRedeemScript.size()) {
1296 if (!
IsHex(strRedeemScript)) {
1298 "Invalid redeem script \"" + strRedeemScript +
1299 "\": must be hex string");
1301 auto parsed_redeemscript =
ParseHex(strRedeemScript);
1303 parsed_redeemscript.begin(), parsed_redeemscript.end());
1305 for (
size_t i = 0; i < pubKeys.
size(); ++i) {
1306 const auto &str = pubKeys[i].
get_str();
1309 "Pubkey \"" + str +
"\" must be a hex string");
1311 auto parsed_pubkey =
ParseHex(str);
1312 CPubKey pubkey(parsed_pubkey);
1316 "\" is not a valid public key");
1318 pubkey_map.emplace(pubkey.
GetID(), pubkey);
1319 ordered_pubkeys.push_back(pubkey.
GetID());
1321 for (
size_t i = 0; i < keys.
size(); ++i) {
1322 const auto &str = keys[i].
get_str();
1326 "Invalid private key encoding");
1330 if (pubkey_map.count(
id)) {
1331 pubkey_map.erase(
id);
1333 privkey_map.emplace(
id, key);
1338 import_data.
redeemscript || pubkey_map.size() || privkey_map.size();
1339 if (have_solving_data) {
1345 bool spendable = std::all_of(
1347 [&](
const std::pair<CKeyID, bool> &used_key) {
1348 return privkey_map.count(used_key.first) > 0;
1350 if (!watchOnly && !spendable) {
1351 warnings.
push_back(
"Some private keys are missing, outputs "
1352 "will be considered watchonly. If this is "
1353 "intentional, specify the watchonly flag.");
1355 if (watchOnly && spendable) {
1357 "All private keys are provided, outputs will be considered "
1358 "spendable. If this is intentional, do not specify the "
1363 if (
error.empty()) {
1364 for (
const auto &require_key : import_data.
used_keys) {
1365 if (!require_key.second) {
1370 if (pubkey_map.count(require_key.first) == 0 &&
1371 privkey_map.count(require_key.first) == 0) {
1372 error =
"some required keys are missing";
1377 if (!
error.empty()) {
1379 ". If this is intentional, don't provide "
1380 "any keys, pubkeys or redeemscript.");
1383 privkey_map.clear();
1384 have_solving_data =
false;
1391 "Ignoring redeemscript as this is not a P2SH script.");
1393 for (
auto it = privkey_map.begin(); it != privkey_map.end();) {
1395 if (import_data.
used_keys.count(oldit->first) == 0) {
1396 warnings.
push_back(
"Ignoring irrelevant private key.");
1397 privkey_map.erase(oldit);
1400 for (
auto it = pubkey_map.begin(); it != pubkey_map.end();) {
1402 auto key_data_it = import_data.
used_keys.find(oldit->first);
1403 if (key_data_it == import_data.
used_keys.end() ||
1404 !key_data_it->second) {
1405 warnings.
push_back(
"Ignoring public key \"" +
1407 "\" as it doesn't appear inside P2PKH.");
1408 pubkey_map.erase(oldit);
1418 std::map<CKeyID, CPubKey> &pubkey_map,
1419 std::map<CKeyID, CKey> &privkey_map,
1420 std::set<CScript> &script_pub_keys,
1421 bool &have_solving_data,
1423 std::vector<CKeyID> &ordered_pubkeys) {
1426 const std::string &descriptor = data[
"desc"].
get_str();
1435 have_solving_data = parsed_desc->IsSolvable();
1436 const bool watch_only =
1439 int64_t range_start = 0, range_end = 0;
1440 if (!parsed_desc->IsRange() && data.
exists(
"range")) {
1443 "Range should not be specified for an un-ranged descriptor");
1444 }
else if (parsed_desc->IsRange()) {
1445 if (!data.
exists(
"range")) {
1448 "Descriptor is ranged, please specify the range");
1458 for (
int i = range_start; i <= range_end; ++i) {
1460 std::vector<CScript> scripts_temp;
1461 parsed_desc->Expand(i, keys, scripts_temp, out_keys);
1462 std::copy(scripts_temp.begin(), scripts_temp.end(),
1463 std::inserter(script_pub_keys, script_pub_keys.end()));
1464 for (
const auto &key_pair : out_keys.
pubkeys) {
1465 ordered_pubkeys.push_back(key_pair.first);
1468 for (
const auto &x : out_keys.
scripts) {
1472 parsed_desc->ExpandPrivate(i, keys, out_keys);
1475 std::inserter(pubkey_map, pubkey_map.end()));
1476 std::copy(out_keys.
keys.begin(), out_keys.
keys.end(),
1477 std::inserter(privkey_map, privkey_map.end()));
1482 for (
size_t i = 0; i < priv_keys.
size(); ++i) {
1483 const auto &str = priv_keys[i].
get_str();
1487 "Invalid private key encoding");
1494 if (!pubkey_map.count(
id)) {
1495 warnings.
push_back(
"Ignoring irrelevant private key.");
1497 privkey_map.emplace(
id, key);
1508 std::all_of(pubkey_map.begin(), pubkey_map.end(),
1509 [&](
const std::pair<CKeyID, CPubKey> &used_key) {
1510 return privkey_map.count(used_key.first) > 0;
1514 [&](
const std::pair<
CKeyID, std::pair<CPubKey, KeyOriginInfo>>
1515 &entry) { return privkey_map.count(entry.first) > 0; });
1516 if (!watch_only && !spendable) {
1518 "Some private keys are missing, outputs will be considered "
1519 "watchonly. If this is intentional, specify the watchonly flag.");
1521 if (watch_only && spendable) {
1522 warnings.
push_back(
"All private keys are provided, outputs will be "
1523 "considered spendable. If this is intentional, do "
1524 "not specify the watchonly flag.");
1531 const int64_t timestamp)
1537 const bool internal =
1538 data.exists(
"internal") ? data[
"internal"].get_bool() :
false;
1540 if (
internal && data.exists(
"label")) {
1542 "Internal addresses should not have a label");
1544 const std::string &label =
1545 data.exists(
"label") ? data[
"label"].get_str() :
"";
1546 const bool add_keypool =
1547 data.exists(
"keypool") ? data[
"keypool"].get_bool() :
false;
1553 "Keys can only be imported to the keypool when "
1554 "private keys are disabled");
1558 std::map<CKeyID, CPubKey> pubkey_map;
1559 std::map<CKeyID, CKey> privkey_map;
1560 std::set<CScript> script_pub_keys;
1561 std::vector<CKeyID> ordered_pubkeys;
1562 bool have_solving_data;
1564 if (data.exists(
"scriptPubKey") && data.exists(
"desc")) {
1567 "Both a descriptor and a scriptPubKey should not be provided.");
1568 }
else if (data.exists(
"scriptPubKey")) {
1570 pwallet, import_data, pubkey_map, privkey_map, script_pub_keys,
1571 have_solving_data, data, ordered_pubkeys);
1572 }
else if (data.exists(
"desc")) {
1574 import_data, pubkey_map, privkey_map, script_pub_keys,
1575 have_solving_data, data, ordered_pubkeys);
1579 "Either a descriptor or scriptPubKey must be provided.");
1585 !privkey_map.empty()) {
1587 "Cannot import private keys to a wallet with "
1588 "private keys disabled");
1592 for (
const CScript &script : script_pub_keys) {
1595 "The wallet already contains the private "
1596 "key for this address or script (\"" +
1602 pwallet->MarkDirty();
1603 if (!pwallet->ImportScripts(import_data.
import_scripts, timestamp)) {
1605 "Error adding script to wallet");
1607 if (!pwallet->ImportPrivKeys(privkey_map, timestamp)) {
1610 if (!pwallet->ImportPubKeys(ordered_pubkeys, pubkey_map,
1612 internal, timestamp)) {
1614 "Error adding address to wallet");
1616 if (!pwallet->ImportScriptPubKeys(label, script_pub_keys,
1617 have_solving_data, !
internal,
1620 "Error adding address to wallet");
1626 result.
pushKV(
"error", e);
1633 if (warnings.
size()) {
1634 result.
pushKV(
"warnings", warnings);
1640 if (data.
exists(
"timestamp")) {
1641 const UniValue ×tamp = data[
"timestamp"];
1642 if (timestamp.
isNum()) {
1644 }
else if (timestamp.
isStr() && timestamp.
get_str() ==
"now") {
1648 strprintf(
"Expected number or \"now\" timestamp "
1649 "value for key. got type %s",
1653 "Missing required timestamp field for key");
1657 const int64_t objectTimestamp,
1658 const int64_t blockTimestamp) {
1660 "Rescan failed for %s with creation timestamp %d. There was an error "
1661 "reading a block from time %d, which is after or within %d seconds of "
1662 "key creation, and could contain transactions pertaining to the %s. As "
1663 "a result, transactions and coins using this %s may not appear in "
1664 "the wallet. This error could be caused by pruning or data corruption "
1665 "(see bitcoind log for details) and could be dealt with by downloading "
1666 "and rescanning the relevant blocks (see -reindex and -rescan "
1675 "Import addresses/scripts (with private or public keys, redeem "
1676 "script (P2SH)), optionally rescanning the blockchain from the "
1677 "earliest creation time of the imported scripts. Requires a new wallet "
1679 "If an address/script is imported without all of the private keys "
1680 "required to spend from that address, it will be watchonly. The "
1681 "'watchonly' option must be set to true in this case or a warning will "
1683 "Conversely, if all the private keys are provided and the "
1684 "address/script is spendable, the watchonly option must be set to "
1685 "false, or a warning will be returned.\n"
1686 "Note: Use \"getwalletinfo\" to query the scanning progress.\n",
1691 "Data to be imported",
1700 "Descriptor to import. If using descriptor, do not "
1701 "also provide address/scriptPubKey, scripts, or "
1706 "Type of scriptPubKey (string for script, json for "
1707 "address). Should not be provided if using a "
1710 {
"\"<script>\" | { \"address\":\"<address>\" }",
1715 "Creation time of the key expressed in " +
1719 " or the string \"now\" to "
1720 "substitute the current synced blockchain time. "
1722 "timestamp of the oldest\n"
1724 " key will determine how far "
1726 "blockchain rescans need to begin for missing "
1730 " \"now\" can be specified to "
1731 "bypass scanning, for keys which are known to "
1733 "have been used, and\n"
1735 " 0 can be specified to scan "
1737 "entire blockchain. Blocks up to 2 hours before "
1741 " creation time of all keys "
1743 "imported by the importmulti call will be "
1746 {
"timestamp | \"now\"",
"integer / string"}},
1749 "Allowed only if the scriptPubKey is a P2SH "
1750 "address/scriptPubKey"},
1754 "Array of strings giving pubkeys to import. They "
1755 "must occur in P2PKH scripts. They are not required "
1756 "when the private key is also provided (see the "
1757 "\"keys\" argument).",
1765 "Array of strings giving private keys to import. The "
1766 "corresponding public keys must occur in the output "
1774 "If a ranged descriptor is used, this specifies the "
1775 "end or the range (in the form [begin,end]) to "
1779 "Stating whether matching outputs should be treated "
1780 "as not incoming payments (also known as change)"},
1783 "Stating whether matching outputs should be "
1784 "considered watchonly."},
1786 "Label to assign to the address, only allowed with "
1789 "Stating whether imported public keys should be "
1790 "added to the keypool for when users request new "
1791 "addresses. Only allowed when wallet private keys "
1803 "Stating if should rescan the blockchain after all imports"},
1809 "Response is an array with the same size as the input that "
1810 "has the execution result",
1836 "'[{ \"scriptPubKey\": { \"address\": \"<my address>\" }, "
1837 "\"timestamp\":1455191478 }, "
1838 "{ \"scriptPubKey\": { \"address\": \"<my 2nd address>\" "
1840 "\"label\": \"example 2\", \"timestamp\": 1455191480 }]'") +
1843 "'[{ \"scriptPubKey\": { \"address\": \"<my address>\" }, "
1844 "\"timestamp\":1455191478 }]' '{ \"rescan\": false}'")
1849 std::shared_ptr<CWallet>
const wallet =
1856 RPCTypeCheck(mainRequest.params, {UniValue::VARR, UniValue::VOBJ});
1860 const UniValue &requests = mainRequest.params[0];
1863 bool fRescan =
true;
1865 if (!mainRequest.params[1].isNull()) {
1866 const UniValue &options = mainRequest.params[1];
1868 if (options.
exists(
"rescan")) {
1869 fRescan = options[
"rescan"].
get_bool();
1874 if (fRescan && !reserver.
reserve()) {
1876 "Wallet is currently rescanning. Abort "
1877 "existing rescan or wait.");
1881 bool fRunScan =
false;
1882 int64_t nLowestTimestamp = 0;
1891 FoundBlock().time(nLowestTimestamp).mtpTime(now)));
1896 const int64_t minimumTimestamp = 1;
1899 const int64_t timestamp = std::max(
1910 if (result[
"success"].get_bool()) {
1915 if (timestamp < nLowestTimestamp) {
1916 nLowestTimestamp = timestamp;
1920 if (fRescan && fRunScan && requests.
size()) {
1922 nLowestTimestamp, reserver,
true );
1930 "Rescan aborted by user.");
1932 if (scannedTime > nLowestTimestamp) {
1933 std::vector<UniValue> results =
response.getValues();
1943 results.at(i).exists(
"error")) {
1955 response.push_back(std::move(result));
1969 const int64_t timestamp)
1975 if (!data.exists(
"desc")) {
1979 const std::string &descriptor = data[
"desc"].get_str();
1981 data.exists(
"active") ? data[
"active"].get_bool() :
false;
1982 const bool internal =
1983 data.exists(
"internal") ? data[
"internal"].get_bool() :
false;
1984 const std::string &label =
1985 data.exists(
"label") ? data[
"label"].get_str() :
"";
1997 int64_t range_start = 0, range_end = 1, next_index = 0;
1998 if (!parsed_desc->IsRange() && data.exists(
"range")) {
2001 "Range should not be specified for an un-ranged descriptor");
2002 }
else if (parsed_desc->IsRange()) {
2003 if (data.exists(
"range")) {
2005 range_start = range.first;
2008 range_end = range.second + 1;
2011 "Range not given, using default keypool range");
2015 next_index = range_start;
2017 if (data.exists(
"next_index")) {
2018 next_index = data[
"next_index"].get_int64();
2020 if (next_index < range_start || next_index >= range_end) {
2022 "next_index is out of range");
2028 if (active && !parsed_desc->IsRange()) {
2030 "Active descriptors must be ranged");
2034 if (data.exists(
"range") && data.exists(
"label")) {
2036 "Ranged descriptors should not have a label");
2040 if (
internal && data.exists(
"label")) {
2042 "Internal addresses should not have a label");
2046 if (active && !parsed_desc->IsSingleType()) {
2048 "Combo descriptors cannot be set to active");
2053 !keys.
keys.empty()) {
2055 "Cannot import private keys to a wallet with "
2056 "private keys disabled");
2062 std::vector<CScript> scripts;
2063 if (!parsed_desc->Expand(0, keys, scripts, expand_keys)) {
2066 "Cannot expand descriptor. Probably because of hardened "
2067 "derivations without private keys provided");
2069 parsed_desc->ExpandPrivate(0, keys, expand_keys);
2072 bool have_all_privkeys = !expand_keys.
keys.empty();
2073 for (
const auto &entry : expand_keys.
origins) {
2074 const CKeyID &key_id = entry.first;
2076 if (!expand_keys.
GetKey(key_id, key)) {
2077 have_all_privkeys =
false;
2084 if (keys.
keys.empty()) {
2087 "Cannot import descriptor without private keys to a wallet "
2088 "with private keys enabled");
2090 if (!have_all_privkeys) {
2092 "Not all private keys provided. Some wallet functionality "
2093 "may return unexpected errors");
2098 range_end, next_index);
2101 auto existing_spk_manager =
2102 pwallet->GetDescriptorScriptPubKeyMan(w_desc);
2103 if (existing_spk_manager &&
2104 !existing_spk_manager->CanUpdateToWalletDescriptor(w_desc,
error)) {
2110 pwallet->AddWalletDescriptor(w_desc, keys, label,
internal);
2111 if (spk_manager ==
nullptr) {
2114 strprintf(
"Could not add descriptor '%s'", descriptor));
2121 "Unknown output type, cannot set descriptor to active.");
2123 pwallet->AddActiveScriptPubKeyMan(
2124 spk_manager->GetID(), *w_desc.
descriptor->GetOutputType(),
2129 pwallet->DeactivateScriptPubKeyMan(
2130 spk_manager->GetID(), *w_desc.
descriptor->GetOutputType(),
2138 result.
pushKV(
"error", e);
2140 if (warnings.
size()) {
2141 result.
pushKV(
"warnings", warnings);
2148 "importdescriptors",
2149 "Import descriptors. This will trigger a rescan of the blockchain "
2150 "based on the earliest timestamp of all descriptors being imported. "
2151 "Requires a new wallet backup.\n"
2152 "\nNote: This call can take over an hour to complete if using an early "
2153 "timestamp; during that time, other rpc calls\n"
2154 "may report that the imported keys, addresses or scripts exist but "
2155 "related transactions are still missing.\n",
2160 "Data to be imported",
2169 "Descriptor to import."},
2171 "Set this descriptor to be the active descriptor for "
2172 "the corresponding output type/externality"},
2175 "If a ranged descriptor is used, this specifies the "
2176 "end or the range (in the form [begin,end]) to "
2180 "If a ranged descriptor is set to active, this "
2181 "specifies the next index to generate addresses "
2186 "Time from which to start rescanning the blockchain "
2187 "for this descriptor, in " +
2191 " Use the string \"now\" to "
2192 "substitute the current synced blockchain time.\n"
2194 " \"now\" can be specified to "
2195 "bypass scanning, for outputs which are known to "
2196 "never have been used, and\n"
2198 " 0 can be specified to scan the "
2199 "entire blockchain. Blocks up to 2 hours before "
2200 "the earliest timestamp\n"
2202 " of all descriptors being imported "
2205 {
"timestamp | \"now\"",
"integer / string"}},
2208 "Whether matching outputs should be treated as not "
2209 "incoming payments (e.g. change)"},
2211 "Label to assign to the address, only allowed with "
2220 "Response is an array with the same size as the input that "
2221 "has the execution result",
2246 "'[{ \"desc\": \"<my descriptor>\", "
2247 "\"timestamp\":1455191478, \"internal\": true }, "
2248 "{ \"desc\": \"<my desccriptor 2>\", \"label\": "
2249 "\"example 2\", \"timestamp\": 1455191480 }]'") +
2251 "importdescriptors",
2252 "'[{ \"desc\": \"<my descriptor>\", \"timestamp\":1455191478, "
2253 "\"active\": true, \"range\": [0,100], \"label\": \"<my "
2254 "cashaddr wallet>\" }]'")},
2257 std::shared_ptr<CWallet>
const wallet =
2267 "importdescriptors is not available for "
2268 "non-descriptor wallets");
2271 RPCTypeCheck(main_request.params, {UniValue::VARR, UniValue::VOBJ});
2276 "Wallet is currently rescanning. Abort "
2277 "existing rescan or wait.");
2280 const UniValue &requests = main_request.params[0];
2281 const int64_t minimum_timestamp = 1;
2283 int64_t lowest_timestamp = 0;
2284 bool rescan =
false;
2292 FoundBlock().time(lowest_timestamp).mtpTime(now)));
2297 const int64_t timestamp = std::max(
2303 if (lowest_timestamp > timestamp) {
2304 lowest_timestamp = timestamp;
2309 if (!rescan && result[
"success"].get_bool()) {
2319 lowest_timestamp, reserver,
true );
2327 "Rescan aborted by user.");
2330 if (scanned_time > lowest_timestamp) {
2331 std::vector<UniValue> results =
response.getValues();
2336 for (
unsigned int i = 0; i < requests.
size(); ++i) {
2345 results.at(i).exists(
"error")) {
2358 response.push_back(std::move(result));
2372 "Safely copies current wallet file to destination, which can be a "
2373 "directory or a path with filename.\n",
2376 "The destination directory or file"},
2383 std::shared_ptr<CWallet>
const wallet =
2393 pwallet->BlockUntilSyncedToCurrentChain();
2397 std::string strDest = request.params[0].get_str();
2400 "Error: Wallet backup failed!");
2411 "\nRestore and loads a wallet from backup.\n",
2414 "The name that will be applied to the restored wallet"},
2416 "The backup file that will be used to restore the wallet."},
2419 "Save wallet name to persistent settings and load on startup. "
2420 "True to add wallet to startup list, false to remove, null to "
2421 "leave unchanged."},
2428 "The wallet name if restored successfully."},
2430 "Warning message if wallet was not loaded cleanly."},
2434 "\"testwallet\" \"home\\backups\\backup-file.bak\"") +
2437 "\"testwallet\" \"home\\backups\\backup-file.bak\"") +
2440 {{
"wallet_name",
"testwallet"},
2441 {
"backup_file",
"home\\backups\\backup-file.bak\""},
2442 {
"load_on_startup",
true}}) +
2445 {{
"wallet_name",
"testwallet"},
2446 {
"backup_file",
"home\\backups\\backup-file.bak\""},
2447 {
"load_on_startup",
true}})},
2457 "Backup file does not exist");
2460 std::string wallet_name = request.params[0].get_str();
2467 "Wallet name already exists.");
2472 strprintf(
"Failed to create database path "
2473 "'%s'. Database already exists.",
2477 auto wallet_file = wallet_path /
"wallet.dat";
2479 fs::copy_file(backup_file, wallet_file, fs::copy_options::none);
2481 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.
const std::string & get_str() const
enum VType getType() const
int64_t get_int64() const
const std::vector< UniValue > & getValues() const
bool push_back(const UniValue &val)
const UniValue & get_array() const
bool exists(const std::string &key) const
bool pushKV(const std::string &key, const 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.
const std::string CLIENT_BUILD
const std::string CLIENT_NAME
bool DecodeHexTx(CMutableTransaction &tx, const std::string &strHexTx)
std::unique_ptr< Descriptor > Parse(const std::string &descriptor, FlatSigningProvider &out, std::string &error, bool require_checksum)
Parse a descriptor string.
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)
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)
void RPCTypeCheck(const UniValue ¶ms, const std::list< UniValueType > &typesExpected, bool fAllowNull)
Type-check arguments; throws JSONRPCError if wrong type given.
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.
@ OMITTED_NAMED_ARG
Optional arg that is a named argument and has a default value of null.
@ OMITTED
Optional argument with default value omitted because they are implicitly clear.
@ 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,...
bool TryCreateDirectories(const fs::path &p)
Ignores exceptions thrown by create_directories if the requested directory exists.
bool error(const char *fmt, const Args &...args)
#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.