Create a contract watcher with the given providers and polling settings.
Contract watcher configuration
Add a contract to be watched.
Once watching, every contract is subscribed and polled whatever its state.
Force a poll of all watched contracts. Useful for manual refresh or after app resume.
Get all in-memory contracts.
Get current connection state.
Every registered contract, retired (inactive) ones included.
Feeds both the subscription and the indexer sweep scope, so narrowing it drops a contract from every background channel at once. Nothing may be narrowed out: an Ark receive address can be paid again after the wallet has rotated past it, and a payment that lands outside every background channel is invisible until some foreground read happens to sweep it. Retirement therefore governs receive-address selection, not coverage.
Check if currently watching.
Remove a contract from watching.
Start watching for virtual output events across all watched contracts.
Stop watching for events.
Run fn with subscription updates coalesced into a single
subscribeForScripts on the way out.
addContract re-subscribes eagerly (the watcher may already be running), and every subscribe posts the whole accumulated script list — so a restore scan that discovers N contracts sends N growing POSTs, quadratic in script-slots. Inside this scope those updates are only marked dirty, flushed once on the way out (success and error path alike).
A contract added inside the scope is therefore not streaming until the
flush. Nothing in the watcher closes that window — the failsafe poll
replays repository state and cannot see VTXOs no one has fetched yet. The
one caller, scanContracts, is covered because Wallet.restore follows
it with a bulk refreshVtxos. A new caller must provide its own
equivalent catch-up, or keep the scope short enough not to need one.
Watches multiple contracts for virtual output state changes with resilient connection handling.
Features:
Example