UNPKG

lightningdevkit

Version:
86 lines (85 loc) 4.69 kB
import { SpendableOutputDescriptor } from '../structs/SpendableOutputDescriptor.mjs'; import { Option_u32Z } from '../structs/Option_u32Z.mjs'; import { Result_NoneNoneZ } from '../structs/Result_NoneNoneZ.mjs'; import { Logger } from '../structs/Logger.mjs'; import { BestBlock } from '../structs/BestBlock.mjs'; import { ChannelId } from '../structs/ChannelId.mjs'; import { BroadcasterInterface } from '../structs/BroadcasterInterface.mjs'; import { FeeEstimator } from '../structs/FeeEstimator.mjs'; import { TrackedSpendableOutput } from '../structs/TrackedSpendableOutput.mjs'; import { Option_FilterZ } from '../structs/Option_FilterZ.mjs'; import { ChangeDestinationSource } from '../structs/ChangeDestinationSource.mjs'; import { KVStore } from '../structs/KVStore.mjs'; import { OutputSpender } from '../structs/OutputSpender.mjs'; import { Result_OutputSweeperDecodeErrorZ } from '../structs/Result_OutputSweeperDecodeErrorZ.mjs'; import { Listen } from '../structs/Listen.mjs'; import { Confirm } from '../structs/Confirm.mjs'; import { CommonBase } from './CommonBase.mjs'; /** * A utility that keeps track of [`SpendableOutputDescriptor`]s, persists them in a given * [`KVStore`] and regularly retries sweeping them based on a callback given to the constructor * methods. * * Users should call [`Self::track_spendable_outputs`] for any [`SpendableOutputDescriptor`]s 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. * * [`Event::SpendableOutputs`]: crate::events::Event::SpendableOutputs */ export declare class OutputSweeper extends CommonBase { /** * 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`. */ static constructor_new(best_block: BestBlock, broadcaster: BroadcasterInterface, fee_estimator: FeeEstimator, chain_data_source: Option_FilterZ, output_spender: OutputSpender, change_destination_source: ChangeDestinationSource, kv_store: KVStore, logger: Logger): OutputSweeper; /** * 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::StaticOutput`]s, 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. * * [`Event::SpendableOutputs`]: crate::events::Event::SpendableOutputs * * Note that channel_id (or a relevant inner pointer) may be NULL or all-0s to represent None */ track_spendable_outputs(output_descriptors: SpendableOutputDescriptor[], channel_id: ChannelId | null, exclude_static_outputs: boolean, delay_until_height: Option_u32Z): Result_NoneNoneZ; /** * Returns a list of the currently tracked spendable outputs. */ tracked_spendable_outputs(): TrackedSpendableOutput[]; /** * Gets the latest best block which was connected either via the [`Listen`] or * [`Confirm`] interfaces. */ current_best_block(): BestBlock; /** * Constructs a new Listen which calls the relevant methods on this_arg. * This copies the `inner` pointer in this_arg and thus the returned Listen must be freed before this_arg is */ as_Listen(): Listen; /** * Constructs a new Confirm which calls the relevant methods on this_arg. * This copies the `inner` pointer in this_arg and thus the returned Confirm must be freed before this_arg is */ as_Confirm(): Confirm; /** * Read a OutputSweeper from a byte array, created by OutputSweeper_write */ static constructor_read(ser: Uint8Array, arg_a: BroadcasterInterface, arg_b: FeeEstimator, arg_c: Option_FilterZ, arg_d: OutputSpender, arg_e: ChangeDestinationSource, arg_f: KVStore, arg_g: Logger): Result_OutputSweeperDecodeErrorZ; }