20 #include "validation.h"
25 #include <boost/algorithm/string.hpp>
26 #include <boost/date_time/posix_time/posix_time.hpp>
31 int64_t
static DecodeDumpTime(
const std::string& str)
33 static const boost::posix_time::ptime epoch = boost::posix_time::from_time_t(0);
34 static const std::locale loc(std::locale::classic(),
35 new boost::posix_time::time_input_facet(
"%Y-%m-%dT%H:%M:%SZ"));
36 std::istringstream iss(str);
38 boost::posix_time::ptime ptime(boost::date_time::not_a_date_time);
40 if (ptime.is_not_a_date_time())
42 return (ptime - epoch).total_seconds();
45 std::string
static EncodeDumpString(
const std::string& str)
47 std::stringstream ret;
48 for (
unsigned char c : str) {
49 if (c <= 32 || c >= 128 || c ==
'%') {
50 ret << '%' << HexStr(Span<const unsigned char>(&c, 1));
60 std::stringstream ret;
61 for (
unsigned int pos = 0; pos < str.length(); pos++) {
62 unsigned char c = str[pos];
63 if (c ==
'%' && pos + 2 < str.length()) {
64 c = (((str[pos + 1] >> 6) * 9 + ((str[pos + 1] -
'0') & 15)) << 4) |
65 ((str[pos + 2] >> 6) * 9 + ((str[pos + 2] -
'0') & 15));
75 return keyOrigin.
path.size() > 3 && keyOrigin.
path[3] == (2 | BIP32_HARDENED_KEY_LIMIT);
86 throw std::runtime_error(
87 "importprivkey \"privkey\" ( \"label\" rescan is_staking_address )\n"
88 "\nAdds a private key (as returned by dumpprivkey) to your wallet. Requires a new wallet backup.\n" +
91 "1. \"privkey\" (string, required) The private key (see dumpprivkey)\n"
92 "2. \"label\" (string, optional, default=\"\") An optional label\n"
93 "3. rescan (boolean, optional, default=true) Rescan the wallet for transactions\n"
94 "4. is_staking_address (boolean, optional, default=false) Whether this key refers to a (cold) staking address\n"
95 "\nNote: This call can take minutes to complete if rescan is true, during that time, other rpc calls\n"
96 "may report that the imported key exists but related transactions are still missing, leading to temporarily incorrect/bogus balances and unspent outputs until rescan completes.\n"
98 "\nDump a private key\n" +
100 "\nImport the private key with rescan\n" +
102 "\nImport using a label and without rescan\n" +
104 "\nAs a JSON-RPC call\n" +
105 HelpExampleRpc(
"importprivkey",
"\"mykey\", \"testing\", false"));
112 if (fRescan && !reserver.
reserve()) {
135 if (pwallet->
HaveKey(vchAddress))
160 throw std::runtime_error(
162 "\nStops current wallet rescan triggered e.g. by an importprivkey call.\n"
164 "\nImport a private key\n"
166 "\nAbort the running wallet rescan\n"
168 "\nAs a JSON-RPC call\n"
177 static void ImportAddress(
CWallet*
const pwallet,
const CTxDestination& dest,
const std::string& strLabel,
const std::string& strPurpose);
179 static void ImportScript(
CWallet*
const pwallet,
const CScript& script,
const std::string& strLabel,
bool isRedeemScript)
189 if (isRedeemScript) {
192 ImportAddress(pwallet,
CScriptID(script), strLabel,
"receive");
196 static void ImportAddress(
CWallet*
const pwallet,
const CTxDestination& dest,
const std::string& strLabel,
const std::string& strPurpose)
199 ImportScript(pwallet, script, strLabel,
false);
214 throw std::runtime_error(
215 "importaddress \"script\" ( \"label\" rescan )\n"
216 "\nAdds a script (in hex), or address, that can be watched as if it were in your wallet but cannot be used to spend. Requires a new wallet backup.\n"
218 "1. \"script\" (string, required) hex-encoded script (or address)\n"
219 "2. \"label\" (string, optional, default=\"\") An optional label\n"
220 "3. rescan (boolean, optional, default=true) Rescan the wallet for transactions\n"
221 "4. p2sh (boolean, optional, default=false) Add the P2SH version of the script as well\n"
222 "\nNote: This call can take minutes to complete if rescan is true, during that time, other rpc calls\n"
223 "may report that the imported address exists but related transactions are still missing, leading to temporarily incorrect/bogus balances and unspent outputs until rescan completes.\n"
225 "\nImport a script with rescan\n" +
227 "\nImport using a label without rescan\n" +
228 HelpExampleCli(
"importaddress",
"\"myscript\" \"testing\" false") +
229 "\nAs a JSON-RPC call\n" +
230 HelpExampleRpc(
"importaddress",
"\"myscript\", \"testing\", false"));
237 if (fRescan && !reserver.
reserve()) {
247 bool isStaking =
false;
248 bool isExchange =
false;
254 ImportAddress(pwallet, dest, strLabel, isStaking ?
260 ImportScript(pwallet,
CScript(data.begin(), data.end()), strLabel, fP2SH);
281 throw std::runtime_error(
282 "importpubkey \"pubkey\" ( \"label\" rescan )\n"
283 "\nAdds a public key (in hex) that can be watched as if it were in your wallet but cannot be used to spend. Requires a new wallet backup.\n"
285 "1. \"pubkey\" (string, required) The hex-encoded public key\n"
286 "2. \"label\" (string, optional, default=\"\") An optional label\n"
287 "3. rescan (boolean, optional, default=true) Rescan the wallet for transactions\n"
288 "\nNote: This call can take minutes to complete if rescan is true, during that time, other rpc calls\n"
289 "may report that the imported pubkey exists but related transactions are still missing, leading to temporarily incorrect/bogus balances and unspent outputs until rescan completes.\n"
291 "\nImport a public key with rescan\n"
293 "\nImport using a label without rescan\n"
294 +
HelpExampleCli(
"importpubkey",
"\"mypubkey\" \"testing\" false") +
295 "\nAs a JSON-RPC call\n"
296 +
HelpExampleRpc(
"importpubkey",
"\"mypubkey\", \"testing\", false")
304 if (fRescan && !reserver.
reserve()) {
311 CPubKey pubKey(data.begin(), data.end());
318 ImportAddress(pwallet, pubKey.
GetID(), strLabel,
"receive");
338 throw std::runtime_error(
339 "importwallet \"filename\"\n"
340 "\nImports keys from a wallet dump file (see dumpwallet). Requires a new wallet backup.\n" +
343 "1. \"filename\" (string, required) The wallet file\n"
346 "\nDump the wallet\n" +
348 "\nImport the wallet\n" +
350 "\nImport using the json rpc call\n" +
354 file.open(request.
params[0].
get_str(), std::ios::in | std::ios::ate);
355 if (!file.is_open()) {
364 int64_t nTimeBegin = 0;
371 int64_t nFilesize = std::max((int64_t)1, (int64_t)file.tellg());
372 file.seekg(0, file.beg);
375 while (file.good()) {
376 pwallet->
ShowProgress(
"", std::max(1, std::min(99, (
int)(((
double)file.tellg() / (
double)nFilesize) * 100))));
378 std::getline(file, line);
379 if (line.empty() || line[0] ==
'#')
382 std::vector<std::string> vstr;
383 boost::split(vstr, line, boost::is_any_of(
" "));
391 int64_t nTime = DecodeDumpTime(vstr[1]);
395 Params().GetConsensus(), saplingSpendingKey, nTime);
413 LogPrintf(
"Skipping import of %s (key already present)\n",
EncodeDestination(keyid));
416 int64_t nTime = DecodeDumpTime(vstr[1]);
417 std::string strLabel;
419 for (
unsigned int nStr = 2; nStr < vstr.size(); nStr++) {
420 const std::string& type = vstr[nStr];
421 if (boost::algorithm::starts_with(type,
"#"))
423 if (type ==
"change=1")
425 else if (type ==
"reserve=1")
427 else if (type ==
"hdseed")
429 if (boost::algorithm::starts_with(type,
"label=")) {
442 nTimeBegin = std::min(nTimeBegin, nTime);
465 throw std::runtime_error(
466 "dumpprivkey \"address\"\n"
467 "\nReveals the private key corresponding to 'address'.\n"
468 "Then the importprivkey can be used with this output\n" +
472 "1. \"address\" (string, required) The pivx address for the private key\n"
475 "\"key\" (string) The private key\n"
488 const CKeyID* keyID = boost::get<CKeyID>(&dest);
492 if (!pwallet->
GetKey(*keyID, vchSecret))
505 throw std::runtime_error(
506 "dumpwallet \"filename\"\n"
507 "\nDumps all wallet keys in a human-readable format to a server-side file. This does not allow overwriting existing files.\n"
508 "Imported scripts are not currently included in wallet dumps, these must be backed up separately.\n"
509 "Note that if your wallet contains keys which are not derived from your HD seed (e.g. imported keys), these are not covered by\n"
510 "only backing up the seed itself, and must be backed up too (e.g. ensure you back up the whole dumpfile).\n" +
513 "1. \"filename\" (string, required) The filename\n"
517 " \"filename\": \"xxxx\", (string) The full path to the wallet dump file.\n"
518 " \"warning\": \"xxxx\" (string) A warning message about the exact contents of this file.\n"
524 if (request.
params[0].
get_str().find(
"bug") != std::string::npos ||
525 request.
params[0].
get_str().find(
"log") != std::string::npos) {
540 filepath = fs::absolute(filepath);
547 if (fs::exists(filepath)) {
556 std::map<CKeyID, int64_t> mapKeyBirth;
562 std::vector<std::pair<int64_t, CKeyID> > vKeyBirth;
563 for (
const auto& entry : mapKeyBirth) {
564 vKeyBirth.emplace_back(entry.second, entry.first);
567 std::sort(vKeyBirth.begin(), vKeyBirth.end());
574 file <<
strprintf(
"# * Best block at time of backup was %i (%s),\n", tip->
nHeight,
578 file <<
"# Missing tip information\n";
587 if (pwallet->
GetKey(seed_id, seed)) {
595 for (std::vector<std::pair<int64_t, CKeyID> >::const_iterator it = vKeyBirth.begin(); it != vKeyBirth.end(); it++) {
596 const CKeyID& keyid = it->second;
599 if (pwallet->
GetKey(keyid, key)) {
608 }
else if (keyid == seed_id) {
610 }
else if (mapKeyPool.count(keyid)) {
620 file <<
"# Sapling keys\n";
622 std::set<libzcash::SaplingPaymentAddress> saplingAddresses;
625 for (
const auto& addr : saplingAddresses) {
632 file <<
strprintf(
"%s %s # shielded_addr=%s%s\n",
642 file <<
"# End of dump\n";
646 reply.
pushKV(
"filename", filepath.string());
647 reply.
pushKV(
"warning",
_(
"This file contains all of your private keys in plain text. DO NOT send this file to anyone!"));
655 bool success =
false;
658 const UniValue& scriptPubKey = data[
"scriptPubKey"];
666 const std::string& strRedeemScript = data.
exists(
"redeemscript") ? data[
"redeemscript"].
get_str() :
"";
669 const bool internal = data.
exists(
"internal") ? data[
"internal"].
get_bool() :
false;
670 const bool watchOnly = data.
exists(
"watchonly") ? data[
"watchonly"].
get_bool() :
false;
671 const std::string& label = data.
exists(
"label") && !
internal ? data[
"label"].
get_str() :
"";
674 bool isP2SH = strRedeemScript.length() > 0;
675 const std::string& output = isScript ? scriptPubKey.
get_str() : scriptPubKey[
"address"].
get_str();
688 if (!
IsHex(output)) {
691 std::vector<unsigned char> vData(
ParseHex(output));
692 script =
CScript(vData.begin(), vData.end());
696 if (watchOnly && keys.
size()) {
701 if (
internal && data.
exists(
"label")) {
706 if (!
internal && isScript) {
711 if (!isP2SH && (keys.
size() > 1 || pubKeys.
size() > 1)) {
716 if (isP2SH && !
IsHex(strRedeemScript)) {
725 std::vector<unsigned char> vData(
ParseHex(strRedeemScript));
763 for (
size_t i = 0; i < keys.
size(); i++) {
764 const std::string& privkey = keys[i].
get_str();
778 if (pwallet->
HaveKey(vchAddress)) {
788 if (timestamp < pwallet->nTimeFirstKey) {
797 if (pubKeys.
size() && keys.
size() == 0) {
798 const std::string& strPubKey = pubKeys[0].
get_str();
800 if (!
IsHex(strPubKey)) {
804 std::vector<unsigned char> vData(
ParseHex(strPubKey));
805 CPubKey pubKey(vData.begin(), vData.end());
814 if (!isScript && !(pubkey_dest == dest)) {
861 const std::string& strPrivkey = keys[0].
get_str();
874 if (!isScript && !(pubkey_dest == dest)) {
890 if (pwallet->
HaveKey(vchAddress)) {
900 if (timestamp < pwallet->nTimeFirstKey) {
908 if (pubKeys.
size() == 0 && keys.
size() == 0) {
936 result.
pushKV(
"error", e);
946 static int64_t GetImportTimestamp(
const UniValue& data, int64_t now)
948 if (data.
exists(
"timestamp")) {
949 const UniValue& timestamp = data[
"timestamp"];
950 if (timestamp.
isNum()) {
952 }
else if (timestamp.
isStr() && timestamp.
get_str() ==
"now") {
968 throw std::runtime_error(
969 "importmulti \"requests\" ( \"options\" )\n"
970 "\nImport addresses/scripts (with private or public keys, redeem script (P2SH)), rescanning all addresses in one-shot-only (rescan can be disabled via options). Requires a new wallet backup.\n" +
974 "1. requests (array, required) Data to be imported\n"
975 " [ (array of json objects)\n"
977 " \"scriptPubKey\": \"script\" | { \"address\":\"address\" }, (string / JSON, required) Type of scriptPubKey (string for script, json for address)\n"
978 " \"timestamp\": timestamp | \"now\" (integer / string, required) Creation time of the key in seconds since epoch (Jan 1 1970 GMT),\n"
979 " or the string \"now\" to substitute the current synced blockchain time. The timestamp of the oldest\n"
980 " key will determine how far back blockchain rescans need to begin for missing wallet transactions.\n"
981 " \"now\" can be specified to bypass scanning, for keys which are known to never have been used, and\n"
982 " 0 can be specified to scan the entire blockchain. Blocks up to 2 hours before the earliest key\n"
983 " creation time of all keys being imported by the importmulti call will be scanned.\n"
984 " \"redeemscript\": \"script\", (string, optional) Allowed only if the scriptPubKey is a P2SH address or a P2SH scriptPubKey\n"
985 " \"pubkeys\": [\"pubKey\", ... ], (array, optional) Array of strings giving pubkeys that must occur in the output or redeemscript\n"
986 " \"keys\": [\"key\", ... ], (array, optional) Array of strings giving private keys whose corresponding public keys must occur in the output or redeemscript\n"
987 " \"internal\": true|false, (boolean, optional, default: false) Stating whether matching outputs should be be treated as not incoming payments\n"
988 " \"watchonly\": true|false, (boolean, optional, default: false) Stating whether matching outputs should be considered watched even when they're not spendable, only allowed if keys are empty\n"
989 " \"label\": label, (string, optional, default: '') Label to assign to the address, only allowed with internal=false\n"
993 "2. options (JSON, optional)\n"
995 " \"rescan\": true|false, (boolean, optional, default: true) Stating if should rescan the blockchain after all imports\n"
999 "[ (Array) An array with the same size as the input that has the execution result\n"
1001 " \"success\": true|false, (boolean) True if import succeeded, otherwise false\n"
1002 " \"error\": { (JSON Object) Object containing error information. Only present when import fails\n"
1003 " \"code\": n, (numeric) The error code\n"
1004 " \"message\": xxxx (string) The error message\n"
1009 "\nNote: This call can take minutes to complete if rescan is true, during that time, other rpc calls\n"
1010 "may report that the imported keys, addresses or scripts exists but related transactions are still missing.\n"
1012 HelpExampleCli(
"importmulti",
"'[{ \"scriptPubKey\": { \"address\": \"<my address>\" }, \"timestamp\":1455191478 }, "
1013 "{ \"scriptPubKey\": { \"address\": \"<my 2nd address>\" }, \"label\": \"example 2\", \"timestamp\": 1455191480 }]'") +
1014 HelpExampleCli(
"importmulti",
"'[{ \"scriptPubKey\": { \"address\": \"<my address>\" }, \"timestamp\":1455191478 }]' '{ \"rescan\": false}'"));
1020 bool fRescan =
true;
1025 if (options.
exists(
"rescan")) {
1026 fRescan = options[
"rescan"].
get_bool();
1031 if (fRescan && !reserver.
reserve()) {
1036 bool fRunScan =
false;
1037 int64_t nLowestTimestamp = 0;
1047 GetImportTimestamp(data, now);
1050 const int64_t minimumTimestamp = 1;
1059 const int64_t timestamp = std::max(GetImportTimestamp(data, now), minimumTimestamp);
1060 const UniValue result = processImport(pwallet, data, timestamp);
1068 if (result[
"success"].get_bool()) {
1073 if (timestamp < nLowestTimestamp) {
1074 nLowestTimestamp = timestamp;
1078 if (fRescan && fRunScan && requests.
size()) {
1079 int64_t scannedTime = pwallet->
RescanFromTime(nLowestTimestamp, reserver,
true );
1082 if (scannedTime > nLowestTimestamp) {
1083 std::vector<UniValue> results = response.
getValues();
1092 if (scannedTime <= GetImportTimestamp(request, now) || results.at(i).exists(
"error")) {
1098 strprintf(
"Rescan failed for key with creation timestamp %d. There was an error reading a "
1099 "block from time %d, which is after or within %d seconds of key creation, and "
1100 "could contain transactions pertaining to the key. As a result, transactions "
1101 "and coins using this key may not appear in the wallet. This error could be "
1102 "caused by pruning or data corruption (see pivxd log for details) and could "
1103 "be dealt with by downloading and rescanning the relevant blocks (see -reindex "
1104 "and -rescan options).",
1105 GetImportTimestamp(request, now), scannedTime - TIMESTAMP_WINDOW - 1, TIMESTAMP_WINDOW)));
1124 throw std::runtime_error(
1125 "bip38encrypt \"address\" \"passphrase\"\n"
1126 "\nEncrypts a private key corresponding to 'address'.\n" +
1130 "1. \"address\" (string, required) The pivx address for the private key (you must hold the key already)\n"
1131 "2. \"passphrase\" (string, required) The passphrase you want the private key to be encrypted with - Valid special chars: !#$%&'()*+,-./:;<=>?`{|}~ \n"
1134 "\"key\" (string) The encrypted private key\n"
1137 HelpExampleCli(
"bip38encrypt",
"\"DMJRSsuU9zfyrvxVaAEFQqK4MxZg6vgeS6\" \"mypasphrase\"") +
1138 HelpExampleRpc(
"bip38encrypt",
"\"DMJRSsuU9zfyrvxVaAEFQqK4MxZg6vgeS6\" \"mypasphrase\""));
1150 const CKeyID* keyID = boost::get<CKeyID>(&address);
1154 if (!pwallet->
GetKey(*keyID, vchSecret))
1161 result.
pushKV(
"Address", strAddress);
1162 result.
pushKV(
"Encrypted Key", encryptedOut);
1175 throw std::runtime_error(
1176 "bip38decrypt \"encrypted_key\" \"passphrase\"\n"
1177 "\nDecrypts and then imports password protected private key.\n" +
1181 "1. \"encrypted_key\" (string, required) The encrypted private key\n"
1182 "2. \"passphrase\" (string, required) The passphrase you want the private key to be encrypted with\n"
1185 "\"key\" (string) The decrypted private key\n"
1188 HelpExampleCli(
"bip38decrypt",
"\"encryptedkey\" \"mypassphrase\"") +
1189 HelpExampleRpc(
"bip38decrypt",
"\"encryptedkey\" \"mypassphrase\""));
1198 if (!
BIP38_Decrypt(strPassphrase, strKey, privKey, fCompressed))
1205 key.
Set(privKey.
begin(), privKey.
end(), fCompressed);
1226 if (pwallet->
HaveKey(vchAddress))
1251 throw std::runtime_error(
1252 "importsaplingkey \"key\" ( rescan height )\n"
1253 "\nAdds a key (as returned by exportsaplingkey) to your wallet.\n"
1257 "1. \"key\" (string, required) The zkey (see exportsaplingkey)\n"
1258 "2. rescan (string, optional, default=\"whenkeyisnew\") Rescan the wallet for transactions - can be \"yes\", \"no\" or \"whenkeyisnew\"\n"
1259 "3. height (numeric, optional, default=0) Block height to start rescan from\n"
1260 "\nNote: This call can take minutes to complete if rescan is true.\n"
1264 " \"address\" : \"address|DefaultAddress\", (string) The address corresponding to the spending key (the default address).\n"
1270 "\nImport the key with rescan\n"
1272 "\nImport the key with partial rescan\n"
1273 +
HelpExampleCli(
"importsaplingkey",
"\"mykey\" whenkeyisnew 30000") +
1274 "\nRe-import the key with longer partial rescan\n"
1276 "\nAs a JSON-RPC call\n"
1281 bool fRescan =
true;
1282 bool fIgnoreExistingKey =
true;
1285 if (rescan.compare(
"whenkeyisnew") != 0) {
1286 fIgnoreExistingKey =
false;
1287 if (rescan.compare(
"yes") == 0) {
1289 }
else if (rescan.compare(
"no") == 0) {
1298 if (fRescan && !reserver.
reserve()) {
1309 int nRescanHeight = 0;
1353 throw std::runtime_error(
1354 "importsaplingviewingkey \"vkey\" ( rescan height )\n"
1355 "\nAdds a viewing key (as returned by exportsaplingviewingkey) to your wallet.\n"
1359 "1. \"vkey\" (string, required) The viewing key (see exportsaplingviewingkey)\n"
1360 "2. rescan (string, optional, default=\"whenkeyisnew\") Rescan the wallet for transactions - can be \"yes\", \"no\" or \"whenkeyisnew\"\n"
1361 "3. height (numeric, optional, default=0) Block height to start rescan from\n"
1362 "\nNote: This call can take minutes to complete if rescan is true.\n"
1366 " \"address\" : \"address|DefaultAddress\", (string) The address corresponding to the viewing key (for Sapling, this is the default address).\n"
1370 "\nImport a viewing key\n"
1372 "\nImport the viewing key without rescan\n"
1374 "\nImport the viewing key with partial rescan\n"
1375 +
HelpExampleCli(
"importsaplingviewingkey",
"\"vkey\" whenkeyisnew 30000") +
1376 "\nRe-import the viewing key with longer partial rescan\n"
1377 +
HelpExampleCli(
"importsaplingviewingkey",
"\"vkey\" yes 20000") +
1378 "\nAs a JSON-RPC call\n"
1383 bool fRescan =
true;
1384 bool fIgnoreExistingKey =
true;
1387 if (rescan.compare(
"whenkeyisnew") != 0) {
1388 fIgnoreExistingKey =
false;
1389 if (rescan.compare(
"no") == 0) {
1391 }
else if (rescan.compare(
"yes") != 0) {
1394 "rescan must be \"yes\", \"no\" or \"whenkeyisnew\"");
1400 if (fRescan && !reserver.
reserve()) {
1411 int nRescanHeight = 0;
1431 "The wallet already contains the private key for this viewing key");
1459 throw std::runtime_error(
1460 "exportsaplingviewingkey \"shield_addr\"\n"
1461 "\nReveals the viewing key corresponding to 'shield_addr'.\n"
1462 "Then the importsaplingviewingkey can be used with this output\n"
1466 "1. \"shield_addr\" (string, required) The shield addr for the viewing key\n"
1469 "\"vkey\" (string) The viewing key\n"
1502 throw std::runtime_error(
1503 "exportsaplingkey \"shield_addr\"\n"
1504 "\nReveals the key corresponding to the 'shield_addr'.\n"
1505 "Then the importsaplingkey can be used with this output\n"
1509 "1. \"addr\" (string, required) The shield addr for the private key\n"
1512 "\"key\" (string) The private key\n"
bool IsValidPaymentAddress(const libzcash::PaymentAddress &zaddr)
Check whether a PaymentAddress is not an InvalidEncoding.
bool BIP38_Decrypt(std::string strPassphrase, std::string strEncryptedKey, uint256 &privKey, bool &fCompressed)
std::string BIP38_Encrypt(std::string strAddress, std::string strPassphrase, uint256 privKey, bool fCompressed)
const CChainParams & Params()
Return the currently selected parameters.
virtual bool HaveWatchOnly(const CScript &dest) const
void GetSaplingPaymentAddresses(std::set< libzcash::SaplingPaymentAddress > &setAddress) const
virtual bool HaveCScript(const CScriptID &hash) const
bool GetSaplingExtendedSpendingKey(const libzcash::SaplingPaymentAddress &addr, libzcash::SaplingExtendedSpendingKey &extskOut) const
The block chain is a tree shaped structure starting with the genesis block at the root,...
uint256 GetBlockHash() const
int64_t GetBlockTime() const
int64_t GetMedianTimePast() const
int nHeight
height of the entry in the chain. The genesis block has height 0
CBlockIndex * Genesis() const
Returns the index entry for the genesis block of this chain, or nullptr if none.
CBlockIndex * Tip(bool fProofOfStake=false) const
Returns the index entry for the tip of this chain, or nullptr if none.
int Height() const
Return the maximal height in the chain.
bool GetKey(const CKeyID &address, CKey &keyOut) const override
bool HaveKey(const CKeyID &address) const override
Check whether a key corresponding to a given address is present in the store.
An encapsulated private key.
unsigned int size() const
Simple read-only vector-like interface.
bool IsValid() const
Check whether this private key is valid.
bool IsCompressed() const
Check whether the public key corresponding to this private key is (to be) compressed.
CPubKey GetPubKey() const
Compute the public key from a private key.
void Set(const T pbegin, const T pend, bool fCompressedIn)
Initialize using begin and end iterators to byte data.
const unsigned char * begin() const
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.
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.
bool IsPayToScriptHash() const
A reference to a CScript: the Hash160 of its serialization (see script.h)
A CWallet is an extension of a keystore, which also maintains a set of transactions and balances,...
void GetKeyBirthTimes(std::map< CKeyID, int64_t > &mapKeyBirth) const EXCLUSIVE_LOCKS_REQUIRED(cs_main)
SaplingScriptPubKeyMan * GetSaplingScriptPubKeyMan() const
std::map< CKeyID, CKeyMetadata > mapKeyMetadata
boost::signals2::signal< void(const std::string &title, int nProgress)> ShowProgress
Show progress e.g.
std::map< libzcash::SaplingIncomingViewingKey, CKeyMetadata > mapSaplingZKeyMetadata
Optional< libzcash::SaplingExtendedFullViewingKey > GetViewingKeyForPaymentAddress(const libzcash::SaplingPaymentAddress &addr) const
Return the full viewing key for the shielded address.
Optional< libzcash::SaplingExtendedSpendingKey > GetSpendingKeyForPaymentAddress(const libzcash::SaplingPaymentAddress &addr) const
Return the spending key for the payment address (nullopt if the wallet has no spending key for such a...
KeyAddResult AddViewingKeyToWallet(const libzcash::SaplingExtendedFullViewingKey &extfvk) const
KeyAddResult AddSpendingKeyToWallet(const Consensus::Params ¶ms, const libzcash::SaplingExtendedSpendingKey &sk, int64_t nTime)
const CHDChain & GetHDChain() const
const std::map< CKeyID, int64_t > & GetAllReserveKeys() const
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)
RAII object to check and reserve a wallet rescan.
std::string ToString() const
SaplingFullViewingKey full_viewing_key() const
SaplingIncomingViewingKey in_viewing_key() const
const std::string CLIENT_BUILD
std::string GetNameForAddressBookEntry(const CWDestination &address) const
bool HasAddressBook(const CWDestination &address) const
bool SetAddressBook(const CWDestination &address, const std::string &strName, const std::string &purpose)
bool AddCScript(const CScript &redeemScript) override
Support for BIP 0013 : see https://github.com/bitcoin/bips/blob/master/bip-0013.mediawiki.
ScriptPubKeyMan * GetScriptPubKeyMan() const
Get spkm.
bool AddWatchOnly(const CScript &dest) override
Adds a watch-only address to the store, and saves it to disk.
CBlockIndex * ScanForWalletTransactions(CBlockIndex *pindexStart, CBlockIndex *pindexStop, const WalletRescanReserver &reserver, bool fUpdate=false, bool fromStartup=false)
Scan the block chain (starting in pindexStart) for transactions from or to us.
void BlockUntilSyncedToCurrentChain()
Blocks until the wallet state is up-to-date to /at least/ the current chain at the time this function...
void UpdateTimeFirstKey(int64_t nCreateTime)
Update wallet first key creation time.
void ReacceptWalletTransactions(bool fFirstLoad=false)
bool HasSaplingSPKM() const
bool AddKeyPubKey(const CKey &key, const CPubKey &pubkey) override
Adds a key to the store, and saves it to disk.
int64_t RescanFromTime(int64_t startTime, const WalletRescanReserver &reserver, bool update)
Scan active chain for relevant transactions after importing keys.
isminetype IsMine(const CKeyStore &keystore, const CTxDestination &dest)
#define LogPrint(category,...)
const std::string RECEIVE
const std::string COLD_STAKING
std::string EncodeSecret(const CKey &key)
libzcash::SpendingKey DecodeSpendingKey(const std::string &str)
std::string EncodePaymentAddress(const libzcash::PaymentAddress &zaddr)
CKey DecodeSecret(const std::string &str)
libzcash::ViewingKey DecodeViewingKey(const std::string &str)
std::string EncodeExtKey(const CExtKey &key)
std::string EncodeViewingKey(const libzcash::ViewingKey &vk)
libzcash::PaymentAddress DecodePaymentAddress(const std::string &str)
std::string EncodeSpendingKey(const libzcash::SpendingKey &zkey)
bool IsValidDestination(const CWDestination &address)
std::string EncodeDestination(const CWDestination &address, const CChainParams::Base58Type addrType)
CWDestination DecodeDestination(const std::string &strAddress)
boost::variant< InvalidEncoding, SaplingExtendedSpendingKey > SpendingKey
boost::variant< InvalidEncoding, SaplingExtendedFullViewingKey > ViewingKey
RecursiveMutex cs_main
Global state.
boost::optional< T > Optional
Substitute for C++17 std::optional.
UniValue JSONRPCError(int code, const std::string &message)
@ RPC_MISC_ERROR
General application defined errors.
@ RPC_TYPE_ERROR
Server is in safe mode, and command is not allowed in safe mode.
@ RPC_INVALID_PARAMETER
Ran out of memory during operation.
@ RPC_WALLET_ERROR
No valid connection manager instance found.
@ RPC_INVALID_ADDRESS_OR_KEY
Unexpected type was passed as parameter.
bool IsStakingDerPath(KeyOriginInfo keyOrigin)
UniValue importpubkey(const JSONRPCRequest &request)
UniValue importprivkey(const JSONRPCRequest &request)
UniValue bip38decrypt(const JSONRPCRequest &request)
UniValue exportsaplingkey(const JSONRPCRequest &request)
UniValue dumpwallet(const JSONRPCRequest &request)
UniValue exportsaplingviewingkey(const JSONRPCRequest &request)
UniValue importwallet(const JSONRPCRequest &request)
UniValue abortrescan(const JSONRPCRequest &request)
std::string DecodeDumpString(const std::string &str)
UniValue dumpprivkey(const JSONRPCRequest &request)
UniValue importaddress(const JSONRPCRequest &request)
UniValue importsaplingkey(const JSONRPCRequest &request)
UniValue importsaplingviewingkey(const JSONRPCRequest &request)
UniValue bip38encrypt(const JSONRPCRequest &request)
UniValue importmulti(const JSONRPCRequest &mainRequest)
CWallet * GetWalletForJSONRPCRequest(const JSONRPCRequest &request)
Figures out what wallet, if any, to use for a JSONRPCRequest.
std::string HelpRequiringPassphrase(CWallet *const pwallet)
void EnsureWalletIsUnlocked(CWallet *const pwallet, bool fAllowAnonOnly)
bool EnsureWalletIsAvailable(CWallet *const pwallet, bool avoidException)
std::string HelpExampleCli(std::string methodname, std::string args)
void RPCTypeCheck(const UniValue ¶ms, const std::list< UniValue::VType > &typesExpected, bool fAllowNull)
Type-check arguments; throws JSONRPCError if wrong type given.
std::string HelpExampleRpc(std::string methodname, std::string args)
CScript GetScriptForRawPubKey(const CPubKey &pubKey)
Generate a P2PK script for the given pubkey.
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a PIVX scriptPubKey for the given CTxDestination.
bool ExtractDestination(const CScript &scriptPubKey, CTxDestination &addressRet, bool fColdStake)
Parse a standard scriptPubKey for the destination address.
boost::variant< CNoDestination, CKeyID, CScriptID, CExchangeKeyID > CTxDestination
A txout script template with a specific destination.
void SetSeed(const unsigned char *seed, unsigned int nSeedLen)
std::vector< uint32_t > path
std::string pathToString() const
libzcash::SaplingPaymentAddress DefaultAddress() const
libzcash::SaplingExpandedSpendingKey expsk
libzcash::SaplingPaymentAddress DefaultAddress() const
std::string _(const char *psz)
Translation function: Call Translate signal on UI interface, which returns a Optional result.
const char * uvTypeName(UniValue::VType t)
const UniValue NullUniValue
std::string HexStr(const Span< const uint8_t > s)
Convert a span of bytes to a lower-case hexadecimal string.
std::vector< unsigned char > ParseHex(const char *psz)
bool IsHex(const std::string &str)
int64_t GetTime()
DEPRECATED Use either GetSystemTimeInSeconds (not mockable) or GetTime<T> (mockable)
std::string FormatISO8601DateTime(int64_t nTime)
ISO 8601 formatting is preferred.
CChain chainActive
The currently-connected chain of blocks (protected by cs_main).
bool IsValidSpendingKey(const libzcash::SpendingKey &zkey)
Check whether a SpendingKey is not an InvalidEncoding.
bool IsValidViewingKey(const libzcash::ViewingKey &vk)
Check whether a ViewingKey is not an InvalidEncoding.