Update auto-generated bindings
[ldk-java] / src / main / java / org / ldk / structs / ChannelMessageHandler.java
1 package org.ldk.structs;
2
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
5 import org.ldk.util.*;
6 import java.util.Arrays;
7
8 /**
9  * A trait to describe an object which can receive channel messages.
10  * 
11  * Messages MAY be called in parallel when they originate from different their_node_ids, however
12  * they MUST NOT be called in parallel when the two calls have the same their_node_id.
13  */
14 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
15 public class ChannelMessageHandler extends CommonBase {
16         final bindings.LDKChannelMessageHandler bindings_instance;
17         ChannelMessageHandler(Object _dummy, long ptr) { super(ptr); bindings_instance = null; }
18         private ChannelMessageHandler(bindings.LDKChannelMessageHandler arg, bindings.LDKMessageSendEventsProvider MessageSendEventsProvider) {
19                 super(bindings.LDKChannelMessageHandler_new(arg, MessageSendEventsProvider));
20                 this.ptrs_to.add(arg);
21                 this.ptrs_to.add(MessageSendEventsProvider);
22                 this.bindings_instance = arg;
23         }
24         @Override @SuppressWarnings("deprecation")
25         protected void finalize() throws Throwable {
26                 if (ptr != 0) { bindings.ChannelMessageHandler_free(ptr); } super.finalize();
27         }
28
29         public static interface ChannelMessageHandlerInterface {
30                 /**
31                  * Handle an incoming open_channel message from the given peer.
32                  */
33                 void handle_open_channel(byte[] their_node_id, InitFeatures their_features, OpenChannel msg);
34                 /**
35                  * Handle an incoming accept_channel message from the given peer.
36                  */
37                 void handle_accept_channel(byte[] their_node_id, InitFeatures their_features, AcceptChannel msg);
38                 /**
39                  * Handle an incoming funding_created message from the given peer.
40                  */
41                 void handle_funding_created(byte[] their_node_id, FundingCreated msg);
42                 /**
43                  * Handle an incoming funding_signed message from the given peer.
44                  */
45                 void handle_funding_signed(byte[] their_node_id, FundingSigned msg);
46                 /**
47                  * Handle an incoming funding_locked message from the given peer.
48                  */
49                 void handle_funding_locked(byte[] their_node_id, FundingLocked msg);
50                 /**
51                  * Handle an incoming shutdown message from the given peer.
52                  */
53                 void handle_shutdown(byte[] their_node_id, InitFeatures their_features, Shutdown msg);
54                 /**
55                  * Handle an incoming closing_signed message from the given peer.
56                  */
57                 void handle_closing_signed(byte[] their_node_id, ClosingSigned msg);
58                 /**
59                  * Handle an incoming update_add_htlc message from the given peer.
60                  */
61                 void handle_update_add_htlc(byte[] their_node_id, UpdateAddHTLC msg);
62                 /**
63                  * Handle an incoming update_fulfill_htlc message from the given peer.
64                  */
65                 void handle_update_fulfill_htlc(byte[] their_node_id, UpdateFulfillHTLC msg);
66                 /**
67                  * Handle an incoming update_fail_htlc message from the given peer.
68                  */
69                 void handle_update_fail_htlc(byte[] their_node_id, UpdateFailHTLC msg);
70                 /**
71                  * Handle an incoming update_fail_malformed_htlc message from the given peer.
72                  */
73                 void handle_update_fail_malformed_htlc(byte[] their_node_id, UpdateFailMalformedHTLC msg);
74                 /**
75                  * Handle an incoming commitment_signed message from the given peer.
76                  */
77                 void handle_commitment_signed(byte[] their_node_id, CommitmentSigned msg);
78                 /**
79                  * Handle an incoming revoke_and_ack message from the given peer.
80                  */
81                 void handle_revoke_and_ack(byte[] their_node_id, RevokeAndACK msg);
82                 /**
83                  * Handle an incoming update_fee message from the given peer.
84                  */
85                 void handle_update_fee(byte[] their_node_id, UpdateFee msg);
86                 /**
87                  * Handle an incoming announcement_signatures message from the given peer.
88                  */
89                 void handle_announcement_signatures(byte[] their_node_id, AnnouncementSignatures msg);
90                 /**
91                  * Indicates a connection to the peer failed/an existing connection was lost. If no connection
92                  * is believed to be possible in the future (eg they're sending us messages we don't
93                  * understand or indicate they require unknown feature bits), no_connection_possible is set
94                  * and any outstanding channels should be failed.
95                  */
96                 void peer_disconnected(byte[] their_node_id, boolean no_connection_possible);
97                 /**
98                  * Handle a peer reconnecting, possibly generating channel_reestablish message(s).
99                  */
100                 void peer_connected(byte[] their_node_id, Init msg);
101                 /**
102                  * Handle an incoming channel_reestablish message from the given peer.
103                  */
104                 void handle_channel_reestablish(byte[] their_node_id, ChannelReestablish msg);
105                 /**
106                  * Handle an incoming channel update from the given peer.
107                  */
108                 void handle_channel_update(byte[] their_node_id, ChannelUpdate msg);
109                 /**
110                  * Handle an incoming error message from the given peer.
111                  */
112                 void handle_error(byte[] their_node_id, ErrorMessage msg);
113         }
114         private static class LDKChannelMessageHandlerHolder { ChannelMessageHandler held; }
115         public static ChannelMessageHandler new_impl(ChannelMessageHandlerInterface arg, MessageSendEventsProvider.MessageSendEventsProviderInterface MessageSendEventsProvider_impl) {
116                 final LDKChannelMessageHandlerHolder impl_holder = new LDKChannelMessageHandlerHolder();
117                 impl_holder.held = new ChannelMessageHandler(new bindings.LDKChannelMessageHandler() {
118                         @Override public void handle_open_channel(byte[] their_node_id, long their_features, long msg) {
119                                 InitFeatures their_features_hu_conv = new InitFeatures(null, their_features);
120                                 their_features_hu_conv.ptrs_to.add(this);
121                                 OpenChannel msg_hu_conv = new OpenChannel(null, msg);
122                                 arg.handle_open_channel(their_node_id, their_features_hu_conv, msg_hu_conv);
123                         }
124                         @Override public void handle_accept_channel(byte[] their_node_id, long their_features, long msg) {
125                                 InitFeatures their_features_hu_conv = new InitFeatures(null, their_features);
126                                 their_features_hu_conv.ptrs_to.add(this);
127                                 AcceptChannel msg_hu_conv = new AcceptChannel(null, msg);
128                                 arg.handle_accept_channel(their_node_id, their_features_hu_conv, msg_hu_conv);
129                         }
130                         @Override public void handle_funding_created(byte[] their_node_id, long msg) {
131                                 FundingCreated msg_hu_conv = new FundingCreated(null, msg);
132                                 arg.handle_funding_created(their_node_id, msg_hu_conv);
133                         }
134                         @Override public void handle_funding_signed(byte[] their_node_id, long msg) {
135                                 FundingSigned msg_hu_conv = new FundingSigned(null, msg);
136                                 arg.handle_funding_signed(their_node_id, msg_hu_conv);
137                         }
138                         @Override public void handle_funding_locked(byte[] their_node_id, long msg) {
139                                 FundingLocked msg_hu_conv = new FundingLocked(null, msg);
140                                 arg.handle_funding_locked(their_node_id, msg_hu_conv);
141                         }
142                         @Override public void handle_shutdown(byte[] their_node_id, long their_features, long msg) {
143                                 InitFeatures their_features_hu_conv = new InitFeatures(null, their_features);
144                                 Shutdown msg_hu_conv = new Shutdown(null, msg);
145                                 arg.handle_shutdown(their_node_id, their_features_hu_conv, msg_hu_conv);
146                         }
147                         @Override public void handle_closing_signed(byte[] their_node_id, long msg) {
148                                 ClosingSigned msg_hu_conv = new ClosingSigned(null, msg);
149                                 arg.handle_closing_signed(their_node_id, msg_hu_conv);
150                         }
151                         @Override public void handle_update_add_htlc(byte[] their_node_id, long msg) {
152                                 UpdateAddHTLC msg_hu_conv = new UpdateAddHTLC(null, msg);
153                                 arg.handle_update_add_htlc(their_node_id, msg_hu_conv);
154                         }
155                         @Override public void handle_update_fulfill_htlc(byte[] their_node_id, long msg) {
156                                 UpdateFulfillHTLC msg_hu_conv = new UpdateFulfillHTLC(null, msg);
157                                 arg.handle_update_fulfill_htlc(their_node_id, msg_hu_conv);
158                         }
159                         @Override public void handle_update_fail_htlc(byte[] their_node_id, long msg) {
160                                 UpdateFailHTLC msg_hu_conv = new UpdateFailHTLC(null, msg);
161                                 arg.handle_update_fail_htlc(their_node_id, msg_hu_conv);
162                         }
163                         @Override public void handle_update_fail_malformed_htlc(byte[] their_node_id, long msg) {
164                                 UpdateFailMalformedHTLC msg_hu_conv = new UpdateFailMalformedHTLC(null, msg);
165                                 arg.handle_update_fail_malformed_htlc(their_node_id, msg_hu_conv);
166                         }
167                         @Override public void handle_commitment_signed(byte[] their_node_id, long msg) {
168                                 CommitmentSigned msg_hu_conv = new CommitmentSigned(null, msg);
169                                 arg.handle_commitment_signed(their_node_id, msg_hu_conv);
170                         }
171                         @Override public void handle_revoke_and_ack(byte[] their_node_id, long msg) {
172                                 RevokeAndACK msg_hu_conv = new RevokeAndACK(null, msg);
173                                 arg.handle_revoke_and_ack(their_node_id, msg_hu_conv);
174                         }
175                         @Override public void handle_update_fee(byte[] their_node_id, long msg) {
176                                 UpdateFee msg_hu_conv = new UpdateFee(null, msg);
177                                 arg.handle_update_fee(their_node_id, msg_hu_conv);
178                         }
179                         @Override public void handle_announcement_signatures(byte[] their_node_id, long msg) {
180                                 AnnouncementSignatures msg_hu_conv = new AnnouncementSignatures(null, msg);
181                                 arg.handle_announcement_signatures(their_node_id, msg_hu_conv);
182                         }
183                         @Override public void peer_disconnected(byte[] their_node_id, boolean no_connection_possible) {
184                                 arg.peer_disconnected(their_node_id, no_connection_possible);
185                         }
186                         @Override public void peer_connected(byte[] their_node_id, long msg) {
187                                 Init msg_hu_conv = new Init(null, msg);
188                                 arg.peer_connected(their_node_id, msg_hu_conv);
189                         }
190                         @Override public void handle_channel_reestablish(byte[] their_node_id, long msg) {
191                                 ChannelReestablish msg_hu_conv = new ChannelReestablish(null, msg);
192                                 arg.handle_channel_reestablish(their_node_id, msg_hu_conv);
193                         }
194                         @Override public void handle_channel_update(byte[] their_node_id, long msg) {
195                                 ChannelUpdate msg_hu_conv = new ChannelUpdate(null, msg);
196                                 arg.handle_channel_update(their_node_id, msg_hu_conv);
197                         }
198                         @Override public void handle_error(byte[] their_node_id, long msg) {
199                                 ErrorMessage msg_hu_conv = new ErrorMessage(null, msg);
200                                 arg.handle_error(their_node_id, msg_hu_conv);
201                         }
202                 }, MessageSendEventsProvider.new_impl(MessageSendEventsProvider_impl).bindings_instance);
203                 return impl_holder.held;
204         }
205
206         /**
207          * Gets the underlying MessageSendEventsProvider.
208          */
209         public MessageSendEventsProvider get_message_send_events_provider() {
210                 MessageSendEventsProvider res = new MessageSendEventsProvider(null, bindings.LDKChannelMessageHandler_get_MessageSendEventsProvider(this.ptr));
211                 this.ptrs_to.add(res);
212                 return res;
213         }
214
215         /**
216          * Handle an incoming open_channel message from the given peer.
217          */
218         public void handle_open_channel(byte[] their_node_id, InitFeatures their_features, OpenChannel msg) {
219                 bindings.ChannelMessageHandler_handle_open_channel(this.ptr, their_node_id, their_features == null ? 0 : their_features.ptr & ~1, msg == null ? 0 : msg.ptr & ~1);
220                 this.ptrs_to.add(their_features);
221                 this.ptrs_to.add(msg);
222         }
223
224         /**
225          * Handle an incoming accept_channel message from the given peer.
226          */
227         public void handle_accept_channel(byte[] their_node_id, InitFeatures their_features, AcceptChannel msg) {
228                 bindings.ChannelMessageHandler_handle_accept_channel(this.ptr, their_node_id, their_features == null ? 0 : their_features.ptr & ~1, msg == null ? 0 : msg.ptr & ~1);
229                 this.ptrs_to.add(their_features);
230                 this.ptrs_to.add(msg);
231         }
232
233         /**
234          * Handle an incoming funding_created message from the given peer.
235          */
236         public void handle_funding_created(byte[] their_node_id, FundingCreated msg) {
237                 bindings.ChannelMessageHandler_handle_funding_created(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
238                 this.ptrs_to.add(msg);
239         }
240
241         /**
242          * Handle an incoming funding_signed message from the given peer.
243          */
244         public void handle_funding_signed(byte[] their_node_id, FundingSigned msg) {
245                 bindings.ChannelMessageHandler_handle_funding_signed(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
246                 this.ptrs_to.add(msg);
247         }
248
249         /**
250          * Handle an incoming funding_locked message from the given peer.
251          */
252         public void handle_funding_locked(byte[] their_node_id, FundingLocked msg) {
253                 bindings.ChannelMessageHandler_handle_funding_locked(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
254                 this.ptrs_to.add(msg);
255         }
256
257         /**
258          * Handle an incoming shutdown message from the given peer.
259          */
260         public void handle_shutdown(byte[] their_node_id, InitFeatures their_features, Shutdown msg) {
261                 bindings.ChannelMessageHandler_handle_shutdown(this.ptr, their_node_id, their_features == null ? 0 : their_features.ptr & ~1, msg == null ? 0 : msg.ptr & ~1);
262                 this.ptrs_to.add(their_features);
263                 this.ptrs_to.add(msg);
264         }
265
266         /**
267          * Handle an incoming closing_signed message from the given peer.
268          */
269         public void handle_closing_signed(byte[] their_node_id, ClosingSigned msg) {
270                 bindings.ChannelMessageHandler_handle_closing_signed(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
271                 this.ptrs_to.add(msg);
272         }
273
274         /**
275          * Handle an incoming update_add_htlc message from the given peer.
276          */
277         public void handle_update_add_htlc(byte[] their_node_id, UpdateAddHTLC msg) {
278                 bindings.ChannelMessageHandler_handle_update_add_htlc(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
279                 this.ptrs_to.add(msg);
280         }
281
282         /**
283          * Handle an incoming update_fulfill_htlc message from the given peer.
284          */
285         public void handle_update_fulfill_htlc(byte[] their_node_id, UpdateFulfillHTLC msg) {
286                 bindings.ChannelMessageHandler_handle_update_fulfill_htlc(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
287                 this.ptrs_to.add(msg);
288         }
289
290         /**
291          * Handle an incoming update_fail_htlc message from the given peer.
292          */
293         public void handle_update_fail_htlc(byte[] their_node_id, UpdateFailHTLC msg) {
294                 bindings.ChannelMessageHandler_handle_update_fail_htlc(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
295                 this.ptrs_to.add(msg);
296         }
297
298         /**
299          * Handle an incoming update_fail_malformed_htlc message from the given peer.
300          */
301         public void handle_update_fail_malformed_htlc(byte[] their_node_id, UpdateFailMalformedHTLC msg) {
302                 bindings.ChannelMessageHandler_handle_update_fail_malformed_htlc(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
303                 this.ptrs_to.add(msg);
304         }
305
306         /**
307          * Handle an incoming commitment_signed message from the given peer.
308          */
309         public void handle_commitment_signed(byte[] their_node_id, CommitmentSigned msg) {
310                 bindings.ChannelMessageHandler_handle_commitment_signed(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
311                 this.ptrs_to.add(msg);
312         }
313
314         /**
315          * Handle an incoming revoke_and_ack message from the given peer.
316          */
317         public void handle_revoke_and_ack(byte[] their_node_id, RevokeAndACK msg) {
318                 bindings.ChannelMessageHandler_handle_revoke_and_ack(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
319                 this.ptrs_to.add(msg);
320         }
321
322         /**
323          * Handle an incoming update_fee message from the given peer.
324          */
325         public void handle_update_fee(byte[] their_node_id, UpdateFee msg) {
326                 bindings.ChannelMessageHandler_handle_update_fee(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
327                 this.ptrs_to.add(msg);
328         }
329
330         /**
331          * Handle an incoming announcement_signatures message from the given peer.
332          */
333         public void handle_announcement_signatures(byte[] their_node_id, AnnouncementSignatures msg) {
334                 bindings.ChannelMessageHandler_handle_announcement_signatures(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
335                 this.ptrs_to.add(msg);
336         }
337
338         /**
339          * Indicates a connection to the peer failed/an existing connection was lost. If no connection
340          * is believed to be possible in the future (eg they're sending us messages we don't
341          * understand or indicate they require unknown feature bits), no_connection_possible is set
342          * and any outstanding channels should be failed.
343          */
344         public void peer_disconnected(byte[] their_node_id, boolean no_connection_possible) {
345                 bindings.ChannelMessageHandler_peer_disconnected(this.ptr, their_node_id, no_connection_possible);
346         }
347
348         /**
349          * Handle a peer reconnecting, possibly generating channel_reestablish message(s).
350          */
351         public void peer_connected(byte[] their_node_id, Init msg) {
352                 bindings.ChannelMessageHandler_peer_connected(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
353                 this.ptrs_to.add(msg);
354         }
355
356         /**
357          * Handle an incoming channel_reestablish message from the given peer.
358          */
359         public void handle_channel_reestablish(byte[] their_node_id, ChannelReestablish msg) {
360                 bindings.ChannelMessageHandler_handle_channel_reestablish(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
361                 this.ptrs_to.add(msg);
362         }
363
364         /**
365          * Handle an incoming channel update from the given peer.
366          */
367         public void handle_channel_update(byte[] their_node_id, ChannelUpdate msg) {
368                 bindings.ChannelMessageHandler_handle_channel_update(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
369                 this.ptrs_to.add(msg);
370         }
371
372         /**
373          * Handle an incoming error message from the given peer.
374          */
375         public void handle_error(byte[] their_node_id, ErrorMessage msg) {
376                 bindings.ChannelMessageHandler_handle_error(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
377                 this.ptrs_to.add(msg);
378         }
379
380 }