1 package org.ldk.structs;
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
6 import java.util.Arrays;
7 import javax.annotation.Nullable;
10 * The `Listen` trait is used to notify when blocks have been connected or disconnected from the
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
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;
27 @Override @SuppressWarnings("deprecation")
28 protected void finalize() throws Throwable {
29 if (ptr != 0) { bindings.Listen_free(ptr); } super.finalize();
32 public static interface ListenInterface {
34 * Notifies the listener that a block was added at the given height.
36 void block_connected(byte[] block, int height);
38 * Notifies the listener that a block was removed at the given height.
40 void block_disconnected(byte[] header, int height);
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);
49 @Override public void block_disconnected(byte[] header, int height) {
50 arg.block_disconnected(header, height);
53 return impl_holder.held;
56 * Notifies the listener that a block was added at the given height.
58 public void block_connected(byte[] block, int height) {
59 bindings.Listen_block_connected(this.ptr, block, height);
63 * Notifies the listener that a block was removed at the given height.
65 public void block_disconnected(byte[] header, int height) {
66 bindings.Listen_block_disconnected(this.ptr, header, height);