X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fldk%2Fstructs%2FListen.java;h=93c1fc228dc5d4e934bb306486397873123959f2;hb=1854b5cebef22ace9e9e4dd191f609818df9ce08;hp=075137cbc3d63db05d038cf817e4625ddf0f9cb8;hpb=246459dcbc3be28c38b4951140a5933f4b3aa024;p=ldk-java diff --git a/src/main/java/org/ldk/structs/Listen.java b/src/main/java/org/ldk/structs/Listen.java index 075137cb..93c1fc22 100644 --- a/src/main/java/org/ldk/structs/Listen.java +++ b/src/main/java/org/ldk/structs/Listen.java @@ -4,7 +4,18 @@ import org.ldk.impl.bindings; import org.ldk.enums.*; import org.ldk.util.*; import java.util.Arrays; +import java.lang.ref.Reference; +import javax.annotation.Nullable; +/** + * The `Listen` trait is used to notify when blocks have been connected or disconnected from the + * chain. + * + * Useful when needing to replay chain data upon startup or as new chain events occur. Clients + * sourcing chain data using a block-oriented API should prefer this interface over [`Confirm`]. + * Such clients fetch the entire header chain whereas clients using [`Confirm`] only fetch headers + * when needed. + */ @SuppressWarnings("unchecked") // We correctly assign various generic arrays public class Listen extends CommonBase { final bindings.LDKListen bindings_instance; @@ -20,7 +31,13 @@ public class Listen extends CommonBase { } public static interface ListenInterface { + /** + * Notifies the listener that a block was added at the given height. + */ void block_connected(byte[] block, int height); + /** + * Notifies the listener that a block was removed at the given height. + */ void block_disconnected(byte[] header, int height); } private static class LDKListenHolder { Listen held; } @@ -36,12 +53,24 @@ public class Listen extends CommonBase { }); return impl_holder.held; } + /** + * Notifies the listener that a block was added at the given height. + */ public void block_connected(byte[] block, int height) { bindings.Listen_block_connected(this.ptr, block, height); + Reference.reachabilityFence(this); + Reference.reachabilityFence(block); + Reference.reachabilityFence(height); } + /** + * Notifies the listener that a block was removed at the given height. + */ public void block_disconnected(byte[] header, int height) { - bindings.Listen_block_disconnected(this.ptr, header, height); + bindings.Listen_block_disconnected(this.ptr, InternalUtils.check_arr_len(header, 80), height); + Reference.reachabilityFence(this); + Reference.reachabilityFence(header); + Reference.reachabilityFence(height); } }