6 namespace org { namespace ldk { namespace structs {
10 * A utility that keeps track of [`SpendableOutputDescriptor`]s, persists them in a given
11 * [`KVStore`] and regularly retries sweeping them based on a callback given to the constructor
14 * Users should call [`Self::track_spendable_outputs`] for any [`SpendableOutputDescriptor`]s received via [`Event::SpendableOutputs`].
16 * This needs to be notified of chain state changes either via its [`Listen`] or [`Confirm`]
17 * implementation and hence has to be connected with the utilized chain data sources.
19 * If chain data is provided via the [`Confirm`] interface or via filtered blocks, users are
20 * required to give their chain data sources (i.e., [`Filter`] implementation) to the respective
23 * [`Event::SpendableOutputs`]: crate::events::Event::SpendableOutputs
25 public class OutputSweeper : CommonBase {
26 internal OutputSweeper(object _dummy, long ptr) : base(ptr) { }
28 if (ptr != 0) { bindings.OutputSweeper_free(ptr); }
32 * Constructs a new [`OutputSweeper`].
34 * If chain data is provided via the [`Confirm`] interface or via filtered blocks, users also
35 * need to register their [`Filter`] implementation via the given `chain_data_source`.
37 public static OutputSweeper of(org.ldk.structs.BestBlock best_block, org.ldk.structs.BroadcasterInterface broadcaster, org.ldk.structs.FeeEstimator fee_estimator, org.ldk.structs.Option_FilterZ chain_data_source, org.ldk.structs.OutputSpender output_spender, org.ldk.structs.ChangeDestinationSource change_destination_source, org.ldk.structs.KVStore kv_store, org.ldk.structs.Logger logger) {
38 long ret = bindings.OutputSweeper_new(best_block.ptr, broadcaster.ptr, fee_estimator.ptr, chain_data_source.ptr, output_spender.ptr, change_destination_source.ptr, kv_store.ptr, logger.ptr);
39 GC.KeepAlive(best_block);
40 GC.KeepAlive(broadcaster);
41 GC.KeepAlive(fee_estimator);
42 GC.KeepAlive(chain_data_source);
43 GC.KeepAlive(output_spender);
44 GC.KeepAlive(change_destination_source);
45 GC.KeepAlive(kv_store);
47 if (ret >= 0 && ret <= 4096) { return null; }
48 org.ldk.structs.OutputSweeper ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.OutputSweeper(null, ret); }
49 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
50 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(best_block); };
51 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(broadcaster); };
52 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(fee_estimator); };
53 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(chain_data_source); };
54 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(output_spender); };
55 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(change_destination_source); };
56 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(kv_store); };
57 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(logger); };
62 * Tells the sweeper to track the given outputs descriptors.
64 * Usually, this should be called based on the values emitted by the
65 * [`Event::SpendableOutputs`].
67 * The given `exclude_static_outputs` flag controls whether the sweeper will filter out
68 * [`SpendableOutputDescriptor::StaticOutput`]s, which may be handled directly by the on-chain
69 * wallet implementation.
71 * If `delay_until_height` is set, we will delay the spending until the respective block
72 * height is reached. This can be used to batch spends, e.g., to reduce on-chain fees.
74 * Returns `Err` on persistence failure, in which case the call may be safely retried.
76 * [`Event::SpendableOutputs`]: crate::events::Event::SpendableOutputs
78 * Note that channel_id (or a relevant inner pointer) may be NULL or all-0s to represent None
80 public Result_NoneNoneZ track_spendable_outputs(SpendableOutputDescriptor[] output_descriptors, org.ldk.structs.ChannelId channel_id, bool exclude_static_outputs, org.ldk.structs.Option_u32Z delay_until_height) {
81 long ret = bindings.OutputSweeper_track_spendable_outputs(this.ptr, InternalUtils.encodeUint64Array(InternalUtils.mapArray(output_descriptors, output_descriptors_conv_27 => output_descriptors_conv_27.ptr)), channel_id == null ? 0 : channel_id.ptr, exclude_static_outputs, delay_until_height.ptr);
83 GC.KeepAlive(output_descriptors);
84 GC.KeepAlive(channel_id);
85 GC.KeepAlive(exclude_static_outputs);
86 GC.KeepAlive(delay_until_height);
87 if (ret >= 0 && ret <= 4096) { return null; }
88 Result_NoneNoneZ ret_hu_conv = Result_NoneNoneZ.constr_from_ptr(ret);
89 foreach (SpendableOutputDescriptor output_descriptors_conv_27 in output_descriptors) { if (this != null) { this.ptrs_to.AddLast(output_descriptors_conv_27); }; };
90 if (this != null) { this.ptrs_to.AddLast(channel_id); };
91 if (this != null) { this.ptrs_to.AddLast(delay_until_height); };
96 * Returns a list of the currently tracked spendable outputs.
98 public TrackedSpendableOutput[] tracked_spendable_outputs() {
99 long ret = bindings.OutputSweeper_tracked_spendable_outputs(this.ptr);
101 if (ret >= 0 && ret <= 4096) { return null; }
102 int ret_conv_24_len = InternalUtils.getArrayLength(ret);
103 TrackedSpendableOutput[] ret_conv_24_arr = new TrackedSpendableOutput[ret_conv_24_len];
104 for (int y = 0; y < ret_conv_24_len; y++) {
105 long ret_conv_24 = InternalUtils.getU64ArrayElem(ret, y);
106 org.ldk.structs.TrackedSpendableOutput ret_conv_24_hu_conv = null; if (ret_conv_24 < 0 || ret_conv_24 > 4096) { ret_conv_24_hu_conv = new org.ldk.structs.TrackedSpendableOutput(null, ret_conv_24); }
107 if (ret_conv_24_hu_conv != null) { ret_conv_24_hu_conv.ptrs_to.AddLast(this); };
108 ret_conv_24_arr[y] = ret_conv_24_hu_conv;
110 bindings.free_buffer(ret);
111 return ret_conv_24_arr;
115 * Gets the latest best block which was connected either via the [`Listen`] or
116 * [`Confirm`] interfaces.
118 public BestBlock current_best_block() {
119 long ret = bindings.OutputSweeper_current_best_block(this.ptr);
121 if (ret >= 0 && ret <= 4096) { return null; }
122 org.ldk.structs.BestBlock ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.BestBlock(null, ret); }
123 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
128 * Constructs a new Listen which calls the relevant methods on this_arg.
129 * This copies the `inner` pointer in this_arg and thus the returned Listen must be freed before this_arg is
131 public Listen as_Listen() {
132 long ret = bindings.OutputSweeper_as_Listen(this.ptr);
134 if (ret >= 0 && ret <= 4096) { return null; }
135 Listen ret_hu_conv = new Listen(null, ret);
136 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
141 * Constructs a new Confirm which calls the relevant methods on this_arg.
142 * This copies the `inner` pointer in this_arg and thus the returned Confirm must be freed before this_arg is
144 public Confirm as_Confirm() {
145 long ret = bindings.OutputSweeper_as_Confirm(this.ptr);
147 if (ret >= 0 && ret <= 4096) { return null; }
148 Confirm ret_hu_conv = new Confirm(null, ret);
149 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
154 * Read a OutputSweeper from a byte array, created by OutputSweeper_write
156 public static Result_OutputSweeperDecodeErrorZ read(byte[] ser, org.ldk.structs.BroadcasterInterface arg_a, org.ldk.structs.FeeEstimator arg_b, org.ldk.structs.Option_FilterZ arg_c, org.ldk.structs.OutputSpender arg_d, org.ldk.structs.ChangeDestinationSource arg_e, org.ldk.structs.KVStore arg_f, org.ldk.structs.Logger arg_g) {
157 long ret = bindings.OutputSweeper_read(InternalUtils.encodeUint8Array(ser), arg_a.ptr, arg_b.ptr, arg_c.ptr, arg_d.ptr, arg_e.ptr, arg_f.ptr, arg_g.ptr);
166 if (ret >= 0 && ret <= 4096) { return null; }
167 Result_OutputSweeperDecodeErrorZ ret_hu_conv = Result_OutputSweeperDecodeErrorZ.constr_from_ptr(ret);
168 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(arg_a); };
169 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(arg_b); };
170 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(arg_c); };
171 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(arg_d); };
172 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(arg_e); };
173 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(arg_f); };
174 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(arg_g); };