aboutsummaryrefslogtreecommitdiff
path: root/src/wallet/rpcdump.cpp
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2017-02-22 12:42:55 +0100
committerWladimir J. van der Laan <laanwj@gmail.com>2017-02-22 12:43:11 +0100
commitba7220b5e82fcfbb7a4912a49e563944a428ab91 (patch)
treee02699dda0c3dde604769b02a480dfa3c24f4c83 /src/wallet/rpcdump.cpp
parenta8c57510381581eb38a9a28c676a6fe0ff796969 (diff)
parente2e2f4c856363bbb0e3b5ba4df225f3754c3db39 (diff)
Merge #9773: Return errors from importmulti if complete rescans are not successful
e2e2f4c Return errors from importmulti if complete rescans are not successful (Russell Yanofsky)
Diffstat (limited to 'src/wallet/rpcdump.cpp')
-rw-r--r--src/wallet/rpcdump.cpp25
1 files changed, 23 insertions, 2 deletions
diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp
index e95c71ac8a..8a9e7d1444 100644
--- a/src/wallet/rpcdump.cpp
+++ b/src/wallet/rpcdump.cpp
@@ -1074,11 +1074,32 @@ UniValue importmulti(const JSONRPCRequest& mainRequest)
if (fRescan && fRunScan && requests.size()) {
CBlockIndex* pindex = nLowestTimestamp > minimumTimestamp ? chainActive.FindEarliestAtLeast(std::max<int64_t>(nLowestTimestamp - 7200, 0)) : chainActive.Genesis();
-
+ CBlockIndex* scannedRange = nullptr;
if (pindex) {
- pwalletMain->ScanForWalletTransactions(pindex, true);
+ scannedRange = pwalletMain->ScanForWalletTransactions(pindex, true);
pwalletMain->ReacceptWalletTransactions();
}
+
+ if (!scannedRange || scannedRange->nHeight > pindex->nHeight) {
+ std::vector<UniValue> results = response.getValues();
+ response.clear();
+ response.setArray();
+ size_t i = 0;
+ for (const UniValue& request : requests.getValues()) {
+ // If key creation date is within the successfully scanned
+ // range, or if the import result already has an error set, let
+ // the result stand unmodified. Otherwise replace the result
+ // with an error message.
+ if (GetImportTimestamp(request, now) - 7200 >= scannedRange->GetBlockTimeMax() || results.at(i).exists("error")) {
+ response.push_back(results.at(i));
+ } else {
+ UniValue result = UniValue(UniValue::VOBJ);
+ result.pushKV("success", UniValue(false));
+ result.pushKV("error", JSONRPCError(RPC_MISC_ERROR, strprintf("Failed to rescan before time %d, transactions may be missing.", scannedRange->GetBlockTimeMax())));
+ response.push_back(std::move(result));
+ }
+ }
+ }
}
return response;