Update auto-generated bindings
[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 javax.annotation.Nullable;
8
9 /**
10  * The `Listen` trait is used to notify when blocks have been connected or disconnected from the
11  * chain.
12  * 
13  * Useful when needing to replay chain data upon startup or as new chain events occur. Clients
14  * sourcing chain data using a block-oriented API should prefer this interface over [`Confirm`].
15  * Such clients fetch the entire header chain whereas clients using [`Confirm`] only fetch headers
16  * when needed.
17  */
18 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
19 public class Listen extends CommonBase {
20         final bindings.LDKListen bindings_instance;
21         Listen(Object _dummy, long ptr) { super(ptr); bindings_instance = null; }
22         private Listen(bindings.LDKListen arg) {
23                 super(bindings.LDKListen_new(arg));
24                 this.ptrs_to.add(arg);
25                 this.bindings_instance = arg;
26         }
27         @Override @SuppressWarnings("deprecation")
28         protected void finalize() throws Throwable {
29                 if (ptr != 0) { bindings.Listen_free(ptr); } super.finalize();
30         }
31
32         public static interface ListenInterface {
33                 /**
34                  * Notifies the listener that a block was added at the given height.
35                  */
36                 void block_connected(byte[] block, int height);
37                 /**
38                  * Notifies the listener that a block was removed at the given height.
39                  */
40                 void block_disconnected(byte[] header, int height);
41         }
42         private static class LDKListenHolder { Listen held; }
43         public static Listen new_impl(ListenInterface arg) {
44                 final LDKListenHolder impl_holder = new LDKListenHolder();
45                 impl_holder.held = new Listen(new bindings.LDKListen() {
46                         @Override public void block_connected(byte[] block, int height) {
47                                 arg.block_connected(block, height);
48                         }
49                         @Override public void block_disconnected(byte[] header, int height) {
50                                 arg.block_disconnected(header, height);
51                         }
52                 });
53                 return impl_holder.held;
54         }
55         /**
56          * Notifies the listener that a block was added at the given height.
57          */
58         public void block_connected(byte[] block, int height) {
59                 bindings.Listen_block_connected(this.ptr, block, height);
60         }
61
62         /**
63          * Notifies the listener that a block was removed at the given height.
64          */
65         public void block_disconnected(byte[] header, int height) {
66                 bindings.Listen_block_disconnected(this.ptr, InternalUtils.check_arr_len(header, 80), height);
67         }
68
69 }