Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/wallet.cpp
Show First 20 Lines • Show All 1,878 Lines • ▼ Show 20 Lines | 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. | ||||
BlockHash start_block; | BlockHash start_block; | ||||
{ | { | ||||
auto locked_chain = chain().lock(); | auto locked_chain = chain().lock(); | ||||
const Optional<int> start_height = locked_chain->findFirstBlockWithTime( | const Optional<int> start_height = | ||||
startTime - TIMESTAMP_WINDOW, &start_block); | locked_chain->findFirstBlockWithTimeAndHeight( | ||||
startTime - TIMESTAMP_WINDOW, 0, &start_block); | |||||
const Optional<int> tip_height = locked_chain->getHeight(); | const Optional<int> tip_height = locked_chain->getHeight(); | ||||
WalletLogPrintf( | WalletLogPrintf( | ||||
"%s: Rescanning last %i blocks\n", __func__, | "%s: Rescanning last %i blocks\n", __func__, | ||||
tip_height && start_height ? *tip_height - *start_height + 1 : 0); | tip_height && start_height ? *tip_height - *start_height + 1 : 0); | ||||
} | } | ||||
if (!start_block.IsNull()) { | if (!start_block.IsNull()) { | ||||
// TODO: this should take into account failure by ScanResult::USER_ABORT | // TODO: this should take into account failure by ScanResult::USER_ABORT | ||||
▲ Show 20 Lines • Show All 2,861 Lines • ▼ Show 20 Lines | if (tip_height && *tip_height != rescan_height) { | ||||
*tip_height - rescan_height, rescan_height); | *tip_height - rescan_height, rescan_height); | ||||
// No need to read and scan block if block was created before our wallet | // No need to read and scan block if block was created before our wallet | ||||
// birthday (as adjusted for block time variability) | // birthday (as adjusted for block time variability) | ||||
if (walletInstance->nTimeFirstKey) { | if (walletInstance->nTimeFirstKey) { | ||||
if (Optional<int> first_block = | if (Optional<int> first_block = | ||||
locked_chain->findFirstBlockWithTimeAndHeight( | locked_chain->findFirstBlockWithTimeAndHeight( | ||||
walletInstance->nTimeFirstKey - TIMESTAMP_WINDOW, | walletInstance->nTimeFirstKey - TIMESTAMP_WINDOW, | ||||
rescan_height)) { | rescan_height, nullptr)) { | ||||
rescan_height = *first_block; | rescan_height = *first_block; | ||||
} | } | ||||
} | } | ||||
nStart = GetTimeMillis(); | nStart = GetTimeMillis(); | ||||
{ | { | ||||
WalletRescanReserver reserver(walletInstance.get()); | WalletRescanReserver reserver(walletInstance.get()); | ||||
if (!reserver.reserve() || | if (!reserver.reserve() || | ||||
▲ Show 20 Lines • Show All 222 Lines • Show Last 20 Lines |