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 ContractState — a retained one is held for reads
only, and never enters a background channel.
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 except the retained ones, retired
(inactive) receive addresses included.
Feeds both the subscription and the indexer sweep scope, so
narrowing it drops a contract from every background channel at
once. state may never narrow it: 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.
ContractWatchState is the one thing that does narrow it, and only when an owner has explicitly said the script is done — a settled swap lockup, a funded one-shot destination. The row stays in getAllContracts so reads, annotation and history are unaffected.
Every script registered via addWatchedScript.
Check if currently watching.
Remove a contract from watching.
Stop watching a script added by addWatchedScript.
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