16 #include <boost/algorithm/string.hpp>
17 #include <boost/date_time/posix_time/posix_time.hpp>
18 #include "json/json_spirit_value.h"
25 std::string
static EncodeDumpTime(int64_t nTime) {
29 int64_t
static DecodeDumpTime(
const std::string &str) {
30 static const boost::posix_time::ptime epoch = boost::posix_time::from_time_t(0);
31 static const std::locale loc(std::locale::classic(),
32 new boost::posix_time::time_input_facet(
"%Y-%m-%dT%H:%M:%SZ"));
33 std::istringstream iss(str);
35 boost::posix_time::ptime ptime(boost::date_time::not_a_date_time);
37 if (ptime.is_not_a_date_time())
39 return (ptime - epoch).total_seconds();
42 std::string
static EncodeDumpString(
const std::string &str) {
43 std::stringstream ret;
44 BOOST_FOREACH(
unsigned char c, str) {
45 if (c <= 32 || c >= 128 || c ==
'%') {
46 ret <<
'%' <<
HexStr(&c, &c + 1);
55 std::stringstream ret;
56 for (
unsigned int pos = 0; pos < str.length(); pos++) {
57 unsigned char c = str[pos];
58 if (c ==
'%' && pos+2 < str.length()) {
59 c = (((str[pos+1]>>6)*9+((str[pos+1]-
'0')&15)) << 4) |
60 ((str[pos+2]>>6)*9+((str[pos+2]-
'0')&15));
70 if (fHelp || params.size() < 1 || params.size() > 3)
72 "importprivkey \"anoncoinprivkey\" ( \"label\" rescan )\n"
73 "\nAdds a private key (as returned by dumpprivkey) to your wallet.\n"
75 "1. \"anoncoinprivkey\" (string, required) The private key (see dumpprivkey)\n"
76 "2. \"label\" (string, optional) an optional label\n"
77 "3. rescan (boolean, optional, default=true) Rescan the wallet for transactions\n"
79 "\nDump a private key\n"
81 "\nImport the private key\n"
83 "\nImport using a label\n"
85 "\nAs a json rpc call\n"
91 string strSecret = params[0].get_str();
93 if (params.size() > 1)
94 strLabel = params[1].get_str();
98 if (params.size() > 2)
99 fRescan = params[2].get_bool();
102 bool fGood = vchSecret.
SetString(strSecret);
137 if (fHelp || params.size() < 1 || params.size() > 3)
139 "importaddress <address> [label] [rescan=true]\n"
140 "Adds an address or script (in hex) that can be watched as if it were in your wallet but cannot be used to spend.");
147 }
else if (
IsHex(params[0].get_str())) {
148 std::vector<unsigned char> data(
ParseHex(params[0].get_str()));
149 script =
CScript(data.begin(), data.end());
154 string strLabel =
"";
155 if (params.size() > 1)
156 strLabel = params[1].get_str();
160 if (params.size() > 2)
161 fRescan = params[2].get_bool();
192 if (fHelp || params.size() != 1)
194 "importwallet \"filename\"\n"
195 "\nImports keys from a wallet dump file (see dumpwallet).\n"
197 "1. \"filename\" (string, required) The wallet file\n"
199 "\nDump the wallet\n"
201 "\nImport the wallet\n"
203 "\nImport using the json rpc call\n"
210 file.open(params[0].get_str().c_str(), std::ios::in | std::ios::ate);
218 int64_t nFilesize = std::max((int64_t)1, (int64_t)file.tellg());
219 file.seekg(0, file.beg);
222 while (file.good()) {
223 pwalletMain->
ShowProgress(
"", std::max(1, std::min(99, (
int)(((
double)file.tellg() / (double)nFilesize) * 100))));
225 std::getline(file, line);
226 if (line.empty() || line[0] ==
'#')
229 std::vector<std::string> vstr;
230 boost::split(vstr, line, boost::is_any_of(
" "));
243 int64_t nTime = DecodeDumpTime(vstr[1]);
244 std::string strLabel;
246 for (
unsigned int nStr = 2; nStr < vstr.size(); nStr++) {
247 if (boost::algorithm::starts_with(vstr[nStr],
"#"))
249 if (vstr[nStr] ==
"change=1")
251 if (vstr[nStr] ==
"reserve=1")
253 if (boost::algorithm::starts_with(vstr[nStr],
"label=")) {
266 nTimeBegin = std::min(nTimeBegin, nTime);
272 while (pindex && pindex->
pprev && pindex->
nTime > nTimeBegin - 7200)
273 pindex = pindex->
pprev;
290 if (fHelp || params.size() != 1)
292 "dumpprivkey \"anoncoinaddress\"\n"
293 "\nReveals the private key corresponding to 'anoncoinaddress'.\n"
294 "Then the importprivkey can be used with this output\n"
296 "1. \"anoncoinaddress\" (string, required) The anoncoin address for the private key\n"
298 "\"key\" (string) The private key\n"
307 string strAddress = params[0].get_str();
323 if (fHelp || params.size() != 1)
325 "dumpwallet \"filename\"\n"
326 "\nDumps all wallet keys in a human-readable format.\n"
328 "1. \"filename\" (string, required) The filename\n"
337 file.open(params[0].get_str().c_str());
341 std::map<CKeyID, int64_t> mapKeyBirth;
342 std::set<CKeyID> setKeyPool;
347 std::vector<std::pair<int64_t, CKeyID> > vKeyBirth;
348 for (std::map<CKeyID, int64_t>::const_iterator it = mapKeyBirth.begin(); it != mapKeyBirth.end(); it++) {
349 vKeyBirth.push_back(std::make_pair(it->second, it->first));
352 std::sort(vKeyBirth.begin(), vKeyBirth.end());
360 for (std::vector<std::pair<int64_t, CKeyID> >::const_iterator it = vKeyBirth.begin(); it != vKeyBirth.end(); it++) {
361 const CKeyID &keyid = it->second;
362 std::string strTime = EncodeDumpTime(it->first);
368 }
else if (setKeyPool.count(keyid)) {
376 file <<
"# End of dump\n";
std::string DecodeDumpString(const std::string &str)
bool AddKeyPubKey(const CKey &key, const CPubKey &pubkey)
bool SetAddressBook(const CTxDestination &address, const std::string &strName, const std::string &purpose)
bool HaveKey(const CKeyID &address) const
std::map< CTxDestination, CAddressBookData > mapAddressBook
isminetype IsMine(const CKeyStore &keystore, const CTxDestination &dest)
std::string HelpExampleRpc(string methodname, string args)
CTxDestination Get() const
Value importwallet(const Array ¶ms, bool fHelp)
bool GetKeyID(CKeyID &keyID) const
void GetAllReserveKeys(std::set< CKeyID > &setAddress) const
bool IsHex(const string &str)
Value dumpwallet(const Array ¶ms, bool fHelp)
virtual bool HaveWatchOnly(const CScript &dest) const
Object JSONRPCError(int code, const string &message)
bool AddWatchOnly(const CScript &dest)
void GetKeyBirthTimes(std::map< CKeyID, int64_t > &mapKeyBirth) const
std::string DateTimeStrFormat(const char *pszFormat, int64_t nTime)
void ReacceptWalletTransactions()
bool GetKey(const CKeyID &address, CKey &keyOut) const
CChain chainActive
The currently-connected chain of blocks.
Value importprivkey(const Array ¶ms, bool fHelp)
void SetDestination(const CTxDestination &address)
CBlockIndex * Tip() const
Returns the index entry for the tip of this chain, or NULL if none.
int Height() const
Return the maximal height in the chain.
void EnsureWalletIsUnlocked()
CPubKey GetPubKey() const
A base58-encoded secret key.
An encapsulated public key.
base58-encoded Anoncoin addresses.
bool SetString(const char *pszSecret)
std::string ToString() const
const std::string CLIENT_DATE
bool SetString(const char *psz, unsigned int nVersionBytes=1)
CBlockIndex * Genesis() const
Returns the index entry for the genesis block of this chain, or NULL if none.
int ScanForWalletTransactions(CBlockIndex *pindexStart, bool fUpdate=false)
The block chain is a tree shaped structure starting with the genesis block at the root...
Serialized script, used inside transaction inputs and outputs.
std::string ToString() const
std::string _(const char *psz)
Translation function: Call Translate signal on UI interface, which returns a boost::optional result...
A reference to a CKey: the Hash160 of its serialized public key.
std::map< CKeyID, CKeyMetadata > mapKeyMetadata
boost::signals2::signal< void(const std::string &title, int nProgress)> ShowProgress
Show progress e.g.
std::string HelpExampleCli(string methodname, string args)
An encapsulated private key.
std::string HexStr(const T itbegin, const T itend, bool fSpaces=false)
vector< unsigned char > ParseHex(const char *psz)
const std::string CLIENT_BUILD
Value importaddress(const Array ¶ms, bool fHelp)
uint256 GetBlockHash() const
Value dumpprivkey(const Array ¶ms, bool fHelp)