pub struct OutputSweeper<B: Deref, D: Deref, E: Deref, F: Deref, K: Deref, L: Deref, O: Deref>where
B::Target: BroadcasterInterface,
D::Target: ChangeDestinationSource,
E::Target: FeeEstimator,
F::Target: Filter,
K::Target: KVStore,
L::Target: Logger,
O::Target: OutputSpender,{ /* private fields */ }Expand description
A utility that keeps track of SpendableOutputDescriptors, persists them in a given
KVStoreSync and regularly retries sweeping them based on a callback given to the constructor
methods.
Users should call Self::track_spendable_outputs for any SpendableOutputDescriptors received via Event::SpendableOutputs.
This needs to be notified of chain state changes either via its Listen or Confirm
implementation and hence has to be connected with the utilized chain data sources.
If chain data is provided via the Confirm interface or via filtered blocks, users are
required to give their chain data sources (i.e., Filter implementation) to the respective
constructor.
Implementations§
Source§impl<B: Deref, D: Deref, E: Deref, F: Deref, K: Deref, L: Deref, O: Deref> OutputSweeper<B, D, E, F, K, L, O>where
B::Target: BroadcasterInterface,
D::Target: ChangeDestinationSource,
E::Target: FeeEstimator,
F::Target: Filter,
K::Target: KVStore,
L::Target: Logger,
O::Target: OutputSpender,
impl<B: Deref, D: Deref, E: Deref, F: Deref, K: Deref, L: Deref, O: Deref> OutputSweeper<B, D, E, F, K, L, O>where
B::Target: BroadcasterInterface,
D::Target: ChangeDestinationSource,
E::Target: FeeEstimator,
F::Target: Filter,
K::Target: KVStore,
L::Target: Logger,
O::Target: OutputSpender,
Sourcepub fn new(
best_block: BestBlock,
broadcaster: B,
fee_estimator: E,
chain_data_source: Option<F>,
output_spender: O,
change_destination_source: D,
kv_store: K,
logger: L,
) -> Self
pub fn new( best_block: BestBlock, broadcaster: B, fee_estimator: E, chain_data_source: Option<F>, output_spender: O, change_destination_source: D, kv_store: K, logger: L, ) -> Self
Constructs a new OutputSweeper.
If chain data is provided via the Confirm interface or via filtered blocks, users also
need to register their Filter implementation via the given chain_data_source.
Sourcepub async fn track_spendable_outputs(
&self,
output_descriptors: Vec<SpendableOutputDescriptor>,
channel_id: Option<ChannelId>,
exclude_static_outputs: bool,
delay_until_height: Option<u32>,
) -> Result<(), ()>
pub async fn track_spendable_outputs( &self, output_descriptors: Vec<SpendableOutputDescriptor>, channel_id: Option<ChannelId>, exclude_static_outputs: bool, delay_until_height: Option<u32>, ) -> Result<(), ()>
Tells the sweeper to track the given outputs descriptors.
Usually, this should be called based on the values emitted by the
Event::SpendableOutputs.
The given exclude_static_outputs flag controls whether the sweeper will filter out
SpendableOutputDescriptor::StaticOutputs, which may be handled directly by the on-chain
wallet implementation.
If delay_until_height is set, we will delay the spending until the respective block
height is reached. This can be used to batch spends, e.g., to reduce on-chain fees.
Returns Err on persistence failure, in which case the call may be safely retried.
Sourcepub fn tracked_spendable_outputs(&self) -> Vec<TrackedSpendableOutput>
pub fn tracked_spendable_outputs(&self) -> Vec<TrackedSpendableOutput>
Returns a list of the currently tracked spendable outputs.
Sourcepub fn current_best_block(&self) -> BestBlock
pub fn current_best_block(&self) -> BestBlock
Sourcepub async fn regenerate_and_broadcast_spend_if_necessary(
&self,
) -> Result<(), ()>
pub async fn regenerate_and_broadcast_spend_if_necessary( &self, ) -> Result<(), ()>
Regenerates and broadcasts the spending transaction for any outputs that are pending. This method will be a no-op if a sweep is already pending.