1 package org.ldk.structs;
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
6 import java.util.Arrays;
9 * The `Listen` trait is used to notify when blocks have been connected or disconnected from the
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
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;
26 @Override @SuppressWarnings("deprecation")
27 protected void finalize() throws Throwable {
28 if (ptr != 0) { bindings.Listen_free(ptr); } super.finalize();
31 public static interface ListenInterface {
33 * Notifies the listener that a block was added at the given height.
35 void block_connected(byte[] block, int height);
37 * Notifies the listener that a block was removed at the given height.
39 void block_disconnected(byte[] header, int height);
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);
48 @Override public void block_disconnected(byte[] header, int height) {
49 arg.block_disconnected(header, height);
52 return impl_holder.held;
55 * Notifies the listener that a block was added at the given height.
57 public void block_connected(byte[] block, int height) {
58 bindings.Listen_block_connected(this.ptr, block, height);
62 * Notifies the listener that a block was removed at the given height.
64 public void block_disconnected(byte[] header, int height) {
65 bindings.Listen_block_disconnected(this.ptr, header, height);