]> git.bitcoin.ninja Git - ldk-java/blob - ts/structs/RoutingMessageHandler.ts
Merge pull request #29 from TheBlueMatt/main
[ldk-java] / ts / structs / RoutingMessageHandler.ts
1
2             
3 import CommonBase from './CommonBase';
4 import * as bindings from '../bindings' // TODO: figure out location
5
6
7
8             export class RoutingMessageHandler extends CommonBase {
9
10                 bindings_instance?: bindings.LDKRoutingMessageHandler;
11
12                 constructor(ptr?: number, arg?: bindings.LDKRoutingMessageHandler, messageSendEventsProvider?: bindings.LDKMessageSendEventsProvider) {
13                     if (Number.isFinite(ptr)) {
14                                         super(ptr);
15                                         this.bindings_instance = null;
16                                     } else {
17                                         // TODO: private constructor instantiation
18                                         super(bindings.LDKRoutingMessageHandler_new(arg, messageSendEventsProvider));
19                                         this.ptrs_to.push(arg);
20                                         this.ptrs_to.push(messageSendEventsProvider);
21
22                                     }
23                 }
24
25                 protected finalize() {
26                     if (this.ptr != 0) {
27                         bindings.RoutingMessageHandler_free(this.ptr);
28                     }
29                     super.finalize();
30                 }
31
32                 static new_impl(arg: RoutingMessageHandlerInterface, messageSendEventsProvider_impl: MessageSendEventsProvider.MessageSendEventsProviderInterface): RoutingMessageHandler {
33                     const impl_holder: LDKRoutingMessageHandlerHolder = new LDKRoutingMessageHandlerHolder();
34                     let structImplementation = <bindings.LDKRoutingMessageHandler>{
35                         // todo: in-line interface filling
36                         handle_node_announcement (msg: number): number {
37                                                         const msg_hu_conv: NodeAnnouncement = new NodeAnnouncement(null, msg);
38                                                         Result_boolLightningErrorZ ret = arg.handle_node_announcement(msg_hu_conv);
39                                 result: number = ret != null ? ret.ptr : 0;
40                                 return result;
41                                                 },
42
43                                                 handle_channel_announcement (msg: number): number {
44                                                         const msg_hu_conv: ChannelAnnouncement = new ChannelAnnouncement(null, msg);
45                                                         Result_boolLightningErrorZ ret = arg.handle_channel_announcement(msg_hu_conv);
46                                 result: number = ret != null ? ret.ptr : 0;
47                                 return result;
48                                                 },
49
50                                                 handle_channel_update (msg: number): number {
51                                                         const msg_hu_conv: ChannelUpdate = new ChannelUpdate(null, msg);
52                                                         Result_boolLightningErrorZ ret = arg.handle_channel_update(msg_hu_conv);
53                                 result: number = ret != null ? ret.ptr : 0;
54                                 return result;
55                                                 },
56
57                                                 handle_htlc_fail_channel_update (update: number): void {
58                                                         HTLCFailChannelUpdate update_hu_conv = HTLCFailChannelUpdate.constr_from_ptr(update);
59                                                         arg.handle_htlc_fail_channel_update(update_hu_conv);
60                                                 },
61
62                                                 get_next_channel_announcements (starting_point: number, batch_amount: number): number[] {
63                                                         ThreeTuple<ChannelAnnouncement, ChannelUpdate, ChannelUpdate>[] ret = arg.get_next_channel_announcements(starting_point, batch_amount);
64                                 result: number[] = Arrays.stream(ret).map(ret_conv_63 -> bindings.C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ_new(ret_conv_63.a == null ? 0 : ret_conv_63.a.ptr & ~1, ret_conv_63.b == null ? 0 : ret_conv_63.b.ptr & ~1, ret_conv_63.c == null ? 0 : ret_conv_63.c.ptr & ~1)).toArray(number[]::new);
65                                 /* TODO 2 ThreeTuple<ChannelAnnouncement, ChannelUpdate, ChannelUpdate>  */;
66                                 return result;
67                                                 },
68
69                                                 get_next_node_announcements (starting_point: Uint8Array, batch_amount: number): number[] {
70                                                         NodeAnnouncement[] ret = arg.get_next_node_announcements(starting_point, batch_amount);
71                                 result: number[] = Arrays.stream(ret).map(ret_conv_18 -> ret_conv_18 == null ? 0 : ret_conv_18.ptr & ~1).toArray(number[]::new);
72                                 /* TODO 2 NodeAnnouncement  */;
73                                 return result;
74                                                 },
75
76                                                 sync_routing_table (their_node_id: Uint8Array, init: number): void {
77                                                         const init_hu_conv: Init = new Init(null, init);
78                                                         arg.sync_routing_table(their_node_id, init_hu_conv);
79                                                 },
80
81                                                 handle_reply_channel_range (their_node_id: Uint8Array, msg: number): number {
82                                                         const msg_hu_conv: ReplyChannelRange = new ReplyChannelRange(null, msg);
83                                 msg_hu_conv.ptrs_to.add(this);
84                                                         Result_NoneLightningErrorZ ret = arg.handle_reply_channel_range(their_node_id, msg_hu_conv);
85                                 result: number = ret != null ? ret.ptr : 0;
86                                 return result;
87                                                 },
88
89                                                 handle_reply_short_channel_ids_end (their_node_id: Uint8Array, msg: number): number {
90                                                         const msg_hu_conv: ReplyShortChannelIdsEnd = new ReplyShortChannelIdsEnd(null, msg);
91                                 msg_hu_conv.ptrs_to.add(this);
92                                                         Result_NoneLightningErrorZ ret = arg.handle_reply_short_channel_ids_end(their_node_id, msg_hu_conv);
93                                 result: number = ret != null ? ret.ptr : 0;
94                                 return result;
95                                                 },
96
97                                                 handle_query_channel_range (their_node_id: Uint8Array, msg: number): number {
98                                                         const msg_hu_conv: QueryChannelRange = new QueryChannelRange(null, msg);
99                                 msg_hu_conv.ptrs_to.add(this);
100                                                         Result_NoneLightningErrorZ ret = arg.handle_query_channel_range(their_node_id, msg_hu_conv);
101                                 result: number = ret != null ? ret.ptr : 0;
102                                 return result;
103                                                 },
104
105                                                 handle_query_short_channel_ids (their_node_id: Uint8Array, msg: number): number {
106                                                         const msg_hu_conv: QueryShortChannelIds = new QueryShortChannelIds(null, msg);
107                                 msg_hu_conv.ptrs_to.add(this);
108                                                         Result_NoneLightningErrorZ ret = arg.handle_query_short_channel_ids(their_node_id, msg_hu_conv);
109                                 result: number = ret != null ? ret.ptr : 0;
110                                 return result;
111                                                 },
112
113                                                 
114                     };
115                     impl_holder.held = new RoutingMessageHandler (null, structImplementation, MessageSendEventsProvider.new_impl(MessageSendEventsProvider_impl).bindings_instance);
116                 }
117             }
118
119             export interface RoutingMessageHandlerInterface {
120                 handle_node_announcement(msg: NodeAnnouncement): Result_boolLightningErrorZ;
121                                 handle_channel_announcement(msg: ChannelAnnouncement): Result_boolLightningErrorZ;
122                                 handle_channel_update(msg: ChannelUpdate): Result_boolLightningErrorZ;
123                                 handle_htlc_fail_channel_update(update: HTLCFailChannelUpdate): void;
124                                 get_next_channel_announcements(starting_point: number, batch_amount: number): ThreeTuple<ChannelAnnouncement, ChannelUpdate, ChannelUpdate>[];
125                                 get_next_node_announcements(starting_point: Uint8Array, batch_amount: number): NodeAnnouncement[];
126                                 sync_routing_table(their_node_id: Uint8Array, init: Init): void;
127                                 handle_reply_channel_range(their_node_id: Uint8Array, msg: ReplyChannelRange): Result_NoneLightningErrorZ;
128                                 handle_reply_short_channel_ids_end(their_node_id: Uint8Array, msg: ReplyShortChannelIdsEnd): Result_NoneLightningErrorZ;
129                                 handle_query_channel_range(their_node_id: Uint8Array, msg: QueryChannelRange): Result_NoneLightningErrorZ;
130                                 handle_query_short_channel_ids(their_node_id: Uint8Array, msg: QueryShortChannelIds): Result_NoneLightningErrorZ;
131                                 
132             }
133
134             class LDKRoutingMessageHandlerHolder {
135                 held: RoutingMessageHandler;
136             }
137         public Result_boolLightningErrorZ handle_node_announcement(NodeAnnouncement msg) {
138                 number ret = bindings.RoutingMessageHandler_handle_node_announcement(this.ptr, msg == null ? 0 : msg.ptr & ~1);
139                 Result_boolLightningErrorZ ret_hu_conv = Result_boolLightningErrorZ.constr_from_ptr(ret);
140                 this.ptrs_to.add(msg);
141                 return ret_hu_conv;
142         }
143
144         public Result_boolLightningErrorZ handle_channel_announcement(ChannelAnnouncement msg) {
145                 number ret = bindings.RoutingMessageHandler_handle_channel_announcement(this.ptr, msg == null ? 0 : msg.ptr & ~1);
146                 Result_boolLightningErrorZ ret_hu_conv = Result_boolLightningErrorZ.constr_from_ptr(ret);
147                 this.ptrs_to.add(msg);
148                 return ret_hu_conv;
149         }
150
151         public Result_boolLightningErrorZ handle_channel_update(ChannelUpdate msg) {
152                 number ret = bindings.RoutingMessageHandler_handle_channel_update(this.ptr, msg == null ? 0 : msg.ptr & ~1);
153                 Result_boolLightningErrorZ ret_hu_conv = Result_boolLightningErrorZ.constr_from_ptr(ret);
154                 this.ptrs_to.add(msg);
155                 return ret_hu_conv;
156         }
157
158         public void handle_htlc_fail_channel_update(HTLCFailChannelUpdate update) {
159                 bindings.RoutingMessageHandler_handle_htlc_fail_channel_update(this.ptr, update == null ? 0 : update.ptr & ~1);
160                 this.ptrs_to.add(update);
161         }
162
163         public ThreeTuple<ChannelAnnouncement, ChannelUpdate, ChannelUpdate>[] get_next_channel_announcements(number starting_point, number batch_amount) {
164                 number[] ret = bindings.RoutingMessageHandler_get_next_channel_announcements(this.ptr, starting_point, batch_amount);
165                 ThreeTuple<ChannelAnnouncement, ChannelUpdate, ChannelUpdate>[] ret_conv_63_arr = new ThreeTuple[ret.length];
166                 for (int l = 0; l < ret.length; l++) {
167                         number ret_conv_63 = ret[l];
168                         number ret_conv_63_a = bindings.LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ_get_a(ret_conv_63);
169                         const ret_conv_63_a_hu_conv: ChannelAnnouncement = new ChannelAnnouncement(null, ret_conv_63_a);
170                         ret_conv_63_a_hu_conv.ptrs_to.add(this);;
171                         number ret_conv_63_b = bindings.LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ_get_b(ret_conv_63);
172                         const ret_conv_63_b_hu_conv: ChannelUpdate = new ChannelUpdate(null, ret_conv_63_b);
173                         ret_conv_63_b_hu_conv.ptrs_to.add(this);;
174                         number ret_conv_63_c = bindings.LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ_get_c(ret_conv_63);
175                         const ret_conv_63_c_hu_conv: ChannelUpdate = new ChannelUpdate(null, ret_conv_63_c);
176                         ret_conv_63_c_hu_conv.ptrs_to.add(this);;
177                         ThreeTuple<ChannelAnnouncement, ChannelUpdate, ChannelUpdate> ret_conv_63_conv = new ThreeTuple<ChannelAnnouncement, ChannelUpdate, ChannelUpdate>(ret_conv_63_a_hu_conv, ret_conv_63_b_hu_conv, ret_conv_63_c_hu_conv, () -> {
178                                 bindings.C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ_free(ret_conv_63);
179                         });
180                         ret_conv_63_a_hu_conv.ptrs_to.add(ret_conv_63_conv);
181                         ret_conv_63_b_hu_conv.ptrs_to.add(ret_conv_63_conv);
182                         ret_conv_63_c_hu_conv.ptrs_to.add(ret_conv_63_conv);
183                         ret_conv_63_arr[l] = ret_conv_63_conv;
184                 }
185                 return ret_conv_63_arr;
186         }
187
188         public NodeAnnouncement[] get_next_node_announcements(Uint8Array starting_point, number batch_amount) {
189                 number[] ret = bindings.RoutingMessageHandler_get_next_node_announcements(this.ptr, starting_point, batch_amount);
190                 NodeAnnouncement[] ret_conv_18_arr = new NodeAnnouncement[ret.length];
191                 for (int s = 0; s < ret.length; s++) {
192                         number ret_conv_18 = ret[s];
193                         const ret_conv_18_hu_conv: NodeAnnouncement = new NodeAnnouncement(null, ret_conv_18);
194                         ret_conv_18_hu_conv.ptrs_to.add(this);
195                         ret_conv_18_arr[s] = ret_conv_18_hu_conv;
196                 }
197                 return ret_conv_18_arr;
198         }
199
200         public void sync_routing_table(Uint8Array their_node_id, Init init) {
201                 bindings.RoutingMessageHandler_sync_routing_table(this.ptr, their_node_id, init == null ? 0 : init.ptr & ~1);
202                 this.ptrs_to.add(init);
203         }
204
205         public Result_NoneLightningErrorZ handle_reply_channel_range(Uint8Array their_node_id, ReplyChannelRange msg) {
206                 number ret = bindings.RoutingMessageHandler_handle_reply_channel_range(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
207                 Result_NoneLightningErrorZ ret_hu_conv = Result_NoneLightningErrorZ.constr_from_ptr(ret);
208                 this.ptrs_to.add(msg);
209                 return ret_hu_conv;
210         }
211
212         public Result_NoneLightningErrorZ handle_reply_short_channel_ids_end(Uint8Array their_node_id, ReplyShortChannelIdsEnd msg) {
213                 number ret = bindings.RoutingMessageHandler_handle_reply_short_channel_ids_end(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
214                 Result_NoneLightningErrorZ ret_hu_conv = Result_NoneLightningErrorZ.constr_from_ptr(ret);
215                 this.ptrs_to.add(msg);
216                 return ret_hu_conv;
217         }
218
219         public Result_NoneLightningErrorZ handle_query_channel_range(Uint8Array their_node_id, QueryChannelRange msg) {
220                 number ret = bindings.RoutingMessageHandler_handle_query_channel_range(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
221                 Result_NoneLightningErrorZ ret_hu_conv = Result_NoneLightningErrorZ.constr_from_ptr(ret);
222                 this.ptrs_to.add(msg);
223                 return ret_hu_conv;
224         }
225
226         public Result_NoneLightningErrorZ handle_query_short_channel_ids(Uint8Array their_node_id, QueryShortChannelIds msg) {
227                 number ret = bindings.RoutingMessageHandler_handle_query_short_channel_ids(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
228                 Result_NoneLightningErrorZ ret_hu_conv = Result_NoneLightningErrorZ.constr_from_ptr(ret);
229                 this.ptrs_to.add(msg);
230                 return ret_hu_conv;
231         }
232
233 }