060133855ae1117c56add57e5cf0a659e0bf9cdf
[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 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
9 public class ChannelMessageHandler extends CommonBase {
10         final bindings.LDKChannelMessageHandler bindings_instance;
11         ChannelMessageHandler(Object _dummy, long ptr) { super(ptr); bindings_instance = null; }
12         private ChannelMessageHandler(bindings.LDKChannelMessageHandler arg, bindings.LDKMessageSendEventsProvider MessageSendEventsProvider) {
13                 super(bindings.LDKChannelMessageHandler_new(arg, MessageSendEventsProvider));
14                 this.ptrs_to.add(arg);
15                 this.ptrs_to.add(MessageSendEventsProvider);
16                 this.bindings_instance = arg;
17         }
18         @Override @SuppressWarnings("deprecation")
19         protected void finalize() throws Throwable {
20                 if (ptr != 0) { bindings.ChannelMessageHandler_free(ptr); } super.finalize();
21         }
22
23         public static interface ChannelMessageHandlerInterface {
24                 void handle_open_channel(byte[] their_node_id, InitFeatures their_features, OpenChannel msg);
25                 void handle_accept_channel(byte[] their_node_id, InitFeatures their_features, AcceptChannel msg);
26                 void handle_funding_created(byte[] their_node_id, FundingCreated msg);
27                 void handle_funding_signed(byte[] their_node_id, FundingSigned msg);
28                 void handle_funding_locked(byte[] their_node_id, FundingLocked msg);
29                 void handle_shutdown(byte[] their_node_id, Shutdown msg);
30                 void handle_closing_signed(byte[] their_node_id, ClosingSigned msg);
31                 void handle_update_add_htlc(byte[] their_node_id, UpdateAddHTLC msg);
32                 void handle_update_fulfill_htlc(byte[] their_node_id, UpdateFulfillHTLC msg);
33                 void handle_update_fail_htlc(byte[] their_node_id, UpdateFailHTLC msg);
34                 void handle_update_fail_malformed_htlc(byte[] their_node_id, UpdateFailMalformedHTLC msg);
35                 void handle_commitment_signed(byte[] their_node_id, CommitmentSigned msg);
36                 void handle_revoke_and_ack(byte[] their_node_id, RevokeAndACK msg);
37                 void handle_update_fee(byte[] their_node_id, UpdateFee msg);
38                 void handle_announcement_signatures(byte[] their_node_id, AnnouncementSignatures msg);
39                 void peer_disconnected(byte[] their_node_id, boolean no_connection_possible);
40                 void peer_connected(byte[] their_node_id, Init msg);
41                 void handle_channel_reestablish(byte[] their_node_id, ChannelReestablish msg);
42                 void handle_error(byte[] their_node_id, ErrorMessage msg);
43         }
44         private static class LDKChannelMessageHandlerHolder { ChannelMessageHandler held; }
45         public static ChannelMessageHandler new_impl(ChannelMessageHandlerInterface arg, MessageSendEventsProvider.MessageSendEventsProviderInterface MessageSendEventsProvider_impl) {
46                 final LDKChannelMessageHandlerHolder impl_holder = new LDKChannelMessageHandlerHolder();
47                 impl_holder.held = new ChannelMessageHandler(new bindings.LDKChannelMessageHandler() {
48                         @Override public void handle_open_channel(byte[] their_node_id, long their_features, long msg) {
49                                 InitFeatures their_features_hu_conv = new InitFeatures(null, their_features);
50                                 their_features_hu_conv.ptrs_to.add(this);
51                                 OpenChannel msg_hu_conv = new OpenChannel(null, msg);
52                                 arg.handle_open_channel(their_node_id, their_features_hu_conv, msg_hu_conv);
53                         }
54                         @Override public void handle_accept_channel(byte[] their_node_id, long their_features, long msg) {
55                                 InitFeatures their_features_hu_conv = new InitFeatures(null, their_features);
56                                 their_features_hu_conv.ptrs_to.add(this);
57                                 AcceptChannel msg_hu_conv = new AcceptChannel(null, msg);
58                                 arg.handle_accept_channel(their_node_id, their_features_hu_conv, msg_hu_conv);
59                         }
60                         @Override public void handle_funding_created(byte[] their_node_id, long msg) {
61                                 FundingCreated msg_hu_conv = new FundingCreated(null, msg);
62                                 arg.handle_funding_created(their_node_id, msg_hu_conv);
63                         }
64                         @Override public void handle_funding_signed(byte[] their_node_id, long msg) {
65                                 FundingSigned msg_hu_conv = new FundingSigned(null, msg);
66                                 arg.handle_funding_signed(their_node_id, msg_hu_conv);
67                         }
68                         @Override public void handle_funding_locked(byte[] their_node_id, long msg) {
69                                 FundingLocked msg_hu_conv = new FundingLocked(null, msg);
70                                 arg.handle_funding_locked(their_node_id, msg_hu_conv);
71                         }
72                         @Override public void handle_shutdown(byte[] their_node_id, long msg) {
73                                 Shutdown msg_hu_conv = new Shutdown(null, msg);
74                                 arg.handle_shutdown(their_node_id, msg_hu_conv);
75                         }
76                         @Override public void handle_closing_signed(byte[] their_node_id, long msg) {
77                                 ClosingSigned msg_hu_conv = new ClosingSigned(null, msg);
78                                 arg.handle_closing_signed(their_node_id, msg_hu_conv);
79                         }
80                         @Override public void handle_update_add_htlc(byte[] their_node_id, long msg) {
81                                 UpdateAddHTLC msg_hu_conv = new UpdateAddHTLC(null, msg);
82                                 arg.handle_update_add_htlc(their_node_id, msg_hu_conv);
83                         }
84                         @Override public void handle_update_fulfill_htlc(byte[] their_node_id, long msg) {
85                                 UpdateFulfillHTLC msg_hu_conv = new UpdateFulfillHTLC(null, msg);
86                                 arg.handle_update_fulfill_htlc(their_node_id, msg_hu_conv);
87                         }
88                         @Override public void handle_update_fail_htlc(byte[] their_node_id, long msg) {
89                                 UpdateFailHTLC msg_hu_conv = new UpdateFailHTLC(null, msg);
90                                 arg.handle_update_fail_htlc(their_node_id, msg_hu_conv);
91                         }
92                         @Override public void handle_update_fail_malformed_htlc(byte[] their_node_id, long msg) {
93                                 UpdateFailMalformedHTLC msg_hu_conv = new UpdateFailMalformedHTLC(null, msg);
94                                 arg.handle_update_fail_malformed_htlc(their_node_id, msg_hu_conv);
95                         }
96                         @Override public void handle_commitment_signed(byte[] their_node_id, long msg) {
97                                 CommitmentSigned msg_hu_conv = new CommitmentSigned(null, msg);
98                                 arg.handle_commitment_signed(their_node_id, msg_hu_conv);
99                         }
100                         @Override public void handle_revoke_and_ack(byte[] their_node_id, long msg) {
101                                 RevokeAndACK msg_hu_conv = new RevokeAndACK(null, msg);
102                                 arg.handle_revoke_and_ack(their_node_id, msg_hu_conv);
103                         }
104                         @Override public void handle_update_fee(byte[] their_node_id, long msg) {
105                                 UpdateFee msg_hu_conv = new UpdateFee(null, msg);
106                                 arg.handle_update_fee(their_node_id, msg_hu_conv);
107                         }
108                         @Override public void handle_announcement_signatures(byte[] their_node_id, long msg) {
109                                 AnnouncementSignatures msg_hu_conv = new AnnouncementSignatures(null, msg);
110                                 arg.handle_announcement_signatures(their_node_id, msg_hu_conv);
111                         }
112                         @Override public void peer_disconnected(byte[] their_node_id, boolean no_connection_possible) {
113                                 arg.peer_disconnected(their_node_id, no_connection_possible);
114                         }
115                         @Override public void peer_connected(byte[] their_node_id, long msg) {
116                                 Init msg_hu_conv = new Init(null, msg);
117                                 arg.peer_connected(their_node_id, msg_hu_conv);
118                         }
119                         @Override public void handle_channel_reestablish(byte[] their_node_id, long msg) {
120                                 ChannelReestablish msg_hu_conv = new ChannelReestablish(null, msg);
121                                 arg.handle_channel_reestablish(their_node_id, msg_hu_conv);
122                         }
123                         @Override public void handle_error(byte[] their_node_id, long msg) {
124                                 ErrorMessage msg_hu_conv = new ErrorMessage(null, msg);
125                                 arg.handle_error(their_node_id, msg_hu_conv);
126                         }
127                 }, MessageSendEventsProvider.new_impl(MessageSendEventsProvider_impl).bindings_instance);
128                 return impl_holder.held;
129         }
130         public void handle_open_channel(byte[] their_node_id, InitFeatures their_features, OpenChannel msg) {
131                 bindings.ChannelMessageHandler_handle_open_channel(this.ptr, their_node_id, their_features == null ? 0 : their_features.ptr & ~1, msg == null ? 0 : msg.ptr & ~1);
132                 this.ptrs_to.add(their_features);
133                 // Due to rust's strict-ownership memory model, in some cases we need to "move"
134                 // an object to pass exclusive ownership to the function being called.
135                 // In most cases, we avoid this being visible in GC'd languages by cloning the object
136                 // at the FFI layer, creating a new object which Rust can claim ownership of
137                 // However, in some cases (eg here), there is no way to clone an object, and thus
138                 // we actually have to pass full ownership to Rust.
139                 // Thus, after this call, their_features is reset to null and is now a dummy object.
140                 their_features.ptr = 0;
141                 this.ptrs_to.add(msg);
142         }
143
144         public void handle_accept_channel(byte[] their_node_id, InitFeatures their_features, AcceptChannel msg) {
145                 bindings.ChannelMessageHandler_handle_accept_channel(this.ptr, their_node_id, their_features == null ? 0 : their_features.ptr & ~1, msg == null ? 0 : msg.ptr & ~1);
146                 this.ptrs_to.add(their_features);
147                 // Due to rust's strict-ownership memory model, in some cases we need to "move"
148                 // an object to pass exclusive ownership to the function being called.
149                 // In most cases, we avoid this being visible in GC'd languages by cloning the object
150                 // at the FFI layer, creating a new object which Rust can claim ownership of
151                 // However, in some cases (eg here), there is no way to clone an object, and thus
152                 // we actually have to pass full ownership to Rust.
153                 // Thus, after this call, their_features is reset to null and is now a dummy object.
154                 their_features.ptr = 0;
155                 this.ptrs_to.add(msg);
156         }
157
158         public void handle_funding_created(byte[] their_node_id, FundingCreated msg) {
159                 bindings.ChannelMessageHandler_handle_funding_created(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
160                 this.ptrs_to.add(msg);
161         }
162
163         public void handle_funding_signed(byte[] their_node_id, FundingSigned msg) {
164                 bindings.ChannelMessageHandler_handle_funding_signed(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
165                 this.ptrs_to.add(msg);
166         }
167
168         public void handle_funding_locked(byte[] their_node_id, FundingLocked msg) {
169                 bindings.ChannelMessageHandler_handle_funding_locked(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
170                 this.ptrs_to.add(msg);
171         }
172
173         public void handle_shutdown(byte[] their_node_id, Shutdown msg) {
174                 bindings.ChannelMessageHandler_handle_shutdown(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
175                 this.ptrs_to.add(msg);
176         }
177
178         public void handle_closing_signed(byte[] their_node_id, ClosingSigned msg) {
179                 bindings.ChannelMessageHandler_handle_closing_signed(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
180                 this.ptrs_to.add(msg);
181         }
182
183         public void handle_update_add_htlc(byte[] their_node_id, UpdateAddHTLC msg) {
184                 bindings.ChannelMessageHandler_handle_update_add_htlc(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
185                 this.ptrs_to.add(msg);
186         }
187
188         public void handle_update_fulfill_htlc(byte[] their_node_id, UpdateFulfillHTLC msg) {
189                 bindings.ChannelMessageHandler_handle_update_fulfill_htlc(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
190                 this.ptrs_to.add(msg);
191         }
192
193         public void handle_update_fail_htlc(byte[] their_node_id, UpdateFailHTLC msg) {
194                 bindings.ChannelMessageHandler_handle_update_fail_htlc(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
195                 this.ptrs_to.add(msg);
196         }
197
198         public void handle_update_fail_malformed_htlc(byte[] their_node_id, UpdateFailMalformedHTLC msg) {
199                 bindings.ChannelMessageHandler_handle_update_fail_malformed_htlc(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
200                 this.ptrs_to.add(msg);
201         }
202
203         public void handle_commitment_signed(byte[] their_node_id, CommitmentSigned msg) {
204                 bindings.ChannelMessageHandler_handle_commitment_signed(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
205                 this.ptrs_to.add(msg);
206         }
207
208         public void handle_revoke_and_ack(byte[] their_node_id, RevokeAndACK msg) {
209                 bindings.ChannelMessageHandler_handle_revoke_and_ack(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
210                 this.ptrs_to.add(msg);
211         }
212
213         public void handle_update_fee(byte[] their_node_id, UpdateFee msg) {
214                 bindings.ChannelMessageHandler_handle_update_fee(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
215                 this.ptrs_to.add(msg);
216         }
217
218         public void handle_announcement_signatures(byte[] their_node_id, AnnouncementSignatures msg) {
219                 bindings.ChannelMessageHandler_handle_announcement_signatures(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
220                 this.ptrs_to.add(msg);
221         }
222
223         public void peer_disconnected(byte[] their_node_id, boolean no_connection_possible) {
224                 bindings.ChannelMessageHandler_peer_disconnected(this.ptr, their_node_id, no_connection_possible);
225         }
226
227         public void peer_connected(byte[] their_node_id, Init msg) {
228                 bindings.ChannelMessageHandler_peer_connected(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
229                 this.ptrs_to.add(msg);
230         }
231
232         public void handle_channel_reestablish(byte[] their_node_id, ChannelReestablish msg) {
233                 bindings.ChannelMessageHandler_handle_channel_reestablish(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
234                 this.ptrs_to.add(msg);
235         }
236
237         public void handle_error(byte[] their_node_id, ErrorMessage msg) {
238                 bindings.ChannelMessageHandler_handle_error(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
239                 this.ptrs_to.add(msg);
240         }
241
242 }