7 namespace org { namespace ldk { namespace structs {
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
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.
19 void block_connected(byte[] block, int height);
20 /**Notifies the listener that a block was removed at the given height.
22 void block_disconnected(byte[] header, int height);
26 * The `Listen` trait is used to notify when blocks have been connected or disconnected from the
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
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.
38 public class Listen : CommonBase {
39 internal bindings.LDKListen bindings_instance;
40 internal long instance_idx;
42 internal Listen(object _dummy, long ptr) : base(ptr) { bindings_instance = null; }
44 if (ptr != 0) { bindings.Listen_free(ptr); }
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;
62 bindings.free_buffer(_txdata);
63 arg.filtered_block_connected(_header_conv, _txdata_conv_28_arr, _height);
66 public void block_connected(long _block, int _height) {
67 byte[] _block_conv = InternalUtils.decodeUint8Array(_block);
68 arg.block_connected(_block_conv, _height);
71 public void block_disconnected(long _header, int _height) {
72 byte[] _header_conv = InternalUtils.decodeUint8Array(_header);
73 arg.block_disconnected(_header_conv, _height);
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);
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;
91 * Notifies the listener that a block was added at the given height, with the transaction data
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);
103 * Notifies the listener that a block was added at the given height.
105 public void block_connected(byte[] block, int height) {
106 bindings.Listen_block_connected(this.ptr, InternalUtils.encodeUint8Array(block), height);
109 GC.KeepAlive(height);
113 * Notifies the listener that a block was removed at the given height.
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);
118 GC.KeepAlive(header);
119 GC.KeepAlive(height);