Skip to main content

Monitor

Struct Monitor 

Source
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: MonitorOptions

Configuration options.

§storage: WalletStorageManager

Storage manager for persistence operations.

§services: Arc<dyn WalletServices>

Network services for broadcasting and proof retrieval.

§chain: Chain

The 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

Source

pub fn builder() -> MonitorBuilder

Returns a new MonitorBuilder for fluent construction.

Source

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.

Source

pub async fn stop_tasks(&mut self)

Stop the polling loop and wait for it to complete.

Source

pub async fn destroy(&mut self)

Destroy the monitor: stops tasks and cleans up subscriptions.

Source

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.

Source

pub async fn run_task(&mut self, name: &str) -> WalletResult<String>

Run a specific task by name (from _tasks or _otherTasks).

Source

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.

Source

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.

Source

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.

Source

pub async fn call_on_broadcasted_transaction(&self, broadcast_result: &str)

Call the on_tx_broadcasted callback if registered.

Source

pub async fn call_on_proven_transaction(&self, tx_status: &str)

Call the on_tx_proven callback if registered.

Source

pub async fn call_on_transaction_status_changed( &self, txid: &str, new_status: &str, )

Call the on_tx_status_changed callback if registered.

Source

pub fn is_running(&self) -> bool

Returns whether the monitor is currently running.

Source

pub fn add_task(&mut self, task: Box<dyn WalletMonitorTask>) -> WalletResult<()>

Add a task to the scheduled task list.

Source

pub fn remove_task(&mut self, name: &str)

Remove a task from the scheduled task list by name.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more