X-Git-Url: http://git.bitcoin.ninja/index.cgi?p=ldk-java;a=blobdiff_plain;f=ts%2Fstructs%2FCustomMessageHandler.mts;h=db8cf77b488706f346e656148b9e60a53ad87dd9;hp=585e17d35e4a8a5a69d6c3a0c5c5c75436ee5803;hb=c629a01650402c8e2f9b9db8ced9ed63ce687727;hpb=d1d0121c000b713c10fd0bedd249eb8dda2e4db7 diff --git a/ts/structs/CustomMessageHandler.mts b/ts/structs/CustomMessageHandler.mts index 585e17d3..db8cf77b 100644 --- a/ts/structs/CustomMessageHandler.mts +++ b/ts/structs/CustomMessageHandler.mts @@ -283,8 +283,17 @@ import * as bindings from '../bindings.mjs' +/** An implementation of CustomMessageHandler */ export interface CustomMessageHandlerInterface { + /**Called with the message type that was received and the buffer to be read. + * Can return a `MessageHandlingError` if the message could not be handled. + */ handle_custom_message(msg: Type, sender_node_id: Uint8Array): Result_NoneLightningErrorZ; + /**Gets the list of pending messages which were generated by the custom message + * handler, clearing the list in the process. The first tuple element must + * correspond to the intended recipients node ids. If no connection to one of the + * specified node does not exist, the message is simply not sent to it. + */ get_and_clear_pending_msg(): TwoTuple_PublicKeyTypeZ[]; } @@ -292,6 +301,9 @@ class LDKCustomMessageHandlerHolder { held: CustomMessageHandler; } +/** + * Handler for BOLT1-compliant messages. + */ export class CustomMessageHandler extends CommonBase { /* @internal */ public bindings_instance?: bindings.LDKCustomMessageHandler; @@ -302,7 +314,8 @@ export class CustomMessageHandler extends CommonBase { this.bindings_instance = null; } - static new_impl(arg: CustomMessageHandlerInterface, customMessageReader_impl: CustomMessageReaderInterface): CustomMessageHandler { + /** Creates a new instance of CustomMessageHandler from a given implementation */ + public static new_impl(arg: CustomMessageHandlerInterface, customMessageReader_impl: CustomMessageReaderInterface): CustomMessageHandler { const impl_holder: LDKCustomMessageHandlerHolder = new LDKCustomMessageHandlerHolder(); let structImplementation = { handle_custom_message (msg: number, sender_node_id: number): number { @@ -327,6 +340,11 @@ export class CustomMessageHandler extends CommonBase { impl_holder.held.ptrs_to.push(customMessageReader); return impl_holder.held; } + + /** + * Called with the message type that was received and the buffer to be read. + * Can return a `MessageHandlingError` if the message could not be handled. + */ public handle_custom_message(msg: Type, sender_node_id: Uint8Array): Result_NoneLightningErrorZ { const ret: number = bindings.CustomMessageHandler_handle_custom_message(this.ptr, msg == null ? 0 : CommonBase.get_ptr_of(msg), bindings.encodeUint8Array(bindings.check_arr_len(sender_node_id, 33))); const ret_hu_conv: Result_NoneLightningErrorZ = Result_NoneLightningErrorZ.constr_from_ptr(ret); @@ -334,6 +352,12 @@ export class CustomMessageHandler extends CommonBase { return ret_hu_conv; } + /** + * Gets the list of pending messages which were generated by the custom message + * handler, clearing the list in the process. The first tuple element must + * correspond to the intended recipients node ids. If no connection to one of the + * specified node does not exist, the message is simply not sent to it. + */ public get_and_clear_pending_msg(): TwoTuple_PublicKeyTypeZ[] { const ret: number = bindings.CustomMessageHandler_get_and_clear_pending_msg(this.ptr); const ret_conv_25_len: number = bindings.getArrayLength(ret); @@ -344,6 +368,7 @@ export class CustomMessageHandler extends CommonBase { CommonBase.add_ref_from(ret_conv_25_hu_conv, this); ret_conv_25_arr[z] = ret_conv_25_hu_conv; } + bindings.freeWasmMemory(ret) return ret_conv_25_arr; }