Bindings updates
[ldk-java] / ts / bindings.c
1 #include <rust_types.h>
2 #include <stdatomic.h>
3 #include <lightning.h>
4
5 // These should be provided...somehow...
6 void *memset(void *s, int c, size_t n);
7 void *memcpy(void *dest, const void *src, size_t n);
8 int memcmp(const void *s1, const void *s2, size_t n);
9
10 void __attribute__((noreturn)) abort(void);
11 void assert(bool expression);
12
13 // Always run a, then assert it is true:
14 #define DO_ASSERT(a) do { bool _assert_val = (a); assert(_assert_val); } while(0)
15 // Assert a is true or do nothing
16 #define CHECK(a) DO_ASSERT(a)
17
18 // Running a leak check across all the allocations and frees of the JDK is a mess,
19 // so instead we implement our own naive leak checker here, relying on the -wrap
20 // linker option to wrap malloc/calloc/realloc/free, tracking everyhing allocated
21 // and free'd in Rust or C across the generated bindings shared library.
22
23 #define BT_MAX 128
24 typedef struct allocation {
25         struct allocation* next;
26         void* ptr;
27         const char* struct_name;
28 } allocation;
29 static allocation* allocation_ll = NULL;
30
31 void* __real_malloc(size_t len);
32 void* __real_calloc(size_t nmemb, size_t len);
33 static void new_allocation(void* res, const char* struct_name) {
34         allocation* new_alloc = __real_malloc(sizeof(allocation));
35         new_alloc->ptr = res;
36         new_alloc->struct_name = struct_name;
37         new_alloc->next = allocation_ll;
38         allocation_ll = new_alloc;
39 }
40 static void* MALLOC(size_t len, const char* struct_name) {
41         void* res = __real_malloc(len);
42         new_allocation(res, struct_name);
43         return res;
44 }
45 void __real_free(void* ptr);
46 static void alloc_freed(void* ptr) {
47         allocation* p = NULL;
48         allocation* it = allocation_ll;
49         while (it->ptr != ptr) {
50                 p = it; it = it->next;
51                 if (it == NULL) {
52                         //XXX: fprintf(stderr, "Tried to free unknown pointer %p\n", ptr);
53                         return; // addrsan should catch malloc-unknown and print more info than we have
54                 }
55         }
56         if (p) { p->next = it->next; } else { allocation_ll = it->next; }
57         DO_ASSERT(it->ptr == ptr);
58         __real_free(it);
59 }
60 static void FREE(void* ptr) {
61         if ((long)ptr < 1024) return; // Rust loves to create pointers to the NULL page for dummys
62         alloc_freed(ptr);
63         __real_free(ptr);
64 }
65
66 void* __wrap_malloc(size_t len) {
67         void* res = __real_malloc(len);
68         new_allocation(res, "malloc call");
69         return res;
70 }
71 void* __wrap_calloc(size_t nmemb, size_t len) {
72         void* res = __real_calloc(nmemb, len);
73         new_allocation(res, "calloc call");
74         return res;
75 }
76 void __wrap_free(void* ptr) {
77         if (ptr == NULL) return;
78         alloc_freed(ptr);
79         __real_free(ptr);
80 }
81
82 void* __real_realloc(void* ptr, size_t newlen);
83 void* __wrap_realloc(void* ptr, size_t len) {
84         if (ptr != NULL) alloc_freed(ptr);
85         void* res = __real_realloc(ptr, len);
86         new_allocation(res, "realloc call");
87         return res;
88 }
89 void __wrap_reallocarray(void* ptr, size_t new_sz) {
90         // Rust doesn't seem to use reallocarray currently
91         DO_ASSERT(false);
92 }
93
94 void __attribute__((destructor)) check_leaks() {
95         for (allocation* a = allocation_ll; a != NULL; a = a->next) {
96                 //XXX: fprintf(stderr, "%s %p remains\n", a->struct_name, a->ptr);
97         }
98         DO_ASSERT(allocation_ll == NULL);
99 }
100
101 // We assume that CVec_u8Z and u8slice are the same size and layout (and thus pointers to the two can be mixed)
102 _Static_assert(sizeof(LDKCVec_u8Z) == sizeof(LDKu8slice), "Vec<u8> and [u8] need to have been mapped identically");
103 _Static_assert(offsetof(LDKCVec_u8Z, data) == offsetof(LDKu8slice, data), "Vec<u8> and [u8] need to have been mapped identically");
104 _Static_assert(offsetof(LDKCVec_u8Z, datalen) == offsetof(LDKu8slice, datalen), "Vec<u8> and [u8] need to have been mapped identically");
105
106 _Static_assert(sizeof(void*) == 4, "Pointers mut be 32 bits");
107
108 typedef struct int64_tArray {uint32_t len;int64_t *ptr;} int64_tArray;
109 typedef struct uint32_tArray {uint32_t len;int32_t *ptr;} uint32_tArray;
110 typedef struct ptrArray {uint32_t len;int32_t *ptr;} ptrArray;
111 typedef struct int8_tArray {uint32_t len;int8_t *ptr;} int8_tArray;
112 typedef struct jstring {} jstring;
113
114 jstring conv_owned_string(const char* _src) { jstring a; return a; }
115
116 typedef bool jboolean;
117
118 static inline struct LDKThirtyTwoBytes ThirtyTwoBytes_clone(const struct LDKThirtyTwoBytes *orig) { struct LDKThirtyTwoBytes ret; memcpy(ret.data, orig->data, 32); return ret; }
119 static inline LDKAccessError LDKAccessError_from_js(int32_t ord) {
120         switch (ord) {
121                 case 0: return LDKAccessError_UnknownChain;
122                 case 1: return LDKAccessError_UnknownTx;
123         }
124         abort();
125 }
126 static inline int32_t LDKAccessError_to_js(LDKAccessError val) {
127         switch (val) {
128                 case LDKAccessError_UnknownChain: return 0;
129                 case LDKAccessError_UnknownTx: return 1;
130                 default: abort();
131         }
132 }
133 static inline LDKChannelMonitorUpdateErr LDKChannelMonitorUpdateErr_from_js(int32_t ord) {
134         switch (ord) {
135                 case 0: return LDKChannelMonitorUpdateErr_TemporaryFailure;
136                 case 1: return LDKChannelMonitorUpdateErr_PermanentFailure;
137         }
138         abort();
139 }
140 static inline int32_t LDKChannelMonitorUpdateErr_to_js(LDKChannelMonitorUpdateErr val) {
141         switch (val) {
142                 case LDKChannelMonitorUpdateErr_TemporaryFailure: return 0;
143                 case LDKChannelMonitorUpdateErr_PermanentFailure: return 1;
144                 default: abort();
145         }
146 }
147 static inline LDKConfirmationTarget LDKConfirmationTarget_from_js(int32_t ord) {
148         switch (ord) {
149                 case 0: return LDKConfirmationTarget_Background;
150                 case 1: return LDKConfirmationTarget_Normal;
151                 case 2: return LDKConfirmationTarget_HighPriority;
152         }
153         abort();
154 }
155 static inline int32_t LDKConfirmationTarget_to_js(LDKConfirmationTarget val) {
156         switch (val) {
157                 case LDKConfirmationTarget_Background: return 0;
158                 case LDKConfirmationTarget_Normal: return 1;
159                 case LDKConfirmationTarget_HighPriority: return 2;
160                 default: abort();
161         }
162 }
163 static inline LDKLevel LDKLevel_from_js(int32_t ord) {
164         switch (ord) {
165                 case 0: return LDKLevel_Off;
166                 case 1: return LDKLevel_Error;
167                 case 2: return LDKLevel_Warn;
168                 case 3: return LDKLevel_Info;
169                 case 4: return LDKLevel_Debug;
170                 case 5: return LDKLevel_Trace;
171         }
172         abort();
173 }
174 static inline int32_t LDKLevel_to_js(LDKLevel val) {
175         switch (val) {
176                 case LDKLevel_Off: return 0;
177                 case LDKLevel_Error: return 1;
178                 case LDKLevel_Warn: return 2;
179                 case LDKLevel_Info: return 3;
180                 case LDKLevel_Debug: return 4;
181                 case LDKLevel_Trace: return 5;
182                 default: abort();
183         }
184 }
185 static inline LDKNetwork LDKNetwork_from_js(int32_t ord) {
186         switch (ord) {
187                 case 0: return LDKNetwork_Bitcoin;
188                 case 1: return LDKNetwork_Testnet;
189                 case 2: return LDKNetwork_Regtest;
190         }
191         abort();
192 }
193 static inline int32_t LDKNetwork_to_js(LDKNetwork val) {
194         switch (val) {
195                 case LDKNetwork_Bitcoin: return 0;
196                 case LDKNetwork_Testnet: return 1;
197                 case LDKNetwork_Regtest: return 2;
198                 default: abort();
199         }
200 }
201 static inline LDKSecp256k1Error LDKSecp256k1Error_from_js(int32_t ord) {
202         switch (ord) {
203                 case 0: return LDKSecp256k1Error_IncorrectSignature;
204                 case 1: return LDKSecp256k1Error_InvalidMessage;
205                 case 2: return LDKSecp256k1Error_InvalidPublicKey;
206                 case 3: return LDKSecp256k1Error_InvalidSignature;
207                 case 4: return LDKSecp256k1Error_InvalidSecretKey;
208                 case 5: return LDKSecp256k1Error_InvalidRecoveryId;
209                 case 6: return LDKSecp256k1Error_InvalidTweak;
210                 case 7: return LDKSecp256k1Error_NotEnoughMemory;
211                 case 8: return LDKSecp256k1Error_CallbackPanicked;
212         }
213         abort();
214 }
215 static inline int32_t LDKSecp256k1Error_to_js(LDKSecp256k1Error val) {
216         switch (val) {
217                 case LDKSecp256k1Error_IncorrectSignature: return 0;
218                 case LDKSecp256k1Error_InvalidMessage: return 1;
219                 case LDKSecp256k1Error_InvalidPublicKey: return 2;
220                 case LDKSecp256k1Error_InvalidSignature: return 3;
221                 case LDKSecp256k1Error_InvalidSecretKey: return 4;
222                 case LDKSecp256k1Error_InvalidRecoveryId: return 5;
223                 case LDKSecp256k1Error_InvalidTweak: return 6;
224                 case LDKSecp256k1Error_NotEnoughMemory: return 7;
225                 case LDKSecp256k1Error_CallbackPanicked: return 8;
226                 default: abort();
227         }
228 }
229 uint32_t LDKCVec_1u8Z_1new(void* ctx_TODO, int8_tArray elems) {
230         LDKCVec_u8Z *ret = MALLOC(sizeof(LDKCVec_u8Z), "LDKCVec_u8Z");
231         ret->datalen = elems.len;
232         if (ret->datalen == 0) {
233                 ret->data = NULL;
234         } else {
235                 ret->data = MALLOC(sizeof(uint8_t) * ret->datalen, "LDKCVec_u8Z Data");
236                 int8_t *java_elems = (int8_t*)elems.ptr;
237                 for (size_t i = 0; i < ret->datalen; i++) {
238                         ret->data[i] = java_elems[i];
239                 }
240         }
241         return (long)ret;
242 }
243 static inline LDKCVec_u8Z CVec_u8Z_clone(const LDKCVec_u8Z *orig) {
244         LDKCVec_u8Z ret = { .data = MALLOC(sizeof(int8_t) * orig->datalen, "LDKCVec_u8Z clone bytes"), .datalen = orig->datalen };
245         memcpy(ret.data, orig->data, sizeof(int8_t) * ret.datalen);
246         return ret;
247 }
248 uint32_t LDKC2Tuple_1u64u64Z_1new(void* ctx_TODO, int64_t a, int64_t b) {
249         LDKC2Tuple_u64u64Z* ret = MALLOC(sizeof(LDKC2Tuple_u64u64Z), "LDKC2Tuple_u64u64Z");
250         ret->a = a;
251         ret->b = b;
252         return (long)ret;
253 }
254 static inline LDKC2Tuple_u64u64Z C2Tuple_u64u64Z_clone(const LDKC2Tuple_u64u64Z *orig) {
255         LDKC2Tuple_u64u64Z ret = {
256                 .a = orig->a,
257                 .b = orig->b,
258         };
259         return ret;
260 }
261 int64_t LDKC2Tuple_1u64u64Z_1get_1a(void* ctx_TODO, uint32_t ptr) {
262         LDKC2Tuple_u64u64Z *tuple = (LDKC2Tuple_u64u64Z*)ptr;
263         return tuple->a;
264 }
265 int64_t LDKC2Tuple_1u64u64Z_1get_1b(void* ctx_TODO, uint32_t ptr) {
266         LDKC2Tuple_u64u64Z *tuple = (LDKC2Tuple_u64u64Z*)ptr;
267         return tuple->b;
268 }
269 uint32_t LDKSpendableOutputDescriptor_1ref_1from_1ptr (void* ctx_TODO, uint32_t ptr) {
270         LDKSpendableOutputDescriptor *obj = (LDKSpendableOutputDescriptor*)ptr;
271         switch(obj->tag) {
272                 case LDKSpendableOutputDescriptor_StaticOutput: {
273                         LDKOutPoint outpoint_var = obj->static_output.outpoint;
274                         CHECK((((long)outpoint_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
275                         CHECK((((long)&outpoint_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
276                         long outpoint_ref = (long)outpoint_var.inner & ~1;
277                         long output_ref = (long)&obj->static_output.output;
278                         return 0 /* LDKSpendableOutputDescriptor - StaticOutput */; (void) outpoint_ref; (void) (long)output_ref;
279                 }
280                 case LDKSpendableOutputDescriptor_DynamicOutputP2WSH: {
281                         LDKOutPoint outpoint_var = obj->dynamic_output_p2wsh.outpoint;
282                         CHECK((((long)outpoint_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
283                         CHECK((((long)&outpoint_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
284                         long outpoint_ref = (long)outpoint_var.inner & ~1;
285                         int8_tArray per_commitment_point_arr = { .len = 33, .ptr = MALLOC(33, "Native int8_tArray Bytes") };
286                         memcpy(per_commitment_point_arr.ptr, obj->dynamic_output_p2wsh.per_commitment_point.compressed_form, 33);
287                         long output_ref = (long)&obj->dynamic_output_p2wsh.output;
288                         long key_derivation_params_ref = (long)&obj->dynamic_output_p2wsh.key_derivation_params;
289                         int8_tArray revocation_pubkey_arr = { .len = 33, .ptr = MALLOC(33, "Native int8_tArray Bytes") };
290                         memcpy(revocation_pubkey_arr.ptr, obj->dynamic_output_p2wsh.revocation_pubkey.compressed_form, 33);
291                         return 0 /* LDKSpendableOutputDescriptor - DynamicOutputP2WSH */; (void) outpoint_ref; (void) per_commitment_point_arr; (void) obj->dynamic_output_p2wsh.to_self_delay; (void) (long)output_ref; (void) key_derivation_params_ref; (void) revocation_pubkey_arr;
292                 }
293                 case LDKSpendableOutputDescriptor_StaticOutputCounterpartyPayment: {
294                         LDKOutPoint outpoint_var = obj->static_output_counterparty_payment.outpoint;
295                         CHECK((((long)outpoint_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
296                         CHECK((((long)&outpoint_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
297                         long outpoint_ref = (long)outpoint_var.inner & ~1;
298                         long output_ref = (long)&obj->static_output_counterparty_payment.output;
299                         long key_derivation_params_ref = (long)&obj->static_output_counterparty_payment.key_derivation_params;
300                         return 0 /* LDKSpendableOutputDescriptor - StaticOutputCounterpartyPayment */; (void) outpoint_ref; (void) (long)output_ref; (void) key_derivation_params_ref;
301                 }
302                 default: abort();
303         }
304 }
305 uint32_t LDKCVec_1SpendableOutputDescriptorZ_1new(void* ctx_TODO, uint32_tArray elems) {
306         LDKCVec_SpendableOutputDescriptorZ *ret = MALLOC(sizeof(LDKCVec_SpendableOutputDescriptorZ), "LDKCVec_SpendableOutputDescriptorZ");
307         ret->datalen = elems.len;
308         if (ret->datalen == 0) {
309                 ret->data = NULL;
310         } else {
311                 ret->data = MALLOC(sizeof(LDKSpendableOutputDescriptor) * ret->datalen, "LDKCVec_SpendableOutputDescriptorZ Data");
312                 uint32_t *java_elems = (uint32_t*)elems.ptr;
313                 for (size_t i = 0; i < ret->datalen; i++) {
314                         uint32_t arr_elem = java_elems[i];
315                         LDKSpendableOutputDescriptor arr_elem_conv = *(LDKSpendableOutputDescriptor*)arr_elem;
316                         FREE((void*)arr_elem);
317                         ret->data[i] = arr_elem_conv;
318                 }
319         }
320         return (long)ret;
321 }
322 static inline LDKCVec_SpendableOutputDescriptorZ CVec_SpendableOutputDescriptorZ_clone(const LDKCVec_SpendableOutputDescriptorZ *orig) {
323         LDKCVec_SpendableOutputDescriptorZ ret = { .data = MALLOC(sizeof(LDKSpendableOutputDescriptor) * orig->datalen, "LDKCVec_SpendableOutputDescriptorZ clone bytes"), .datalen = orig->datalen };
324         for (size_t i = 0; i < ret.datalen; i++) {
325                 ret.data[i] = SpendableOutputDescriptor_clone(&orig->data[i]);
326         }
327         return ret;
328 }
329 uint32_t LDKErrorAction_1ref_1from_1ptr (void* ctx_TODO, uint32_t ptr) {
330         LDKErrorAction *obj = (LDKErrorAction*)ptr;
331         switch(obj->tag) {
332                 case LDKErrorAction_DisconnectPeer: {
333                         LDKErrorMessage msg_var = obj->disconnect_peer.msg;
334                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
335                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
336                         long msg_ref = (long)msg_var.inner & ~1;
337                         return 0 /* LDKErrorAction - DisconnectPeer */; (void) msg_ref;
338                 }
339                 case LDKErrorAction_IgnoreError: {
340                         return 0 /* LDKErrorAction - IgnoreError */;
341                 }
342                 case LDKErrorAction_SendErrorMessage: {
343                         LDKErrorMessage msg_var = obj->send_error_message.msg;
344                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
345                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
346                         long msg_ref = (long)msg_var.inner & ~1;
347                         return 0 /* LDKErrorAction - SendErrorMessage */; (void) msg_ref;
348                 }
349                 default: abort();
350         }
351 }
352 uint32_t LDKHTLCFailChannelUpdate_1ref_1from_1ptr (void* ctx_TODO, uint32_t ptr) {
353         LDKHTLCFailChannelUpdate *obj = (LDKHTLCFailChannelUpdate*)ptr;
354         switch(obj->tag) {
355                 case LDKHTLCFailChannelUpdate_ChannelUpdateMessage: {
356                         LDKChannelUpdate msg_var = obj->channel_update_message.msg;
357                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
358                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
359                         long msg_ref = (long)msg_var.inner & ~1;
360                         return 0 /* LDKHTLCFailChannelUpdate - ChannelUpdateMessage */; (void) msg_ref;
361                 }
362                 case LDKHTLCFailChannelUpdate_ChannelClosed: {
363                         return 0 /* LDKHTLCFailChannelUpdate - ChannelClosed */; (void) obj->channel_closed.short_channel_id; (void) obj->channel_closed.is_permanent;
364                 }
365                 case LDKHTLCFailChannelUpdate_NodeFailure: {
366                         int8_tArray node_id_arr = { .len = 33, .ptr = MALLOC(33, "Native int8_tArray Bytes") };
367                         memcpy(node_id_arr.ptr, obj->node_failure.node_id.compressed_form, 33);
368                         return 0 /* LDKHTLCFailChannelUpdate - NodeFailure */; (void) node_id_arr; (void) obj->node_failure.is_permanent;
369                 }
370                 default: abort();
371         }
372 }
373 uint32_t LDKMessageSendEvent_1ref_1from_1ptr (void* ctx_TODO, uint32_t ptr) {
374         LDKMessageSendEvent *obj = (LDKMessageSendEvent*)ptr;
375         switch(obj->tag) {
376                 case LDKMessageSendEvent_SendAcceptChannel: {
377                         int8_tArray node_id_arr = { .len = 33, .ptr = MALLOC(33, "Native int8_tArray Bytes") };
378                         memcpy(node_id_arr.ptr, obj->send_accept_channel.node_id.compressed_form, 33);
379                         LDKAcceptChannel msg_var = obj->send_accept_channel.msg;
380                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
381                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
382                         long msg_ref = (long)msg_var.inner & ~1;
383                         return 0 /* LDKMessageSendEvent - SendAcceptChannel */; (void) node_id_arr; (void) msg_ref;
384                 }
385                 case LDKMessageSendEvent_SendOpenChannel: {
386                         int8_tArray node_id_arr = { .len = 33, .ptr = MALLOC(33, "Native int8_tArray Bytes") };
387                         memcpy(node_id_arr.ptr, obj->send_open_channel.node_id.compressed_form, 33);
388                         LDKOpenChannel msg_var = obj->send_open_channel.msg;
389                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
390                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
391                         long msg_ref = (long)msg_var.inner & ~1;
392                         return 0 /* LDKMessageSendEvent - SendOpenChannel */; (void) node_id_arr; (void) msg_ref;
393                 }
394                 case LDKMessageSendEvent_SendFundingCreated: {
395                         int8_tArray node_id_arr = { .len = 33, .ptr = MALLOC(33, "Native int8_tArray Bytes") };
396                         memcpy(node_id_arr.ptr, obj->send_funding_created.node_id.compressed_form, 33);
397                         LDKFundingCreated msg_var = obj->send_funding_created.msg;
398                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
399                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
400                         long msg_ref = (long)msg_var.inner & ~1;
401                         return 0 /* LDKMessageSendEvent - SendFundingCreated */; (void) node_id_arr; (void) msg_ref;
402                 }
403                 case LDKMessageSendEvent_SendFundingSigned: {
404                         int8_tArray node_id_arr = { .len = 33, .ptr = MALLOC(33, "Native int8_tArray Bytes") };
405                         memcpy(node_id_arr.ptr, obj->send_funding_signed.node_id.compressed_form, 33);
406                         LDKFundingSigned msg_var = obj->send_funding_signed.msg;
407                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
408                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
409                         long msg_ref = (long)msg_var.inner & ~1;
410                         return 0 /* LDKMessageSendEvent - SendFundingSigned */; (void) node_id_arr; (void) msg_ref;
411                 }
412                 case LDKMessageSendEvent_SendFundingLocked: {
413                         int8_tArray node_id_arr = { .len = 33, .ptr = MALLOC(33, "Native int8_tArray Bytes") };
414                         memcpy(node_id_arr.ptr, obj->send_funding_locked.node_id.compressed_form, 33);
415                         LDKFundingLocked msg_var = obj->send_funding_locked.msg;
416                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
417                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
418                         long msg_ref = (long)msg_var.inner & ~1;
419                         return 0 /* LDKMessageSendEvent - SendFundingLocked */; (void) node_id_arr; (void) msg_ref;
420                 }
421                 case LDKMessageSendEvent_SendAnnouncementSignatures: {
422                         int8_tArray node_id_arr = { .len = 33, .ptr = MALLOC(33, "Native int8_tArray Bytes") };
423                         memcpy(node_id_arr.ptr, obj->send_announcement_signatures.node_id.compressed_form, 33);
424                         LDKAnnouncementSignatures msg_var = obj->send_announcement_signatures.msg;
425                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
426                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
427                         long msg_ref = (long)msg_var.inner & ~1;
428                         return 0 /* LDKMessageSendEvent - SendAnnouncementSignatures */; (void) node_id_arr; (void) msg_ref;
429                 }
430                 case LDKMessageSendEvent_UpdateHTLCs: {
431                         int8_tArray node_id_arr = { .len = 33, .ptr = MALLOC(33, "Native int8_tArray Bytes") };
432                         memcpy(node_id_arr.ptr, obj->update_htl_cs.node_id.compressed_form, 33);
433                         LDKCommitmentUpdate updates_var = obj->update_htl_cs.updates;
434                         CHECK((((long)updates_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
435                         CHECK((((long)&updates_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
436                         long updates_ref = (long)updates_var.inner & ~1;
437                         return 0 /* LDKMessageSendEvent - UpdateHTLCs */; (void) node_id_arr; (void) updates_ref;
438                 }
439                 case LDKMessageSendEvent_SendRevokeAndACK: {
440                         int8_tArray node_id_arr = { .len = 33, .ptr = MALLOC(33, "Native int8_tArray Bytes") };
441                         memcpy(node_id_arr.ptr, obj->send_revoke_and_ack.node_id.compressed_form, 33);
442                         LDKRevokeAndACK msg_var = obj->send_revoke_and_ack.msg;
443                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
444                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
445                         long msg_ref = (long)msg_var.inner & ~1;
446                         return 0 /* LDKMessageSendEvent - SendRevokeAndACK */; (void) node_id_arr; (void) msg_ref;
447                 }
448                 case LDKMessageSendEvent_SendClosingSigned: {
449                         int8_tArray node_id_arr = { .len = 33, .ptr = MALLOC(33, "Native int8_tArray Bytes") };
450                         memcpy(node_id_arr.ptr, obj->send_closing_signed.node_id.compressed_form, 33);
451                         LDKClosingSigned msg_var = obj->send_closing_signed.msg;
452                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
453                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
454                         long msg_ref = (long)msg_var.inner & ~1;
455                         return 0 /* LDKMessageSendEvent - SendClosingSigned */; (void) node_id_arr; (void) msg_ref;
456                 }
457                 case LDKMessageSendEvent_SendShutdown: {
458                         int8_tArray node_id_arr = { .len = 33, .ptr = MALLOC(33, "Native int8_tArray Bytes") };
459                         memcpy(node_id_arr.ptr, obj->send_shutdown.node_id.compressed_form, 33);
460                         LDKShutdown msg_var = obj->send_shutdown.msg;
461                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
462                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
463                         long msg_ref = (long)msg_var.inner & ~1;
464                         return 0 /* LDKMessageSendEvent - SendShutdown */; (void) node_id_arr; (void) msg_ref;
465                 }
466                 case LDKMessageSendEvent_SendChannelReestablish: {
467                         int8_tArray node_id_arr = { .len = 33, .ptr = MALLOC(33, "Native int8_tArray Bytes") };
468                         memcpy(node_id_arr.ptr, obj->send_channel_reestablish.node_id.compressed_form, 33);
469                         LDKChannelReestablish msg_var = obj->send_channel_reestablish.msg;
470                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
471                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
472                         long msg_ref = (long)msg_var.inner & ~1;
473                         return 0 /* LDKMessageSendEvent - SendChannelReestablish */; (void) node_id_arr; (void) msg_ref;
474                 }
475                 case LDKMessageSendEvent_BroadcastChannelAnnouncement: {
476                         LDKChannelAnnouncement msg_var = obj->broadcast_channel_announcement.msg;
477                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
478                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
479                         long msg_ref = (long)msg_var.inner & ~1;
480                         LDKChannelUpdate update_msg_var = obj->broadcast_channel_announcement.update_msg;
481                         CHECK((((long)update_msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
482                         CHECK((((long)&update_msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
483                         long update_msg_ref = (long)update_msg_var.inner & ~1;
484                         return 0 /* LDKMessageSendEvent - BroadcastChannelAnnouncement */; (void) msg_ref; (void) update_msg_ref;
485                 }
486                 case LDKMessageSendEvent_BroadcastNodeAnnouncement: {
487                         LDKNodeAnnouncement msg_var = obj->broadcast_node_announcement.msg;
488                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
489                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
490                         long msg_ref = (long)msg_var.inner & ~1;
491                         return 0 /* LDKMessageSendEvent - BroadcastNodeAnnouncement */; (void) msg_ref;
492                 }
493                 case LDKMessageSendEvent_BroadcastChannelUpdate: {
494                         LDKChannelUpdate msg_var = obj->broadcast_channel_update.msg;
495                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
496                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
497                         long msg_ref = (long)msg_var.inner & ~1;
498                         return 0 /* LDKMessageSendEvent - BroadcastChannelUpdate */; (void) msg_ref;
499                 }
500                 case LDKMessageSendEvent_HandleError: {
501                         int8_tArray node_id_arr = { .len = 33, .ptr = MALLOC(33, "Native int8_tArray Bytes") };
502                         memcpy(node_id_arr.ptr, obj->handle_error.node_id.compressed_form, 33);
503                         long action_ref = (long)&obj->handle_error.action;
504                         return 0 /* LDKMessageSendEvent - HandleError */; (void) node_id_arr; (void) action_ref;
505                 }
506                 case LDKMessageSendEvent_PaymentFailureNetworkUpdate: {
507                         long update_ref = (long)&obj->payment_failure_network_update.update;
508                         return 0 /* LDKMessageSendEvent - PaymentFailureNetworkUpdate */; (void) update_ref;
509                 }
510                 case LDKMessageSendEvent_SendChannelRangeQuery: {
511                         int8_tArray node_id_arr = { .len = 33, .ptr = MALLOC(33, "Native int8_tArray Bytes") };
512                         memcpy(node_id_arr.ptr, obj->send_channel_range_query.node_id.compressed_form, 33);
513                         LDKQueryChannelRange msg_var = obj->send_channel_range_query.msg;
514                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
515                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
516                         long msg_ref = (long)msg_var.inner & ~1;
517                         return 0 /* LDKMessageSendEvent - SendChannelRangeQuery */; (void) node_id_arr; (void) msg_ref;
518                 }
519                 case LDKMessageSendEvent_SendShortIdsQuery: {
520                         int8_tArray node_id_arr = { .len = 33, .ptr = MALLOC(33, "Native int8_tArray Bytes") };
521                         memcpy(node_id_arr.ptr, obj->send_short_ids_query.node_id.compressed_form, 33);
522                         LDKQueryShortChannelIds msg_var = obj->send_short_ids_query.msg;
523                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
524                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
525                         long msg_ref = (long)msg_var.inner & ~1;
526                         return 0 /* LDKMessageSendEvent - SendShortIdsQuery */; (void) node_id_arr; (void) msg_ref;
527                 }
528                 default: abort();
529         }
530 }
531 uint32_t LDKCVec_1MessageSendEventZ_1new(void* ctx_TODO, uint32_tArray elems) {
532         LDKCVec_MessageSendEventZ *ret = MALLOC(sizeof(LDKCVec_MessageSendEventZ), "LDKCVec_MessageSendEventZ");
533         ret->datalen = elems.len;
534         if (ret->datalen == 0) {
535                 ret->data = NULL;
536         } else {
537                 ret->data = MALLOC(sizeof(LDKMessageSendEvent) * ret->datalen, "LDKCVec_MessageSendEventZ Data");
538                 uint32_t *java_elems = (uint32_t*)elems.ptr;
539                 for (size_t i = 0; i < ret->datalen; i++) {
540                         uint32_t arr_elem = java_elems[i];
541                         LDKMessageSendEvent arr_elem_conv = *(LDKMessageSendEvent*)arr_elem;
542                         FREE((void*)arr_elem);
543                         ret->data[i] = arr_elem_conv;
544                 }
545         }
546         return (long)ret;
547 }
548 static inline LDKCVec_MessageSendEventZ CVec_MessageSendEventZ_clone(const LDKCVec_MessageSendEventZ *orig) {
549         LDKCVec_MessageSendEventZ ret = { .data = MALLOC(sizeof(LDKMessageSendEvent) * orig->datalen, "LDKCVec_MessageSendEventZ clone bytes"), .datalen = orig->datalen };
550         for (size_t i = 0; i < ret.datalen; i++) {
551                 ret.data[i] = MessageSendEvent_clone(&orig->data[i]);
552         }
553         return ret;
554 }
555 uint32_t LDKEvent_1ref_1from_1ptr (void* ctx_TODO, uint32_t ptr) {
556         LDKEvent *obj = (LDKEvent*)ptr;
557         switch(obj->tag) {
558                 case LDKEvent_FundingGenerationReady: {
559                         int8_tArray temporary_channel_id_arr = { .len = 32, .ptr = MALLOC(32, "Native int8_tArray Bytes") };
560                         memcpy(temporary_channel_id_arr.ptr, obj->funding_generation_ready.temporary_channel_id.data, 32);
561                         LDKCVec_u8Z output_script_var = obj->funding_generation_ready.output_script;
562                         int8_tArray output_script_arr = { .len = output_script_var.datalen, .ptr = MALLOC(output_script_var.datalen, "Native int8_tArray Bytes") };
563                         memcpy(output_script_arr.ptr, output_script_var.data, output_script_var.datalen);
564                         return 0 /* LDKEvent - FundingGenerationReady */; (void) temporary_channel_id_arr; (void) obj->funding_generation_ready.channel_value_satoshis; (void) output_script_arr; (void) obj->funding_generation_ready.user_channel_id;
565                 }
566                 case LDKEvent_FundingBroadcastSafe: {
567                         LDKOutPoint funding_txo_var = obj->funding_broadcast_safe.funding_txo;
568                         CHECK((((long)funding_txo_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
569                         CHECK((((long)&funding_txo_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
570                         long funding_txo_ref = (long)funding_txo_var.inner & ~1;
571                         return 0 /* LDKEvent - FundingBroadcastSafe */; (void) funding_txo_ref; (void) obj->funding_broadcast_safe.user_channel_id;
572                 }
573                 case LDKEvent_PaymentReceived: {
574                         int8_tArray payment_hash_arr = { .len = 32, .ptr = MALLOC(32, "Native int8_tArray Bytes") };
575                         memcpy(payment_hash_arr.ptr, obj->payment_received.payment_hash.data, 32);
576                         int8_tArray payment_secret_arr = { .len = 32, .ptr = MALLOC(32, "Native int8_tArray Bytes") };
577                         memcpy(payment_secret_arr.ptr, obj->payment_received.payment_secret.data, 32);
578                         return 0 /* LDKEvent - PaymentReceived */; (void) payment_hash_arr; (void) payment_secret_arr; (void) obj->payment_received.amt;
579                 }
580                 case LDKEvent_PaymentSent: {
581                         int8_tArray payment_preimage_arr = { .len = 32, .ptr = MALLOC(32, "Native int8_tArray Bytes") };
582                         memcpy(payment_preimage_arr.ptr, obj->payment_sent.payment_preimage.data, 32);
583                         return 0 /* LDKEvent - PaymentSent */; (void) payment_preimage_arr;
584                 }
585                 case LDKEvent_PaymentFailed: {
586                         int8_tArray payment_hash_arr = { .len = 32, .ptr = MALLOC(32, "Native int8_tArray Bytes") };
587                         memcpy(payment_hash_arr.ptr, obj->payment_failed.payment_hash.data, 32);
588                         return 0 /* LDKEvent - PaymentFailed */; (void) payment_hash_arr; (void) obj->payment_failed.rejected_by_dest;
589                 }
590                 case LDKEvent_PendingHTLCsForwardable: {
591                         return 0 /* LDKEvent - PendingHTLCsForwardable */; (void) obj->pending_htl_cs_forwardable.time_forwardable;
592                 }
593                 case LDKEvent_SpendableOutputs: {
594                         LDKCVec_SpendableOutputDescriptorZ outputs_var = obj->spendable_outputs.outputs;
595                         uint32_tArray outputs_arr = { .len = outputs_var.datalen, .ptr = MALLOC(outputs_var.datalen * sizeof(int32_t), "Native uint32_tArray Bytes") };
596                         uint32_t *outputs_arr_ptr = (uint32_t*)outputs_arr.ptr;
597                         for (size_t b = 0; b < outputs_var.datalen; b++) {
598                                 long arr_conv_27_ref = (long)&outputs_var.data[b];
599                                 outputs_arr_ptr[b] = arr_conv_27_ref;
600                         }
601                         return 0 /* LDKEvent - SpendableOutputs */; (void) outputs_arr;
602                 }
603                 default: abort();
604         }
605 }
606 uint32_t LDKCVec_1EventZ_1new(void* ctx_TODO, uint32_tArray elems) {
607         LDKCVec_EventZ *ret = MALLOC(sizeof(LDKCVec_EventZ), "LDKCVec_EventZ");
608         ret->datalen = elems.len;
609         if (ret->datalen == 0) {
610                 ret->data = NULL;
611         } else {
612                 ret->data = MALLOC(sizeof(LDKEvent) * ret->datalen, "LDKCVec_EventZ Data");
613                 uint32_t *java_elems = (uint32_t*)elems.ptr;
614                 for (size_t i = 0; i < ret->datalen; i++) {
615                         uint32_t arr_elem = java_elems[i];
616                         LDKEvent arr_elem_conv = *(LDKEvent*)arr_elem;
617                         FREE((void*)arr_elem);
618                         ret->data[i] = arr_elem_conv;
619                 }
620         }
621         return (long)ret;
622 }
623 static inline LDKCVec_EventZ CVec_EventZ_clone(const LDKCVec_EventZ *orig) {
624         LDKCVec_EventZ ret = { .data = MALLOC(sizeof(LDKEvent) * orig->datalen, "LDKCVec_EventZ clone bytes"), .datalen = orig->datalen };
625         for (size_t i = 0; i < ret.datalen; i++) {
626                 ret.data[i] = Event_clone(&orig->data[i]);
627         }
628         return ret;
629 }
630 uint32_t LDKC2Tuple_1usizeTransactionZ_1new(void* ctx_TODO, intptr_t a, int8_tArray b) {
631         LDKC2Tuple_usizeTransactionZ* ret = MALLOC(sizeof(LDKC2Tuple_usizeTransactionZ), "LDKC2Tuple_usizeTransactionZ");
632         ret->a = a;
633         LDKTransaction b_ref;
634         b_ref.datalen = b.len;
635         b_ref.data = MALLOC(b_ref.datalen, "LDKTransaction Bytes");
636         memcpy(b_ref.data, b.ptr, b_ref.datalen);
637         b_ref.data_is_owned = false;
638         ret->b = b_ref;
639         return (long)ret;
640 }
641 intptr_t LDKC2Tuple_1usizeTransactionZ_1get_1a(void* ctx_TODO, uint32_t ptr) {
642         LDKC2Tuple_usizeTransactionZ *tuple = (LDKC2Tuple_usizeTransactionZ*)ptr;
643         return tuple->a;
644 }
645 int8_tArray LDKC2Tuple_1usizeTransactionZ_1get_1b(void* ctx_TODO, uint32_t ptr) {
646         LDKC2Tuple_usizeTransactionZ *tuple = (LDKC2Tuple_usizeTransactionZ*)ptr;
647         LDKTransaction b_var = tuple->b;
648         int8_tArray b_arr = { .len = b_var.datalen, .ptr = MALLOC(b_var.datalen, "Native int8_tArray Bytes") };
649         memcpy(b_arr.ptr, b_var.data, b_var.datalen);
650         return b_arr;
651 }
652 uint32_t LDKCVec_1C2Tuple_1usizeTransactionZZ_1new(void* ctx_TODO, uint32_tArray elems) {
653         LDKCVec_C2Tuple_usizeTransactionZZ *ret = MALLOC(sizeof(LDKCVec_C2Tuple_usizeTransactionZZ), "LDKCVec_C2Tuple_usizeTransactionZZ");
654         ret->datalen = elems.len;
655         if (ret->datalen == 0) {
656                 ret->data = NULL;
657         } else {
658                 ret->data = MALLOC(sizeof(LDKC2Tuple_usizeTransactionZ) * ret->datalen, "LDKCVec_C2Tuple_usizeTransactionZZ Data");
659                 uint32_t *java_elems = (uint32_t*)elems.ptr;
660                 for (size_t i = 0; i < ret->datalen; i++) {
661                         uint32_t arr_elem = java_elems[i];
662                         LDKC2Tuple_usizeTransactionZ arr_elem_conv = *(LDKC2Tuple_usizeTransactionZ*)arr_elem;
663                         FREE((void*)arr_elem);
664                         ret->data[i] = arr_elem_conv;
665                 }
666         }
667         return (long)ret;
668 }
669 jboolean LDKCResult_1NoneChannelMonitorUpdateErrZ_1result_1ok (void* ctx_TODO, uint32_t arg) {
670         return ((LDKCResult_NoneChannelMonitorUpdateErrZ*)arg)->result_ok;
671 }
672 void LDKCResult_1NoneChannelMonitorUpdateErrZ_1get_1ok (void* ctx_TODO, uint32_t arg) {
673         LDKCResult_NoneChannelMonitorUpdateErrZ *val = (LDKCResult_NoneChannelMonitorUpdateErrZ*)arg;
674         CHECK(val->result_ok);
675         return *val->contents.result;
676 }
677 uint32_t LDKCResult_1NoneChannelMonitorUpdateErrZ_1get_1err (void* ctx_TODO, uint32_t arg) {
678         LDKCResult_NoneChannelMonitorUpdateErrZ *val = (LDKCResult_NoneChannelMonitorUpdateErrZ*)arg;
679         CHECK(!val->result_ok);
680         uint32_t err_conv = LDKChannelMonitorUpdateErr_to_js((*val->contents.err));
681         return err_conv;
682 }
683 static inline LDKCResult_NoneChannelMonitorUpdateErrZ CResult_NoneChannelMonitorUpdateErrZ_clone(const LDKCResult_NoneChannelMonitorUpdateErrZ *orig) {
684         LDKCResult_NoneChannelMonitorUpdateErrZ res = { .result_ok = orig->result_ok };
685         if (orig->result_ok) {
686                 res.contents.result = NULL;
687         } else {
688                 LDKChannelMonitorUpdateErr* contents = MALLOC(sizeof(LDKChannelMonitorUpdateErr), "LDKChannelMonitorUpdateErr result Err clone");
689                 *contents = ChannelMonitorUpdateErr_clone(orig->contents.err);
690                 res.contents.err = contents;
691         }
692         return res;
693 }
694 uint32_t LDKCVec_1MonitorEventZ_1new(void* ctx_TODO, uint32_tArray elems) {
695         LDKCVec_MonitorEventZ *ret = MALLOC(sizeof(LDKCVec_MonitorEventZ), "LDKCVec_MonitorEventZ");
696         ret->datalen = elems.len;
697         if (ret->datalen == 0) {
698                 ret->data = NULL;
699         } else {
700                 ret->data = MALLOC(sizeof(LDKMonitorEvent) * ret->datalen, "LDKCVec_MonitorEventZ Data");
701                 uint32_t *java_elems = (uint32_t*)elems.ptr;
702                 for (size_t i = 0; i < ret->datalen; i++) {
703                         uint32_t arr_elem = java_elems[i];
704                         LDKMonitorEvent arr_elem_conv;
705                         arr_elem_conv.inner = (void*)(arr_elem & (~1));
706                         arr_elem_conv.is_owned = (arr_elem & 1) || (arr_elem == 0);
707                         if (arr_elem_conv.inner != NULL)
708                                 arr_elem_conv = MonitorEvent_clone(&arr_elem_conv);
709                         ret->data[i] = arr_elem_conv;
710                 }
711         }
712         return (long)ret;
713 }
714 static inline LDKCVec_MonitorEventZ CVec_MonitorEventZ_clone(const LDKCVec_MonitorEventZ *orig) {
715         LDKCVec_MonitorEventZ ret = { .data = MALLOC(sizeof(LDKMonitorEvent) * orig->datalen, "LDKCVec_MonitorEventZ clone bytes"), .datalen = orig->datalen };
716         for (size_t i = 0; i < ret.datalen; i++) {
717                 ret.data[i] = MonitorEvent_clone(&orig->data[i]);
718         }
719         return ret;
720 }
721 jboolean LDKCResult_1ChannelMonitorUpdateDecodeErrorZ_1result_1ok (void* ctx_TODO, uint32_t arg) {
722         return ((LDKCResult_ChannelMonitorUpdateDecodeErrorZ*)arg)->result_ok;
723 }
724 uint32_t LDKCResult_1ChannelMonitorUpdateDecodeErrorZ_1get_1ok (void* ctx_TODO, uint32_t arg) {
725         LDKCResult_ChannelMonitorUpdateDecodeErrorZ *val = (LDKCResult_ChannelMonitorUpdateDecodeErrorZ*)arg;
726         CHECK(val->result_ok);
727         LDKChannelMonitorUpdate res_var = (*val->contents.result);
728         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
729         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
730         long res_ref = (long)res_var.inner & ~1;
731         return res_ref;
732 }
733 uint32_t LDKCResult_1ChannelMonitorUpdateDecodeErrorZ_1get_1err (void* ctx_TODO, uint32_t arg) {
734         LDKCResult_ChannelMonitorUpdateDecodeErrorZ *val = (LDKCResult_ChannelMonitorUpdateDecodeErrorZ*)arg;
735         CHECK(!val->result_ok);
736         LDKDecodeError err_var = (*val->contents.err);
737         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
738         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
739         long err_ref = (long)err_var.inner & ~1;
740         return err_ref;
741 }
742 jboolean LDKCResult_1NoneMonitorUpdateErrorZ_1result_1ok (void* ctx_TODO, uint32_t arg) {
743         return ((LDKCResult_NoneMonitorUpdateErrorZ*)arg)->result_ok;
744 }
745 void LDKCResult_1NoneMonitorUpdateErrorZ_1get_1ok (void* ctx_TODO, uint32_t arg) {
746         LDKCResult_NoneMonitorUpdateErrorZ *val = (LDKCResult_NoneMonitorUpdateErrorZ*)arg;
747         CHECK(val->result_ok);
748         return *val->contents.result;
749 }
750 uint32_t LDKCResult_1NoneMonitorUpdateErrorZ_1get_1err (void* ctx_TODO, uint32_t arg) {
751         LDKCResult_NoneMonitorUpdateErrorZ *val = (LDKCResult_NoneMonitorUpdateErrorZ*)arg;
752         CHECK(!val->result_ok);
753         LDKMonitorUpdateError err_var = (*val->contents.err);
754         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
755         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
756         long err_ref = (long)err_var.inner & ~1;
757         return err_ref;
758 }
759 uint32_t LDKC2Tuple_1OutPointScriptZ_1new(void* ctx_TODO, uint32_t a, int8_tArray b) {
760         LDKC2Tuple_OutPointScriptZ* ret = MALLOC(sizeof(LDKC2Tuple_OutPointScriptZ), "LDKC2Tuple_OutPointScriptZ");
761         LDKOutPoint a_conv;
762         a_conv.inner = (void*)(a & (~1));
763         a_conv.is_owned = (a & 1) || (a == 0);
764         if (a_conv.inner != NULL)
765                 a_conv = OutPoint_clone(&a_conv);
766         ret->a = a_conv;
767         LDKCVec_u8Z b_ref;
768         b_ref.datalen = b.len;
769         b_ref.data = MALLOC(b_ref.datalen, "LDKCVec_u8Z Bytes");
770         memcpy(b_ref.data, b.ptr, b_ref.datalen);
771         ret->b = b_ref;
772         return (long)ret;
773 }
774 static inline LDKC2Tuple_OutPointScriptZ C2Tuple_OutPointScriptZ_clone(const LDKC2Tuple_OutPointScriptZ *orig) {
775         LDKC2Tuple_OutPointScriptZ ret = {
776                 .a = OutPoint_clone(&orig->a),
777                 .b = CVec_u8Z_clone(&orig->b),
778         };
779         return ret;
780 }
781 uint32_t LDKC2Tuple_1OutPointScriptZ_1get_1a(void* ctx_TODO, uint32_t ptr) {
782         LDKC2Tuple_OutPointScriptZ *tuple = (LDKC2Tuple_OutPointScriptZ*)ptr;
783         LDKOutPoint a_var = tuple->a;
784         CHECK((((long)a_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
785         CHECK((((long)&a_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
786         long a_ref = (long)a_var.inner & ~1;
787         return a_ref;
788 }
789 int8_tArray LDKC2Tuple_1OutPointScriptZ_1get_1b(void* ctx_TODO, uint32_t ptr) {
790         LDKC2Tuple_OutPointScriptZ *tuple = (LDKC2Tuple_OutPointScriptZ*)ptr;
791         LDKCVec_u8Z b_var = tuple->b;
792         int8_tArray b_arr = { .len = b_var.datalen, .ptr = MALLOC(b_var.datalen, "Native int8_tArray Bytes") };
793         memcpy(b_arr.ptr, b_var.data, b_var.datalen);
794         return b_arr;
795 }
796 uint32_t LDKC2Tuple_1u32TxOutZ_1new(void* ctx_TODO, int32_t a, uint32_t b) {
797         LDKC2Tuple_u32TxOutZ* ret = MALLOC(sizeof(LDKC2Tuple_u32TxOutZ), "LDKC2Tuple_u32TxOutZ");
798         ret->a = a;
799         LDKTxOut b_conv = *(LDKTxOut*)b;
800         FREE((void*)b);
801         ret->b = b_conv;
802         return (long)ret;
803 }
804 int32_t LDKC2Tuple_1u32TxOutZ_1get_1a(void* ctx_TODO, uint32_t ptr) {
805         LDKC2Tuple_u32TxOutZ *tuple = (LDKC2Tuple_u32TxOutZ*)ptr;
806         return tuple->a;
807 }
808 uint32_t LDKC2Tuple_1u32TxOutZ_1get_1b(void* ctx_TODO, uint32_t ptr) {
809         LDKC2Tuple_u32TxOutZ *tuple = (LDKC2Tuple_u32TxOutZ*)ptr;
810         long b_ref = (long)&tuple->b;
811         return (long)b_ref;
812 }
813 uint32_t LDKCVec_1C2Tuple_1u32TxOutZZ_1new(void* ctx_TODO, uint32_tArray elems) {
814         LDKCVec_C2Tuple_u32TxOutZZ *ret = MALLOC(sizeof(LDKCVec_C2Tuple_u32TxOutZZ), "LDKCVec_C2Tuple_u32TxOutZZ");
815         ret->datalen = elems.len;
816         if (ret->datalen == 0) {
817                 ret->data = NULL;
818         } else {
819                 ret->data = MALLOC(sizeof(LDKC2Tuple_u32TxOutZ) * ret->datalen, "LDKCVec_C2Tuple_u32TxOutZZ Data");
820                 uint32_t *java_elems = (uint32_t*)elems.ptr;
821                 for (size_t i = 0; i < ret->datalen; i++) {
822                         uint32_t arr_elem = java_elems[i];
823                         LDKC2Tuple_u32TxOutZ arr_elem_conv = *(LDKC2Tuple_u32TxOutZ*)arr_elem;
824                         FREE((void*)arr_elem);
825                         ret->data[i] = arr_elem_conv;
826                 }
827         }
828         return (long)ret;
829 }
830 uint32_t LDKC2Tuple_1TxidCVec_1C2Tuple_1u32TxOutZZZ_1new(void* ctx_TODO, int8_tArray a, uint32_tArray b) {
831         LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ* ret = MALLOC(sizeof(LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ), "LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ");
832         LDKThirtyTwoBytes a_ref;
833         CHECK(a.len == 32);
834         memcpy(a_ref.data, a.ptr, 32);
835         ret->a = a_ref;
836         LDKCVec_C2Tuple_u32TxOutZZ b_constr;
837         b_constr.datalen = b.len;
838         if (b_constr.datalen > 0)
839                 b_constr.data = MALLOC(b_constr.datalen * sizeof(LDKC2Tuple_u32TxOutZ), "LDKCVec_C2Tuple_u32TxOutZZ Elements");
840         else
841                 b_constr.data = NULL;
842         uint32_t* b_vals = (uint32_t*) b.ptr;
843         for (size_t z = 0; z < b_constr.datalen; z++) {
844                 uint32_t arr_conv_25 = b_vals[z];
845                 LDKC2Tuple_u32TxOutZ arr_conv_25_conv = *(LDKC2Tuple_u32TxOutZ*)arr_conv_25;
846                 FREE((void*)arr_conv_25);
847                 b_constr.data[z] = arr_conv_25_conv;
848         }
849         ret->b = b_constr;
850         return (long)ret;
851 }
852 int8_tArray LDKC2Tuple_1TxidCVec_1C2Tuple_1u32TxOutZZZ_1get_1a(void* ctx_TODO, uint32_t ptr) {
853         LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ *tuple = (LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ*)ptr;
854         int8_tArray a_arr = { .len = 32, .ptr = MALLOC(32, "Native int8_tArray Bytes") };
855         memcpy(a_arr.ptr, tuple->a.data, 32);
856         return a_arr;
857 }
858 uint32_tArray LDKC2Tuple_1TxidCVec_1C2Tuple_1u32TxOutZZZ_1get_1b(void* ctx_TODO, uint32_t ptr) {
859         LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ *tuple = (LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ*)ptr;
860         LDKCVec_C2Tuple_u32TxOutZZ b_var = tuple->b;
861         uint32_tArray b_arr = { .len = b_var.datalen, .ptr = MALLOC(b_var.datalen * sizeof(int32_t), "Native uint32_tArray Bytes") };
862         uint32_t *b_arr_ptr = (uint32_t*)b_arr.ptr;
863         for (size_t z = 0; z < b_var.datalen; z++) {
864                 long arr_conv_25_ref = (long)&b_var.data[z];
865                 b_arr_ptr[z] = arr_conv_25_ref;
866         }
867         return b_arr;
868 }
869 uint32_t LDKCVec_1C2Tuple_1TxidCVec_1C2Tuple_1u32TxOutZZZZ_1new(void* ctx_TODO, uint32_tArray elems) {
870         LDKCVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ *ret = MALLOC(sizeof(LDKCVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ), "LDKCVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ");
871         ret->datalen = elems.len;
872         if (ret->datalen == 0) {
873                 ret->data = NULL;
874         } else {
875                 ret->data = MALLOC(sizeof(LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ) * ret->datalen, "LDKCVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ Data");
876                 uint32_t *java_elems = (uint32_t*)elems.ptr;
877                 for (size_t i = 0; i < ret->datalen; i++) {
878                         uint32_t arr_elem = java_elems[i];
879                         LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ arr_elem_conv = *(LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ*)arr_elem;
880                         FREE((void*)arr_elem);
881                         ret->data[i] = arr_elem_conv;
882                 }
883         }
884         return (long)ret;
885 }
886 uint32_t LDKC2Tuple_1SignatureCVec_1SignatureZZ_1new(void* ctx_TODO, int8_tArray a, ptrArray b) {
887         LDKC2Tuple_SignatureCVec_SignatureZZ* ret = MALLOC(sizeof(LDKC2Tuple_SignatureCVec_SignatureZZ), "LDKC2Tuple_SignatureCVec_SignatureZZ");
888         LDKSignature a_ref;
889         CHECK(a.len == 64);
890         memcpy(a_ref.compact_form, a.ptr, 64);
891         ret->a = a_ref;
892         LDKCVec_SignatureZ b_constr;
893         b_constr.datalen = b.len;
894         if (b_constr.datalen > 0)
895                 b_constr.data = MALLOC(b_constr.datalen * sizeof(LDKSignature), "LDKCVec_SignatureZ Elements");
896         else
897                 b_constr.data = NULL;
898         int8_tArray* b_vals = (int8_tArray*) b.ptr;
899         for (size_t m = 0; m < b_constr.datalen; m++) {
900                 int8_tArray arr_conv_12 = b_vals[m];
901                 LDKSignature arr_conv_12_ref;
902                 CHECK(arr_conv_12.len == 64);
903                 memcpy(arr_conv_12_ref.compact_form, arr_conv_12.ptr, 64);
904                 b_constr.data[m] = arr_conv_12_ref;
905         }
906         ret->b = b_constr;
907         return (long)ret;
908 }
909 int8_tArray LDKC2Tuple_1SignatureCVec_1SignatureZZ_1get_1a(void* ctx_TODO, uint32_t ptr) {
910         LDKC2Tuple_SignatureCVec_SignatureZZ *tuple = (LDKC2Tuple_SignatureCVec_SignatureZZ*)ptr;
911         int8_tArray a_arr = { .len = 64, .ptr = MALLOC(64, "Native int8_tArray Bytes") };
912         memcpy(a_arr.ptr, tuple->a.compact_form, 64);
913         return a_arr;
914 }
915 ptrArray LDKC2Tuple_1SignatureCVec_1SignatureZZ_1get_1b(void* ctx_TODO, uint32_t ptr) {
916         LDKC2Tuple_SignatureCVec_SignatureZZ *tuple = (LDKC2Tuple_SignatureCVec_SignatureZZ*)ptr;
917         LDKCVec_SignatureZ b_var = tuple->b;
918         ptrArray b_arr = { .len = b_var.datalen, .ptr = MALLOC(b_var.datalen * sizeof(int32_t), "Native Object Bytes") };
919         int8_tArray *b_arr_ptr = (int8_tArray*)b_arr.ptr;
920         for (size_t m = 0; m < b_var.datalen; m++) {
921                 int8_tArray arr_conv_12_arr = { .len = 64, .ptr = MALLOC(64, "Native int8_tArray Bytes") };
922                 memcpy(arr_conv_12_arr.ptr, b_var.data[m].compact_form, 64);
923                 b_arr_ptr[m] = arr_conv_12_arr;
924         }
925         return b_arr;
926 }
927 jboolean LDKCResult_1C2Tuple_1SignatureCVec_1SignatureZZNoneZ_1result_1ok (void* ctx_TODO, uint32_t arg) {
928         return ((LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ*)arg)->result_ok;
929 }
930 uint32_t LDKCResult_1C2Tuple_1SignatureCVec_1SignatureZZNoneZ_1get_1ok (void* ctx_TODO, uint32_t arg) {
931         LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ *val = (LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ*)arg;
932         CHECK(val->result_ok);
933         long res_ref = (long)&(*val->contents.result);
934         return res_ref;
935 }
936 void LDKCResult_1C2Tuple_1SignatureCVec_1SignatureZZNoneZ_1get_1err (void* ctx_TODO, uint32_t arg) {
937         LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ *val = (LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ*)arg;
938         CHECK(!val->result_ok);
939         return *val->contents.err;
940 }
941 jboolean LDKCResult_1SignatureNoneZ_1result_1ok (void* ctx_TODO, uint32_t arg) {
942         return ((LDKCResult_SignatureNoneZ*)arg)->result_ok;
943 }
944 int8_tArray LDKCResult_1SignatureNoneZ_1get_1ok (void* ctx_TODO, uint32_t arg) {
945         LDKCResult_SignatureNoneZ *val = (LDKCResult_SignatureNoneZ*)arg;
946         CHECK(val->result_ok);
947         int8_tArray res_arr = { .len = 64, .ptr = MALLOC(64, "Native int8_tArray Bytes") };
948         memcpy(res_arr.ptr, (*val->contents.result).compact_form, 64);
949         return res_arr;
950 }
951 void LDKCResult_1SignatureNoneZ_1get_1err (void* ctx_TODO, uint32_t arg) {
952         LDKCResult_SignatureNoneZ *val = (LDKCResult_SignatureNoneZ*)arg;
953         CHECK(!val->result_ok);
954         return *val->contents.err;
955 }
956 jboolean LDKCResult_1CVec_1SignatureZNoneZ_1result_1ok (void* ctx_TODO, uint32_t arg) {
957         return ((LDKCResult_CVec_SignatureZNoneZ*)arg)->result_ok;
958 }
959 ptrArray LDKCResult_1CVec_1SignatureZNoneZ_1get_1ok (void* ctx_TODO, uint32_t arg) {
960         LDKCResult_CVec_SignatureZNoneZ *val = (LDKCResult_CVec_SignatureZNoneZ*)arg;
961         CHECK(val->result_ok);
962         LDKCVec_SignatureZ res_var = (*val->contents.result);
963         ptrArray res_arr = { .len = res_var.datalen, .ptr = MALLOC(res_var.datalen * sizeof(int32_t), "Native Object Bytes") };
964         int8_tArray *res_arr_ptr = (int8_tArray*)res_arr.ptr;
965         for (size_t m = 0; m < res_var.datalen; m++) {
966                 int8_tArray arr_conv_12_arr = { .len = 64, .ptr = MALLOC(64, "Native int8_tArray Bytes") };
967                 memcpy(arr_conv_12_arr.ptr, res_var.data[m].compact_form, 64);
968                 res_arr_ptr[m] = arr_conv_12_arr;
969         }
970         return res_arr;
971 }
972 void LDKCResult_1CVec_1SignatureZNoneZ_1get_1err (void* ctx_TODO, uint32_t arg) {
973         LDKCResult_CVec_SignatureZNoneZ *val = (LDKCResult_CVec_SignatureZNoneZ*)arg;
974         CHECK(!val->result_ok);
975         return *val->contents.err;
976 }
977 typedef struct LDKChannelKeys_JCalls {
978         atomic_size_t refcnt;
979         // TODO: Object pointer o;
980         // TODO: Some kind of method pointer get_per_commitment_point_meth;
981         // TODO: Some kind of method pointer release_commitment_secret_meth;
982         // TODO: Some kind of method pointer key_derivation_params_meth;
983         // TODO: Some kind of method pointer sign_counterparty_commitment_meth;
984         // TODO: Some kind of method pointer sign_holder_commitment_meth;
985         // TODO: Some kind of method pointer sign_holder_commitment_htlc_transactions_meth;
986         // TODO: Some kind of method pointer sign_justice_transaction_meth;
987         // TODO: Some kind of method pointer sign_counterparty_htlc_transaction_meth;
988         // TODO: Some kind of method pointer sign_closing_transaction_meth;
989         // TODO: Some kind of method pointer sign_channel_announcement_meth;
990         // TODO: Some kind of method pointer ready_channel_meth;
991         // TODO: Some kind of method pointer write_meth;
992 } LDKChannelKeys_JCalls;
993 static void LDKChannelKeys_JCalls_free(void* this_arg) {
994         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
995         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
996                 // TODO: do any release required for j_calls->o (refcnt-- in java, but may be redundant)
997                 FREE(j_calls);
998         }
999 }
1000 LDKPublicKey get_per_commitment_point_jcall(const void* this_arg, uint64_t idx) {
1001         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1002         //TODO: jobject obj = get object we can call against on j_calls->o
1003         int8_tArray arg; // TODO: Call get_per_commitment_point on j_calls with instance obj, returning an object, idx);
1004         LDKPublicKey arg_ref;
1005         CHECK(arg.len == 33);
1006         memcpy(arg_ref.compressed_form, arg.ptr, 33);
1007         return arg_ref;
1008 }
1009 LDKThirtyTwoBytes release_commitment_secret_jcall(const void* this_arg, uint64_t idx) {
1010         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1011         //TODO: jobject obj = get object we can call against on j_calls->o
1012         int8_tArray arg; // TODO: Call release_commitment_secret on j_calls with instance obj, returning an object, idx);
1013         LDKThirtyTwoBytes arg_ref;
1014         CHECK(arg.len == 32);
1015         memcpy(arg_ref.data, arg.ptr, 32);
1016         return arg_ref;
1017 }
1018 LDKC2Tuple_u64u64Z key_derivation_params_jcall(const void* this_arg) {
1019         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1020         //TODO: jobject obj = get object we can call against on j_calls->o
1021         LDKC2Tuple_u64u64Z* ret; // TODO: Call key_derivation_params on j_calls with instance obj, returning a pointer);
1022         LDKC2Tuple_u64u64Z ret_conv = *(LDKC2Tuple_u64u64Z*)ret;
1023         FREE((void*)ret);
1024         return ret_conv;
1025 }
1026 LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ sign_counterparty_commitment_jcall(const void* this_arg, const LDKCommitmentTransaction * commitment_tx) {
1027         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1028         LDKCommitmentTransaction commitment_tx_var = *commitment_tx;
1029         if (commitment_tx->inner != NULL)
1030                 commitment_tx_var = CommitmentTransaction_clone(commitment_tx);
1031         CHECK((((long)commitment_tx_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1032         CHECK((((long)&commitment_tx_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1033         long commitment_tx_ref = (long)commitment_tx_var.inner;
1034         if (commitment_tx_var.is_owned) {
1035                 commitment_tx_ref |= 1;
1036         }
1037         //TODO: jobject obj = get object we can call against on j_calls->o
1038         LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ* ret; // TODO: Call sign_counterparty_commitment on j_calls with instance obj, returning a pointer, commitment_tx_ref);
1039         LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ ret_conv = *(LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ*)ret;
1040         FREE((void*)ret);
1041         return ret_conv;
1042 }
1043 LDKCResult_SignatureNoneZ sign_holder_commitment_jcall(const void* this_arg, const LDKHolderCommitmentTransaction * commitment_tx) {
1044         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1045         LDKHolderCommitmentTransaction commitment_tx_var = *commitment_tx;
1046         if (commitment_tx->inner != NULL)
1047                 commitment_tx_var = HolderCommitmentTransaction_clone(commitment_tx);
1048         CHECK((((long)commitment_tx_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1049         CHECK((((long)&commitment_tx_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1050         long commitment_tx_ref = (long)commitment_tx_var.inner;
1051         if (commitment_tx_var.is_owned) {
1052                 commitment_tx_ref |= 1;
1053         }
1054         //TODO: jobject obj = get object we can call against on j_calls->o
1055         LDKCResult_SignatureNoneZ* ret; // TODO: Call sign_holder_commitment on j_calls with instance obj, returning a pointer, commitment_tx_ref);
1056         LDKCResult_SignatureNoneZ ret_conv = *(LDKCResult_SignatureNoneZ*)ret;
1057         FREE((void*)ret);
1058         return ret_conv;
1059 }
1060 LDKCResult_CVec_SignatureZNoneZ sign_holder_commitment_htlc_transactions_jcall(const void* this_arg, const LDKHolderCommitmentTransaction * commitment_tx) {
1061         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1062         LDKHolderCommitmentTransaction commitment_tx_var = *commitment_tx;
1063         if (commitment_tx->inner != NULL)
1064                 commitment_tx_var = HolderCommitmentTransaction_clone(commitment_tx);
1065         CHECK((((long)commitment_tx_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1066         CHECK((((long)&commitment_tx_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1067         long commitment_tx_ref = (long)commitment_tx_var.inner;
1068         if (commitment_tx_var.is_owned) {
1069                 commitment_tx_ref |= 1;
1070         }
1071         //TODO: jobject obj = get object we can call against on j_calls->o
1072         LDKCResult_CVec_SignatureZNoneZ* ret; // TODO: Call sign_holder_commitment_htlc_transactions on j_calls with instance obj, returning a pointer, commitment_tx_ref);
1073         LDKCResult_CVec_SignatureZNoneZ ret_conv = *(LDKCResult_CVec_SignatureZNoneZ*)ret;
1074         FREE((void*)ret);
1075         return ret_conv;
1076 }
1077 LDKCResult_SignatureNoneZ sign_justice_transaction_jcall(const void* this_arg, LDKTransaction justice_tx, uintptr_t input, uint64_t amount, const uint8_t (* per_commitment_key)[32], const LDKHTLCOutputInCommitment * htlc) {
1078         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1079         LDKTransaction justice_tx_var = justice_tx;
1080         int8_tArray justice_tx_arr = { .len = justice_tx_var.datalen, .ptr = MALLOC(justice_tx_var.datalen, "Native int8_tArray Bytes") };
1081         memcpy(justice_tx_arr.ptr, justice_tx_var.data, justice_tx_var.datalen);
1082         Transaction_free(justice_tx_var);
1083         int8_tArray per_commitment_key_arr = { .len = 32, .ptr = MALLOC(32, "Native int8_tArray Bytes") };
1084         memcpy(per_commitment_key_arr.ptr, *per_commitment_key, 32);
1085         LDKHTLCOutputInCommitment htlc_var = *htlc;
1086         if (htlc->inner != NULL)
1087                 htlc_var = HTLCOutputInCommitment_clone(htlc);
1088         CHECK((((long)htlc_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1089         CHECK((((long)&htlc_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1090         long htlc_ref = (long)htlc_var.inner;
1091         if (htlc_var.is_owned) {
1092                 htlc_ref |= 1;
1093         }
1094         //TODO: jobject obj = get object we can call against on j_calls->o
1095         LDKCResult_SignatureNoneZ* ret; // TODO: Call sign_justice_transaction on j_calls with instance obj, returning a pointer, justice_tx_arr, input, amount, per_commitment_key_arr, htlc_ref);
1096         LDKCResult_SignatureNoneZ ret_conv = *(LDKCResult_SignatureNoneZ*)ret;
1097         FREE((void*)ret);
1098         return ret_conv;
1099 }
1100 LDKCResult_SignatureNoneZ sign_counterparty_htlc_transaction_jcall(const void* this_arg, LDKTransaction htlc_tx, uintptr_t input, uint64_t amount, LDKPublicKey per_commitment_point, const LDKHTLCOutputInCommitment * htlc) {
1101         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1102         LDKTransaction htlc_tx_var = htlc_tx;
1103         int8_tArray htlc_tx_arr = { .len = htlc_tx_var.datalen, .ptr = MALLOC(htlc_tx_var.datalen, "Native int8_tArray Bytes") };
1104         memcpy(htlc_tx_arr.ptr, htlc_tx_var.data, htlc_tx_var.datalen);
1105         Transaction_free(htlc_tx_var);
1106         int8_tArray per_commitment_point_arr = { .len = 33, .ptr = MALLOC(33, "Native int8_tArray Bytes") };
1107         memcpy(per_commitment_point_arr.ptr, per_commitment_point.compressed_form, 33);
1108         LDKHTLCOutputInCommitment htlc_var = *htlc;
1109         if (htlc->inner != NULL)
1110                 htlc_var = HTLCOutputInCommitment_clone(htlc);
1111         CHECK((((long)htlc_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1112         CHECK((((long)&htlc_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1113         long htlc_ref = (long)htlc_var.inner;
1114         if (htlc_var.is_owned) {
1115                 htlc_ref |= 1;
1116         }
1117         //TODO: jobject obj = get object we can call against on j_calls->o
1118         LDKCResult_SignatureNoneZ* ret; // TODO: Call sign_counterparty_htlc_transaction on j_calls with instance obj, returning a pointer, htlc_tx_arr, input, amount, per_commitment_point_arr, htlc_ref);
1119         LDKCResult_SignatureNoneZ ret_conv = *(LDKCResult_SignatureNoneZ*)ret;
1120         FREE((void*)ret);
1121         return ret_conv;
1122 }
1123 LDKCResult_SignatureNoneZ sign_closing_transaction_jcall(const void* this_arg, LDKTransaction closing_tx) {
1124         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1125         LDKTransaction closing_tx_var = closing_tx;
1126         int8_tArray closing_tx_arr = { .len = closing_tx_var.datalen, .ptr = MALLOC(closing_tx_var.datalen, "Native int8_tArray Bytes") };
1127         memcpy(closing_tx_arr.ptr, closing_tx_var.data, closing_tx_var.datalen);
1128         Transaction_free(closing_tx_var);
1129         //TODO: jobject obj = get object we can call against on j_calls->o
1130         LDKCResult_SignatureNoneZ* ret; // TODO: Call sign_closing_transaction on j_calls with instance obj, returning a pointer, closing_tx_arr);
1131         LDKCResult_SignatureNoneZ ret_conv = *(LDKCResult_SignatureNoneZ*)ret;
1132         FREE((void*)ret);
1133         return ret_conv;
1134 }
1135 LDKCResult_SignatureNoneZ sign_channel_announcement_jcall(const void* this_arg, const LDKUnsignedChannelAnnouncement * msg) {
1136         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1137         LDKUnsignedChannelAnnouncement msg_var = *msg;
1138         if (msg->inner != NULL)
1139                 msg_var = UnsignedChannelAnnouncement_clone(msg);
1140         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1141         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1142         long msg_ref = (long)msg_var.inner;
1143         if (msg_var.is_owned) {
1144                 msg_ref |= 1;
1145         }
1146         //TODO: jobject obj = get object we can call against on j_calls->o
1147         LDKCResult_SignatureNoneZ* ret; // TODO: Call sign_channel_announcement on j_calls with instance obj, returning a pointer, msg_ref);
1148         LDKCResult_SignatureNoneZ ret_conv = *(LDKCResult_SignatureNoneZ*)ret;
1149         FREE((void*)ret);
1150         return ret_conv;
1151 }
1152 void ready_channel_jcall(void* this_arg, const LDKChannelTransactionParameters * channel_parameters) {
1153         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1154         LDKChannelTransactionParameters channel_parameters_var = *channel_parameters;
1155         if (channel_parameters->inner != NULL)
1156                 channel_parameters_var = ChannelTransactionParameters_clone(channel_parameters);
1157         CHECK((((long)channel_parameters_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1158         CHECK((((long)&channel_parameters_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1159         long channel_parameters_ref = (long)channel_parameters_var.inner;
1160         if (channel_parameters_var.is_owned) {
1161                 channel_parameters_ref |= 1;
1162         }
1163         //TODO: jobject obj = get object we can call against on j_calls->o
1164         return; //TODO: Call ready_channel on j_calls with instance obj, channel_parameters_ref);
1165 }
1166 LDKCVec_u8Z write_jcall(const void* this_arg) {
1167         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1168         //TODO: jobject obj = get object we can call against on j_calls->o
1169         int8_tArray arg; // TODO: Call write on j_calls with instance obj, returning an object);
1170         LDKCVec_u8Z arg_ref;
1171         arg_ref.datalen = arg.len;
1172         arg_ref.data = MALLOC(arg_ref.datalen, "LDKCVec_u8Z Bytes");
1173         memcpy(arg_ref.data, arg.ptr, arg_ref.datalen);
1174         return arg_ref;
1175 }
1176 static void* LDKChannelKeys_JCalls_clone(const void* this_arg) {
1177         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1178         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
1179         return (void*) this_arg;
1180 }
1181 static inline LDKChannelKeys LDKChannelKeys_init (void* ctx_TODO, /*TODO: JS Object Reference */void* o, uint32_t pubkeys) {
1182         LDKChannelKeys_JCalls *calls = MALLOC(sizeof(LDKChannelKeys_JCalls), "LDKChannelKeys_JCalls");
1183         atomic_init(&calls->refcnt, 1);
1184         //TODO: Assign calls->o from o
1185
1186         LDKChannelPublicKeys pubkeys_conv;
1187         pubkeys_conv.inner = (void*)(pubkeys & (~1));
1188         pubkeys_conv.is_owned = (pubkeys & 1) || (pubkeys == 0);
1189         if (pubkeys_conv.inner != NULL)
1190                 pubkeys_conv = ChannelPublicKeys_clone(&pubkeys_conv);
1191
1192         LDKChannelKeys ret = {
1193                 .this_arg = (void*) calls,
1194                 .get_per_commitment_point = get_per_commitment_point_jcall,
1195                 .release_commitment_secret = release_commitment_secret_jcall,
1196                 .key_derivation_params = key_derivation_params_jcall,
1197                 .sign_counterparty_commitment = sign_counterparty_commitment_jcall,
1198                 .sign_holder_commitment = sign_holder_commitment_jcall,
1199                 .sign_holder_commitment_htlc_transactions = sign_holder_commitment_htlc_transactions_jcall,
1200                 .sign_justice_transaction = sign_justice_transaction_jcall,
1201                 .sign_counterparty_htlc_transaction = sign_counterparty_htlc_transaction_jcall,
1202                 .sign_closing_transaction = sign_closing_transaction_jcall,
1203                 .sign_channel_announcement = sign_channel_announcement_jcall,
1204                 .ready_channel = ready_channel_jcall,
1205                 .clone = LDKChannelKeys_JCalls_clone,
1206                 .write = write_jcall,
1207                 .free = LDKChannelKeys_JCalls_free,
1208                 .pubkeys = pubkeys_conv,
1209                 .set_pubkeys = NULL,
1210         };
1211         return ret;
1212 }
1213 long LDKChannelKeys_1new (void* ctx_TODO, /*TODO: JS Object Reference */void* o, uint32_t pubkeys) {
1214         LDKChannelKeys *res_ptr = MALLOC(sizeof(LDKChannelKeys), "LDKChannelKeys");
1215         *res_ptr = LDKChannelKeys_init(NULL, o, pubkeys);
1216         return (long)res_ptr;
1217 }
1218 int8_tArray ChannelKeys_1get_1per_1commitment_1point(void* ctx_TODO, uint32_t this_arg, int64_t idx) {
1219         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
1220         int8_tArray arg_arr = { .len = 33, .ptr = MALLOC(33, "Native int8_tArray Bytes") };
1221         memcpy(arg_arr.ptr, (this_arg_conv->get_per_commitment_point)(this_arg_conv->this_arg, idx).compressed_form, 33);
1222         return arg_arr;
1223 }
1224
1225 int8_tArray ChannelKeys_1release_1commitment_1secret(void* ctx_TODO, uint32_t this_arg, int64_t idx) {
1226         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
1227         int8_tArray arg_arr = { .len = 32, .ptr = MALLOC(32, "Native int8_tArray Bytes") };
1228         memcpy(arg_arr.ptr, (this_arg_conv->release_commitment_secret)(this_arg_conv->this_arg, idx).data, 32);
1229         return arg_arr;
1230 }
1231
1232 uint32_t ChannelKeys_1key_1derivation_1params(void* ctx_TODO, uint32_t this_arg) {
1233         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
1234         LDKC2Tuple_u64u64Z* ret_ref = MALLOC(sizeof(LDKC2Tuple_u64u64Z), "LDKC2Tuple_u64u64Z");
1235         *ret_ref = (this_arg_conv->key_derivation_params)(this_arg_conv->this_arg);
1236         return (long)ret_ref;
1237 }
1238
1239 uint32_t ChannelKeys_1sign_1counterparty_1commitment(void* ctx_TODO, uint32_t this_arg, uint32_t commitment_tx) {
1240         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
1241         LDKCommitmentTransaction commitment_tx_conv;
1242         commitment_tx_conv.inner = (void*)(commitment_tx & (~1));
1243         commitment_tx_conv.is_owned = false;
1244         LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ), "LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ");
1245         *ret_conv = (this_arg_conv->sign_counterparty_commitment)(this_arg_conv->this_arg, &commitment_tx_conv);
1246         return (long)ret_conv;
1247 }
1248
1249 uint32_t ChannelKeys_1sign_1holder_1commitment(void* ctx_TODO, uint32_t this_arg, uint32_t commitment_tx) {
1250         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
1251         LDKHolderCommitmentTransaction commitment_tx_conv;
1252         commitment_tx_conv.inner = (void*)(commitment_tx & (~1));
1253         commitment_tx_conv.is_owned = false;
1254         LDKCResult_SignatureNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_SignatureNoneZ), "LDKCResult_SignatureNoneZ");
1255         *ret_conv = (this_arg_conv->sign_holder_commitment)(this_arg_conv->this_arg, &commitment_tx_conv);
1256         return (long)ret_conv;
1257 }
1258
1259 uint32_t ChannelKeys_1sign_1holder_1commitment_1htlc_1transactions(void* ctx_TODO, uint32_t this_arg, uint32_t commitment_tx) {
1260         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
1261         LDKHolderCommitmentTransaction commitment_tx_conv;
1262         commitment_tx_conv.inner = (void*)(commitment_tx & (~1));
1263         commitment_tx_conv.is_owned = false;
1264         LDKCResult_CVec_SignatureZNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_CVec_SignatureZNoneZ), "LDKCResult_CVec_SignatureZNoneZ");
1265         *ret_conv = (this_arg_conv->sign_holder_commitment_htlc_transactions)(this_arg_conv->this_arg, &commitment_tx_conv);
1266         return (long)ret_conv;
1267 }
1268
1269 uint32_t ChannelKeys_1sign_1justice_1transaction(void* ctx_TODO, uint32_t this_arg, int8_tArray justice_tx, intptr_t input, int64_t amount, int8_tArray per_commitment_key, uint32_t htlc) {
1270         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
1271         LDKTransaction justice_tx_ref;
1272         justice_tx_ref.datalen = justice_tx.len;
1273         justice_tx_ref.data = MALLOC(justice_tx_ref.datalen, "LDKTransaction Bytes");
1274         memcpy(justice_tx_ref.data, justice_tx.ptr, justice_tx_ref.datalen);
1275         justice_tx_ref.data_is_owned = true;
1276         unsigned char per_commitment_key_arr[32];
1277         CHECK(per_commitment_key.len == 32);
1278         memcpy(per_commitment_key_arr, per_commitment_key.ptr, 32);
1279         unsigned char (*per_commitment_key_ref)[32] = &per_commitment_key_arr;
1280         LDKHTLCOutputInCommitment htlc_conv;
1281         htlc_conv.inner = (void*)(htlc & (~1));
1282         htlc_conv.is_owned = false;
1283         LDKCResult_SignatureNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_SignatureNoneZ), "LDKCResult_SignatureNoneZ");
1284         *ret_conv = (this_arg_conv->sign_justice_transaction)(this_arg_conv->this_arg, justice_tx_ref, input, amount, per_commitment_key_ref, &htlc_conv);
1285         return (long)ret_conv;
1286 }
1287
1288 uint32_t ChannelKeys_1sign_1counterparty_1htlc_1transaction(void* ctx_TODO, uint32_t this_arg, int8_tArray htlc_tx, intptr_t input, int64_t amount, int8_tArray per_commitment_point, uint32_t htlc) {
1289         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
1290         LDKTransaction htlc_tx_ref;
1291         htlc_tx_ref.datalen = htlc_tx.len;
1292         htlc_tx_ref.data = MALLOC(htlc_tx_ref.datalen, "LDKTransaction Bytes");
1293         memcpy(htlc_tx_ref.data, htlc_tx.ptr, htlc_tx_ref.datalen);
1294         htlc_tx_ref.data_is_owned = true;
1295         LDKPublicKey per_commitment_point_ref;
1296         CHECK(per_commitment_point.len == 33);
1297         memcpy(per_commitment_point_ref.compressed_form, per_commitment_point.ptr, 33);
1298         LDKHTLCOutputInCommitment htlc_conv;
1299         htlc_conv.inner = (void*)(htlc & (~1));
1300         htlc_conv.is_owned = false;
1301         LDKCResult_SignatureNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_SignatureNoneZ), "LDKCResult_SignatureNoneZ");
1302         *ret_conv = (this_arg_conv->sign_counterparty_htlc_transaction)(this_arg_conv->this_arg, htlc_tx_ref, input, amount, per_commitment_point_ref, &htlc_conv);
1303         return (long)ret_conv;
1304 }
1305
1306 uint32_t ChannelKeys_1sign_1closing_1transaction(void* ctx_TODO, uint32_t this_arg, int8_tArray closing_tx) {
1307         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
1308         LDKTransaction closing_tx_ref;
1309         closing_tx_ref.datalen = closing_tx.len;
1310         closing_tx_ref.data = MALLOC(closing_tx_ref.datalen, "LDKTransaction Bytes");
1311         memcpy(closing_tx_ref.data, closing_tx.ptr, closing_tx_ref.datalen);
1312         closing_tx_ref.data_is_owned = true;
1313         LDKCResult_SignatureNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_SignatureNoneZ), "LDKCResult_SignatureNoneZ");
1314         *ret_conv = (this_arg_conv->sign_closing_transaction)(this_arg_conv->this_arg, closing_tx_ref);
1315         return (long)ret_conv;
1316 }
1317
1318 uint32_t ChannelKeys_1sign_1channel_1announcement(void* ctx_TODO, uint32_t this_arg, uint32_t msg) {
1319         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
1320         LDKUnsignedChannelAnnouncement msg_conv;
1321         msg_conv.inner = (void*)(msg & (~1));
1322         msg_conv.is_owned = false;
1323         LDKCResult_SignatureNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_SignatureNoneZ), "LDKCResult_SignatureNoneZ");
1324         *ret_conv = (this_arg_conv->sign_channel_announcement)(this_arg_conv->this_arg, &msg_conv);
1325         return (long)ret_conv;
1326 }
1327
1328 void ChannelKeys_1ready_1channel(void* ctx_TODO, uint32_t this_arg, uint32_t channel_parameters) {
1329         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
1330         LDKChannelTransactionParameters channel_parameters_conv;
1331         channel_parameters_conv.inner = (void*)(channel_parameters & (~1));
1332         channel_parameters_conv.is_owned = false;
1333         (this_arg_conv->ready_channel)(this_arg_conv->this_arg, &channel_parameters_conv);
1334 }
1335
1336 int8_tArray ChannelKeys_1write(void* ctx_TODO, uint32_t this_arg) {
1337         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
1338         LDKCVec_u8Z arg_var = (this_arg_conv->write)(this_arg_conv->this_arg);
1339         int8_tArray arg_arr = { .len = arg_var.datalen, .ptr = MALLOC(arg_var.datalen, "Native int8_tArray Bytes") };
1340         memcpy(arg_arr.ptr, arg_var.data, arg_var.datalen);
1341         CVec_u8Z_free(arg_var);
1342         return arg_arr;
1343 }
1344
1345 LDKChannelPublicKeys LDKChannelKeys_set_get_pubkeys(LDKChannelKeys* this_arg) {
1346         if (this_arg->set_pubkeys != NULL)
1347                 this_arg->set_pubkeys(this_arg);
1348         return this_arg->pubkeys;
1349 }
1350 uint32_t ChannelKeys_1get_1pubkeys(void* ctx_TODO, uint32_t this_arg) {
1351         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
1352         LDKChannelPublicKeys ret_var = LDKChannelKeys_set_get_pubkeys(this_arg_conv);
1353         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1354         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1355         long ret_ref = (long)ret_var.inner;
1356         if (ret_var.is_owned) {
1357                 ret_ref |= 1;
1358         }
1359         return ret_ref;
1360 }
1361
1362 uint32_t LDKC2Tuple_1BlockHashChannelMonitorZ_1new(void* ctx_TODO, int8_tArray a, uint32_t b) {
1363         LDKC2Tuple_BlockHashChannelMonitorZ* ret = MALLOC(sizeof(LDKC2Tuple_BlockHashChannelMonitorZ), "LDKC2Tuple_BlockHashChannelMonitorZ");
1364         LDKThirtyTwoBytes a_ref;
1365         CHECK(a.len == 32);
1366         memcpy(a_ref.data, a.ptr, 32);
1367         ret->a = a_ref;
1368         LDKChannelMonitor b_conv;
1369         b_conv.inner = (void*)(b & (~1));
1370         b_conv.is_owned = (b & 1) || (b == 0);
1371         // Warning: we may need a move here but can't clone!
1372         ret->b = b_conv;
1373         return (long)ret;
1374 }
1375 int8_tArray LDKC2Tuple_1BlockHashChannelMonitorZ_1get_1a(void* ctx_TODO, uint32_t ptr) {
1376         LDKC2Tuple_BlockHashChannelMonitorZ *tuple = (LDKC2Tuple_BlockHashChannelMonitorZ*)ptr;
1377         int8_tArray a_arr = { .len = 32, .ptr = MALLOC(32, "Native int8_tArray Bytes") };
1378         memcpy(a_arr.ptr, tuple->a.data, 32);
1379         return a_arr;
1380 }
1381 uint32_t LDKC2Tuple_1BlockHashChannelMonitorZ_1get_1b(void* ctx_TODO, uint32_t ptr) {
1382         LDKC2Tuple_BlockHashChannelMonitorZ *tuple = (LDKC2Tuple_BlockHashChannelMonitorZ*)ptr;
1383         LDKChannelMonitor b_var = tuple->b;
1384         CHECK((((long)b_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1385         CHECK((((long)&b_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1386         long b_ref = (long)b_var.inner & ~1;
1387         return b_ref;
1388 }
1389 jboolean LDKCResult_1C2Tuple_1BlockHashChannelMonitorZDecodeErrorZ_1result_1ok (void* ctx_TODO, uint32_t arg) {
1390         return ((LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ*)arg)->result_ok;
1391 }
1392 uint32_t LDKCResult_1C2Tuple_1BlockHashChannelMonitorZDecodeErrorZ_1get_1ok (void* ctx_TODO, uint32_t arg) {
1393         LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ *val = (LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ*)arg;
1394         CHECK(val->result_ok);
1395         long res_ref = (long)&(*val->contents.result);
1396         return res_ref;
1397 }
1398 uint32_t LDKCResult_1C2Tuple_1BlockHashChannelMonitorZDecodeErrorZ_1get_1err (void* ctx_TODO, uint32_t arg) {
1399         LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ *val = (LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ*)arg;
1400         CHECK(!val->result_ok);
1401         LDKDecodeError err_var = (*val->contents.err);
1402         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1403         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1404         long err_ref = (long)err_var.inner & ~1;
1405         return err_ref;
1406 }
1407 jboolean LDKCResult_1SpendableOutputDescriptorDecodeErrorZ_1result_1ok (void* ctx_TODO, uint32_t arg) {
1408         return ((LDKCResult_SpendableOutputDescriptorDecodeErrorZ*)arg)->result_ok;
1409 }
1410 uint32_t LDKCResult_1SpendableOutputDescriptorDecodeErrorZ_1get_1ok (void* ctx_TODO, uint32_t arg) {
1411         LDKCResult_SpendableOutputDescriptorDecodeErrorZ *val = (LDKCResult_SpendableOutputDescriptorDecodeErrorZ*)arg;
1412         CHECK(val->result_ok);
1413         long res_ref = (long)&(*val->contents.result);
1414         return res_ref;
1415 }
1416 uint32_t LDKCResult_1SpendableOutputDescriptorDecodeErrorZ_1get_1err (void* ctx_TODO, uint32_t arg) {
1417         LDKCResult_SpendableOutputDescriptorDecodeErrorZ *val = (LDKCResult_SpendableOutputDescriptorDecodeErrorZ*)arg;
1418         CHECK(!val->result_ok);
1419         LDKDecodeError err_var = (*val->contents.err);
1420         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1421         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1422         long err_ref = (long)err_var.inner & ~1;
1423         return err_ref;
1424 }
1425 jboolean LDKCResult_1ChanKeySignerDecodeErrorZ_1result_1ok (void* ctx_TODO, uint32_t arg) {
1426         return ((LDKCResult_ChanKeySignerDecodeErrorZ*)arg)->result_ok;
1427 }
1428 uint32_t LDKCResult_1ChanKeySignerDecodeErrorZ_1get_1ok (void* ctx_TODO, uint32_t arg) {
1429         LDKCResult_ChanKeySignerDecodeErrorZ *val = (LDKCResult_ChanKeySignerDecodeErrorZ*)arg;
1430         CHECK(val->result_ok);
1431         LDKChannelKeys* ret = MALLOC(sizeof(LDKChannelKeys), "LDKChannelKeys");
1432         *ret = (*val->contents.result);
1433         return (long)ret;
1434 }
1435 uint32_t LDKCResult_1ChanKeySignerDecodeErrorZ_1get_1err (void* ctx_TODO, uint32_t arg) {
1436         LDKCResult_ChanKeySignerDecodeErrorZ *val = (LDKCResult_ChanKeySignerDecodeErrorZ*)arg;
1437         CHECK(!val->result_ok);
1438         LDKDecodeError err_var = (*val->contents.err);
1439         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1440         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1441         long err_ref = (long)err_var.inner & ~1;
1442         return err_ref;
1443 }
1444 jboolean LDKCResult_1InMemoryChannelKeysDecodeErrorZ_1result_1ok (void* ctx_TODO, uint32_t arg) {
1445         return ((LDKCResult_InMemoryChannelKeysDecodeErrorZ*)arg)->result_ok;
1446 }
1447 uint32_t LDKCResult_1InMemoryChannelKeysDecodeErrorZ_1get_1ok (void* ctx_TODO, uint32_t arg) {
1448         LDKCResult_InMemoryChannelKeysDecodeErrorZ *val = (LDKCResult_InMemoryChannelKeysDecodeErrorZ*)arg;
1449         CHECK(val->result_ok);
1450         LDKInMemoryChannelKeys res_var = (*val->contents.result);
1451         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1452         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1453         long res_ref = (long)res_var.inner & ~1;
1454         return res_ref;
1455 }
1456 uint32_t LDKCResult_1InMemoryChannelKeysDecodeErrorZ_1get_1err (void* ctx_TODO, uint32_t arg) {
1457         LDKCResult_InMemoryChannelKeysDecodeErrorZ *val = (LDKCResult_InMemoryChannelKeysDecodeErrorZ*)arg;
1458         CHECK(!val->result_ok);
1459         LDKDecodeError err_var = (*val->contents.err);
1460         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1461         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1462         long err_ref = (long)err_var.inner & ~1;
1463         return err_ref;
1464 }
1465 jboolean LDKCResult_1TxOutAccessErrorZ_1result_1ok (void* ctx_TODO, uint32_t arg) {
1466         return ((LDKCResult_TxOutAccessErrorZ*)arg)->result_ok;
1467 }
1468 uint32_t LDKCResult_1TxOutAccessErrorZ_1get_1ok (void* ctx_TODO, uint32_t arg) {
1469         LDKCResult_TxOutAccessErrorZ *val = (LDKCResult_TxOutAccessErrorZ*)arg;
1470         CHECK(val->result_ok);
1471         long res_ref = (long)&(*val->contents.result);
1472         return (long)res_ref;
1473 }
1474 uint32_t LDKCResult_1TxOutAccessErrorZ_1get_1err (void* ctx_TODO, uint32_t arg) {
1475         LDKCResult_TxOutAccessErrorZ *val = (LDKCResult_TxOutAccessErrorZ*)arg;
1476         CHECK(!val->result_ok);
1477         uint32_t err_conv = LDKAccessError_to_js((*val->contents.err));
1478         return err_conv;
1479 }
1480 uint32_t LDKAPIError_1ref_1from_1ptr (void* ctx_TODO, uint32_t ptr) {
1481         LDKAPIError *obj = (LDKAPIError*)ptr;
1482         switch(obj->tag) {
1483                 case LDKAPIError_APIMisuseError: {
1484                         LDKCVec_u8Z err_var = obj->api_misuse_error.err;
1485                         int8_tArray err_arr = { .len = err_var.datalen, .ptr = MALLOC(err_var.datalen, "Native int8_tArray Bytes") };
1486                         memcpy(err_arr.ptr, err_var.data, err_var.datalen);
1487                         return 0 /* LDKAPIError - APIMisuseError */; (void) err_arr;
1488                 }
1489                 case LDKAPIError_FeeRateTooHigh: {
1490                         LDKCVec_u8Z err_var = obj->fee_rate_too_high.err;
1491                         int8_tArray err_arr = { .len = err_var.datalen, .ptr = MALLOC(err_var.datalen, "Native int8_tArray Bytes") };
1492                         memcpy(err_arr.ptr, err_var.data, err_var.datalen);
1493                         return 0 /* LDKAPIError - FeeRateTooHigh */; (void) err_arr; (void) obj->fee_rate_too_high.feerate;
1494                 }
1495                 case LDKAPIError_RouteError: {
1496                         LDKStr err_str = obj->route_error.err;
1497                         char* err_buf = MALLOC(err_str.len + 1, "str conv buf");
1498                         memcpy(err_buf, err_str.chars, err_str.len);
1499                         err_buf[err_str.len] = 0;
1500                         jstring err_conv = conv_owned_string(err_str.chars);
1501                         FREE(err_buf);
1502                         return 0 /* LDKAPIError - RouteError */; (void) err_conv;
1503                 }
1504                 case LDKAPIError_ChannelUnavailable: {
1505                         LDKCVec_u8Z err_var = obj->channel_unavailable.err;
1506                         int8_tArray err_arr = { .len = err_var.datalen, .ptr = MALLOC(err_var.datalen, "Native int8_tArray Bytes") };
1507                         memcpy(err_arr.ptr, err_var.data, err_var.datalen);
1508                         return 0 /* LDKAPIError - ChannelUnavailable */; (void) err_arr;
1509                 }
1510                 case LDKAPIError_MonitorUpdateFailed: {
1511                         return 0 /* LDKAPIError - MonitorUpdateFailed */;
1512                 }
1513                 default: abort();
1514         }
1515 }
1516 jboolean LDKCResult_1NoneAPIErrorZ_1result_1ok (void* ctx_TODO, uint32_t arg) {
1517         return ((LDKCResult_NoneAPIErrorZ*)arg)->result_ok;
1518 }
1519 void LDKCResult_1NoneAPIErrorZ_1get_1ok (void* ctx_TODO, uint32_t arg) {
1520         LDKCResult_NoneAPIErrorZ *val = (LDKCResult_NoneAPIErrorZ*)arg;
1521         CHECK(val->result_ok);
1522         return *val->contents.result;
1523 }
1524 uint32_t LDKCResult_1NoneAPIErrorZ_1get_1err (void* ctx_TODO, uint32_t arg) {
1525         LDKCResult_NoneAPIErrorZ *val = (LDKCResult_NoneAPIErrorZ*)arg;
1526         CHECK(!val->result_ok);
1527         long err_ref = (long)&(*val->contents.err);
1528         return err_ref;
1529 }
1530 static inline LDKCResult_NoneAPIErrorZ CResult_NoneAPIErrorZ_clone(const LDKCResult_NoneAPIErrorZ *orig) {
1531         LDKCResult_NoneAPIErrorZ res = { .result_ok = orig->result_ok };
1532         if (orig->result_ok) {
1533                 res.contents.result = NULL;
1534         } else {
1535                 LDKAPIError* contents = MALLOC(sizeof(LDKAPIError), "LDKAPIError result Err clone");
1536                 *contents = APIError_clone(orig->contents.err);
1537                 res.contents.err = contents;
1538         }
1539         return res;
1540 }
1541 uint32_t LDKCVec_1ChannelDetailsZ_1new(void* ctx_TODO, uint32_tArray elems) {
1542         LDKCVec_ChannelDetailsZ *ret = MALLOC(sizeof(LDKCVec_ChannelDetailsZ), "LDKCVec_ChannelDetailsZ");
1543         ret->datalen = elems.len;
1544         if (ret->datalen == 0) {
1545                 ret->data = NULL;
1546         } else {
1547                 ret->data = MALLOC(sizeof(LDKChannelDetails) * ret->datalen, "LDKCVec_ChannelDetailsZ Data");
1548                 uint32_t *java_elems = (uint32_t*)elems.ptr;
1549                 for (size_t i = 0; i < ret->datalen; i++) {
1550                         uint32_t arr_elem = java_elems[i];
1551                         LDKChannelDetails arr_elem_conv;
1552                         arr_elem_conv.inner = (void*)(arr_elem & (~1));
1553                         arr_elem_conv.is_owned = (arr_elem & 1) || (arr_elem == 0);
1554                         if (arr_elem_conv.inner != NULL)
1555                                 arr_elem_conv = ChannelDetails_clone(&arr_elem_conv);
1556                         ret->data[i] = arr_elem_conv;
1557                 }
1558         }
1559         return (long)ret;
1560 }
1561 static inline LDKCVec_ChannelDetailsZ CVec_ChannelDetailsZ_clone(const LDKCVec_ChannelDetailsZ *orig) {
1562         LDKCVec_ChannelDetailsZ ret = { .data = MALLOC(sizeof(LDKChannelDetails) * orig->datalen, "LDKCVec_ChannelDetailsZ clone bytes"), .datalen = orig->datalen };
1563         for (size_t i = 0; i < ret.datalen; i++) {
1564                 ret.data[i] = ChannelDetails_clone(&orig->data[i]);
1565         }
1566         return ret;
1567 }
1568 jboolean LDKCResult_1NonePaymentSendFailureZ_1result_1ok (void* ctx_TODO, uint32_t arg) {
1569         return ((LDKCResult_NonePaymentSendFailureZ*)arg)->result_ok;
1570 }
1571 void LDKCResult_1NonePaymentSendFailureZ_1get_1ok (void* ctx_TODO, uint32_t arg) {
1572         LDKCResult_NonePaymentSendFailureZ *val = (LDKCResult_NonePaymentSendFailureZ*)arg;
1573         CHECK(val->result_ok);
1574         return *val->contents.result;
1575 }
1576 uint32_t LDKCResult_1NonePaymentSendFailureZ_1get_1err (void* ctx_TODO, uint32_t arg) {
1577         LDKCResult_NonePaymentSendFailureZ *val = (LDKCResult_NonePaymentSendFailureZ*)arg;
1578         CHECK(!val->result_ok);
1579         LDKPaymentSendFailure err_var = (*val->contents.err);
1580         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1581         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1582         long err_ref = (long)err_var.inner & ~1;
1583         return err_ref;
1584 }
1585 uint32_t LDKNetAddress_1ref_1from_1ptr (void* ctx_TODO, uint32_t ptr) {
1586         LDKNetAddress *obj = (LDKNetAddress*)ptr;
1587         switch(obj->tag) {
1588                 case LDKNetAddress_IPv4: {
1589                         int8_tArray addr_arr = { .len = 4, .ptr = MALLOC(4, "Native int8_tArray Bytes") };
1590                         memcpy(addr_arr.ptr, obj->i_pv4.addr.data, 4);
1591                         return 0 /* LDKNetAddress - IPv4 */; (void) addr_arr; (void) obj->i_pv4.port;
1592                 }
1593                 case LDKNetAddress_IPv6: {
1594                         int8_tArray addr_arr = { .len = 16, .ptr = MALLOC(16, "Native int8_tArray Bytes") };
1595                         memcpy(addr_arr.ptr, obj->i_pv6.addr.data, 16);
1596                         return 0 /* LDKNetAddress - IPv6 */; (void) addr_arr; (void) obj->i_pv6.port;
1597                 }
1598                 case LDKNetAddress_OnionV2: {
1599                         int8_tArray addr_arr = { .len = 10, .ptr = MALLOC(10, "Native int8_tArray Bytes") };
1600                         memcpy(addr_arr.ptr, obj->onion_v2.addr.data, 10);
1601                         return 0 /* LDKNetAddress - OnionV2 */; (void) addr_arr; (void) obj->onion_v2.port;
1602                 }
1603                 case LDKNetAddress_OnionV3: {
1604                         int8_tArray ed25519_pubkey_arr = { .len = 32, .ptr = MALLOC(32, "Native int8_tArray Bytes") };
1605                         memcpy(ed25519_pubkey_arr.ptr, obj->onion_v3.ed25519_pubkey.data, 32);
1606                         return 0 /* LDKNetAddress - OnionV3 */; (void) ed25519_pubkey_arr; (void) obj->onion_v3.checksum; (void) obj->onion_v3.version; (void) obj->onion_v3.port;
1607                 }
1608                 default: abort();
1609         }
1610 }
1611 uint32_t LDKCVec_1NetAddressZ_1new(void* ctx_TODO, uint32_tArray elems) {
1612         LDKCVec_NetAddressZ *ret = MALLOC(sizeof(LDKCVec_NetAddressZ), "LDKCVec_NetAddressZ");
1613         ret->datalen = elems.len;
1614         if (ret->datalen == 0) {
1615                 ret->data = NULL;
1616         } else {
1617                 ret->data = MALLOC(sizeof(LDKNetAddress) * ret->datalen, "LDKCVec_NetAddressZ Data");
1618                 uint32_t *java_elems = (uint32_t*)elems.ptr;
1619                 for (size_t i = 0; i < ret->datalen; i++) {
1620                         uint32_t arr_elem = java_elems[i];
1621                         LDKNetAddress arr_elem_conv = *(LDKNetAddress*)arr_elem;
1622                         FREE((void*)arr_elem);
1623                         ret->data[i] = arr_elem_conv;
1624                 }
1625         }
1626         return (long)ret;
1627 }
1628 static inline LDKCVec_NetAddressZ CVec_NetAddressZ_clone(const LDKCVec_NetAddressZ *orig) {
1629         LDKCVec_NetAddressZ ret = { .data = MALLOC(sizeof(LDKNetAddress) * orig->datalen, "LDKCVec_NetAddressZ clone bytes"), .datalen = orig->datalen };
1630         for (size_t i = 0; i < ret.datalen; i++) {
1631                 ret.data[i] = NetAddress_clone(&orig->data[i]);
1632         }
1633         return ret;
1634 }
1635 uint32_t LDKCVec_1ChannelMonitorZ_1new(void* ctx_TODO, uint32_tArray elems) {
1636         LDKCVec_ChannelMonitorZ *ret = MALLOC(sizeof(LDKCVec_ChannelMonitorZ), "LDKCVec_ChannelMonitorZ");
1637         ret->datalen = elems.len;
1638         if (ret->datalen == 0) {
1639                 ret->data = NULL;
1640         } else {
1641                 ret->data = MALLOC(sizeof(LDKChannelMonitor) * ret->datalen, "LDKCVec_ChannelMonitorZ Data");
1642                 uint32_t *java_elems = (uint32_t*)elems.ptr;
1643                 for (size_t i = 0; i < ret->datalen; i++) {
1644                         uint32_t arr_elem = java_elems[i];
1645                         LDKChannelMonitor arr_elem_conv;
1646                         arr_elem_conv.inner = (void*)(arr_elem & (~1));
1647                         arr_elem_conv.is_owned = (arr_elem & 1) || (arr_elem == 0);
1648                         // Warning: we may need a move here but can't clone!
1649                         ret->data[i] = arr_elem_conv;
1650                 }
1651         }
1652         return (long)ret;
1653 }
1654 typedef struct LDKWatch_JCalls {
1655         atomic_size_t refcnt;
1656         // TODO: Object pointer o;
1657         // TODO: Some kind of method pointer watch_channel_meth;
1658         // TODO: Some kind of method pointer update_channel_meth;
1659         // TODO: Some kind of method pointer release_pending_monitor_events_meth;
1660 } LDKWatch_JCalls;
1661 static void LDKWatch_JCalls_free(void* this_arg) {
1662         LDKWatch_JCalls *j_calls = (LDKWatch_JCalls*) this_arg;
1663         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
1664                 // TODO: do any release required for j_calls->o (refcnt-- in java, but may be redundant)
1665                 FREE(j_calls);
1666         }
1667 }
1668 LDKCResult_NoneChannelMonitorUpdateErrZ watch_channel_jcall(const void* this_arg, LDKOutPoint funding_txo, LDKChannelMonitor monitor) {
1669         LDKWatch_JCalls *j_calls = (LDKWatch_JCalls*) this_arg;
1670         LDKOutPoint funding_txo_var = funding_txo;
1671         CHECK((((long)funding_txo_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1672         CHECK((((long)&funding_txo_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1673         long funding_txo_ref = (long)funding_txo_var.inner;
1674         if (funding_txo_var.is_owned) {
1675                 funding_txo_ref |= 1;
1676         }
1677         LDKChannelMonitor monitor_var = monitor;
1678         CHECK((((long)monitor_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1679         CHECK((((long)&monitor_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1680         long monitor_ref = (long)monitor_var.inner;
1681         if (monitor_var.is_owned) {
1682                 monitor_ref |= 1;
1683         }
1684         //TODO: jobject obj = get object we can call against on j_calls->o
1685         LDKCResult_NoneChannelMonitorUpdateErrZ* ret; // TODO: Call watch_channel on j_calls with instance obj, returning a pointer, funding_txo_ref, monitor_ref);
1686         LDKCResult_NoneChannelMonitorUpdateErrZ ret_conv = *(LDKCResult_NoneChannelMonitorUpdateErrZ*)ret;
1687         FREE((void*)ret);
1688         return ret_conv;
1689 }
1690 LDKCResult_NoneChannelMonitorUpdateErrZ update_channel_jcall(const void* this_arg, LDKOutPoint funding_txo, LDKChannelMonitorUpdate update) {
1691         LDKWatch_JCalls *j_calls = (LDKWatch_JCalls*) this_arg;
1692         LDKOutPoint funding_txo_var = funding_txo;
1693         CHECK((((long)funding_txo_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1694         CHECK((((long)&funding_txo_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1695         long funding_txo_ref = (long)funding_txo_var.inner;
1696         if (funding_txo_var.is_owned) {
1697                 funding_txo_ref |= 1;
1698         }
1699         LDKChannelMonitorUpdate update_var = update;
1700         CHECK((((long)update_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1701         CHECK((((long)&update_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1702         long update_ref = (long)update_var.inner;
1703         if (update_var.is_owned) {
1704                 update_ref |= 1;
1705         }
1706         //TODO: jobject obj = get object we can call against on j_calls->o
1707         LDKCResult_NoneChannelMonitorUpdateErrZ* ret; // TODO: Call update_channel on j_calls with instance obj, returning a pointer, funding_txo_ref, update_ref);
1708         LDKCResult_NoneChannelMonitorUpdateErrZ ret_conv = *(LDKCResult_NoneChannelMonitorUpdateErrZ*)ret;
1709         FREE((void*)ret);
1710         return ret_conv;
1711 }
1712 LDKCVec_MonitorEventZ release_pending_monitor_events_jcall(const void* this_arg) {
1713         LDKWatch_JCalls *j_calls = (LDKWatch_JCalls*) this_arg;
1714         //TODO: jobject obj = get object we can call against on j_calls->o
1715         uint32_tArray arg; // TODO: Call release_pending_monitor_events on j_calls with instance obj, returning an object);
1716         LDKCVec_MonitorEventZ arg_constr;
1717         arg_constr.datalen = arg.len;
1718         if (arg_constr.datalen > 0)
1719                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKMonitorEvent), "LDKCVec_MonitorEventZ Elements");
1720         else
1721                 arg_constr.data = NULL;
1722         uint32_t* arg_vals = (uint32_t*) arg.ptr;
1723         for (size_t o = 0; o < arg_constr.datalen; o++) {
1724                 uint32_t arr_conv_14 = arg_vals[o];
1725                 LDKMonitorEvent arr_conv_14_conv;
1726                 arr_conv_14_conv.inner = (void*)(arr_conv_14 & (~1));
1727                 arr_conv_14_conv.is_owned = (arr_conv_14 & 1) || (arr_conv_14 == 0);
1728                 if (arr_conv_14_conv.inner != NULL)
1729                         arr_conv_14_conv = MonitorEvent_clone(&arr_conv_14_conv);
1730                 arg_constr.data[o] = arr_conv_14_conv;
1731         }
1732         return arg_constr;
1733 }
1734 static void* LDKWatch_JCalls_clone(const void* this_arg) {
1735         LDKWatch_JCalls *j_calls = (LDKWatch_JCalls*) this_arg;
1736         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
1737         return (void*) this_arg;
1738 }
1739 static inline LDKWatch LDKWatch_init (void* ctx_TODO, /*TODO: JS Object Reference */void* o) {
1740         LDKWatch_JCalls *calls = MALLOC(sizeof(LDKWatch_JCalls), "LDKWatch_JCalls");
1741         atomic_init(&calls->refcnt, 1);
1742         //TODO: Assign calls->o from o
1743
1744         LDKWatch ret = {
1745                 .this_arg = (void*) calls,
1746                 .watch_channel = watch_channel_jcall,
1747                 .update_channel = update_channel_jcall,
1748                 .release_pending_monitor_events = release_pending_monitor_events_jcall,
1749                 .free = LDKWatch_JCalls_free,
1750         };
1751         return ret;
1752 }
1753 long LDKWatch_1new (void* ctx_TODO, /*TODO: JS Object Reference */void* o) {
1754         LDKWatch *res_ptr = MALLOC(sizeof(LDKWatch), "LDKWatch");
1755         *res_ptr = LDKWatch_init(NULL, o);
1756         return (long)res_ptr;
1757 }
1758 uint32_t Watch_1watch_1channel(void* ctx_TODO, uint32_t this_arg, uint32_t funding_txo, uint32_t monitor) {
1759         LDKWatch* this_arg_conv = (LDKWatch*)this_arg;
1760         LDKOutPoint funding_txo_conv;
1761         funding_txo_conv.inner = (void*)(funding_txo & (~1));
1762         funding_txo_conv.is_owned = (funding_txo & 1) || (funding_txo == 0);
1763         if (funding_txo_conv.inner != NULL)
1764                 funding_txo_conv = OutPoint_clone(&funding_txo_conv);
1765         LDKChannelMonitor monitor_conv;
1766         monitor_conv.inner = (void*)(monitor & (~1));
1767         monitor_conv.is_owned = (monitor & 1) || (monitor == 0);
1768         // Warning: we may need a move here but can't clone!
1769         LDKCResult_NoneChannelMonitorUpdateErrZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneChannelMonitorUpdateErrZ), "LDKCResult_NoneChannelMonitorUpdateErrZ");
1770         *ret_conv = (this_arg_conv->watch_channel)(this_arg_conv->this_arg, funding_txo_conv, monitor_conv);
1771         return (long)ret_conv;
1772 }
1773
1774 uint32_t Watch_1update_1channel(void* ctx_TODO, uint32_t this_arg, uint32_t funding_txo, uint32_t update) {
1775         LDKWatch* this_arg_conv = (LDKWatch*)this_arg;
1776         LDKOutPoint funding_txo_conv;
1777         funding_txo_conv.inner = (void*)(funding_txo & (~1));
1778         funding_txo_conv.is_owned = (funding_txo & 1) || (funding_txo == 0);
1779         if (funding_txo_conv.inner != NULL)
1780                 funding_txo_conv = OutPoint_clone(&funding_txo_conv);
1781         LDKChannelMonitorUpdate update_conv;
1782         update_conv.inner = (void*)(update & (~1));
1783         update_conv.is_owned = (update & 1) || (update == 0);
1784         if (update_conv.inner != NULL)
1785                 update_conv = ChannelMonitorUpdate_clone(&update_conv);
1786         LDKCResult_NoneChannelMonitorUpdateErrZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneChannelMonitorUpdateErrZ), "LDKCResult_NoneChannelMonitorUpdateErrZ");
1787         *ret_conv = (this_arg_conv->update_channel)(this_arg_conv->this_arg, funding_txo_conv, update_conv);
1788         return (long)ret_conv;
1789 }
1790
1791 uint32_tArray Watch_1release_1pending_1monitor_1events(void* ctx_TODO, uint32_t this_arg) {
1792         LDKWatch* this_arg_conv = (LDKWatch*)this_arg;
1793         LDKCVec_MonitorEventZ ret_var = (this_arg_conv->release_pending_monitor_events)(this_arg_conv->this_arg);
1794         uint32_tArray ret_arr = { .len = ret_var.datalen, .ptr = MALLOC(ret_var.datalen * sizeof(int32_t), "Native uint32_tArray Bytes") };
1795         uint32_t *ret_arr_ptr = (uint32_t*)ret_arr.ptr;
1796         for (size_t o = 0; o < ret_var.datalen; o++) {
1797                 LDKMonitorEvent arr_conv_14_var = ret_var.data[o];
1798                 CHECK((((long)arr_conv_14_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1799                 CHECK((((long)&arr_conv_14_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1800                 long arr_conv_14_ref = (long)arr_conv_14_var.inner;
1801                 if (arr_conv_14_var.is_owned) {
1802                         arr_conv_14_ref |= 1;
1803                 }
1804                 ret_arr_ptr[o] = arr_conv_14_ref;
1805         }
1806         FREE(ret_var.data);
1807         return ret_arr;
1808 }
1809
1810 typedef struct LDKBroadcasterInterface_JCalls {
1811         atomic_size_t refcnt;
1812         // TODO: Object pointer o;
1813         // TODO: Some kind of method pointer broadcast_transaction_meth;
1814 } LDKBroadcasterInterface_JCalls;
1815 static void LDKBroadcasterInterface_JCalls_free(void* this_arg) {
1816         LDKBroadcasterInterface_JCalls *j_calls = (LDKBroadcasterInterface_JCalls*) this_arg;
1817         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
1818                 // TODO: do any release required for j_calls->o (refcnt-- in java, but may be redundant)
1819                 FREE(j_calls);
1820         }
1821 }
1822 void broadcast_transaction_jcall(const void* this_arg, LDKTransaction tx) {
1823         LDKBroadcasterInterface_JCalls *j_calls = (LDKBroadcasterInterface_JCalls*) this_arg;
1824         LDKTransaction tx_var = tx;
1825         int8_tArray tx_arr = { .len = tx_var.datalen, .ptr = MALLOC(tx_var.datalen, "Native int8_tArray Bytes") };
1826         memcpy(tx_arr.ptr, tx_var.data, tx_var.datalen);
1827         Transaction_free(tx_var);
1828         //TODO: jobject obj = get object we can call against on j_calls->o
1829         return; //TODO: Call broadcast_transaction on j_calls with instance obj, tx_arr);
1830 }
1831 static void* LDKBroadcasterInterface_JCalls_clone(const void* this_arg) {
1832         LDKBroadcasterInterface_JCalls *j_calls = (LDKBroadcasterInterface_JCalls*) this_arg;
1833         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
1834         return (void*) this_arg;
1835 }
1836 static inline LDKBroadcasterInterface LDKBroadcasterInterface_init (void* ctx_TODO, /*TODO: JS Object Reference */void* o) {
1837         LDKBroadcasterInterface_JCalls *calls = MALLOC(sizeof(LDKBroadcasterInterface_JCalls), "LDKBroadcasterInterface_JCalls");
1838         atomic_init(&calls->refcnt, 1);
1839         //TODO: Assign calls->o from o
1840
1841         LDKBroadcasterInterface ret = {
1842                 .this_arg = (void*) calls,
1843                 .broadcast_transaction = broadcast_transaction_jcall,
1844                 .free = LDKBroadcasterInterface_JCalls_free,
1845         };
1846         return ret;
1847 }
1848 long LDKBroadcasterInterface_1new (void* ctx_TODO, /*TODO: JS Object Reference */void* o) {
1849         LDKBroadcasterInterface *res_ptr = MALLOC(sizeof(LDKBroadcasterInterface), "LDKBroadcasterInterface");
1850         *res_ptr = LDKBroadcasterInterface_init(NULL, o);
1851         return (long)res_ptr;
1852 }
1853 void BroadcasterInterface_1broadcast_1transaction(void* ctx_TODO, uint32_t this_arg, int8_tArray tx) {
1854         LDKBroadcasterInterface* this_arg_conv = (LDKBroadcasterInterface*)this_arg;
1855         LDKTransaction tx_ref;
1856         tx_ref.datalen = tx.len;
1857         tx_ref.data = MALLOC(tx_ref.datalen, "LDKTransaction Bytes");
1858         memcpy(tx_ref.data, tx.ptr, tx_ref.datalen);
1859         tx_ref.data_is_owned = true;
1860         (this_arg_conv->broadcast_transaction)(this_arg_conv->this_arg, tx_ref);
1861 }
1862
1863 typedef struct LDKKeysInterface_JCalls {
1864         atomic_size_t refcnt;
1865         // TODO: Object pointer o;
1866         // TODO: Some kind of method pointer get_node_secret_meth;
1867         // TODO: Some kind of method pointer get_destination_script_meth;
1868         // TODO: Some kind of method pointer get_shutdown_pubkey_meth;
1869         // TODO: Some kind of method pointer get_channel_keys_meth;
1870         // TODO: Some kind of method pointer get_secure_random_bytes_meth;
1871         // TODO: Some kind of method pointer read_chan_signer_meth;
1872 } LDKKeysInterface_JCalls;
1873 static void LDKKeysInterface_JCalls_free(void* this_arg) {
1874         LDKKeysInterface_JCalls *j_calls = (LDKKeysInterface_JCalls*) this_arg;
1875         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
1876                 // TODO: do any release required for j_calls->o (refcnt-- in java, but may be redundant)
1877                 FREE(j_calls);
1878         }
1879 }
1880 LDKSecretKey get_node_secret_jcall(const void* this_arg) {
1881         LDKKeysInterface_JCalls *j_calls = (LDKKeysInterface_JCalls*) this_arg;
1882         //TODO: jobject obj = get object we can call against on j_calls->o
1883         int8_tArray arg; // TODO: Call get_node_secret on j_calls with instance obj, returning an object);
1884         LDKSecretKey arg_ref;
1885         CHECK(arg.len == 32);
1886         memcpy(arg_ref.bytes, arg.ptr, 32);
1887         return arg_ref;
1888 }
1889 LDKCVec_u8Z get_destination_script_jcall(const void* this_arg) {
1890         LDKKeysInterface_JCalls *j_calls = (LDKKeysInterface_JCalls*) this_arg;
1891         //TODO: jobject obj = get object we can call against on j_calls->o
1892         int8_tArray arg; // TODO: Call get_destination_script on j_calls with instance obj, returning an object);
1893         LDKCVec_u8Z arg_ref;
1894         arg_ref.datalen = arg.len;
1895         arg_ref.data = MALLOC(arg_ref.datalen, "LDKCVec_u8Z Bytes");
1896         memcpy(arg_ref.data, arg.ptr, arg_ref.datalen);
1897         return arg_ref;
1898 }
1899 LDKPublicKey get_shutdown_pubkey_jcall(const void* this_arg) {
1900         LDKKeysInterface_JCalls *j_calls = (LDKKeysInterface_JCalls*) this_arg;
1901         //TODO: jobject obj = get object we can call against on j_calls->o
1902         int8_tArray arg; // TODO: Call get_shutdown_pubkey on j_calls with instance obj, returning an object);
1903         LDKPublicKey arg_ref;
1904         CHECK(arg.len == 33);
1905         memcpy(arg_ref.compressed_form, arg.ptr, 33);
1906         return arg_ref;
1907 }
1908 LDKChannelKeys get_channel_keys_jcall(const void* this_arg, bool inbound, uint64_t channel_value_satoshis) {
1909         LDKKeysInterface_JCalls *j_calls = (LDKKeysInterface_JCalls*) this_arg;
1910         //TODO: jobject obj = get object we can call against on j_calls->o
1911         LDKChannelKeys* ret; // TODO: Call get_channel_keys on j_calls with instance obj, returning a pointer, inbound, channel_value_satoshis);
1912         LDKChannelKeys ret_conv = *(LDKChannelKeys*)ret;
1913         ret_conv = ChannelKeys_clone(ret);
1914         return ret_conv;
1915 }
1916 LDKThirtyTwoBytes get_secure_random_bytes_jcall(const void* this_arg) {
1917         LDKKeysInterface_JCalls *j_calls = (LDKKeysInterface_JCalls*) this_arg;
1918         //TODO: jobject obj = get object we can call against on j_calls->o
1919         int8_tArray arg; // TODO: Call get_secure_random_bytes on j_calls with instance obj, returning an object);
1920         LDKThirtyTwoBytes arg_ref;
1921         CHECK(arg.len == 32);
1922         memcpy(arg_ref.data, arg.ptr, 32);
1923         return arg_ref;
1924 }
1925 LDKCResult_ChanKeySignerDecodeErrorZ read_chan_signer_jcall(const void* this_arg, LDKu8slice reader) {
1926         LDKKeysInterface_JCalls *j_calls = (LDKKeysInterface_JCalls*) this_arg;
1927         LDKu8slice reader_var = reader;
1928         int8_tArray reader_arr = { .len = reader_var.datalen, .ptr = MALLOC(reader_var.datalen, "Native int8_tArray Bytes") };
1929         memcpy(reader_arr.ptr, reader_var.data, reader_var.datalen);
1930         //TODO: jobject obj = get object we can call against on j_calls->o
1931         LDKCResult_ChanKeySignerDecodeErrorZ* ret; // TODO: Call read_chan_signer on j_calls with instance obj, returning a pointer, reader_arr);
1932         LDKCResult_ChanKeySignerDecodeErrorZ ret_conv = *(LDKCResult_ChanKeySignerDecodeErrorZ*)ret;
1933         FREE((void*)ret);
1934         return ret_conv;
1935 }
1936 static void* LDKKeysInterface_JCalls_clone(const void* this_arg) {
1937         LDKKeysInterface_JCalls *j_calls = (LDKKeysInterface_JCalls*) this_arg;
1938         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
1939         return (void*) this_arg;
1940 }
1941 static inline LDKKeysInterface LDKKeysInterface_init (void* ctx_TODO, /*TODO: JS Object Reference */void* o) {
1942         LDKKeysInterface_JCalls *calls = MALLOC(sizeof(LDKKeysInterface_JCalls), "LDKKeysInterface_JCalls");
1943         atomic_init(&calls->refcnt, 1);
1944         //TODO: Assign calls->o from o
1945
1946         LDKKeysInterface ret = {
1947                 .this_arg = (void*) calls,
1948                 .get_node_secret = get_node_secret_jcall,
1949                 .get_destination_script = get_destination_script_jcall,
1950                 .get_shutdown_pubkey = get_shutdown_pubkey_jcall,
1951                 .get_channel_keys = get_channel_keys_jcall,
1952                 .get_secure_random_bytes = get_secure_random_bytes_jcall,
1953                 .read_chan_signer = read_chan_signer_jcall,
1954                 .free = LDKKeysInterface_JCalls_free,
1955         };
1956         return ret;
1957 }
1958 long LDKKeysInterface_1new (void* ctx_TODO, /*TODO: JS Object Reference */void* o) {
1959         LDKKeysInterface *res_ptr = MALLOC(sizeof(LDKKeysInterface), "LDKKeysInterface");
1960         *res_ptr = LDKKeysInterface_init(NULL, o);
1961         return (long)res_ptr;
1962 }
1963 int8_tArray KeysInterface_1get_1node_1secret(void* ctx_TODO, uint32_t this_arg) {
1964         LDKKeysInterface* this_arg_conv = (LDKKeysInterface*)this_arg;
1965         int8_tArray arg_arr = { .len = 32, .ptr = MALLOC(32, "Native int8_tArray Bytes") };
1966         memcpy(arg_arr.ptr, (this_arg_conv->get_node_secret)(this_arg_conv->this_arg).bytes, 32);
1967         return arg_arr;
1968 }
1969
1970 int8_tArray KeysInterface_1get_1destination_1script(void* ctx_TODO, uint32_t this_arg) {
1971         LDKKeysInterface* this_arg_conv = (LDKKeysInterface*)this_arg;
1972         LDKCVec_u8Z arg_var = (this_arg_conv->get_destination_script)(this_arg_conv->this_arg);
1973         int8_tArray arg_arr = { .len = arg_var.datalen, .ptr = MALLOC(arg_var.datalen, "Native int8_tArray Bytes") };
1974         memcpy(arg_arr.ptr, arg_var.data, arg_var.datalen);
1975         CVec_u8Z_free(arg_var);
1976         return arg_arr;
1977 }
1978
1979 int8_tArray KeysInterface_1get_1shutdown_1pubkey(void* ctx_TODO, uint32_t this_arg) {
1980         LDKKeysInterface* this_arg_conv = (LDKKeysInterface*)this_arg;
1981         int8_tArray arg_arr = { .len = 33, .ptr = MALLOC(33, "Native int8_tArray Bytes") };
1982         memcpy(arg_arr.ptr, (this_arg_conv->get_shutdown_pubkey)(this_arg_conv->this_arg).compressed_form, 33);
1983         return arg_arr;
1984 }
1985
1986 uint32_t KeysInterface_1get_1channel_1keys(void* ctx_TODO, uint32_t this_arg, jboolean inbound, int64_t channel_value_satoshis) {
1987         LDKKeysInterface* this_arg_conv = (LDKKeysInterface*)this_arg;
1988         LDKChannelKeys* ret = MALLOC(sizeof(LDKChannelKeys), "LDKChannelKeys");
1989         *ret = (this_arg_conv->get_channel_keys)(this_arg_conv->this_arg, inbound, channel_value_satoshis);
1990         return (long)ret;
1991 }
1992
1993 int8_tArray KeysInterface_1get_1secure_1random_1bytes(void* ctx_TODO, uint32_t this_arg) {
1994         LDKKeysInterface* this_arg_conv = (LDKKeysInterface*)this_arg;
1995         int8_tArray arg_arr = { .len = 32, .ptr = MALLOC(32, "Native int8_tArray Bytes") };
1996         memcpy(arg_arr.ptr, (this_arg_conv->get_secure_random_bytes)(this_arg_conv->this_arg).data, 32);
1997         return arg_arr;
1998 }
1999
2000 uint32_t KeysInterface_1read_1chan_1signer(void* ctx_TODO, uint32_t this_arg, int8_tArray reader) {
2001         LDKKeysInterface* this_arg_conv = (LDKKeysInterface*)this_arg;
2002         LDKu8slice reader_ref;
2003         reader_ref.datalen = reader.len;
2004         reader_ref.data = reader.ptr;
2005         LDKCResult_ChanKeySignerDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ChanKeySignerDecodeErrorZ), "LDKCResult_ChanKeySignerDecodeErrorZ");
2006         *ret_conv = (this_arg_conv->read_chan_signer)(this_arg_conv->this_arg, reader_ref);
2007         return (long)ret_conv;
2008 }
2009
2010 typedef struct LDKFeeEstimator_JCalls {
2011         atomic_size_t refcnt;
2012         // TODO: Object pointer o;
2013         // TODO: Some kind of method pointer get_est_sat_per_1000_weight_meth;
2014 } LDKFeeEstimator_JCalls;
2015 static void LDKFeeEstimator_JCalls_free(void* this_arg) {
2016         LDKFeeEstimator_JCalls *j_calls = (LDKFeeEstimator_JCalls*) this_arg;
2017         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
2018                 // TODO: do any release required for j_calls->o (refcnt-- in java, but may be redundant)
2019                 FREE(j_calls);
2020         }
2021 }
2022 uint32_t get_est_sat_per_1000_weight_jcall(const void* this_arg, LDKConfirmationTarget confirmation_target) {
2023         LDKFeeEstimator_JCalls *j_calls = (LDKFeeEstimator_JCalls*) this_arg;
2024         uint32_t confirmation_target_conv = LDKConfirmationTarget_to_js(confirmation_target);
2025         //TODO: jobject obj = get object we can call against on j_calls->o
2026         return 0; //TODO: Call get_est_sat_per_1000_weight on j_calls with instance obj, returning number, confirmation_target_conv);
2027 }
2028 static void* LDKFeeEstimator_JCalls_clone(const void* this_arg) {
2029         LDKFeeEstimator_JCalls *j_calls = (LDKFeeEstimator_JCalls*) this_arg;
2030         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
2031         return (void*) this_arg;
2032 }
2033 static inline LDKFeeEstimator LDKFeeEstimator_init (void* ctx_TODO, /*TODO: JS Object Reference */void* o) {
2034         LDKFeeEstimator_JCalls *calls = MALLOC(sizeof(LDKFeeEstimator_JCalls), "LDKFeeEstimator_JCalls");
2035         atomic_init(&calls->refcnt, 1);
2036         //TODO: Assign calls->o from o
2037
2038         LDKFeeEstimator ret = {
2039                 .this_arg = (void*) calls,
2040                 .get_est_sat_per_1000_weight = get_est_sat_per_1000_weight_jcall,
2041                 .free = LDKFeeEstimator_JCalls_free,
2042         };
2043         return ret;
2044 }
2045 long LDKFeeEstimator_1new (void* ctx_TODO, /*TODO: JS Object Reference */void* o) {
2046         LDKFeeEstimator *res_ptr = MALLOC(sizeof(LDKFeeEstimator), "LDKFeeEstimator");
2047         *res_ptr = LDKFeeEstimator_init(NULL, o);
2048         return (long)res_ptr;
2049 }
2050 int32_t FeeEstimator_1get_1est_1sat_1per_11000_1weight(void* ctx_TODO, uint32_t this_arg, uint32_t confirmation_target) {
2051         LDKFeeEstimator* this_arg_conv = (LDKFeeEstimator*)this_arg;
2052         LDKConfirmationTarget confirmation_target_conv = LDKConfirmationTarget_from_js(confirmation_target);
2053         int32_t ret_val = (this_arg_conv->get_est_sat_per_1000_weight)(this_arg_conv->this_arg, confirmation_target_conv);
2054         return ret_val;
2055 }
2056
2057 typedef struct LDKLogger_JCalls {
2058         atomic_size_t refcnt;
2059         // TODO: Object pointer o;
2060         // TODO: Some kind of method pointer log_meth;
2061 } LDKLogger_JCalls;
2062 static void LDKLogger_JCalls_free(void* this_arg) {
2063         LDKLogger_JCalls *j_calls = (LDKLogger_JCalls*) this_arg;
2064         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
2065                 // TODO: do any release required for j_calls->o (refcnt-- in java, but may be redundant)
2066                 FREE(j_calls);
2067         }
2068 }
2069 void log_jcall(const void* this_arg, const char* record) {
2070         LDKLogger_JCalls *j_calls = (LDKLogger_JCalls*) this_arg;
2071         jstring record_conv = conv_owned_string(record);
2072         //TODO: jobject obj = get object we can call against on j_calls->o
2073         return; //TODO: Call log on j_calls with instance obj, record_conv);
2074 }
2075 static void* LDKLogger_JCalls_clone(const void* this_arg) {
2076         LDKLogger_JCalls *j_calls = (LDKLogger_JCalls*) this_arg;
2077         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
2078         return (void*) this_arg;
2079 }
2080 static inline LDKLogger LDKLogger_init (void* ctx_TODO, /*TODO: JS Object Reference */void* o) {
2081         LDKLogger_JCalls *calls = MALLOC(sizeof(LDKLogger_JCalls), "LDKLogger_JCalls");
2082         atomic_init(&calls->refcnt, 1);
2083         //TODO: Assign calls->o from o
2084
2085         LDKLogger ret = {
2086                 .this_arg = (void*) calls,
2087                 .log = log_jcall,
2088                 .free = LDKLogger_JCalls_free,
2089         };
2090         return ret;
2091 }
2092 long LDKLogger_1new (void* ctx_TODO, /*TODO: JS Object Reference */void* o) {
2093         LDKLogger *res_ptr = MALLOC(sizeof(LDKLogger), "LDKLogger");
2094         *res_ptr = LDKLogger_init(NULL, o);
2095         return (long)res_ptr;
2096 }
2097 uint32_t LDKC2Tuple_1BlockHashChannelManagerZ_1new(void* ctx_TODO, int8_tArray a, uint32_t b) {
2098         LDKC2Tuple_BlockHashChannelManagerZ* ret = MALLOC(sizeof(LDKC2Tuple_BlockHashChannelManagerZ), "LDKC2Tuple_BlockHashChannelManagerZ");
2099         LDKThirtyTwoBytes a_ref;
2100         CHECK(a.len == 32);
2101         memcpy(a_ref.data, a.ptr, 32);
2102         ret->a = a_ref;
2103         LDKChannelManager b_conv;
2104         b_conv.inner = (void*)(b & (~1));
2105         b_conv.is_owned = (b & 1) || (b == 0);
2106         // Warning: we may need a move here but can't clone!
2107         ret->b = b_conv;
2108         return (long)ret;
2109 }
2110 int8_tArray LDKC2Tuple_1BlockHashChannelManagerZ_1get_1a(void* ctx_TODO, uint32_t ptr) {
2111         LDKC2Tuple_BlockHashChannelManagerZ *tuple = (LDKC2Tuple_BlockHashChannelManagerZ*)ptr;
2112         int8_tArray a_arr = { .len = 32, .ptr = MALLOC(32, "Native int8_tArray Bytes") };
2113         memcpy(a_arr.ptr, tuple->a.data, 32);
2114         return a_arr;
2115 }
2116 uint32_t LDKC2Tuple_1BlockHashChannelManagerZ_1get_1b(void* ctx_TODO, uint32_t ptr) {
2117         LDKC2Tuple_BlockHashChannelManagerZ *tuple = (LDKC2Tuple_BlockHashChannelManagerZ*)ptr;
2118         LDKChannelManager b_var = tuple->b;
2119         CHECK((((long)b_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2120         CHECK((((long)&b_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2121         long b_ref = (long)b_var.inner & ~1;
2122         return b_ref;
2123 }
2124 jboolean LDKCResult_1C2Tuple_1BlockHashChannelManagerZDecodeErrorZ_1result_1ok (void* ctx_TODO, uint32_t arg) {
2125         return ((LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ*)arg)->result_ok;
2126 }
2127 uint32_t LDKCResult_1C2Tuple_1BlockHashChannelManagerZDecodeErrorZ_1get_1ok (void* ctx_TODO, uint32_t arg) {
2128         LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ *val = (LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ*)arg;
2129         CHECK(val->result_ok);
2130         long res_ref = (long)&(*val->contents.result);
2131         return res_ref;
2132 }
2133 uint32_t LDKCResult_1C2Tuple_1BlockHashChannelManagerZDecodeErrorZ_1get_1err (void* ctx_TODO, uint32_t arg) {
2134         LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ *val = (LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ*)arg;
2135         CHECK(!val->result_ok);
2136         LDKDecodeError err_var = (*val->contents.err);
2137         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2138         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2139         long err_ref = (long)err_var.inner & ~1;
2140         return err_ref;
2141 }
2142 jboolean LDKCResult_1NetAddressu8Z_1result_1ok (void* ctx_TODO, uint32_t arg) {
2143         return ((LDKCResult_NetAddressu8Z*)arg)->result_ok;
2144 }
2145 uint32_t LDKCResult_1NetAddressu8Z_1get_1ok (void* ctx_TODO, uint32_t arg) {
2146         LDKCResult_NetAddressu8Z *val = (LDKCResult_NetAddressu8Z*)arg;
2147         CHECK(val->result_ok);
2148         long res_ref = (long)&(*val->contents.result);
2149         return res_ref;
2150 }
2151 int8_t LDKCResult_1NetAddressu8Z_1get_1err (void* ctx_TODO, uint32_t arg) {
2152         LDKCResult_NetAddressu8Z *val = (LDKCResult_NetAddressu8Z*)arg;
2153         CHECK(!val->result_ok);
2154         return *val->contents.err;
2155 }
2156 static inline LDKCResult_NetAddressu8Z CResult_NetAddressu8Z_clone(const LDKCResult_NetAddressu8Z *orig) {
2157         LDKCResult_NetAddressu8Z res = { .result_ok = orig->result_ok };
2158         if (orig->result_ok) {
2159                 LDKNetAddress* contents = MALLOC(sizeof(LDKNetAddress), "LDKNetAddress result OK clone");
2160                 *contents = NetAddress_clone(orig->contents.result);
2161                 res.contents.result = contents;
2162         } else {
2163                 int8_t* contents = MALLOC(sizeof(int8_t), "int8_t result Err clone");
2164                 *contents = *orig->contents.err;
2165                 res.contents.err = contents;
2166         }
2167         return res;
2168 }
2169 jboolean LDKCResult_1CResult_1NetAddressu8ZDecodeErrorZ_1result_1ok (void* ctx_TODO, uint32_t arg) {
2170         return ((LDKCResult_CResult_NetAddressu8ZDecodeErrorZ*)arg)->result_ok;
2171 }
2172 uint32_t LDKCResult_1CResult_1NetAddressu8ZDecodeErrorZ_1get_1ok (void* ctx_TODO, uint32_t arg) {
2173         LDKCResult_CResult_NetAddressu8ZDecodeErrorZ *val = (LDKCResult_CResult_NetAddressu8ZDecodeErrorZ*)arg;
2174         CHECK(val->result_ok);
2175         LDKCResult_NetAddressu8Z* res_conv = MALLOC(sizeof(LDKCResult_NetAddressu8Z), "LDKCResult_NetAddressu8Z");
2176         *res_conv = (*val->contents.result);
2177         *res_conv = CResult_NetAddressu8Z_clone(res_conv);
2178         return (long)res_conv;
2179 }
2180 uint32_t LDKCResult_1CResult_1NetAddressu8ZDecodeErrorZ_1get_1err (void* ctx_TODO, uint32_t arg) {
2181         LDKCResult_CResult_NetAddressu8ZDecodeErrorZ *val = (LDKCResult_CResult_NetAddressu8ZDecodeErrorZ*)arg;
2182         CHECK(!val->result_ok);
2183         LDKDecodeError err_var = (*val->contents.err);
2184         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2185         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2186         long err_ref = (long)err_var.inner & ~1;
2187         return err_ref;
2188 }
2189 uint32_t LDKCVec_1u64Z_1new(void* ctx_TODO, int64_tArray elems) {
2190         LDKCVec_u64Z *ret = MALLOC(sizeof(LDKCVec_u64Z), "LDKCVec_u64Z");
2191         ret->datalen = elems.len;
2192         if (ret->datalen == 0) {
2193                 ret->data = NULL;
2194         } else {
2195                 ret->data = MALLOC(sizeof(uint64_t) * ret->datalen, "LDKCVec_u64Z Data");
2196                 int64_t *java_elems = (int64_t*)elems.ptr;
2197                 for (size_t i = 0; i < ret->datalen; i++) {
2198                         ret->data[i] = java_elems[i];
2199                 }
2200         }
2201         return (long)ret;
2202 }
2203 static inline LDKCVec_u64Z CVec_u64Z_clone(const LDKCVec_u64Z *orig) {
2204         LDKCVec_u64Z ret = { .data = MALLOC(sizeof(int64_t) * orig->datalen, "LDKCVec_u64Z clone bytes"), .datalen = orig->datalen };
2205         memcpy(ret.data, orig->data, sizeof(int64_t) * ret.datalen);
2206         return ret;
2207 }
2208 uint32_t LDKCVec_1UpdateAddHTLCZ_1new(void* ctx_TODO, uint32_tArray elems) {
2209         LDKCVec_UpdateAddHTLCZ *ret = MALLOC(sizeof(LDKCVec_UpdateAddHTLCZ), "LDKCVec_UpdateAddHTLCZ");
2210         ret->datalen = elems.len;
2211         if (ret->datalen == 0) {
2212                 ret->data = NULL;
2213         } else {
2214                 ret->data = MALLOC(sizeof(LDKUpdateAddHTLC) * ret->datalen, "LDKCVec_UpdateAddHTLCZ Data");
2215                 uint32_t *java_elems = (uint32_t*)elems.ptr;
2216                 for (size_t i = 0; i < ret->datalen; i++) {
2217                         uint32_t arr_elem = java_elems[i];
2218                         LDKUpdateAddHTLC arr_elem_conv;
2219                         arr_elem_conv.inner = (void*)(arr_elem & (~1));
2220                         arr_elem_conv.is_owned = (arr_elem & 1) || (arr_elem == 0);
2221                         if (arr_elem_conv.inner != NULL)
2222                                 arr_elem_conv = UpdateAddHTLC_clone(&arr_elem_conv);
2223                         ret->data[i] = arr_elem_conv;
2224                 }
2225         }
2226         return (long)ret;
2227 }
2228 static inline LDKCVec_UpdateAddHTLCZ CVec_UpdateAddHTLCZ_clone(const LDKCVec_UpdateAddHTLCZ *orig) {
2229         LDKCVec_UpdateAddHTLCZ ret = { .data = MALLOC(sizeof(LDKUpdateAddHTLC) * orig->datalen, "LDKCVec_UpdateAddHTLCZ clone bytes"), .datalen = orig->datalen };
2230         for (size_t i = 0; i < ret.datalen; i++) {
2231                 ret.data[i] = UpdateAddHTLC_clone(&orig->data[i]);
2232         }
2233         return ret;
2234 }
2235 uint32_t LDKCVec_1UpdateFulfillHTLCZ_1new(void* ctx_TODO, uint32_tArray elems) {
2236         LDKCVec_UpdateFulfillHTLCZ *ret = MALLOC(sizeof(LDKCVec_UpdateFulfillHTLCZ), "LDKCVec_UpdateFulfillHTLCZ");
2237         ret->datalen = elems.len;
2238         if (ret->datalen == 0) {
2239                 ret->data = NULL;
2240         } else {
2241                 ret->data = MALLOC(sizeof(LDKUpdateFulfillHTLC) * ret->datalen, "LDKCVec_UpdateFulfillHTLCZ Data");
2242                 uint32_t *java_elems = (uint32_t*)elems.ptr;
2243                 for (size_t i = 0; i < ret->datalen; i++) {
2244                         uint32_t arr_elem = java_elems[i];
2245                         LDKUpdateFulfillHTLC arr_elem_conv;
2246                         arr_elem_conv.inner = (void*)(arr_elem & (~1));
2247                         arr_elem_conv.is_owned = (arr_elem & 1) || (arr_elem == 0);
2248                         if (arr_elem_conv.inner != NULL)
2249                                 arr_elem_conv = UpdateFulfillHTLC_clone(&arr_elem_conv);
2250                         ret->data[i] = arr_elem_conv;
2251                 }
2252         }
2253         return (long)ret;
2254 }
2255 static inline LDKCVec_UpdateFulfillHTLCZ CVec_UpdateFulfillHTLCZ_clone(const LDKCVec_UpdateFulfillHTLCZ *orig) {
2256         LDKCVec_UpdateFulfillHTLCZ ret = { .data = MALLOC(sizeof(LDKUpdateFulfillHTLC) * orig->datalen, "LDKCVec_UpdateFulfillHTLCZ clone bytes"), .datalen = orig->datalen };
2257         for (size_t i = 0; i < ret.datalen; i++) {
2258                 ret.data[i] = UpdateFulfillHTLC_clone(&orig->data[i]);
2259         }
2260         return ret;
2261 }
2262 uint32_t LDKCVec_1UpdateFailHTLCZ_1new(void* ctx_TODO, uint32_tArray elems) {
2263         LDKCVec_UpdateFailHTLCZ *ret = MALLOC(sizeof(LDKCVec_UpdateFailHTLCZ), "LDKCVec_UpdateFailHTLCZ");
2264         ret->datalen = elems.len;
2265         if (ret->datalen == 0) {
2266                 ret->data = NULL;
2267         } else {
2268                 ret->data = MALLOC(sizeof(LDKUpdateFailHTLC) * ret->datalen, "LDKCVec_UpdateFailHTLCZ Data");
2269                 uint32_t *java_elems = (uint32_t*)elems.ptr;
2270                 for (size_t i = 0; i < ret->datalen; i++) {
2271                         uint32_t arr_elem = java_elems[i];
2272                         LDKUpdateFailHTLC arr_elem_conv;
2273                         arr_elem_conv.inner = (void*)(arr_elem & (~1));
2274                         arr_elem_conv.is_owned = (arr_elem & 1) || (arr_elem == 0);
2275                         if (arr_elem_conv.inner != NULL)
2276                                 arr_elem_conv = UpdateFailHTLC_clone(&arr_elem_conv);
2277                         ret->data[i] = arr_elem_conv;
2278                 }
2279         }
2280         return (long)ret;
2281 }
2282 static inline LDKCVec_UpdateFailHTLCZ CVec_UpdateFailHTLCZ_clone(const LDKCVec_UpdateFailHTLCZ *orig) {
2283         LDKCVec_UpdateFailHTLCZ ret = { .data = MALLOC(sizeof(LDKUpdateFailHTLC) * orig->datalen, "LDKCVec_UpdateFailHTLCZ clone bytes"), .datalen = orig->datalen };
2284         for (size_t i = 0; i < ret.datalen; i++) {
2285                 ret.data[i] = UpdateFailHTLC_clone(&orig->data[i]);
2286         }
2287         return ret;
2288 }
2289 uint32_t LDKCVec_1UpdateFailMalformedHTLCZ_1new(void* ctx_TODO, uint32_tArray elems) {
2290         LDKCVec_UpdateFailMalformedHTLCZ *ret = MALLOC(sizeof(LDKCVec_UpdateFailMalformedHTLCZ), "LDKCVec_UpdateFailMalformedHTLCZ");
2291         ret->datalen = elems.len;
2292         if (ret->datalen == 0) {
2293                 ret->data = NULL;
2294         } else {
2295                 ret->data = MALLOC(sizeof(LDKUpdateFailMalformedHTLC) * ret->datalen, "LDKCVec_UpdateFailMalformedHTLCZ Data");
2296                 uint32_t *java_elems = (uint32_t*)elems.ptr;
2297                 for (size_t i = 0; i < ret->datalen; i++) {
2298                         uint32_t arr_elem = java_elems[i];
2299                         LDKUpdateFailMalformedHTLC arr_elem_conv;
2300                         arr_elem_conv.inner = (void*)(arr_elem & (~1));
2301                         arr_elem_conv.is_owned = (arr_elem & 1) || (arr_elem == 0);
2302                         if (arr_elem_conv.inner != NULL)
2303                                 arr_elem_conv = UpdateFailMalformedHTLC_clone(&arr_elem_conv);
2304                         ret->data[i] = arr_elem_conv;
2305                 }
2306         }
2307         return (long)ret;
2308 }
2309 static inline LDKCVec_UpdateFailMalformedHTLCZ CVec_UpdateFailMalformedHTLCZ_clone(const LDKCVec_UpdateFailMalformedHTLCZ *orig) {
2310         LDKCVec_UpdateFailMalformedHTLCZ ret = { .data = MALLOC(sizeof(LDKUpdateFailMalformedHTLC) * orig->datalen, "LDKCVec_UpdateFailMalformedHTLCZ clone bytes"), .datalen = orig->datalen };
2311         for (size_t i = 0; i < ret.datalen; i++) {
2312                 ret.data[i] = UpdateFailMalformedHTLC_clone(&orig->data[i]);
2313         }
2314         return ret;
2315 }
2316 jboolean LDKCResult_1boolLightningErrorZ_1result_1ok (void* ctx_TODO, uint32_t arg) {
2317         return ((LDKCResult_boolLightningErrorZ*)arg)->result_ok;
2318 }
2319 jboolean LDKCResult_1boolLightningErrorZ_1get_1ok (void* ctx_TODO, uint32_t arg) {
2320         LDKCResult_boolLightningErrorZ *val = (LDKCResult_boolLightningErrorZ*)arg;
2321         CHECK(val->result_ok);
2322         return *val->contents.result;
2323 }
2324 uint32_t LDKCResult_1boolLightningErrorZ_1get_1err (void* ctx_TODO, uint32_t arg) {
2325         LDKCResult_boolLightningErrorZ *val = (LDKCResult_boolLightningErrorZ*)arg;
2326         CHECK(!val->result_ok);
2327         LDKLightningError err_var = (*val->contents.err);
2328         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2329         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2330         long err_ref = (long)err_var.inner & ~1;
2331         return err_ref;
2332 }
2333 uint32_t LDKC3Tuple_1ChannelAnnouncementChannelUpdateChannelUpdateZ_1new(void* ctx_TODO, uint32_t a, uint32_t b, uint32_t c) {
2334         LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ* ret = MALLOC(sizeof(LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ), "LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ");
2335         LDKChannelAnnouncement a_conv;
2336         a_conv.inner = (void*)(a & (~1));
2337         a_conv.is_owned = (a & 1) || (a == 0);
2338         if (a_conv.inner != NULL)
2339                 a_conv = ChannelAnnouncement_clone(&a_conv);
2340         ret->a = a_conv;
2341         LDKChannelUpdate b_conv;
2342         b_conv.inner = (void*)(b & (~1));
2343         b_conv.is_owned = (b & 1) || (b == 0);
2344         if (b_conv.inner != NULL)
2345                 b_conv = ChannelUpdate_clone(&b_conv);
2346         ret->b = b_conv;
2347         LDKChannelUpdate c_conv;
2348         c_conv.inner = (void*)(c & (~1));
2349         c_conv.is_owned = (c & 1) || (c == 0);
2350         if (c_conv.inner != NULL)
2351                 c_conv = ChannelUpdate_clone(&c_conv);
2352         ret->c = c_conv;
2353         return (long)ret;
2354 }
2355 static inline LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ_clone(const LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ *orig) {
2356         LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ ret = {
2357                 .a = ChannelAnnouncement_clone(&orig->a),
2358                 .b = ChannelUpdate_clone(&orig->b),
2359                 .c = ChannelUpdate_clone(&orig->c),
2360         };
2361         return ret;
2362 }
2363 uint32_t LDKC3Tuple_1ChannelAnnouncementChannelUpdateChannelUpdateZ_1get_1a(void* ctx_TODO, uint32_t ptr) {
2364         LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ *tuple = (LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ*)ptr;
2365         LDKChannelAnnouncement a_var = tuple->a;
2366         CHECK((((long)a_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2367         CHECK((((long)&a_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2368         long a_ref = (long)a_var.inner & ~1;
2369         return a_ref;
2370 }
2371 uint32_t LDKC3Tuple_1ChannelAnnouncementChannelUpdateChannelUpdateZ_1get_1b(void* ctx_TODO, uint32_t ptr) {
2372         LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ *tuple = (LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ*)ptr;
2373         LDKChannelUpdate b_var = tuple->b;
2374         CHECK((((long)b_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2375         CHECK((((long)&b_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2376         long b_ref = (long)b_var.inner & ~1;
2377         return b_ref;
2378 }
2379 uint32_t LDKC3Tuple_1ChannelAnnouncementChannelUpdateChannelUpdateZ_1get_1c(void* ctx_TODO, uint32_t ptr) {
2380         LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ *tuple = (LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ*)ptr;
2381         LDKChannelUpdate c_var = tuple->c;
2382         CHECK((((long)c_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2383         CHECK((((long)&c_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2384         long c_ref = (long)c_var.inner & ~1;
2385         return c_ref;
2386 }
2387 uint32_t LDKCVec_1C3Tuple_1ChannelAnnouncementChannelUpdateChannelUpdateZZ_1new(void* ctx_TODO, uint32_tArray elems) {
2388         LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ *ret = MALLOC(sizeof(LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ), "LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ");
2389         ret->datalen = elems.len;
2390         if (ret->datalen == 0) {
2391                 ret->data = NULL;
2392         } else {
2393                 ret->data = MALLOC(sizeof(LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ) * ret->datalen, "LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ Data");
2394                 uint32_t *java_elems = (uint32_t*)elems.ptr;
2395                 for (size_t i = 0; i < ret->datalen; i++) {
2396                         uint32_t arr_elem = java_elems[i];
2397                         LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ arr_elem_conv = *(LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ*)arr_elem;
2398                         FREE((void*)arr_elem);
2399                         ret->data[i] = arr_elem_conv;
2400                 }
2401         }
2402         return (long)ret;
2403 }
2404 static inline LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ CVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ_clone(const LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ *orig) {
2405         LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ ret = { .data = MALLOC(sizeof(LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ) * orig->datalen, "LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ clone bytes"), .datalen = orig->datalen };
2406         for (size_t i = 0; i < ret.datalen; i++) {
2407                 ret.data[i] = C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ_clone(&orig->data[i]);
2408         }
2409         return ret;
2410 }
2411 uint32_t LDKCVec_1NodeAnnouncementZ_1new(void* ctx_TODO, uint32_tArray elems) {
2412         LDKCVec_NodeAnnouncementZ *ret = MALLOC(sizeof(LDKCVec_NodeAnnouncementZ), "LDKCVec_NodeAnnouncementZ");
2413         ret->datalen = elems.len;
2414         if (ret->datalen == 0) {
2415                 ret->data = NULL;
2416         } else {
2417                 ret->data = MALLOC(sizeof(LDKNodeAnnouncement) * ret->datalen, "LDKCVec_NodeAnnouncementZ Data");
2418                 uint32_t *java_elems = (uint32_t*)elems.ptr;
2419                 for (size_t i = 0; i < ret->datalen; i++) {
2420                         uint32_t arr_elem = java_elems[i];
2421                         LDKNodeAnnouncement arr_elem_conv;
2422                         arr_elem_conv.inner = (void*)(arr_elem & (~1));
2423                         arr_elem_conv.is_owned = (arr_elem & 1) || (arr_elem == 0);
2424                         if (arr_elem_conv.inner != NULL)
2425                                 arr_elem_conv = NodeAnnouncement_clone(&arr_elem_conv);
2426                         ret->data[i] = arr_elem_conv;
2427                 }
2428         }
2429         return (long)ret;
2430 }
2431 static inline LDKCVec_NodeAnnouncementZ CVec_NodeAnnouncementZ_clone(const LDKCVec_NodeAnnouncementZ *orig) {
2432         LDKCVec_NodeAnnouncementZ ret = { .data = MALLOC(sizeof(LDKNodeAnnouncement) * orig->datalen, "LDKCVec_NodeAnnouncementZ clone bytes"), .datalen = orig->datalen };
2433         for (size_t i = 0; i < ret.datalen; i++) {
2434                 ret.data[i] = NodeAnnouncement_clone(&orig->data[i]);
2435         }
2436         return ret;
2437 }
2438 jboolean LDKCResult_1NoneLightningErrorZ_1result_1ok (void* ctx_TODO, uint32_t arg) {
2439         return ((LDKCResult_NoneLightningErrorZ*)arg)->result_ok;
2440 }
2441 void LDKCResult_1NoneLightningErrorZ_1get_1ok (void* ctx_TODO, uint32_t arg) {
2442         LDKCResult_NoneLightningErrorZ *val = (LDKCResult_NoneLightningErrorZ*)arg;
2443         CHECK(val->result_ok);
2444         return *val->contents.result;
2445 }
2446 uint32_t LDKCResult_1NoneLightningErrorZ_1get_1err (void* ctx_TODO, uint32_t arg) {
2447         LDKCResult_NoneLightningErrorZ *val = (LDKCResult_NoneLightningErrorZ*)arg;
2448         CHECK(!val->result_ok);
2449         LDKLightningError err_var = (*val->contents.err);
2450         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2451         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2452         long err_ref = (long)err_var.inner & ~1;
2453         return err_ref;
2454 }
2455 jboolean LDKCResult_1ChannelReestablishDecodeErrorZ_1result_1ok (void* ctx_TODO, uint32_t arg) {
2456         return ((LDKCResult_ChannelReestablishDecodeErrorZ*)arg)->result_ok;
2457 }
2458 uint32_t LDKCResult_1ChannelReestablishDecodeErrorZ_1get_1ok (void* ctx_TODO, uint32_t arg) {
2459         LDKCResult_ChannelReestablishDecodeErrorZ *val = (LDKCResult_ChannelReestablishDecodeErrorZ*)arg;
2460         CHECK(val->result_ok);
2461         LDKChannelReestablish res_var = (*val->contents.result);
2462         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2463         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2464         long res_ref = (long)res_var.inner & ~1;
2465         return res_ref;
2466 }
2467 uint32_t LDKCResult_1ChannelReestablishDecodeErrorZ_1get_1err (void* ctx_TODO, uint32_t arg) {
2468         LDKCResult_ChannelReestablishDecodeErrorZ *val = (LDKCResult_ChannelReestablishDecodeErrorZ*)arg;
2469         CHECK(!val->result_ok);
2470         LDKDecodeError err_var = (*val->contents.err);
2471         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2472         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2473         long err_ref = (long)err_var.inner & ~1;
2474         return err_ref;
2475 }
2476 jboolean LDKCResult_1InitDecodeErrorZ_1result_1ok (void* ctx_TODO, uint32_t arg) {
2477         return ((LDKCResult_InitDecodeErrorZ*)arg)->result_ok;
2478 }
2479 uint32_t LDKCResult_1InitDecodeErrorZ_1get_1ok (void* ctx_TODO, uint32_t arg) {
2480         LDKCResult_InitDecodeErrorZ *val = (LDKCResult_InitDecodeErrorZ*)arg;
2481         CHECK(val->result_ok);
2482         LDKInit res_var = (*val->contents.result);
2483         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2484         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2485         long res_ref = (long)res_var.inner & ~1;
2486         return res_ref;
2487 }
2488 uint32_t LDKCResult_1InitDecodeErrorZ_1get_1err (void* ctx_TODO, uint32_t arg) {
2489         LDKCResult_InitDecodeErrorZ *val = (LDKCResult_InitDecodeErrorZ*)arg;
2490         CHECK(!val->result_ok);
2491         LDKDecodeError err_var = (*val->contents.err);
2492         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2493         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2494         long err_ref = (long)err_var.inner & ~1;
2495         return err_ref;
2496 }
2497 jboolean LDKCResult_1PingDecodeErrorZ_1result_1ok (void* ctx_TODO, uint32_t arg) {
2498         return ((LDKCResult_PingDecodeErrorZ*)arg)->result_ok;
2499 }
2500 uint32_t LDKCResult_1PingDecodeErrorZ_1get_1ok (void* ctx_TODO, uint32_t arg) {
2501         LDKCResult_PingDecodeErrorZ *val = (LDKCResult_PingDecodeErrorZ*)arg;
2502         CHECK(val->result_ok);
2503         LDKPing res_var = (*val->contents.result);
2504         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2505         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2506         long res_ref = (long)res_var.inner & ~1;
2507         return res_ref;
2508 }
2509 uint32_t LDKCResult_1PingDecodeErrorZ_1get_1err (void* ctx_TODO, uint32_t arg) {
2510         LDKCResult_PingDecodeErrorZ *val = (LDKCResult_PingDecodeErrorZ*)arg;
2511         CHECK(!val->result_ok);
2512         LDKDecodeError err_var = (*val->contents.err);
2513         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2514         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2515         long err_ref = (long)err_var.inner & ~1;
2516         return err_ref;
2517 }
2518 jboolean LDKCResult_1PongDecodeErrorZ_1result_1ok (void* ctx_TODO, uint32_t arg) {
2519         return ((LDKCResult_PongDecodeErrorZ*)arg)->result_ok;
2520 }
2521 uint32_t LDKCResult_1PongDecodeErrorZ_1get_1ok (void* ctx_TODO, uint32_t arg) {
2522         LDKCResult_PongDecodeErrorZ *val = (LDKCResult_PongDecodeErrorZ*)arg;
2523         CHECK(val->result_ok);
2524         LDKPong res_var = (*val->contents.result);
2525         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2526         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2527         long res_ref = (long)res_var.inner & ~1;
2528         return res_ref;
2529 }
2530 uint32_t LDKCResult_1PongDecodeErrorZ_1get_1err (void* ctx_TODO, uint32_t arg) {
2531         LDKCResult_PongDecodeErrorZ *val = (LDKCResult_PongDecodeErrorZ*)arg;
2532         CHECK(!val->result_ok);
2533         LDKDecodeError err_var = (*val->contents.err);
2534         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2535         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2536         long err_ref = (long)err_var.inner & ~1;
2537         return err_ref;
2538 }
2539 jboolean LDKCResult_1UnsignedChannelAnnouncementDecodeErrorZ_1result_1ok (void* ctx_TODO, uint32_t arg) {
2540         return ((LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ*)arg)->result_ok;
2541 }
2542 uint32_t LDKCResult_1UnsignedChannelAnnouncementDecodeErrorZ_1get_1ok (void* ctx_TODO, uint32_t arg) {
2543         LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ *val = (LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ*)arg;
2544         CHECK(val->result_ok);
2545         LDKUnsignedChannelAnnouncement res_var = (*val->contents.result);
2546         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2547         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2548         long res_ref = (long)res_var.inner & ~1;
2549         return res_ref;
2550 }
2551 uint32_t LDKCResult_1UnsignedChannelAnnouncementDecodeErrorZ_1get_1err (void* ctx_TODO, uint32_t arg) {
2552         LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ *val = (LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ*)arg;
2553         CHECK(!val->result_ok);
2554         LDKDecodeError err_var = (*val->contents.err);
2555         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2556         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2557         long err_ref = (long)err_var.inner & ~1;
2558         return err_ref;
2559 }
2560 jboolean LDKCResult_1UnsignedChannelUpdateDecodeErrorZ_1result_1ok (void* ctx_TODO, uint32_t arg) {
2561         return ((LDKCResult_UnsignedChannelUpdateDecodeErrorZ*)arg)->result_ok;
2562 }
2563 uint32_t LDKCResult_1UnsignedChannelUpdateDecodeErrorZ_1get_1ok (void* ctx_TODO, uint32_t arg) {
2564         LDKCResult_UnsignedChannelUpdateDecodeErrorZ *val = (LDKCResult_UnsignedChannelUpdateDecodeErrorZ*)arg;
2565         CHECK(val->result_ok);
2566         LDKUnsignedChannelUpdate res_var = (*val->contents.result);
2567         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2568         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2569         long res_ref = (long)res_var.inner & ~1;
2570         return res_ref;
2571 }
2572 uint32_t LDKCResult_1UnsignedChannelUpdateDecodeErrorZ_1get_1err (void* ctx_TODO, uint32_t arg) {
2573         LDKCResult_UnsignedChannelUpdateDecodeErrorZ *val = (LDKCResult_UnsignedChannelUpdateDecodeErrorZ*)arg;
2574         CHECK(!val->result_ok);
2575         LDKDecodeError err_var = (*val->contents.err);
2576         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2577         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2578         long err_ref = (long)err_var.inner & ~1;
2579         return err_ref;
2580 }
2581 jboolean LDKCResult_1ErrorMessageDecodeErrorZ_1result_1ok (void* ctx_TODO, uint32_t arg) {
2582         return ((LDKCResult_ErrorMessageDecodeErrorZ*)arg)->result_ok;
2583 }
2584 uint32_t LDKCResult_1ErrorMessageDecodeErrorZ_1get_1ok (void* ctx_TODO, uint32_t arg) {
2585         LDKCResult_ErrorMessageDecodeErrorZ *val = (LDKCResult_ErrorMessageDecodeErrorZ*)arg;
2586         CHECK(val->result_ok);
2587         LDKErrorMessage res_var = (*val->contents.result);
2588         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2589         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2590         long res_ref = (long)res_var.inner & ~1;
2591         return res_ref;
2592 }
2593 uint32_t LDKCResult_1ErrorMessageDecodeErrorZ_1get_1err (void* ctx_TODO, uint32_t arg) {
2594         LDKCResult_ErrorMessageDecodeErrorZ *val = (LDKCResult_ErrorMessageDecodeErrorZ*)arg;
2595         CHECK(!val->result_ok);
2596         LDKDecodeError err_var = (*val->contents.err);
2597         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2598         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2599         long err_ref = (long)err_var.inner & ~1;
2600         return err_ref;
2601 }
2602 jboolean LDKCResult_1UnsignedNodeAnnouncementDecodeErrorZ_1result_1ok (void* ctx_TODO, uint32_t arg) {
2603         return ((LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ*)arg)->result_ok;
2604 }
2605 uint32_t LDKCResult_1UnsignedNodeAnnouncementDecodeErrorZ_1get_1ok (void* ctx_TODO, uint32_t arg) {
2606         LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ *val = (LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ*)arg;
2607         CHECK(val->result_ok);
2608         LDKUnsignedNodeAnnouncement res_var = (*val->contents.result);
2609         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2610         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2611         long res_ref = (long)res_var.inner & ~1;
2612         return res_ref;
2613 }
2614 uint32_t LDKCResult_1UnsignedNodeAnnouncementDecodeErrorZ_1get_1err (void* ctx_TODO, uint32_t arg) {
2615         LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ *val = (LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ*)arg;
2616         CHECK(!val->result_ok);
2617         LDKDecodeError err_var = (*val->contents.err);
2618         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2619         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2620         long err_ref = (long)err_var.inner & ~1;
2621         return err_ref;
2622 }
2623 jboolean LDKCResult_1QueryShortChannelIdsDecodeErrorZ_1result_1ok (void* ctx_TODO, uint32_t arg) {
2624         return ((LDKCResult_QueryShortChannelIdsDecodeErrorZ*)arg)->result_ok;
2625 }
2626 uint32_t LDKCResult_1QueryShortChannelIdsDecodeErrorZ_1get_1ok (void* ctx_TODO, uint32_t arg) {
2627         LDKCResult_QueryShortChannelIdsDecodeErrorZ *val = (LDKCResult_QueryShortChannelIdsDecodeErrorZ*)arg;
2628         CHECK(val->result_ok);
2629         LDKQueryShortChannelIds res_var = (*val->contents.result);
2630         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2631         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2632         long res_ref = (long)res_var.inner & ~1;
2633         return res_ref;
2634 }
2635 uint32_t LDKCResult_1QueryShortChannelIdsDecodeErrorZ_1get_1err (void* ctx_TODO, uint32_t arg) {
2636         LDKCResult_QueryShortChannelIdsDecodeErrorZ *val = (LDKCResult_QueryShortChannelIdsDecodeErrorZ*)arg;
2637         CHECK(!val->result_ok);
2638         LDKDecodeError err_var = (*val->contents.err);
2639         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2640         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2641         long err_ref = (long)err_var.inner & ~1;
2642         return err_ref;
2643 }
2644 jboolean LDKCResult_1ReplyShortChannelIdsEndDecodeErrorZ_1result_1ok (void* ctx_TODO, uint32_t arg) {
2645         return ((LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ*)arg)->result_ok;
2646 }
2647 uint32_t LDKCResult_1ReplyShortChannelIdsEndDecodeErrorZ_1get_1ok (void* ctx_TODO, uint32_t arg) {
2648         LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ *val = (LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ*)arg;
2649         CHECK(val->result_ok);
2650         LDKReplyShortChannelIdsEnd res_var = (*val->contents.result);
2651         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2652         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2653         long res_ref = (long)res_var.inner & ~1;
2654         return res_ref;
2655 }
2656 uint32_t LDKCResult_1ReplyShortChannelIdsEndDecodeErrorZ_1get_1err (void* ctx_TODO, uint32_t arg) {
2657         LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ *val = (LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ*)arg;
2658         CHECK(!val->result_ok);
2659         LDKDecodeError err_var = (*val->contents.err);
2660         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2661         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2662         long err_ref = (long)err_var.inner & ~1;
2663         return err_ref;
2664 }
2665 jboolean LDKCResult_1QueryChannelRangeDecodeErrorZ_1result_1ok (void* ctx_TODO, uint32_t arg) {
2666         return ((LDKCResult_QueryChannelRangeDecodeErrorZ*)arg)->result_ok;
2667 }
2668 uint32_t LDKCResult_1QueryChannelRangeDecodeErrorZ_1get_1ok (void* ctx_TODO, uint32_t arg) {
2669         LDKCResult_QueryChannelRangeDecodeErrorZ *val = (LDKCResult_QueryChannelRangeDecodeErrorZ*)arg;
2670         CHECK(val->result_ok);
2671         LDKQueryChannelRange res_var = (*val->contents.result);
2672         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2673         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2674         long res_ref = (long)res_var.inner & ~1;
2675         return res_ref;
2676 }
2677 uint32_t LDKCResult_1QueryChannelRangeDecodeErrorZ_1get_1err (void* ctx_TODO, uint32_t arg) {
2678         LDKCResult_QueryChannelRangeDecodeErrorZ *val = (LDKCResult_QueryChannelRangeDecodeErrorZ*)arg;
2679         CHECK(!val->result_ok);
2680         LDKDecodeError err_var = (*val->contents.err);
2681         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2682         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2683         long err_ref = (long)err_var.inner & ~1;
2684         return err_ref;
2685 }
2686 jboolean LDKCResult_1ReplyChannelRangeDecodeErrorZ_1result_1ok (void* ctx_TODO, uint32_t arg) {
2687         return ((LDKCResult_ReplyChannelRangeDecodeErrorZ*)arg)->result_ok;
2688 }
2689 uint32_t LDKCResult_1ReplyChannelRangeDecodeErrorZ_1get_1ok (void* ctx_TODO, uint32_t arg) {
2690         LDKCResult_ReplyChannelRangeDecodeErrorZ *val = (LDKCResult_ReplyChannelRangeDecodeErrorZ*)arg;
2691         CHECK(val->result_ok);
2692         LDKReplyChannelRange res_var = (*val->contents.result);
2693         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2694         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2695         long res_ref = (long)res_var.inner & ~1;
2696         return res_ref;
2697 }
2698 uint32_t LDKCResult_1ReplyChannelRangeDecodeErrorZ_1get_1err (void* ctx_TODO, uint32_t arg) {
2699         LDKCResult_ReplyChannelRangeDecodeErrorZ *val = (LDKCResult_ReplyChannelRangeDecodeErrorZ*)arg;
2700         CHECK(!val->result_ok);
2701         LDKDecodeError err_var = (*val->contents.err);
2702         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2703         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2704         long err_ref = (long)err_var.inner & ~1;
2705         return err_ref;
2706 }
2707 jboolean LDKCResult_1GossipTimestampFilterDecodeErrorZ_1result_1ok (void* ctx_TODO, uint32_t arg) {
2708         return ((LDKCResult_GossipTimestampFilterDecodeErrorZ*)arg)->result_ok;
2709 }
2710 uint32_t LDKCResult_1GossipTimestampFilterDecodeErrorZ_1get_1ok (void* ctx_TODO, uint32_t arg) {
2711         LDKCResult_GossipTimestampFilterDecodeErrorZ *val = (LDKCResult_GossipTimestampFilterDecodeErrorZ*)arg;
2712         CHECK(val->result_ok);
2713         LDKGossipTimestampFilter res_var = (*val->contents.result);
2714         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2715         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2716         long res_ref = (long)res_var.inner & ~1;
2717         return res_ref;
2718 }
2719 uint32_t LDKCResult_1GossipTimestampFilterDecodeErrorZ_1get_1err (void* ctx_TODO, uint32_t arg) {
2720         LDKCResult_GossipTimestampFilterDecodeErrorZ *val = (LDKCResult_GossipTimestampFilterDecodeErrorZ*)arg;
2721         CHECK(!val->result_ok);
2722         LDKDecodeError err_var = (*val->contents.err);
2723         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2724         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2725         long err_ref = (long)err_var.inner & ~1;
2726         return err_ref;
2727 }
2728 jboolean LDKCResult_1CVec_1u8ZPeerHandleErrorZ_1result_1ok (void* ctx_TODO, uint32_t arg) {
2729         return ((LDKCResult_CVec_u8ZPeerHandleErrorZ*)arg)->result_ok;
2730 }
2731 int8_tArray LDKCResult_1CVec_1u8ZPeerHandleErrorZ_1get_1ok (void* ctx_TODO, uint32_t arg) {
2732         LDKCResult_CVec_u8ZPeerHandleErrorZ *val = (LDKCResult_CVec_u8ZPeerHandleErrorZ*)arg;
2733         CHECK(val->result_ok);
2734         LDKCVec_u8Z res_var = (*val->contents.result);
2735         int8_tArray res_arr = { .len = res_var.datalen, .ptr = MALLOC(res_var.datalen, "Native int8_tArray Bytes") };
2736         memcpy(res_arr.ptr, res_var.data, res_var.datalen);
2737         return res_arr;
2738 }
2739 uint32_t LDKCResult_1CVec_1u8ZPeerHandleErrorZ_1get_1err (void* ctx_TODO, uint32_t arg) {
2740         LDKCResult_CVec_u8ZPeerHandleErrorZ *val = (LDKCResult_CVec_u8ZPeerHandleErrorZ*)arg;
2741         CHECK(!val->result_ok);
2742         LDKPeerHandleError err_var = (*val->contents.err);
2743         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2744         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2745         long err_ref = (long)err_var.inner & ~1;
2746         return err_ref;
2747 }
2748 jboolean LDKCResult_1NonePeerHandleErrorZ_1result_1ok (void* ctx_TODO, uint32_t arg) {
2749         return ((LDKCResult_NonePeerHandleErrorZ*)arg)->result_ok;
2750 }
2751 void LDKCResult_1NonePeerHandleErrorZ_1get_1ok (void* ctx_TODO, uint32_t arg) {
2752         LDKCResult_NonePeerHandleErrorZ *val = (LDKCResult_NonePeerHandleErrorZ*)arg;
2753         CHECK(val->result_ok);
2754         return *val->contents.result;
2755 }
2756 uint32_t LDKCResult_1NonePeerHandleErrorZ_1get_1err (void* ctx_TODO, uint32_t arg) {
2757         LDKCResult_NonePeerHandleErrorZ *val = (LDKCResult_NonePeerHandleErrorZ*)arg;
2758         CHECK(!val->result_ok);
2759         LDKPeerHandleError err_var = (*val->contents.err);
2760         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2761         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2762         long err_ref = (long)err_var.inner & ~1;
2763         return err_ref;
2764 }
2765 jboolean LDKCResult_1boolPeerHandleErrorZ_1result_1ok (void* ctx_TODO, uint32_t arg) {
2766         return ((LDKCResult_boolPeerHandleErrorZ*)arg)->result_ok;
2767 }
2768 jboolean LDKCResult_1boolPeerHandleErrorZ_1get_1ok (void* ctx_TODO, uint32_t arg) {
2769         LDKCResult_boolPeerHandleErrorZ *val = (LDKCResult_boolPeerHandleErrorZ*)arg;
2770         CHECK(val->result_ok);
2771         return *val->contents.result;
2772 }
2773 uint32_t LDKCResult_1boolPeerHandleErrorZ_1get_1err (void* ctx_TODO, uint32_t arg) {
2774         LDKCResult_boolPeerHandleErrorZ *val = (LDKCResult_boolPeerHandleErrorZ*)arg;
2775         CHECK(!val->result_ok);
2776         LDKPeerHandleError err_var = (*val->contents.err);
2777         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2778         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2779         long err_ref = (long)err_var.inner & ~1;
2780         return err_ref;
2781 }
2782 jboolean LDKCResult_1SecretKeySecpErrorZ_1result_1ok (void* ctx_TODO, uint32_t arg) {
2783         return ((LDKCResult_SecretKeySecpErrorZ*)arg)->result_ok;
2784 }
2785 int8_tArray LDKCResult_1SecretKeySecpErrorZ_1get_1ok (void* ctx_TODO, uint32_t arg) {
2786         LDKCResult_SecretKeySecpErrorZ *val = (LDKCResult_SecretKeySecpErrorZ*)arg;
2787         CHECK(val->result_ok);
2788         int8_tArray res_arr = { .len = 32, .ptr = MALLOC(32, "Native int8_tArray Bytes") };
2789         memcpy(res_arr.ptr, (*val->contents.result).bytes, 32);
2790         return res_arr;
2791 }
2792 uint32_t LDKCResult_1SecretKeySecpErrorZ_1get_1err (void* ctx_TODO, uint32_t arg) {
2793         LDKCResult_SecretKeySecpErrorZ *val = (LDKCResult_SecretKeySecpErrorZ*)arg;
2794         CHECK(!val->result_ok);
2795         uint32_t err_conv = LDKSecp256k1Error_to_js((*val->contents.err));
2796         return err_conv;
2797 }
2798 jboolean LDKCResult_1PublicKeySecpErrorZ_1result_1ok (void* ctx_TODO, uint32_t arg) {
2799         return ((LDKCResult_PublicKeySecpErrorZ*)arg)->result_ok;
2800 }
2801 int8_tArray LDKCResult_1PublicKeySecpErrorZ_1get_1ok (void* ctx_TODO, uint32_t arg) {
2802         LDKCResult_PublicKeySecpErrorZ *val = (LDKCResult_PublicKeySecpErrorZ*)arg;
2803         CHECK(val->result_ok);
2804         int8_tArray res_arr = { .len = 33, .ptr = MALLOC(33, "Native int8_tArray Bytes") };
2805         memcpy(res_arr.ptr, (*val->contents.result).compressed_form, 33);
2806         return res_arr;
2807 }
2808 uint32_t LDKCResult_1PublicKeySecpErrorZ_1get_1err (void* ctx_TODO, uint32_t arg) {
2809         LDKCResult_PublicKeySecpErrorZ *val = (LDKCResult_PublicKeySecpErrorZ*)arg;
2810         CHECK(!val->result_ok);
2811         uint32_t err_conv = LDKSecp256k1Error_to_js((*val->contents.err));
2812         return err_conv;
2813 }
2814 jboolean LDKCResult_1TxCreationKeysSecpErrorZ_1result_1ok (void* ctx_TODO, uint32_t arg) {
2815         return ((LDKCResult_TxCreationKeysSecpErrorZ*)arg)->result_ok;
2816 }
2817 uint32_t LDKCResult_1TxCreationKeysSecpErrorZ_1get_1ok (void* ctx_TODO, uint32_t arg) {
2818         LDKCResult_TxCreationKeysSecpErrorZ *val = (LDKCResult_TxCreationKeysSecpErrorZ*)arg;
2819         CHECK(val->result_ok);
2820         LDKTxCreationKeys res_var = (*val->contents.result);
2821         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2822         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2823         long res_ref = (long)res_var.inner & ~1;
2824         return res_ref;
2825 }
2826 uint32_t LDKCResult_1TxCreationKeysSecpErrorZ_1get_1err (void* ctx_TODO, uint32_t arg) {
2827         LDKCResult_TxCreationKeysSecpErrorZ *val = (LDKCResult_TxCreationKeysSecpErrorZ*)arg;
2828         CHECK(!val->result_ok);
2829         uint32_t err_conv = LDKSecp256k1Error_to_js((*val->contents.err));
2830         return err_conv;
2831 }
2832 jboolean LDKCResult_1TrustedCommitmentTransactionNoneZ_1result_1ok (void* ctx_TODO, uint32_t arg) {
2833         return ((LDKCResult_TrustedCommitmentTransactionNoneZ*)arg)->result_ok;
2834 }
2835 uint32_t LDKCResult_1TrustedCommitmentTransactionNoneZ_1get_1ok (void* ctx_TODO, uint32_t arg) {
2836         LDKCResult_TrustedCommitmentTransactionNoneZ *val = (LDKCResult_TrustedCommitmentTransactionNoneZ*)arg;
2837         CHECK(val->result_ok);
2838         LDKTrustedCommitmentTransaction res_var = (*val->contents.result);
2839         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2840         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2841         long res_ref = (long)res_var.inner & ~1;
2842         return res_ref;
2843 }
2844 void LDKCResult_1TrustedCommitmentTransactionNoneZ_1get_1err (void* ctx_TODO, uint32_t arg) {
2845         LDKCResult_TrustedCommitmentTransactionNoneZ *val = (LDKCResult_TrustedCommitmentTransactionNoneZ*)arg;
2846         CHECK(!val->result_ok);
2847         return *val->contents.err;
2848 }
2849 uint32_t LDKCVec_1RouteHopZ_1new(void* ctx_TODO, uint32_tArray elems) {
2850         LDKCVec_RouteHopZ *ret = MALLOC(sizeof(LDKCVec_RouteHopZ), "LDKCVec_RouteHopZ");
2851         ret->datalen = elems.len;
2852         if (ret->datalen == 0) {
2853                 ret->data = NULL;
2854         } else {
2855                 ret->data = MALLOC(sizeof(LDKRouteHop) * ret->datalen, "LDKCVec_RouteHopZ Data");
2856                 uint32_t *java_elems = (uint32_t*)elems.ptr;
2857                 for (size_t i = 0; i < ret->datalen; i++) {
2858                         uint32_t arr_elem = java_elems[i];
2859                         LDKRouteHop arr_elem_conv;
2860                         arr_elem_conv.inner = (void*)(arr_elem & (~1));
2861                         arr_elem_conv.is_owned = (arr_elem & 1) || (arr_elem == 0);
2862                         if (arr_elem_conv.inner != NULL)
2863                                 arr_elem_conv = RouteHop_clone(&arr_elem_conv);
2864                         ret->data[i] = arr_elem_conv;
2865                 }
2866         }
2867         return (long)ret;
2868 }
2869 static inline LDKCVec_RouteHopZ CVec_RouteHopZ_clone(const LDKCVec_RouteHopZ *orig) {
2870         LDKCVec_RouteHopZ ret = { .data = MALLOC(sizeof(LDKRouteHop) * orig->datalen, "LDKCVec_RouteHopZ clone bytes"), .datalen = orig->datalen };
2871         for (size_t i = 0; i < ret.datalen; i++) {
2872                 ret.data[i] = RouteHop_clone(&orig->data[i]);
2873         }
2874         return ret;
2875 }
2876 static inline LDKCVec_CVec_RouteHopZZ CVec_CVec_RouteHopZZ_clone(const LDKCVec_CVec_RouteHopZZ *orig) {
2877         LDKCVec_CVec_RouteHopZZ ret = { .data = MALLOC(sizeof(LDKCVec_RouteHopZ) * orig->datalen, "LDKCVec_CVec_RouteHopZZ clone bytes"), .datalen = orig->datalen };
2878         for (size_t i = 0; i < ret.datalen; i++) {
2879                 ret.data[i] = CVec_RouteHopZ_clone(&orig->data[i]);
2880         }
2881         return ret;
2882 }
2883 jboolean LDKCResult_1RouteDecodeErrorZ_1result_1ok (void* ctx_TODO, uint32_t arg) {
2884         return ((LDKCResult_RouteDecodeErrorZ*)arg)->result_ok;
2885 }
2886 uint32_t LDKCResult_1RouteDecodeErrorZ_1get_1ok (void* ctx_TODO, uint32_t arg) {
2887         LDKCResult_RouteDecodeErrorZ *val = (LDKCResult_RouteDecodeErrorZ*)arg;
2888         CHECK(val->result_ok);
2889         LDKRoute res_var = (*val->contents.result);
2890         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2891         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2892         long res_ref = (long)res_var.inner & ~1;
2893         return res_ref;
2894 }
2895 uint32_t LDKCResult_1RouteDecodeErrorZ_1get_1err (void* ctx_TODO, uint32_t arg) {
2896         LDKCResult_RouteDecodeErrorZ *val = (LDKCResult_RouteDecodeErrorZ*)arg;
2897         CHECK(!val->result_ok);
2898         LDKDecodeError err_var = (*val->contents.err);
2899         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2900         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2901         long err_ref = (long)err_var.inner & ~1;
2902         return err_ref;
2903 }
2904 uint32_t LDKCVec_1RouteHintZ_1new(void* ctx_TODO, uint32_tArray elems) {
2905         LDKCVec_RouteHintZ *ret = MALLOC(sizeof(LDKCVec_RouteHintZ), "LDKCVec_RouteHintZ");
2906         ret->datalen = elems.len;
2907         if (ret->datalen == 0) {
2908                 ret->data = NULL;
2909         } else {
2910                 ret->data = MALLOC(sizeof(LDKRouteHint) * ret->datalen, "LDKCVec_RouteHintZ Data");
2911                 uint32_t *java_elems = (uint32_t*)elems.ptr;
2912                 for (size_t i = 0; i < ret->datalen; i++) {
2913                         uint32_t arr_elem = java_elems[i];
2914                         LDKRouteHint arr_elem_conv;
2915                         arr_elem_conv.inner = (void*)(arr_elem & (~1));
2916                         arr_elem_conv.is_owned = (arr_elem & 1) || (arr_elem == 0);
2917                         if (arr_elem_conv.inner != NULL)
2918                                 arr_elem_conv = RouteHint_clone(&arr_elem_conv);
2919                         ret->data[i] = arr_elem_conv;
2920                 }
2921         }
2922         return (long)ret;
2923 }
2924 static inline LDKCVec_RouteHintZ CVec_RouteHintZ_clone(const LDKCVec_RouteHintZ *orig) {
2925         LDKCVec_RouteHintZ ret = { .data = MALLOC(sizeof(LDKRouteHint) * orig->datalen, "LDKCVec_RouteHintZ clone bytes"), .datalen = orig->datalen };
2926         for (size_t i = 0; i < ret.datalen; i++) {
2927                 ret.data[i] = RouteHint_clone(&orig->data[i]);
2928         }
2929         return ret;
2930 }
2931 jboolean LDKCResult_1RouteLightningErrorZ_1result_1ok (void* ctx_TODO, uint32_t arg) {
2932         return ((LDKCResult_RouteLightningErrorZ*)arg)->result_ok;
2933 }
2934 uint32_t LDKCResult_1RouteLightningErrorZ_1get_1ok (void* ctx_TODO, uint32_t arg) {
2935         LDKCResult_RouteLightningErrorZ *val = (LDKCResult_RouteLightningErrorZ*)arg;
2936         CHECK(val->result_ok);
2937         LDKRoute res_var = (*val->contents.result);
2938         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2939         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2940         long res_ref = (long)res_var.inner & ~1;
2941         return res_ref;
2942 }
2943 uint32_t LDKCResult_1RouteLightningErrorZ_1get_1err (void* ctx_TODO, uint32_t arg) {
2944         LDKCResult_RouteLightningErrorZ *val = (LDKCResult_RouteLightningErrorZ*)arg;
2945         CHECK(!val->result_ok);
2946         LDKLightningError err_var = (*val->contents.err);
2947         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2948         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2949         long err_ref = (long)err_var.inner & ~1;
2950         return err_ref;
2951 }
2952 jboolean LDKCResult_1RoutingFeesDecodeErrorZ_1result_1ok (void* ctx_TODO, uint32_t arg) {
2953         return ((LDKCResult_RoutingFeesDecodeErrorZ*)arg)->result_ok;
2954 }
2955 uint32_t LDKCResult_1RoutingFeesDecodeErrorZ_1get_1ok (void* ctx_TODO, uint32_t arg) {
2956         LDKCResult_RoutingFeesDecodeErrorZ *val = (LDKCResult_RoutingFeesDecodeErrorZ*)arg;
2957         CHECK(val->result_ok);
2958         LDKRoutingFees res_var = (*val->contents.result);
2959         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2960         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2961         long res_ref = (long)res_var.inner & ~1;
2962         return res_ref;
2963 }
2964 uint32_t LDKCResult_1RoutingFeesDecodeErrorZ_1get_1err (void* ctx_TODO, uint32_t arg) {
2965         LDKCResult_RoutingFeesDecodeErrorZ *val = (LDKCResult_RoutingFeesDecodeErrorZ*)arg;
2966         CHECK(!val->result_ok);
2967         LDKDecodeError err_var = (*val->contents.err);
2968         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2969         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2970         long err_ref = (long)err_var.inner & ~1;
2971         return err_ref;
2972 }
2973 jboolean LDKCResult_1NodeAnnouncementInfoDecodeErrorZ_1result_1ok (void* ctx_TODO, uint32_t arg) {
2974         return ((LDKCResult_NodeAnnouncementInfoDecodeErrorZ*)arg)->result_ok;
2975 }
2976 uint32_t LDKCResult_1NodeAnnouncementInfoDecodeErrorZ_1get_1ok (void* ctx_TODO, uint32_t arg) {
2977         LDKCResult_NodeAnnouncementInfoDecodeErrorZ *val = (LDKCResult_NodeAnnouncementInfoDecodeErrorZ*)arg;
2978         CHECK(val->result_ok);
2979         LDKNodeAnnouncementInfo res_var = (*val->contents.result);
2980         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2981         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2982         long res_ref = (long)res_var.inner & ~1;
2983         return res_ref;
2984 }
2985 uint32_t LDKCResult_1NodeAnnouncementInfoDecodeErrorZ_1get_1err (void* ctx_TODO, uint32_t arg) {
2986         LDKCResult_NodeAnnouncementInfoDecodeErrorZ *val = (LDKCResult_NodeAnnouncementInfoDecodeErrorZ*)arg;
2987         CHECK(!val->result_ok);
2988         LDKDecodeError err_var = (*val->contents.err);
2989         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2990         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2991         long err_ref = (long)err_var.inner & ~1;
2992         return err_ref;
2993 }
2994 jboolean LDKCResult_1NodeInfoDecodeErrorZ_1result_1ok (void* ctx_TODO, uint32_t arg) {
2995         return ((LDKCResult_NodeInfoDecodeErrorZ*)arg)->result_ok;
2996 }
2997 uint32_t LDKCResult_1NodeInfoDecodeErrorZ_1get_1ok (void* ctx_TODO, uint32_t arg) {
2998         LDKCResult_NodeInfoDecodeErrorZ *val = (LDKCResult_NodeInfoDecodeErrorZ*)arg;
2999         CHECK(val->result_ok);
3000         LDKNodeInfo res_var = (*val->contents.result);
3001         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3002         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3003         long res_ref = (long)res_var.inner & ~1;
3004         return res_ref;
3005 }
3006 uint32_t LDKCResult_1NodeInfoDecodeErrorZ_1get_1err (void* ctx_TODO, uint32_t arg) {
3007         LDKCResult_NodeInfoDecodeErrorZ *val = (LDKCResult_NodeInfoDecodeErrorZ*)arg;
3008         CHECK(!val->result_ok);
3009         LDKDecodeError err_var = (*val->contents.err);
3010         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3011         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3012         long err_ref = (long)err_var.inner & ~1;
3013         return err_ref;
3014 }
3015 jboolean LDKCResult_1NetworkGraphDecodeErrorZ_1result_1ok (void* ctx_TODO, uint32_t arg) {
3016         return ((LDKCResult_NetworkGraphDecodeErrorZ*)arg)->result_ok;
3017 }
3018 uint32_t LDKCResult_1NetworkGraphDecodeErrorZ_1get_1ok (void* ctx_TODO, uint32_t arg) {
3019         LDKCResult_NetworkGraphDecodeErrorZ *val = (LDKCResult_NetworkGraphDecodeErrorZ*)arg;
3020         CHECK(val->result_ok);
3021         LDKNetworkGraph res_var = (*val->contents.result);
3022         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3023         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3024         long res_ref = (long)res_var.inner & ~1;
3025         return res_ref;
3026 }
3027 uint32_t LDKCResult_1NetworkGraphDecodeErrorZ_1get_1err (void* ctx_TODO, uint32_t arg) {
3028         LDKCResult_NetworkGraphDecodeErrorZ *val = (LDKCResult_NetworkGraphDecodeErrorZ*)arg;
3029         CHECK(!val->result_ok);
3030         LDKDecodeError err_var = (*val->contents.err);
3031         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3032         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3033         long err_ref = (long)err_var.inner & ~1;
3034         return err_ref;
3035 }
3036 typedef struct LDKMessageSendEventsProvider_JCalls {
3037         atomic_size_t refcnt;
3038         // TODO: Object pointer o;
3039         // TODO: Some kind of method pointer get_and_clear_pending_msg_events_meth;
3040 } LDKMessageSendEventsProvider_JCalls;
3041 static void LDKMessageSendEventsProvider_JCalls_free(void* this_arg) {
3042         LDKMessageSendEventsProvider_JCalls *j_calls = (LDKMessageSendEventsProvider_JCalls*) this_arg;
3043         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
3044                 // TODO: do any release required for j_calls->o (refcnt-- in java, but may be redundant)
3045                 FREE(j_calls);
3046         }
3047 }
3048 LDKCVec_MessageSendEventZ get_and_clear_pending_msg_events_jcall(const void* this_arg) {
3049         LDKMessageSendEventsProvider_JCalls *j_calls = (LDKMessageSendEventsProvider_JCalls*) this_arg;
3050         //TODO: jobject obj = get object we can call against on j_calls->o
3051         uint32_tArray arg; // TODO: Call get_and_clear_pending_msg_events on j_calls with instance obj, returning an object);
3052         LDKCVec_MessageSendEventZ arg_constr;
3053         arg_constr.datalen = arg.len;
3054         if (arg_constr.datalen > 0)
3055                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKMessageSendEvent), "LDKCVec_MessageSendEventZ Elements");
3056         else
3057                 arg_constr.data = NULL;
3058         uint32_t* arg_vals = (uint32_t*) arg.ptr;
3059         for (size_t s = 0; s < arg_constr.datalen; s++) {
3060                 uint32_t arr_conv_18 = arg_vals[s];
3061                 LDKMessageSendEvent arr_conv_18_conv = *(LDKMessageSendEvent*)arr_conv_18;
3062                 FREE((void*)arr_conv_18);
3063                 arg_constr.data[s] = arr_conv_18_conv;
3064         }
3065         return arg_constr;
3066 }
3067 static void* LDKMessageSendEventsProvider_JCalls_clone(const void* this_arg) {
3068         LDKMessageSendEventsProvider_JCalls *j_calls = (LDKMessageSendEventsProvider_JCalls*) this_arg;
3069         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
3070         return (void*) this_arg;
3071 }
3072 static inline LDKMessageSendEventsProvider LDKMessageSendEventsProvider_init (void* ctx_TODO, /*TODO: JS Object Reference */void* o) {
3073         LDKMessageSendEventsProvider_JCalls *calls = MALLOC(sizeof(LDKMessageSendEventsProvider_JCalls), "LDKMessageSendEventsProvider_JCalls");
3074         atomic_init(&calls->refcnt, 1);
3075         //TODO: Assign calls->o from o
3076
3077         LDKMessageSendEventsProvider ret = {
3078                 .this_arg = (void*) calls,
3079                 .get_and_clear_pending_msg_events = get_and_clear_pending_msg_events_jcall,
3080                 .free = LDKMessageSendEventsProvider_JCalls_free,
3081         };
3082         return ret;
3083 }
3084 long LDKMessageSendEventsProvider_1new (void* ctx_TODO, /*TODO: JS Object Reference */void* o) {
3085         LDKMessageSendEventsProvider *res_ptr = MALLOC(sizeof(LDKMessageSendEventsProvider), "LDKMessageSendEventsProvider");
3086         *res_ptr = LDKMessageSendEventsProvider_init(NULL, o);
3087         return (long)res_ptr;
3088 }
3089 uint32_tArray MessageSendEventsProvider_1get_1and_1clear_1pending_1msg_1events(void* ctx_TODO, uint32_t this_arg) {
3090         LDKMessageSendEventsProvider* this_arg_conv = (LDKMessageSendEventsProvider*)this_arg;
3091         LDKCVec_MessageSendEventZ ret_var = (this_arg_conv->get_and_clear_pending_msg_events)(this_arg_conv->this_arg);
3092         uint32_tArray ret_arr = { .len = ret_var.datalen, .ptr = MALLOC(ret_var.datalen * sizeof(int32_t), "Native uint32_tArray Bytes") };
3093         uint32_t *ret_arr_ptr = (uint32_t*)ret_arr.ptr;
3094         for (size_t s = 0; s < ret_var.datalen; s++) {
3095                 LDKMessageSendEvent *arr_conv_18_copy = MALLOC(sizeof(LDKMessageSendEvent), "LDKMessageSendEvent");
3096                 *arr_conv_18_copy = MessageSendEvent_clone(&ret_var.data[s]);
3097                 long arr_conv_18_ref = (long)arr_conv_18_copy;
3098                 ret_arr_ptr[s] = arr_conv_18_ref;
3099         }
3100         FREE(ret_var.data);
3101         return ret_arr;
3102 }
3103
3104 typedef struct LDKEventsProvider_JCalls {
3105         atomic_size_t refcnt;
3106         // TODO: Object pointer o;
3107         // TODO: Some kind of method pointer get_and_clear_pending_events_meth;
3108 } LDKEventsProvider_JCalls;
3109 static void LDKEventsProvider_JCalls_free(void* this_arg) {
3110         LDKEventsProvider_JCalls *j_calls = (LDKEventsProvider_JCalls*) this_arg;
3111         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
3112                 // TODO: do any release required for j_calls->o (refcnt-- in java, but may be redundant)
3113                 FREE(j_calls);
3114         }
3115 }
3116 LDKCVec_EventZ get_and_clear_pending_events_jcall(const void* this_arg) {
3117         LDKEventsProvider_JCalls *j_calls = (LDKEventsProvider_JCalls*) this_arg;
3118         //TODO: jobject obj = get object we can call against on j_calls->o
3119         uint32_tArray arg; // TODO: Call get_and_clear_pending_events on j_calls with instance obj, returning an object);
3120         LDKCVec_EventZ arg_constr;
3121         arg_constr.datalen = arg.len;
3122         if (arg_constr.datalen > 0)
3123                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKEvent), "LDKCVec_EventZ Elements");
3124         else
3125                 arg_constr.data = NULL;
3126         uint32_t* arg_vals = (uint32_t*) arg.ptr;
3127         for (size_t h = 0; h < arg_constr.datalen; h++) {
3128                 uint32_t arr_conv_7 = arg_vals[h];
3129                 LDKEvent arr_conv_7_conv = *(LDKEvent*)arr_conv_7;
3130                 FREE((void*)arr_conv_7);
3131                 arg_constr.data[h] = arr_conv_7_conv;
3132         }
3133         return arg_constr;
3134 }
3135 static void* LDKEventsProvider_JCalls_clone(const void* this_arg) {
3136         LDKEventsProvider_JCalls *j_calls = (LDKEventsProvider_JCalls*) this_arg;
3137         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
3138         return (void*) this_arg;
3139 }
3140 static inline LDKEventsProvider LDKEventsProvider_init (void* ctx_TODO, /*TODO: JS Object Reference */void* o) {
3141         LDKEventsProvider_JCalls *calls = MALLOC(sizeof(LDKEventsProvider_JCalls), "LDKEventsProvider_JCalls");
3142         atomic_init(&calls->refcnt, 1);
3143         //TODO: Assign calls->o from o
3144
3145         LDKEventsProvider ret = {
3146                 .this_arg = (void*) calls,
3147                 .get_and_clear_pending_events = get_and_clear_pending_events_jcall,
3148                 .free = LDKEventsProvider_JCalls_free,
3149         };
3150         return ret;
3151 }
3152 long LDKEventsProvider_1new (void* ctx_TODO, /*TODO: JS Object Reference */void* o) {
3153         LDKEventsProvider *res_ptr = MALLOC(sizeof(LDKEventsProvider), "LDKEventsProvider");
3154         *res_ptr = LDKEventsProvider_init(NULL, o);
3155         return (long)res_ptr;
3156 }
3157 uint32_tArray EventsProvider_1get_1and_1clear_1pending_1events(void* ctx_TODO, uint32_t this_arg) {
3158         LDKEventsProvider* this_arg_conv = (LDKEventsProvider*)this_arg;
3159         LDKCVec_EventZ ret_var = (this_arg_conv->get_and_clear_pending_events)(this_arg_conv->this_arg);
3160         uint32_tArray ret_arr = { .len = ret_var.datalen, .ptr = MALLOC(ret_var.datalen * sizeof(int32_t), "Native uint32_tArray Bytes") };
3161         uint32_t *ret_arr_ptr = (uint32_t*)ret_arr.ptr;
3162         for (size_t h = 0; h < ret_var.datalen; h++) {
3163                 LDKEvent *arr_conv_7_copy = MALLOC(sizeof(LDKEvent), "LDKEvent");
3164                 *arr_conv_7_copy = Event_clone(&ret_var.data[h]);
3165                 long arr_conv_7_ref = (long)arr_conv_7_copy;
3166                 ret_arr_ptr[h] = arr_conv_7_ref;
3167         }
3168         FREE(ret_var.data);
3169         return ret_arr;
3170 }
3171
3172 typedef struct LDKAccess_JCalls {
3173         atomic_size_t refcnt;
3174         // TODO: Object pointer o;
3175         // TODO: Some kind of method pointer get_utxo_meth;
3176 } LDKAccess_JCalls;
3177 static void LDKAccess_JCalls_free(void* this_arg) {
3178         LDKAccess_JCalls *j_calls = (LDKAccess_JCalls*) this_arg;
3179         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
3180                 // TODO: do any release required for j_calls->o (refcnt-- in java, but may be redundant)
3181                 FREE(j_calls);
3182         }
3183 }
3184 LDKCResult_TxOutAccessErrorZ get_utxo_jcall(const void* this_arg, const uint8_t (* genesis_hash)[32], uint64_t short_channel_id) {
3185         LDKAccess_JCalls *j_calls = (LDKAccess_JCalls*) this_arg;
3186         int8_tArray genesis_hash_arr = { .len = 32, .ptr = MALLOC(32, "Native int8_tArray Bytes") };
3187         memcpy(genesis_hash_arr.ptr, *genesis_hash, 32);
3188         //TODO: jobject obj = get object we can call against on j_calls->o
3189         LDKCResult_TxOutAccessErrorZ* ret; // TODO: Call get_utxo on j_calls with instance obj, returning a pointer, genesis_hash_arr, short_channel_id);
3190         LDKCResult_TxOutAccessErrorZ ret_conv = *(LDKCResult_TxOutAccessErrorZ*)ret;
3191         FREE((void*)ret);
3192         return ret_conv;
3193 }
3194 static void* LDKAccess_JCalls_clone(const void* this_arg) {
3195         LDKAccess_JCalls *j_calls = (LDKAccess_JCalls*) this_arg;
3196         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
3197         return (void*) this_arg;
3198 }
3199 static inline LDKAccess LDKAccess_init (void* ctx_TODO, /*TODO: JS Object Reference */void* o) {
3200         LDKAccess_JCalls *calls = MALLOC(sizeof(LDKAccess_JCalls), "LDKAccess_JCalls");
3201         atomic_init(&calls->refcnt, 1);
3202         //TODO: Assign calls->o from o
3203
3204         LDKAccess ret = {
3205                 .this_arg = (void*) calls,
3206                 .get_utxo = get_utxo_jcall,
3207                 .free = LDKAccess_JCalls_free,
3208         };
3209         return ret;
3210 }
3211 long LDKAccess_1new (void* ctx_TODO, /*TODO: JS Object Reference */void* o) {
3212         LDKAccess *res_ptr = MALLOC(sizeof(LDKAccess), "LDKAccess");
3213         *res_ptr = LDKAccess_init(NULL, o);
3214         return (long)res_ptr;
3215 }
3216 uint32_t Access_1get_1utxo(void* ctx_TODO, uint32_t this_arg, int8_tArray genesis_hash, int64_t short_channel_id) {
3217         LDKAccess* this_arg_conv = (LDKAccess*)this_arg;
3218         unsigned char genesis_hash_arr[32];
3219         CHECK(genesis_hash.len == 32);
3220         memcpy(genesis_hash_arr, genesis_hash.ptr, 32);
3221         unsigned char (*genesis_hash_ref)[32] = &genesis_hash_arr;
3222         LDKCResult_TxOutAccessErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_TxOutAccessErrorZ), "LDKCResult_TxOutAccessErrorZ");
3223         *ret_conv = (this_arg_conv->get_utxo)(this_arg_conv->this_arg, genesis_hash_ref, short_channel_id);
3224         return (long)ret_conv;
3225 }
3226
3227 typedef struct LDKFilter_JCalls {
3228         atomic_size_t refcnt;
3229         // TODO: Object pointer o;
3230         // TODO: Some kind of method pointer register_tx_meth;
3231         // TODO: Some kind of method pointer register_output_meth;
3232 } LDKFilter_JCalls;
3233 static void LDKFilter_JCalls_free(void* this_arg) {
3234         LDKFilter_JCalls *j_calls = (LDKFilter_JCalls*) this_arg;
3235         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
3236                 // TODO: do any release required for j_calls->o (refcnt-- in java, but may be redundant)
3237                 FREE(j_calls);
3238         }
3239 }
3240 void register_tx_jcall(const void* this_arg, const uint8_t (* txid)[32], LDKu8slice script_pubkey) {
3241         LDKFilter_JCalls *j_calls = (LDKFilter_JCalls*) this_arg;
3242         int8_tArray txid_arr = { .len = 32, .ptr = MALLOC(32, "Native int8_tArray Bytes") };
3243         memcpy(txid_arr.ptr, *txid, 32);
3244         LDKu8slice script_pubkey_var = script_pubkey;
3245         int8_tArray script_pubkey_arr = { .len = script_pubkey_var.datalen, .ptr = MALLOC(script_pubkey_var.datalen, "Native int8_tArray Bytes") };
3246         memcpy(script_pubkey_arr.ptr, script_pubkey_var.data, script_pubkey_var.datalen);
3247         //TODO: jobject obj = get object we can call against on j_calls->o
3248         return; //TODO: Call register_tx on j_calls with instance obj, txid_arr, script_pubkey_arr);
3249 }
3250 void register_output_jcall(const void* this_arg, const LDKOutPoint * outpoint, LDKu8slice script_pubkey) {
3251         LDKFilter_JCalls *j_calls = (LDKFilter_JCalls*) this_arg;
3252         LDKOutPoint outpoint_var = *outpoint;
3253         if (outpoint->inner != NULL)
3254                 outpoint_var = OutPoint_clone(outpoint);
3255         CHECK((((long)outpoint_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3256         CHECK((((long)&outpoint_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3257         long outpoint_ref = (long)outpoint_var.inner;
3258         if (outpoint_var.is_owned) {
3259                 outpoint_ref |= 1;
3260         }
3261         LDKu8slice script_pubkey_var = script_pubkey;
3262         int8_tArray script_pubkey_arr = { .len = script_pubkey_var.datalen, .ptr = MALLOC(script_pubkey_var.datalen, "Native int8_tArray Bytes") };
3263         memcpy(script_pubkey_arr.ptr, script_pubkey_var.data, script_pubkey_var.datalen);
3264         //TODO: jobject obj = get object we can call against on j_calls->o
3265         return; //TODO: Call register_output on j_calls with instance obj, outpoint_ref, script_pubkey_arr);
3266 }
3267 static void* LDKFilter_JCalls_clone(const void* this_arg) {
3268         LDKFilter_JCalls *j_calls = (LDKFilter_JCalls*) this_arg;
3269         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
3270         return (void*) this_arg;
3271 }
3272 static inline LDKFilter LDKFilter_init (void* ctx_TODO, /*TODO: JS Object Reference */void* o) {
3273         LDKFilter_JCalls *calls = MALLOC(sizeof(LDKFilter_JCalls), "LDKFilter_JCalls");
3274         atomic_init(&calls->refcnt, 1);
3275         //TODO: Assign calls->o from o
3276
3277         LDKFilter ret = {
3278                 .this_arg = (void*) calls,
3279                 .register_tx = register_tx_jcall,
3280                 .register_output = register_output_jcall,
3281                 .free = LDKFilter_JCalls_free,
3282         };
3283         return ret;
3284 }
3285 long LDKFilter_1new (void* ctx_TODO, /*TODO: JS Object Reference */void* o) {
3286         LDKFilter *res_ptr = MALLOC(sizeof(LDKFilter), "LDKFilter");
3287         *res_ptr = LDKFilter_init(NULL, o);
3288         return (long)res_ptr;
3289 }
3290 void Filter_1register_1tx(void* ctx_TODO, uint32_t this_arg, int8_tArray txid, int8_tArray script_pubkey) {
3291         LDKFilter* this_arg_conv = (LDKFilter*)this_arg;
3292         unsigned char txid_arr[32];
3293         CHECK(txid.len == 32);
3294         memcpy(txid_arr, txid.ptr, 32);
3295         unsigned char (*txid_ref)[32] = &txid_arr;
3296         LDKu8slice script_pubkey_ref;
3297         script_pubkey_ref.datalen = script_pubkey.len;
3298         script_pubkey_ref.data = script_pubkey.ptr;
3299         (this_arg_conv->register_tx)(this_arg_conv->this_arg, txid_ref, script_pubkey_ref);
3300 }
3301
3302 void Filter_1register_1output(void* ctx_TODO, uint32_t this_arg, uint32_t outpoint, int8_tArray script_pubkey) {
3303         LDKFilter* this_arg_conv = (LDKFilter*)this_arg;
3304         LDKOutPoint outpoint_conv;
3305         outpoint_conv.inner = (void*)(outpoint & (~1));
3306         outpoint_conv.is_owned = false;
3307         LDKu8slice script_pubkey_ref;
3308         script_pubkey_ref.datalen = script_pubkey.len;
3309         script_pubkey_ref.data = script_pubkey.ptr;
3310         (this_arg_conv->register_output)(this_arg_conv->this_arg, &outpoint_conv, script_pubkey_ref);
3311 }
3312
3313 typedef struct LDKPersist_JCalls {
3314         atomic_size_t refcnt;
3315         // TODO: Object pointer o;
3316         // TODO: Some kind of method pointer persist_new_channel_meth;
3317         // TODO: Some kind of method pointer update_persisted_channel_meth;
3318 } LDKPersist_JCalls;
3319 static void LDKPersist_JCalls_free(void* this_arg) {
3320         LDKPersist_JCalls *j_calls = (LDKPersist_JCalls*) this_arg;
3321         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
3322                 // TODO: do any release required for j_calls->o (refcnt-- in java, but may be redundant)
3323                 FREE(j_calls);
3324         }
3325 }
3326 LDKCResult_NoneChannelMonitorUpdateErrZ persist_new_channel_jcall(const void* this_arg, LDKOutPoint id, const LDKChannelMonitor * data) {
3327         LDKPersist_JCalls *j_calls = (LDKPersist_JCalls*) this_arg;
3328         LDKOutPoint id_var = id;
3329         CHECK((((long)id_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3330         CHECK((((long)&id_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3331         long id_ref = (long)id_var.inner;
3332         if (id_var.is_owned) {
3333                 id_ref |= 1;
3334         }
3335         LDKChannelMonitor data_var = *data;
3336         // Warning: we may need a move here but can't clone!
3337         CHECK((((long)data_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3338         CHECK((((long)&data_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3339         long data_ref = (long)data_var.inner;
3340         if (data_var.is_owned) {
3341                 data_ref |= 1;
3342         }
3343         //TODO: jobject obj = get object we can call against on j_calls->o
3344         LDKCResult_NoneChannelMonitorUpdateErrZ* ret; // TODO: Call persist_new_channel on j_calls with instance obj, returning a pointer, id_ref, data_ref);
3345         LDKCResult_NoneChannelMonitorUpdateErrZ ret_conv = *(LDKCResult_NoneChannelMonitorUpdateErrZ*)ret;
3346         FREE((void*)ret);
3347         return ret_conv;
3348 }
3349 LDKCResult_NoneChannelMonitorUpdateErrZ update_persisted_channel_jcall(const void* this_arg, LDKOutPoint id, const LDKChannelMonitorUpdate * update, const LDKChannelMonitor * data) {
3350         LDKPersist_JCalls *j_calls = (LDKPersist_JCalls*) this_arg;
3351         LDKOutPoint id_var = id;
3352         CHECK((((long)id_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3353         CHECK((((long)&id_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3354         long id_ref = (long)id_var.inner;
3355         if (id_var.is_owned) {
3356                 id_ref |= 1;
3357         }
3358         LDKChannelMonitorUpdate update_var = *update;
3359         if (update->inner != NULL)
3360                 update_var = ChannelMonitorUpdate_clone(update);
3361         CHECK((((long)update_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3362         CHECK((((long)&update_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3363         long update_ref = (long)update_var.inner;
3364         if (update_var.is_owned) {
3365                 update_ref |= 1;
3366         }
3367         LDKChannelMonitor data_var = *data;
3368         // Warning: we may need a move here but can't clone!
3369         CHECK((((long)data_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3370         CHECK((((long)&data_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3371         long data_ref = (long)data_var.inner;
3372         if (data_var.is_owned) {
3373                 data_ref |= 1;
3374         }
3375         //TODO: jobject obj = get object we can call against on j_calls->o
3376         LDKCResult_NoneChannelMonitorUpdateErrZ* ret; // TODO: Call update_persisted_channel on j_calls with instance obj, returning a pointer, id_ref, update_ref, data_ref);
3377         LDKCResult_NoneChannelMonitorUpdateErrZ ret_conv = *(LDKCResult_NoneChannelMonitorUpdateErrZ*)ret;
3378         FREE((void*)ret);
3379         return ret_conv;
3380 }
3381 static void* LDKPersist_JCalls_clone(const void* this_arg) {
3382         LDKPersist_JCalls *j_calls = (LDKPersist_JCalls*) this_arg;
3383         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
3384         return (void*) this_arg;
3385 }
3386 static inline LDKPersist LDKPersist_init (void* ctx_TODO, /*TODO: JS Object Reference */void* o) {
3387         LDKPersist_JCalls *calls = MALLOC(sizeof(LDKPersist_JCalls), "LDKPersist_JCalls");
3388         atomic_init(&calls->refcnt, 1);
3389         //TODO: Assign calls->o from o
3390
3391         LDKPersist ret = {
3392                 .this_arg = (void*) calls,
3393                 .persist_new_channel = persist_new_channel_jcall,
3394                 .update_persisted_channel = update_persisted_channel_jcall,
3395                 .free = LDKPersist_JCalls_free,
3396         };
3397         return ret;
3398 }
3399 long LDKPersist_1new (void* ctx_TODO, /*TODO: JS Object Reference */void* o) {
3400         LDKPersist *res_ptr = MALLOC(sizeof(LDKPersist), "LDKPersist");
3401         *res_ptr = LDKPersist_init(NULL, o);
3402         return (long)res_ptr;
3403 }
3404 uint32_t Persist_1persist_1new_1channel(void* ctx_TODO, uint32_t this_arg, uint32_t id, uint32_t data) {
3405         LDKPersist* this_arg_conv = (LDKPersist*)this_arg;
3406         LDKOutPoint id_conv;
3407         id_conv.inner = (void*)(id & (~1));
3408         id_conv.is_owned = (id & 1) || (id == 0);
3409         if (id_conv.inner != NULL)
3410                 id_conv = OutPoint_clone(&id_conv);
3411         LDKChannelMonitor data_conv;
3412         data_conv.inner = (void*)(data & (~1));
3413         data_conv.is_owned = false;
3414         LDKCResult_NoneChannelMonitorUpdateErrZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneChannelMonitorUpdateErrZ), "LDKCResult_NoneChannelMonitorUpdateErrZ");
3415         *ret_conv = (this_arg_conv->persist_new_channel)(this_arg_conv->this_arg, id_conv, &data_conv);
3416         return (long)ret_conv;
3417 }
3418
3419 uint32_t Persist_1update_1persisted_1channel(void* ctx_TODO, uint32_t this_arg, uint32_t id, uint32_t update, uint32_t data) {
3420         LDKPersist* this_arg_conv = (LDKPersist*)this_arg;
3421         LDKOutPoint id_conv;
3422         id_conv.inner = (void*)(id & (~1));
3423         id_conv.is_owned = (id & 1) || (id == 0);
3424         if (id_conv.inner != NULL)
3425                 id_conv = OutPoint_clone(&id_conv);
3426         LDKChannelMonitorUpdate update_conv;
3427         update_conv.inner = (void*)(update & (~1));
3428         update_conv.is_owned = false;
3429         LDKChannelMonitor data_conv;
3430         data_conv.inner = (void*)(data & (~1));
3431         data_conv.is_owned = false;
3432         LDKCResult_NoneChannelMonitorUpdateErrZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneChannelMonitorUpdateErrZ), "LDKCResult_NoneChannelMonitorUpdateErrZ");
3433         *ret_conv = (this_arg_conv->update_persisted_channel)(this_arg_conv->this_arg, id_conv, &update_conv, &data_conv);
3434         return (long)ret_conv;
3435 }
3436
3437 typedef struct LDKChannelMessageHandler_JCalls {
3438         atomic_size_t refcnt;
3439         // TODO: Object pointer o;
3440         LDKMessageSendEventsProvider_JCalls* MessageSendEventsProvider;
3441         // TODO: Some kind of method pointer handle_open_channel_meth;
3442         // TODO: Some kind of method pointer handle_accept_channel_meth;
3443         // TODO: Some kind of method pointer handle_funding_created_meth;
3444         // TODO: Some kind of method pointer handle_funding_signed_meth;
3445         // TODO: Some kind of method pointer handle_funding_locked_meth;
3446         // TODO: Some kind of method pointer handle_shutdown_meth;
3447         // TODO: Some kind of method pointer handle_closing_signed_meth;
3448         // TODO: Some kind of method pointer handle_update_add_htlc_meth;
3449         // TODO: Some kind of method pointer handle_update_fulfill_htlc_meth;
3450         // TODO: Some kind of method pointer handle_update_fail_htlc_meth;
3451         // TODO: Some kind of method pointer handle_update_fail_malformed_htlc_meth;
3452         // TODO: Some kind of method pointer handle_commitment_signed_meth;
3453         // TODO: Some kind of method pointer handle_revoke_and_ack_meth;
3454         // TODO: Some kind of method pointer handle_update_fee_meth;
3455         // TODO: Some kind of method pointer handle_announcement_signatures_meth;
3456         // TODO: Some kind of method pointer peer_disconnected_meth;
3457         // TODO: Some kind of method pointer peer_connected_meth;
3458         // TODO: Some kind of method pointer handle_channel_reestablish_meth;
3459         // TODO: Some kind of method pointer handle_error_meth;
3460 } LDKChannelMessageHandler_JCalls;
3461 static void LDKChannelMessageHandler_JCalls_free(void* this_arg) {
3462         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3463         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
3464                 // TODO: do any release required for j_calls->o (refcnt-- in java, but may be redundant)
3465                 FREE(j_calls);
3466         }
3467 }
3468 void handle_open_channel_jcall(const void* this_arg, LDKPublicKey their_node_id, LDKInitFeatures their_features, const LDKOpenChannel * msg) {
3469         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3470         int8_tArray their_node_id_arr = { .len = 33, .ptr = MALLOC(33, "Native int8_tArray Bytes") };
3471         memcpy(their_node_id_arr.ptr, their_node_id.compressed_form, 33);
3472         LDKInitFeatures their_features_var = their_features;
3473         CHECK((((long)their_features_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3474         CHECK((((long)&their_features_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3475         long their_features_ref = (long)their_features_var.inner;
3476         if (their_features_var.is_owned) {
3477                 their_features_ref |= 1;
3478         }
3479         LDKOpenChannel msg_var = *msg;
3480         if (msg->inner != NULL)
3481                 msg_var = OpenChannel_clone(msg);
3482         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3483         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3484         long msg_ref = (long)msg_var.inner;
3485         if (msg_var.is_owned) {
3486                 msg_ref |= 1;
3487         }
3488         //TODO: jobject obj = get object we can call against on j_calls->o
3489         return; //TODO: Call handle_open_channel on j_calls with instance obj, their_node_id_arr, their_features_ref, msg_ref);
3490 }
3491 void handle_accept_channel_jcall(const void* this_arg, LDKPublicKey their_node_id, LDKInitFeatures their_features, const LDKAcceptChannel * msg) {
3492         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3493         int8_tArray their_node_id_arr = { .len = 33, .ptr = MALLOC(33, "Native int8_tArray Bytes") };
3494         memcpy(their_node_id_arr.ptr, their_node_id.compressed_form, 33);
3495         LDKInitFeatures their_features_var = their_features;
3496         CHECK((((long)their_features_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3497         CHECK((((long)&their_features_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3498         long their_features_ref = (long)their_features_var.inner;
3499         if (their_features_var.is_owned) {
3500                 their_features_ref |= 1;
3501         }
3502         LDKAcceptChannel msg_var = *msg;
3503         if (msg->inner != NULL)
3504                 msg_var = AcceptChannel_clone(msg);
3505         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3506         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3507         long msg_ref = (long)msg_var.inner;
3508         if (msg_var.is_owned) {
3509                 msg_ref |= 1;
3510         }
3511         //TODO: jobject obj = get object we can call against on j_calls->o
3512         return; //TODO: Call handle_accept_channel on j_calls with instance obj, their_node_id_arr, their_features_ref, msg_ref);
3513 }
3514 void handle_funding_created_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKFundingCreated * msg) {
3515         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3516         int8_tArray their_node_id_arr = { .len = 33, .ptr = MALLOC(33, "Native int8_tArray Bytes") };
3517         memcpy(their_node_id_arr.ptr, their_node_id.compressed_form, 33);
3518         LDKFundingCreated msg_var = *msg;
3519         if (msg->inner != NULL)
3520                 msg_var = FundingCreated_clone(msg);
3521         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3522         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3523         long msg_ref = (long)msg_var.inner;
3524         if (msg_var.is_owned) {
3525                 msg_ref |= 1;
3526         }
3527         //TODO: jobject obj = get object we can call against on j_calls->o
3528         return; //TODO: Call handle_funding_created on j_calls with instance obj, their_node_id_arr, msg_ref);
3529 }
3530 void handle_funding_signed_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKFundingSigned * msg) {
3531         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3532         int8_tArray their_node_id_arr = { .len = 33, .ptr = MALLOC(33, "Native int8_tArray Bytes") };
3533         memcpy(their_node_id_arr.ptr, their_node_id.compressed_form, 33);
3534         LDKFundingSigned msg_var = *msg;
3535         if (msg->inner != NULL)
3536                 msg_var = FundingSigned_clone(msg);
3537         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3538         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3539         long msg_ref = (long)msg_var.inner;
3540         if (msg_var.is_owned) {
3541                 msg_ref |= 1;
3542         }
3543         //TODO: jobject obj = get object we can call against on j_calls->o
3544         return; //TODO: Call handle_funding_signed on j_calls with instance obj, their_node_id_arr, msg_ref);
3545 }
3546 void handle_funding_locked_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKFundingLocked * msg) {
3547         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3548         int8_tArray their_node_id_arr = { .len = 33, .ptr = MALLOC(33, "Native int8_tArray Bytes") };
3549         memcpy(their_node_id_arr.ptr, their_node_id.compressed_form, 33);
3550         LDKFundingLocked msg_var = *msg;
3551         if (msg->inner != NULL)
3552                 msg_var = FundingLocked_clone(msg);
3553         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3554         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3555         long msg_ref = (long)msg_var.inner;
3556         if (msg_var.is_owned) {
3557                 msg_ref |= 1;
3558         }
3559         //TODO: jobject obj = get object we can call against on j_calls->o
3560         return; //TODO: Call handle_funding_locked on j_calls with instance obj, their_node_id_arr, msg_ref);
3561 }
3562 void handle_shutdown_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKShutdown * msg) {
3563         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3564         int8_tArray their_node_id_arr = { .len = 33, .ptr = MALLOC(33, "Native int8_tArray Bytes") };
3565         memcpy(their_node_id_arr.ptr, their_node_id.compressed_form, 33);
3566         LDKShutdown msg_var = *msg;
3567         if (msg->inner != NULL)
3568                 msg_var = Shutdown_clone(msg);
3569         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3570         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3571         long msg_ref = (long)msg_var.inner;
3572         if (msg_var.is_owned) {
3573                 msg_ref |= 1;
3574         }
3575         //TODO: jobject obj = get object we can call against on j_calls->o
3576         return; //TODO: Call handle_shutdown on j_calls with instance obj, their_node_id_arr, msg_ref);
3577 }
3578 void handle_closing_signed_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKClosingSigned * msg) {
3579         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3580         int8_tArray their_node_id_arr = { .len = 33, .ptr = MALLOC(33, "Native int8_tArray Bytes") };
3581         memcpy(their_node_id_arr.ptr, their_node_id.compressed_form, 33);
3582         LDKClosingSigned msg_var = *msg;
3583         if (msg->inner != NULL)
3584                 msg_var = ClosingSigned_clone(msg);
3585         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3586         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3587         long msg_ref = (long)msg_var.inner;
3588         if (msg_var.is_owned) {
3589                 msg_ref |= 1;
3590         }
3591         //TODO: jobject obj = get object we can call against on j_calls->o
3592         return; //TODO: Call handle_closing_signed on j_calls with instance obj, their_node_id_arr, msg_ref);
3593 }
3594 void handle_update_add_htlc_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKUpdateAddHTLC * msg) {
3595         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3596         int8_tArray their_node_id_arr = { .len = 33, .ptr = MALLOC(33, "Native int8_tArray Bytes") };
3597         memcpy(their_node_id_arr.ptr, their_node_id.compressed_form, 33);
3598         LDKUpdateAddHTLC msg_var = *msg;
3599         if (msg->inner != NULL)
3600                 msg_var = UpdateAddHTLC_clone(msg);
3601         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3602         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3603         long msg_ref = (long)msg_var.inner;
3604         if (msg_var.is_owned) {
3605                 msg_ref |= 1;
3606         }
3607         //TODO: jobject obj = get object we can call against on j_calls->o
3608         return; //TODO: Call handle_update_add_htlc on j_calls with instance obj, their_node_id_arr, msg_ref);
3609 }
3610 void handle_update_fulfill_htlc_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKUpdateFulfillHTLC * msg) {
3611         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3612         int8_tArray their_node_id_arr = { .len = 33, .ptr = MALLOC(33, "Native int8_tArray Bytes") };
3613         memcpy(their_node_id_arr.ptr, their_node_id.compressed_form, 33);
3614         LDKUpdateFulfillHTLC msg_var = *msg;
3615         if (msg->inner != NULL)
3616                 msg_var = UpdateFulfillHTLC_clone(msg);
3617         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3618         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3619         long msg_ref = (long)msg_var.inner;
3620         if (msg_var.is_owned) {
3621                 msg_ref |= 1;
3622         }
3623         //TODO: jobject obj = get object we can call against on j_calls->o
3624         return; //TODO: Call handle_update_fulfill_htlc on j_calls with instance obj, their_node_id_arr, msg_ref);
3625 }
3626 void handle_update_fail_htlc_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKUpdateFailHTLC * msg) {
3627         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3628         int8_tArray their_node_id_arr = { .len = 33, .ptr = MALLOC(33, "Native int8_tArray Bytes") };
3629         memcpy(their_node_id_arr.ptr, their_node_id.compressed_form, 33);
3630         LDKUpdateFailHTLC msg_var = *msg;
3631         if (msg->inner != NULL)
3632                 msg_var = UpdateFailHTLC_clone(msg);
3633         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3634         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3635         long msg_ref = (long)msg_var.inner;
3636         if (msg_var.is_owned) {
3637                 msg_ref |= 1;
3638         }
3639         //TODO: jobject obj = get object we can call against on j_calls->o
3640         return; //TODO: Call handle_update_fail_htlc on j_calls with instance obj, their_node_id_arr, msg_ref);
3641 }
3642 void handle_update_fail_malformed_htlc_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKUpdateFailMalformedHTLC * msg) {
3643         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3644         int8_tArray their_node_id_arr = { .len = 33, .ptr = MALLOC(33, "Native int8_tArray Bytes") };
3645         memcpy(their_node_id_arr.ptr, their_node_id.compressed_form, 33);
3646         LDKUpdateFailMalformedHTLC msg_var = *msg;
3647         if (msg->inner != NULL)
3648                 msg_var = UpdateFailMalformedHTLC_clone(msg);
3649         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3650         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3651         long msg_ref = (long)msg_var.inner;
3652         if (msg_var.is_owned) {
3653                 msg_ref |= 1;
3654         }
3655         //TODO: jobject obj = get object we can call against on j_calls->o
3656         return; //TODO: Call handle_update_fail_malformed_htlc on j_calls with instance obj, their_node_id_arr, msg_ref);
3657 }
3658 void handle_commitment_signed_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKCommitmentSigned * msg) {
3659         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3660         int8_tArray their_node_id_arr = { .len = 33, .ptr = MALLOC(33, "Native int8_tArray Bytes") };
3661         memcpy(their_node_id_arr.ptr, their_node_id.compressed_form, 33);
3662         LDKCommitmentSigned msg_var = *msg;
3663         if (msg->inner != NULL)
3664                 msg_var = CommitmentSigned_clone(msg);
3665         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3666         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3667         long msg_ref = (long)msg_var.inner;
3668         if (msg_var.is_owned) {
3669                 msg_ref |= 1;
3670         }
3671         //TODO: jobject obj = get object we can call against on j_calls->o
3672         return; //TODO: Call handle_commitment_signed on j_calls with instance obj, their_node_id_arr, msg_ref);
3673 }
3674 void handle_revoke_and_ack_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKRevokeAndACK * msg) {
3675         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3676         int8_tArray their_node_id_arr = { .len = 33, .ptr = MALLOC(33, "Native int8_tArray Bytes") };
3677         memcpy(their_node_id_arr.ptr, their_node_id.compressed_form, 33);
3678         LDKRevokeAndACK msg_var = *msg;
3679         if (msg->inner != NULL)
3680                 msg_var = RevokeAndACK_clone(msg);
3681         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3682         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3683         long msg_ref = (long)msg_var.inner;
3684         if (msg_var.is_owned) {
3685                 msg_ref |= 1;
3686         }
3687         //TODO: jobject obj = get object we can call against on j_calls->o
3688         return; //TODO: Call handle_revoke_and_ack on j_calls with instance obj, their_node_id_arr, msg_ref);
3689 }
3690 void handle_update_fee_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKUpdateFee * msg) {
3691         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3692         int8_tArray their_node_id_arr = { .len = 33, .ptr = MALLOC(33, "Native int8_tArray Bytes") };
3693         memcpy(their_node_id_arr.ptr, their_node_id.compressed_form, 33);
3694         LDKUpdateFee msg_var = *msg;
3695         if (msg->inner != NULL)
3696                 msg_var = UpdateFee_clone(msg);
3697         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3698         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3699         long msg_ref = (long)msg_var.inner;
3700         if (msg_var.is_owned) {
3701                 msg_ref |= 1;
3702         }
3703         //TODO: jobject obj = get object we can call against on j_calls->o
3704         return; //TODO: Call handle_update_fee on j_calls with instance obj, their_node_id_arr, msg_ref);
3705 }
3706 void handle_announcement_signatures_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKAnnouncementSignatures * msg) {
3707         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3708         int8_tArray their_node_id_arr = { .len = 33, .ptr = MALLOC(33, "Native int8_tArray Bytes") };
3709         memcpy(their_node_id_arr.ptr, their_node_id.compressed_form, 33);
3710         LDKAnnouncementSignatures msg_var = *msg;
3711         if (msg->inner != NULL)
3712                 msg_var = AnnouncementSignatures_clone(msg);
3713         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3714         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3715         long msg_ref = (long)msg_var.inner;
3716         if (msg_var.is_owned) {
3717                 msg_ref |= 1;
3718         }
3719         //TODO: jobject obj = get object we can call against on j_calls->o
3720         return; //TODO: Call handle_announcement_signatures on j_calls with instance obj, their_node_id_arr, msg_ref);
3721 }
3722 void peer_disconnected_jcall(const void* this_arg, LDKPublicKey their_node_id, bool no_connection_possible) {
3723         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3724         int8_tArray their_node_id_arr = { .len = 33, .ptr = MALLOC(33, "Native int8_tArray Bytes") };
3725         memcpy(their_node_id_arr.ptr, their_node_id.compressed_form, 33);
3726         //TODO: jobject obj = get object we can call against on j_calls->o
3727         return; //TODO: Call peer_disconnected on j_calls with instance obj, their_node_id_arr, no_connection_possible);
3728 }
3729 void peer_connected_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKInit * msg) {
3730         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3731         int8_tArray their_node_id_arr = { .len = 33, .ptr = MALLOC(33, "Native int8_tArray Bytes") };
3732         memcpy(their_node_id_arr.ptr, their_node_id.compressed_form, 33);
3733         LDKInit msg_var = *msg;
3734         if (msg->inner != NULL)
3735                 msg_var = Init_clone(msg);
3736         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3737         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3738         long msg_ref = (long)msg_var.inner;
3739         if (msg_var.is_owned) {
3740                 msg_ref |= 1;
3741         }
3742         //TODO: jobject obj = get object we can call against on j_calls->o
3743         return; //TODO: Call peer_connected on j_calls with instance obj, their_node_id_arr, msg_ref);
3744 }
3745 void handle_channel_reestablish_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKChannelReestablish * msg) {
3746         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3747         int8_tArray their_node_id_arr = { .len = 33, .ptr = MALLOC(33, "Native int8_tArray Bytes") };
3748         memcpy(their_node_id_arr.ptr, their_node_id.compressed_form, 33);
3749         LDKChannelReestablish msg_var = *msg;
3750         if (msg->inner != NULL)
3751                 msg_var = ChannelReestablish_clone(msg);
3752         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3753         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3754         long msg_ref = (long)msg_var.inner;
3755         if (msg_var.is_owned) {
3756                 msg_ref |= 1;
3757         }
3758         //TODO: jobject obj = get object we can call against on j_calls->o
3759         return; //TODO: Call handle_channel_reestablish on j_calls with instance obj, their_node_id_arr, msg_ref);
3760 }
3761 void handle_error_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKErrorMessage * msg) {
3762         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3763         int8_tArray their_node_id_arr = { .len = 33, .ptr = MALLOC(33, "Native int8_tArray Bytes") };
3764         memcpy(their_node_id_arr.ptr, their_node_id.compressed_form, 33);
3765         LDKErrorMessage msg_var = *msg;
3766         if (msg->inner != NULL)
3767                 msg_var = ErrorMessage_clone(msg);
3768         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3769         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3770         long msg_ref = (long)msg_var.inner;
3771         if (msg_var.is_owned) {
3772                 msg_ref |= 1;
3773         }
3774         //TODO: jobject obj = get object we can call against on j_calls->o
3775         return; //TODO: Call handle_error on j_calls with instance obj, their_node_id_arr, msg_ref);
3776 }
3777 static void* LDKChannelMessageHandler_JCalls_clone(const void* this_arg) {
3778         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3779         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
3780         atomic_fetch_add_explicit(&j_calls->MessageSendEventsProvider->refcnt, 1, memory_order_release);
3781         return (void*) this_arg;
3782 }
3783 static inline LDKChannelMessageHandler LDKChannelMessageHandler_init (void* ctx_TODO, /*TODO: JS Object Reference */void* o, /*TODO: JS Object Reference */void* MessageSendEventsProvider) {
3784         LDKChannelMessageHandler_JCalls *calls = MALLOC(sizeof(LDKChannelMessageHandler_JCalls), "LDKChannelMessageHandler_JCalls");
3785         atomic_init(&calls->refcnt, 1);
3786         //TODO: Assign calls->o from o
3787
3788         LDKChannelMessageHandler ret = {
3789                 .this_arg = (void*) calls,
3790                 .handle_open_channel = handle_open_channel_jcall,
3791                 .handle_accept_channel = handle_accept_channel_jcall,
3792                 .handle_funding_created = handle_funding_created_jcall,
3793                 .handle_funding_signed = handle_funding_signed_jcall,
3794                 .handle_funding_locked = handle_funding_locked_jcall,
3795                 .handle_shutdown = handle_shutdown_jcall,
3796                 .handle_closing_signed = handle_closing_signed_jcall,
3797                 .handle_update_add_htlc = handle_update_add_htlc_jcall,
3798                 .handle_update_fulfill_htlc = handle_update_fulfill_htlc_jcall,
3799                 .handle_update_fail_htlc = handle_update_fail_htlc_jcall,
3800                 .handle_update_fail_malformed_htlc = handle_update_fail_malformed_htlc_jcall,
3801                 .handle_commitment_signed = handle_commitment_signed_jcall,
3802                 .handle_revoke_and_ack = handle_revoke_and_ack_jcall,
3803                 .handle_update_fee = handle_update_fee_jcall,
3804                 .handle_announcement_signatures = handle_announcement_signatures_jcall,
3805                 .peer_disconnected = peer_disconnected_jcall,
3806                 .peer_connected = peer_connected_jcall,
3807                 .handle_channel_reestablish = handle_channel_reestablish_jcall,
3808                 .handle_error = handle_error_jcall,
3809                 .free = LDKChannelMessageHandler_JCalls_free,
3810                 .MessageSendEventsProvider = LDKMessageSendEventsProvider_init(NULL, MessageSendEventsProvider),
3811         };
3812         calls->MessageSendEventsProvider = ret.MessageSendEventsProvider.this_arg;
3813         return ret;
3814 }
3815 long LDKChannelMessageHandler_1new (void* ctx_TODO, /*TODO: JS Object Reference */void* o, /*TODO: JS Object Reference */ void* MessageSendEventsProvider) {
3816         LDKChannelMessageHandler *res_ptr = MALLOC(sizeof(LDKChannelMessageHandler), "LDKChannelMessageHandler");
3817         *res_ptr = LDKChannelMessageHandler_init(NULL, o, MessageSendEventsProvider);
3818         return (long)res_ptr;
3819 }
3820 void ChannelMessageHandler_1handle_1open_1channel(void* ctx_TODO, uint32_t this_arg, int8_tArray their_node_id, uint32_t their_features, uint32_t msg) {
3821         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
3822         LDKPublicKey their_node_id_ref;
3823         CHECK(their_node_id.len == 33);
3824         memcpy(their_node_id_ref.compressed_form, their_node_id.ptr, 33);
3825         LDKInitFeatures their_features_conv;
3826         their_features_conv.inner = (void*)(their_features & (~1));
3827         their_features_conv.is_owned = (their_features & 1) || (their_features == 0);
3828         // Warning: we may need a move here but can't clone!
3829         LDKOpenChannel msg_conv;
3830         msg_conv.inner = (void*)(msg & (~1));
3831         msg_conv.is_owned = false;
3832         (this_arg_conv->handle_open_channel)(this_arg_conv->this_arg, their_node_id_ref, their_features_conv, &msg_conv);
3833 }
3834
3835 void ChannelMessageHandler_1handle_1accept_1channel(void* ctx_TODO, uint32_t this_arg, int8_tArray their_node_id, uint32_t their_features, uint32_t msg) {
3836         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
3837         LDKPublicKey their_node_id_ref;
3838         CHECK(their_node_id.len == 33);
3839         memcpy(their_node_id_ref.compressed_form, their_node_id.ptr, 33);
3840         LDKInitFeatures their_features_conv;
3841         their_features_conv.inner = (void*)(their_features & (~1));
3842         their_features_conv.is_owned = (their_features & 1) || (their_features == 0);
3843         // Warning: we may need a move here but can't clone!
3844         LDKAcceptChannel msg_conv;
3845         msg_conv.inner = (void*)(msg & (~1));
3846         msg_conv.is_owned = false;
3847         (this_arg_conv->handle_accept_channel)(this_arg_conv->this_arg, their_node_id_ref, their_features_conv, &msg_conv);
3848 }
3849
3850 void ChannelMessageHandler_1handle_1funding_1created(void* ctx_TODO, uint32_t this_arg, int8_tArray their_node_id, uint32_t msg) {
3851         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
3852         LDKPublicKey their_node_id_ref;
3853         CHECK(their_node_id.len == 33);
3854         memcpy(their_node_id_ref.compressed_form, their_node_id.ptr, 33);
3855         LDKFundingCreated msg_conv;
3856         msg_conv.inner = (void*)(msg & (~1));
3857         msg_conv.is_owned = false;
3858         (this_arg_conv->handle_funding_created)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
3859 }
3860
3861 void ChannelMessageHandler_1handle_1funding_1signed(void* ctx_TODO, uint32_t this_arg, int8_tArray their_node_id, uint32_t msg) {
3862         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
3863         LDKPublicKey their_node_id_ref;
3864         CHECK(their_node_id.len == 33);
3865         memcpy(their_node_id_ref.compressed_form, their_node_id.ptr, 33);
3866         LDKFundingSigned msg_conv;
3867         msg_conv.inner = (void*)(msg & (~1));
3868         msg_conv.is_owned = false;
3869         (this_arg_conv->handle_funding_signed)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
3870 }
3871
3872 void ChannelMessageHandler_1handle_1funding_1locked(void* ctx_TODO, uint32_t this_arg, int8_tArray their_node_id, uint32_t msg) {
3873         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
3874         LDKPublicKey their_node_id_ref;
3875         CHECK(their_node_id.len == 33);
3876         memcpy(their_node_id_ref.compressed_form, their_node_id.ptr, 33);
3877         LDKFundingLocked msg_conv;
3878         msg_conv.inner = (void*)(msg & (~1));
3879         msg_conv.is_owned = false;
3880         (this_arg_conv->handle_funding_locked)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
3881 }
3882
3883 void ChannelMessageHandler_1handle_1shutdown(void* ctx_TODO, uint32_t this_arg, int8_tArray their_node_id, uint32_t msg) {
3884         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
3885         LDKPublicKey their_node_id_ref;
3886         CHECK(their_node_id.len == 33);
3887         memcpy(their_node_id_ref.compressed_form, their_node_id.ptr, 33);
3888         LDKShutdown msg_conv;
3889         msg_conv.inner = (void*)(msg & (~1));
3890         msg_conv.is_owned = false;
3891         (this_arg_conv->handle_shutdown)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
3892 }
3893
3894 void ChannelMessageHandler_1handle_1closing_1signed(void* ctx_TODO, uint32_t this_arg, int8_tArray their_node_id, uint32_t msg) {
3895         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
3896         LDKPublicKey their_node_id_ref;
3897         CHECK(their_node_id.len == 33);
3898         memcpy(their_node_id_ref.compressed_form, their_node_id.ptr, 33);
3899         LDKClosingSigned msg_conv;
3900         msg_conv.inner = (void*)(msg & (~1));
3901         msg_conv.is_owned = false;
3902         (this_arg_conv->handle_closing_signed)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
3903 }
3904
3905 void ChannelMessageHandler_1handle_1update_1add_1htlc(void* ctx_TODO, uint32_t this_arg, int8_tArray their_node_id, uint32_t msg) {
3906         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
3907         LDKPublicKey their_node_id_ref;
3908         CHECK(their_node_id.len == 33);
3909         memcpy(their_node_id_ref.compressed_form, their_node_id.ptr, 33);
3910         LDKUpdateAddHTLC msg_conv;
3911         msg_conv.inner = (void*)(msg & (~1));
3912         msg_conv.is_owned = false;
3913         (this_arg_conv->handle_update_add_htlc)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
3914 }
3915
3916 void ChannelMessageHandler_1handle_1update_1fulfill_1htlc(void* ctx_TODO, uint32_t this_arg, int8_tArray their_node_id, uint32_t msg) {
3917         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
3918         LDKPublicKey their_node_id_ref;
3919         CHECK(their_node_id.len == 33);
3920         memcpy(their_node_id_ref.compressed_form, their_node_id.ptr, 33);
3921         LDKUpdateFulfillHTLC msg_conv;
3922         msg_conv.inner = (void*)(msg & (~1));
3923         msg_conv.is_owned = false;
3924         (this_arg_conv->handle_update_fulfill_htlc)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
3925 }
3926
3927 void ChannelMessageHandler_1handle_1update_1fail_1htlc(void* ctx_TODO, uint32_t this_arg, int8_tArray their_node_id, uint32_t msg) {
3928         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
3929         LDKPublicKey their_node_id_ref;
3930         CHECK(their_node_id.len == 33);
3931         memcpy(their_node_id_ref.compressed_form, their_node_id.ptr, 33);
3932         LDKUpdateFailHTLC msg_conv;
3933         msg_conv.inner = (void*)(msg & (~1));
3934         msg_conv.is_owned = false;
3935         (this_arg_conv->handle_update_fail_htlc)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
3936 }
3937
3938 void ChannelMessageHandler_1handle_1update_1fail_1malformed_1htlc(void* ctx_TODO, uint32_t this_arg, int8_tArray their_node_id, uint32_t msg) {
3939         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
3940         LDKPublicKey their_node_id_ref;
3941         CHECK(their_node_id.len == 33);
3942         memcpy(their_node_id_ref.compressed_form, their_node_id.ptr, 33);
3943         LDKUpdateFailMalformedHTLC msg_conv;
3944         msg_conv.inner = (void*)(msg & (~1));
3945         msg_conv.is_owned = false;
3946         (this_arg_conv->handle_update_fail_malformed_htlc)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
3947 }
3948
3949 void ChannelMessageHandler_1handle_1commitment_1signed(void* ctx_TODO, uint32_t this_arg, int8_tArray their_node_id, uint32_t msg) {
3950         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
3951         LDKPublicKey their_node_id_ref;
3952         CHECK(their_node_id.len == 33);
3953         memcpy(their_node_id_ref.compressed_form, their_node_id.ptr, 33);
3954         LDKCommitmentSigned msg_conv;
3955         msg_conv.inner = (void*)(msg & (~1));
3956         msg_conv.is_owned = false;
3957         (this_arg_conv->handle_commitment_signed)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
3958 }
3959
3960 void ChannelMessageHandler_1handle_1revoke_1and_1ack(void* ctx_TODO, uint32_t this_arg, int8_tArray their_node_id, uint32_t msg) {
3961         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
3962         LDKPublicKey their_node_id_ref;
3963         CHECK(their_node_id.len == 33);
3964         memcpy(their_node_id_ref.compressed_form, their_node_id.ptr, 33);
3965         LDKRevokeAndACK msg_conv;
3966         msg_conv.inner = (void*)(msg & (~1));
3967         msg_conv.is_owned = false;
3968         (this_arg_conv->handle_revoke_and_ack)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
3969 }
3970
3971 void ChannelMessageHandler_1handle_1update_1fee(void* ctx_TODO, uint32_t this_arg, int8_tArray their_node_id, uint32_t msg) {
3972         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
3973         LDKPublicKey their_node_id_ref;
3974         CHECK(their_node_id.len == 33);
3975         memcpy(their_node_id_ref.compressed_form, their_node_id.ptr, 33);
3976         LDKUpdateFee msg_conv;
3977         msg_conv.inner = (void*)(msg & (~1));
3978         msg_conv.is_owned = false;
3979         (this_arg_conv->handle_update_fee)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
3980 }
3981
3982 void ChannelMessageHandler_1handle_1announcement_1signatures(void* ctx_TODO, uint32_t this_arg, int8_tArray their_node_id, uint32_t msg) {
3983         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
3984         LDKPublicKey their_node_id_ref;
3985         CHECK(their_node_id.len == 33);
3986         memcpy(their_node_id_ref.compressed_form, their_node_id.ptr, 33);
3987         LDKAnnouncementSignatures msg_conv;
3988         msg_conv.inner = (void*)(msg & (~1));
3989         msg_conv.is_owned = false;
3990         (this_arg_conv->handle_announcement_signatures)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
3991 }
3992
3993 void ChannelMessageHandler_1peer_1disconnected(void* ctx_TODO, uint32_t this_arg, int8_tArray their_node_id, jboolean no_connection_possible) {
3994         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
3995         LDKPublicKey their_node_id_ref;
3996         CHECK(their_node_id.len == 33);
3997         memcpy(their_node_id_ref.compressed_form, their_node_id.ptr, 33);
3998         (this_arg_conv->peer_disconnected)(this_arg_conv->this_arg, their_node_id_ref, no_connection_possible);
3999 }
4000
4001 void ChannelMessageHandler_1peer_1connected(void* ctx_TODO, uint32_t this_arg, int8_tArray their_node_id, uint32_t msg) {
4002         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
4003         LDKPublicKey their_node_id_ref;
4004         CHECK(their_node_id.len == 33);
4005         memcpy(their_node_id_ref.compressed_form, their_node_id.ptr, 33);
4006         LDKInit msg_conv;
4007         msg_conv.inner = (void*)(msg & (~1));
4008         msg_conv.is_owned = false;
4009         (this_arg_conv->peer_connected)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
4010 }
4011
4012 void ChannelMessageHandler_1handle_1channel_1reestablish(void* ctx_TODO, uint32_t this_arg, int8_tArray their_node_id, uint32_t msg) {
4013         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
4014         LDKPublicKey their_node_id_ref;
4015         CHECK(their_node_id.len == 33);
4016         memcpy(their_node_id_ref.compressed_form, their_node_id.ptr, 33);
4017         LDKChannelReestablish msg_conv;
4018         msg_conv.inner = (void*)(msg & (~1));
4019         msg_conv.is_owned = false;
4020         (this_arg_conv->handle_channel_reestablish)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
4021 }
4022
4023 void ChannelMessageHandler_1handle_1error(void* ctx_TODO, uint32_t this_arg, int8_tArray their_node_id, uint32_t msg) {
4024         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
4025         LDKPublicKey their_node_id_ref;
4026         CHECK(their_node_id.len == 33);
4027         memcpy(their_node_id_ref.compressed_form, their_node_id.ptr, 33);
4028         LDKErrorMessage msg_conv;
4029         msg_conv.inner = (void*)(msg & (~1));
4030         msg_conv.is_owned = false;
4031         (this_arg_conv->handle_error)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
4032 }
4033
4034 typedef struct LDKRoutingMessageHandler_JCalls {
4035         atomic_size_t refcnt;
4036         // TODO: Object pointer o;
4037         LDKMessageSendEventsProvider_JCalls* MessageSendEventsProvider;
4038         // TODO: Some kind of method pointer handle_node_announcement_meth;
4039         // TODO: Some kind of method pointer handle_channel_announcement_meth;
4040         // TODO: Some kind of method pointer handle_channel_update_meth;
4041         // TODO: Some kind of method pointer handle_htlc_fail_channel_update_meth;
4042         // TODO: Some kind of method pointer get_next_channel_announcements_meth;
4043         // TODO: Some kind of method pointer get_next_node_announcements_meth;
4044         // TODO: Some kind of method pointer sync_routing_table_meth;
4045         // TODO: Some kind of method pointer handle_reply_channel_range_meth;
4046         // TODO: Some kind of method pointer handle_reply_short_channel_ids_end_meth;
4047         // TODO: Some kind of method pointer handle_query_channel_range_meth;
4048         // TODO: Some kind of method pointer handle_query_short_channel_ids_meth;
4049 } LDKRoutingMessageHandler_JCalls;
4050 static void LDKRoutingMessageHandler_JCalls_free(void* this_arg) {
4051         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
4052         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
4053                 // TODO: do any release required for j_calls->o (refcnt-- in java, but may be redundant)
4054                 FREE(j_calls);
4055         }
4056 }
4057 LDKCResult_boolLightningErrorZ handle_node_announcement_jcall(const void* this_arg, const LDKNodeAnnouncement * msg) {
4058         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
4059         LDKNodeAnnouncement msg_var = *msg;
4060         if (msg->inner != NULL)
4061                 msg_var = NodeAnnouncement_clone(msg);
4062         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4063         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4064         long msg_ref = (long)msg_var.inner;
4065         if (msg_var.is_owned) {
4066                 msg_ref |= 1;
4067         }
4068         //TODO: jobject obj = get object we can call against on j_calls->o
4069         LDKCResult_boolLightningErrorZ* ret; // TODO: Call handle_node_announcement on j_calls with instance obj, returning a pointer, msg_ref);
4070         LDKCResult_boolLightningErrorZ ret_conv = *(LDKCResult_boolLightningErrorZ*)ret;
4071         FREE((void*)ret);
4072         return ret_conv;
4073 }
4074 LDKCResult_boolLightningErrorZ handle_channel_announcement_jcall(const void* this_arg, const LDKChannelAnnouncement * msg) {
4075         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
4076         LDKChannelAnnouncement msg_var = *msg;
4077         if (msg->inner != NULL)
4078                 msg_var = ChannelAnnouncement_clone(msg);
4079         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4080         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4081         long msg_ref = (long)msg_var.inner;
4082         if (msg_var.is_owned) {
4083                 msg_ref |= 1;
4084         }
4085         //TODO: jobject obj = get object we can call against on j_calls->o
4086         LDKCResult_boolLightningErrorZ* ret; // TODO: Call handle_channel_announcement on j_calls with instance obj, returning a pointer, msg_ref);
4087         LDKCResult_boolLightningErrorZ ret_conv = *(LDKCResult_boolLightningErrorZ*)ret;
4088         FREE((void*)ret);
4089         return ret_conv;
4090 }
4091 LDKCResult_boolLightningErrorZ handle_channel_update_jcall(const void* this_arg, const LDKChannelUpdate * msg) {
4092         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
4093         LDKChannelUpdate msg_var = *msg;
4094         if (msg->inner != NULL)
4095                 msg_var = ChannelUpdate_clone(msg);
4096         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4097         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4098         long msg_ref = (long)msg_var.inner;
4099         if (msg_var.is_owned) {
4100                 msg_ref |= 1;
4101         }
4102         //TODO: jobject obj = get object we can call against on j_calls->o
4103         LDKCResult_boolLightningErrorZ* ret; // TODO: Call handle_channel_update on j_calls with instance obj, returning a pointer, msg_ref);
4104         LDKCResult_boolLightningErrorZ ret_conv = *(LDKCResult_boolLightningErrorZ*)ret;
4105         FREE((void*)ret);
4106         return ret_conv;
4107 }
4108 void handle_htlc_fail_channel_update_jcall(const void* this_arg, const LDKHTLCFailChannelUpdate * update) {
4109         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
4110         long ret_update = (long)update;
4111         //TODO: jobject obj = get object we can call against on j_calls->o
4112         return; //TODO: Call handle_htlc_fail_channel_update on j_calls with instance obj, ret_update);
4113 }
4114 LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ get_next_channel_announcements_jcall(const void* this_arg, uint64_t starting_point, uint8_t batch_amount) {
4115         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
4116         //TODO: jobject obj = get object we can call against on j_calls->o
4117         uint32_tArray arg; // TODO: Call get_next_channel_announcements on j_calls with instance obj, returning an object, starting_point, batch_amount);
4118         LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ arg_constr;
4119         arg_constr.datalen = arg.len;
4120         if (arg_constr.datalen > 0)
4121                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ), "LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ Elements");
4122         else
4123                 arg_constr.data = NULL;
4124         uint32_t* arg_vals = (uint32_t*) arg.ptr;
4125         for (size_t l = 0; l < arg_constr.datalen; l++) {
4126                 uint32_t arr_conv_63 = arg_vals[l];
4127                 LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ arr_conv_63_conv = *(LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ*)arr_conv_63;
4128                 FREE((void*)arr_conv_63);
4129                 arg_constr.data[l] = arr_conv_63_conv;
4130         }
4131         return arg_constr;
4132 }
4133 LDKCVec_NodeAnnouncementZ get_next_node_announcements_jcall(const void* this_arg, LDKPublicKey starting_point, uint8_t batch_amount) {
4134         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
4135         int8_tArray starting_point_arr = { .len = 33, .ptr = MALLOC(33, "Native int8_tArray Bytes") };
4136         memcpy(starting_point_arr.ptr, starting_point.compressed_form, 33);
4137         //TODO: jobject obj = get object we can call against on j_calls->o
4138         uint32_tArray arg; // TODO: Call get_next_node_announcements on j_calls with instance obj, returning an object, starting_point_arr, batch_amount);
4139         LDKCVec_NodeAnnouncementZ arg_constr;
4140         arg_constr.datalen = arg.len;
4141         if (arg_constr.datalen > 0)
4142                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKNodeAnnouncement), "LDKCVec_NodeAnnouncementZ Elements");
4143         else
4144                 arg_constr.data = NULL;
4145         uint32_t* arg_vals = (uint32_t*) arg.ptr;
4146         for (size_t s = 0; s < arg_constr.datalen; s++) {
4147                 uint32_t arr_conv_18 = arg_vals[s];
4148                 LDKNodeAnnouncement arr_conv_18_conv;
4149                 arr_conv_18_conv.inner = (void*)(arr_conv_18 & (~1));
4150                 arr_conv_18_conv.is_owned = (arr_conv_18 & 1) || (arr_conv_18 == 0);
4151                 if (arr_conv_18_conv.inner != NULL)
4152                         arr_conv_18_conv = NodeAnnouncement_clone(&arr_conv_18_conv);
4153                 arg_constr.data[s] = arr_conv_18_conv;
4154         }
4155         return arg_constr;
4156 }
4157 void sync_routing_table_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKInit * init) {
4158         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
4159         int8_tArray their_node_id_arr = { .len = 33, .ptr = MALLOC(33, "Native int8_tArray Bytes") };
4160         memcpy(their_node_id_arr.ptr, their_node_id.compressed_form, 33);
4161         LDKInit init_var = *init;
4162         if (init->inner != NULL)
4163                 init_var = Init_clone(init);
4164         CHECK((((long)init_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4165         CHECK((((long)&init_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4166         long init_ref = (long)init_var.inner;
4167         if (init_var.is_owned) {
4168                 init_ref |= 1;
4169         }
4170         //TODO: jobject obj = get object we can call against on j_calls->o
4171         return; //TODO: Call sync_routing_table on j_calls with instance obj, their_node_id_arr, init_ref);
4172 }
4173 LDKCResult_NoneLightningErrorZ handle_reply_channel_range_jcall(const void* this_arg, LDKPublicKey their_node_id, LDKReplyChannelRange msg) {
4174         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
4175         int8_tArray their_node_id_arr = { .len = 33, .ptr = MALLOC(33, "Native int8_tArray Bytes") };
4176         memcpy(their_node_id_arr.ptr, their_node_id.compressed_form, 33);
4177         LDKReplyChannelRange msg_var = msg;
4178         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4179         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4180         long msg_ref = (long)msg_var.inner;
4181         if (msg_var.is_owned) {
4182                 msg_ref |= 1;
4183         }
4184         //TODO: jobject obj = get object we can call against on j_calls->o
4185         LDKCResult_NoneLightningErrorZ* ret; // TODO: Call handle_reply_channel_range on j_calls with instance obj, returning a pointer, their_node_id_arr, msg_ref);
4186         LDKCResult_NoneLightningErrorZ ret_conv = *(LDKCResult_NoneLightningErrorZ*)ret;
4187         FREE((void*)ret);
4188         return ret_conv;
4189 }
4190 LDKCResult_NoneLightningErrorZ handle_reply_short_channel_ids_end_jcall(const void* this_arg, LDKPublicKey their_node_id, LDKReplyShortChannelIdsEnd msg) {
4191         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
4192         int8_tArray their_node_id_arr = { .len = 33, .ptr = MALLOC(33, "Native int8_tArray Bytes") };
4193         memcpy(their_node_id_arr.ptr, their_node_id.compressed_form, 33);
4194         LDKReplyShortChannelIdsEnd msg_var = msg;
4195         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4196         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4197         long msg_ref = (long)msg_var.inner;
4198         if (msg_var.is_owned) {
4199                 msg_ref |= 1;
4200         }
4201         //TODO: jobject obj = get object we can call against on j_calls->o
4202         LDKCResult_NoneLightningErrorZ* ret; // TODO: Call handle_reply_short_channel_ids_end on j_calls with instance obj, returning a pointer, their_node_id_arr, msg_ref);
4203         LDKCResult_NoneLightningErrorZ ret_conv = *(LDKCResult_NoneLightningErrorZ*)ret;
4204         FREE((void*)ret);
4205         return ret_conv;
4206 }
4207 LDKCResult_NoneLightningErrorZ handle_query_channel_range_jcall(const void* this_arg, LDKPublicKey their_node_id, LDKQueryChannelRange msg) {
4208         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
4209         int8_tArray their_node_id_arr = { .len = 33, .ptr = MALLOC(33, "Native int8_tArray Bytes") };
4210         memcpy(their_node_id_arr.ptr, their_node_id.compressed_form, 33);
4211         LDKQueryChannelRange msg_var = msg;
4212         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4213         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4214         long msg_ref = (long)msg_var.inner;
4215         if (msg_var.is_owned) {
4216                 msg_ref |= 1;
4217         }
4218         //TODO: jobject obj = get object we can call against on j_calls->o
4219         LDKCResult_NoneLightningErrorZ* ret; // TODO: Call handle_query_channel_range on j_calls with instance obj, returning a pointer, their_node_id_arr, msg_ref);
4220         LDKCResult_NoneLightningErrorZ ret_conv = *(LDKCResult_NoneLightningErrorZ*)ret;
4221         FREE((void*)ret);
4222         return ret_conv;
4223 }
4224 LDKCResult_NoneLightningErrorZ handle_query_short_channel_ids_jcall(const void* this_arg, LDKPublicKey their_node_id, LDKQueryShortChannelIds msg) {
4225         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
4226         int8_tArray their_node_id_arr = { .len = 33, .ptr = MALLOC(33, "Native int8_tArray Bytes") };
4227         memcpy(their_node_id_arr.ptr, their_node_id.compressed_form, 33);
4228         LDKQueryShortChannelIds msg_var = msg;
4229         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4230         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4231         long msg_ref = (long)msg_var.inner;
4232         if (msg_var.is_owned) {
4233                 msg_ref |= 1;
4234         }
4235         //TODO: jobject obj = get object we can call against on j_calls->o
4236         LDKCResult_NoneLightningErrorZ* ret; // TODO: Call handle_query_short_channel_ids on j_calls with instance obj, returning a pointer, their_node_id_arr, msg_ref);
4237         LDKCResult_NoneLightningErrorZ ret_conv = *(LDKCResult_NoneLightningErrorZ*)ret;
4238         FREE((void*)ret);
4239         return ret_conv;
4240 }
4241 static void* LDKRoutingMessageHandler_JCalls_clone(const void* this_arg) {
4242         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
4243         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
4244         atomic_fetch_add_explicit(&j_calls->MessageSendEventsProvider->refcnt, 1, memory_order_release);
4245         return (void*) this_arg;
4246 }
4247 static inline LDKRoutingMessageHandler LDKRoutingMessageHandler_init (void* ctx_TODO, /*TODO: JS Object Reference */void* o, /*TODO: JS Object Reference */void* MessageSendEventsProvider) {
4248         LDKRoutingMessageHandler_JCalls *calls = MALLOC(sizeof(LDKRoutingMessageHandler_JCalls), "LDKRoutingMessageHandler_JCalls");
4249         atomic_init(&calls->refcnt, 1);
4250         //TODO: Assign calls->o from o
4251
4252         LDKRoutingMessageHandler ret = {
4253                 .this_arg = (void*) calls,
4254                 .handle_node_announcement = handle_node_announcement_jcall,
4255                 .handle_channel_announcement = handle_channel_announcement_jcall,
4256                 .handle_channel_update = handle_channel_update_jcall,
4257                 .handle_htlc_fail_channel_update = handle_htlc_fail_channel_update_jcall,
4258                 .get_next_channel_announcements = get_next_channel_announcements_jcall,
4259                 .get_next_node_announcements = get_next_node_announcements_jcall,
4260                 .sync_routing_table = sync_routing_table_jcall,
4261                 .handle_reply_channel_range = handle_reply_channel_range_jcall,
4262                 .handle_reply_short_channel_ids_end = handle_reply_short_channel_ids_end_jcall,
4263                 .handle_query_channel_range = handle_query_channel_range_jcall,
4264                 .handle_query_short_channel_ids = handle_query_short_channel_ids_jcall,
4265                 .free = LDKRoutingMessageHandler_JCalls_free,
4266                 .MessageSendEventsProvider = LDKMessageSendEventsProvider_init(NULL, MessageSendEventsProvider),
4267         };
4268         calls->MessageSendEventsProvider = ret.MessageSendEventsProvider.this_arg;
4269         return ret;
4270 }
4271 long LDKRoutingMessageHandler_1new (void* ctx_TODO, /*TODO: JS Object Reference */void* o, /*TODO: JS Object Reference */ void* MessageSendEventsProvider) {
4272         LDKRoutingMessageHandler *res_ptr = MALLOC(sizeof(LDKRoutingMessageHandler), "LDKRoutingMessageHandler");
4273         *res_ptr = LDKRoutingMessageHandler_init(NULL, o, MessageSendEventsProvider);
4274         return (long)res_ptr;
4275 }
4276 uint32_t RoutingMessageHandler_1handle_1node_1announcement(void* ctx_TODO, uint32_t this_arg, uint32_t msg) {
4277         LDKRoutingMessageHandler* this_arg_conv = (LDKRoutingMessageHandler*)this_arg;
4278         LDKNodeAnnouncement msg_conv;
4279         msg_conv.inner = (void*)(msg & (~1));
4280         msg_conv.is_owned = false;
4281         LDKCResult_boolLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_boolLightningErrorZ), "LDKCResult_boolLightningErrorZ");
4282         *ret_conv = (this_arg_conv->handle_node_announcement)(this_arg_conv->this_arg, &msg_conv);
4283         return (long)ret_conv;
4284 }
4285
4286 uint32_t RoutingMessageHandler_1handle_1channel_1announcement(void* ctx_TODO, uint32_t this_arg, uint32_t msg) {
4287         LDKRoutingMessageHandler* this_arg_conv = (LDKRoutingMessageHandler*)this_arg;
4288         LDKChannelAnnouncement msg_conv;
4289         msg_conv.inner = (void*)(msg & (~1));
4290         msg_conv.is_owned = false;
4291         LDKCResult_boolLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_boolLightningErrorZ), "LDKCResult_boolLightningErrorZ");
4292         *ret_conv = (this_arg_conv->handle_channel_announcement)(this_arg_conv->this_arg, &msg_conv);
4293         return (long)ret_conv;
4294 }
4295
4296 uint32_t RoutingMessageHandler_1handle_1channel_1update(void* ctx_TODO, uint32_t this_arg, uint32_t msg) {
4297         LDKRoutingMessageHandler* this_arg_conv = (LDKRoutingMessageHandler*)this_arg;
4298         LDKChannelUpdate msg_conv;
4299         msg_conv.inner = (void*)(msg & (~1));
4300         msg_conv.is_owned = false;
4301         LDKCResult_boolLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_boolLightningErrorZ), "LDKCResult_boolLightningErrorZ");
4302         *ret_conv = (this_arg_conv->handle_channel_update)(this_arg_conv->this_arg, &msg_conv);
4303         return (long)ret_conv;
4304 }
4305
4306 void RoutingMessageHandler_1handle_1htlc_1fail_1channel_1update(void* ctx_TODO, uint32_t this_arg, uint32_t update) {
4307         LDKRoutingMessageHandler* this_arg_conv = (LDKRoutingMessageHandler*)this_arg;
4308         LDKHTLCFailChannelUpdate* update_conv = (LDKHTLCFailChannelUpdate*)update;
4309         (this_arg_conv->handle_htlc_fail_channel_update)(this_arg_conv->this_arg, update_conv);
4310 }
4311
4312 uint32_tArray RoutingMessageHandler_1get_1next_1channel_1announcements(void* ctx_TODO, uint32_t this_arg, int64_t starting_point, int8_t batch_amount) {
4313         LDKRoutingMessageHandler* this_arg_conv = (LDKRoutingMessageHandler*)this_arg;
4314         LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ ret_var = (this_arg_conv->get_next_channel_announcements)(this_arg_conv->this_arg, starting_point, batch_amount);
4315         uint32_tArray ret_arr = { .len = ret_var.datalen, .ptr = MALLOC(ret_var.datalen * sizeof(int32_t), "Native uint32_tArray Bytes") };
4316         uint32_t *ret_arr_ptr = (uint32_t*)ret_arr.ptr;
4317         for (size_t l = 0; l < ret_var.datalen; l++) {
4318                 LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ* arr_conv_63_ref = MALLOC(sizeof(LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ), "LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ");
4319                 *arr_conv_63_ref = ret_var.data[l];
4320                 arr_conv_63_ref->a = ChannelAnnouncement_clone(&arr_conv_63_ref->a);
4321                 arr_conv_63_ref->b = ChannelUpdate_clone(&arr_conv_63_ref->b);
4322                 arr_conv_63_ref->c = ChannelUpdate_clone(&arr_conv_63_ref->c);
4323                 ret_arr_ptr[l] = (long)arr_conv_63_ref;
4324         }
4325         FREE(ret_var.data);
4326         return ret_arr;
4327 }
4328
4329 uint32_tArray RoutingMessageHandler_1get_1next_1node_1announcements(void* ctx_TODO, uint32_t this_arg, int8_tArray starting_point, int8_t batch_amount) {
4330         LDKRoutingMessageHandler* this_arg_conv = (LDKRoutingMessageHandler*)this_arg;
4331         LDKPublicKey starting_point_ref;
4332         CHECK(starting_point.len == 33);
4333         memcpy(starting_point_ref.compressed_form, starting_point.ptr, 33);
4334         LDKCVec_NodeAnnouncementZ ret_var = (this_arg_conv->get_next_node_announcements)(this_arg_conv->this_arg, starting_point_ref, batch_amount);
4335         uint32_tArray ret_arr = { .len = ret_var.datalen, .ptr = MALLOC(ret_var.datalen * sizeof(int32_t), "Native uint32_tArray Bytes") };
4336         uint32_t *ret_arr_ptr = (uint32_t*)ret_arr.ptr;
4337         for (size_t s = 0; s < ret_var.datalen; s++) {
4338                 LDKNodeAnnouncement arr_conv_18_var = ret_var.data[s];
4339                 CHECK((((long)arr_conv_18_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4340                 CHECK((((long)&arr_conv_18_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4341                 long arr_conv_18_ref = (long)arr_conv_18_var.inner;
4342                 if (arr_conv_18_var.is_owned) {
4343                         arr_conv_18_ref |= 1;
4344                 }
4345                 ret_arr_ptr[s] = arr_conv_18_ref;
4346         }
4347         FREE(ret_var.data);
4348         return ret_arr;
4349 }
4350
4351 void RoutingMessageHandler_1sync_1routing_1table(void* ctx_TODO, uint32_t this_arg, int8_tArray their_node_id, uint32_t init) {
4352         LDKRoutingMessageHandler* this_arg_conv = (LDKRoutingMessageHandler*)this_arg;
4353         LDKPublicKey their_node_id_ref;
4354         CHECK(their_node_id.len == 33);
4355         memcpy(their_node_id_ref.compressed_form, their_node_id.ptr, 33);
4356         LDKInit init_conv;
4357         init_conv.inner = (void*)(init & (~1));
4358         init_conv.is_owned = false;
4359         (this_arg_conv->sync_routing_table)(this_arg_conv->this_arg, their_node_id_ref, &init_conv);
4360 }
4361
4362 uint32_t RoutingMessageHandler_1handle_1reply_1channel_1range(void* ctx_TODO, uint32_t this_arg, int8_tArray their_node_id, uint32_t msg) {
4363         LDKRoutingMessageHandler* this_arg_conv = (LDKRoutingMessageHandler*)this_arg;
4364         LDKPublicKey their_node_id_ref;
4365         CHECK(their_node_id.len == 33);
4366         memcpy(their_node_id_ref.compressed_form, their_node_id.ptr, 33);
4367         LDKReplyChannelRange msg_conv;
4368         msg_conv.inner = (void*)(msg & (~1));
4369         msg_conv.is_owned = (msg & 1) || (msg == 0);
4370         if (msg_conv.inner != NULL)
4371                 msg_conv = ReplyChannelRange_clone(&msg_conv);
4372         LDKCResult_NoneLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneLightningErrorZ), "LDKCResult_NoneLightningErrorZ");
4373         *ret_conv = (this_arg_conv->handle_reply_channel_range)(this_arg_conv->this_arg, their_node_id_ref, msg_conv);
4374         return (long)ret_conv;
4375 }
4376
4377 uint32_t RoutingMessageHandler_1handle_1reply_1short_1channel_1ids_1end(void* ctx_TODO, uint32_t this_arg, int8_tArray their_node_id, uint32_t msg) {
4378         LDKRoutingMessageHandler* this_arg_conv = (LDKRoutingMessageHandler*)this_arg;
4379         LDKPublicKey their_node_id_ref;
4380         CHECK(their_node_id.len == 33);
4381         memcpy(their_node_id_ref.compressed_form, their_node_id.ptr, 33);
4382         LDKReplyShortChannelIdsEnd msg_conv;
4383         msg_conv.inner = (void*)(msg & (~1));
4384         msg_conv.is_owned = (msg & 1) || (msg == 0);
4385         if (msg_conv.inner != NULL)
4386                 msg_conv = ReplyShortChannelIdsEnd_clone(&msg_conv);
4387         LDKCResult_NoneLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneLightningErrorZ), "LDKCResult_NoneLightningErrorZ");
4388         *ret_conv = (this_arg_conv->handle_reply_short_channel_ids_end)(this_arg_conv->this_arg, their_node_id_ref, msg_conv);
4389         return (long)ret_conv;
4390 }
4391
4392 uint32_t RoutingMessageHandler_1handle_1query_1channel_1range(void* ctx_TODO, uint32_t this_arg, int8_tArray their_node_id, uint32_t msg) {
4393         LDKRoutingMessageHandler* this_arg_conv = (LDKRoutingMessageHandler*)this_arg;
4394         LDKPublicKey their_node_id_ref;
4395         CHECK(their_node_id.len == 33);
4396         memcpy(their_node_id_ref.compressed_form, their_node_id.ptr, 33);
4397         LDKQueryChannelRange msg_conv;
4398         msg_conv.inner = (void*)(msg & (~1));
4399         msg_conv.is_owned = (msg & 1) || (msg == 0);
4400         if (msg_conv.inner != NULL)
4401                 msg_conv = QueryChannelRange_clone(&msg_conv);
4402         LDKCResult_NoneLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneLightningErrorZ), "LDKCResult_NoneLightningErrorZ");
4403         *ret_conv = (this_arg_conv->handle_query_channel_range)(this_arg_conv->this_arg, their_node_id_ref, msg_conv);
4404         return (long)ret_conv;
4405 }
4406
4407 uint32_t RoutingMessageHandler_1handle_1query_1short_1channel_1ids(void* ctx_TODO, uint32_t this_arg, int8_tArray their_node_id, uint32_t msg) {
4408         LDKRoutingMessageHandler* this_arg_conv = (LDKRoutingMessageHandler*)this_arg;
4409         LDKPublicKey their_node_id_ref;
4410         CHECK(their_node_id.len == 33);
4411         memcpy(their_node_id_ref.compressed_form, their_node_id.ptr, 33);
4412         LDKQueryShortChannelIds msg_conv;
4413         msg_conv.inner = (void*)(msg & (~1));
4414         msg_conv.is_owned = (msg & 1) || (msg == 0);
4415         if (msg_conv.inner != NULL)
4416                 msg_conv = QueryShortChannelIds_clone(&msg_conv);
4417         LDKCResult_NoneLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneLightningErrorZ), "LDKCResult_NoneLightningErrorZ");
4418         *ret_conv = (this_arg_conv->handle_query_short_channel_ids)(this_arg_conv->this_arg, their_node_id_ref, msg_conv);
4419         return (long)ret_conv;
4420 }
4421
4422 typedef struct LDKSocketDescriptor_JCalls {
4423         atomic_size_t refcnt;
4424         // TODO: Object pointer o;
4425         // TODO: Some kind of method pointer send_data_meth;
4426         // TODO: Some kind of method pointer disconnect_socket_meth;
4427         // TODO: Some kind of method pointer eq_meth;
4428         // TODO: Some kind of method pointer hash_meth;
4429 } LDKSocketDescriptor_JCalls;
4430 static void LDKSocketDescriptor_JCalls_free(void* this_arg) {
4431         LDKSocketDescriptor_JCalls *j_calls = (LDKSocketDescriptor_JCalls*) this_arg;
4432         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
4433                 // TODO: do any release required for j_calls->o (refcnt-- in java, but may be redundant)
4434                 FREE(j_calls);
4435         }
4436 }
4437 uintptr_t send_data_jcall(void* this_arg, LDKu8slice data, bool resume_read) {
4438         LDKSocketDescriptor_JCalls *j_calls = (LDKSocketDescriptor_JCalls*) this_arg;
4439         LDKu8slice data_var = data;
4440         int8_tArray data_arr = { .len = data_var.datalen, .ptr = MALLOC(data_var.datalen, "Native int8_tArray Bytes") };
4441         memcpy(data_arr.ptr, data_var.data, data_var.datalen);
4442         //TODO: jobject obj = get object we can call against on j_calls->o
4443         return 0; //TODO: Call send_data on j_calls with instance obj, returning number, data_arr, resume_read);
4444 }
4445 void disconnect_socket_jcall(void* this_arg) {
4446         LDKSocketDescriptor_JCalls *j_calls = (LDKSocketDescriptor_JCalls*) this_arg;
4447         //TODO: jobject obj = get object we can call against on j_calls->o
4448         return; //TODO: Call disconnect_socket on j_calls with instance obj);
4449 }
4450 bool eq_jcall(const void* this_arg, const LDKSocketDescriptor * other_arg) {
4451         LDKSocketDescriptor_JCalls *j_calls = (LDKSocketDescriptor_JCalls*) this_arg;
4452         LDKSocketDescriptor *other_arg_clone = MALLOC(sizeof(LDKSocketDescriptor), "LDKSocketDescriptor");
4453         *other_arg_clone = SocketDescriptor_clone(other_arg);
4454         //TODO: jobject obj = get object we can call against on j_calls->o
4455         return 0; //TODO: Call eq on j_calls with instance obj, returning boolean, (long)other_arg_clone);
4456 }
4457 uint64_t hash_jcall(const void* this_arg) {
4458         LDKSocketDescriptor_JCalls *j_calls = (LDKSocketDescriptor_JCalls*) this_arg;
4459         //TODO: jobject obj = get object we can call against on j_calls->o
4460         return 0; //TODO: Call hash on j_calls with instance obj, returning number);
4461 }
4462 static void* LDKSocketDescriptor_JCalls_clone(const void* this_arg) {
4463         LDKSocketDescriptor_JCalls *j_calls = (LDKSocketDescriptor_JCalls*) this_arg;
4464         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
4465         return (void*) this_arg;
4466 }
4467 static inline LDKSocketDescriptor LDKSocketDescriptor_init (void* ctx_TODO, /*TODO: JS Object Reference */void* o) {
4468         LDKSocketDescriptor_JCalls *calls = MALLOC(sizeof(LDKSocketDescriptor_JCalls), "LDKSocketDescriptor_JCalls");
4469         atomic_init(&calls->refcnt, 1);
4470         //TODO: Assign calls->o from o
4471
4472         LDKSocketDescriptor ret = {
4473                 .this_arg = (void*) calls,
4474                 .send_data = send_data_jcall,
4475                 .disconnect_socket = disconnect_socket_jcall,
4476                 .eq = eq_jcall,
4477                 .hash = hash_jcall,
4478                 .clone = LDKSocketDescriptor_JCalls_clone,
4479                 .free = LDKSocketDescriptor_JCalls_free,
4480         };
4481         return ret;
4482 }
4483 long LDKSocketDescriptor_1new (void* ctx_TODO, /*TODO: JS Object Reference */void* o) {
4484         LDKSocketDescriptor *res_ptr = MALLOC(sizeof(LDKSocketDescriptor), "LDKSocketDescriptor");
4485         *res_ptr = LDKSocketDescriptor_init(NULL, o);
4486         return (long)res_ptr;
4487 }
4488 intptr_t SocketDescriptor_1send_1data(void* ctx_TODO, uint32_t this_arg, int8_tArray data, jboolean resume_read) {
4489         LDKSocketDescriptor* this_arg_conv = (LDKSocketDescriptor*)this_arg;
4490         LDKu8slice data_ref;
4491         data_ref.datalen = data.len;
4492         data_ref.data = data.ptr;
4493         intptr_t ret_val = (this_arg_conv->send_data)(this_arg_conv->this_arg, data_ref, resume_read);
4494         return ret_val;
4495 }
4496
4497 void SocketDescriptor_1disconnect_1socket(void* ctx_TODO, uint32_t this_arg) {
4498         LDKSocketDescriptor* this_arg_conv = (LDKSocketDescriptor*)this_arg;
4499         (this_arg_conv->disconnect_socket)(this_arg_conv->this_arg);
4500 }
4501
4502 int64_t SocketDescriptor_1hash(void* ctx_TODO, uint32_t this_arg) {
4503         LDKSocketDescriptor* this_arg_conv = (LDKSocketDescriptor*)this_arg;
4504         int64_t ret_val = (this_arg_conv->hash)(this_arg_conv->this_arg);
4505         return ret_val;
4506 }
4507
4508 void Transaction_1free(void* ctx_TODO, int8_tArray _res) {
4509         LDKTransaction _res_ref;
4510         _res_ref.datalen = _res.len;
4511         _res_ref.data = MALLOC(_res_ref.datalen, "LDKTransaction Bytes");
4512         memcpy(_res_ref.data, _res.ptr, _res_ref.datalen);
4513         _res_ref.data_is_owned = true;
4514         Transaction_free(_res_ref);
4515 }
4516
4517 void TxOut_1free(void* ctx_TODO, uint32_t _res) {
4518         LDKTxOut _res_conv = *(LDKTxOut*)_res;
4519         FREE((void*)_res);
4520         TxOut_free(_res_conv);
4521 }
4522
4523 void CVec_1SpendableOutputDescriptorZ_1free(void* ctx_TODO, uint32_tArray _res) {
4524         LDKCVec_SpendableOutputDescriptorZ _res_constr;
4525         _res_constr.datalen = _res.len;
4526         if (_res_constr.datalen > 0)
4527                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKSpendableOutputDescriptor), "LDKCVec_SpendableOutputDescriptorZ Elements");
4528         else
4529                 _res_constr.data = NULL;
4530         uint32_t* _res_vals = (uint32_t*) _res.ptr;
4531         for (size_t b = 0; b < _res_constr.datalen; b++) {
4532                 uint32_t arr_conv_27 = _res_vals[b];
4533                 LDKSpendableOutputDescriptor arr_conv_27_conv = *(LDKSpendableOutputDescriptor*)arr_conv_27;
4534                 FREE((void*)arr_conv_27);
4535                 _res_constr.data[b] = arr_conv_27_conv;
4536         }
4537         CVec_SpendableOutputDescriptorZ_free(_res_constr);
4538 }
4539
4540 void CVec_1MessageSendEventZ_1free(void* ctx_TODO, uint32_tArray _res) {
4541         LDKCVec_MessageSendEventZ _res_constr;
4542         _res_constr.datalen = _res.len;
4543         if (_res_constr.datalen > 0)
4544                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKMessageSendEvent), "LDKCVec_MessageSendEventZ Elements");
4545         else
4546                 _res_constr.data = NULL;
4547         uint32_t* _res_vals = (uint32_t*) _res.ptr;
4548         for (size_t s = 0; s < _res_constr.datalen; s++) {
4549                 uint32_t arr_conv_18 = _res_vals[s];
4550                 LDKMessageSendEvent arr_conv_18_conv = *(LDKMessageSendEvent*)arr_conv_18;
4551                 FREE((void*)arr_conv_18);
4552                 _res_constr.data[s] = arr_conv_18_conv;
4553         }
4554         CVec_MessageSendEventZ_free(_res_constr);
4555 }
4556
4557 void CVec_1EventZ_1free(void* ctx_TODO, uint32_tArray _res) {
4558         LDKCVec_EventZ _res_constr;
4559         _res_constr.datalen = _res.len;
4560         if (_res_constr.datalen > 0)
4561                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKEvent), "LDKCVec_EventZ Elements");
4562         else
4563                 _res_constr.data = NULL;
4564         uint32_t* _res_vals = (uint32_t*) _res.ptr;
4565         for (size_t h = 0; h < _res_constr.datalen; h++) {
4566                 uint32_t arr_conv_7 = _res_vals[h];
4567                 LDKEvent arr_conv_7_conv = *(LDKEvent*)arr_conv_7;
4568                 FREE((void*)arr_conv_7);
4569                 _res_constr.data[h] = arr_conv_7_conv;
4570         }
4571         CVec_EventZ_free(_res_constr);
4572 }
4573
4574 void C2Tuple_1usizeTransactionZ_1free(void* ctx_TODO, uint32_t _res) {
4575         LDKC2Tuple_usizeTransactionZ _res_conv = *(LDKC2Tuple_usizeTransactionZ*)_res;
4576         FREE((void*)_res);
4577         C2Tuple_usizeTransactionZ_free(_res_conv);
4578 }
4579
4580 uint32_t C2Tuple_1usizeTransactionZ_1new(void* ctx_TODO, intptr_t a, int8_tArray b) {
4581         LDKTransaction b_ref;
4582         b_ref.datalen = b.len;
4583         b_ref.data = MALLOC(b_ref.datalen, "LDKTransaction Bytes");
4584         memcpy(b_ref.data, b.ptr, b_ref.datalen);
4585         b_ref.data_is_owned = true;
4586         LDKC2Tuple_usizeTransactionZ* ret_ref = MALLOC(sizeof(LDKC2Tuple_usizeTransactionZ), "LDKC2Tuple_usizeTransactionZ");
4587         *ret_ref = C2Tuple_usizeTransactionZ_new(a, b_ref);
4588         // XXX: We likely need to clone here, but no _clone fn is available for Uint8Array
4589         return (long)ret_ref;
4590 }
4591
4592 void CVec_1C2Tuple_1usizeTransactionZZ_1free(void* ctx_TODO, uint32_tArray _res) {
4593         LDKCVec_C2Tuple_usizeTransactionZZ _res_constr;
4594         _res_constr.datalen = _res.len;
4595         if (_res_constr.datalen > 0)
4596                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKC2Tuple_usizeTransactionZ), "LDKCVec_C2Tuple_usizeTransactionZZ Elements");
4597         else
4598                 _res_constr.data = NULL;
4599         uint32_t* _res_vals = (uint32_t*) _res.ptr;
4600         for (size_t e = 0; e < _res_constr.datalen; e++) {
4601                 uint32_t arr_conv_30 = _res_vals[e];
4602                 LDKC2Tuple_usizeTransactionZ arr_conv_30_conv = *(LDKC2Tuple_usizeTransactionZ*)arr_conv_30;
4603                 FREE((void*)arr_conv_30);
4604                 _res_constr.data[e] = arr_conv_30_conv;
4605         }
4606         CVec_C2Tuple_usizeTransactionZZ_free(_res_constr);
4607 }
4608
4609 uint32_t CResult_1NoneChannelMonitorUpdateErrZ_1ok(void* ctx_TODO) {
4610         LDKCResult_NoneChannelMonitorUpdateErrZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneChannelMonitorUpdateErrZ), "LDKCResult_NoneChannelMonitorUpdateErrZ");
4611         *ret_conv = CResult_NoneChannelMonitorUpdateErrZ_ok();
4612         return (long)ret_conv;
4613 }
4614
4615 uint32_t CResult_1NoneChannelMonitorUpdateErrZ_1err(void* ctx_TODO, uint32_t e) {
4616         LDKChannelMonitorUpdateErr e_conv = LDKChannelMonitorUpdateErr_from_js(e);
4617         LDKCResult_NoneChannelMonitorUpdateErrZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneChannelMonitorUpdateErrZ), "LDKCResult_NoneChannelMonitorUpdateErrZ");
4618         *ret_conv = CResult_NoneChannelMonitorUpdateErrZ_err(e_conv);
4619         return (long)ret_conv;
4620 }
4621
4622 void CResult_1NoneChannelMonitorUpdateErrZ_1free(void* ctx_TODO, uint32_t _res) {
4623         LDKCResult_NoneChannelMonitorUpdateErrZ _res_conv = *(LDKCResult_NoneChannelMonitorUpdateErrZ*)_res;
4624         FREE((void*)_res);
4625         CResult_NoneChannelMonitorUpdateErrZ_free(_res_conv);
4626 }
4627
4628 void CVec_1MonitorEventZ_1free(void* ctx_TODO, uint32_tArray _res) {
4629         LDKCVec_MonitorEventZ _res_constr;
4630         _res_constr.datalen = _res.len;
4631         if (_res_constr.datalen > 0)
4632                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKMonitorEvent), "LDKCVec_MonitorEventZ Elements");
4633         else
4634                 _res_constr.data = NULL;
4635         uint32_t* _res_vals = (uint32_t*) _res.ptr;
4636         for (size_t o = 0; o < _res_constr.datalen; o++) {
4637                 uint32_t arr_conv_14 = _res_vals[o];
4638                 LDKMonitorEvent arr_conv_14_conv;
4639                 arr_conv_14_conv.inner = (void*)(arr_conv_14 & (~1));
4640                 arr_conv_14_conv.is_owned = (arr_conv_14 & 1) || (arr_conv_14 == 0);
4641                 _res_constr.data[o] = arr_conv_14_conv;
4642         }
4643         CVec_MonitorEventZ_free(_res_constr);
4644 }
4645
4646 uint32_t CResult_1ChannelMonitorUpdateDecodeErrorZ_1ok(void* ctx_TODO, uint32_t o) {
4647         LDKChannelMonitorUpdate o_conv;
4648         o_conv.inner = (void*)(o & (~1));
4649         o_conv.is_owned = (o & 1) || (o == 0);
4650         if (o_conv.inner != NULL)
4651                 o_conv = ChannelMonitorUpdate_clone(&o_conv);
4652         LDKCResult_ChannelMonitorUpdateDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ChannelMonitorUpdateDecodeErrorZ), "LDKCResult_ChannelMonitorUpdateDecodeErrorZ");
4653         *ret_conv = CResult_ChannelMonitorUpdateDecodeErrorZ_ok(o_conv);
4654         return (long)ret_conv;
4655 }
4656
4657 uint32_t CResult_1ChannelMonitorUpdateDecodeErrorZ_1err(void* ctx_TODO, uint32_t e) {
4658         LDKDecodeError e_conv;
4659         e_conv.inner = (void*)(e & (~1));
4660         e_conv.is_owned = (e & 1) || (e == 0);
4661         // Warning: we may need a move here but can't clone!
4662         LDKCResult_ChannelMonitorUpdateDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ChannelMonitorUpdateDecodeErrorZ), "LDKCResult_ChannelMonitorUpdateDecodeErrorZ");
4663         *ret_conv = CResult_ChannelMonitorUpdateDecodeErrorZ_err(e_conv);
4664         return (long)ret_conv;
4665 }
4666
4667 void CResult_1ChannelMonitorUpdateDecodeErrorZ_1free(void* ctx_TODO, uint32_t _res) {
4668         LDKCResult_ChannelMonitorUpdateDecodeErrorZ _res_conv = *(LDKCResult_ChannelMonitorUpdateDecodeErrorZ*)_res;
4669         FREE((void*)_res);
4670         CResult_ChannelMonitorUpdateDecodeErrorZ_free(_res_conv);
4671 }
4672
4673 uint32_t CResult_1NoneMonitorUpdateErrorZ_1ok(void* ctx_TODO) {
4674         LDKCResult_NoneMonitorUpdateErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneMonitorUpdateErrorZ), "LDKCResult_NoneMonitorUpdateErrorZ");
4675         *ret_conv = CResult_NoneMonitorUpdateErrorZ_ok();
4676         return (long)ret_conv;
4677 }
4678
4679 uint32_t CResult_1NoneMonitorUpdateErrorZ_1err(void* ctx_TODO, uint32_t e) {
4680         LDKMonitorUpdateError e_conv;
4681         e_conv.inner = (void*)(e & (~1));
4682         e_conv.is_owned = (e & 1) || (e == 0);
4683         // Warning: we may need a move here but can't clone!
4684         LDKCResult_NoneMonitorUpdateErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneMonitorUpdateErrorZ), "LDKCResult_NoneMonitorUpdateErrorZ");
4685         *ret_conv = CResult_NoneMonitorUpdateErrorZ_err(e_conv);
4686         return (long)ret_conv;
4687 }
4688
4689 void CResult_1NoneMonitorUpdateErrorZ_1free(void* ctx_TODO, uint32_t _res) {
4690         LDKCResult_NoneMonitorUpdateErrorZ _res_conv = *(LDKCResult_NoneMonitorUpdateErrorZ*)_res;
4691         FREE((void*)_res);
4692         CResult_NoneMonitorUpdateErrorZ_free(_res_conv);
4693 }
4694
4695 void C2Tuple_1OutPointScriptZ_1free(void* ctx_TODO, uint32_t _res) {
4696         LDKC2Tuple_OutPointScriptZ _res_conv = *(LDKC2Tuple_OutPointScriptZ*)_res;
4697         FREE((void*)_res);
4698         C2Tuple_OutPointScriptZ_free(_res_conv);
4699 }
4700
4701 uint32_t C2Tuple_1OutPointScriptZ_1new(void* ctx_TODO, uint32_t a, int8_tArray b) {
4702         LDKOutPoint a_conv;
4703         a_conv.inner = (void*)(a & (~1));
4704         a_conv.is_owned = (a & 1) || (a == 0);
4705         if (a_conv.inner != NULL)
4706                 a_conv = OutPoint_clone(&a_conv);
4707         LDKCVec_u8Z b_ref;
4708         b_ref.datalen = b.len;
4709         b_ref.data = MALLOC(b_ref.datalen, "LDKCVec_u8Z Bytes");
4710         memcpy(b_ref.data, b.ptr, b_ref.datalen);
4711         LDKC2Tuple_OutPointScriptZ* ret_ref = MALLOC(sizeof(LDKC2Tuple_OutPointScriptZ), "LDKC2Tuple_OutPointScriptZ");
4712         *ret_ref = C2Tuple_OutPointScriptZ_new(a_conv, b_ref);
4713         ret_ref->a = OutPoint_clone(&ret_ref->a);
4714         ret_ref->b = CVec_u8Z_clone(&ret_ref->b);
4715         return (long)ret_ref;
4716 }
4717
4718 void CVec_1TransactionZ_1free(void* ctx_TODO, ptrArray _res) {
4719         LDKCVec_TransactionZ _res_constr;
4720         _res_constr.datalen = _res.len;
4721         if (_res_constr.datalen > 0)
4722                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKTransaction), "LDKCVec_TransactionZ Elements");
4723         else
4724                 _res_constr.data = NULL;
4725         int8_tArray* _res_vals = (int8_tArray*) _res.ptr;
4726         for (size_t m = 0; m < _res_constr.datalen; m++) {
4727                 int8_tArray arr_conv_12 = _res_vals[m];
4728                 LDKTransaction arr_conv_12_ref;
4729                 arr_conv_12_ref.datalen = arr_conv_12.len;
4730                 arr_conv_12_ref.data = MALLOC(arr_conv_12_ref.datalen, "LDKTransaction Bytes");
4731                 memcpy(arr_conv_12_ref.data, arr_conv_12.ptr, arr_conv_12_ref.datalen);
4732                 arr_conv_12_ref.data_is_owned = true;
4733                 _res_constr.data[m] = arr_conv_12_ref;
4734         }
4735         CVec_TransactionZ_free(_res_constr);
4736 }
4737
4738 void C2Tuple_1u32TxOutZ_1free(void* ctx_TODO, uint32_t _res) {
4739         LDKC2Tuple_u32TxOutZ _res_conv = *(LDKC2Tuple_u32TxOutZ*)_res;
4740         FREE((void*)_res);
4741         C2Tuple_u32TxOutZ_free(_res_conv);
4742 }
4743
4744 uint32_t C2Tuple_1u32TxOutZ_1new(void* ctx_TODO, int32_t a, uint32_t b) {
4745         LDKTxOut b_conv = *(LDKTxOut*)b;
4746         FREE((void*)b);
4747         LDKC2Tuple_u32TxOutZ* ret_ref = MALLOC(sizeof(LDKC2Tuple_u32TxOutZ), "LDKC2Tuple_u32TxOutZ");
4748         *ret_ref = C2Tuple_u32TxOutZ_new(a, b_conv);
4749         // XXX: We likely need to clone here, but no _clone fn is available for TxOut
4750         return (long)ret_ref;
4751 }
4752
4753 void CVec_1C2Tuple_1u32TxOutZZ_1free(void* ctx_TODO, uint32_tArray _res) {
4754         LDKCVec_C2Tuple_u32TxOutZZ _res_constr;
4755         _res_constr.datalen = _res.len;
4756         if (_res_constr.datalen > 0)
4757                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKC2Tuple_u32TxOutZ), "LDKCVec_C2Tuple_u32TxOutZZ Elements");
4758         else
4759                 _res_constr.data = NULL;
4760         uint32_t* _res_vals = (uint32_t*) _res.ptr;
4761         for (size_t z = 0; z < _res_constr.datalen; z++) {
4762                 uint32_t arr_conv_25 = _res_vals[z];
4763                 LDKC2Tuple_u32TxOutZ arr_conv_25_conv = *(LDKC2Tuple_u32TxOutZ*)arr_conv_25;
4764                 FREE((void*)arr_conv_25);
4765                 _res_constr.data[z] = arr_conv_25_conv;
4766         }
4767         CVec_C2Tuple_u32TxOutZZ_free(_res_constr);
4768 }
4769
4770 void C2Tuple_1TxidCVec_1C2Tuple_1u32TxOutZZZ_1free(void* ctx_TODO, uint32_t _res) {
4771         LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ _res_conv = *(LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ*)_res;
4772         FREE((void*)_res);
4773         C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ_free(_res_conv);
4774 }
4775
4776 uint32_t C2Tuple_1TxidCVec_1C2Tuple_1u32TxOutZZZ_1new(void* ctx_TODO, int8_tArray a, uint32_tArray b) {
4777         LDKThirtyTwoBytes a_ref;
4778         CHECK(a.len == 32);
4779         memcpy(a_ref.data, a.ptr, 32);
4780         LDKCVec_C2Tuple_u32TxOutZZ b_constr;
4781         b_constr.datalen = b.len;
4782         if (b_constr.datalen > 0)
4783                 b_constr.data = MALLOC(b_constr.datalen * sizeof(LDKC2Tuple_u32TxOutZ), "LDKCVec_C2Tuple_u32TxOutZZ Elements");
4784         else
4785                 b_constr.data = NULL;
4786         uint32_t* b_vals = (uint32_t*) b.ptr;
4787         for (size_t z = 0; z < b_constr.datalen; z++) {
4788                 uint32_t arr_conv_25 = b_vals[z];
4789                 LDKC2Tuple_u32TxOutZ arr_conv_25_conv = *(LDKC2Tuple_u32TxOutZ*)arr_conv_25;
4790                 FREE((void*)arr_conv_25);
4791                 b_constr.data[z] = arr_conv_25_conv;
4792         }
4793         LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ* ret_ref = MALLOC(sizeof(LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ), "LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ");
4794         *ret_ref = C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ_new(a_ref, b_constr);
4795         ret_ref->a = ThirtyTwoBytes_clone(&ret_ref->a);
4796         // XXX: We likely need to clone here, but no _clone fn is available for TwoTuple<Number, TxOut>[]
4797         return (long)ret_ref;
4798 }
4799
4800 void CVec_1C2Tuple_1TxidCVec_1C2Tuple_1u32TxOutZZZZ_1free(void* ctx_TODO, uint32_tArray _res) {
4801         LDKCVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ _res_constr;
4802         _res_constr.datalen = _res.len;
4803         if (_res_constr.datalen > 0)
4804                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ), "LDKCVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ Elements");
4805         else
4806                 _res_constr.data = NULL;
4807         uint32_t* _res_vals = (uint32_t*) _res.ptr;
4808         for (size_t x = 0; x < _res_constr.datalen; x++) {
4809                 uint32_t arr_conv_49 = _res_vals[x];
4810                 LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ arr_conv_49_conv = *(LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ*)arr_conv_49;
4811                 FREE((void*)arr_conv_49);
4812                 _res_constr.data[x] = arr_conv_49_conv;
4813         }
4814         CVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ_free(_res_constr);
4815 }
4816
4817 void C2Tuple_1BlockHashChannelMonitorZ_1free(void* ctx_TODO, uint32_t _res) {
4818         LDKC2Tuple_BlockHashChannelMonitorZ _res_conv = *(LDKC2Tuple_BlockHashChannelMonitorZ*)_res;
4819         FREE((void*)_res);
4820         C2Tuple_BlockHashChannelMonitorZ_free(_res_conv);
4821 }
4822
4823 uint32_t C2Tuple_1BlockHashChannelMonitorZ_1new(void* ctx_TODO, int8_tArray a, uint32_t b) {
4824         LDKThirtyTwoBytes a_ref;
4825         CHECK(a.len == 32);
4826         memcpy(a_ref.data, a.ptr, 32);
4827         LDKChannelMonitor b_conv;
4828         b_conv.inner = (void*)(b & (~1));
4829         b_conv.is_owned = (b & 1) || (b == 0);
4830         // Warning: we may need a move here but can't clone!
4831         LDKC2Tuple_BlockHashChannelMonitorZ* ret_ref = MALLOC(sizeof(LDKC2Tuple_BlockHashChannelMonitorZ), "LDKC2Tuple_BlockHashChannelMonitorZ");
4832         *ret_ref = C2Tuple_BlockHashChannelMonitorZ_new(a_ref, b_conv);
4833         ret_ref->a = ThirtyTwoBytes_clone(&ret_ref->a);
4834         // XXX: We likely need to clone here, but no _clone fn is available for ChannelMonitor
4835         return (long)ret_ref;
4836 }
4837
4838 uint32_t CResult_1C2Tuple_1BlockHashChannelMonitorZDecodeErrorZ_1ok(void* ctx_TODO, uint32_t o) {
4839         LDKC2Tuple_BlockHashChannelMonitorZ o_conv = *(LDKC2Tuple_BlockHashChannelMonitorZ*)o;
4840         FREE((void*)o);
4841         LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ), "LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ");
4842         *ret_conv = CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ_ok(o_conv);
4843         return (long)ret_conv;
4844 }
4845
4846 uint32_t CResult_1C2Tuple_1BlockHashChannelMonitorZDecodeErrorZ_1err(void* ctx_TODO, uint32_t e) {
4847         LDKDecodeError e_conv;
4848         e_conv.inner = (void*)(e & (~1));
4849         e_conv.is_owned = (e & 1) || (e == 0);
4850         // Warning: we may need a move here but can't clone!
4851         LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ), "LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ");
4852         *ret_conv = CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ_err(e_conv);
4853         return (long)ret_conv;
4854 }
4855
4856 void CResult_1C2Tuple_1BlockHashChannelMonitorZDecodeErrorZ_1free(void* ctx_TODO, uint32_t _res) {
4857         LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ _res_conv = *(LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ*)_res;
4858         FREE((void*)_res);
4859         CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ_free(_res_conv);
4860 }
4861
4862 void C2Tuple_1u64u64Z_1free(void* ctx_TODO, uint32_t _res) {
4863         LDKC2Tuple_u64u64Z _res_conv = *(LDKC2Tuple_u64u64Z*)_res;
4864         FREE((void*)_res);
4865         C2Tuple_u64u64Z_free(_res_conv);
4866 }
4867
4868 uint32_t C2Tuple_1u64u64Z_1new(void* ctx_TODO, int64_t a, int64_t b) {
4869         LDKC2Tuple_u64u64Z* ret_ref = MALLOC(sizeof(LDKC2Tuple_u64u64Z), "LDKC2Tuple_u64u64Z");
4870         *ret_ref = C2Tuple_u64u64Z_new(a, b);
4871         return (long)ret_ref;
4872 }
4873
4874 uint32_t CResult_1SpendableOutputDescriptorDecodeErrorZ_1ok(void* ctx_TODO, uint32_t o) {
4875         LDKSpendableOutputDescriptor o_conv = *(LDKSpendableOutputDescriptor*)o;
4876         FREE((void*)o);
4877         LDKCResult_SpendableOutputDescriptorDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_SpendableOutputDescriptorDecodeErrorZ), "LDKCResult_SpendableOutputDescriptorDecodeErrorZ");
4878         *ret_conv = CResult_SpendableOutputDescriptorDecodeErrorZ_ok(o_conv);
4879         return (long)ret_conv;
4880 }
4881
4882 uint32_t CResult_1SpendableOutputDescriptorDecodeErrorZ_1err(void* ctx_TODO, uint32_t e) {
4883         LDKDecodeError e_conv;
4884         e_conv.inner = (void*)(e & (~1));
4885         e_conv.is_owned = (e & 1) || (e == 0);
4886         // Warning: we may need a move here but can't clone!
4887         LDKCResult_SpendableOutputDescriptorDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_SpendableOutputDescriptorDecodeErrorZ), "LDKCResult_SpendableOutputDescriptorDecodeErrorZ");
4888         *ret_conv = CResult_SpendableOutputDescriptorDecodeErrorZ_err(e_conv);
4889         return (long)ret_conv;
4890 }
4891
4892 void CResult_1SpendableOutputDescriptorDecodeErrorZ_1free(void* ctx_TODO, uint32_t _res) {
4893         LDKCResult_SpendableOutputDescriptorDecodeErrorZ _res_conv = *(LDKCResult_SpendableOutputDescriptorDecodeErrorZ*)_res;
4894         FREE((void*)_res);
4895         CResult_SpendableOutputDescriptorDecodeErrorZ_free(_res_conv);
4896 }
4897
4898 void CVec_1SignatureZ_1free(void* ctx_TODO, ptrArray _res) {
4899         LDKCVec_SignatureZ _res_constr;
4900         _res_constr.datalen = _res.len;
4901         if (_res_constr.datalen > 0)
4902                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKSignature), "LDKCVec_SignatureZ Elements");
4903         else
4904                 _res_constr.data = NULL;
4905         int8_tArray* _res_vals = (int8_tArray*) _res.ptr;
4906         for (size_t m = 0; m < _res_constr.datalen; m++) {
4907                 int8_tArray arr_conv_12 = _res_vals[m];
4908                 LDKSignature arr_conv_12_ref;
4909                 CHECK(arr_conv_12.len == 64);
4910                 memcpy(arr_conv_12_ref.compact_form, arr_conv_12.ptr, 64);
4911                 _res_constr.data[m] = arr_conv_12_ref;
4912         }
4913         CVec_SignatureZ_free(_res_constr);
4914 }
4915
4916 void C2Tuple_1SignatureCVec_1SignatureZZ_1free(void* ctx_TODO, uint32_t _res) {
4917         LDKC2Tuple_SignatureCVec_SignatureZZ _res_conv = *(LDKC2Tuple_SignatureCVec_SignatureZZ*)_res;
4918         FREE((void*)_res);
4919         C2Tuple_SignatureCVec_SignatureZZ_free(_res_conv);
4920 }
4921
4922 uint32_t C2Tuple_1SignatureCVec_1SignatureZZ_1new(void* ctx_TODO, int8_tArray a, ptrArray b) {
4923         LDKSignature a_ref;
4924         CHECK(a.len == 64);
4925         memcpy(a_ref.compact_form, a.ptr, 64);
4926         LDKCVec_SignatureZ b_constr;
4927         b_constr.datalen = b.len;
4928         if (b_constr.datalen > 0)
4929                 b_constr.data = MALLOC(b_constr.datalen * sizeof(LDKSignature), "LDKCVec_SignatureZ Elements");
4930         else
4931                 b_constr.data = NULL;
4932         int8_tArray* b_vals = (int8_tArray*) b.ptr;
4933         for (size_t m = 0; m < b_constr.datalen; m++) {
4934                 int8_tArray arr_conv_12 = b_vals[m];
4935                 LDKSignature arr_conv_12_ref;
4936                 CHECK(arr_conv_12.len == 64);
4937                 memcpy(arr_conv_12_ref.compact_form, arr_conv_12.ptr, 64);
4938                 b_constr.data[m] = arr_conv_12_ref;
4939         }
4940         LDKC2Tuple_SignatureCVec_SignatureZZ* ret_ref = MALLOC(sizeof(LDKC2Tuple_SignatureCVec_SignatureZZ), "LDKC2Tuple_SignatureCVec_SignatureZZ");
4941         *ret_ref = C2Tuple_SignatureCVec_SignatureZZ_new(a_ref, b_constr);
4942         // XXX: We likely need to clone here, but no _clone fn is available for Uint8Array
4943         // XXX: We likely need to clone here, but no _clone fn is available for Uint8Array[]
4944         return (long)ret_ref;
4945 }
4946
4947 uint32_t CResult_1C2Tuple_1SignatureCVec_1SignatureZZNoneZ_1ok(void* ctx_TODO, uint32_t o) {
4948         LDKC2Tuple_SignatureCVec_SignatureZZ o_conv = *(LDKC2Tuple_SignatureCVec_SignatureZZ*)o;
4949         FREE((void*)o);
4950         LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ), "LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ");
4951         *ret_conv = CResult_C2Tuple_SignatureCVec_SignatureZZNoneZ_ok(o_conv);
4952         return (long)ret_conv;
4953 }
4954
4955 uint32_t CResult_1C2Tuple_1SignatureCVec_1SignatureZZNoneZ_1err(void* ctx_TODO) {
4956         LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ), "LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ");
4957         *ret_conv = CResult_C2Tuple_SignatureCVec_SignatureZZNoneZ_err();
4958         return (long)ret_conv;
4959 }
4960
4961 void CResult_1C2Tuple_1SignatureCVec_1SignatureZZNoneZ_1free(void* ctx_TODO, uint32_t _res) {
4962         LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ _res_conv = *(LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ*)_res;
4963         FREE((void*)_res);
4964         CResult_C2Tuple_SignatureCVec_SignatureZZNoneZ_free(_res_conv);
4965 }
4966
4967 uint32_t CResult_1SignatureNoneZ_1ok(void* ctx_TODO, int8_tArray o) {
4968         LDKSignature o_ref;
4969         CHECK(o.len == 64);
4970         memcpy(o_ref.compact_form, o.ptr, 64);
4971         LDKCResult_SignatureNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_SignatureNoneZ), "LDKCResult_SignatureNoneZ");
4972         *ret_conv = CResult_SignatureNoneZ_ok(o_ref);
4973         return (long)ret_conv;
4974 }
4975
4976 uint32_t CResult_1SignatureNoneZ_1err(void* ctx_TODO) {
4977         LDKCResult_SignatureNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_SignatureNoneZ), "LDKCResult_SignatureNoneZ");
4978         *ret_conv = CResult_SignatureNoneZ_err();
4979         return (long)ret_conv;
4980 }
4981
4982 void CResult_1SignatureNoneZ_1free(void* ctx_TODO, uint32_t _res) {
4983         LDKCResult_SignatureNoneZ _res_conv = *(LDKCResult_SignatureNoneZ*)_res;
4984         FREE((void*)_res);
4985         CResult_SignatureNoneZ_free(_res_conv);
4986 }
4987
4988 uint32_t CResult_1CVec_1SignatureZNoneZ_1ok(void* ctx_TODO, ptrArray o) {
4989         LDKCVec_SignatureZ o_constr;
4990         o_constr.datalen = o.len;
4991         if (o_constr.datalen > 0)
4992                 o_constr.data = MALLOC(o_constr.datalen * sizeof(LDKSignature), "LDKCVec_SignatureZ Elements");
4993         else
4994                 o_constr.data = NULL;
4995         int8_tArray* o_vals = (int8_tArray*) o.ptr;
4996         for (size_t m = 0; m < o_constr.datalen; m++) {
4997                 int8_tArray arr_conv_12 = o_vals[m];
4998                 LDKSignature arr_conv_12_ref;
4999                 CHECK(arr_conv_12.len == 64);
5000                 memcpy(arr_conv_12_ref.compact_form, arr_conv_12.ptr, 64);
5001                 o_constr.data[m] = arr_conv_12_ref;
5002         }
5003         LDKCResult_CVec_SignatureZNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_CVec_SignatureZNoneZ), "LDKCResult_CVec_SignatureZNoneZ");
5004         *ret_conv = CResult_CVec_SignatureZNoneZ_ok(o_constr);
5005         return (long)ret_conv;
5006 }
5007
5008 uint32_t CResult_1CVec_1SignatureZNoneZ_1err(void* ctx_TODO) {
5009         LDKCResult_CVec_SignatureZNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_CVec_SignatureZNoneZ), "LDKCResult_CVec_SignatureZNoneZ");
5010         *ret_conv = CResult_CVec_SignatureZNoneZ_err();
5011         return (long)ret_conv;
5012 }
5013
5014 void CResult_1CVec_1SignatureZNoneZ_1free(void* ctx_TODO, uint32_t _res) {
5015         LDKCResult_CVec_SignatureZNoneZ _res_conv = *(LDKCResult_CVec_SignatureZNoneZ*)_res;
5016         FREE((void*)_res);
5017         CResult_CVec_SignatureZNoneZ_free(_res_conv);
5018 }
5019
5020 uint32_t CResult_1ChanKeySignerDecodeErrorZ_1ok(void* ctx_TODO, uint32_t o) {
5021         LDKChannelKeys o_conv = *(LDKChannelKeys*)o;
5022         LDKCResult_ChanKeySignerDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ChanKeySignerDecodeErrorZ), "LDKCResult_ChanKeySignerDecodeErrorZ");
5023         *ret_conv = CResult_ChanKeySignerDecodeErrorZ_ok(o_conv);
5024         return (long)ret_conv;
5025 }
5026
5027 uint32_t CResult_1ChanKeySignerDecodeErrorZ_1err(void* ctx_TODO, uint32_t e) {
5028         LDKDecodeError e_conv;
5029         e_conv.inner = (void*)(e & (~1));
5030         e_conv.is_owned = (e & 1) || (e == 0);
5031         // Warning: we may need a move here but can't clone!
5032         LDKCResult_ChanKeySignerDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ChanKeySignerDecodeErrorZ), "LDKCResult_ChanKeySignerDecodeErrorZ");
5033         *ret_conv = CResult_ChanKeySignerDecodeErrorZ_err(e_conv);
5034         return (long)ret_conv;
5035 }
5036
5037 void CResult_1ChanKeySignerDecodeErrorZ_1free(void* ctx_TODO, uint32_t _res) {
5038         LDKCResult_ChanKeySignerDecodeErrorZ _res_conv = *(LDKCResult_ChanKeySignerDecodeErrorZ*)_res;
5039         FREE((void*)_res);
5040         CResult_ChanKeySignerDecodeErrorZ_free(_res_conv);
5041 }
5042
5043 uint32_t CResult_1InMemoryChannelKeysDecodeErrorZ_1ok(void* ctx_TODO, uint32_t o) {
5044         LDKInMemoryChannelKeys o_conv;
5045         o_conv.inner = (void*)(o & (~1));
5046         o_conv.is_owned = (o & 1) || (o == 0);
5047         if (o_conv.inner != NULL)
5048                 o_conv = InMemoryChannelKeys_clone(&o_conv);
5049         LDKCResult_InMemoryChannelKeysDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_InMemoryChannelKeysDecodeErrorZ), "LDKCResult_InMemoryChannelKeysDecodeErrorZ");
5050         *ret_conv = CResult_InMemoryChannelKeysDecodeErrorZ_ok(o_conv);
5051         return (long)ret_conv;
5052 }
5053
5054 uint32_t CResult_1InMemoryChannelKeysDecodeErrorZ_1err(void* ctx_TODO, uint32_t e) {
5055         LDKDecodeError e_conv;
5056         e_conv.inner = (void*)(e & (~1));
5057         e_conv.is_owned = (e & 1) || (e == 0);
5058         // Warning: we may need a move here but can't clone!
5059         LDKCResult_InMemoryChannelKeysDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_InMemoryChannelKeysDecodeErrorZ), "LDKCResult_InMemoryChannelKeysDecodeErrorZ");
5060         *ret_conv = CResult_InMemoryChannelKeysDecodeErrorZ_err(e_conv);
5061         return (long)ret_conv;
5062 }
5063
5064 void CResult_1InMemoryChannelKeysDecodeErrorZ_1free(void* ctx_TODO, uint32_t _res) {
5065         LDKCResult_InMemoryChannelKeysDecodeErrorZ _res_conv = *(LDKCResult_InMemoryChannelKeysDecodeErrorZ*)_res;
5066         FREE((void*)_res);
5067         CResult_InMemoryChannelKeysDecodeErrorZ_free(_res_conv);
5068 }
5069
5070 uint32_t CResult_1TxOutAccessErrorZ_1ok(void* ctx_TODO, uint32_t o) {
5071         LDKTxOut o_conv = *(LDKTxOut*)o;
5072         FREE((void*)o);
5073         LDKCResult_TxOutAccessErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_TxOutAccessErrorZ), "LDKCResult_TxOutAccessErrorZ");
5074         *ret_conv = CResult_TxOutAccessErrorZ_ok(o_conv);
5075         return (long)ret_conv;
5076 }
5077
5078 uint32_t CResult_1TxOutAccessErrorZ_1err(void* ctx_TODO, uint32_t e) {
5079         LDKAccessError e_conv = LDKAccessError_from_js(e);
5080         LDKCResult_TxOutAccessErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_TxOutAccessErrorZ), "LDKCResult_TxOutAccessErrorZ");
5081         *ret_conv = CResult_TxOutAccessErrorZ_err(e_conv);
5082         return (long)ret_conv;
5083 }
5084
5085 void CResult_1TxOutAccessErrorZ_1free(void* ctx_TODO, uint32_t _res) {
5086         LDKCResult_TxOutAccessErrorZ _res_conv = *(LDKCResult_TxOutAccessErrorZ*)_res;
5087         FREE((void*)_res);
5088         CResult_TxOutAccessErrorZ_free(_res_conv);
5089 }
5090
5091 uint32_t CResult_1NoneAPIErrorZ_1ok(void* ctx_TODO) {
5092         LDKCResult_NoneAPIErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneAPIErrorZ), "LDKCResult_NoneAPIErrorZ");
5093         *ret_conv = CResult_NoneAPIErrorZ_ok();
5094         return (long)ret_conv;
5095 }
5096
5097 uint32_t CResult_1NoneAPIErrorZ_1err(void* ctx_TODO, uint32_t e) {
5098         LDKAPIError e_conv = *(LDKAPIError*)e;
5099         FREE((void*)e);
5100         LDKCResult_NoneAPIErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneAPIErrorZ), "LDKCResult_NoneAPIErrorZ");
5101         *ret_conv = CResult_NoneAPIErrorZ_err(e_conv);
5102         return (long)ret_conv;
5103 }
5104
5105 void CResult_1NoneAPIErrorZ_1free(void* ctx_TODO, uint32_t _res) {
5106         LDKCResult_NoneAPIErrorZ _res_conv = *(LDKCResult_NoneAPIErrorZ*)_res;
5107         FREE((void*)_res);
5108         CResult_NoneAPIErrorZ_free(_res_conv);
5109 }
5110
5111 void CVec_1ChannelDetailsZ_1free(void* ctx_TODO, uint32_tArray _res) {
5112         LDKCVec_ChannelDetailsZ _res_constr;
5113         _res_constr.datalen = _res.len;
5114         if (_res_constr.datalen > 0)
5115                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKChannelDetails), "LDKCVec_ChannelDetailsZ Elements");
5116         else
5117                 _res_constr.data = NULL;
5118         uint32_t* _res_vals = (uint32_t*) _res.ptr;
5119         for (size_t q = 0; q < _res_constr.datalen; q++) {
5120                 uint32_t arr_conv_16 = _res_vals[q];
5121                 LDKChannelDetails arr_conv_16_conv;
5122                 arr_conv_16_conv.inner = (void*)(arr_conv_16 & (~1));
5123                 arr_conv_16_conv.is_owned = (arr_conv_16 & 1) || (arr_conv_16 == 0);
5124                 _res_constr.data[q] = arr_conv_16_conv;
5125         }
5126         CVec_ChannelDetailsZ_free(_res_constr);
5127 }
5128
5129 uint32_t CResult_1NonePaymentSendFailureZ_1ok(void* ctx_TODO) {
5130         LDKCResult_NonePaymentSendFailureZ* ret_conv = MALLOC(sizeof(LDKCResult_NonePaymentSendFailureZ), "LDKCResult_NonePaymentSendFailureZ");
5131         *ret_conv = CResult_NonePaymentSendFailureZ_ok();
5132         return (long)ret_conv;
5133 }
5134
5135 uint32_t CResult_1NonePaymentSendFailureZ_1err(void* ctx_TODO, uint32_t e) {
5136         LDKPaymentSendFailure e_conv;
5137         e_conv.inner = (void*)(e & (~1));
5138         e_conv.is_owned = (e & 1) || (e == 0);
5139         // Warning: we may need a move here but can't clone!
5140         LDKCResult_NonePaymentSendFailureZ* ret_conv = MALLOC(sizeof(LDKCResult_NonePaymentSendFailureZ), "LDKCResult_NonePaymentSendFailureZ");
5141         *ret_conv = CResult_NonePaymentSendFailureZ_err(e_conv);
5142         return (long)ret_conv;
5143 }
5144
5145 void CResult_1NonePaymentSendFailureZ_1free(void* ctx_TODO, uint32_t _res) {
5146         LDKCResult_NonePaymentSendFailureZ _res_conv = *(LDKCResult_NonePaymentSendFailureZ*)_res;
5147         FREE((void*)_res);
5148         CResult_NonePaymentSendFailureZ_free(_res_conv);
5149 }
5150
5151 void CVec_1NetAddressZ_1free(void* ctx_TODO, uint32_tArray _res) {
5152         LDKCVec_NetAddressZ _res_constr;
5153         _res_constr.datalen = _res.len;
5154         if (_res_constr.datalen > 0)
5155                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKNetAddress), "LDKCVec_NetAddressZ Elements");
5156         else
5157                 _res_constr.data = NULL;
5158         uint32_t* _res_vals = (uint32_t*) _res.ptr;
5159         for (size_t m = 0; m < _res_constr.datalen; m++) {
5160                 uint32_t arr_conv_12 = _res_vals[m];
5161                 LDKNetAddress arr_conv_12_conv = *(LDKNetAddress*)arr_conv_12;
5162                 FREE((void*)arr_conv_12);
5163                 _res_constr.data[m] = arr_conv_12_conv;
5164         }
5165         CVec_NetAddressZ_free(_res_constr);
5166 }
5167
5168 void CVec_1ChannelMonitorZ_1free(void* ctx_TODO, uint32_tArray _res) {
5169         LDKCVec_ChannelMonitorZ _res_constr;
5170         _res_constr.datalen = _res.len;
5171         if (_res_constr.datalen > 0)
5172                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKChannelMonitor), "LDKCVec_ChannelMonitorZ Elements");
5173         else
5174                 _res_constr.data = NULL;
5175         uint32_t* _res_vals = (uint32_t*) _res.ptr;
5176         for (size_t q = 0; q < _res_constr.datalen; q++) {
5177                 uint32_t arr_conv_16 = _res_vals[q];
5178                 LDKChannelMonitor arr_conv_16_conv;
5179                 arr_conv_16_conv.inner = (void*)(arr_conv_16 & (~1));
5180                 arr_conv_16_conv.is_owned = (arr_conv_16 & 1) || (arr_conv_16 == 0);
5181                 _res_constr.data[q] = arr_conv_16_conv;
5182         }
5183         CVec_ChannelMonitorZ_free(_res_constr);
5184 }
5185
5186 void C2Tuple_1BlockHashChannelManagerZ_1free(void* ctx_TODO, uint32_t _res) {
5187         LDKC2Tuple_BlockHashChannelManagerZ _res_conv = *(LDKC2Tuple_BlockHashChannelManagerZ*)_res;
5188         FREE((void*)_res);
5189         C2Tuple_BlockHashChannelManagerZ_free(_res_conv);
5190 }
5191
5192 uint32_t C2Tuple_1BlockHashChannelManagerZ_1new(void* ctx_TODO, int8_tArray a, uint32_t b) {
5193         LDKThirtyTwoBytes a_ref;
5194         CHECK(a.len == 32);
5195         memcpy(a_ref.data, a.ptr, 32);
5196         LDKChannelManager b_conv;
5197         b_conv.inner = (void*)(b & (~1));
5198         b_conv.is_owned = (b & 1) || (b == 0);
5199         // Warning: we may need a move here but can't clone!
5200         LDKC2Tuple_BlockHashChannelManagerZ* ret_ref = MALLOC(sizeof(LDKC2Tuple_BlockHashChannelManagerZ), "LDKC2Tuple_BlockHashChannelManagerZ");
5201         *ret_ref = C2Tuple_BlockHashChannelManagerZ_new(a_ref, b_conv);
5202         ret_ref->a = ThirtyTwoBytes_clone(&ret_ref->a);
5203         // XXX: We likely need to clone here, but no _clone fn is available for ChannelManager
5204         return (long)ret_ref;
5205 }
5206
5207 uint32_t CResult_1C2Tuple_1BlockHashChannelManagerZDecodeErrorZ_1ok(void* ctx_TODO, uint32_t o) {
5208         LDKC2Tuple_BlockHashChannelManagerZ o_conv = *(LDKC2Tuple_BlockHashChannelManagerZ*)o;
5209         FREE((void*)o);
5210         LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ), "LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ");
5211         *ret_conv = CResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ_ok(o_conv);
5212         return (long)ret_conv;
5213 }
5214
5215 uint32_t CResult_1C2Tuple_1BlockHashChannelManagerZDecodeErrorZ_1err(void* ctx_TODO, uint32_t e) {
5216         LDKDecodeError e_conv;
5217         e_conv.inner = (void*)(e & (~1));
5218         e_conv.is_owned = (e & 1) || (e == 0);
5219         // Warning: we may need a move here but can't clone!
5220         LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ), "LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ");
5221         *ret_conv = CResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ_err(e_conv);
5222         return (long)ret_conv;
5223 }
5224
5225 void CResult_1C2Tuple_1BlockHashChannelManagerZDecodeErrorZ_1free(void* ctx_TODO, uint32_t _res) {
5226         LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ _res_conv = *(LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ*)_res;
5227         FREE((void*)_res);
5228         CResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ_free(_res_conv);
5229 }
5230
5231 uint32_t CResult_1NetAddressu8Z_1ok(void* ctx_TODO, uint32_t o) {
5232         LDKNetAddress o_conv = *(LDKNetAddress*)o;
5233         FREE((void*)o);
5234         LDKCResult_NetAddressu8Z* ret_conv = MALLOC(sizeof(LDKCResult_NetAddressu8Z), "LDKCResult_NetAddressu8Z");
5235         *ret_conv = CResult_NetAddressu8Z_ok(o_conv);
5236         return (long)ret_conv;
5237 }
5238
5239 uint32_t CResult_1NetAddressu8Z_1err(void* ctx_TODO, int8_t e) {
5240         LDKCResult_NetAddressu8Z* ret_conv = MALLOC(sizeof(LDKCResult_NetAddressu8Z), "LDKCResult_NetAddressu8Z");
5241         *ret_conv = CResult_NetAddressu8Z_err(e);
5242         return (long)ret_conv;
5243 }
5244
5245 void CResult_1NetAddressu8Z_1free(void* ctx_TODO, uint32_t _res) {
5246         LDKCResult_NetAddressu8Z _res_conv = *(LDKCResult_NetAddressu8Z*)_res;
5247         FREE((void*)_res);
5248         CResult_NetAddressu8Z_free(_res_conv);
5249 }
5250
5251 uint32_t CResult_1CResult_1NetAddressu8ZDecodeErrorZ_1ok(void* ctx_TODO, uint32_t o) {
5252         LDKCResult_NetAddressu8Z o_conv = *(LDKCResult_NetAddressu8Z*)o;
5253         FREE((void*)o);
5254         LDKCResult_CResult_NetAddressu8ZDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_CResult_NetAddressu8ZDecodeErrorZ), "LDKCResult_CResult_NetAddressu8ZDecodeErrorZ");
5255         *ret_conv = CResult_CResult_NetAddressu8ZDecodeErrorZ_ok(o_conv);
5256         return (long)ret_conv;
5257 }
5258
5259 uint32_t CResult_1CResult_1NetAddressu8ZDecodeErrorZ_1err(void* ctx_TODO, uint32_t e) {
5260         LDKDecodeError e_conv;
5261         e_conv.inner = (void*)(e & (~1));
5262         e_conv.is_owned = (e & 1) || (e == 0);
5263         // Warning: we may need a move here but can't clone!
5264         LDKCResult_CResult_NetAddressu8ZDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_CResult_NetAddressu8ZDecodeErrorZ), "LDKCResult_CResult_NetAddressu8ZDecodeErrorZ");
5265         *ret_conv = CResult_CResult_NetAddressu8ZDecodeErrorZ_err(e_conv);
5266         return (long)ret_conv;
5267 }
5268
5269 void CResult_1CResult_1NetAddressu8ZDecodeErrorZ_1free(void* ctx_TODO, uint32_t _res) {
5270         LDKCResult_CResult_NetAddressu8ZDecodeErrorZ _res_conv = *(LDKCResult_CResult_NetAddressu8ZDecodeErrorZ*)_res;
5271         FREE((void*)_res);
5272         CResult_CResult_NetAddressu8ZDecodeErrorZ_free(_res_conv);
5273 }
5274
5275 void CVec_1u64Z_1free(void* ctx_TODO, int64_tArray _res) {
5276         LDKCVec_u64Z _res_constr;
5277         _res_constr.datalen = _res.len;
5278         if (_res_constr.datalen > 0)
5279                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(int64_t), "LDKCVec_u64Z Elements");
5280         else
5281                 _res_constr.data = NULL;
5282         int64_t* _res_vals = (int64_t*) _res.ptr;
5283         for (size_t i = 0; i < _res_constr.datalen; i++) {
5284                 int64_t arr_conv_8 = _res_vals[i];
5285                 _res_constr.data[i] = arr_conv_8;
5286         }
5287         CVec_u64Z_free(_res_constr);
5288 }
5289
5290 void CVec_1UpdateAddHTLCZ_1free(void* ctx_TODO, uint32_tArray _res) {
5291         LDKCVec_UpdateAddHTLCZ _res_constr;
5292         _res_constr.datalen = _res.len;
5293         if (_res_constr.datalen > 0)
5294                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKUpdateAddHTLC), "LDKCVec_UpdateAddHTLCZ Elements");
5295         else
5296                 _res_constr.data = NULL;
5297         uint32_t* _res_vals = (uint32_t*) _res.ptr;
5298         for (size_t p = 0; p < _res_constr.datalen; p++) {
5299                 uint32_t arr_conv_15 = _res_vals[p];
5300                 LDKUpdateAddHTLC arr_conv_15_conv;
5301                 arr_conv_15_conv.inner = (void*)(arr_conv_15 & (~1));
5302                 arr_conv_15_conv.is_owned = (arr_conv_15 & 1) || (arr_conv_15 == 0);
5303                 _res_constr.data[p] = arr_conv_15_conv;
5304         }
5305         CVec_UpdateAddHTLCZ_free(_res_constr);
5306 }
5307
5308 void CVec_1UpdateFulfillHTLCZ_1free(void* ctx_TODO, uint32_tArray _res) {
5309         LDKCVec_UpdateFulfillHTLCZ _res_constr;
5310         _res_constr.datalen = _res.len;
5311         if (_res_constr.datalen > 0)
5312                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKUpdateFulfillHTLC), "LDKCVec_UpdateFulfillHTLCZ Elements");
5313         else
5314                 _res_constr.data = NULL;
5315         uint32_t* _res_vals = (uint32_t*) _res.ptr;
5316         for (size_t t = 0; t < _res_constr.datalen; t++) {
5317                 uint32_t arr_conv_19 = _res_vals[t];
5318                 LDKUpdateFulfillHTLC arr_conv_19_conv;
5319                 arr_conv_19_conv.inner = (void*)(arr_conv_19 & (~1));
5320                 arr_conv_19_conv.is_owned = (arr_conv_19 & 1) || (arr_conv_19 == 0);
5321                 _res_constr.data[t] = arr_conv_19_conv;
5322         }
5323         CVec_UpdateFulfillHTLCZ_free(_res_constr);
5324 }
5325
5326 void CVec_1UpdateFailHTLCZ_1free(void* ctx_TODO, uint32_tArray _res) {
5327         LDKCVec_UpdateFailHTLCZ _res_constr;
5328         _res_constr.datalen = _res.len;
5329         if (_res_constr.datalen > 0)
5330                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKUpdateFailHTLC), "LDKCVec_UpdateFailHTLCZ Elements");
5331         else
5332                 _res_constr.data = NULL;
5333         uint32_t* _res_vals = (uint32_t*) _res.ptr;
5334         for (size_t q = 0; q < _res_constr.datalen; q++) {
5335                 uint32_t arr_conv_16 = _res_vals[q];
5336                 LDKUpdateFailHTLC arr_conv_16_conv;
5337                 arr_conv_16_conv.inner = (void*)(arr_conv_16 & (~1));
5338                 arr_conv_16_conv.is_owned = (arr_conv_16 & 1) || (arr_conv_16 == 0);
5339                 _res_constr.data[q] = arr_conv_16_conv;
5340         }
5341         CVec_UpdateFailHTLCZ_free(_res_constr);
5342 }
5343
5344 void CVec_1UpdateFailMalformedHTLCZ_1free(void* ctx_TODO, uint32_tArray _res) {
5345         LDKCVec_UpdateFailMalformedHTLCZ _res_constr;
5346         _res_constr.datalen = _res.len;
5347         if (_res_constr.datalen > 0)
5348                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKUpdateFailMalformedHTLC), "LDKCVec_UpdateFailMalformedHTLCZ Elements");
5349         else
5350                 _res_constr.data = NULL;
5351         uint32_t* _res_vals = (uint32_t*) _res.ptr;
5352         for (size_t z = 0; z < _res_constr.datalen; z++) {
5353                 uint32_t arr_conv_25 = _res_vals[z];
5354                 LDKUpdateFailMalformedHTLC arr_conv_25_conv;
5355                 arr_conv_25_conv.inner = (void*)(arr_conv_25 & (~1));
5356                 arr_conv_25_conv.is_owned = (arr_conv_25 & 1) || (arr_conv_25 == 0);
5357                 _res_constr.data[z] = arr_conv_25_conv;
5358         }
5359         CVec_UpdateFailMalformedHTLCZ_free(_res_constr);
5360 }
5361
5362 uint32_t CResult_1boolLightningErrorZ_1ok(void* ctx_TODO, jboolean o) {
5363         LDKCResult_boolLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_boolLightningErrorZ), "LDKCResult_boolLightningErrorZ");
5364         *ret_conv = CResult_boolLightningErrorZ_ok(o);
5365         return (long)ret_conv;
5366 }
5367
5368 uint32_t CResult_1boolLightningErrorZ_1err(void* ctx_TODO, uint32_t e) {
5369         LDKLightningError e_conv;
5370         e_conv.inner = (void*)(e & (~1));
5371         e_conv.is_owned = (e & 1) || (e == 0);
5372         // Warning: we may need a move here but can't clone!
5373         LDKCResult_boolLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_boolLightningErrorZ), "LDKCResult_boolLightningErrorZ");
5374         *ret_conv = CResult_boolLightningErrorZ_err(e_conv);
5375         return (long)ret_conv;
5376 }
5377
5378 void CResult_1boolLightningErrorZ_1free(void* ctx_TODO, uint32_t _res) {
5379         LDKCResult_boolLightningErrorZ _res_conv = *(LDKCResult_boolLightningErrorZ*)_res;
5380         FREE((void*)_res);
5381         CResult_boolLightningErrorZ_free(_res_conv);
5382 }
5383
5384 void C3Tuple_1ChannelAnnouncementChannelUpdateChannelUpdateZ_1free(void* ctx_TODO, uint32_t _res) {
5385         LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ _res_conv = *(LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ*)_res;
5386         FREE((void*)_res);
5387         C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ_free(_res_conv);
5388 }
5389
5390 uint32_t C3Tuple_1ChannelAnnouncementChannelUpdateChannelUpdateZ_1new(void* ctx_TODO, uint32_t a, uint32_t b, uint32_t c) {
5391         LDKChannelAnnouncement a_conv;
5392         a_conv.inner = (void*)(a & (~1));
5393         a_conv.is_owned = (a & 1) || (a == 0);
5394         if (a_conv.inner != NULL)
5395                 a_conv = ChannelAnnouncement_clone(&a_conv);
5396         LDKChannelUpdate b_conv;
5397         b_conv.inner = (void*)(b & (~1));
5398         b_conv.is_owned = (b & 1) || (b == 0);
5399         if (b_conv.inner != NULL)
5400                 b_conv = ChannelUpdate_clone(&b_conv);
5401         LDKChannelUpdate c_conv;
5402         c_conv.inner = (void*)(c & (~1));
5403         c_conv.is_owned = (c & 1) || (c == 0);
5404         if (c_conv.inner != NULL)
5405                 c_conv = ChannelUpdate_clone(&c_conv);
5406         LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ* ret_ref = MALLOC(sizeof(LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ), "LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ");
5407         *ret_ref = C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ_new(a_conv, b_conv, c_conv);
5408         ret_ref->a = ChannelAnnouncement_clone(&ret_ref->a);
5409         ret_ref->b = ChannelUpdate_clone(&ret_ref->b);
5410         ret_ref->c = ChannelUpdate_clone(&ret_ref->c);
5411         return (long)ret_ref;
5412 }
5413
5414 void CVec_1C3Tuple_1ChannelAnnouncementChannelUpdateChannelUpdateZZ_1free(void* ctx_TODO, uint32_tArray _res) {
5415         LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ _res_constr;
5416         _res_constr.datalen = _res.len;
5417         if (_res_constr.datalen > 0)
5418                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ), "LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ Elements");
5419         else
5420                 _res_constr.data = NULL;
5421         uint32_t* _res_vals = (uint32_t*) _res.ptr;
5422         for (size_t l = 0; l < _res_constr.datalen; l++) {
5423                 uint32_t arr_conv_63 = _res_vals[l];
5424                 LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ arr_conv_63_conv = *(LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ*)arr_conv_63;
5425                 FREE((void*)arr_conv_63);
5426                 _res_constr.data[l] = arr_conv_63_conv;
5427         }
5428         CVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ_free(_res_constr);
5429 }
5430
5431 void CVec_1NodeAnnouncementZ_1free(void* ctx_TODO, uint32_tArray _res) {
5432         LDKCVec_NodeAnnouncementZ _res_constr;
5433         _res_constr.datalen = _res.len;
5434         if (_res_constr.datalen > 0)
5435                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKNodeAnnouncement), "LDKCVec_NodeAnnouncementZ Elements");
5436         else
5437                 _res_constr.data = NULL;
5438         uint32_t* _res_vals = (uint32_t*) _res.ptr;
5439         for (size_t s = 0; s < _res_constr.datalen; s++) {
5440                 uint32_t arr_conv_18 = _res_vals[s];
5441                 LDKNodeAnnouncement arr_conv_18_conv;
5442                 arr_conv_18_conv.inner = (void*)(arr_conv_18 & (~1));
5443                 arr_conv_18_conv.is_owned = (arr_conv_18 & 1) || (arr_conv_18 == 0);
5444                 _res_constr.data[s] = arr_conv_18_conv;
5445         }
5446         CVec_NodeAnnouncementZ_free(_res_constr);
5447 }
5448
5449 uint32_t CResult_1NoneLightningErrorZ_1ok(void* ctx_TODO) {
5450         LDKCResult_NoneLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneLightningErrorZ), "LDKCResult_NoneLightningErrorZ");
5451         *ret_conv = CResult_NoneLightningErrorZ_ok();
5452         return (long)ret_conv;
5453 }
5454
5455 uint32_t CResult_1NoneLightningErrorZ_1err(void* ctx_TODO, uint32_t e) {
5456         LDKLightningError e_conv;
5457         e_conv.inner = (void*)(e & (~1));
5458         e_conv.is_owned = (e & 1) || (e == 0);
5459         // Warning: we may need a move here but can't clone!
5460         LDKCResult_NoneLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneLightningErrorZ), "LDKCResult_NoneLightningErrorZ");
5461         *ret_conv = CResult_NoneLightningErrorZ_err(e_conv);
5462         return (long)ret_conv;
5463 }
5464
5465 void CResult_1NoneLightningErrorZ_1free(void* ctx_TODO, uint32_t _res) {
5466         LDKCResult_NoneLightningErrorZ _res_conv = *(LDKCResult_NoneLightningErrorZ*)_res;
5467         FREE((void*)_res);
5468         CResult_NoneLightningErrorZ_free(_res_conv);
5469 }
5470
5471 uint32_t CResult_1ChannelReestablishDecodeErrorZ_1ok(void* ctx_TODO, uint32_t o) {
5472         LDKChannelReestablish o_conv;
5473         o_conv.inner = (void*)(o & (~1));
5474         o_conv.is_owned = (o & 1) || (o == 0);
5475         if (o_conv.inner != NULL)
5476                 o_conv = ChannelReestablish_clone(&o_conv);
5477         LDKCResult_ChannelReestablishDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ChannelReestablishDecodeErrorZ), "LDKCResult_ChannelReestablishDecodeErrorZ");
5478         *ret_conv = CResult_ChannelReestablishDecodeErrorZ_ok(o_conv);
5479         return (long)ret_conv;
5480 }
5481
5482 uint32_t CResult_1ChannelReestablishDecodeErrorZ_1err(void* ctx_TODO, uint32_t e) {
5483         LDKDecodeError e_conv;
5484         e_conv.inner = (void*)(e & (~1));
5485         e_conv.is_owned = (e & 1) || (e == 0);
5486         // Warning: we may need a move here but can't clone!
5487         LDKCResult_ChannelReestablishDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ChannelReestablishDecodeErrorZ), "LDKCResult_ChannelReestablishDecodeErrorZ");
5488         *ret_conv = CResult_ChannelReestablishDecodeErrorZ_err(e_conv);
5489         return (long)ret_conv;
5490 }
5491
5492 void CResult_1ChannelReestablishDecodeErrorZ_1free(void* ctx_TODO, uint32_t _res) {
5493         LDKCResult_ChannelReestablishDecodeErrorZ _res_conv = *(LDKCResult_ChannelReestablishDecodeErrorZ*)_res;
5494         FREE((void*)_res);
5495         CResult_ChannelReestablishDecodeErrorZ_free(_res_conv);
5496 }
5497
5498 uint32_t CResult_1InitDecodeErrorZ_1ok(void* ctx_TODO, uint32_t o) {
5499         LDKInit o_conv;
5500         o_conv.inner = (void*)(o & (~1));
5501         o_conv.is_owned = (o & 1) || (o == 0);
5502         if (o_conv.inner != NULL)
5503                 o_conv = Init_clone(&o_conv);
5504         LDKCResult_InitDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_InitDecodeErrorZ), "LDKCResult_InitDecodeErrorZ");
5505         *ret_conv = CResult_InitDecodeErrorZ_ok(o_conv);
5506         return (long)ret_conv;
5507 }
5508
5509 uint32_t CResult_1InitDecodeErrorZ_1err(void* ctx_TODO, uint32_t e) {
5510         LDKDecodeError e_conv;
5511         e_conv.inner = (void*)(e & (~1));
5512         e_conv.is_owned = (e & 1) || (e == 0);
5513         // Warning: we may need a move here but can't clone!
5514         LDKCResult_InitDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_InitDecodeErrorZ), "LDKCResult_InitDecodeErrorZ");
5515         *ret_conv = CResult_InitDecodeErrorZ_err(e_conv);
5516         return (long)ret_conv;
5517 }
5518
5519 void CResult_1InitDecodeErrorZ_1free(void* ctx_TODO, uint32_t _res) {
5520         LDKCResult_InitDecodeErrorZ _res_conv = *(LDKCResult_InitDecodeErrorZ*)_res;
5521         FREE((void*)_res);
5522         CResult_InitDecodeErrorZ_free(_res_conv);
5523 }
5524
5525 uint32_t CResult_1PingDecodeErrorZ_1ok(void* ctx_TODO, uint32_t o) {
5526         LDKPing o_conv;
5527         o_conv.inner = (void*)(o & (~1));
5528         o_conv.is_owned = (o & 1) || (o == 0);
5529         if (o_conv.inner != NULL)
5530                 o_conv = Ping_clone(&o_conv);
5531         LDKCResult_PingDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_PingDecodeErrorZ), "LDKCResult_PingDecodeErrorZ");
5532         *ret_conv = CResult_PingDecodeErrorZ_ok(o_conv);
5533         return (long)ret_conv;
5534 }
5535
5536 uint32_t CResult_1PingDecodeErrorZ_1err(void* ctx_TODO, uint32_t e) {
5537         LDKDecodeError e_conv;
5538         e_conv.inner = (void*)(e & (~1));
5539         e_conv.is_owned = (e & 1) || (e == 0);
5540         // Warning: we may need a move here but can't clone!
5541         LDKCResult_PingDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_PingDecodeErrorZ), "LDKCResult_PingDecodeErrorZ");
5542         *ret_conv = CResult_PingDecodeErrorZ_err(e_conv);
5543         return (long)ret_conv;
5544 }
5545
5546 void CResult_1PingDecodeErrorZ_1free(void* ctx_TODO, uint32_t _res) {
5547         LDKCResult_PingDecodeErrorZ _res_conv = *(LDKCResult_PingDecodeErrorZ*)_res;
5548         FREE((void*)_res);
5549         CResult_PingDecodeErrorZ_free(_res_conv);
5550 }
5551
5552 uint32_t CResult_1PongDecodeErrorZ_1ok(void* ctx_TODO, uint32_t o) {
5553         LDKPong o_conv;
5554         o_conv.inner = (void*)(o & (~1));
5555         o_conv.is_owned = (o & 1) || (o == 0);
5556         if (o_conv.inner != NULL)
5557                 o_conv = Pong_clone(&o_conv);
5558         LDKCResult_PongDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_PongDecodeErrorZ), "LDKCResult_PongDecodeErrorZ");
5559         *ret_conv = CResult_PongDecodeErrorZ_ok(o_conv);
5560         return (long)ret_conv;
5561 }
5562
5563 uint32_t CResult_1PongDecodeErrorZ_1err(void* ctx_TODO, uint32_t e) {
5564         LDKDecodeError e_conv;
5565         e_conv.inner = (void*)(e & (~1));
5566         e_conv.is_owned = (e & 1) || (e == 0);
5567         // Warning: we may need a move here but can't clone!
5568         LDKCResult_PongDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_PongDecodeErrorZ), "LDKCResult_PongDecodeErrorZ");
5569         *ret_conv = CResult_PongDecodeErrorZ_err(e_conv);
5570         return (long)ret_conv;
5571 }
5572
5573 void CResult_1PongDecodeErrorZ_1free(void* ctx_TODO, uint32_t _res) {
5574         LDKCResult_PongDecodeErrorZ _res_conv = *(LDKCResult_PongDecodeErrorZ*)_res;
5575         FREE((void*)_res);
5576         CResult_PongDecodeErrorZ_free(_res_conv);
5577 }
5578
5579 uint32_t CResult_1UnsignedChannelAnnouncementDecodeErrorZ_1ok(void* ctx_TODO, uint32_t o) {
5580         LDKUnsignedChannelAnnouncement o_conv;
5581         o_conv.inner = (void*)(o & (~1));
5582         o_conv.is_owned = (o & 1) || (o == 0);
5583         if (o_conv.inner != NULL)
5584                 o_conv = UnsignedChannelAnnouncement_clone(&o_conv);
5585         LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ), "LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ");
5586         *ret_conv = CResult_UnsignedChannelAnnouncementDecodeErrorZ_ok(o_conv);
5587         return (long)ret_conv;
5588 }
5589
5590 uint32_t CResult_1UnsignedChannelAnnouncementDecodeErrorZ_1err(void* ctx_TODO, uint32_t e) {
5591         LDKDecodeError e_conv;
5592         e_conv.inner = (void*)(e & (~1));
5593         e_conv.is_owned = (e & 1) || (e == 0);
5594         // Warning: we may need a move here but can't clone!
5595         LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ), "LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ");
5596         *ret_conv = CResult_UnsignedChannelAnnouncementDecodeErrorZ_err(e_conv);
5597         return (long)ret_conv;
5598 }
5599
5600 void CResult_1UnsignedChannelAnnouncementDecodeErrorZ_1free(void* ctx_TODO, uint32_t _res) {
5601         LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ _res_conv = *(LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ*)_res;
5602         FREE((void*)_res);
5603         CResult_UnsignedChannelAnnouncementDecodeErrorZ_free(_res_conv);
5604 }
5605
5606 uint32_t CResult_1UnsignedChannelUpdateDecodeErrorZ_1ok(void* ctx_TODO, uint32_t o) {
5607         LDKUnsignedChannelUpdate o_conv;
5608         o_conv.inner = (void*)(o & (~1));
5609         o_conv.is_owned = (o & 1) || (o == 0);
5610         if (o_conv.inner != NULL)
5611                 o_conv = UnsignedChannelUpdate_clone(&o_conv);
5612         LDKCResult_UnsignedChannelUpdateDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_UnsignedChannelUpdateDecodeErrorZ), "LDKCResult_UnsignedChannelUpdateDecodeErrorZ");
5613         *ret_conv = CResult_UnsignedChannelUpdateDecodeErrorZ_ok(o_conv);
5614         return (long)ret_conv;
5615 }
5616
5617 uint32_t CResult_1UnsignedChannelUpdateDecodeErrorZ_1err(void* ctx_TODO, uint32_t e) {
5618         LDKDecodeError e_conv;
5619         e_conv.inner = (void*)(e & (~1));
5620         e_conv.is_owned = (e & 1) || (e == 0);
5621         // Warning: we may need a move here but can't clone!
5622         LDKCResult_UnsignedChannelUpdateDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_UnsignedChannelUpdateDecodeErrorZ), "LDKCResult_UnsignedChannelUpdateDecodeErrorZ");
5623         *ret_conv = CResult_UnsignedChannelUpdateDecodeErrorZ_err(e_conv);
5624         return (long)ret_conv;
5625 }
5626
5627 void CResult_1UnsignedChannelUpdateDecodeErrorZ_1free(void* ctx_TODO, uint32_t _res) {
5628         LDKCResult_UnsignedChannelUpdateDecodeErrorZ _res_conv = *(LDKCResult_UnsignedChannelUpdateDecodeErrorZ*)_res;
5629         FREE((void*)_res);
5630         CResult_UnsignedChannelUpdateDecodeErrorZ_free(_res_conv);
5631 }
5632
5633 uint32_t CResult_1ErrorMessageDecodeErrorZ_1ok(void* ctx_TODO, uint32_t o) {
5634         LDKErrorMessage o_conv;
5635         o_conv.inner = (void*)(o & (~1));
5636         o_conv.is_owned = (o & 1) || (o == 0);
5637         if (o_conv.inner != NULL)
5638                 o_conv = ErrorMessage_clone(&o_conv);
5639         LDKCResult_ErrorMessageDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ErrorMessageDecodeErrorZ), "LDKCResult_ErrorMessageDecodeErrorZ");
5640         *ret_conv = CResult_ErrorMessageDecodeErrorZ_ok(o_conv);
5641         return (long)ret_conv;
5642 }
5643
5644 uint32_t CResult_1ErrorMessageDecodeErrorZ_1err(void* ctx_TODO, uint32_t e) {
5645         LDKDecodeError e_conv;
5646         e_conv.inner = (void*)(e & (~1));
5647         e_conv.is_owned = (e & 1) || (e == 0);
5648         // Warning: we may need a move here but can't clone!
5649         LDKCResult_ErrorMessageDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ErrorMessageDecodeErrorZ), "LDKCResult_ErrorMessageDecodeErrorZ");
5650         *ret_conv = CResult_ErrorMessageDecodeErrorZ_err(e_conv);
5651         return (long)ret_conv;
5652 }
5653
5654 void CResult_1ErrorMessageDecodeErrorZ_1free(void* ctx_TODO, uint32_t _res) {
5655         LDKCResult_ErrorMessageDecodeErrorZ _res_conv = *(LDKCResult_ErrorMessageDecodeErrorZ*)_res;
5656         FREE((void*)_res);
5657         CResult_ErrorMessageDecodeErrorZ_free(_res_conv);
5658 }
5659
5660 uint32_t CResult_1UnsignedNodeAnnouncementDecodeErrorZ_1ok(void* ctx_TODO, uint32_t o) {
5661         LDKUnsignedNodeAnnouncement o_conv;
5662         o_conv.inner = (void*)(o & (~1));
5663         o_conv.is_owned = (o & 1) || (o == 0);
5664         if (o_conv.inner != NULL)
5665                 o_conv = UnsignedNodeAnnouncement_clone(&o_conv);
5666         LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ), "LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ");
5667         *ret_conv = CResult_UnsignedNodeAnnouncementDecodeErrorZ_ok(o_conv);
5668         return (long)ret_conv;
5669 }
5670
5671 uint32_t CResult_1UnsignedNodeAnnouncementDecodeErrorZ_1err(void* ctx_TODO, uint32_t e) {
5672         LDKDecodeError e_conv;
5673         e_conv.inner = (void*)(e & (~1));
5674         e_conv.is_owned = (e & 1) || (e == 0);
5675         // Warning: we may need a move here but can't clone!
5676         LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ), "LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ");
5677         *ret_conv = CResult_UnsignedNodeAnnouncementDecodeErrorZ_err(e_conv);
5678         return (long)ret_conv;
5679 }
5680
5681 void CResult_1UnsignedNodeAnnouncementDecodeErrorZ_1free(void* ctx_TODO, uint32_t _res) {
5682         LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ _res_conv = *(LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ*)_res;
5683         FREE((void*)_res);
5684         CResult_UnsignedNodeAnnouncementDecodeErrorZ_free(_res_conv);
5685 }
5686
5687 uint32_t CResult_1QueryShortChannelIdsDecodeErrorZ_1ok(void* ctx_TODO, uint32_t o) {
5688         LDKQueryShortChannelIds o_conv;
5689         o_conv.inner = (void*)(o & (~1));
5690         o_conv.is_owned = (o & 1) || (o == 0);
5691         if (o_conv.inner != NULL)
5692                 o_conv = QueryShortChannelIds_clone(&o_conv);
5693         LDKCResult_QueryShortChannelIdsDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_QueryShortChannelIdsDecodeErrorZ), "LDKCResult_QueryShortChannelIdsDecodeErrorZ");
5694         *ret_conv = CResult_QueryShortChannelIdsDecodeErrorZ_ok(o_conv);
5695         return (long)ret_conv;
5696 }
5697
5698 uint32_t CResult_1QueryShortChannelIdsDecodeErrorZ_1err(void* ctx_TODO, uint32_t e) {
5699         LDKDecodeError e_conv;
5700         e_conv.inner = (void*)(e & (~1));
5701         e_conv.is_owned = (e & 1) || (e == 0);
5702         // Warning: we may need a move here but can't clone!
5703         LDKCResult_QueryShortChannelIdsDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_QueryShortChannelIdsDecodeErrorZ), "LDKCResult_QueryShortChannelIdsDecodeErrorZ");
5704         *ret_conv = CResult_QueryShortChannelIdsDecodeErrorZ_err(e_conv);
5705         return (long)ret_conv;
5706 }
5707
5708 void CResult_1QueryShortChannelIdsDecodeErrorZ_1free(void* ctx_TODO, uint32_t _res) {
5709         LDKCResult_QueryShortChannelIdsDecodeErrorZ _res_conv = *(LDKCResult_QueryShortChannelIdsDecodeErrorZ*)_res;
5710         FREE((void*)_res);
5711         CResult_QueryShortChannelIdsDecodeErrorZ_free(_res_conv);
5712 }
5713
5714 uint32_t CResult_1ReplyShortChannelIdsEndDecodeErrorZ_1ok(void* ctx_TODO, uint32_t o) {
5715         LDKReplyShortChannelIdsEnd o_conv;
5716         o_conv.inner = (void*)(o & (~1));
5717         o_conv.is_owned = (o & 1) || (o == 0);
5718         if (o_conv.inner != NULL)
5719                 o_conv = ReplyShortChannelIdsEnd_clone(&o_conv);
5720         LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ), "LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ");
5721         *ret_conv = CResult_ReplyShortChannelIdsEndDecodeErrorZ_ok(o_conv);
5722         return (long)ret_conv;
5723 }
5724
5725 uint32_t CResult_1ReplyShortChannelIdsEndDecodeErrorZ_1err(void* ctx_TODO, uint32_t e) {
5726         LDKDecodeError e_conv;
5727         e_conv.inner = (void*)(e & (~1));
5728         e_conv.is_owned = (e & 1) || (e == 0);
5729         // Warning: we may need a move here but can't clone!
5730         LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ), "LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ");
5731         *ret_conv = CResult_ReplyShortChannelIdsEndDecodeErrorZ_err(e_conv);
5732         return (long)ret_conv;
5733 }
5734
5735 void CResult_1ReplyShortChannelIdsEndDecodeErrorZ_1free(void* ctx_TODO, uint32_t _res) {
5736         LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ _res_conv = *(LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ*)_res;
5737         FREE((void*)_res);
5738         CResult_ReplyShortChannelIdsEndDecodeErrorZ_free(_res_conv);
5739 }
5740
5741 uint32_t CResult_1QueryChannelRangeDecodeErrorZ_1ok(void* ctx_TODO, uint32_t o) {
5742         LDKQueryChannelRange o_conv;
5743         o_conv.inner = (void*)(o & (~1));
5744         o_conv.is_owned = (o & 1) || (o == 0);
5745         if (o_conv.inner != NULL)
5746                 o_conv = QueryChannelRange_clone(&o_conv);
5747         LDKCResult_QueryChannelRangeDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_QueryChannelRangeDecodeErrorZ), "LDKCResult_QueryChannelRangeDecodeErrorZ");
5748         *ret_conv = CResult_QueryChannelRangeDecodeErrorZ_ok(o_conv);
5749         return (long)ret_conv;
5750 }
5751
5752 uint32_t CResult_1QueryChannelRangeDecodeErrorZ_1err(void* ctx_TODO, uint32_t e) {
5753         LDKDecodeError e_conv;
5754         e_conv.inner = (void*)(e & (~1));
5755         e_conv.is_owned = (e & 1) || (e == 0);
5756         // Warning: we may need a move here but can't clone!
5757         LDKCResult_QueryChannelRangeDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_QueryChannelRangeDecodeErrorZ), "LDKCResult_QueryChannelRangeDecodeErrorZ");
5758         *ret_conv = CResult_QueryChannelRangeDecodeErrorZ_err(e_conv);
5759         return (long)ret_conv;
5760 }
5761
5762 void CResult_1QueryChannelRangeDecodeErrorZ_1free(void* ctx_TODO, uint32_t _res) {
5763         LDKCResult_QueryChannelRangeDecodeErrorZ _res_conv = *(LDKCResult_QueryChannelRangeDecodeErrorZ*)_res;
5764         FREE((void*)_res);
5765         CResult_QueryChannelRangeDecodeErrorZ_free(_res_conv);
5766 }
5767
5768 uint32_t CResult_1ReplyChannelRangeDecodeErrorZ_1ok(void* ctx_TODO, uint32_t o) {
5769         LDKReplyChannelRange o_conv;
5770         o_conv.inner = (void*)(o & (~1));
5771         o_conv.is_owned = (o & 1) || (o == 0);
5772         if (o_conv.inner != NULL)
5773                 o_conv = ReplyChannelRange_clone(&o_conv);
5774         LDKCResult_ReplyChannelRangeDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ReplyChannelRangeDecodeErrorZ), "LDKCResult_ReplyChannelRangeDecodeErrorZ");
5775         *ret_conv = CResult_ReplyChannelRangeDecodeErrorZ_ok(o_conv);
5776         return (long)ret_conv;
5777 }
5778
5779 uint32_t CResult_1ReplyChannelRangeDecodeErrorZ_1err(void* ctx_TODO, uint32_t e) {
5780         LDKDecodeError e_conv;
5781         e_conv.inner = (void*)(e & (~1));
5782         e_conv.is_owned = (e & 1) || (e == 0);
5783         // Warning: we may need a move here but can't clone!
5784         LDKCResult_ReplyChannelRangeDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ReplyChannelRangeDecodeErrorZ), "LDKCResult_ReplyChannelRangeDecodeErrorZ");
5785         *ret_conv = CResult_ReplyChannelRangeDecodeErrorZ_err(e_conv);
5786         return (long)ret_conv;
5787 }
5788
5789 void CResult_1ReplyChannelRangeDecodeErrorZ_1free(void* ctx_TODO, uint32_t _res) {
5790         LDKCResult_ReplyChannelRangeDecodeErrorZ _res_conv = *(LDKCResult_ReplyChannelRangeDecodeErrorZ*)_res;
5791         FREE((void*)_res);
5792         CResult_ReplyChannelRangeDecodeErrorZ_free(_res_conv);
5793 }
5794
5795 uint32_t CResult_1GossipTimestampFilterDecodeErrorZ_1ok(void* ctx_TODO, uint32_t o) {
5796         LDKGossipTimestampFilter o_conv;
5797         o_conv.inner = (void*)(o & (~1));
5798         o_conv.is_owned = (o & 1) || (o == 0);
5799         if (o_conv.inner != NULL)
5800                 o_conv = GossipTimestampFilter_clone(&o_conv);
5801         LDKCResult_GossipTimestampFilterDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_GossipTimestampFilterDecodeErrorZ), "LDKCResult_GossipTimestampFilterDecodeErrorZ");
5802         *ret_conv = CResult_GossipTimestampFilterDecodeErrorZ_ok(o_conv);
5803         return (long)ret_conv;
5804 }
5805
5806 uint32_t CResult_1GossipTimestampFilterDecodeErrorZ_1err(void* ctx_TODO, uint32_t e) {
5807         LDKDecodeError e_conv;
5808         e_conv.inner = (void*)(e & (~1));
5809         e_conv.is_owned = (e & 1) || (e == 0);
5810         // Warning: we may need a move here but can't clone!
5811         LDKCResult_GossipTimestampFilterDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_GossipTimestampFilterDecodeErrorZ), "LDKCResult_GossipTimestampFilterDecodeErrorZ");
5812         *ret_conv = CResult_GossipTimestampFilterDecodeErrorZ_err(e_conv);
5813         return (long)ret_conv;
5814 }
5815
5816 void CResult_1GossipTimestampFilterDecodeErrorZ_1free(void* ctx_TODO, uint32_t _res) {
5817         LDKCResult_GossipTimestampFilterDecodeErrorZ _res_conv = *(LDKCResult_GossipTimestampFilterDecodeErrorZ*)_res;
5818         FREE((void*)_res);
5819         CResult_GossipTimestampFilterDecodeErrorZ_free(_res_conv);
5820 }
5821
5822 void CVec_1PublicKeyZ_1free(void* ctx_TODO, ptrArray _res) {
5823         LDKCVec_PublicKeyZ _res_constr;
5824         _res_constr.datalen = _res.len;
5825         if (_res_constr.datalen > 0)
5826                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKPublicKey), "LDKCVec_PublicKeyZ Elements");
5827         else
5828                 _res_constr.data = NULL;
5829         int8_tArray* _res_vals = (int8_tArray*) _res.ptr;
5830         for (size_t m = 0; m < _res_constr.datalen; m++) {
5831                 int8_tArray arr_conv_12 = _res_vals[m];
5832                 LDKPublicKey arr_conv_12_ref;
5833                 CHECK(arr_conv_12.len == 33);
5834                 memcpy(arr_conv_12_ref.compressed_form, arr_conv_12.ptr, 33);
5835                 _res_constr.data[m] = arr_conv_12_ref;
5836         }
5837         CVec_PublicKeyZ_free(_res_constr);
5838 }
5839
5840 void CVec_1u8Z_1free(void* ctx_TODO, int8_tArray _res) {
5841         LDKCVec_u8Z _res_ref;
5842         _res_ref.datalen = _res.len;
5843         _res_ref.data = MALLOC(_res_ref.datalen, "LDKCVec_u8Z Bytes");
5844         memcpy(_res_ref.data, _res.ptr, _res_ref.datalen);
5845         CVec_u8Z_free(_res_ref);
5846 }
5847
5848 uint32_t CResult_1CVec_1u8ZPeerHandleErrorZ_1ok(void* ctx_TODO, int8_tArray o) {
5849         LDKCVec_u8Z o_ref;
5850         o_ref.datalen = o.len;
5851         o_ref.data = MALLOC(o_ref.datalen, "LDKCVec_u8Z Bytes");
5852         memcpy(o_ref.data, o.ptr, o_ref.datalen);
5853         LDKCResult_CVec_u8ZPeerHandleErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_CVec_u8ZPeerHandleErrorZ), "LDKCResult_CVec_u8ZPeerHandleErrorZ");
5854         *ret_conv = CResult_CVec_u8ZPeerHandleErrorZ_ok(o_ref);
5855         return (long)ret_conv;
5856 }
5857
5858 uint32_t CResult_1CVec_1u8ZPeerHandleErrorZ_1err(void* ctx_TODO, uint32_t e) {
5859         LDKPeerHandleError e_conv;
5860         e_conv.inner = (void*)(e & (~1));
5861         e_conv.is_owned = (e & 1) || (e == 0);
5862         // Warning: we may need a move here but can't clone!
5863         LDKCResult_CVec_u8ZPeerHandleErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_CVec_u8ZPeerHandleErrorZ), "LDKCResult_CVec_u8ZPeerHandleErrorZ");
5864         *ret_conv = CResult_CVec_u8ZPeerHandleErrorZ_err(e_conv);
5865         return (long)ret_conv;
5866 }
5867
5868 void CResult_1CVec_1u8ZPeerHandleErrorZ_1free(void* ctx_TODO, uint32_t _res) {
5869         LDKCResult_CVec_u8ZPeerHandleErrorZ _res_conv = *(LDKCResult_CVec_u8ZPeerHandleErrorZ*)_res;
5870         FREE((void*)_res);
5871         CResult_CVec_u8ZPeerHandleErrorZ_free(_res_conv);
5872 }
5873
5874 uint32_t CResult_1NonePeerHandleErrorZ_1ok(void* ctx_TODO) {
5875         LDKCResult_NonePeerHandleErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NonePeerHandleErrorZ), "LDKCResult_NonePeerHandleErrorZ");
5876         *ret_conv = CResult_NonePeerHandleErrorZ_ok();
5877         return (long)ret_conv;
5878 }
5879
5880 uint32_t CResult_1NonePeerHandleErrorZ_1err(void* ctx_TODO, uint32_t e) {
5881         LDKPeerHandleError e_conv;
5882         e_conv.inner = (void*)(e & (~1));
5883         e_conv.is_owned = (e & 1) || (e == 0);
5884         // Warning: we may need a move here but can't clone!
5885         LDKCResult_NonePeerHandleErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NonePeerHandleErrorZ), "LDKCResult_NonePeerHandleErrorZ");
5886         *ret_conv = CResult_NonePeerHandleErrorZ_err(e_conv);
5887         return (long)ret_conv;
5888 }
5889
5890 void CResult_1NonePeerHandleErrorZ_1free(void* ctx_TODO, uint32_t _res) {
5891         LDKCResult_NonePeerHandleErrorZ _res_conv = *(LDKCResult_NonePeerHandleErrorZ*)_res;
5892         FREE((void*)_res);
5893         CResult_NonePeerHandleErrorZ_free(_res_conv);
5894 }
5895
5896 uint32_t CResult_1boolPeerHandleErrorZ_1ok(void* ctx_TODO, jboolean o) {
5897         LDKCResult_boolPeerHandleErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_boolPeerHandleErrorZ), "LDKCResult_boolPeerHandleErrorZ");
5898         *ret_conv = CResult_boolPeerHandleErrorZ_ok(o);
5899         return (long)ret_conv;
5900 }
5901
5902 uint32_t CResult_1boolPeerHandleErrorZ_1err(void* ctx_TODO, uint32_t e) {
5903         LDKPeerHandleError e_conv;
5904         e_conv.inner = (void*)(e & (~1));
5905         e_conv.is_owned = (e & 1) || (e == 0);
5906         // Warning: we may need a move here but can't clone!
5907         LDKCResult_boolPeerHandleErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_boolPeerHandleErrorZ), "LDKCResult_boolPeerHandleErrorZ");
5908         *ret_conv = CResult_boolPeerHandleErrorZ_err(e_conv);
5909         return (long)ret_conv;
5910 }
5911
5912 void CResult_1boolPeerHandleErrorZ_1free(void* ctx_TODO, uint32_t _res) {
5913         LDKCResult_boolPeerHandleErrorZ _res_conv = *(LDKCResult_boolPeerHandleErrorZ*)_res;
5914         FREE((void*)_res);
5915         CResult_boolPeerHandleErrorZ_free(_res_conv);
5916 }
5917
5918 uint32_t CResult_1SecretKeySecpErrorZ_1ok(void* ctx_TODO, int8_tArray o) {
5919         LDKSecretKey o_ref;
5920         CHECK(o.len == 32);
5921         memcpy(o_ref.bytes, o.ptr, 32);
5922         LDKCResult_SecretKeySecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_SecretKeySecpErrorZ), "LDKCResult_SecretKeySecpErrorZ");
5923         *ret_conv = CResult_SecretKeySecpErrorZ_ok(o_ref);
5924         return (long)ret_conv;
5925 }
5926
5927 uint32_t CResult_1SecretKeySecpErrorZ_1err(void* ctx_TODO, uint32_t e) {
5928         LDKSecp256k1Error e_conv = LDKSecp256k1Error_from_js(e);
5929         LDKCResult_SecretKeySecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_SecretKeySecpErrorZ), "LDKCResult_SecretKeySecpErrorZ");
5930         *ret_conv = CResult_SecretKeySecpErrorZ_err(e_conv);
5931         return (long)ret_conv;
5932 }
5933
5934 void CResult_1SecretKeySecpErrorZ_1free(void* ctx_TODO, uint32_t _res) {
5935         LDKCResult_SecretKeySecpErrorZ _res_conv = *(LDKCResult_SecretKeySecpErrorZ*)_res;
5936         FREE((void*)_res);
5937         CResult_SecretKeySecpErrorZ_free(_res_conv);
5938 }
5939
5940 uint32_t CResult_1PublicKeySecpErrorZ_1ok(void* ctx_TODO, int8_tArray o) {
5941         LDKPublicKey o_ref;
5942         CHECK(o.len == 33);
5943         memcpy(o_ref.compressed_form, o.ptr, 33);
5944         LDKCResult_PublicKeySecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_PublicKeySecpErrorZ), "LDKCResult_PublicKeySecpErrorZ");
5945         *ret_conv = CResult_PublicKeySecpErrorZ_ok(o_ref);
5946         return (long)ret_conv;
5947 }
5948
5949 uint32_t CResult_1PublicKeySecpErrorZ_1err(void* ctx_TODO, uint32_t e) {
5950         LDKSecp256k1Error e_conv = LDKSecp256k1Error_from_js(e);
5951         LDKCResult_PublicKeySecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_PublicKeySecpErrorZ), "LDKCResult_PublicKeySecpErrorZ");
5952         *ret_conv = CResult_PublicKeySecpErrorZ_err(e_conv);
5953         return (long)ret_conv;
5954 }
5955
5956 void CResult_1PublicKeySecpErrorZ_1free(void* ctx_TODO, uint32_t _res) {
5957         LDKCResult_PublicKeySecpErrorZ _res_conv = *(LDKCResult_PublicKeySecpErrorZ*)_res;
5958         FREE((void*)_res);
5959         CResult_PublicKeySecpErrorZ_free(_res_conv);
5960 }
5961
5962 uint32_t CResult_1TxCreationKeysSecpErrorZ_1ok(void* ctx_TODO, uint32_t o) {
5963         LDKTxCreationKeys o_conv;
5964         o_conv.inner = (void*)(o & (~1));
5965         o_conv.is_owned = (o & 1) || (o == 0);
5966         if (o_conv.inner != NULL)
5967                 o_conv = TxCreationKeys_clone(&o_conv);
5968         LDKCResult_TxCreationKeysSecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_TxCreationKeysSecpErrorZ), "LDKCResult_TxCreationKeysSecpErrorZ");
5969         *ret_conv = CResult_TxCreationKeysSecpErrorZ_ok(o_conv);
5970         return (long)ret_conv;
5971 }
5972
5973 uint32_t CResult_1TxCreationKeysSecpErrorZ_1err(void* ctx_TODO, uint32_t e) {
5974         LDKSecp256k1Error e_conv = LDKSecp256k1Error_from_js(e);
5975         LDKCResult_TxCreationKeysSecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_TxCreationKeysSecpErrorZ), "LDKCResult_TxCreationKeysSecpErrorZ");
5976         *ret_conv = CResult_TxCreationKeysSecpErrorZ_err(e_conv);
5977         return (long)ret_conv;
5978 }
5979
5980 void CResult_1TxCreationKeysSecpErrorZ_1free(void* ctx_TODO, uint32_t _res) {
5981         LDKCResult_TxCreationKeysSecpErrorZ _res_conv = *(LDKCResult_TxCreationKeysSecpErrorZ*)_res;
5982         FREE((void*)_res);
5983         CResult_TxCreationKeysSecpErrorZ_free(_res_conv);
5984 }
5985
5986 uint32_t CResult_1TrustedCommitmentTransactionNoneZ_1ok(void* ctx_TODO, uint32_t o) {
5987         LDKTrustedCommitmentTransaction o_conv;
5988         o_conv.inner = (void*)(o & (~1));
5989         o_conv.is_owned = (o & 1) || (o == 0);
5990         // Warning: we may need a move here but can't clone!
5991         LDKCResult_TrustedCommitmentTransactionNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_TrustedCommitmentTransactionNoneZ), "LDKCResult_TrustedCommitmentTransactionNoneZ");
5992         *ret_conv = CResult_TrustedCommitmentTransactionNoneZ_ok(o_conv);
5993         return (long)ret_conv;
5994 }
5995
5996 uint32_t CResult_1TrustedCommitmentTransactionNoneZ_1err(void* ctx_TODO) {
5997         LDKCResult_TrustedCommitmentTransactionNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_TrustedCommitmentTransactionNoneZ), "LDKCResult_TrustedCommitmentTransactionNoneZ");
5998         *ret_conv = CResult_TrustedCommitmentTransactionNoneZ_err();
5999         return (long)ret_conv;
6000 }
6001
6002 void CResult_1TrustedCommitmentTransactionNoneZ_1free(void* ctx_TODO, uint32_t _res) {
6003         LDKCResult_TrustedCommitmentTransactionNoneZ _res_conv = *(LDKCResult_TrustedCommitmentTransactionNoneZ*)_res;
6004         FREE((void*)_res);
6005         CResult_TrustedCommitmentTransactionNoneZ_free(_res_conv);
6006 }
6007
6008 void CVec_1RouteHopZ_1free(void* ctx_TODO, uint32_tArray _res) {
6009         LDKCVec_RouteHopZ _res_constr;
6010         _res_constr.datalen = _res.len;
6011         if (_res_constr.datalen > 0)
6012                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKRouteHop), "LDKCVec_RouteHopZ Elements");
6013         else
6014                 _res_constr.data = NULL;
6015         uint32_t* _res_vals = (uint32_t*) _res.ptr;
6016         for (size_t k = 0; k < _res_constr.datalen; k++) {
6017                 uint32_t arr_conv_10 = _res_vals[k];
6018                 LDKRouteHop arr_conv_10_conv;
6019                 arr_conv_10_conv.inner = (void*)(arr_conv_10 & (~1));
6020                 arr_conv_10_conv.is_owned = (arr_conv_10 & 1) || (arr_conv_10 == 0);
6021                 _res_constr.data[k] = arr_conv_10_conv;
6022         }
6023         CVec_RouteHopZ_free(_res_constr);
6024 }
6025
6026 void CVec_1CVec_1RouteHopZZ_1free(void* ctx_TODO, ptrArray _res) {
6027         LDKCVec_CVec_RouteHopZZ _res_constr;
6028         _res_constr.datalen = _res.len;
6029         if (_res_constr.datalen > 0)
6030                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKCVec_RouteHopZ), "LDKCVec_CVec_RouteHopZZ Elements");
6031         else
6032                 _res_constr.data = NULL;
6033         uint32_tArray* _res_vals = (uint32_tArray*) _res.ptr;
6034         for (size_t m = 0; m < _res_constr.datalen; m++) {
6035                 uint32_tArray arr_conv_12 = _res_vals[m];
6036                 LDKCVec_RouteHopZ arr_conv_12_constr;
6037                 arr_conv_12_constr.datalen = arr_conv_12.len;
6038                 if (arr_conv_12_constr.datalen > 0)
6039                         arr_conv_12_constr.data = MALLOC(arr_conv_12_constr.datalen * sizeof(LDKRouteHop), "LDKCVec_RouteHopZ Elements");
6040                 else
6041                         arr_conv_12_constr.data = NULL;
6042                 uint32_t* arr_conv_12_vals = (uint32_t*) arr_conv_12.ptr;
6043                 for (size_t k = 0; k < arr_conv_12_constr.datalen; k++) {
6044                         uint32_t arr_conv_10 = arr_conv_12_vals[k];
6045                         LDKRouteHop arr_conv_10_conv;
6046                         arr_conv_10_conv.inner = (void*)(arr_conv_10 & (~1));
6047                         arr_conv_10_conv.is_owned = (arr_conv_10 & 1) || (arr_conv_10 == 0);
6048                         arr_conv_12_constr.data[k] = arr_conv_10_conv;
6049                 }
6050                 _res_constr.data[m] = arr_conv_12_constr;
6051         }
6052         CVec_CVec_RouteHopZZ_free(_res_constr);
6053 }
6054
6055 uint32_t CResult_1RouteDecodeErrorZ_1ok(void* ctx_TODO, uint32_t o) {
6056         LDKRoute o_conv;
6057         o_conv.inner = (void*)(o & (~1));
6058         o_conv.is_owned = (o & 1) || (o == 0);
6059         if (o_conv.inner != NULL)
6060                 o_conv = Route_clone(&o_conv);
6061         LDKCResult_RouteDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_RouteDecodeErrorZ), "LDKCResult_RouteDecodeErrorZ");
6062         *ret_conv = CResult_RouteDecodeErrorZ_ok(o_conv);
6063         return (long)ret_conv;
6064 }
6065
6066 uint32_t CResult_1RouteDecodeErrorZ_1err(void* ctx_TODO, uint32_t e) {
6067         LDKDecodeError e_conv;
6068         e_conv.inner = (void*)(e & (~1));
6069         e_conv.is_owned = (e & 1) || (e == 0);
6070         // Warning: we may need a move here but can't clone!
6071         LDKCResult_RouteDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_RouteDecodeErrorZ), "LDKCResult_RouteDecodeErrorZ");
6072         *ret_conv = CResult_RouteDecodeErrorZ_err(e_conv);
6073         return (long)ret_conv;
6074 }
6075
6076 void CResult_1RouteDecodeErrorZ_1free(void* ctx_TODO, uint32_t _res) {
6077         LDKCResult_RouteDecodeErrorZ _res_conv = *(LDKCResult_RouteDecodeErrorZ*)_res;
6078         FREE((void*)_res);
6079         CResult_RouteDecodeErrorZ_free(_res_conv);
6080 }
6081
6082 void CVec_1RouteHintZ_1free(void* ctx_TODO, uint32_tArray _res) {
6083         LDKCVec_RouteHintZ _res_constr;
6084         _res_constr.datalen = _res.len;
6085         if (_res_constr.datalen > 0)
6086                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKRouteHint), "LDKCVec_RouteHintZ Elements");
6087         else
6088                 _res_constr.data = NULL;
6089         uint32_t* _res_vals = (uint32_t*) _res.ptr;
6090         for (size_t l = 0; l < _res_constr.datalen; l++) {
6091                 uint32_t arr_conv_11 = _res_vals[l];
6092                 LDKRouteHint arr_conv_11_conv;
6093                 arr_conv_11_conv.inner = (void*)(arr_conv_11 & (~1));
6094                 arr_conv_11_conv.is_owned = (arr_conv_11 & 1) || (arr_conv_11 == 0);
6095                 _res_constr.data[l] = arr_conv_11_conv;
6096         }
6097         CVec_RouteHintZ_free(_res_constr);
6098 }
6099
6100 uint32_t CResult_1RouteLightningErrorZ_1ok(void* ctx_TODO, uint32_t o) {
6101         LDKRoute o_conv;
6102         o_conv.inner = (void*)(o & (~1));
6103         o_conv.is_owned = (o & 1) || (o == 0);
6104         if (o_conv.inner != NULL)
6105                 o_conv = Route_clone(&o_conv);
6106         LDKCResult_RouteLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_RouteLightningErrorZ), "LDKCResult_RouteLightningErrorZ");
6107         *ret_conv = CResult_RouteLightningErrorZ_ok(o_conv);
6108         return (long)ret_conv;
6109 }
6110
6111 uint32_t CResult_1RouteLightningErrorZ_1err(void* ctx_TODO, uint32_t e) {
6112         LDKLightningError e_conv;
6113         e_conv.inner = (void*)(e & (~1));
6114         e_conv.is_owned = (e & 1) || (e == 0);
6115         // Warning: we may need a move here but can't clone!
6116         LDKCResult_RouteLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_RouteLightningErrorZ), "LDKCResult_RouteLightningErrorZ");
6117         *ret_conv = CResult_RouteLightningErrorZ_err(e_conv);
6118         return (long)ret_conv;
6119 }
6120
6121 void CResult_1RouteLightningErrorZ_1free(void* ctx_TODO, uint32_t _res) {
6122         LDKCResult_RouteLightningErrorZ _res_conv = *(LDKCResult_RouteLightningErrorZ*)_res;
6123         FREE((void*)_res);
6124         CResult_RouteLightningErrorZ_free(_res_conv);
6125 }
6126
6127 uint32_t CResult_1RoutingFeesDecodeErrorZ_1ok(void* ctx_TODO, uint32_t o) {
6128         LDKRoutingFees o_conv;
6129         o_conv.inner = (void*)(o & (~1));
6130         o_conv.is_owned = (o & 1) || (o == 0);
6131         if (o_conv.inner != NULL)
6132                 o_conv = RoutingFees_clone(&o_conv);
6133         LDKCResult_RoutingFeesDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_RoutingFeesDecodeErrorZ), "LDKCResult_RoutingFeesDecodeErrorZ");
6134         *ret_conv = CResult_RoutingFeesDecodeErrorZ_ok(o_conv);
6135         return (long)ret_conv;
6136 }
6137
6138 uint32_t CResult_1RoutingFeesDecodeErrorZ_1err(void* ctx_TODO, uint32_t e) {
6139         LDKDecodeError e_conv;
6140         e_conv.inner = (void*)(e & (~1));
6141         e_conv.is_owned = (e & 1) || (e == 0);
6142         // Warning: we may need a move here but can't clone!
6143         LDKCResult_RoutingFeesDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_RoutingFeesDecodeErrorZ), "LDKCResult_RoutingFeesDecodeErrorZ");
6144         *ret_conv = CResult_RoutingFeesDecodeErrorZ_err(e_conv);
6145         return (long)ret_conv;
6146 }
6147
6148 void CResult_1RoutingFeesDecodeErrorZ_1free(void* ctx_TODO, uint32_t _res) {
6149         LDKCResult_RoutingFeesDecodeErrorZ _res_conv = *(LDKCResult_RoutingFeesDecodeErrorZ*)_res;
6150         FREE((void*)_res);
6151         CResult_RoutingFeesDecodeErrorZ_free(_res_conv);
6152 }
6153
6154 uint32_t CResult_1NodeAnnouncementInfoDecodeErrorZ_1ok(void* ctx_TODO, uint32_t o) {
6155         LDKNodeAnnouncementInfo o_conv;
6156         o_conv.inner = (void*)(o & (~1));
6157         o_conv.is_owned = (o & 1) || (o == 0);
6158         // Warning: we may need a move here but can't clone!
6159         LDKCResult_NodeAnnouncementInfoDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NodeAnnouncementInfoDecodeErrorZ), "LDKCResult_NodeAnnouncementInfoDecodeErrorZ");
6160         *ret_conv = CResult_NodeAnnouncementInfoDecodeErrorZ_ok(o_conv);
6161         return (long)ret_conv;
6162 }
6163
6164 uint32_t CResult_1NodeAnnouncementInfoDecodeErrorZ_1err(void* ctx_TODO, uint32_t e) {
6165         LDKDecodeError e_conv;
6166         e_conv.inner = (void*)(e & (~1));
6167         e_conv.is_owned = (e & 1) || (e == 0);
6168         // Warning: we may need a move here but can't clone!
6169         LDKCResult_NodeAnnouncementInfoDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NodeAnnouncementInfoDecodeErrorZ), "LDKCResult_NodeAnnouncementInfoDecodeErrorZ");
6170         *ret_conv = CResult_NodeAnnouncementInfoDecodeErrorZ_err(e_conv);
6171         return (long)ret_conv;
6172 }
6173
6174 void CResult_1NodeAnnouncementInfoDecodeErrorZ_1free(void* ctx_TODO, uint32_t _res) {
6175         LDKCResult_NodeAnnouncementInfoDecodeErrorZ _res_conv = *(LDKCResult_NodeAnnouncementInfoDecodeErrorZ*)_res;
6176         FREE((void*)_res);
6177         CResult_NodeAnnouncementInfoDecodeErrorZ_free(_res_conv);
6178 }
6179
6180 uint32_t CResult_1NodeInfoDecodeErrorZ_1ok(void* ctx_TODO, uint32_t o) {
6181         LDKNodeInfo o_conv;
6182         o_conv.inner = (void*)(o & (~1));
6183         o_conv.is_owned = (o & 1) || (o == 0);
6184         // Warning: we may need a move here but can't clone!
6185         LDKCResult_NodeInfoDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NodeInfoDecodeErrorZ), "LDKCResult_NodeInfoDecodeErrorZ");
6186         *ret_conv = CResult_NodeInfoDecodeErrorZ_ok(o_conv);
6187         return (long)ret_conv;
6188 }
6189
6190 uint32_t CResult_1NodeInfoDecodeErrorZ_1err(void* ctx_TODO, uint32_t e) {
6191         LDKDecodeError e_conv;
6192         e_conv.inner = (void*)(e & (~1));
6193         e_conv.is_owned = (e & 1) || (e == 0);
6194         // Warning: we may need a move here but can't clone!
6195         LDKCResult_NodeInfoDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NodeInfoDecodeErrorZ), "LDKCResult_NodeInfoDecodeErrorZ");
6196         *ret_conv = CResult_NodeInfoDecodeErrorZ_err(e_conv);
6197         return (long)ret_conv;
6198 }
6199
6200 void CResult_1NodeInfoDecodeErrorZ_1free(void* ctx_TODO, uint32_t _res) {
6201         LDKCResult_NodeInfoDecodeErrorZ _res_conv = *(LDKCResult_NodeInfoDecodeErrorZ*)_res;
6202         FREE((void*)_res);
6203         CResult_NodeInfoDecodeErrorZ_free(_res_conv);
6204 }
6205
6206 uint32_t CResult_1NetworkGraphDecodeErrorZ_1ok(void* ctx_TODO, uint32_t o) {
6207         LDKNetworkGraph o_conv;
6208         o_conv.inner = (void*)(o & (~1));
6209         o_conv.is_owned = (o & 1) || (o == 0);
6210         // Warning: we may need a move here but can't clone!
6211         LDKCResult_NetworkGraphDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NetworkGraphDecodeErrorZ), "LDKCResult_NetworkGraphDecodeErrorZ");
6212         *ret_conv = CResult_NetworkGraphDecodeErrorZ_ok(o_conv);
6213         return (long)ret_conv;
6214 }
6215
6216 uint32_t CResult_1NetworkGraphDecodeErrorZ_1err(void* ctx_TODO, uint32_t e) {
6217         LDKDecodeError e_conv;
6218         e_conv.inner = (void*)(e & (~1));
6219         e_conv.is_owned = (e & 1) || (e == 0);
6220         // Warning: we may need a move here but can't clone!
6221         LDKCResult_NetworkGraphDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NetworkGraphDecodeErrorZ), "LDKCResult_NetworkGraphDecodeErrorZ");
6222         *ret_conv = CResult_NetworkGraphDecodeErrorZ_err(e_conv);
6223         return (long)ret_conv;
6224 }
6225
6226 void CResult_1NetworkGraphDecodeErrorZ_1free(void* ctx_TODO, uint32_t _res) {
6227         LDKCResult_NetworkGraphDecodeErrorZ _res_conv = *(LDKCResult_NetworkGraphDecodeErrorZ*)_res;
6228         FREE((void*)_res);
6229         CResult_NetworkGraphDecodeErrorZ_free(_res_conv);
6230 }
6231
6232 void Event_1free(void* ctx_TODO, uint32_t this_ptr) {
6233         LDKEvent this_ptr_conv = *(LDKEvent*)this_ptr;
6234         FREE((void*)this_ptr);
6235         Event_free(this_ptr_conv);
6236 }
6237
6238 uint32_t Event_1clone(void* ctx_TODO, uint32_t orig) {
6239         LDKEvent* orig_conv = (LDKEvent*)orig;
6240         LDKEvent *ret_copy = MALLOC(sizeof(LDKEvent), "LDKEvent");
6241         *ret_copy = Event_clone(orig_conv);
6242         long ret_ref = (long)ret_copy;
6243         return ret_ref;
6244 }
6245
6246 int8_tArray Event_1write(void* ctx_TODO, uint32_t obj) {
6247         LDKEvent* obj_conv = (LDKEvent*)obj;
6248         LDKCVec_u8Z arg_var = Event_write(obj_conv);
6249         int8_tArray arg_arr = { .len = arg_var.datalen, .ptr = MALLOC(arg_var.datalen, "Native int8_tArray Bytes") };
6250         memcpy(arg_arr.ptr, arg_var.data, arg_var.datalen);
6251         CVec_u8Z_free(arg_var);
6252         return arg_arr;
6253 }
6254
6255 void MessageSendEvent_1free(void* ctx_TODO, uint32_t this_ptr) {
6256         LDKMessageSendEvent this_ptr_conv = *(LDKMessageSendEvent*)this_ptr;
6257         FREE((void*)this_ptr);
6258         MessageSendEvent_free(this_ptr_conv);
6259 }
6260
6261 uint32_t MessageSendEvent_1clone(void* ctx_TODO, uint32_t orig) {
6262         LDKMessageSendEvent* orig_conv = (LDKMessageSendEvent*)orig;
6263         LDKMessageSendEvent *ret_copy = MALLOC(sizeof(LDKMessageSendEvent), "LDKMessageSendEvent");
6264         *ret_copy = MessageSendEvent_clone(orig_conv);
6265         long ret_ref = (long)ret_copy;
6266         return ret_ref;
6267 }
6268
6269 void MessageSendEventsProvider_1free(void* ctx_TODO, uint32_t this_ptr) {
6270         LDKMessageSendEventsProvider this_ptr_conv = *(LDKMessageSendEventsProvider*)this_ptr;
6271         FREE((void*)this_ptr);
6272         MessageSendEventsProvider_free(this_ptr_conv);
6273 }
6274
6275 void EventsProvider_1free(void* ctx_TODO, uint32_t this_ptr) {
6276         LDKEventsProvider this_ptr_conv = *(LDKEventsProvider*)this_ptr;
6277         FREE((void*)this_ptr);
6278         EventsProvider_free(this_ptr_conv);
6279 }
6280
6281 void APIError_1free(void* ctx_TODO, uint32_t this_ptr) {
6282         LDKAPIError this_ptr_conv = *(LDKAPIError*)this_ptr;
6283         FREE((void*)this_ptr);
6284         APIError_free(this_ptr_conv);
6285 }
6286
6287 uint32_t APIError_1clone(void* ctx_TODO, uint32_t orig) {
6288         LDKAPIError* orig_conv = (LDKAPIError*)orig;
6289         LDKAPIError *ret_copy = MALLOC(sizeof(LDKAPIError), "LDKAPIError");
6290         *ret_copy = APIError_clone(orig_conv);
6291         long ret_ref = (long)ret_copy;
6292         return ret_ref;
6293 }
6294
6295 uint32_t Level_1clone(void* ctx_TODO, uint32_t orig) {
6296         LDKLevel* orig_conv = (LDKLevel*)orig;
6297         uint32_t ret_conv = LDKLevel_to_js(Level_clone(orig_conv));
6298         return ret_conv;
6299 }
6300
6301 uint32_t Level_1max(void* ctx_TODO) {
6302         uint32_t ret_conv = LDKLevel_to_js(Level_max());
6303         return ret_conv;
6304 }
6305
6306 void Logger_1free(void* ctx_TODO, uint32_t this_ptr) {
6307         LDKLogger this_ptr_conv = *(LDKLogger*)this_ptr;
6308         FREE((void*)this_ptr);
6309         Logger_free(this_ptr_conv);
6310 }
6311
6312 void ChannelHandshakeConfig_1free(void* ctx_TODO, uint32_t this_ptr) {
6313         LDKChannelHandshakeConfig this_ptr_conv;
6314         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6315         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
6316         ChannelHandshakeConfig_free(this_ptr_conv);
6317 }
6318
6319 uint32_t ChannelHandshakeConfig_1clone(void* ctx_TODO, uint32_t orig) {
6320         LDKChannelHandshakeConfig orig_conv;
6321         orig_conv.inner = (void*)(orig & (~1));
6322         orig_conv.is_owned = false;
6323         LDKChannelHandshakeConfig ret_var = ChannelHandshakeConfig_clone(&orig_conv);
6324         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6325         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6326         long ret_ref = (long)ret_var.inner;
6327         if (ret_var.is_owned) {
6328                 ret_ref |= 1;
6329         }
6330         return ret_ref;
6331 }
6332
6333 int32_t ChannelHandshakeConfig_1get_1minimum_1depth(void* ctx_TODO, uint32_t this_ptr) {
6334         LDKChannelHandshakeConfig this_ptr_conv;
6335         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6336         this_ptr_conv.is_owned = false;
6337         int32_t ret_val = ChannelHandshakeConfig_get_minimum_depth(&this_ptr_conv);
6338         return ret_val;
6339 }
6340
6341 void ChannelHandshakeConfig_1set_1minimum_1depth(void* ctx_TODO, uint32_t this_ptr, int32_t val) {
6342         LDKChannelHandshakeConfig this_ptr_conv;
6343         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6344         this_ptr_conv.is_owned = false;
6345         ChannelHandshakeConfig_set_minimum_depth(&this_ptr_conv, val);
6346 }
6347
6348 int16_t ChannelHandshakeConfig_1get_1our_1to_1self_1delay(void* ctx_TODO, uint32_t this_ptr) {
6349         LDKChannelHandshakeConfig this_ptr_conv;
6350         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6351         this_ptr_conv.is_owned = false;
6352         int16_t ret_val = ChannelHandshakeConfig_get_our_to_self_delay(&this_ptr_conv);
6353         return ret_val;
6354 }
6355
6356 void ChannelHandshakeConfig_1set_1our_1to_1self_1delay(void* ctx_TODO, uint32_t this_ptr, int16_t val) {
6357         LDKChannelHandshakeConfig this_ptr_conv;
6358         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6359         this_ptr_conv.is_owned = false;
6360         ChannelHandshakeConfig_set_our_to_self_delay(&this_ptr_conv, val);
6361 }
6362
6363 int64_t ChannelHandshakeConfig_1get_1our_1htlc_1minimum_1msat(void* ctx_TODO, uint32_t this_ptr) {
6364         LDKChannelHandshakeConfig this_ptr_conv;
6365         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6366         this_ptr_conv.is_owned = false;
6367         int64_t ret_val = ChannelHandshakeConfig_get_our_htlc_minimum_msat(&this_ptr_conv);
6368         return ret_val;
6369 }
6370
6371 void ChannelHandshakeConfig_1set_1our_1htlc_1minimum_1msat(void* ctx_TODO, uint32_t this_ptr, int64_t val) {
6372         LDKChannelHandshakeConfig this_ptr_conv;
6373         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6374         this_ptr_conv.is_owned = false;
6375         ChannelHandshakeConfig_set_our_htlc_minimum_msat(&this_ptr_conv, val);
6376 }
6377
6378 uint32_t ChannelHandshakeConfig_1new(void* ctx_TODO, int32_t minimum_depth_arg, int16_t our_to_self_delay_arg, int64_t our_htlc_minimum_msat_arg) {
6379         LDKChannelHandshakeConfig ret_var = ChannelHandshakeConfig_new(minimum_depth_arg, our_to_self_delay_arg, our_htlc_minimum_msat_arg);
6380         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6381         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6382         long ret_ref = (long)ret_var.inner;
6383         if (ret_var.is_owned) {
6384                 ret_ref |= 1;
6385         }
6386         return ret_ref;
6387 }
6388
6389 uint32_t ChannelHandshakeConfig_1default(void* ctx_TODO) {
6390         LDKChannelHandshakeConfig ret_var = ChannelHandshakeConfig_default();
6391         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6392         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6393         long ret_ref = (long)ret_var.inner;
6394         if (ret_var.is_owned) {
6395                 ret_ref |= 1;
6396         }
6397         return ret_ref;
6398 }
6399
6400 void ChannelHandshakeLimits_1free(void* ctx_TODO, uint32_t this_ptr) {
6401         LDKChannelHandshakeLimits this_ptr_conv;
6402         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6403         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
6404         ChannelHandshakeLimits_free(this_ptr_conv);
6405 }
6406
6407 uint32_t ChannelHandshakeLimits_1clone(void* ctx_TODO, uint32_t orig) {
6408         LDKChannelHandshakeLimits orig_conv;
6409         orig_conv.inner = (void*)(orig & (~1));
6410         orig_conv.is_owned = false;
6411         LDKChannelHandshakeLimits ret_var = ChannelHandshakeLimits_clone(&orig_conv);
6412         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6413         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6414         long ret_ref = (long)ret_var.inner;
6415         if (ret_var.is_owned) {
6416                 ret_ref |= 1;
6417         }
6418         return ret_ref;
6419 }
6420
6421 int64_t ChannelHandshakeLimits_1get_1min_1funding_1satoshis(void* ctx_TODO, uint32_t this_ptr) {
6422         LDKChannelHandshakeLimits this_ptr_conv;
6423         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6424         this_ptr_conv.is_owned = false;
6425         int64_t ret_val = ChannelHandshakeLimits_get_min_funding_satoshis(&this_ptr_conv);
6426         return ret_val;
6427 }
6428
6429 void ChannelHandshakeLimits_1set_1min_1funding_1satoshis(void* ctx_TODO, uint32_t this_ptr, int64_t val) {
6430         LDKChannelHandshakeLimits this_ptr_conv;
6431         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6432         this_ptr_conv.is_owned = false;
6433         ChannelHandshakeLimits_set_min_funding_satoshis(&this_ptr_conv, val);
6434 }
6435
6436 int64_t ChannelHandshakeLimits_1get_1max_1htlc_1minimum_1msat(void* ctx_TODO, uint32_t this_ptr) {
6437         LDKChannelHandshakeLimits this_ptr_conv;
6438         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6439         this_ptr_conv.is_owned = false;
6440         int64_t ret_val = ChannelHandshakeLimits_get_max_htlc_minimum_msat(&this_ptr_conv);
6441         return ret_val;
6442 }
6443
6444 void ChannelHandshakeLimits_1set_1max_1htlc_1minimum_1msat(void* ctx_TODO, uint32_t this_ptr, int64_t val) {
6445         LDKChannelHandshakeLimits this_ptr_conv;
6446         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6447         this_ptr_conv.is_owned = false;
6448         ChannelHandshakeLimits_set_max_htlc_minimum_msat(&this_ptr_conv, val);
6449 }
6450
6451 int64_t ChannelHandshakeLimits_1get_1min_1max_1htlc_1value_1in_1flight_1msat(void* ctx_TODO, uint32_t this_ptr) {
6452         LDKChannelHandshakeLimits this_ptr_conv;
6453         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6454         this_ptr_conv.is_owned = false;
6455         int64_t ret_val = ChannelHandshakeLimits_get_min_max_htlc_value_in_flight_msat(&this_ptr_conv);
6456         return ret_val;
6457 }
6458
6459 void ChannelHandshakeLimits_1set_1min_1max_1htlc_1value_1in_1flight_1msat(void* ctx_TODO, uint32_t this_ptr, int64_t val) {
6460         LDKChannelHandshakeLimits this_ptr_conv;
6461         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6462         this_ptr_conv.is_owned = false;
6463         ChannelHandshakeLimits_set_min_max_htlc_value_in_flight_msat(&this_ptr_conv, val);
6464 }
6465
6466 int64_t ChannelHandshakeLimits_1get_1max_1channel_1reserve_1satoshis(void* ctx_TODO, uint32_t this_ptr) {
6467         LDKChannelHandshakeLimits this_ptr_conv;
6468         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6469         this_ptr_conv.is_owned = false;
6470         int64_t ret_val = ChannelHandshakeLimits_get_max_channel_reserve_satoshis(&this_ptr_conv);
6471         return ret_val;
6472 }
6473
6474 void ChannelHandshakeLimits_1set_1max_1channel_1reserve_1satoshis(void* ctx_TODO, uint32_t this_ptr, int64_t val) {
6475         LDKChannelHandshakeLimits this_ptr_conv;
6476         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6477         this_ptr_conv.is_owned = false;
6478         ChannelHandshakeLimits_set_max_channel_reserve_satoshis(&this_ptr_conv, val);
6479 }
6480
6481 int16_t ChannelHandshakeLimits_1get_1min_1max_1accepted_1htlcs(void* ctx_TODO, uint32_t this_ptr) {
6482         LDKChannelHandshakeLimits this_ptr_conv;
6483         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6484         this_ptr_conv.is_owned = false;
6485         int16_t ret_val = ChannelHandshakeLimits_get_min_max_accepted_htlcs(&this_ptr_conv);
6486         return ret_val;
6487 }
6488
6489 void ChannelHandshakeLimits_1set_1min_1max_1accepted_1htlcs(void* ctx_TODO, uint32_t this_ptr, int16_t val) {
6490         LDKChannelHandshakeLimits this_ptr_conv;
6491         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6492         this_ptr_conv.is_owned = false;
6493         ChannelHandshakeLimits_set_min_max_accepted_htlcs(&this_ptr_conv, val);
6494 }
6495
6496 int64_t ChannelHandshakeLimits_1get_1min_1dust_1limit_1satoshis(void* ctx_TODO, uint32_t this_ptr) {
6497         LDKChannelHandshakeLimits this_ptr_conv;
6498         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6499         this_ptr_conv.is_owned = false;
6500         int64_t ret_val = ChannelHandshakeLimits_get_min_dust_limit_satoshis(&this_ptr_conv);
6501         return ret_val;
6502 }
6503
6504 void ChannelHandshakeLimits_1set_1min_1dust_1limit_1satoshis(void* ctx_TODO, uint32_t this_ptr, int64_t val) {
6505         LDKChannelHandshakeLimits this_ptr_conv;
6506         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6507         this_ptr_conv.is_owned = false;
6508         ChannelHandshakeLimits_set_min_dust_limit_satoshis(&this_ptr_conv, val);
6509 }
6510
6511 int64_t ChannelHandshakeLimits_1get_1max_1dust_1limit_1satoshis(void* ctx_TODO, uint32_t this_ptr) {
6512         LDKChannelHandshakeLimits this_ptr_conv;
6513         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6514         this_ptr_conv.is_owned = false;
6515         int64_t ret_val = ChannelHandshakeLimits_get_max_dust_limit_satoshis(&this_ptr_conv);
6516         return ret_val;
6517 }
6518
6519 void ChannelHandshakeLimits_1set_1max_1dust_1limit_1satoshis(void* ctx_TODO, uint32_t this_ptr, int64_t val) {
6520         LDKChannelHandshakeLimits this_ptr_conv;
6521         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6522         this_ptr_conv.is_owned = false;
6523         ChannelHandshakeLimits_set_max_dust_limit_satoshis(&this_ptr_conv, val);
6524 }
6525
6526 int32_t ChannelHandshakeLimits_1get_1max_1minimum_1depth(void* ctx_TODO, uint32_t this_ptr) {
6527         LDKChannelHandshakeLimits this_ptr_conv;
6528         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6529         this_ptr_conv.is_owned = false;
6530         int32_t ret_val = ChannelHandshakeLimits_get_max_minimum_depth(&this_ptr_conv);
6531         return ret_val;
6532 }
6533
6534 void ChannelHandshakeLimits_1set_1max_1minimum_1depth(void* ctx_TODO, uint32_t this_ptr, int32_t val) {
6535         LDKChannelHandshakeLimits this_ptr_conv;
6536         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6537         this_ptr_conv.is_owned = false;
6538         ChannelHandshakeLimits_set_max_minimum_depth(&this_ptr_conv, val);
6539 }
6540
6541 jboolean ChannelHandshakeLimits_1get_1force_1announced_1channel_1preference(void* ctx_TODO, uint32_t this_ptr) {
6542         LDKChannelHandshakeLimits this_ptr_conv;
6543         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6544         this_ptr_conv.is_owned = false;
6545         jboolean ret_val = ChannelHandshakeLimits_get_force_announced_channel_preference(&this_ptr_conv);
6546         return ret_val;
6547 }
6548
6549 void ChannelHandshakeLimits_1set_1force_1announced_1channel_1preference(void* ctx_TODO, uint32_t this_ptr, jboolean val) {
6550         LDKChannelHandshakeLimits this_ptr_conv;
6551         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6552         this_ptr_conv.is_owned = false;
6553         ChannelHandshakeLimits_set_force_announced_channel_preference(&this_ptr_conv, val);
6554 }
6555
6556 int16_t ChannelHandshakeLimits_1get_1their_1to_1self_1delay(void* ctx_TODO, uint32_t this_ptr) {
6557         LDKChannelHandshakeLimits this_ptr_conv;
6558         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6559         this_ptr_conv.is_owned = false;
6560         int16_t ret_val = ChannelHandshakeLimits_get_their_to_self_delay(&this_ptr_conv);
6561         return ret_val;
6562 }
6563
6564 void ChannelHandshakeLimits_1set_1their_1to_1self_1delay(void* ctx_TODO, uint32_t this_ptr, int16_t val) {
6565         LDKChannelHandshakeLimits this_ptr_conv;
6566         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6567         this_ptr_conv.is_owned = false;
6568         ChannelHandshakeLimits_set_their_to_self_delay(&this_ptr_conv, val);
6569 }
6570
6571 uint32_t ChannelHandshakeLimits_1new(void* ctx_TODO, int64_t min_funding_satoshis_arg, int64_t max_htlc_minimum_msat_arg, int64_t min_max_htlc_value_in_flight_msat_arg, int64_t max_channel_reserve_satoshis_arg, int16_t min_max_accepted_htlcs_arg, int64_t min_dust_limit_satoshis_arg, int64_t max_dust_limit_satoshis_arg, int32_t max_minimum_depth_arg, jboolean force_announced_channel_preference_arg, int16_t their_to_self_delay_arg) {
6572         LDKChannelHandshakeLimits ret_var = ChannelHandshakeLimits_new(min_funding_satoshis_arg, max_htlc_minimum_msat_arg, min_max_htlc_value_in_flight_msat_arg, max_channel_reserve_satoshis_arg, min_max_accepted_htlcs_arg, min_dust_limit_satoshis_arg, max_dust_limit_satoshis_arg, max_minimum_depth_arg, force_announced_channel_preference_arg, their_to_self_delay_arg);
6573         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6574         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6575         long ret_ref = (long)ret_var.inner;
6576         if (ret_var.is_owned) {
6577                 ret_ref |= 1;
6578         }
6579         return ret_ref;
6580 }
6581
6582 uint32_t ChannelHandshakeLimits_1default(void* ctx_TODO) {
6583         LDKChannelHandshakeLimits ret_var = ChannelHandshakeLimits_default();
6584         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6585         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6586         long ret_ref = (long)ret_var.inner;
6587         if (ret_var.is_owned) {
6588                 ret_ref |= 1;
6589         }
6590         return ret_ref;
6591 }
6592
6593 void ChannelConfig_1free(void* ctx_TODO, uint32_t this_ptr) {
6594         LDKChannelConfig this_ptr_conv;
6595         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6596         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
6597         ChannelConfig_free(this_ptr_conv);
6598 }
6599
6600 uint32_t ChannelConfig_1clone(void* ctx_TODO, uint32_t orig) {
6601         LDKChannelConfig orig_conv;
6602         orig_conv.inner = (void*)(orig & (~1));
6603         orig_conv.is_owned = false;
6604         LDKChannelConfig ret_var = ChannelConfig_clone(&orig_conv);
6605         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6606         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6607         long ret_ref = (long)ret_var.inner;
6608         if (ret_var.is_owned) {
6609                 ret_ref |= 1;
6610         }
6611         return ret_ref;
6612 }
6613
6614 int32_t ChannelConfig_1get_1fee_1proportional_1millionths(void* ctx_TODO, uint32_t this_ptr) {
6615         LDKChannelConfig this_ptr_conv;
6616         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6617         this_ptr_conv.is_owned = false;
6618         int32_t ret_val = ChannelConfig_get_fee_proportional_millionths(&this_ptr_conv);
6619         return ret_val;
6620 }
6621
6622 void ChannelConfig_1set_1fee_1proportional_1millionths(void* ctx_TODO, uint32_t this_ptr, int32_t val) {
6623         LDKChannelConfig this_ptr_conv;
6624         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6625         this_ptr_conv.is_owned = false;
6626         ChannelConfig_set_fee_proportional_millionths(&this_ptr_conv, val);
6627 }
6628
6629 jboolean ChannelConfig_1get_1announced_1channel(void* ctx_TODO, uint32_t this_ptr) {
6630         LDKChannelConfig this_ptr_conv;
6631         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6632         this_ptr_conv.is_owned = false;
6633         jboolean ret_val = ChannelConfig_get_announced_channel(&this_ptr_conv);
6634         return ret_val;
6635 }
6636
6637 void ChannelConfig_1set_1announced_1channel(void* ctx_TODO, uint32_t this_ptr, jboolean val) {
6638         LDKChannelConfig this_ptr_conv;
6639         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6640         this_ptr_conv.is_owned = false;
6641         ChannelConfig_set_announced_channel(&this_ptr_conv, val);
6642 }
6643
6644 jboolean ChannelConfig_1get_1commit_1upfront_1shutdown_1pubkey(void* ctx_TODO, uint32_t this_ptr) {
6645         LDKChannelConfig this_ptr_conv;
6646         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6647         this_ptr_conv.is_owned = false;
6648         jboolean ret_val = ChannelConfig_get_commit_upfront_shutdown_pubkey(&this_ptr_conv);
6649         return ret_val;
6650 }
6651
6652 void ChannelConfig_1set_1commit_1upfront_1shutdown_1pubkey(void* ctx_TODO, uint32_t this_ptr, jboolean val) {
6653         LDKChannelConfig this_ptr_conv;
6654         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6655         this_ptr_conv.is_owned = false;
6656         ChannelConfig_set_commit_upfront_shutdown_pubkey(&this_ptr_conv, val);
6657 }
6658
6659 uint32_t ChannelConfig_1new(void* ctx_TODO, int32_t fee_proportional_millionths_arg, jboolean announced_channel_arg, jboolean commit_upfront_shutdown_pubkey_arg) {
6660         LDKChannelConfig ret_var = ChannelConfig_new(fee_proportional_millionths_arg, announced_channel_arg, commit_upfront_shutdown_pubkey_arg);
6661         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6662         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6663         long ret_ref = (long)ret_var.inner;
6664         if (ret_var.is_owned) {
6665                 ret_ref |= 1;
6666         }
6667         return ret_ref;
6668 }
6669
6670 uint32_t ChannelConfig_1default(void* ctx_TODO) {
6671         LDKChannelConfig ret_var = ChannelConfig_default();
6672         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6673         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6674         long ret_ref = (long)ret_var.inner;
6675         if (ret_var.is_owned) {
6676                 ret_ref |= 1;
6677         }
6678         return ret_ref;
6679 }
6680
6681 int8_tArray ChannelConfig_1write(void* ctx_TODO, uint32_t obj) {
6682         LDKChannelConfig obj_conv;
6683         obj_conv.inner = (void*)(obj & (~1));
6684         obj_conv.is_owned = false;
6685         LDKCVec_u8Z arg_var = ChannelConfig_write(&obj_conv);
6686         int8_tArray arg_arr = { .len = arg_var.datalen, .ptr = MALLOC(arg_var.datalen, "Native int8_tArray Bytes") };
6687         memcpy(arg_arr.ptr, arg_var.data, arg_var.datalen);
6688         CVec_u8Z_free(arg_var);
6689         return arg_arr;
6690 }
6691
6692 uint32_t ChannelConfig_1read(void* ctx_TODO, int8_tArray ser) {
6693         LDKu8slice ser_ref;
6694         ser_ref.datalen = ser.len;
6695         ser_ref.data = ser.ptr;
6696         LDKChannelConfig ret_var = ChannelConfig_read(ser_ref);
6697         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6698         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6699         long ret_ref = (long)ret_var.inner;
6700         if (ret_var.is_owned) {
6701                 ret_ref |= 1;
6702         }
6703         return ret_ref;
6704 }
6705
6706 void UserConfig_1free(void* ctx_TODO, uint32_t this_ptr) {
6707         LDKUserConfig this_ptr_conv;
6708         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6709         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
6710         UserConfig_free(this_ptr_conv);
6711 }
6712
6713 uint32_t UserConfig_1clone(void* ctx_TODO, uint32_t orig) {
6714         LDKUserConfig orig_conv;
6715         orig_conv.inner = (void*)(orig & (~1));
6716         orig_conv.is_owned = false;
6717         LDKUserConfig ret_var = UserConfig_clone(&orig_conv);
6718         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6719         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6720         long ret_ref = (long)ret_var.inner;
6721         if (ret_var.is_owned) {
6722                 ret_ref |= 1;
6723         }
6724         return ret_ref;
6725 }
6726
6727 uint32_t UserConfig_1get_1own_1channel_1config(void* ctx_TODO, uint32_t this_ptr) {
6728         LDKUserConfig this_ptr_conv;
6729         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6730         this_ptr_conv.is_owned = false;
6731         LDKChannelHandshakeConfig ret_var = UserConfig_get_own_channel_config(&this_ptr_conv);
6732         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6733         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6734         long ret_ref = (long)ret_var.inner;
6735         if (ret_var.is_owned) {
6736                 ret_ref |= 1;
6737         }
6738         return ret_ref;
6739 }
6740
6741 void UserConfig_1set_1own_1channel_1config(void* ctx_TODO, uint32_t this_ptr, uint32_t val) {
6742         LDKUserConfig this_ptr_conv;
6743         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6744         this_ptr_conv.is_owned = false;
6745         LDKChannelHandshakeConfig val_conv;
6746         val_conv.inner = (void*)(val & (~1));
6747         val_conv.is_owned = (val & 1) || (val == 0);
6748         if (val_conv.inner != NULL)
6749                 val_conv = ChannelHandshakeConfig_clone(&val_conv);
6750         UserConfig_set_own_channel_config(&this_ptr_conv, val_conv);
6751 }
6752
6753 uint32_t UserConfig_1get_1peer_1channel_1config_1limits(void* ctx_TODO, uint32_t this_ptr) {
6754         LDKUserConfig this_ptr_conv;
6755         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6756         this_ptr_conv.is_owned = false;
6757         LDKChannelHandshakeLimits ret_var = UserConfig_get_peer_channel_config_limits(&this_ptr_conv);
6758         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6759         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6760         long ret_ref = (long)ret_var.inner;
6761         if (ret_var.is_owned) {
6762                 ret_ref |= 1;
6763         }
6764         return ret_ref;
6765 }
6766
6767 void UserConfig_1set_1peer_1channel_1config_1limits(void* ctx_TODO, uint32_t this_ptr, uint32_t val) {
6768         LDKUserConfig this_ptr_conv;
6769         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6770         this_ptr_conv.is_owned = false;
6771         LDKChannelHandshakeLimits val_conv;
6772         val_conv.inner = (void*)(val & (~1));
6773         val_conv.is_owned = (val & 1) || (val == 0);
6774         if (val_conv.inner != NULL)
6775                 val_conv = ChannelHandshakeLimits_clone(&val_conv);
6776         UserConfig_set_peer_channel_config_limits(&this_ptr_conv, val_conv);
6777 }
6778
6779 uint32_t UserConfig_1get_1channel_1options(void* ctx_TODO, uint32_t this_ptr) {
6780         LDKUserConfig this_ptr_conv;
6781         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6782         this_ptr_conv.is_owned = false;
6783         LDKChannelConfig ret_var = UserConfig_get_channel_options(&this_ptr_conv);
6784         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6785         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6786         long ret_ref = (long)ret_var.inner;
6787         if (ret_var.is_owned) {
6788                 ret_ref |= 1;
6789         }
6790         return ret_ref;
6791 }
6792
6793 void UserConfig_1set_1channel_1options(void* ctx_TODO, uint32_t this_ptr, uint32_t val) {
6794         LDKUserConfig this_ptr_conv;
6795         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6796         this_ptr_conv.is_owned = false;
6797         LDKChannelConfig val_conv;
6798         val_conv.inner = (void*)(val & (~1));
6799         val_conv.is_owned = (val & 1) || (val == 0);
6800         if (val_conv.inner != NULL)
6801                 val_conv = ChannelConfig_clone(&val_conv);
6802         UserConfig_set_channel_options(&this_ptr_conv, val_conv);
6803 }
6804
6805 uint32_t UserConfig_1new(void* ctx_TODO, uint32_t own_channel_config_arg, uint32_t peer_channel_config_limits_arg, uint32_t channel_options_arg) {
6806         LDKChannelHandshakeConfig own_channel_config_arg_conv;
6807         own_channel_config_arg_conv.inner = (void*)(own_channel_config_arg & (~1));
6808         own_channel_config_arg_conv.is_owned = (own_channel_config_arg & 1) || (own_channel_config_arg == 0);
6809         if (own_channel_config_arg_conv.inner != NULL)
6810                 own_channel_config_arg_conv = ChannelHandshakeConfig_clone(&own_channel_config_arg_conv);
6811         LDKChannelHandshakeLimits peer_channel_config_limits_arg_conv;
6812         peer_channel_config_limits_arg_conv.inner = (void*)(peer_channel_config_limits_arg & (~1));
6813         peer_channel_config_limits_arg_conv.is_owned = (peer_channel_config_limits_arg & 1) || (peer_channel_config_limits_arg == 0);
6814         if (peer_channel_config_limits_arg_conv.inner != NULL)
6815                 peer_channel_config_limits_arg_conv = ChannelHandshakeLimits_clone(&peer_channel_config_limits_arg_conv);
6816         LDKChannelConfig channel_options_arg_conv;
6817         channel_options_arg_conv.inner = (void*)(channel_options_arg & (~1));
6818         channel_options_arg_conv.is_owned = (channel_options_arg & 1) || (channel_options_arg == 0);
6819         if (channel_options_arg_conv.inner != NULL)
6820                 channel_options_arg_conv = ChannelConfig_clone(&channel_options_arg_conv);
6821         LDKUserConfig ret_var = UserConfig_new(own_channel_config_arg_conv, peer_channel_config_limits_arg_conv, channel_options_arg_conv);
6822         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6823         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6824         long ret_ref = (long)ret_var.inner;
6825         if (ret_var.is_owned) {
6826                 ret_ref |= 1;
6827         }
6828         return ret_ref;
6829 }
6830
6831 uint32_t UserConfig_1default(void* ctx_TODO) {
6832         LDKUserConfig ret_var = UserConfig_default();
6833         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6834         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6835         long ret_ref = (long)ret_var.inner;
6836         if (ret_var.is_owned) {
6837                 ret_ref |= 1;
6838         }
6839         return ret_ref;
6840 }
6841
6842 uint32_t AccessError_1clone(void* ctx_TODO, uint32_t orig) {
6843         LDKAccessError* orig_conv = (LDKAccessError*)orig;
6844         uint32_t ret_conv = LDKAccessError_to_js(AccessError_clone(orig_conv));
6845         return ret_conv;
6846 }
6847
6848 void Access_1free(void* ctx_TODO, uint32_t this_ptr) {
6849         LDKAccess this_ptr_conv = *(LDKAccess*)this_ptr;
6850         FREE((void*)this_ptr);
6851         Access_free(this_ptr_conv);
6852 }
6853
6854 void Watch_1free(void* ctx_TODO, uint32_t this_ptr) {
6855         LDKWatch this_ptr_conv = *(LDKWatch*)this_ptr;
6856         FREE((void*)this_ptr);
6857         Watch_free(this_ptr_conv);
6858 }
6859
6860 void Filter_1free(void* ctx_TODO, uint32_t this_ptr) {
6861         LDKFilter this_ptr_conv = *(LDKFilter*)this_ptr;
6862         FREE((void*)this_ptr);
6863         Filter_free(this_ptr_conv);
6864 }
6865
6866 void BroadcasterInterface_1free(void* ctx_TODO, uint32_t this_ptr) {
6867         LDKBroadcasterInterface this_ptr_conv = *(LDKBroadcasterInterface*)this_ptr;
6868         FREE((void*)this_ptr);
6869         BroadcasterInterface_free(this_ptr_conv);
6870 }
6871
6872 uint32_t ConfirmationTarget_1clone(void* ctx_TODO, uint32_t orig) {
6873         LDKConfirmationTarget* orig_conv = (LDKConfirmationTarget*)orig;
6874         uint32_t ret_conv = LDKConfirmationTarget_to_js(ConfirmationTarget_clone(orig_conv));
6875         return ret_conv;
6876 }
6877
6878 void FeeEstimator_1free(void* ctx_TODO, uint32_t this_ptr) {
6879         LDKFeeEstimator this_ptr_conv = *(LDKFeeEstimator*)this_ptr;
6880         FREE((void*)this_ptr);
6881         FeeEstimator_free(this_ptr_conv);
6882 }
6883
6884 void ChainMonitor_1free(void* ctx_TODO, uint32_t this_ptr) {
6885         LDKChainMonitor this_ptr_conv;
6886         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6887         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
6888         ChainMonitor_free(this_ptr_conv);
6889 }
6890
6891 void ChainMonitor_1block_1connected(void* ctx_TODO, uint32_t this_arg, int8_tArray header, uint32_tArray txdata, int32_t height) {
6892         LDKChainMonitor this_arg_conv;
6893         this_arg_conv.inner = (void*)(this_arg & (~1));
6894         this_arg_conv.is_owned = false;
6895         unsigned char header_arr[80];
6896         CHECK(header.len == 80);
6897         memcpy(header_arr, header.ptr, 80);
6898         unsigned char (*header_ref)[80] = &header_arr;
6899         LDKCVec_C2Tuple_usizeTransactionZZ txdata_constr;
6900         txdata_constr.datalen = txdata.len;
6901         if (txdata_constr.datalen > 0)
6902                 txdata_constr.data = MALLOC(txdata_constr.datalen * sizeof(LDKC2Tuple_usizeTransactionZ), "LDKCVec_C2Tuple_usizeTransactionZZ Elements");
6903         else
6904                 txdata_constr.data = NULL;
6905         uint32_t* txdata_vals = (uint32_t*) txdata.ptr;
6906         for (size_t e = 0; e < txdata_constr.datalen; e++) {
6907                 uint32_t arr_conv_30 = txdata_vals[e];
6908                 LDKC2Tuple_usizeTransactionZ arr_conv_30_conv = *(LDKC2Tuple_usizeTransactionZ*)arr_conv_30;
6909                 FREE((void*)arr_conv_30);
6910                 txdata_constr.data[e] = arr_conv_30_conv;
6911         }
6912         ChainMonitor_block_connected(&this_arg_conv, header_ref, txdata_constr, height);
6913 }
6914
6915 void ChainMonitor_1block_1disconnected(void* ctx_TODO, uint32_t this_arg, int8_tArray header, int32_t disconnected_height) {
6916         LDKChainMonitor this_arg_conv;
6917         this_arg_conv.inner = (void*)(this_arg & (~1));
6918         this_arg_conv.is_owned = false;
6919         unsigned char header_arr[80];
6920         CHECK(header.len == 80);
6921         memcpy(header_arr, header.ptr, 80);
6922         unsigned char (*header_ref)[80] = &header_arr;
6923         ChainMonitor_block_disconnected(&this_arg_conv, header_ref, disconnected_height);
6924 }
6925
6926 uint32_t ChainMonitor_1new(void* ctx_TODO, uint32_t chain_source, uint32_t broadcaster, uint32_t logger, uint32_t feeest, uint32_t persister) {
6927         LDKFilter* chain_source_conv = (LDKFilter*)chain_source;
6928         LDKBroadcasterInterface broadcaster_conv = *(LDKBroadcasterInterface*)broadcaster;
6929         LDKLogger logger_conv = *(LDKLogger*)logger;
6930         LDKFeeEstimator feeest_conv = *(LDKFeeEstimator*)feeest;
6931         LDKPersist persister_conv = *(LDKPersist*)persister;
6932         LDKChainMonitor ret_var = ChainMonitor_new(chain_source_conv, broadcaster_conv, logger_conv, feeest_conv, persister_conv);
6933         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6934         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6935         long ret_ref = (long)ret_var.inner;
6936         if (ret_var.is_owned) {
6937                 ret_ref |= 1;
6938         }
6939         return ret_ref;
6940 }
6941
6942 uint32_t ChainMonitor_1as_1Watch(void* ctx_TODO, uint32_t this_arg) {
6943         LDKChainMonitor this_arg_conv;
6944         this_arg_conv.inner = (void*)(this_arg & (~1));
6945         this_arg_conv.is_owned = false;
6946         LDKWatch* ret = MALLOC(sizeof(LDKWatch), "LDKWatch");
6947         *ret = ChainMonitor_as_Watch(&this_arg_conv);
6948         return (long)ret;
6949 }
6950
6951 uint32_t ChainMonitor_1as_1EventsProvider(void* ctx_TODO, uint32_t this_arg) {
6952         LDKChainMonitor this_arg_conv;
6953         this_arg_conv.inner = (void*)(this_arg & (~1));
6954         this_arg_conv.is_owned = false;
6955         LDKEventsProvider* ret = MALLOC(sizeof(LDKEventsProvider), "LDKEventsProvider");
6956         *ret = ChainMonitor_as_EventsProvider(&this_arg_conv);
6957         return (long)ret;
6958 }
6959
6960 void ChannelMonitorUpdate_1free(void* ctx_TODO, uint32_t this_ptr) {
6961         LDKChannelMonitorUpdate this_ptr_conv;
6962         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6963         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
6964         ChannelMonitorUpdate_free(this_ptr_conv);
6965 }
6966
6967 uint32_t ChannelMonitorUpdate_1clone(void* ctx_TODO, uint32_t orig) {
6968         LDKChannelMonitorUpdate orig_conv;
6969         orig_conv.inner = (void*)(orig & (~1));
6970         orig_conv.is_owned = false;
6971         LDKChannelMonitorUpdate ret_var = ChannelMonitorUpdate_clone(&orig_conv);
6972         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6973         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6974         long ret_ref = (long)ret_var.inner;
6975         if (ret_var.is_owned) {
6976                 ret_ref |= 1;
6977         }
6978         return ret_ref;
6979 }
6980
6981 int64_t ChannelMonitorUpdate_1get_1update_1id(void* ctx_TODO, uint32_t this_ptr) {
6982         LDKChannelMonitorUpdate this_ptr_conv;
6983         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6984         this_ptr_conv.is_owned = false;
6985         int64_t ret_val = ChannelMonitorUpdate_get_update_id(&this_ptr_conv);
6986         return ret_val;
6987 }
6988
6989 void ChannelMonitorUpdate_1set_1update_1id(void* ctx_TODO, uint32_t this_ptr, int64_t val) {
6990         LDKChannelMonitorUpdate this_ptr_conv;
6991         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6992         this_ptr_conv.is_owned = false;
6993         ChannelMonitorUpdate_set_update_id(&this_ptr_conv, val);
6994 }
6995
6996 int8_tArray ChannelMonitorUpdate_1write(void* ctx_TODO, uint32_t obj) {
6997         LDKChannelMonitorUpdate obj_conv;
6998         obj_conv.inner = (void*)(obj & (~1));
6999         obj_conv.is_owned = false;
7000         LDKCVec_u8Z arg_var = ChannelMonitorUpdate_write(&obj_conv);
7001         int8_tArray arg_arr = { .len = arg_var.datalen, .ptr = MALLOC(arg_var.datalen, "Native int8_tArray Bytes") };
7002         memcpy(arg_arr.ptr, arg_var.data, arg_var.datalen);
7003         CVec_u8Z_free(arg_var);
7004         return arg_arr;
7005 }
7006
7007 uint32_t ChannelMonitorUpdate_1read(void* ctx_TODO, int8_tArray ser) {
7008         LDKu8slice ser_ref;
7009         ser_ref.datalen = ser.len;
7010         ser_ref.data = ser.ptr;
7011         LDKCResult_ChannelMonitorUpdateDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ChannelMonitorUpdateDecodeErrorZ), "LDKCResult_ChannelMonitorUpdateDecodeErrorZ");
7012         *ret_conv = ChannelMonitorUpdate_read(ser_ref);
7013         return (long)ret_conv;
7014 }
7015
7016 uint32_t ChannelMonitorUpdateErr_1clone(void* ctx_TODO, uint32_t orig) {
7017         LDKChannelMonitorUpdateErr* orig_conv = (LDKChannelMonitorUpdateErr*)orig;
7018         uint32_t ret_conv = LDKChannelMonitorUpdateErr_to_js(ChannelMonitorUpdateErr_clone(orig_conv));
7019         return ret_conv;
7020 }
7021
7022 void MonitorUpdateError_1free(void* ctx_TODO, uint32_t this_ptr) {
7023         LDKMonitorUpdateError this_ptr_conv;
7024         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7025         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7026         MonitorUpdateError_free(this_ptr_conv);
7027 }
7028
7029 void MonitorEvent_1free(void* ctx_TODO, uint32_t this_ptr) {
7030         LDKMonitorEvent this_ptr_conv;
7031         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7032         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7033         MonitorEvent_free(this_ptr_conv);
7034 }
7035
7036 uint32_t MonitorEvent_1clone(void* ctx_TODO, uint32_t orig) {
7037         LDKMonitorEvent orig_conv;
7038         orig_conv.inner = (void*)(orig & (~1));
7039         orig_conv.is_owned = false;
7040         LDKMonitorEvent ret_var = MonitorEvent_clone(&orig_conv);
7041         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7042         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7043         long ret_ref = (long)ret_var.inner;
7044         if (ret_var.is_owned) {
7045                 ret_ref |= 1;
7046         }
7047         return ret_ref;
7048 }
7049
7050 void HTLCUpdate_1free(void* ctx_TODO, uint32_t this_ptr) {
7051         LDKHTLCUpdate this_ptr_conv;
7052         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7053         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7054         HTLCUpdate_free(this_ptr_conv);
7055 }
7056
7057 uint32_t HTLCUpdate_1clone(void* ctx_TODO, uint32_t orig) {
7058         LDKHTLCUpdate orig_conv;
7059         orig_conv.inner = (void*)(orig & (~1));
7060         orig_conv.is_owned = false;
7061         LDKHTLCUpdate ret_var = HTLCUpdate_clone(&orig_conv);
7062         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7063         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7064         long ret_ref = (long)ret_var.inner;
7065         if (ret_var.is_owned) {
7066                 ret_ref |= 1;
7067         }
7068         return ret_ref;
7069 }
7070
7071 int8_tArray HTLCUpdate_1write(void* ctx_TODO, uint32_t obj) {
7072         LDKHTLCUpdate obj_conv;
7073         obj_conv.inner = (void*)(obj & (~1));
7074         obj_conv.is_owned = false;
7075         LDKCVec_u8Z arg_var = HTLCUpdate_write(&obj_conv);
7076         int8_tArray arg_arr = { .len = arg_var.datalen, .ptr = MALLOC(arg_var.datalen, "Native int8_tArray Bytes") };
7077         memcpy(arg_arr.ptr, arg_var.data, arg_var.datalen);
7078         CVec_u8Z_free(arg_var);
7079         return arg_arr;
7080 }
7081
7082 uint32_t HTLCUpdate_1read(void* ctx_TODO, int8_tArray ser) {
7083         LDKu8slice ser_ref;
7084         ser_ref.datalen = ser.len;
7085         ser_ref.data = ser.ptr;
7086         LDKHTLCUpdate ret_var = HTLCUpdate_read(ser_ref);
7087         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7088         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7089         long ret_ref = (long)ret_var.inner;
7090         if (ret_var.is_owned) {
7091                 ret_ref |= 1;
7092         }
7093         return ret_ref;
7094 }
7095
7096 void ChannelMonitor_1free(void* ctx_TODO, uint32_t this_ptr) {
7097         LDKChannelMonitor this_ptr_conv;
7098         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7099         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7100         ChannelMonitor_free(this_ptr_conv);
7101 }
7102
7103 int8_tArray ChannelMonitor_1write(void* ctx_TODO, uint32_t obj) {
7104         LDKChannelMonitor obj_conv;
7105         obj_conv.inner = (void*)(obj & (~1));
7106         obj_conv.is_owned = false;
7107         LDKCVec_u8Z arg_var = ChannelMonitor_write(&obj_conv);
7108         int8_tArray arg_arr = { .len = arg_var.datalen, .ptr = MALLOC(arg_var.datalen, "Native int8_tArray Bytes") };
7109         memcpy(arg_arr.ptr, arg_var.data, arg_var.datalen);
7110         CVec_u8Z_free(arg_var);
7111         return arg_arr;
7112 }
7113
7114 uint32_t ChannelMonitor_1update_1monitor(void* ctx_TODO, uint32_t this_arg, uint32_t updates, uint32_t broadcaster, uint32_t fee_estimator, uint32_t logger) {
7115         LDKChannelMonitor this_arg_conv;
7116         this_arg_conv.inner = (void*)(this_arg & (~1));
7117         this_arg_conv.is_owned = false;
7118         LDKChannelMonitorUpdate updates_conv;
7119         updates_conv.inner = (void*)(updates & (~1));
7120         updates_conv.is_owned = false;
7121         LDKBroadcasterInterface* broadcaster_conv = (LDKBroadcasterInterface*)broadcaster;
7122         LDKFeeEstimator* fee_estimator_conv = (LDKFeeEstimator*)fee_estimator;
7123         LDKLogger* logger_conv = (LDKLogger*)logger;
7124         LDKCResult_NoneMonitorUpdateErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneMonitorUpdateErrorZ), "LDKCResult_NoneMonitorUpdateErrorZ");
7125         *ret_conv = ChannelMonitor_update_monitor(&this_arg_conv, &updates_conv, broadcaster_conv, fee_estimator_conv, logger_conv);
7126         return (long)ret_conv;
7127 }
7128
7129 int64_t ChannelMonitor_1get_1latest_1update_1id(void* ctx_TODO, uint32_t this_arg) {
7130         LDKChannelMonitor this_arg_conv;
7131         this_arg_conv.inner = (void*)(this_arg & (~1));
7132         this_arg_conv.is_owned = false;
7133         int64_t ret_val = ChannelMonitor_get_latest_update_id(&this_arg_conv);
7134         return ret_val;
7135 }
7136
7137 uint32_t ChannelMonitor_1get_1funding_1txo(void* ctx_TODO, uint32_t this_arg) {
7138         LDKChannelMonitor this_arg_conv;
7139         this_arg_conv.inner = (void*)(this_arg & (~1));
7140         this_arg_conv.is_owned = false;
7141         LDKC2Tuple_OutPointScriptZ* ret_ref = MALLOC(sizeof(LDKC2Tuple_OutPointScriptZ), "LDKC2Tuple_OutPointScriptZ");
7142         *ret_ref = ChannelMonitor_get_funding_txo(&this_arg_conv);
7143         ret_ref->a = OutPoint_clone(&ret_ref->a);
7144         ret_ref->b = CVec_u8Z_clone(&ret_ref->b);
7145         return (long)ret_ref;
7146 }
7147
7148 uint32_tArray ChannelMonitor_1get_1and_1clear_1pending_1monitor_1events(void* ctx_TODO, uint32_t this_arg) {
7149         LDKChannelMonitor this_arg_conv;
7150         this_arg_conv.inner = (void*)(this_arg & (~1));
7151         this_arg_conv.is_owned = false;
7152         LDKCVec_MonitorEventZ ret_var = ChannelMonitor_get_and_clear_pending_monitor_events(&this_arg_conv);
7153         uint32_tArray ret_arr = { .len = ret_var.datalen, .ptr = MALLOC(ret_var.datalen * sizeof(int32_t), "Native uint32_tArray Bytes") };
7154         uint32_t *ret_arr_ptr = (uint32_t*)ret_arr.ptr;
7155         for (size_t o = 0; o < ret_var.datalen; o++) {
7156                 LDKMonitorEvent arr_conv_14_var = ret_var.data[o];
7157                 CHECK((((long)arr_conv_14_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7158                 CHECK((((long)&arr_conv_14_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7159                 long arr_conv_14_ref = (long)arr_conv_14_var.inner;
7160                 if (arr_conv_14_var.is_owned) {
7161                         arr_conv_14_ref |= 1;
7162                 }
7163                 ret_arr_ptr[o] = arr_conv_14_ref;
7164         }
7165         FREE(ret_var.data);
7166         return ret_arr;
7167 }
7168
7169 uint32_tArray ChannelMonitor_1get_1and_1clear_1pending_1events(void* ctx_TODO, uint32_t this_arg) {
7170         LDKChannelMonitor this_arg_conv;
7171         this_arg_conv.inner = (void*)(this_arg & (~1));
7172         this_arg_conv.is_owned = false;
7173         LDKCVec_EventZ ret_var = ChannelMonitor_get_and_clear_pending_events(&this_arg_conv);
7174         uint32_tArray ret_arr = { .len = ret_var.datalen, .ptr = MALLOC(ret_var.datalen * sizeof(int32_t), "Native uint32_tArray Bytes") };
7175         uint32_t *ret_arr_ptr = (uint32_t*)ret_arr.ptr;
7176         for (size_t h = 0; h < ret_var.datalen; h++) {
7177                 LDKEvent *arr_conv_7_copy = MALLOC(sizeof(LDKEvent), "LDKEvent");
7178                 *arr_conv_7_copy = Event_clone(&ret_var.data[h]);
7179                 long arr_conv_7_ref = (long)arr_conv_7_copy;
7180                 ret_arr_ptr[h] = arr_conv_7_ref;
7181         }
7182         FREE(ret_var.data);
7183         return ret_arr;
7184 }
7185
7186 ptrArray ChannelMonitor_1get_1latest_1holder_1commitment_1txn(void* ctx_TODO, uint32_t this_arg, uint32_t logger) {
7187         LDKChannelMonitor this_arg_conv;
7188         this_arg_conv.inner = (void*)(this_arg & (~1));
7189         this_arg_conv.is_owned = false;
7190         LDKLogger* logger_conv = (LDKLogger*)logger;
7191         LDKCVec_TransactionZ ret_var = ChannelMonitor_get_latest_holder_commitment_txn(&this_arg_conv, logger_conv);
7192         ptrArray ret_arr = { .len = ret_var.datalen, .ptr = MALLOC(ret_var.datalen * sizeof(int32_t), "Native Object Bytes") };
7193         int8_tArray *ret_arr_ptr = (int8_tArray*)ret_arr.ptr;
7194         for (size_t m = 0; m < ret_var.datalen; m++) {
7195                 LDKTransaction arr_conv_12_var = ret_var.data[m];
7196                 int8_tArray arr_conv_12_arr = { .len = arr_conv_12_var.datalen, .ptr = MALLOC(arr_conv_12_var.datalen, "Native int8_tArray Bytes") };
7197                 memcpy(arr_conv_12_arr.ptr, arr_conv_12_var.data, arr_conv_12_var.datalen);
7198                 Transaction_free(arr_conv_12_var);
7199                 ret_arr_ptr[m] = arr_conv_12_arr;
7200         }
7201         FREE(ret_var.data);
7202         return ret_arr;
7203 }
7204
7205 uint32_tArray ChannelMonitor_1block_1connected(void* ctx_TODO, uint32_t this_arg, int8_tArray header, uint32_tArray txdata, int32_t height, uint32_t broadcaster, uint32_t fee_estimator, uint32_t logger) {
7206         LDKChannelMonitor this_arg_conv;
7207         this_arg_conv.inner = (void*)(this_arg & (~1));
7208         this_arg_conv.is_owned = false;
7209         unsigned char header_arr[80];
7210         CHECK(header.len == 80);
7211         memcpy(header_arr, header.ptr, 80);
7212         unsigned char (*header_ref)[80] = &header_arr;
7213         LDKCVec_C2Tuple_usizeTransactionZZ txdata_constr;
7214         txdata_constr.datalen = txdata.len;
7215         if (txdata_constr.datalen > 0)
7216                 txdata_constr.data = MALLOC(txdata_constr.datalen * sizeof(LDKC2Tuple_usizeTransactionZ), "LDKCVec_C2Tuple_usizeTransactionZZ Elements");
7217         else
7218                 txdata_constr.data = NULL;
7219         uint32_t* txdata_vals = (uint32_t*) txdata.ptr;
7220         for (size_t e = 0; e < txdata_constr.datalen; e++) {
7221                 uint32_t arr_conv_30 = txdata_vals[e];
7222                 LDKC2Tuple_usizeTransactionZ arr_conv_30_conv = *(LDKC2Tuple_usizeTransactionZ*)arr_conv_30;
7223                 FREE((void*)arr_conv_30);
7224                 txdata_constr.data[e] = arr_conv_30_conv;
7225         }
7226         LDKBroadcasterInterface broadcaster_conv = *(LDKBroadcasterInterface*)broadcaster;
7227         LDKFeeEstimator fee_estimator_conv = *(LDKFeeEstimator*)fee_estimator;
7228         LDKLogger logger_conv = *(LDKLogger*)logger;
7229         LDKCVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ ret_var = ChannelMonitor_block_connected(&this_arg_conv, header_ref, txdata_constr, height, broadcaster_conv, fee_estimator_conv, logger_conv);
7230         uint32_tArray ret_arr = { .len = ret_var.datalen, .ptr = MALLOC(ret_var.datalen * sizeof(int32_t), "Native uint32_tArray Bytes") };
7231         uint32_t *ret_arr_ptr = (uint32_t*)ret_arr.ptr;
7232         for (size_t x = 0; x < ret_var.datalen; x++) {
7233                 LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ* arr_conv_49_ref = MALLOC(sizeof(LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ), "LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ");
7234                 *arr_conv_49_ref = ret_var.data[x];
7235                 arr_conv_49_ref->a = ThirtyTwoBytes_clone(&arr_conv_49_ref->a);
7236                 // XXX: We likely need to clone here, but no _clone fn is available for TwoTuple<Number, TxOut>[]
7237                 ret_arr_ptr[x] = (long)arr_conv_49_ref;
7238         }
7239         FREE(ret_var.data);
7240         return ret_arr;
7241 }
7242
7243 void ChannelMonitor_1block_1disconnected(void* ctx_TODO, uint32_t this_arg, int8_tArray header, int32_t height, uint32_t broadcaster, uint32_t fee_estimator, uint32_t logger) {
7244         LDKChannelMonitor this_arg_conv;
7245         this_arg_conv.inner = (void*)(this_arg & (~1));
7246         this_arg_conv.is_owned = false;
7247         unsigned char header_arr[80];
7248         CHECK(header.len == 80);
7249         memcpy(header_arr, header.ptr, 80);
7250         unsigned char (*header_ref)[80] = &header_arr;
7251         LDKBroadcasterInterface broadcaster_conv = *(LDKBroadcasterInterface*)broadcaster;
7252         LDKFeeEstimator fee_estimator_conv = *(LDKFeeEstimator*)fee_estimator;
7253         LDKLogger logger_conv = *(LDKLogger*)logger;
7254         ChannelMonitor_block_disconnected(&this_arg_conv, header_ref, height, broadcaster_conv, fee_estimator_conv, logger_conv);
7255 }
7256
7257 void Persist_1free(void* ctx_TODO, uint32_t this_ptr) {
7258         LDKPersist this_ptr_conv = *(LDKPersist*)this_ptr;
7259         FREE((void*)this_ptr);
7260         Persist_free(this_ptr_conv);
7261 }
7262
7263 uint32_t C2Tuple_1BlockHashChannelMonitorZ_1read(void* ctx_TODO, int8_tArray ser, uint32_t arg) {
7264         LDKu8slice ser_ref;
7265         ser_ref.datalen = ser.len;
7266         ser_ref.data = ser.ptr;
7267         LDKKeysInterface* arg_conv = (LDKKeysInterface*)arg;
7268         LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ), "LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ");
7269         *ret_conv = C2Tuple_BlockHashChannelMonitorZ_read(ser_ref, arg_conv);
7270         return (long)ret_conv;
7271 }
7272
7273 void OutPoint_1free(void* ctx_TODO, uint32_t this_ptr) {
7274         LDKOutPoint this_ptr_conv;
7275         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7276         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7277         OutPoint_free(this_ptr_conv);
7278 }
7279
7280 uint32_t OutPoint_1clone(void* ctx_TODO, uint32_t orig) {
7281         LDKOutPoint orig_conv;
7282         orig_conv.inner = (void*)(orig & (~1));
7283         orig_conv.is_owned = false;
7284         LDKOutPoint ret_var = OutPoint_clone(&orig_conv);
7285         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7286         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7287         long ret_ref = (long)ret_var.inner;
7288         if (ret_var.is_owned) {
7289                 ret_ref |= 1;
7290         }
7291         return ret_ref;
7292 }
7293
7294 int8_tArray OutPoint_1get_1txid(void* ctx_TODO, uint32_t this_ptr) {
7295         LDKOutPoint this_ptr_conv;
7296         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7297         this_ptr_conv.is_owned = false;
7298         int8_tArray ret_arr = { .len = 32, .ptr = MALLOC(32, "Native int8_tArray Bytes") };
7299         memcpy(ret_arr.ptr, *OutPoint_get_txid(&this_ptr_conv), 32);
7300         return ret_arr;
7301 }
7302
7303 void OutPoint_1set_1txid(void* ctx_TODO, uint32_t this_ptr, int8_tArray val) {
7304         LDKOutPoint this_ptr_conv;
7305         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7306         this_ptr_conv.is_owned = false;
7307         LDKThirtyTwoBytes val_ref;
7308         CHECK(val.len == 32);
7309         memcpy(val_ref.data, val.ptr, 32);
7310         OutPoint_set_txid(&this_ptr_conv, val_ref);
7311 }
7312
7313 int16_t OutPoint_1get_1index(void* ctx_TODO, uint32_t this_ptr) {
7314         LDKOutPoint this_ptr_conv;
7315         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7316         this_ptr_conv.is_owned = false;
7317         int16_t ret_val = OutPoint_get_index(&this_ptr_conv);
7318         return ret_val;
7319 }
7320
7321 void OutPoint_1set_1index(void* ctx_TODO, uint32_t this_ptr, int16_t val) {
7322         LDKOutPoint this_ptr_conv;
7323         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7324         this_ptr_conv.is_owned = false;
7325         OutPoint_set_index(&this_ptr_conv, val);
7326 }
7327
7328 uint32_t OutPoint_1new(void* ctx_TODO, int8_tArray txid_arg, int16_t index_arg) {
7329         LDKThirtyTwoBytes txid_arg_ref;
7330         CHECK(txid_arg.len == 32);
7331         memcpy(txid_arg_ref.data, txid_arg.ptr, 32);
7332         LDKOutPoint ret_var = OutPoint_new(txid_arg_ref, index_arg);
7333         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7334         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7335         long ret_ref = (long)ret_var.inner;
7336         if (ret_var.is_owned) {
7337                 ret_ref |= 1;
7338         }
7339         return ret_ref;
7340 }
7341
7342 int8_tArray OutPoint_1to_1channel_1id(void* ctx_TODO, uint32_t this_arg) {
7343         LDKOutPoint this_arg_conv;
7344         this_arg_conv.inner = (void*)(this_arg & (~1));
7345         this_arg_conv.is_owned = false;
7346         int8_tArray arg_arr = { .len = 32, .ptr = MALLOC(32, "Native int8_tArray Bytes") };
7347         memcpy(arg_arr.ptr, OutPoint_to_channel_id(&this_arg_conv).data, 32);
7348         return arg_arr;
7349 }
7350
7351 int8_tArray OutPoint_1write(void* ctx_TODO, uint32_t obj) {
7352         LDKOutPoint obj_conv;
7353         obj_conv.inner = (void*)(obj & (~1));
7354         obj_conv.is_owned = false;
7355         LDKCVec_u8Z arg_var = OutPoint_write(&obj_conv);
7356         int8_tArray arg_arr = { .len = arg_var.datalen, .ptr = MALLOC(arg_var.datalen, "Native int8_tArray Bytes") };
7357         memcpy(arg_arr.ptr, arg_var.data, arg_var.datalen);
7358         CVec_u8Z_free(arg_var);
7359         return arg_arr;
7360 }
7361
7362 uint32_t OutPoint_1read(void* ctx_TODO, int8_tArray ser) {
7363         LDKu8slice ser_ref;
7364         ser_ref.datalen = ser.len;
7365         ser_ref.data = ser.ptr;
7366         LDKOutPoint ret_var = OutPoint_read(ser_ref);
7367         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7368         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7369         long ret_ref = (long)ret_var.inner;
7370         if (ret_var.is_owned) {
7371                 ret_ref |= 1;
7372         }
7373         return ret_ref;
7374 }
7375
7376 void SpendableOutputDescriptor_1free(void* ctx_TODO, uint32_t this_ptr) {
7377         LDKSpendableOutputDescriptor this_ptr_conv = *(LDKSpendableOutputDescriptor*)this_ptr;
7378         FREE((void*)this_ptr);
7379         SpendableOutputDescriptor_free(this_ptr_conv);
7380 }
7381
7382 uint32_t SpendableOutputDescriptor_1clone(void* ctx_TODO, uint32_t orig) {
7383         LDKSpendableOutputDescriptor* orig_conv = (LDKSpendableOutputDescriptor*)orig;
7384         LDKSpendableOutputDescriptor *ret_copy = MALLOC(sizeof(LDKSpendableOutputDescriptor), "LDKSpendableOutputDescriptor");
7385         *ret_copy = SpendableOutputDescriptor_clone(orig_conv);
7386         long ret_ref = (long)ret_copy;
7387         return ret_ref;
7388 }
7389
7390 int8_tArray SpendableOutputDescriptor_1write(void* ctx_TODO, uint32_t obj) {
7391         LDKSpendableOutputDescriptor* obj_conv = (LDKSpendableOutputDescriptor*)obj;
7392         LDKCVec_u8Z arg_var = SpendableOutputDescriptor_write(obj_conv);
7393         int8_tArray arg_arr = { .len = arg_var.datalen, .ptr = MALLOC(arg_var.datalen, "Native int8_tArray Bytes") };
7394         memcpy(arg_arr.ptr, arg_var.data, arg_var.datalen);
7395         CVec_u8Z_free(arg_var);
7396         return arg_arr;
7397 }
7398
7399 uint32_t SpendableOutputDescriptor_1read(void* ctx_TODO, int8_tArray ser) {
7400         LDKu8slice ser_ref;
7401         ser_ref.datalen = ser.len;
7402         ser_ref.data = ser.ptr;
7403         LDKCResult_SpendableOutputDescriptorDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_SpendableOutputDescriptorDecodeErrorZ), "LDKCResult_SpendableOutputDescriptorDecodeErrorZ");
7404         *ret_conv = SpendableOutputDescriptor_read(ser_ref);
7405         return (long)ret_conv;
7406 }
7407
7408 uint32_t ChannelKeys_1clone(void* ctx_TODO, uint32_t orig) {
7409         LDKChannelKeys* orig_conv = (LDKChannelKeys*)orig;
7410         LDKChannelKeys* ret = MALLOC(sizeof(LDKChannelKeys), "LDKChannelKeys");
7411         *ret = ChannelKeys_clone(orig_conv);
7412         return (long)ret;
7413 }
7414
7415 void ChannelKeys_1free(void* ctx_TODO, uint32_t this_ptr) {
7416         LDKChannelKeys this_ptr_conv = *(LDKChannelKeys*)this_ptr;
7417         FREE((void*)this_ptr);
7418         ChannelKeys_free(this_ptr_conv);
7419 }
7420
7421 void KeysInterface_1free(void* ctx_TODO, uint32_t this_ptr) {
7422         LDKKeysInterface this_ptr_conv = *(LDKKeysInterface*)this_ptr;
7423         FREE((void*)this_ptr);
7424         KeysInterface_free(this_ptr_conv);
7425 }
7426
7427 void InMemoryChannelKeys_1free(void* ctx_TODO, uint32_t this_ptr) {
7428         LDKInMemoryChannelKeys this_ptr_conv;
7429         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7430         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7431         InMemoryChannelKeys_free(this_ptr_conv);
7432 }
7433
7434 uint32_t InMemoryChannelKeys_1clone(void* ctx_TODO, uint32_t orig) {
7435         LDKInMemoryChannelKeys orig_conv;
7436         orig_conv.inner = (void*)(orig & (~1));
7437         orig_conv.is_owned = false;
7438         LDKInMemoryChannelKeys ret_var = InMemoryChannelKeys_clone(&orig_conv);
7439         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7440         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7441         long ret_ref = (long)ret_var.inner;
7442         if (ret_var.is_owned) {
7443                 ret_ref |= 1;
7444         }
7445         return ret_ref;
7446 }
7447
7448 int8_tArray InMemoryChannelKeys_1get_1funding_1key(void* ctx_TODO, uint32_t this_ptr) {
7449         LDKInMemoryChannelKeys this_ptr_conv;
7450         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7451         this_ptr_conv.is_owned = false;
7452         int8_tArray ret_arr = { .len = 32, .ptr = MALLOC(32, "Native int8_tArray Bytes") };
7453         memcpy(ret_arr.ptr, *InMemoryChannelKeys_get_funding_key(&this_ptr_conv), 32);
7454         return ret_arr;
7455 }
7456
7457 void InMemoryChannelKeys_1set_1funding_1key(void* ctx_TODO, uint32_t this_ptr, int8_tArray val) {
7458         LDKInMemoryChannelKeys this_ptr_conv;
7459         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7460         this_ptr_conv.is_owned = false;
7461         LDKSecretKey val_ref;
7462         CHECK(val.len == 32);
7463         memcpy(val_ref.bytes, val.ptr, 32);
7464         InMemoryChannelKeys_set_funding_key(&this_ptr_conv, val_ref);
7465 }
7466
7467 int8_tArray InMemoryChannelKeys_1get_1revocation_1base_1key(void* ctx_TODO, uint32_t this_ptr) {
7468         LDKInMemoryChannelKeys this_ptr_conv;
7469         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7470         this_ptr_conv.is_owned = false;
7471         int8_tArray ret_arr = { .len = 32, .ptr = MALLOC(32, "Native int8_tArray Bytes") };
7472         memcpy(ret_arr.ptr, *InMemoryChannelKeys_get_revocation_base_key(&this_ptr_conv), 32);
7473         return ret_arr;
7474 }
7475
7476 void InMemoryChannelKeys_1set_1revocation_1base_1key(void* ctx_TODO, uint32_t this_ptr, int8_tArray val) {
7477         LDKInMemoryChannelKeys this_ptr_conv;
7478         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7479         this_ptr_conv.is_owned = false;
7480         LDKSecretKey val_ref;
7481         CHECK(val.len == 32);
7482         memcpy(val_ref.bytes, val.ptr, 32);
7483         InMemoryChannelKeys_set_revocation_base_key(&this_ptr_conv, val_ref);
7484 }
7485
7486 int8_tArray InMemoryChannelKeys_1get_1payment_1key(void* ctx_TODO, uint32_t this_ptr) {
7487         LDKInMemoryChannelKeys this_ptr_conv;
7488         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7489         this_ptr_conv.is_owned = false;
7490         int8_tArray ret_arr = { .len = 32, .ptr = MALLOC(32, "Native int8_tArray Bytes") };
7491         memcpy(ret_arr.ptr, *InMemoryChannelKeys_get_payment_key(&this_ptr_conv), 32);
7492         return ret_arr;
7493 }
7494
7495 void InMemoryChannelKeys_1set_1payment_1key(void* ctx_TODO, uint32_t this_ptr, int8_tArray val) {
7496         LDKInMemoryChannelKeys this_ptr_conv;
7497         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7498         this_ptr_conv.is_owned = false;
7499         LDKSecretKey val_ref;
7500         CHECK(val.len == 32);
7501         memcpy(val_ref.bytes, val.ptr, 32);
7502         InMemoryChannelKeys_set_payment_key(&this_ptr_conv, val_ref);
7503 }
7504
7505 int8_tArray InMemoryChannelKeys_1get_1delayed_1payment_1base_1key(void* ctx_TODO, uint32_t this_ptr) {
7506         LDKInMemoryChannelKeys this_ptr_conv;
7507         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7508         this_ptr_conv.is_owned = false;
7509         int8_tArray ret_arr = { .len = 32, .ptr = MALLOC(32, "Native int8_tArray Bytes") };
7510         memcpy(ret_arr.ptr, *InMemoryChannelKeys_get_delayed_payment_base_key(&this_ptr_conv), 32);
7511         return ret_arr;
7512 }
7513
7514 void InMemoryChannelKeys_1set_1delayed_1payment_1base_1key(void* ctx_TODO, uint32_t this_ptr, int8_tArray val) {
7515         LDKInMemoryChannelKeys this_ptr_conv;
7516         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7517         this_ptr_conv.is_owned = false;
7518         LDKSecretKey val_ref;
7519         CHECK(val.len == 32);
7520         memcpy(val_ref.bytes, val.ptr, 32);
7521         InMemoryChannelKeys_set_delayed_payment_base_key(&this_ptr_conv, val_ref);
7522 }
7523
7524 int8_tArray InMemoryChannelKeys_1get_1htlc_1base_1key(void* ctx_TODO, uint32_t this_ptr) {
7525         LDKInMemoryChannelKeys this_ptr_conv;
7526         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7527         this_ptr_conv.is_owned = false;
7528         int8_tArray ret_arr = { .len = 32, .ptr = MALLOC(32, "Native int8_tArray Bytes") };
7529         memcpy(ret_arr.ptr, *InMemoryChannelKeys_get_htlc_base_key(&this_ptr_conv), 32);
7530         return ret_arr;
7531 }
7532
7533 void InMemoryChannelKeys_1set_1htlc_1base_1key(void* ctx_TODO, uint32_t this_ptr, int8_tArray val) {
7534         LDKInMemoryChannelKeys this_ptr_conv;
7535         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7536         this_ptr_conv.is_owned = false;
7537         LDKSecretKey val_ref;
7538         CHECK(val.len == 32);
7539         memcpy(val_ref.bytes, val.ptr, 32);
7540         InMemoryChannelKeys_set_htlc_base_key(&this_ptr_conv, val_ref);
7541 }
7542
7543 int8_tArray InMemoryChannelKeys_1get_1commitment_1seed(void* ctx_TODO, uint32_t this_ptr) {
7544         LDKInMemoryChannelKeys this_ptr_conv;
7545         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7546         this_ptr_conv.is_owned = false;
7547         int8_tArray ret_arr = { .len = 32, .ptr = MALLOC(32, "Native int8_tArray Bytes") };
7548         memcpy(ret_arr.ptr, *InMemoryChannelKeys_get_commitment_seed(&this_ptr_conv), 32);
7549         return ret_arr;
7550 }
7551
7552 void InMemoryChannelKeys_1set_1commitment_1seed(void* ctx_TODO, uint32_t this_ptr, int8_tArray val) {
7553         LDKInMemoryChannelKeys this_ptr_conv;
7554         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7555         this_ptr_conv.is_owned = false;
7556         LDKThirtyTwoBytes val_ref;
7557         CHECK(val.len == 32);
7558         memcpy(val_ref.data, val.ptr, 32);
7559         InMemoryChannelKeys_set_commitment_seed(&this_ptr_conv, val_ref);
7560 }
7561
7562 uint32_t InMemoryChannelKeys_1new(void* ctx_TODO, int8_tArray funding_key, int8_tArray revocation_base_key, int8_tArray payment_key, int8_tArray delayed_payment_base_key, int8_tArray htlc_base_key, int8_tArray commitment_seed, int64_t channel_value_satoshis, uint32_t key_derivation_params) {
7563         LDKSecretKey funding_key_ref;
7564         CHECK(funding_key.len == 32);
7565         memcpy(funding_key_ref.bytes, funding_key.ptr, 32);
7566         LDKSecretKey revocation_base_key_ref;
7567         CHECK(revocation_base_key.len == 32);
7568         memcpy(revocation_base_key_ref.bytes, revocation_base_key.ptr, 32);
7569         LDKSecretKey payment_key_ref;
7570         CHECK(payment_key.len == 32);
7571         memcpy(payment_key_ref.bytes, payment_key.ptr, 32);
7572         LDKSecretKey delayed_payment_base_key_ref;
7573         CHECK(delayed_payment_base_key.len == 32);
7574         memcpy(delayed_payment_base_key_ref.bytes, delayed_payment_base_key.ptr, 32);
7575         LDKSecretKey htlc_base_key_ref;
7576         CHECK(htlc_base_key.len == 32);
7577         memcpy(htlc_base_key_ref.bytes, htlc_base_key.ptr, 32);
7578         LDKThirtyTwoBytes commitment_seed_ref;
7579         CHECK(commitment_seed.len == 32);
7580         memcpy(commitment_seed_ref.data, commitment_seed.ptr, 32);
7581         LDKC2Tuple_u64u64Z key_derivation_params_conv = *(LDKC2Tuple_u64u64Z*)key_derivation_params;
7582         FREE((void*)key_derivation_params);
7583         LDKInMemoryChannelKeys ret_var = InMemoryChannelKeys_new(funding_key_ref, revocation_base_key_ref, payment_key_ref, delayed_payment_base_key_ref, htlc_base_key_ref, commitment_seed_ref, channel_value_satoshis, key_derivation_params_conv);
7584         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7585         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7586         long ret_ref = (long)ret_var.inner;
7587         if (ret_var.is_owned) {
7588                 ret_ref |= 1;
7589         }
7590         return ret_ref;
7591 }
7592
7593 uint32_t InMemoryChannelKeys_1counterparty_1pubkeys(void* ctx_TODO, uint32_t this_arg) {
7594         LDKInMemoryChannelKeys this_arg_conv;
7595         this_arg_conv.inner = (void*)(this_arg & (~1));
7596         this_arg_conv.is_owned = false;
7597         LDKChannelPublicKeys ret_var = InMemoryChannelKeys_counterparty_pubkeys(&this_arg_conv);
7598         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7599         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7600         long ret_ref = (long)ret_var.inner;
7601         if (ret_var.is_owned) {
7602                 ret_ref |= 1;
7603         }
7604         return ret_ref;
7605 }
7606
7607 int16_t InMemoryChannelKeys_1counterparty_1selected_1contest_1delay(void* ctx_TODO, uint32_t this_arg) {
7608         LDKInMemoryChannelKeys this_arg_conv;
7609         this_arg_conv.inner = (void*)(this_arg & (~1));
7610         this_arg_conv.is_owned = false;
7611         int16_t ret_val = InMemoryChannelKeys_counterparty_selected_contest_delay(&this_arg_conv);
7612         return ret_val;
7613 }
7614
7615 int16_t InMemoryChannelKeys_1holder_1selected_1contest_1delay(void* ctx_TODO, uint32_t this_arg) {
7616         LDKInMemoryChannelKeys this_arg_conv;
7617         this_arg_conv.inner = (void*)(this_arg & (~1));
7618         this_arg_conv.is_owned = false;
7619         int16_t ret_val = InMemoryChannelKeys_holder_selected_contest_delay(&this_arg_conv);
7620         return ret_val;
7621 }
7622
7623 jboolean InMemoryChannelKeys_1is_1outbound(void* ctx_TODO, uint32_t this_arg) {
7624         LDKInMemoryChannelKeys this_arg_conv;
7625         this_arg_conv.inner = (void*)(this_arg & (~1));
7626         this_arg_conv.is_owned = false;
7627         jboolean ret_val = InMemoryChannelKeys_is_outbound(&this_arg_conv);
7628         return ret_val;
7629 }
7630
7631 uint32_t InMemoryChannelKeys_1funding_1outpoint(void* ctx_TODO, uint32_t this_arg) {
7632         LDKInMemoryChannelKeys this_arg_conv;
7633         this_arg_conv.inner = (void*)(this_arg & (~1));
7634         this_arg_conv.is_owned = false;
7635         LDKOutPoint ret_var = InMemoryChannelKeys_funding_outpoint(&this_arg_conv);
7636         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7637         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7638         long ret_ref = (long)ret_var.inner;
7639         if (ret_var.is_owned) {
7640                 ret_ref |= 1;
7641         }
7642         return ret_ref;
7643 }
7644
7645 uint32_t InMemoryChannelKeys_1get_1channel_1parameters(void* ctx_TODO, uint32_t this_arg) {
7646         LDKInMemoryChannelKeys this_arg_conv;
7647         this_arg_conv.inner = (void*)(this_arg & (~1));
7648         this_arg_conv.is_owned = false;
7649         LDKChannelTransactionParameters ret_var = InMemoryChannelKeys_get_channel_parameters(&this_arg_conv);
7650         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7651         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7652         long ret_ref = (long)ret_var.inner;
7653         if (ret_var.is_owned) {
7654                 ret_ref |= 1;
7655         }
7656         return ret_ref;
7657 }
7658
7659 uint32_t InMemoryChannelKeys_1as_1ChannelKeys(void* ctx_TODO, uint32_t this_arg) {
7660         LDKInMemoryChannelKeys this_arg_conv;
7661         this_arg_conv.inner = (void*)(this_arg & (~1));
7662         this_arg_conv.is_owned = false;
7663         LDKChannelKeys* ret = MALLOC(sizeof(LDKChannelKeys), "LDKChannelKeys");
7664         *ret = InMemoryChannelKeys_as_ChannelKeys(&this_arg_conv);
7665         return (long)ret;
7666 }
7667
7668 int8_tArray InMemoryChannelKeys_1write(void* ctx_TODO, uint32_t obj) {
7669         LDKInMemoryChannelKeys obj_conv;
7670         obj_conv.inner = (void*)(obj & (~1));
7671         obj_conv.is_owned = false;
7672         LDKCVec_u8Z arg_var = InMemoryChannelKeys_write(&obj_conv);
7673         int8_tArray arg_arr = { .len = arg_var.datalen, .ptr = MALLOC(arg_var.datalen, "Native int8_tArray Bytes") };
7674         memcpy(arg_arr.ptr, arg_var.data, arg_var.datalen);
7675         CVec_u8Z_free(arg_var);
7676         return arg_arr;
7677 }
7678
7679 uint32_t InMemoryChannelKeys_1read(void* ctx_TODO, int8_tArray ser) {
7680         LDKu8slice ser_ref;
7681         ser_ref.datalen = ser.len;
7682         ser_ref.data = ser.ptr;
7683         LDKCResult_InMemoryChannelKeysDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_InMemoryChannelKeysDecodeErrorZ), "LDKCResult_InMemoryChannelKeysDecodeErrorZ");
7684         *ret_conv = InMemoryChannelKeys_read(ser_ref);
7685         return (long)ret_conv;
7686 }
7687
7688 void KeysManager_1free(void* ctx_TODO, uint32_t this_ptr) {
7689         LDKKeysManager this_ptr_conv;
7690         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7691         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7692         KeysManager_free(this_ptr_conv);
7693 }
7694
7695 uint32_t KeysManager_1new(void* ctx_TODO, int8_tArray seed, uint32_t network, int64_t starting_time_secs, int32_t starting_time_nanos) {
7696         unsigned char seed_arr[32];
7697         CHECK(seed.len == 32);
7698         memcpy(seed_arr, seed.ptr, 32);
7699         unsigned char (*seed_ref)[32] = &seed_arr;
7700         LDKNetwork network_conv = LDKNetwork_from_js(network);
7701         LDKKeysManager ret_var = KeysManager_new(seed_ref, network_conv, starting_time_secs, starting_time_nanos);
7702         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7703         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7704         long ret_ref = (long)ret_var.inner;
7705         if (ret_var.is_owned) {
7706                 ret_ref |= 1;
7707         }
7708         return ret_ref;
7709 }
7710
7711 uint32_t KeysManager_1derive_1channel_1keys(void* ctx_TODO, uint32_t this_arg, int64_t channel_value_satoshis, int64_t params_1, int64_t params_2) {
7712         LDKKeysManager this_arg_conv;
7713         this_arg_conv.inner = (void*)(this_arg & (~1));
7714         this_arg_conv.is_owned = false;
7715         LDKInMemoryChannelKeys ret_var = KeysManager_derive_channel_keys(&this_arg_conv, channel_value_satoshis, params_1, params_2);
7716         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7717         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7718         long ret_ref = (long)ret_var.inner;
7719         if (ret_var.is_owned) {
7720                 ret_ref |= 1;
7721         }
7722         return ret_ref;
7723 }
7724
7725 uint32_t KeysManager_1as_1KeysInterface(void* ctx_TODO, uint32_t this_arg) {
7726         LDKKeysManager this_arg_conv;
7727         this_arg_conv.inner = (void*)(this_arg & (~1));
7728         this_arg_conv.is_owned = false;
7729         LDKKeysInterface* ret = MALLOC(sizeof(LDKKeysInterface), "LDKKeysInterface");
7730         *ret = KeysManager_as_KeysInterface(&this_arg_conv);
7731         return (long)ret;
7732 }
7733
7734 void ChannelManager_1free(void* ctx_TODO, uint32_t this_ptr) {
7735         LDKChannelManager this_ptr_conv;
7736         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7737         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7738         ChannelManager_free(this_ptr_conv);
7739 }
7740
7741 void ChannelDetails_1free(void* ctx_TODO, uint32_t this_ptr) {
7742         LDKChannelDetails this_ptr_conv;
7743         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7744         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7745         ChannelDetails_free(this_ptr_conv);
7746 }
7747
7748 uint32_t ChannelDetails_1clone(void* ctx_TODO, uint32_t orig) {
7749         LDKChannelDetails orig_conv;
7750         orig_conv.inner = (void*)(orig & (~1));
7751         orig_conv.is_owned = false;
7752         LDKChannelDetails ret_var = ChannelDetails_clone(&orig_conv);
7753         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7754         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7755         long ret_ref = (long)ret_var.inner;
7756         if (ret_var.is_owned) {
7757                 ret_ref |= 1;
7758         }
7759         return ret_ref;
7760 }
7761
7762 int8_tArray ChannelDetails_1get_1channel_1id(void* ctx_TODO, uint32_t this_ptr) {
7763         LDKChannelDetails this_ptr_conv;
7764         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7765         this_ptr_conv.is_owned = false;
7766         int8_tArray ret_arr = { .len = 32, .ptr = MALLOC(32, "Native int8_tArray Bytes") };
7767         memcpy(ret_arr.ptr, *ChannelDetails_get_channel_id(&this_ptr_conv), 32);
7768         return ret_arr;
7769 }
7770
7771 void ChannelDetails_1set_1channel_1id(void* ctx_TODO, uint32_t this_ptr, int8_tArray val) {
7772         LDKChannelDetails this_ptr_conv;
7773         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7774         this_ptr_conv.is_owned = false;
7775         LDKThirtyTwoBytes val_ref;
7776         CHECK(val.len == 32);
7777         memcpy(val_ref.data, val.ptr, 32);
7778         ChannelDetails_set_channel_id(&this_ptr_conv, val_ref);
7779 }
7780
7781 int8_tArray ChannelDetails_1get_1remote_1network_1id(void* ctx_TODO, uint32_t this_ptr) {
7782         LDKChannelDetails this_ptr_conv;
7783         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7784         this_ptr_conv.is_owned = false;
7785         int8_tArray arg_arr = { .len = 33, .ptr = MALLOC(33, "Native int8_tArray Bytes") };
7786         memcpy(arg_arr.ptr, ChannelDetails_get_remote_network_id(&this_ptr_conv).compressed_form, 33);
7787         return arg_arr;
7788 }
7789
7790 void ChannelDetails_1set_1remote_1network_1id(void* ctx_TODO, uint32_t this_ptr, int8_tArray val) {
7791         LDKChannelDetails this_ptr_conv;
7792         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7793         this_ptr_conv.is_owned = false;
7794         LDKPublicKey val_ref;
7795         CHECK(val.len == 33);
7796         memcpy(val_ref.compressed_form, val.ptr, 33);
7797         ChannelDetails_set_remote_network_id(&this_ptr_conv, val_ref);
7798 }
7799
7800 uint32_t ChannelDetails_1get_1counterparty_1features(void* ctx_TODO, uint32_t this_ptr) {
7801         LDKChannelDetails this_ptr_conv;
7802         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7803         this_ptr_conv.is_owned = false;
7804         LDKInitFeatures ret_var = ChannelDetails_get_counterparty_features(&this_ptr_conv);
7805         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7806         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7807         long ret_ref = (long)ret_var.inner;
7808         if (ret_var.is_owned) {
7809                 ret_ref |= 1;
7810         }
7811         return ret_ref;
7812 }
7813
7814 void ChannelDetails_1set_1counterparty_1features(void* ctx_TODO, uint32_t this_ptr, uint32_t val) {
7815         LDKChannelDetails this_ptr_conv;
7816         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7817         this_ptr_conv.is_owned = false;
7818         LDKInitFeatures val_conv;
7819         val_conv.inner = (void*)(val & (~1));
7820         val_conv.is_owned = (val & 1) || (val == 0);
7821         // Warning: we may need a move here but can't clone!
7822         ChannelDetails_set_counterparty_features(&this_ptr_conv, val_conv);
7823 }
7824
7825 int64_t ChannelDetails_1get_1channel_1value_1satoshis(void* ctx_TODO, uint32_t this_ptr) {
7826         LDKChannelDetails this_ptr_conv;
7827         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7828         this_ptr_conv.is_owned = false;
7829         int64_t ret_val = ChannelDetails_get_channel_value_satoshis(&this_ptr_conv);
7830         return ret_val;
7831 }
7832
7833 void ChannelDetails_1set_1channel_1value_1satoshis(void* ctx_TODO, uint32_t this_ptr, int64_t val) {
7834         LDKChannelDetails this_ptr_conv;
7835         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7836         this_ptr_conv.is_owned = false;
7837         ChannelDetails_set_channel_value_satoshis(&this_ptr_conv, val);
7838 }
7839
7840 int64_t ChannelDetails_1get_1user_1id(void* ctx_TODO, uint32_t this_ptr) {
7841         LDKChannelDetails this_ptr_conv;
7842         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7843         this_ptr_conv.is_owned = false;
7844         int64_t ret_val = ChannelDetails_get_user_id(&this_ptr_conv);
7845         return ret_val;
7846 }
7847
7848 void ChannelDetails_1set_1user_1id(void* ctx_TODO, uint32_t this_ptr, int64_t val) {
7849         LDKChannelDetails this_ptr_conv;
7850         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7851         this_ptr_conv.is_owned = false;
7852         ChannelDetails_set_user_id(&this_ptr_conv, val);
7853 }
7854
7855 int64_t ChannelDetails_1get_1outbound_1capacity_1msat(void* ctx_TODO, uint32_t this_ptr) {
7856         LDKChannelDetails this_ptr_conv;
7857         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7858         this_ptr_conv.is_owned = false;
7859         int64_t ret_val = ChannelDetails_get_outbound_capacity_msat(&this_ptr_conv);
7860         return ret_val;
7861 }
7862
7863 void ChannelDetails_1set_1outbound_1capacity_1msat(void* ctx_TODO, uint32_t this_ptr, int64_t val) {
7864         LDKChannelDetails this_ptr_conv;
7865         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7866         this_ptr_conv.is_owned = false;
7867         ChannelDetails_set_outbound_capacity_msat(&this_ptr_conv, val);
7868 }
7869
7870 int64_t ChannelDetails_1get_1inbound_1capacity_1msat(void* ctx_TODO, uint32_t this_ptr) {
7871         LDKChannelDetails this_ptr_conv;
7872         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7873         this_ptr_conv.is_owned = false;
7874         int64_t ret_val = ChannelDetails_get_inbound_capacity_msat(&this_ptr_conv);
7875         return ret_val;
7876 }
7877
7878 void ChannelDetails_1set_1inbound_1capacity_1msat(void* ctx_TODO, uint32_t this_ptr, int64_t val) {
7879         LDKChannelDetails this_ptr_conv;
7880         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7881         this_ptr_conv.is_owned = false;
7882         ChannelDetails_set_inbound_capacity_msat(&this_ptr_conv, val);
7883 }
7884
7885 jboolean ChannelDetails_1get_1is_1live(void* ctx_TODO, uint32_t this_ptr) {
7886         LDKChannelDetails this_ptr_conv;
7887         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7888         this_ptr_conv.is_owned = false;
7889         jboolean ret_val = ChannelDetails_get_is_live(&this_ptr_conv);
7890         return ret_val;
7891 }
7892
7893 void ChannelDetails_1set_1is_1live(void* ctx_TODO, uint32_t this_ptr, jboolean val) {
7894         LDKChannelDetails this_ptr_conv;
7895         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7896         this_ptr_conv.is_owned = false;
7897         ChannelDetails_set_is_live(&this_ptr_conv, val);
7898 }
7899
7900 void PaymentSendFailure_1free(void* ctx_TODO, uint32_t this_ptr) {
7901         LDKPaymentSendFailure this_ptr_conv;
7902         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7903         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7904         PaymentSendFailure_free(this_ptr_conv);
7905 }
7906
7907 uint32_t ChannelManager_1new(void* ctx_TODO, uint32_t network, uint32_t fee_est, uint32_t chain_monitor, uint32_t tx_broadcaster, uint32_t logger, uint32_t keys_manager, uint32_t config, intptr_t current_blockchain_height) {
7908         LDKNetwork network_conv = LDKNetwork_from_js(network);
7909         LDKFeeEstimator fee_est_conv = *(LDKFeeEstimator*)fee_est;
7910         LDKWatch chain_monitor_conv = *(LDKWatch*)chain_monitor;
7911         LDKBroadcasterInterface tx_broadcaster_conv = *(LDKBroadcasterInterface*)tx_broadcaster;
7912         LDKLogger logger_conv = *(LDKLogger*)logger;
7913         LDKKeysInterface keys_manager_conv = *(LDKKeysInterface*)keys_manager;
7914         LDKUserConfig config_conv;
7915         config_conv.inner = (void*)(config & (~1));
7916         config_conv.is_owned = (config & 1) || (config == 0);
7917         if (config_conv.inner != NULL)
7918                 config_conv = UserConfig_clone(&config_conv);
7919         LDKChannelManager ret_var = ChannelManager_new(network_conv, fee_est_conv, chain_monitor_conv, tx_broadcaster_conv, logger_conv, keys_manager_conv, config_conv, current_blockchain_height);
7920         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7921         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7922         long ret_ref = (long)ret_var.inner;
7923         if (ret_var.is_owned) {
7924                 ret_ref |= 1;
7925         }
7926         return ret_ref;
7927 }
7928
7929 uint32_t ChannelManager_1create_1channel(void* ctx_TODO, uint32_t this_arg, int8_tArray their_network_key, int64_t channel_value_satoshis, int64_t push_msat, int64_t user_id, uint32_t override_config) {
7930         LDKChannelManager this_arg_conv;
7931         this_arg_conv.inner = (void*)(this_arg & (~1));
7932         this_arg_conv.is_owned = false;
7933         LDKPublicKey their_network_key_ref;
7934         CHECK(their_network_key.len == 33);
7935         memcpy(their_network_key_ref.compressed_form, their_network_key.ptr, 33);
7936         LDKUserConfig override_config_conv;
7937         override_config_conv.inner = (void*)(override_config & (~1));
7938         override_config_conv.is_owned = (override_config & 1) || (override_config == 0);
7939         if (override_config_conv.inner != NULL)
7940                 override_config_conv = UserConfig_clone(&override_config_conv);
7941         LDKCResult_NoneAPIErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneAPIErrorZ), "LDKCResult_NoneAPIErrorZ");
7942         *ret_conv = ChannelManager_create_channel(&this_arg_conv, their_network_key_ref, channel_value_satoshis, push_msat, user_id, override_config_conv);
7943         return (long)ret_conv;
7944 }
7945
7946 uint32_tArray ChannelManager_1list_1channels(void* ctx_TODO, uint32_t this_arg) {
7947         LDKChannelManager this_arg_conv;
7948         this_arg_conv.inner = (void*)(this_arg & (~1));
7949         this_arg_conv.is_owned = false;
7950         LDKCVec_ChannelDetailsZ ret_var = ChannelManager_list_channels(&this_arg_conv);
7951         uint32_tArray ret_arr = { .len = ret_var.datalen, .ptr = MALLOC(ret_var.datalen * sizeof(int32_t), "Native uint32_tArray Bytes") };
7952         uint32_t *ret_arr_ptr = (uint32_t*)ret_arr.ptr;
7953         for (size_t q = 0; q < ret_var.datalen; q++) {
7954                 LDKChannelDetails arr_conv_16_var = ret_var.data[q];
7955                 CHECK((((long)arr_conv_16_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7956                 CHECK((((long)&arr_conv_16_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7957                 long arr_conv_16_ref = (long)arr_conv_16_var.inner;
7958                 if (arr_conv_16_var.is_owned) {
7959                         arr_conv_16_ref |= 1;
7960                 }
7961                 ret_arr_ptr[q] = arr_conv_16_ref;
7962         }
7963         FREE(ret_var.data);
7964         return ret_arr;
7965 }
7966
7967 uint32_tArray ChannelManager_1list_1usable_1channels(void* ctx_TODO, uint32_t this_arg) {
7968         LDKChannelManager this_arg_conv;
7969         this_arg_conv.inner = (void*)(this_arg & (~1));
7970         this_arg_conv.is_owned = false;
7971         LDKCVec_ChannelDetailsZ ret_var = ChannelManager_list_usable_channels(&this_arg_conv);
7972         uint32_tArray ret_arr = { .len = ret_var.datalen, .ptr = MALLOC(ret_var.datalen * sizeof(int32_t), "Native uint32_tArray Bytes") };
7973         uint32_t *ret_arr_ptr = (uint32_t*)ret_arr.ptr;
7974         for (size_t q = 0; q < ret_var.datalen; q++) {
7975                 LDKChannelDetails arr_conv_16_var = ret_var.data[q];
7976                 CHECK((((long)arr_conv_16_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7977                 CHECK((((long)&arr_conv_16_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7978                 long arr_conv_16_ref = (long)arr_conv_16_var.inner;
7979                 if (arr_conv_16_var.is_owned) {
7980                         arr_conv_16_ref |= 1;
7981                 }
7982                 ret_arr_ptr[q] = arr_conv_16_ref;
7983         }
7984         FREE(ret_var.data);
7985         return ret_arr;
7986 }
7987
7988 uint32_t ChannelManager_1close_1channel(void* ctx_TODO, uint32_t this_arg, int8_tArray channel_id) {
7989         LDKChannelManager this_arg_conv;
7990         this_arg_conv.inner = (void*)(this_arg & (~1));
7991         this_arg_conv.is_owned = false;
7992         unsigned char channel_id_arr[32];
7993         CHECK(channel_id.len == 32);
7994         memcpy(channel_id_arr, channel_id.ptr, 32);
7995         unsigned char (*channel_id_ref)[32] = &channel_id_arr;
7996         LDKCResult_NoneAPIErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneAPIErrorZ), "LDKCResult_NoneAPIErrorZ");
7997         *ret_conv = ChannelManager_close_channel(&this_arg_conv, channel_id_ref);
7998         return (long)ret_conv;
7999 }
8000
8001 void ChannelManager_1force_1close_1channel(void* ctx_TODO, uint32_t this_arg, int8_tArray channel_id) {
8002         LDKChannelManager this_arg_conv;
8003         this_arg_conv.inner = (void*)(this_arg & (~1));
8004         this_arg_conv.is_owned = false;
8005         unsigned char channel_id_arr[32];
8006         CHECK(channel_id.len == 32);
8007         memcpy(channel_id_arr, channel_id.ptr, 32);
8008         unsigned char (*channel_id_ref)[32] = &channel_id_arr;
8009         ChannelManager_force_close_channel(&this_arg_conv, channel_id_ref);
8010 }
8011
8012 void ChannelManager_1force_1close_1all_1channels(void* ctx_TODO, uint32_t this_arg) {
8013         LDKChannelManager this_arg_conv;
8014         this_arg_conv.inner = (void*)(this_arg & (~1));
8015         this_arg_conv.is_owned = false;
8016         ChannelManager_force_close_all_channels(&this_arg_conv);
8017 }
8018
8019 uint32_t ChannelManager_1send_1payment(void* ctx_TODO, uint32_t this_arg, uint32_t route, int8_tArray payment_hash, int8_tArray payment_secret) {
8020         LDKChannelManager this_arg_conv;
8021         this_arg_conv.inner = (void*)(this_arg & (~1));
8022         this_arg_conv.is_owned = false;
8023         LDKRoute route_conv;
8024         route_conv.inner = (void*)(route & (~1));
8025         route_conv.is_owned = false;
8026         LDKThirtyTwoBytes payment_hash_ref;
8027         CHECK(payment_hash.len == 32);
8028         memcpy(payment_hash_ref.data, payment_hash.ptr, 32);
8029         LDKThirtyTwoBytes payment_secret_ref;
8030         CHECK(payment_secret.len == 32);
8031         memcpy(payment_secret_ref.data, payment_secret.ptr, 32);
8032         LDKCResult_NonePaymentSendFailureZ* ret_conv = MALLOC(sizeof(LDKCResult_NonePaymentSendFailureZ), "LDKCResult_NonePaymentSendFailureZ");
8033         *ret_conv = ChannelManager_send_payment(&this_arg_conv, &route_conv, payment_hash_ref, payment_secret_ref);
8034         return (long)ret_conv;
8035 }
8036
8037 void ChannelManager_1funding_1transaction_1generated(void* ctx_TODO, uint32_t this_arg, int8_tArray temporary_channel_id, uint32_t funding_txo) {
8038         LDKChannelManager this_arg_conv;
8039         this_arg_conv.inner = (void*)(this_arg & (~1));
8040         this_arg_conv.is_owned = false;
8041         unsigned char temporary_channel_id_arr[32];
8042         CHECK(temporary_channel_id.len == 32);
8043         memcpy(temporary_channel_id_arr, temporary_channel_id.ptr, 32);
8044         unsigned char (*temporary_channel_id_ref)[32] = &temporary_channel_id_arr;
8045         LDKOutPoint funding_txo_conv;
8046         funding_txo_conv.inner = (void*)(funding_txo & (~1));
8047         funding_txo_conv.is_owned = (funding_txo & 1) || (funding_txo == 0);
8048         if (funding_txo_conv.inner != NULL)
8049                 funding_txo_conv = OutPoint_clone(&funding_txo_conv);
8050         ChannelManager_funding_transaction_generated(&this_arg_conv, temporary_channel_id_ref, funding_txo_conv);
8051 }
8052
8053 void ChannelManager_1broadcast_1node_1announcement(void* ctx_TODO, uint32_t this_arg, int8_tArray rgb, int8_tArray alias, uint32_tArray addresses) {
8054         LDKChannelManager this_arg_conv;
8055         this_arg_conv.inner = (void*)(this_arg & (~1));
8056         this_arg_conv.is_owned = false;
8057         LDKThreeBytes rgb_ref;
8058         CHECK(rgb.len == 3);
8059         memcpy(rgb_ref.data, rgb.ptr, 3);
8060         LDKThirtyTwoBytes alias_ref;
8061         CHECK(alias.len == 32);
8062         memcpy(alias_ref.data, alias.ptr, 32);
8063         LDKCVec_NetAddressZ addresses_constr;
8064         addresses_constr.datalen = addresses.len;
8065         if (addresses_constr.datalen > 0)
8066                 addresses_constr.data = MALLOC(addresses_constr.datalen * sizeof(LDKNetAddress), "LDKCVec_NetAddressZ Elements");
8067         else
8068                 addresses_constr.data = NULL;
8069         uint32_t* addresses_vals = (uint32_t*) addresses.ptr;
8070         for (size_t m = 0; m < addresses_constr.datalen; m++) {
8071                 uint32_t arr_conv_12 = addresses_vals[m];
8072                 LDKNetAddress arr_conv_12_conv = *(LDKNetAddress*)arr_conv_12;
8073                 FREE((void*)arr_conv_12);
8074                 addresses_constr.data[m] = arr_conv_12_conv;
8075         }
8076         ChannelManager_broadcast_node_announcement(&this_arg_conv, rgb_ref, alias_ref, addresses_constr);
8077 }
8078
8079 void ChannelManager_1process_1pending_1htlc_1forwards(void* ctx_TODO, uint32_t this_arg) {
8080         LDKChannelManager this_arg_conv;
8081         this_arg_conv.inner = (void*)(this_arg & (~1));
8082         this_arg_conv.is_owned = false;
8083         ChannelManager_process_pending_htlc_forwards(&this_arg_conv);
8084 }
8085
8086 void ChannelManager_1timer_1chan_1freshness_1every_1min(void* ctx_TODO, uint32_t this_arg) {
8087         LDKChannelManager this_arg_conv;
8088         this_arg_conv.inner = (void*)(this_arg & (~1));
8089         this_arg_conv.is_owned = false;
8090         ChannelManager_timer_chan_freshness_every_min(&this_arg_conv);
8091 }
8092
8093 jboolean ChannelManager_1fail_1htlc_1backwards(void* ctx_TODO, uint32_t this_arg, int8_tArray payment_hash, int8_tArray payment_secret) {
8094         LDKChannelManager this_arg_conv;
8095         this_arg_conv.inner = (void*)(this_arg & (~1));
8096         this_arg_conv.is_owned = false;
8097         unsigned char payment_hash_arr[32];
8098         CHECK(payment_hash.len == 32);
8099         memcpy(payment_hash_arr, payment_hash.ptr, 32);
8100         unsigned char (*payment_hash_ref)[32] = &payment_hash_arr;
8101         LDKThirtyTwoBytes payment_secret_ref;
8102         CHECK(payment_secret.len == 32);
8103         memcpy(payment_secret_ref.data, payment_secret.ptr, 32);
8104         jboolean ret_val = ChannelManager_fail_htlc_backwards(&this_arg_conv, payment_hash_ref, payment_secret_ref);
8105         return ret_val;
8106 }
8107
8108 jboolean ChannelManager_1claim_1funds(void* ctx_TODO, uint32_t this_arg, int8_tArray payment_preimage, int8_tArray payment_secret, int64_t expected_amount) {
8109         LDKChannelManager this_arg_conv;
8110         this_arg_conv.inner = (void*)(this_arg & (~1));
8111         this_arg_conv.is_owned = false;
8112         LDKThirtyTwoBytes payment_preimage_ref;
8113         CHECK(payment_preimage.len == 32);
8114         memcpy(payment_preimage_ref.data, payment_preimage.ptr, 32);
8115         LDKThirtyTwoBytes payment_secret_ref;
8116         CHECK(payment_secret.len == 32);
8117         memcpy(payment_secret_ref.data, payment_secret.ptr, 32);
8118         jboolean ret_val = ChannelManager_claim_funds(&this_arg_conv, payment_preimage_ref, payment_secret_ref, expected_amount);
8119         return ret_val;
8120 }
8121
8122 int8_tArray ChannelManager_1get_1our_1node_1id(void* ctx_TODO, uint32_t this_arg) {
8123         LDKChannelManager this_arg_conv;
8124         this_arg_conv.inner = (void*)(this_arg & (~1));
8125         this_arg_conv.is_owned = false;
8126         int8_tArray arg_arr = { .len = 33, .ptr = MALLOC(33, "Native int8_tArray Bytes") };
8127         memcpy(arg_arr.ptr, ChannelManager_get_our_node_id(&this_arg_conv).compressed_form, 33);
8128         return arg_arr;
8129 }
8130
8131 void ChannelManager_1channel_1monitor_1updated(void* ctx_TODO, uint32_t this_arg, uint32_t funding_txo, int64_t highest_applied_update_id) {
8132         LDKChannelManager this_arg_conv;
8133         this_arg_conv.inner = (void*)(this_arg & (~1));
8134         this_arg_conv.is_owned = false;
8135         LDKOutPoint funding_txo_conv;
8136         funding_txo_conv.inner = (void*)(funding_txo & (~1));
8137         funding_txo_conv.is_owned = false;
8138         ChannelManager_channel_monitor_updated(&this_arg_conv, &funding_txo_conv, highest_applied_update_id);
8139 }
8140
8141 uint32_t ChannelManager_1as_1MessageSendEventsProvider(void* ctx_TODO, uint32_t this_arg) {
8142         LDKChannelManager this_arg_conv;
8143         this_arg_conv.inner = (void*)(this_arg & (~1));
8144         this_arg_conv.is_owned = false;
8145         LDKMessageSendEventsProvider* ret = MALLOC(sizeof(LDKMessageSendEventsProvider), "LDKMessageSendEventsProvider");
8146         *ret = ChannelManager_as_MessageSendEventsProvider(&this_arg_conv);
8147         return (long)ret;
8148 }
8149
8150 uint32_t ChannelManager_1as_1EventsProvider(void* ctx_TODO, uint32_t this_arg) {
8151         LDKChannelManager this_arg_conv;
8152         this_arg_conv.inner = (void*)(this_arg & (~1));
8153         this_arg_conv.is_owned = false;
8154         LDKEventsProvider* ret = MALLOC(sizeof(LDKEventsProvider), "LDKEventsProvider");
8155         *ret = ChannelManager_as_EventsProvider(&this_arg_conv);
8156         return (long)ret;
8157 }
8158
8159 void ChannelManager_1block_1connected(void* ctx_TODO, uint32_t this_arg, int8_tArray header, uint32_tArray txdata, int32_t height) {
8160         LDKChannelManager this_arg_conv;
8161         this_arg_conv.inner = (void*)(this_arg & (~1));
8162         this_arg_conv.is_owned = false;
8163         unsigned char header_arr[80];
8164         CHECK(header.len == 80);
8165         memcpy(header_arr, header.ptr, 80);
8166         unsigned char (*header_ref)[80] = &header_arr;
8167         LDKCVec_C2Tuple_usizeTransactionZZ txdata_constr;
8168         txdata_constr.datalen = txdata.len;
8169         if (txdata_constr.datalen > 0)
8170                 txdata_constr.data = MALLOC(txdata_constr.datalen * sizeof(LDKC2Tuple_usizeTransactionZ), "LDKCVec_C2Tuple_usizeTransactionZZ Elements");
8171         else
8172                 txdata_constr.data = NULL;
8173         uint32_t* txdata_vals = (uint32_t*) txdata.ptr;
8174         for (size_t e = 0; e < txdata_constr.datalen; e++) {
8175                 uint32_t arr_conv_30 = txdata_vals[e];
8176                 LDKC2Tuple_usizeTransactionZ arr_conv_30_conv = *(LDKC2Tuple_usizeTransactionZ*)arr_conv_30;
8177                 FREE((void*)arr_conv_30);
8178                 txdata_constr.data[e] = arr_conv_30_conv;
8179         }
8180         ChannelManager_block_connected(&this_arg_conv, header_ref, txdata_constr, height);
8181 }
8182
8183 void ChannelManager_1block_1disconnected(void* ctx_TODO, uint32_t this_arg, int8_tArray header) {
8184         LDKChannelManager this_arg_conv;
8185         this_arg_conv.inner = (void*)(this_arg & (~1));
8186         this_arg_conv.is_owned = false;
8187         unsigned char header_arr[80];
8188         CHECK(header.len == 80);
8189         memcpy(header_arr, header.ptr, 80);
8190         unsigned char (*header_ref)[80] = &header_arr;
8191         ChannelManager_block_disconnected(&this_arg_conv, header_ref);
8192 }
8193
8194 uint32_t ChannelManager_1as_1ChannelMessageHandler(void* ctx_TODO, uint32_t this_arg) {
8195         LDKChannelManager this_arg_conv;
8196         this_arg_conv.inner = (void*)(this_arg & (~1));
8197         this_arg_conv.is_owned = false;
8198         LDKChannelMessageHandler* ret = MALLOC(sizeof(LDKChannelMessageHandler), "LDKChannelMessageHandler");
8199         *ret = ChannelManager_as_ChannelMessageHandler(&this_arg_conv);
8200         return (long)ret;
8201 }
8202
8203 int8_tArray ChannelManager_1write(void* ctx_TODO, uint32_t obj) {
8204         LDKChannelManager obj_conv;
8205         obj_conv.inner = (void*)(obj & (~1));
8206         obj_conv.is_owned = false;
8207         LDKCVec_u8Z arg_var = ChannelManager_write(&obj_conv);
8208         int8_tArray arg_arr = { .len = arg_var.datalen, .ptr = MALLOC(arg_var.datalen, "Native int8_tArray Bytes") };
8209         memcpy(arg_arr.ptr, arg_var.data, arg_var.datalen);
8210         CVec_u8Z_free(arg_var);
8211         return arg_arr;
8212 }
8213
8214 void ChannelManagerReadArgs_1free(void* ctx_TODO, uint32_t this_ptr) {
8215         LDKChannelManagerReadArgs this_ptr_conv;
8216         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8217         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8218         ChannelManagerReadArgs_free(this_ptr_conv);
8219 }
8220
8221 uint32_t ChannelManagerReadArgs_1get_1keys_1manager(void* ctx_TODO, uint32_t this_ptr) {
8222         LDKChannelManagerReadArgs this_ptr_conv;
8223         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8224         this_ptr_conv.is_owned = false;
8225         long ret_ret = (long)ChannelManagerReadArgs_get_keys_manager(&this_ptr_conv);
8226         return ret_ret;
8227 }
8228
8229 void ChannelManagerReadArgs_1set_1keys_1manager(void* ctx_TODO, uint32_t this_ptr, uint32_t val) {
8230         LDKChannelManagerReadArgs this_ptr_conv;
8231         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8232         this_ptr_conv.is_owned = false;
8233         LDKKeysInterface val_conv = *(LDKKeysInterface*)val;
8234         ChannelManagerReadArgs_set_keys_manager(&this_ptr_conv, val_conv);
8235 }
8236
8237 uint32_t ChannelManagerReadArgs_1get_1fee_1estimator(void* ctx_TODO, uint32_t this_ptr) {
8238         LDKChannelManagerReadArgs this_ptr_conv;
8239         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8240         this_ptr_conv.is_owned = false;
8241         long ret_ret = (long)ChannelManagerReadArgs_get_fee_estimator(&this_ptr_conv);
8242         return ret_ret;
8243 }
8244
8245 void ChannelManagerReadArgs_1set_1fee_1estimator(void* ctx_TODO, uint32_t this_ptr, uint32_t val) {
8246         LDKChannelManagerReadArgs this_ptr_conv;
8247         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8248         this_ptr_conv.is_owned = false;
8249         LDKFeeEstimator val_conv = *(LDKFeeEstimator*)val;
8250         ChannelManagerReadArgs_set_fee_estimator(&this_ptr_conv, val_conv);
8251 }
8252
8253 uint32_t ChannelManagerReadArgs_1get_1chain_1monitor(void* ctx_TODO, uint32_t this_ptr) {
8254         LDKChannelManagerReadArgs this_ptr_conv;
8255         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8256         this_ptr_conv.is_owned = false;
8257         long ret_ret = (long)ChannelManagerReadArgs_get_chain_monitor(&this_ptr_conv);
8258         return ret_ret;
8259 }
8260
8261 void ChannelManagerReadArgs_1set_1chain_1monitor(void* ctx_TODO, uint32_t this_ptr, uint32_t val) {
8262         LDKChannelManagerReadArgs this_ptr_conv;
8263         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8264         this_ptr_conv.is_owned = false;
8265         LDKWatch val_conv = *(LDKWatch*)val;
8266         ChannelManagerReadArgs_set_chain_monitor(&this_ptr_conv, val_conv);
8267 }
8268
8269 uint32_t ChannelManagerReadArgs_1get_1tx_1broadcaster(void* ctx_TODO, uint32_t this_ptr) {
8270         LDKChannelManagerReadArgs this_ptr_conv;
8271         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8272         this_ptr_conv.is_owned = false;
8273         long ret_ret = (long)ChannelManagerReadArgs_get_tx_broadcaster(&this_ptr_conv);
8274         return ret_ret;
8275 }
8276
8277 void ChannelManagerReadArgs_1set_1tx_1broadcaster(void* ctx_TODO, uint32_t this_ptr, uint32_t val) {
8278         LDKChannelManagerReadArgs this_ptr_conv;
8279         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8280         this_ptr_conv.is_owned = false;
8281         LDKBroadcasterInterface val_conv = *(LDKBroadcasterInterface*)val;
8282         ChannelManagerReadArgs_set_tx_broadcaster(&this_ptr_conv, val_conv);
8283 }
8284
8285 uint32_t ChannelManagerReadArgs_1get_1logger(void* ctx_TODO, uint32_t this_ptr) {
8286         LDKChannelManagerReadArgs this_ptr_conv;
8287         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8288         this_ptr_conv.is_owned = false;
8289         long ret_ret = (long)ChannelManagerReadArgs_get_logger(&this_ptr_conv);
8290         return ret_ret;
8291 }
8292
8293 void ChannelManagerReadArgs_1set_1logger(void* ctx_TODO, uint32_t this_ptr, uint32_t val) {
8294         LDKChannelManagerReadArgs this_ptr_conv;
8295         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8296         this_ptr_conv.is_owned = false;
8297         LDKLogger val_conv = *(LDKLogger*)val;
8298         ChannelManagerReadArgs_set_logger(&this_ptr_conv, val_conv);
8299 }
8300
8301 uint32_t ChannelManagerReadArgs_1get_1default_1config(void* ctx_TODO, uint32_t this_ptr) {
8302         LDKChannelManagerReadArgs this_ptr_conv;
8303         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8304         this_ptr_conv.is_owned = false;
8305         LDKUserConfig ret_var = ChannelManagerReadArgs_get_default_config(&this_ptr_conv);
8306         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8307         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8308         long ret_ref = (long)ret_var.inner;
8309         if (ret_var.is_owned) {
8310                 ret_ref |= 1;
8311         }
8312         return ret_ref;
8313 }
8314
8315 void ChannelManagerReadArgs_1set_1default_1config(void* ctx_TODO, uint32_t this_ptr, uint32_t val) {
8316         LDKChannelManagerReadArgs this_ptr_conv;
8317         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8318         this_ptr_conv.is_owned = false;
8319         LDKUserConfig val_conv;
8320         val_conv.inner = (void*)(val & (~1));
8321         val_conv.is_owned = (val & 1) || (val == 0);
8322         if (val_conv.inner != NULL)
8323                 val_conv = UserConfig_clone(&val_conv);
8324         ChannelManagerReadArgs_set_default_config(&this_ptr_conv, val_conv);
8325 }
8326
8327 uint32_t ChannelManagerReadArgs_1new(void* ctx_TODO, uint32_t keys_manager, uint32_t fee_estimator, uint32_t chain_monitor, uint32_t tx_broadcaster, uint32_t logger, uint32_t default_config, uint32_tArray channel_monitors) {
8328         LDKKeysInterface keys_manager_conv = *(LDKKeysInterface*)keys_manager;
8329         LDKFeeEstimator fee_estimator_conv = *(LDKFeeEstimator*)fee_estimator;
8330         LDKWatch chain_monitor_conv = *(LDKWatch*)chain_monitor;
8331         LDKBroadcasterInterface tx_broadcaster_conv = *(LDKBroadcasterInterface*)tx_broadcaster;
8332         LDKLogger logger_conv = *(LDKLogger*)logger;
8333         LDKUserConfig default_config_conv;
8334         default_config_conv.inner = (void*)(default_config & (~1));
8335         default_config_conv.is_owned = (default_config & 1) || (default_config == 0);
8336         if (default_config_conv.inner != NULL)
8337                 default_config_conv = UserConfig_clone(&default_config_conv);
8338         LDKCVec_ChannelMonitorZ channel_monitors_constr;
8339         channel_monitors_constr.datalen = channel_monitors.len;
8340         if (channel_monitors_constr.datalen > 0)
8341                 channel_monitors_constr.data = MALLOC(channel_monitors_constr.datalen * sizeof(LDKChannelMonitor), "LDKCVec_ChannelMonitorZ Elements");
8342         else
8343                 channel_monitors_constr.data = NULL;
8344         uint32_t* channel_monitors_vals = (uint32_t*) channel_monitors.ptr;
8345         for (size_t q = 0; q < channel_monitors_constr.datalen; q++) {
8346                 uint32_t arr_conv_16 = channel_monitors_vals[q];
8347                 LDKChannelMonitor arr_conv_16_conv;
8348                 arr_conv_16_conv.inner = (void*)(arr_conv_16 & (~1));
8349                 arr_conv_16_conv.is_owned = (arr_conv_16 & 1) || (arr_conv_16 == 0);
8350                 // Warning: we may need a move here but can't clone!
8351                 channel_monitors_constr.data[q] = arr_conv_16_conv;
8352         }
8353         LDKChannelManagerReadArgs ret_var = ChannelManagerReadArgs_new(keys_manager_conv, fee_estimator_conv, chain_monitor_conv, tx_broadcaster_conv, logger_conv, default_config_conv, channel_monitors_constr);
8354         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8355         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8356         long ret_ref = (long)ret_var.inner;
8357         if (ret_var.is_owned) {
8358                 ret_ref |= 1;
8359         }
8360         return ret_ref;
8361 }
8362
8363 uint32_t C2Tuple_1BlockHashChannelManagerZ_1read(void* ctx_TODO, int8_tArray ser, uint32_t arg) {
8364         LDKu8slice ser_ref;
8365         ser_ref.datalen = ser.len;
8366         ser_ref.data = ser.ptr;
8367         LDKChannelManagerReadArgs arg_conv;
8368         arg_conv.inner = (void*)(arg & (~1));
8369         arg_conv.is_owned = (arg & 1) || (arg == 0);
8370         // Warning: we may need a move here but can't clone!
8371         LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ), "LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ");
8372         *ret_conv = C2Tuple_BlockHashChannelManagerZ_read(ser_ref, arg_conv);
8373         return (long)ret_conv;
8374 }
8375
8376 void DecodeError_1free(void* ctx_TODO, uint32_t this_ptr) {
8377         LDKDecodeError this_ptr_conv;
8378         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8379         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8380         DecodeError_free(this_ptr_conv);
8381 }
8382
8383 void Init_1free(void* ctx_TODO, uint32_t this_ptr) {
8384         LDKInit this_ptr_conv;
8385         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8386         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8387         Init_free(this_ptr_conv);
8388 }
8389
8390 uint32_t Init_1clone(void* ctx_TODO, uint32_t orig) {
8391         LDKInit orig_conv;
8392         orig_conv.inner = (void*)(orig & (~1));
8393         orig_conv.is_owned = false;
8394         LDKInit ret_var = Init_clone(&orig_conv);
8395         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8396         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8397         long ret_ref = (long)ret_var.inner;
8398         if (ret_var.is_owned) {
8399                 ret_ref |= 1;
8400         }
8401         return ret_ref;
8402 }
8403
8404 void ErrorMessage_1free(void* ctx_TODO, uint32_t this_ptr) {
8405         LDKErrorMessage this_ptr_conv;
8406         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8407         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8408         ErrorMessage_free(this_ptr_conv);
8409 }
8410
8411 uint32_t ErrorMessage_1clone(void* ctx_TODO, uint32_t orig) {
8412         LDKErrorMessage orig_conv;
8413         orig_conv.inner = (void*)(orig & (~1));
8414         orig_conv.is_owned = false;
8415         LDKErrorMessage ret_var = ErrorMessage_clone(&orig_conv);
8416         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8417         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8418         long ret_ref = (long)ret_var.inner;
8419         if (ret_var.is_owned) {
8420                 ret_ref |= 1;
8421         }
8422         return ret_ref;
8423 }
8424
8425 int8_tArray ErrorMessage_1get_1channel_1id(void* ctx_TODO, uint32_t this_ptr) {
8426         LDKErrorMessage this_ptr_conv;
8427         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8428         this_ptr_conv.is_owned = false;
8429         int8_tArray ret_arr = { .len = 32, .ptr = MALLOC(32, "Native int8_tArray Bytes") };
8430         memcpy(ret_arr.ptr, *ErrorMessage_get_channel_id(&this_ptr_conv), 32);
8431         return ret_arr;
8432 }
8433
8434 void ErrorMessage_1set_1channel_1id(void* ctx_TODO, uint32_t this_ptr, int8_tArray val) {
8435         LDKErrorMessage this_ptr_conv;
8436         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8437         this_ptr_conv.is_owned = false;
8438         LDKThirtyTwoBytes val_ref;
8439         CHECK(val.len == 32);
8440         memcpy(val_ref.data, val.ptr, 32);
8441         ErrorMessage_set_channel_id(&this_ptr_conv, val_ref);
8442 }
8443
8444 jstring ErrorMessage_1get_1data(void* ctx_TODO, uint32_t this_ptr) {
8445         LDKErrorMessage this_ptr_conv;
8446         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8447         this_ptr_conv.is_owned = false;
8448         LDKStr _str = ErrorMessage_get_data(&this_ptr_conv);
8449         char* _buf = MALLOC(_str.len + 1, "str conv buf");
8450         memcpy(_buf, _str.chars, _str.len);
8451         _buf[_str.len] = 0;
8452         jstring _conv = conv_owned_string(_str.chars);
8453         FREE(_buf);
8454         return _conv;
8455 }
8456
8457 void ErrorMessage_1set_1data(void* ctx_TODO, uint32_t this_ptr, int8_tArray val) {
8458         LDKErrorMessage this_ptr_conv;
8459         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8460         this_ptr_conv.is_owned = false;
8461         LDKCVec_u8Z val_ref;
8462         val_ref.datalen = val.len;
8463         val_ref.data = MALLOC(val_ref.datalen, "LDKCVec_u8Z Bytes");
8464         memcpy(val_ref.data, val.ptr, val_ref.datalen);
8465         ErrorMessage_set_data(&this_ptr_conv, val_ref);
8466 }
8467
8468 uint32_t ErrorMessage_1new(void* ctx_TODO, int8_tArray channel_id_arg, int8_tArray data_arg) {
8469         LDKThirtyTwoBytes channel_id_arg_ref;
8470         CHECK(channel_id_arg.len == 32);
8471         memcpy(channel_id_arg_ref.data, channel_id_arg.ptr, 32);
8472         LDKCVec_u8Z data_arg_ref;
8473         data_arg_ref.datalen = data_arg.len;
8474         data_arg_ref.data = MALLOC(data_arg_ref.datalen, "LDKCVec_u8Z Bytes");
8475         memcpy(data_arg_ref.data, data_arg.ptr, data_arg_ref.datalen);
8476         LDKErrorMessage ret_var = ErrorMessage_new(channel_id_arg_ref, data_arg_ref);
8477         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8478         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8479         long ret_ref = (long)ret_var.inner;
8480         if (ret_var.is_owned) {
8481                 ret_ref |= 1;
8482         }
8483         return ret_ref;
8484 }
8485
8486 void Ping_1free(void* ctx_TODO, uint32_t this_ptr) {
8487         LDKPing this_ptr_conv;
8488         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8489         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8490         Ping_free(this_ptr_conv);
8491 }
8492
8493 uint32_t Ping_1clone(void* ctx_TODO, uint32_t orig) {
8494         LDKPing orig_conv;
8495         orig_conv.inner = (void*)(orig & (~1));
8496         orig_conv.is_owned = false;
8497         LDKPing ret_var = Ping_clone(&orig_conv);
8498         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8499         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8500         long ret_ref = (long)ret_var.inner;
8501         if (ret_var.is_owned) {
8502                 ret_ref |= 1;
8503         }
8504         return ret_ref;
8505 }
8506
8507 int16_t Ping_1get_1ponglen(void* ctx_TODO, uint32_t this_ptr) {
8508         LDKPing this_ptr_conv;
8509         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8510         this_ptr_conv.is_owned = false;
8511         int16_t ret_val = Ping_get_ponglen(&this_ptr_conv);
8512         return ret_val;
8513 }
8514
8515 void Ping_1set_1ponglen(void* ctx_TODO, uint32_t this_ptr, int16_t val) {
8516         LDKPing this_ptr_conv;
8517         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8518         this_ptr_conv.is_owned = false;
8519         Ping_set_ponglen(&this_ptr_conv, val);
8520 }
8521
8522 int16_t Ping_1get_1byteslen(void* ctx_TODO, uint32_t this_ptr) {
8523         LDKPing this_ptr_conv;
8524         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8525         this_ptr_conv.is_owned = false;
8526         int16_t ret_val = Ping_get_byteslen(&this_ptr_conv);
8527         return ret_val;
8528 }
8529
8530 void Ping_1set_1byteslen(void* ctx_TODO, uint32_t this_ptr, int16_t val) {
8531         LDKPing this_ptr_conv;
8532         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8533         this_ptr_conv.is_owned = false;
8534         Ping_set_byteslen(&this_ptr_conv, val);
8535 }
8536
8537 uint32_t Ping_1new(void* ctx_TODO, int16_t ponglen_arg, int16_t byteslen_arg) {
8538         LDKPing ret_var = Ping_new(ponglen_arg, byteslen_arg);
8539         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8540         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8541         long ret_ref = (long)ret_var.inner;
8542         if (ret_var.is_owned) {
8543                 ret_ref |= 1;
8544         }
8545         return ret_ref;
8546 }
8547
8548 void Pong_1free(void* ctx_TODO, uint32_t this_ptr) {
8549         LDKPong this_ptr_conv;
8550         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8551         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8552         Pong_free(this_ptr_conv);
8553 }
8554
8555 uint32_t Pong_1clone(void* ctx_TODO, uint32_t orig) {
8556         LDKPong orig_conv;
8557         orig_conv.inner = (void*)(orig & (~1));
8558         orig_conv.is_owned = false;
8559         LDKPong ret_var = Pong_clone(&orig_conv);
8560         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8561         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8562         long ret_ref = (long)ret_var.inner;
8563         if (ret_var.is_owned) {
8564                 ret_ref |= 1;
8565         }
8566         return ret_ref;
8567 }
8568
8569 int16_t Pong_1get_1byteslen(void* ctx_TODO, uint32_t this_ptr) {
8570         LDKPong this_ptr_conv;
8571         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8572         this_ptr_conv.is_owned = false;
8573         int16_t ret_val = Pong_get_byteslen(&this_ptr_conv);
8574         return ret_val;
8575 }
8576
8577 void Pong_1set_1byteslen(void* ctx_TODO, uint32_t this_ptr, int16_t val) {
8578         LDKPong this_ptr_conv;
8579         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8580         this_ptr_conv.is_owned = false;
8581         Pong_set_byteslen(&this_ptr_conv, val);
8582 }
8583
8584 uint32_t Pong_1new(void* ctx_TODO, int16_t byteslen_arg) {
8585         LDKPong ret_var = Pong_new(byteslen_arg);
8586         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8587         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8588         long ret_ref = (long)ret_var.inner;
8589         if (ret_var.is_owned) {
8590                 ret_ref |= 1;
8591         }
8592         return ret_ref;
8593 }
8594
8595 void OpenChannel_1free(void* ctx_TODO, uint32_t this_ptr) {
8596         LDKOpenChannel this_ptr_conv;
8597         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8598         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8599         OpenChannel_free(this_ptr_conv);
8600 }
8601
8602 uint32_t OpenChannel_1clone(void* ctx_TODO, uint32_t orig) {
8603         LDKOpenChannel orig_conv;
8604         orig_conv.inner = (void*)(orig & (~1));
8605         orig_conv.is_owned = false;
8606         LDKOpenChannel ret_var = OpenChannel_clone(&orig_conv);
8607         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8608         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8609         long ret_ref = (long)ret_var.inner;
8610         if (ret_var.is_owned) {
8611                 ret_ref |= 1;
8612         }
8613         return ret_ref;
8614 }
8615
8616 int8_tArray OpenChannel_1get_1chain_1hash(void* ctx_TODO, uint32_t this_ptr) {
8617         LDKOpenChannel this_ptr_conv;
8618         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8619         this_ptr_conv.is_owned = false;
8620         int8_tArray ret_arr = { .len = 32, .ptr = MALLOC(32, "Native int8_tArray Bytes") };
8621         memcpy(ret_arr.ptr, *OpenChannel_get_chain_hash(&this_ptr_conv), 32);
8622         return ret_arr;
8623 }
8624
8625 void OpenChannel_1set_1chain_1hash(void* ctx_TODO, uint32_t this_ptr, int8_tArray val) {
8626         LDKOpenChannel this_ptr_conv;
8627         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8628         this_ptr_conv.is_owned = false;
8629         LDKThirtyTwoBytes val_ref;
8630         CHECK(val.len == 32);
8631         memcpy(val_ref.data, val.ptr, 32);
8632         OpenChannel_set_chain_hash(&this_ptr_conv, val_ref);
8633 }
8634
8635 int8_tArray OpenChannel_1get_1temporary_1channel_1id(void* ctx_TODO, uint32_t this_ptr) {
8636         LDKOpenChannel this_ptr_conv;
8637         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8638         this_ptr_conv.is_owned = false;
8639         int8_tArray ret_arr = { .len = 32, .ptr = MALLOC(32, "Native int8_tArray Bytes") };
8640         memcpy(ret_arr.ptr, *OpenChannel_get_temporary_channel_id(&this_ptr_conv), 32);
8641         return ret_arr;
8642 }
8643
8644 void OpenChannel_1set_1temporary_1channel_1id(void* ctx_TODO, uint32_t this_ptr, int8_tArray val) {
8645         LDKOpenChannel this_ptr_conv;
8646         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8647         this_ptr_conv.is_owned = false;
8648         LDKThirtyTwoBytes val_ref;
8649         CHECK(val.len == 32);
8650         memcpy(val_ref.data, val.ptr, 32);
8651         OpenChannel_set_temporary_channel_id(&this_ptr_conv, val_ref);
8652 }
8653
8654 int64_t OpenChannel_1get_1funding_1satoshis(void* ctx_TODO, uint32_t this_ptr) {
8655         LDKOpenChannel this_ptr_conv;
8656         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8657         this_ptr_conv.is_owned = false;
8658         int64_t ret_val = OpenChannel_get_funding_satoshis(&this_ptr_conv);
8659         return ret_val;
8660 }
8661
8662 void OpenChannel_1set_1funding_1satoshis(void* ctx_TODO, uint32_t this_ptr, int64_t val) {
8663         LDKOpenChannel this_ptr_conv;
8664         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8665         this_ptr_conv.is_owned = false;
8666         OpenChannel_set_funding_satoshis(&this_ptr_conv, val);
8667 }
8668
8669 int64_t OpenChannel_1get_1push_1msat(void* ctx_TODO, uint32_t this_ptr) {
8670         LDKOpenChannel this_ptr_conv;
8671         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8672         this_ptr_conv.is_owned = false;
8673         int64_t ret_val = OpenChannel_get_push_msat(&this_ptr_conv);
8674         return ret_val;
8675 }
8676
8677 void OpenChannel_1set_1push_1msat(void* ctx_TODO, uint32_t this_ptr, int64_t val) {
8678         LDKOpenChannel this_ptr_conv;
8679         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8680         this_ptr_conv.is_owned = false;
8681         OpenChannel_set_push_msat(&this_ptr_conv, val);
8682 }
8683
8684 int64_t OpenChannel_1get_1dust_1limit_1satoshis(void* ctx_TODO, uint32_t this_ptr) {
8685         LDKOpenChannel this_ptr_conv;
8686         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8687         this_ptr_conv.is_owned = false;
8688         int64_t ret_val = OpenChannel_get_dust_limit_satoshis(&this_ptr_conv);
8689         return ret_val;
8690 }
8691
8692 void OpenChannel_1set_1dust_1limit_1satoshis(void* ctx_TODO, uint32_t this_ptr, int64_t val) {
8693         LDKOpenChannel this_ptr_conv;
8694         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8695         this_ptr_conv.is_owned = false;
8696         OpenChannel_set_dust_limit_satoshis(&this_ptr_conv, val);
8697 }
8698
8699 int64_t OpenChannel_1get_1max_1htlc_1value_1in_1flight_1msat(void* ctx_TODO, uint32_t this_ptr) {
8700         LDKOpenChannel this_ptr_conv;
8701         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8702         this_ptr_conv.is_owned = false;
8703         int64_t ret_val = OpenChannel_get_max_htlc_value_in_flight_msat(&this_ptr_conv);
8704         return ret_val;
8705 }
8706
8707 void OpenChannel_1set_1max_1htlc_1value_1in_1flight_1msat(void* ctx_TODO, uint32_t this_ptr, int64_t val) {
8708         LDKOpenChannel this_ptr_conv;
8709         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8710         this_ptr_conv.is_owned = false;
8711         OpenChannel_set_max_htlc_value_in_flight_msat(&this_ptr_conv, val);
8712 }
8713
8714 int64_t OpenChannel_1get_1channel_1reserve_1satoshis(void* ctx_TODO, uint32_t this_ptr) {
8715         LDKOpenChannel this_ptr_conv;
8716         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8717         this_ptr_conv.is_owned = false;
8718         int64_t ret_val = OpenChannel_get_channel_reserve_satoshis(&this_ptr_conv);
8719         return ret_val;
8720 }
8721
8722 void OpenChannel_1set_1channel_1reserve_1satoshis(void* ctx_TODO, uint32_t this_ptr, int64_t val) {
8723         LDKOpenChannel this_ptr_conv;
8724         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8725         this_ptr_conv.is_owned = false;
8726         OpenChannel_set_channel_reserve_satoshis(&this_ptr_conv, val);
8727 }
8728
8729 int64_t OpenChannel_1get_1htlc_1minimum_1msat(void* ctx_TODO, uint32_t this_ptr) {
8730         LDKOpenChannel this_ptr_conv;
8731         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8732         this_ptr_conv.is_owned = false;
8733         int64_t ret_val = OpenChannel_get_htlc_minimum_msat(&this_ptr_conv);
8734         return ret_val;
8735 }
8736
8737 void OpenChannel_1set_1htlc_1minimum_1msat(void* ctx_TODO, uint32_t this_ptr, int64_t val) {
8738         LDKOpenChannel this_ptr_conv;
8739         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8740         this_ptr_conv.is_owned = false;
8741         OpenChannel_set_htlc_minimum_msat(&this_ptr_conv, val);
8742 }
8743
8744 int32_t OpenChannel_1get_1feerate_1per_1kw(void* ctx_TODO, uint32_t this_ptr) {
8745         LDKOpenChannel this_ptr_conv;
8746         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8747         this_ptr_conv.is_owned = false;
8748         int32_t ret_val = OpenChannel_get_feerate_per_kw(&this_ptr_conv);
8749         return ret_val;
8750 }
8751
8752 void OpenChannel_1set_1feerate_1per_1kw(void* ctx_TODO, uint32_t this_ptr, int32_t val) {
8753         LDKOpenChannel this_ptr_conv;
8754         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8755         this_ptr_conv.is_owned = false;
8756         OpenChannel_set_feerate_per_kw(&this_ptr_conv, val);
8757 }
8758
8759 int16_t OpenChannel_1get_1to_1self_1delay(void* ctx_TODO, uint32_t this_ptr) {
8760         LDKOpenChannel this_ptr_conv;
8761         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8762         this_ptr_conv.is_owned = false;
8763         int16_t ret_val = OpenChannel_get_to_self_delay(&this_ptr_conv);
8764         return ret_val;
8765 }
8766
8767 void OpenChannel_1set_1to_1self_1delay(void* ctx_TODO, uint32_t this_ptr, int16_t val) {
8768         LDKOpenChannel this_ptr_conv;
8769         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8770         this_ptr_conv.is_owned = false;
8771         OpenChannel_set_to_self_delay(&this_ptr_conv, val);
8772 }
8773
8774 int16_t OpenChannel_1get_1max_1accepted_1htlcs(void* ctx_TODO, uint32_t this_ptr) {
8775         LDKOpenChannel this_ptr_conv;
8776         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8777         this_ptr_conv.is_owned = false;
8778         int16_t ret_val = OpenChannel_get_max_accepted_htlcs(&this_ptr_conv);
8779         return ret_val;
8780 }
8781
8782 void OpenChannel_1set_1max_1accepted_1htlcs(void* ctx_TODO, uint32_t this_ptr, int16_t val) {
8783         LDKOpenChannel this_ptr_conv;
8784         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8785         this_ptr_conv.is_owned = false;
8786         OpenChannel_set_max_accepted_htlcs(&this_ptr_conv, val);
8787 }
8788
8789 int8_tArray OpenChannel_1get_1funding_1pubkey(void* ctx_TODO, uint32_t this_ptr) {
8790         LDKOpenChannel this_ptr_conv;
8791         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8792         this_ptr_conv.is_owned = false;
8793         int8_tArray arg_arr = { .len = 33, .ptr = MALLOC(33, "Native int8_tArray Bytes") };
8794         memcpy(arg_arr.ptr, OpenChannel_get_funding_pubkey(&this_ptr_conv).compressed_form, 33);
8795         return arg_arr;
8796 }
8797
8798 void OpenChannel_1set_1funding_1pubkey(void* ctx_TODO, uint32_t this_ptr, int8_tArray val) {
8799         LDKOpenChannel this_ptr_conv;
8800         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8801         this_ptr_conv.is_owned = false;
8802         LDKPublicKey val_ref;
8803         CHECK(val.len == 33);
8804         memcpy(val_ref.compressed_form, val.ptr, 33);
8805         OpenChannel_set_funding_pubkey(&this_ptr_conv, val_ref);
8806 }
8807
8808 int8_tArray OpenChannel_1get_1revocation_1basepoint(void* ctx_TODO, uint32_t this_ptr) {
8809         LDKOpenChannel this_ptr_conv;
8810         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8811         this_ptr_conv.is_owned = false;
8812         int8_tArray arg_arr = { .len = 33, .ptr = MALLOC(33, "Native int8_tArray Bytes") };
8813         memcpy(arg_arr.ptr, OpenChannel_get_revocation_basepoint(&this_ptr_conv).compressed_form, 33);
8814         return arg_arr;
8815 }
8816
8817 void OpenChannel_1set_1revocation_1basepoint(void* ctx_TODO, uint32_t this_ptr, int8_tArray val) {
8818         LDKOpenChannel this_ptr_conv;
8819         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8820         this_ptr_conv.is_owned = false;
8821         LDKPublicKey val_ref;
8822         CHECK(val.len == 33);
8823         memcpy(val_ref.compressed_form, val.ptr, 33);
8824         OpenChannel_set_revocation_basepoint(&this_ptr_conv, val_ref);
8825 }
8826
8827 int8_tArray OpenChannel_1get_1payment_1point(void* ctx_TODO, uint32_t this_ptr) {
8828         LDKOpenChannel this_ptr_conv;
8829         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8830         this_ptr_conv.is_owned = false;
8831         int8_tArray arg_arr = { .len = 33, .ptr = MALLOC(33, "Native int8_tArray Bytes") };
8832         memcpy(arg_arr.ptr, OpenChannel_get_payment_point(&this_ptr_conv).compressed_form, 33);
8833         return arg_arr;
8834 }
8835
8836 void OpenChannel_1set_1payment_1point(void* ctx_TODO, uint32_t this_ptr, int8_tArray val) {
8837         LDKOpenChannel this_ptr_conv;
8838         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8839         this_ptr_conv.is_owned = false;
8840         LDKPublicKey val_ref;
8841         CHECK(val.len == 33);
8842         memcpy(val_ref.compressed_form, val.ptr, 33);
8843         OpenChannel_set_payment_point(&this_ptr_conv, val_ref);
8844 }
8845
8846 int8_tArray OpenChannel_1get_1delayed_1payment_1basepoint(void* ctx_TODO, uint32_t this_ptr) {
8847         LDKOpenChannel this_ptr_conv;
8848         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8849         this_ptr_conv.is_owned = false;
8850         int8_tArray arg_arr = { .len = 33, .ptr = MALLOC(33, "Native int8_tArray Bytes") };
8851         memcpy(arg_arr.ptr, OpenChannel_get_delayed_payment_basepoint(&this_ptr_conv).compressed_form, 33);
8852         return arg_arr;
8853 }
8854
8855 void OpenChannel_1set_1delayed_1payment_1basepoint(void* ctx_TODO, uint32_t this_ptr, int8_tArray val) {
8856         LDKOpenChannel this_ptr_conv;
8857         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8858         this_ptr_conv.is_owned = false;
8859         LDKPublicKey val_ref;
8860         CHECK(val.len == 33);
8861         memcpy(val_ref.compressed_form, val.ptr, 33);
8862         OpenChannel_set_delayed_payment_basepoint(&this_ptr_conv, val_ref);
8863 }
8864
8865 int8_tArray OpenChannel_1get_1htlc_1basepoint(void* ctx_TODO, uint32_t this_ptr) {
8866         LDKOpenChannel this_ptr_conv;
8867         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8868         this_ptr_conv.is_owned = false;
8869         int8_tArray arg_arr = { .len = 33, .ptr = MALLOC(33, "Native int8_tArray Bytes") };
8870         memcpy(arg_arr.ptr, OpenChannel_get_htlc_basepoint(&this_ptr_conv).compressed_form, 33);
8871         return arg_arr;
8872 }
8873
8874 void OpenChannel_1set_1htlc_1basepoint(void* ctx_TODO, uint32_t this_ptr, int8_tArray val) {
8875         LDKOpenChannel this_ptr_conv;
8876         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8877         this_ptr_conv.is_owned = false;
8878         LDKPublicKey val_ref;
8879         CHECK(val.len == 33);
8880         memcpy(val_ref.compressed_form, val.ptr, 33);
8881         OpenChannel_set_htlc_basepoint(&this_ptr_conv, val_ref);
8882 }
8883
8884 int8_tArray OpenChannel_1get_1first_1per_1commitment_1point(void* ctx_TODO, uint32_t this_ptr) {
8885         LDKOpenChannel this_ptr_conv;
8886         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8887         this_ptr_conv.is_owned = false;
8888         int8_tArray arg_arr = { .len = 33, .ptr = MALLOC(33, "Native int8_tArray Bytes") };
8889         memcpy(arg_arr.ptr, OpenChannel_get_first_per_commitment_point(&this_ptr_conv).compressed_form, 33);
8890         return arg_arr;
8891 }
8892
8893 void OpenChannel_1set_1first_1per_1commitment_1point(void* ctx_TODO, uint32_t this_ptr, int8_tArray val) {
8894         LDKOpenChannel this_ptr_conv;
8895         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8896         this_ptr_conv.is_owned = false;
8897         LDKPublicKey val_ref;
8898         CHECK(val.len == 33);
8899         memcpy(val_ref.compressed_form, val.ptr, 33);
8900         OpenChannel_set_first_per_commitment_point(&this_ptr_conv, val_ref);
8901 }
8902
8903 int8_t OpenChannel_1get_1channel_1flags(void* ctx_TODO, uint32_t this_ptr) {
8904         LDKOpenChannel this_ptr_conv;
8905         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8906         this_ptr_conv.is_owned = false;
8907         int8_t ret_val = OpenChannel_get_channel_flags(&this_ptr_conv);
8908         return ret_val;
8909 }
8910
8911 void OpenChannel_1set_1channel_1flags(void* ctx_TODO, uint32_t this_ptr, int8_t val) {
8912         LDKOpenChannel this_ptr_conv;
8913         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8914         this_ptr_conv.is_owned = false;
8915         OpenChannel_set_channel_flags(&this_ptr_conv, val);
8916 }
8917
8918 void AcceptChannel_1free(void* ctx_TODO, uint32_t this_ptr) {
8919         LDKAcceptChannel this_ptr_conv;
8920         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8921         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8922         AcceptChannel_free(this_ptr_conv);
8923 }
8924
8925 uint32_t AcceptChannel_1clone(void* ctx_TODO, uint32_t orig) {
8926         LDKAcceptChannel orig_conv;
8927         orig_conv.inner = (void*)(orig & (~1));
8928         orig_conv.is_owned = false;
8929         LDKAcceptChannel ret_var = AcceptChannel_clone(&orig_conv);
8930         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8931         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8932         long ret_ref = (long)ret_var.inner;
8933         if (ret_var.is_owned) {
8934                 ret_ref |= 1;
8935         }
8936         return ret_ref;
8937 }
8938
8939 int8_tArray AcceptChannel_1get_1temporary_1channel_1id(void* ctx_TODO, uint32_t this_ptr) {
8940         LDKAcceptChannel this_ptr_conv;
8941         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8942         this_ptr_conv.is_owned = false;
8943         int8_tArray ret_arr = { .len = 32, .ptr = MALLOC(32, "Native int8_tArray Bytes") };
8944         memcpy(ret_arr.ptr, *AcceptChannel_get_temporary_channel_id(&this_ptr_conv), 32);
8945         return ret_arr;
8946 }
8947
8948 void AcceptChannel_1set_1temporary_1channel_1id(void* ctx_TODO, uint32_t this_ptr, int8_tArray val) {
8949         LDKAcceptChannel this_ptr_conv;
8950         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8951         this_ptr_conv.is_owned = false;
8952         LDKThirtyTwoBytes val_ref;
8953         CHECK(val.len == 32);
8954         memcpy(val_ref.data, val.ptr, 32);
8955         AcceptChannel_set_temporary_channel_id(&this_ptr_conv, val_ref);
8956 }
8957
8958 int64_t AcceptChannel_1get_1dust_1limit_1satoshis(void* ctx_TODO, uint32_t this_ptr) {
8959         LDKAcceptChannel this_ptr_conv;
8960         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8961         this_ptr_conv.is_owned = false;
8962         int64_t ret_val = AcceptChannel_get_dust_limit_satoshis(&this_ptr_conv);
8963         return ret_val;
8964 }
8965
8966 void AcceptChannel_1set_1dust_1limit_1satoshis(void* ctx_TODO, uint32_t this_ptr, int64_t val) {
8967         LDKAcceptChannel this_ptr_conv;
8968         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8969         this_ptr_conv.is_owned = false;
8970         AcceptChannel_set_dust_limit_satoshis(&this_ptr_conv, val);
8971 }
8972
8973 int64_t AcceptChannel_1get_1max_1htlc_1value_1in_1flight_1msat(void* ctx_TODO, uint32_t this_ptr) {
8974         LDKAcceptChannel this_ptr_conv;
8975         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8976         this_ptr_conv.is_owned = false;
8977         int64_t ret_val = AcceptChannel_get_max_htlc_value_in_flight_msat(&this_ptr_conv);
8978         return ret_val;
8979 }
8980
8981 void AcceptChannel_1set_1max_1htlc_1value_1in_1flight_1msat(void* ctx_TODO, uint32_t this_ptr, int64_t val) {
8982         LDKAcceptChannel this_ptr_conv;
8983         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8984         this_ptr_conv.is_owned = false;
8985         AcceptChannel_set_max_htlc_value_in_flight_msat(&this_ptr_conv, val);
8986 }
8987
8988 int64_t AcceptChannel_1get_1channel_1reserve_1satoshis(void* ctx_TODO, uint32_t this_ptr) {
8989         LDKAcceptChannel this_ptr_conv;
8990         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8991         this_ptr_conv.is_owned = false;
8992         int64_t ret_val = AcceptChannel_get_channel_reserve_satoshis(&this_ptr_conv);
8993         return ret_val;
8994 }
8995
8996 void AcceptChannel_1set_1channel_1reserve_1satoshis(void* ctx_TODO, uint32_t this_ptr, int64_t val) {
8997         LDKAcceptChannel this_ptr_conv;
8998         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8999         this_ptr_conv.is_owned = false;
9000         AcceptChannel_set_channel_reserve_satoshis(&this_ptr_conv, val);
9001 }
9002
9003 int64_t AcceptChannel_1get_1htlc_1minimum_1msat(void* ctx_TODO, uint32_t this_ptr) {
9004         LDKAcceptChannel this_ptr_conv;
9005         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9006         this_ptr_conv.is_owned = false;
9007         int64_t ret_val = AcceptChannel_get_htlc_minimum_msat(&this_ptr_conv);
9008         return ret_val;
9009 }
9010
9011 void AcceptChannel_1set_1htlc_1minimum_1msat(void* ctx_TODO, uint32_t this_ptr, int64_t val) {
9012         LDKAcceptChannel this_ptr_conv;
9013         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9014         this_ptr_conv.is_owned = false;
9015         AcceptChannel_set_htlc_minimum_msat(&this_ptr_conv, val);
9016 }
9017
9018 int32_t AcceptChannel_1get_1minimum_1depth(void* ctx_TODO, uint32_t this_ptr) {
9019         LDKAcceptChannel this_ptr_conv;
9020         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9021         this_ptr_conv.is_owned = false;
9022         int32_t ret_val = AcceptChannel_get_minimum_depth(&this_ptr_conv);
9023         return ret_val;
9024 }
9025
9026 void AcceptChannel_1set_1minimum_1depth(void* ctx_TODO, uint32_t this_ptr, int32_t val) {
9027         LDKAcceptChannel this_ptr_conv;
9028         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9029         this_ptr_conv.is_owned = false;
9030         AcceptChannel_set_minimum_depth(&this_ptr_conv, val);
9031 }
9032
9033 int16_t AcceptChannel_1get_1to_1self_1delay(void* ctx_TODO, uint32_t this_ptr) {
9034         LDKAcceptChannel this_ptr_conv;
9035         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9036         this_ptr_conv.is_owned = false;
9037         int16_t ret_val = AcceptChannel_get_to_self_delay(&this_ptr_conv);
9038         return ret_val;
9039 }
9040
9041 void AcceptChannel_1set_1to_1self_1delay(void* ctx_TODO, uint32_t this_ptr, int16_t val) {
9042         LDKAcceptChannel this_ptr_conv;
9043         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9044         this_ptr_conv.is_owned = false;
9045         AcceptChannel_set_to_self_delay(&this_ptr_conv, val);
9046 }
9047
9048 int16_t AcceptChannel_1get_1max_1accepted_1htlcs(void* ctx_TODO, uint32_t this_ptr) {
9049         LDKAcceptChannel this_ptr_conv;
9050         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9051         this_ptr_conv.is_owned = false;
9052         int16_t ret_val = AcceptChannel_get_max_accepted_htlcs(&this_ptr_conv);
9053         return ret_val;
9054 }
9055
9056 void AcceptChannel_1set_1max_1accepted_1htlcs(void* ctx_TODO, uint32_t this_ptr, int16_t val) {
9057         LDKAcceptChannel this_ptr_conv;
9058         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9059         this_ptr_conv.is_owned = false;
9060         AcceptChannel_set_max_accepted_htlcs(&this_ptr_conv, val);
9061 }
9062
9063 int8_tArray AcceptChannel_1get_1funding_1pubkey(void* ctx_TODO, uint32_t this_ptr) {
9064         LDKAcceptChannel this_ptr_conv;
9065         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9066         this_ptr_conv.is_owned = false;
9067         int8_tArray arg_arr = { .len = 33, .ptr = MALLOC(33, "Native int8_tArray Bytes") };
9068         memcpy(arg_arr.ptr, AcceptChannel_get_funding_pubkey(&this_ptr_conv).compressed_form, 33);
9069         return arg_arr;
9070 }
9071
9072 void AcceptChannel_1set_1funding_1pubkey(void* ctx_TODO, uint32_t this_ptr, int8_tArray val) {
9073         LDKAcceptChannel this_ptr_conv;
9074         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9075         this_ptr_conv.is_owned = false;
9076         LDKPublicKey val_ref;
9077         CHECK(val.len == 33);
9078         memcpy(val_ref.compressed_form, val.ptr, 33);
9079         AcceptChannel_set_funding_pubkey(&this_ptr_conv, val_ref);
9080 }
9081
9082 int8_tArray AcceptChannel_1get_1revocation_1basepoint(void* ctx_TODO, uint32_t this_ptr) {
9083         LDKAcceptChannel this_ptr_conv;
9084         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9085         this_ptr_conv.is_owned = false;
9086         int8_tArray arg_arr = { .len = 33, .ptr = MALLOC(33, "Native int8_tArray Bytes") };
9087         memcpy(arg_arr.ptr, AcceptChannel_get_revocation_basepoint(&this_ptr_conv).compressed_form, 33);
9088         return arg_arr;
9089 }
9090
9091 void AcceptChannel_1set_1revocation_1basepoint(void* ctx_TODO, uint32_t this_ptr, int8_tArray val) {
9092         LDKAcceptChannel this_ptr_conv;
9093         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9094         this_ptr_conv.is_owned = false;
9095         LDKPublicKey val_ref;
9096         CHECK(val.len == 33);
9097         memcpy(val_ref.compressed_form, val.ptr, 33);
9098         AcceptChannel_set_revocation_basepoint(&this_ptr_conv, val_ref);
9099 }
9100
9101 int8_tArray AcceptChannel_1get_1payment_1point(void* ctx_TODO, uint32_t this_ptr) {
9102         LDKAcceptChannel this_ptr_conv;
9103         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9104         this_ptr_conv.is_owned = false;
9105         int8_tArray arg_arr = { .len = 33, .ptr = MALLOC(33, "Native int8_tArray Bytes") };
9106         memcpy(arg_arr.ptr, AcceptChannel_get_payment_point(&this_ptr_conv).compressed_form, 33);
9107         return arg_arr;
9108 }
9109
9110 void AcceptChannel_1set_1payment_1point(void* ctx_TODO, uint32_t this_ptr, int8_tArray val) {
9111         LDKAcceptChannel this_ptr_conv;
9112         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9113         this_ptr_conv.is_owned = false;
9114         LDKPublicKey val_ref;
9115         CHECK(val.len == 33);
9116         memcpy(val_ref.compressed_form, val.ptr, 33);
9117         AcceptChannel_set_payment_point(&this_ptr_conv, val_ref);
9118 }
9119
9120 int8_tArray AcceptChannel_1get_1delayed_1payment_1basepoint(void* ctx_TODO, uint32_t this_ptr) {
9121         LDKAcceptChannel this_ptr_conv;
9122         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9123         this_ptr_conv.is_owned = false;
9124         int8_tArray arg_arr = { .len = 33, .ptr = MALLOC(33, "Native int8_tArray Bytes") };
9125         memcpy(arg_arr.ptr, AcceptChannel_get_delayed_payment_basepoint(&this_ptr_conv).compressed_form, 33);
9126         return arg_arr;
9127 }
9128
9129 void AcceptChannel_1set_1delayed_1payment_1basepoint(void* ctx_TODO, uint32_t this_ptr, int8_tArray val) {
9130         LDKAcceptChannel this_ptr_conv;
9131         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9132         this_ptr_conv.is_owned = false;
9133         LDKPublicKey val_ref;
9134         CHECK(val.len == 33);
9135         memcpy(val_ref.compressed_form, val.ptr, 33);
9136         AcceptChannel_set_delayed_payment_basepoint(&this_ptr_conv, val_ref);
9137 }
9138
9139 int8_tArray AcceptChannel_1get_1htlc_1basepoint(void* ctx_TODO, uint32_t this_ptr) {
9140         LDKAcceptChannel this_ptr_conv;
9141         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9142         this_ptr_conv.is_owned = false;
9143         int8_tArray arg_arr = { .len = 33, .ptr = MALLOC(33, "Native int8_tArray Bytes") };
9144         memcpy(arg_arr.ptr, AcceptChannel_get_htlc_basepoint(&this_ptr_conv).compressed_form, 33);
9145         return arg_arr;
9146 }
9147
9148 void AcceptChannel_1set_1htlc_1basepoint(void* ctx_TODO, uint32_t this_ptr, int8_tArray val) {
9149         LDKAcceptChannel this_ptr_conv;
9150         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9151         this_ptr_conv.is_owned = false;
9152         LDKPublicKey val_ref;
9153         CHECK(val.len == 33);
9154         memcpy(val_ref.compressed_form, val.ptr, 33);
9155         AcceptChannel_set_htlc_basepoint(&this_ptr_conv, val_ref);
9156 }
9157
9158 int8_tArray AcceptChannel_1get_1first_1per_1commitment_1point(void* ctx_TODO, uint32_t this_ptr) {
9159         LDKAcceptChannel this_ptr_conv;
9160         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9161         this_ptr_conv.is_owned = false;
9162         int8_tArray arg_arr = { .len = 33, .ptr = MALLOC(33, "Native int8_tArray Bytes") };
9163         memcpy(arg_arr.ptr, AcceptChannel_get_first_per_commitment_point(&this_ptr_conv).compressed_form, 33);
9164         return arg_arr;
9165 }
9166
9167 void AcceptChannel_1set_1first_1per_1commitment_1point(void* ctx_TODO, uint32_t this_ptr, int8_tArray val) {
9168         LDKAcceptChannel this_ptr_conv;
9169         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9170         this_ptr_conv.is_owned = false;
9171         LDKPublicKey val_ref;
9172         CHECK(val.len == 33);
9173         memcpy(val_ref.compressed_form, val.ptr, 33);
9174         AcceptChannel_set_first_per_commitment_point(&this_ptr_conv, val_ref);
9175 }
9176
9177 void FundingCreated_1free(void* ctx_TODO, uint32_t this_ptr) {
9178         LDKFundingCreated this_ptr_conv;
9179         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9180         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9181         FundingCreated_free(this_ptr_conv);
9182 }
9183
9184 uint32_t FundingCreated_1clone(void* ctx_TODO, uint32_t orig) {
9185         LDKFundingCreated orig_conv;
9186         orig_conv.inner = (void*)(orig & (~1));
9187         orig_conv.is_owned = false;
9188         LDKFundingCreated ret_var = FundingCreated_clone(&orig_conv);
9189         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9190         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9191         long ret_ref = (long)ret_var.inner;
9192         if (ret_var.is_owned) {
9193                 ret_ref |= 1;
9194         }
9195         return ret_ref;
9196 }
9197
9198 int8_tArray FundingCreated_1get_1temporary_1channel_1id(void* ctx_TODO, uint32_t this_ptr) {
9199         LDKFundingCreated this_ptr_conv;
9200         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9201         this_ptr_conv.is_owned = false;
9202         int8_tArray ret_arr = { .len = 32, .ptr = MALLOC(32, "Native int8_tArray Bytes") };
9203         memcpy(ret_arr.ptr, *FundingCreated_get_temporary_channel_id(&this_ptr_conv), 32);
9204         return ret_arr;
9205 }
9206
9207 void FundingCreated_1set_1temporary_1channel_1id(void* ctx_TODO, uint32_t this_ptr, int8_tArray val) {
9208         LDKFundingCreated this_ptr_conv;
9209         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9210         this_ptr_conv.is_owned = false;
9211         LDKThirtyTwoBytes val_ref;
9212         CHECK(val.len == 32);
9213         memcpy(val_ref.data, val.ptr, 32);
9214         FundingCreated_set_temporary_channel_id(&this_ptr_conv, val_ref);
9215 }
9216
9217 int8_tArray FundingCreated_1get_1funding_1txid(void* ctx_TODO, uint32_t this_ptr) {
9218         LDKFundingCreated this_ptr_conv;
9219         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9220         this_ptr_conv.is_owned = false;
9221         int8_tArray ret_arr = { .len = 32, .ptr = MALLOC(32, "Native int8_tArray Bytes") };
9222         memcpy(ret_arr.ptr, *FundingCreated_get_funding_txid(&this_ptr_conv), 32);
9223         return ret_arr;
9224 }
9225
9226 void FundingCreated_1set_1funding_1txid(void* ctx_TODO, uint32_t this_ptr, int8_tArray val) {
9227         LDKFundingCreated this_ptr_conv;
9228         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9229         this_ptr_conv.is_owned = false;
9230         LDKThirtyTwoBytes val_ref;
9231         CHECK(val.len == 32);
9232         memcpy(val_ref.data, val.ptr, 32);
9233         FundingCreated_set_funding_txid(&this_ptr_conv, val_ref);
9234 }
9235
9236 int16_t FundingCreated_1get_1funding_1output_1index(void* ctx_TODO, uint32_t this_ptr) {
9237         LDKFundingCreated this_ptr_conv;
9238         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9239         this_ptr_conv.is_owned = false;
9240         int16_t ret_val = FundingCreated_get_funding_output_index(&this_ptr_conv);
9241         return ret_val;
9242 }
9243
9244 void FundingCreated_1set_1funding_1output_1index(void* ctx_TODO, uint32_t this_ptr, int16_t val) {
9245         LDKFundingCreated this_ptr_conv;
9246         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9247         this_ptr_conv.is_owned = false;
9248         FundingCreated_set_funding_output_index(&this_ptr_conv, val);
9249 }
9250
9251 int8_tArray FundingCreated_1get_1signature(void* ctx_TODO, uint32_t this_ptr) {
9252         LDKFundingCreated this_ptr_conv;
9253         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9254         this_ptr_conv.is_owned = false;
9255         int8_tArray arg_arr = { .len = 64, .ptr = MALLOC(64, "Native int8_tArray Bytes") };
9256         memcpy(arg_arr.ptr, FundingCreated_get_signature(&this_ptr_conv).compact_form, 64);
9257         return arg_arr;
9258 }
9259
9260 void FundingCreated_1set_1signature(void* ctx_TODO, uint32_t this_ptr, int8_tArray val) {
9261         LDKFundingCreated this_ptr_conv;
9262         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9263         this_ptr_conv.is_owned = false;
9264         LDKSignature val_ref;
9265         CHECK(val.len == 64);
9266         memcpy(val_ref.compact_form, val.ptr, 64);
9267         FundingCreated_set_signature(&this_ptr_conv, val_ref);
9268 }
9269
9270 uint32_t FundingCreated_1new(void* ctx_TODO, int8_tArray temporary_channel_id_arg, int8_tArray funding_txid_arg, int16_t funding_output_index_arg, int8_tArray signature_arg) {
9271         LDKThirtyTwoBytes temporary_channel_id_arg_ref;
9272         CHECK(temporary_channel_id_arg.len == 32);
9273         memcpy(temporary_channel_id_arg_ref.data, temporary_channel_id_arg.ptr, 32);
9274         LDKThirtyTwoBytes funding_txid_arg_ref;
9275         CHECK(funding_txid_arg.len == 32);
9276         memcpy(funding_txid_arg_ref.data, funding_txid_arg.ptr, 32);
9277         LDKSignature signature_arg_ref;
9278         CHECK(signature_arg.len == 64);
9279         memcpy(signature_arg_ref.compact_form, signature_arg.ptr, 64);
9280         LDKFundingCreated ret_var = FundingCreated_new(temporary_channel_id_arg_ref, funding_txid_arg_ref, funding_output_index_arg, signature_arg_ref);
9281         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9282         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9283         long ret_ref = (long)ret_var.inner;
9284         if (ret_var.is_owned) {
9285                 ret_ref |= 1;
9286         }
9287         return ret_ref;
9288 }
9289
9290 void FundingSigned_1free(void* ctx_TODO, uint32_t this_ptr) {
9291         LDKFundingSigned this_ptr_conv;
9292         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9293         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9294         FundingSigned_free(this_ptr_conv);
9295 }
9296
9297 uint32_t FundingSigned_1clone(void* ctx_TODO, uint32_t orig) {
9298         LDKFundingSigned orig_conv;
9299         orig_conv.inner = (void*)(orig & (~1));
9300         orig_conv.is_owned = false;
9301         LDKFundingSigned ret_var = FundingSigned_clone(&orig_conv);
9302         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9303         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9304         long ret_ref = (long)ret_var.inner;
9305         if (ret_var.is_owned) {
9306                 ret_ref |= 1;
9307         }
9308         return ret_ref;
9309 }
9310
9311 int8_tArray FundingSigned_1get_1channel_1id(void* ctx_TODO, uint32_t this_ptr) {
9312         LDKFundingSigned this_ptr_conv;
9313         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9314         this_ptr_conv.is_owned = false;
9315         int8_tArray ret_arr = { .len = 32, .ptr = MALLOC(32, "Native int8_tArray Bytes") };
9316         memcpy(ret_arr.ptr, *FundingSigned_get_channel_id(&this_ptr_conv), 32);
9317         return ret_arr;
9318 }
9319
9320 void FundingSigned_1set_1channel_1id(void* ctx_TODO, uint32_t this_ptr, int8_tArray val) {
9321         LDKFundingSigned this_ptr_conv;
9322         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9323         this_ptr_conv.is_owned = false;
9324         LDKThirtyTwoBytes val_ref;
9325         CHECK(val.len == 32);
9326         memcpy(val_ref.data, val.ptr, 32);
9327         FundingSigned_set_channel_id(&this_ptr_conv, val_ref);
9328 }
9329
9330 int8_tArray FundingSigned_1get_1signature(void* ctx_TODO, uint32_t this_ptr) {
9331         LDKFundingSigned this_ptr_conv;
9332         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9333         this_ptr_conv.is_owned = false;
9334         int8_tArray arg_arr = { .len = 64, .ptr = MALLOC(64, "Native int8_tArray Bytes") };
9335         memcpy(arg_arr.ptr, FundingSigned_get_signature(&this_ptr_conv).compact_form, 64);
9336         return arg_arr;
9337 }
9338
9339 void FundingSigned_1set_1signature(void* ctx_TODO, uint32_t this_ptr, int8_tArray val) {
9340         LDKFundingSigned this_ptr_conv;
9341         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9342         this_ptr_conv.is_owned = false;
9343         LDKSignature val_ref;
9344         CHECK(val.len == 64);
9345         memcpy(val_ref.compact_form, val.ptr, 64);
9346         FundingSigned_set_signature(&this_ptr_conv, val_ref);
9347 }
9348
9349 uint32_t FundingSigned_1new(void* ctx_TODO, int8_tArray channel_id_arg, int8_tArray signature_arg) {
9350         LDKThirtyTwoBytes channel_id_arg_ref;
9351         CHECK(channel_id_arg.len == 32);
9352         memcpy(channel_id_arg_ref.data, channel_id_arg.ptr, 32);
9353         LDKSignature signature_arg_ref;
9354         CHECK(signature_arg.len == 64);
9355         memcpy(signature_arg_ref.compact_form, signature_arg.ptr, 64);
9356         LDKFundingSigned ret_var = FundingSigned_new(channel_id_arg_ref, signature_arg_ref);
9357         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9358         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9359         long ret_ref = (long)ret_var.inner;
9360         if (ret_var.is_owned) {
9361                 ret_ref |= 1;
9362         }
9363         return ret_ref;
9364 }
9365
9366 void FundingLocked_1free(void* ctx_TODO, uint32_t this_ptr) {
9367         LDKFundingLocked this_ptr_conv;
9368         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9369         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9370         FundingLocked_free(this_ptr_conv);
9371 }
9372
9373 uint32_t FundingLocked_1clone(void* ctx_TODO, uint32_t orig) {
9374         LDKFundingLocked orig_conv;
9375         orig_conv.inner = (void*)(orig & (~1));
9376         orig_conv.is_owned = false;
9377         LDKFundingLocked ret_var = FundingLocked_clone(&orig_conv);
9378         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9379         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9380         long ret_ref = (long)ret_var.inner;
9381         if (ret_var.is_owned) {
9382                 ret_ref |= 1;
9383         }
9384         return ret_ref;
9385 }
9386
9387 int8_tArray FundingLocked_1get_1channel_1id(void* ctx_TODO, uint32_t this_ptr) {
9388         LDKFundingLocked this_ptr_conv;
9389         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9390         this_ptr_conv.is_owned = false;
9391         int8_tArray ret_arr = { .len = 32, .ptr = MALLOC(32, "Native int8_tArray Bytes") };
9392         memcpy(ret_arr.ptr, *FundingLocked_get_channel_id(&this_ptr_conv), 32);
9393         return ret_arr;
9394 }
9395
9396 void FundingLocked_1set_1channel_1id(void* ctx_TODO, uint32_t this_ptr, int8_tArray val) {
9397         LDKFundingLocked this_ptr_conv;
9398         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9399         this_ptr_conv.is_owned = false;
9400         LDKThirtyTwoBytes val_ref;
9401         CHECK(val.len == 32);
9402         memcpy(val_ref.data, val.ptr, 32);
9403         FundingLocked_set_channel_id(&this_ptr_conv, val_ref);
9404 }
9405
9406 int8_tArray FundingLocked_1get_1next_1per_1commitment_1point(void* ctx_TODO, uint32_t this_ptr) {
9407         LDKFundingLocked this_ptr_conv;
9408         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9409         this_ptr_conv.is_owned = false;
9410         int8_tArray arg_arr = { .len = 33, .ptr = MALLOC(33, "Native int8_tArray Bytes") };
9411         memcpy(arg_arr.ptr, FundingLocked_get_next_per_commitment_point(&this_ptr_conv).compressed_form, 33);
9412         return arg_arr;
9413 }
9414
9415 void FundingLocked_1set_1next_1per_1commitment_1point(void* ctx_TODO, uint32_t this_ptr, int8_tArray val) {
9416         LDKFundingLocked this_ptr_conv;
9417         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9418         this_ptr_conv.is_owned = false;
9419         LDKPublicKey val_ref;
9420         CHECK(val.len == 33);
9421         memcpy(val_ref.compressed_form, val.ptr, 33);
9422         FundingLocked_set_next_per_commitment_point(&this_ptr_conv, val_ref);
9423 }
9424
9425 uint32_t FundingLocked_1new(void* ctx_TODO, int8_tArray channel_id_arg, int8_tArray next_per_commitment_point_arg) {
9426         LDKThirtyTwoBytes channel_id_arg_ref;
9427         CHECK(channel_id_arg.len == 32);
9428         memcpy(channel_id_arg_ref.data, channel_id_arg.ptr, 32);
9429         LDKPublicKey next_per_commitment_point_arg_ref;
9430         CHECK(next_per_commitment_point_arg.len == 33);
9431         memcpy(next_per_commitment_point_arg_ref.compressed_form, next_per_commitment_point_arg.ptr, 33);
9432         LDKFundingLocked ret_var = FundingLocked_new(channel_id_arg_ref, next_per_commitment_point_arg_ref);
9433         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9434         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9435         long ret_ref = (long)ret_var.inner;
9436         if (ret_var.is_owned) {
9437                 ret_ref |= 1;
9438         }
9439         return ret_ref;
9440 }
9441
9442 void Shutdown_1free(void* ctx_TODO, uint32_t this_ptr) {
9443         LDKShutdown this_ptr_conv;
9444         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9445         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9446         Shutdown_free(this_ptr_conv);
9447 }
9448
9449 uint32_t Shutdown_1clone(void* ctx_TODO, uint32_t orig) {
9450         LDKShutdown orig_conv;
9451         orig_conv.inner = (void*)(orig & (~1));
9452         orig_conv.is_owned = false;
9453         LDKShutdown ret_var = Shutdown_clone(&orig_conv);
9454         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9455         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9456         long ret_ref = (long)ret_var.inner;
9457         if (ret_var.is_owned) {
9458                 ret_ref |= 1;
9459         }
9460         return ret_ref;
9461 }
9462
9463 int8_tArray Shutdown_1get_1channel_1id(void* ctx_TODO, uint32_t this_ptr) {
9464         LDKShutdown this_ptr_conv;
9465         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9466         this_ptr_conv.is_owned = false;
9467         int8_tArray ret_arr = { .len = 32, .ptr = MALLOC(32, "Native int8_tArray Bytes") };
9468         memcpy(ret_arr.ptr, *Shutdown_get_channel_id(&this_ptr_conv), 32);
9469         return ret_arr;
9470 }
9471
9472 void Shutdown_1set_1channel_1id(void* ctx_TODO, uint32_t this_ptr, int8_tArray val) {
9473         LDKShutdown this_ptr_conv;
9474         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9475         this_ptr_conv.is_owned = false;
9476         LDKThirtyTwoBytes val_ref;
9477         CHECK(val.len == 32);
9478         memcpy(val_ref.data, val.ptr, 32);
9479         Shutdown_set_channel_id(&this_ptr_conv, val_ref);
9480 }
9481
9482 int8_tArray Shutdown_1get_1scriptpubkey(void* ctx_TODO, uint32_t this_ptr) {
9483         LDKShutdown this_ptr_conv;
9484         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9485         this_ptr_conv.is_owned = false;
9486         LDKu8slice arg_var = Shutdown_get_scriptpubkey(&this_ptr_conv);
9487         int8_tArray arg_arr = { .len = arg_var.datalen, .ptr = MALLOC(arg_var.datalen, "Native int8_tArray Bytes") };
9488         memcpy(arg_arr.ptr, arg_var.data, arg_var.datalen);
9489         return arg_arr;
9490 }
9491
9492 void Shutdown_1set_1scriptpubkey(void* ctx_TODO, uint32_t this_ptr, int8_tArray val) {
9493         LDKShutdown this_ptr_conv;
9494         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9495         this_ptr_conv.is_owned = false;
9496         LDKCVec_u8Z val_ref;
9497         val_ref.datalen = val.len;
9498         val_ref.data = MALLOC(val_ref.datalen, "LDKCVec_u8Z Bytes");
9499         memcpy(val_ref.data, val.ptr, val_ref.datalen);
9500         Shutdown_set_scriptpubkey(&this_ptr_conv, val_ref);
9501 }
9502
9503 uint32_t Shutdown_1new(void* ctx_TODO, int8_tArray channel_id_arg, int8_tArray scriptpubkey_arg) {
9504         LDKThirtyTwoBytes channel_id_arg_ref;
9505         CHECK(channel_id_arg.len == 32);
9506         memcpy(channel_id_arg_ref.data, channel_id_arg.ptr, 32);
9507         LDKCVec_u8Z scriptpubkey_arg_ref;
9508         scriptpubkey_arg_ref.datalen = scriptpubkey_arg.len;
9509         scriptpubkey_arg_ref.data = MALLOC(scriptpubkey_arg_ref.datalen, "LDKCVec_u8Z Bytes");
9510         memcpy(scriptpubkey_arg_ref.data, scriptpubkey_arg.ptr, scriptpubkey_arg_ref.datalen);
9511         LDKShutdown ret_var = Shutdown_new(channel_id_arg_ref, scriptpubkey_arg_ref);
9512         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9513         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9514         long ret_ref = (long)ret_var.inner;
9515         if (ret_var.is_owned) {
9516                 ret_ref |= 1;
9517         }
9518         return ret_ref;
9519 }
9520
9521 void ClosingSigned_1free(void* ctx_TODO, uint32_t this_ptr) {
9522         LDKClosingSigned this_ptr_conv;
9523         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9524         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9525         ClosingSigned_free(this_ptr_conv);
9526 }
9527
9528 uint32_t ClosingSigned_1clone(void* ctx_TODO, uint32_t orig) {
9529         LDKClosingSigned orig_conv;
9530         orig_conv.inner = (void*)(orig & (~1));
9531         orig_conv.is_owned = false;
9532         LDKClosingSigned ret_var = ClosingSigned_clone(&orig_conv);
9533         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9534         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9535         long ret_ref = (long)ret_var.inner;
9536         if (ret_var.is_owned) {
9537                 ret_ref |= 1;
9538         }
9539         return ret_ref;
9540 }
9541
9542 int8_tArray ClosingSigned_1get_1channel_1id(void* ctx_TODO, uint32_t this_ptr) {
9543         LDKClosingSigned this_ptr_conv;
9544         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9545         this_ptr_conv.is_owned = false;
9546         int8_tArray ret_arr = { .len = 32, .ptr = MALLOC(32, "Native int8_tArray Bytes") };
9547         memcpy(ret_arr.ptr, *ClosingSigned_get_channel_id(&this_ptr_conv), 32);
9548         return ret_arr;
9549 }
9550
9551 void ClosingSigned_1set_1channel_1id(void* ctx_TODO, uint32_t this_ptr, int8_tArray val) {
9552         LDKClosingSigned this_ptr_conv;
9553         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9554         this_ptr_conv.is_owned = false;
9555         LDKThirtyTwoBytes val_ref;
9556         CHECK(val.len == 32);
9557         memcpy(val_ref.data, val.ptr, 32);
9558         ClosingSigned_set_channel_id(&this_ptr_conv, val_ref);
9559 }
9560
9561 int64_t ClosingSigned_1get_1fee_1satoshis(void* ctx_TODO, uint32_t this_ptr) {
9562         LDKClosingSigned this_ptr_conv;
9563         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9564         this_ptr_conv.is_owned = false;
9565         int64_t ret_val = ClosingSigned_get_fee_satoshis(&this_ptr_conv);
9566         return ret_val;
9567 }
9568
9569 void ClosingSigned_1set_1fee_1satoshis(void* ctx_TODO, uint32_t this_ptr, int64_t val) {
9570         LDKClosingSigned this_ptr_conv;
9571         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9572         this_ptr_conv.is_owned = false;
9573         ClosingSigned_set_fee_satoshis(&this_ptr_conv, val);
9574 }
9575
9576 int8_tArray ClosingSigned_1get_1signature(void* ctx_TODO, uint32_t this_ptr) {
9577         LDKClosingSigned this_ptr_conv;
9578         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9579         this_ptr_conv.is_owned = false;
9580         int8_tArray arg_arr = { .len = 64, .ptr = MALLOC(64, "Native int8_tArray Bytes") };
9581         memcpy(arg_arr.ptr, ClosingSigned_get_signature(&this_ptr_conv).compact_form, 64);
9582         return arg_arr;
9583 }
9584
9585 void ClosingSigned_1set_1signature(void* ctx_TODO, uint32_t this_ptr, int8_tArray val) {
9586         LDKClosingSigned this_ptr_conv;
9587         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9588         this_ptr_conv.is_owned = false;
9589         LDKSignature val_ref;
9590         CHECK(val.len == 64);
9591         memcpy(val_ref.compact_form, val.ptr, 64);
9592         ClosingSigned_set_signature(&this_ptr_conv, val_ref);
9593 }
9594
9595 uint32_t ClosingSigned_1new(void* ctx_TODO, int8_tArray channel_id_arg, int64_t fee_satoshis_arg, int8_tArray signature_arg) {
9596         LDKThirtyTwoBytes channel_id_arg_ref;
9597         CHECK(channel_id_arg.len == 32);
9598         memcpy(channel_id_arg_ref.data, channel_id_arg.ptr, 32);
9599         LDKSignature signature_arg_ref;
9600         CHECK(signature_arg.len == 64);
9601         memcpy(signature_arg_ref.compact_form, signature_arg.ptr, 64);
9602         LDKClosingSigned ret_var = ClosingSigned_new(channel_id_arg_ref, fee_satoshis_arg, signature_arg_ref);
9603         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9604         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9605         long ret_ref = (long)ret_var.inner;
9606         if (ret_var.is_owned) {
9607                 ret_ref |= 1;
9608         }
9609         return ret_ref;
9610 }
9611
9612 void UpdateAddHTLC_1free(void* ctx_TODO, uint32_t this_ptr) {
9613         LDKUpdateAddHTLC this_ptr_conv;
9614         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9615         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9616         UpdateAddHTLC_free(this_ptr_conv);
9617 }
9618
9619 uint32_t UpdateAddHTLC_1clone(void* ctx_TODO, uint32_t orig) {
9620         LDKUpdateAddHTLC orig_conv;
9621         orig_conv.inner = (void*)(orig & (~1));
9622         orig_conv.is_owned = false;
9623         LDKUpdateAddHTLC ret_var = UpdateAddHTLC_clone(&orig_conv);
9624         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9625         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9626         long ret_ref = (long)ret_var.inner;
9627         if (ret_var.is_owned) {
9628                 ret_ref |= 1;
9629         }
9630         return ret_ref;
9631 }
9632
9633 int8_tArray UpdateAddHTLC_1get_1channel_1id(void* ctx_TODO, uint32_t this_ptr) {
9634         LDKUpdateAddHTLC this_ptr_conv;
9635         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9636         this_ptr_conv.is_owned = false;
9637         int8_tArray ret_arr = { .len = 32, .ptr = MALLOC(32, "Native int8_tArray Bytes") };
9638         memcpy(ret_arr.ptr, *UpdateAddHTLC_get_channel_id(&this_ptr_conv), 32);
9639         return ret_arr;
9640 }
9641
9642 void UpdateAddHTLC_1set_1channel_1id(void* ctx_TODO, uint32_t this_ptr, int8_tArray val) {
9643         LDKUpdateAddHTLC this_ptr_conv;
9644         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9645         this_ptr_conv.is_owned = false;
9646         LDKThirtyTwoBytes val_ref;
9647         CHECK(val.len == 32);
9648         memcpy(val_ref.data, val.ptr, 32);
9649         UpdateAddHTLC_set_channel_id(&this_ptr_conv, val_ref);
9650 }
9651
9652 int64_t UpdateAddHTLC_1get_1htlc_1id(void* ctx_TODO, uint32_t this_ptr) {
9653         LDKUpdateAddHTLC this_ptr_conv;
9654         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9655         this_ptr_conv.is_owned = false;
9656         int64_t ret_val = UpdateAddHTLC_get_htlc_id(&this_ptr_conv);
9657         return ret_val;
9658 }
9659
9660 void UpdateAddHTLC_1set_1htlc_1id(void* ctx_TODO, uint32_t this_ptr, int64_t val) {
9661         LDKUpdateAddHTLC this_ptr_conv;
9662         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9663         this_ptr_conv.is_owned = false;
9664         UpdateAddHTLC_set_htlc_id(&this_ptr_conv, val);
9665 }
9666
9667 int64_t UpdateAddHTLC_1get_1amount_1msat(void* ctx_TODO, uint32_t this_ptr) {
9668         LDKUpdateAddHTLC this_ptr_conv;
9669         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9670         this_ptr_conv.is_owned = false;
9671         int64_t ret_val = UpdateAddHTLC_get_amount_msat(&this_ptr_conv);
9672         return ret_val;
9673 }
9674
9675 void UpdateAddHTLC_1set_1amount_1msat(void* ctx_TODO, uint32_t this_ptr, int64_t val) {
9676         LDKUpdateAddHTLC this_ptr_conv;
9677         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9678         this_ptr_conv.is_owned = false;
9679         UpdateAddHTLC_set_amount_msat(&this_ptr_conv, val);
9680 }
9681
9682 int8_tArray UpdateAddHTLC_1get_1payment_1hash(void* ctx_TODO, uint32_t this_ptr) {
9683         LDKUpdateAddHTLC this_ptr_conv;
9684         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9685         this_ptr_conv.is_owned = false;
9686         int8_tArray ret_arr = { .len = 32, .ptr = MALLOC(32, "Native int8_tArray Bytes") };
9687         memcpy(ret_arr.ptr, *UpdateAddHTLC_get_payment_hash(&this_ptr_conv), 32);
9688         return ret_arr;
9689 }
9690
9691 void UpdateAddHTLC_1set_1payment_1hash(void* ctx_TODO, uint32_t this_ptr, int8_tArray val) {
9692         LDKUpdateAddHTLC this_ptr_conv;
9693         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9694         this_ptr_conv.is_owned = false;
9695         LDKThirtyTwoBytes val_ref;
9696         CHECK(val.len == 32);
9697         memcpy(val_ref.data, val.ptr, 32);
9698         UpdateAddHTLC_set_payment_hash(&this_ptr_conv, val_ref);
9699 }
9700
9701 int32_t UpdateAddHTLC_1get_1cltv_1expiry(void* ctx_TODO, uint32_t this_ptr) {
9702         LDKUpdateAddHTLC this_ptr_conv;
9703         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9704         this_ptr_conv.is_owned = false;
9705         int32_t ret_val = UpdateAddHTLC_get_cltv_expiry(&this_ptr_conv);
9706         return ret_val;
9707 }
9708
9709 void UpdateAddHTLC_1set_1cltv_1expiry(void* ctx_TODO, uint32_t this_ptr, int32_t val) {
9710         LDKUpdateAddHTLC this_ptr_conv;
9711         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9712         this_ptr_conv.is_owned = false;
9713         UpdateAddHTLC_set_cltv_expiry(&this_ptr_conv, val);
9714 }
9715
9716 void UpdateFulfillHTLC_1free(void* ctx_TODO, uint32_t this_ptr) {
9717         LDKUpdateFulfillHTLC this_ptr_conv;
9718         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9719         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9720         UpdateFulfillHTLC_free(this_ptr_conv);
9721 }
9722
9723 uint32_t UpdateFulfillHTLC_1clone(void* ctx_TODO, uint32_t orig) {
9724         LDKUpdateFulfillHTLC orig_conv;
9725         orig_conv.inner = (void*)(orig & (~1));
9726         orig_conv.is_owned = false;
9727         LDKUpdateFulfillHTLC ret_var = UpdateFulfillHTLC_clone(&orig_conv);
9728         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9729         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9730         long ret_ref = (long)ret_var.inner;
9731         if (ret_var.is_owned) {
9732                 ret_ref |= 1;
9733         }
9734         return ret_ref;
9735 }
9736
9737 int8_tArray UpdateFulfillHTLC_1get_1channel_1id(void* ctx_TODO, uint32_t this_ptr) {
9738         LDKUpdateFulfillHTLC this_ptr_conv;
9739         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9740         this_ptr_conv.is_owned = false;
9741         int8_tArray ret_arr = { .len = 32, .ptr = MALLOC(32, "Native int8_tArray Bytes") };
9742         memcpy(ret_arr.ptr, *UpdateFulfillHTLC_get_channel_id(&this_ptr_conv), 32);
9743         return ret_arr;
9744 }
9745
9746 void UpdateFulfillHTLC_1set_1channel_1id(void* ctx_TODO, uint32_t this_ptr, int8_tArray val) {
9747         LDKUpdateFulfillHTLC this_ptr_conv;
9748         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9749         this_ptr_conv.is_owned = false;
9750         LDKThirtyTwoBytes val_ref;
9751         CHECK(val.len == 32);
9752         memcpy(val_ref.data, val.ptr, 32);
9753         UpdateFulfillHTLC_set_channel_id(&this_ptr_conv, val_ref);
9754 }
9755
9756 int64_t UpdateFulfillHTLC_1get_1htlc_1id(void* ctx_TODO, uint32_t this_ptr) {
9757         LDKUpdateFulfillHTLC this_ptr_conv;
9758         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9759         this_ptr_conv.is_owned = false;
9760         int64_t ret_val = UpdateFulfillHTLC_get_htlc_id(&this_ptr_conv);
9761         return ret_val;
9762 }
9763
9764 void UpdateFulfillHTLC_1set_1htlc_1id(void* ctx_TODO, uint32_t this_ptr, int64_t val) {
9765         LDKUpdateFulfillHTLC this_ptr_conv;
9766         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9767         this_ptr_conv.is_owned = false;
9768         UpdateFulfillHTLC_set_htlc_id(&this_ptr_conv, val);
9769 }
9770
9771 int8_tArray UpdateFulfillHTLC_1get_1payment_1preimage(void* ctx_TODO, uint32_t this_ptr) {
9772         LDKUpdateFulfillHTLC this_ptr_conv;
9773         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9774         this_ptr_conv.is_owned = false;
9775         int8_tArray ret_arr = { .len = 32, .ptr = MALLOC(32, "Native int8_tArray Bytes") };
9776         memcpy(ret_arr.ptr, *UpdateFulfillHTLC_get_payment_preimage(&this_ptr_conv), 32);
9777         return ret_arr;
9778 }
9779
9780 void UpdateFulfillHTLC_1set_1payment_1preimage(void* ctx_TODO, uint32_t this_ptr, int8_tArray val) {
9781         LDKUpdateFulfillHTLC this_ptr_conv;
9782         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9783         this_ptr_conv.is_owned = false;
9784         LDKThirtyTwoBytes val_ref;
9785         CHECK(val.len == 32);
9786         memcpy(val_ref.data, val.ptr, 32);
9787         UpdateFulfillHTLC_set_payment_preimage(&this_ptr_conv, val_ref);
9788 }
9789
9790 uint32_t UpdateFulfillHTLC_1new(void* ctx_TODO, int8_tArray channel_id_arg, int64_t htlc_id_arg, int8_tArray payment_preimage_arg) {
9791         LDKThirtyTwoBytes channel_id_arg_ref;
9792         CHECK(channel_id_arg.len == 32);
9793         memcpy(channel_id_arg_ref.data, channel_id_arg.ptr, 32);
9794         LDKThirtyTwoBytes payment_preimage_arg_ref;
9795         CHECK(payment_preimage_arg.len == 32);
9796         memcpy(payment_preimage_arg_ref.data, payment_preimage_arg.ptr, 32);
9797         LDKUpdateFulfillHTLC ret_var = UpdateFulfillHTLC_new(channel_id_arg_ref, htlc_id_arg, payment_preimage_arg_ref);
9798         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9799         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9800         long ret_ref = (long)ret_var.inner;
9801         if (ret_var.is_owned) {
9802                 ret_ref |= 1;
9803         }
9804         return ret_ref;
9805 }
9806
9807 void UpdateFailHTLC_1free(void* ctx_TODO, uint32_t this_ptr) {
9808         LDKUpdateFailHTLC this_ptr_conv;
9809         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9810         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9811         UpdateFailHTLC_free(this_ptr_conv);
9812 }
9813
9814 uint32_t UpdateFailHTLC_1clone(void* ctx_TODO, uint32_t orig) {
9815         LDKUpdateFailHTLC orig_conv;
9816         orig_conv.inner = (void*)(orig & (~1));
9817         orig_conv.is_owned = false;
9818         LDKUpdateFailHTLC ret_var = UpdateFailHTLC_clone(&orig_conv);
9819         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9820         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9821         long ret_ref = (long)ret_var.inner;
9822         if (ret_var.is_owned) {
9823                 ret_ref |= 1;
9824         }
9825         return ret_ref;
9826 }
9827
9828 int8_tArray UpdateFailHTLC_1get_1channel_1id(void* ctx_TODO, uint32_t this_ptr) {
9829         LDKUpdateFailHTLC this_ptr_conv;
9830         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9831         this_ptr_conv.is_owned = false;
9832         int8_tArray ret_arr = { .len = 32, .ptr = MALLOC(32, "Native int8_tArray Bytes") };
9833         memcpy(ret_arr.ptr, *UpdateFailHTLC_get_channel_id(&this_ptr_conv), 32);
9834         return ret_arr;
9835 }
9836
9837 void UpdateFailHTLC_1set_1channel_1id(void* ctx_TODO, uint32_t this_ptr, int8_tArray val) {
9838         LDKUpdateFailHTLC this_ptr_conv;
9839         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9840         this_ptr_conv.is_owned = false;
9841         LDKThirtyTwoBytes val_ref;
9842         CHECK(val.len == 32);
9843         memcpy(val_ref.data, val.ptr, 32);
9844         UpdateFailHTLC_set_channel_id(&this_ptr_conv, val_ref);
9845 }
9846
9847 int64_t UpdateFailHTLC_1get_1htlc_1id(void* ctx_TODO, uint32_t this_ptr) {
9848         LDKUpdateFailHTLC this_ptr_conv;
9849         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9850         this_ptr_conv.is_owned = false;
9851         int64_t ret_val = UpdateFailHTLC_get_htlc_id(&this_ptr_conv);
9852         return ret_val;
9853 }
9854
9855 void UpdateFailHTLC_1set_1htlc_1id(void* ctx_TODO, uint32_t this_ptr, int64_t val) {
9856         LDKUpdateFailHTLC this_ptr_conv;
9857         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9858         this_ptr_conv.is_owned = false;
9859         UpdateFailHTLC_set_htlc_id(&this_ptr_conv, val);
9860 }
9861
9862 void UpdateFailMalformedHTLC_1free(void* ctx_TODO, uint32_t this_ptr) {
9863         LDKUpdateFailMalformedHTLC this_ptr_conv;
9864         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9865         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9866         UpdateFailMalformedHTLC_free(this_ptr_conv);
9867 }
9868
9869 uint32_t UpdateFailMalformedHTLC_1clone(void* ctx_TODO, uint32_t orig) {
9870         LDKUpdateFailMalformedHTLC orig_conv;
9871         orig_conv.inner = (void*)(orig & (~1));
9872         orig_conv.is_owned = false;
9873         LDKUpdateFailMalformedHTLC ret_var = UpdateFailMalformedHTLC_clone(&orig_conv);
9874         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9875         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9876         long ret_ref = (long)ret_var.inner;
9877         if (ret_var.is_owned) {
9878                 ret_ref |= 1;
9879         }
9880         return ret_ref;
9881 }
9882
9883 int8_tArray UpdateFailMalformedHTLC_1get_1channel_1id(void* ctx_TODO, uint32_t this_ptr) {
9884         LDKUpdateFailMalformedHTLC this_ptr_conv;
9885         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9886         this_ptr_conv.is_owned = false;
9887         int8_tArray ret_arr = { .len = 32, .ptr = MALLOC(32, "Native int8_tArray Bytes") };
9888         memcpy(ret_arr.ptr, *UpdateFailMalformedHTLC_get_channel_id(&this_ptr_conv), 32);
9889         return ret_arr;
9890 }
9891
9892 void UpdateFailMalformedHTLC_1set_1channel_1id(void* ctx_TODO, uint32_t this_ptr, int8_tArray val) {
9893         LDKUpdateFailMalformedHTLC this_ptr_conv;
9894         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9895         this_ptr_conv.is_owned = false;
9896         LDKThirtyTwoBytes val_ref;
9897         CHECK(val.len == 32);
9898         memcpy(val_ref.data, val.ptr, 32);
9899         UpdateFailMalformedHTLC_set_channel_id(&this_ptr_conv, val_ref);
9900 }
9901
9902 int64_t UpdateFailMalformedHTLC_1get_1htlc_1id(void* ctx_TODO, uint32_t this_ptr) {
9903         LDKUpdateFailMalformedHTLC this_ptr_conv;
9904         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9905         this_ptr_conv.is_owned = false;
9906         int64_t ret_val = UpdateFailMalformedHTLC_get_htlc_id(&this_ptr_conv);
9907         return ret_val;
9908 }
9909
9910 void UpdateFailMalformedHTLC_1set_1htlc_1id(void* ctx_TODO, uint32_t this_ptr, int64_t val) {
9911         LDKUpdateFailMalformedHTLC this_ptr_conv;
9912         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9913         this_ptr_conv.is_owned = false;
9914         UpdateFailMalformedHTLC_set_htlc_id(&this_ptr_conv, val);
9915 }
9916
9917 int16_t UpdateFailMalformedHTLC_1get_1failure_1code(void* ctx_TODO, uint32_t this_ptr) {
9918         LDKUpdateFailMalformedHTLC this_ptr_conv;
9919         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9920         this_ptr_conv.is_owned = false;
9921         int16_t ret_val = UpdateFailMalformedHTLC_get_failure_code(&this_ptr_conv);
9922         return ret_val;
9923 }
9924
9925 void UpdateFailMalformedHTLC_1set_1failure_1code(void* ctx_TODO, uint32_t this_ptr, int16_t val) {
9926         LDKUpdateFailMalformedHTLC this_ptr_conv;
9927         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9928         this_ptr_conv.is_owned = false;
9929         UpdateFailMalformedHTLC_set_failure_code(&this_ptr_conv, val);
9930 }
9931
9932 void CommitmentSigned_1free(void* ctx_TODO, uint32_t this_ptr) {
9933         LDKCommitmentSigned this_ptr_conv;
9934         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9935         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9936         CommitmentSigned_free(this_ptr_conv);
9937 }
9938
9939 uint32_t CommitmentSigned_1clone(void* ctx_TODO, uint32_t orig) {
9940         LDKCommitmentSigned orig_conv;
9941         orig_conv.inner = (void*)(orig & (~1));
9942         orig_conv.is_owned = false;
9943         LDKCommitmentSigned ret_var = CommitmentSigned_clone(&orig_conv);
9944         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9945         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9946         long ret_ref = (long)ret_var.inner;
9947         if (ret_var.is_owned) {
9948                 ret_ref |= 1;
9949         }
9950         return ret_ref;
9951 }
9952
9953 int8_tArray CommitmentSigned_1get_1channel_1id(void* ctx_TODO, uint32_t this_ptr) {
9954         LDKCommitmentSigned this_ptr_conv;
9955         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9956         this_ptr_conv.is_owned = false;
9957         int8_tArray ret_arr = { .len = 32, .ptr = MALLOC(32, "Native int8_tArray Bytes") };
9958         memcpy(ret_arr.ptr, *CommitmentSigned_get_channel_id(&this_ptr_conv), 32);
9959         return ret_arr;
9960 }
9961
9962 void CommitmentSigned_1set_1channel_1id(void* ctx_TODO, uint32_t this_ptr, int8_tArray val) {
9963         LDKCommitmentSigned this_ptr_conv;
9964         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9965         this_ptr_conv.is_owned = false;
9966         LDKThirtyTwoBytes val_ref;
9967         CHECK(val.len == 32);
9968         memcpy(val_ref.data, val.ptr, 32);
9969         CommitmentSigned_set_channel_id(&this_ptr_conv, val_ref);
9970 }
9971
9972 int8_tArray CommitmentSigned_1get_1signature(void* ctx_TODO, uint32_t this_ptr) {
9973         LDKCommitmentSigned this_ptr_conv;
9974         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9975         this_ptr_conv.is_owned = false;
9976         int8_tArray arg_arr = { .len = 64, .ptr = MALLOC(64, "Native int8_tArray Bytes") };
9977         memcpy(arg_arr.ptr, CommitmentSigned_get_signature(&this_ptr_conv).compact_form, 64);
9978         return arg_arr;
9979 }
9980
9981 void CommitmentSigned_1set_1signature(void* ctx_TODO, uint32_t this_ptr, int8_tArray val) {
9982         LDKCommitmentSigned this_ptr_conv;
9983         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9984         this_ptr_conv.is_owned = false;
9985         LDKSignature val_ref;
9986         CHECK(val.len == 64);
9987         memcpy(val_ref.compact_form, val.ptr, 64);
9988         CommitmentSigned_set_signature(&this_ptr_conv, val_ref);
9989 }
9990
9991 void CommitmentSigned_1set_1htlc_1signatures(void* ctx_TODO, uint32_t this_ptr, ptrArray val) {
9992         LDKCommitmentSigned this_ptr_conv;
9993         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9994         this_ptr_conv.is_owned = false;
9995         LDKCVec_SignatureZ val_constr;
9996         val_constr.datalen = val.len;
9997         if (val_constr.datalen > 0)
9998                 val_constr.data = MALLOC(val_constr.datalen * sizeof(LDKSignature), "LDKCVec_SignatureZ Elements");
9999         else
10000                 val_constr.data = NULL;
10001         int8_tArray* val_vals = (int8_tArray*) val.ptr;
10002         for (size_t m = 0; m < val_constr.datalen; m++) {
10003                 int8_tArray arr_conv_12 = val_vals[m];
10004                 LDKSignature arr_conv_12_ref;
10005                 CHECK(arr_conv_12.len == 64);
10006                 memcpy(arr_conv_12_ref.compact_form, arr_conv_12.ptr, 64);
10007                 val_constr.data[m] = arr_conv_12_ref;
10008         }
10009         CommitmentSigned_set_htlc_signatures(&this_ptr_conv, val_constr);
10010 }
10011
10012 uint32_t CommitmentSigned_1new(void* ctx_TODO, int8_tArray channel_id_arg, int8_tArray signature_arg, ptrArray htlc_signatures_arg) {
10013         LDKThirtyTwoBytes channel_id_arg_ref;
10014         CHECK(channel_id_arg.len == 32);
10015         memcpy(channel_id_arg_ref.data, channel_id_arg.ptr, 32);
10016         LDKSignature signature_arg_ref;
10017         CHECK(signature_arg.len == 64);
10018         memcpy(signature_arg_ref.compact_form, signature_arg.ptr, 64);
10019         LDKCVec_SignatureZ htlc_signatures_arg_constr;
10020         htlc_signatures_arg_constr.datalen = htlc_signatures_arg.len;
10021         if (htlc_signatures_arg_constr.datalen > 0)
10022                 htlc_signatures_arg_constr.data = MALLOC(htlc_signatures_arg_constr.datalen * sizeof(LDKSignature), "LDKCVec_SignatureZ Elements");
10023         else
10024                 htlc_signatures_arg_constr.data = NULL;
10025         int8_tArray* htlc_signatures_arg_vals = (int8_tArray*) htlc_signatures_arg.ptr;
10026         for (size_t m = 0; m < htlc_signatures_arg_constr.datalen; m++) {
10027                 int8_tArray arr_conv_12 = htlc_signatures_arg_vals[m];
10028                 LDKSignature arr_conv_12_ref;
10029                 CHECK(arr_conv_12.len == 64);
10030                 memcpy(arr_conv_12_ref.compact_form, arr_conv_12.ptr, 64);
10031                 htlc_signatures_arg_constr.data[m] = arr_conv_12_ref;
10032         }
10033         LDKCommitmentSigned ret_var = CommitmentSigned_new(channel_id_arg_ref, signature_arg_ref, htlc_signatures_arg_constr);
10034         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10035         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10036         long ret_ref = (long)ret_var.inner;
10037         if (ret_var.is_owned) {
10038                 ret_ref |= 1;
10039         }
10040         return ret_ref;
10041 }
10042
10043 void RevokeAndACK_1free(void* ctx_TODO, uint32_t this_ptr) {
10044         LDKRevokeAndACK this_ptr_conv;
10045         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10046         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10047         RevokeAndACK_free(this_ptr_conv);
10048 }
10049
10050 uint32_t RevokeAndACK_1clone(void* ctx_TODO, uint32_t orig) {
10051         LDKRevokeAndACK orig_conv;
10052         orig_conv.inner = (void*)(orig & (~1));
10053         orig_conv.is_owned = false;
10054         LDKRevokeAndACK ret_var = RevokeAndACK_clone(&orig_conv);
10055         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10056         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10057         long ret_ref = (long)ret_var.inner;
10058         if (ret_var.is_owned) {
10059                 ret_ref |= 1;
10060         }
10061         return ret_ref;
10062 }
10063
10064 int8_tArray RevokeAndACK_1get_1channel_1id(void* ctx_TODO, uint32_t this_ptr) {
10065         LDKRevokeAndACK this_ptr_conv;
10066         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10067         this_ptr_conv.is_owned = false;
10068         int8_tArray ret_arr = { .len = 32, .ptr = MALLOC(32, "Native int8_tArray Bytes") };
10069         memcpy(ret_arr.ptr, *RevokeAndACK_get_channel_id(&this_ptr_conv), 32);
10070         return ret_arr;
10071 }
10072
10073 void RevokeAndACK_1set_1channel_1id(void* ctx_TODO, uint32_t this_ptr, int8_tArray val) {
10074         LDKRevokeAndACK this_ptr_conv;
10075         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10076         this_ptr_conv.is_owned = false;
10077         LDKThirtyTwoBytes val_ref;
10078         CHECK(val.len == 32);
10079         memcpy(val_ref.data, val.ptr, 32);
10080         RevokeAndACK_set_channel_id(&this_ptr_conv, val_ref);
10081 }
10082
10083 int8_tArray RevokeAndACK_1get_1per_1commitment_1secret(void* ctx_TODO, uint32_t this_ptr) {
10084         LDKRevokeAndACK this_ptr_conv;
10085         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10086         this_ptr_conv.is_owned = false;
10087         int8_tArray ret_arr = { .len = 32, .ptr = MALLOC(32, "Native int8_tArray Bytes") };
10088         memcpy(ret_arr.ptr, *RevokeAndACK_get_per_commitment_secret(&this_ptr_conv), 32);
10089         return ret_arr;
10090 }
10091
10092 void RevokeAndACK_1set_1per_1commitment_1secret(void* ctx_TODO, uint32_t this_ptr, int8_tArray val) {
10093         LDKRevokeAndACK this_ptr_conv;
10094         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10095         this_ptr_conv.is_owned = false;
10096         LDKThirtyTwoBytes val_ref;
10097         CHECK(val.len == 32);
10098         memcpy(val_ref.data, val.ptr, 32);
10099         RevokeAndACK_set_per_commitment_secret(&this_ptr_conv, val_ref);
10100 }
10101
10102 int8_tArray RevokeAndACK_1get_1next_1per_1commitment_1point(void* ctx_TODO, uint32_t this_ptr) {
10103         LDKRevokeAndACK this_ptr_conv;
10104         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10105         this_ptr_conv.is_owned = false;
10106         int8_tArray arg_arr = { .len = 33, .ptr = MALLOC(33, "Native int8_tArray Bytes") };
10107         memcpy(arg_arr.ptr, RevokeAndACK_get_next_per_commitment_point(&this_ptr_conv).compressed_form, 33);
10108         return arg_arr;
10109 }
10110
10111 void RevokeAndACK_1set_1next_1per_1commitment_1point(void* ctx_TODO, uint32_t this_ptr, int8_tArray val) {
10112         LDKRevokeAndACK this_ptr_conv;
10113         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10114         this_ptr_conv.is_owned = false;
10115         LDKPublicKey val_ref;
10116         CHECK(val.len == 33);
10117         memcpy(val_ref.compressed_form, val.ptr, 33);
10118         RevokeAndACK_set_next_per_commitment_point(&this_ptr_conv, val_ref);
10119 }
10120
10121 uint32_t RevokeAndACK_1new(void* ctx_TODO, int8_tArray channel_id_arg, int8_tArray per_commitment_secret_arg, int8_tArray next_per_commitment_point_arg) {
10122         LDKThirtyTwoBytes channel_id_arg_ref;
10123         CHECK(channel_id_arg.len == 32);
10124         memcpy(channel_id_arg_ref.data, channel_id_arg.ptr, 32);
10125         LDKThirtyTwoBytes per_commitment_secret_arg_ref;
10126         CHECK(per_commitment_secret_arg.len == 32);
10127         memcpy(per_commitment_secret_arg_ref.data, per_commitment_secret_arg.ptr, 32);
10128         LDKPublicKey next_per_commitment_point_arg_ref;
10129         CHECK(next_per_commitment_point_arg.len == 33);
10130         memcpy(next_per_commitment_point_arg_ref.compressed_form, next_per_commitment_point_arg.ptr, 33);
10131         LDKRevokeAndACK ret_var = RevokeAndACK_new(channel_id_arg_ref, per_commitment_secret_arg_ref, next_per_commitment_point_arg_ref);
10132         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10133         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10134         long ret_ref = (long)ret_var.inner;
10135         if (ret_var.is_owned) {
10136                 ret_ref |= 1;
10137         }
10138         return ret_ref;
10139 }
10140
10141 void UpdateFee_1free(void* ctx_TODO, uint32_t this_ptr) {
10142         LDKUpdateFee this_ptr_conv;
10143         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10144         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10145         UpdateFee_free(this_ptr_conv);
10146 }
10147
10148 uint32_t UpdateFee_1clone(void* ctx_TODO, uint32_t orig) {
10149         LDKUpdateFee orig_conv;
10150         orig_conv.inner = (void*)(orig & (~1));
10151         orig_conv.is_owned = false;
10152         LDKUpdateFee ret_var = UpdateFee_clone(&orig_conv);
10153         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10154         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10155         long ret_ref = (long)ret_var.inner;
10156         if (ret_var.is_owned) {
10157                 ret_ref |= 1;
10158         }
10159         return ret_ref;
10160 }
10161
10162 int8_tArray UpdateFee_1get_1channel_1id(void* ctx_TODO, uint32_t this_ptr) {
10163         LDKUpdateFee this_ptr_conv;
10164         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10165         this_ptr_conv.is_owned = false;
10166         int8_tArray ret_arr = { .len = 32, .ptr = MALLOC(32, "Native int8_tArray Bytes") };
10167         memcpy(ret_arr.ptr, *UpdateFee_get_channel_id(&this_ptr_conv), 32);
10168         return ret_arr;
10169 }
10170
10171 void UpdateFee_1set_1channel_1id(void* ctx_TODO, uint32_t this_ptr, int8_tArray val) {
10172         LDKUpdateFee this_ptr_conv;
10173         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10174         this_ptr_conv.is_owned = false;
10175         LDKThirtyTwoBytes val_ref;
10176         CHECK(val.len == 32);
10177         memcpy(val_ref.data, val.ptr, 32);
10178         UpdateFee_set_channel_id(&this_ptr_conv, val_ref);
10179 }
10180
10181 int32_t UpdateFee_1get_1feerate_1per_1kw(void* ctx_TODO, uint32_t this_ptr) {
10182         LDKUpdateFee this_ptr_conv;
10183         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10184         this_ptr_conv.is_owned = false;
10185         int32_t ret_val = UpdateFee_get_feerate_per_kw(&this_ptr_conv);
10186         return ret_val;
10187 }
10188
10189 void UpdateFee_1set_1feerate_1per_1kw(void* ctx_TODO, uint32_t this_ptr, int32_t val) {
10190         LDKUpdateFee this_ptr_conv;
10191         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10192         this_ptr_conv.is_owned = false;
10193         UpdateFee_set_feerate_per_kw(&this_ptr_conv, val);
10194 }
10195
10196 uint32_t UpdateFee_1new(void* ctx_TODO, int8_tArray channel_id_arg, int32_t feerate_per_kw_arg) {
10197         LDKThirtyTwoBytes channel_id_arg_ref;
10198         CHECK(channel_id_arg.len == 32);
10199         memcpy(channel_id_arg_ref.data, channel_id_arg.ptr, 32);
10200         LDKUpdateFee ret_var = UpdateFee_new(channel_id_arg_ref, feerate_per_kw_arg);
10201         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10202         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10203         long ret_ref = (long)ret_var.inner;
10204         if (ret_var.is_owned) {
10205                 ret_ref |= 1;
10206         }
10207         return ret_ref;
10208 }
10209
10210 void DataLossProtect_1free(void* ctx_TODO, uint32_t this_ptr) {
10211         LDKDataLossProtect this_ptr_conv;
10212         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10213         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10214         DataLossProtect_free(this_ptr_conv);
10215 }
10216
10217 uint32_t DataLossProtect_1clone(void* ctx_TODO, uint32_t orig) {
10218         LDKDataLossProtect orig_conv;
10219         orig_conv.inner = (void*)(orig & (~1));
10220         orig_conv.is_owned = false;
10221         LDKDataLossProtect ret_var = DataLossProtect_clone(&orig_conv);
10222         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10223         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10224         long ret_ref = (long)ret_var.inner;
10225         if (ret_var.is_owned) {
10226                 ret_ref |= 1;
10227         }
10228         return ret_ref;
10229 }
10230
10231 int8_tArray DataLossProtect_1get_1your_1last_1per_1commitment_1secret(void* ctx_TODO, uint32_t this_ptr) {
10232         LDKDataLossProtect this_ptr_conv;
10233         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10234         this_ptr_conv.is_owned = false;
10235         int8_tArray ret_arr = { .len = 32, .ptr = MALLOC(32, "Native int8_tArray Bytes") };
10236         memcpy(ret_arr.ptr, *DataLossProtect_get_your_last_per_commitment_secret(&this_ptr_conv), 32);
10237         return ret_arr;
10238 }
10239
10240 void DataLossProtect_1set_1your_1last_1per_1commitment_1secret(void* ctx_TODO, uint32_t this_ptr, int8_tArray val) {
10241         LDKDataLossProtect this_ptr_conv;
10242         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10243         this_ptr_conv.is_owned = false;
10244         LDKThirtyTwoBytes val_ref;
10245         CHECK(val.len == 32);
10246         memcpy(val_ref.data, val.ptr, 32);
10247         DataLossProtect_set_your_last_per_commitment_secret(&this_ptr_conv, val_ref);
10248 }
10249
10250 int8_tArray DataLossProtect_1get_1my_1current_1per_1commitment_1point(void* ctx_TODO, uint32_t this_ptr) {
10251         LDKDataLossProtect this_ptr_conv;
10252         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10253         this_ptr_conv.is_owned = false;
10254         int8_tArray arg_arr = { .len = 33, .ptr = MALLOC(33, "Native int8_tArray Bytes") };
10255         memcpy(arg_arr.ptr, DataLossProtect_get_my_current_per_commitment_point(&this_ptr_conv).compressed_form, 33);
10256         return arg_arr;
10257 }
10258
10259 void DataLossProtect_1set_1my_1current_1per_1commitment_1point(void* ctx_TODO, uint32_t this_ptr, int8_tArray val) {
10260         LDKDataLossProtect this_ptr_conv;
10261         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10262         this_ptr_conv.is_owned = false;
10263         LDKPublicKey val_ref;
10264         CHECK(val.len == 33);
10265         memcpy(val_ref.compressed_form, val.ptr, 33);
10266         DataLossProtect_set_my_current_per_commitment_point(&this_ptr_conv, val_ref);
10267 }
10268
10269 uint32_t DataLossProtect_1new(void* ctx_TODO, int8_tArray your_last_per_commitment_secret_arg, int8_tArray my_current_per_commitment_point_arg) {
10270         LDKThirtyTwoBytes your_last_per_commitment_secret_arg_ref;
10271         CHECK(your_last_per_commitment_secret_arg.len == 32);
10272         memcpy(your_last_per_commitment_secret_arg_ref.data, your_last_per_commitment_secret_arg.ptr, 32);
10273         LDKPublicKey my_current_per_commitment_point_arg_ref;
10274         CHECK(my_current_per_commitment_point_arg.len == 33);
10275         memcpy(my_current_per_commitment_point_arg_ref.compressed_form, my_current_per_commitment_point_arg.ptr, 33);
10276         LDKDataLossProtect ret_var = DataLossProtect_new(your_last_per_commitment_secret_arg_ref, my_current_per_commitment_point_arg_ref);
10277         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10278         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10279         long ret_ref = (long)ret_var.inner;
10280         if (ret_var.is_owned) {
10281                 ret_ref |= 1;
10282         }
10283         return ret_ref;
10284 }
10285
10286 void ChannelReestablish_1free(void* ctx_TODO, uint32_t this_ptr) {
10287         LDKChannelReestablish this_ptr_conv;
10288         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10289         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10290         ChannelReestablish_free(this_ptr_conv);
10291 }
10292
10293 uint32_t ChannelReestablish_1clone(void* ctx_TODO, uint32_t orig) {
10294         LDKChannelReestablish orig_conv;
10295         orig_conv.inner = (void*)(orig & (~1));
10296         orig_conv.is_owned = false;
10297         LDKChannelReestablish ret_var = ChannelReestablish_clone(&orig_conv);
10298         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10299         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10300         long ret_ref = (long)ret_var.inner;
10301         if (ret_var.is_owned) {
10302                 ret_ref |= 1;
10303         }
10304         return ret_ref;
10305 }
10306
10307 int8_tArray ChannelReestablish_1get_1channel_1id(void* ctx_TODO, uint32_t this_ptr) {
10308         LDKChannelReestablish this_ptr_conv;
10309         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10310         this_ptr_conv.is_owned = false;
10311         int8_tArray ret_arr = { .len = 32, .ptr = MALLOC(32, "Native int8_tArray Bytes") };
10312         memcpy(ret_arr.ptr, *ChannelReestablish_get_channel_id(&this_ptr_conv), 32);
10313         return ret_arr;
10314 }
10315
10316 void ChannelReestablish_1set_1channel_1id(void* ctx_TODO, uint32_t this_ptr, int8_tArray val) {
10317         LDKChannelReestablish this_ptr_conv;
10318         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10319         this_ptr_conv.is_owned = false;
10320         LDKThirtyTwoBytes val_ref;
10321         CHECK(val.len == 32);
10322         memcpy(val_ref.data, val.ptr, 32);
10323         ChannelReestablish_set_channel_id(&this_ptr_conv, val_ref);
10324 }
10325
10326 int64_t ChannelReestablish_1get_1next_1local_1commitment_1number(void* ctx_TODO, uint32_t this_ptr) {
10327         LDKChannelReestablish this_ptr_conv;
10328         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10329         this_ptr_conv.is_owned = false;
10330         int64_t ret_val = ChannelReestablish_get_next_local_commitment_number(&this_ptr_conv);
10331         return ret_val;
10332 }
10333
10334 void ChannelReestablish_1set_1next_1local_1commitment_1number(void* ctx_TODO, uint32_t this_ptr, int64_t val) {
10335         LDKChannelReestablish this_ptr_conv;
10336         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10337         this_ptr_conv.is_owned = false;
10338         ChannelReestablish_set_next_local_commitment_number(&this_ptr_conv, val);
10339 }
10340
10341 int64_t ChannelReestablish_1get_1next_1remote_1commitment_1number(void* ctx_TODO, uint32_t this_ptr) {
10342         LDKChannelReestablish this_ptr_conv;
10343         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10344         this_ptr_conv.is_owned = false;
10345         int64_t ret_val = ChannelReestablish_get_next_remote_commitment_number(&this_ptr_conv);
10346         return ret_val;
10347 }
10348
10349 void ChannelReestablish_1set_1next_1remote_1commitment_1number(void* ctx_TODO, uint32_t this_ptr, int64_t val) {
10350         LDKChannelReestablish this_ptr_conv;
10351         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10352         this_ptr_conv.is_owned = false;
10353         ChannelReestablish_set_next_remote_commitment_number(&this_ptr_conv, val);
10354 }
10355
10356 void AnnouncementSignatures_1free(void* ctx_TODO, uint32_t this_ptr) {
10357         LDKAnnouncementSignatures this_ptr_conv;
10358         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10359         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10360         AnnouncementSignatures_free(this_ptr_conv);
10361 }
10362
10363 uint32_t AnnouncementSignatures_1clone(void* ctx_TODO, uint32_t orig) {
10364         LDKAnnouncementSignatures orig_conv;
10365         orig_conv.inner = (void*)(orig & (~1));
10366         orig_conv.is_owned = false;
10367         LDKAnnouncementSignatures ret_var = AnnouncementSignatures_clone(&orig_conv);
10368         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10369         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10370         long ret_ref = (long)ret_var.inner;
10371         if (ret_var.is_owned) {
10372                 ret_ref |= 1;
10373         }
10374         return ret_ref;
10375 }
10376
10377 int8_tArray AnnouncementSignatures_1get_1channel_1id(void* ctx_TODO, uint32_t this_ptr) {
10378         LDKAnnouncementSignatures this_ptr_conv;
10379         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10380         this_ptr_conv.is_owned = false;
10381         int8_tArray ret_arr = { .len = 32, .ptr = MALLOC(32, "Native int8_tArray Bytes") };
10382         memcpy(ret_arr.ptr, *AnnouncementSignatures_get_channel_id(&this_ptr_conv), 32);
10383         return ret_arr;
10384 }
10385
10386 void AnnouncementSignatures_1set_1channel_1id(void* ctx_TODO, uint32_t this_ptr, int8_tArray val) {
10387         LDKAnnouncementSignatures this_ptr_conv;
10388         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10389         this_ptr_conv.is_owned = false;
10390         LDKThirtyTwoBytes val_ref;
10391         CHECK(val.len == 32);
10392         memcpy(val_ref.data, val.ptr, 32);
10393         AnnouncementSignatures_set_channel_id(&this_ptr_conv, val_ref);
10394 }
10395
10396 int64_t AnnouncementSignatures_1get_1short_1channel_1id(void* ctx_TODO, uint32_t this_ptr) {
10397         LDKAnnouncementSignatures this_ptr_conv;
10398         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10399         this_ptr_conv.is_owned = false;
10400         int64_t ret_val = AnnouncementSignatures_get_short_channel_id(&this_ptr_conv);
10401         return ret_val;
10402 }
10403
10404 void AnnouncementSignatures_1set_1short_1channel_1id(void* ctx_TODO, uint32_t this_ptr, int64_t val) {
10405         LDKAnnouncementSignatures this_ptr_conv;
10406         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10407         this_ptr_conv.is_owned = false;
10408         AnnouncementSignatures_set_short_channel_id(&this_ptr_conv, val);
10409 }
10410
10411 int8_tArray AnnouncementSignatures_1get_1node_1signature(void* ctx_TODO, uint32_t this_ptr) {
10412         LDKAnnouncementSignatures this_ptr_conv;
10413         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10414         this_ptr_conv.is_owned = false;
10415         int8_tArray arg_arr = { .len = 64, .ptr = MALLOC(64, "Native int8_tArray Bytes") };
10416         memcpy(arg_arr.ptr, AnnouncementSignatures_get_node_signature(&this_ptr_conv).compact_form, 64);
10417         return arg_arr;
10418 }
10419
10420 void AnnouncementSignatures_1set_1node_1signature(void* ctx_TODO, uint32_t this_ptr, int8_tArray val) {
10421         LDKAnnouncementSignatures this_ptr_conv;
10422         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10423         this_ptr_conv.is_owned = false;
10424         LDKSignature val_ref;
10425         CHECK(val.len == 64);
10426         memcpy(val_ref.compact_form, val.ptr, 64);
10427         AnnouncementSignatures_set_node_signature(&this_ptr_conv, val_ref);
10428 }
10429
10430 int8_tArray AnnouncementSignatures_1get_1bitcoin_1signature(void* ctx_TODO, uint32_t this_ptr) {
10431         LDKAnnouncementSignatures this_ptr_conv;
10432         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10433         this_ptr_conv.is_owned = false;
10434         int8_tArray arg_arr = { .len = 64, .ptr = MALLOC(64, "Native int8_tArray Bytes") };
10435         memcpy(arg_arr.ptr, AnnouncementSignatures_get_bitcoin_signature(&this_ptr_conv).compact_form, 64);
10436         return arg_arr;
10437 }
10438
10439 void AnnouncementSignatures_1set_1bitcoin_1signature(void* ctx_TODO, uint32_t this_ptr, int8_tArray val) {
10440         LDKAnnouncementSignatures this_ptr_conv;
10441         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10442         this_ptr_conv.is_owned = false;
10443         LDKSignature val_ref;
10444         CHECK(val.len == 64);
10445         memcpy(val_ref.compact_form, val.ptr, 64);
10446         AnnouncementSignatures_set_bitcoin_signature(&this_ptr_conv, val_ref);
10447 }
10448
10449 uint32_t AnnouncementSignatures_1new(void* ctx_TODO, int8_tArray channel_id_arg, int64_t short_channel_id_arg, int8_tArray node_signature_arg, int8_tArray bitcoin_signature_arg) {
10450         LDKThirtyTwoBytes channel_id_arg_ref;
10451         CHECK(channel_id_arg.len == 32);
10452         memcpy(channel_id_arg_ref.data, channel_id_arg.ptr, 32);
10453         LDKSignature node_signature_arg_ref;
10454         CHECK(node_signature_arg.len == 64);
10455         memcpy(node_signature_arg_ref.compact_form, node_signature_arg.ptr, 64);
10456         LDKSignature bitcoin_signature_arg_ref;
10457         CHECK(bitcoin_signature_arg.len == 64);
10458         memcpy(bitcoin_signature_arg_ref.compact_form, bitcoin_signature_arg.ptr, 64);
10459         LDKAnnouncementSignatures ret_var = AnnouncementSignatures_new(channel_id_arg_ref, short_channel_id_arg, node_signature_arg_ref, bitcoin_signature_arg_ref);
10460         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10461         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10462         long ret_ref = (long)ret_var.inner;
10463         if (ret_var.is_owned) {
10464                 ret_ref |= 1;
10465         }
10466         return ret_ref;
10467 }
10468
10469 void NetAddress_1free(void* ctx_TODO, uint32_t this_ptr) {
10470         LDKNetAddress this_ptr_conv = *(LDKNetAddress*)this_ptr;
10471         FREE((void*)this_ptr);
10472         NetAddress_free(this_ptr_conv);
10473 }
10474
10475 uint32_t NetAddress_1clone(void* ctx_TODO, uint32_t orig) {
10476         LDKNetAddress* orig_conv = (LDKNetAddress*)orig;
10477         LDKNetAddress *ret_copy = MALLOC(sizeof(LDKNetAddress), "LDKNetAddress");
10478         *ret_copy = NetAddress_clone(orig_conv);
10479         long ret_ref = (long)ret_copy;
10480         return ret_ref;
10481 }
10482
10483 int8_tArray NetAddress_1write(void* ctx_TODO, uint32_t obj) {
10484         LDKNetAddress* obj_conv = (LDKNetAddress*)obj;
10485         LDKCVec_u8Z arg_var = NetAddress_write(obj_conv);
10486         int8_tArray arg_arr = { .len = arg_var.datalen, .ptr = MALLOC(arg_var.datalen, "Native int8_tArray Bytes") };
10487         memcpy(arg_arr.ptr, arg_var.data, arg_var.datalen);
10488         CVec_u8Z_free(arg_var);
10489         return arg_arr;
10490 }
10491
10492 uint32_t Result_1read(void* ctx_TODO, int8_tArray ser) {
10493         LDKu8slice ser_ref;
10494         ser_ref.datalen = ser.len;
10495         ser_ref.data = ser.ptr;
10496         LDKCResult_CResult_NetAddressu8ZDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_CResult_NetAddressu8ZDecodeErrorZ), "LDKCResult_CResult_NetAddressu8ZDecodeErrorZ");
10497         *ret_conv = Result_read(ser_ref);
10498         return (long)ret_conv;
10499 }
10500
10501 void UnsignedNodeAnnouncement_1free(void* ctx_TODO, uint32_t this_ptr) {
10502         LDKUnsignedNodeAnnouncement this_ptr_conv;
10503         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10504         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10505         UnsignedNodeAnnouncement_free(this_ptr_conv);
10506 }
10507
10508 uint32_t UnsignedNodeAnnouncement_1clone(void* ctx_TODO, uint32_t orig) {
10509         LDKUnsignedNodeAnnouncement orig_conv;
10510         orig_conv.inner = (void*)(orig & (~1));
10511         orig_conv.is_owned = false;
10512         LDKUnsignedNodeAnnouncement ret_var = UnsignedNodeAnnouncement_clone(&orig_conv);
10513         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10514         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10515         long ret_ref = (long)ret_var.inner;
10516         if (ret_var.is_owned) {
10517                 ret_ref |= 1;
10518         }
10519         return ret_ref;
10520 }
10521
10522 uint32_t UnsignedNodeAnnouncement_1get_1features(void* ctx_TODO, uint32_t this_ptr) {
10523         LDKUnsignedNodeAnnouncement this_ptr_conv;
10524         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10525         this_ptr_conv.is_owned = false;
10526         LDKNodeFeatures ret_var = UnsignedNodeAnnouncement_get_features(&this_ptr_conv);
10527         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10528         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10529         long ret_ref = (long)ret_var.inner;
10530         if (ret_var.is_owned) {
10531                 ret_ref |= 1;
10532         }
10533         return ret_ref;
10534 }
10535
10536 void UnsignedNodeAnnouncement_1set_1features(void* ctx_TODO, uint32_t this_ptr, uint32_t val) {
10537         LDKUnsignedNodeAnnouncement this_ptr_conv;
10538         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10539         this_ptr_conv.is_owned = false;
10540         LDKNodeFeatures val_conv;
10541         val_conv.inner = (void*)(val & (~1));
10542         val_conv.is_owned = (val & 1) || (val == 0);
10543         // Warning: we may need a move here but can't clone!
10544         UnsignedNodeAnnouncement_set_features(&this_ptr_conv, val_conv);
10545 }
10546
10547 int32_t UnsignedNodeAnnouncement_1get_1timestamp(void* ctx_TODO, uint32_t this_ptr) {
10548         LDKUnsignedNodeAnnouncement this_ptr_conv;
10549         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10550         this_ptr_conv.is_owned = false;
10551         int32_t ret_val = UnsignedNodeAnnouncement_get_timestamp(&this_ptr_conv);
10552         return ret_val;
10553 }
10554
10555 void UnsignedNodeAnnouncement_1set_1timestamp(void* ctx_TODO, uint32_t this_ptr, int32_t val) {
10556         LDKUnsignedNodeAnnouncement this_ptr_conv;
10557         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10558         this_ptr_conv.is_owned = false;
10559         UnsignedNodeAnnouncement_set_timestamp(&this_ptr_conv, val);
10560 }
10561
10562 int8_tArray UnsignedNodeAnnouncement_1get_1node_1id(void* ctx_TODO, uint32_t this_ptr) {
10563         LDKUnsignedNodeAnnouncement this_ptr_conv;
10564         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10565         this_ptr_conv.is_owned = false;
10566         int8_tArray arg_arr = { .len = 33, .ptr = MALLOC(33, "Native int8_tArray Bytes") };
10567         memcpy(arg_arr.ptr, UnsignedNodeAnnouncement_get_node_id(&this_ptr_conv).compressed_form, 33);
10568         return arg_arr;
10569 }
10570
10571 void UnsignedNodeAnnouncement_1set_1node_1id(void* ctx_TODO, uint32_t this_ptr, int8_tArray val) {
10572         LDKUnsignedNodeAnnouncement this_ptr_conv;
10573         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10574         this_ptr_conv.is_owned = false;
10575         LDKPublicKey val_ref;
10576         CHECK(val.len == 33);
10577         memcpy(val_ref.compressed_form, val.ptr, 33);
10578         UnsignedNodeAnnouncement_set_node_id(&this_ptr_conv, val_ref);
10579 }
10580
10581 int8_tArray UnsignedNodeAnnouncement_1get_1rgb(void* ctx_TODO, uint32_t this_ptr) {
10582         LDKUnsignedNodeAnnouncement this_ptr_conv;
10583         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10584         this_ptr_conv.is_owned = false;
10585         int8_tArray ret_arr = { .len = 3, .ptr = MALLOC(3, "Native int8_tArray Bytes") };
10586         memcpy(ret_arr.ptr, *UnsignedNodeAnnouncement_get_rgb(&this_ptr_conv), 3);
10587         return ret_arr;
10588 }
10589
10590 void UnsignedNodeAnnouncement_1set_1rgb(void* ctx_TODO, uint32_t this_ptr, int8_tArray val) {
10591         LDKUnsignedNodeAnnouncement this_ptr_conv;
10592         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10593         this_ptr_conv.is_owned = false;
10594         LDKThreeBytes val_ref;
10595         CHECK(val.len == 3);
10596         memcpy(val_ref.data, val.ptr, 3);
10597         UnsignedNodeAnnouncement_set_rgb(&this_ptr_conv, val_ref);
10598 }
10599
10600 int8_tArray UnsignedNodeAnnouncement_1get_1alias(void* ctx_TODO, uint32_t this_ptr) {
10601         LDKUnsignedNodeAnnouncement this_ptr_conv;
10602         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10603         this_ptr_conv.is_owned = false;
10604         int8_tArray ret_arr = { .len = 32, .ptr = MALLOC(32, "Native int8_tArray Bytes") };
10605         memcpy(ret_arr.ptr, *UnsignedNodeAnnouncement_get_alias(&this_ptr_conv), 32);
10606         return ret_arr;
10607 }
10608
10609 void UnsignedNodeAnnouncement_1set_1alias(void* ctx_TODO, uint32_t this_ptr, int8_tArray val) {
10610         LDKUnsignedNodeAnnouncement this_ptr_conv;
10611         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10612         this_ptr_conv.is_owned = false;
10613         LDKThirtyTwoBytes val_ref;
10614         CHECK(val.len == 32);
10615         memcpy(val_ref.data, val.ptr, 32);
10616         UnsignedNodeAnnouncement_set_alias(&this_ptr_conv, val_ref);
10617 }
10618
10619 void UnsignedNodeAnnouncement_1set_1addresses(void* ctx_TODO, uint32_t this_ptr, uint32_tArray val) {
10620         LDKUnsignedNodeAnnouncement this_ptr_conv;
10621         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10622         this_ptr_conv.is_owned = false;
10623         LDKCVec_NetAddressZ val_constr;
10624         val_constr.datalen = val.len;
10625         if (val_constr.datalen > 0)
10626                 val_constr.data = MALLOC(val_constr.datalen * sizeof(LDKNetAddress), "LDKCVec_NetAddressZ Elements");
10627         else
10628                 val_constr.data = NULL;
10629         uint32_t* val_vals = (uint32_t*) val.ptr;
10630         for (size_t m = 0; m < val_constr.datalen; m++) {
10631                 uint32_t arr_conv_12 = val_vals[m];
10632                 LDKNetAddress arr_conv_12_conv = *(LDKNetAddress*)arr_conv_12;
10633                 FREE((void*)arr_conv_12);
10634                 val_constr.data[m] = arr_conv_12_conv;
10635         }
10636         UnsignedNodeAnnouncement_set_addresses(&this_ptr_conv, val_constr);
10637 }
10638
10639 void NodeAnnouncement_1free(void* ctx_TODO, uint32_t this_ptr) {
10640         LDKNodeAnnouncement this_ptr_conv;
10641         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10642         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10643         NodeAnnouncement_free(this_ptr_conv);
10644 }
10645
10646 uint32_t NodeAnnouncement_1clone(void* ctx_TODO, uint32_t orig) {
10647         LDKNodeAnnouncement orig_conv;
10648         orig_conv.inner = (void*)(orig & (~1));
10649         orig_conv.is_owned = false;
10650         LDKNodeAnnouncement ret_var = NodeAnnouncement_clone(&orig_conv);
10651         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10652         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10653         long ret_ref = (long)ret_var.inner;
10654         if (ret_var.is_owned) {
10655                 ret_ref |= 1;
10656         }
10657         return ret_ref;
10658 }
10659
10660 int8_tArray NodeAnnouncement_1get_1signature(void* ctx_TODO, uint32_t this_ptr) {
10661         LDKNodeAnnouncement this_ptr_conv;
10662         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10663         this_ptr_conv.is_owned = false;
10664         int8_tArray arg_arr = { .len = 64, .ptr = MALLOC(64, "Native int8_tArray Bytes") };
10665         memcpy(arg_arr.ptr, NodeAnnouncement_get_signature(&this_ptr_conv).compact_form, 64);
10666         return arg_arr;
10667 }
10668
10669 void NodeAnnouncement_1set_1signature(void* ctx_TODO, uint32_t this_ptr, int8_tArray val) {
10670         LDKNodeAnnouncement this_ptr_conv;
10671         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10672         this_ptr_conv.is_owned = false;
10673         LDKSignature val_ref;
10674         CHECK(val.len == 64);
10675         memcpy(val_ref.compact_form, val.ptr, 64);
10676         NodeAnnouncement_set_signature(&this_ptr_conv, val_ref);
10677 }
10678
10679 uint32_t NodeAnnouncement_1get_1contents(void* ctx_TODO, uint32_t this_ptr) {
10680         LDKNodeAnnouncement this_ptr_conv;
10681         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10682         this_ptr_conv.is_owned = false;
10683         LDKUnsignedNodeAnnouncement ret_var = NodeAnnouncement_get_contents(&this_ptr_conv);
10684         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10685         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10686         long ret_ref = (long)ret_var.inner;
10687         if (ret_var.is_owned) {
10688                 ret_ref |= 1;
10689         }
10690         return ret_ref;
10691 }
10692
10693 void NodeAnnouncement_1set_1contents(void* ctx_TODO, uint32_t this_ptr, uint32_t val) {
10694         LDKNodeAnnouncement this_ptr_conv;
10695         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10696         this_ptr_conv.is_owned = false;
10697         LDKUnsignedNodeAnnouncement val_conv;
10698         val_conv.inner = (void*)(val & (~1));
10699         val_conv.is_owned = (val & 1) || (val == 0);
10700         if (val_conv.inner != NULL)
10701                 val_conv = UnsignedNodeAnnouncement_clone(&val_conv);
10702         NodeAnnouncement_set_contents(&this_ptr_conv, val_conv);
10703 }
10704
10705 uint32_t NodeAnnouncement_1new(void* ctx_TODO, int8_tArray signature_arg, uint32_t contents_arg) {
10706         LDKSignature signature_arg_ref;
10707         CHECK(signature_arg.len == 64);
10708         memcpy(signature_arg_ref.compact_form, signature_arg.ptr, 64);
10709         LDKUnsignedNodeAnnouncement contents_arg_conv;
10710         contents_arg_conv.inner = (void*)(contents_arg & (~1));
10711         contents_arg_conv.is_owned = (contents_arg & 1) || (contents_arg == 0);
10712         if (contents_arg_conv.inner != NULL)
10713                 contents_arg_conv = UnsignedNodeAnnouncement_clone(&contents_arg_conv);
10714         LDKNodeAnnouncement ret_var = NodeAnnouncement_new(signature_arg_ref, contents_arg_conv);
10715         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10716         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10717         long ret_ref = (long)ret_var.inner;
10718         if (ret_var.is_owned) {
10719                 ret_ref |= 1;
10720         }
10721         return ret_ref;
10722 }
10723
10724 void UnsignedChannelAnnouncement_1free(void* ctx_TODO, uint32_t this_ptr) {
10725         LDKUnsignedChannelAnnouncement this_ptr_conv;
10726         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10727         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10728         UnsignedChannelAnnouncement_free(this_ptr_conv);
10729 }
10730
10731 uint32_t UnsignedChannelAnnouncement_1clone(void* ctx_TODO, uint32_t orig) {
10732         LDKUnsignedChannelAnnouncement orig_conv;
10733         orig_conv.inner = (void*)(orig & (~1));
10734         orig_conv.is_owned = false;
10735         LDKUnsignedChannelAnnouncement ret_var = UnsignedChannelAnnouncement_clone(&orig_conv);
10736         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10737         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10738         long ret_ref = (long)ret_var.inner;
10739         if (ret_var.is_owned) {
10740                 ret_ref |= 1;
10741         }
10742         return ret_ref;
10743 }
10744
10745 uint32_t UnsignedChannelAnnouncement_1get_1features(void* ctx_TODO, uint32_t this_ptr) {
10746         LDKUnsignedChannelAnnouncement this_ptr_conv;
10747         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10748         this_ptr_conv.is_owned = false;
10749         LDKChannelFeatures ret_var = UnsignedChannelAnnouncement_get_features(&this_ptr_conv);
10750         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10751         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10752         long ret_ref = (long)ret_var.inner;
10753         if (ret_var.is_owned) {
10754                 ret_ref |= 1;
10755         }
10756         return ret_ref;
10757 }
10758
10759 void UnsignedChannelAnnouncement_1set_1features(void* ctx_TODO, uint32_t this_ptr, uint32_t val) {
10760         LDKUnsignedChannelAnnouncement this_ptr_conv;
10761         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10762         this_ptr_conv.is_owned = false;
10763         LDKChannelFeatures val_conv;
10764         val_conv.inner = (void*)(val & (~1));
10765         val_conv.is_owned = (val & 1) || (val == 0);
10766         // Warning: we may need a move here but can't clone!
10767         UnsignedChannelAnnouncement_set_features(&this_ptr_conv, val_conv);
10768 }
10769
10770 int8_tArray UnsignedChannelAnnouncement_1get_1chain_1hash(void* ctx_TODO, uint32_t this_ptr) {
10771         LDKUnsignedChannelAnnouncement this_ptr_conv;
10772         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10773         this_ptr_conv.is_owned = false;
10774         int8_tArray ret_arr = { .len = 32, .ptr = MALLOC(32, "Native int8_tArray Bytes") };
10775         memcpy(ret_arr.ptr, *UnsignedChannelAnnouncement_get_chain_hash(&this_ptr_conv), 32);
10776         return ret_arr;
10777 }
10778
10779 void UnsignedChannelAnnouncement_1set_1chain_1hash(void* ctx_TODO, uint32_t this_ptr, int8_tArray val) {
10780         LDKUnsignedChannelAnnouncement this_ptr_conv;
10781         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10782         this_ptr_conv.is_owned = false;
10783         LDKThirtyTwoBytes val_ref;
10784         CHECK(val.len == 32);
10785         memcpy(val_ref.data, val.ptr, 32);
10786         UnsignedChannelAnnouncement_set_chain_hash(&this_ptr_conv, val_ref);
10787 }
10788
10789 int64_t UnsignedChannelAnnouncement_1get_1short_1channel_1id(void* ctx_TODO, uint32_t this_ptr) {
10790         LDKUnsignedChannelAnnouncement this_ptr_conv;
10791         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10792         this_ptr_conv.is_owned = false;
10793         int64_t ret_val = UnsignedChannelAnnouncement_get_short_channel_id(&this_ptr_conv);
10794         return ret_val;
10795 }
10796
10797 void UnsignedChannelAnnouncement_1set_1short_1channel_1id(void* ctx_TODO, uint32_t this_ptr, int64_t val) {
10798         LDKUnsignedChannelAnnouncement this_ptr_conv;
10799         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10800         this_ptr_conv.is_owned = false;
10801         UnsignedChannelAnnouncement_set_short_channel_id(&this_ptr_conv, val);
10802 }
10803
10804 int8_tArray UnsignedChannelAnnouncement_1get_1node_1id_11(void* ctx_TODO, uint32_t this_ptr) {
10805         LDKUnsignedChannelAnnouncement this_ptr_conv;
10806         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10807         this_ptr_conv.is_owned = false;
10808         int8_tArray arg_arr = { .len = 33, .ptr = MALLOC(33, "Native int8_tArray Bytes") };
10809         memcpy(arg_arr.ptr, UnsignedChannelAnnouncement_get_node_id_1(&this_ptr_conv).compressed_form, 33);
10810         return arg_arr;
10811 }
10812
10813 void UnsignedChannelAnnouncement_1set_1node_1id_11(void* ctx_TODO, uint32_t this_ptr, int8_tArray val) {
10814         LDKUnsignedChannelAnnouncement this_ptr_conv;
10815         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10816         this_ptr_conv.is_owned = false;
10817         LDKPublicKey val_ref;
10818         CHECK(val.len == 33);
10819         memcpy(val_ref.compressed_form, val.ptr, 33);
10820         UnsignedChannelAnnouncement_set_node_id_1(&this_ptr_conv, val_ref);
10821 }
10822
10823 int8_tArray UnsignedChannelAnnouncement_1get_1node_1id_12(void* ctx_TODO, uint32_t this_ptr) {
10824         LDKUnsignedChannelAnnouncement this_ptr_conv;
10825         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10826         this_ptr_conv.is_owned = false;
10827         int8_tArray arg_arr = { .len = 33, .ptr = MALLOC(33, "Native int8_tArray Bytes") };
10828         memcpy(arg_arr.ptr, UnsignedChannelAnnouncement_get_node_id_2(&this_ptr_conv).compressed_form, 33);
10829         return arg_arr;
10830 }
10831
10832 void UnsignedChannelAnnouncement_1set_1node_1id_12(void* ctx_TODO, uint32_t this_ptr, int8_tArray val) {
10833         LDKUnsignedChannelAnnouncement this_ptr_conv;
10834         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10835         this_ptr_conv.is_owned = false;
10836         LDKPublicKey val_ref;
10837         CHECK(val.len == 33);
10838         memcpy(val_ref.compressed_form, val.ptr, 33);
10839         UnsignedChannelAnnouncement_set_node_id_2(&this_ptr_conv, val_ref);
10840 }
10841
10842 int8_tArray UnsignedChannelAnnouncement_1get_1bitcoin_1key_11(void* ctx_TODO, uint32_t this_ptr) {
10843         LDKUnsignedChannelAnnouncement this_ptr_conv;
10844         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10845         this_ptr_conv.is_owned = false;
10846         int8_tArray arg_arr = { .len = 33, .ptr = MALLOC(33, "Native int8_tArray Bytes") };
10847         memcpy(arg_arr.ptr, UnsignedChannelAnnouncement_get_bitcoin_key_1(&this_ptr_conv).compressed_form, 33);
10848         return arg_arr;
10849 }
10850
10851 void UnsignedChannelAnnouncement_1set_1bitcoin_1key_11(void* ctx_TODO, uint32_t this_ptr, int8_tArray val) {
10852         LDKUnsignedChannelAnnouncement this_ptr_conv;
10853         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10854         this_ptr_conv.is_owned = false;
10855         LDKPublicKey val_ref;
10856         CHECK(val.len == 33);
10857         memcpy(val_ref.compressed_form, val.ptr, 33);
10858         UnsignedChannelAnnouncement_set_bitcoin_key_1(&this_ptr_conv, val_ref);
10859 }
10860
10861 int8_tArray UnsignedChannelAnnouncement_1get_1bitcoin_1key_12(void* ctx_TODO, uint32_t this_ptr) {
10862         LDKUnsignedChannelAnnouncement this_ptr_conv;
10863         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10864         this_ptr_conv.is_owned = false;
10865         int8_tArray arg_arr = { .len = 33, .ptr = MALLOC(33, "Native int8_tArray Bytes") };
10866         memcpy(arg_arr.ptr, UnsignedChannelAnnouncement_get_bitcoin_key_2(&this_ptr_conv).compressed_form, 33);
10867         return arg_arr;
10868 }
10869
10870 void UnsignedChannelAnnouncement_1set_1bitcoin_1key_12(void* ctx_TODO, uint32_t this_ptr, int8_tArray val) {
10871         LDKUnsignedChannelAnnouncement this_ptr_conv;
10872         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10873         this_ptr_conv.is_owned = false;
10874         LDKPublicKey val_ref;
10875         CHECK(val.len == 33);
10876         memcpy(val_ref.compressed_form, val.ptr, 33);
10877         UnsignedChannelAnnouncement_set_bitcoin_key_2(&this_ptr_conv, val_ref);
10878 }
10879
10880 void ChannelAnnouncement_1free(void* ctx_TODO, uint32_t this_ptr) {
10881         LDKChannelAnnouncement this_ptr_conv;
10882         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10883         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10884         ChannelAnnouncement_free(this_ptr_conv);
10885 }
10886
10887 uint32_t ChannelAnnouncement_1clone(void* ctx_TODO, uint32_t orig) {
10888         LDKChannelAnnouncement orig_conv;
10889         orig_conv.inner = (void*)(orig & (~1));
10890         orig_conv.is_owned = false;
10891         LDKChannelAnnouncement ret_var = ChannelAnnouncement_clone(&orig_conv);
10892         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10893         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10894         long ret_ref = (long)ret_var.inner;
10895         if (ret_var.is_owned) {
10896                 ret_ref |= 1;
10897         }
10898         return ret_ref;
10899 }
10900
10901 int8_tArray ChannelAnnouncement_1get_1node_1signature_11(void* ctx_TODO, uint32_t this_ptr) {
10902         LDKChannelAnnouncement this_ptr_conv;
10903         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10904         this_ptr_conv.is_owned = false;
10905         int8_tArray arg_arr = { .len = 64, .ptr = MALLOC(64, "Native int8_tArray Bytes") };
10906         memcpy(arg_arr.ptr, ChannelAnnouncement_get_node_signature_1(&this_ptr_conv).compact_form, 64);
10907         return arg_arr;
10908 }
10909
10910 void ChannelAnnouncement_1set_1node_1signature_11(void* ctx_TODO, uint32_t this_ptr, int8_tArray val) {
10911         LDKChannelAnnouncement this_ptr_conv;
10912         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10913         this_ptr_conv.is_owned = false;
10914         LDKSignature val_ref;
10915         CHECK(val.len == 64);
10916         memcpy(val_ref.compact_form, val.ptr, 64);
10917         ChannelAnnouncement_set_node_signature_1(&this_ptr_conv, val_ref);
10918 }
10919
10920 int8_tArray ChannelAnnouncement_1get_1node_1signature_12(void* ctx_TODO, uint32_t this_ptr) {
10921         LDKChannelAnnouncement this_ptr_conv;
10922         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10923         this_ptr_conv.is_owned = false;
10924         int8_tArray arg_arr = { .len = 64, .ptr = MALLOC(64, "Native int8_tArray Bytes") };
10925         memcpy(arg_arr.ptr, ChannelAnnouncement_get_node_signature_2(&this_ptr_conv).compact_form, 64);
10926         return arg_arr;
10927 }
10928
10929 void ChannelAnnouncement_1set_1node_1signature_12(void* ctx_TODO, uint32_t this_ptr, int8_tArray val) {
10930         LDKChannelAnnouncement this_ptr_conv;
10931         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10932         this_ptr_conv.is_owned = false;
10933         LDKSignature val_ref;
10934         CHECK(val.len == 64);
10935         memcpy(val_ref.compact_form, val.ptr, 64);
10936         ChannelAnnouncement_set_node_signature_2(&this_ptr_conv, val_ref);
10937 }
10938
10939 int8_tArray ChannelAnnouncement_1get_1bitcoin_1signature_11(void* ctx_TODO, uint32_t this_ptr) {
10940         LDKChannelAnnouncement this_ptr_conv;
10941         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10942         this_ptr_conv.is_owned = false;
10943         int8_tArray arg_arr = { .len = 64, .ptr = MALLOC(64, "Native int8_tArray Bytes") };
10944         memcpy(arg_arr.ptr, ChannelAnnouncement_get_bitcoin_signature_1(&this_ptr_conv).compact_form, 64);
10945         return arg_arr;
10946 }
10947
10948 void ChannelAnnouncement_1set_1bitcoin_1signature_11(void* ctx_TODO, uint32_t this_ptr, int8_tArray val) {
10949         LDKChannelAnnouncement this_ptr_conv;
10950         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10951         this_ptr_conv.is_owned = false;
10952         LDKSignature val_ref;
10953         CHECK(val.len == 64);
10954         memcpy(val_ref.compact_form, val.ptr, 64);
10955         ChannelAnnouncement_set_bitcoin_signature_1(&this_ptr_conv, val_ref);
10956 }
10957
10958 int8_tArray ChannelAnnouncement_1get_1bitcoin_1signature_12(void* ctx_TODO, uint32_t this_ptr) {
10959         LDKChannelAnnouncement this_ptr_conv;
10960         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10961         this_ptr_conv.is_owned = false;
10962         int8_tArray arg_arr = { .len = 64, .ptr = MALLOC(64, "Native int8_tArray Bytes") };
10963         memcpy(arg_arr.ptr, ChannelAnnouncement_get_bitcoin_signature_2(&this_ptr_conv).compact_form, 64);
10964         return arg_arr;
10965 }
10966
10967 void ChannelAnnouncement_1set_1bitcoin_1signature_12(void* ctx_TODO, uint32_t this_ptr, int8_tArray val) {
10968         LDKChannelAnnouncement this_ptr_conv;
10969         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10970         this_ptr_conv.is_owned = false;
10971         LDKSignature val_ref;
10972         CHECK(val.len == 64);
10973         memcpy(val_ref.compact_form, val.ptr, 64);
10974         ChannelAnnouncement_set_bitcoin_signature_2(&this_ptr_conv, val_ref);
10975 }
10976
10977 uint32_t ChannelAnnouncement_1get_1contents(void* ctx_TODO, uint32_t this_ptr) {
10978         LDKChannelAnnouncement this_ptr_conv;
10979         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10980         this_ptr_conv.is_owned = false;
10981         LDKUnsignedChannelAnnouncement ret_var = ChannelAnnouncement_get_contents(&this_ptr_conv);
10982         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10983         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10984         long ret_ref = (long)ret_var.inner;
10985         if (ret_var.is_owned) {
10986                 ret_ref |= 1;
10987         }
10988         return ret_ref;
10989 }
10990
10991 void ChannelAnnouncement_1set_1contents(void* ctx_TODO, uint32_t this_ptr, uint32_t val) {
10992         LDKChannelAnnouncement this_ptr_conv;
10993         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10994         this_ptr_conv.is_owned = false;
10995         LDKUnsignedChannelAnnouncement val_conv;
10996         val_conv.inner = (void*)(val & (~1));
10997         val_conv.is_owned = (val & 1) || (val == 0);
10998         if (val_conv.inner != NULL)
10999                 val_conv = UnsignedChannelAnnouncement_clone(&val_conv);
11000         ChannelAnnouncement_set_contents(&this_ptr_conv, val_conv);
11001 }
11002
11003 uint32_t ChannelAnnouncement_1new(void* ctx_TODO, int8_tArray node_signature_1_arg, int8_tArray node_signature_2_arg, int8_tArray bitcoin_signature_1_arg, int8_tArray bitcoin_signature_2_arg, uint32_t contents_arg) {
11004         LDKSignature node_signature_1_arg_ref;
11005         CHECK(node_signature_1_arg.len == 64);
11006         memcpy(node_signature_1_arg_ref.compact_form, node_signature_1_arg.ptr, 64);
11007         LDKSignature node_signature_2_arg_ref;
11008         CHECK(node_signature_2_arg.len == 64);
11009         memcpy(node_signature_2_arg_ref.compact_form, node_signature_2_arg.ptr, 64);
11010         LDKSignature bitcoin_signature_1_arg_ref;
11011         CHECK(bitcoin_signature_1_arg.len == 64);
11012         memcpy(bitcoin_signature_1_arg_ref.compact_form, bitcoin_signature_1_arg.ptr, 64);
11013         LDKSignature bitcoin_signature_2_arg_ref;
11014         CHECK(bitcoin_signature_2_arg.len == 64);
11015         memcpy(bitcoin_signature_2_arg_ref.compact_form, bitcoin_signature_2_arg.ptr, 64);
11016         LDKUnsignedChannelAnnouncement contents_arg_conv;
11017         contents_arg_conv.inner = (void*)(contents_arg & (~1));
11018         contents_arg_conv.is_owned = (contents_arg & 1) || (contents_arg == 0);
11019         if (contents_arg_conv.inner != NULL)
11020                 contents_arg_conv = UnsignedChannelAnnouncement_clone(&contents_arg_conv);
11021         LDKChannelAnnouncement ret_var = ChannelAnnouncement_new(node_signature_1_arg_ref, node_signature_2_arg_ref, bitcoin_signature_1_arg_ref, bitcoin_signature_2_arg_ref, contents_arg_conv);
11022         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11023         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11024         long ret_ref = (long)ret_var.inner;
11025         if (ret_var.is_owned) {
11026                 ret_ref |= 1;
11027         }
11028         return ret_ref;
11029 }
11030
11031 void UnsignedChannelUpdate_1free(void* ctx_TODO, uint32_t this_ptr) {
11032         LDKUnsignedChannelUpdate this_ptr_conv;
11033         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11034         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
11035         UnsignedChannelUpdate_free(this_ptr_conv);
11036 }
11037
11038 uint32_t UnsignedChannelUpdate_1clone(void* ctx_TODO, uint32_t orig) {
11039         LDKUnsignedChannelUpdate orig_conv;
11040         orig_conv.inner = (void*)(orig & (~1));
11041         orig_conv.is_owned = false;
11042         LDKUnsignedChannelUpdate ret_var = UnsignedChannelUpdate_clone(&orig_conv);
11043         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11044         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11045         long ret_ref = (long)ret_var.inner;
11046         if (ret_var.is_owned) {
11047                 ret_ref |= 1;
11048         }
11049         return ret_ref;
11050 }
11051
11052 int8_tArray UnsignedChannelUpdate_1get_1chain_1hash(void* ctx_TODO, uint32_t this_ptr) {
11053         LDKUnsignedChannelUpdate this_ptr_conv;
11054         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11055         this_ptr_conv.is_owned = false;
11056         int8_tArray ret_arr = { .len = 32, .ptr = MALLOC(32, "Native int8_tArray Bytes") };
11057         memcpy(ret_arr.ptr, *UnsignedChannelUpdate_get_chain_hash(&this_ptr_conv), 32);
11058         return ret_arr;
11059 }
11060
11061 void UnsignedChannelUpdate_1set_1chain_1hash(void* ctx_TODO, uint32_t this_ptr, int8_tArray val) {
11062         LDKUnsignedChannelUpdate this_ptr_conv;
11063         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11064         this_ptr_conv.is_owned = false;
11065         LDKThirtyTwoBytes val_ref;
11066         CHECK(val.len == 32);
11067         memcpy(val_ref.data, val.ptr, 32);
11068         UnsignedChannelUpdate_set_chain_hash(&this_ptr_conv, val_ref);
11069 }
11070
11071 int64_t UnsignedChannelUpdate_1get_1short_1channel_1id(void* ctx_TODO, uint32_t this_ptr) {
11072         LDKUnsignedChannelUpdate this_ptr_conv;
11073         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11074         this_ptr_conv.is_owned = false;
11075         int64_t ret_val = UnsignedChannelUpdate_get_short_channel_id(&this_ptr_conv);
11076         return ret_val;
11077 }
11078
11079 void UnsignedChannelUpdate_1set_1short_1channel_1id(void* ctx_TODO, uint32_t this_ptr, int64_t val) {
11080         LDKUnsignedChannelUpdate this_ptr_conv;
11081         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11082         this_ptr_conv.is_owned = false;
11083         UnsignedChannelUpdate_set_short_channel_id(&this_ptr_conv, val);
11084 }
11085
11086 int32_t UnsignedChannelUpdate_1get_1timestamp(void* ctx_TODO, uint32_t this_ptr) {
11087         LDKUnsignedChannelUpdate this_ptr_conv;
11088         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11089         this_ptr_conv.is_owned = false;
11090         int32_t ret_val = UnsignedChannelUpdate_get_timestamp(&this_ptr_conv);
11091         return ret_val;
11092 }
11093
11094 void UnsignedChannelUpdate_1set_1timestamp(void* ctx_TODO, uint32_t this_ptr, int32_t val) {
11095         LDKUnsignedChannelUpdate this_ptr_conv;
11096         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11097         this_ptr_conv.is_owned = false;
11098         UnsignedChannelUpdate_set_timestamp(&this_ptr_conv, val);
11099 }
11100
11101 int8_t UnsignedChannelUpdate_1get_1flags(void* ctx_TODO, uint32_t this_ptr) {
11102         LDKUnsignedChannelUpdate this_ptr_conv;
11103         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11104         this_ptr_conv.is_owned = false;
11105         int8_t ret_val = UnsignedChannelUpdate_get_flags(&this_ptr_conv);
11106         return ret_val;
11107 }
11108
11109 void UnsignedChannelUpdate_1set_1flags(void* ctx_TODO, uint32_t this_ptr, int8_t val) {
11110         LDKUnsignedChannelUpdate this_ptr_conv;
11111         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11112         this_ptr_conv.is_owned = false;
11113         UnsignedChannelUpdate_set_flags(&this_ptr_conv, val);
11114 }
11115
11116 int16_t UnsignedChannelUpdate_1get_1cltv_1expiry_1delta(void* ctx_TODO, uint32_t this_ptr) {
11117         LDKUnsignedChannelUpdate this_ptr_conv;
11118         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11119         this_ptr_conv.is_owned = false;
11120         int16_t ret_val = UnsignedChannelUpdate_get_cltv_expiry_delta(&this_ptr_conv);
11121         return ret_val;
11122 }
11123
11124 void UnsignedChannelUpdate_1set_1cltv_1expiry_1delta(void* ctx_TODO, uint32_t this_ptr, int16_t val) {
11125         LDKUnsignedChannelUpdate this_ptr_conv;
11126         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11127         this_ptr_conv.is_owned = false;
11128         UnsignedChannelUpdate_set_cltv_expiry_delta(&this_ptr_conv, val);
11129 }
11130
11131 int64_t UnsignedChannelUpdate_1get_1htlc_1minimum_1msat(void* ctx_TODO, uint32_t this_ptr) {
11132         LDKUnsignedChannelUpdate this_ptr_conv;
11133         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11134         this_ptr_conv.is_owned = false;
11135         int64_t ret_val = UnsignedChannelUpdate_get_htlc_minimum_msat(&this_ptr_conv);
11136         return ret_val;
11137 }
11138
11139 void UnsignedChannelUpdate_1set_1htlc_1minimum_1msat(void* ctx_TODO, uint32_t this_ptr, int64_t val) {
11140         LDKUnsignedChannelUpdate this_ptr_conv;
11141         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11142         this_ptr_conv.is_owned = false;
11143         UnsignedChannelUpdate_set_htlc_minimum_msat(&this_ptr_conv, val);
11144 }
11145
11146 int32_t UnsignedChannelUpdate_1get_1fee_1base_1msat(void* ctx_TODO, uint32_t this_ptr) {
11147         LDKUnsignedChannelUpdate this_ptr_conv;
11148         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11149         this_ptr_conv.is_owned = false;
11150         int32_t ret_val = UnsignedChannelUpdate_get_fee_base_msat(&this_ptr_conv);
11151         return ret_val;
11152 }
11153
11154 void UnsignedChannelUpdate_1set_1fee_1base_1msat(void* ctx_TODO, uint32_t this_ptr, int32_t val) {
11155         LDKUnsignedChannelUpdate this_ptr_conv;
11156         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11157         this_ptr_conv.is_owned = false;
11158         UnsignedChannelUpdate_set_fee_base_msat(&this_ptr_conv, val);
11159 }
11160
11161 int32_t UnsignedChannelUpdate_1get_1fee_1proportional_1millionths(void* ctx_TODO, uint32_t this_ptr) {
11162         LDKUnsignedChannelUpdate this_ptr_conv;
11163         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11164         this_ptr_conv.is_owned = false;
11165         int32_t ret_val = UnsignedChannelUpdate_get_fee_proportional_millionths(&this_ptr_conv);
11166         return ret_val;
11167 }
11168
11169 void UnsignedChannelUpdate_1set_1fee_1proportional_1millionths(void* ctx_TODO, uint32_t this_ptr, int32_t val) {
11170         LDKUnsignedChannelUpdate this_ptr_conv;
11171         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11172         this_ptr_conv.is_owned = false;
11173         UnsignedChannelUpdate_set_fee_proportional_millionths(&this_ptr_conv, val);
11174 }
11175
11176 void ChannelUpdate_1free(void* ctx_TODO, uint32_t this_ptr) {
11177         LDKChannelUpdate this_ptr_conv;
11178         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11179         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
11180         ChannelUpdate_free(this_ptr_conv);
11181 }
11182
11183 uint32_t ChannelUpdate_1clone(void* ctx_TODO, uint32_t orig) {
11184         LDKChannelUpdate orig_conv;
11185         orig_conv.inner = (void*)(orig & (~1));
11186         orig_conv.is_owned = false;
11187         LDKChannelUpdate ret_var = ChannelUpdate_clone(&orig_conv);
11188         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11189         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11190         long ret_ref = (long)ret_var.inner;
11191         if (ret_var.is_owned) {
11192                 ret_ref |= 1;
11193         }
11194         return ret_ref;
11195 }
11196
11197 int8_tArray ChannelUpdate_1get_1signature(void* ctx_TODO, uint32_t this_ptr) {
11198         LDKChannelUpdate this_ptr_conv;
11199         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11200         this_ptr_conv.is_owned = false;
11201         int8_tArray arg_arr = { .len = 64, .ptr = MALLOC(64, "Native int8_tArray Bytes") };
11202         memcpy(arg_arr.ptr, ChannelUpdate_get_signature(&this_ptr_conv).compact_form, 64);
11203         return arg_arr;
11204 }
11205
11206 void ChannelUpdate_1set_1signature(void* ctx_TODO, uint32_t this_ptr, int8_tArray val) {
11207         LDKChannelUpdate this_ptr_conv;
11208         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11209         this_ptr_conv.is_owned = false;
11210         LDKSignature val_ref;
11211         CHECK(val.len == 64);
11212         memcpy(val_ref.compact_form, val.ptr, 64);
11213         ChannelUpdate_set_signature(&this_ptr_conv, val_ref);
11214 }
11215
11216 uint32_t ChannelUpdate_1get_1contents(void* ctx_TODO, uint32_t this_ptr) {
11217         LDKChannelUpdate this_ptr_conv;
11218         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11219         this_ptr_conv.is_owned = false;
11220         LDKUnsignedChannelUpdate ret_var = ChannelUpdate_get_contents(&this_ptr_conv);
11221         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11222         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11223         long ret_ref = (long)ret_var.inner;
11224         if (ret_var.is_owned) {
11225                 ret_ref |= 1;
11226         }
11227         return ret_ref;
11228 }
11229
11230 void ChannelUpdate_1set_1contents(void* ctx_TODO, uint32_t this_ptr, uint32_t val) {
11231         LDKChannelUpdate this_ptr_conv;
11232         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11233         this_ptr_conv.is_owned = false;
11234         LDKUnsignedChannelUpdate val_conv;
11235         val_conv.inner = (void*)(val & (~1));
11236         val_conv.is_owned = (val & 1) || (val == 0);
11237         if (val_conv.inner != NULL)
11238                 val_conv = UnsignedChannelUpdate_clone(&val_conv);
11239         ChannelUpdate_set_contents(&this_ptr_conv, val_conv);
11240 }
11241
11242 uint32_t ChannelUpdate_1new(void* ctx_TODO, int8_tArray signature_arg, uint32_t contents_arg) {
11243         LDKSignature signature_arg_ref;
11244         CHECK(signature_arg.len == 64);
11245         memcpy(signature_arg_ref.compact_form, signature_arg.ptr, 64);
11246         LDKUnsignedChannelUpdate contents_arg_conv;
11247         contents_arg_conv.inner = (void*)(contents_arg & (~1));
11248         contents_arg_conv.is_owned = (contents_arg & 1) || (contents_arg == 0);
11249         if (contents_arg_conv.inner != NULL)
11250                 contents_arg_conv = UnsignedChannelUpdate_clone(&contents_arg_conv);
11251         LDKChannelUpdate ret_var = ChannelUpdate_new(signature_arg_ref, contents_arg_conv);
11252         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11253         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11254         long ret_ref = (long)ret_var.inner;
11255         if (ret_var.is_owned) {
11256                 ret_ref |= 1;
11257         }
11258         return ret_ref;
11259 }
11260
11261 void QueryChannelRange_1free(void* ctx_TODO, uint32_t this_ptr) {
11262         LDKQueryChannelRange this_ptr_conv;
11263         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11264         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
11265         QueryChannelRange_free(this_ptr_conv);
11266 }
11267
11268 uint32_t QueryChannelRange_1clone(void* ctx_TODO, uint32_t orig) {
11269         LDKQueryChannelRange orig_conv;
11270         orig_conv.inner = (void*)(orig & (~1));
11271         orig_conv.is_owned = false;
11272         LDKQueryChannelRange ret_var = QueryChannelRange_clone(&orig_conv);
11273         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11274         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11275         long ret_ref = (long)ret_var.inner;
11276         if (ret_var.is_owned) {
11277                 ret_ref |= 1;
11278         }
11279         return ret_ref;
11280 }
11281
11282 int8_tArray QueryChannelRange_1get_1chain_1hash(void* ctx_TODO, uint32_t this_ptr) {
11283         LDKQueryChannelRange this_ptr_conv;
11284         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11285         this_ptr_conv.is_owned = false;
11286         int8_tArray ret_arr = { .len = 32, .ptr = MALLOC(32, "Native int8_tArray Bytes") };
11287         memcpy(ret_arr.ptr, *QueryChannelRange_get_chain_hash(&this_ptr_conv), 32);
11288         return ret_arr;
11289 }
11290
11291 void QueryChannelRange_1set_1chain_1hash(void* ctx_TODO, uint32_t this_ptr, int8_tArray val) {
11292         LDKQueryChannelRange this_ptr_conv;
11293         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11294         this_ptr_conv.is_owned = false;
11295         LDKThirtyTwoBytes val_ref;
11296         CHECK(val.len == 32);
11297         memcpy(val_ref.data, val.ptr, 32);
11298         QueryChannelRange_set_chain_hash(&this_ptr_conv, val_ref);
11299 }
11300
11301 int32_t QueryChannelRange_1get_1first_1blocknum(void* ctx_TODO, uint32_t this_ptr) {
11302         LDKQueryChannelRange this_ptr_conv;
11303         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11304         this_ptr_conv.is_owned = false;
11305         int32_t ret_val = QueryChannelRange_get_first_blocknum(&this_ptr_conv);
11306         return ret_val;
11307 }
11308
11309 void QueryChannelRange_1set_1first_1blocknum(void* ctx_TODO, uint32_t this_ptr, int32_t val) {
11310         LDKQueryChannelRange this_ptr_conv;
11311         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11312         this_ptr_conv.is_owned = false;
11313         QueryChannelRange_set_first_blocknum(&this_ptr_conv, val);
11314 }
11315
11316 int32_t QueryChannelRange_1get_1number_1of_1blocks(void* ctx_TODO, uint32_t this_ptr) {
11317         LDKQueryChannelRange this_ptr_conv;
11318         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11319         this_ptr_conv.is_owned = false;
11320         int32_t ret_val = QueryChannelRange_get_number_of_blocks(&this_ptr_conv);
11321         return ret_val;
11322 }
11323
11324 void QueryChannelRange_1set_1number_1of_1blocks(void* ctx_TODO, uint32_t this_ptr, int32_t val) {
11325         LDKQueryChannelRange this_ptr_conv;
11326         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11327         this_ptr_conv.is_owned = false;
11328         QueryChannelRange_set_number_of_blocks(&this_ptr_conv, val);
11329 }
11330
11331 uint32_t QueryChannelRange_1new(void* ctx_TODO, int8_tArray chain_hash_arg, int32_t first_blocknum_arg, int32_t number_of_blocks_arg) {
11332         LDKThirtyTwoBytes chain_hash_arg_ref;
11333         CHECK(chain_hash_arg.len == 32);
11334         memcpy(chain_hash_arg_ref.data, chain_hash_arg.ptr, 32);
11335         LDKQueryChannelRange ret_var = QueryChannelRange_new(chain_hash_arg_ref, first_blocknum_arg, number_of_blocks_arg);
11336         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11337         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11338         long ret_ref = (long)ret_var.inner;
11339         if (ret_var.is_owned) {
11340                 ret_ref |= 1;
11341         }
11342         return ret_ref;
11343 }
11344
11345 void ReplyChannelRange_1free(void* ctx_TODO, uint32_t this_ptr) {
11346         LDKReplyChannelRange this_ptr_conv;
11347         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11348         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
11349         ReplyChannelRange_free(this_ptr_conv);
11350 }
11351
11352 uint32_t ReplyChannelRange_1clone(void* ctx_TODO, uint32_t orig) {
11353         LDKReplyChannelRange orig_conv;
11354         orig_conv.inner = (void*)(orig & (~1));
11355         orig_conv.is_owned = false;
11356         LDKReplyChannelRange ret_var = ReplyChannelRange_clone(&orig_conv);
11357         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11358         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11359         long ret_ref = (long)ret_var.inner;
11360         if (ret_var.is_owned) {
11361                 ret_ref |= 1;
11362         }
11363         return ret_ref;
11364 }
11365
11366 int8_tArray ReplyChannelRange_1get_1chain_1hash(void* ctx_TODO, uint32_t this_ptr) {
11367         LDKReplyChannelRange this_ptr_conv;
11368         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11369         this_ptr_conv.is_owned = false;
11370         int8_tArray ret_arr = { .len = 32, .ptr = MALLOC(32, "Native int8_tArray Bytes") };
11371         memcpy(ret_arr.ptr, *ReplyChannelRange_get_chain_hash(&this_ptr_conv), 32);
11372         return ret_arr;
11373 }
11374
11375 void ReplyChannelRange_1set_1chain_1hash(void* ctx_TODO, uint32_t this_ptr, int8_tArray val) {
11376         LDKReplyChannelRange this_ptr_conv;
11377         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11378         this_ptr_conv.is_owned = false;
11379         LDKThirtyTwoBytes val_ref;
11380         CHECK(val.len == 32);
11381         memcpy(val_ref.data, val.ptr, 32);
11382         ReplyChannelRange_set_chain_hash(&this_ptr_conv, val_ref);
11383 }
11384
11385 int32_t ReplyChannelRange_1get_1first_1blocknum(void* ctx_TODO, uint32_t this_ptr) {
11386         LDKReplyChannelRange this_ptr_conv;
11387         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11388         this_ptr_conv.is_owned = false;
11389         int32_t ret_val = ReplyChannelRange_get_first_blocknum(&this_ptr_conv);
11390         return ret_val;
11391 }
11392
11393 void ReplyChannelRange_1set_1first_1blocknum(void* ctx_TODO, uint32_t this_ptr, int32_t val) {
11394         LDKReplyChannelRange this_ptr_conv;
11395         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11396         this_ptr_conv.is_owned = false;
11397         ReplyChannelRange_set_first_blocknum(&this_ptr_conv, val);
11398 }
11399
11400 int32_t ReplyChannelRange_1get_1number_1of_1blocks(void* ctx_TODO, uint32_t this_ptr) {
11401         LDKReplyChannelRange this_ptr_conv;
11402         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11403         this_ptr_conv.is_owned = false;
11404         int32_t ret_val = ReplyChannelRange_get_number_of_blocks(&this_ptr_conv);
11405         return ret_val;
11406 }
11407
11408 void ReplyChannelRange_1set_1number_1of_1blocks(void* ctx_TODO, uint32_t this_ptr, int32_t val) {
11409         LDKReplyChannelRange this_ptr_conv;
11410         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11411         this_ptr_conv.is_owned = false;
11412         ReplyChannelRange_set_number_of_blocks(&this_ptr_conv, val);
11413 }
11414
11415 jboolean ReplyChannelRange_1get_1full_1information(void* ctx_TODO, uint32_t this_ptr) {
11416         LDKReplyChannelRange this_ptr_conv;
11417         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11418         this_ptr_conv.is_owned = false;
11419         jboolean ret_val = ReplyChannelRange_get_full_information(&this_ptr_conv);
11420         return ret_val;
11421 }
11422
11423 void ReplyChannelRange_1set_1full_1information(void* ctx_TODO, uint32_t this_ptr, jboolean val) {
11424         LDKReplyChannelRange this_ptr_conv;
11425         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11426         this_ptr_conv.is_owned = false;
11427         ReplyChannelRange_set_full_information(&this_ptr_conv, val);
11428 }
11429
11430 void ReplyChannelRange_1set_1short_1channel_1ids(void* ctx_TODO, uint32_t this_ptr, int64_tArray val) {
11431         LDKReplyChannelRange this_ptr_conv;
11432         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11433         this_ptr_conv.is_owned = false;
11434         LDKCVec_u64Z val_constr;
11435         val_constr.datalen = val.len;
11436         if (val_constr.datalen > 0)
11437                 val_constr.data = MALLOC(val_constr.datalen * sizeof(int64_t), "LDKCVec_u64Z Elements");
11438         else
11439                 val_constr.data = NULL;
11440         int64_t* val_vals = (int64_t*) val.ptr;
11441         for (size_t i = 0; i < val_constr.datalen; i++) {
11442                 int64_t arr_conv_8 = val_vals[i];
11443                 val_constr.data[i] = arr_conv_8;
11444         }
11445         ReplyChannelRange_set_short_channel_ids(&this_ptr_conv, val_constr);
11446 }
11447
11448 uint32_t ReplyChannelRange_1new(void* ctx_TODO, int8_tArray chain_hash_arg, int32_t first_blocknum_arg, int32_t number_of_blocks_arg, jboolean full_information_arg, int64_tArray short_channel_ids_arg) {
11449         LDKThirtyTwoBytes chain_hash_arg_ref;
11450         CHECK(chain_hash_arg.len == 32);
11451         memcpy(chain_hash_arg_ref.data, chain_hash_arg.ptr, 32);
11452         LDKCVec_u64Z short_channel_ids_arg_constr;
11453         short_channel_ids_arg_constr.datalen = short_channel_ids_arg.len;
11454         if (short_channel_ids_arg_constr.datalen > 0)
11455                 short_channel_ids_arg_constr.data = MALLOC(short_channel_ids_arg_constr.datalen * sizeof(int64_t), "LDKCVec_u64Z Elements");
11456         else
11457                 short_channel_ids_arg_constr.data = NULL;
11458         int64_t* short_channel_ids_arg_vals = (int64_t*) short_channel_ids_arg.ptr;
11459         for (size_t i = 0; i < short_channel_ids_arg_constr.datalen; i++) {
11460                 int64_t arr_conv_8 = short_channel_ids_arg_vals[i];
11461                 short_channel_ids_arg_constr.data[i] = arr_conv_8;
11462         }
11463         LDKReplyChannelRange ret_var = ReplyChannelRange_new(chain_hash_arg_ref, first_blocknum_arg, number_of_blocks_arg, full_information_arg, short_channel_ids_arg_constr);
11464         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11465         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11466         long ret_ref = (long)ret_var.inner;
11467         if (ret_var.is_owned) {
11468                 ret_ref |= 1;
11469         }
11470         return ret_ref;
11471 }
11472
11473 void QueryShortChannelIds_1free(void* ctx_TODO, uint32_t this_ptr) {
11474         LDKQueryShortChannelIds this_ptr_conv;
11475         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11476         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
11477         QueryShortChannelIds_free(this_ptr_conv);
11478 }
11479
11480 uint32_t QueryShortChannelIds_1clone(void* ctx_TODO, uint32_t orig) {
11481         LDKQueryShortChannelIds orig_conv;
11482         orig_conv.inner = (void*)(orig & (~1));
11483         orig_conv.is_owned = false;
11484         LDKQueryShortChannelIds ret_var = QueryShortChannelIds_clone(&orig_conv);
11485         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11486         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11487         long ret_ref = (long)ret_var.inner;
11488         if (ret_var.is_owned) {
11489                 ret_ref |= 1;
11490         }
11491         return ret_ref;
11492 }
11493
11494 int8_tArray QueryShortChannelIds_1get_1chain_1hash(void* ctx_TODO, uint32_t this_ptr) {
11495         LDKQueryShortChannelIds this_ptr_conv;
11496         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11497         this_ptr_conv.is_owned = false;
11498         int8_tArray ret_arr = { .len = 32, .ptr = MALLOC(32, "Native int8_tArray Bytes") };
11499         memcpy(ret_arr.ptr, *QueryShortChannelIds_get_chain_hash(&this_ptr_conv), 32);
11500         return ret_arr;
11501 }
11502
11503 void QueryShortChannelIds_1set_1chain_1hash(void* ctx_TODO, uint32_t this_ptr, int8_tArray val) {
11504         LDKQueryShortChannelIds this_ptr_conv;
11505         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11506         this_ptr_conv.is_owned = false;
11507         LDKThirtyTwoBytes val_ref;
11508         CHECK(val.len == 32);
11509         memcpy(val_ref.data, val.ptr, 32);
11510         QueryShortChannelIds_set_chain_hash(&this_ptr_conv, val_ref);
11511 }
11512
11513 void QueryShortChannelIds_1set_1short_1channel_1ids(void* ctx_TODO, uint32_t this_ptr, int64_tArray val) {
11514         LDKQueryShortChannelIds this_ptr_conv;
11515         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11516         this_ptr_conv.is_owned = false;
11517         LDKCVec_u64Z val_constr;
11518         val_constr.datalen = val.len;
11519         if (val_constr.datalen > 0)
11520                 val_constr.data = MALLOC(val_constr.datalen * sizeof(int64_t), "LDKCVec_u64Z Elements");
11521         else
11522                 val_constr.data = NULL;
11523         int64_t* val_vals = (int64_t*) val.ptr;
11524         for (size_t i = 0; i < val_constr.datalen; i++) {
11525                 int64_t arr_conv_8 = val_vals[i];
11526                 val_constr.data[i] = arr_conv_8;
11527         }
11528         QueryShortChannelIds_set_short_channel_ids(&this_ptr_conv, val_constr);
11529 }
11530
11531 uint32_t QueryShortChannelIds_1new(void* ctx_TODO, int8_tArray chain_hash_arg, int64_tArray short_channel_ids_arg) {
11532         LDKThirtyTwoBytes chain_hash_arg_ref;
11533         CHECK(chain_hash_arg.len == 32);
11534         memcpy(chain_hash_arg_ref.data, chain_hash_arg.ptr, 32);
11535         LDKCVec_u64Z short_channel_ids_arg_constr;
11536         short_channel_ids_arg_constr.datalen = short_channel_ids_arg.len;
11537         if (short_channel_ids_arg_constr.datalen > 0)
11538                 short_channel_ids_arg_constr.data = MALLOC(short_channel_ids_arg_constr.datalen * sizeof(int64_t), "LDKCVec_u64Z Elements");
11539         else
11540                 short_channel_ids_arg_constr.data = NULL;
11541         int64_t* short_channel_ids_arg_vals = (int64_t*) short_channel_ids_arg.ptr;
11542         for (size_t i = 0; i < short_channel_ids_arg_constr.datalen; i++) {
11543                 int64_t arr_conv_8 = short_channel_ids_arg_vals[i];
11544                 short_channel_ids_arg_constr.data[i] = arr_conv_8;
11545         }
11546         LDKQueryShortChannelIds ret_var = QueryShortChannelIds_new(chain_hash_arg_ref, short_channel_ids_arg_constr);
11547         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11548         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11549         long ret_ref = (long)ret_var.inner;
11550         if (ret_var.is_owned) {
11551                 ret_ref |= 1;
11552         }
11553         return ret_ref;
11554 }
11555
11556 void ReplyShortChannelIdsEnd_1free(void* ctx_TODO, uint32_t this_ptr) {
11557         LDKReplyShortChannelIdsEnd this_ptr_conv;
11558         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11559         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
11560         ReplyShortChannelIdsEnd_free(this_ptr_conv);
11561 }
11562
11563 uint32_t ReplyShortChannelIdsEnd_1clone(void* ctx_TODO, uint32_t orig) {
11564         LDKReplyShortChannelIdsEnd orig_conv;
11565         orig_conv.inner = (void*)(orig & (~1));
11566         orig_conv.is_owned = false;
11567         LDKReplyShortChannelIdsEnd ret_var = ReplyShortChannelIdsEnd_clone(&orig_conv);
11568         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11569         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11570         long ret_ref = (long)ret_var.inner;
11571         if (ret_var.is_owned) {
11572                 ret_ref |= 1;
11573         }
11574         return ret_ref;
11575 }
11576
11577 int8_tArray ReplyShortChannelIdsEnd_1get_1chain_1hash(void* ctx_TODO, uint32_t this_ptr) {
11578         LDKReplyShortChannelIdsEnd this_ptr_conv;
11579         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11580         this_ptr_conv.is_owned = false;
11581         int8_tArray ret_arr = { .len = 32, .ptr = MALLOC(32, "Native int8_tArray Bytes") };
11582         memcpy(ret_arr.ptr, *ReplyShortChannelIdsEnd_get_chain_hash(&this_ptr_conv), 32);
11583         return ret_arr;
11584 }
11585
11586 void ReplyShortChannelIdsEnd_1set_1chain_1hash(void* ctx_TODO, uint32_t this_ptr, int8_tArray val) {
11587         LDKReplyShortChannelIdsEnd this_ptr_conv;
11588         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11589         this_ptr_conv.is_owned = false;
11590         LDKThirtyTwoBytes val_ref;
11591         CHECK(val.len == 32);
11592         memcpy(val_ref.data, val.ptr, 32);
11593         ReplyShortChannelIdsEnd_set_chain_hash(&this_ptr_conv, val_ref);
11594 }
11595
11596 jboolean ReplyShortChannelIdsEnd_1get_1full_1information(void* ctx_TODO, uint32_t this_ptr) {
11597         LDKReplyShortChannelIdsEnd this_ptr_conv;
11598         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11599         this_ptr_conv.is_owned = false;
11600         jboolean ret_val = ReplyShortChannelIdsEnd_get_full_information(&this_ptr_conv);
11601         return ret_val;
11602 }
11603
11604 void ReplyShortChannelIdsEnd_1set_1full_1information(void* ctx_TODO, uint32_t this_ptr, jboolean val) {
11605         LDKReplyShortChannelIdsEnd this_ptr_conv;
11606         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11607         this_ptr_conv.is_owned = false;
11608         ReplyShortChannelIdsEnd_set_full_information(&this_ptr_conv, val);
11609 }
11610
11611 uint32_t ReplyShortChannelIdsEnd_1new(void* ctx_TODO, int8_tArray chain_hash_arg, jboolean full_information_arg) {
11612         LDKThirtyTwoBytes chain_hash_arg_ref;
11613         CHECK(chain_hash_arg.len == 32);
11614         memcpy(chain_hash_arg_ref.data, chain_hash_arg.ptr, 32);
11615         LDKReplyShortChannelIdsEnd ret_var = ReplyShortChannelIdsEnd_new(chain_hash_arg_ref, full_information_arg);
11616         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11617         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11618         long ret_ref = (long)ret_var.inner;
11619         if (ret_var.is_owned) {
11620                 ret_ref |= 1;
11621         }
11622         return ret_ref;
11623 }
11624
11625 void GossipTimestampFilter_1free(void* ctx_TODO, uint32_t this_ptr) {
11626         LDKGossipTimestampFilter this_ptr_conv;
11627         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11628         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
11629         GossipTimestampFilter_free(this_ptr_conv);
11630 }
11631
11632 uint32_t GossipTimestampFilter_1clone(void* ctx_TODO, uint32_t orig) {
11633         LDKGossipTimestampFilter orig_conv;
11634         orig_conv.inner = (void*)(orig & (~1));
11635         orig_conv.is_owned = false;
11636         LDKGossipTimestampFilter ret_var = GossipTimestampFilter_clone(&orig_conv);
11637         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11638         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11639         long ret_ref = (long)ret_var.inner;
11640         if (ret_var.is_owned) {
11641                 ret_ref |= 1;
11642         }
11643         return ret_ref;
11644 }
11645
11646 int8_tArray GossipTimestampFilter_1get_1chain_1hash(void* ctx_TODO, uint32_t this_ptr) {
11647         LDKGossipTimestampFilter this_ptr_conv;
11648         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11649         this_ptr_conv.is_owned = false;
11650         int8_tArray ret_arr = { .len = 32, .ptr = MALLOC(32, "Native int8_tArray Bytes") };
11651         memcpy(ret_arr.ptr, *GossipTimestampFilter_get_chain_hash(&this_ptr_conv), 32);
11652         return ret_arr;
11653 }
11654
11655 void GossipTimestampFilter_1set_1chain_1hash(void* ctx_TODO, uint32_t this_ptr, int8_tArray val) {
11656         LDKGossipTimestampFilter this_ptr_conv;
11657         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11658         this_ptr_conv.is_owned = false;
11659         LDKThirtyTwoBytes val_ref;
11660         CHECK(val.len == 32);
11661         memcpy(val_ref.data, val.ptr, 32);
11662         GossipTimestampFilter_set_chain_hash(&this_ptr_conv, val_ref);
11663 }
11664
11665 int32_t GossipTimestampFilter_1get_1first_1timestamp(void* ctx_TODO, uint32_t this_ptr) {
11666         LDKGossipTimestampFilter this_ptr_conv;
11667         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11668         this_ptr_conv.is_owned = false;
11669         int32_t ret_val = GossipTimestampFilter_get_first_timestamp(&this_ptr_conv);
11670         return ret_val;
11671 }
11672
11673 void GossipTimestampFilter_1set_1first_1timestamp(void* ctx_TODO, uint32_t this_ptr, int32_t val) {
11674         LDKGossipTimestampFilter this_ptr_conv;
11675         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11676         this_ptr_conv.is_owned = false;
11677         GossipTimestampFilter_set_first_timestamp(&this_ptr_conv, val);
11678 }
11679
11680 int32_t GossipTimestampFilter_1get_1timestamp_1range(void* ctx_TODO, uint32_t this_ptr) {
11681         LDKGossipTimestampFilter this_ptr_conv;
11682         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11683         this_ptr_conv.is_owned = false;
11684         int32_t ret_val = GossipTimestampFilter_get_timestamp_range(&this_ptr_conv);
11685         return ret_val;
11686 }
11687
11688 void GossipTimestampFilter_1set_1timestamp_1range(void* ctx_TODO, uint32_t this_ptr, int32_t val) {
11689         LDKGossipTimestampFilter this_ptr_conv;
11690         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11691         this_ptr_conv.is_owned = false;
11692         GossipTimestampFilter_set_timestamp_range(&this_ptr_conv, val);
11693 }
11694
11695 uint32_t GossipTimestampFilter_1new(void* ctx_TODO, int8_tArray chain_hash_arg, int32_t first_timestamp_arg, int32_t timestamp_range_arg) {
11696         LDKThirtyTwoBytes chain_hash_arg_ref;
11697         CHECK(chain_hash_arg.len == 32);
11698         memcpy(chain_hash_arg_ref.data, chain_hash_arg.ptr, 32);
11699         LDKGossipTimestampFilter ret_var = GossipTimestampFilter_new(chain_hash_arg_ref, first_timestamp_arg, timestamp_range_arg);
11700         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11701         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11702         long ret_ref = (long)ret_var.inner;
11703         if (ret_var.is_owned) {
11704                 ret_ref |= 1;
11705         }
11706         return ret_ref;
11707 }
11708
11709 void ErrorAction_1free(void* ctx_TODO, uint32_t this_ptr) {
11710         LDKErrorAction this_ptr_conv = *(LDKErrorAction*)this_ptr;
11711         FREE((void*)this_ptr);
11712         ErrorAction_free(this_ptr_conv);
11713 }
11714
11715 uint32_t ErrorAction_1clone(void* ctx_TODO, uint32_t orig) {
11716         LDKErrorAction* orig_conv = (LDKErrorAction*)orig;
11717         LDKErrorAction *ret_copy = MALLOC(sizeof(LDKErrorAction), "LDKErrorAction");
11718         *ret_copy = ErrorAction_clone(orig_conv);
11719         long ret_ref = (long)ret_copy;
11720         return ret_ref;
11721 }
11722
11723 void LightningError_1free(void* ctx_TODO, uint32_t this_ptr) {
11724         LDKLightningError this_ptr_conv;
11725         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11726         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
11727         LightningError_free(this_ptr_conv);
11728 }
11729
11730 jstring LightningError_1get_1err(void* ctx_TODO, uint32_t this_ptr) {
11731         LDKLightningError this_ptr_conv;
11732         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11733         this_ptr_conv.is_owned = false;
11734         LDKStr _str = LightningError_get_err(&this_ptr_conv);
11735         char* _buf = MALLOC(_str.len + 1, "str conv buf");
11736         memcpy(_buf, _str.chars, _str.len);
11737         _buf[_str.len] = 0;
11738         jstring _conv = conv_owned_string(_str.chars);
11739         FREE(_buf);
11740         return _conv;
11741 }
11742
11743 void LightningError_1set_1err(void* ctx_TODO, uint32_t this_ptr, int8_tArray val) {
11744         LDKLightningError this_ptr_conv;
11745         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11746         this_ptr_conv.is_owned = false;
11747         LDKCVec_u8Z val_ref;
11748         val_ref.datalen = val.len;
11749         val_ref.data = MALLOC(val_ref.datalen, "LDKCVec_u8Z Bytes");
11750         memcpy(val_ref.data, val.ptr, val_ref.datalen);
11751         LightningError_set_err(&this_ptr_conv, val_ref);
11752 }
11753
11754 uint32_t LightningError_1get_1action(void* ctx_TODO, uint32_t this_ptr) {
11755         LDKLightningError this_ptr_conv;
11756         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11757         this_ptr_conv.is_owned = false;
11758         LDKErrorAction *ret_copy = MALLOC(sizeof(LDKErrorAction), "LDKErrorAction");
11759         *ret_copy = LightningError_get_action(&this_ptr_conv);
11760         long ret_ref = (long)ret_copy;
11761         return ret_ref;
11762 }
11763
11764 void LightningError_1set_1action(void* ctx_TODO, uint32_t this_ptr, uint32_t val) {
11765         LDKLightningError this_ptr_conv;
11766         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11767         this_ptr_conv.is_owned = false;
11768         LDKErrorAction val_conv = *(LDKErrorAction*)val;
11769         FREE((void*)val);
11770         LightningError_set_action(&this_ptr_conv, val_conv);
11771 }
11772
11773 uint32_t LightningError_1new(void* ctx_TODO, int8_tArray err_arg, uint32_t action_arg) {
11774         LDKCVec_u8Z err_arg_ref;
11775         err_arg_ref.datalen = err_arg.len;
11776         err_arg_ref.data = MALLOC(err_arg_ref.datalen, "LDKCVec_u8Z Bytes");
11777         memcpy(err_arg_ref.data, err_arg.ptr, err_arg_ref.datalen);
11778         LDKErrorAction action_arg_conv = *(LDKErrorAction*)action_arg;
11779         FREE((void*)action_arg);
11780         LDKLightningError ret_var = LightningError_new(err_arg_ref, action_arg_conv);
11781         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11782         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11783         long ret_ref = (long)ret_var.inner;
11784         if (ret_var.is_owned) {
11785                 ret_ref |= 1;
11786         }
11787         return ret_ref;
11788 }
11789
11790 void CommitmentUpdate_1free(void* ctx_TODO, uint32_t this_ptr) {
11791         LDKCommitmentUpdate this_ptr_conv;
11792         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11793         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
11794         CommitmentUpdate_free(this_ptr_conv);
11795 }
11796
11797 uint32_t CommitmentUpdate_1clone(void* ctx_TODO, uint32_t orig) {
11798         LDKCommitmentUpdate orig_conv;
11799         orig_conv.inner = (void*)(orig & (~1));
11800         orig_conv.is_owned = false;
11801         LDKCommitmentUpdate ret_var = CommitmentUpdate_clone(&orig_conv);
11802         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11803         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11804         long ret_ref = (long)ret_var.inner;
11805         if (ret_var.is_owned) {
11806                 ret_ref |= 1;
11807         }
11808         return ret_ref;
11809 }
11810
11811 void CommitmentUpdate_1set_1update_1add_1htlcs(void* ctx_TODO, uint32_t this_ptr, uint32_tArray val) {
11812         LDKCommitmentUpdate this_ptr_conv;
11813         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11814         this_ptr_conv.is_owned = false;
11815         LDKCVec_UpdateAddHTLCZ val_constr;
11816         val_constr.datalen = val.len;
11817         if (val_constr.datalen > 0)
11818                 val_constr.data = MALLOC(val_constr.datalen * sizeof(LDKUpdateAddHTLC), "LDKCVec_UpdateAddHTLCZ Elements");
11819         else
11820                 val_constr.data = NULL;
11821         uint32_t* val_vals = (uint32_t*) val.ptr;
11822         for (size_t p = 0; p < val_constr.datalen; p++) {
11823                 uint32_t arr_conv_15 = val_vals[p];
11824                 LDKUpdateAddHTLC arr_conv_15_conv;
11825                 arr_conv_15_conv.inner = (void*)(arr_conv_15 & (~1));
11826                 arr_conv_15_conv.is_owned = (arr_conv_15 & 1) || (arr_conv_15 == 0);
11827                 if (arr_conv_15_conv.inner != NULL)
11828                         arr_conv_15_conv = UpdateAddHTLC_clone(&arr_conv_15_conv);
11829                 val_constr.data[p] = arr_conv_15_conv;
11830         }
11831         CommitmentUpdate_set_update_add_htlcs(&this_ptr_conv, val_constr);
11832 }
11833
11834 void CommitmentUpdate_1set_1update_1fulfill_1htlcs(void* ctx_TODO, uint32_t this_ptr, uint32_tArray val) {
11835         LDKCommitmentUpdate this_ptr_conv;
11836         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11837         this_ptr_conv.is_owned = false;
11838         LDKCVec_UpdateFulfillHTLCZ val_constr;
11839         val_constr.datalen = val.len;
11840         if (val_constr.datalen > 0)
11841                 val_constr.data = MALLOC(val_constr.datalen * sizeof(LDKUpdateFulfillHTLC), "LDKCVec_UpdateFulfillHTLCZ Elements");
11842         else
11843                 val_constr.data = NULL;
11844         uint32_t* val_vals = (uint32_t*) val.ptr;
11845         for (size_t t = 0; t < val_constr.datalen; t++) {
11846                 uint32_t arr_conv_19 = val_vals[t];
11847                 LDKUpdateFulfillHTLC arr_conv_19_conv;
11848                 arr_conv_19_conv.inner = (void*)(arr_conv_19 & (~1));
11849                 arr_conv_19_conv.is_owned = (arr_conv_19 & 1) || (arr_conv_19 == 0);
11850                 if (arr_conv_19_conv.inner != NULL)
11851                         arr_conv_19_conv = UpdateFulfillHTLC_clone(&arr_conv_19_conv);
11852                 val_constr.data[t] = arr_conv_19_conv;
11853         }
11854         CommitmentUpdate_set_update_fulfill_htlcs(&this_ptr_conv, val_constr);
11855 }
11856
11857 void CommitmentUpdate_1set_1update_1fail_1htlcs(void* ctx_TODO, uint32_t this_ptr, uint32_tArray val) {
11858         LDKCommitmentUpdate this_ptr_conv;
11859         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11860         this_ptr_conv.is_owned = false;
11861         LDKCVec_UpdateFailHTLCZ val_constr;
11862         val_constr.datalen = val.len;
11863         if (val_constr.datalen > 0)
11864                 val_constr.data = MALLOC(val_constr.datalen * sizeof(LDKUpdateFailHTLC), "LDKCVec_UpdateFailHTLCZ Elements");
11865         else
11866                 val_constr.data = NULL;
11867         uint32_t* val_vals = (uint32_t*) val.ptr;
11868         for (size_t q = 0; q < val_constr.datalen; q++) {
11869                 uint32_t arr_conv_16 = val_vals[q];
11870                 LDKUpdateFailHTLC arr_conv_16_conv;
11871                 arr_conv_16_conv.inner = (void*)(arr_conv_16 & (~1));
11872                 arr_conv_16_conv.is_owned = (arr_conv_16 & 1) || (arr_conv_16 == 0);
11873                 if (arr_conv_16_conv.inner != NULL)
11874                         arr_conv_16_conv = UpdateFailHTLC_clone(&arr_conv_16_conv);
11875                 val_constr.data[q] = arr_conv_16_conv;
11876         }
11877         CommitmentUpdate_set_update_fail_htlcs(&this_ptr_conv, val_constr);
11878 }
11879
11880 void CommitmentUpdate_1set_1update_1fail_1malformed_1htlcs(void* ctx_TODO, uint32_t this_ptr, uint32_tArray val) {
11881         LDKCommitmentUpdate this_ptr_conv;
11882         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11883         this_ptr_conv.is_owned = false;
11884         LDKCVec_UpdateFailMalformedHTLCZ val_constr;
11885         val_constr.datalen = val.len;
11886         if (val_constr.datalen > 0)
11887                 val_constr.data = MALLOC(val_constr.datalen * sizeof(LDKUpdateFailMalformedHTLC), "LDKCVec_UpdateFailMalformedHTLCZ Elements");
11888         else
11889                 val_constr.data = NULL;
11890         uint32_t* val_vals = (uint32_t*) val.ptr;
11891         for (size_t z = 0; z < val_constr.datalen; z++) {
11892                 uint32_t arr_conv_25 = val_vals[z];
11893                 LDKUpdateFailMalformedHTLC arr_conv_25_conv;
11894                 arr_conv_25_conv.inner = (void*)(arr_conv_25 & (~1));
11895                 arr_conv_25_conv.is_owned = (arr_conv_25 & 1) || (arr_conv_25 == 0);
11896                 if (arr_conv_25_conv.inner != NULL)
11897                         arr_conv_25_conv = UpdateFailMalformedHTLC_clone(&arr_conv_25_conv);
11898                 val_constr.data[z] = arr_conv_25_conv;
11899         }
11900         CommitmentUpdate_set_update_fail_malformed_htlcs(&this_ptr_conv, val_constr);
11901 }
11902
11903 uint32_t CommitmentUpdate_1get_1update_1fee(void* ctx_TODO, uint32_t this_ptr) {
11904         LDKCommitmentUpdate this_ptr_conv;
11905         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11906         this_ptr_conv.is_owned = false;
11907         LDKUpdateFee ret_var = CommitmentUpdate_get_update_fee(&this_ptr_conv);
11908         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11909         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11910         long ret_ref = (long)ret_var.inner;
11911         if (ret_var.is_owned) {
11912                 ret_ref |= 1;
11913         }
11914         return ret_ref;
11915 }
11916
11917 void CommitmentUpdate_1set_1update_1fee(void* ctx_TODO, uint32_t this_ptr, uint32_t val) {
11918         LDKCommitmentUpdate this_ptr_conv;
11919         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11920         this_ptr_conv.is_owned = false;
11921         LDKUpdateFee val_conv;
11922         val_conv.inner = (void*)(val & (~1));
11923         val_conv.is_owned = (val & 1) || (val == 0);
11924         if (val_conv.inner != NULL)
11925                 val_conv = UpdateFee_clone(&val_conv);
11926         CommitmentUpdate_set_update_fee(&this_ptr_conv, val_conv);
11927 }
11928
11929 uint32_t CommitmentUpdate_1get_1commitment_1signed(void* ctx_TODO, uint32_t this_ptr) {
11930         LDKCommitmentUpdate this_ptr_conv;
11931         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11932         this_ptr_conv.is_owned = false;
11933         LDKCommitmentSigned ret_var = CommitmentUpdate_get_commitment_signed(&this_ptr_conv);
11934         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11935         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11936         long ret_ref = (long)ret_var.inner;
11937         if (ret_var.is_owned) {
11938                 ret_ref |= 1;
11939         }
11940         return ret_ref;
11941 }
11942
11943 void CommitmentUpdate_1set_1commitment_1signed(void* ctx_TODO, uint32_t this_ptr, uint32_t val) {
11944         LDKCommitmentUpdate this_ptr_conv;
11945         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11946         this_ptr_conv.is_owned = false;
11947         LDKCommitmentSigned val_conv;
11948         val_conv.inner = (void*)(val & (~1));
11949         val_conv.is_owned = (val & 1) || (val == 0);
11950         if (val_conv.inner != NULL)
11951                 val_conv = CommitmentSigned_clone(&val_conv);
11952         CommitmentUpdate_set_commitment_signed(&this_ptr_conv, val_conv);
11953 }
11954
11955 uint32_t CommitmentUpdate_1new(void* ctx_TODO, uint32_tArray update_add_htlcs_arg, uint32_tArray update_fulfill_htlcs_arg, uint32_tArray update_fail_htlcs_arg, uint32_tArray update_fail_malformed_htlcs_arg, uint32_t update_fee_arg, uint32_t commitment_signed_arg) {
11956         LDKCVec_UpdateAddHTLCZ update_add_htlcs_arg_constr;
11957         update_add_htlcs_arg_constr.datalen = update_add_htlcs_arg.len;
11958         if (update_add_htlcs_arg_constr.datalen > 0)
11959                 update_add_htlcs_arg_constr.data = MALLOC(update_add_htlcs_arg_constr.datalen * sizeof(LDKUpdateAddHTLC), "LDKCVec_UpdateAddHTLCZ Elements");
11960         else
11961                 update_add_htlcs_arg_constr.data = NULL;
11962         uint32_t* update_add_htlcs_arg_vals = (uint32_t*) update_add_htlcs_arg.ptr;
11963         for (size_t p = 0; p < update_add_htlcs_arg_constr.datalen; p++) {
11964                 uint32_t arr_conv_15 = update_add_htlcs_arg_vals[p];
11965                 LDKUpdateAddHTLC arr_conv_15_conv;
11966                 arr_conv_15_conv.inner = (void*)(arr_conv_15 & (~1));
11967                 arr_conv_15_conv.is_owned = (arr_conv_15 & 1) || (arr_conv_15 == 0);
11968                 if (arr_conv_15_conv.inner != NULL)
11969                         arr_conv_15_conv = UpdateAddHTLC_clone(&arr_conv_15_conv);
11970                 update_add_htlcs_arg_constr.data[p] = arr_conv_15_conv;
11971         }
11972         LDKCVec_UpdateFulfillHTLCZ update_fulfill_htlcs_arg_constr;
11973         update_fulfill_htlcs_arg_constr.datalen = update_fulfill_htlcs_arg.len;
11974         if (update_fulfill_htlcs_arg_constr.datalen > 0)
11975                 update_fulfill_htlcs_arg_constr.data = MALLOC(update_fulfill_htlcs_arg_constr.datalen * sizeof(LDKUpdateFulfillHTLC), "LDKCVec_UpdateFulfillHTLCZ Elements");
11976         else
11977                 update_fulfill_htlcs_arg_constr.data = NULL;
11978         uint32_t* update_fulfill_htlcs_arg_vals = (uint32_t*) update_fulfill_htlcs_arg.ptr;
11979         for (size_t t = 0; t < update_fulfill_htlcs_arg_constr.datalen; t++) {
11980                 uint32_t arr_conv_19 = update_fulfill_htlcs_arg_vals[t];
11981                 LDKUpdateFulfillHTLC arr_conv_19_conv;
11982                 arr_conv_19_conv.inner = (void*)(arr_conv_19 & (~1));
11983                 arr_conv_19_conv.is_owned = (arr_conv_19 & 1) || (arr_conv_19 == 0);
11984                 if (arr_conv_19_conv.inner != NULL)
11985                         arr_conv_19_conv = UpdateFulfillHTLC_clone(&arr_conv_19_conv);
11986                 update_fulfill_htlcs_arg_constr.data[t] = arr_conv_19_conv;
11987         }
11988         LDKCVec_UpdateFailHTLCZ update_fail_htlcs_arg_constr;
11989         update_fail_htlcs_arg_constr.datalen = update_fail_htlcs_arg.len;
11990         if (update_fail_htlcs_arg_constr.datalen > 0)
11991                 update_fail_htlcs_arg_constr.data = MALLOC(update_fail_htlcs_arg_constr.datalen * sizeof(LDKUpdateFailHTLC), "LDKCVec_UpdateFailHTLCZ Elements");
11992         else
11993                 update_fail_htlcs_arg_constr.data = NULL;
11994         uint32_t* update_fail_htlcs_arg_vals = (uint32_t*) update_fail_htlcs_arg.ptr;
11995         for (size_t q = 0; q < update_fail_htlcs_arg_constr.datalen; q++) {
11996                 uint32_t arr_conv_16 = update_fail_htlcs_arg_vals[q];
11997                 LDKUpdateFailHTLC arr_conv_16_conv;
11998                 arr_conv_16_conv.inner = (void*)(arr_conv_16 & (~1));
11999                 arr_conv_16_conv.is_owned = (arr_conv_16 & 1) || (arr_conv_16 == 0);
12000                 if (arr_conv_16_conv.inner != NULL)
12001                         arr_conv_16_conv = UpdateFailHTLC_clone(&arr_conv_16_conv);
12002                 update_fail_htlcs_arg_constr.data[q] = arr_conv_16_conv;
12003         }
12004         LDKCVec_UpdateFailMalformedHTLCZ update_fail_malformed_htlcs_arg_constr;
12005         update_fail_malformed_htlcs_arg_constr.datalen = update_fail_malformed_htlcs_arg.len;
12006         if (update_fail_malformed_htlcs_arg_constr.datalen > 0)
12007                 update_fail_malformed_htlcs_arg_constr.data = MALLOC(update_fail_malformed_htlcs_arg_constr.datalen * sizeof(LDKUpdateFailMalformedHTLC), "LDKCVec_UpdateFailMalformedHTLCZ Elements");
12008         else
12009                 update_fail_malformed_htlcs_arg_constr.data = NULL;
12010         uint32_t* update_fail_malformed_htlcs_arg_vals = (uint32_t*) update_fail_malformed_htlcs_arg.ptr;
12011         for (size_t z = 0; z < update_fail_malformed_htlcs_arg_constr.datalen; z++) {
12012                 uint32_t arr_conv_25 = update_fail_malformed_htlcs_arg_vals[z];
12013                 LDKUpdateFailMalformedHTLC arr_conv_25_conv;
12014                 arr_conv_25_conv.inner = (void*)(arr_conv_25 & (~1));
12015                 arr_conv_25_conv.is_owned = (arr_conv_25 & 1) || (arr_conv_25 == 0);
12016                 if (arr_conv_25_conv.inner != NULL)
12017                         arr_conv_25_conv = UpdateFailMalformedHTLC_clone(&arr_conv_25_conv);
12018                 update_fail_malformed_htlcs_arg_constr.data[z] = arr_conv_25_conv;
12019         }
12020         LDKUpdateFee update_fee_arg_conv;
12021         update_fee_arg_conv.inner = (void*)(update_fee_arg & (~1));
12022         update_fee_arg_conv.is_owned = (update_fee_arg & 1) || (update_fee_arg == 0);
12023         if (update_fee_arg_conv.inner != NULL)
12024                 update_fee_arg_conv = UpdateFee_clone(&update_fee_arg_conv);
12025         LDKCommitmentSigned commitment_signed_arg_conv;
12026         commitment_signed_arg_conv.inner = (void*)(commitment_signed_arg & (~1));
12027         commitment_signed_arg_conv.is_owned = (commitment_signed_arg & 1) || (commitment_signed_arg == 0);
12028         if (commitment_signed_arg_conv.inner != NULL)
12029                 commitment_signed_arg_conv = CommitmentSigned_clone(&commitment_signed_arg_conv);
12030         LDKCommitmentUpdate ret_var = CommitmentUpdate_new(update_add_htlcs_arg_constr, update_fulfill_htlcs_arg_constr, update_fail_htlcs_arg_constr, update_fail_malformed_htlcs_arg_constr, update_fee_arg_conv, commitment_signed_arg_conv);
12031         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12032         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12033         long ret_ref = (long)ret_var.inner;
12034         if (ret_var.is_owned) {
12035                 ret_ref |= 1;
12036         }
12037         return ret_ref;
12038 }
12039
12040 void HTLCFailChannelUpdate_1free(void* ctx_TODO, uint32_t this_ptr) {
12041         LDKHTLCFailChannelUpdate this_ptr_conv = *(LDKHTLCFailChannelUpdate*)this_ptr;
12042         FREE((void*)this_ptr);
12043         HTLCFailChannelUpdate_free(this_ptr_conv);
12044 }
12045
12046 uint32_t HTLCFailChannelUpdate_1clone(void* ctx_TODO, uint32_t orig) {
12047         LDKHTLCFailChannelUpdate* orig_conv = (LDKHTLCFailChannelUpdate*)orig;
12048         LDKHTLCFailChannelUpdate *ret_copy = MALLOC(sizeof(LDKHTLCFailChannelUpdate), "LDKHTLCFailChannelUpdate");
12049         *ret_copy = HTLCFailChannelUpdate_clone(orig_conv);
12050         long ret_ref = (long)ret_copy;
12051         return ret_ref;
12052 }
12053
12054 void ChannelMessageHandler_1free(void* ctx_TODO, uint32_t this_ptr) {
12055         LDKChannelMessageHandler this_ptr_conv = *(LDKChannelMessageHandler*)this_ptr;
12056         FREE((void*)this_ptr);
12057         ChannelMessageHandler_free(this_ptr_conv);
12058 }
12059
12060 void RoutingMessageHandler_1free(void* ctx_TODO, uint32_t this_ptr) {
12061         LDKRoutingMessageHandler this_ptr_conv = *(LDKRoutingMessageHandler*)this_ptr;
12062         FREE((void*)this_ptr);
12063         RoutingMessageHandler_free(this_ptr_conv);
12064 }
12065
12066 int8_tArray AcceptChannel_1write(void* ctx_TODO, uint32_t obj) {
12067         LDKAcceptChannel obj_conv;
12068         obj_conv.inner = (void*)(obj & (~1));
12069         obj_conv.is_owned = false;
12070         LDKCVec_u8Z arg_var = AcceptChannel_write(&obj_conv);
12071         int8_tArray arg_arr = { .len = arg_var.datalen, .ptr = MALLOC(arg_var.datalen, "Native int8_tArray Bytes") };
12072         memcpy(arg_arr.ptr, arg_var.data, arg_var.datalen);
12073         CVec_u8Z_free(arg_var);
12074         return arg_arr;
12075 }
12076
12077 uint32_t AcceptChannel_1read(void* ctx_TODO, int8_tArray ser) {
12078         LDKu8slice ser_ref;
12079         ser_ref.datalen = ser.len;
12080         ser_ref.data = ser.ptr;
12081         LDKAcceptChannel ret_var = AcceptChannel_read(ser_ref);
12082         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12083         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12084         long ret_ref = (long)ret_var.inner;
12085         if (ret_var.is_owned) {
12086                 ret_ref |= 1;
12087         }
12088         return ret_ref;
12089 }
12090
12091 int8_tArray AnnouncementSignatures_1write(void* ctx_TODO, uint32_t obj) {
12092         LDKAnnouncementSignatures obj_conv;
12093         obj_conv.inner = (void*)(obj & (~1));
12094         obj_conv.is_owned = false;
12095         LDKCVec_u8Z arg_var = AnnouncementSignatures_write(&obj_conv);
12096         int8_tArray arg_arr = { .len = arg_var.datalen, .ptr = MALLOC(arg_var.datalen, "Native int8_tArray Bytes") };
12097         memcpy(arg_arr.ptr, arg_var.data, arg_var.datalen);
12098         CVec_u8Z_free(arg_var);
12099         return arg_arr;
12100 }
12101
12102 uint32_t AnnouncementSignatures_1read(void* ctx_TODO, int8_tArray ser) {
12103         LDKu8slice ser_ref;
12104         ser_ref.datalen = ser.len;
12105         ser_ref.data = ser.ptr;
12106         LDKAnnouncementSignatures ret_var = AnnouncementSignatures_read(ser_ref);
12107         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12108         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12109         long ret_ref = (long)ret_var.inner;
12110         if (ret_var.is_owned) {
12111                 ret_ref |= 1;
12112         }
12113         return ret_ref;
12114 }
12115
12116 int8_tArray ChannelReestablish_1write(void* ctx_TODO, uint32_t obj) {
12117         LDKChannelReestablish obj_conv;
12118         obj_conv.inner = (void*)(obj & (~1));
12119         obj_conv.is_owned = false;
12120         LDKCVec_u8Z arg_var = ChannelReestablish_write(&obj_conv);
12121         int8_tArray arg_arr = { .len = arg_var.datalen, .ptr = MALLOC(arg_var.datalen, "Native int8_tArray Bytes") };
12122         memcpy(arg_arr.ptr, arg_var.data, arg_var.datalen);
12123         CVec_u8Z_free(arg_var);
12124         return arg_arr;
12125 }
12126
12127 uint32_t ChannelReestablish_1read(void* ctx_TODO, int8_tArray ser) {
12128         LDKu8slice ser_ref;
12129         ser_ref.datalen = ser.len;
12130         ser_ref.data = ser.ptr;
12131         LDKCResult_ChannelReestablishDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ChannelReestablishDecodeErrorZ), "LDKCResult_ChannelReestablishDecodeErrorZ");
12132         *ret_conv = ChannelReestablish_read(ser_ref);
12133         return (long)ret_conv;
12134 }
12135
12136 int8_tArray ClosingSigned_1write(void* ctx_TODO, uint32_t obj) {
12137         LDKClosingSigned obj_conv;
12138         obj_conv.inner = (void*)(obj & (~1));
12139         obj_conv.is_owned = false;
12140         LDKCVec_u8Z arg_var = ClosingSigned_write(&obj_conv);
12141         int8_tArray arg_arr = { .len = arg_var.datalen, .ptr = MALLOC(arg_var.datalen, "Native int8_tArray Bytes") };
12142         memcpy(arg_arr.ptr, arg_var.data, arg_var.datalen);
12143         CVec_u8Z_free(arg_var);
12144         return arg_arr;
12145 }
12146
12147 uint32_t ClosingSigned_1read(void* ctx_TODO, int8_tArray ser) {
12148         LDKu8slice ser_ref;
12149         ser_ref.datalen = ser.len;
12150         ser_ref.data = ser.ptr;
12151         LDKClosingSigned ret_var = ClosingSigned_read(ser_ref);
12152         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12153         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12154         long ret_ref = (long)ret_var.inner;
12155         if (ret_var.is_owned) {
12156                 ret_ref |= 1;
12157         }
12158         return ret_ref;
12159 }
12160
12161 int8_tArray CommitmentSigned_1write(void* ctx_TODO, uint32_t obj) {
12162         LDKCommitmentSigned obj_conv;
12163         obj_conv.inner = (void*)(obj & (~1));
12164         obj_conv.is_owned = false;
12165         LDKCVec_u8Z arg_var = CommitmentSigned_write(&obj_conv);
12166         int8_tArray arg_arr = { .len = arg_var.datalen, .ptr = MALLOC(arg_var.datalen, "Native int8_tArray Bytes") };
12167         memcpy(arg_arr.ptr, arg_var.data, arg_var.datalen);
12168         CVec_u8Z_free(arg_var);
12169         return arg_arr;
12170 }
12171
12172 uint32_t CommitmentSigned_1read(void* ctx_TODO, int8_tArray ser) {
12173         LDKu8slice ser_ref;
12174         ser_ref.datalen = ser.len;
12175         ser_ref.data = ser.ptr;
12176         LDKCommitmentSigned ret_var = CommitmentSigned_read(ser_ref);
12177         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12178         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12179         long ret_ref = (long)ret_var.inner;
12180         if (ret_var.is_owned) {
12181                 ret_ref |= 1;
12182         }
12183         return ret_ref;
12184 }
12185
12186 int8_tArray FundingCreated_1write(void* ctx_TODO, uint32_t obj) {
12187         LDKFundingCreated obj_conv;
12188         obj_conv.inner = (void*)(obj & (~1));
12189         obj_conv.is_owned = false;
12190         LDKCVec_u8Z arg_var = FundingCreated_write(&obj_conv);
12191         int8_tArray arg_arr = { .len = arg_var.datalen, .ptr = MALLOC(arg_var.datalen, "Native int8_tArray Bytes") };
12192         memcpy(arg_arr.ptr, arg_var.data, arg_var.datalen);
12193         CVec_u8Z_free(arg_var);
12194         return arg_arr;
12195 }
12196
12197 uint32_t FundingCreated_1read(void* ctx_TODO, int8_tArray ser) {
12198         LDKu8slice ser_ref;
12199         ser_ref.datalen = ser.len;
12200         ser_ref.data = ser.ptr;
12201         LDKFundingCreated ret_var = FundingCreated_read(ser_ref);
12202         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12203         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12204         long ret_ref = (long)ret_var.inner;
12205         if (ret_var.is_owned) {
12206                 ret_ref |= 1;
12207         }
12208         return ret_ref;
12209 }
12210
12211 int8_tArray FundingSigned_1write(void* ctx_TODO, uint32_t obj) {
12212         LDKFundingSigned obj_conv;
12213         obj_conv.inner = (void*)(obj & (~1));
12214         obj_conv.is_owned = false;
12215         LDKCVec_u8Z arg_var = FundingSigned_write(&obj_conv);
12216         int8_tArray arg_arr = { .len = arg_var.datalen, .ptr = MALLOC(arg_var.datalen, "Native int8_tArray Bytes") };
12217         memcpy(arg_arr.ptr, arg_var.data, arg_var.datalen);
12218         CVec_u8Z_free(arg_var);
12219         return arg_arr;
12220 }
12221
12222 uint32_t FundingSigned_1read(void* ctx_TODO, int8_tArray ser) {
12223         LDKu8slice ser_ref;
12224         ser_ref.datalen = ser.len;
12225         ser_ref.data = ser.ptr;
12226         LDKFundingSigned ret_var = FundingSigned_read(ser_ref);
12227         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12228         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12229         long ret_ref = (long)ret_var.inner;
12230         if (ret_var.is_owned) {
12231                 ret_ref |= 1;
12232         }
12233         return ret_ref;
12234 }
12235
12236 int8_tArray FundingLocked_1write(void* ctx_TODO, uint32_t obj) {
12237         LDKFundingLocked obj_conv;
12238         obj_conv.inner = (void*)(obj & (~1));
12239         obj_conv.is_owned = false;
12240         LDKCVec_u8Z arg_var = FundingLocked_write(&obj_conv);
12241         int8_tArray arg_arr = { .len = arg_var.datalen, .ptr = MALLOC(arg_var.datalen, "Native int8_tArray Bytes") };
12242         memcpy(arg_arr.ptr, arg_var.data, arg_var.datalen);
12243         CVec_u8Z_free(arg_var);
12244         return arg_arr;
12245 }
12246
12247 uint32_t FundingLocked_1read(void* ctx_TODO, int8_tArray ser) {
12248         LDKu8slice ser_ref;
12249         ser_ref.datalen = ser.len;
12250         ser_ref.data = ser.ptr;
12251         LDKFundingLocked ret_var = FundingLocked_read(ser_ref);
12252         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12253         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12254         long ret_ref = (long)ret_var.inner;
12255         if (ret_var.is_owned) {
12256                 ret_ref |= 1;
12257         }
12258         return ret_ref;
12259 }
12260
12261 int8_tArray Init_1write(void* ctx_TODO, uint32_t obj) {
12262         LDKInit obj_conv;
12263         obj_conv.inner = (void*)(obj & (~1));
12264         obj_conv.is_owned = false;
12265         LDKCVec_u8Z arg_var = Init_write(&obj_conv);
12266         int8_tArray arg_arr = { .len = arg_var.datalen, .ptr = MALLOC(arg_var.datalen, "Native int8_tArray Bytes") };
12267         memcpy(arg_arr.ptr, arg_var.data, arg_var.datalen);
12268         CVec_u8Z_free(arg_var);
12269         return arg_arr;
12270 }
12271
12272 uint32_t Init_1read(void* ctx_TODO, int8_tArray ser) {
12273         LDKu8slice ser_ref;
12274         ser_ref.datalen = ser.len;
12275         ser_ref.data = ser.ptr;
12276         LDKCResult_InitDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_InitDecodeErrorZ), "LDKCResult_InitDecodeErrorZ");
12277         *ret_conv = Init_read(ser_ref);
12278         return (long)ret_conv;
12279 }
12280
12281 int8_tArray OpenChannel_1write(void* ctx_TODO, uint32_t obj) {
12282         LDKOpenChannel obj_conv;
12283         obj_conv.inner = (void*)(obj & (~1));
12284         obj_conv.is_owned = false;
12285         LDKCVec_u8Z arg_var = OpenChannel_write(&obj_conv);
12286         int8_tArray arg_arr = { .len = arg_var.datalen, .ptr = MALLOC(arg_var.datalen, "Native int8_tArray Bytes") };
12287         memcpy(arg_arr.ptr, arg_var.data, arg_var.datalen);
12288         CVec_u8Z_free(arg_var);
12289         return arg_arr;
12290 }
12291
12292 uint32_t OpenChannel_1read(void* ctx_TODO, int8_tArray ser) {
12293         LDKu8slice ser_ref;
12294         ser_ref.datalen = ser.len;
12295         ser_ref.data = ser.ptr;
12296         LDKOpenChannel ret_var = OpenChannel_read(ser_ref);
12297         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12298         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12299         long ret_ref = (long)ret_var.inner;
12300         if (ret_var.is_owned) {
12301                 ret_ref |= 1;
12302         }
12303         return ret_ref;
12304 }
12305
12306 int8_tArray RevokeAndACK_1write(void* ctx_TODO, uint32_t obj) {
12307         LDKRevokeAndACK obj_conv;
12308         obj_conv.inner = (void*)(obj & (~1));
12309         obj_conv.is_owned = false;
12310         LDKCVec_u8Z arg_var = RevokeAndACK_write(&obj_conv);
12311         int8_tArray arg_arr = { .len = arg_var.datalen, .ptr = MALLOC(arg_var.datalen, "Native int8_tArray Bytes") };
12312         memcpy(arg_arr.ptr, arg_var.data, arg_var.datalen);
12313         CVec_u8Z_free(arg_var);
12314         return arg_arr;
12315 }
12316
12317 uint32_t RevokeAndACK_1read(void* ctx_TODO, int8_tArray ser) {
12318         LDKu8slice ser_ref;
12319         ser_ref.datalen = ser.len;
12320         ser_ref.data = ser.ptr;
12321         LDKRevokeAndACK ret_var = RevokeAndACK_read(ser_ref);
12322         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12323         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12324         long ret_ref = (long)ret_var.inner;
12325         if (ret_var.is_owned) {
12326                 ret_ref |= 1;
12327         }
12328         return ret_ref;
12329 }
12330
12331 int8_tArray Shutdown_1write(void* ctx_TODO, uint32_t obj) {
12332         LDKShutdown obj_conv;
12333         obj_conv.inner = (void*)(obj & (~1));
12334         obj_conv.is_owned = false;
12335         LDKCVec_u8Z arg_var = Shutdown_write(&obj_conv);
12336         int8_tArray arg_arr = { .len = arg_var.datalen, .ptr = MALLOC(arg_var.datalen, "Native int8_tArray Bytes") };
12337         memcpy(arg_arr.ptr, arg_var.data, arg_var.datalen);
12338         CVec_u8Z_free(arg_var);
12339         return arg_arr;
12340 }
12341
12342 uint32_t Shutdown_1read(void* ctx_TODO, int8_tArray ser) {
12343         LDKu8slice ser_ref;
12344         ser_ref.datalen = ser.len;
12345         ser_ref.data = ser.ptr;
12346         LDKShutdown ret_var = Shutdown_read(ser_ref);
12347         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12348         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12349         long ret_ref = (long)ret_var.inner;
12350         if (ret_var.is_owned) {
12351                 ret_ref |= 1;
12352         }
12353         return ret_ref;
12354 }
12355
12356 int8_tArray UpdateFailHTLC_1write(void* ctx_TODO, uint32_t obj) {
12357         LDKUpdateFailHTLC obj_conv;
12358         obj_conv.inner = (void*)(obj & (~1));
12359         obj_conv.is_owned = false;
12360         LDKCVec_u8Z arg_var = UpdateFailHTLC_write(&obj_conv);
12361         int8_tArray arg_arr = { .len = arg_var.datalen, .ptr = MALLOC(arg_var.datalen, "Native int8_tArray Bytes") };
12362         memcpy(arg_arr.ptr, arg_var.data, arg_var.datalen);
12363         CVec_u8Z_free(arg_var);
12364         return arg_arr;
12365 }
12366
12367 uint32_t UpdateFailHTLC_1read(void* ctx_TODO, int8_tArray ser) {
12368         LDKu8slice ser_ref;
12369         ser_ref.datalen = ser.len;
12370         ser_ref.data = ser.ptr;
12371         LDKUpdateFailHTLC ret_var = UpdateFailHTLC_read(ser_ref);
12372         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12373         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12374         long ret_ref = (long)ret_var.inner;
12375         if (ret_var.is_owned) {
12376                 ret_ref |= 1;
12377         }
12378         return ret_ref;
12379 }
12380
12381 int8_tArray UpdateFailMalformedHTLC_1write(void* ctx_TODO, uint32_t obj) {
12382         LDKUpdateFailMalformedHTLC obj_conv;
12383         obj_conv.inner = (void*)(obj & (~1));
12384         obj_conv.is_owned = false;
12385         LDKCVec_u8Z arg_var = UpdateFailMalformedHTLC_write(&obj_conv);
12386         int8_tArray arg_arr = { .len = arg_var.datalen, .ptr = MALLOC(arg_var.datalen, "Native int8_tArray Bytes") };
12387         memcpy(arg_arr.ptr, arg_var.data, arg_var.datalen);
12388         CVec_u8Z_free(arg_var);
12389         return arg_arr;
12390 }
12391
12392 uint32_t UpdateFailMalformedHTLC_1read(void* ctx_TODO, int8_tArray ser) {
12393         LDKu8slice ser_ref;
12394         ser_ref.datalen = ser.len;
12395         ser_ref.data = ser.ptr;
12396         LDKUpdateFailMalformedHTLC ret_var = UpdateFailMalformedHTLC_read(ser_ref);
12397         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12398         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12399         long ret_ref = (long)ret_var.inner;
12400         if (ret_var.is_owned) {
12401                 ret_ref |= 1;
12402         }
12403         return ret_ref;
12404 }
12405
12406 int8_tArray UpdateFee_1write(void* ctx_TODO, uint32_t obj) {
12407         LDKUpdateFee obj_conv;
12408         obj_conv.inner = (void*)(obj & (~1));
12409         obj_conv.is_owned = false;
12410         LDKCVec_u8Z arg_var = UpdateFee_write(&obj_conv);
12411         int8_tArray arg_arr = { .len = arg_var.datalen, .ptr = MALLOC(arg_var.datalen, "Native int8_tArray Bytes") };
12412         memcpy(arg_arr.ptr, arg_var.data, arg_var.datalen);
12413         CVec_u8Z_free(arg_var);
12414         return arg_arr;
12415 }
12416
12417 uint32_t UpdateFee_1read(void* ctx_TODO, int8_tArray ser) {
12418         LDKu8slice ser_ref;
12419         ser_ref.datalen = ser.len;
12420         ser_ref.data = ser.ptr;
12421         LDKUpdateFee ret_var = UpdateFee_read(ser_ref);
12422         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12423         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12424         long ret_ref = (long)ret_var.inner;
12425         if (ret_var.is_owned) {
12426                 ret_ref |= 1;
12427         }
12428         return ret_ref;
12429 }
12430
12431 int8_tArray UpdateFulfillHTLC_1write(void* ctx_TODO, uint32_t obj) {
12432         LDKUpdateFulfillHTLC obj_conv;
12433         obj_conv.inner = (void*)(obj & (~1));
12434         obj_conv.is_owned = false;
12435         LDKCVec_u8Z arg_var = UpdateFulfillHTLC_write(&obj_conv);
12436         int8_tArray arg_arr = { .len = arg_var.datalen, .ptr = MALLOC(arg_var.datalen, "Native int8_tArray Bytes") };
12437         memcpy(arg_arr.ptr, arg_var.data, arg_var.datalen);
12438         CVec_u8Z_free(arg_var);
12439         return arg_arr;
12440 }
12441
12442 uint32_t UpdateFulfillHTLC_1read(void* ctx_TODO, int8_tArray ser) {
12443         LDKu8slice ser_ref;
12444         ser_ref.datalen = ser.len;
12445         ser_ref.data = ser.ptr;
12446         LDKUpdateFulfillHTLC ret_var = UpdateFulfillHTLC_read(ser_ref);
12447         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12448         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12449         long ret_ref = (long)ret_var.inner;
12450         if (ret_var.is_owned) {
12451                 ret_ref |= 1;
12452         }
12453         return ret_ref;
12454 }
12455
12456 int8_tArray UpdateAddHTLC_1write(void* ctx_TODO, uint32_t obj) {
12457         LDKUpdateAddHTLC obj_conv;
12458         obj_conv.inner = (void*)(obj & (~1));
12459         obj_conv.is_owned = false;
12460         LDKCVec_u8Z arg_var = UpdateAddHTLC_write(&obj_conv);
12461         int8_tArray arg_arr = { .len = arg_var.datalen, .ptr = MALLOC(arg_var.datalen, "Native int8_tArray Bytes") };
12462         memcpy(arg_arr.ptr, arg_var.data, arg_var.datalen);
12463         CVec_u8Z_free(arg_var);
12464         return arg_arr;
12465 }
12466
12467 uint32_t UpdateAddHTLC_1read(void* ctx_TODO, int8_tArray ser) {
12468         LDKu8slice ser_ref;
12469         ser_ref.datalen = ser.len;
12470         ser_ref.data = ser.ptr;
12471         LDKUpdateAddHTLC ret_var = UpdateAddHTLC_read(ser_ref);
12472         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12473         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12474         long ret_ref = (long)ret_var.inner;
12475         if (ret_var.is_owned) {
12476                 ret_ref |= 1;
12477         }
12478         return ret_ref;
12479 }
12480
12481 int8_tArray Ping_1write(void* ctx_TODO, uint32_t obj) {
12482         LDKPing obj_conv;
12483         obj_conv.inner = (void*)(obj & (~1));
12484         obj_conv.is_owned = false;
12485         LDKCVec_u8Z arg_var = Ping_write(&obj_conv);
12486         int8_tArray arg_arr = { .len = arg_var.datalen, .ptr = MALLOC(arg_var.datalen, "Native int8_tArray Bytes") };
12487         memcpy(arg_arr.ptr, arg_var.data, arg_var.datalen);
12488         CVec_u8Z_free(arg_var);
12489         return arg_arr;
12490 }
12491
12492 uint32_t Ping_1read(void* ctx_TODO, int8_tArray ser) {
12493         LDKu8slice ser_ref;
12494         ser_ref.datalen = ser.len;
12495         ser_ref.data = ser.ptr;
12496         LDKCResult_PingDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_PingDecodeErrorZ), "LDKCResult_PingDecodeErrorZ");
12497         *ret_conv = Ping_read(ser_ref);
12498         return (long)ret_conv;
12499 }
12500
12501 int8_tArray Pong_1write(void* ctx_TODO, uint32_t obj) {
12502         LDKPong obj_conv;
12503         obj_conv.inner = (void*)(obj & (~1));
12504         obj_conv.is_owned = false;
12505         LDKCVec_u8Z arg_var = Pong_write(&obj_conv);
12506         int8_tArray arg_arr = { .len = arg_var.datalen, .ptr = MALLOC(arg_var.datalen, "Native int8_tArray Bytes") };
12507         memcpy(arg_arr.ptr, arg_var.data, arg_var.datalen);
12508         CVec_u8Z_free(arg_var);
12509         return arg_arr;
12510 }
12511
12512 uint32_t Pong_1read(void* ctx_TODO, int8_tArray ser) {
12513         LDKu8slice ser_ref;
12514         ser_ref.datalen = ser.len;
12515         ser_ref.data = ser.ptr;
12516         LDKCResult_PongDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_PongDecodeErrorZ), "LDKCResult_PongDecodeErrorZ");
12517         *ret_conv = Pong_read(ser_ref);
12518         return (long)ret_conv;
12519 }
12520
12521 int8_tArray UnsignedChannelAnnouncement_1write(void* ctx_TODO, uint32_t obj) {
12522         LDKUnsignedChannelAnnouncement obj_conv;
12523         obj_conv.inner = (void*)(obj & (~1));
12524         obj_conv.is_owned = false;
12525         LDKCVec_u8Z arg_var = UnsignedChannelAnnouncement_write(&obj_conv);
12526         int8_tArray arg_arr = { .len = arg_var.datalen, .ptr = MALLOC(arg_var.datalen, "Native int8_tArray Bytes") };
12527         memcpy(arg_arr.ptr, arg_var.data, arg_var.datalen);
12528         CVec_u8Z_free(arg_var);
12529         return arg_arr;
12530 }
12531
12532 uint32_t UnsignedChannelAnnouncement_1read(void* ctx_TODO, int8_tArray ser) {
12533         LDKu8slice ser_ref;
12534         ser_ref.datalen = ser.len;
12535         ser_ref.data = ser.ptr;
12536         LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ), "LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ");
12537         *ret_conv = UnsignedChannelAnnouncement_read(ser_ref);
12538         return (long)ret_conv;
12539 }
12540
12541 int8_tArray ChannelAnnouncement_1write(void* ctx_TODO, uint32_t obj) {
12542         LDKChannelAnnouncement obj_conv;
12543         obj_conv.inner = (void*)(obj & (~1));
12544         obj_conv.is_owned = false;
12545         LDKCVec_u8Z arg_var = ChannelAnnouncement_write(&obj_conv);
12546         int8_tArray arg_arr = { .len = arg_var.datalen, .ptr = MALLOC(arg_var.datalen, "Native int8_tArray Bytes") };
12547         memcpy(arg_arr.ptr, arg_var.data, arg_var.datalen);
12548         CVec_u8Z_free(arg_var);
12549         return arg_arr;
12550 }
12551
12552 uint32_t ChannelAnnouncement_1read(void* ctx_TODO, int8_tArray ser) {
12553         LDKu8slice ser_ref;
12554         ser_ref.datalen = ser.len;
12555         ser_ref.data = ser.ptr;
12556         LDKChannelAnnouncement ret_var = ChannelAnnouncement_read(ser_ref);
12557         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12558         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12559         long ret_ref = (long)ret_var.inner;
12560         if (ret_var.is_owned) {
12561                 ret_ref |= 1;
12562         }
12563         return ret_ref;
12564 }
12565
12566 int8_tArray UnsignedChannelUpdate_1write(void* ctx_TODO, uint32_t obj) {
12567         LDKUnsignedChannelUpdate obj_conv;
12568         obj_conv.inner = (void*)(obj & (~1));
12569         obj_conv.is_owned = false;
12570         LDKCVec_u8Z arg_var = UnsignedChannelUpdate_write(&obj_conv);
12571         int8_tArray arg_arr = { .len = arg_var.datalen, .ptr = MALLOC(arg_var.datalen, "Native int8_tArray Bytes") };
12572         memcpy(arg_arr.ptr, arg_var.data, arg_var.datalen);
12573         CVec_u8Z_free(arg_var);
12574         return arg_arr;
12575 }
12576
12577 uint32_t UnsignedChannelUpdate_1read(void* ctx_TODO, int8_tArray ser) {
12578         LDKu8slice ser_ref;
12579         ser_ref.datalen = ser.len;
12580         ser_ref.data = ser.ptr;
12581         LDKCResult_UnsignedChannelUpdateDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_UnsignedChannelUpdateDecodeErrorZ), "LDKCResult_UnsignedChannelUpdateDecodeErrorZ");
12582         *ret_conv = UnsignedChannelUpdate_read(ser_ref);
12583         return (long)ret_conv;
12584 }
12585
12586 int8_tArray ChannelUpdate_1write(void* ctx_TODO, uint32_t obj) {
12587         LDKChannelUpdate obj_conv;
12588         obj_conv.inner = (void*)(obj & (~1));
12589         obj_conv.is_owned = false;
12590         LDKCVec_u8Z arg_var = ChannelUpdate_write(&obj_conv);
12591         int8_tArray arg_arr = { .len = arg_var.datalen, .ptr = MALLOC(arg_var.datalen, "Native int8_tArray Bytes") };
12592         memcpy(arg_arr.ptr, arg_var.data, arg_var.datalen);
12593         CVec_u8Z_free(arg_var);
12594         return arg_arr;
12595 }
12596
12597 uint32_t ChannelUpdate_1read(void* ctx_TODO, int8_tArray ser) {
12598         LDKu8slice ser_ref;
12599         ser_ref.datalen = ser.len;
12600         ser_ref.data = ser.ptr;
12601         LDKChannelUpdate ret_var = ChannelUpdate_read(ser_ref);
12602         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12603         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12604         long ret_ref = (long)ret_var.inner;
12605         if (ret_var.is_owned) {
12606                 ret_ref |= 1;
12607         }
12608         return ret_ref;
12609 }
12610
12611 int8_tArray ErrorMessage_1write(void* ctx_TODO, uint32_t obj) {
12612         LDKErrorMessage obj_conv;
12613         obj_conv.inner = (void*)(obj & (~1));
12614         obj_conv.is_owned = false;
12615         LDKCVec_u8Z arg_var = ErrorMessage_write(&obj_conv);
12616         int8_tArray arg_arr = { .len = arg_var.datalen, .ptr = MALLOC(arg_var.datalen, "Native int8_tArray Bytes") };
12617         memcpy(arg_arr.ptr, arg_var.data, arg_var.datalen);
12618         CVec_u8Z_free(arg_var);
12619         return arg_arr;
12620 }
12621
12622 uint32_t ErrorMessage_1read(void* ctx_TODO, int8_tArray ser) {
12623         LDKu8slice ser_ref;
12624         ser_ref.datalen = ser.len;
12625         ser_ref.data = ser.ptr;
12626         LDKCResult_ErrorMessageDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ErrorMessageDecodeErrorZ), "LDKCResult_ErrorMessageDecodeErrorZ");
12627         *ret_conv = ErrorMessage_read(ser_ref);
12628         return (long)ret_conv;
12629 }
12630
12631 int8_tArray UnsignedNodeAnnouncement_1write(void* ctx_TODO, uint32_t obj) {
12632         LDKUnsignedNodeAnnouncement obj_conv;
12633         obj_conv.inner = (void*)(obj & (~1));
12634         obj_conv.is_owned = false;
12635         LDKCVec_u8Z arg_var = UnsignedNodeAnnouncement_write(&obj_conv);
12636         int8_tArray arg_arr = { .len = arg_var.datalen, .ptr = MALLOC(arg_var.datalen, "Native int8_tArray Bytes") };
12637         memcpy(arg_arr.ptr, arg_var.data, arg_var.datalen);
12638         CVec_u8Z_free(arg_var);
12639         return arg_arr;
12640 }
12641
12642 uint32_t UnsignedNodeAnnouncement_1read(void* ctx_TODO, int8_tArray ser) {
12643         LDKu8slice ser_ref;
12644         ser_ref.datalen = ser.len;
12645         ser_ref.data = ser.ptr;
12646         LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ), "LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ");
12647         *ret_conv = UnsignedNodeAnnouncement_read(ser_ref);
12648         return (long)ret_conv;
12649 }
12650
12651 int8_tArray NodeAnnouncement_1write(void* ctx_TODO, uint32_t obj) {
12652         LDKNodeAnnouncement obj_conv;
12653         obj_conv.inner = (void*)(obj & (~1));
12654         obj_conv.is_owned = false;
12655         LDKCVec_u8Z arg_var = NodeAnnouncement_write(&obj_conv);
12656         int8_tArray arg_arr = { .len = arg_var.datalen, .ptr = MALLOC(arg_var.datalen, "Native int8_tArray Bytes") };
12657         memcpy(arg_arr.ptr, arg_var.data, arg_var.datalen);
12658         CVec_u8Z_free(arg_var);
12659         return arg_arr;
12660 }
12661
12662 uint32_t NodeAnnouncement_1read(void* ctx_TODO, int8_tArray ser) {
12663         LDKu8slice ser_ref;
12664         ser_ref.datalen = ser.len;
12665         ser_ref.data = ser.ptr;
12666         LDKNodeAnnouncement ret_var = NodeAnnouncement_read(ser_ref);
12667         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12668         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12669         long ret_ref = (long)ret_var.inner;
12670         if (ret_var.is_owned) {
12671                 ret_ref |= 1;
12672         }
12673         return ret_ref;
12674 }
12675
12676 uint32_t QueryShortChannelIds_1read(void* ctx_TODO, int8_tArray ser) {
12677         LDKu8slice ser_ref;
12678         ser_ref.datalen = ser.len;
12679         ser_ref.data = ser.ptr;
12680         LDKCResult_QueryShortChannelIdsDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_QueryShortChannelIdsDecodeErrorZ), "LDKCResult_QueryShortChannelIdsDecodeErrorZ");
12681         *ret_conv = QueryShortChannelIds_read(ser_ref);
12682         return (long)ret_conv;
12683 }
12684
12685 int8_tArray QueryShortChannelIds_1write(void* ctx_TODO, uint32_t obj) {
12686         LDKQueryShortChannelIds obj_conv;
12687         obj_conv.inner = (void*)(obj & (~1));
12688         obj_conv.is_owned = false;
12689         LDKCVec_u8Z arg_var = QueryShortChannelIds_write(&obj_conv);
12690         int8_tArray arg_arr = { .len = arg_var.datalen, .ptr = MALLOC(arg_var.datalen, "Native int8_tArray Bytes") };
12691         memcpy(arg_arr.ptr, arg_var.data, arg_var.datalen);
12692         CVec_u8Z_free(arg_var);
12693         return arg_arr;
12694 }
12695
12696 uint32_t ReplyShortChannelIdsEnd_1read(void* ctx_TODO, int8_tArray ser) {
12697         LDKu8slice ser_ref;
12698         ser_ref.datalen = ser.len;
12699         ser_ref.data = ser.ptr;
12700         LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ), "LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ");
12701         *ret_conv = ReplyShortChannelIdsEnd_read(ser_ref);
12702         return (long)ret_conv;
12703 }
12704
12705 int8_tArray ReplyShortChannelIdsEnd_1write(void* ctx_TODO, uint32_t obj) {
12706         LDKReplyShortChannelIdsEnd obj_conv;
12707         obj_conv.inner = (void*)(obj & (~1));
12708         obj_conv.is_owned = false;
12709         LDKCVec_u8Z arg_var = ReplyShortChannelIdsEnd_write(&obj_conv);
12710         int8_tArray arg_arr = { .len = arg_var.datalen, .ptr = MALLOC(arg_var.datalen, "Native int8_tArray Bytes") };
12711         memcpy(arg_arr.ptr, arg_var.data, arg_var.datalen);
12712         CVec_u8Z_free(arg_var);
12713         return arg_arr;
12714 }
12715
12716 uint32_t QueryChannelRange_1read(void* ctx_TODO, int8_tArray ser) {
12717         LDKu8slice ser_ref;
12718         ser_ref.datalen = ser.len;
12719         ser_ref.data = ser.ptr;
12720         LDKCResult_QueryChannelRangeDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_QueryChannelRangeDecodeErrorZ), "LDKCResult_QueryChannelRangeDecodeErrorZ");
12721         *ret_conv = QueryChannelRange_read(ser_ref);
12722         return (long)ret_conv;
12723 }
12724
12725 int8_tArray QueryChannelRange_1write(void* ctx_TODO, uint32_t obj) {
12726         LDKQueryChannelRange obj_conv;
12727         obj_conv.inner = (void*)(obj & (~1));
12728         obj_conv.is_owned = false;
12729         LDKCVec_u8Z arg_var = QueryChannelRange_write(&obj_conv);
12730         int8_tArray arg_arr = { .len = arg_var.datalen, .ptr = MALLOC(arg_var.datalen, "Native int8_tArray Bytes") };
12731         memcpy(arg_arr.ptr, arg_var.data, arg_var.datalen);
12732         CVec_u8Z_free(arg_var);
12733         return arg_arr;
12734 }
12735
12736 uint32_t ReplyChannelRange_1read(void* ctx_TODO, int8_tArray ser) {
12737         LDKu8slice ser_ref;
12738         ser_ref.datalen = ser.len;
12739         ser_ref.data = ser.ptr;
12740         LDKCResult_ReplyChannelRangeDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ReplyChannelRangeDecodeErrorZ), "LDKCResult_ReplyChannelRangeDecodeErrorZ");
12741         *ret_conv = ReplyChannelRange_read(ser_ref);
12742         return (long)ret_conv;
12743 }
12744
12745 int8_tArray ReplyChannelRange_1write(void* ctx_TODO, uint32_t obj) {
12746         LDKReplyChannelRange obj_conv;
12747         obj_conv.inner = (void*)(obj & (~1));
12748         obj_conv.is_owned = false;
12749         LDKCVec_u8Z arg_var = ReplyChannelRange_write(&obj_conv);
12750         int8_tArray arg_arr = { .len = arg_var.datalen, .ptr = MALLOC(arg_var.datalen, "Native int8_tArray Bytes") };
12751         memcpy(arg_arr.ptr, arg_var.data, arg_var.datalen);
12752         CVec_u8Z_free(arg_var);
12753         return arg_arr;
12754 }
12755
12756 uint32_t GossipTimestampFilter_1read(void* ctx_TODO, int8_tArray ser) {
12757         LDKu8slice ser_ref;
12758         ser_ref.datalen = ser.len;
12759         ser_ref.data = ser.ptr;
12760         LDKCResult_GossipTimestampFilterDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_GossipTimestampFilterDecodeErrorZ), "LDKCResult_GossipTimestampFilterDecodeErrorZ");
12761         *ret_conv = GossipTimestampFilter_read(ser_ref);
12762         return (long)ret_conv;
12763 }
12764
12765 int8_tArray GossipTimestampFilter_1write(void* ctx_TODO, uint32_t obj) {
12766         LDKGossipTimestampFilter obj_conv;
12767         obj_conv.inner = (void*)(obj & (~1));
12768         obj_conv.is_owned = false;
12769         LDKCVec_u8Z arg_var = GossipTimestampFilter_write(&obj_conv);
12770         int8_tArray arg_arr = { .len = arg_var.datalen, .ptr = MALLOC(arg_var.datalen, "Native int8_tArray Bytes") };
12771         memcpy(arg_arr.ptr, arg_var.data, arg_var.datalen);
12772         CVec_u8Z_free(arg_var);
12773         return arg_arr;
12774 }
12775
12776 void MessageHandler_1free(void* ctx_TODO, uint32_t this_ptr) {
12777         LDKMessageHandler this_ptr_conv;
12778         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12779         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12780         MessageHandler_free(this_ptr_conv);
12781 }
12782
12783 uint32_t MessageHandler_1get_1chan_1handler(void* ctx_TODO, uint32_t this_ptr) {
12784         LDKMessageHandler this_ptr_conv;
12785         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12786         this_ptr_conv.is_owned = false;
12787         long ret_ret = (long)MessageHandler_get_chan_handler(&this_ptr_conv);
12788         return ret_ret;
12789 }
12790
12791 void MessageHandler_1set_1chan_1handler(void* ctx_TODO, uint32_t this_ptr, uint32_t val) {
12792         LDKMessageHandler this_ptr_conv;
12793         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12794         this_ptr_conv.is_owned = false;
12795         LDKChannelMessageHandler val_conv = *(LDKChannelMessageHandler*)val;
12796         MessageHandler_set_chan_handler(&this_ptr_conv, val_conv);
12797 }
12798
12799 uint32_t MessageHandler_1get_1route_1handler(void* ctx_TODO, uint32_t this_ptr) {
12800         LDKMessageHandler this_ptr_conv;
12801         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12802         this_ptr_conv.is_owned = false;
12803         long ret_ret = (long)MessageHandler_get_route_handler(&this_ptr_conv);
12804         return ret_ret;
12805 }
12806
12807 void MessageHandler_1set_1route_1handler(void* ctx_TODO, uint32_t this_ptr, uint32_t val) {
12808         LDKMessageHandler this_ptr_conv;
12809         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12810         this_ptr_conv.is_owned = false;
12811         LDKRoutingMessageHandler val_conv = *(LDKRoutingMessageHandler*)val;
12812         MessageHandler_set_route_handler(&this_ptr_conv, val_conv);
12813 }
12814
12815 uint32_t MessageHandler_1new(void* ctx_TODO, uint32_t chan_handler_arg, uint32_t route_handler_arg) {
12816         LDKChannelMessageHandler chan_handler_arg_conv = *(LDKChannelMessageHandler*)chan_handler_arg;
12817         LDKRoutingMessageHandler route_handler_arg_conv = *(LDKRoutingMessageHandler*)route_handler_arg;
12818         LDKMessageHandler ret_var = MessageHandler_new(chan_handler_arg_conv, route_handler_arg_conv);
12819         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12820         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12821         long ret_ref = (long)ret_var.inner;
12822         if (ret_var.is_owned) {
12823                 ret_ref |= 1;
12824         }
12825         return ret_ref;
12826 }
12827
12828 uint32_t SocketDescriptor_1clone(void* ctx_TODO, uint32_t orig) {
12829         LDKSocketDescriptor* orig_conv = (LDKSocketDescriptor*)orig;
12830         LDKSocketDescriptor* ret = MALLOC(sizeof(LDKSocketDescriptor), "LDKSocketDescriptor");
12831         *ret = SocketDescriptor_clone(orig_conv);
12832         return (long)ret;
12833 }
12834
12835 void SocketDescriptor_1free(void* ctx_TODO, uint32_t this_ptr) {
12836         LDKSocketDescriptor this_ptr_conv = *(LDKSocketDescriptor*)this_ptr;
12837         FREE((void*)this_ptr);
12838         SocketDescriptor_free(this_ptr_conv);
12839 }
12840
12841 void PeerHandleError_1free(void* ctx_TODO, uint32_t this_ptr) {
12842         LDKPeerHandleError this_ptr_conv;
12843         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12844         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12845         PeerHandleError_free(this_ptr_conv);
12846 }
12847
12848 jboolean PeerHandleError_1get_1no_1connection_1possible(void* ctx_TODO, uint32_t this_ptr) {
12849         LDKPeerHandleError this_ptr_conv;
12850         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12851         this_ptr_conv.is_owned = false;
12852         jboolean ret_val = PeerHandleError_get_no_connection_possible(&this_ptr_conv);
12853         return ret_val;
12854 }
12855
12856 void PeerHandleError_1set_1no_1connection_1possible(void* ctx_TODO, uint32_t this_ptr, jboolean val) {
12857         LDKPeerHandleError this_ptr_conv;
12858         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12859         this_ptr_conv.is_owned = false;
12860         PeerHandleError_set_no_connection_possible(&this_ptr_conv, val);
12861 }
12862
12863 uint32_t PeerHandleError_1new(void* ctx_TODO, jboolean no_connection_possible_arg) {
12864         LDKPeerHandleError ret_var = PeerHandleError_new(no_connection_possible_arg);
12865         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12866         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12867         long ret_ref = (long)ret_var.inner;
12868         if (ret_var.is_owned) {
12869                 ret_ref |= 1;
12870         }
12871         return ret_ref;
12872 }
12873
12874 void PeerManager_1free(void* ctx_TODO, uint32_t this_ptr) {
12875         LDKPeerManager this_ptr_conv;
12876         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12877         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12878         PeerManager_free(this_ptr_conv);
12879 }
12880
12881 uint32_t PeerManager_1new(void* ctx_TODO, uint32_t message_handler, int8_tArray our_node_secret, int8_tArray ephemeral_random_data, uint32_t logger) {
12882         LDKMessageHandler message_handler_conv;
12883         message_handler_conv.inner = (void*)(message_handler & (~1));
12884         message_handler_conv.is_owned = (message_handler & 1) || (message_handler == 0);
12885         // Warning: we may need a move here but can't clone!
12886         LDKSecretKey our_node_secret_ref;
12887         CHECK(our_node_secret.len == 32);
12888         memcpy(our_node_secret_ref.bytes, our_node_secret.ptr, 32);
12889         unsigned char ephemeral_random_data_arr[32];
12890         CHECK(ephemeral_random_data.len == 32);
12891         memcpy(ephemeral_random_data_arr, ephemeral_random_data.ptr, 32);
12892         unsigned char (*ephemeral_random_data_ref)[32] = &ephemeral_random_data_arr;
12893         LDKLogger logger_conv = *(LDKLogger*)logger;
12894         LDKPeerManager ret_var = PeerManager_new(message_handler_conv, our_node_secret_ref, ephemeral_random_data_ref, logger_conv);
12895         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12896         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12897         long ret_ref = (long)ret_var.inner;
12898         if (ret_var.is_owned) {
12899                 ret_ref |= 1;
12900         }
12901         return ret_ref;
12902 }
12903
12904 ptrArray PeerManager_1get_1peer_1node_1ids(void* ctx_TODO, uint32_t this_arg) {
12905         LDKPeerManager this_arg_conv;
12906         this_arg_conv.inner = (void*)(this_arg & (~1));
12907         this_arg_conv.is_owned = false;
12908         LDKCVec_PublicKeyZ ret_var = PeerManager_get_peer_node_ids(&this_arg_conv);
12909         ptrArray ret_arr = { .len = ret_var.datalen, .ptr = MALLOC(ret_var.datalen * sizeof(int32_t), "Native Object Bytes") };
12910         int8_tArray *ret_arr_ptr = (int8_tArray*)ret_arr.ptr;
12911         for (size_t m = 0; m < ret_var.datalen; m++) {
12912                 int8_tArray arr_conv_12_arr = { .len = 33, .ptr = MALLOC(33, "Native int8_tArray Bytes") };
12913                 memcpy(arr_conv_12_arr.ptr, ret_var.data[m].compressed_form, 33);
12914                 ret_arr_ptr[m] = arr_conv_12_arr;
12915         }
12916         FREE(ret_var.data);
12917         return ret_arr;
12918 }
12919
12920 uint32_t PeerManager_1new_1outbound_1connection(void* ctx_TODO, uint32_t this_arg, int8_tArray their_node_id, uint32_t descriptor) {
12921         LDKPeerManager this_arg_conv;
12922         this_arg_conv.inner = (void*)(this_arg & (~1));
12923         this_arg_conv.is_owned = false;
12924         LDKPublicKey their_node_id_ref;
12925         CHECK(their_node_id.len == 33);
12926         memcpy(their_node_id_ref.compressed_form, their_node_id.ptr, 33);
12927         LDKSocketDescriptor descriptor_conv = *(LDKSocketDescriptor*)descriptor;
12928         LDKCResult_CVec_u8ZPeerHandleErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_CVec_u8ZPeerHandleErrorZ), "LDKCResult_CVec_u8ZPeerHandleErrorZ");
12929         *ret_conv = PeerManager_new_outbound_connection(&this_arg_conv, their_node_id_ref, descriptor_conv);
12930         return (long)ret_conv;
12931 }
12932
12933 uint32_t PeerManager_1new_1inbound_1connection(void* ctx_TODO, uint32_t this_arg, uint32_t descriptor) {
12934         LDKPeerManager this_arg_conv;
12935         this_arg_conv.inner = (void*)(this_arg & (~1));
12936         this_arg_conv.is_owned = false;
12937         LDKSocketDescriptor descriptor_conv = *(LDKSocketDescriptor*)descriptor;
12938         LDKCResult_NonePeerHandleErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NonePeerHandleErrorZ), "LDKCResult_NonePeerHandleErrorZ");
12939         *ret_conv = PeerManager_new_inbound_connection(&this_arg_conv, descriptor_conv);
12940         return (long)ret_conv;
12941 }
12942
12943 uint32_t PeerManager_1write_1buffer_1space_1avail(void* ctx_TODO, uint32_t this_arg, uint32_t descriptor) {
12944         LDKPeerManager this_arg_conv;
12945         this_arg_conv.inner = (void*)(this_arg & (~1));
12946         this_arg_conv.is_owned = false;
12947         LDKSocketDescriptor* descriptor_conv = (LDKSocketDescriptor*)descriptor;
12948         LDKCResult_NonePeerHandleErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NonePeerHandleErrorZ), "LDKCResult_NonePeerHandleErrorZ");
12949         *ret_conv = PeerManager_write_buffer_space_avail(&this_arg_conv, descriptor_conv);
12950         return (long)ret_conv;
12951 }
12952
12953 uint32_t PeerManager_1read_1event(void* ctx_TODO, uint32_t this_arg, uint32_t peer_descriptor, int8_tArray data) {
12954         LDKPeerManager this_arg_conv;
12955         this_arg_conv.inner = (void*)(this_arg & (~1));
12956         this_arg_conv.is_owned = false;
12957         LDKSocketDescriptor* peer_descriptor_conv = (LDKSocketDescriptor*)peer_descriptor;
12958         LDKu8slice data_ref;
12959         data_ref.datalen = data.len;
12960         data_ref.data = data.ptr;
12961         LDKCResult_boolPeerHandleErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_boolPeerHandleErrorZ), "LDKCResult_boolPeerHandleErrorZ");
12962         *ret_conv = PeerManager_read_event(&this_arg_conv, peer_descriptor_conv, data_ref);
12963         return (long)ret_conv;
12964 }
12965
12966 void PeerManager_1process_1events(void* ctx_TODO, uint32_t this_arg) {
12967         LDKPeerManager this_arg_conv;
12968         this_arg_conv.inner = (void*)(this_arg & (~1));
12969         this_arg_conv.is_owned = false;
12970         PeerManager_process_events(&this_arg_conv);
12971 }
12972
12973 void PeerManager_1socket_1disconnected(void* ctx_TODO, uint32_t this_arg, uint32_t descriptor) {
12974         LDKPeerManager this_arg_conv;
12975         this_arg_conv.inner = (void*)(this_arg & (~1));
12976         this_arg_conv.is_owned = false;
12977         LDKSocketDescriptor* descriptor_conv = (LDKSocketDescriptor*)descriptor;
12978         PeerManager_socket_disconnected(&this_arg_conv, descriptor_conv);
12979 }
12980
12981 void PeerManager_1timer_1tick_1occured(void* ctx_TODO, uint32_t this_arg) {
12982         LDKPeerManager this_arg_conv;
12983         this_arg_conv.inner = (void*)(this_arg & (~1));
12984         this_arg_conv.is_owned = false;
12985         PeerManager_timer_tick_occured(&this_arg_conv);
12986 }
12987
12988 int8_tArray build_1commitment_1secret(void* ctx_TODO, int8_tArray commitment_seed, int64_t idx) {
12989         unsigned char commitment_seed_arr[32];
12990         CHECK(commitment_seed.len == 32);
12991         memcpy(commitment_seed_arr, commitment_seed.ptr, 32);
12992         unsigned char (*commitment_seed_ref)[32] = &commitment_seed_arr;
12993         int8_tArray arg_arr = { .len = 32, .ptr = MALLOC(32, "Native int8_tArray Bytes") };
12994         memcpy(arg_arr.ptr, build_commitment_secret(commitment_seed_ref, idx).data, 32);
12995         return arg_arr;
12996 }
12997
12998 uint32_t derive_1private_1key(void* ctx_TODO, int8_tArray per_commitment_point, int8_tArray base_secret) {
12999         LDKPublicKey per_commitment_point_ref;
13000         CHECK(per_commitment_point.len == 33);
13001         memcpy(per_commitment_point_ref.compressed_form, per_commitment_point.ptr, 33);
13002         unsigned char base_secret_arr[32];
13003         CHECK(base_secret.len == 32);
13004         memcpy(base_secret_arr, base_secret.ptr, 32);
13005         unsigned char (*base_secret_ref)[32] = &base_secret_arr;
13006         LDKCResult_SecretKeySecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_SecretKeySecpErrorZ), "LDKCResult_SecretKeySecpErrorZ");
13007         *ret_conv = derive_private_key(per_commitment_point_ref, base_secret_ref);
13008         return (long)ret_conv;
13009 }
13010
13011 uint32_t derive_1public_1key(void* ctx_TODO, int8_tArray per_commitment_point, int8_tArray base_point) {
13012         LDKPublicKey per_commitment_point_ref;
13013         CHECK(per_commitment_point.len == 33);
13014         memcpy(per_commitment_point_ref.compressed_form, per_commitment_point.ptr, 33);
13015         LDKPublicKey base_point_ref;
13016         CHECK(base_point.len == 33);
13017         memcpy(base_point_ref.compressed_form, base_point.ptr, 33);
13018         LDKCResult_PublicKeySecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_PublicKeySecpErrorZ), "LDKCResult_PublicKeySecpErrorZ");
13019         *ret_conv = derive_public_key(per_commitment_point_ref, base_point_ref);
13020         return (long)ret_conv;
13021 }
13022
13023 uint32_t derive_1private_1revocation_1key(void* ctx_TODO, int8_tArray per_commitment_secret, int8_tArray countersignatory_revocation_base_secret) {
13024         unsigned char per_commitment_secret_arr[32];
13025         CHECK(per_commitment_secret.len == 32);
13026         memcpy(per_commitment_secret_arr, per_commitment_secret.ptr, 32);
13027         unsigned char (*per_commitment_secret_ref)[32] = &per_commitment_secret_arr;
13028         unsigned char countersignatory_revocation_base_secret_arr[32];
13029         CHECK(countersignatory_revocation_base_secret.len == 32);
13030         memcpy(countersignatory_revocation_base_secret_arr, countersignatory_revocation_base_secret.ptr, 32);
13031         unsigned char (*countersignatory_revocation_base_secret_ref)[32] = &countersignatory_revocation_base_secret_arr;
13032         LDKCResult_SecretKeySecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_SecretKeySecpErrorZ), "LDKCResult_SecretKeySecpErrorZ");
13033         *ret_conv = derive_private_revocation_key(per_commitment_secret_ref, countersignatory_revocation_base_secret_ref);
13034         return (long)ret_conv;
13035 }
13036
13037 uint32_t derive_1public_1revocation_1key(void* ctx_TODO, int8_tArray per_commitment_point, int8_tArray countersignatory_revocation_base_point) {
13038         LDKPublicKey per_commitment_point_ref;
13039         CHECK(per_commitment_point.len == 33);
13040         memcpy(per_commitment_point_ref.compressed_form, per_commitment_point.ptr, 33);
13041         LDKPublicKey countersignatory_revocation_base_point_ref;
13042         CHECK(countersignatory_revocation_base_point.len == 33);
13043         memcpy(countersignatory_revocation_base_point_ref.compressed_form, countersignatory_revocation_base_point.ptr, 33);
13044         LDKCResult_PublicKeySecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_PublicKeySecpErrorZ), "LDKCResult_PublicKeySecpErrorZ");
13045         *ret_conv = derive_public_revocation_key(per_commitment_point_ref, countersignatory_revocation_base_point_ref);
13046         return (long)ret_conv;
13047 }
13048
13049 void TxCreationKeys_1free(void* ctx_TODO, uint32_t this_ptr) {
13050         LDKTxCreationKeys this_ptr_conv;
13051         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13052         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13053         TxCreationKeys_free(this_ptr_conv);
13054 }
13055
13056 uint32_t TxCreationKeys_1clone(void* ctx_TODO, uint32_t orig) {
13057         LDKTxCreationKeys orig_conv;
13058         orig_conv.inner = (void*)(orig & (~1));
13059         orig_conv.is_owned = false;
13060         LDKTxCreationKeys ret_var = TxCreationKeys_clone(&orig_conv);
13061         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13062         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13063         long ret_ref = (long)ret_var.inner;
13064         if (ret_var.is_owned) {
13065                 ret_ref |= 1;
13066         }
13067         return ret_ref;
13068 }
13069
13070 int8_tArray TxCreationKeys_1get_1per_1commitment_1point(void* ctx_TODO, uint32_t this_ptr) {
13071         LDKTxCreationKeys this_ptr_conv;
13072         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13073         this_ptr_conv.is_owned = false;
13074         int8_tArray arg_arr = { .len = 33, .ptr = MALLOC(33, "Native int8_tArray Bytes") };
13075         memcpy(arg_arr.ptr, TxCreationKeys_get_per_commitment_point(&this_ptr_conv).compressed_form, 33);
13076         return arg_arr;
13077 }
13078
13079 void TxCreationKeys_1set_1per_1commitment_1point(void* ctx_TODO, uint32_t this_ptr, int8_tArray val) {
13080         LDKTxCreationKeys this_ptr_conv;
13081         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13082         this_ptr_conv.is_owned = false;
13083         LDKPublicKey val_ref;
13084         CHECK(val.len == 33);
13085         memcpy(val_ref.compressed_form, val.ptr, 33);
13086         TxCreationKeys_set_per_commitment_point(&this_ptr_conv, val_ref);
13087 }
13088
13089 int8_tArray TxCreationKeys_1get_1revocation_1key(void* ctx_TODO, uint32_t this_ptr) {
13090         LDKTxCreationKeys this_ptr_conv;
13091         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13092         this_ptr_conv.is_owned = false;
13093         int8_tArray arg_arr = { .len = 33, .ptr = MALLOC(33, "Native int8_tArray Bytes") };
13094         memcpy(arg_arr.ptr, TxCreationKeys_get_revocation_key(&this_ptr_conv).compressed_form, 33);
13095         return arg_arr;
13096 }
13097
13098 void TxCreationKeys_1set_1revocation_1key(void* ctx_TODO, uint32_t this_ptr, int8_tArray val) {
13099         LDKTxCreationKeys this_ptr_conv;
13100         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13101         this_ptr_conv.is_owned = false;
13102         LDKPublicKey val_ref;
13103         CHECK(val.len == 33);
13104         memcpy(val_ref.compressed_form, val.ptr, 33);
13105         TxCreationKeys_set_revocation_key(&this_ptr_conv, val_ref);
13106 }
13107
13108 int8_tArray TxCreationKeys_1get_1broadcaster_1htlc_1key(void* ctx_TODO, uint32_t this_ptr) {
13109         LDKTxCreationKeys this_ptr_conv;
13110         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13111         this_ptr_conv.is_owned = false;
13112         int8_tArray arg_arr = { .len = 33, .ptr = MALLOC(33, "Native int8_tArray Bytes") };
13113         memcpy(arg_arr.ptr, TxCreationKeys_get_broadcaster_htlc_key(&this_ptr_conv).compressed_form, 33);
13114         return arg_arr;
13115 }
13116
13117 void TxCreationKeys_1set_1broadcaster_1htlc_1key(void* ctx_TODO, uint32_t this_ptr, int8_tArray val) {
13118         LDKTxCreationKeys this_ptr_conv;
13119         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13120         this_ptr_conv.is_owned = false;
13121         LDKPublicKey val_ref;
13122         CHECK(val.len == 33);
13123         memcpy(val_ref.compressed_form, val.ptr, 33);
13124         TxCreationKeys_set_broadcaster_htlc_key(&this_ptr_conv, val_ref);
13125 }
13126
13127 int8_tArray TxCreationKeys_1get_1countersignatory_1htlc_1key(void* ctx_TODO, uint32_t this_ptr) {
13128         LDKTxCreationKeys this_ptr_conv;
13129         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13130         this_ptr_conv.is_owned = false;
13131         int8_tArray arg_arr = { .len = 33, .ptr = MALLOC(33, "Native int8_tArray Bytes") };
13132         memcpy(arg_arr.ptr, TxCreationKeys_get_countersignatory_htlc_key(&this_ptr_conv).compressed_form, 33);
13133         return arg_arr;
13134 }
13135
13136 void TxCreationKeys_1set_1countersignatory_1htlc_1key(void* ctx_TODO, uint32_t this_ptr, int8_tArray val) {
13137         LDKTxCreationKeys this_ptr_conv;
13138         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13139         this_ptr_conv.is_owned = false;
13140         LDKPublicKey val_ref;
13141         CHECK(val.len == 33);
13142         memcpy(val_ref.compressed_form, val.ptr, 33);
13143         TxCreationKeys_set_countersignatory_htlc_key(&this_ptr_conv, val_ref);
13144 }
13145
13146 int8_tArray TxCreationKeys_1get_1broadcaster_1delayed_1payment_1key(void* ctx_TODO, uint32_t this_ptr) {
13147         LDKTxCreationKeys this_ptr_conv;
13148         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13149         this_ptr_conv.is_owned = false;
13150         int8_tArray arg_arr = { .len = 33, .ptr = MALLOC(33, "Native int8_tArray Bytes") };
13151         memcpy(arg_arr.ptr, TxCreationKeys_get_broadcaster_delayed_payment_key(&this_ptr_conv).compressed_form, 33);
13152         return arg_arr;
13153 }
13154
13155 void TxCreationKeys_1set_1broadcaster_1delayed_1payment_1key(void* ctx_TODO, uint32_t this_ptr, int8_tArray val) {
13156         LDKTxCreationKeys this_ptr_conv;
13157         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13158         this_ptr_conv.is_owned = false;
13159         LDKPublicKey val_ref;
13160         CHECK(val.len == 33);
13161         memcpy(val_ref.compressed_form, val.ptr, 33);
13162         TxCreationKeys_set_broadcaster_delayed_payment_key(&this_ptr_conv, val_ref);
13163 }
13164
13165 uint32_t TxCreationKeys_1new(void* ctx_TODO, int8_tArray per_commitment_point_arg, int8_tArray revocation_key_arg, int8_tArray broadcaster_htlc_key_arg, int8_tArray countersignatory_htlc_key_arg, int8_tArray broadcaster_delayed_payment_key_arg) {
13166         LDKPublicKey per_commitment_point_arg_ref;
13167         CHECK(per_commitment_point_arg.len == 33);
13168         memcpy(per_commitment_point_arg_ref.compressed_form, per_commitment_point_arg.ptr, 33);
13169         LDKPublicKey revocation_key_arg_ref;
13170         CHECK(revocation_key_arg.len == 33);
13171         memcpy(revocation_key_arg_ref.compressed_form, revocation_key_arg.ptr, 33);
13172         LDKPublicKey broadcaster_htlc_key_arg_ref;
13173         CHECK(broadcaster_htlc_key_arg.len == 33);
13174         memcpy(broadcaster_htlc_key_arg_ref.compressed_form, broadcaster_htlc_key_arg.ptr, 33);
13175         LDKPublicKey countersignatory_htlc_key_arg_ref;
13176         CHECK(countersignatory_htlc_key_arg.len == 33);
13177         memcpy(countersignatory_htlc_key_arg_ref.compressed_form, countersignatory_htlc_key_arg.ptr, 33);
13178         LDKPublicKey broadcaster_delayed_payment_key_arg_ref;
13179         CHECK(broadcaster_delayed_payment_key_arg.len == 33);
13180         memcpy(broadcaster_delayed_payment_key_arg_ref.compressed_form, broadcaster_delayed_payment_key_arg.ptr, 33);
13181         LDKTxCreationKeys ret_var = TxCreationKeys_new(per_commitment_point_arg_ref, revocation_key_arg_ref, broadcaster_htlc_key_arg_ref, countersignatory_htlc_key_arg_ref, broadcaster_delayed_payment_key_arg_ref);
13182         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13183         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13184         long ret_ref = (long)ret_var.inner;
13185         if (ret_var.is_owned) {
13186                 ret_ref |= 1;
13187         }
13188         return ret_ref;
13189 }
13190
13191 int8_tArray TxCreationKeys_1write(void* ctx_TODO, uint32_t obj) {
13192         LDKTxCreationKeys obj_conv;
13193         obj_conv.inner = (void*)(obj & (~1));
13194         obj_conv.is_owned = false;
13195         LDKCVec_u8Z arg_var = TxCreationKeys_write(&obj_conv);
13196         int8_tArray arg_arr = { .len = arg_var.datalen, .ptr = MALLOC(arg_var.datalen, "Native int8_tArray Bytes") };
13197         memcpy(arg_arr.ptr, arg_var.data, arg_var.datalen);
13198         CVec_u8Z_free(arg_var);
13199         return arg_arr;
13200 }
13201
13202 uint32_t TxCreationKeys_1read(void* ctx_TODO, int8_tArray ser) {
13203         LDKu8slice ser_ref;
13204         ser_ref.datalen = ser.len;
13205         ser_ref.data = ser.ptr;
13206         LDKTxCreationKeys ret_var = TxCreationKeys_read(ser_ref);
13207         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13208         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13209         long ret_ref = (long)ret_var.inner;
13210         if (ret_var.is_owned) {
13211                 ret_ref |= 1;
13212         }
13213         return ret_ref;
13214 }
13215
13216 void ChannelPublicKeys_1free(void* ctx_TODO, uint32_t this_ptr) {
13217         LDKChannelPublicKeys this_ptr_conv;
13218         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13219         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13220         ChannelPublicKeys_free(this_ptr_conv);
13221 }
13222
13223 uint32_t ChannelPublicKeys_1clone(void* ctx_TODO, uint32_t orig) {
13224         LDKChannelPublicKeys orig_conv;
13225         orig_conv.inner = (void*)(orig & (~1));
13226         orig_conv.is_owned = false;
13227         LDKChannelPublicKeys ret_var = ChannelPublicKeys_clone(&orig_conv);
13228         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13229         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13230         long ret_ref = (long)ret_var.inner;
13231         if (ret_var.is_owned) {
13232                 ret_ref |= 1;
13233         }
13234         return ret_ref;
13235 }
13236
13237 int8_tArray ChannelPublicKeys_1get_1funding_1pubkey(void* ctx_TODO, uint32_t this_ptr) {
13238         LDKChannelPublicKeys this_ptr_conv;
13239         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13240         this_ptr_conv.is_owned = false;
13241         int8_tArray arg_arr = { .len = 33, .ptr = MALLOC(33, "Native int8_tArray Bytes") };
13242         memcpy(arg_arr.ptr, ChannelPublicKeys_get_funding_pubkey(&this_ptr_conv).compressed_form, 33);
13243         return arg_arr;
13244 }
13245
13246 void ChannelPublicKeys_1set_1funding_1pubkey(void* ctx_TODO, uint32_t this_ptr, int8_tArray val) {
13247         LDKChannelPublicKeys this_ptr_conv;
13248         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13249         this_ptr_conv.is_owned = false;
13250         LDKPublicKey val_ref;
13251         CHECK(val.len == 33);
13252         memcpy(val_ref.compressed_form, val.ptr, 33);
13253         ChannelPublicKeys_set_funding_pubkey(&this_ptr_conv, val_ref);
13254 }
13255
13256 int8_tArray ChannelPublicKeys_1get_1revocation_1basepoint(void* ctx_TODO, uint32_t this_ptr) {
13257         LDKChannelPublicKeys this_ptr_conv;
13258         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13259         this_ptr_conv.is_owned = false;
13260         int8_tArray arg_arr = { .len = 33, .ptr = MALLOC(33, "Native int8_tArray Bytes") };
13261         memcpy(arg_arr.ptr, ChannelPublicKeys_get_revocation_basepoint(&this_ptr_conv).compressed_form, 33);
13262         return arg_arr;
13263 }
13264
13265 void ChannelPublicKeys_1set_1revocation_1basepoint(void* ctx_TODO, uint32_t this_ptr, int8_tArray val) {
13266         LDKChannelPublicKeys this_ptr_conv;
13267         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13268         this_ptr_conv.is_owned = false;
13269         LDKPublicKey val_ref;
13270         CHECK(val.len == 33);
13271         memcpy(val_ref.compressed_form, val.ptr, 33);
13272         ChannelPublicKeys_set_revocation_basepoint(&this_ptr_conv, val_ref);
13273 }
13274
13275 int8_tArray ChannelPublicKeys_1get_1payment_1point(void* ctx_TODO, uint32_t this_ptr) {
13276         LDKChannelPublicKeys this_ptr_conv;
13277         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13278         this_ptr_conv.is_owned = false;
13279         int8_tArray arg_arr = { .len = 33, .ptr = MALLOC(33, "Native int8_tArray Bytes") };
13280         memcpy(arg_arr.ptr, ChannelPublicKeys_get_payment_point(&this_ptr_conv).compressed_form, 33);
13281         return arg_arr;
13282 }
13283
13284 void ChannelPublicKeys_1set_1payment_1point(void* ctx_TODO, uint32_t this_ptr, int8_tArray val) {
13285         LDKChannelPublicKeys this_ptr_conv;
13286         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13287         this_ptr_conv.is_owned = false;
13288         LDKPublicKey val_ref;
13289         CHECK(val.len == 33);
13290         memcpy(val_ref.compressed_form, val.ptr, 33);
13291         ChannelPublicKeys_set_payment_point(&this_ptr_conv, val_ref);
13292 }
13293
13294 int8_tArray ChannelPublicKeys_1get_1delayed_1payment_1basepoint(void* ctx_TODO, uint32_t this_ptr) {
13295         LDKChannelPublicKeys this_ptr_conv;
13296         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13297         this_ptr_conv.is_owned = false;
13298         int8_tArray arg_arr = { .len = 33, .ptr = MALLOC(33, "Native int8_tArray Bytes") };
13299         memcpy(arg_arr.ptr, ChannelPublicKeys_get_delayed_payment_basepoint(&this_ptr_conv).compressed_form, 33);
13300         return arg_arr;
13301 }
13302
13303 void ChannelPublicKeys_1set_1delayed_1payment_1basepoint(void* ctx_TODO, uint32_t this_ptr, int8_tArray val) {
13304         LDKChannelPublicKeys this_ptr_conv;
13305         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13306         this_ptr_conv.is_owned = false;
13307         LDKPublicKey val_ref;
13308         CHECK(val.len == 33);
13309         memcpy(val_ref.compressed_form, val.ptr, 33);
13310         ChannelPublicKeys_set_delayed_payment_basepoint(&this_ptr_conv, val_ref);
13311 }
13312
13313 int8_tArray ChannelPublicKeys_1get_1htlc_1basepoint(void* ctx_TODO, uint32_t this_ptr) {
13314         LDKChannelPublicKeys this_ptr_conv;
13315         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13316         this_ptr_conv.is_owned = false;
13317         int8_tArray arg_arr = { .len = 33, .ptr = MALLOC(33, "Native int8_tArray Bytes") };
13318         memcpy(arg_arr.ptr, ChannelPublicKeys_get_htlc_basepoint(&this_ptr_conv).compressed_form, 33);
13319         return arg_arr;
13320 }
13321
13322 void ChannelPublicKeys_1set_1htlc_1basepoint(void* ctx_TODO, uint32_t this_ptr, int8_tArray val) {
13323         LDKChannelPublicKeys this_ptr_conv;
13324         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13325         this_ptr_conv.is_owned = false;
13326         LDKPublicKey val_ref;
13327         CHECK(val.len == 33);
13328         memcpy(val_ref.compressed_form, val.ptr, 33);
13329         ChannelPublicKeys_set_htlc_basepoint(&this_ptr_conv, val_ref);
13330 }
13331
13332 uint32_t ChannelPublicKeys_1new(void* ctx_TODO, int8_tArray funding_pubkey_arg, int8_tArray revocation_basepoint_arg, int8_tArray payment_point_arg, int8_tArray delayed_payment_basepoint_arg, int8_tArray htlc_basepoint_arg) {
13333         LDKPublicKey funding_pubkey_arg_ref;
13334         CHECK(funding_pubkey_arg.len == 33);
13335         memcpy(funding_pubkey_arg_ref.compressed_form, funding_pubkey_arg.ptr, 33);
13336         LDKPublicKey revocation_basepoint_arg_ref;
13337         CHECK(revocation_basepoint_arg.len == 33);
13338         memcpy(revocation_basepoint_arg_ref.compressed_form, revocation_basepoint_arg.ptr, 33);
13339         LDKPublicKey payment_point_arg_ref;
13340         CHECK(payment_point_arg.len == 33);
13341         memcpy(payment_point_arg_ref.compressed_form, payment_point_arg.ptr, 33);
13342         LDKPublicKey delayed_payment_basepoint_arg_ref;
13343         CHECK(delayed_payment_basepoint_arg.len == 33);
13344         memcpy(delayed_payment_basepoint_arg_ref.compressed_form, delayed_payment_basepoint_arg.ptr, 33);
13345         LDKPublicKey htlc_basepoint_arg_ref;
13346         CHECK(htlc_basepoint_arg.len == 33);
13347         memcpy(htlc_basepoint_arg_ref.compressed_form, htlc_basepoint_arg.ptr, 33);
13348         LDKChannelPublicKeys ret_var = ChannelPublicKeys_new(funding_pubkey_arg_ref, revocation_basepoint_arg_ref, payment_point_arg_ref, delayed_payment_basepoint_arg_ref, htlc_basepoint_arg_ref);
13349         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13350         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13351         long ret_ref = (long)ret_var.inner;
13352         if (ret_var.is_owned) {
13353                 ret_ref |= 1;
13354         }
13355         return ret_ref;
13356 }
13357
13358 int8_tArray ChannelPublicKeys_1write(void* ctx_TODO, uint32_t obj) {
13359         LDKChannelPublicKeys obj_conv;
13360         obj_conv.inner = (void*)(obj & (~1));
13361         obj_conv.is_owned = false;
13362         LDKCVec_u8Z arg_var = ChannelPublicKeys_write(&obj_conv);
13363         int8_tArray arg_arr = { .len = arg_var.datalen, .ptr = MALLOC(arg_var.datalen, "Native int8_tArray Bytes") };
13364         memcpy(arg_arr.ptr, arg_var.data, arg_var.datalen);
13365         CVec_u8Z_free(arg_var);
13366         return arg_arr;
13367 }
13368
13369 uint32_t ChannelPublicKeys_1read(void* ctx_TODO, int8_tArray ser) {
13370         LDKu8slice ser_ref;
13371         ser_ref.datalen = ser.len;
13372         ser_ref.data = ser.ptr;
13373         LDKChannelPublicKeys ret_var = ChannelPublicKeys_read(ser_ref);
13374         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13375         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13376         long ret_ref = (long)ret_var.inner;
13377         if (ret_var.is_owned) {
13378                 ret_ref |= 1;
13379         }
13380         return ret_ref;
13381 }
13382
13383 uint32_t TxCreationKeys_1derive_1new(void* ctx_TODO, int8_tArray per_commitment_point, int8_tArray broadcaster_delayed_payment_base, int8_tArray broadcaster_htlc_base, int8_tArray countersignatory_revocation_base, int8_tArray countersignatory_htlc_base) {
13384         LDKPublicKey per_commitment_point_ref;
13385         CHECK(per_commitment_point.len == 33);
13386         memcpy(per_commitment_point_ref.compressed_form, per_commitment_point.ptr, 33);
13387         LDKPublicKey broadcaster_delayed_payment_base_ref;
13388         CHECK(broadcaster_delayed_payment_base.len == 33);
13389         memcpy(broadcaster_delayed_payment_base_ref.compressed_form, broadcaster_delayed_payment_base.ptr, 33);
13390         LDKPublicKey broadcaster_htlc_base_ref;
13391         CHECK(broadcaster_htlc_base.len == 33);
13392         memcpy(broadcaster_htlc_base_ref.compressed_form, broadcaster_htlc_base.ptr, 33);
13393         LDKPublicKey countersignatory_revocation_base_ref;
13394         CHECK(countersignatory_revocation_base.len == 33);
13395         memcpy(countersignatory_revocation_base_ref.compressed_form, countersignatory_revocation_base.ptr, 33);
13396         LDKPublicKey countersignatory_htlc_base_ref;
13397         CHECK(countersignatory_htlc_base.len == 33);
13398         memcpy(countersignatory_htlc_base_ref.compressed_form, countersignatory_htlc_base.ptr, 33);
13399         LDKCResult_TxCreationKeysSecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_TxCreationKeysSecpErrorZ), "LDKCResult_TxCreationKeysSecpErrorZ");
13400         *ret_conv = TxCreationKeys_derive_new(per_commitment_point_ref, broadcaster_delayed_payment_base_ref, broadcaster_htlc_base_ref, countersignatory_revocation_base_ref, countersignatory_htlc_base_ref);
13401         return (long)ret_conv;
13402 }
13403
13404 uint32_t TxCreationKeys_1from_1channel_1static_1keys(void* ctx_TODO, int8_tArray per_commitment_point, uint32_t broadcaster_keys, uint32_t countersignatory_keys) {
13405         LDKPublicKey per_commitment_point_ref;
13406         CHECK(per_commitment_point.len == 33);
13407         memcpy(per_commitment_point_ref.compressed_form, per_commitment_point.ptr, 33);
13408         LDKChannelPublicKeys broadcaster_keys_conv;
13409         broadcaster_keys_conv.inner = (void*)(broadcaster_keys & (~1));
13410         broadcaster_keys_conv.is_owned = false;
13411         LDKChannelPublicKeys countersignatory_keys_conv;
13412         countersignatory_keys_conv.inner = (void*)(countersignatory_keys & (~1));
13413         countersignatory_keys_conv.is_owned = false;
13414         LDKCResult_TxCreationKeysSecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_TxCreationKeysSecpErrorZ), "LDKCResult_TxCreationKeysSecpErrorZ");
13415         *ret_conv = TxCreationKeys_from_channel_static_keys(per_commitment_point_ref, &broadcaster_keys_conv, &countersignatory_keys_conv);
13416         return (long)ret_conv;
13417 }
13418
13419 int8_tArray get_1revokeable_1redeemscript(void* ctx_TODO, int8_tArray revocation_key, int16_t contest_delay, int8_tArray broadcaster_delayed_payment_key) {
13420         LDKPublicKey revocation_key_ref;
13421         CHECK(revocation_key.len == 33);
13422         memcpy(revocation_key_ref.compressed_form, revocation_key.ptr, 33);
13423         LDKPublicKey broadcaster_delayed_payment_key_ref;
13424         CHECK(broadcaster_delayed_payment_key.len == 33);
13425         memcpy(broadcaster_delayed_payment_key_ref.compressed_form, broadcaster_delayed_payment_key.ptr, 33);
13426         LDKCVec_u8Z arg_var = get_revokeable_redeemscript(revocation_key_ref, contest_delay, broadcaster_delayed_payment_key_ref);
13427         int8_tArray arg_arr = { .len = arg_var.datalen, .ptr = MALLOC(arg_var.datalen, "Native int8_tArray Bytes") };
13428         memcpy(arg_arr.ptr, arg_var.data, arg_var.datalen);
13429         CVec_u8Z_free(arg_var);
13430         return arg_arr;
13431 }
13432
13433 void HTLCOutputInCommitment_1free(void* ctx_TODO, uint32_t this_ptr) {
13434         LDKHTLCOutputInCommitment this_ptr_conv;
13435         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13436         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13437         HTLCOutputInCommitment_free(this_ptr_conv);
13438 }
13439
13440 uint32_t HTLCOutputInCommitment_1clone(void* ctx_TODO, uint32_t orig) {
13441         LDKHTLCOutputInCommitment orig_conv;
13442         orig_conv.inner = (void*)(orig & (~1));
13443         orig_conv.is_owned = false;
13444         LDKHTLCOutputInCommitment ret_var = HTLCOutputInCommitment_clone(&orig_conv);
13445         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13446         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13447         long ret_ref = (long)ret_var.inner;
13448         if (ret_var.is_owned) {
13449                 ret_ref |= 1;
13450         }
13451         return ret_ref;
13452 }
13453
13454 jboolean HTLCOutputInCommitment_1get_1offered(void* ctx_TODO, uint32_t this_ptr) {
13455         LDKHTLCOutputInCommitment this_ptr_conv;
13456         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13457         this_ptr_conv.is_owned = false;
13458         jboolean ret_val = HTLCOutputInCommitment_get_offered(&this_ptr_conv);
13459         return ret_val;
13460 }
13461
13462 void HTLCOutputInCommitment_1set_1offered(void* ctx_TODO, uint32_t this_ptr, jboolean val) {
13463         LDKHTLCOutputInCommitment this_ptr_conv;
13464         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13465         this_ptr_conv.is_owned = false;
13466         HTLCOutputInCommitment_set_offered(&this_ptr_conv, val);
13467 }
13468
13469 int64_t HTLCOutputInCommitment_1get_1amount_1msat(void* ctx_TODO, uint32_t this_ptr) {
13470         LDKHTLCOutputInCommitment this_ptr_conv;
13471         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13472         this_ptr_conv.is_owned = false;
13473         int64_t ret_val = HTLCOutputInCommitment_get_amount_msat(&this_ptr_conv);
13474         return ret_val;
13475 }
13476
13477 void HTLCOutputInCommitment_1set_1amount_1msat(void* ctx_TODO, uint32_t this_ptr, int64_t val) {
13478         LDKHTLCOutputInCommitment this_ptr_conv;
13479         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13480         this_ptr_conv.is_owned = false;
13481         HTLCOutputInCommitment_set_amount_msat(&this_ptr_conv, val);
13482 }
13483
13484 int32_t HTLCOutputInCommitment_1get_1cltv_1expiry(void* ctx_TODO, uint32_t this_ptr) {
13485         LDKHTLCOutputInCommitment this_ptr_conv;
13486         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13487         this_ptr_conv.is_owned = false;
13488         int32_t ret_val = HTLCOutputInCommitment_get_cltv_expiry(&this_ptr_conv);
13489         return ret_val;
13490 }
13491
13492 void HTLCOutputInCommitment_1set_1cltv_1expiry(void* ctx_TODO, uint32_t this_ptr, int32_t val) {
13493         LDKHTLCOutputInCommitment this_ptr_conv;
13494         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13495         this_ptr_conv.is_owned = false;
13496         HTLCOutputInCommitment_set_cltv_expiry(&this_ptr_conv, val);
13497 }
13498
13499 int8_tArray HTLCOutputInCommitment_1get_1payment_1hash(void* ctx_TODO, uint32_t this_ptr) {
13500         LDKHTLCOutputInCommitment this_ptr_conv;
13501         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13502         this_ptr_conv.is_owned = false;
13503         int8_tArray ret_arr = { .len = 32, .ptr = MALLOC(32, "Native int8_tArray Bytes") };
13504         memcpy(ret_arr.ptr, *HTLCOutputInCommitment_get_payment_hash(&this_ptr_conv), 32);
13505         return ret_arr;
13506 }
13507
13508 void HTLCOutputInCommitment_1set_1payment_1hash(void* ctx_TODO, uint32_t this_ptr, int8_tArray val) {
13509         LDKHTLCOutputInCommitment this_ptr_conv;
13510         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13511         this_ptr_conv.is_owned = false;
13512         LDKThirtyTwoBytes val_ref;
13513         CHECK(val.len == 32);
13514         memcpy(val_ref.data, val.ptr, 32);
13515         HTLCOutputInCommitment_set_payment_hash(&this_ptr_conv, val_ref);
13516 }
13517
13518 int8_tArray HTLCOutputInCommitment_1write(void* ctx_TODO, uint32_t obj) {
13519         LDKHTLCOutputInCommitment obj_conv;
13520         obj_conv.inner = (void*)(obj & (~1));
13521         obj_conv.is_owned = false;
13522         LDKCVec_u8Z arg_var = HTLCOutputInCommitment_write(&obj_conv);
13523         int8_tArray arg_arr = { .len = arg_var.datalen, .ptr = MALLOC(arg_var.datalen, "Native int8_tArray Bytes") };
13524         memcpy(arg_arr.ptr, arg_var.data, arg_var.datalen);
13525         CVec_u8Z_free(arg_var);
13526         return arg_arr;
13527 }
13528
13529 uint32_t HTLCOutputInCommitment_1read(void* ctx_TODO, int8_tArray ser) {
13530         LDKu8slice ser_ref;
13531         ser_ref.datalen = ser.len;
13532         ser_ref.data = ser.ptr;
13533         LDKHTLCOutputInCommitment ret_var = HTLCOutputInCommitment_read(ser_ref);
13534         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13535         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13536         long ret_ref = (long)ret_var.inner;
13537         if (ret_var.is_owned) {
13538                 ret_ref |= 1;
13539         }
13540         return ret_ref;
13541 }
13542
13543 int8_tArray get_1htlc_1redeemscript(void* ctx_TODO, uint32_t htlc, uint32_t keys) {
13544         LDKHTLCOutputInCommitment htlc_conv;
13545         htlc_conv.inner = (void*)(htlc & (~1));
13546         htlc_conv.is_owned = false;
13547         LDKTxCreationKeys keys_conv;
13548         keys_conv.inner = (void*)(keys & (~1));
13549         keys_conv.is_owned = false;
13550         LDKCVec_u8Z arg_var = get_htlc_redeemscript(&htlc_conv, &keys_conv);
13551         int8_tArray arg_arr = { .len = arg_var.datalen, .ptr = MALLOC(arg_var.datalen, "Native int8_tArray Bytes") };
13552         memcpy(arg_arr.ptr, arg_var.data, arg_var.datalen);
13553         CVec_u8Z_free(arg_var);
13554         return arg_arr;
13555 }
13556
13557 int8_tArray make_1funding_1redeemscript(void* ctx_TODO, int8_tArray broadcaster, int8_tArray countersignatory) {
13558         LDKPublicKey broadcaster_ref;
13559         CHECK(broadcaster.len == 33);
13560         memcpy(broadcaster_ref.compressed_form, broadcaster.ptr, 33);
13561         LDKPublicKey countersignatory_ref;
13562         CHECK(countersignatory.len == 33);
13563         memcpy(countersignatory_ref.compressed_form, countersignatory.ptr, 33);
13564         LDKCVec_u8Z arg_var = make_funding_redeemscript(broadcaster_ref, countersignatory_ref);
13565         int8_tArray arg_arr = { .len = arg_var.datalen, .ptr = MALLOC(arg_var.datalen, "Native int8_tArray Bytes") };
13566         memcpy(arg_arr.ptr, arg_var.data, arg_var.datalen);
13567         CVec_u8Z_free(arg_var);
13568         return arg_arr;
13569 }
13570
13571 int8_tArray build_1htlc_1transaction(void* ctx_TODO, int8_tArray prev_hash, int32_t feerate_per_kw, int16_t contest_delay, uint32_t htlc, int8_tArray broadcaster_delayed_payment_key, int8_tArray revocation_key) {
13572         unsigned char prev_hash_arr[32];
13573         CHECK(prev_hash.len == 32);
13574         memcpy(prev_hash_arr, prev_hash.ptr, 32);
13575         unsigned char (*prev_hash_ref)[32] = &prev_hash_arr;
13576         LDKHTLCOutputInCommitment htlc_conv;
13577         htlc_conv.inner = (void*)(htlc & (~1));
13578         htlc_conv.is_owned = false;
13579         LDKPublicKey broadcaster_delayed_payment_key_ref;
13580         CHECK(broadcaster_delayed_payment_key.len == 33);
13581         memcpy(broadcaster_delayed_payment_key_ref.compressed_form, broadcaster_delayed_payment_key.ptr, 33);
13582         LDKPublicKey revocation_key_ref;
13583         CHECK(revocation_key.len == 33);
13584         memcpy(revocation_key_ref.compressed_form, revocation_key.ptr, 33);
13585         LDKTransaction arg_var = build_htlc_transaction(prev_hash_ref, feerate_per_kw, contest_delay, &htlc_conv, broadcaster_delayed_payment_key_ref, revocation_key_ref);
13586         int8_tArray arg_arr = { .len = arg_var.datalen, .ptr = MALLOC(arg_var.datalen, "Native int8_tArray Bytes") };
13587         memcpy(arg_arr.ptr, arg_var.data, arg_var.datalen);
13588         Transaction_free(arg_var);
13589         return arg_arr;
13590 }
13591
13592 void ChannelTransactionParameters_1free(void* ctx_TODO, uint32_t this_ptr) {
13593         LDKChannelTransactionParameters this_ptr_conv;
13594         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13595         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13596         ChannelTransactionParameters_free(this_ptr_conv);
13597 }
13598
13599 uint32_t ChannelTransactionParameters_1clone(void* ctx_TODO, uint32_t orig) {
13600         LDKChannelTransactionParameters orig_conv;
13601         orig_conv.inner = (void*)(orig & (~1));
13602         orig_conv.is_owned = false;
13603         LDKChannelTransactionParameters ret_var = ChannelTransactionParameters_clone(&orig_conv);
13604         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13605         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13606         long ret_ref = (long)ret_var.inner;
13607         if (ret_var.is_owned) {
13608                 ret_ref |= 1;
13609         }
13610         return ret_ref;
13611 }
13612
13613 uint32_t ChannelTransactionParameters_1get_1holder_1pubkeys(void* ctx_TODO, uint32_t this_ptr) {
13614         LDKChannelTransactionParameters this_ptr_conv;
13615         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13616         this_ptr_conv.is_owned = false;
13617         LDKChannelPublicKeys ret_var = ChannelTransactionParameters_get_holder_pubkeys(&this_ptr_conv);
13618         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13619         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13620         long ret_ref = (long)ret_var.inner;
13621         if (ret_var.is_owned) {
13622                 ret_ref |= 1;
13623         }
13624         return ret_ref;
13625 }
13626
13627 void ChannelTransactionParameters_1set_1holder_1pubkeys(void* ctx_TODO, uint32_t this_ptr, uint32_t val) {
13628         LDKChannelTransactionParameters this_ptr_conv;
13629         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13630         this_ptr_conv.is_owned = false;
13631         LDKChannelPublicKeys val_conv;
13632         val_conv.inner = (void*)(val & (~1));
13633         val_conv.is_owned = (val & 1) || (val == 0);
13634         if (val_conv.inner != NULL)
13635                 val_conv = ChannelPublicKeys_clone(&val_conv);
13636         ChannelTransactionParameters_set_holder_pubkeys(&this_ptr_conv, val_conv);
13637 }
13638
13639 int16_t ChannelTransactionParameters_1get_1holder_1selected_1contest_1delay(void* ctx_TODO, uint32_t this_ptr) {
13640         LDKChannelTransactionParameters this_ptr_conv;
13641         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13642         this_ptr_conv.is_owned = false;
13643         int16_t ret_val = ChannelTransactionParameters_get_holder_selected_contest_delay(&this_ptr_conv);
13644         return ret_val;
13645 }
13646
13647 void ChannelTransactionParameters_1set_1holder_1selected_1contest_1delay(void* ctx_TODO, uint32_t this_ptr, int16_t val) {
13648         LDKChannelTransactionParameters this_ptr_conv;
13649         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13650         this_ptr_conv.is_owned = false;
13651         ChannelTransactionParameters_set_holder_selected_contest_delay(&this_ptr_conv, val);
13652 }
13653
13654 jboolean ChannelTransactionParameters_1get_1is_1outbound_1from_1holder(void* ctx_TODO, uint32_t this_ptr) {
13655         LDKChannelTransactionParameters this_ptr_conv;
13656         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13657         this_ptr_conv.is_owned = false;
13658         jboolean ret_val = ChannelTransactionParameters_get_is_outbound_from_holder(&this_ptr_conv);
13659         return ret_val;
13660 }
13661
13662 void ChannelTransactionParameters_1set_1is_1outbound_1from_1holder(void* ctx_TODO, uint32_t this_ptr, jboolean val) {
13663         LDKChannelTransactionParameters this_ptr_conv;
13664         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13665         this_ptr_conv.is_owned = false;
13666         ChannelTransactionParameters_set_is_outbound_from_holder(&this_ptr_conv, val);
13667 }
13668
13669 uint32_t ChannelTransactionParameters_1get_1counterparty_1parameters(void* ctx_TODO, uint32_t this_ptr) {
13670         LDKChannelTransactionParameters this_ptr_conv;
13671         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13672         this_ptr_conv.is_owned = false;
13673         LDKCounterpartyChannelTransactionParameters ret_var = ChannelTransactionParameters_get_counterparty_parameters(&this_ptr_conv);
13674         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13675         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13676         long ret_ref = (long)ret_var.inner;
13677         if (ret_var.is_owned) {
13678                 ret_ref |= 1;
13679         }
13680         return ret_ref;
13681 }
13682
13683 void ChannelTransactionParameters_1set_1counterparty_1parameters(void* ctx_TODO, uint32_t this_ptr, uint32_t val) {
13684         LDKChannelTransactionParameters this_ptr_conv;
13685         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13686         this_ptr_conv.is_owned = false;
13687         LDKCounterpartyChannelTransactionParameters val_conv;
13688         val_conv.inner = (void*)(val & (~1));
13689         val_conv.is_owned = (val & 1) || (val == 0);
13690         if (val_conv.inner != NULL)
13691                 val_conv = CounterpartyChannelTransactionParameters_clone(&val_conv);
13692         ChannelTransactionParameters_set_counterparty_parameters(&this_ptr_conv, val_conv);
13693 }
13694
13695 uint32_t ChannelTransactionParameters_1get_1funding_1outpoint(void* ctx_TODO, uint32_t this_ptr) {
13696         LDKChannelTransactionParameters this_ptr_conv;
13697         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13698         this_ptr_conv.is_owned = false;
13699         LDKOutPoint ret_var = ChannelTransactionParameters_get_funding_outpoint(&this_ptr_conv);
13700         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13701         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13702         long ret_ref = (long)ret_var.inner;
13703         if (ret_var.is_owned) {
13704                 ret_ref |= 1;
13705         }
13706         return ret_ref;
13707 }
13708
13709 void ChannelTransactionParameters_1set_1funding_1outpoint(void* ctx_TODO, uint32_t this_ptr, uint32_t val) {
13710         LDKChannelTransactionParameters this_ptr_conv;
13711         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13712         this_ptr_conv.is_owned = false;
13713         LDKOutPoint val_conv;
13714         val_conv.inner = (void*)(val & (~1));
13715         val_conv.is_owned = (val & 1) || (val == 0);
13716         if (val_conv.inner != NULL)
13717                 val_conv = OutPoint_clone(&val_conv);
13718         ChannelTransactionParameters_set_funding_outpoint(&this_ptr_conv, val_conv);
13719 }
13720
13721 uint32_t ChannelTransactionParameters_1new(void* ctx_TODO, uint32_t holder_pubkeys_arg, int16_t holder_selected_contest_delay_arg, jboolean is_outbound_from_holder_arg, uint32_t counterparty_parameters_arg, uint32_t funding_outpoint_arg) {
13722         LDKChannelPublicKeys holder_pubkeys_arg_conv;
13723         holder_pubkeys_arg_conv.inner = (void*)(holder_pubkeys_arg & (~1));
13724         holder_pubkeys_arg_conv.is_owned = (holder_pubkeys_arg & 1) || (holder_pubkeys_arg == 0);
13725         if (holder_pubkeys_arg_conv.inner != NULL)
13726                 holder_pubkeys_arg_conv = ChannelPublicKeys_clone(&holder_pubkeys_arg_conv);
13727         LDKCounterpartyChannelTransactionParameters counterparty_parameters_arg_conv;
13728         counterparty_parameters_arg_conv.inner = (void*)(counterparty_parameters_arg & (~1));
13729         counterparty_parameters_arg_conv.is_owned = (counterparty_parameters_arg & 1) || (counterparty_parameters_arg == 0);
13730         if (counterparty_parameters_arg_conv.inner != NULL)
13731                 counterparty_parameters_arg_conv = CounterpartyChannelTransactionParameters_clone(&counterparty_parameters_arg_conv);
13732         LDKOutPoint funding_outpoint_arg_conv;
13733         funding_outpoint_arg_conv.inner = (void*)(funding_outpoint_arg & (~1));
13734         funding_outpoint_arg_conv.is_owned = (funding_outpoint_arg & 1) || (funding_outpoint_arg == 0);
13735         if (funding_outpoint_arg_conv.inner != NULL)
13736                 funding_outpoint_arg_conv = OutPoint_clone(&funding_outpoint_arg_conv);
13737         LDKChannelTransactionParameters ret_var = ChannelTransactionParameters_new(holder_pubkeys_arg_conv, holder_selected_contest_delay_arg, is_outbound_from_holder_arg, counterparty_parameters_arg_conv, funding_outpoint_arg_conv);
13738         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13739         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13740         long ret_ref = (long)ret_var.inner;
13741         if (ret_var.is_owned) {
13742                 ret_ref |= 1;
13743         }
13744         return ret_ref;
13745 }
13746
13747 void CounterpartyChannelTransactionParameters_1free(void* ctx_TODO, uint32_t this_ptr) {
13748         LDKCounterpartyChannelTransactionParameters this_ptr_conv;
13749         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13750         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13751         CounterpartyChannelTransactionParameters_free(this_ptr_conv);
13752 }
13753
13754 uint32_t CounterpartyChannelTransactionParameters_1clone(void* ctx_TODO, uint32_t orig) {
13755         LDKCounterpartyChannelTransactionParameters orig_conv;
13756         orig_conv.inner = (void*)(orig & (~1));
13757         orig_conv.is_owned = false;
13758         LDKCounterpartyChannelTransactionParameters ret_var = CounterpartyChannelTransactionParameters_clone(&orig_conv);
13759         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13760         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13761         long ret_ref = (long)ret_var.inner;
13762         if (ret_var.is_owned) {
13763                 ret_ref |= 1;
13764         }
13765         return ret_ref;
13766 }
13767
13768 uint32_t CounterpartyChannelTransactionParameters_1get_1pubkeys(void* ctx_TODO, uint32_t this_ptr) {
13769         LDKCounterpartyChannelTransactionParameters this_ptr_conv;
13770         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13771         this_ptr_conv.is_owned = false;
13772         LDKChannelPublicKeys ret_var = CounterpartyChannelTransactionParameters_get_pubkeys(&this_ptr_conv);
13773         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13774         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13775         long ret_ref = (long)ret_var.inner;
13776         if (ret_var.is_owned) {
13777                 ret_ref |= 1;
13778         }
13779         return ret_ref;
13780 }
13781
13782 void CounterpartyChannelTransactionParameters_1set_1pubkeys(void* ctx_TODO, uint32_t this_ptr, uint32_t val) {
13783         LDKCounterpartyChannelTransactionParameters this_ptr_conv;
13784         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13785         this_ptr_conv.is_owned = false;
13786         LDKChannelPublicKeys val_conv;
13787         val_conv.inner = (void*)(val & (~1));
13788         val_conv.is_owned = (val & 1) || (val == 0);
13789         if (val_conv.inner != NULL)
13790                 val_conv = ChannelPublicKeys_clone(&val_conv);
13791         CounterpartyChannelTransactionParameters_set_pubkeys(&this_ptr_conv, val_conv);
13792 }
13793
13794 int16_t CounterpartyChannelTransactionParameters_1get_1selected_1contest_1delay(void* ctx_TODO, uint32_t this_ptr) {
13795         LDKCounterpartyChannelTransactionParameters this_ptr_conv;
13796         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13797         this_ptr_conv.is_owned = false;
13798         int16_t ret_val = CounterpartyChannelTransactionParameters_get_selected_contest_delay(&this_ptr_conv);
13799         return ret_val;
13800 }
13801
13802 void CounterpartyChannelTransactionParameters_1set_1selected_1contest_1delay(void* ctx_TODO, uint32_t this_ptr, int16_t val) {
13803         LDKCounterpartyChannelTransactionParameters this_ptr_conv;
13804         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13805         this_ptr_conv.is_owned = false;
13806         CounterpartyChannelTransactionParameters_set_selected_contest_delay(&this_ptr_conv, val);
13807 }
13808
13809 uint32_t CounterpartyChannelTransactionParameters_1new(void* ctx_TODO, uint32_t pubkeys_arg, int16_t selected_contest_delay_arg) {
13810         LDKChannelPublicKeys pubkeys_arg_conv;
13811         pubkeys_arg_conv.inner = (void*)(pubkeys_arg & (~1));
13812         pubkeys_arg_conv.is_owned = (pubkeys_arg & 1) || (pubkeys_arg == 0);
13813         if (pubkeys_arg_conv.inner != NULL)
13814                 pubkeys_arg_conv = ChannelPublicKeys_clone(&pubkeys_arg_conv);
13815         LDKCounterpartyChannelTransactionParameters ret_var = CounterpartyChannelTransactionParameters_new(pubkeys_arg_conv, selected_contest_delay_arg);
13816         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13817         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13818         long ret_ref = (long)ret_var.inner;
13819         if (ret_var.is_owned) {
13820                 ret_ref |= 1;
13821         }
13822         return ret_ref;
13823 }
13824
13825 jboolean ChannelTransactionParameters_1is_1populated(void* ctx_TODO, uint32_t this_arg) {
13826         LDKChannelTransactionParameters this_arg_conv;
13827         this_arg_conv.inner = (void*)(this_arg & (~1));
13828         this_arg_conv.is_owned = false;
13829         jboolean ret_val = ChannelTransactionParameters_is_populated(&this_arg_conv);
13830         return ret_val;
13831 }
13832
13833 uint32_t ChannelTransactionParameters_1as_1holder_1broadcastable(void* ctx_TODO, uint32_t this_arg) {
13834         LDKChannelTransactionParameters this_arg_conv;
13835         this_arg_conv.inner = (void*)(this_arg & (~1));
13836         this_arg_conv.is_owned = false;
13837         LDKDirectedChannelTransactionParameters ret_var = ChannelTransactionParameters_as_holder_broadcastable(&this_arg_conv);
13838         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13839         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13840         long ret_ref = (long)ret_var.inner;
13841         if (ret_var.is_owned) {
13842                 ret_ref |= 1;
13843         }
13844         return ret_ref;
13845 }
13846
13847 uint32_t ChannelTransactionParameters_1as_1counterparty_1broadcastable(void* ctx_TODO, uint32_t this_arg) {
13848         LDKChannelTransactionParameters this_arg_conv;
13849         this_arg_conv.inner = (void*)(this_arg & (~1));
13850         this_arg_conv.is_owned = false;
13851         LDKDirectedChannelTransactionParameters ret_var = ChannelTransactionParameters_as_counterparty_broadcastable(&this_arg_conv);
13852         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13853         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13854         long ret_ref = (long)ret_var.inner;
13855         if (ret_var.is_owned) {
13856                 ret_ref |= 1;
13857         }
13858         return ret_ref;
13859 }
13860
13861 int8_tArray CounterpartyChannelTransactionParameters_1write(void* ctx_TODO, uint32_t obj) {
13862         LDKCounterpartyChannelTransactionParameters obj_conv;
13863         obj_conv.inner = (void*)(obj & (~1));
13864         obj_conv.is_owned = false;
13865         LDKCVec_u8Z arg_var = CounterpartyChannelTransactionParameters_write(&obj_conv);
13866         int8_tArray arg_arr = { .len = arg_var.datalen, .ptr = MALLOC(arg_var.datalen, "Native int8_tArray Bytes") };
13867         memcpy(arg_arr.ptr, arg_var.data, arg_var.datalen);
13868         CVec_u8Z_free(arg_var);
13869         return arg_arr;
13870 }
13871
13872 uint32_t CounterpartyChannelTransactionParameters_1read(void* ctx_TODO, int8_tArray ser) {
13873         LDKu8slice ser_ref;
13874         ser_ref.datalen = ser.len;
13875         ser_ref.data = ser.ptr;
13876         LDKCounterpartyChannelTransactionParameters ret_var = CounterpartyChannelTransactionParameters_read(ser_ref);
13877         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13878         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13879         long ret_ref = (long)ret_var.inner;
13880         if (ret_var.is_owned) {
13881                 ret_ref |= 1;
13882         }
13883         return ret_ref;
13884 }
13885
13886 int8_tArray ChannelTransactionParameters_1write(void* ctx_TODO, uint32_t obj) {
13887         LDKChannelTransactionParameters obj_conv;
13888         obj_conv.inner = (void*)(obj & (~1));
13889         obj_conv.is_owned = false;
13890         LDKCVec_u8Z arg_var = ChannelTransactionParameters_write(&obj_conv);
13891         int8_tArray arg_arr = { .len = arg_var.datalen, .ptr = MALLOC(arg_var.datalen, "Native int8_tArray Bytes") };
13892         memcpy(arg_arr.ptr, arg_var.data, arg_var.datalen);
13893         CVec_u8Z_free(arg_var);
13894         return arg_arr;
13895 }
13896
13897 uint32_t ChannelTransactionParameters_1read(void* ctx_TODO, int8_tArray ser) {
13898         LDKu8slice ser_ref;
13899         ser_ref.datalen = ser.len;
13900         ser_ref.data = ser.ptr;
13901         LDKChannelTransactionParameters ret_var = ChannelTransactionParameters_read(ser_ref);
13902         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13903         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13904         long ret_ref = (long)ret_var.inner;
13905         if (ret_var.is_owned) {
13906                 ret_ref |= 1;
13907         }
13908         return ret_ref;
13909 }
13910
13911 void DirectedChannelTransactionParameters_1free(void* ctx_TODO, uint32_t this_ptr) {
13912         LDKDirectedChannelTransactionParameters this_ptr_conv;
13913         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13914         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13915         DirectedChannelTransactionParameters_free(this_ptr_conv);
13916 }
13917
13918 uint32_t DirectedChannelTransactionParameters_1broadcaster_1pubkeys(void* ctx_TODO, uint32_t this_arg) {
13919         LDKDirectedChannelTransactionParameters this_arg_conv;
13920         this_arg_conv.inner = (void*)(this_arg & (~1));
13921         this_arg_conv.is_owned = false;
13922         LDKChannelPublicKeys ret_var = DirectedChannelTransactionParameters_broadcaster_pubkeys(&this_arg_conv);
13923         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13924         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13925         long ret_ref = (long)ret_var.inner;
13926         if (ret_var.is_owned) {
13927                 ret_ref |= 1;
13928         }
13929         return ret_ref;
13930 }
13931
13932 uint32_t DirectedChannelTransactionParameters_1countersignatory_1pubkeys(void* ctx_TODO, uint32_t this_arg) {
13933         LDKDirectedChannelTransactionParameters this_arg_conv;
13934         this_arg_conv.inner = (void*)(this_arg & (~1));
13935         this_arg_conv.is_owned = false;
13936         LDKChannelPublicKeys ret_var = DirectedChannelTransactionParameters_countersignatory_pubkeys(&this_arg_conv);
13937         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13938         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13939         long ret_ref = (long)ret_var.inner;
13940         if (ret_var.is_owned) {
13941                 ret_ref |= 1;
13942         }
13943         return ret_ref;
13944 }
13945
13946 int16_t DirectedChannelTransactionParameters_1contest_1delay(void* ctx_TODO, uint32_t this_arg) {
13947         LDKDirectedChannelTransactionParameters this_arg_conv;
13948         this_arg_conv.inner = (void*)(this_arg & (~1));
13949         this_arg_conv.is_owned = false;
13950         int16_t ret_val = DirectedChannelTransactionParameters_contest_delay(&this_arg_conv);
13951         return ret_val;
13952 }
13953
13954 jboolean DirectedChannelTransactionParameters_1is_1outbound(void* ctx_TODO, uint32_t this_arg) {
13955         LDKDirectedChannelTransactionParameters this_arg_conv;
13956         this_arg_conv.inner = (void*)(this_arg & (~1));
13957         this_arg_conv.is_owned = false;
13958         jboolean ret_val = DirectedChannelTransactionParameters_is_outbound(&this_arg_conv);
13959         return ret_val;
13960 }
13961
13962 uint32_t DirectedChannelTransactionParameters_1funding_1outpoint(void* ctx_TODO, uint32_t this_arg) {
13963         LDKDirectedChannelTransactionParameters this_arg_conv;
13964         this_arg_conv.inner = (void*)(this_arg & (~1));
13965         this_arg_conv.is_owned = false;
13966         LDKOutPoint ret_var = DirectedChannelTransactionParameters_funding_outpoint(&this_arg_conv);
13967         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13968         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13969         long ret_ref = (long)ret_var.inner;
13970         if (ret_var.is_owned) {
13971                 ret_ref |= 1;
13972         }
13973         return ret_ref;
13974 }
13975
13976 void HolderCommitmentTransaction_1free(void* ctx_TODO, uint32_t this_ptr) {
13977         LDKHolderCommitmentTransaction this_ptr_conv;
13978         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13979         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13980         HolderCommitmentTransaction_free(this_ptr_conv);
13981 }
13982
13983 uint32_t HolderCommitmentTransaction_1clone(void* ctx_TODO, uint32_t orig) {
13984         LDKHolderCommitmentTransaction orig_conv;
13985         orig_conv.inner = (void*)(orig & (~1));
13986         orig_conv.is_owned = false;
13987         LDKHolderCommitmentTransaction ret_var = HolderCommitmentTransaction_clone(&orig_conv);
13988         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13989         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13990         long ret_ref = (long)ret_var.inner;
13991         if (ret_var.is_owned) {
13992                 ret_ref |= 1;
13993         }
13994         return ret_ref;
13995 }
13996
13997 int8_tArray HolderCommitmentTransaction_1get_1counterparty_1sig(void* ctx_TODO, uint32_t this_ptr) {
13998         LDKHolderCommitmentTransaction this_ptr_conv;
13999         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14000         this_ptr_conv.is_owned = false;
14001         int8_tArray arg_arr = { .len = 64, .ptr = MALLOC(64, "Native int8_tArray Bytes") };
14002         memcpy(arg_arr.ptr, HolderCommitmentTransaction_get_counterparty_sig(&this_ptr_conv).compact_form, 64);
14003         return arg_arr;
14004 }
14005
14006 void HolderCommitmentTransaction_1set_1counterparty_1sig(void* ctx_TODO, uint32_t this_ptr, int8_tArray val) {
14007         LDKHolderCommitmentTransaction this_ptr_conv;
14008         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14009         this_ptr_conv.is_owned = false;
14010         LDKSignature val_ref;
14011         CHECK(val.len == 64);
14012         memcpy(val_ref.compact_form, val.ptr, 64);
14013         HolderCommitmentTransaction_set_counterparty_sig(&this_ptr_conv, val_ref);
14014 }
14015
14016 void HolderCommitmentTransaction_1set_1counterparty_1htlc_1sigs(void* ctx_TODO, uint32_t this_ptr, ptrArray val) {
14017         LDKHolderCommitmentTransaction this_ptr_conv;
14018         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14019         this_ptr_conv.is_owned = false;
14020         LDKCVec_SignatureZ val_constr;
14021         val_constr.datalen = val.len;
14022         if (val_constr.datalen > 0)
14023                 val_constr.data = MALLOC(val_constr.datalen * sizeof(LDKSignature), "LDKCVec_SignatureZ Elements");
14024         else
14025                 val_constr.data = NULL;
14026         int8_tArray* val_vals = (int8_tArray*) val.ptr;
14027         for (size_t m = 0; m < val_constr.datalen; m++) {
14028                 int8_tArray arr_conv_12 = val_vals[m];
14029                 LDKSignature arr_conv_12_ref;
14030                 CHECK(arr_conv_12.len == 64);
14031                 memcpy(arr_conv_12_ref.compact_form, arr_conv_12.ptr, 64);
14032                 val_constr.data[m] = arr_conv_12_ref;
14033         }
14034         HolderCommitmentTransaction_set_counterparty_htlc_sigs(&this_ptr_conv, val_constr);
14035 }
14036
14037 int8_tArray HolderCommitmentTransaction_1write(void* ctx_TODO, uint32_t obj) {
14038         LDKHolderCommitmentTransaction obj_conv;
14039         obj_conv.inner = (void*)(obj & (~1));
14040         obj_conv.is_owned = false;
14041         LDKCVec_u8Z arg_var = HolderCommitmentTransaction_write(&obj_conv);
14042         int8_tArray arg_arr = { .len = arg_var.datalen, .ptr = MALLOC(arg_var.datalen, "Native int8_tArray Bytes") };
14043         memcpy(arg_arr.ptr, arg_var.data, arg_var.datalen);
14044         CVec_u8Z_free(arg_var);
14045         return arg_arr;
14046 }
14047
14048 uint32_t HolderCommitmentTransaction_1read(void* ctx_TODO, int8_tArray ser) {
14049         LDKu8slice ser_ref;
14050         ser_ref.datalen = ser.len;
14051         ser_ref.data = ser.ptr;
14052         LDKHolderCommitmentTransaction ret_var = HolderCommitmentTransaction_read(ser_ref);
14053         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14054         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14055         long ret_ref = (long)ret_var.inner;
14056         if (ret_var.is_owned) {
14057                 ret_ref |= 1;
14058         }
14059         return ret_ref;
14060 }
14061
14062 uint32_t HolderCommitmentTransaction_1new(void* ctx_TODO, uint32_t commitment_tx, int8_tArray counterparty_sig, ptrArray counterparty_htlc_sigs, int8_tArray holder_funding_key, int8_tArray counterparty_funding_key) {
14063         LDKCommitmentTransaction commitment_tx_conv;
14064         commitment_tx_conv.inner = (void*)(commitment_tx & (~1));
14065         commitment_tx_conv.is_owned = (commitment_tx & 1) || (commitment_tx == 0);
14066         if (commitment_tx_conv.inner != NULL)
14067                 commitment_tx_conv = CommitmentTransaction_clone(&commitment_tx_conv);
14068         LDKSignature counterparty_sig_ref;
14069         CHECK(counterparty_sig.len == 64);
14070         memcpy(counterparty_sig_ref.compact_form, counterparty_sig.ptr, 64);
14071         LDKCVec_SignatureZ counterparty_htlc_sigs_constr;
14072         counterparty_htlc_sigs_constr.datalen = counterparty_htlc_sigs.len;
14073         if (counterparty_htlc_sigs_constr.datalen > 0)
14074                 counterparty_htlc_sigs_constr.data = MALLOC(counterparty_htlc_sigs_constr.datalen * sizeof(LDKSignature), "LDKCVec_SignatureZ Elements");
14075         else
14076                 counterparty_htlc_sigs_constr.data = NULL;
14077         int8_tArray* counterparty_htlc_sigs_vals = (int8_tArray*) counterparty_htlc_sigs.ptr;
14078         for (size_t m = 0; m < counterparty_htlc_sigs_constr.datalen; m++) {
14079                 int8_tArray arr_conv_12 = counterparty_htlc_sigs_vals[m];
14080                 LDKSignature arr_conv_12_ref;
14081                 CHECK(arr_conv_12.len == 64);
14082                 memcpy(arr_conv_12_ref.compact_form, arr_conv_12.ptr, 64);
14083                 counterparty_htlc_sigs_constr.data[m] = arr_conv_12_ref;
14084         }
14085         LDKPublicKey holder_funding_key_ref;
14086         CHECK(holder_funding_key.len == 33);
14087         memcpy(holder_funding_key_ref.compressed_form, holder_funding_key.ptr, 33);
14088         LDKPublicKey counterparty_funding_key_ref;
14089         CHECK(counterparty_funding_key.len == 33);
14090         memcpy(counterparty_funding_key_ref.compressed_form, counterparty_funding_key.ptr, 33);
14091         LDKHolderCommitmentTransaction ret_var = HolderCommitmentTransaction_new(commitment_tx_conv, counterparty_sig_ref, counterparty_htlc_sigs_constr, holder_funding_key_ref, counterparty_funding_key_ref);
14092         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14093         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14094         long ret_ref = (long)ret_var.inner;
14095         if (ret_var.is_owned) {
14096                 ret_ref |= 1;
14097         }
14098         return ret_ref;
14099 }
14100
14101 void BuiltCommitmentTransaction_1free(void* ctx_TODO, uint32_t this_ptr) {
14102         LDKBuiltCommitmentTransaction this_ptr_conv;
14103         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14104         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
14105         BuiltCommitmentTransaction_free(this_ptr_conv);
14106 }
14107
14108 uint32_t BuiltCommitmentTransaction_1clone(void* ctx_TODO, uint32_t orig) {
14109         LDKBuiltCommitmentTransaction orig_conv;
14110         orig_conv.inner = (void*)(orig & (~1));
14111         orig_conv.is_owned = false;
14112         LDKBuiltCommitmentTransaction ret_var = BuiltCommitmentTransaction_clone(&orig_conv);
14113         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14114         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14115         long ret_ref = (long)ret_var.inner;
14116         if (ret_var.is_owned) {
14117                 ret_ref |= 1;
14118         }
14119         return ret_ref;
14120 }
14121
14122 int8_tArray BuiltCommitmentTransaction_1get_1transaction(void* ctx_TODO, uint32_t this_ptr) {
14123         LDKBuiltCommitmentTransaction this_ptr_conv;
14124         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14125         this_ptr_conv.is_owned = false;
14126         LDKTransaction arg_var = BuiltCommitmentTransaction_get_transaction(&this_ptr_conv);
14127         int8_tArray arg_arr = { .len = arg_var.datalen, .ptr = MALLOC(arg_var.datalen, "Native int8_tArray Bytes") };
14128         memcpy(arg_arr.ptr, arg_var.data, arg_var.datalen);
14129         Transaction_free(arg_var);
14130         return arg_arr;
14131 }
14132
14133 void BuiltCommitmentTransaction_1set_1transaction(void* ctx_TODO, uint32_t this_ptr, int8_tArray val) {
14134         LDKBuiltCommitmentTransaction this_ptr_conv;
14135         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14136         this_ptr_conv.is_owned = false;
14137         LDKTransaction val_ref;
14138         val_ref.datalen = val.len;
14139         val_ref.data = MALLOC(val_ref.datalen, "LDKTransaction Bytes");
14140         memcpy(val_ref.data, val.ptr, val_ref.datalen);
14141         val_ref.data_is_owned = true;
14142         BuiltCommitmentTransaction_set_transaction(&this_ptr_conv, val_ref);
14143 }
14144
14145 int8_tArray BuiltCommitmentTransaction_1get_1txid(void* ctx_TODO, uint32_t this_ptr) {
14146         LDKBuiltCommitmentTransaction this_ptr_conv;
14147         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14148         this_ptr_conv.is_owned = false;
14149         int8_tArray ret_arr = { .len = 32, .ptr = MALLOC(32, "Native int8_tArray Bytes") };
14150         memcpy(ret_arr.ptr, *BuiltCommitmentTransaction_get_txid(&this_ptr_conv), 32);
14151         return ret_arr;
14152 }
14153
14154 void BuiltCommitmentTransaction_1set_1txid(void* ctx_TODO, uint32_t this_ptr, int8_tArray val) {
14155         LDKBuiltCommitmentTransaction this_ptr_conv;
14156         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14157         this_ptr_conv.is_owned = false;
14158         LDKThirtyTwoBytes val_ref;
14159         CHECK(val.len == 32);
14160         memcpy(val_ref.data, val.ptr, 32);
14161         BuiltCommitmentTransaction_set_txid(&this_ptr_conv, val_ref);
14162 }
14163
14164 uint32_t BuiltCommitmentTransaction_1new(void* ctx_TODO, int8_tArray transaction_arg, int8_tArray txid_arg) {
14165         LDKTransaction transaction_arg_ref;
14166         transaction_arg_ref.datalen = transaction_arg.len;
14167         transaction_arg_ref.data = MALLOC(transaction_arg_ref.datalen, "LDKTransaction Bytes");
14168         memcpy(transaction_arg_ref.data, transaction_arg.ptr, transaction_arg_ref.datalen);
14169         transaction_arg_ref.data_is_owned = true;
14170         LDKThirtyTwoBytes txid_arg_ref;
14171         CHECK(txid_arg.len == 32);
14172         memcpy(txid_arg_ref.data, txid_arg.ptr, 32);
14173         LDKBuiltCommitmentTransaction ret_var = BuiltCommitmentTransaction_new(transaction_arg_ref, txid_arg_ref);
14174         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14175         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14176         long ret_ref = (long)ret_var.inner;
14177         if (ret_var.is_owned) {
14178                 ret_ref |= 1;
14179         }
14180         return ret_ref;
14181 }
14182
14183 int8_tArray BuiltCommitmentTransaction_1write(void* ctx_TODO, uint32_t obj) {
14184         LDKBuiltCommitmentTransaction obj_conv;
14185         obj_conv.inner = (void*)(obj & (~1));
14186         obj_conv.is_owned = false;
14187         LDKCVec_u8Z arg_var = BuiltCommitmentTransaction_write(&obj_conv);
14188         int8_tArray arg_arr = { .len = arg_var.datalen, .ptr = MALLOC(arg_var.datalen, "Native int8_tArray Bytes") };
14189         memcpy(arg_arr.ptr, arg_var.data, arg_var.datalen);
14190         CVec_u8Z_free(arg_var);
14191         return arg_arr;
14192 }
14193
14194 uint32_t BuiltCommitmentTransaction_1read(void* ctx_TODO, int8_tArray ser) {
14195         LDKu8slice ser_ref;
14196         ser_ref.datalen = ser.len;
14197         ser_ref.data = ser.ptr;
14198         LDKBuiltCommitmentTransaction ret_var = BuiltCommitmentTransaction_read(ser_ref);
14199         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14200         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14201         long ret_ref = (long)ret_var.inner;
14202         if (ret_var.is_owned) {
14203                 ret_ref |= 1;
14204         }
14205         return ret_ref;
14206 }
14207
14208 int8_tArray BuiltCommitmentTransaction_1get_1sighash_1all(void* ctx_TODO, uint32_t this_arg, int8_tArray funding_redeemscript, int64_t channel_value_satoshis) {
14209         LDKBuiltCommitmentTransaction this_arg_conv;
14210         this_arg_conv.inner = (void*)(this_arg & (~1));
14211         this_arg_conv.is_owned = false;
14212         LDKu8slice funding_redeemscript_ref;
14213         funding_redeemscript_ref.datalen = funding_redeemscript.len;
14214         funding_redeemscript_ref.data = funding_redeemscript.ptr;
14215         int8_tArray arg_arr = { .len = 32, .ptr = MALLOC(32, "Native int8_tArray Bytes") };
14216         memcpy(arg_arr.ptr, BuiltCommitmentTransaction_get_sighash_all(&this_arg_conv, funding_redeemscript_ref, channel_value_satoshis).data, 32);
14217         return arg_arr;
14218 }
14219
14220 int8_tArray BuiltCommitmentTransaction_1sign(void* ctx_TODO, uint32_t this_arg, int8_tArray funding_key, int8_tArray funding_redeemscript, int64_t channel_value_satoshis) {
14221         LDKBuiltCommitmentTransaction this_arg_conv;
14222         this_arg_conv.inner = (void*)(this_arg & (~1));
14223         this_arg_conv.is_owned = false;
14224         unsigned char funding_key_arr[32];
14225         CHECK(funding_key.len == 32);
14226         memcpy(funding_key_arr, funding_key.ptr, 32);
14227         unsigned char (*funding_key_ref)[32] = &funding_key_arr;
14228         LDKu8slice funding_redeemscript_ref;
14229         funding_redeemscript_ref.datalen = funding_redeemscript.len;
14230         funding_redeemscript_ref.data = funding_redeemscript.ptr;
14231         int8_tArray arg_arr = { .len = 64, .ptr = MALLOC(64, "Native int8_tArray Bytes") };
14232         memcpy(arg_arr.ptr, BuiltCommitmentTransaction_sign(&this_arg_conv, funding_key_ref, funding_redeemscript_ref, channel_value_satoshis).compact_form, 64);
14233         return arg_arr;
14234 }
14235
14236 void CommitmentTransaction_1free(void* ctx_TODO, uint32_t this_ptr) {
14237         LDKCommitmentTransaction this_ptr_conv;
14238         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14239         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
14240         CommitmentTransaction_free(this_ptr_conv);
14241 }
14242
14243 uint32_t CommitmentTransaction_1clone(void* ctx_TODO, uint32_t orig) {
14244         LDKCommitmentTransaction orig_conv;
14245         orig_conv.inner = (void*)(orig & (~1));
14246         orig_conv.is_owned = false;
14247         LDKCommitmentTransaction ret_var = CommitmentTransaction_clone(&orig_conv);
14248         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14249         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14250         long ret_ref = (long)ret_var.inner;
14251         if (ret_var.is_owned) {
14252                 ret_ref |= 1;
14253         }
14254         return ret_ref;
14255 }
14256
14257 int8_tArray CommitmentTransaction_1write(void* ctx_TODO, uint32_t obj) {
14258         LDKCommitmentTransaction obj_conv;
14259         obj_conv.inner = (void*)(obj & (~1));
14260         obj_conv.is_owned = false;
14261         LDKCVec_u8Z arg_var = CommitmentTransaction_write(&obj_conv);
14262         int8_tArray arg_arr = { .len = arg_var.datalen, .ptr = MALLOC(arg_var.datalen, "Native int8_tArray Bytes") };
14263         memcpy(arg_arr.ptr, arg_var.data, arg_var.datalen);
14264         CVec_u8Z_free(arg_var);
14265         return arg_arr;
14266 }
14267
14268 uint32_t CommitmentTransaction_1read(void* ctx_TODO, int8_tArray ser) {
14269         LDKu8slice ser_ref;
14270         ser_ref.datalen = ser.len;
14271         ser_ref.data = ser.ptr;
14272         LDKCommitmentTransaction ret_var = CommitmentTransaction_read(ser_ref);
14273         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14274         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14275         long ret_ref = (long)ret_var.inner;
14276         if (ret_var.is_owned) {
14277                 ret_ref |= 1;
14278         }
14279         return ret_ref;
14280 }
14281
14282 int64_t CommitmentTransaction_1commitment_1number(void* ctx_TODO, uint32_t this_arg) {
14283         LDKCommitmentTransaction this_arg_conv;
14284         this_arg_conv.inner = (void*)(this_arg & (~1));
14285         this_arg_conv.is_owned = false;
14286         int64_t ret_val = CommitmentTransaction_commitment_number(&this_arg_conv);
14287         return ret_val;
14288 }
14289
14290 int64_t CommitmentTransaction_1to_1broadcaster_1value_1sat(void* ctx_TODO, uint32_t this_arg) {
14291         LDKCommitmentTransaction this_arg_conv;
14292         this_arg_conv.inner = (void*)(this_arg & (~1));
14293         this_arg_conv.is_owned = false;
14294         int64_t ret_val = CommitmentTransaction_to_broadcaster_value_sat(&this_arg_conv);
14295         return ret_val;
14296 }
14297
14298 int64_t CommitmentTransaction_1to_1countersignatory_1value_1sat(void* ctx_TODO, uint32_t this_arg) {
14299         LDKCommitmentTransaction this_arg_conv;
14300         this_arg_conv.inner = (void*)(this_arg & (~1));
14301         this_arg_conv.is_owned = false;
14302         int64_t ret_val = CommitmentTransaction_to_countersignatory_value_sat(&this_arg_conv);
14303         return ret_val;
14304 }
14305
14306 int32_t CommitmentTransaction_1feerate_1per_1kw(void* ctx_TODO, uint32_t this_arg) {
14307         LDKCommitmentTransaction this_arg_conv;
14308         this_arg_conv.inner = (void*)(this_arg & (~1));
14309         this_arg_conv.is_owned = false;
14310         int32_t ret_val = CommitmentTransaction_feerate_per_kw(&this_arg_conv);
14311         return ret_val;
14312 }
14313
14314 uint32_t CommitmentTransaction_1trust(void* ctx_TODO, uint32_t this_arg) {
14315         LDKCommitmentTransaction this_arg_conv;
14316         this_arg_conv.inner = (void*)(this_arg & (~1));
14317         this_arg_conv.is_owned = false;
14318         LDKTrustedCommitmentTransaction ret_var = CommitmentTransaction_trust(&this_arg_conv);
14319         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14320         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14321         long ret_ref = (long)ret_var.inner;
14322         if (ret_var.is_owned) {
14323                 ret_ref |= 1;
14324         }
14325         return ret_ref;
14326 }
14327
14328 uint32_t CommitmentTransaction_1verify(void* ctx_TODO, uint32_t this_arg, uint32_t channel_parameters, uint32_t broadcaster_keys, uint32_t countersignatory_keys) {
14329         LDKCommitmentTransaction this_arg_conv;
14330         this_arg_conv.inner = (void*)(this_arg & (~1));
14331         this_arg_conv.is_owned = false;
14332         LDKDirectedChannelTransactionParameters channel_parameters_conv;
14333         channel_parameters_conv.inner = (void*)(channel_parameters & (~1));
14334         channel_parameters_conv.is_owned = false;
14335         LDKChannelPublicKeys broadcaster_keys_conv;
14336         broadcaster_keys_conv.inner = (void*)(broadcaster_keys & (~1));
14337         broadcaster_keys_conv.is_owned = false;
14338         LDKChannelPublicKeys countersignatory_keys_conv;
14339         countersignatory_keys_conv.inner = (void*)(countersignatory_keys & (~1));
14340         countersignatory_keys_conv.is_owned = false;
14341         LDKCResult_TrustedCommitmentTransactionNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_TrustedCommitmentTransactionNoneZ), "LDKCResult_TrustedCommitmentTransactionNoneZ");
14342         *ret_conv = CommitmentTransaction_verify(&this_arg_conv, &channel_parameters_conv, &broadcaster_keys_conv, &countersignatory_keys_conv);
14343         return (long)ret_conv;
14344 }
14345
14346 void TrustedCommitmentTransaction_1free(void* ctx_TODO, uint32_t this_ptr) {
14347         LDKTrustedCommitmentTransaction this_ptr_conv;
14348         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14349         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
14350         TrustedCommitmentTransaction_free(this_ptr_conv);
14351 }
14352
14353 int8_tArray TrustedCommitmentTransaction_1txid(void* ctx_TODO, uint32_t this_arg) {
14354         LDKTrustedCommitmentTransaction this_arg_conv;
14355         this_arg_conv.inner = (void*)(this_arg & (~1));
14356         this_arg_conv.is_owned = false;
14357         int8_tArray arg_arr = { .len = 32, .ptr = MALLOC(32, "Native int8_tArray Bytes") };
14358         memcpy(arg_arr.ptr, TrustedCommitmentTransaction_txid(&this_arg_conv).data, 32);
14359         return arg_arr;
14360 }
14361
14362 uint32_t TrustedCommitmentTransaction_1built_1transaction(void* ctx_TODO, uint32_t this_arg) {
14363         LDKTrustedCommitmentTransaction this_arg_conv;
14364         this_arg_conv.inner = (void*)(this_arg & (~1));
14365         this_arg_conv.is_owned = false;
14366         LDKBuiltCommitmentTransaction ret_var = TrustedCommitmentTransaction_built_transaction(&this_arg_conv);
14367         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14368         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14369         long ret_ref = (long)ret_var.inner;
14370         if (ret_var.is_owned) {
14371                 ret_ref |= 1;
14372         }
14373         return ret_ref;
14374 }
14375
14376 uint32_t TrustedCommitmentTransaction_1keys(void* ctx_TODO, uint32_t this_arg) {
14377         LDKTrustedCommitmentTransaction this_arg_conv;
14378         this_arg_conv.inner = (void*)(this_arg & (~1));
14379         this_arg_conv.is_owned = false;
14380         LDKTxCreationKeys ret_var = TrustedCommitmentTransaction_keys(&this_arg_conv);
14381         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14382         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14383         long ret_ref = (long)ret_var.inner;
14384         if (ret_var.is_owned) {
14385                 ret_ref |= 1;
14386         }
14387         return ret_ref;
14388 }
14389
14390 uint32_t TrustedCommitmentTransaction_1get_1htlc_1sigs(void* ctx_TODO, uint32_t this_arg, int8_tArray htlc_base_key, uint32_t channel_parameters) {
14391         LDKTrustedCommitmentTransaction this_arg_conv;
14392         this_arg_conv.inner = (void*)(this_arg & (~1));
14393         this_arg_conv.is_owned = false;
14394         unsigned char htlc_base_key_arr[32];
14395         CHECK(htlc_base_key.len == 32);
14396         memcpy(htlc_base_key_arr, htlc_base_key.ptr, 32);
14397         unsigned char (*htlc_base_key_ref)[32] = &htlc_base_key_arr;
14398         LDKDirectedChannelTransactionParameters channel_parameters_conv;
14399         channel_parameters_conv.inner = (void*)(channel_parameters & (~1));
14400         channel_parameters_conv.is_owned = false;
14401         LDKCResult_CVec_SignatureZNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_CVec_SignatureZNoneZ), "LDKCResult_CVec_SignatureZNoneZ");
14402         *ret_conv = TrustedCommitmentTransaction_get_htlc_sigs(&this_arg_conv, htlc_base_key_ref, &channel_parameters_conv);
14403         return (long)ret_conv;
14404 }
14405
14406 int64_t get_1commitment_1transaction_1number_1obscure_1factor(void* ctx_TODO, int8_tArray broadcaster_payment_basepoint, int8_tArray countersignatory_payment_basepoint, jboolean outbound_from_broadcaster) {
14407         LDKPublicKey broadcaster_payment_basepoint_ref;
14408         CHECK(broadcaster_payment_basepoint.len == 33);
14409         memcpy(broadcaster_payment_basepoint_ref.compressed_form, broadcaster_payment_basepoint.ptr, 33);
14410         LDKPublicKey countersignatory_payment_basepoint_ref;
14411         CHECK(countersignatory_payment_basepoint.len == 33);
14412         memcpy(countersignatory_payment_basepoint_ref.compressed_form, countersignatory_payment_basepoint.ptr, 33);
14413         int64_t ret_val = get_commitment_transaction_number_obscure_factor(broadcaster_payment_basepoint_ref, countersignatory_payment_basepoint_ref, outbound_from_broadcaster);
14414         return ret_val;
14415 }
14416
14417 void InitFeatures_1free(void* ctx_TODO, uint32_t this_ptr) {
14418         LDKInitFeatures this_ptr_conv;
14419         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14420         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
14421         InitFeatures_free(this_ptr_conv);
14422 }
14423
14424 void NodeFeatures_1free(void* ctx_TODO, uint32_t this_ptr) {
14425         LDKNodeFeatures this_ptr_conv;
14426         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14427         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
14428         NodeFeatures_free(this_ptr_conv);
14429 }
14430
14431 void ChannelFeatures_1free(void* ctx_TODO, uint32_t this_ptr) {
14432         LDKChannelFeatures this_ptr_conv;
14433         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14434         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
14435         ChannelFeatures_free(this_ptr_conv);
14436 }
14437
14438 void RouteHop_1free(void* ctx_TODO, uint32_t this_ptr) {
14439         LDKRouteHop this_ptr_conv;
14440         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14441         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
14442         RouteHop_free(this_ptr_conv);
14443 }
14444
14445 uint32_t RouteHop_1clone(void* ctx_TODO, uint32_t orig) {
14446         LDKRouteHop orig_conv;
14447         orig_conv.inner = (void*)(orig & (~1));
14448         orig_conv.is_owned = false;
14449         LDKRouteHop ret_var = RouteHop_clone(&orig_conv);
14450         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14451         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14452         long ret_ref = (long)ret_var.inner;
14453         if (ret_var.is_owned) {
14454                 ret_ref |= 1;
14455         }
14456         return ret_ref;
14457 }
14458
14459 int8_tArray RouteHop_1get_1pubkey(void* ctx_TODO, uint32_t this_ptr) {
14460         LDKRouteHop this_ptr_conv;
14461         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14462         this_ptr_conv.is_owned = false;
14463         int8_tArray arg_arr = { .len = 33, .ptr = MALLOC(33, "Native int8_tArray Bytes") };
14464         memcpy(arg_arr.ptr, RouteHop_get_pubkey(&this_ptr_conv).compressed_form, 33);
14465         return arg_arr;
14466 }
14467
14468 void RouteHop_1set_1pubkey(void* ctx_TODO, uint32_t this_ptr, int8_tArray val) {
14469         LDKRouteHop this_ptr_conv;
14470         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14471         this_ptr_conv.is_owned = false;
14472         LDKPublicKey val_ref;
14473         CHECK(val.len == 33);
14474         memcpy(val_ref.compressed_form, val.ptr, 33);
14475         RouteHop_set_pubkey(&this_ptr_conv, val_ref);
14476 }
14477
14478 uint32_t RouteHop_1get_1node_1features(void* ctx_TODO, uint32_t this_ptr) {
14479         LDKRouteHop this_ptr_conv;
14480         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14481         this_ptr_conv.is_owned = false;
14482         LDKNodeFeatures ret_var = RouteHop_get_node_features(&this_ptr_conv);
14483         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14484         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14485         long ret_ref = (long)ret_var.inner;
14486         if (ret_var.is_owned) {
14487                 ret_ref |= 1;
14488         }
14489         return ret_ref;
14490 }
14491
14492 void RouteHop_1set_1node_1features(void* ctx_TODO, uint32_t this_ptr, uint32_t val) {
14493         LDKRouteHop this_ptr_conv;
14494         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14495         this_ptr_conv.is_owned = false;
14496         LDKNodeFeatures val_conv;
14497         val_conv.inner = (void*)(val & (~1));
14498         val_conv.is_owned = (val & 1) || (val == 0);
14499         // Warning: we may need a move here but can't clone!
14500         RouteHop_set_node_features(&this_ptr_conv, val_conv);
14501 }
14502
14503 int64_t RouteHop_1get_1short_1channel_1id(void* ctx_TODO, uint32_t this_ptr) {
14504         LDKRouteHop this_ptr_conv;
14505         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14506         this_ptr_conv.is_owned = false;
14507         int64_t ret_val = RouteHop_get_short_channel_id(&this_ptr_conv);
14508         return ret_val;
14509 }
14510
14511 void RouteHop_1set_1short_1channel_1id(void* ctx_TODO, uint32_t this_ptr, int64_t val) {
14512         LDKRouteHop this_ptr_conv;
14513         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14514         this_ptr_conv.is_owned = false;
14515         RouteHop_set_short_channel_id(&this_ptr_conv, val);
14516 }
14517
14518 uint32_t RouteHop_1get_1channel_1features(void* ctx_TODO, uint32_t this_ptr) {
14519         LDKRouteHop this_ptr_conv;
14520         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14521         this_ptr_conv.is_owned = false;
14522         LDKChannelFeatures ret_var = RouteHop_get_channel_features(&this_ptr_conv);
14523         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14524         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14525         long ret_ref = (long)ret_var.inner;
14526         if (ret_var.is_owned) {
14527                 ret_ref |= 1;
14528         }
14529         return ret_ref;
14530 }
14531
14532 void RouteHop_1set_1channel_1features(void* ctx_TODO, uint32_t this_ptr, uint32_t val) {
14533         LDKRouteHop this_ptr_conv;
14534         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14535         this_ptr_conv.is_owned = false;
14536         LDKChannelFeatures val_conv;
14537         val_conv.inner = (void*)(val & (~1));
14538         val_conv.is_owned = (val & 1) || (val == 0);
14539         // Warning: we may need a move here but can't clone!
14540         RouteHop_set_channel_features(&this_ptr_conv, val_conv);
14541 }
14542
14543 int64_t RouteHop_1get_1fee_1msat(void* ctx_TODO, uint32_t this_ptr) {
14544         LDKRouteHop this_ptr_conv;
14545         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14546         this_ptr_conv.is_owned = false;
14547         int64_t ret_val = RouteHop_get_fee_msat(&this_ptr_conv);
14548         return ret_val;
14549 }
14550
14551 void RouteHop_1set_1fee_1msat(void* ctx_TODO, uint32_t this_ptr, int64_t val) {
14552         LDKRouteHop this_ptr_conv;
14553         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14554         this_ptr_conv.is_owned = false;
14555         RouteHop_set_fee_msat(&this_ptr_conv, val);
14556 }
14557
14558 int32_t RouteHop_1get_1cltv_1expiry_1delta(void* ctx_TODO, uint32_t this_ptr) {
14559         LDKRouteHop this_ptr_conv;
14560         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14561         this_ptr_conv.is_owned = false;
14562         int32_t ret_val = RouteHop_get_cltv_expiry_delta(&this_ptr_conv);
14563         return ret_val;
14564 }
14565
14566 void RouteHop_1set_1cltv_1expiry_1delta(void* ctx_TODO, uint32_t this_ptr, int32_t val) {
14567         LDKRouteHop this_ptr_conv;
14568         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14569         this_ptr_conv.is_owned = false;
14570         RouteHop_set_cltv_expiry_delta(&this_ptr_conv, val);
14571 }
14572
14573 uint32_t RouteHop_1new(void* ctx_TODO, int8_tArray pubkey_arg, uint32_t node_features_arg, int64_t short_channel_id_arg, uint32_t channel_features_arg, int64_t fee_msat_arg, int32_t cltv_expiry_delta_arg) {
14574         LDKPublicKey pubkey_arg_ref;
14575         CHECK(pubkey_arg.len == 33);
14576         memcpy(pubkey_arg_ref.compressed_form, pubkey_arg.ptr, 33);
14577         LDKNodeFeatures node_features_arg_conv;
14578         node_features_arg_conv.inner = (void*)(node_features_arg & (~1));
14579         node_features_arg_conv.is_owned = (node_features_arg & 1) || (node_features_arg == 0);
14580         // Warning: we may need a move here but can't clone!
14581         LDKChannelFeatures channel_features_arg_conv;
14582         channel_features_arg_conv.inner = (void*)(channel_features_arg & (~1));
14583         channel_features_arg_conv.is_owned = (channel_features_arg & 1) || (channel_features_arg == 0);
14584         // Warning: we may need a move here but can't clone!
14585         LDKRouteHop ret_var = RouteHop_new(pubkey_arg_ref, node_features_arg_conv, short_channel_id_arg, channel_features_arg_conv, fee_msat_arg, cltv_expiry_delta_arg);
14586         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14587         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14588         long ret_ref = (long)ret_var.inner;
14589         if (ret_var.is_owned) {
14590                 ret_ref |= 1;
14591         }
14592         return ret_ref;
14593 }
14594
14595 void Route_1free(void* ctx_TODO, uint32_t this_ptr) {
14596         LDKRoute this_ptr_conv;
14597         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14598         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
14599         Route_free(this_ptr_conv);
14600 }
14601
14602 uint32_t Route_1clone(void* ctx_TODO, uint32_t orig) {
14603         LDKRoute orig_conv;
14604         orig_conv.inner = (void*)(orig & (~1));
14605         orig_conv.is_owned = false;
14606         LDKRoute ret_var = Route_clone(&orig_conv);
14607         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14608         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14609         long ret_ref = (long)ret_var.inner;
14610         if (ret_var.is_owned) {
14611                 ret_ref |= 1;
14612         }
14613         return ret_ref;
14614 }
14615
14616 void Route_1set_1paths(void* ctx_TODO, uint32_t this_ptr, ptrArray val) {
14617         LDKRoute this_ptr_conv;
14618         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14619         this_ptr_conv.is_owned = false;
14620         LDKCVec_CVec_RouteHopZZ val_constr;
14621         val_constr.datalen = val.len;
14622         if (val_constr.datalen > 0)
14623                 val_constr.data = MALLOC(val_constr.datalen * sizeof(LDKCVec_RouteHopZ), "LDKCVec_CVec_RouteHopZZ Elements");
14624         else
14625                 val_constr.data = NULL;
14626         uint32_tArray* val_vals = (uint32_tArray*) val.ptr;
14627         for (size_t m = 0; m < val_constr.datalen; m++) {
14628                 uint32_tArray arr_conv_12 = val_vals[m];
14629                 LDKCVec_RouteHopZ arr_conv_12_constr;
14630                 arr_conv_12_constr.datalen = arr_conv_12.len;
14631                 if (arr_conv_12_constr.datalen > 0)
14632                         arr_conv_12_constr.data = MALLOC(arr_conv_12_constr.datalen * sizeof(LDKRouteHop), "LDKCVec_RouteHopZ Elements");
14633                 else
14634                         arr_conv_12_constr.data = NULL;
14635                 uint32_t* arr_conv_12_vals = (uint32_t*) arr_conv_12.ptr;
14636                 for (size_t k = 0; k < arr_conv_12_constr.datalen; k++) {
14637                         uint32_t arr_conv_10 = arr_conv_12_vals[k];
14638                         LDKRouteHop arr_conv_10_conv;
14639                         arr_conv_10_conv.inner = (void*)(arr_conv_10 & (~1));
14640                         arr_conv_10_conv.is_owned = (arr_conv_10 & 1) || (arr_conv_10 == 0);
14641                         if (arr_conv_10_conv.inner != NULL)
14642                                 arr_conv_10_conv = RouteHop_clone(&arr_conv_10_conv);
14643                         arr_conv_12_constr.data[k] = arr_conv_10_conv;
14644                 }
14645                 val_constr.data[m] = arr_conv_12_constr;
14646         }
14647         Route_set_paths(&this_ptr_conv, val_constr);
14648 }
14649
14650 uint32_t Route_1new(void* ctx_TODO, ptrArray paths_arg) {
14651         LDKCVec_CVec_RouteHopZZ paths_arg_constr;
14652         paths_arg_constr.datalen = paths_arg.len;
14653         if (paths_arg_constr.datalen > 0)
14654                 paths_arg_constr.data = MALLOC(paths_arg_constr.datalen * sizeof(LDKCVec_RouteHopZ), "LDKCVec_CVec_RouteHopZZ Elements");
14655         else
14656                 paths_arg_constr.data = NULL;
14657         uint32_tArray* paths_arg_vals = (uint32_tArray*) paths_arg.ptr;
14658         for (size_t m = 0; m < paths_arg_constr.datalen; m++) {
14659                 uint32_tArray arr_conv_12 = paths_arg_vals[m];
14660                 LDKCVec_RouteHopZ arr_conv_12_constr;
14661                 arr_conv_12_constr.datalen = arr_conv_12.len;
14662                 if (arr_conv_12_constr.datalen > 0)
14663                         arr_conv_12_constr.data = MALLOC(arr_conv_12_constr.datalen * sizeof(LDKRouteHop), "LDKCVec_RouteHopZ Elements");
14664                 else
14665                         arr_conv_12_constr.data = NULL;
14666                 uint32_t* arr_conv_12_vals = (uint32_t*) arr_conv_12.ptr;
14667                 for (size_t k = 0; k < arr_conv_12_constr.datalen; k++) {
14668                         uint32_t arr_conv_10 = arr_conv_12_vals[k];
14669                         LDKRouteHop arr_conv_10_conv;
14670                         arr_conv_10_conv.inner = (void*)(arr_conv_10 & (~1));
14671                         arr_conv_10_conv.is_owned = (arr_conv_10 & 1) || (arr_conv_10 == 0);
14672                         if (arr_conv_10_conv.inner != NULL)
14673                                 arr_conv_10_conv = RouteHop_clone(&arr_conv_10_conv);
14674                         arr_conv_12_constr.data[k] = arr_conv_10_conv;
14675                 }
14676                 paths_arg_constr.data[m] = arr_conv_12_constr;
14677         }
14678         LDKRoute ret_var = Route_new(paths_arg_constr);
14679         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14680         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14681         long ret_ref = (long)ret_var.inner;
14682         if (ret_var.is_owned) {
14683                 ret_ref |= 1;
14684         }
14685         return ret_ref;
14686 }
14687
14688 int8_tArray Route_1write(void* ctx_TODO, uint32_t obj) {
14689         LDKRoute obj_conv;
14690         obj_conv.inner = (void*)(obj & (~1));
14691         obj_conv.is_owned = false;
14692         LDKCVec_u8Z arg_var = Route_write(&obj_conv);
14693         int8_tArray arg_arr = { .len = arg_var.datalen, .ptr = MALLOC(arg_var.datalen, "Native int8_tArray Bytes") };
14694         memcpy(arg_arr.ptr, arg_var.data, arg_var.datalen);
14695         CVec_u8Z_free(arg_var);
14696         return arg_arr;
14697 }
14698
14699 uint32_t Route_1read(void* ctx_TODO, int8_tArray ser) {
14700         LDKu8slice ser_ref;
14701         ser_ref.datalen = ser.len;
14702         ser_ref.data = ser.ptr;
14703         LDKCResult_RouteDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_RouteDecodeErrorZ), "LDKCResult_RouteDecodeErrorZ");
14704         *ret_conv = Route_read(ser_ref);
14705         return (long)ret_conv;
14706 }
14707
14708 void RouteHint_1free(void* ctx_TODO, uint32_t this_ptr) {
14709         LDKRouteHint this_ptr_conv;
14710         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14711         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
14712         RouteHint_free(this_ptr_conv);
14713 }
14714
14715 uint32_t RouteHint_1clone(void* ctx_TODO, uint32_t orig) {
14716         LDKRouteHint orig_conv;
14717         orig_conv.inner = (void*)(orig & (~1));
14718         orig_conv.is_owned = false;
14719         LDKRouteHint ret_var = RouteHint_clone(&orig_conv);
14720         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14721         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14722         long ret_ref = (long)ret_var.inner;
14723         if (ret_var.is_owned) {
14724                 ret_ref |= 1;
14725         }
14726         return ret_ref;
14727 }
14728
14729 int8_tArray RouteHint_1get_1src_1node_1id(void* ctx_TODO, uint32_t this_ptr) {
14730         LDKRouteHint this_ptr_conv;
14731         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14732         this_ptr_conv.is_owned = false;
14733         int8_tArray arg_arr = { .len = 33, .ptr = MALLOC(33, "Native int8_tArray Bytes") };
14734         memcpy(arg_arr.ptr, RouteHint_get_src_node_id(&this_ptr_conv).compressed_form, 33);
14735         return arg_arr;
14736 }
14737
14738 void RouteHint_1set_1src_1node_1id(void* ctx_TODO, uint32_t this_ptr, int8_tArray val) {
14739         LDKRouteHint this_ptr_conv;
14740         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14741         this_ptr_conv.is_owned = false;
14742         LDKPublicKey val_ref;
14743         CHECK(val.len == 33);
14744         memcpy(val_ref.compressed_form, val.ptr, 33);
14745         RouteHint_set_src_node_id(&this_ptr_conv, val_ref);
14746 }
14747
14748 int64_t RouteHint_1get_1short_1channel_1id(void* ctx_TODO, uint32_t this_ptr) {
14749         LDKRouteHint this_ptr_conv;
14750         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14751         this_ptr_conv.is_owned = false;
14752         int64_t ret_val = RouteHint_get_short_channel_id(&this_ptr_conv);
14753         return ret_val;
14754 }
14755
14756 void RouteHint_1set_1short_1channel_1id(void* ctx_TODO, uint32_t this_ptr, int64_t val) {
14757         LDKRouteHint this_ptr_conv;
14758         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14759         this_ptr_conv.is_owned = false;
14760         RouteHint_set_short_channel_id(&this_ptr_conv, val);
14761 }
14762
14763 uint32_t RouteHint_1get_1fees(void* ctx_TODO, uint32_t this_ptr) {
14764         LDKRouteHint this_ptr_conv;
14765         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14766         this_ptr_conv.is_owned = false;
14767         LDKRoutingFees ret_var = RouteHint_get_fees(&this_ptr_conv);
14768         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14769         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14770         long ret_ref = (long)ret_var.inner;
14771         if (ret_var.is_owned) {
14772                 ret_ref |= 1;
14773         }
14774         return ret_ref;
14775 }
14776
14777 void RouteHint_1set_1fees(void* ctx_TODO, uint32_t this_ptr, uint32_t val) {
14778         LDKRouteHint this_ptr_conv;
14779         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14780         this_ptr_conv.is_owned = false;
14781         LDKRoutingFees val_conv;
14782         val_conv.inner = (void*)(val & (~1));
14783         val_conv.is_owned = (val & 1) || (val == 0);
14784         if (val_conv.inner != NULL)
14785                 val_conv = RoutingFees_clone(&val_conv);
14786         RouteHint_set_fees(&this_ptr_conv, val_conv);
14787 }
14788
14789 int16_t RouteHint_1get_1cltv_1expiry_1delta(void* ctx_TODO, uint32_t this_ptr) {
14790         LDKRouteHint this_ptr_conv;
14791         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14792         this_ptr_conv.is_owned = false;
14793         int16_t ret_val = RouteHint_get_cltv_expiry_delta(&this_ptr_conv);
14794         return ret_val;
14795 }
14796
14797 void RouteHint_1set_1cltv_1expiry_1delta(void* ctx_TODO, uint32_t this_ptr, int16_t val) {
14798         LDKRouteHint this_ptr_conv;
14799         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14800         this_ptr_conv.is_owned = false;
14801         RouteHint_set_cltv_expiry_delta(&this_ptr_conv, val);
14802 }
14803
14804 int64_t RouteHint_1get_1htlc_1minimum_1msat(void* ctx_TODO, uint32_t this_ptr) {
14805         LDKRouteHint this_ptr_conv;
14806         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14807         this_ptr_conv.is_owned = false;
14808         int64_t ret_val = RouteHint_get_htlc_minimum_msat(&this_ptr_conv);
14809         return ret_val;
14810 }
14811
14812 void RouteHint_1set_1htlc_1minimum_1msat(void* ctx_TODO, uint32_t this_ptr, int64_t val) {
14813         LDKRouteHint this_ptr_conv;
14814         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14815         this_ptr_conv.is_owned = false;
14816         RouteHint_set_htlc_minimum_msat(&this_ptr_conv, val);
14817 }
14818
14819 uint32_t RouteHint_1new(void* ctx_TODO, int8_tArray src_node_id_arg, int64_t short_channel_id_arg, uint32_t fees_arg, int16_t cltv_expiry_delta_arg, int64_t htlc_minimum_msat_arg) {
14820         LDKPublicKey src_node_id_arg_ref;
14821         CHECK(src_node_id_arg.len == 33);
14822         memcpy(src_node_id_arg_ref.compressed_form, src_node_id_arg.ptr, 33);
14823         LDKRoutingFees fees_arg_conv;
14824         fees_arg_conv.inner = (void*)(fees_arg & (~1));
14825         fees_arg_conv.is_owned = (fees_arg & 1) || (fees_arg == 0);
14826         if (fees_arg_conv.inner != NULL)
14827                 fees_arg_conv = RoutingFees_clone(&fees_arg_conv);
14828         LDKRouteHint ret_var = RouteHint_new(src_node_id_arg_ref, short_channel_id_arg, fees_arg_conv, cltv_expiry_delta_arg, htlc_minimum_msat_arg);
14829         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14830         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14831         long ret_ref = (long)ret_var.inner;
14832         if (ret_var.is_owned) {
14833                 ret_ref |= 1;
14834         }
14835         return ret_ref;
14836 }
14837
14838 uint32_t get_1route(void* ctx_TODO, int8_tArray our_node_id, uint32_t network, int8_tArray target, uint32_tArray first_hops, uint32_tArray last_hops, int64_t final_value_msat, int32_t final_cltv, uint32_t logger) {
14839         LDKPublicKey our_node_id_ref;
14840         CHECK(our_node_id.len == 33);
14841         memcpy(our_node_id_ref.compressed_form, our_node_id.ptr, 33);
14842         LDKNetworkGraph network_conv;
14843         network_conv.inner = (void*)(network & (~1));
14844         network_conv.is_owned = false;
14845         LDKPublicKey target_ref;
14846         CHECK(target.len == 33);
14847         memcpy(target_ref.compressed_form, target.ptr, 33);
14848         LDKCVec_ChannelDetailsZ first_hops_constr;
14849         first_hops_constr.datalen = first_hops.len;
14850         if (first_hops_constr.datalen > 0)
14851                 first_hops_constr.data = MALLOC(first_hops_constr.datalen * sizeof(LDKChannelDetails), "LDKCVec_ChannelDetailsZ Elements");
14852         else
14853                 first_hops_constr.data = NULL;
14854         uint32_t* first_hops_vals = (uint32_t*) first_hops.ptr;
14855         for (size_t q = 0; q < first_hops_constr.datalen; q++) {
14856                 uint32_t arr_conv_16 = first_hops_vals[q];
14857                 LDKChannelDetails arr_conv_16_conv;
14858                 arr_conv_16_conv.inner = (void*)(arr_conv_16 & (~1));
14859                 arr_conv_16_conv.is_owned = (arr_conv_16 & 1) || (arr_conv_16 == 0);
14860                 first_hops_constr.data[q] = arr_conv_16_conv;
14861         }
14862         LDKCVec_RouteHintZ last_hops_constr;
14863         last_hops_constr.datalen = last_hops.len;
14864         if (last_hops_constr.datalen > 0)
14865                 last_hops_constr.data = MALLOC(last_hops_constr.datalen * sizeof(LDKRouteHint), "LDKCVec_RouteHintZ Elements");
14866         else
14867                 last_hops_constr.data = NULL;
14868         uint32_t* last_hops_vals = (uint32_t*) last_hops.ptr;
14869         for (size_t l = 0; l < last_hops_constr.datalen; l++) {
14870                 uint32_t arr_conv_11 = last_hops_vals[l];
14871                 LDKRouteHint arr_conv_11_conv;
14872                 arr_conv_11_conv.inner = (void*)(arr_conv_11 & (~1));
14873                 arr_conv_11_conv.is_owned = (arr_conv_11 & 1) || (arr_conv_11 == 0);
14874                 if (arr_conv_11_conv.inner != NULL)
14875                         arr_conv_11_conv = RouteHint_clone(&arr_conv_11_conv);
14876                 last_hops_constr.data[l] = arr_conv_11_conv;
14877         }
14878         LDKLogger logger_conv = *(LDKLogger*)logger;
14879         LDKCResult_RouteLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_RouteLightningErrorZ), "LDKCResult_RouteLightningErrorZ");
14880         *ret_conv = get_route(our_node_id_ref, &network_conv, target_ref, &first_hops_constr, last_hops_constr, final_value_msat, final_cltv, logger_conv);
14881         FREE(first_hops_constr.data);
14882         return (long)ret_conv;
14883 }
14884
14885 void NetworkGraph_1free(void* ctx_TODO, uint32_t this_ptr) {
14886         LDKNetworkGraph this_ptr_conv;
14887         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14888         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
14889         NetworkGraph_free(this_ptr_conv);
14890 }
14891
14892 void LockedNetworkGraph_1free(void* ctx_TODO, uint32_t this_ptr) {
14893         LDKLockedNetworkGraph this_ptr_conv;
14894         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14895         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
14896         LockedNetworkGraph_free(this_ptr_conv);
14897 }
14898
14899 void NetGraphMsgHandler_1free(void* ctx_TODO, uint32_t this_ptr) {
14900         LDKNetGraphMsgHandler this_ptr_conv;
14901         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14902         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
14903         NetGraphMsgHandler_free(this_ptr_conv);
14904 }
14905
14906 uint32_t NetGraphMsgHandler_1new(void* ctx_TODO, int8_tArray genesis_hash, uint32_t chain_access, uint32_t logger) {
14907         LDKThirtyTwoBytes genesis_hash_ref;
14908         CHECK(genesis_hash.len == 32);
14909         memcpy(genesis_hash_ref.data, genesis_hash.ptr, 32);
14910         LDKAccess* chain_access_conv = (LDKAccess*)chain_access;
14911         LDKLogger logger_conv = *(LDKLogger*)logger;
14912         LDKNetGraphMsgHandler ret_var = NetGraphMsgHandler_new(genesis_hash_ref, chain_access_conv, logger_conv);
14913         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14914         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14915         long ret_ref = (long)ret_var.inner;
14916         if (ret_var.is_owned) {
14917                 ret_ref |= 1;
14918         }
14919         return ret_ref;
14920 }
14921
14922 uint32_t NetGraphMsgHandler_1from_1net_1graph(void* ctx_TODO, uint32_t chain_access, uint32_t logger, uint32_t network_graph) {
14923         LDKAccess* chain_access_conv = (LDKAccess*)chain_access;
14924         LDKLogger logger_conv = *(LDKLogger*)logger;
14925         LDKNetworkGraph network_graph_conv;
14926         network_graph_conv.inner = (void*)(network_graph & (~1));
14927         network_graph_conv.is_owned = (network_graph & 1) || (network_graph == 0);
14928         // Warning: we may need a move here but can't clone!
14929         LDKNetGraphMsgHandler ret_var = NetGraphMsgHandler_from_net_graph(chain_access_conv, logger_conv, network_graph_conv);
14930         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14931         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14932         long ret_ref = (long)ret_var.inner;
14933         if (ret_var.is_owned) {
14934                 ret_ref |= 1;
14935         }
14936         return ret_ref;
14937 }
14938
14939 uint32_t NetGraphMsgHandler_1read_1locked_1graph(void* ctx_TODO, uint32_t this_arg) {
14940         LDKNetGraphMsgHandler this_arg_conv;
14941         this_arg_conv.inner = (void*)(this_arg & (~1));
14942         this_arg_conv.is_owned = false;
14943         LDKLockedNetworkGraph ret_var = NetGraphMsgHandler_read_locked_graph(&this_arg_conv);
14944         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14945         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14946         long ret_ref = (long)ret_var.inner;
14947         if (ret_var.is_owned) {
14948                 ret_ref |= 1;
14949         }
14950         return ret_ref;
14951 }
14952
14953 uint32_t LockedNetworkGraph_1graph(void* ctx_TODO, uint32_t this_arg) {
14954         LDKLockedNetworkGraph this_arg_conv;
14955         this_arg_conv.inner = (void*)(this_arg & (~1));
14956         this_arg_conv.is_owned = false;
14957         LDKNetworkGraph ret_var = LockedNetworkGraph_graph(&this_arg_conv);
14958         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14959         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14960         long ret_ref = (long)ret_var.inner;
14961         if (ret_var.is_owned) {
14962                 ret_ref |= 1;
14963         }
14964         return ret_ref;
14965 }
14966
14967 uint32_t NetGraphMsgHandler_1as_1RoutingMessageHandler(void* ctx_TODO, uint32_t this_arg) {
14968         LDKNetGraphMsgHandler this_arg_conv;
14969         this_arg_conv.inner = (void*)(this_arg & (~1));
14970         this_arg_conv.is_owned = false;
14971         LDKRoutingMessageHandler* ret = MALLOC(sizeof(LDKRoutingMessageHandler), "LDKRoutingMessageHandler");
14972         *ret = NetGraphMsgHandler_as_RoutingMessageHandler(&this_arg_conv);
14973         return (long)ret;
14974 }
14975
14976 uint32_t NetGraphMsgHandler_1as_1MessageSendEventsProvider(void* ctx_TODO, uint32_t this_arg) {
14977         LDKNetGraphMsgHandler this_arg_conv;
14978         this_arg_conv.inner = (void*)(this_arg & (~1));
14979         this_arg_conv.is_owned = false;
14980         LDKMessageSendEventsProvider* ret = MALLOC(sizeof(LDKMessageSendEventsProvider), "LDKMessageSendEventsProvider");
14981         *ret = NetGraphMsgHandler_as_MessageSendEventsProvider(&this_arg_conv);
14982         return (long)ret;
14983 }
14984
14985 void DirectionalChannelInfo_1free(void* ctx_TODO, uint32_t this_ptr) {
14986         LDKDirectionalChannelInfo this_ptr_conv;
14987         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14988         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
14989         DirectionalChannelInfo_free(this_ptr_conv);
14990 }
14991
14992 int32_t DirectionalChannelInfo_1get_1last_1update(void* ctx_TODO, uint32_t this_ptr) {
14993         LDKDirectionalChannelInfo this_ptr_conv;
14994         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14995         this_ptr_conv.is_owned = false;
14996         int32_t ret_val = DirectionalChannelInfo_get_last_update(&this_ptr_conv);
14997         return ret_val;
14998 }
14999
15000 void DirectionalChannelInfo_1set_1last_1update(void* ctx_TODO, uint32_t this_ptr, int32_t val) {
15001         LDKDirectionalChannelInfo this_ptr_conv;
15002         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15003         this_ptr_conv.is_owned = false;
15004         DirectionalChannelInfo_set_last_update(&this_ptr_conv, val);
15005 }
15006
15007 jboolean DirectionalChannelInfo_1get_1enabled(void* ctx_TODO, uint32_t this_ptr) {
15008         LDKDirectionalChannelInfo this_ptr_conv;
15009         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15010         this_ptr_conv.is_owned = false;
15011         jboolean ret_val = DirectionalChannelInfo_get_enabled(&this_ptr_conv);
15012         return ret_val;
15013 }
15014
15015 void DirectionalChannelInfo_1set_1enabled(void* ctx_TODO, uint32_t this_ptr, jboolean val) {
15016         LDKDirectionalChannelInfo this_ptr_conv;
15017         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15018         this_ptr_conv.is_owned = false;
15019         DirectionalChannelInfo_set_enabled(&this_ptr_conv, val);
15020 }
15021
15022 int16_t DirectionalChannelInfo_1get_1cltv_1expiry_1delta(void* ctx_TODO, uint32_t this_ptr) {
15023         LDKDirectionalChannelInfo this_ptr_conv;
15024         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15025         this_ptr_conv.is_owned = false;
15026         int16_t ret_val = DirectionalChannelInfo_get_cltv_expiry_delta(&this_ptr_conv);
15027         return ret_val;
15028 }
15029
15030 void DirectionalChannelInfo_1set_1cltv_1expiry_1delta(void* ctx_TODO, uint32_t this_ptr, int16_t val) {
15031         LDKDirectionalChannelInfo this_ptr_conv;
15032         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15033         this_ptr_conv.is_owned = false;
15034         DirectionalChannelInfo_set_cltv_expiry_delta(&this_ptr_conv, val);
15035 }
15036
15037 int64_t DirectionalChannelInfo_1get_1htlc_1minimum_1msat(void* ctx_TODO, uint32_t this_ptr) {
15038         LDKDirectionalChannelInfo this_ptr_conv;
15039         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15040         this_ptr_conv.is_owned = false;
15041         int64_t ret_val = DirectionalChannelInfo_get_htlc_minimum_msat(&this_ptr_conv);
15042         return ret_val;
15043 }
15044
15045 void DirectionalChannelInfo_1set_1htlc_1minimum_1msat(void* ctx_TODO, uint32_t this_ptr, int64_t val) {
15046         LDKDirectionalChannelInfo this_ptr_conv;
15047         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15048         this_ptr_conv.is_owned = false;
15049         DirectionalChannelInfo_set_htlc_minimum_msat(&this_ptr_conv, val);
15050 }
15051
15052 uint32_t DirectionalChannelInfo_1get_1fees(void* ctx_TODO, uint32_t this_ptr) {
15053         LDKDirectionalChannelInfo this_ptr_conv;
15054         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15055         this_ptr_conv.is_owned = false;
15056         LDKRoutingFees ret_var = DirectionalChannelInfo_get_fees(&this_ptr_conv);
15057         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15058         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15059         long ret_ref = (long)ret_var.inner;
15060         if (ret_var.is_owned) {
15061                 ret_ref |= 1;
15062         }
15063         return ret_ref;
15064 }
15065
15066 void DirectionalChannelInfo_1set_1fees(void* ctx_TODO, uint32_t this_ptr, uint32_t val) {
15067         LDKDirectionalChannelInfo this_ptr_conv;
15068         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15069         this_ptr_conv.is_owned = false;
15070         LDKRoutingFees val_conv;
15071         val_conv.inner = (void*)(val & (~1));
15072         val_conv.is_owned = (val & 1) || (val == 0);
15073         if (val_conv.inner != NULL)
15074                 val_conv = RoutingFees_clone(&val_conv);
15075         DirectionalChannelInfo_set_fees(&this_ptr_conv, val_conv);
15076 }
15077
15078 uint32_t DirectionalChannelInfo_1get_1last_1update_1message(void* ctx_TODO, uint32_t this_ptr) {
15079         LDKDirectionalChannelInfo this_ptr_conv;
15080         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15081         this_ptr_conv.is_owned = false;
15082         LDKChannelUpdate ret_var = DirectionalChannelInfo_get_last_update_message(&this_ptr_conv);
15083         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15084         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15085         long ret_ref = (long)ret_var.inner;
15086         if (ret_var.is_owned) {
15087                 ret_ref |= 1;
15088         }
15089         return ret_ref;
15090 }
15091
15092 void DirectionalChannelInfo_1set_1last_1update_1message(void* ctx_TODO, uint32_t this_ptr, uint32_t val) {
15093         LDKDirectionalChannelInfo this_ptr_conv;
15094         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15095         this_ptr_conv.is_owned = false;
15096         LDKChannelUpdate val_conv;
15097         val_conv.inner = (void*)(val & (~1));
15098         val_conv.is_owned = (val & 1) || (val == 0);
15099         if (val_conv.inner != NULL)
15100                 val_conv = ChannelUpdate_clone(&val_conv);
15101         DirectionalChannelInfo_set_last_update_message(&this_ptr_conv, val_conv);
15102 }
15103
15104 int8_tArray DirectionalChannelInfo_1write(void* ctx_TODO, uint32_t obj) {
15105         LDKDirectionalChannelInfo obj_conv;
15106         obj_conv.inner = (void*)(obj & (~1));
15107         obj_conv.is_owned = false;
15108         LDKCVec_u8Z arg_var = DirectionalChannelInfo_write(&obj_conv);
15109         int8_tArray arg_arr = { .len = arg_var.datalen, .ptr = MALLOC(arg_var.datalen, "Native int8_tArray Bytes") };
15110         memcpy(arg_arr.ptr, arg_var.data, arg_var.datalen);
15111         CVec_u8Z_free(arg_var);
15112         return arg_arr;
15113 }
15114
15115 uint32_t DirectionalChannelInfo_1read(void* ctx_TODO, int8_tArray ser) {
15116         LDKu8slice ser_ref;
15117         ser_ref.datalen = ser.len;
15118         ser_ref.data = ser.ptr;
15119         LDKDirectionalChannelInfo ret_var = DirectionalChannelInfo_read(ser_ref);
15120         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15121         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15122         long ret_ref = (long)ret_var.inner;
15123         if (ret_var.is_owned) {
15124                 ret_ref |= 1;
15125         }
15126         return ret_ref;
15127 }
15128
15129 void ChannelInfo_1free(void* ctx_TODO, uint32_t this_ptr) {
15130         LDKChannelInfo this_ptr_conv;
15131         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15132         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
15133         ChannelInfo_free(this_ptr_conv);
15134 }
15135
15136 uint32_t ChannelInfo_1get_1features(void* ctx_TODO, uint32_t this_ptr) {
15137         LDKChannelInfo this_ptr_conv;
15138         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15139         this_ptr_conv.is_owned = false;
15140         LDKChannelFeatures ret_var = ChannelInfo_get_features(&this_ptr_conv);
15141         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15142         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15143         long ret_ref = (long)ret_var.inner;
15144         if (ret_var.is_owned) {
15145                 ret_ref |= 1;
15146         }
15147         return ret_ref;
15148 }
15149
15150 void ChannelInfo_1set_1features(void* ctx_TODO, uint32_t this_ptr, uint32_t val) {
15151         LDKChannelInfo this_ptr_conv;
15152         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15153         this_ptr_conv.is_owned = false;
15154         LDKChannelFeatures val_conv;
15155         val_conv.inner = (void*)(val & (~1));
15156         val_conv.is_owned = (val & 1) || (val == 0);
15157         // Warning: we may need a move here but can't clone!
15158         ChannelInfo_set_features(&this_ptr_conv, val_conv);
15159 }
15160
15161 int8_tArray ChannelInfo_1get_1node_1one(void* ctx_TODO, uint32_t this_ptr) {
15162         LDKChannelInfo this_ptr_conv;
15163         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15164         this_ptr_conv.is_owned = false;
15165         int8_tArray arg_arr = { .len = 33, .ptr = MALLOC(33, "Native int8_tArray Bytes") };
15166         memcpy(arg_arr.ptr, ChannelInfo_get_node_one(&this_ptr_conv).compressed_form, 33);
15167         return arg_arr;
15168 }
15169
15170 void ChannelInfo_1set_1node_1one(void* ctx_TODO, uint32_t this_ptr, int8_tArray val) {
15171         LDKChannelInfo this_ptr_conv;
15172         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15173         this_ptr_conv.is_owned = false;
15174         LDKPublicKey val_ref;
15175         CHECK(val.len == 33);
15176         memcpy(val_ref.compressed_form, val.ptr, 33);
15177         ChannelInfo_set_node_one(&this_ptr_conv, val_ref);
15178 }
15179
15180 uint32_t ChannelInfo_1get_1one_1to_1two(void* ctx_TODO, uint32_t this_ptr) {
15181         LDKChannelInfo this_ptr_conv;
15182         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15183         this_ptr_conv.is_owned = false;
15184         LDKDirectionalChannelInfo ret_var = ChannelInfo_get_one_to_two(&this_ptr_conv);
15185         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15186         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15187         long ret_ref = (long)ret_var.inner;
15188         if (ret_var.is_owned) {
15189                 ret_ref |= 1;
15190         }
15191         return ret_ref;
15192 }
15193
15194 void ChannelInfo_1set_1one_1to_1two(void* ctx_TODO, uint32_t this_ptr, uint32_t val) {
15195         LDKChannelInfo this_ptr_conv;
15196         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15197         this_ptr_conv.is_owned = false;
15198         LDKDirectionalChannelInfo val_conv;
15199         val_conv.inner = (void*)(val & (~1));
15200         val_conv.is_owned = (val & 1) || (val == 0);
15201         // Warning: we may need a move here but can't clone!
15202         ChannelInfo_set_one_to_two(&this_ptr_conv, val_conv);
15203 }
15204
15205 int8_tArray ChannelInfo_1get_1node_1two(void* ctx_TODO, uint32_t this_ptr) {
15206         LDKChannelInfo this_ptr_conv;
15207         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15208         this_ptr_conv.is_owned = false;
15209         int8_tArray arg_arr = { .len = 33, .ptr = MALLOC(33, "Native int8_tArray Bytes") };
15210         memcpy(arg_arr.ptr, ChannelInfo_get_node_two(&this_ptr_conv).compressed_form, 33);
15211         return arg_arr;
15212 }
15213
15214 void ChannelInfo_1set_1node_1two(void* ctx_TODO, uint32_t this_ptr, int8_tArray val) {
15215         LDKChannelInfo this_ptr_conv;
15216         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15217         this_ptr_conv.is_owned = false;
15218         LDKPublicKey val_ref;
15219         CHECK(val.len == 33);
15220         memcpy(val_ref.compressed_form, val.ptr, 33);
15221         ChannelInfo_set_node_two(&this_ptr_conv, val_ref);
15222 }
15223
15224 uint32_t ChannelInfo_1get_1two_1to_1one(void* ctx_TODO, uint32_t this_ptr) {
15225         LDKChannelInfo this_ptr_conv;
15226         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15227         this_ptr_conv.is_owned = false;
15228         LDKDirectionalChannelInfo ret_var = ChannelInfo_get_two_to_one(&this_ptr_conv);
15229         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15230         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15231         long ret_ref = (long)ret_var.inner;
15232         if (ret_var.is_owned) {
15233                 ret_ref |= 1;
15234         }
15235         return ret_ref;
15236 }
15237
15238 void ChannelInfo_1set_1two_1to_1one(void* ctx_TODO, uint32_t this_ptr, uint32_t val) {
15239         LDKChannelInfo this_ptr_conv;
15240         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15241         this_ptr_conv.is_owned = false;
15242         LDKDirectionalChannelInfo val_conv;
15243         val_conv.inner = (void*)(val & (~1));
15244         val_conv.is_owned = (val & 1) || (val == 0);
15245         // Warning: we may need a move here but can't clone!
15246         ChannelInfo_set_two_to_one(&this_ptr_conv, val_conv);
15247 }
15248
15249 uint32_t ChannelInfo_1get_1announcement_1message(void* ctx_TODO, uint32_t this_ptr) {
15250         LDKChannelInfo this_ptr_conv;
15251         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15252         this_ptr_conv.is_owned = false;
15253         LDKChannelAnnouncement ret_var = ChannelInfo_get_announcement_message(&this_ptr_conv);
15254         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15255         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15256         long ret_ref = (long)ret_var.inner;
15257         if (ret_var.is_owned) {
15258                 ret_ref |= 1;
15259         }
15260         return ret_ref;
15261 }
15262
15263 void ChannelInfo_1set_1announcement_1message(void* ctx_TODO, uint32_t this_ptr, uint32_t val) {
15264         LDKChannelInfo this_ptr_conv;
15265         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15266         this_ptr_conv.is_owned = false;
15267         LDKChannelAnnouncement val_conv;
15268         val_conv.inner = (void*)(val & (~1));
15269         val_conv.is_owned = (val & 1) || (val == 0);
15270         if (val_conv.inner != NULL)
15271                 val_conv = ChannelAnnouncement_clone(&val_conv);
15272         ChannelInfo_set_announcement_message(&this_ptr_conv, val_conv);
15273 }
15274
15275 int8_tArray ChannelInfo_1write(void* ctx_TODO, uint32_t obj) {
15276         LDKChannelInfo obj_conv;
15277         obj_conv.inner = (void*)(obj & (~1));
15278         obj_conv.is_owned = false;
15279         LDKCVec_u8Z arg_var = ChannelInfo_write(&obj_conv);
15280         int8_tArray arg_arr = { .len = arg_var.datalen, .ptr = MALLOC(arg_var.datalen, "Native int8_tArray Bytes") };
15281         memcpy(arg_arr.ptr, arg_var.data, arg_var.datalen);
15282         CVec_u8Z_free(arg_var);
15283         return arg_arr;
15284 }
15285
15286 uint32_t ChannelInfo_1read(void* ctx_TODO, int8_tArray ser) {
15287         LDKu8slice ser_ref;
15288         ser_ref.datalen = ser.len;
15289         ser_ref.data = ser.ptr;
15290         LDKChannelInfo ret_var = ChannelInfo_read(ser_ref);
15291         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15292         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15293         long ret_ref = (long)ret_var.inner;
15294         if (ret_var.is_owned) {
15295                 ret_ref |= 1;
15296         }
15297         return ret_ref;
15298 }
15299
15300 void RoutingFees_1free(void* ctx_TODO, uint32_t this_ptr) {
15301         LDKRoutingFees this_ptr_conv;
15302         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15303         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
15304         RoutingFees_free(this_ptr_conv);
15305 }
15306
15307 uint32_t RoutingFees_1clone(void* ctx_TODO, uint32_t orig) {
15308         LDKRoutingFees orig_conv;
15309         orig_conv.inner = (void*)(orig & (~1));
15310         orig_conv.is_owned = false;
15311         LDKRoutingFees ret_var = RoutingFees_clone(&orig_conv);
15312         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15313         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15314         long ret_ref = (long)ret_var.inner;
15315         if (ret_var.is_owned) {
15316                 ret_ref |= 1;
15317         }
15318         return ret_ref;
15319 }
15320
15321 int32_t RoutingFees_1get_1base_1msat(void* ctx_TODO, uint32_t this_ptr) {
15322         LDKRoutingFees this_ptr_conv;
15323         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15324         this_ptr_conv.is_owned = false;
15325         int32_t ret_val = RoutingFees_get_base_msat(&this_ptr_conv);
15326         return ret_val;
15327 }
15328
15329 void RoutingFees_1set_1base_1msat(void* ctx_TODO, uint32_t this_ptr, int32_t val) {
15330         LDKRoutingFees this_ptr_conv;
15331         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15332         this_ptr_conv.is_owned = false;
15333         RoutingFees_set_base_msat(&this_ptr_conv, val);
15334 }
15335
15336 int32_t RoutingFees_1get_1proportional_1millionths(void* ctx_TODO, uint32_t this_ptr) {
15337         LDKRoutingFees this_ptr_conv;
15338         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15339         this_ptr_conv.is_owned = false;
15340         int32_t ret_val = RoutingFees_get_proportional_millionths(&this_ptr_conv);
15341         return ret_val;
15342 }
15343
15344 void RoutingFees_1set_1proportional_1millionths(void* ctx_TODO, uint32_t this_ptr, int32_t val) {
15345         LDKRoutingFees this_ptr_conv;
15346         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15347         this_ptr_conv.is_owned = false;
15348         RoutingFees_set_proportional_millionths(&this_ptr_conv, val);
15349 }
15350
15351 uint32_t RoutingFees_1new(void* ctx_TODO, int32_t base_msat_arg, int32_t proportional_millionths_arg) {
15352         LDKRoutingFees ret_var = RoutingFees_new(base_msat_arg, proportional_millionths_arg);
15353         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15354         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15355         long ret_ref = (long)ret_var.inner;
15356         if (ret_var.is_owned) {
15357                 ret_ref |= 1;
15358         }
15359         return ret_ref;
15360 }
15361
15362 uint32_t RoutingFees_1read(void* ctx_TODO, int8_tArray ser) {
15363         LDKu8slice ser_ref;
15364         ser_ref.datalen = ser.len;
15365         ser_ref.data = ser.ptr;
15366         LDKCResult_RoutingFeesDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_RoutingFeesDecodeErrorZ), "LDKCResult_RoutingFeesDecodeErrorZ");
15367         *ret_conv = RoutingFees_read(ser_ref);
15368         return (long)ret_conv;
15369 }
15370
15371 int8_tArray RoutingFees_1write(void* ctx_TODO, uint32_t obj) {
15372         LDKRoutingFees obj_conv;
15373         obj_conv.inner = (void*)(obj & (~1));
15374         obj_conv.is_owned = false;
15375         LDKCVec_u8Z arg_var = RoutingFees_write(&obj_conv);
15376         int8_tArray arg_arr = { .len = arg_var.datalen, .ptr = MALLOC(arg_var.datalen, "Native int8_tArray Bytes") };
15377         memcpy(arg_arr.ptr, arg_var.data, arg_var.datalen);
15378         CVec_u8Z_free(arg_var);
15379         return arg_arr;
15380 }
15381
15382 void NodeAnnouncementInfo_1free(void* ctx_TODO, uint32_t this_ptr) {
15383         LDKNodeAnnouncementInfo this_ptr_conv;
15384         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15385         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
15386         NodeAnnouncementInfo_free(this_ptr_conv);
15387 }
15388
15389 uint32_t NodeAnnouncementInfo_1get_1features(void* ctx_TODO, uint32_t this_ptr) {
15390         LDKNodeAnnouncementInfo this_ptr_conv;
15391         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15392         this_ptr_conv.is_owned = false;
15393         LDKNodeFeatures ret_var = NodeAnnouncementInfo_get_features(&this_ptr_conv);
15394         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15395         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15396         long ret_ref = (long)ret_var.inner;
15397         if (ret_var.is_owned) {
15398                 ret_ref |= 1;
15399         }
15400         return ret_ref;
15401 }
15402
15403 void NodeAnnouncementInfo_1set_1features(void* ctx_TODO, uint32_t this_ptr, uint32_t val) {
15404         LDKNodeAnnouncementInfo this_ptr_conv;
15405         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15406         this_ptr_conv.is_owned = false;
15407         LDKNodeFeatures val_conv;
15408         val_conv.inner = (void*)(val & (~1));
15409         val_conv.is_owned = (val & 1) || (val == 0);
15410         // Warning: we may need a move here but can't clone!
15411         NodeAnnouncementInfo_set_features(&this_ptr_conv, val_conv);
15412 }
15413
15414 int32_t NodeAnnouncementInfo_1get_1last_1update(void* ctx_TODO, uint32_t this_ptr) {
15415         LDKNodeAnnouncementInfo this_ptr_conv;
15416         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15417         this_ptr_conv.is_owned = false;
15418         int32_t ret_val = NodeAnnouncementInfo_get_last_update(&this_ptr_conv);
15419         return ret_val;
15420 }
15421
15422 void NodeAnnouncementInfo_1set_1last_1update(void* ctx_TODO, uint32_t this_ptr, int32_t val) {
15423         LDKNodeAnnouncementInfo this_ptr_conv;
15424         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15425         this_ptr_conv.is_owned = false;
15426         NodeAnnouncementInfo_set_last_update(&this_ptr_conv, val);
15427 }
15428
15429 int8_tArray NodeAnnouncementInfo_1get_1rgb(void* ctx_TODO, uint32_t this_ptr) {
15430         LDKNodeAnnouncementInfo this_ptr_conv;
15431         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15432         this_ptr_conv.is_owned = false;
15433         int8_tArray ret_arr = { .len = 3, .ptr = MALLOC(3, "Native int8_tArray Bytes") };
15434         memcpy(ret_arr.ptr, *NodeAnnouncementInfo_get_rgb(&this_ptr_conv), 3);
15435         return ret_arr;
15436 }
15437
15438 void NodeAnnouncementInfo_1set_1rgb(void* ctx_TODO, uint32_t this_ptr, int8_tArray val) {
15439         LDKNodeAnnouncementInfo this_ptr_conv;
15440         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15441         this_ptr_conv.is_owned = false;
15442         LDKThreeBytes val_ref;
15443         CHECK(val.len == 3);
15444         memcpy(val_ref.data, val.ptr, 3);
15445         NodeAnnouncementInfo_set_rgb(&this_ptr_conv, val_ref);
15446 }
15447
15448 int8_tArray NodeAnnouncementInfo_1get_1alias(void* ctx_TODO, uint32_t this_ptr) {
15449         LDKNodeAnnouncementInfo this_ptr_conv;
15450         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15451         this_ptr_conv.is_owned = false;
15452         int8_tArray ret_arr = { .len = 32, .ptr = MALLOC(32, "Native int8_tArray Bytes") };
15453         memcpy(ret_arr.ptr, *NodeAnnouncementInfo_get_alias(&this_ptr_conv), 32);
15454         return ret_arr;
15455 }
15456
15457 void NodeAnnouncementInfo_1set_1alias(void* ctx_TODO, uint32_t this_ptr, int8_tArray val) {
15458         LDKNodeAnnouncementInfo this_ptr_conv;
15459         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15460         this_ptr_conv.is_owned = false;
15461         LDKThirtyTwoBytes val_ref;
15462         CHECK(val.len == 32);
15463         memcpy(val_ref.data, val.ptr, 32);
15464         NodeAnnouncementInfo_set_alias(&this_ptr_conv, val_ref);
15465 }
15466
15467 void NodeAnnouncementInfo_1set_1addresses(void* ctx_TODO, uint32_t this_ptr, uint32_tArray val) {
15468         LDKNodeAnnouncementInfo this_ptr_conv;
15469         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15470         this_ptr_conv.is_owned = false;
15471         LDKCVec_NetAddressZ val_constr;
15472         val_constr.datalen = val.len;
15473         if (val_constr.datalen > 0)
15474                 val_constr.data = MALLOC(val_constr.datalen * sizeof(LDKNetAddress), "LDKCVec_NetAddressZ Elements");
15475         else
15476                 val_constr.data = NULL;
15477         uint32_t* val_vals = (uint32_t*) val.ptr;
15478         for (size_t m = 0; m < val_constr.datalen; m++) {
15479                 uint32_t arr_conv_12 = val_vals[m];
15480                 LDKNetAddress arr_conv_12_conv = *(LDKNetAddress*)arr_conv_12;
15481                 FREE((void*)arr_conv_12);
15482                 val_constr.data[m] = arr_conv_12_conv;
15483         }
15484         NodeAnnouncementInfo_set_addresses(&this_ptr_conv, val_constr);
15485 }
15486
15487 uint32_t NodeAnnouncementInfo_1get_1announcement_1message(void* ctx_TODO, uint32_t this_ptr) {
15488         LDKNodeAnnouncementInfo this_ptr_conv;
15489         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15490         this_ptr_conv.is_owned = false;
15491         LDKNodeAnnouncement ret_var = NodeAnnouncementInfo_get_announcement_message(&this_ptr_conv);
15492         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15493         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15494         long ret_ref = (long)ret_var.inner;
15495         if (ret_var.is_owned) {
15496                 ret_ref |= 1;
15497         }
15498         return ret_ref;
15499 }
15500
15501 void NodeAnnouncementInfo_1set_1announcement_1message(void* ctx_TODO, uint32_t this_ptr, uint32_t val) {
15502         LDKNodeAnnouncementInfo this_ptr_conv;
15503         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15504         this_ptr_conv.is_owned = false;
15505         LDKNodeAnnouncement val_conv;
15506         val_conv.inner = (void*)(val & (~1));
15507         val_conv.is_owned = (val & 1) || (val == 0);
15508         if (val_conv.inner != NULL)
15509                 val_conv = NodeAnnouncement_clone(&val_conv);
15510         NodeAnnouncementInfo_set_announcement_message(&this_ptr_conv, val_conv);
15511 }
15512
15513 uint32_t NodeAnnouncementInfo_1new(void* ctx_TODO, uint32_t features_arg, int32_t last_update_arg, int8_tArray rgb_arg, int8_tArray alias_arg, uint32_tArray addresses_arg, uint32_t announcement_message_arg) {
15514         LDKNodeFeatures features_arg_conv;
15515         features_arg_conv.inner = (void*)(features_arg & (~1));
15516         features_arg_conv.is_owned = (features_arg & 1) || (features_arg == 0);
15517         // Warning: we may need a move here but can't clone!
15518         LDKThreeBytes rgb_arg_ref;
15519         CHECK(rgb_arg.len == 3);
15520         memcpy(rgb_arg_ref.data, rgb_arg.ptr, 3);
15521         LDKThirtyTwoBytes alias_arg_ref;
15522         CHECK(alias_arg.len == 32);
15523         memcpy(alias_arg_ref.data, alias_arg.ptr, 32);
15524         LDKCVec_NetAddressZ addresses_arg_constr;
15525         addresses_arg_constr.datalen = addresses_arg.len;
15526         if (addresses_arg_constr.datalen > 0)
15527                 addresses_arg_constr.data = MALLOC(addresses_arg_constr.datalen * sizeof(LDKNetAddress), "LDKCVec_NetAddressZ Elements");
15528         else
15529                 addresses_arg_constr.data = NULL;
15530         uint32_t* addresses_arg_vals = (uint32_t*) addresses_arg.ptr;
15531         for (size_t m = 0; m < addresses_arg_constr.datalen; m++) {
15532                 uint32_t arr_conv_12 = addresses_arg_vals[m];
15533                 LDKNetAddress arr_conv_12_conv = *(LDKNetAddress*)arr_conv_12;
15534                 FREE((void*)arr_conv_12);
15535                 addresses_arg_constr.data[m] = arr_conv_12_conv;
15536         }
15537         LDKNodeAnnouncement announcement_message_arg_conv;
15538         announcement_message_arg_conv.inner = (void*)(announcement_message_arg & (~1));
15539         announcement_message_arg_conv.is_owned = (announcement_message_arg & 1) || (announcement_message_arg == 0);
15540         if (announcement_message_arg_conv.inner != NULL)
15541                 announcement_message_arg_conv = NodeAnnouncement_clone(&announcement_message_arg_conv);
15542         LDKNodeAnnouncementInfo ret_var = NodeAnnouncementInfo_new(features_arg_conv, last_update_arg, rgb_arg_ref, alias_arg_ref, addresses_arg_constr, announcement_message_arg_conv);
15543         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15544         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15545         long ret_ref = (long)ret_var.inner;
15546         if (ret_var.is_owned) {
15547                 ret_ref |= 1;
15548         }
15549         return ret_ref;
15550 }
15551
15552 int8_tArray NodeAnnouncementInfo_1write(void* ctx_TODO, uint32_t obj) {
15553         LDKNodeAnnouncementInfo obj_conv;
15554         obj_conv.inner = (void*)(obj & (~1));
15555         obj_conv.is_owned = false;
15556         LDKCVec_u8Z arg_var = NodeAnnouncementInfo_write(&obj_conv);
15557         int8_tArray arg_arr = { .len = arg_var.datalen, .ptr = MALLOC(arg_var.datalen, "Native int8_tArray Bytes") };
15558         memcpy(arg_arr.ptr, arg_var.data, arg_var.datalen);
15559         CVec_u8Z_free(arg_var);
15560         return arg_arr;
15561 }
15562
15563 uint32_t NodeAnnouncementInfo_1read(void* ctx_TODO, int8_tArray ser) {
15564         LDKu8slice ser_ref;
15565         ser_ref.datalen = ser.len;
15566         ser_ref.data = ser.ptr;
15567         LDKCResult_NodeAnnouncementInfoDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NodeAnnouncementInfoDecodeErrorZ), "LDKCResult_NodeAnnouncementInfoDecodeErrorZ");
15568         *ret_conv = NodeAnnouncementInfo_read(ser_ref);
15569         return (long)ret_conv;
15570 }
15571
15572 void NodeInfo_1free(void* ctx_TODO, uint32_t this_ptr) {
15573         LDKNodeInfo this_ptr_conv;
15574         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15575         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
15576         NodeInfo_free(this_ptr_conv);
15577 }
15578
15579 void NodeInfo_1set_1channels(void* ctx_TODO, uint32_t this_ptr, int64_tArray val) {
15580         LDKNodeInfo this_ptr_conv;
15581         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15582         this_ptr_conv.is_owned = false;
15583         LDKCVec_u64Z val_constr;
15584         val_constr.datalen = val.len;
15585         if (val_constr.datalen > 0)
15586                 val_constr.data = MALLOC(val_constr.datalen * sizeof(int64_t), "LDKCVec_u64Z Elements");
15587         else
15588                 val_constr.data = NULL;
15589         int64_t* val_vals = (int64_t*) val.ptr;
15590         for (size_t i = 0; i < val_constr.datalen; i++) {
15591                 int64_t arr_conv_8 = val_vals[i];
15592                 val_constr.data[i] = arr_conv_8;
15593         }
15594         NodeInfo_set_channels(&this_ptr_conv, val_constr);
15595 }
15596
15597 uint32_t NodeInfo_1get_1lowest_1inbound_1channel_1fees(void* ctx_TODO, uint32_t this_ptr) {
15598         LDKNodeInfo this_ptr_conv;
15599         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15600         this_ptr_conv.is_owned = false;
15601         LDKRoutingFees ret_var = NodeInfo_get_lowest_inbound_channel_fees(&this_ptr_conv);
15602         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15603         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15604         long ret_ref = (long)ret_var.inner;
15605         if (ret_var.is_owned) {
15606                 ret_ref |= 1;
15607         }
15608         return ret_ref;
15609 }
15610
15611 void NodeInfo_1set_1lowest_1inbound_1channel_1fees(void* ctx_TODO, uint32_t this_ptr, uint32_t val) {
15612         LDKNodeInfo this_ptr_conv;
15613         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15614         this_ptr_conv.is_owned = false;
15615         LDKRoutingFees val_conv;
15616         val_conv.inner = (void*)(val & (~1));
15617         val_conv.is_owned = (val & 1) || (val == 0);
15618         if (val_conv.inner != NULL)
15619                 val_conv = RoutingFees_clone(&val_conv);
15620         NodeInfo_set_lowest_inbound_channel_fees(&this_ptr_conv, val_conv);
15621 }
15622
15623 uint32_t NodeInfo_1get_1announcement_1info(void* ctx_TODO, uint32_t this_ptr) {
15624         LDKNodeInfo this_ptr_conv;
15625         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15626         this_ptr_conv.is_owned = false;
15627         LDKNodeAnnouncementInfo ret_var = NodeInfo_get_announcement_info(&this_ptr_conv);
15628         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15629         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15630         long ret_ref = (long)ret_var.inner;
15631         if (ret_var.is_owned) {
15632                 ret_ref |= 1;
15633         }
15634         return ret_ref;
15635 }
15636
15637 void NodeInfo_1set_1announcement_1info(void* ctx_TODO, uint32_t this_ptr, uint32_t val) {
15638         LDKNodeInfo this_ptr_conv;
15639         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15640         this_ptr_conv.is_owned = false;
15641         LDKNodeAnnouncementInfo val_conv;
15642         val_conv.inner = (void*)(val & (~1));
15643         val_conv.is_owned = (val & 1) || (val == 0);
15644         // Warning: we may need a move here but can't clone!
15645         NodeInfo_set_announcement_info(&this_ptr_conv, val_conv);
15646 }
15647
15648 uint32_t NodeInfo_1new(void* ctx_TODO, int64_tArray channels_arg, uint32_t lowest_inbound_channel_fees_arg, uint32_t announcement_info_arg) {
15649         LDKCVec_u64Z channels_arg_constr;
15650         channels_arg_constr.datalen = channels_arg.len;
15651         if (channels_arg_constr.datalen > 0)
15652                 channels_arg_constr.data = MALLOC(channels_arg_constr.datalen * sizeof(int64_t), "LDKCVec_u64Z Elements");
15653         else
15654                 channels_arg_constr.data = NULL;
15655         int64_t* channels_arg_vals = (int64_t*) channels_arg.ptr;
15656         for (size_t i = 0; i < channels_arg_constr.datalen; i++) {
15657                 int64_t arr_conv_8 = channels_arg_vals[i];
15658                 channels_arg_constr.data[i] = arr_conv_8;
15659         }
15660         LDKRoutingFees lowest_inbound_channel_fees_arg_conv;
15661         lowest_inbound_channel_fees_arg_conv.inner = (void*)(lowest_inbound_channel_fees_arg & (~1));
15662         lowest_inbound_channel_fees_arg_conv.is_owned = (lowest_inbound_channel_fees_arg & 1) || (lowest_inbound_channel_fees_arg == 0);
15663         if (lowest_inbound_channel_fees_arg_conv.inner != NULL)
15664                 lowest_inbound_channel_fees_arg_conv = RoutingFees_clone(&lowest_inbound_channel_fees_arg_conv);
15665         LDKNodeAnnouncementInfo announcement_info_arg_conv;
15666         announcement_info_arg_conv.inner = (void*)(announcement_info_arg & (~1));
15667         announcement_info_arg_conv.is_owned = (announcement_info_arg & 1) || (announcement_info_arg == 0);
15668         // Warning: we may need a move here but can't clone!
15669         LDKNodeInfo ret_var = NodeInfo_new(channels_arg_constr, lowest_inbound_channel_fees_arg_conv, announcement_info_arg_conv);
15670         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15671         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15672         long ret_ref = (long)ret_var.inner;
15673         if (ret_var.is_owned) {
15674                 ret_ref |= 1;
15675         }
15676         return ret_ref;
15677 }
15678
15679 int8_tArray NodeInfo_1write(void* ctx_TODO, uint32_t obj) {
15680         LDKNodeInfo obj_conv;
15681         obj_conv.inner = (void*)(obj & (~1));
15682         obj_conv.is_owned = false;
15683         LDKCVec_u8Z arg_var = NodeInfo_write(&obj_conv);
15684         int8_tArray arg_arr = { .len = arg_var.datalen, .ptr = MALLOC(arg_var.datalen, "Native int8_tArray Bytes") };
15685         memcpy(arg_arr.ptr, arg_var.data, arg_var.datalen);
15686         CVec_u8Z_free(arg_var);
15687         return arg_arr;
15688 }
15689
15690 uint32_t NodeInfo_1read(void* ctx_TODO, int8_tArray ser) {
15691         LDKu8slice ser_ref;
15692         ser_ref.datalen = ser.len;
15693         ser_ref.data = ser.ptr;
15694         LDKCResult_NodeInfoDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NodeInfoDecodeErrorZ), "LDKCResult_NodeInfoDecodeErrorZ");
15695         *ret_conv = NodeInfo_read(ser_ref);
15696         return (long)ret_conv;
15697 }
15698
15699 int8_tArray NetworkGraph_1write(void* ctx_TODO, uint32_t obj) {
15700         LDKNetworkGraph obj_conv;
15701         obj_conv.inner = (void*)(obj & (~1));
15702         obj_conv.is_owned = false;
15703         LDKCVec_u8Z arg_var = NetworkGraph_write(&obj_conv);
15704         int8_tArray arg_arr = { .len = arg_var.datalen, .ptr = MALLOC(arg_var.datalen, "Native int8_tArray Bytes") };
15705         memcpy(arg_arr.ptr, arg_var.data, arg_var.datalen);
15706         CVec_u8Z_free(arg_var);
15707         return arg_arr;
15708 }
15709
15710 uint32_t NetworkGraph_1read(void* ctx_TODO, int8_tArray ser) {
15711         LDKu8slice ser_ref;
15712         ser_ref.datalen = ser.len;
15713         ser_ref.data = ser.ptr;
15714         LDKCResult_NetworkGraphDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NetworkGraphDecodeErrorZ), "LDKCResult_NetworkGraphDecodeErrorZ");
15715         *ret_conv = NetworkGraph_read(ser_ref);
15716         return (long)ret_conv;
15717 }
15718
15719 uint32_t NetworkGraph_1new(void* ctx_TODO, int8_tArray genesis_hash) {
15720         LDKThirtyTwoBytes genesis_hash_ref;
15721         CHECK(genesis_hash.len == 32);
15722         memcpy(genesis_hash_ref.data, genesis_hash.ptr, 32);
15723         LDKNetworkGraph ret_var = NetworkGraph_new(genesis_hash_ref);
15724         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15725         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15726         long ret_ref = (long)ret_var.inner;
15727         if (ret_var.is_owned) {
15728                 ret_ref |= 1;
15729         }
15730         return ret_ref;
15731 }
15732
15733 uint32_t NetworkGraph_1update_1node_1from_1announcement(void* ctx_TODO, uint32_t this_arg, uint32_t msg) {
15734         LDKNetworkGraph this_arg_conv;
15735         this_arg_conv.inner = (void*)(this_arg & (~1));
15736         this_arg_conv.is_owned = false;
15737         LDKNodeAnnouncement msg_conv;
15738         msg_conv.inner = (void*)(msg & (~1));
15739         msg_conv.is_owned = false;
15740         LDKCResult_NoneLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneLightningErrorZ), "LDKCResult_NoneLightningErrorZ");
15741         *ret_conv = NetworkGraph_update_node_from_announcement(&this_arg_conv, &msg_conv);
15742         return (long)ret_conv;
15743 }
15744
15745 uint32_t NetworkGraph_1update_1node_1from_1unsigned_1announcement(void* ctx_TODO, uint32_t this_arg, uint32_t msg) {
15746         LDKNetworkGraph this_arg_conv;
15747         this_arg_conv.inner = (void*)(this_arg & (~1));
15748         this_arg_conv.is_owned = false;
15749         LDKUnsignedNodeAnnouncement msg_conv;
15750         msg_conv.inner = (void*)(msg & (~1));
15751         msg_conv.is_owned = false;
15752         LDKCResult_NoneLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneLightningErrorZ), "LDKCResult_NoneLightningErrorZ");
15753         *ret_conv = NetworkGraph_update_node_from_unsigned_announcement(&this_arg_conv, &msg_conv);
15754         return (long)ret_conv;
15755 }
15756
15757 uint32_t NetworkGraph_1update_1channel_1from_1announcement(void* ctx_TODO, uint32_t this_arg, uint32_t msg, uint32_t chain_access) {
15758         LDKNetworkGraph this_arg_conv;
15759         this_arg_conv.inner = (void*)(this_arg & (~1));
15760         this_arg_conv.is_owned = false;
15761         LDKChannelAnnouncement msg_conv;
15762         msg_conv.inner = (void*)(msg & (~1));
15763         msg_conv.is_owned = false;
15764         LDKAccess* chain_access_conv = (LDKAccess*)chain_access;
15765         LDKCResult_NoneLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneLightningErrorZ), "LDKCResult_NoneLightningErrorZ");
15766         *ret_conv = NetworkGraph_update_channel_from_announcement(&this_arg_conv, &msg_conv, chain_access_conv);
15767         return (long)ret_conv;
15768 }
15769
15770 uint32_t NetworkGraph_1update_1channel_1from_1unsigned_1announcement(void* ctx_TODO, uint32_t this_arg, uint32_t msg, uint32_t chain_access) {
15771         LDKNetworkGraph this_arg_conv;
15772         this_arg_conv.inner = (void*)(this_arg & (~1));
15773         this_arg_conv.is_owned = false;
15774         LDKUnsignedChannelAnnouncement msg_conv;
15775         msg_conv.inner = (void*)(msg & (~1));
15776         msg_conv.is_owned = false;
15777         LDKAccess* chain_access_conv = (LDKAccess*)chain_access;
15778         LDKCResult_NoneLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneLightningErrorZ), "LDKCResult_NoneLightningErrorZ");
15779         *ret_conv = NetworkGraph_update_channel_from_unsigned_announcement(&this_arg_conv, &msg_conv, chain_access_conv);
15780         return (long)ret_conv;
15781 }
15782
15783 void NetworkGraph_1close_1channel_1from_1update(void* ctx_TODO, uint32_t this_arg, int64_t short_channel_id, jboolean is_permanent) {
15784         LDKNetworkGraph this_arg_conv;
15785         this_arg_conv.inner = (void*)(this_arg & (~1));
15786         this_arg_conv.is_owned = false;
15787         NetworkGraph_close_channel_from_update(&this_arg_conv, short_channel_id, is_permanent);
15788 }
15789
15790 uint32_t NetworkGraph_1update_1channel(void* ctx_TODO, uint32_t this_arg, uint32_t msg) {
15791         LDKNetworkGraph this_arg_conv;
15792         this_arg_conv.inner = (void*)(this_arg & (~1));
15793         this_arg_conv.is_owned = false;
15794         LDKChannelUpdate msg_conv;
15795         msg_conv.inner = (void*)(msg & (~1));
15796         msg_conv.is_owned = false;
15797         LDKCResult_NoneLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneLightningErrorZ), "LDKCResult_NoneLightningErrorZ");
15798         *ret_conv = NetworkGraph_update_channel(&this_arg_conv, &msg_conv);
15799         return (long)ret_conv;
15800 }
15801
15802 uint32_t NetworkGraph_1update_1channel_1unsigned(void* ctx_TODO, uint32_t this_arg, uint32_t msg) {
15803         LDKNetworkGraph this_arg_conv;
15804         this_arg_conv.inner = (void*)(this_arg & (~1));
15805         this_arg_conv.is_owned = false;
15806         LDKUnsignedChannelUpdate msg_conv;
15807         msg_conv.inner = (void*)(msg & (~1));
15808         msg_conv.is_owned = false;
15809         LDKCResult_NoneLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneLightningErrorZ), "LDKCResult_NoneLightningErrorZ");
15810         *ret_conv = NetworkGraph_update_channel_unsigned(&this_arg_conv, &msg_conv);
15811         return (long)ret_conv;
15812 }
15813