Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/rpcdump.cpp
Show First 20 Lines • Show All 1,288 Lines • ▼ Show 20 Lines | UniValue importmulti(const Config &config, const JSONRPCRequest &mainRequest) { | ||||
} | } | ||||
if (fRescan && fRunScan && requests.size()) { | if (fRescan && fRunScan && requests.size()) { | ||||
CBlockIndex *pindex = | CBlockIndex *pindex = | ||||
nLowestTimestamp > minimumTimestamp | nLowestTimestamp > minimumTimestamp | ||||
? chainActive.FindEarliestAtLeast( | ? chainActive.FindEarliestAtLeast( | ||||
std::max<int64_t>(nLowestTimestamp - TIMESTAMP_WINDOW, 0)) | std::max<int64_t>(nLowestTimestamp - TIMESTAMP_WINDOW, 0)) | ||||
: chainActive.Genesis(); | : chainActive.Genesis(); | ||||
CBlockIndex *scannedRange = nullptr; | CBlockIndex *scanFailed = nullptr; | ||||
if (pindex) { | if (pindex) { | ||||
scannedRange = pwallet->ScanForWalletTransactions(pindex, true); | scanFailed = pwallet->ScanForWalletTransactions(pindex, true); | ||||
pwallet->ReacceptWalletTransactions(); | pwallet->ReacceptWalletTransactions(); | ||||
} | } | ||||
if (!scannedRange || scannedRange->nHeight > pindex->nHeight) { | if (scanFailed) { | ||||
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 | ||||
// the result stand unmodified. Otherwise replace the result | // the result stand unmodified. Otherwise replace the result | ||||
// with an error message. | // with an error message. | ||||
if (GetImportTimestamp(request, now) - TIMESTAMP_WINDOW >= | if (GetImportTimestamp(request, now) - TIMESTAMP_WINDOW > | ||||
scannedRange->GetBlockTimeMax() || | scanFailed->GetBlockTimeMax() || | ||||
results.at(i).exists("error")) { | results.at(i).exists("error")) { | ||||
response.push_back(results.at(i)); | response.push_back(results.at(i)); | ||||
} else { | } else { | ||||
UniValue result = UniValue(UniValue::VOBJ); | UniValue result = UniValue(UniValue::VOBJ); | ||||
result.pushKV("success", UniValue(false)); | result.pushKV("success", UniValue(false)); | ||||
result.pushKV( | result.pushKV( | ||||
"error", | "error", | ||||
JSONRPCError( | JSONRPCError( | ||||
RPC_MISC_ERROR, | RPC_MISC_ERROR, | ||||
strprintf("Failed to rescan before time %d, " | strprintf( | ||||
"transactions may be missing.", | "Rescan failed for key with creation timestamp " | ||||
scannedRange->GetBlockTimeMax()))); | "%d. There was an error reading a block from " | ||||
"time %d, which is after or within %d seconds " | |||||
"of key creation, and could contain " | |||||
"transactions pertaining to the key. As a " | |||||
"result, transactions and coins using this key " | |||||
"may not appear in the wallet. This error " | |||||
"could be caused by pruning or data corruption " | |||||
"(see bitcoind log for details) and could be " | |||||
"dealt with by downloading and rescanning the " | |||||
"relevant blocks (see -reindex and -rescan " | |||||
"options).", | |||||
GetImportTimestamp(request, now), | |||||
scanFailed->GetBlockTimeMax(), | |||||
TIMESTAMP_WINDOW))); | |||||
response.push_back(std::move(result)); | response.push_back(std::move(result)); | ||||
} | } | ||||
++i; | ++i; | ||||
} | } | ||||
} | } | ||||
} | } | ||||
return response; | return response; | ||||
Show All 27 Lines |