Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/wallet.cpp
Show First 20 Lines • Show All 1,702 Lines • ▼ Show 20 Lines | |||||
* returned will be higher than startTime if relevant blocks could not be read. | * returned will be higher than startTime if relevant blocks could not be read. | ||||
*/ | */ | ||||
int64_t CWallet::RescanFromTime(int64_t startTime, | int64_t CWallet::RescanFromTime(int64_t startTime, | ||||
const WalletRescanReserver &reserver, | const WalletRescanReserver &reserver, | ||||
bool update) { | bool update) { | ||||
// Find starting block. May be null if nCreateTime is greater than the | // Find starting block. May be null if nCreateTime is greater than the | ||||
// highest blockchain timestamp, in which case there is nothing that needs | // highest blockchain timestamp, in which case there is nothing that needs | ||||
// to be scanned. | // to be scanned. | ||||
int start_height = 0; | |||||
BlockHash start_block; | BlockHash start_block; | ||||
{ | bool start = chain().findFirstBlockWithTimeAndHeight( | ||||
auto locked_chain = chain().lock(); | startTime - TIMESTAMP_WINDOW, 0, | ||||
const Optional<int> start_height = | FoundBlock().hash(start_block).height(start_height)); | ||||
locked_chain->findFirstBlockWithTimeAndHeight( | WalletLogPrintf("%s: Rescanning last %i blocks\n", __func__, | ||||
startTime - TIMESTAMP_WINDOW, 0, &start_block); | start ? WITH_LOCK(cs_wallet, return GetLastBlockHeight()) - | ||||
const Optional<int> tip_height = locked_chain->getHeight(); | start_height + 1 | ||||
WalletLogPrintf( | : 0); | ||||
"%s: Rescanning last %i blocks\n", __func__, | |||||
tip_height && start_height ? *tip_height - *start_height + 1 : 0); | |||||
} | |||||
if (!start_block.IsNull()) { | if (start) { | ||||
// TODO: this should take into account failure by ScanResult::USER_ABORT | // TODO: this should take into account failure by ScanResult::USER_ABORT | ||||
ScanResult result = ScanForWalletTransactions(start_block, BlockHash(), | ScanResult result = ScanForWalletTransactions(start_block, BlockHash(), | ||||
reserver, update); | reserver, update); | ||||
if (result.status == ScanResult::FAILURE) { | if (result.status == ScanResult::FAILURE) { | ||||
int64_t time_max; | int64_t time_max; | ||||
CHECK_NONFATAL(chain().findBlock(result.last_failed_block, | CHECK_NONFATAL(chain().findBlock(result.last_failed_block, | ||||
FoundBlock().maxTime(time_max))); | FoundBlock().maxTime(time_max))); | ||||
return time_max + TIMESTAMP_WINDOW + 1; | return time_max + TIMESTAMP_WINDOW + 1; | ||||
▲ Show 20 Lines • Show All 3,043 Lines • Show Last 20 Lines |