Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/rpcdump.cpp
Show First 20 Lines • Show All 126 Lines • ▼ Show 20 Lines | bool fRescan = true; | ||||
} | } | ||||
if (fRescan && !reserver.reserve()) { | if (fRescan && !reserver.reserve()) { | ||||
throw JSONRPCError(RPC_WALLET_ERROR, | throw JSONRPCError(RPC_WALLET_ERROR, | ||||
"Wallet is currently rescanning. Abort existing " | "Wallet is currently rescanning. Abort existing " | ||||
"rescan or wait."); | "rescan or wait."); | ||||
} | } | ||||
CBitcoinSecret vchSecret; | CKey key = DecodeSecret(strSecret); | ||||
bool fGood = vchSecret.SetString(strSecret); | |||||
if (!fGood) { | |||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | |||||
"Invalid private key encoding"); | |||||
} | |||||
CKey key = vchSecret.GetKey(); | |||||
if (!key.IsValid()) { | if (!key.IsValid()) { | ||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | ||||
"Private key outside allowed range"); | "Invalid private key encoding"); | ||||
} | } | ||||
CPubKey pubkey = key.GetPubKey(); | CPubKey pubkey = key.GetPubKey(); | ||||
assert(key.VerifyPubKey(pubkey)); | assert(key.VerifyPubKey(pubkey)); | ||||
CKeyID vchAddress = pubkey.GetID(); | CKeyID vchAddress = pubkey.GetID(); | ||||
{ | { | ||||
pwallet->MarkDirty(); | pwallet->MarkDirty(); | ||||
// We don't know which corresponding address will be used; label | // We don't know which corresponding address will be used; label | ||||
▲ Show 20 Lines • Show All 471 Lines • ▼ Show 20 Lines | bool fGood = true; | ||||
continue; | continue; | ||||
} | } | ||||
std::vector<std::string> vstr; | std::vector<std::string> vstr; | ||||
boost::split(vstr, line, boost::is_any_of(" ")); | boost::split(vstr, line, boost::is_any_of(" ")); | ||||
if (vstr.size() < 2) { | if (vstr.size() < 2) { | ||||
continue; | continue; | ||||
} | } | ||||
CBitcoinSecret vchSecret; | CKey key = DecodeSecret(vstr[0]); | ||||
if (vchSecret.SetString(vstr[0])) { | if (key.IsValid()) { | ||||
CKey key = vchSecret.GetKey(); | |||||
CPubKey pubkey = key.GetPubKey(); | CPubKey pubkey = key.GetPubKey(); | ||||
assert(key.VerifyPubKey(pubkey)); | assert(key.VerifyPubKey(pubkey)); | ||||
CKeyID keyid = pubkey.GetID(); | CKeyID keyid = pubkey.GetID(); | ||||
if (pwallet->HaveKey(keyid)) { | if (pwallet->HaveKey(keyid)) { | ||||
LogPrintf("Skipping import of %s (key already present)\n", | LogPrintf("Skipping import of %s (key already present)\n", | ||||
EncodeDestination(keyid, config)); | EncodeDestination(keyid, config)); | ||||
continue; | continue; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 102 Lines • ▼ Show 20 Lines | UniValue dumpprivkey(const Config &config, const JSONRPCRequest &request) { | ||||
if (keyid.IsNull()) { | if (keyid.IsNull()) { | ||||
throw JSONRPCError(RPC_TYPE_ERROR, "Address does not refer to a key"); | throw JSONRPCError(RPC_TYPE_ERROR, "Address does not refer to a key"); | ||||
} | } | ||||
CKey vchSecret; | CKey vchSecret; | ||||
if (!pwallet->GetKey(keyid, vchSecret)) { | if (!pwallet->GetKey(keyid, vchSecret)) { | ||||
throw JSONRPCError(RPC_WALLET_ERROR, "Private key for address " + | throw JSONRPCError(RPC_WALLET_ERROR, "Private key for address " + | ||||
strAddress + " is not known"); | strAddress + " is not known"); | ||||
} | } | ||||
return CBitcoinSecret(vchSecret).ToString(); | return EncodeSecret(vchSecret); | ||||
} | } | ||||
UniValue dumpwallet(const Config &config, const JSONRPCRequest &request) { | UniValue dumpwallet(const Config &config, const JSONRPCRequest &request) { | ||||
CWallet *const pwallet = GetWalletForJSONRPCRequest(request); | CWallet *const pwallet = GetWalletForJSONRPCRequest(request); | ||||
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 94 Lines • ▼ Show 20 Lines | UniValue dumpwallet(const Config &config, const JSONRPCRequest &request) { | ||||
for (std::vector<std::pair<int64_t, CKeyID>>::const_iterator it = | for (std::vector<std::pair<int64_t, CKeyID>>::const_iterator it = | ||||
vKeyBirth.begin(); | vKeyBirth.begin(); | ||||
it != vKeyBirth.end(); it++) { | it != vKeyBirth.end(); it++) { | ||||
const CKeyID &keyid = it->second; | const CKeyID &keyid = it->second; | ||||
std::string strTime = FormatISO8601DateTime(it->first); | std::string strTime = FormatISO8601DateTime(it->first); | ||||
std::string strAddr = EncodeDestination(keyid, config); | std::string strAddr = EncodeDestination(keyid, config); | ||||
CKey key; | CKey key; | ||||
if (pwallet->GetKey(keyid, key)) { | if (pwallet->GetKey(keyid, key)) { | ||||
file << strprintf("%s %s ", CBitcoinSecret(key).ToString(), | file << strprintf("%s %s ", EncodeSecret(key), strTime); | ||||
strTime); | |||||
if (pwallet->mapAddressBook.count(keyid)) { | if (pwallet->mapAddressBook.count(keyid)) { | ||||
file << strprintf( | file << strprintf( | ||||
"label=%s", | "label=%s", | ||||
EncodeDumpString(pwallet->mapAddressBook[keyid].name)); | EncodeDumpString(pwallet->mapAddressBook[keyid].name)); | ||||
} else if (keyid == masterKeyID) { | } else if (keyid == masterKeyID) { | ||||
file << "hdmaster=1"; | file << "hdmaster=1"; | ||||
} else if (mapKeyPool.count(keyid)) { | } else if (mapKeyPool.count(keyid)) { | ||||
file << "reserve=1"; | file << "reserve=1"; | ||||
▲ Show 20 Lines • Show All 173 Lines • ▼ Show 20 Lines | try { | ||||
pwallet->SetAddressBook(dest, label, "receive"); | pwallet->SetAddressBook(dest, label, "receive"); | ||||
} | } | ||||
// Import private keys. | // Import private keys. | ||||
if (keys.size()) { | if (keys.size()) { | ||||
for (size_t i = 0; i < keys.size(); i++) { | for (size_t i = 0; i < keys.size(); i++) { | ||||
const std::string &privkey = keys[i].get_str(); | const std::string &privkey = keys[i].get_str(); | ||||
CBitcoinSecret vchSecret; | CKey key = DecodeSecret(privkey); | ||||
bool fGood = vchSecret.SetString(privkey); | |||||
if (!fGood) { | |||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | |||||
"Invalid private key encoding"); | |||||
} | |||||
CKey key = vchSecret.GetKey(); | |||||
if (!key.IsValid()) { | if (!key.IsValid()) { | ||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | ||||
"Private key outside allowed range"); | "Invalid private key encoding"); | ||||
} | } | ||||
CPubKey pubkey = key.GetPubKey(); | CPubKey pubkey = key.GetPubKey(); | ||||
assert(key.VerifyPubKey(pubkey)); | assert(key.VerifyPubKey(pubkey)); | ||||
CKeyID vchAddress = pubkey.GetID(); | CKeyID vchAddress = pubkey.GetID(); | ||||
pwallet->MarkDirty(); | pwallet->MarkDirty(); | ||||
pwallet->SetAddressBook(vchAddress, label, "receive"); | pwallet->SetAddressBook(vchAddress, label, "receive"); | ||||
▲ Show 20 Lines • Show All 94 Lines • ▼ Show 20 Lines | try { | ||||
success = true; | success = true; | ||||
} | } | ||||
// Import private keys. | // Import private keys. | ||||
if (keys.size()) { | if (keys.size()) { | ||||
const std::string &strPrivkey = keys[0].get_str(); | const std::string &strPrivkey = keys[0].get_str(); | ||||
// Checks. | // Checks. | ||||
CBitcoinSecret vchSecret; | CKey key = DecodeSecret(strPrivkey); | ||||
bool fGood = vchSecret.SetString(strPrivkey); | |||||
if (!fGood) { | |||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | |||||
"Invalid private key encoding"); | |||||
} | |||||
CKey key = vchSecret.GetKey(); | |||||
if (!key.IsValid()) { | if (!key.IsValid()) { | ||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | ||||
"Private key outside allowed range"); | "Invalid private key encoding"); | ||||
} | } | ||||
CPubKey pubKey = key.GetPubKey(); | CPubKey pubKey = key.GetPubKey(); | ||||
assert(key.VerifyPubKey(pubKey)); | assert(key.VerifyPubKey(pubKey)); | ||||
CTxDestination pubkey_dest = pubKey.GetID(); | CTxDestination pubkey_dest = pubKey.GetID(); | ||||
// Consistency check. | // Consistency check. | ||||
▲ Show 20 Lines • Show All 287 Lines • Show Last 20 Lines |