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())) {
464 std::vector<uint256> vMatch;
465 std::vector<size_t> vIndex;
469 "Something wrong with merkleblock");
478 "Block not found in chain");
481 std::vector<uint256>::const_iterator it;
482 if ((it = std::find(vMatch.begin(), vMatch.end(), txid)) ==
485 "Transaction given doesn't exist in proof");
488 size_t txnIndex = vIndex[it - vMatch.begin()];
491 CWalletTx::Status::CONFIRMED, height,
495 if (pwallet->
IsMine(*tx_ref)) {
502 "No addresses in wallet correspond to included transaction");
510 "Deletes the specified transaction from the wallet. Meant for use "
511 "with pruned wallets and as a companion to importprunedfunds. This "
512 "will affect wallet balances.\n",
515 "The hex-encoded id of the transaction you are deleting"},
519 "\"a8d0c0184dde994a09ec054286f1ce581bebf4644"
520 "6a512166eae7628734ea0a5\"") +
521 "\nAs a JSON-RPC call\n" +
523 "\"a8d0c0184dde994a09ec054286f1ce581bebf4644"
524 "6a512166eae7628734ea0a5\"")},
527 std::shared_ptr<CWallet>
const wallet =
537 std::vector<TxId> txIds;
538 txIds.push_back(txid);
539 std::vector<TxId> txIdsOut;
544 "Could not properly delete the transaction.");
547 if (txIdsOut.empty()) {
549 "Transaction does not exist in wallet.");
560 "Adds a public key (in hex) that can be watched as if it were in "
561 "your wallet but cannot be used to spend. Requires a new wallet "
563 "Hint: use importmulti to import more than one public key.\n"
564 "\nNote: This call can take minutes to complete if rescan is true, "
565 "during that time, other rpc calls\n"
566 "may report that the imported pubkey exists but related transactions "
567 "are still missing, leading to temporarily incorrect/bogus balances "
568 "and unspent outputs until rescan completes.\n"
569 "Note: Use \"getwalletinfo\" to query the scanning progress.\n"
570 "Note: This command is only compatible with legacy wallets. Use "
571 "\"importdescriptors\" with \"combo(X)\" for descriptor wallets.\n",
574 "The hex-encoded public key"},
576 "An optional label"},
578 "Rescan the wallet for transactions"},
582 "\nImport a public key with rescan\n" +
584 "\nImport using a label without rescan\n" +
585 HelpExampleCli(
"importpubkey",
"\"mypubkey\" \"testing\" false") +
586 "\nAs a JSON-RPC call\n" +
587 HelpExampleRpc(
"importpubkey",
"\"mypubkey\", \"testing\", false")},
590 std::shared_ptr<CWallet>
const wallet =
599 std::string strLabel;
600 if (!request.params[1].isNull()) {
601 strLabel = request.params[1].get_str();
606 if (!request.params[2].isNull()) {
607 fRescan = request.params[2].get_bool();
615 "Rescan is disabled when blocks are pruned");
619 if (fRescan && !reserver.
reserve()) {
621 "Wallet is currently rescanning. Abort "
622 "existing rescan or wait.");
625 if (!
IsHex(request.params[0].get_str())) {
627 "Pubkey must be a hex string");
629 std::vector<uint8_t> data(
ParseHex(request.params[0].get_str()));
633 "Pubkey is not a valid public key");
639 std::set<CScript> script_pub_keys;
647 strLabel, script_pub_keys,
true ,
671 "Imports keys from a wallet dump file (see dumpwallet). Requires a "
672 "new wallet backup to include imported keys.\n"
673 "Note: Use \"getwalletinfo\" to query the scanning progress.\n"
674 "Note: This command is only compatible with legacy wallets.\n",
682 "\nImport the wallet\n" +
684 "\nImport using the json rpc call\n" +
688 std::shared_ptr<CWallet>
const wallet =
700 "Wallet is currently rescanning. Abort "
701 "existing rescan or wait.");
704 int64_t nTimeBegin = 0;
712 file.open(
fs::u8path(request.params[0].get_str()),
713 std::ios::in | std::ios::ate);
714 if (!file.is_open()) {
716 "Cannot open wallet dump file");
722 int64_t nFilesize = std::max<int64_t>(1, file.tellg());
723 file.seekg(0, file.beg);
733 strprintf(
"%s " +
_(
"Importing...").translated,
736 std::vector<std::tuple<CKey, int64_t, bool, std::string>> keys;
737 std::vector<std::pair<CScript, int64_t>> scripts;
738 while (file.good()) {
742 std::min<int>(50, 100 *
double(file.tellg()) /
746 std::getline(file, line);
747 if (line.empty() || line[0] ==
'#') {
751 std::vector<std::string> vstr =
SplitString(line,
' ');
752 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());
785 if (birth_time > 0) {
786 nTimeBegin = std::min(nTimeBegin, birth_time);
789 std::pair<CScript, int64_t>(script, birth_time));
801 "Importing wallets is disabled when "
802 "private keys are disabled");
804 double total = double(keys.size() + scripts.size());
806 for (
const auto &key_tuple : keys) {
809 std::max(50, std::min<int>(75, 100 * progress / total) +
812 const CKey &key = std::get<0>(key_tuple);
813 int64_t time = std::get<1>(key_tuple);
814 bool has_label = std::get<2>(key_tuple);
815 std::string label = std::get<3>(key_tuple);
827 "Error importing key for %s\n",
839 for (
const auto &script_pair : scripts) {
842 std::max(50, std::min<int>(75, 100 * progress / total) +
845 const CScript &script = script_pair.first;
846 int64_t time = script_pair.second;
862 pwallet->chain().showProgress(
"", 100,
false);
864 pwallet->MarkDirty();
868 "Error adding some keys/scripts to wallet");
879 "Reveals the private key corresponding to 'address'.\n"
880 "Then the importprivkey can be used with this output\n"
881 "Note: This command is only compatible with legacy wallets.\n",
884 "The bitcoin address for the private key"},
892 std::shared_ptr<CWallet>
const wallet =
906 std::string strAddress = request.params[0].get_str();
911 "Invalid Bitcoin address");
914 if (keyid.IsNull()) {
916 "Address does not refer to a key");
919 if (!spk_man.
GetKey(keyid, vchSecret)) {
921 "Private key for address " + strAddress +
932 "Dumps all wallet keys in a human-readable format to a server-side "
933 "file. This does not allow overwriting existing files.\n"
934 "Imported scripts are included in the dumpsfile, but corresponding "
935 "addresses may not be added automatically by importwallet.\n"
936 "Note that if your wallet contains keys which are not derived from "
937 "your HD seed (e.g. imported keys), these are not covered by\n"
938 "only backing up the seed itself, and must be backed up too (e.g. "
939 "ensure you back up the whole dumpfile).\n"
940 "Note: This command is only compatible with legacy wallets.\n",
943 "The filename with path (absolute path recommended)"},
950 "The filename with full absolute path"},
956 std::shared_ptr<CWallet>
const pwallet =
969 wallet.BlockUntilSyncedToCurrentChain();
987 " already exists. If you are "
988 "sure this is what you want, "
989 "move it out of the way first");
994 if (!file.is_open()) {
996 "Cannot open wallet dump file");
999 std::map<CKeyID, int64_t> mapKeyBirth;
1000 wallet.GetKeyBirthTimes(mapKeyBirth);
1002 int64_t block_time = 0;
1012 const std::map<CKeyID, int64_t> &mapKeyPool =
1014 std::set<CScriptID> scripts = spk_man.
GetCScripts();
1017 std::vector<std::pair<int64_t, CKeyID>> vKeyBirth;
1018 vKeyBirth.reserve(mapKeyBirth.size());
1019 for (
const auto &entry : mapKeyBirth) {
1020 vKeyBirth.push_back(std::make_pair(entry.second, entry.first));
1022 mapKeyBirth.clear();
1023 std::sort(vKeyBirth.begin(), vKeyBirth.end());
1028 file <<
strprintf(
"# * Created on %s\n",
1030 file <<
strprintf(
"# * Best block at time of backup was %i (%s),\n",
1031 wallet.GetLastBlockHeight(),
1032 wallet.GetLastBlockHash().ToString());
1041 if (spk_man.
GetKey(seed_id, seed)) {
1045 file <<
"# extended private masterkey: "
1049 for (std::vector<std::pair<int64_t, CKeyID>>::const_iterator it =
1051 it != vKeyBirth.end(); it++) {
1052 const CKeyID &keyid = it->second;
1054 std::string strAddr;
1055 std::string strLabel;
1057 if (spk_man.
GetKey(keyid, key)) {
1060 keyid, strAddr, strLabel)) {
1061 file <<
strprintf(
"label=%s", strLabel);
1062 }
else if (keyid == seed_id) {
1064 }
else if (mapKeyPool.count(keyid)) {
1065 file <<
"reserve=1";
1066 }
else if (spk_man.mapKeyMetadata[keyid].hdKeypath ==
"s") {
1067 file <<
"inactivehdseed=1";
1072 " # addr=%s%s\n", strAddr,
1073 (spk_man.mapKeyMetadata[keyid].has_key_origin
1081 for (
const CScriptID &scriptid : scripts) {
1083 std::string create_time =
"0";
1084 std::string address =
1087 auto it = spk_man.m_script_metadata.find(scriptid);
1088 if (it != spk_man.m_script_metadata.end()) {
1094 file <<
strprintf(
" # addr=%s\n", address);
1098 file <<
"# End of dump\n";
1112 "dump all the UTXO tracked by the wallet.\n",
1121 "The list of UTXO corresponding to this address.",
1128 "The transaction id"},
1132 "The output's amount"},
1141 std::shared_ptr<CWallet>
const pwallet =
1152 wallet.BlockUntilSyncedToCurrentChain();
1161 for (
const auto &o : p.second) {
1163 utxo.
pushKV(
"txid", o.tx->GetId().ToString());
1164 utxo.
pushKV(
"vout", o.i);
1165 utxo.
pushKV(
"depth", o.nDepth);
1166 utxo.
pushKV(
"value", o.tx->tx->vout[o.i].nValue);
1206 std::vector<std::vector<uint8_t>> solverdata;
1209 switch (script_type) {
1211 CPubKey pubkey(solverdata[0]);
1223 "Trying to nest P2SH inside another P2SH");
1231 return "missing redeemscript";
1234 return "redeemScript does not match the scriptPubKey";
1241 for (
size_t i = 1; i + 1 < solverdata.size(); ++i) {
1242 CPubKey pubkey(solverdata[i]);
1248 return "unspendable script";
1251 return "unrecognized script";
1257 std::map<CKeyID, CPubKey> &pubkey_map, std::map<CKeyID, CKey> &privkey_map,
1258 std::set<CScript> &script_pub_keys,
bool &have_solving_data,
1259 const UniValue &data, std::vector<CKeyID> &ordered_pubkeys) {
1264 const UniValue &scriptPubKey = data[
"scriptPubKey"];
1267 scriptPubKey.
exists(
"address"))) {
1269 "scriptPubKey must be string with script or JSON "
1270 "with address string");
1272 const std::string &output =
1273 isScript ? scriptPubKey.
get_str() : scriptPubKey[
"address"].
get_str();
1276 const std::string &strRedeemScript =
1277 data.
exists(
"redeemscript") ? data[
"redeemscript"].
get_str() :
"";
1282 const bool internal =
1284 const bool watchOnly =
1287 if (data.
exists(
"range")) {
1290 "Range should not be specified for a non-descriptor import");
1300 "Invalid address \"" + output +
"\"");
1304 if (!
IsHex(output)) {
1306 "Invalid scriptPubKey \"" + output +
"\"");
1308 std::vector<uint8_t> vData(
ParseHex(output));
1309 script = CScript(vData.begin(), vData.end());
1313 "Internal must be set to true for "
1314 "nonstandard scriptPubKey imports.");
1317 script_pub_keys.emplace(script);
1320 if (strRedeemScript.size()) {
1321 if (!
IsHex(strRedeemScript)) {
1323 "Invalid redeem script \"" + strRedeemScript +
1324 "\": must be hex string");
1326 auto parsed_redeemscript =
ParseHex(strRedeemScript);
1328 parsed_redeemscript.begin(), parsed_redeemscript.end());
1330 for (
size_t i = 0; i < pubKeys.
size(); ++i) {
1331 const auto &str = pubKeys[i].
get_str();
1334 "Pubkey \"" + str +
"\" must be a hex string");
1336 auto parsed_pubkey =
ParseHex(str);
1337 CPubKey pubkey(parsed_pubkey);
1341 "\" is not a valid public key");
1343 pubkey_map.emplace(pubkey.
GetID(), pubkey);
1344 ordered_pubkeys.push_back(pubkey.
GetID());
1346 for (
size_t i = 0; i < keys.
size(); ++i) {
1347 const auto &str = keys[i].
get_str();
1351 "Invalid private key encoding");
1355 if (pubkey_map.count(
id)) {
1356 pubkey_map.erase(
id);
1358 privkey_map.emplace(
id, key);
1363 import_data.
redeemscript || pubkey_map.size() || privkey_map.size();
1364 if (have_solving_data) {
1370 bool spendable = std::all_of(
1372 [&](
const std::pair<CKeyID, bool> &used_key) {
1373 return privkey_map.count(used_key.first) > 0;
1375 if (!watchOnly && !spendable) {
1376 warnings.
push_back(
"Some private keys are missing, outputs "
1377 "will be considered watchonly. If this is "
1378 "intentional, specify the watchonly flag.");
1380 if (watchOnly && spendable) {
1382 "All private keys are provided, outputs will be considered "
1383 "spendable. If this is intentional, do not specify the "
1388 if (error.empty()) {
1389 for (
const auto &require_key : import_data.
used_keys) {
1390 if (!require_key.second) {
1395 if (pubkey_map.count(require_key.first) == 0 &&
1396 privkey_map.count(require_key.first) == 0) {
1397 error =
"some required keys are missing";
1402 if (!error.empty()) {
1403 warnings.
push_back(
"Importing as non-solvable: " + error +
1404 ". If this is intentional, don't provide "
1405 "any keys, pubkeys or redeemscript.");
1408 privkey_map.clear();
1409 have_solving_data =
false;
1416 "Ignoring redeemscript as this is not a P2SH script.");
1418 for (
auto it = privkey_map.begin(); it != privkey_map.end();) {
1420 if (import_data.
used_keys.count(oldit->first) == 0) {
1421 warnings.
push_back(
"Ignoring irrelevant private key.");
1422 privkey_map.erase(oldit);
1425 for (
auto it = pubkey_map.begin(); it != pubkey_map.end();) {
1427 auto key_data_it = import_data.
used_keys.find(oldit->first);
1428 if (key_data_it == import_data.
used_keys.end() ||
1429 !key_data_it->second) {
1430 warnings.
push_back(
"Ignoring public key \"" +
1432 "\" as it doesn't appear inside P2PKH.");
1433 pubkey_map.erase(oldit);
1443 std::map<CKeyID, CPubKey> &pubkey_map,
1444 std::map<CKeyID, CKey> &privkey_map,
1445 std::set<CScript> &script_pub_keys,
1446 bool &have_solving_data,
1448 std::vector<CKeyID> &ordered_pubkeys) {
1451 const std::string &descriptor = data[
"desc"].
get_str();
1455 Parse(descriptor, keys, error,
true);
1460 have_solving_data = parsed_desc->IsSolvable();
1461 const bool watch_only =
1464 int64_t range_start = 0, range_end = 0;
1465 if (!parsed_desc->IsRange() && data.
exists(
"range")) {
1468 "Range should not be specified for an un-ranged descriptor");
1469 }
else if (parsed_desc->IsRange()) {
1470 if (!data.
exists(
"range")) {
1473 "Descriptor is ranged, please specify the range");
1483 for (
int i = range_start; i <= range_end; ++i) {
1485 std::vector<CScript> scripts_temp;
1486 parsed_desc->Expand(i, keys, scripts_temp, out_keys);
1487 std::copy(scripts_temp.begin(), scripts_temp.end(),
1488 std::inserter(script_pub_keys, script_pub_keys.end()));
1489 for (
const auto &key_pair : out_keys.
pubkeys) {
1490 ordered_pubkeys.push_back(key_pair.first);
1493 for (
const auto &x : out_keys.
scripts) {
1497 parsed_desc->ExpandPrivate(i, keys, out_keys);
1500 std::inserter(pubkey_map, pubkey_map.end()));
1501 std::copy(out_keys.
keys.begin(), out_keys.
keys.end(),
1502 std::inserter(privkey_map, privkey_map.end()));
1507 for (
size_t i = 0; i < priv_keys.
size(); ++i) {
1508 const auto &str = priv_keys[i].
get_str();
1512 "Invalid private key encoding");
1519 if (!pubkey_map.count(
id)) {
1520 warnings.
push_back(
"Ignoring irrelevant private key.");
1522 privkey_map.emplace(
id, key);
1533 std::all_of(pubkey_map.begin(), pubkey_map.end(),
1534 [&](
const std::pair<CKeyID, CPubKey> &used_key) {
1535 return privkey_map.count(used_key.first) > 0;
1539 [&](
const std::pair<
CKeyID, std::pair<CPubKey, KeyOriginInfo>>
1540 &entry) { return privkey_map.count(entry.first) > 0; });
1541 if (!watch_only && !spendable) {
1543 "Some private keys are missing, outputs will be considered "
1544 "watchonly. If this is intentional, specify the watchonly flag.");
1546 if (watch_only && spendable) {
1547 warnings.
push_back(
"All private keys are provided, outputs will be "
1548 "considered spendable. If this is intentional, do "
1549 "not specify the watchonly flag.");
1556 const int64_t timestamp)
1562 const bool internal =
1563 data.exists(
"internal") ? data[
"internal"].get_bool() :
false;
1565 if (internal && data.exists(
"label")) {
1567 "Internal addresses should not have a label");
1569 const std::string &label =
1570 data.exists(
"label") ? data[
"label"].get_str() :
"";
1571 const bool add_keypool =
1572 data.exists(
"keypool") ? data[
"keypool"].get_bool() :
false;
1578 "Keys can only be imported to the keypool when "
1579 "private keys are disabled");
1583 std::map<CKeyID, CPubKey> pubkey_map;
1584 std::map<CKeyID, CKey> privkey_map;
1585 std::set<CScript> script_pub_keys;
1586 std::vector<CKeyID> ordered_pubkeys;
1587 bool have_solving_data;
1589 if (data.exists(
"scriptPubKey") && data.exists(
"desc")) {
1592 "Both a descriptor and a scriptPubKey should not be provided.");
1593 }
else if (data.exists(
"scriptPubKey")) {
1595 pwallet, import_data, pubkey_map, privkey_map, script_pub_keys,
1596 have_solving_data, data, ordered_pubkeys);
1597 }
else if (data.exists(
"desc")) {
1599 import_data, pubkey_map, privkey_map, script_pub_keys,
1600 have_solving_data, data, ordered_pubkeys);
1604 "Either a descriptor or scriptPubKey must be provided.");
1610 !privkey_map.empty()) {
1612 "Cannot import private keys to a wallet with "
1613 "private keys disabled");
1617 for (
const CScript &script : script_pub_keys) {
1620 "The wallet already contains the private "
1621 "key for this address or script (\"" +
1627 pwallet->MarkDirty();
1628 if (!pwallet->ImportScripts(import_data.
import_scripts, timestamp)) {
1630 "Error adding script to wallet");
1632 if (!pwallet->ImportPrivKeys(privkey_map, timestamp)) {
1635 if (!pwallet->ImportPubKeys(ordered_pubkeys, pubkey_map,
1637 internal, timestamp)) {
1639 "Error adding address to wallet");
1641 if (!pwallet->ImportScriptPubKeys(label, script_pub_keys,
1642 have_solving_data, !internal,
1645 "Error adding address to wallet");
1651 result.
pushKV(
"error", e);
1658 if (warnings.
size()) {
1659 result.
pushKV(
"warnings", warnings);
1665 if (data.
exists(
"timestamp")) {
1666 const UniValue ×tamp = data[
"timestamp"];
1667 if (timestamp.
isNum()) {
1668 return timestamp.
getInt<int64_t>();
1669 }
else if (timestamp.
isStr() && timestamp.
get_str() ==
"now") {
1673 strprintf(
"Expected number or \"now\" timestamp "
1674 "value for key. got type %s",
1678 "Missing required timestamp field for key");
1682 const int64_t objectTimestamp,
1683 const int64_t blockTimestamp,
1684 const bool have_pruned,
1685 const bool has_assumed_valid_chain) {
1686 std::string error_msg{
1687 strprintf(
"Rescan failed for %s with creation timestamp %d. There "
1688 "was an error reading a block from time %d, which is after "
1689 "or within %d seconds of key creation, and could contain "
1690 "transactions pertaining to the %s. As a result, "
1691 "transactions and coins using this %s may not appear "
1697 "This error could be caused by pruning or data corruption "
1698 "(see bitcoind log for details) and could be dealt with by "
1699 "downloading and rescanning the relevant blocks (see -reindex "
1700 "option and rescanblockchain RPC).");
1701 }
else if (has_assumed_valid_chain) {
1703 "This error is likely caused by an in-progress assumeutxo "
1704 "background sync. Check logs or getchainstates RPC for assumeutxo "
1705 "background sync progress and try again later.");
1708 "This error could potentially be caused by data corruption. If "
1709 "the issue persists you may want to reindex (see -reindex "
1718 "Import addresses/scripts (with private or public keys, redeem "
1719 "script (P2SH)), optionally rescanning the blockchain from the "
1720 "earliest creation time of the imported scripts. Requires a new wallet "
1722 "If an address/script is imported without all of the private keys "
1723 "required to spend from that address, it will be watchonly. The "
1724 "'watchonly' option must be set to true in this case or a warning will "
1726 "Conversely, if all the private keys are provided and the "
1727 "address/script is spendable, the watchonly option must be set to "
1728 "false, or a warning will be returned.\n"
1729 "Note: Use \"getwalletinfo\" to query the scanning progress.\n"
1730 "Note: This command is only compatible with legacy wallets. Use "
1731 "\"importdescriptors\" for descriptor wallets.\n",
1736 "Data to be imported",
1745 "Descriptor to import. If using descriptor, do not "
1746 "also provide address/scriptPubKey, scripts, or "
1750 "Type of scriptPubKey (string for script, json for "
1751 "address). Should not be provided if using a "
1755 "\"address\":\"<address>\" }",
1758 "Creation time of the key expressed in " +
1761 "or the string \"now\" to substitute the current "
1762 "synced blockchain time. The timestamp of the "
1764 "key will determine how far back blockchain "
1765 "rescans need to begin for missing wallet "
1767 "\"now\" can be specified to bypass scanning, "
1768 "for keys which are known to never have been "
1770 "0 can be specified to scan the entire "
1771 "blockchain. Blocks up to 2 hours before the "
1773 "creation time of all keys being imported by the "
1774 "importmulti call will be scanned.",
1776 "integer / string"}}},
1779 "Allowed only if the scriptPubKey is a P2SH "
1780 "address/scriptPubKey"},
1784 "Array of strings giving pubkeys to import. They "
1785 "must occur in P2PKH scripts. They are not required "
1786 "when the private key is also provided (see the "
1787 "\"keys\" argument).",
1795 "Array of strings giving private keys to import. The "
1796 "corresponding public keys must occur in the output "
1804 "If a ranged descriptor is used, this specifies the "
1805 "end or the range (in the form [begin,end]) to "
1809 "Stating whether matching outputs should be treated "
1810 "as not incoming payments (also known as change)"},
1813 "Stating whether matching outputs should be "
1814 "considered watchonly."},
1816 "Label to assign to the address, only allowed with "
1819 "Stating whether imported public keys should be "
1820 "added to the keypool for when users request new "
1821 "addresses. Only allowed when wallet private keys "
1833 "Stating if should rescan the blockchain after all imports"},
1839 "Response is an array with the same size as the input that "
1840 "has the execution result",
1866 "'[{ \"scriptPubKey\": { \"address\": \"<my address>\" }, "
1867 "\"timestamp\":1455191478 }, "
1868 "{ \"scriptPubKey\": { \"address\": \"<my 2nd address>\" "
1870 "\"label\": \"example 2\", \"timestamp\": 1455191480 }]'") +
1873 "'[{ \"scriptPubKey\": { \"address\": \"<my address>\" }, "
1874 "\"timestamp\":1455191478 }]' '{ \"rescan\": false}'")
1879 std::shared_ptr<CWallet>
const wallet =
1888 const UniValue &requests = mainRequest.params[0];
1891 bool fRescan =
true;
1893 if (!mainRequest.params[1].isNull()) {
1894 const UniValue &options = mainRequest.params[1];
1896 if (options.
exists(
"rescan")) {
1897 fRescan = options[
"rescan"].
get_bool();
1902 if (fRescan && !reserver.
reserve()) {
1904 "Wallet is currently rescanning. Abort "
1905 "existing rescan or wait.");
1909 bool fRunScan =
false;
1910 int64_t nLowestTimestamp = 0;
1919 FoundBlock().time(nLowestTimestamp).mtpTime(now)));
1924 const int64_t minimumTimestamp = 1;
1927 const int64_t timestamp = std::max(
1938 if (result[
"success"].get_bool()) {
1943 if (timestamp < nLowestTimestamp) {
1944 nLowestTimestamp = timestamp;
1948 if (fRescan && fRunScan && requests.
size()) {
1950 nLowestTimestamp, reserver,
true );
1958 "Rescan aborted by user.");
1960 if (scannedTime > nLowestTimestamp) {
1961 std::vector<UniValue> results =
response.getValues();
1971 results.at(i).exists(
"error")) {
1986 response.push_back(std::move(result));
2000 const int64_t timestamp)
2006 if (!data.exists(
"desc")) {
2010 const std::string &descriptor = data[
"desc"].get_str();
2012 data.exists(
"active") ? data[
"active"].get_bool() :
false;
2013 const bool internal =
2014 data.exists(
"internal") ? data[
"internal"].get_bool() :
false;
2015 const std::string &label =
2016 data.exists(
"label") ? data[
"label"].get_str() :
"";
2022 Parse(descriptor, keys, error,
true);
2028 int64_t range_start = 0, range_end = 1, next_index = 0;
2029 if (!parsed_desc->IsRange() && data.exists(
"range")) {
2032 "Range should not be specified for an un-ranged descriptor");
2033 }
else if (parsed_desc->IsRange()) {
2034 if (data.exists(
"range")) {
2036 range_start = range.first;
2039 range_end = range.second + 1;
2042 "Range not given, using default keypool range");
2046 next_index = range_start;
2048 if (data.exists(
"next_index")) {
2049 next_index = data[
"next_index"].getInt<int64_t>();
2051 if (next_index < range_start || next_index >= range_end) {
2053 "next_index is out of range");
2059 if (active && !parsed_desc->IsRange()) {
2061 "Active descriptors must be ranged");
2065 if (data.exists(
"range") && data.exists(
"label")) {
2067 "Ranged descriptors should not have a label");
2071 if (internal && data.exists(
"label")) {
2073 "Internal addresses should not have a label");
2077 if (active && !parsed_desc->IsSingleType()) {
2079 "Combo descriptors cannot be set to active");
2084 !keys.
keys.empty()) {
2086 "Cannot import private keys to a wallet with "
2087 "private keys disabled");
2093 std::vector<CScript> scripts;
2094 if (!parsed_desc->Expand(0, keys, scripts, expand_keys)) {
2097 "Cannot expand descriptor. Probably because of hardened "
2098 "derivations without private keys provided");
2100 parsed_desc->ExpandPrivate(0, keys, expand_keys);
2103 bool have_all_privkeys = !expand_keys.
keys.empty();
2104 for (
const auto &entry : expand_keys.
origins) {
2105 const CKeyID &key_id = entry.first;
2107 if (!expand_keys.
GetKey(key_id, key)) {
2108 have_all_privkeys =
false;
2115 if (keys.
keys.empty()) {
2118 "Cannot import descriptor without private keys to a wallet "
2119 "with private keys enabled");
2121 if (!have_all_privkeys) {
2123 "Not all private keys provided. Some wallet functionality "
2124 "may return unexpected errors");
2129 range_end, next_index);
2132 auto existing_spk_manager =
2133 pwallet->GetDescriptorScriptPubKeyMan(w_desc);
2134 if (existing_spk_manager &&
2135 !existing_spk_manager->CanUpdateToWalletDescriptor(w_desc, error)) {
2141 pwallet->AddWalletDescriptor(w_desc, keys, label, internal);
2142 if (spk_manager ==
nullptr) {
2145 strprintf(
"Could not add descriptor '%s'", descriptor));
2152 "Unknown output type, cannot set descriptor to active.");
2154 pwallet->AddActiveScriptPubKeyMan(
2155 spk_manager->GetID(), *w_desc.
descriptor->GetOutputType(),
2160 pwallet->DeactivateScriptPubKeyMan(
2161 spk_manager->GetID(), *w_desc.
descriptor->GetOutputType(),
2169 result.
pushKV(
"error", e);
2171 if (warnings.
size()) {
2172 result.
pushKV(
"warnings", warnings);
2179 "importdescriptors",
2180 "Import descriptors. This will trigger a rescan of the blockchain "
2181 "based on the earliest timestamp of all descriptors being imported. "
2182 "Requires a new wallet backup.\n"
2183 "\nNote: This call can take over an hour to complete if using an early "
2184 "timestamp; during that time, other rpc calls\n"
2185 "may report that the imported keys, addresses or scripts exist but "
2186 "related transactions are still missing.\n",
2191 "Data to be imported",
2200 "Descriptor to import."},
2202 "Set this descriptor to be the active descriptor for "
2203 "the corresponding output type/externality"},
2206 "If a ranged descriptor is used, this specifies the "
2207 "end or the range (in the form [begin,end]) to "
2211 "If a ranged descriptor is set to active, this "
2212 "specifies the next index to generate addresses "
2215 "Time from which to start rescanning the blockchain "
2216 "for this descriptor, in " +
2219 "Use the string \"now\" to substitute the "
2220 "current synced blockchain time.\n"
2221 "\"now\" can be specified to bypass scanning, "
2222 "for outputs which are known to never have been "
2224 "0 can be specified to scan the entire "
2225 "blockchain. Blocks up to 2 hours before the "
2226 "earliest timestamp\n"
2227 "of all descriptors being imported will be "
2230 "integer / string"}}},
2233 "Whether matching outputs should be treated as not "
2234 "incoming payments (e.g. change)"},
2236 "Label to assign to the address, only allowed with "
2245 "Response is an array with the same size as the input that "
2246 "has the execution result",
2271 "'[{ \"desc\": \"<my descriptor>\", "
2272 "\"timestamp\":1455191478, \"internal\": true }, "
2273 "{ \"desc\": \"<my desccriptor 2>\", \"label\": "
2274 "\"example 2\", \"timestamp\": 1455191480 }]'") +
2276 "importdescriptors",
2277 "'[{ \"desc\": \"<my descriptor>\", \"timestamp\":1455191478, "
2278 "\"active\": true, \"range\": [0,100], \"label\": \"<my "
2279 "cashaddr wallet>\" }]'")},
2282 std::shared_ptr<CWallet>
const wallet =
2292 "importdescriptors is not available for "
2293 "non-descriptor wallets");
2299 "Wallet is currently rescanning. Abort "
2300 "existing rescan or wait.");
2303 const UniValue &requests = main_request.params[0];
2304 const int64_t minimum_timestamp = 1;
2306 int64_t lowest_timestamp = 0;
2307 bool rescan =
false;
2315 FoundBlock().time(lowest_timestamp).mtpTime(now)));
2320 const int64_t timestamp = std::max(
2326 if (lowest_timestamp > timestamp) {
2327 lowest_timestamp = timestamp;
2332 if (!rescan && result[
"success"].get_bool()) {
2342 lowest_timestamp, reserver,
true );
2350 "Rescan aborted by user.");
2353 if (scanned_time > lowest_timestamp) {
2354 std::vector<UniValue> results =
response.getValues();
2359 for (
unsigned int i = 0; i < requests.
size(); ++i) {
2368 results.at(i).exists(
"error")) {
2384 response.push_back(std::move(result));
2398 "Safely copies current wallet file to destination, which can be a "
2399 "directory or a path with filename.\n",
2402 "The destination directory or file"},
2409 std::shared_ptr<CWallet>
const wallet =
2419 pwallet->BlockUntilSyncedToCurrentChain();
2423 std::string strDest = request.params[0].get_str();
2426 "Error: Wallet backup failed!");
2437 "\nRestore and loads a wallet from backup.\n",
2440 "The name that will be applied to the restored wallet"},
2442 "The backup file that will be used to restore the wallet."},
2444 "Save wallet name to persistent settings and load on startup. "
2445 "True to add wallet to startup list, false to remove, null to "
2446 "leave unchanged."},
2453 "The wallet name if restored successfully."},
2455 "Warning message if wallet was not loaded cleanly."},
2459 "\"testwallet\" \"home\\backups\\backup-file.bak\"") +
2462 "\"testwallet\" \"home\\backups\\backup-file.bak\"") +
2465 {{
"wallet_name",
"testwallet"},
2466 {
"backup_file",
"home\\backups\\backup-file.bak\""},
2467 {
"load_on_startup",
true}}) +
2470 {{
"wallet_name",
"testwallet"},
2471 {
"backup_file",
"home\\backups\\backup-file.bak\""},
2472 {
"load_on_startup",
true}})},
2480 std::string wallet_name = request.params[0].get_str();
2482 std::optional<bool> load_on_start =
2483 request.params[2].isNull()
2485 : std::optional<bool>(request.params[2].get_bool());
2489 std::vector<bilingual_str> warnings;
2491 const std::shared_ptr<CWallet>
wallet =
2492 RestoreWallet(context, backup_file, wallet_name, load_on_start,
2493 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.
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.
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
std::string GetDisplayName() const override
Returns a bracketed wallet name for displaying in logs, will return [default wallet] if the wallet ha...
const CAddressBookData * FindAddressBookEntry(const CTxDestination &, bool allow_change=false) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Double ended buffer combining vector and stream-like interfaces.
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)
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.
std::optional< int64_t > ParseISO8601DateTime(std::string_view 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.
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.