6 namespace org { namespace ldk { namespace structs {
9 * The `Listen` trait is used to notify when blocks have been connected or disconnected from the
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
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.
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;
29 if (ptr != 0) { bindings.Listen_free(ptr); }
32 public interface ListenInterface {
34 * Notifies the listener that a block was added at the given height, with the transaction data
37 void filtered_block_connected(byte[] _header, TwoTuple_usizeTransactionZ[] _txdata, int _height);
39 * Notifies the listener that a block was added at the given height.
41 void block_connected(byte[] _block, int _height);
43 * Notifies the listener that a block was removed at the given height.
45 void block_disconnected(byte[] _header, int _height);
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;
61 arg.filtered_block_connected(_header, _txdata_conv_28_arr, _height);
64 public void block_connected(byte[] _block, int _height) {
65 arg.block_connected(_block, _height);
68 public void block_disconnected(byte[] _header, int _height) {
69 arg.block_disconnected(_header, _height);
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;
79 * Notifies the listener that a block was added at the given height, with the transaction data
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);
91 * Notifies the listener that a block was added at the given height.
93 public void block_connected(byte[] block, int height) {
94 bindings.Listen_block_connected(this.ptr, block, height);
101 * Notifies the listener that a block was removed at the given height.
103 public void block_disconnected(byte[] header, int height) {
104 bindings.Listen_block_disconnected(this.ptr, InternalUtils.check_arr_len(header, 80), height);
106 GC.KeepAlive(header);
107 GC.KeepAlive(height);