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