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