MCPcopy Create free account
hub / github.com/ElementsProject/elements / RescanFromTime

Method RescanFromTime

src/wallet/wallet.cpp:1580–1600  ·  view source on GitHub ↗

* Scan active chain for relevant transactions after importing keys. This should * be called whenever new keys are added to the wallet, with the oldest key * creation time. * * @return Earliest timestamp that could be successfully scanned from. Timestamp * returned will be higher than startTime if relevant blocks could not be read. */

Source from the content-addressed store, hash-verified

1578 * returned will be higher than startTime if relevant blocks could not be read.
1579 */
1580int64_t CWallet::RescanFromTime(int64_t startTime, const WalletRescanReserver& reserver, bool update)
1581{
1582 // Find starting block. May be null if nCreateTime is greater than the
1583 // highest blockchain timestamp, in which case there is nothing that needs
1584 // to be scanned.
1585 int start_height = 0;
1586 uint256 start_block;
1587 bool start = chain().findFirstBlockWithTimeAndHeight(startTime - TIMESTAMP_WINDOW, 0, FoundBlock().hash(start_block).height(start_height));
1588 WalletLogPrintf("%s: Rescanning last %i blocks\n", __func__, start ? WITH_LOCK(cs_wallet, return GetLastBlockHeight()) - start_height + 1 : 0);
1589
1590 if (start) {
1591 // TODO: this should take into account failure by ScanResult::USER_ABORT
1592 ScanResult result = ScanForWalletTransactions(start_block, start_height, {} /* max_height */, reserver, update);
1593 if (result.status == ScanResult::FAILURE) {
1594 int64_t time_max;
1595 CHECK_NONFATAL(chain().findBlock(result.last_failed_block, FoundBlock().maxTime(time_max)));
1596 return time_max + TIMESTAMP_WINDOW + 1;
1597 }
1598 }
1599 return startTime;
1600}
1601
1602/**
1603 * Scan the block chain (starting in start_block) for transactions

Callers 3

RescanWalletFunction · 0.80
importmultiFunction · 0.80
importdescriptorsFunction · 0.80

Calls 5

FoundBlockClass · 0.85
hashMethod · 0.80
findBlockMethod · 0.80
heightMethod · 0.45

Tested by

no test coverage detected