X-Git-Url: http://git.bitcoin.ninja/index.cgi?p=ldk-java;a=blobdiff_plain;f=ts%2Fstructs%2FListen.mts;h=a19b9d5d206a5fc886cf53c3c06ed1b38cebac78;hp=3e3f61c2cfbfcda87134c08dd6e20deea71fe521;hb=c629a01650402c8e2f9b9db8ced9ed63ce687727;hpb=d1d0121c000b713c10fd0bedd249eb8dda2e4db7 diff --git a/ts/structs/Listen.mts b/ts/structs/Listen.mts index 3e3f61c2..a19b9d5d 100644 --- a/ts/structs/Listen.mts +++ b/ts/structs/Listen.mts @@ -283,8 +283,13 @@ import * as bindings from '../bindings.mjs' +/** An implementation of Listen */ export interface ListenInterface { + /**Notifies the listener that a block was added at the given height. + */ block_connected(block: Uint8Array, height: number): void; + /**Notifies the listener that a block was removed at the given height. + */ block_disconnected(header: Uint8Array, height: number): void; } @@ -292,6 +297,15 @@ class LDKListenHolder { held: Listen; } +/** + * 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. + */ export class Listen extends CommonBase { /* @internal */ public bindings_instance?: bindings.LDKListen; @@ -302,7 +316,8 @@ export class Listen extends CommonBase { this.bindings_instance = null; } - static new_impl(arg: ListenInterface): Listen { + /** Creates a new instance of Listen from a given implementation */ + public static new_impl(arg: ListenInterface): Listen { const impl_holder: LDKListenHolder = new LDKListenHolder(); let structImplementation = { block_connected (block: number, height: number): void { @@ -320,10 +335,17 @@ export class Listen extends CommonBase { impl_holder.held.bindings_instance = structImplementation; return impl_holder.held; } + + /** + * Notifies the listener that a block was added at the given height. + */ public block_connected(block: Uint8Array, height: number): void { bindings.Listen_block_connected(this.ptr, bindings.encodeUint8Array(block), height); } + /** + * Notifies the listener that a block was removed at the given height. + */ public block_disconnected(header: Uint8Array, height: number): void { bindings.Listen_block_disconnected(this.ptr, bindings.encodeUint8Array(bindings.check_arr_len(header, 80)), height); }