pub struct Monitor {
pub options: MonitorOptions,
pub storage: WalletStorageManager,
pub services: Arc<dyn WalletServices>,
pub chain: Chain,
pub check_now: Arc<AtomicBool>,
pub last_new_header_height: Arc<AtomicU32>,
pub last_new_header: Option<BlockHeader>,
pub last_new_header_when: Option<u64>,
pub deactivated_headers: Arc<Mutex<Vec<DeactivatedHeader>>>,
/* private fields */
}Expand description
Background task scheduler that manages transaction lifecycle.
Automatically handles broadcasting pending transactions, collecting merkle proofs, detecting chain reorgs, failing stale transactions, and cleaning up old data.
Translated from TS Monitor class in wallet-toolbox/src/monitor/Monitor.ts.
NOTE: Tasks run sequentially within each polling iteration, matching the TS pattern. Concurrent task execution is a future optimization.
Fields§
§options: MonitorOptionsConfiguration options.
storage: WalletStorageManagerStorage manager for persistence operations.
services: Arc<dyn WalletServices>Network services for broadcasting and proof retrieval.
chain: ChainThe chain this monitor is configured for.
check_now: Arc<AtomicBool>Flag to nudge proof checking (set by processNewBlockHeader). Shared with TaskCheckForProofs.
last_new_header_height: Arc<AtomicU32>Shared last header height for max acceptable height guard. u32::MAX is the sentinel for “no height known”. Shared with TaskCheckForProofs and updated in process_new_block_header.
last_new_header: Option<BlockHeader>The last new block header received.
last_new_header_when: Option<u64>When the last new header was received (epoch ms).
deactivated_headers: Arc<Mutex<Vec<DeactivatedHeader>>>Queue of deactivated headers from reorg events, awaiting processing.
Implementations§
Source§impl Monitor
impl Monitor
Sourcepub fn builder() -> MonitorBuilder
pub fn builder() -> MonitorBuilder
Returns a new MonitorBuilder for fluent construction.
Sourcepub fn start_tasks(&mut self) -> WalletResult<()>
pub fn start_tasks(&mut self) -> WalletResult<()>
Start the polling loop in a background tokio task.
Validates that the monitor is not already running, then spawns the loop.
Sourcepub async fn stop_tasks(&mut self)
pub async fn stop_tasks(&mut self)
Stop the polling loop and wait for it to complete.
Sourcepub async fn run_once(&mut self) -> WalletResult<()>
pub async fn run_once(&mut self) -> WalletResult<()>
Run one iteration of the polling loop (for testing).
Runs async_setup on first call, then triggers and runs tasks once.
Sourcepub async fn run_task(&mut self, name: &str) -> WalletResult<String>
pub async fn run_task(&mut self, name: &str) -> WalletResult<String>
Run a specific task by name (from _tasks or _otherTasks).
Sourcepub fn process_new_block_header(&mut self, header: BlockHeader)
pub fn process_new_block_header(&mut self, header: BlockHeader)
Process a new block header event received from Chaintracks.
Stores the header and nudges the proof checker to try again.
Sourcepub async fn process_reorg(
&self,
_depth: u32,
_old_tip: &BlockHeader,
_new_tip: &BlockHeader,
deactivated: Option<&[BlockHeader]>,
)
pub async fn process_reorg( &self, _depth: u32, _old_tip: &BlockHeader, _new_tip: &BlockHeader, deactivated: Option<&[BlockHeader]>, )
Process a reorg event received from Chaintracks.
Reorgs can move recent transactions to new blocks at new index positions. Affected transaction proofs become invalid and must be updated.
Sourcepub fn process_header(&self, _header: &BlockHeader)
pub fn process_header(&self, _header: &BlockHeader)
Handler for new header events from Chaintracks.
To minimize reorg processing, new headers are aged before processing via TaskNewHeader. Therefore this handler is intentionally a no-op.
Sourcepub async fn call_on_broadcasted_transaction(&self, broadcast_result: &str)
pub async fn call_on_broadcasted_transaction(&self, broadcast_result: &str)
Call the on_tx_broadcasted callback if registered.
Sourcepub async fn call_on_proven_transaction(&self, tx_status: &str)
pub async fn call_on_proven_transaction(&self, tx_status: &str)
Call the on_tx_proven callback if registered.
Sourcepub async fn call_on_transaction_status_changed(
&self,
txid: &str,
new_status: &str,
)
pub async fn call_on_transaction_status_changed( &self, txid: &str, new_status: &str, )
Call the on_tx_status_changed callback if registered.
Sourcepub fn is_running(&self) -> bool
pub fn is_running(&self) -> bool
Returns whether the monitor is currently running.
Sourcepub fn add_task(&mut self, task: Box<dyn WalletMonitorTask>) -> WalletResult<()>
pub fn add_task(&mut self, task: Box<dyn WalletMonitorTask>) -> WalletResult<()>
Add a task to the scheduled task list.
Sourcepub fn remove_task(&mut self, name: &str)
pub fn remove_task(&mut self, name: &str)
Remove a task from the scheduled task list by name.
Auto Trait Implementations§
impl !Freeze for Monitor
impl !RefUnwindSafe for Monitor
impl Send for Monitor
impl Sync for Monitor
impl Unpin for Monitor
impl UnsafeUnpin for Monitor
impl !UnwindSafe for Monitor
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more