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<Uint8Array, Type>[] ret = arg.get_and_clear_pending_msg();
46 result: number[] = ret != null ? Arrays.stream(ret).map(ret_conv_28 -> bindings.C2Tuple_PublicKeyTypeZ_new(ret_conv_28.a, ret_conv_28.b == null ? 0 : ret_conv_28.b.ptr)).toArray(number[]::new) : null;
47 for (TwoTuple<Uint8Array, Type> ret_conv_28: ret) { impl_holder.held.ptrs_to.add(ret_conv_28.b); };
53 impl_holder.held = new CustomMessageHandler (null, structImplementation, CustomMessageReader.new_impl(CustomMessageReader_impl).bindings_instance);
57 export interface CustomMessageHandlerInterface {
58 handle_custom_message(msg: Type, sender_node_id: Uint8Array): Result_NoneLightningErrorZ;
59 get_and_clear_pending_msg(): TwoTuple<Uint8Array, Type>[];
63 class LDKCustomMessageHandlerHolder {
64 held: CustomMessageHandler;
66 public Result_NoneLightningErrorZ handle_custom_message(Type msg, Uint8Array sender_node_id) {
67 number ret = bindings.CustomMessageHandler_handle_custom_message(this.ptr, msg == null ? 0 : msg.ptr, sender_node_id);
68 Result_NoneLightningErrorZ ret_hu_conv = Result_NoneLightningErrorZ.constr_from_ptr(ret);
69 this.ptrs_to.add(msg);
73 public TwoTuple<Uint8Array, Type>[] get_and_clear_pending_msg() {
74 number[] ret = bindings.CustomMessageHandler_get_and_clear_pending_msg(this.ptr);
75 TwoTuple<Uint8Array, Type>[] ret_conv_28_arr = new TwoTuple[ret.length];
76 for (int c = 0; c < ret.length; c++) {
77 number ret_conv_28 = ret[c];
78 Uint8Array ret_conv_28_a = bindings.LDKC2Tuple_PublicKeyTypeZ_get_a(ret_conv_28);
79 number ret_conv_28_b = bindings.LDKC2Tuple_PublicKeyTypeZ_get_b(ret_conv_28);
80 Type ret_hu_conv = new Type(null, ret_conv_28_b);
81 ret_hu_conv.ptrs_to.add(this);;
82 TwoTuple<Uint8Array, Type> ret_conv_28_conv = new TwoTuple<Uint8Array, Type>(ret_conv_28_a, ret_hu_conv, () -> {
83 bindings.C2Tuple_PublicKeyTypeZ_free(ret_conv_28);
85 ret_hu_conv.ptrs_to.add(ret_conv_28_conv);
86 ret_conv_28_arr[c] = ret_conv_28_conv;
88 return ret_conv_28_arr;