3 import CommonBase from './CommonBase';
4 import * as bindings from '../bindings' // TODO: figure out location
8 export class CustomMessageHandler extends CommonBase {
10 bindings_instance?: bindings.LDKCustomMessageHandler;
12 constructor(ptr?: number, arg?: bindings.LDKCustomMessageHandler, customMessageReader?: bindings.LDKCustomMessageReader) {
13 if (Number.isFinite(ptr)) {
15 this.bindings_instance = null;
17 // TODO: private constructor instantiation
18 super(bindings.LDKCustomMessageHandler_new(arg, customMessageReader));
19 this.ptrs_to.push(arg);
20 this.ptrs_to.push(customMessageReader);
25 protected finalize() {
27 bindings.CustomMessageHandler_free(this.ptr);
32 static new_impl(arg: CustomMessageHandlerInterface, customMessageReader_impl: CustomMessageReader.CustomMessageReaderInterface): CustomMessageHandler {
33 const impl_holder: LDKCustomMessageHandlerHolder = new LDKCustomMessageHandlerHolder();
34 let structImplementation = <bindings.LDKCustomMessageHandler>{
35 // todo: in-line interface filling
36 handle_custom_message (msg: number, sender_node_id: Uint8Array): number {
37 Type ret_hu_conv = new Type(null, msg);
38 ret_hu_conv.ptrs_to.add(this);
39 Result_NoneLightningErrorZ ret = arg.handle_custom_message(ret_hu_conv, sender_node_id);
40 result: number = ret != null ? ret.ptr : 0;
44 get_and_clear_pending_msg (): number[] {
45 TwoTuple_PublicKeyTypeZ[] ret = arg.get_and_clear_pending_msg();
46 result: number[] = ret != null ? Arrays.stream(ret).map(ret_conv_25 -> ret_conv_25 != null ? ret_conv_25.ptr : 0).toArray(number[]::new) : null;
52 impl_holder.held = new CustomMessageHandler (null, structImplementation, CustomMessageReader.new_impl(CustomMessageReader_impl).bindings_instance);
56 export interface CustomMessageHandlerInterface {
57 handle_custom_message(msg: Type, sender_node_id: Uint8Array): Result_NoneLightningErrorZ;
58 get_and_clear_pending_msg(): TwoTuple_PublicKeyTypeZ[];
62 class LDKCustomMessageHandlerHolder {
63 held: CustomMessageHandler;
65 public Result_NoneLightningErrorZ handle_custom_message(Type msg, Uint8Array sender_node_id) {
66 number ret = bindings.CustomMessageHandler_handle_custom_message(this.ptr, msg == null ? 0 : msg.ptr, sender_node_id);
67 Result_NoneLightningErrorZ ret_hu_conv = Result_NoneLightningErrorZ.constr_from_ptr(ret);
68 this.ptrs_to.add(msg);
72 public TwoTuple_PublicKeyTypeZ[] get_and_clear_pending_msg() {
73 number[] ret = bindings.CustomMessageHandler_get_and_clear_pending_msg(this.ptr);
74 TwoTuple_PublicKeyTypeZ[] ret_conv_25_arr = new TwoTuple_PublicKeyTypeZ[ret.length];
75 for (int z = 0; z < ret.length; z++) {
76 number ret_conv_25 = ret[z];
77 TwoTuple_PublicKeyTypeZ ret_conv_25_hu_conv = new TwoTuple_PublicKeyTypeZ(null, ret_conv_25);
78 ret_conv_25_hu_conv.ptrs_to.add(this);
79 ret_conv_25_arr[z] = ret_conv_25_hu_conv;
81 return ret_conv_25_arr;