Skip to content

Commit 7e2a221

Browse files
committed
Merge #9829: Fix importmulti returning rescan errors for wrong keys
306bd72 Fix importmulti returning rescan errors for wrong keys (Russell Yanofsky) Tree-SHA512: ae9998236cbd3ff749d6b5c716bd76c9cec386b0708583e4912e4e05bf4584545258e1d0543aa5445024d2b5decf859a64f40c6503029773366a0f9a9ddf9b88
2 parents b7547fa + 306bd72 commit 7e2a221

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

src/wallet/rpcdump.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,6 +1098,7 @@ UniValue importmulti(const JSONRPCRequest& mainRequest)
10981098
result.pushKV("error", JSONRPCError(RPC_MISC_ERROR, strprintf("Failed to rescan before time %d, transactions may be missing.", scannedRange->GetBlockTimeMax())));
10991099
response.push_back(std::move(result));
11001100
}
1101+
++i;
11011102
}
11021103
}
11031104
}

src/wallet/test/wallet_tests.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -395,24 +395,35 @@ BOOST_FIXTURE_TEST_CASE(rescan, TestChain100Setup)
395395
BOOST_CHECK_EQUAL(wallet.GetImmatureBalance(), 50 * COIN);
396396
}
397397

398+
// Verify importmulti RPC returns failure for a key whose creation time is
399+
// before the missing block, and success for a key whose creation time is
400+
// after.
398401
{
399402
CWallet wallet;
400403
CWallet *backup = ::pwalletMain;
401404
::pwalletMain = &wallet;
405+
UniValue keys;
406+
keys.setArray();
402407
UniValue key;
403408
key.setObject();
404409
key.pushKV("scriptPubKey", HexStr(GetScriptForRawPubKey(coinbaseKey.GetPubKey())));
405410
key.pushKV("timestamp", 0);
406411
key.pushKV("internal", UniValue(true));
407-
UniValue keys;
408-
keys.setArray();
412+
keys.push_back(key);
413+
key.clear();
414+
key.setObject();
415+
CKey futureKey;
416+
futureKey.MakeNewKey(true);
417+
key.pushKV("scriptPubKey", HexStr(GetScriptForRawPubKey(futureKey.GetPubKey())));
418+
key.pushKV("timestamp", newTip->GetBlockTimeMax() + 7200);
419+
key.pushKV("internal", UniValue(true));
409420
keys.push_back(key);
410421
JSONRPCRequest request;
411422
request.params.setArray();
412423
request.params.push_back(keys);
413424

414425
UniValue response = importmulti(request);
415-
BOOST_CHECK_EQUAL(response.write(), strprintf("[{\"success\":false,\"error\":{\"code\":-1,\"message\":\"Failed to rescan before time %d, transactions may be missing.\"}}]", newTip->GetBlockTimeMax()));
426+
BOOST_CHECK_EQUAL(response.write(), strprintf("[{\"success\":false,\"error\":{\"code\":-1,\"message\":\"Failed to rescan before time %d, transactions may be missing.\"}},{\"success\":true}]", newTip->GetBlockTimeMax()));
416427
::pwalletMain = backup;
417428
}
418429
}

0 commit comments

Comments
 (0)