Bitcoin Core 32.99.0
P2P Digital Currency
Classes | Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
wallet::ChainScanner Class Reference

#include <scan.h>

Collaboration diagram for wallet::ChainScanner:
[legend]

Classes

struct  LoopState
 Progress window and tip tracked across Scan loop iterations. More...
 

Public Member Functions

 ChainScanner (CWallet &wallet)
 
void Abort ()
 
bool IsAborting () const
 
bool IsScanning () const
 
bool IsScanningWithPassphrase () const
 
SteadyClock::duration ScanningDuration () const
 
double ScanningProgress () const
 
int64_t ScanFromTime (int64_t startTime, const WalletRescanReserver &reserver)
 Scan active chain for relevant transactions after importing keys. More...
 
ScanResult Scan (const uint256 &start_block, int start_height, std::optional< int > max_height, const WalletRescanReserver &reserver, bool save_progress)
 Scan the block chain (starting in start_block) for transactions from or to us. More...
 

Private Member Functions

bool QueueNextBlock (const uint256 &block_hash, int block_height, std::optional< std::pair< uint256, int > > &next_block, std::optional< int > max_height)
 Locate block_hash in the chain, queueing its active-chain successor into next_block if it exists and is within the scan range. More...
 
bool ScanBlock (const uint256 &block_hash, int block_height, bool save_progress)
 
void UpdateProgress (const LoopState &state, double progress_current, int block_height)
 
void UpdateTipIfChanged (LoopState &state)
 
bool TryReserve (bool with_passphrase=false)
 
void Release ()
 

Private Attributes

CWalletm_wallet
 
std::atomic< bool > m_abort {false}
 
std::atomic< bool > m_scanning {false}
 
std::atomic< bool > m_scanning_with_passphrase {false}
 
std::atomic< SteadyClock::time_point > m_scanning_start {SteadyClock::time_point{}}
 
std::atomic< double > m_scanning_progress {0}
 

Friends

class WalletRescanReserver
 Only WalletRescanReserver may reserve and release scans, so that reservations are always managed RAII-style. More...
 

Detailed Description

Definition at line 57 of file scan.h.

Constructor & Destructor Documentation

◆ ChainScanner()

wallet::ChainScanner::ChainScanner ( CWallet wallet)
inlineexplicit

Definition at line 92 of file scan.h.

Member Function Documentation

◆ Abort()

void wallet::ChainScanner::Abort ( )
inline

Definition at line 94 of file scan.h.

◆ IsAborting()

bool wallet::ChainScanner::IsAborting ( ) const
inline

Definition at line 95 of file scan.h.

◆ IsScanning()

bool wallet::ChainScanner::IsScanning ( ) const
inline

Definition at line 96 of file scan.h.

Here is the caller graph for this function:

◆ IsScanningWithPassphrase()

bool wallet::ChainScanner::IsScanningWithPassphrase ( ) const
inline

Definition at line 97 of file scan.h.

◆ QueueNextBlock()

bool wallet::ChainScanner::QueueNextBlock ( const uint256 block_hash,
int  block_height,
std::optional< std::pair< uint256, int > > &  next_block,
std::optional< int >  max_height 
)
private

Locate block_hash in the chain, queueing its active-chain successor into next_block if it exists and is within the scan range.

Returns whether the block itself is still in the active chain.

Definition at line 148 of file scan.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Release()

void wallet::ChainScanner::Release ( )
private

Definition at line 71 of file scan.cpp.

Here is the caller graph for this function:

◆ Scan()

ScanResult wallet::ChainScanner::Scan ( const uint256 start_block,
int  start_height,
std::optional< int >  max_height,
const WalletRescanReserver reserver,
bool  save_progress 
)

Scan the block chain (starting in start_block) for transactions from or to us.

If max_height is not set, the mempool will be scanned as well.

Parameters
[in]start_blockScan starting block. If block is not on the active chain, the scan will return SUCCESS immediately.
[in]start_heightHeight of start_block
[in]max_heightOptional max scanning height. If unset there is no maximum and scanning can continue to the tip
Returns
ScanResult returning scan information and indicating success or failure. Return status will be set to SUCCESS if scan was successful. FAILURE if a complete rescan was not possible (due to pruning or corruption). USER_ABORT if the rescan was aborted before it could complete.
Precondition
Caller needs to make sure start_block (and the optional stop_block) are on the main chain after the addition of any new keys you want to detect transactions for.

Definition at line 218 of file scan.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ScanBlock()

bool wallet::ChainScanner::ScanBlock ( const uint256 block_hash,
int  block_height,
bool  save_progress 
)
private

Definition at line 187 of file scan.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ScanFromTime()

int64_t wallet::ChainScanner::ScanFromTime ( int64_t  startTime,
const WalletRescanReserver reserver 
)

Scan active chain for relevant transactions after importing keys.

Should be called whenever new keys are added to the wallet, with the oldest key creation time.

Returns
Earliest timestamp that could be successfully scanned from. Timestamp returned will be higher than startTime if relevant blocks could not be read.

Definition at line 18 of file scan.cpp.

Here is the call graph for this function:

◆ ScanningDuration()

SteadyClock::duration wallet::ChainScanner::ScanningDuration ( ) const
inline

Definition at line 98 of file scan.h.

◆ ScanningProgress()

double wallet::ChainScanner::ScanningProgress ( ) const
inline

Definition at line 99 of file scan.h.

◆ TryReserve()

bool wallet::ChainScanner::TryReserve ( bool  with_passphrase = false)
private

Definition at line 59 of file scan.cpp.

Here is the caller graph for this function:

◆ UpdateProgress()

void wallet::ChainScanner::UpdateProgress ( const LoopState state,
double  progress_current,
int  block_height 
)
private

Definition at line 165 of file scan.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ UpdateTipIfChanged()

void wallet::ChainScanner::UpdateTipIfChanged ( LoopState state)
private

Definition at line 179 of file scan.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

Friends And Related Function Documentation

◆ WalletRescanReserver

friend class WalletRescanReserver
friend

Only WalletRescanReserver may reserve and release scans, so that reservations are always managed RAII-style.

Definition at line 87 of file scan.h.

Member Data Documentation

◆ m_abort

std::atomic<bool> wallet::ChainScanner::m_abort {false}
private

Definition at line 61 of file scan.h.

◆ m_scanning

std::atomic<bool> wallet::ChainScanner::m_scanning {false}
private

Definition at line 62 of file scan.h.

◆ m_scanning_progress

std::atomic<double> wallet::ChainScanner::m_scanning_progress {0}
private

Definition at line 65 of file scan.h.

◆ m_scanning_start

std::atomic<SteadyClock::time_point> wallet::ChainScanner::m_scanning_start {SteadyClock::time_point{}}
private

Definition at line 64 of file scan.h.

◆ m_scanning_with_passphrase

std::atomic<bool> wallet::ChainScanner::m_scanning_with_passphrase {false}
private

Definition at line 63 of file scan.h.

◆ m_wallet

CWallet& wallet::ChainScanner::m_wallet
private

Definition at line 59 of file scan.h.


The documentation for this class was generated from the following files: