Merge pull request #139 from TheBlueMatt/main
[ldk-java] / c_sharp / src / org / ldk / structs / ChannelMessageHandler.cs
1 using org.ldk.impl;
2 using org.ldk.enums;
3 using org.ldk.util;
4 using System;
5
6 namespace org { namespace ldk { namespace structs {
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 public class ChannelMessageHandler : CommonBase {
15         internal readonly bindings.LDKChannelMessageHandler bindings_instance;
16         internal ChannelMessageHandler(object _dummy, long ptr) : base(ptr) { bindings_instance = null; }
17         private ChannelMessageHandler(bindings.LDKChannelMessageHandler arg, bindings.LDKMessageSendEventsProvider MessageSendEventsProvider) : base(bindings.LDKChannelMessageHandler_new(arg, MessageSendEventsProvider)) {
18                 this.ptrs_to.AddLast(arg);
19                 this.ptrs_to.AddLast(MessageSendEventsProvider);
20                 this.bindings_instance = arg;
21         }
22         ~ChannelMessageHandler() {
23                 if (ptr != 0) { bindings.ChannelMessageHandler_free(ptr); }
24         }
25
26         public interface ChannelMessageHandlerInterface {
27                 /**
28                  * Handle an incoming `open_channel` message from the given peer.
29                  */
30                 void handle_open_channel(byte[] _their_node_id, OpenChannel _msg);
31                 /**
32                  * Handle an incoming `open_channel2` message from the given peer.
33                  */
34                 void handle_open_channel_v2(byte[] _their_node_id, OpenChannelV2 _msg);
35                 /**
36                  * Handle an incoming `accept_channel` message from the given peer.
37                  */
38                 void handle_accept_channel(byte[] _their_node_id, AcceptChannel _msg);
39                 /**
40                  * Handle an incoming `accept_channel2` message from the given peer.
41                  */
42                 void handle_accept_channel_v2(byte[] _their_node_id, AcceptChannelV2 _msg);
43                 /**
44                  * Handle an incoming `funding_created` message from the given peer.
45                  */
46                 void handle_funding_created(byte[] _their_node_id, FundingCreated _msg);
47                 /**
48                  * Handle an incoming `funding_signed` message from the given peer.
49                  */
50                 void handle_funding_signed(byte[] _their_node_id, FundingSigned _msg);
51                 /**
52                  * Handle an incoming `channel_ready` message from the given peer.
53                  */
54                 void handle_channel_ready(byte[] _their_node_id, ChannelReady _msg);
55                 /**
56                  * Handle an incoming `shutdown` message from the given peer.
57                  */
58                 void handle_shutdown(byte[] _their_node_id, Shutdown _msg);
59                 /**
60                  * Handle an incoming `closing_signed` message from the given peer.
61                  */
62                 void handle_closing_signed(byte[] _their_node_id, ClosingSigned _msg);
63                 /**
64                  * Handle an incoming `tx_add_input message` from the given peer.
65                  */
66                 void handle_tx_add_input(byte[] _their_node_id, TxAddInput _msg);
67                 /**
68                  * Handle an incoming `tx_add_output` message from the given peer.
69                  */
70                 void handle_tx_add_output(byte[] _their_node_id, TxAddOutput _msg);
71                 /**
72                  * Handle an incoming `tx_remove_input` message from the given peer.
73                  */
74                 void handle_tx_remove_input(byte[] _their_node_id, TxRemoveInput _msg);
75                 /**
76                  * Handle an incoming `tx_remove_output` message from the given peer.
77                  */
78                 void handle_tx_remove_output(byte[] _their_node_id, TxRemoveOutput _msg);
79                 /**
80                  * Handle an incoming `tx_complete message` from the given peer.
81                  */
82                 void handle_tx_complete(byte[] _their_node_id, TxComplete _msg);
83                 /**
84                  * Handle an incoming `tx_signatures` message from the given peer.
85                  */
86                 void handle_tx_signatures(byte[] _their_node_id, TxSignatures _msg);
87                 /**
88                  * Handle an incoming `tx_init_rbf` message from the given peer.
89                  */
90                 void handle_tx_init_rbf(byte[] _their_node_id, TxInitRbf _msg);
91                 /**
92                  * Handle an incoming `tx_ack_rbf` message from the given peer.
93                  */
94                 void handle_tx_ack_rbf(byte[] _their_node_id, TxAckRbf _msg);
95                 /**
96                  * Handle an incoming `tx_abort message` from the given peer.
97                  */
98                 void handle_tx_abort(byte[] _their_node_id, TxAbort _msg);
99                 /**
100                  * Handle an incoming `update_add_htlc` message from the given peer.
101                  */
102                 void handle_update_add_htlc(byte[] _their_node_id, UpdateAddHTLC _msg);
103                 /**
104                  * Handle an incoming `update_fulfill_htlc` message from the given peer.
105                  */
106                 void handle_update_fulfill_htlc(byte[] _their_node_id, UpdateFulfillHTLC _msg);
107                 /**
108                  * Handle an incoming `update_fail_htlc` message from the given peer.
109                  */
110                 void handle_update_fail_htlc(byte[] _their_node_id, UpdateFailHTLC _msg);
111                 /**
112                  * Handle an incoming `update_fail_malformed_htlc` message from the given peer.
113                  */
114                 void handle_update_fail_malformed_htlc(byte[] _their_node_id, UpdateFailMalformedHTLC _msg);
115                 /**
116                  * Handle an incoming `commitment_signed` message from the given peer.
117                  */
118                 void handle_commitment_signed(byte[] _their_node_id, CommitmentSigned _msg);
119                 /**
120                  * Handle an incoming `revoke_and_ack` message from the given peer.
121                  */
122                 void handle_revoke_and_ack(byte[] _their_node_id, RevokeAndACK _msg);
123                 /**
124                  * Handle an incoming `update_fee` message from the given peer.
125                  */
126                 void handle_update_fee(byte[] _their_node_id, UpdateFee _msg);
127                 /**
128                  * Handle an incoming `announcement_signatures` message from the given peer.
129                  */
130                 void handle_announcement_signatures(byte[] _their_node_id, AnnouncementSignatures _msg);
131                 /**
132                  * Indicates a connection to the peer failed/an existing connection was lost.
133                  */
134                 void peer_disconnected(byte[] _their_node_id);
135                 /**
136                  * Handle a peer reconnecting, possibly generating `channel_reestablish` message(s).
137                  * 
138                  * May return an `Err(())` if the features the peer supports are not sufficient to communicate
139                  * with us. Implementors should be somewhat conservative about doing so, however, as other
140                  * message handlers may still wish to communicate with this peer.
141                  */
142                 Result_NoneNoneZ peer_connected(byte[] _their_node_id, Init _msg, bool _inbound);
143                 /**
144                  * Handle an incoming `channel_reestablish` message from the given peer.
145                  */
146                 void handle_channel_reestablish(byte[] _their_node_id, ChannelReestablish _msg);
147                 /**
148                  * Handle an incoming `channel_update` message from the given peer.
149                  */
150                 void handle_channel_update(byte[] _their_node_id, ChannelUpdate _msg);
151                 /**
152                  * Handle an incoming `error` message from the given peer.
153                  */
154                 void handle_error(byte[] _their_node_id, ErrorMessage _msg);
155                 /**
156                  * Gets the node feature flags which this handler itself supports. All available handlers are
157                  * queried similarly and their feature flags are OR'd together to form the [`NodeFeatures`]
158                  * which are broadcasted in our [`NodeAnnouncement`] message.
159                  */
160                 NodeFeatures provided_node_features();
161                 /**
162                  * Gets the init feature flags which should be sent to the given peer. All available handlers
163                  * are queried similarly and their feature flags are OR'd together to form the [`InitFeatures`]
164                  * which are sent in our [`Init`] message.
165                  * 
166                  * Note that this method is called before [`Self::peer_connected`].
167                  */
168                 InitFeatures provided_init_features(byte[] _their_node_id);
169                 /**
170                  * Gets the genesis hashes for this `ChannelMessageHandler` indicating which chains it supports.
171                  * 
172                  * If it's `None`, then no particular network chain hash compatibility will be enforced when
173                  * connecting to peers.
174                  */
175                 Option_CVec_ChainHashZZ get_genesis_hashes();
176         }
177         private class LDKChannelMessageHandlerHolder { internal ChannelMessageHandler held; }
178         private class LDKChannelMessageHandlerImpl : bindings.LDKChannelMessageHandler {
179                 internal LDKChannelMessageHandlerImpl(ChannelMessageHandlerInterface arg, LDKChannelMessageHandlerHolder impl_holder) { this.arg = arg; this.impl_holder = impl_holder; }
180                 private ChannelMessageHandlerInterface arg;
181                 private LDKChannelMessageHandlerHolder impl_holder;
182                 public void handle_open_channel(byte[] _their_node_id, long _msg) {
183                         org.ldk.structs.OpenChannel _msg_hu_conv = null; if (_msg < 0 || _msg > 4096) { _msg_hu_conv = new org.ldk.structs.OpenChannel(null, _msg); }
184                         arg.handle_open_channel(_their_node_id, _msg_hu_conv);
185                                 GC.KeepAlive(arg);
186                 }
187                 public void handle_open_channel_v2(byte[] _their_node_id, long _msg) {
188                         org.ldk.structs.OpenChannelV2 _msg_hu_conv = null; if (_msg < 0 || _msg > 4096) { _msg_hu_conv = new org.ldk.structs.OpenChannelV2(null, _msg); }
189                         arg.handle_open_channel_v2(_their_node_id, _msg_hu_conv);
190                                 GC.KeepAlive(arg);
191                 }
192                 public void handle_accept_channel(byte[] _their_node_id, long _msg) {
193                         org.ldk.structs.AcceptChannel _msg_hu_conv = null; if (_msg < 0 || _msg > 4096) { _msg_hu_conv = new org.ldk.structs.AcceptChannel(null, _msg); }
194                         arg.handle_accept_channel(_their_node_id, _msg_hu_conv);
195                                 GC.KeepAlive(arg);
196                 }
197                 public void handle_accept_channel_v2(byte[] _their_node_id, long _msg) {
198                         org.ldk.structs.AcceptChannelV2 _msg_hu_conv = null; if (_msg < 0 || _msg > 4096) { _msg_hu_conv = new org.ldk.structs.AcceptChannelV2(null, _msg); }
199                         arg.handle_accept_channel_v2(_their_node_id, _msg_hu_conv);
200                                 GC.KeepAlive(arg);
201                 }
202                 public void handle_funding_created(byte[] _their_node_id, long _msg) {
203                         org.ldk.structs.FundingCreated _msg_hu_conv = null; if (_msg < 0 || _msg > 4096) { _msg_hu_conv = new org.ldk.structs.FundingCreated(null, _msg); }
204                         arg.handle_funding_created(_their_node_id, _msg_hu_conv);
205                                 GC.KeepAlive(arg);
206                 }
207                 public void handle_funding_signed(byte[] _their_node_id, long _msg) {
208                         org.ldk.structs.FundingSigned _msg_hu_conv = null; if (_msg < 0 || _msg > 4096) { _msg_hu_conv = new org.ldk.structs.FundingSigned(null, _msg); }
209                         arg.handle_funding_signed(_their_node_id, _msg_hu_conv);
210                                 GC.KeepAlive(arg);
211                 }
212                 public void handle_channel_ready(byte[] _their_node_id, long _msg) {
213                         org.ldk.structs.ChannelReady _msg_hu_conv = null; if (_msg < 0 || _msg > 4096) { _msg_hu_conv = new org.ldk.structs.ChannelReady(null, _msg); }
214                         arg.handle_channel_ready(_their_node_id, _msg_hu_conv);
215                                 GC.KeepAlive(arg);
216                 }
217                 public void handle_shutdown(byte[] _their_node_id, long _msg) {
218                         org.ldk.structs.Shutdown _msg_hu_conv = null; if (_msg < 0 || _msg > 4096) { _msg_hu_conv = new org.ldk.structs.Shutdown(null, _msg); }
219                         arg.handle_shutdown(_their_node_id, _msg_hu_conv);
220                                 GC.KeepAlive(arg);
221                 }
222                 public void handle_closing_signed(byte[] _their_node_id, long _msg) {
223                         org.ldk.structs.ClosingSigned _msg_hu_conv = null; if (_msg < 0 || _msg > 4096) { _msg_hu_conv = new org.ldk.structs.ClosingSigned(null, _msg); }
224                         arg.handle_closing_signed(_their_node_id, _msg_hu_conv);
225                                 GC.KeepAlive(arg);
226                 }
227                 public void handle_tx_add_input(byte[] _their_node_id, long _msg) {
228                         org.ldk.structs.TxAddInput _msg_hu_conv = null; if (_msg < 0 || _msg > 4096) { _msg_hu_conv = new org.ldk.structs.TxAddInput(null, _msg); }
229                         arg.handle_tx_add_input(_their_node_id, _msg_hu_conv);
230                                 GC.KeepAlive(arg);
231                 }
232                 public void handle_tx_add_output(byte[] _their_node_id, long _msg) {
233                         org.ldk.structs.TxAddOutput _msg_hu_conv = null; if (_msg < 0 || _msg > 4096) { _msg_hu_conv = new org.ldk.structs.TxAddOutput(null, _msg); }
234                         arg.handle_tx_add_output(_their_node_id, _msg_hu_conv);
235                                 GC.KeepAlive(arg);
236                 }
237                 public void handle_tx_remove_input(byte[] _their_node_id, long _msg) {
238                         org.ldk.structs.TxRemoveInput _msg_hu_conv = null; if (_msg < 0 || _msg > 4096) { _msg_hu_conv = new org.ldk.structs.TxRemoveInput(null, _msg); }
239                         arg.handle_tx_remove_input(_their_node_id, _msg_hu_conv);
240                                 GC.KeepAlive(arg);
241                 }
242                 public void handle_tx_remove_output(byte[] _their_node_id, long _msg) {
243                         org.ldk.structs.TxRemoveOutput _msg_hu_conv = null; if (_msg < 0 || _msg > 4096) { _msg_hu_conv = new org.ldk.structs.TxRemoveOutput(null, _msg); }
244                         arg.handle_tx_remove_output(_their_node_id, _msg_hu_conv);
245                                 GC.KeepAlive(arg);
246                 }
247                 public void handle_tx_complete(byte[] _their_node_id, long _msg) {
248                         org.ldk.structs.TxComplete _msg_hu_conv = null; if (_msg < 0 || _msg > 4096) { _msg_hu_conv = new org.ldk.structs.TxComplete(null, _msg); }
249                         arg.handle_tx_complete(_their_node_id, _msg_hu_conv);
250                                 GC.KeepAlive(arg);
251                 }
252                 public void handle_tx_signatures(byte[] _their_node_id, long _msg) {
253                         org.ldk.structs.TxSignatures _msg_hu_conv = null; if (_msg < 0 || _msg > 4096) { _msg_hu_conv = new org.ldk.structs.TxSignatures(null, _msg); }
254                         arg.handle_tx_signatures(_their_node_id, _msg_hu_conv);
255                                 GC.KeepAlive(arg);
256                 }
257                 public void handle_tx_init_rbf(byte[] _their_node_id, long _msg) {
258                         org.ldk.structs.TxInitRbf _msg_hu_conv = null; if (_msg < 0 || _msg > 4096) { _msg_hu_conv = new org.ldk.structs.TxInitRbf(null, _msg); }
259                         arg.handle_tx_init_rbf(_their_node_id, _msg_hu_conv);
260                                 GC.KeepAlive(arg);
261                 }
262                 public void handle_tx_ack_rbf(byte[] _their_node_id, long _msg) {
263                         org.ldk.structs.TxAckRbf _msg_hu_conv = null; if (_msg < 0 || _msg > 4096) { _msg_hu_conv = new org.ldk.structs.TxAckRbf(null, _msg); }
264                         arg.handle_tx_ack_rbf(_their_node_id, _msg_hu_conv);
265                                 GC.KeepAlive(arg);
266                 }
267                 public void handle_tx_abort(byte[] _their_node_id, long _msg) {
268                         org.ldk.structs.TxAbort _msg_hu_conv = null; if (_msg < 0 || _msg > 4096) { _msg_hu_conv = new org.ldk.structs.TxAbort(null, _msg); }
269                         arg.handle_tx_abort(_their_node_id, _msg_hu_conv);
270                                 GC.KeepAlive(arg);
271                 }
272                 public void handle_update_add_htlc(byte[] _their_node_id, long _msg) {
273                         org.ldk.structs.UpdateAddHTLC _msg_hu_conv = null; if (_msg < 0 || _msg > 4096) { _msg_hu_conv = new org.ldk.structs.UpdateAddHTLC(null, _msg); }
274                         arg.handle_update_add_htlc(_their_node_id, _msg_hu_conv);
275                                 GC.KeepAlive(arg);
276                 }
277                 public void handle_update_fulfill_htlc(byte[] _their_node_id, long _msg) {
278                         org.ldk.structs.UpdateFulfillHTLC _msg_hu_conv = null; if (_msg < 0 || _msg > 4096) { _msg_hu_conv = new org.ldk.structs.UpdateFulfillHTLC(null, _msg); }
279                         arg.handle_update_fulfill_htlc(_their_node_id, _msg_hu_conv);
280                                 GC.KeepAlive(arg);
281                 }
282                 public void handle_update_fail_htlc(byte[] _their_node_id, long _msg) {
283                         org.ldk.structs.UpdateFailHTLC _msg_hu_conv = null; if (_msg < 0 || _msg > 4096) { _msg_hu_conv = new org.ldk.structs.UpdateFailHTLC(null, _msg); }
284                         arg.handle_update_fail_htlc(_their_node_id, _msg_hu_conv);
285                                 GC.KeepAlive(arg);
286                 }
287                 public void handle_update_fail_malformed_htlc(byte[] _their_node_id, long _msg) {
288                         org.ldk.structs.UpdateFailMalformedHTLC _msg_hu_conv = null; if (_msg < 0 || _msg > 4096) { _msg_hu_conv = new org.ldk.structs.UpdateFailMalformedHTLC(null, _msg); }
289                         arg.handle_update_fail_malformed_htlc(_their_node_id, _msg_hu_conv);
290                                 GC.KeepAlive(arg);
291                 }
292                 public void handle_commitment_signed(byte[] _their_node_id, long _msg) {
293                         org.ldk.structs.CommitmentSigned _msg_hu_conv = null; if (_msg < 0 || _msg > 4096) { _msg_hu_conv = new org.ldk.structs.CommitmentSigned(null, _msg); }
294                         arg.handle_commitment_signed(_their_node_id, _msg_hu_conv);
295                                 GC.KeepAlive(arg);
296                 }
297                 public void handle_revoke_and_ack(byte[] _their_node_id, long _msg) {
298                         org.ldk.structs.RevokeAndACK _msg_hu_conv = null; if (_msg < 0 || _msg > 4096) { _msg_hu_conv = new org.ldk.structs.RevokeAndACK(null, _msg); }
299                         arg.handle_revoke_and_ack(_their_node_id, _msg_hu_conv);
300                                 GC.KeepAlive(arg);
301                 }
302                 public void handle_update_fee(byte[] _their_node_id, long _msg) {
303                         org.ldk.structs.UpdateFee _msg_hu_conv = null; if (_msg < 0 || _msg > 4096) { _msg_hu_conv = new org.ldk.structs.UpdateFee(null, _msg); }
304                         arg.handle_update_fee(_their_node_id, _msg_hu_conv);
305                                 GC.KeepAlive(arg);
306                 }
307                 public void handle_announcement_signatures(byte[] _their_node_id, long _msg) {
308                         org.ldk.structs.AnnouncementSignatures _msg_hu_conv = null; if (_msg < 0 || _msg > 4096) { _msg_hu_conv = new org.ldk.structs.AnnouncementSignatures(null, _msg); }
309                         arg.handle_announcement_signatures(_their_node_id, _msg_hu_conv);
310                                 GC.KeepAlive(arg);
311                 }
312                 public void peer_disconnected(byte[] _their_node_id) {
313                         arg.peer_disconnected(_their_node_id);
314                                 GC.KeepAlive(arg);
315                 }
316                 public long peer_connected(byte[] _their_node_id, long _msg, bool _inbound) {
317                         org.ldk.structs.Init _msg_hu_conv = null; if (_msg < 0 || _msg > 4096) { _msg_hu_conv = new org.ldk.structs.Init(null, _msg); }
318                         Result_NoneNoneZ ret = arg.peer_connected(_their_node_id, _msg_hu_conv, _inbound);
319                                 GC.KeepAlive(arg);
320                         long result = ret == null ? 0 : ret.clone_ptr();
321                         return result;
322                 }
323                 public void handle_channel_reestablish(byte[] _their_node_id, long _msg) {
324                         org.ldk.structs.ChannelReestablish _msg_hu_conv = null; if (_msg < 0 || _msg > 4096) { _msg_hu_conv = new org.ldk.structs.ChannelReestablish(null, _msg); }
325                         arg.handle_channel_reestablish(_their_node_id, _msg_hu_conv);
326                                 GC.KeepAlive(arg);
327                 }
328                 public void handle_channel_update(byte[] _their_node_id, long _msg) {
329                         org.ldk.structs.ChannelUpdate _msg_hu_conv = null; if (_msg < 0 || _msg > 4096) { _msg_hu_conv = new org.ldk.structs.ChannelUpdate(null, _msg); }
330                         arg.handle_channel_update(_their_node_id, _msg_hu_conv);
331                                 GC.KeepAlive(arg);
332                 }
333                 public void handle_error(byte[] _their_node_id, long _msg) {
334                         org.ldk.structs.ErrorMessage _msg_hu_conv = null; if (_msg < 0 || _msg > 4096) { _msg_hu_conv = new org.ldk.structs.ErrorMessage(null, _msg); }
335                         arg.handle_error(_their_node_id, _msg_hu_conv);
336                                 GC.KeepAlive(arg);
337                 }
338                 public long provided_node_features() {
339                         NodeFeatures ret = arg.provided_node_features();
340                                 GC.KeepAlive(arg);
341                         long result = ret == null ? 0 : ret.clone_ptr();
342                         return result;
343                 }
344                 public long provided_init_features(byte[] _their_node_id) {
345                         InitFeatures ret = arg.provided_init_features(_their_node_id);
346                                 GC.KeepAlive(arg);
347                         long result = ret == null ? 0 : ret.clone_ptr();
348                         return result;
349                 }
350                 public long get_genesis_hashes() {
351                         Option_CVec_ChainHashZZ ret = arg.get_genesis_hashes();
352                                 GC.KeepAlive(arg);
353                         long result = ret == null ? 0 : ret.clone_ptr();
354                         if (impl_holder.held != null) { impl_holder.held.ptrs_to.AddLast(ret); };
355                         return result;
356                 }
357         }
358         public static ChannelMessageHandler new_impl(ChannelMessageHandlerInterface arg, MessageSendEventsProvider.MessageSendEventsProviderInterface MessageSendEventsProvider_impl) {
359                 LDKChannelMessageHandlerHolder impl_holder = new LDKChannelMessageHandlerHolder();
360                 impl_holder.held = new ChannelMessageHandler(new LDKChannelMessageHandlerImpl(arg, impl_holder), MessageSendEventsProvider.new_impl(MessageSendEventsProvider_impl).bindings_instance);
361                 return impl_holder.held;
362         }
363
364         /**
365          * Gets the underlying MessageSendEventsProvider.
366          */
367         public MessageSendEventsProvider get_message_send_events_provider() {
368                 MessageSendEventsProvider res = new MessageSendEventsProvider(null, bindings.LDKChannelMessageHandler_get_MessageSendEventsProvider(this.ptr));
369                 this.ptrs_to.AddLast(res);
370                 return res;
371         }
372
373         /**
374          * Handle an incoming `open_channel` message from the given peer.
375          */
376         public void handle_open_channel(byte[] their_node_id, org.ldk.structs.OpenChannel msg) {
377                 bindings.ChannelMessageHandler_handle_open_channel(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), msg == null ? 0 : msg.ptr);
378                 GC.KeepAlive(this);
379                 GC.KeepAlive(their_node_id);
380                 GC.KeepAlive(msg);
381                 if (this != null) { this.ptrs_to.AddLast(msg); };
382         }
383
384         /**
385          * Handle an incoming `open_channel2` message from the given peer.
386          */
387         public void handle_open_channel_v2(byte[] their_node_id, org.ldk.structs.OpenChannelV2 msg) {
388                 bindings.ChannelMessageHandler_handle_open_channel_v2(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), msg == null ? 0 : msg.ptr);
389                 GC.KeepAlive(this);
390                 GC.KeepAlive(their_node_id);
391                 GC.KeepAlive(msg);
392                 if (this != null) { this.ptrs_to.AddLast(msg); };
393         }
394
395         /**
396          * Handle an incoming `accept_channel` message from the given peer.
397          */
398         public void handle_accept_channel(byte[] their_node_id, org.ldk.structs.AcceptChannel msg) {
399                 bindings.ChannelMessageHandler_handle_accept_channel(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), msg == null ? 0 : msg.ptr);
400                 GC.KeepAlive(this);
401                 GC.KeepAlive(their_node_id);
402                 GC.KeepAlive(msg);
403                 if (this != null) { this.ptrs_to.AddLast(msg); };
404         }
405
406         /**
407          * Handle an incoming `accept_channel2` message from the given peer.
408          */
409         public void handle_accept_channel_v2(byte[] their_node_id, org.ldk.structs.AcceptChannelV2 msg) {
410                 bindings.ChannelMessageHandler_handle_accept_channel_v2(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), msg == null ? 0 : msg.ptr);
411                 GC.KeepAlive(this);
412                 GC.KeepAlive(their_node_id);
413                 GC.KeepAlive(msg);
414                 if (this != null) { this.ptrs_to.AddLast(msg); };
415         }
416
417         /**
418          * Handle an incoming `funding_created` message from the given peer.
419          */
420         public void handle_funding_created(byte[] their_node_id, org.ldk.structs.FundingCreated msg) {
421                 bindings.ChannelMessageHandler_handle_funding_created(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), msg == null ? 0 : msg.ptr);
422                 GC.KeepAlive(this);
423                 GC.KeepAlive(their_node_id);
424                 GC.KeepAlive(msg);
425                 if (this != null) { this.ptrs_to.AddLast(msg); };
426         }
427
428         /**
429          * Handle an incoming `funding_signed` message from the given peer.
430          */
431         public void handle_funding_signed(byte[] their_node_id, org.ldk.structs.FundingSigned msg) {
432                 bindings.ChannelMessageHandler_handle_funding_signed(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), msg == null ? 0 : msg.ptr);
433                 GC.KeepAlive(this);
434                 GC.KeepAlive(their_node_id);
435                 GC.KeepAlive(msg);
436                 if (this != null) { this.ptrs_to.AddLast(msg); };
437         }
438
439         /**
440          * Handle an incoming `channel_ready` message from the given peer.
441          */
442         public void handle_channel_ready(byte[] their_node_id, org.ldk.structs.ChannelReady msg) {
443                 bindings.ChannelMessageHandler_handle_channel_ready(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), msg == null ? 0 : msg.ptr);
444                 GC.KeepAlive(this);
445                 GC.KeepAlive(their_node_id);
446                 GC.KeepAlive(msg);
447                 if (this != null) { this.ptrs_to.AddLast(msg); };
448         }
449
450         /**
451          * Handle an incoming `shutdown` message from the given peer.
452          */
453         public void handle_shutdown(byte[] their_node_id, org.ldk.structs.Shutdown msg) {
454                 bindings.ChannelMessageHandler_handle_shutdown(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), msg == null ? 0 : msg.ptr);
455                 GC.KeepAlive(this);
456                 GC.KeepAlive(their_node_id);
457                 GC.KeepAlive(msg);
458                 if (this != null) { this.ptrs_to.AddLast(msg); };
459         }
460
461         /**
462          * Handle an incoming `closing_signed` message from the given peer.
463          */
464         public void handle_closing_signed(byte[] their_node_id, org.ldk.structs.ClosingSigned msg) {
465                 bindings.ChannelMessageHandler_handle_closing_signed(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), msg == null ? 0 : msg.ptr);
466                 GC.KeepAlive(this);
467                 GC.KeepAlive(their_node_id);
468                 GC.KeepAlive(msg);
469                 if (this != null) { this.ptrs_to.AddLast(msg); };
470         }
471
472         /**
473          * Handle an incoming `tx_add_input message` from the given peer.
474          */
475         public void handle_tx_add_input(byte[] their_node_id, org.ldk.structs.TxAddInput msg) {
476                 bindings.ChannelMessageHandler_handle_tx_add_input(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), msg == null ? 0 : msg.ptr);
477                 GC.KeepAlive(this);
478                 GC.KeepAlive(their_node_id);
479                 GC.KeepAlive(msg);
480                 if (this != null) { this.ptrs_to.AddLast(msg); };
481         }
482
483         /**
484          * Handle an incoming `tx_add_output` message from the given peer.
485          */
486         public void handle_tx_add_output(byte[] their_node_id, org.ldk.structs.TxAddOutput msg) {
487                 bindings.ChannelMessageHandler_handle_tx_add_output(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), msg == null ? 0 : msg.ptr);
488                 GC.KeepAlive(this);
489                 GC.KeepAlive(their_node_id);
490                 GC.KeepAlive(msg);
491                 if (this != null) { this.ptrs_to.AddLast(msg); };
492         }
493
494         /**
495          * Handle an incoming `tx_remove_input` message from the given peer.
496          */
497         public void handle_tx_remove_input(byte[] their_node_id, org.ldk.structs.TxRemoveInput msg) {
498                 bindings.ChannelMessageHandler_handle_tx_remove_input(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), msg == null ? 0 : msg.ptr);
499                 GC.KeepAlive(this);
500                 GC.KeepAlive(their_node_id);
501                 GC.KeepAlive(msg);
502                 if (this != null) { this.ptrs_to.AddLast(msg); };
503         }
504
505         /**
506          * Handle an incoming `tx_remove_output` message from the given peer.
507          */
508         public void handle_tx_remove_output(byte[] their_node_id, org.ldk.structs.TxRemoveOutput msg) {
509                 bindings.ChannelMessageHandler_handle_tx_remove_output(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), msg == null ? 0 : msg.ptr);
510                 GC.KeepAlive(this);
511                 GC.KeepAlive(their_node_id);
512                 GC.KeepAlive(msg);
513                 if (this != null) { this.ptrs_to.AddLast(msg); };
514         }
515
516         /**
517          * Handle an incoming `tx_complete message` from the given peer.
518          */
519         public void handle_tx_complete(byte[] their_node_id, org.ldk.structs.TxComplete msg) {
520                 bindings.ChannelMessageHandler_handle_tx_complete(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), msg == null ? 0 : msg.ptr);
521                 GC.KeepAlive(this);
522                 GC.KeepAlive(their_node_id);
523                 GC.KeepAlive(msg);
524                 if (this != null) { this.ptrs_to.AddLast(msg); };
525         }
526
527         /**
528          * Handle an incoming `tx_signatures` message from the given peer.
529          */
530         public void handle_tx_signatures(byte[] their_node_id, org.ldk.structs.TxSignatures msg) {
531                 bindings.ChannelMessageHandler_handle_tx_signatures(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), msg == null ? 0 : msg.ptr);
532                 GC.KeepAlive(this);
533                 GC.KeepAlive(their_node_id);
534                 GC.KeepAlive(msg);
535                 if (this != null) { this.ptrs_to.AddLast(msg); };
536         }
537
538         /**
539          * Handle an incoming `tx_init_rbf` message from the given peer.
540          */
541         public void handle_tx_init_rbf(byte[] their_node_id, org.ldk.structs.TxInitRbf msg) {
542                 bindings.ChannelMessageHandler_handle_tx_init_rbf(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), msg == null ? 0 : msg.ptr);
543                 GC.KeepAlive(this);
544                 GC.KeepAlive(their_node_id);
545                 GC.KeepAlive(msg);
546                 if (this != null) { this.ptrs_to.AddLast(msg); };
547         }
548
549         /**
550          * Handle an incoming `tx_ack_rbf` message from the given peer.
551          */
552         public void handle_tx_ack_rbf(byte[] their_node_id, org.ldk.structs.TxAckRbf msg) {
553                 bindings.ChannelMessageHandler_handle_tx_ack_rbf(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), msg == null ? 0 : msg.ptr);
554                 GC.KeepAlive(this);
555                 GC.KeepAlive(their_node_id);
556                 GC.KeepAlive(msg);
557                 if (this != null) { this.ptrs_to.AddLast(msg); };
558         }
559
560         /**
561          * Handle an incoming `tx_abort message` from the given peer.
562          */
563         public void handle_tx_abort(byte[] their_node_id, org.ldk.structs.TxAbort msg) {
564                 bindings.ChannelMessageHandler_handle_tx_abort(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), msg == null ? 0 : msg.ptr);
565                 GC.KeepAlive(this);
566                 GC.KeepAlive(their_node_id);
567                 GC.KeepAlive(msg);
568                 if (this != null) { this.ptrs_to.AddLast(msg); };
569         }
570
571         /**
572          * Handle an incoming `update_add_htlc` message from the given peer.
573          */
574         public void handle_update_add_htlc(byte[] their_node_id, org.ldk.structs.UpdateAddHTLC msg) {
575                 bindings.ChannelMessageHandler_handle_update_add_htlc(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), msg == null ? 0 : msg.ptr);
576                 GC.KeepAlive(this);
577                 GC.KeepAlive(their_node_id);
578                 GC.KeepAlive(msg);
579                 if (this != null) { this.ptrs_to.AddLast(msg); };
580         }
581
582         /**
583          * Handle an incoming `update_fulfill_htlc` message from the given peer.
584          */
585         public void handle_update_fulfill_htlc(byte[] their_node_id, org.ldk.structs.UpdateFulfillHTLC msg) {
586                 bindings.ChannelMessageHandler_handle_update_fulfill_htlc(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), msg == null ? 0 : msg.ptr);
587                 GC.KeepAlive(this);
588                 GC.KeepAlive(their_node_id);
589                 GC.KeepAlive(msg);
590                 if (this != null) { this.ptrs_to.AddLast(msg); };
591         }
592
593         /**
594          * Handle an incoming `update_fail_htlc` message from the given peer.
595          */
596         public void handle_update_fail_htlc(byte[] their_node_id, org.ldk.structs.UpdateFailHTLC msg) {
597                 bindings.ChannelMessageHandler_handle_update_fail_htlc(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), msg == null ? 0 : msg.ptr);
598                 GC.KeepAlive(this);
599                 GC.KeepAlive(their_node_id);
600                 GC.KeepAlive(msg);
601                 if (this != null) { this.ptrs_to.AddLast(msg); };
602         }
603
604         /**
605          * Handle an incoming `update_fail_malformed_htlc` message from the given peer.
606          */
607         public void handle_update_fail_malformed_htlc(byte[] their_node_id, org.ldk.structs.UpdateFailMalformedHTLC msg) {
608                 bindings.ChannelMessageHandler_handle_update_fail_malformed_htlc(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), msg == null ? 0 : msg.ptr);
609                 GC.KeepAlive(this);
610                 GC.KeepAlive(their_node_id);
611                 GC.KeepAlive(msg);
612                 if (this != null) { this.ptrs_to.AddLast(msg); };
613         }
614
615         /**
616          * Handle an incoming `commitment_signed` message from the given peer.
617          */
618         public void handle_commitment_signed(byte[] their_node_id, org.ldk.structs.CommitmentSigned msg) {
619                 bindings.ChannelMessageHandler_handle_commitment_signed(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), msg == null ? 0 : msg.ptr);
620                 GC.KeepAlive(this);
621                 GC.KeepAlive(their_node_id);
622                 GC.KeepAlive(msg);
623                 if (this != null) { this.ptrs_to.AddLast(msg); };
624         }
625
626         /**
627          * Handle an incoming `revoke_and_ack` message from the given peer.
628          */
629         public void handle_revoke_and_ack(byte[] their_node_id, org.ldk.structs.RevokeAndACK msg) {
630                 bindings.ChannelMessageHandler_handle_revoke_and_ack(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), msg == null ? 0 : msg.ptr);
631                 GC.KeepAlive(this);
632                 GC.KeepAlive(their_node_id);
633                 GC.KeepAlive(msg);
634                 if (this != null) { this.ptrs_to.AddLast(msg); };
635         }
636
637         /**
638          * Handle an incoming `update_fee` message from the given peer.
639          */
640         public void handle_update_fee(byte[] their_node_id, org.ldk.structs.UpdateFee msg) {
641                 bindings.ChannelMessageHandler_handle_update_fee(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), msg == null ? 0 : msg.ptr);
642                 GC.KeepAlive(this);
643                 GC.KeepAlive(their_node_id);
644                 GC.KeepAlive(msg);
645                 if (this != null) { this.ptrs_to.AddLast(msg); };
646         }
647
648         /**
649          * Handle an incoming `announcement_signatures` message from the given peer.
650          */
651         public void handle_announcement_signatures(byte[] their_node_id, org.ldk.structs.AnnouncementSignatures msg) {
652                 bindings.ChannelMessageHandler_handle_announcement_signatures(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), msg == null ? 0 : msg.ptr);
653                 GC.KeepAlive(this);
654                 GC.KeepAlive(their_node_id);
655                 GC.KeepAlive(msg);
656                 if (this != null) { this.ptrs_to.AddLast(msg); };
657         }
658
659         /**
660          * Indicates a connection to the peer failed/an existing connection was lost.
661          */
662         public void peer_disconnected(byte[] their_node_id) {
663                 bindings.ChannelMessageHandler_peer_disconnected(this.ptr, InternalUtils.check_arr_len(their_node_id, 33));
664                 GC.KeepAlive(this);
665                 GC.KeepAlive(their_node_id);
666         }
667
668         /**
669          * Handle a peer reconnecting, possibly generating `channel_reestablish` message(s).
670          * 
671          * May return an `Err(())` if the features the peer supports are not sufficient to communicate
672          * with us. Implementors should be somewhat conservative about doing so, however, as other
673          * message handlers may still wish to communicate with this peer.
674          */
675         public Result_NoneNoneZ peer_connected(byte[] their_node_id, org.ldk.structs.Init msg, bool inbound) {
676                 long ret = bindings.ChannelMessageHandler_peer_connected(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), msg == null ? 0 : msg.ptr, inbound);
677                 GC.KeepAlive(this);
678                 GC.KeepAlive(their_node_id);
679                 GC.KeepAlive(msg);
680                 GC.KeepAlive(inbound);
681                 if (ret >= 0 && ret <= 4096) { return null; }
682                 Result_NoneNoneZ ret_hu_conv = Result_NoneNoneZ.constr_from_ptr(ret);
683                 if (this != null) { this.ptrs_to.AddLast(msg); };
684                 return ret_hu_conv;
685         }
686
687         /**
688          * Handle an incoming `channel_reestablish` message from the given peer.
689          */
690         public void handle_channel_reestablish(byte[] their_node_id, org.ldk.structs.ChannelReestablish msg) {
691                 bindings.ChannelMessageHandler_handle_channel_reestablish(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), msg == null ? 0 : msg.ptr);
692                 GC.KeepAlive(this);
693                 GC.KeepAlive(their_node_id);
694                 GC.KeepAlive(msg);
695                 if (this != null) { this.ptrs_to.AddLast(msg); };
696         }
697
698         /**
699          * Handle an incoming `channel_update` message from the given peer.
700          */
701         public void handle_channel_update(byte[] their_node_id, org.ldk.structs.ChannelUpdate msg) {
702                 bindings.ChannelMessageHandler_handle_channel_update(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), msg == null ? 0 : msg.ptr);
703                 GC.KeepAlive(this);
704                 GC.KeepAlive(their_node_id);
705                 GC.KeepAlive(msg);
706                 if (this != null) { this.ptrs_to.AddLast(msg); };
707         }
708
709         /**
710          * Handle an incoming `error` message from the given peer.
711          */
712         public void handle_error(byte[] their_node_id, org.ldk.structs.ErrorMessage msg) {
713                 bindings.ChannelMessageHandler_handle_error(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), msg == null ? 0 : msg.ptr);
714                 GC.KeepAlive(this);
715                 GC.KeepAlive(their_node_id);
716                 GC.KeepAlive(msg);
717                 if (this != null) { this.ptrs_to.AddLast(msg); };
718         }
719
720         /**
721          * Gets the node feature flags which this handler itself supports. All available handlers are
722          * queried similarly and their feature flags are OR'd together to form the [`NodeFeatures`]
723          * which are broadcasted in our [`NodeAnnouncement`] message.
724          */
725         public NodeFeatures provided_node_features() {
726                 long ret = bindings.ChannelMessageHandler_provided_node_features(this.ptr);
727                 GC.KeepAlive(this);
728                 if (ret >= 0 && ret <= 4096) { return null; }
729                 org.ldk.structs.NodeFeatures ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.NodeFeatures(null, ret); }
730                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
731                 return ret_hu_conv;
732         }
733
734         /**
735          * Gets the init feature flags which should be sent to the given peer. All available handlers
736          * are queried similarly and their feature flags are OR'd together to form the [`InitFeatures`]
737          * which are sent in our [`Init`] message.
738          * 
739          * Note that this method is called before [`Self::peer_connected`].
740          */
741         public InitFeatures provided_init_features(byte[] their_node_id) {
742                 long ret = bindings.ChannelMessageHandler_provided_init_features(this.ptr, InternalUtils.check_arr_len(their_node_id, 33));
743                 GC.KeepAlive(this);
744                 GC.KeepAlive(their_node_id);
745                 if (ret >= 0 && ret <= 4096) { return null; }
746                 org.ldk.structs.InitFeatures ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.InitFeatures(null, ret); }
747                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
748                 return ret_hu_conv;
749         }
750
751         /**
752          * Gets the genesis hashes for this `ChannelMessageHandler` indicating which chains it supports.
753          * 
754          * If it's `None`, then no particular network chain hash compatibility will be enforced when
755          * connecting to peers.
756          */
757         public Option_CVec_ChainHashZZ get_genesis_hashes() {
758                 long ret = bindings.ChannelMessageHandler_get_genesis_hashes(this.ptr);
759                 GC.KeepAlive(this);
760                 if (ret >= 0 && ret <= 4096) { return null; }
761                 org.ldk.structs.Option_CVec_ChainHashZZ ret_hu_conv = org.ldk.structs.Option_CVec_ChainHashZZ.constr_from_ptr(ret);
762                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
763                 return ret_hu_conv;
764         }
765
766 }
767 } } }