[Java] Update auto-generated Java structs
[ldk-java] / src / main / java / org / ldk / structs / Listen.java
1 package org.ldk.structs;
2
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
5 import org.ldk.util.*;
6 import java.util.Arrays;
7 import java.lang.ref.Reference;
8 import javax.annotation.Nullable;
9
10 /**
11  * The `Listen` trait is used to notify when blocks have been connected or disconnected from the
12  * chain.
13  * 
14  * Useful when needing to replay chain data upon startup or as new chain events occur. Clients
15  * sourcing chain data using a block-oriented API should prefer this interface over [`Confirm`].
16  * Such clients fetch the entire header chain whereas clients using [`Confirm`] only fetch headers
17  * when needed.
18  * 
19  * By using [`Listen::filtered_block_connected`] this interface supports clients fetching the
20  * entire header chain and only blocks with matching transaction data using BIP 157 filters or
21  * other similar filtering.
22  */
23 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
24 public class Listen extends CommonBase {
25         final bindings.LDKListen bindings_instance;
26         Listen(Object _dummy, long ptr) { super(ptr); bindings_instance = null; }
27         private Listen(bindings.LDKListen arg) {
28                 super(bindings.LDKListen_new(arg));
29                 this.ptrs_to.add(arg);
30                 this.bindings_instance = arg;
31         }
32         @Override @SuppressWarnings("deprecation")
33         protected void finalize() throws Throwable {
34                 if (ptr != 0) { bindings.Listen_free(ptr); } super.finalize();
35         }
36
37         public static interface ListenInterface {
38                 /**
39                  * Notifies the listener that a block was added at the given height, with the transaction data
40                  * possibly filtered.
41                  */
42                 void filtered_block_connected(byte[] header, TwoTuple_usizeTransactionZ[] txdata, int height);
43                 /**
44                  * Notifies the listener that a block was added at the given height.
45                  */
46                 void block_connected(byte[] block, int height);
47                 /**
48                  * Notifies the listener that a block was removed at the given height.
49                  */
50                 void block_disconnected(byte[] header, int height);
51         }
52         private static class LDKListenHolder { Listen held; }
53         public static Listen new_impl(ListenInterface arg) {
54                 final LDKListenHolder impl_holder = new LDKListenHolder();
55                 impl_holder.held = new Listen(new bindings.LDKListen() {
56                         @Override public void filtered_block_connected(byte[] header, long[] txdata, int height) {
57                                 int txdata_conv_28_len = txdata.length;
58                                 TwoTuple_usizeTransactionZ[] txdata_conv_28_arr = new TwoTuple_usizeTransactionZ[txdata_conv_28_len];
59                                 for (int c = 0; c < txdata_conv_28_len; c++) {
60                                         long txdata_conv_28 = txdata[c];
61                                         TwoTuple_usizeTransactionZ txdata_conv_28_hu_conv = new TwoTuple_usizeTransactionZ(null, txdata_conv_28);
62                                         if (txdata_conv_28_hu_conv != null) { txdata_conv_28_hu_conv.ptrs_to.add(this); };
63                                         txdata_conv_28_arr[c] = txdata_conv_28_hu_conv;
64                                 }
65                                 arg.filtered_block_connected(header, txdata_conv_28_arr, height);
66                                 Reference.reachabilityFence(arg);
67                         }
68                         @Override public void block_connected(byte[] block, int height) {
69                                 arg.block_connected(block, height);
70                                 Reference.reachabilityFence(arg);
71                         }
72                         @Override public void block_disconnected(byte[] header, int height) {
73                                 arg.block_disconnected(header, height);
74                                 Reference.reachabilityFence(arg);
75                         }
76                 });
77                 return impl_holder.held;
78         }
79         /**
80          * Notifies the listener that a block was added at the given height, with the transaction data
81          * possibly filtered.
82          */
83         public void filtered_block_connected(byte[] header, TwoTuple_usizeTransactionZ[] txdata, int height) {
84                 bindings.Listen_filtered_block_connected(this.ptr, InternalUtils.check_arr_len(header, 80), txdata != null ? Arrays.stream(txdata).mapToLong(txdata_conv_28 -> txdata_conv_28 != null ? txdata_conv_28.ptr : 0).toArray() : null, height);
85                 Reference.reachabilityFence(this);
86                 Reference.reachabilityFence(header);
87                 Reference.reachabilityFence(txdata);
88                 Reference.reachabilityFence(height);
89         }
90
91         /**
92          * Notifies the listener that a block was added at the given height.
93          */
94         public void block_connected(byte[] block, int height) {
95                 bindings.Listen_block_connected(this.ptr, block, height);
96                 Reference.reachabilityFence(this);
97                 Reference.reachabilityFence(block);
98                 Reference.reachabilityFence(height);
99         }
100
101         /**
102          * Notifies the listener that a block was removed at the given height.
103          */
104         public void block_disconnected(byte[] header, int height) {
105                 bindings.Listen_block_disconnected(this.ptr, InternalUtils.check_arr_len(header, 80), height);
106                 Reference.reachabilityFence(this);
107                 Reference.reachabilityFence(header);
108                 Reference.reachabilityFence(height);
109         }
110
111 }