PRCYCoin  2.0.0.7rc1
P2P Digital Currency
rpcdump.cpp
Go to the documentation of this file.
1 // Copyright (c) 2009-2014 The Bitcoin developers
2 // Copyright (c) 2014-2015 The Dash developers
3 // Copyright (c) 2015-2018 The PIVX developers
4 // Copyright (c) 2018-2020 The DAPS Project developers
5 // Distributed under the MIT software license, see the accompanying
6 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
7 
8 #include "bip38.h"
9 #include "init.h"
10 #include "main.h"
11 #include "rpc/server.h"
12 #include "script/script.h"
13 #include "script/standard.h"
14 #include "sync.h"
15 #include "util.h"
16 #include "utilstrencodings.h"
17 #include "utiltime.h"
18 #include "wallet/wallet.h"
19 
20 #include <fstream>
21 #include <secp256k1.h>
22 #include <stdint.h>
23 
24 #include <boost/algorithm/string.hpp>
25 #include <boost/date_time/posix_time/posix_time.hpp>
26 #include <openssl/aes.h>
27 #include <openssl/sha.h>
28 
29 #include <univalue.h>
30 
31 
32 void EnsureWallet();
33 void EnsureWalletIsUnlocked(bool fAllowAnonOnly);
34 
35 std::string static EncodeDumpTime(int64_t nTime)
36 {
37  return DateTimeStrFormat("%Y-%m-%dT%H:%M:%SZ", nTime);
38 }
39 
40 int64_t static DecodeDumpTime(const std::string& str)
41 {
42  static const boost::posix_time::ptime epoch = boost::posix_time::from_time_t(0);
43  static const std::locale loc(std::locale::classic(),
44  new boost::posix_time::time_input_facet("%Y-%m-%dT%H:%M:%SZ"));
45  std::istringstream iss(str);
46  iss.imbue(loc);
47  boost::posix_time::ptime ptime(boost::date_time::not_a_date_time);
48  iss >> ptime;
49  if (ptime.is_not_a_date_time())
50  return 0;
51  return (ptime - epoch).total_seconds();
52 }
53 
54 std::string static EncodeDumpString(const std::string& str)
55 {
56  std::stringstream ret;
57  for (unsigned char c : str) {
58  if (c <= 32 || c >= 128 || c == '%') {
59  ret << '%' << HexStr(&c, &c + 1);
60  } else {
61  ret << c;
62  }
63  }
64  return ret.str();
65 }
66 
67 std::string DecodeDumpString(const std::string& str)
68 {
69  std::stringstream ret;
70  for (unsigned int pos = 0; pos < str.length(); pos++) {
71  unsigned char c = str[pos];
72  if (c == '%' && pos + 2 < str.length()) {
73  c = (((str[pos + 1] >> 6) * 9 + ((str[pos + 1] - '0') & 15)) << 4) |
74  ((str[pos + 2] >> 6) * 9 + ((str[pos + 2] - '0') & 15));
75  pos += 2;
76  }
77  ret << c;
78  }
79  return ret.str();
80 }
81 
82 UniValue importprivkey(const UniValue& params, bool fHelp)
83 {
84  if (fHelp || params.size() < 1 || params.size() > 3)
85  throw std::runtime_error(
86  "importprivkey \"prcycoinprivkey\" ( \"label\" rescan )\n"
87  "\nAdds a private key (as returned by dumpprivkey) to your wallet.\n"
88  "\nArguments:\n"
89  "1. \"prcycoinprivkey\" (string, required) The private key (see dumpprivkey)\n"
90  "2. \"label\" (string, optional, default=\"\") An optional label\n"
91  "3. rescan (boolean, optional, default=true) Rescan the wallet for transactions\n"
92  "\nNote: This call can take minutes to complete if rescan is true.\n"
93  "\nExamples:\n"
94  "\nDump a private key\n" +
95  HelpExampleCli("dumpprivkey", "\"myaddress\"") +
96  "\nImport the private key with rescan\n" + HelpExampleCli("importprivkey", "\"mykey\"") +
97  "\nImport using a label and without rescan\n" + HelpExampleCli("importprivkey", "\"mykey\" \"testing\" false") +
98  "\nAs a JSON-RPC call\n" + HelpExampleRpc("importprivkey", "\"mykey\", \"testing\", false"));
100 
102 
103  std::string strSecret = params[0].get_str();
104  std::string strLabel = "";
105  if (params.size() > 1)
106  strLabel = params[1].get_str();
107 
108  // Whether to perform rescan after import
109  bool fRescan = true;
110  if (params.size() > 2)
111  fRescan = params[2].get_bool();
112 
113  CBitcoinSecret vchSecret;
114  bool fGood = vchSecret.SetString(strSecret);
115 
116  if (!fGood) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid private key encoding");
117 
118  CKey key = vchSecret.GetKey();
119  if (!key.IsValid()) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Private key outside allowed range");
120 
121  CPubKey pubkey = key.GetPubKey();
122  assert(key.VerifyPubKey(pubkey));
123  CKeyID vchAddress = pubkey.GetID();
124  {
126  pwalletMain->SetAddressBook(vchAddress, strLabel, "receive");
127 
128  // Don't throw error in case a key is already there
129  if (pwalletMain->HaveKey(vchAddress))
130  return NullUniValue;
131 
132  pwalletMain->mapKeyMetadata[vchAddress].nCreateTime = 1;
133 
134  if (!pwalletMain->AddKeyPubKey(key, pubkey))
135  throw JSONRPCError(RPC_WALLET_ERROR, "Error adding key to wallet");
136 
137  // whenever a key is imported, we need to scan the whole chain
138  pwalletMain->nTimeFirstKey = 1; // 0 would be considered 'no value'
139 
140  if (fRescan) {
142  }
143  }
144 
145  return NullUniValue;
146 }
147 
148 UniValue importaddress(const UniValue& params, bool fHelp)
149 {
150  if (fHelp || params.size() < 1 || params.size() > 3)
151  throw std::runtime_error(
152  "importaddress \"address\" ( \"label\" rescan )\n"
153  "\nAdds an address or script (in hex) that can be watched as if it were in your wallet but cannot be used to spend.\n"
154  "\nArguments:\n"
155  "1. \"address\" (string, required) The address\n"
156  "2. \"label\" (string, optional, default=\"\") An optional label\n"
157  "3. rescan (boolean, optional, default=true) Rescan the wallet for transactions\n"
158  "\nNote: This call can take minutes to complete if rescan is true.\n"
159  "\nExamples:\n"
160  "\nImport an address with rescan\n" +
161  HelpExampleCli("importaddress", "\"myaddress\"") +
162  "\nImport using a label without rescan\n" + HelpExampleCli("importaddress", "\"myaddress\" \"testing\" false") +
163  "\nAs a JSON-RPC call\n" + HelpExampleRpc("importaddress", "\"myaddress\", \"testing\", false"));
164 
166 
167  CScript script;
168 
169  CBitcoinAddress address(params[0].get_str());
170  if (address.IsValid()) {
171  script = GetScriptForDestination(address.Get());
172  } else if (IsHex(params[0].get_str())) {
173  std::vector<unsigned char> data(ParseHex(params[0].get_str()));
174  script = CScript(data.begin(), data.end());
175  } else {
176  throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid PRCY address or script");
177  }
178 
179  std::string strLabel = "";
180  if (params.size() > 1)
181  strLabel = params[1].get_str();
182 
183  // Whether to perform rescan after import
184  bool fRescan = true;
185  if (params.size() > 2)
186  fRescan = params[2].get_bool();
187 
188  {
189  if (::IsMine(*pwalletMain, script) == ISMINE_SPENDABLE)
190  throw JSONRPCError(RPC_WALLET_ERROR, "The wallet already contains the private key for this address or script");
191 
192  // add to address book or update label
193  if (address.IsValid())
194  pwalletMain->SetAddressBook(address.Get(), strLabel, "receive");
195 
196  // Don't throw error in case an address is already there
197  if (pwalletMain->HaveWatchOnly(script))
198  return NullUniValue;
199 
201 
202  if (!pwalletMain->AddWatchOnly(script))
203  throw JSONRPCError(RPC_WALLET_ERROR, "Error adding address to wallet");
204 
205  if (fRescan) {
208  }
209  }
210 
211  return NullUniValue;
212 }
213 
214 UniValue importwallet(const UniValue& params, bool fHelp)
215 {
216  if (fHelp || params.size() != 1)
217  throw std::runtime_error(
218  "importwallet \"filename\"\n"
219  "\nImports keys from a wallet dump file (see dumpwallet).\n"
220  "\nArguments:\n"
221  "1. \"filename\" (string, required) The wallet file\n"
222  "\nExamples:\n"
223  "\nDump the wallet\n" +
224  HelpExampleCli("dumpwallet", "\"test\"") +
225  "\nImport the wallet\n" + HelpExampleCli("importwallet", "\"test\"") +
226  "\nImport using the json rpc call\n" + HelpExampleRpc("importwallet", "\"test\""));
227 
229 
231 
232  std::ifstream file;
233  file.open(params[0].get_str().c_str(), std::ios::in | std::ios::ate);
234  if (!file.is_open())
235  throw JSONRPCError(RPC_INVALID_PARAMETER, "Cannot open wallet dump file");
236 
237  int64_t nTimeBegin = chainActive.Tip()->GetBlockTime();
238 
239  bool fGood = true;
240 
241  int64_t nFilesize = std::max((int64_t)1, (int64_t)file.tellg());
242  file.seekg(0, file.beg);
243 
244  pwalletMain->ShowProgress(_("Importing..."), 0); // show progress dialog in GUI
245  while (file.good()) {
246  pwalletMain->ShowProgress("", std::max(1, std::min(99, (int)(((double)file.tellg() / (double)nFilesize) * 100))));
247  std::string line;
248  std::getline(file, line);
249  if (line.empty() || line[0] == '#')
250  continue;
251 
252  std::vector<std::string> vstr;
253  boost::split(vstr, line, boost::is_any_of(" "));
254  if (vstr.size() < 2)
255  continue;
256  CBitcoinSecret vchSecret;
257  if (!vchSecret.SetString(vstr[0]))
258  continue;
259  CKey key = vchSecret.GetKey();
260  CPubKey pubkey = key.GetPubKey();
261  assert(key.VerifyPubKey(pubkey));
262  CKeyID keyid = pubkey.GetID();
263  if (pwalletMain->HaveKey(keyid)) {
264  LogPrintf("Skipping import of %s (key already present)\n", CBitcoinAddress(keyid).ToString());
265  continue;
266  }
267  int64_t nTime = DecodeDumpTime(vstr[1]);
268  std::string strLabel;
269  bool fLabel = true;
270  for (unsigned int nStr = 2; nStr < vstr.size(); nStr++) {
271  if (boost::algorithm::starts_with(vstr[nStr], "#"))
272  break;
273  if (vstr[nStr] == "change=1")
274  fLabel = false;
275  if (vstr[nStr] == "reserve=1")
276  fLabel = false;
277  if (boost::algorithm::starts_with(vstr[nStr], "label=")) {
278  strLabel = DecodeDumpString(vstr[nStr].substr(6));
279  fLabel = true;
280  }
281  }
282  LogPrintf("Importing %s...\n", CBitcoinAddress(keyid).ToString());
283  if (!pwalletMain->AddKeyPubKey(key, pubkey)) {
284  fGood = false;
285  continue;
286  }
287  pwalletMain->mapKeyMetadata[keyid].nCreateTime = nTime;
288  if (fLabel)
289  pwalletMain->SetAddressBook(keyid, strLabel, "receive");
290  nTimeBegin = std::min(nTimeBegin, nTime);
291  }
292  file.close();
293  pwalletMain->ShowProgress("", 100); // hide progress dialog in GUI
294 
295  CBlockIndex* pindex = chainActive.Tip();
296  while (pindex && pindex->pprev && pindex->GetBlockTime() > nTimeBegin - 7200)
297  pindex = pindex->pprev;
298 
299  if (!pwalletMain->nTimeFirstKey || nTimeBegin < pwalletMain->nTimeFirstKey)
300  pwalletMain->nTimeFirstKey = nTimeBegin;
301 
302  LogPrintf("Rescanning last %i blocks\n", chainActive.Height() - pindex->nHeight + 1);
305 
306  if (!fGood)
307  throw JSONRPCError(RPC_WALLET_ERROR, "Error adding some keys to wallet");
308 
309  return NullUniValue;
310 }
311 
312 UniValue dumpprivkey(const UniValue& params, bool fHelp)
313 {
314  if (fHelp || params.size() != 1)
315  throw std::runtime_error(
316  "dumpprivkey \"prcycoinaddress\"\n"
317  "\nReveals the private key corresponding to 'prcycoinaddress'.\n"
318  "Then the importprivkey can be used with this output\n"
319  "\nArguments:\n"
320  "1. \"prcycoinaddress\" (string, required) The prcycoin address for the private key\n"
321  "\nResult:\n"
322  "\"key\" (string) The private key\n"
323  "\nExamples:\n" +
324  HelpExampleCli("dumpprivkey", "\"myaddress\"") + HelpExampleCli("importprivkey", "\"mykey\"") + HelpExampleRpc("dumpprivkey", "\"myaddress\""));
325 
327 
329 
330  std::string strAddress = params[0].get_str();
331  CBitcoinAddress address;
332  if (!address.SetString(strAddress))
333  throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid PRCY address");
334  CKeyID keyID;
335  if (!address.GetKeyID(keyID))
336  throw JSONRPCError(RPC_TYPE_ERROR, "Address does not refer to a key");
337  CKey vchSecret;
338  if (!pwalletMain->GetKey(keyID, vchSecret))
339  throw JSONRPCError(RPC_WALLET_ERROR, "Private key for address " + strAddress + " is not known");
340  return CBitcoinSecret(vchSecret).ToString();
341 }
342 
343 
344 UniValue dumpwallet(const UniValue& params, bool fHelp)
345 {
346  if (fHelp || params.size() != 1)
347  throw std::runtime_error(
348  "dumpwallet \"filename\"\n"
349  "\nDumps all wallet keys in a human-readable format.\n"
350  "\nArguments:\n"
351  "1. \"filename\" (string, required) The filename\n"
352  "\nExamples:\n" +
353  HelpExampleCli("dumpwallet", "\"test\"") + HelpExampleRpc("dumpwallet", "\"test\""));
354 
356 
358 
359  fs::path filepath = params[0].get_str().c_str();
360  filepath = fs::absolute(filepath);
361 
362  std::ofstream file;
363  file.open(params[0].get_str().c_str());
364  if (!file.is_open())
365  throw JSONRPCError(RPC_INVALID_PARAMETER, "Cannot open wallet dump file");
366 
367  std::map<CKeyID, int64_t> mapKeyBirth;
368  std::set<CKeyID> setKeyPool;
369  pwalletMain->GetKeyBirthTimes(mapKeyBirth);
370  pwalletMain->GetAllReserveKeys(setKeyPool);
371 
372  // sort time/key pairs
373  std::vector<std::pair<int64_t, CKeyID> > vKeyBirth;
374  for (std::map<CKeyID, int64_t>::const_iterator it = mapKeyBirth.begin(); it != mapKeyBirth.end(); it++) {
375  vKeyBirth.push_back(std::make_pair(it->second, it->first));
376  }
377  mapKeyBirth.clear();
378  std::sort(vKeyBirth.begin(), vKeyBirth.end());
379 
380  // produce output
381  file << strprintf("# Wallet dump created by PRCY%s\n", CLIENT_BUILD);
382  file << strprintf("# * Created on %s\n", EncodeDumpTime(GetTime()));
383  file << strprintf("# * Best block at time of backup was %i (%s),\n", chainActive.Height(), chainActive.Tip()->GetBlockHash().ToString());
384  file << strprintf("# mined on %s\n", EncodeDumpTime(chainActive.Tip()->GetBlockTime()));
385  file << "\n";
386  for (std::vector<std::pair<int64_t, CKeyID> >::const_iterator it = vKeyBirth.begin(); it != vKeyBirth.end(); it++) {
387  const CKeyID& keyid = it->second;
388  std::string strTime = EncodeDumpTime(it->first);
389  std::string strAddr = CBitcoinAddress(keyid).ToString();
390  CKey key;
391  if (pwalletMain->GetKey(keyid, key)) {
392  if (pwalletMain->mapAddressBook.count(keyid)) {
393  file << strprintf("%s %s label=%s # addr=%s\n", CBitcoinSecret(key).ToString(), strTime, EncodeDumpString(pwalletMain->mapAddressBook[keyid].name), strAddr);
394  } else if (setKeyPool.count(keyid)) {
395  file << strprintf("%s %s reserve=1 # addr=%s\n", CBitcoinSecret(key).ToString(), strTime, strAddr);
396  } else {
397  file << strprintf("%s %s change=1 # addr=%s\n", CBitcoinSecret(key).ToString(), strTime, strAddr);
398  }
399  }
400  }
401  file << "\n";
402  file << "# End of dump\n";
403  file.close();
404 
405  UniValue reply(UniValue::VOBJ);
406  reply.push_back(Pair("filename", filepath.string()));
407 
408  return reply;
409 }
410 
411 UniValue bip38encrypt(const UniValue& params, bool fHelp)
412 {
413  if (fHelp || params.size() != 2)
414  throw std::runtime_error(
415  "bip38encrypt \"prcycoinaddress\"\n"
416  "\nEncrypts a private key corresponding to 'prcycoinaddress'.\n"
417  "\nArguments:\n"
418  "1. \"prcycoinaddress\" (string, required) The prcycoin address for the private key (you must hold the key already)\n"
419  "2. \"passphrase\" (string, required) The passphrase you want the private key to be encrypted with - Valid special chars: !#$%&'()*+,-./:;<=>?`{|}~ \n"
420  "\nResult:\n"
421  "\"key\" (string) The encrypted private key\n"
422  "\nExamples:\n");
423 
425 
427 
428  std::string strAddress = params[0].get_str();
429  std::string strPassphrase = params[1].get_str();
430 
431  CBitcoinAddress address;
432  if (!address.SetString(strAddress))
433  throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid PRCY address");
434  CKeyID keyID;
435  if (!address.GetKeyID(keyID))
436  throw JSONRPCError(RPC_TYPE_ERROR, "Address does not refer to a key");
437  CKey vchSecret;
438  if (!pwalletMain->GetKey(keyID, vchSecret))
439  throw JSONRPCError(RPC_WALLET_ERROR, "Private key for address " + strAddress + " is not known");
440 
441  uint256 privKey = vchSecret.GetPrivKey_256();
442  std::string encryptedOut = BIP38_Encrypt(strAddress, strPassphrase, privKey, vchSecret.IsCompressed());
443 
444  UniValue result(UniValue::VOBJ);
445  result.push_back(Pair("Addess", strAddress));
446  result.push_back(Pair("Encrypted Key", encryptedOut));
447 
448  return result;
449 }
450 
451 UniValue bip38decrypt(const UniValue& params, bool fHelp)
452 {
453  if (fHelp || params.size() != 2)
454  throw std::runtime_error(
455  "bip38decrypt \"prcycoinaddress\"\n"
456  "\nDecrypts and then imports password protected private key.\n"
457  "\nArguments:\n"
458  "1. \"encryptedkey\" (string, required) The encrypted private key\n"
459  "2. \"passphrase\" (string, required) The passphrase you want the private key to be encrypted with\n"
460 
461  "\nResult:\n"
462  "\"key\" (string) The decrypted private key\n"
463  "\nExamples:\n");
464 
466 
468 
470  std::string strKey = params[0].get_str();
471  std::string strPassphrase = params[1].get_str();
472 
473  uint256 privKey;
474  bool fCompressed;
475  if (!BIP38_Decrypt(strPassphrase, strKey, privKey, fCompressed))
476  throw JSONRPCError(RPC_WALLET_ERROR, "Failed To Decrypt");
477 
478  UniValue result(UniValue::VOBJ);
479  result.push_back(Pair("privatekey", HexStr(privKey)));
480 
481  CKey key;
482  key.Set(privKey.begin(), privKey.end(), fCompressed);
483 
484  if (!key.IsValid())
485  throw JSONRPCError(RPC_WALLET_ERROR, "Private Key Not Valid");
486 
487  CPubKey pubkey = key.GetPubKey();
488  pubkey.IsCompressed();
489  assert(key.VerifyPubKey(pubkey));
490  result.push_back(Pair("Address", CBitcoinAddress(pubkey.GetID()).ToString()));
491  CKeyID vchAddress = pubkey.GetID();
492  {
494  pwalletMain->SetAddressBook(vchAddress, "", "receive");
495 
496  // Don't throw error in case a key is already there
497  if (pwalletMain->HaveKey(vchAddress))
498  throw JSONRPCError(RPC_WALLET_ERROR, "Key already held by wallet");
499 
500  pwalletMain->mapKeyMetadata[vchAddress].nCreateTime = 1;
501 
502  if (!pwalletMain->AddKeyPubKey(key, pubkey))
503  throw JSONRPCError(RPC_WALLET_ERROR, "Error adding key to wallet");
504 
505  // whenever a key is imported, we need to scan the whole chain
506  pwalletMain->nTimeFirstKey = 1; // 0 would be considered 'no value'
508  }
509 
510  return result;
511 }
CBlockIndex::GetBlockTime
int64_t GetBlockTime() const
Definition: chain.h:364
CKey::IsCompressed
bool IsCompressed() const
Check whether the public key corresponding to this private key is (to be) compressed.
Definition: key.h:107
LOCK2
#define LOCK2(cs1, cs2)
Definition: sync.h:183
IsMine
isminetype IsMine(const CKeyStore &keystore, const CTxDestination &dest)
Definition: wallet_ismine.cpp:30
base_uint::end
unsigned char * end()
Definition: arith_uint256.h:245
UniValue::VOBJ
@ VOBJ
Definition: univalue.h:21
utiltime.h
CBitcoinSecret::GetKey
CKey GetKey()
Definition: base58.cpp:304
UniValue::get_bool
bool get_bool() const
Definition: univalue.cpp:302
GetTime
int64_t GetTime()
For unit testing.
Definition: utiltime.cpp:19
CLIENT_BUILD
const std::string CLIENT_BUILD
CWallet::ScanForWalletTransactions
int ScanForWalletTransactions(CBlockIndex *pindexStart, bool fUpdate=false, bool fromStartup=false, int height=-1)
Scan the block chain (starting in pindexStart) for transactions from or to us.
Definition: wallet.cpp:2062
ParseHex
std::vector< unsigned char > ParseHex(const char *psz)
Definition: utilstrencodings.cpp:77
CBitcoinAddress::GetKeyID
bool GetKeyID(CKeyID &keyID) const
Definition: base58.cpp:281
base_uint::begin
unsigned char * begin()
Definition: arith_uint256.h:240
sync.h
chainActive
CChain chainActive
The currently-connected chain of blocks.
Definition: main.cpp:70
NullUniValue
const UniValue NullUniValue
Definition: univalue.cpp:78
GetScriptForDestination
CScript GetScriptForDestination(const CTxDestination &dest)
Definition: standard.cpp:285
CBitcoinAddress
base58-encoded PRCY addresses.
Definition: base58.h:109
RPC_INVALID_PARAMETER
@ RPC_INVALID_PARAMETER
Ran out of memory during operation.
Definition: protocol.h:45
CBlockIndex::pprev
CBlockIndex * pprev
pointer to the index of the predecessor of this block
Definition: chain.h:169
CKey::Set
void Set(const T pbegin, const T pend, bool fCompressedIn)
Initialize using begin and end iterators to byte data.
Definition: key.h:83
CBlockIndex::nHeight
int nHeight
height of the entry in the chain. The genesis block has height 0
Definition: chain.h:181
wallet.h
EnsureWallet
void EnsureWallet()
Definition: rpcwallet.cpp:37
CKeyID
A reference to a CKey: the Hash160 of its serialized public key.
Definition: pubkey.h:29
DateTimeStrFormat
std::string DateTimeStrFormat(const char *pszFormat, int64_t nTime)
Definition: utiltime.cpp:50
CBase58Data::ToString
std::string ToString() const
Definition: base58.cpp:200
dumpwallet
UniValue dumpwallet(const UniValue &params, bool fHelp)
Definition: rpcdump.cpp:344
CWallet::AddKeyPubKey
bool AddKeyPubKey(const CKey &key, const CPubKey &pubkey)
Adds a key to the store, and saves it to disk.
Definition: wallet.cpp:240
UniValue
Definition: univalue.h:19
EnsureWalletIsUnlocked
void EnsureWalletIsUnlocked(bool fAllowAnonOnly)
Definition: rpcwallet.cpp:45
CBitcoinSecret
A base58-encoded secret key.
Definition: base58.h:131
CWallet::GetKeyBirthTimes
void GetKeyBirthTimes(std::map< CKeyID, int64_t > &mapKeyBirth) const
Definition: wallet.cpp:5131
CWallet::SetAddressBook
bool SetAddressBook(const CTxDestination &address, const std::string &strName, const std::string &purpose)
Definition: wallet.cpp:4589
CWallet::MarkDirty
void MarkDirty()
Definition: wallet.cpp:1162
UniValue::get_str
const std::string & get_str() const
Definition: univalue.cpp:309
cs_main
RecursiveMutex cs_main
Global state.
Definition: main.cpp:65
dumpprivkey
UniValue dumpprivkey(const UniValue &params, bool fHelp)
Definition: rpcdump.cpp:312
CKey::GetPrivKey_256
uint256 GetPrivKey_256()
Definition: key.cpp:58
IsHex
bool IsHex(const std::string &str)
Definition: utilstrencodings.cpp:68
secp256k1.h
CBase58Data::SetString
bool SetString(const char *psz, unsigned int nVersionBytes=1)
Definition: base58.cpp:178
importprivkey
UniValue importprivkey(const UniValue &params, bool fHelp)
Definition: rpcdump.cpp:82
_
std::string _(const char *psz)
Translation function: Call Translate signal on UI interface, which returns a boost::optional result.
Definition: guiinterface.h:119
init.h
univalue.h
HexStr
std::string HexStr(const T itbegin, const T itend, bool fSpaces=false)
Definition: utilstrencodings.h:85
CKey::IsValid
bool IsValid() const
Check whether this private key is valid.
Definition: key.h:104
CWallet::ShowProgress
boost::signals2::signal< void(const std::string &title, int nProgress)> ShowProgress
Show progress e.g.
Definition: wallet.h:610
JSONRPCError
UniValue JSONRPCError(int code, const std::string &message)
Definition: protocol.cpp:60
LogPrintf
#define LogPrintf(...)
Definition: logging.h:147
standard.h
CWallet::GetAllReserveKeys
void GetAllReserveKeys(std::set< CKeyID > &setAddress) const
Definition: wallet.cpp:5024
CBitcoinSecret::SetString
bool SetString(const char *pszSecret)
Definition: base58.cpp:319
RPC_WALLET_ERROR
@ RPC_WALLET_ERROR
Invalid IP/Subnet.
Definition: protocol.h:68
ISMINE_SPENDABLE
@ ISMINE_SPENDABLE
Definition: wallet_ismine.h:20
HelpExampleRpc
std::string HelpExampleRpc(std::string methodname, std::string args)
Definition: server.cpp:607
uint256
256-bit unsigned big integer.
Definition: uint256.h:38
CKey::GetPubKey
CPubKey GetPubKey() const
Compute the public key from a private key.
Definition: key.cpp:79
CScript
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:363
CBlockIndex::GetBlockHash
uint256 GetBlockHash() const
Definition: chain.h:359
DecodeDumpString
std::string DecodeDumpString(const std::string &str)
Definition: rpcdump.cpp:67
CChain::Height
int Height() const
Return the maximal height in the chain.
Definition: chain.h:641
HelpExampleCli
std::string HelpExampleCli(std::string methodname, std::string args)
Definition: server.cpp:603
RPC_INVALID_ADDRESS_OR_KEY
@ RPC_INVALID_ADDRESS_OR_KEY
Unexpected type was passed as parameter.
Definition: protocol.h:43
CPubKey::IsCompressed
bool IsCompressed() const
Check whether this is a compressed public key.
Definition: pubkey.h:168
strprintf
#define strprintf
Definition: tinyformat.h:1056
CPubKey
An encapsulated public key.
Definition: pubkey.h:37
CKey
An encapsulated private key.
Definition: key.h:39
CKey::VerifyPubKey
bool VerifyPubKey(const CPubKey &vchPubKey) const
Verify thoroughly whether a private key and a public key match.
Definition: key.cpp:111
bip38encrypt
UniValue bip38encrypt(const UniValue &params, bool fHelp)
Definition: rpcdump.cpp:411
CWallet::HaveKey
bool HaveKey(const CKeyID &address) const
Check whether a key corresponding to a given address is present in the store.
Definition: wallet.cpp:6932
main.h
key
CKey key
Definition: bip38tooldialog.cpp:173
BIP38_Encrypt
std::string BIP38_Encrypt(std::string strAddress, std::string strPassphrase, uint256 privKey, bool fCompressed)
Definition: bip38.cpp:81
UniValue::push_back
bool push_back(const UniValue &val)
Definition: univalue.cpp:173
CWallet::mapKeyMetadata
std::map< CKeyID, CKeyMetadata > mapKeyMetadata
Definition: wallet.h:308
CWallet::cs_wallet
RecursiveMutex cs_wallet
Definition: wallet.h:301
UniValue::size
size_t size() const
Definition: univalue.h:69
script.h
CWallet::AddWatchOnly
bool AddWatchOnly(const CScript &dest)
Adds a watch-only address to the store, and saves it to disk.
Definition: wallet.cpp:469
utilstrencodings.h
CChain::Tip
CBlockIndex * Tip(bool fProofOfStake=false) const
Returns the index entry for the tip of this chain, or NULL if none.
Definition: chain.h:596
RPC_TYPE_ERROR
@ RPC_TYPE_ERROR
Server is in safe mode, and command is not allowed in safe mode.
Definition: protocol.h:42
CWallet::ReacceptWalletTransactions
void ReacceptWalletTransactions()
Definition: wallet.cpp:2132
CBitcoinAddress::IsValid
bool IsValid() const
Definition: base58.cpp:254
server.h
CBlockIndex
The block chain is a tree shaped structure starting with the genesis block at the root,...
Definition: chain.h:162
CBasicKeyStore::HaveWatchOnly
virtual bool HaveWatchOnly(const CScript &dest) const
Definition: keystore.cpp:75
CBitcoinAddress::Get
CTxDestination Get() const
Definition: base58.cpp:267
bip38decrypt
UniValue bip38decrypt(const UniValue &params, bool fHelp)
Definition: rpcdump.cpp:451
pwalletMain
CWallet * pwalletMain
Definition: wallet.cpp:49
CWallet::GetKey
bool GetKey(const CKeyID &address, CKey &keyOut) const
GetKey implementation that can derive a HD private key on the fly.
Definition: wallet.cpp:6906
BIP38_Decrypt
bool BIP38_Decrypt(std::string strPassphrase, std::string strEncryptedKey, uint256 &privKey, bool &fCompressed)
Definition: bip38.cpp:132
CWallet::nTimeFirstKey
int64_t nTimeFirstKey
Definition: wallet.h:363
importaddress
UniValue importaddress(const UniValue &params, bool fHelp)
Definition: rpcdump.cpp:148
importwallet
UniValue importwallet(const UniValue &params, bool fHelp)
Definition: rpcdump.cpp:214
CChain::Genesis
CBlockIndex * Genesis() const
Returns the index entry for the genesis block of this chain, or NULL if none.
Definition: chain.h:590
CWallet::mapAddressBook
std::map< CTxDestination, CAddressBookData > mapAddressBook
Definition: wallet.h:354
CPubKey::GetID
CKeyID GetID() const
Get the KeyID of this public key (hash of its serialization)
Definition: pubkey.h:143
bip38.h
base_uint::ToString
std::string ToString() const
Definition: arith_uint256.cpp:199