Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/rpcdump.cpp
Show First 20 Lines • Show All 48 Lines • ▼ Show 20 Lines | for (uint8_t c : str) { | ||||
ret << '%' << HexStr(&c, &c + 1); | ret << '%' << HexStr(&c, &c + 1); | ||||
} else { | } else { | ||||
ret << c; | ret << c; | ||||
} | } | ||||
} | } | ||||
return ret.str(); | return ret.str(); | ||||
} | } | ||||
std::string DecodeDumpString(const std::string &str) { | static std::string DecodeDumpString(const std::string &str) { | ||||
std::stringstream ret; | std::stringstream ret; | ||||
for (unsigned int pos = 0; pos < str.length(); pos++) { | for (unsigned int pos = 0; pos < str.length(); pos++) { | ||||
uint8_t c = str[pos]; | uint8_t c = str[pos]; | ||||
if (c == '%' && pos + 2 < str.length()) { | if (c == '%' && pos + 2 < str.length()) { | ||||
c = (((str[pos + 1] >> 6) * 9 + ((str[pos + 1] - '0') & 15)) << 4) | | c = (((str[pos + 1] >> 6) * 9 + ((str[pos + 1] - '0') & 15)) << 4) | | ||||
((str[pos + 2] >> 6) * 9 + ((str[pos + 2] - '0') & 15)); | ((str[pos + 2] >> 6) * 9 + ((str[pos + 2] - '0') & 15)); | ||||
pos += 2; | pos += 2; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 136 Lines • ▼ Show 20 Lines | UniValue abortrescan(const Config &config, const JSONRPCRequest &request) { | ||||
if (!pwallet->IsScanning() || pwallet->IsAbortingRescan()) { | if (!pwallet->IsScanning() || pwallet->IsAbortingRescan()) { | ||||
return false; | return false; | ||||
} | } | ||||
pwallet->AbortRescan(); | pwallet->AbortRescan(); | ||||
return true; | return true; | ||||
} | } | ||||
void ImportAddress(CWallet *, const CTxDestination &dest, | static void ImportAddress(CWallet *, const CTxDestination &dest, | ||||
const std::string &strLabel); | const std::string &strLabel); | ||||
void ImportScript(CWallet *const pwallet, const CScript &script, | static void ImportScript(CWallet *const pwallet, const CScript &script, | ||||
const std::string &strLabel, bool isRedeemScript) { | const std::string &strLabel, bool isRedeemScript) { | ||||
if (!isRedeemScript && ::IsMine(*pwallet, script) == ISMINE_SPENDABLE) { | if (!isRedeemScript && ::IsMine(*pwallet, script) == ISMINE_SPENDABLE) { | ||||
throw JSONRPCError(RPC_WALLET_ERROR, "The wallet already contains the " | throw JSONRPCError(RPC_WALLET_ERROR, "The wallet already contains the " | ||||
"private key for this address or " | "private key for this address or " | ||||
"script"); | "script"); | ||||
} | } | ||||
pwallet->MarkDirty(); | pwallet->MarkDirty(); | ||||
Show All 11 Lines | static void ImportScript(CWallet *const pwallet, const CScript &script, | ||||
} else { | } else { | ||||
CTxDestination destination; | CTxDestination destination; | ||||
if (ExtractDestination(script, destination)) { | if (ExtractDestination(script, destination)) { | ||||
pwallet->SetAddressBook(destination, strLabel, "receive"); | pwallet->SetAddressBook(destination, strLabel, "receive"); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
void ImportAddress(CWallet *const pwallet, const CTxDestination &dest, | static void ImportAddress(CWallet *const pwallet, const CTxDestination &dest, | ||||
const std::string &strLabel) { | const std::string &strLabel) { | ||||
CScript script = GetScriptForDestination(dest); | CScript script = GetScriptForDestination(dest); | ||||
ImportScript(pwallet, script, strLabel, false); | ImportScript(pwallet, script, strLabel, false); | ||||
// add to address book or update label | // add to address book or update label | ||||
if (IsValidDestination(dest)) { | if (IsValidDestination(dest)) { | ||||
pwallet->SetAddressBook(dest, strLabel, "receive"); | pwallet->SetAddressBook(dest, strLabel, "receive"); | ||||
} | } | ||||
} | } | ||||
▲ Show 20 Lines • Show All 655 Lines • ▼ Show 20 Lines | UniValue dumpwallet(const Config &config, const JSONRPCRequest &request) { | ||||
file.close(); | file.close(); | ||||
UniValue reply(UniValue::VOBJ); | UniValue reply(UniValue::VOBJ); | ||||
reply.pushKV("filename", filepath.string()); | reply.pushKV("filename", filepath.string()); | ||||
return reply; | return reply; | ||||
} | } | ||||
UniValue ProcessImport(CWallet *const pwallet, const UniValue &data, | static UniValue ProcessImport(CWallet *const pwallet, const UniValue &data, | ||||
const int64_t timestamp) { | const int64_t timestamp) { | ||||
try { | try { | ||||
bool success = false; | bool success = false; | ||||
// Required fields. | // Required fields. | ||||
const UniValue &scriptPubKey = data["scriptPubKey"]; | const UniValue &scriptPubKey = data["scriptPubKey"]; | ||||
// Should have script or JSON with "address". | // Should have script or JSON with "address". | ||||
if (!(scriptPubKey.getType() == UniValue::VOBJ && | if (!(scriptPubKey.getType() == UniValue::VOBJ && | ||||
▲ Show 20 Lines • Show All 351 Lines • ▼ Show 20 Lines | try { | ||||
UniValue result = UniValue(UniValue::VOBJ); | UniValue result = UniValue(UniValue::VOBJ); | ||||
result.pushKV("success", UniValue(false)); | result.pushKV("success", UniValue(false)); | ||||
result.pushKV("error", | result.pushKV("error", | ||||
JSONRPCError(RPC_MISC_ERROR, "Missing required fields")); | JSONRPCError(RPC_MISC_ERROR, "Missing required fields")); | ||||
return result; | return result; | ||||
} | } | ||||
} | } | ||||
int64_t GetImportTimestamp(const UniValue &data, int64_t now) { | static int64_t GetImportTimestamp(const UniValue &data, int64_t now) { | ||||
if (data.exists("timestamp")) { | if (data.exists("timestamp")) { | ||||
const UniValue ×tamp = data["timestamp"]; | const UniValue ×tamp = data["timestamp"]; | ||||
if (timestamp.isNum()) { | if (timestamp.isNum()) { | ||||
return timestamp.get_int64(); | return timestamp.get_int64(); | ||||
} else if (timestamp.isStr() && timestamp.get_str() == "now") { | } else if (timestamp.isStr() && timestamp.get_str() == "now") { | ||||
return now; | return now; | ||||
} | } | ||||
throw JSONRPCError(RPC_TYPE_ERROR, | throw JSONRPCError(RPC_TYPE_ERROR, | ||||
▲ Show 20 Lines • Show All 194 Lines • Show Last 20 Lines |