[Java] Print error stack trace when tests fail
[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          * Destroys the object, freeing associated resources. After this call, any access
38          * to this object may result in a SEGFAULT or worse.
39          *
40          * You should generally NEVER call this method. You should let the garbage collector
41          * do this for you when it finalizes objects. However, it may be useful for types
42          * which represent locks and should be closed immediately to avoid holding locks
43          * until the GC runs.
44          */
45         public void destroy() {
46                 if (ptr != 0) { bindings.Listen_free(ptr); }
47                 ptr = 0;
48         }
49         public static interface ListenInterface {
50                 /**
51                  * Notifies the listener that a block was added at the given height, with the transaction data
52                  * possibly filtered.
53                  */
54                 void filtered_block_connected(byte[] header, TwoTuple_usizeTransactionZ[] txdata, int height);
55                 /**
56                  * Notifies the listener that a block was added at the given height.
57                  */
58                 void block_connected(byte[] block, int height);
59                 /**
60                  * Notifies the listener that a block was removed at the given height.
61                  */
62                 void block_disconnected(byte[] header, int height);
63         }
64         private static class LDKListenHolder { Listen held; }
65         public static Listen new_impl(ListenInterface arg) {
66                 final LDKListenHolder impl_holder = new LDKListenHolder();
67                 impl_holder.held = new Listen(new bindings.LDKListen() {
68                         @Override public void filtered_block_connected(byte[] header, long[] txdata, int height) {
69                                 int txdata_conv_28_len = txdata.length;
70                                 TwoTuple_usizeTransactionZ[] txdata_conv_28_arr = new TwoTuple_usizeTransactionZ[txdata_conv_28_len];
71                                 for (int c = 0; c < txdata_conv_28_len; c++) {
72                                         long txdata_conv_28 = txdata[c];
73                                         TwoTuple_usizeTransactionZ txdata_conv_28_hu_conv = new TwoTuple_usizeTransactionZ(null, txdata_conv_28);
74                                         if (txdata_conv_28_hu_conv != null) { txdata_conv_28_hu_conv.ptrs_to.add(this); };
75                                         txdata_conv_28_arr[c] = txdata_conv_28_hu_conv;
76                                 }
77                                 arg.filtered_block_connected(header, txdata_conv_28_arr, height);
78                                 Reference.reachabilityFence(arg);
79                         }
80                         @Override public void block_connected(byte[] block, int height) {
81                                 arg.block_connected(block, height);
82                                 Reference.reachabilityFence(arg);
83                         }
84                         @Override public void block_disconnected(byte[] header, int height) {
85                                 arg.block_disconnected(header, height);
86                                 Reference.reachabilityFence(arg);
87                         }
88                 });
89                 return impl_holder.held;
90         }
91         /**
92          * Notifies the listener that a block was added at the given height, with the transaction data
93          * possibly filtered.
94          */
95         public void filtered_block_connected(byte[] header, TwoTuple_usizeTransactionZ[] txdata, int height) {
96                 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.ptr).toArray() : null, height);
97                 Reference.reachabilityFence(this);
98                 Reference.reachabilityFence(header);
99                 Reference.reachabilityFence(txdata);
100                 Reference.reachabilityFence(height);
101         }
102
103         /**
104          * Notifies the listener that a block was added at the given height.
105          */
106         public void block_connected(byte[] block, int height) {
107                 bindings.Listen_block_connected(this.ptr, block, height);
108                 Reference.reachabilityFence(this);
109                 Reference.reachabilityFence(block);
110                 Reference.reachabilityFence(height);
111         }
112
113         /**
114          * Notifies the listener that a block was removed at the given height.
115          */
116         public void block_disconnected(byte[] header, int height) {
117                 bindings.Listen_block_disconnected(this.ptr, InternalUtils.check_arr_len(header, 80), height);
118                 Reference.reachabilityFence(this);
119                 Reference.reachabilityFence(header);
120                 Reference.reachabilityFence(height);
121         }
122
123 }