Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/rpcdump.cpp
Show First 20 Lines • Show All 185 Lines • ▼ Show 20 Lines | bool fRescan = true; | ||||
if (!pwallet->AddKeyPubKey(key, pubkey)) { | if (!pwallet->AddKeyPubKey(key, pubkey)) { | ||||
throw JSONRPCError(RPC_WALLET_ERROR, | throw JSONRPCError(RPC_WALLET_ERROR, | ||||
"Error adding key to wallet"); | "Error adding key to wallet"); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
if (fRescan) { | if (fRescan) { | ||||
int64_t scanned_time = | |||||
pwallet->RescanFromTime(TIMESTAMP_MIN, reserver, true /* update */); | pwallet->RescanFromTime(TIMESTAMP_MIN, reserver, true /* update */); | ||||
if (pwallet->IsAbortingRescan()) { | |||||
throw JSONRPCError(RPC_MISC_ERROR, "Rescan aborted by user."); | |||||
} | |||||
if (scanned_time > TIMESTAMP_MIN) { | |||||
throw JSONRPCError(RPC_WALLET_ERROR, | |||||
"Rescan was unable to fully rescan the " | |||||
"blockchain. Some transactions may be missing."); | |||||
} | |||||
} | } | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
UniValue abortrescan(const Config &config, const JSONRPCRequest &request) { | UniValue abortrescan(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)) { | ||||
▲ Show 20 Lines • Show All 150 Lines • ▼ Show 20 Lines | if (!request.params[3].isNull()) { | ||||
ImportScript(pwallet, CScript(data.begin(), data.end()), strLabel, | ImportScript(pwallet, CScript(data.begin(), data.end()), strLabel, | ||||
fP2SH); | fP2SH); | ||||
} else { | } else { | ||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | ||||
"Invalid Bitcoin address or script"); | "Invalid Bitcoin address or script"); | ||||
} | } | ||||
} | } | ||||
if (fRescan) { | if (fRescan) { | ||||
int64_t scanned_time = | |||||
pwallet->RescanFromTime(TIMESTAMP_MIN, reserver, true /* update */); | pwallet->RescanFromTime(TIMESTAMP_MIN, reserver, true /* update */); | ||||
if (pwallet->IsAbortingRescan()) { | |||||
throw JSONRPCError(RPC_MISC_ERROR, "Rescan aborted by user."); | |||||
} | |||||
if (scanned_time > TIMESTAMP_MIN) { | |||||
throw JSONRPCError(RPC_WALLET_ERROR, | |||||
"Rescan was unable to fully rescan the " | |||||
"blockchain. Some transactions may be missing."); | |||||
} | |||||
pwallet->ReacceptWalletTransactions(); | pwallet->ReacceptWalletTransactions(); | ||||
} | } | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
UniValue importprunedfunds(const Config &config, | UniValue importprunedfunds(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
▲ Show 20 Lines • Show All 195 Lines • ▼ Show 20 Lines | if (!pubKey.IsFullyValid()) { | ||||
for (const auto &dest : GetAllDestinationsForKey(pubKey)) { | for (const auto &dest : GetAllDestinationsForKey(pubKey)) { | ||||
ImportAddress(pwallet, dest, strLabel); | ImportAddress(pwallet, dest, strLabel); | ||||
} | } | ||||
ImportScript(pwallet, GetScriptForRawPubKey(pubKey), strLabel, false); | ImportScript(pwallet, GetScriptForRawPubKey(pubKey), strLabel, false); | ||||
pwallet->LearnAllRelatedScripts(pubKey); | pwallet->LearnAllRelatedScripts(pubKey); | ||||
} | } | ||||
if (fRescan) { | if (fRescan) { | ||||
int64_t scanned_time = | |||||
pwallet->RescanFromTime(TIMESTAMP_MIN, reserver, true /* update */); | pwallet->RescanFromTime(TIMESTAMP_MIN, reserver, true /* update */); | ||||
if (pwallet->IsAbortingRescan()) { | |||||
throw JSONRPCError(RPC_MISC_ERROR, "Rescan aborted by user."); | |||||
} | |||||
if (scanned_time > TIMESTAMP_MIN) { | |||||
throw JSONRPCError(RPC_WALLET_ERROR, | |||||
"Rescan was unable to fully rescan the " | |||||
"blockchain. Some transactions may be missing."); | |||||
} | |||||
pwallet->ReacceptWalletTransactions(); | pwallet->ReacceptWalletTransactions(); | ||||
} | } | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
UniValue importwallet(const Config &config, const JSONRPCRequest &request) { | UniValue importwallet(const Config &config, const JSONRPCRequest &request) { | ||||
CWallet *const pwallet = GetWalletForJSONRPCRequest(request); | CWallet *const pwallet = GetWalletForJSONRPCRequest(request); | ||||
▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | bool fGood = true; | ||||
throw JSONRPCError(RPC_INVALID_PARAMETER, | throw JSONRPCError(RPC_INVALID_PARAMETER, | ||||
"Cannot open wallet dump file"); | "Cannot open wallet dump file"); | ||||
} | } | ||||
nTimeBegin = chainActive.Tip()->GetBlockTime(); | nTimeBegin = chainActive.Tip()->GetBlockTime(); | ||||
int64_t nFilesize = std::max((int64_t)1, (int64_t)file.tellg()); | int64_t nFilesize = std::max((int64_t)1, (int64_t)file.tellg()); | ||||
file.seekg(0, file.beg); | file.seekg(0, file.beg); | ||||
// Use uiInterface.ShowProgress instead of pwallet.ShowProgress because | |||||
// pwallet.ShowProgress has a cancel button tied to AbortRescan which we | |||||
// don't want for this progress bar showing the import progress. | |||||
// uiInterface.ShowProgress does not have a cancel button. | |||||
// show progress dialog in GUI | // show progress dialog in GUI | ||||
pwallet->ShowProgress(_("Importing..."), 0); | uiInterface.ShowProgress(_("Importing..."), 0, false); | ||||
while (file.good()) { | while (file.good()) { | ||||
pwallet->ShowProgress( | uiInterface.ShowProgress( | ||||
"", std::max(1, std::min(99, (int)(((double)file.tellg() / | "", | ||||
std::max(1, std::min(99, (int)(((double)file.tellg() / | |||||
(double)nFilesize) * | (double)nFilesize) * | ||||
100)))); | 100))), | ||||
false); | |||||
std::string line; | std::string line; | ||||
std::getline(file, line); | std::getline(file, line); | ||||
if (line.empty() || line[0] == '#') { | if (line.empty() || line[0] == '#') { | ||||
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(" ")); | ||||
▲ Show 20 Lines • Show All 59 Lines • ▼ Show 20 Lines | bool fGood = true; | ||||
birth_time; | birth_time; | ||||
nTimeBegin = std::min(nTimeBegin, birth_time); | nTimeBegin = std::min(nTimeBegin, birth_time); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
file.close(); | file.close(); | ||||
// hide progress dialog in GUI | // hide progress dialog in GUI | ||||
pwallet->ShowProgress("", 100); | uiInterface.ShowProgress("", 100, false); | ||||
pwallet->UpdateTimeFirstKey(nTimeBegin); | pwallet->UpdateTimeFirstKey(nTimeBegin); | ||||
} | } | ||||
// hide progress dialog in GUI | |||||
uiInterface.ShowProgress("", 100, false); | |||||
int64_t scanned_time = | |||||
pwallet->RescanFromTime(nTimeBegin, reserver, false /* update */); | pwallet->RescanFromTime(nTimeBegin, reserver, false /* update */); | ||||
if (pwallet->IsAbortingRescan()) { | |||||
throw JSONRPCError(RPC_MISC_ERROR, "Rescan aborted by user."); | |||||
} | |||||
if (scanned_time > nTimeBegin) { | |||||
throw JSONRPCError(RPC_WALLET_ERROR, | |||||
"Rescan was unable to fully rescan the blockchain. " | |||||
"Some transactions may be missing."); | |||||
} | |||||
pwallet->MarkDirty(); | pwallet->MarkDirty(); | ||||
if (!fGood) { | if (!fGood) { | ||||
throw JSONRPCError(RPC_WALLET_ERROR, | throw JSONRPCError(RPC_WALLET_ERROR, | ||||
"Error adding some keys/scripts to wallet"); | "Error adding some keys/scripts to wallet"); | ||||
} | } | ||||
return NullUniValue; | return NullUniValue; | ||||
▲ Show 20 Lines • Show All 681 Lines • ▼ Show 20 Lines | UniValue response(UniValue::VARR); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
if (fRescan && fRunScan && requests.size()) { | if (fRescan && fRunScan && requests.size()) { | ||||
int64_t scannedTime = pwallet->RescanFromTime( | int64_t scannedTime = pwallet->RescanFromTime( | ||||
nLowestTimestamp, reserver, true /* update */); | nLowestTimestamp, reserver, true /* update */); | ||||
pwallet->ReacceptWalletTransactions(); | pwallet->ReacceptWalletTransactions(); | ||||
if (pwallet->IsAbortingRescan()) { | |||||
throw JSONRPCError(RPC_MISC_ERROR, "Rescan aborted by user."); | |||||
} | |||||
if (scannedTime > nLowestTimestamp) { | if (scannedTime > nLowestTimestamp) { | ||||
std::vector<UniValue> results = response.getValues(); | std::vector<UniValue> results = response.getValues(); | ||||
response.clear(); | response.clear(); | ||||
response.setArray(); | response.setArray(); | ||||
size_t i = 0; | size_t i = 0; | ||||
for (const UniValue &request : requests.getValues()) { | for (const UniValue &request : requests.getValues()) { | ||||
// If key creation date is within the successfully scanned | // If key creation date is within the successfully scanned | ||||
// range, or if the import result already has an error set, let | // range, or if the import result already has an error set, let | ||||
▲ Show 20 Lines • Show All 60 Lines • Show Last 20 Lines |