[C#] Check in initial auto-generated C# bindings
[ldk-java] / c_sharp / src / org / ldk / structs / Listen.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 `Listen` trait is used to notify when blocks have been connected or disconnected from the
10  * chain.
11  * 
12  * Useful when needing to replay chain data upon startup or as new chain events occur. Clients
13  * sourcing chain data using a block-oriented API should prefer this interface over [`Confirm`].
14  * Such clients fetch the entire header chain whereas clients using [`Confirm`] only fetch headers
15  * when needed.
16  * 
17  * By using [`Listen::filtered_block_connected`] this interface supports clients fetching the
18  * entire header chain and only blocks with matching transaction data using BIP 157 filters or
19  * other similar filtering.
20  */
21 public class Listen : CommonBase {
22         internal readonly bindings.LDKListen bindings_instance;
23         internal Listen(object _dummy, long ptr) : base(ptr) { bindings_instance = null; }
24         private Listen(bindings.LDKListen arg) : base(bindings.LDKListen_new(arg)) {
25                 this.ptrs_to.AddLast(arg);
26                 this.bindings_instance = arg;
27         }
28         ~Listen() {
29                 if (ptr != 0) { bindings.Listen_free(ptr); }
30         }
31
32         public interface ListenInterface {
33                 /**
34                  * Notifies the listener that a block was added at the given height, with the transaction data
35                  * possibly filtered.
36                  */
37                 void filtered_block_connected(byte[] _header, TwoTuple_usizeTransactionZ[] _txdata, int _height);
38                 /**
39                  * Notifies the listener that a block was added at the given height.
40                  */
41                 void block_connected(byte[] _block, int _height);
42                 /**
43                  * Notifies the listener that a block was removed at the given height.
44                  */
45                 void block_disconnected(byte[] _header, int _height);
46         }
47         private class LDKListenHolder { internal Listen held; }
48         private class LDKListenImpl : bindings.LDKListen {
49                 internal LDKListenImpl(ListenInterface arg, LDKListenHolder impl_holder) { this.arg = arg; this.impl_holder = impl_holder; }
50                 private ListenInterface arg;
51                 private LDKListenHolder impl_holder;
52                 public void filtered_block_connected(byte[] _header, long[] _txdata, int _height) {
53                         int _txdata_conv_28_len = _txdata.Length;
54                         TwoTuple_usizeTransactionZ[] _txdata_conv_28_arr = new TwoTuple_usizeTransactionZ[_txdata_conv_28_len];
55                         for (int c = 0; c < _txdata_conv_28_len; c++) {
56                                 long _txdata_conv_28 = _txdata[c];
57                                 TwoTuple_usizeTransactionZ _txdata_conv_28_hu_conv = new TwoTuple_usizeTransactionZ(null, _txdata_conv_28);
58                                 if (_txdata_conv_28_hu_conv != null) { _txdata_conv_28_hu_conv.ptrs_to.AddLast(this); };
59                                 _txdata_conv_28_arr[c] = _txdata_conv_28_hu_conv;
60                         }
61                         arg.filtered_block_connected(_header, _txdata_conv_28_arr, _height);
62                                 GC.KeepAlive(arg);
63                 }
64                 public void block_connected(byte[] _block, int _height) {
65                         arg.block_connected(_block, _height);
66                                 GC.KeepAlive(arg);
67                 }
68                 public void block_disconnected(byte[] _header, int _height) {
69                         arg.block_disconnected(_header, _height);
70                                 GC.KeepAlive(arg);
71                 }
72         }
73         public static Listen new_impl(ListenInterface arg) {
74                 LDKListenHolder impl_holder = new LDKListenHolder();
75                 impl_holder.held = new Listen(new LDKListenImpl(arg, impl_holder));
76                 return impl_holder.held;
77         }
78         /**
79          * Notifies the listener that a block was added at the given height, with the transaction data
80          * possibly filtered.
81          */
82         public void filtered_block_connected(byte[] header, TwoTuple_usizeTransactionZ[] txdata, int height) {
83                 bindings.Listen_filtered_block_connected(this.ptr, InternalUtils.check_arr_len(header, 80), txdata != null ? InternalUtils.mapArray(txdata, txdata_conv_28 => txdata_conv_28 != null ? txdata_conv_28.ptr : 0) : null, height);
84                 GC.KeepAlive(this);
85                 GC.KeepAlive(header);
86                 GC.KeepAlive(txdata);
87                 GC.KeepAlive(height);
88         }
89
90         /**
91          * Notifies the listener that a block was added at the given height.
92          */
93         public void block_connected(byte[] block, int height) {
94                 bindings.Listen_block_connected(this.ptr, block, height);
95                 GC.KeepAlive(this);
96                 GC.KeepAlive(block);
97                 GC.KeepAlive(height);
98         }
99
100         /**
101          * Notifies the listener that a block was removed at the given height.
102          */
103         public void block_disconnected(byte[] header, int height) {
104                 bindings.Listen_block_disconnected(this.ptr, InternalUtils.check_arr_len(header, 80), height);
105                 GC.KeepAlive(this);
106                 GC.KeepAlive(header);
107                 GC.KeepAlive(height);
108         }
109
110 }
111 } } }