 |
PRCYCoin
2.0.0.7rc1
P2P Digital Currency
|
Go to the documentation of this file.
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>
35 std::string
static EncodeDumpTime(int64_t nTime)
40 int64_t
static DecodeDumpTime(
const std::string& str)
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);
47 boost::posix_time::ptime ptime(boost::date_time::not_a_date_time);
49 if (ptime.is_not_a_date_time())
51 return (ptime - epoch).total_seconds();
54 std::string
static EncodeDumpString(
const std::string& str)
56 std::stringstream ret;
57 for (
unsigned char c : str) {
58 if (c <= 32 || c >= 128 || c ==
'%') {
59 ret <<
'%' <<
HexStr(&c, &c + 1);
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));
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"
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"
94 "\nDump a private key\n" +
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"));
103 std::string strSecret = params[0].
get_str();
104 std::string strLabel =
"";
105 if (params.
size() > 1)
106 strLabel = params[1].
get_str();
110 if (params.
size() > 2)
114 bool fGood = vchSecret.
SetString(strSecret);
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"
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"
160 "\nImport an address with rescan\n" +
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"));
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());
179 std::string strLabel =
"";
180 if (params.
size() > 1)
181 strLabel = params[1].
get_str();
185 if (params.
size() > 2)
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"
221 "1. \"filename\" (string, required) The wallet file\n"
223 "\nDump the wallet\n" +
225 "\nImport the wallet\n" +
HelpExampleCli(
"importwallet",
"\"test\"") +
226 "\nImport using the json rpc call\n" +
HelpExampleRpc(
"importwallet",
"\"test\""));
233 file.open(params[0].get_str().c_str(), std::ios::in | std::ios::ate);
241 int64_t nFilesize = std::max((int64_t)1, (int64_t)file.tellg());
242 file.seekg(0, file.beg);
245 while (file.good()) {
246 pwalletMain->
ShowProgress(
"", std::max(1, std::min(99, (
int)(((
double)file.tellg() / (
double)nFilesize) * 100))));
248 std::getline(file, line);
249 if (line.empty() || line[0] ==
'#')
252 std::vector<std::string> vstr;
253 boost::split(vstr, line, boost::is_any_of(
" "));
267 int64_t nTime = DecodeDumpTime(vstr[1]);
268 std::string strLabel;
270 for (
unsigned int nStr = 2; nStr < vstr.size(); nStr++) {
271 if (boost::algorithm::starts_with(vstr[nStr],
"#"))
273 if (vstr[nStr] ==
"change=1")
275 if (vstr[nStr] ==
"reserve=1")
277 if (boost::algorithm::starts_with(vstr[nStr],
"label=")) {
290 nTimeBegin = std::min(nTimeBegin, nTime);
297 pindex = pindex->
pprev;
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"
320 "1. \"prcycoinaddress\" (string, required) The prcycoin address for the private key\n"
322 "\"key\" (string) The private key\n"
330 std::string strAddress = params[0].
get_str();
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"
351 "1. \"filename\" (string, required) The filename\n"
359 fs::path filepath = params[0].
get_str().c_str();
360 filepath = fs::absolute(filepath);
363 file.open(params[0].get_str().c_str());
367 std::map<CKeyID, int64_t> mapKeyBirth;
368 std::set<CKeyID> setKeyPool;
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));
378 std::sort(vKeyBirth.begin(), vKeyBirth.end());
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);
394 }
else if (setKeyPool.count(keyid)) {
402 file <<
"# End of dump\n";
406 reply.
push_back(Pair(
"filename", filepath.string()));
413 if (fHelp || params.
size() != 2)
414 throw std::runtime_error(
415 "bip38encrypt \"prcycoinaddress\"\n"
416 "\nEncrypts a private key corresponding to 'prcycoinaddress'.\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"
421 "\"key\" (string) The encrypted private key\n"
428 std::string strAddress = params[0].
get_str();
429 std::string strPassphrase = params[1].
get_str();
445 result.
push_back(Pair(
"Addess", strAddress));
446 result.
push_back(Pair(
"Encrypted Key", encryptedOut));
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"
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"
462 "\"key\" (string) The decrypted private key\n"
470 std::string strKey = params[0].
get_str();
471 std::string strPassphrase = params[1].
get_str();
475 if (!
BIP38_Decrypt(strPassphrase, strKey, privKey, fCompressed))
int64_t GetBlockTime() const
bool IsCompressed() const
Check whether the public key corresponding to this private key is (to be) compressed.
isminetype IsMine(const CKeyStore &keystore, const CTxDestination &dest)
int64_t GetTime()
For unit testing.
const std::string CLIENT_BUILD
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.
std::vector< unsigned char > ParseHex(const char *psz)
bool GetKeyID(CKeyID &keyID) const
CChain chainActive
The currently-connected chain of blocks.
const UniValue NullUniValue
CScript GetScriptForDestination(const CTxDestination &dest)
base58-encoded PRCY addresses.
@ RPC_INVALID_PARAMETER
Ran out of memory during operation.
CBlockIndex * pprev
pointer to the index of the predecessor of this block
void Set(const T pbegin, const T pend, bool fCompressedIn)
Initialize using begin and end iterators to byte data.
int nHeight
height of the entry in the chain. The genesis block has height 0
A reference to a CKey: the Hash160 of its serialized public key.
std::string DateTimeStrFormat(const char *pszFormat, int64_t nTime)
std::string ToString() const
UniValue dumpwallet(const UniValue ¶ms, bool fHelp)
bool AddKeyPubKey(const CKey &key, const CPubKey &pubkey)
Adds a key to the store, and saves it to disk.
void EnsureWalletIsUnlocked(bool fAllowAnonOnly)
A base58-encoded secret key.
void GetKeyBirthTimes(std::map< CKeyID, int64_t > &mapKeyBirth) const
bool SetAddressBook(const CTxDestination &address, const std::string &strName, const std::string &purpose)
const std::string & get_str() const
RecursiveMutex cs_main
Global state.
UniValue dumpprivkey(const UniValue ¶ms, bool fHelp)
bool IsHex(const std::string &str)
bool SetString(const char *psz, unsigned int nVersionBytes=1)
UniValue importprivkey(const UniValue ¶ms, bool fHelp)
std::string _(const char *psz)
Translation function: Call Translate signal on UI interface, which returns a boost::optional result.
std::string HexStr(const T itbegin, const T itend, bool fSpaces=false)
bool IsValid() const
Check whether this private key is valid.
boost::signals2::signal< void(const std::string &title, int nProgress)> ShowProgress
Show progress e.g.
UniValue JSONRPCError(int code, const std::string &message)
void GetAllReserveKeys(std::set< CKeyID > &setAddress) const
bool SetString(const char *pszSecret)
@ RPC_WALLET_ERROR
Invalid IP/Subnet.
std::string HelpExampleRpc(std::string methodname, std::string args)
256-bit unsigned big integer.
CPubKey GetPubKey() const
Compute the public key from a private key.
Serialized script, used inside transaction inputs and outputs.
uint256 GetBlockHash() const
std::string DecodeDumpString(const std::string &str)
int Height() const
Return the maximal height in the chain.
std::string HelpExampleCli(std::string methodname, std::string args)
@ RPC_INVALID_ADDRESS_OR_KEY
Unexpected type was passed as parameter.
bool IsCompressed() const
Check whether this is a compressed public key.
An encapsulated public key.
An encapsulated private key.
bool VerifyPubKey(const CPubKey &vchPubKey) const
Verify thoroughly whether a private key and a public key match.
UniValue bip38encrypt(const UniValue ¶ms, bool fHelp)
bool HaveKey(const CKeyID &address) const
Check whether a key corresponding to a given address is present in the store.
std::string BIP38_Encrypt(std::string strAddress, std::string strPassphrase, uint256 privKey, bool fCompressed)
bool push_back(const UniValue &val)
std::map< CKeyID, CKeyMetadata > mapKeyMetadata
bool AddWatchOnly(const CScript &dest)
Adds a watch-only address to the store, and saves it to disk.
CBlockIndex * Tip(bool fProofOfStake=false) const
Returns the index entry for the tip of this chain, or NULL if none.
@ RPC_TYPE_ERROR
Server is in safe mode, and command is not allowed in safe mode.
void ReacceptWalletTransactions()
The block chain is a tree shaped structure starting with the genesis block at the root,...
virtual bool HaveWatchOnly(const CScript &dest) const
CTxDestination Get() const
UniValue bip38decrypt(const UniValue ¶ms, bool fHelp)
bool GetKey(const CKeyID &address, CKey &keyOut) const
GetKey implementation that can derive a HD private key on the fly.
bool BIP38_Decrypt(std::string strPassphrase, std::string strEncryptedKey, uint256 &privKey, bool &fCompressed)
UniValue importaddress(const UniValue ¶ms, bool fHelp)
UniValue importwallet(const UniValue ¶ms, bool fHelp)
CBlockIndex * Genesis() const
Returns the index entry for the genesis block of this chain, or NULL if none.
std::map< CTxDestination, CAddressBookData > mapAddressBook
CKeyID GetID() const
Get the KeyID of this public key (hash of its serialization)
std::string ToString() const