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