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