[TS] Update auto-generated TypeScript Bindings
[ldk-java] / ts / structs / CustomMessageHandler.mts
index 61419412e0f848d1f120013a91186daba0642ddc..db8cf77b488706f346e656148b9e60a53ad87dd9 100644 (file)
@@ -280,12 +280,20 @@ import { MultiThreadedLockableScore } from '../structs/MultiThreadedLockableScor
 
 import CommonBase from './CommonBase.mjs';
 import * as bindings from '../bindings.mjs'
-import * as InternalUtils from '../InternalUtils.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[];
 }
 
@@ -293,6 +301,9 @@ class LDKCustomMessageHandlerHolder {
        held: CustomMessageHandler;
 }
 
+/**
+ * Handler for BOLT1-compliant messages.
+ */
 export class CustomMessageHandler extends CommonBase {
        /* @internal */
        public bindings_instance?: bindings.LDKCustomMessageHandler;
@@ -303,19 +314,21 @@ 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: Uint8Array): number {
+                       handle_custom_message (msg: number, sender_node_id: number): number {
                                const ret_hu_conv: Type = new Type(null, msg);
                                CommonBase.add_ref_from(ret_hu_conv, this);
-                               const ret: Result_NoneLightningErrorZ = arg.handle_custom_message(ret_hu_conv, sender_node_id);
+                               const sender_node_id_conv: Uint8Array = bindings.decodeUint8Array(sender_node_id);
+                               const ret: Result_NoneLightningErrorZ = arg.handle_custom_message(ret_hu_conv, sender_node_id_conv);
                                const result: number = ret == null ? 0 : ret.clone_ptr();
                                return result;
                        },
-                       get_and_clear_pending_msg (): number[] {
+                       get_and_clear_pending_msg (): number {
                                const ret: TwoTuple_PublicKeyTypeZ[] = arg.get_and_clear_pending_msg();
-                               const result: number[] = ret != null ? ret.map(ret_conv_25 => ret_conv_25 == null ? 0 : ret_conv_25.clone_ptr()) : null;
+                               const result: number = bindings.encodeUint32Array(ret != null ? ret.map(ret_conv_25 => ret_conv_25 == null ? 0 : ret_conv_25.clone_ptr()) : null);
                                return result;
                        },
                } as bindings.LDKCustomMessageHandler;
@@ -327,22 +340,35 @@ 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), InternalUtils.check_arr_len(sender_node_id, 33));
+               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);
                CommonBase.add_ref_from(this, msg);
                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_arr: TwoTuple_PublicKeyTypeZ[] = new Array(ret.length).fill(null);
-               for (var z = 0; z < ret.length; z++) {
-                       const ret_conv_25: number = ret[z];
+               const ret: number = bindings.CustomMessageHandler_get_and_clear_pending_msg(this.ptr);
+               const ret_conv_25_len: number = bindings.getArrayLength(ret);
+               const ret_conv_25_arr: TwoTuple_PublicKeyTypeZ[] = new Array(ret_conv_25_len).fill(null);
+               for (var z = 0; z < ret_conv_25_len; z++) {
+                       const ret_conv_25: number = bindings.getU32ArrayElem(ret, z);
                        const ret_conv_25_hu_conv: TwoTuple_PublicKeyTypeZ = new TwoTuple_PublicKeyTypeZ(null, ret_conv_25);
                        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;
        }