Merge pull request #45 from TheBlueMatt/main
[ldk-java] / ts / structs / CustomMessageHandler.ts
1
2             
3 import CommonBase from './CommonBase';
4 import * as bindings from '../bindings' // TODO: figure out location
5
6
7
8             export class CustomMessageHandler extends CommonBase {
9
10                 bindings_instance?: bindings.LDKCustomMessageHandler;
11
12                 constructor(ptr?: number, arg?: bindings.LDKCustomMessageHandler, customMessageReader?: bindings.LDKCustomMessageReader) {
13                     if (Number.isFinite(ptr)) {
14                                         super(ptr);
15                                         this.bindings_instance = null;
16                                     } else {
17                                         // TODO: private constructor instantiation
18                                         super(bindings.LDKCustomMessageHandler_new(arg, customMessageReader));
19                                         this.ptrs_to.push(arg);
20                                         this.ptrs_to.push(customMessageReader);
21
22                                     }
23                 }
24
25                 protected finalize() {
26                     if (this.ptr != 0) {
27                         bindings.CustomMessageHandler_free(this.ptr);
28                     }
29                     super.finalize();
30                 }
31
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;
41                                 return result;
42                                                 },
43
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); };
48                                 return result;
49                                                 },
50
51                                                 
52                     };
53                     impl_holder.held = new CustomMessageHandler (null, structImplementation, CustomMessageReader.new_impl(CustomMessageReader_impl).bindings_instance);
54                 }
55             }
56
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>[];
60                                 
61             }
62
63             class LDKCustomMessageHandlerHolder {
64                 held: CustomMessageHandler;
65             }
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);
70                 return ret_hu_conv;
71         }
72
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);
84                         });
85                         ret_hu_conv.ptrs_to.add(ret_conv_28_conv);
86                         ret_conv_28_arr[c] = ret_conv_28_conv;
87                 }
88                 return ret_conv_28_arr;
89         }
90
91 }