[C#] Update auto-generated C# bindings
[ldk-java] / c_sharp / src / org / ldk / structs / Filter.cs
1
2 using org.ldk.impl;
3 using org.ldk.enums;
4 using org.ldk.util;
5 using System;
6
7 namespace org { namespace ldk { namespace structs {
8
9
10
11 /** An implementation of Filter */
12 public interface FilterInterface {
13         /**Registers interest in a transaction with `txid` and having an output with `script_pubkey` as
14          * a spending condition.
15          */
16         void register_tx(byte[] txid, byte[] script_pubkey);
17         /**Registers interest in spends of a transaction output.
18          * 
19          * Note that this method might be called during processing of a new block. You therefore need
20          * to ensure that also dependent output spents within an already connected block are correctly
21          * handled, e.g., by re-scanning the block in question whenever new outputs have been
22          * registered mid-processing.
23          */
24         void register_output(WatchedOutput output);
25 }
26
27 /**
28  * The `Filter` trait defines behavior for indicating chain activity of interest pertaining to
29  * channels.
30  * 
31  * This is useful in order to have a [`Watch`] implementation convey to a chain source which
32  * transactions to be notified of. Notification may take the form of pre-filtering blocks or, in
33  * the case of [BIP 157]/[BIP 158], only fetching a block if the compact filter matches. If
34  * receiving full blocks from a chain source, any further filtering is unnecessary.
35  * 
36  * After an output has been registered, subsequent block retrievals from the chain source must not
37  * exclude any transactions matching the new criteria nor any in-block descendants of such
38  * transactions.
39  * 
40  * Note that use as part of a [`Watch`] implementation involves reentrancy. Therefore, the `Filter`
41  * should not block on I/O. Implementations should instead queue the newly monitored data to be
42  * processed later. Then, in order to block until the data has been processed, any [`Watch`]
43  * invocation that has called the `Filter` must return [`InProgress`].
44  * 
45  * [`InProgress`]: ChannelMonitorUpdateStatus::InProgress
46  * [BIP 157]: https://github.com/bitcoin/bips/blob/master/bip-0157.mediawiki
47  * [BIP 158]: https://github.com/bitcoin/bips/blob/master/bip-0158.mediawiki
48  */
49 public class Filter : CommonBase {
50         internal bindings.LDKFilter bindings_instance;
51         internal long instance_idx;
52
53         internal Filter(object _dummy, long ptr) : base(ptr) { bindings_instance = null; }
54         ~Filter() {
55                 if (ptr != 0) { bindings.Filter_free(ptr); }
56         }
57
58         private class LDKFilterHolder { internal Filter held; }
59         private class LDKFilterImpl : bindings.LDKFilter {
60                 internal LDKFilterImpl(FilterInterface arg, LDKFilterHolder impl_holder) { this.arg = arg; this.impl_holder = impl_holder; }
61                 private FilterInterface arg;
62                 private LDKFilterHolder impl_holder;
63                 public void register_tx(long _txid, long _script_pubkey) {
64                         byte[] _txid_conv = InternalUtils.decodeUint8Array(_txid);
65                         byte[] _script_pubkey_conv = InternalUtils.decodeUint8Array(_script_pubkey);
66                         arg.register_tx(_txid_conv, _script_pubkey_conv);
67                                 GC.KeepAlive(arg);
68                 }
69                 public void register_output(long _output) {
70                         org.ldk.structs.WatchedOutput _output_hu_conv = null; if (_output < 0 || _output > 4096) { _output_hu_conv = new org.ldk.structs.WatchedOutput(null, _output); }
71                         if (_output_hu_conv != null) { _output_hu_conv.ptrs_to.AddLast(this); };
72                         arg.register_output(_output_hu_conv);
73                                 GC.KeepAlive(arg);
74                 }
75         }
76
77         /** Creates a new instance of Filter from a given implementation */
78         public static Filter new_impl(FilterInterface arg) {
79                 LDKFilterHolder impl_holder = new LDKFilterHolder();
80                 LDKFilterImpl impl = new LDKFilterImpl(arg, impl_holder);
81                 long[] ptr_idx = bindings.LDKFilter_new(impl);
82
83                 impl_holder.held = new Filter(null, ptr_idx[0]);
84                 impl_holder.held.instance_idx = ptr_idx[1];
85                 impl_holder.held.bindings_instance = impl;
86                 return impl_holder.held;
87         }
88
89         /**
90          * Registers interest in a transaction with `txid` and having an output with `script_pubkey` as
91          * a spending condition.
92          */
93         public void register_tx(byte[] txid, byte[] script_pubkey) {
94                 bindings.Filter_register_tx(this.ptr, InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(txid, 32)), InternalUtils.encodeUint8Array(script_pubkey));
95                 GC.KeepAlive(this);
96                 GC.KeepAlive(txid);
97                 GC.KeepAlive(script_pubkey);
98         }
99
100         /**
101          * Registers interest in spends of a transaction output.
102          * 
103          * Note that this method might be called during processing of a new block. You therefore need
104          * to ensure that also dependent output spents within an already connected block are correctly
105          * handled, e.g., by re-scanning the block in question whenever new outputs have been
106          * registered mid-processing.
107          */
108         public void register_output(org.ldk.structs.WatchedOutput output) {
109                 bindings.Filter_register_output(this.ptr, output == null ? 0 : output.ptr);
110                 GC.KeepAlive(this);
111                 GC.KeepAlive(output);
112                 if (this != null) { this.ptrs_to.AddLast(output); };
113         }
114
115 }
116 } } }