Bindings updates
[ldk-java] / ts / bindings.c
1 #include <rust_types.h>
2 #include "js-wasm.h"
3 #include <stdatomic.h>
4 #include <lightning.h>
5
6 // These should be provided...somehow...
7 void *memset(void *s, int c, size_t n);
8 void *memcpy(void *dest, const void *src, size_t n);
9 int memcmp(const void *s1, const void *s2, size_t n);
10
11 void __attribute__((noreturn)) abort(void);
12 void assert(bool expression);
13
14 // Always run a, then assert it is true:
15 #define DO_ASSERT(a) do { bool _assert_val = (a); assert(_assert_val); } while(0)
16 // Assert a is true or do nothing
17 #define CHECK(a) DO_ASSERT(a)
18
19 // Running a leak check across all the allocations and frees of the JDK is a mess,
20 // so instead we implement our own naive leak checker here, relying on the -wrap
21 // linker option to wrap malloc/calloc/realloc/free, tracking everyhing allocated
22 // and free'd in Rust or C across the generated bindings shared library.
23
24 #define BT_MAX 128
25 typedef struct allocation {
26         struct allocation* next;
27         void* ptr;
28         const char* struct_name;
29 } allocation;
30 static allocation* allocation_ll = NULL;
31
32 void* __real_malloc(size_t len);
33 void* __real_calloc(size_t nmemb, size_t len);
34 static void new_allocation(void* res, const char* struct_name) {
35         allocation* new_alloc = __real_malloc(sizeof(allocation));
36         new_alloc->ptr = res;
37         new_alloc->struct_name = struct_name;
38         new_alloc->next = allocation_ll;
39         allocation_ll = new_alloc;
40 }
41 static void* MALLOC(size_t len, const char* struct_name) {
42         void* res = __real_malloc(len);
43         new_allocation(res, struct_name);
44         return res;
45 }
46 void __real_free(void* ptr);
47 static void alloc_freed(void* ptr) {
48         allocation* p = NULL;
49         allocation* it = allocation_ll;
50         while (it->ptr != ptr) {
51                 p = it; it = it->next;
52                 if (it == NULL) {
53                         //XXX: fprintf(stderr, "Tried to free unknown pointer %p\n", ptr);
54                         return; // addrsan should catch malloc-unknown and print more info than we have
55                 }
56         }
57         if (p) { p->next = it->next; } else { allocation_ll = it->next; }
58         DO_ASSERT(it->ptr == ptr);
59         __real_free(it);
60 }
61 static void FREE(void* ptr) {
62         if ((long)ptr < 1024) return; // Rust loves to create pointers to the NULL page for dummys
63         alloc_freed(ptr);
64         __real_free(ptr);
65 }
66
67 void* __wrap_malloc(size_t len) {
68         void* res = __real_malloc(len);
69         new_allocation(res, "malloc call");
70         return res;
71 }
72 void* __wrap_calloc(size_t nmemb, size_t len) {
73         void* res = __real_calloc(nmemb, len);
74         new_allocation(res, "calloc call");
75         return res;
76 }
77 void __wrap_free(void* ptr) {
78         if (ptr == NULL) return;
79         alloc_freed(ptr);
80         __real_free(ptr);
81 }
82
83 void* __real_realloc(void* ptr, size_t newlen);
84 void* __wrap_realloc(void* ptr, size_t len) {
85         if (ptr != NULL) alloc_freed(ptr);
86         void* res = __real_realloc(ptr, len);
87         new_allocation(res, "realloc call");
88         return res;
89 }
90 void __wrap_reallocarray(void* ptr, size_t new_sz) {
91         // Rust doesn't seem to use reallocarray currently
92         DO_ASSERT(false);
93 }
94
95 void __attribute__((destructor)) check_leaks() {
96         for (allocation* a = allocation_ll; a != NULL; a = a->next) {
97                 //XXX: fprintf(stderr, "%s %p remains\n", a->struct_name, a->ptr);
98         }
99         DO_ASSERT(allocation_ll == NULL);
100 }
101
102 // We assume that CVec_u8Z and u8slice are the same size and layout (and thus pointers to the two can be mixed)
103 _Static_assert(sizeof(LDKCVec_u8Z) == sizeof(LDKu8slice), "Vec<u8> and [u8] need to have been mapped identically");
104 _Static_assert(offsetof(LDKCVec_u8Z, data) == offsetof(LDKu8slice, data), "Vec<u8> and [u8] need to have been mapped identically");
105 _Static_assert(offsetof(LDKCVec_u8Z, datalen) == offsetof(LDKu8slice, datalen), "Vec<u8> and [u8] need to have been mapped identically");
106
107 _Static_assert(sizeof(void*) == 4, "Pointers mut be 32 bits");
108
109 //typedef struct int64_tArray { uint32_t *len; /* len + 1 is data */ } int64_tArray;
110 //typedef struct uint32_tArray { uint32_t *len; /* len + 1 is data */ } uint32_tArray;
111 //typedef struct ptrArray { uint32_t *len; /* len + 1 is data */ } ptrArray;
112 //typedef struct int8_tArray { uint32_t *len; /* len + 1 is data */ } int8_tArray;
113 typedef uint32_t int64_tArray;
114 typedef uint32_t int8_tArray;
115 typedef uint32_t uint32_tArray;
116 typedef uint32_t ptrArray;
117 typedef uint32_t jstring;
118
119 static inline uint32_t init_arr(size_t arr_len, size_t elem_size, const char *type_desc) {
120         uint32_t *elems = (uint32_t*)MALLOC(arr_len * elem_size + 4, type_desc);
121         elems[0] = arr_len;
122         return (uint32_t)elems;
123 }
124
125 jstring str_ref_to_ts(const char* chars, size_t len) {
126         char* err_buf = MALLOC(len + 4, "str conv buf");
127         *((uint32_t*)err_buf) = len;
128         memcpy(err_buf + 4, chars, len);
129         return (uint32_t) err_buf;
130 }
131
132 typedef bool jboolean;
133
134 static inline struct LDKThirtyTwoBytes ThirtyTwoBytes_clone(const struct LDKThirtyTwoBytes *orig) { struct LDKThirtyTwoBytes ret; memcpy(ret.data, orig->data, 32); return ret; }
135 static inline LDKAccessError LDKAccessError_from_js(int32_t ord) {
136         switch (ord) {
137                 case 0: return LDKAccessError_UnknownChain;
138                 case 1: return LDKAccessError_UnknownTx;
139         }
140         abort();
141 }
142 static inline int32_t LDKAccessError_to_js(LDKAccessError val) {
143         switch (val) {
144                 case LDKAccessError_UnknownChain: return 0;
145                 case LDKAccessError_UnknownTx: return 1;
146                 default: abort();
147         }
148 }
149 static inline LDKChannelMonitorUpdateErr LDKChannelMonitorUpdateErr_from_js(int32_t ord) {
150         switch (ord) {
151                 case 0: return LDKChannelMonitorUpdateErr_TemporaryFailure;
152                 case 1: return LDKChannelMonitorUpdateErr_PermanentFailure;
153         }
154         abort();
155 }
156 static inline int32_t LDKChannelMonitorUpdateErr_to_js(LDKChannelMonitorUpdateErr val) {
157         switch (val) {
158                 case LDKChannelMonitorUpdateErr_TemporaryFailure: return 0;
159                 case LDKChannelMonitorUpdateErr_PermanentFailure: return 1;
160                 default: abort();
161         }
162 }
163 static inline LDKConfirmationTarget LDKConfirmationTarget_from_js(int32_t ord) {
164         switch (ord) {
165                 case 0: return LDKConfirmationTarget_Background;
166                 case 1: return LDKConfirmationTarget_Normal;
167                 case 2: return LDKConfirmationTarget_HighPriority;
168         }
169         abort();
170 }
171 static inline int32_t LDKConfirmationTarget_to_js(LDKConfirmationTarget val) {
172         switch (val) {
173                 case LDKConfirmationTarget_Background: return 0;
174                 case LDKConfirmationTarget_Normal: return 1;
175                 case LDKConfirmationTarget_HighPriority: return 2;
176                 default: abort();
177         }
178 }
179 static inline LDKLevel LDKLevel_from_js(int32_t ord) {
180         switch (ord) {
181                 case 0: return LDKLevel_Off;
182                 case 1: return LDKLevel_Error;
183                 case 2: return LDKLevel_Warn;
184                 case 3: return LDKLevel_Info;
185                 case 4: return LDKLevel_Debug;
186                 case 5: return LDKLevel_Trace;
187         }
188         abort();
189 }
190 static inline int32_t LDKLevel_to_js(LDKLevel val) {
191         switch (val) {
192                 case LDKLevel_Off: return 0;
193                 case LDKLevel_Error: return 1;
194                 case LDKLevel_Warn: return 2;
195                 case LDKLevel_Info: return 3;
196                 case LDKLevel_Debug: return 4;
197                 case LDKLevel_Trace: return 5;
198                 default: abort();
199         }
200 }
201 static inline LDKNetwork LDKNetwork_from_js(int32_t ord) {
202         switch (ord) {
203                 case 0: return LDKNetwork_Bitcoin;
204                 case 1: return LDKNetwork_Testnet;
205                 case 2: return LDKNetwork_Regtest;
206         }
207         abort();
208 }
209 static inline int32_t LDKNetwork_to_js(LDKNetwork val) {
210         switch (val) {
211                 case LDKNetwork_Bitcoin: return 0;
212                 case LDKNetwork_Testnet: return 1;
213                 case LDKNetwork_Regtest: return 2;
214                 default: abort();
215         }
216 }
217 static inline LDKSecp256k1Error LDKSecp256k1Error_from_js(int32_t ord) {
218         switch (ord) {
219                 case 0: return LDKSecp256k1Error_IncorrectSignature;
220                 case 1: return LDKSecp256k1Error_InvalidMessage;
221                 case 2: return LDKSecp256k1Error_InvalidPublicKey;
222                 case 3: return LDKSecp256k1Error_InvalidSignature;
223                 case 4: return LDKSecp256k1Error_InvalidSecretKey;
224                 case 5: return LDKSecp256k1Error_InvalidRecoveryId;
225                 case 6: return LDKSecp256k1Error_InvalidTweak;
226                 case 7: return LDKSecp256k1Error_NotEnoughMemory;
227                 case 8: return LDKSecp256k1Error_CallbackPanicked;
228         }
229         abort();
230 }
231 static inline int32_t LDKSecp256k1Error_to_js(LDKSecp256k1Error val) {
232         switch (val) {
233                 case LDKSecp256k1Error_IncorrectSignature: return 0;
234                 case LDKSecp256k1Error_InvalidMessage: return 1;
235                 case LDKSecp256k1Error_InvalidPublicKey: return 2;
236                 case LDKSecp256k1Error_InvalidSignature: return 3;
237                 case LDKSecp256k1Error_InvalidSecretKey: return 4;
238                 case LDKSecp256k1Error_InvalidRecoveryId: return 5;
239                 case LDKSecp256k1Error_InvalidTweak: return 6;
240                 case LDKSecp256k1Error_NotEnoughMemory: return 7;
241                 case LDKSecp256k1Error_CallbackPanicked: return 8;
242                 default: abort();
243         }
244 }
245 uint32_t TS_LDKCVec_u8Z_new(int8_tArray elems) {
246         LDKCVec_u8Z *ret = MALLOC(sizeof(LDKCVec_u8Z), "LDKCVec_u8Z");
247         ret->datalen = *((uint32_t*)elems);
248         if (ret->datalen == 0) {
249                 ret->data = NULL;
250         } else {
251                 ret->data = MALLOC(sizeof(uint8_t) * ret->datalen, "LDKCVec_u8Z Data");
252                 int8_t *java_elems = (int8_t*)(elems + 4);
253                 for (size_t i = 0; i < ret->datalen; i++) {
254                         ret->data[i] = java_elems[i];
255                 }
256         }
257         return (long)ret;
258 }
259 static inline LDKCVec_u8Z CVec_u8Z_clone(const LDKCVec_u8Z *orig) {
260         LDKCVec_u8Z ret = { .data = MALLOC(sizeof(int8_t) * orig->datalen, "LDKCVec_u8Z clone bytes"), .datalen = orig->datalen };
261         memcpy(ret.data, orig->data, sizeof(int8_t) * ret.datalen);
262         return ret;
263 }
264 uint32_t TS_LDKC2Tuple_u64u64Z_new(int64_t a, int64_t b) {
265         LDKC2Tuple_u64u64Z* ret = MALLOC(sizeof(LDKC2Tuple_u64u64Z), "LDKC2Tuple_u64u64Z");
266         ret->a = a;
267         ret->b = b;
268         return (long)ret;
269 }
270 static inline LDKC2Tuple_u64u64Z C2Tuple_u64u64Z_clone(const LDKC2Tuple_u64u64Z *orig) {
271         LDKC2Tuple_u64u64Z ret = {
272                 .a = orig->a,
273                 .b = orig->b,
274         };
275         return ret;
276 }
277 int64_t TS_LDKC2Tuple_u64u64Z_get_a(uint32_t ptr) {
278         LDKC2Tuple_u64u64Z *tuple = (LDKC2Tuple_u64u64Z*)ptr;
279         return tuple->a;
280 }
281 int64_t TS_LDKC2Tuple_u64u64Z_get_b(uint32_t ptr) {
282         LDKC2Tuple_u64u64Z *tuple = (LDKC2Tuple_u64u64Z*)ptr;
283         return tuple->b;
284 }
285 uint32_t TS_LDKSpendableOutputDescriptor_ref_from_ptr (uint32_t ptr) {
286         LDKSpendableOutputDescriptor *obj = (LDKSpendableOutputDescriptor*)ptr;
287         switch(obj->tag) {
288                 case LDKSpendableOutputDescriptor_StaticOutput: {
289                         LDKOutPoint outpoint_var = obj->static_output.outpoint;
290                         CHECK((((long)outpoint_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
291                         CHECK((((long)&outpoint_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
292                         long outpoint_ref = (long)outpoint_var.inner & ~1;
293                         long output_ref = (long)&obj->static_output.output;
294                         return 0 /* LDKSpendableOutputDescriptor - StaticOutput */; (void) outpoint_ref; (void) (long)output_ref;
295                 }
296                 case LDKSpendableOutputDescriptor_DynamicOutputP2WSH: {
297                         LDKOutPoint outpoint_var = obj->dynamic_output_p2wsh.outpoint;
298                         CHECK((((long)outpoint_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
299                         CHECK((((long)&outpoint_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
300                         long outpoint_ref = (long)outpoint_var.inner & ~1;
301                         int8_tArray per_commitment_point_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
302                         memcpy((uint8_t*)(per_commitment_point_arr + 4), obj->dynamic_output_p2wsh.per_commitment_point.compressed_form, 33);
303                         long output_ref = (long)&obj->dynamic_output_p2wsh.output;
304                         long key_derivation_params_ref = (long)&obj->dynamic_output_p2wsh.key_derivation_params;
305                         int8_tArray revocation_pubkey_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
306                         memcpy((uint8_t*)(revocation_pubkey_arr + 4), obj->dynamic_output_p2wsh.revocation_pubkey.compressed_form, 33);
307                         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;
308                 }
309                 case LDKSpendableOutputDescriptor_StaticOutputCounterpartyPayment: {
310                         LDKOutPoint outpoint_var = obj->static_output_counterparty_payment.outpoint;
311                         CHECK((((long)outpoint_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
312                         CHECK((((long)&outpoint_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
313                         long outpoint_ref = (long)outpoint_var.inner & ~1;
314                         long output_ref = (long)&obj->static_output_counterparty_payment.output;
315                         long key_derivation_params_ref = (long)&obj->static_output_counterparty_payment.key_derivation_params;
316                         return 0 /* LDKSpendableOutputDescriptor - StaticOutputCounterpartyPayment */; (void) outpoint_ref; (void) (long)output_ref; (void) key_derivation_params_ref;
317                 }
318                 default: abort();
319         }
320 }
321 uint32_t TS_LDKCVec_SpendableOutputDescriptorZ_new(uint32_tArray elems) {
322         LDKCVec_SpendableOutputDescriptorZ *ret = MALLOC(sizeof(LDKCVec_SpendableOutputDescriptorZ), "LDKCVec_SpendableOutputDescriptorZ");
323         ret->datalen = *((uint32_t*)elems);
324         if (ret->datalen == 0) {
325                 ret->data = NULL;
326         } else {
327                 ret->data = MALLOC(sizeof(LDKSpendableOutputDescriptor) * ret->datalen, "LDKCVec_SpendableOutputDescriptorZ Data");
328                 uint32_t *java_elems = (uint32_t*)(elems + 4);
329                 for (size_t i = 0; i < ret->datalen; i++) {
330                         uint32_t arr_elem = java_elems[i];
331                         LDKSpendableOutputDescriptor arr_elem_conv = *(LDKSpendableOutputDescriptor*)arr_elem;
332                         FREE((void*)arr_elem);
333                         ret->data[i] = arr_elem_conv;
334                 }
335         }
336         return (long)ret;
337 }
338 static inline LDKCVec_SpendableOutputDescriptorZ CVec_SpendableOutputDescriptorZ_clone(const LDKCVec_SpendableOutputDescriptorZ *orig) {
339         LDKCVec_SpendableOutputDescriptorZ ret = { .data = MALLOC(sizeof(LDKSpendableOutputDescriptor) * orig->datalen, "LDKCVec_SpendableOutputDescriptorZ clone bytes"), .datalen = orig->datalen };
340         for (size_t i = 0; i < ret.datalen; i++) {
341                 ret.data[i] = SpendableOutputDescriptor_clone(&orig->data[i]);
342         }
343         return ret;
344 }
345 uint32_t TS_LDKErrorAction_ref_from_ptr (uint32_t ptr) {
346         LDKErrorAction *obj = (LDKErrorAction*)ptr;
347         switch(obj->tag) {
348                 case LDKErrorAction_DisconnectPeer: {
349                         LDKErrorMessage msg_var = obj->disconnect_peer.msg;
350                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
351                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
352                         long msg_ref = (long)msg_var.inner & ~1;
353                         return 0 /* LDKErrorAction - DisconnectPeer */; (void) msg_ref;
354                 }
355                 case LDKErrorAction_IgnoreError: {
356                         return 0 /* LDKErrorAction - IgnoreError */;
357                 }
358                 case LDKErrorAction_SendErrorMessage: {
359                         LDKErrorMessage msg_var = obj->send_error_message.msg;
360                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
361                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
362                         long msg_ref = (long)msg_var.inner & ~1;
363                         return 0 /* LDKErrorAction - SendErrorMessage */; (void) msg_ref;
364                 }
365                 default: abort();
366         }
367 }
368 uint32_t TS_LDKHTLCFailChannelUpdate_ref_from_ptr (uint32_t ptr) {
369         LDKHTLCFailChannelUpdate *obj = (LDKHTLCFailChannelUpdate*)ptr;
370         switch(obj->tag) {
371                 case LDKHTLCFailChannelUpdate_ChannelUpdateMessage: {
372                         LDKChannelUpdate msg_var = obj->channel_update_message.msg;
373                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
374                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
375                         long msg_ref = (long)msg_var.inner & ~1;
376                         return 0 /* LDKHTLCFailChannelUpdate - ChannelUpdateMessage */; (void) msg_ref;
377                 }
378                 case LDKHTLCFailChannelUpdate_ChannelClosed: {
379                         return 0 /* LDKHTLCFailChannelUpdate - ChannelClosed */; (void) obj->channel_closed.short_channel_id; (void) obj->channel_closed.is_permanent;
380                 }
381                 case LDKHTLCFailChannelUpdate_NodeFailure: {
382                         int8_tArray node_id_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
383                         memcpy((uint8_t*)(node_id_arr + 4), obj->node_failure.node_id.compressed_form, 33);
384                         return 0 /* LDKHTLCFailChannelUpdate - NodeFailure */; (void) node_id_arr; (void) obj->node_failure.is_permanent;
385                 }
386                 default: abort();
387         }
388 }
389 uint32_t TS_LDKMessageSendEvent_ref_from_ptr (uint32_t ptr) {
390         LDKMessageSendEvent *obj = (LDKMessageSendEvent*)ptr;
391         switch(obj->tag) {
392                 case LDKMessageSendEvent_SendAcceptChannel: {
393                         int8_tArray node_id_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
394                         memcpy((uint8_t*)(node_id_arr + 4), obj->send_accept_channel.node_id.compressed_form, 33);
395                         LDKAcceptChannel msg_var = obj->send_accept_channel.msg;
396                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
397                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
398                         long msg_ref = (long)msg_var.inner & ~1;
399                         return 0 /* LDKMessageSendEvent - SendAcceptChannel */; (void) node_id_arr; (void) msg_ref;
400                 }
401                 case LDKMessageSendEvent_SendOpenChannel: {
402                         int8_tArray node_id_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
403                         memcpy((uint8_t*)(node_id_arr + 4), obj->send_open_channel.node_id.compressed_form, 33);
404                         LDKOpenChannel msg_var = obj->send_open_channel.msg;
405                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
406                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
407                         long msg_ref = (long)msg_var.inner & ~1;
408                         return 0 /* LDKMessageSendEvent - SendOpenChannel */; (void) node_id_arr; (void) msg_ref;
409                 }
410                 case LDKMessageSendEvent_SendFundingCreated: {
411                         int8_tArray node_id_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
412                         memcpy((uint8_t*)(node_id_arr + 4), obj->send_funding_created.node_id.compressed_form, 33);
413                         LDKFundingCreated msg_var = obj->send_funding_created.msg;
414                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
415                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
416                         long msg_ref = (long)msg_var.inner & ~1;
417                         return 0 /* LDKMessageSendEvent - SendFundingCreated */; (void) node_id_arr; (void) msg_ref;
418                 }
419                 case LDKMessageSendEvent_SendFundingSigned: {
420                         int8_tArray node_id_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
421                         memcpy((uint8_t*)(node_id_arr + 4), obj->send_funding_signed.node_id.compressed_form, 33);
422                         LDKFundingSigned msg_var = obj->send_funding_signed.msg;
423                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
424                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
425                         long msg_ref = (long)msg_var.inner & ~1;
426                         return 0 /* LDKMessageSendEvent - SendFundingSigned */; (void) node_id_arr; (void) msg_ref;
427                 }
428                 case LDKMessageSendEvent_SendFundingLocked: {
429                         int8_tArray node_id_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
430                         memcpy((uint8_t*)(node_id_arr + 4), obj->send_funding_locked.node_id.compressed_form, 33);
431                         LDKFundingLocked msg_var = obj->send_funding_locked.msg;
432                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
433                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
434                         long msg_ref = (long)msg_var.inner & ~1;
435                         return 0 /* LDKMessageSendEvent - SendFundingLocked */; (void) node_id_arr; (void) msg_ref;
436                 }
437                 case LDKMessageSendEvent_SendAnnouncementSignatures: {
438                         int8_tArray node_id_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
439                         memcpy((uint8_t*)(node_id_arr + 4), obj->send_announcement_signatures.node_id.compressed_form, 33);
440                         LDKAnnouncementSignatures msg_var = obj->send_announcement_signatures.msg;
441                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
442                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
443                         long msg_ref = (long)msg_var.inner & ~1;
444                         return 0 /* LDKMessageSendEvent - SendAnnouncementSignatures */; (void) node_id_arr; (void) msg_ref;
445                 }
446                 case LDKMessageSendEvent_UpdateHTLCs: {
447                         int8_tArray node_id_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
448                         memcpy((uint8_t*)(node_id_arr + 4), obj->update_htl_cs.node_id.compressed_form, 33);
449                         LDKCommitmentUpdate updates_var = obj->update_htl_cs.updates;
450                         CHECK((((long)updates_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
451                         CHECK((((long)&updates_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
452                         long updates_ref = (long)updates_var.inner & ~1;
453                         return 0 /* LDKMessageSendEvent - UpdateHTLCs */; (void) node_id_arr; (void) updates_ref;
454                 }
455                 case LDKMessageSendEvent_SendRevokeAndACK: {
456                         int8_tArray node_id_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
457                         memcpy((uint8_t*)(node_id_arr + 4), obj->send_revoke_and_ack.node_id.compressed_form, 33);
458                         LDKRevokeAndACK msg_var = obj->send_revoke_and_ack.msg;
459                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
460                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
461                         long msg_ref = (long)msg_var.inner & ~1;
462                         return 0 /* LDKMessageSendEvent - SendRevokeAndACK */; (void) node_id_arr; (void) msg_ref;
463                 }
464                 case LDKMessageSendEvent_SendClosingSigned: {
465                         int8_tArray node_id_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
466                         memcpy((uint8_t*)(node_id_arr + 4), obj->send_closing_signed.node_id.compressed_form, 33);
467                         LDKClosingSigned msg_var = obj->send_closing_signed.msg;
468                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
469                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
470                         long msg_ref = (long)msg_var.inner & ~1;
471                         return 0 /* LDKMessageSendEvent - SendClosingSigned */; (void) node_id_arr; (void) msg_ref;
472                 }
473                 case LDKMessageSendEvent_SendShutdown: {
474                         int8_tArray node_id_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
475                         memcpy((uint8_t*)(node_id_arr + 4), obj->send_shutdown.node_id.compressed_form, 33);
476                         LDKShutdown msg_var = obj->send_shutdown.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                         return 0 /* LDKMessageSendEvent - SendShutdown */; (void) node_id_arr; (void) msg_ref;
481                 }
482                 case LDKMessageSendEvent_SendChannelReestablish: {
483                         int8_tArray node_id_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
484                         memcpy((uint8_t*)(node_id_arr + 4), obj->send_channel_reestablish.node_id.compressed_form, 33);
485                         LDKChannelReestablish msg_var = obj->send_channel_reestablish.msg;
486                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
487                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
488                         long msg_ref = (long)msg_var.inner & ~1;
489                         return 0 /* LDKMessageSendEvent - SendChannelReestablish */; (void) node_id_arr; (void) msg_ref;
490                 }
491                 case LDKMessageSendEvent_BroadcastChannelAnnouncement: {
492                         LDKChannelAnnouncement msg_var = obj->broadcast_channel_announcement.msg;
493                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
494                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
495                         long msg_ref = (long)msg_var.inner & ~1;
496                         LDKChannelUpdate update_msg_var = obj->broadcast_channel_announcement.update_msg;
497                         CHECK((((long)update_msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
498                         CHECK((((long)&update_msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
499                         long update_msg_ref = (long)update_msg_var.inner & ~1;
500                         return 0 /* LDKMessageSendEvent - BroadcastChannelAnnouncement */; (void) msg_ref; (void) update_msg_ref;
501                 }
502                 case LDKMessageSendEvent_BroadcastNodeAnnouncement: {
503                         LDKNodeAnnouncement msg_var = obj->broadcast_node_announcement.msg;
504                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
505                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
506                         long msg_ref = (long)msg_var.inner & ~1;
507                         return 0 /* LDKMessageSendEvent - BroadcastNodeAnnouncement */; (void) msg_ref;
508                 }
509                 case LDKMessageSendEvent_BroadcastChannelUpdate: {
510                         LDKChannelUpdate msg_var = obj->broadcast_channel_update.msg;
511                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
512                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
513                         long msg_ref = (long)msg_var.inner & ~1;
514                         return 0 /* LDKMessageSendEvent - BroadcastChannelUpdate */; (void) msg_ref;
515                 }
516                 case LDKMessageSendEvent_HandleError: {
517                         int8_tArray node_id_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
518                         memcpy((uint8_t*)(node_id_arr + 4), obj->handle_error.node_id.compressed_form, 33);
519                         long action_ref = (long)&obj->handle_error.action;
520                         return 0 /* LDKMessageSendEvent - HandleError */; (void) node_id_arr; (void) action_ref;
521                 }
522                 case LDKMessageSendEvent_PaymentFailureNetworkUpdate: {
523                         long update_ref = (long)&obj->payment_failure_network_update.update;
524                         return 0 /* LDKMessageSendEvent - PaymentFailureNetworkUpdate */; (void) update_ref;
525                 }
526                 case LDKMessageSendEvent_SendChannelRangeQuery: {
527                         int8_tArray node_id_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
528                         memcpy((uint8_t*)(node_id_arr + 4), obj->send_channel_range_query.node_id.compressed_form, 33);
529                         LDKQueryChannelRange msg_var = obj->send_channel_range_query.msg;
530                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
531                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
532                         long msg_ref = (long)msg_var.inner & ~1;
533                         return 0 /* LDKMessageSendEvent - SendChannelRangeQuery */; (void) node_id_arr; (void) msg_ref;
534                 }
535                 case LDKMessageSendEvent_SendShortIdsQuery: {
536                         int8_tArray node_id_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
537                         memcpy((uint8_t*)(node_id_arr + 4), obj->send_short_ids_query.node_id.compressed_form, 33);
538                         LDKQueryShortChannelIds msg_var = obj->send_short_ids_query.msg;
539                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
540                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
541                         long msg_ref = (long)msg_var.inner & ~1;
542                         return 0 /* LDKMessageSendEvent - SendShortIdsQuery */; (void) node_id_arr; (void) msg_ref;
543                 }
544                 default: abort();
545         }
546 }
547 uint32_t TS_LDKCVec_MessageSendEventZ_new(uint32_tArray elems) {
548         LDKCVec_MessageSendEventZ *ret = MALLOC(sizeof(LDKCVec_MessageSendEventZ), "LDKCVec_MessageSendEventZ");
549         ret->datalen = *((uint32_t*)elems);
550         if (ret->datalen == 0) {
551                 ret->data = NULL;
552         } else {
553                 ret->data = MALLOC(sizeof(LDKMessageSendEvent) * ret->datalen, "LDKCVec_MessageSendEventZ Data");
554                 uint32_t *java_elems = (uint32_t*)(elems + 4);
555                 for (size_t i = 0; i < ret->datalen; i++) {
556                         uint32_t arr_elem = java_elems[i];
557                         LDKMessageSendEvent arr_elem_conv = *(LDKMessageSendEvent*)arr_elem;
558                         FREE((void*)arr_elem);
559                         ret->data[i] = arr_elem_conv;
560                 }
561         }
562         return (long)ret;
563 }
564 static inline LDKCVec_MessageSendEventZ CVec_MessageSendEventZ_clone(const LDKCVec_MessageSendEventZ *orig) {
565         LDKCVec_MessageSendEventZ ret = { .data = MALLOC(sizeof(LDKMessageSendEvent) * orig->datalen, "LDKCVec_MessageSendEventZ clone bytes"), .datalen = orig->datalen };
566         for (size_t i = 0; i < ret.datalen; i++) {
567                 ret.data[i] = MessageSendEvent_clone(&orig->data[i]);
568         }
569         return ret;
570 }
571 uint32_t TS_LDKEvent_ref_from_ptr (uint32_t ptr) {
572         LDKEvent *obj = (LDKEvent*)ptr;
573         switch(obj->tag) {
574                 case LDKEvent_FundingGenerationReady: {
575                         int8_tArray temporary_channel_id_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
576                         memcpy((uint8_t*)(temporary_channel_id_arr + 4), obj->funding_generation_ready.temporary_channel_id.data, 32);
577                         LDKCVec_u8Z output_script_var = obj->funding_generation_ready.output_script;
578                         int8_tArray output_script_arr = init_arr(output_script_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
579                         memcpy((uint8_t*)(output_script_arr + 4), output_script_var.data, output_script_var.datalen);
580                         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;
581                 }
582                 case LDKEvent_FundingBroadcastSafe: {
583                         LDKOutPoint funding_txo_var = obj->funding_broadcast_safe.funding_txo;
584                         CHECK((((long)funding_txo_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
585                         CHECK((((long)&funding_txo_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
586                         long funding_txo_ref = (long)funding_txo_var.inner & ~1;
587                         return 0 /* LDKEvent - FundingBroadcastSafe */; (void) funding_txo_ref; (void) obj->funding_broadcast_safe.user_channel_id;
588                 }
589                 case LDKEvent_PaymentReceived: {
590                         int8_tArray payment_hash_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
591                         memcpy((uint8_t*)(payment_hash_arr + 4), obj->payment_received.payment_hash.data, 32);
592                         int8_tArray payment_secret_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
593                         memcpy((uint8_t*)(payment_secret_arr + 4), obj->payment_received.payment_secret.data, 32);
594                         return 0 /* LDKEvent - PaymentReceived */; (void) payment_hash_arr; (void) payment_secret_arr; (void) obj->payment_received.amt;
595                 }
596                 case LDKEvent_PaymentSent: {
597                         int8_tArray payment_preimage_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
598                         memcpy((uint8_t*)(payment_preimage_arr + 4), obj->payment_sent.payment_preimage.data, 32);
599                         return 0 /* LDKEvent - PaymentSent */; (void) payment_preimage_arr;
600                 }
601                 case LDKEvent_PaymentFailed: {
602                         int8_tArray payment_hash_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
603                         memcpy((uint8_t*)(payment_hash_arr + 4), obj->payment_failed.payment_hash.data, 32);
604                         return 0 /* LDKEvent - PaymentFailed */; (void) payment_hash_arr; (void) obj->payment_failed.rejected_by_dest;
605                 }
606                 case LDKEvent_PendingHTLCsForwardable: {
607                         return 0 /* LDKEvent - PendingHTLCsForwardable */; (void) obj->pending_htl_cs_forwardable.time_forwardable;
608                 }
609                 case LDKEvent_SpendableOutputs: {
610                         LDKCVec_SpendableOutputDescriptorZ outputs_var = obj->spendable_outputs.outputs;
611                         uint32_tArray outputs_arr = init_arr(outputs_var.datalen, sizeof(uint32_t), "Native uint32_tArray Bytes");
612                         uint32_t *outputs_arr_ptr = (uint32_t*)(outputs_arr + 4);
613                         for (size_t b = 0; b < outputs_var.datalen; b++) {
614                                 long arr_conv_27_ref = (long)&outputs_var.data[b];
615                                 outputs_arr_ptr[b] = arr_conv_27_ref;
616                         }
617                         return 0 /* LDKEvent - SpendableOutputs */; (void) outputs_arr;
618                 }
619                 default: abort();
620         }
621 }
622 uint32_t TS_LDKCVec_EventZ_new(uint32_tArray elems) {
623         LDKCVec_EventZ *ret = MALLOC(sizeof(LDKCVec_EventZ), "LDKCVec_EventZ");
624         ret->datalen = *((uint32_t*)elems);
625         if (ret->datalen == 0) {
626                 ret->data = NULL;
627         } else {
628                 ret->data = MALLOC(sizeof(LDKEvent) * ret->datalen, "LDKCVec_EventZ Data");
629                 uint32_t *java_elems = (uint32_t*)(elems + 4);
630                 for (size_t i = 0; i < ret->datalen; i++) {
631                         uint32_t arr_elem = java_elems[i];
632                         LDKEvent arr_elem_conv = *(LDKEvent*)arr_elem;
633                         FREE((void*)arr_elem);
634                         ret->data[i] = arr_elem_conv;
635                 }
636         }
637         return (long)ret;
638 }
639 static inline LDKCVec_EventZ CVec_EventZ_clone(const LDKCVec_EventZ *orig) {
640         LDKCVec_EventZ ret = { .data = MALLOC(sizeof(LDKEvent) * orig->datalen, "LDKCVec_EventZ clone bytes"), .datalen = orig->datalen };
641         for (size_t i = 0; i < ret.datalen; i++) {
642                 ret.data[i] = Event_clone(&orig->data[i]);
643         }
644         return ret;
645 }
646 uint32_t TS_LDKC2Tuple_usizeTransactionZ_new(intptr_t a, int8_tArray b) {
647         LDKC2Tuple_usizeTransactionZ* ret = MALLOC(sizeof(LDKC2Tuple_usizeTransactionZ), "LDKC2Tuple_usizeTransactionZ");
648         ret->a = a;
649         LDKTransaction b_ref;
650         b_ref.datalen = *((uint32_t*)b);
651         b_ref.data = MALLOC(b_ref.datalen, "LDKTransaction Bytes");
652         memcpy(b_ref.data, (uint8_t*)(b + 4), b_ref.datalen);
653         b_ref.data_is_owned = false;
654         ret->b = b_ref;
655         return (long)ret;
656 }
657 intptr_t TS_LDKC2Tuple_usizeTransactionZ_get_a(uint32_t ptr) {
658         LDKC2Tuple_usizeTransactionZ *tuple = (LDKC2Tuple_usizeTransactionZ*)ptr;
659         return tuple->a;
660 }
661 int8_tArray TS_LDKC2Tuple_usizeTransactionZ_get_b(uint32_t ptr) {
662         LDKC2Tuple_usizeTransactionZ *tuple = (LDKC2Tuple_usizeTransactionZ*)ptr;
663         LDKTransaction b_var = tuple->b;
664         int8_tArray b_arr = init_arr(b_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
665         memcpy((uint8_t*)(b_arr + 4), b_var.data, b_var.datalen);
666         return b_arr;
667 }
668 uint32_t TS_LDKCVec_C2Tuple_usizeTransactionZZ_new(uint32_tArray elems) {
669         LDKCVec_C2Tuple_usizeTransactionZZ *ret = MALLOC(sizeof(LDKCVec_C2Tuple_usizeTransactionZZ), "LDKCVec_C2Tuple_usizeTransactionZZ");
670         ret->datalen = *((uint32_t*)elems);
671         if (ret->datalen == 0) {
672                 ret->data = NULL;
673         } else {
674                 ret->data = MALLOC(sizeof(LDKC2Tuple_usizeTransactionZ) * ret->datalen, "LDKCVec_C2Tuple_usizeTransactionZZ Data");
675                 uint32_t *java_elems = (uint32_t*)(elems + 4);
676                 for (size_t i = 0; i < ret->datalen; i++) {
677                         uint32_t arr_elem = java_elems[i];
678                         LDKC2Tuple_usizeTransactionZ arr_elem_conv = *(LDKC2Tuple_usizeTransactionZ*)arr_elem;
679                         FREE((void*)arr_elem);
680                         ret->data[i] = arr_elem_conv;
681                 }
682         }
683         return (long)ret;
684 }
685 jboolean TS_LDKCResult_NoneChannelMonitorUpdateErrZ_result_ok(uint32_t arg) {
686         return ((LDKCResult_NoneChannelMonitorUpdateErrZ*)arg)->result_ok;
687 }
688 void TS_LDKCResult_NoneChannelMonitorUpdateErrZ_get_ok(uint32_t arg) {
689         LDKCResult_NoneChannelMonitorUpdateErrZ *val = (LDKCResult_NoneChannelMonitorUpdateErrZ*)arg;
690         CHECK(val->result_ok);
691         return *val->contents.result;
692 }
693 uint32_t TS_LDKCResult_NoneChannelMonitorUpdateErrZ_get_err(uint32_t arg) {
694         LDKCResult_NoneChannelMonitorUpdateErrZ *val = (LDKCResult_NoneChannelMonitorUpdateErrZ*)arg;
695         CHECK(!val->result_ok);
696         uint32_t err_conv = LDKChannelMonitorUpdateErr_to_js((*val->contents.err));
697         return err_conv;
698 }
699 static inline LDKCResult_NoneChannelMonitorUpdateErrZ CResult_NoneChannelMonitorUpdateErrZ_clone(const LDKCResult_NoneChannelMonitorUpdateErrZ *orig) {
700         LDKCResult_NoneChannelMonitorUpdateErrZ res = { .result_ok = orig->result_ok };
701         if (orig->result_ok) {
702                 res.contents.result = NULL;
703         } else {
704                 LDKChannelMonitorUpdateErr* contents = MALLOC(sizeof(LDKChannelMonitorUpdateErr), "LDKChannelMonitorUpdateErr result Err clone");
705                 *contents = ChannelMonitorUpdateErr_clone(orig->contents.err);
706                 res.contents.err = contents;
707         }
708         return res;
709 }
710 uint32_t TS_LDKCVec_MonitorEventZ_new(uint32_tArray elems) {
711         LDKCVec_MonitorEventZ *ret = MALLOC(sizeof(LDKCVec_MonitorEventZ), "LDKCVec_MonitorEventZ");
712         ret->datalen = *((uint32_t*)elems);
713         if (ret->datalen == 0) {
714                 ret->data = NULL;
715         } else {
716                 ret->data = MALLOC(sizeof(LDKMonitorEvent) * ret->datalen, "LDKCVec_MonitorEventZ Data");
717                 uint32_t *java_elems = (uint32_t*)(elems + 4);
718                 for (size_t i = 0; i < ret->datalen; i++) {
719                         uint32_t arr_elem = java_elems[i];
720                         LDKMonitorEvent arr_elem_conv;
721                         arr_elem_conv.inner = (void*)(arr_elem & (~1));
722                         arr_elem_conv.is_owned = (arr_elem & 1) || (arr_elem == 0);
723                         if (arr_elem_conv.inner != NULL)
724                                 arr_elem_conv = MonitorEvent_clone(&arr_elem_conv);
725                         ret->data[i] = arr_elem_conv;
726                 }
727         }
728         return (long)ret;
729 }
730 static inline LDKCVec_MonitorEventZ CVec_MonitorEventZ_clone(const LDKCVec_MonitorEventZ *orig) {
731         LDKCVec_MonitorEventZ ret = { .data = MALLOC(sizeof(LDKMonitorEvent) * orig->datalen, "LDKCVec_MonitorEventZ clone bytes"), .datalen = orig->datalen };
732         for (size_t i = 0; i < ret.datalen; i++) {
733                 ret.data[i] = MonitorEvent_clone(&orig->data[i]);
734         }
735         return ret;
736 }
737 jboolean TS_LDKCResult_ChannelMonitorUpdateDecodeErrorZ_result_ok(uint32_t arg) {
738         return ((LDKCResult_ChannelMonitorUpdateDecodeErrorZ*)arg)->result_ok;
739 }
740 uint32_t TS_LDKCResult_ChannelMonitorUpdateDecodeErrorZ_get_ok(uint32_t arg) {
741         LDKCResult_ChannelMonitorUpdateDecodeErrorZ *val = (LDKCResult_ChannelMonitorUpdateDecodeErrorZ*)arg;
742         CHECK(val->result_ok);
743         LDKChannelMonitorUpdate res_var = (*val->contents.result);
744         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
745         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
746         long res_ref = (long)res_var.inner & ~1;
747         return res_ref;
748 }
749 uint32_t TS_LDKCResult_ChannelMonitorUpdateDecodeErrorZ_get_err(uint32_t arg) {
750         LDKCResult_ChannelMonitorUpdateDecodeErrorZ *val = (LDKCResult_ChannelMonitorUpdateDecodeErrorZ*)arg;
751         CHECK(!val->result_ok);
752         LDKDecodeError err_var = (*val->contents.err);
753         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
754         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
755         long err_ref = (long)err_var.inner & ~1;
756         return err_ref;
757 }
758 jboolean TS_LDKCResult_NoneMonitorUpdateErrorZ_result_ok(uint32_t arg) {
759         return ((LDKCResult_NoneMonitorUpdateErrorZ*)arg)->result_ok;
760 }
761 void TS_LDKCResult_NoneMonitorUpdateErrorZ_get_ok(uint32_t arg) {
762         LDKCResult_NoneMonitorUpdateErrorZ *val = (LDKCResult_NoneMonitorUpdateErrorZ*)arg;
763         CHECK(val->result_ok);
764         return *val->contents.result;
765 }
766 uint32_t TS_LDKCResult_NoneMonitorUpdateErrorZ_get_err(uint32_t arg) {
767         LDKCResult_NoneMonitorUpdateErrorZ *val = (LDKCResult_NoneMonitorUpdateErrorZ*)arg;
768         CHECK(!val->result_ok);
769         LDKMonitorUpdateError err_var = (*val->contents.err);
770         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
771         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
772         long err_ref = (long)err_var.inner & ~1;
773         return err_ref;
774 }
775 uint32_t TS_LDKC2Tuple_OutPointScriptZ_new(uint32_t a, int8_tArray b) {
776         LDKC2Tuple_OutPointScriptZ* ret = MALLOC(sizeof(LDKC2Tuple_OutPointScriptZ), "LDKC2Tuple_OutPointScriptZ");
777         LDKOutPoint a_conv;
778         a_conv.inner = (void*)(a & (~1));
779         a_conv.is_owned = (a & 1) || (a == 0);
780         if (a_conv.inner != NULL)
781                 a_conv = OutPoint_clone(&a_conv);
782         ret->a = a_conv;
783         LDKCVec_u8Z b_ref;
784         b_ref.datalen = *((uint32_t*)b);
785         b_ref.data = MALLOC(b_ref.datalen, "LDKCVec_u8Z Bytes");
786         memcpy(b_ref.data, (uint8_t*)(b + 4), b_ref.datalen);
787         ret->b = b_ref;
788         return (long)ret;
789 }
790 static inline LDKC2Tuple_OutPointScriptZ C2Tuple_OutPointScriptZ_clone(const LDKC2Tuple_OutPointScriptZ *orig) {
791         LDKC2Tuple_OutPointScriptZ ret = {
792                 .a = OutPoint_clone(&orig->a),
793                 .b = CVec_u8Z_clone(&orig->b),
794         };
795         return ret;
796 }
797 uint32_t TS_LDKC2Tuple_OutPointScriptZ_get_a(uint32_t ptr) {
798         LDKC2Tuple_OutPointScriptZ *tuple = (LDKC2Tuple_OutPointScriptZ*)ptr;
799         LDKOutPoint a_var = tuple->a;
800         CHECK((((long)a_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
801         CHECK((((long)&a_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
802         long a_ref = (long)a_var.inner & ~1;
803         return a_ref;
804 }
805 int8_tArray TS_LDKC2Tuple_OutPointScriptZ_get_b(uint32_t ptr) {
806         LDKC2Tuple_OutPointScriptZ *tuple = (LDKC2Tuple_OutPointScriptZ*)ptr;
807         LDKCVec_u8Z b_var = tuple->b;
808         int8_tArray b_arr = init_arr(b_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
809         memcpy((uint8_t*)(b_arr + 4), b_var.data, b_var.datalen);
810         return b_arr;
811 }
812 uint32_t TS_LDKC2Tuple_u32TxOutZ_new(int32_t a, uint32_t b) {
813         LDKC2Tuple_u32TxOutZ* ret = MALLOC(sizeof(LDKC2Tuple_u32TxOutZ), "LDKC2Tuple_u32TxOutZ");
814         ret->a = a;
815         LDKTxOut b_conv = *(LDKTxOut*)b;
816         FREE((void*)b);
817         ret->b = b_conv;
818         return (long)ret;
819 }
820 int32_t TS_LDKC2Tuple_u32TxOutZ_get_a(uint32_t ptr) {
821         LDKC2Tuple_u32TxOutZ *tuple = (LDKC2Tuple_u32TxOutZ*)ptr;
822         return tuple->a;
823 }
824 uint32_t TS_LDKC2Tuple_u32TxOutZ_get_b(uint32_t ptr) {
825         LDKC2Tuple_u32TxOutZ *tuple = (LDKC2Tuple_u32TxOutZ*)ptr;
826         long b_ref = (long)&tuple->b;
827         return (long)b_ref;
828 }
829 uint32_t TS_LDKCVec_C2Tuple_u32TxOutZZ_new(uint32_tArray elems) {
830         LDKCVec_C2Tuple_u32TxOutZZ *ret = MALLOC(sizeof(LDKCVec_C2Tuple_u32TxOutZZ), "LDKCVec_C2Tuple_u32TxOutZZ");
831         ret->datalen = *((uint32_t*)elems);
832         if (ret->datalen == 0) {
833                 ret->data = NULL;
834         } else {
835                 ret->data = MALLOC(sizeof(LDKC2Tuple_u32TxOutZ) * ret->datalen, "LDKCVec_C2Tuple_u32TxOutZZ Data");
836                 uint32_t *java_elems = (uint32_t*)(elems + 4);
837                 for (size_t i = 0; i < ret->datalen; i++) {
838                         uint32_t arr_elem = java_elems[i];
839                         LDKC2Tuple_u32TxOutZ arr_elem_conv = *(LDKC2Tuple_u32TxOutZ*)arr_elem;
840                         FREE((void*)arr_elem);
841                         ret->data[i] = arr_elem_conv;
842                 }
843         }
844         return (long)ret;
845 }
846 uint32_t TS_LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ_new(int8_tArray a, uint32_tArray b) {
847         LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ* ret = MALLOC(sizeof(LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ), "LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ");
848         LDKThirtyTwoBytes a_ref;
849         CHECK(*((uint32_t*)a) == 32);
850         memcpy(a_ref.data, (uint8_t*)(a + 4), 32);
851         ret->a = a_ref;
852         LDKCVec_C2Tuple_u32TxOutZZ b_constr;
853         b_constr.datalen = *((uint32_t*)b);
854         if (b_constr.datalen > 0)
855                 b_constr.data = MALLOC(b_constr.datalen * sizeof(LDKC2Tuple_u32TxOutZ), "LDKCVec_C2Tuple_u32TxOutZZ Elements");
856         else
857                 b_constr.data = NULL;
858         uint32_t* b_vals = (uint32_t*)(b + 4);
859         for (size_t z = 0; z < b_constr.datalen; z++) {
860                 uint32_t arr_conv_25 = b_vals[z];
861                 LDKC2Tuple_u32TxOutZ arr_conv_25_conv = *(LDKC2Tuple_u32TxOutZ*)arr_conv_25;
862                 FREE((void*)arr_conv_25);
863                 b_constr.data[z] = arr_conv_25_conv;
864         }
865         ret->b = b_constr;
866         return (long)ret;
867 }
868 int8_tArray TS_LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ_get_a(uint32_t ptr) {
869         LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ *tuple = (LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ*)ptr;
870         int8_tArray a_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
871         memcpy((uint8_t*)(a_arr + 4), tuple->a.data, 32);
872         return a_arr;
873 }
874 uint32_tArray TS_LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ_get_b(uint32_t ptr) {
875         LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ *tuple = (LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ*)ptr;
876         LDKCVec_C2Tuple_u32TxOutZZ b_var = tuple->b;
877         uint32_tArray b_arr = init_arr(b_var.datalen, sizeof(uint32_t), "Native uint32_tArray Bytes");
878         uint32_t *b_arr_ptr = (uint32_t*)(b_arr + 4);
879         for (size_t z = 0; z < b_var.datalen; z++) {
880                 long arr_conv_25_ref = (long)&b_var.data[z];
881                 b_arr_ptr[z] = arr_conv_25_ref;
882         }
883         return b_arr;
884 }
885 uint32_t TS_LDKCVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ_new(uint32_tArray elems) {
886         LDKCVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ *ret = MALLOC(sizeof(LDKCVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ), "LDKCVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ");
887         ret->datalen = *((uint32_t*)elems);
888         if (ret->datalen == 0) {
889                 ret->data = NULL;
890         } else {
891                 ret->data = MALLOC(sizeof(LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ) * ret->datalen, "LDKCVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ Data");
892                 uint32_t *java_elems = (uint32_t*)(elems + 4);
893                 for (size_t i = 0; i < ret->datalen; i++) {
894                         uint32_t arr_elem = java_elems[i];
895                         LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ arr_elem_conv = *(LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ*)arr_elem;
896                         FREE((void*)arr_elem);
897                         ret->data[i] = arr_elem_conv;
898                 }
899         }
900         return (long)ret;
901 }
902 uint32_t TS_LDKC2Tuple_SignatureCVec_SignatureZZ_new(int8_tArray a, ptrArray b) {
903         LDKC2Tuple_SignatureCVec_SignatureZZ* ret = MALLOC(sizeof(LDKC2Tuple_SignatureCVec_SignatureZZ), "LDKC2Tuple_SignatureCVec_SignatureZZ");
904         LDKSignature a_ref;
905         CHECK(*((uint32_t*)a) == 64);
906         memcpy(a_ref.compact_form, (uint8_t*)(a + 4), 64);
907         ret->a = a_ref;
908         LDKCVec_SignatureZ b_constr;
909         b_constr.datalen = *((uint32_t*)b);
910         if (b_constr.datalen > 0)
911                 b_constr.data = MALLOC(b_constr.datalen * sizeof(LDKSignature), "LDKCVec_SignatureZ Elements");
912         else
913                 b_constr.data = NULL;
914         int8_tArray* b_vals = (int8_tArray*)(b + 4);
915         for (size_t m = 0; m < b_constr.datalen; m++) {
916                 int8_tArray arr_conv_12 = b_vals[m];
917                 LDKSignature arr_conv_12_ref;
918                 CHECK(*((uint32_t*)arr_conv_12) == 64);
919                 memcpy(arr_conv_12_ref.compact_form, (uint8_t*)(arr_conv_12 + 4), 64);
920                 b_constr.data[m] = arr_conv_12_ref;
921         }
922         ret->b = b_constr;
923         return (long)ret;
924 }
925 int8_tArray TS_LDKC2Tuple_SignatureCVec_SignatureZZ_get_a(uint32_t ptr) {
926         LDKC2Tuple_SignatureCVec_SignatureZZ *tuple = (LDKC2Tuple_SignatureCVec_SignatureZZ*)ptr;
927         int8_tArray a_arr = init_arr(64, sizeof(uint8_t), "Native int8_tArray Bytes");
928         memcpy((uint8_t*)(a_arr + 4), tuple->a.compact_form, 64);
929         return a_arr;
930 }
931 ptrArray TS_LDKC2Tuple_SignatureCVec_SignatureZZ_get_b(uint32_t ptr) {
932         LDKC2Tuple_SignatureCVec_SignatureZZ *tuple = (LDKC2Tuple_SignatureCVec_SignatureZZ*)ptr;
933         LDKCVec_SignatureZ b_var = tuple->b;
934         ptrArray b_arr = init_arr(b_var.datalen, sizeof(uint32_t), "Native ptrArray Bytes");
935         int8_tArray *b_arr_ptr = (int8_tArray*)(b_arr + 4);
936         for (size_t m = 0; m < b_var.datalen; m++) {
937                 int8_tArray arr_conv_12_arr = init_arr(64, sizeof(uint8_t), "Native int8_tArray Bytes");
938                 memcpy((uint8_t*)(arr_conv_12_arr + 4), b_var.data[m].compact_form, 64);
939                 b_arr_ptr[m] = arr_conv_12_arr;
940         }
941         return b_arr;
942 }
943 jboolean TS_LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ_result_ok(uint32_t arg) {
944         return ((LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ*)arg)->result_ok;
945 }
946 uint32_t TS_LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ_get_ok(uint32_t arg) {
947         LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ *val = (LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ*)arg;
948         CHECK(val->result_ok);
949         long res_ref = (long)&(*val->contents.result);
950         return res_ref;
951 }
952 void TS_LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ_get_err(uint32_t arg) {
953         LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ *val = (LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ*)arg;
954         CHECK(!val->result_ok);
955         return *val->contents.err;
956 }
957 jboolean TS_LDKCResult_SignatureNoneZ_result_ok(uint32_t arg) {
958         return ((LDKCResult_SignatureNoneZ*)arg)->result_ok;
959 }
960 int8_tArray TS_LDKCResult_SignatureNoneZ_get_ok(uint32_t arg) {
961         LDKCResult_SignatureNoneZ *val = (LDKCResult_SignatureNoneZ*)arg;
962         CHECK(val->result_ok);
963         int8_tArray res_arr = init_arr(64, sizeof(uint8_t), "Native int8_tArray Bytes");
964         memcpy((uint8_t*)(res_arr + 4), (*val->contents.result).compact_form, 64);
965         return res_arr;
966 }
967 void TS_LDKCResult_SignatureNoneZ_get_err(uint32_t arg) {
968         LDKCResult_SignatureNoneZ *val = (LDKCResult_SignatureNoneZ*)arg;
969         CHECK(!val->result_ok);
970         return *val->contents.err;
971 }
972 jboolean TS_LDKCResult_CVec_SignatureZNoneZ_result_ok(uint32_t arg) {
973         return ((LDKCResult_CVec_SignatureZNoneZ*)arg)->result_ok;
974 }
975 ptrArray TS_LDKCResult_CVec_SignatureZNoneZ_get_ok(uint32_t arg) {
976         LDKCResult_CVec_SignatureZNoneZ *val = (LDKCResult_CVec_SignatureZNoneZ*)arg;
977         CHECK(val->result_ok);
978         LDKCVec_SignatureZ res_var = (*val->contents.result);
979         ptrArray res_arr = init_arr(res_var.datalen, sizeof(uint32_t), "Native ptrArray Bytes");
980         int8_tArray *res_arr_ptr = (int8_tArray*)(res_arr + 4);
981         for (size_t m = 0; m < res_var.datalen; m++) {
982                 int8_tArray arr_conv_12_arr = init_arr(64, sizeof(uint8_t), "Native int8_tArray Bytes");
983                 memcpy((uint8_t*)(arr_conv_12_arr + 4), res_var.data[m].compact_form, 64);
984                 res_arr_ptr[m] = arr_conv_12_arr;
985         }
986         return res_arr;
987 }
988 void TS_LDKCResult_CVec_SignatureZNoneZ_get_err(uint32_t arg) {
989         LDKCResult_CVec_SignatureZNoneZ *val = (LDKCResult_CVec_SignatureZNoneZ*)arg;
990         CHECK(!val->result_ok);
991         return *val->contents.err;
992 }
993 typedef struct LDKChannelKeys_JCalls {
994         atomic_size_t refcnt;
995         uint32_t get_per_commitment_point_meth;
996         uint32_t release_commitment_secret_meth;
997         uint32_t key_derivation_params_meth;
998         uint32_t sign_counterparty_commitment_meth;
999         uint32_t sign_holder_commitment_meth;
1000         uint32_t sign_holder_commitment_htlc_transactions_meth;
1001         uint32_t sign_justice_transaction_meth;
1002         uint32_t sign_counterparty_htlc_transaction_meth;
1003         uint32_t sign_closing_transaction_meth;
1004         uint32_t sign_channel_announcement_meth;
1005         uint32_t ready_channel_meth;
1006         uint32_t write_meth;
1007 } LDKChannelKeys_JCalls;
1008 static void LDKChannelKeys_JCalls_free(void* this_arg) {
1009         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1010         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
1011                 js_free(j_calls->get_per_commitment_point_meth);
1012                 js_free(j_calls->release_commitment_secret_meth);
1013                 js_free(j_calls->key_derivation_params_meth);
1014                 js_free(j_calls->sign_counterparty_commitment_meth);
1015                 js_free(j_calls->sign_holder_commitment_meth);
1016                 js_free(j_calls->sign_holder_commitment_htlc_transactions_meth);
1017                 js_free(j_calls->sign_justice_transaction_meth);
1018                 js_free(j_calls->sign_counterparty_htlc_transaction_meth);
1019                 js_free(j_calls->sign_closing_transaction_meth);
1020                 js_free(j_calls->sign_channel_announcement_meth);
1021                 js_free(j_calls->ready_channel_meth);
1022                 js_free(j_calls->write_meth);
1023                 FREE(j_calls);
1024         }
1025 }
1026 LDKPublicKey get_per_commitment_point_jcall(const void* this_arg, uint64_t idx) {
1027         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1028         int8_tArray arg = js_invoke_function_1(j_calls->get_per_commitment_point_meth, idx);
1029         LDKPublicKey arg_ref;
1030         CHECK(*((uint32_t*)arg) == 33);
1031         memcpy(arg_ref.compressed_form, (uint8_t*)(arg + 4), 33);
1032         return arg_ref;
1033 }
1034 LDKThirtyTwoBytes release_commitment_secret_jcall(const void* this_arg, uint64_t idx) {
1035         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1036         int8_tArray arg = js_invoke_function_1(j_calls->release_commitment_secret_meth, idx);
1037         LDKThirtyTwoBytes arg_ref;
1038         CHECK(*((uint32_t*)arg) == 32);
1039         memcpy(arg_ref.data, (uint8_t*)(arg + 4), 32);
1040         return arg_ref;
1041 }
1042 LDKC2Tuple_u64u64Z key_derivation_params_jcall(const void* this_arg) {
1043         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1044         LDKC2Tuple_u64u64Z* ret; // TODO: Call key_derivation_params on j_calls with instance obj, returning a pointer);
1045         LDKC2Tuple_u64u64Z ret_conv = *(LDKC2Tuple_u64u64Z*)ret;
1046         FREE((void*)ret);
1047         return ret_conv;
1048 }
1049 LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ sign_counterparty_commitment_jcall(const void* this_arg, const LDKCommitmentTransaction * commitment_tx) {
1050         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1051         LDKCommitmentTransaction commitment_tx_var = *commitment_tx;
1052         if (commitment_tx->inner != NULL)
1053                 commitment_tx_var = CommitmentTransaction_clone(commitment_tx);
1054         CHECK((((long)commitment_tx_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1055         CHECK((((long)&commitment_tx_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1056         long commitment_tx_ref = (long)commitment_tx_var.inner;
1057         if (commitment_tx_var.is_owned) {
1058                 commitment_tx_ref |= 1;
1059         }
1060         LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ* ret; // TODO: Call sign_counterparty_commitment on j_calls with instance obj, returning a pointer, commitment_tx_ref);
1061         LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ ret_conv = *(LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ*)ret;
1062         FREE((void*)ret);
1063         return ret_conv;
1064 }
1065 LDKCResult_SignatureNoneZ sign_holder_commitment_jcall(const void* this_arg, const LDKHolderCommitmentTransaction * commitment_tx) {
1066         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1067         LDKHolderCommitmentTransaction commitment_tx_var = *commitment_tx;
1068         if (commitment_tx->inner != NULL)
1069                 commitment_tx_var = HolderCommitmentTransaction_clone(commitment_tx);
1070         CHECK((((long)commitment_tx_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1071         CHECK((((long)&commitment_tx_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1072         long commitment_tx_ref = (long)commitment_tx_var.inner;
1073         if (commitment_tx_var.is_owned) {
1074                 commitment_tx_ref |= 1;
1075         }
1076         LDKCResult_SignatureNoneZ* ret; // TODO: Call sign_holder_commitment on j_calls with instance obj, returning a pointer, commitment_tx_ref);
1077         LDKCResult_SignatureNoneZ ret_conv = *(LDKCResult_SignatureNoneZ*)ret;
1078         FREE((void*)ret);
1079         return ret_conv;
1080 }
1081 LDKCResult_CVec_SignatureZNoneZ sign_holder_commitment_htlc_transactions_jcall(const void* this_arg, const LDKHolderCommitmentTransaction * commitment_tx) {
1082         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1083         LDKHolderCommitmentTransaction commitment_tx_var = *commitment_tx;
1084         if (commitment_tx->inner != NULL)
1085                 commitment_tx_var = HolderCommitmentTransaction_clone(commitment_tx);
1086         CHECK((((long)commitment_tx_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1087         CHECK((((long)&commitment_tx_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1088         long commitment_tx_ref = (long)commitment_tx_var.inner;
1089         if (commitment_tx_var.is_owned) {
1090                 commitment_tx_ref |= 1;
1091         }
1092         LDKCResult_CVec_SignatureZNoneZ* ret; // TODO: Call sign_holder_commitment_htlc_transactions on j_calls with instance obj, returning a pointer, commitment_tx_ref);
1093         LDKCResult_CVec_SignatureZNoneZ ret_conv = *(LDKCResult_CVec_SignatureZNoneZ*)ret;
1094         FREE((void*)ret);
1095         return ret_conv;
1096 }
1097 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) {
1098         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1099         LDKTransaction justice_tx_var = justice_tx;
1100         int8_tArray justice_tx_arr = init_arr(justice_tx_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
1101         memcpy((uint8_t*)(justice_tx_arr + 4), justice_tx_var.data, justice_tx_var.datalen);
1102         Transaction_free(justice_tx_var);
1103         int8_tArray per_commitment_key_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
1104         memcpy((uint8_t*)(per_commitment_key_arr + 4), *per_commitment_key, 32);
1105         LDKHTLCOutputInCommitment htlc_var = *htlc;
1106         if (htlc->inner != NULL)
1107                 htlc_var = HTLCOutputInCommitment_clone(htlc);
1108         CHECK((((long)htlc_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1109         CHECK((((long)&htlc_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1110         long htlc_ref = (long)htlc_var.inner;
1111         if (htlc_var.is_owned) {
1112                 htlc_ref |= 1;
1113         }
1114         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);
1115         LDKCResult_SignatureNoneZ ret_conv = *(LDKCResult_SignatureNoneZ*)ret;
1116         FREE((void*)ret);
1117         return ret_conv;
1118 }
1119 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) {
1120         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1121         LDKTransaction htlc_tx_var = htlc_tx;
1122         int8_tArray htlc_tx_arr = init_arr(htlc_tx_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
1123         memcpy((uint8_t*)(htlc_tx_arr + 4), htlc_tx_var.data, htlc_tx_var.datalen);
1124         Transaction_free(htlc_tx_var);
1125         int8_tArray per_commitment_point_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
1126         memcpy((uint8_t*)(per_commitment_point_arr + 4), per_commitment_point.compressed_form, 33);
1127         LDKHTLCOutputInCommitment htlc_var = *htlc;
1128         if (htlc->inner != NULL)
1129                 htlc_var = HTLCOutputInCommitment_clone(htlc);
1130         CHECK((((long)htlc_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1131         CHECK((((long)&htlc_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1132         long htlc_ref = (long)htlc_var.inner;
1133         if (htlc_var.is_owned) {
1134                 htlc_ref |= 1;
1135         }
1136         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);
1137         LDKCResult_SignatureNoneZ ret_conv = *(LDKCResult_SignatureNoneZ*)ret;
1138         FREE((void*)ret);
1139         return ret_conv;
1140 }
1141 LDKCResult_SignatureNoneZ sign_closing_transaction_jcall(const void* this_arg, LDKTransaction closing_tx) {
1142         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1143         LDKTransaction closing_tx_var = closing_tx;
1144         int8_tArray closing_tx_arr = init_arr(closing_tx_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
1145         memcpy((uint8_t*)(closing_tx_arr + 4), closing_tx_var.data, closing_tx_var.datalen);
1146         Transaction_free(closing_tx_var);
1147         LDKCResult_SignatureNoneZ* ret; // TODO: Call sign_closing_transaction on j_calls with instance obj, returning a pointer, closing_tx_arr);
1148         LDKCResult_SignatureNoneZ ret_conv = *(LDKCResult_SignatureNoneZ*)ret;
1149         FREE((void*)ret);
1150         return ret_conv;
1151 }
1152 LDKCResult_SignatureNoneZ sign_channel_announcement_jcall(const void* this_arg, const LDKUnsignedChannelAnnouncement * msg) {
1153         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1154         LDKUnsignedChannelAnnouncement msg_var = *msg;
1155         if (msg->inner != NULL)
1156                 msg_var = UnsignedChannelAnnouncement_clone(msg);
1157         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1158         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1159         long msg_ref = (long)msg_var.inner;
1160         if (msg_var.is_owned) {
1161                 msg_ref |= 1;
1162         }
1163         LDKCResult_SignatureNoneZ* ret; // TODO: Call sign_channel_announcement on j_calls with instance obj, returning a pointer, msg_ref);
1164         LDKCResult_SignatureNoneZ ret_conv = *(LDKCResult_SignatureNoneZ*)ret;
1165         FREE((void*)ret);
1166         return ret_conv;
1167 }
1168 void ready_channel_jcall(void* this_arg, const LDKChannelTransactionParameters * channel_parameters) {
1169         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1170         LDKChannelTransactionParameters channel_parameters_var = *channel_parameters;
1171         if (channel_parameters->inner != NULL)
1172                 channel_parameters_var = ChannelTransactionParameters_clone(channel_parameters);
1173         CHECK((((long)channel_parameters_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1174         CHECK((((long)&channel_parameters_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1175         long channel_parameters_ref = (long)channel_parameters_var.inner;
1176         if (channel_parameters_var.is_owned) {
1177                 channel_parameters_ref |= 1;
1178         }
1179         js_invoke_function_1(j_calls->ready_channel_meth, channel_parameters_ref);
1180 }
1181 LDKCVec_u8Z write_jcall(const void* this_arg) {
1182         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1183         int8_tArray arg = js_invoke_function_0(j_calls->write_meth);
1184         LDKCVec_u8Z arg_ref;
1185         arg_ref.datalen = *((uint32_t*)arg);
1186         arg_ref.data = MALLOC(arg_ref.datalen, "LDKCVec_u8Z Bytes");
1187         memcpy(arg_ref.data, (uint8_t*)(arg + 4), arg_ref.datalen);
1188         return arg_ref;
1189 }
1190 static void* LDKChannelKeys_JCalls_clone(const void* this_arg) {
1191         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1192         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
1193         return (void*) this_arg;
1194 }
1195 static inline LDKChannelKeys LDKChannelKeys_init (/*TODO: JS Object Reference */void* o, uint32_t pubkeys) {
1196         LDKChannelKeys_JCalls *calls = MALLOC(sizeof(LDKChannelKeys_JCalls), "LDKChannelKeys_JCalls");
1197         atomic_init(&calls->refcnt, 1);
1198         //TODO: Assign calls->o from o
1199
1200         LDKChannelPublicKeys pubkeys_conv;
1201         pubkeys_conv.inner = (void*)(pubkeys & (~1));
1202         pubkeys_conv.is_owned = (pubkeys & 1) || (pubkeys == 0);
1203         if (pubkeys_conv.inner != NULL)
1204                 pubkeys_conv = ChannelPublicKeys_clone(&pubkeys_conv);
1205
1206         LDKChannelKeys ret = {
1207                 .this_arg = (void*) calls,
1208                 .get_per_commitment_point = get_per_commitment_point_jcall,
1209                 .release_commitment_secret = release_commitment_secret_jcall,
1210                 .key_derivation_params = key_derivation_params_jcall,
1211                 .sign_counterparty_commitment = sign_counterparty_commitment_jcall,
1212                 .sign_holder_commitment = sign_holder_commitment_jcall,
1213                 .sign_holder_commitment_htlc_transactions = sign_holder_commitment_htlc_transactions_jcall,
1214                 .sign_justice_transaction = sign_justice_transaction_jcall,
1215                 .sign_counterparty_htlc_transaction = sign_counterparty_htlc_transaction_jcall,
1216                 .sign_closing_transaction = sign_closing_transaction_jcall,
1217                 .sign_channel_announcement = sign_channel_announcement_jcall,
1218                 .ready_channel = ready_channel_jcall,
1219                 .clone = LDKChannelKeys_JCalls_clone,
1220                 .write = write_jcall,
1221                 .free = LDKChannelKeys_JCalls_free,
1222                 .pubkeys = pubkeys_conv,
1223                 .set_pubkeys = NULL,
1224         };
1225         return ret;
1226 }
1227 long TS_LDKChannelKeys_new (/*TODO: JS Object Reference */void* o, uint32_t pubkeys) {
1228         LDKChannelKeys *res_ptr = MALLOC(sizeof(LDKChannelKeys), "LDKChannelKeys");
1229         *res_ptr = LDKChannelKeys_init(o, pubkeys);
1230         return (long)res_ptr;
1231 }
1232 int8_tArray TS_ChannelKeys_get_per_commitment_point(uint32_t this_arg, int64_t idx) {
1233         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
1234         int8_tArray arg_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
1235         memcpy((uint8_t*)(arg_arr + 4), (this_arg_conv->get_per_commitment_point)(this_arg_conv->this_arg, idx).compressed_form, 33);
1236         return arg_arr;
1237 }
1238
1239 int8_tArray TS_ChannelKeys_release_commitment_secret(uint32_t this_arg, int64_t idx) {
1240         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
1241         int8_tArray arg_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
1242         memcpy((uint8_t*)(arg_arr + 4), (this_arg_conv->release_commitment_secret)(this_arg_conv->this_arg, idx).data, 32);
1243         return arg_arr;
1244 }
1245
1246 uint32_t TS_ChannelKeys_key_derivation_params(uint32_t this_arg) {
1247         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
1248         LDKC2Tuple_u64u64Z* ret_ref = MALLOC(sizeof(LDKC2Tuple_u64u64Z), "LDKC2Tuple_u64u64Z");
1249         *ret_ref = (this_arg_conv->key_derivation_params)(this_arg_conv->this_arg);
1250         return (long)ret_ref;
1251 }
1252
1253 uint32_t TS_ChannelKeys_sign_counterparty_commitment(uint32_t this_arg, uint32_t commitment_tx) {
1254         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
1255         LDKCommitmentTransaction commitment_tx_conv;
1256         commitment_tx_conv.inner = (void*)(commitment_tx & (~1));
1257         commitment_tx_conv.is_owned = false;
1258         LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ), "LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ");
1259         *ret_conv = (this_arg_conv->sign_counterparty_commitment)(this_arg_conv->this_arg, &commitment_tx_conv);
1260         return (long)ret_conv;
1261 }
1262
1263 uint32_t TS_ChannelKeys_sign_holder_commitment(uint32_t this_arg, uint32_t commitment_tx) {
1264         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
1265         LDKHolderCommitmentTransaction commitment_tx_conv;
1266         commitment_tx_conv.inner = (void*)(commitment_tx & (~1));
1267         commitment_tx_conv.is_owned = false;
1268         LDKCResult_SignatureNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_SignatureNoneZ), "LDKCResult_SignatureNoneZ");
1269         *ret_conv = (this_arg_conv->sign_holder_commitment)(this_arg_conv->this_arg, &commitment_tx_conv);
1270         return (long)ret_conv;
1271 }
1272
1273 uint32_t TS_ChannelKeys_sign_holder_commitment_htlc_transactions(uint32_t this_arg, uint32_t commitment_tx) {
1274         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
1275         LDKHolderCommitmentTransaction commitment_tx_conv;
1276         commitment_tx_conv.inner = (void*)(commitment_tx & (~1));
1277         commitment_tx_conv.is_owned = false;
1278         LDKCResult_CVec_SignatureZNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_CVec_SignatureZNoneZ), "LDKCResult_CVec_SignatureZNoneZ");
1279         *ret_conv = (this_arg_conv->sign_holder_commitment_htlc_transactions)(this_arg_conv->this_arg, &commitment_tx_conv);
1280         return (long)ret_conv;
1281 }
1282
1283 uint32_t TS_ChannelKeys_sign_justice_transaction(uint32_t this_arg, int8_tArray justice_tx, intptr_t input, int64_t amount, int8_tArray per_commitment_key, uint32_t htlc) {
1284         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
1285         LDKTransaction justice_tx_ref;
1286         justice_tx_ref.datalen = *((uint32_t*)justice_tx);
1287         justice_tx_ref.data = MALLOC(justice_tx_ref.datalen, "LDKTransaction Bytes");
1288         memcpy(justice_tx_ref.data, (uint8_t*)(justice_tx + 4), justice_tx_ref.datalen);
1289         justice_tx_ref.data_is_owned = true;
1290         unsigned char per_commitment_key_arr[32];
1291         CHECK(*((uint32_t*)per_commitment_key) == 32);
1292         memcpy(per_commitment_key_arr, (uint8_t*)(per_commitment_key + 4), 32);
1293         unsigned char (*per_commitment_key_ref)[32] = &per_commitment_key_arr;
1294         LDKHTLCOutputInCommitment htlc_conv;
1295         htlc_conv.inner = (void*)(htlc & (~1));
1296         htlc_conv.is_owned = false;
1297         LDKCResult_SignatureNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_SignatureNoneZ), "LDKCResult_SignatureNoneZ");
1298         *ret_conv = (this_arg_conv->sign_justice_transaction)(this_arg_conv->this_arg, justice_tx_ref, input, amount, per_commitment_key_ref, &htlc_conv);
1299         return (long)ret_conv;
1300 }
1301
1302 uint32_t TS_ChannelKeys_sign_counterparty_htlc_transaction(uint32_t this_arg, int8_tArray htlc_tx, intptr_t input, int64_t amount, int8_tArray per_commitment_point, uint32_t htlc) {
1303         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
1304         LDKTransaction htlc_tx_ref;
1305         htlc_tx_ref.datalen = *((uint32_t*)htlc_tx);
1306         htlc_tx_ref.data = MALLOC(htlc_tx_ref.datalen, "LDKTransaction Bytes");
1307         memcpy(htlc_tx_ref.data, (uint8_t*)(htlc_tx + 4), htlc_tx_ref.datalen);
1308         htlc_tx_ref.data_is_owned = true;
1309         LDKPublicKey per_commitment_point_ref;
1310         CHECK(*((uint32_t*)per_commitment_point) == 33);
1311         memcpy(per_commitment_point_ref.compressed_form, (uint8_t*)(per_commitment_point + 4), 33);
1312         LDKHTLCOutputInCommitment htlc_conv;
1313         htlc_conv.inner = (void*)(htlc & (~1));
1314         htlc_conv.is_owned = false;
1315         LDKCResult_SignatureNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_SignatureNoneZ), "LDKCResult_SignatureNoneZ");
1316         *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);
1317         return (long)ret_conv;
1318 }
1319
1320 uint32_t TS_ChannelKeys_sign_closing_transaction(uint32_t this_arg, int8_tArray closing_tx) {
1321         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
1322         LDKTransaction closing_tx_ref;
1323         closing_tx_ref.datalen = *((uint32_t*)closing_tx);
1324         closing_tx_ref.data = MALLOC(closing_tx_ref.datalen, "LDKTransaction Bytes");
1325         memcpy(closing_tx_ref.data, (uint8_t*)(closing_tx + 4), closing_tx_ref.datalen);
1326         closing_tx_ref.data_is_owned = true;
1327         LDKCResult_SignatureNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_SignatureNoneZ), "LDKCResult_SignatureNoneZ");
1328         *ret_conv = (this_arg_conv->sign_closing_transaction)(this_arg_conv->this_arg, closing_tx_ref);
1329         return (long)ret_conv;
1330 }
1331
1332 uint32_t TS_ChannelKeys_sign_channel_announcement(uint32_t this_arg, uint32_t msg) {
1333         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
1334         LDKUnsignedChannelAnnouncement msg_conv;
1335         msg_conv.inner = (void*)(msg & (~1));
1336         msg_conv.is_owned = false;
1337         LDKCResult_SignatureNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_SignatureNoneZ), "LDKCResult_SignatureNoneZ");
1338         *ret_conv = (this_arg_conv->sign_channel_announcement)(this_arg_conv->this_arg, &msg_conv);
1339         return (long)ret_conv;
1340 }
1341
1342 void TS_ChannelKeys_ready_channel(uint32_t this_arg, uint32_t channel_parameters) {
1343         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
1344         LDKChannelTransactionParameters channel_parameters_conv;
1345         channel_parameters_conv.inner = (void*)(channel_parameters & (~1));
1346         channel_parameters_conv.is_owned = false;
1347         (this_arg_conv->ready_channel)(this_arg_conv->this_arg, &channel_parameters_conv);
1348 }
1349
1350 int8_tArray TS_ChannelKeys_write(uint32_t this_arg) {
1351         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
1352         LDKCVec_u8Z arg_var = (this_arg_conv->write)(this_arg_conv->this_arg);
1353         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
1354         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
1355         CVec_u8Z_free(arg_var);
1356         return arg_arr;
1357 }
1358
1359 LDKChannelPublicKeys LDKChannelKeys_set_get_pubkeys(LDKChannelKeys* this_arg) {
1360         if (this_arg->set_pubkeys != NULL)
1361                 this_arg->set_pubkeys(this_arg);
1362         return this_arg->pubkeys;
1363 }
1364 uint32_t TS_ChannelKeys_get_pubkeys(uint32_t this_arg) {
1365         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
1366         LDKChannelPublicKeys ret_var = LDKChannelKeys_set_get_pubkeys(this_arg_conv);
1367         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1368         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1369         long ret_ref = (long)ret_var.inner;
1370         if (ret_var.is_owned) {
1371                 ret_ref |= 1;
1372         }
1373         return ret_ref;
1374 }
1375
1376 uint32_t TS_LDKC2Tuple_BlockHashChannelMonitorZ_new(int8_tArray a, uint32_t b) {
1377         LDKC2Tuple_BlockHashChannelMonitorZ* ret = MALLOC(sizeof(LDKC2Tuple_BlockHashChannelMonitorZ), "LDKC2Tuple_BlockHashChannelMonitorZ");
1378         LDKThirtyTwoBytes a_ref;
1379         CHECK(*((uint32_t*)a) == 32);
1380         memcpy(a_ref.data, (uint8_t*)(a + 4), 32);
1381         ret->a = a_ref;
1382         LDKChannelMonitor b_conv;
1383         b_conv.inner = (void*)(b & (~1));
1384         b_conv.is_owned = (b & 1) || (b == 0);
1385         // Warning: we may need a move here but can't clone!
1386         ret->b = b_conv;
1387         return (long)ret;
1388 }
1389 int8_tArray TS_LDKC2Tuple_BlockHashChannelMonitorZ_get_a(uint32_t ptr) {
1390         LDKC2Tuple_BlockHashChannelMonitorZ *tuple = (LDKC2Tuple_BlockHashChannelMonitorZ*)ptr;
1391         int8_tArray a_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
1392         memcpy((uint8_t*)(a_arr + 4), tuple->a.data, 32);
1393         return a_arr;
1394 }
1395 uint32_t TS_LDKC2Tuple_BlockHashChannelMonitorZ_get_b(uint32_t ptr) {
1396         LDKC2Tuple_BlockHashChannelMonitorZ *tuple = (LDKC2Tuple_BlockHashChannelMonitorZ*)ptr;
1397         LDKChannelMonitor b_var = tuple->b;
1398         CHECK((((long)b_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1399         CHECK((((long)&b_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1400         long b_ref = (long)b_var.inner & ~1;
1401         return b_ref;
1402 }
1403 jboolean TS_LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ_result_ok(uint32_t arg) {
1404         return ((LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ*)arg)->result_ok;
1405 }
1406 uint32_t TS_LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ_get_ok(uint32_t arg) {
1407         LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ *val = (LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ*)arg;
1408         CHECK(val->result_ok);
1409         long res_ref = (long)&(*val->contents.result);
1410         return res_ref;
1411 }
1412 uint32_t TS_LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ_get_err(uint32_t arg) {
1413         LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ *val = (LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ*)arg;
1414         CHECK(!val->result_ok);
1415         LDKDecodeError err_var = (*val->contents.err);
1416         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1417         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1418         long err_ref = (long)err_var.inner & ~1;
1419         return err_ref;
1420 }
1421 jboolean TS_LDKCResult_SpendableOutputDescriptorDecodeErrorZ_result_ok(uint32_t arg) {
1422         return ((LDKCResult_SpendableOutputDescriptorDecodeErrorZ*)arg)->result_ok;
1423 }
1424 uint32_t TS_LDKCResult_SpendableOutputDescriptorDecodeErrorZ_get_ok(uint32_t arg) {
1425         LDKCResult_SpendableOutputDescriptorDecodeErrorZ *val = (LDKCResult_SpendableOutputDescriptorDecodeErrorZ*)arg;
1426         CHECK(val->result_ok);
1427         long res_ref = (long)&(*val->contents.result);
1428         return res_ref;
1429 }
1430 uint32_t TS_LDKCResult_SpendableOutputDescriptorDecodeErrorZ_get_err(uint32_t arg) {
1431         LDKCResult_SpendableOutputDescriptorDecodeErrorZ *val = (LDKCResult_SpendableOutputDescriptorDecodeErrorZ*)arg;
1432         CHECK(!val->result_ok);
1433         LDKDecodeError err_var = (*val->contents.err);
1434         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1435         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1436         long err_ref = (long)err_var.inner & ~1;
1437         return err_ref;
1438 }
1439 jboolean TS_LDKCResult_ChanKeySignerDecodeErrorZ_result_ok(uint32_t arg) {
1440         return ((LDKCResult_ChanKeySignerDecodeErrorZ*)arg)->result_ok;
1441 }
1442 uint32_t TS_LDKCResult_ChanKeySignerDecodeErrorZ_get_ok(uint32_t arg) {
1443         LDKCResult_ChanKeySignerDecodeErrorZ *val = (LDKCResult_ChanKeySignerDecodeErrorZ*)arg;
1444         CHECK(val->result_ok);
1445         LDKChannelKeys* ret = MALLOC(sizeof(LDKChannelKeys), "LDKChannelKeys");
1446         *ret = (*val->contents.result);
1447         return (long)ret;
1448 }
1449 uint32_t TS_LDKCResult_ChanKeySignerDecodeErrorZ_get_err(uint32_t arg) {
1450         LDKCResult_ChanKeySignerDecodeErrorZ *val = (LDKCResult_ChanKeySignerDecodeErrorZ*)arg;
1451         CHECK(!val->result_ok);
1452         LDKDecodeError err_var = (*val->contents.err);
1453         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1454         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1455         long err_ref = (long)err_var.inner & ~1;
1456         return err_ref;
1457 }
1458 jboolean TS_LDKCResult_InMemoryChannelKeysDecodeErrorZ_result_ok(uint32_t arg) {
1459         return ((LDKCResult_InMemoryChannelKeysDecodeErrorZ*)arg)->result_ok;
1460 }
1461 uint32_t TS_LDKCResult_InMemoryChannelKeysDecodeErrorZ_get_ok(uint32_t arg) {
1462         LDKCResult_InMemoryChannelKeysDecodeErrorZ *val = (LDKCResult_InMemoryChannelKeysDecodeErrorZ*)arg;
1463         CHECK(val->result_ok);
1464         LDKInMemoryChannelKeys res_var = (*val->contents.result);
1465         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1466         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1467         long res_ref = (long)res_var.inner & ~1;
1468         return res_ref;
1469 }
1470 uint32_t TS_LDKCResult_InMemoryChannelKeysDecodeErrorZ_get_err(uint32_t arg) {
1471         LDKCResult_InMemoryChannelKeysDecodeErrorZ *val = (LDKCResult_InMemoryChannelKeysDecodeErrorZ*)arg;
1472         CHECK(!val->result_ok);
1473         LDKDecodeError err_var = (*val->contents.err);
1474         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1475         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1476         long err_ref = (long)err_var.inner & ~1;
1477         return err_ref;
1478 }
1479 jboolean TS_LDKCResult_TxOutAccessErrorZ_result_ok(uint32_t arg) {
1480         return ((LDKCResult_TxOutAccessErrorZ*)arg)->result_ok;
1481 }
1482 uint32_t TS_LDKCResult_TxOutAccessErrorZ_get_ok(uint32_t arg) {
1483         LDKCResult_TxOutAccessErrorZ *val = (LDKCResult_TxOutAccessErrorZ*)arg;
1484         CHECK(val->result_ok);
1485         long res_ref = (long)&(*val->contents.result);
1486         return (long)res_ref;
1487 }
1488 uint32_t TS_LDKCResult_TxOutAccessErrorZ_get_err(uint32_t arg) {
1489         LDKCResult_TxOutAccessErrorZ *val = (LDKCResult_TxOutAccessErrorZ*)arg;
1490         CHECK(!val->result_ok);
1491         uint32_t err_conv = LDKAccessError_to_js((*val->contents.err));
1492         return err_conv;
1493 }
1494 uint32_t TS_LDKAPIError_ref_from_ptr (uint32_t ptr) {
1495         LDKAPIError *obj = (LDKAPIError*)ptr;
1496         switch(obj->tag) {
1497                 case LDKAPIError_APIMisuseError: {
1498                         LDKCVec_u8Z err_var = obj->api_misuse_error.err;
1499                         int8_tArray err_arr = init_arr(err_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
1500                         memcpy((uint8_t*)(err_arr + 4), err_var.data, err_var.datalen);
1501                         return 0 /* LDKAPIError - APIMisuseError */; (void) err_arr;
1502                 }
1503                 case LDKAPIError_FeeRateTooHigh: {
1504                         LDKCVec_u8Z err_var = obj->fee_rate_too_high.err;
1505                         int8_tArray err_arr = init_arr(err_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
1506                         memcpy((uint8_t*)(err_arr + 4), err_var.data, err_var.datalen);
1507                         return 0 /* LDKAPIError - FeeRateTooHigh */; (void) err_arr; (void) obj->fee_rate_too_high.feerate;
1508                 }
1509                 case LDKAPIError_RouteError: {
1510                         LDKStr err_str = obj->route_error.err;
1511                         jstring err_conv = str_ref_to_ts(err_str.chars, err_str.len);
1512                         return 0 /* LDKAPIError - RouteError */; (void) err_conv;
1513                 }
1514                 case LDKAPIError_ChannelUnavailable: {
1515                         LDKCVec_u8Z err_var = obj->channel_unavailable.err;
1516                         int8_tArray err_arr = init_arr(err_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
1517                         memcpy((uint8_t*)(err_arr + 4), err_var.data, err_var.datalen);
1518                         return 0 /* LDKAPIError - ChannelUnavailable */; (void) err_arr;
1519                 }
1520                 case LDKAPIError_MonitorUpdateFailed: {
1521                         return 0 /* LDKAPIError - MonitorUpdateFailed */;
1522                 }
1523                 default: abort();
1524         }
1525 }
1526 jboolean TS_LDKCResult_NoneAPIErrorZ_result_ok(uint32_t arg) {
1527         return ((LDKCResult_NoneAPIErrorZ*)arg)->result_ok;
1528 }
1529 void TS_LDKCResult_NoneAPIErrorZ_get_ok(uint32_t arg) {
1530         LDKCResult_NoneAPIErrorZ *val = (LDKCResult_NoneAPIErrorZ*)arg;
1531         CHECK(val->result_ok);
1532         return *val->contents.result;
1533 }
1534 uint32_t TS_LDKCResult_NoneAPIErrorZ_get_err(uint32_t arg) {
1535         LDKCResult_NoneAPIErrorZ *val = (LDKCResult_NoneAPIErrorZ*)arg;
1536         CHECK(!val->result_ok);
1537         long err_ref = (long)&(*val->contents.err);
1538         return err_ref;
1539 }
1540 static inline LDKCResult_NoneAPIErrorZ CResult_NoneAPIErrorZ_clone(const LDKCResult_NoneAPIErrorZ *orig) {
1541         LDKCResult_NoneAPIErrorZ res = { .result_ok = orig->result_ok };
1542         if (orig->result_ok) {
1543                 res.contents.result = NULL;
1544         } else {
1545                 LDKAPIError* contents = MALLOC(sizeof(LDKAPIError), "LDKAPIError result Err clone");
1546                 *contents = APIError_clone(orig->contents.err);
1547                 res.contents.err = contents;
1548         }
1549         return res;
1550 }
1551 uint32_t TS_LDKCVec_ChannelDetailsZ_new(uint32_tArray elems) {
1552         LDKCVec_ChannelDetailsZ *ret = MALLOC(sizeof(LDKCVec_ChannelDetailsZ), "LDKCVec_ChannelDetailsZ");
1553         ret->datalen = *((uint32_t*)elems);
1554         if (ret->datalen == 0) {
1555                 ret->data = NULL;
1556         } else {
1557                 ret->data = MALLOC(sizeof(LDKChannelDetails) * ret->datalen, "LDKCVec_ChannelDetailsZ Data");
1558                 uint32_t *java_elems = (uint32_t*)(elems + 4);
1559                 for (size_t i = 0; i < ret->datalen; i++) {
1560                         uint32_t arr_elem = java_elems[i];
1561                         LDKChannelDetails arr_elem_conv;
1562                         arr_elem_conv.inner = (void*)(arr_elem & (~1));
1563                         arr_elem_conv.is_owned = (arr_elem & 1) || (arr_elem == 0);
1564                         if (arr_elem_conv.inner != NULL)
1565                                 arr_elem_conv = ChannelDetails_clone(&arr_elem_conv);
1566                         ret->data[i] = arr_elem_conv;
1567                 }
1568         }
1569         return (long)ret;
1570 }
1571 static inline LDKCVec_ChannelDetailsZ CVec_ChannelDetailsZ_clone(const LDKCVec_ChannelDetailsZ *orig) {
1572         LDKCVec_ChannelDetailsZ ret = { .data = MALLOC(sizeof(LDKChannelDetails) * orig->datalen, "LDKCVec_ChannelDetailsZ clone bytes"), .datalen = orig->datalen };
1573         for (size_t i = 0; i < ret.datalen; i++) {
1574                 ret.data[i] = ChannelDetails_clone(&orig->data[i]);
1575         }
1576         return ret;
1577 }
1578 jboolean TS_LDKCResult_NonePaymentSendFailureZ_result_ok(uint32_t arg) {
1579         return ((LDKCResult_NonePaymentSendFailureZ*)arg)->result_ok;
1580 }
1581 void TS_LDKCResult_NonePaymentSendFailureZ_get_ok(uint32_t arg) {
1582         LDKCResult_NonePaymentSendFailureZ *val = (LDKCResult_NonePaymentSendFailureZ*)arg;
1583         CHECK(val->result_ok);
1584         return *val->contents.result;
1585 }
1586 uint32_t TS_LDKCResult_NonePaymentSendFailureZ_get_err(uint32_t arg) {
1587         LDKCResult_NonePaymentSendFailureZ *val = (LDKCResult_NonePaymentSendFailureZ*)arg;
1588         CHECK(!val->result_ok);
1589         LDKPaymentSendFailure err_var = (*val->contents.err);
1590         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1591         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1592         long err_ref = (long)err_var.inner & ~1;
1593         return err_ref;
1594 }
1595 uint32_t TS_LDKNetAddress_ref_from_ptr (uint32_t ptr) {
1596         LDKNetAddress *obj = (LDKNetAddress*)ptr;
1597         switch(obj->tag) {
1598                 case LDKNetAddress_IPv4: {
1599                         int8_tArray addr_arr = init_arr(4, sizeof(uint8_t), "Native int8_tArray Bytes");
1600                         memcpy((uint8_t*)(addr_arr + 4), obj->i_pv4.addr.data, 4);
1601                         return 0 /* LDKNetAddress - IPv4 */; (void) addr_arr; (void) obj->i_pv4.port;
1602                 }
1603                 case LDKNetAddress_IPv6: {
1604                         int8_tArray addr_arr = init_arr(16, sizeof(uint8_t), "Native int8_tArray Bytes");
1605                         memcpy((uint8_t*)(addr_arr + 4), obj->i_pv6.addr.data, 16);
1606                         return 0 /* LDKNetAddress - IPv6 */; (void) addr_arr; (void) obj->i_pv6.port;
1607                 }
1608                 case LDKNetAddress_OnionV2: {
1609                         int8_tArray addr_arr = init_arr(10, sizeof(uint8_t), "Native int8_tArray Bytes");
1610                         memcpy((uint8_t*)(addr_arr + 4), obj->onion_v2.addr.data, 10);
1611                         return 0 /* LDKNetAddress - OnionV2 */; (void) addr_arr; (void) obj->onion_v2.port;
1612                 }
1613                 case LDKNetAddress_OnionV3: {
1614                         int8_tArray ed25519_pubkey_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
1615                         memcpy((uint8_t*)(ed25519_pubkey_arr + 4), obj->onion_v3.ed25519_pubkey.data, 32);
1616                         return 0 /* LDKNetAddress - OnionV3 */; (void) ed25519_pubkey_arr; (void) obj->onion_v3.checksum; (void) obj->onion_v3.version; (void) obj->onion_v3.port;
1617                 }
1618                 default: abort();
1619         }
1620 }
1621 uint32_t TS_LDKCVec_NetAddressZ_new(uint32_tArray elems) {
1622         LDKCVec_NetAddressZ *ret = MALLOC(sizeof(LDKCVec_NetAddressZ), "LDKCVec_NetAddressZ");
1623         ret->datalen = *((uint32_t*)elems);
1624         if (ret->datalen == 0) {
1625                 ret->data = NULL;
1626         } else {
1627                 ret->data = MALLOC(sizeof(LDKNetAddress) * ret->datalen, "LDKCVec_NetAddressZ Data");
1628                 uint32_t *java_elems = (uint32_t*)(elems + 4);
1629                 for (size_t i = 0; i < ret->datalen; i++) {
1630                         uint32_t arr_elem = java_elems[i];
1631                         LDKNetAddress arr_elem_conv = *(LDKNetAddress*)arr_elem;
1632                         FREE((void*)arr_elem);
1633                         ret->data[i] = arr_elem_conv;
1634                 }
1635         }
1636         return (long)ret;
1637 }
1638 static inline LDKCVec_NetAddressZ CVec_NetAddressZ_clone(const LDKCVec_NetAddressZ *orig) {
1639         LDKCVec_NetAddressZ ret = { .data = MALLOC(sizeof(LDKNetAddress) * orig->datalen, "LDKCVec_NetAddressZ clone bytes"), .datalen = orig->datalen };
1640         for (size_t i = 0; i < ret.datalen; i++) {
1641                 ret.data[i] = NetAddress_clone(&orig->data[i]);
1642         }
1643         return ret;
1644 }
1645 uint32_t TS_LDKCVec_ChannelMonitorZ_new(uint32_tArray elems) {
1646         LDKCVec_ChannelMonitorZ *ret = MALLOC(sizeof(LDKCVec_ChannelMonitorZ), "LDKCVec_ChannelMonitorZ");
1647         ret->datalen = *((uint32_t*)elems);
1648         if (ret->datalen == 0) {
1649                 ret->data = NULL;
1650         } else {
1651                 ret->data = MALLOC(sizeof(LDKChannelMonitor) * ret->datalen, "LDKCVec_ChannelMonitorZ Data");
1652                 uint32_t *java_elems = (uint32_t*)(elems + 4);
1653                 for (size_t i = 0; i < ret->datalen; i++) {
1654                         uint32_t arr_elem = java_elems[i];
1655                         LDKChannelMonitor arr_elem_conv;
1656                         arr_elem_conv.inner = (void*)(arr_elem & (~1));
1657                         arr_elem_conv.is_owned = (arr_elem & 1) || (arr_elem == 0);
1658                         // Warning: we may need a move here but can't clone!
1659                         ret->data[i] = arr_elem_conv;
1660                 }
1661         }
1662         return (long)ret;
1663 }
1664 typedef struct LDKWatch_JCalls {
1665         atomic_size_t refcnt;
1666         uint32_t watch_channel_meth;
1667         uint32_t update_channel_meth;
1668         uint32_t release_pending_monitor_events_meth;
1669 } LDKWatch_JCalls;
1670 static void LDKWatch_JCalls_free(void* this_arg) {
1671         LDKWatch_JCalls *j_calls = (LDKWatch_JCalls*) this_arg;
1672         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
1673                 js_free(j_calls->watch_channel_meth);
1674                 js_free(j_calls->update_channel_meth);
1675                 js_free(j_calls->release_pending_monitor_events_meth);
1676                 FREE(j_calls);
1677         }
1678 }
1679 LDKCResult_NoneChannelMonitorUpdateErrZ watch_channel_jcall(const void* this_arg, LDKOutPoint funding_txo, LDKChannelMonitor monitor) {
1680         LDKWatch_JCalls *j_calls = (LDKWatch_JCalls*) this_arg;
1681         LDKOutPoint funding_txo_var = funding_txo;
1682         CHECK((((long)funding_txo_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1683         CHECK((((long)&funding_txo_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1684         long funding_txo_ref = (long)funding_txo_var.inner;
1685         if (funding_txo_var.is_owned) {
1686                 funding_txo_ref |= 1;
1687         }
1688         LDKChannelMonitor monitor_var = monitor;
1689         CHECK((((long)monitor_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1690         CHECK((((long)&monitor_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1691         long monitor_ref = (long)monitor_var.inner;
1692         if (monitor_var.is_owned) {
1693                 monitor_ref |= 1;
1694         }
1695         LDKCResult_NoneChannelMonitorUpdateErrZ* ret; // TODO: Call watch_channel on j_calls with instance obj, returning a pointer, funding_txo_ref, monitor_ref);
1696         LDKCResult_NoneChannelMonitorUpdateErrZ ret_conv = *(LDKCResult_NoneChannelMonitorUpdateErrZ*)ret;
1697         FREE((void*)ret);
1698         return ret_conv;
1699 }
1700 LDKCResult_NoneChannelMonitorUpdateErrZ update_channel_jcall(const void* this_arg, LDKOutPoint funding_txo, LDKChannelMonitorUpdate update) {
1701         LDKWatch_JCalls *j_calls = (LDKWatch_JCalls*) this_arg;
1702         LDKOutPoint funding_txo_var = funding_txo;
1703         CHECK((((long)funding_txo_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1704         CHECK((((long)&funding_txo_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1705         long funding_txo_ref = (long)funding_txo_var.inner;
1706         if (funding_txo_var.is_owned) {
1707                 funding_txo_ref |= 1;
1708         }
1709         LDKChannelMonitorUpdate update_var = update;
1710         CHECK((((long)update_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1711         CHECK((((long)&update_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1712         long update_ref = (long)update_var.inner;
1713         if (update_var.is_owned) {
1714                 update_ref |= 1;
1715         }
1716         LDKCResult_NoneChannelMonitorUpdateErrZ* ret; // TODO: Call update_channel on j_calls with instance obj, returning a pointer, funding_txo_ref, update_ref);
1717         LDKCResult_NoneChannelMonitorUpdateErrZ ret_conv = *(LDKCResult_NoneChannelMonitorUpdateErrZ*)ret;
1718         FREE((void*)ret);
1719         return ret_conv;
1720 }
1721 LDKCVec_MonitorEventZ release_pending_monitor_events_jcall(const void* this_arg) {
1722         LDKWatch_JCalls *j_calls = (LDKWatch_JCalls*) this_arg;
1723         uint32_tArray arg = js_invoke_function_0(j_calls->release_pending_monitor_events_meth);
1724         LDKCVec_MonitorEventZ arg_constr;
1725         arg_constr.datalen = *((uint32_t*)arg);
1726         if (arg_constr.datalen > 0)
1727                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKMonitorEvent), "LDKCVec_MonitorEventZ Elements");
1728         else
1729                 arg_constr.data = NULL;
1730         uint32_t* arg_vals = (uint32_t*)(arg + 4);
1731         for (size_t o = 0; o < arg_constr.datalen; o++) {
1732                 uint32_t arr_conv_14 = arg_vals[o];
1733                 LDKMonitorEvent arr_conv_14_conv;
1734                 arr_conv_14_conv.inner = (void*)(arr_conv_14 & (~1));
1735                 arr_conv_14_conv.is_owned = (arr_conv_14 & 1) || (arr_conv_14 == 0);
1736                 if (arr_conv_14_conv.inner != NULL)
1737                         arr_conv_14_conv = MonitorEvent_clone(&arr_conv_14_conv);
1738                 arg_constr.data[o] = arr_conv_14_conv;
1739         }
1740         return arg_constr;
1741 }
1742 static void* LDKWatch_JCalls_clone(const void* this_arg) {
1743         LDKWatch_JCalls *j_calls = (LDKWatch_JCalls*) this_arg;
1744         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
1745         return (void*) this_arg;
1746 }
1747 static inline LDKWatch LDKWatch_init (/*TODO: JS Object Reference */void* o) {
1748         LDKWatch_JCalls *calls = MALLOC(sizeof(LDKWatch_JCalls), "LDKWatch_JCalls");
1749         atomic_init(&calls->refcnt, 1);
1750         //TODO: Assign calls->o from o
1751
1752         LDKWatch ret = {
1753                 .this_arg = (void*) calls,
1754                 .watch_channel = watch_channel_jcall,
1755                 .update_channel = update_channel_jcall,
1756                 .release_pending_monitor_events = release_pending_monitor_events_jcall,
1757                 .free = LDKWatch_JCalls_free,
1758         };
1759         return ret;
1760 }
1761 long TS_LDKWatch_new (/*TODO: JS Object Reference */void* o) {
1762         LDKWatch *res_ptr = MALLOC(sizeof(LDKWatch), "LDKWatch");
1763         *res_ptr = LDKWatch_init(o);
1764         return (long)res_ptr;
1765 }
1766 uint32_t TS_Watch_watch_channel(uint32_t this_arg, uint32_t funding_txo, uint32_t monitor) {
1767         LDKWatch* this_arg_conv = (LDKWatch*)this_arg;
1768         LDKOutPoint funding_txo_conv;
1769         funding_txo_conv.inner = (void*)(funding_txo & (~1));
1770         funding_txo_conv.is_owned = (funding_txo & 1) || (funding_txo == 0);
1771         if (funding_txo_conv.inner != NULL)
1772                 funding_txo_conv = OutPoint_clone(&funding_txo_conv);
1773         LDKChannelMonitor monitor_conv;
1774         monitor_conv.inner = (void*)(monitor & (~1));
1775         monitor_conv.is_owned = (monitor & 1) || (monitor == 0);
1776         // Warning: we may need a move here but can't clone!
1777         LDKCResult_NoneChannelMonitorUpdateErrZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneChannelMonitorUpdateErrZ), "LDKCResult_NoneChannelMonitorUpdateErrZ");
1778         *ret_conv = (this_arg_conv->watch_channel)(this_arg_conv->this_arg, funding_txo_conv, monitor_conv);
1779         return (long)ret_conv;
1780 }
1781
1782 uint32_t TS_Watch_update_channel(uint32_t this_arg, uint32_t funding_txo, uint32_t update) {
1783         LDKWatch* this_arg_conv = (LDKWatch*)this_arg;
1784         LDKOutPoint funding_txo_conv;
1785         funding_txo_conv.inner = (void*)(funding_txo & (~1));
1786         funding_txo_conv.is_owned = (funding_txo & 1) || (funding_txo == 0);
1787         if (funding_txo_conv.inner != NULL)
1788                 funding_txo_conv = OutPoint_clone(&funding_txo_conv);
1789         LDKChannelMonitorUpdate update_conv;
1790         update_conv.inner = (void*)(update & (~1));
1791         update_conv.is_owned = (update & 1) || (update == 0);
1792         if (update_conv.inner != NULL)
1793                 update_conv = ChannelMonitorUpdate_clone(&update_conv);
1794         LDKCResult_NoneChannelMonitorUpdateErrZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneChannelMonitorUpdateErrZ), "LDKCResult_NoneChannelMonitorUpdateErrZ");
1795         *ret_conv = (this_arg_conv->update_channel)(this_arg_conv->this_arg, funding_txo_conv, update_conv);
1796         return (long)ret_conv;
1797 }
1798
1799 uint32_tArray TS_Watch_release_pending_monitor_events(uint32_t this_arg) {
1800         LDKWatch* this_arg_conv = (LDKWatch*)this_arg;
1801         LDKCVec_MonitorEventZ ret_var = (this_arg_conv->release_pending_monitor_events)(this_arg_conv->this_arg);
1802         uint32_tArray ret_arr = init_arr(ret_var.datalen, sizeof(uint32_t), "Native uint32_tArray Bytes");
1803         uint32_t *ret_arr_ptr = (uint32_t*)(ret_arr + 4);
1804         for (size_t o = 0; o < ret_var.datalen; o++) {
1805                 LDKMonitorEvent arr_conv_14_var = ret_var.data[o];
1806                 CHECK((((long)arr_conv_14_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1807                 CHECK((((long)&arr_conv_14_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1808                 long arr_conv_14_ref = (long)arr_conv_14_var.inner;
1809                 if (arr_conv_14_var.is_owned) {
1810                         arr_conv_14_ref |= 1;
1811                 }
1812                 ret_arr_ptr[o] = arr_conv_14_ref;
1813         }
1814         FREE(ret_var.data);
1815         return ret_arr;
1816 }
1817
1818 typedef struct LDKBroadcasterInterface_JCalls {
1819         atomic_size_t refcnt;
1820         uint32_t broadcast_transaction_meth;
1821 } LDKBroadcasterInterface_JCalls;
1822 static void LDKBroadcasterInterface_JCalls_free(void* this_arg) {
1823         LDKBroadcasterInterface_JCalls *j_calls = (LDKBroadcasterInterface_JCalls*) this_arg;
1824         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
1825                 js_free(j_calls->broadcast_transaction_meth);
1826                 FREE(j_calls);
1827         }
1828 }
1829 void broadcast_transaction_jcall(const void* this_arg, LDKTransaction tx) {
1830         LDKBroadcasterInterface_JCalls *j_calls = (LDKBroadcasterInterface_JCalls*) this_arg;
1831         LDKTransaction tx_var = tx;
1832         int8_tArray tx_arr = init_arr(tx_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
1833         memcpy((uint8_t*)(tx_arr + 4), tx_var.data, tx_var.datalen);
1834         Transaction_free(tx_var);
1835         js_invoke_function_1(j_calls->broadcast_transaction_meth, tx_arr);
1836 }
1837 static void* LDKBroadcasterInterface_JCalls_clone(const void* this_arg) {
1838         LDKBroadcasterInterface_JCalls *j_calls = (LDKBroadcasterInterface_JCalls*) this_arg;
1839         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
1840         return (void*) this_arg;
1841 }
1842 static inline LDKBroadcasterInterface LDKBroadcasterInterface_init (/*TODO: JS Object Reference */void* o) {
1843         LDKBroadcasterInterface_JCalls *calls = MALLOC(sizeof(LDKBroadcasterInterface_JCalls), "LDKBroadcasterInterface_JCalls");
1844         atomic_init(&calls->refcnt, 1);
1845         //TODO: Assign calls->o from o
1846
1847         LDKBroadcasterInterface ret = {
1848                 .this_arg = (void*) calls,
1849                 .broadcast_transaction = broadcast_transaction_jcall,
1850                 .free = LDKBroadcasterInterface_JCalls_free,
1851         };
1852         return ret;
1853 }
1854 long TS_LDKBroadcasterInterface_new (/*TODO: JS Object Reference */void* o) {
1855         LDKBroadcasterInterface *res_ptr = MALLOC(sizeof(LDKBroadcasterInterface), "LDKBroadcasterInterface");
1856         *res_ptr = LDKBroadcasterInterface_init(o);
1857         return (long)res_ptr;
1858 }
1859 void TS_BroadcasterInterface_broadcast_transaction(uint32_t this_arg, int8_tArray tx) {
1860         LDKBroadcasterInterface* this_arg_conv = (LDKBroadcasterInterface*)this_arg;
1861         LDKTransaction tx_ref;
1862         tx_ref.datalen = *((uint32_t*)tx);
1863         tx_ref.data = MALLOC(tx_ref.datalen, "LDKTransaction Bytes");
1864         memcpy(tx_ref.data, (uint8_t*)(tx + 4), tx_ref.datalen);
1865         tx_ref.data_is_owned = true;
1866         (this_arg_conv->broadcast_transaction)(this_arg_conv->this_arg, tx_ref);
1867 }
1868
1869 typedef struct LDKKeysInterface_JCalls {
1870         atomic_size_t refcnt;
1871         uint32_t get_node_secret_meth;
1872         uint32_t get_destination_script_meth;
1873         uint32_t get_shutdown_pubkey_meth;
1874         uint32_t get_channel_keys_meth;
1875         uint32_t get_secure_random_bytes_meth;
1876         uint32_t read_chan_signer_meth;
1877 } LDKKeysInterface_JCalls;
1878 static void LDKKeysInterface_JCalls_free(void* this_arg) {
1879         LDKKeysInterface_JCalls *j_calls = (LDKKeysInterface_JCalls*) this_arg;
1880         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
1881                 js_free(j_calls->get_node_secret_meth);
1882                 js_free(j_calls->get_destination_script_meth);
1883                 js_free(j_calls->get_shutdown_pubkey_meth);
1884                 js_free(j_calls->get_channel_keys_meth);
1885                 js_free(j_calls->get_secure_random_bytes_meth);
1886                 js_free(j_calls->read_chan_signer_meth);
1887                 FREE(j_calls);
1888         }
1889 }
1890 LDKSecretKey get_node_secret_jcall(const void* this_arg) {
1891         LDKKeysInterface_JCalls *j_calls = (LDKKeysInterface_JCalls*) this_arg;
1892         int8_tArray arg = js_invoke_function_0(j_calls->get_node_secret_meth);
1893         LDKSecretKey arg_ref;
1894         CHECK(*((uint32_t*)arg) == 32);
1895         memcpy(arg_ref.bytes, (uint8_t*)(arg + 4), 32);
1896         return arg_ref;
1897 }
1898 LDKCVec_u8Z get_destination_script_jcall(const void* this_arg) {
1899         LDKKeysInterface_JCalls *j_calls = (LDKKeysInterface_JCalls*) this_arg;
1900         int8_tArray arg = js_invoke_function_0(j_calls->get_destination_script_meth);
1901         LDKCVec_u8Z arg_ref;
1902         arg_ref.datalen = *((uint32_t*)arg);
1903         arg_ref.data = MALLOC(arg_ref.datalen, "LDKCVec_u8Z Bytes");
1904         memcpy(arg_ref.data, (uint8_t*)(arg + 4), arg_ref.datalen);
1905         return arg_ref;
1906 }
1907 LDKPublicKey get_shutdown_pubkey_jcall(const void* this_arg) {
1908         LDKKeysInterface_JCalls *j_calls = (LDKKeysInterface_JCalls*) this_arg;
1909         int8_tArray arg = js_invoke_function_0(j_calls->get_shutdown_pubkey_meth);
1910         LDKPublicKey arg_ref;
1911         CHECK(*((uint32_t*)arg) == 33);
1912         memcpy(arg_ref.compressed_form, (uint8_t*)(arg + 4), 33);
1913         return arg_ref;
1914 }
1915 LDKChannelKeys get_channel_keys_jcall(const void* this_arg, bool inbound, uint64_t channel_value_satoshis) {
1916         LDKKeysInterface_JCalls *j_calls = (LDKKeysInterface_JCalls*) this_arg;
1917         LDKChannelKeys* ret; // TODO: Call get_channel_keys on j_calls with instance obj, returning a pointer, inbound, channel_value_satoshis);
1918         LDKChannelKeys ret_conv = *(LDKChannelKeys*)ret;
1919         ret_conv = ChannelKeys_clone(ret);
1920         return ret_conv;
1921 }
1922 LDKThirtyTwoBytes get_secure_random_bytes_jcall(const void* this_arg) {
1923         LDKKeysInterface_JCalls *j_calls = (LDKKeysInterface_JCalls*) this_arg;
1924         int8_tArray arg = js_invoke_function_0(j_calls->get_secure_random_bytes_meth);
1925         LDKThirtyTwoBytes arg_ref;
1926         CHECK(*((uint32_t*)arg) == 32);
1927         memcpy(arg_ref.data, (uint8_t*)(arg + 4), 32);
1928         return arg_ref;
1929 }
1930 LDKCResult_ChanKeySignerDecodeErrorZ read_chan_signer_jcall(const void* this_arg, LDKu8slice reader) {
1931         LDKKeysInterface_JCalls *j_calls = (LDKKeysInterface_JCalls*) this_arg;
1932         LDKu8slice reader_var = reader;
1933         int8_tArray reader_arr = init_arr(reader_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
1934         memcpy((uint8_t*)(reader_arr + 4), reader_var.data, reader_var.datalen);
1935         LDKCResult_ChanKeySignerDecodeErrorZ* ret; // TODO: Call read_chan_signer on j_calls with instance obj, returning a pointer, reader_arr);
1936         LDKCResult_ChanKeySignerDecodeErrorZ ret_conv = *(LDKCResult_ChanKeySignerDecodeErrorZ*)ret;
1937         FREE((void*)ret);
1938         return ret_conv;
1939 }
1940 static void* LDKKeysInterface_JCalls_clone(const void* this_arg) {
1941         LDKKeysInterface_JCalls *j_calls = (LDKKeysInterface_JCalls*) this_arg;
1942         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
1943         return (void*) this_arg;
1944 }
1945 static inline LDKKeysInterface LDKKeysInterface_init (/*TODO: JS Object Reference */void* o) {
1946         LDKKeysInterface_JCalls *calls = MALLOC(sizeof(LDKKeysInterface_JCalls), "LDKKeysInterface_JCalls");
1947         atomic_init(&calls->refcnt, 1);
1948         //TODO: Assign calls->o from o
1949
1950         LDKKeysInterface ret = {
1951                 .this_arg = (void*) calls,
1952                 .get_node_secret = get_node_secret_jcall,
1953                 .get_destination_script = get_destination_script_jcall,
1954                 .get_shutdown_pubkey = get_shutdown_pubkey_jcall,
1955                 .get_channel_keys = get_channel_keys_jcall,
1956                 .get_secure_random_bytes = get_secure_random_bytes_jcall,
1957                 .read_chan_signer = read_chan_signer_jcall,
1958                 .free = LDKKeysInterface_JCalls_free,
1959         };
1960         return ret;
1961 }
1962 long TS_LDKKeysInterface_new (/*TODO: JS Object Reference */void* o) {
1963         LDKKeysInterface *res_ptr = MALLOC(sizeof(LDKKeysInterface), "LDKKeysInterface");
1964         *res_ptr = LDKKeysInterface_init(o);
1965         return (long)res_ptr;
1966 }
1967 int8_tArray TS_KeysInterface_get_node_secret(uint32_t this_arg) {
1968         LDKKeysInterface* this_arg_conv = (LDKKeysInterface*)this_arg;
1969         int8_tArray arg_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
1970         memcpy((uint8_t*)(arg_arr + 4), (this_arg_conv->get_node_secret)(this_arg_conv->this_arg).bytes, 32);
1971         return arg_arr;
1972 }
1973
1974 int8_tArray TS_KeysInterface_get_destination_script(uint32_t this_arg) {
1975         LDKKeysInterface* this_arg_conv = (LDKKeysInterface*)this_arg;
1976         LDKCVec_u8Z arg_var = (this_arg_conv->get_destination_script)(this_arg_conv->this_arg);
1977         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
1978         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
1979         CVec_u8Z_free(arg_var);
1980         return arg_arr;
1981 }
1982
1983 int8_tArray TS_KeysInterface_get_shutdown_pubkey(uint32_t this_arg) {
1984         LDKKeysInterface* this_arg_conv = (LDKKeysInterface*)this_arg;
1985         int8_tArray arg_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
1986         memcpy((uint8_t*)(arg_arr + 4), (this_arg_conv->get_shutdown_pubkey)(this_arg_conv->this_arg).compressed_form, 33);
1987         return arg_arr;
1988 }
1989
1990 uint32_t TS_KeysInterface_get_channel_keys(uint32_t this_arg, jboolean inbound, int64_t channel_value_satoshis) {
1991         LDKKeysInterface* this_arg_conv = (LDKKeysInterface*)this_arg;
1992         LDKChannelKeys* ret = MALLOC(sizeof(LDKChannelKeys), "LDKChannelKeys");
1993         *ret = (this_arg_conv->get_channel_keys)(this_arg_conv->this_arg, inbound, channel_value_satoshis);
1994         return (long)ret;
1995 }
1996
1997 int8_tArray TS_KeysInterface_get_secure_random_bytes(uint32_t this_arg) {
1998         LDKKeysInterface* this_arg_conv = (LDKKeysInterface*)this_arg;
1999         int8_tArray arg_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
2000         memcpy((uint8_t*)(arg_arr + 4), (this_arg_conv->get_secure_random_bytes)(this_arg_conv->this_arg).data, 32);
2001         return arg_arr;
2002 }
2003
2004 uint32_t TS_KeysInterface_read_chan_signer(uint32_t this_arg, int8_tArray reader) {
2005         LDKKeysInterface* this_arg_conv = (LDKKeysInterface*)this_arg;
2006         LDKu8slice reader_ref;
2007         reader_ref.datalen = *((uint32_t*)reader);
2008         reader_ref.data = (int8_t*)(reader + 4);
2009         LDKCResult_ChanKeySignerDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ChanKeySignerDecodeErrorZ), "LDKCResult_ChanKeySignerDecodeErrorZ");
2010         *ret_conv = (this_arg_conv->read_chan_signer)(this_arg_conv->this_arg, reader_ref);
2011         return (long)ret_conv;
2012 }
2013
2014 typedef struct LDKFeeEstimator_JCalls {
2015         atomic_size_t refcnt;
2016         uint32_t get_est_sat_per_1000_weight_meth;
2017 } LDKFeeEstimator_JCalls;
2018 static void LDKFeeEstimator_JCalls_free(void* this_arg) {
2019         LDKFeeEstimator_JCalls *j_calls = (LDKFeeEstimator_JCalls*) this_arg;
2020         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
2021                 js_free(j_calls->get_est_sat_per_1000_weight_meth);
2022                 FREE(j_calls);
2023         }
2024 }
2025 uint32_t get_est_sat_per_1000_weight_jcall(const void* this_arg, LDKConfirmationTarget confirmation_target) {
2026         LDKFeeEstimator_JCalls *j_calls = (LDKFeeEstimator_JCalls*) this_arg;
2027         uint32_t confirmation_target_conv = LDKConfirmationTarget_to_js(confirmation_target);
2028         return js_invoke_function_1(j_calls->get_est_sat_per_1000_weight_meth, confirmation_target_conv);
2029 }
2030 static void* LDKFeeEstimator_JCalls_clone(const void* this_arg) {
2031         LDKFeeEstimator_JCalls *j_calls = (LDKFeeEstimator_JCalls*) this_arg;
2032         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
2033         return (void*) this_arg;
2034 }
2035 static inline LDKFeeEstimator LDKFeeEstimator_init (/*TODO: JS Object Reference */void* o) {
2036         LDKFeeEstimator_JCalls *calls = MALLOC(sizeof(LDKFeeEstimator_JCalls), "LDKFeeEstimator_JCalls");
2037         atomic_init(&calls->refcnt, 1);
2038         //TODO: Assign calls->o from o
2039
2040         LDKFeeEstimator ret = {
2041                 .this_arg = (void*) calls,
2042                 .get_est_sat_per_1000_weight = get_est_sat_per_1000_weight_jcall,
2043                 .free = LDKFeeEstimator_JCalls_free,
2044         };
2045         return ret;
2046 }
2047 long TS_LDKFeeEstimator_new (/*TODO: JS Object Reference */void* o) {
2048         LDKFeeEstimator *res_ptr = MALLOC(sizeof(LDKFeeEstimator), "LDKFeeEstimator");
2049         *res_ptr = LDKFeeEstimator_init(o);
2050         return (long)res_ptr;
2051 }
2052 int32_t TS_FeeEstimator_get_est_sat_per_1000_weight(uint32_t this_arg, uint32_t confirmation_target) {
2053         LDKFeeEstimator* this_arg_conv = (LDKFeeEstimator*)this_arg;
2054         LDKConfirmationTarget confirmation_target_conv = LDKConfirmationTarget_from_js(confirmation_target);
2055         int32_t ret_val = (this_arg_conv->get_est_sat_per_1000_weight)(this_arg_conv->this_arg, confirmation_target_conv);
2056         return ret_val;
2057 }
2058
2059 typedef struct LDKLogger_JCalls {
2060         atomic_size_t refcnt;
2061         uint32_t log_meth;
2062 } LDKLogger_JCalls;
2063 static void LDKLogger_JCalls_free(void* this_arg) {
2064         LDKLogger_JCalls *j_calls = (LDKLogger_JCalls*) this_arg;
2065         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
2066                 js_free(j_calls->log_meth);
2067                 FREE(j_calls);
2068         }
2069 }
2070 void log_jcall(const void* this_arg, const char* record) {
2071         LDKLogger_JCalls *j_calls = (LDKLogger_JCalls*) this_arg;
2072         const char* record_str = record;
2073         jstring record_conv = str_ref_to_ts(record_str, strlen(record_str));
2074         js_invoke_function_1(j_calls->log_meth, record_conv);
2075 }
2076 static void* LDKLogger_JCalls_clone(const void* this_arg) {
2077         LDKLogger_JCalls *j_calls = (LDKLogger_JCalls*) this_arg;
2078         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
2079         return (void*) this_arg;
2080 }
2081 static inline LDKLogger LDKLogger_init (/*TODO: JS Object Reference */void* o) {
2082         LDKLogger_JCalls *calls = MALLOC(sizeof(LDKLogger_JCalls), "LDKLogger_JCalls");
2083         atomic_init(&calls->refcnt, 1);
2084         //TODO: Assign calls->o from o
2085
2086         LDKLogger ret = {
2087                 .this_arg = (void*) calls,
2088                 .log = log_jcall,
2089                 .free = LDKLogger_JCalls_free,
2090         };
2091         return ret;
2092 }
2093 long TS_LDKLogger_new (/*TODO: JS Object Reference */void* o) {
2094         LDKLogger *res_ptr = MALLOC(sizeof(LDKLogger), "LDKLogger");
2095         *res_ptr = LDKLogger_init(o);
2096         return (long)res_ptr;
2097 }
2098 uint32_t TS_LDKC2Tuple_BlockHashChannelManagerZ_new(int8_tArray a, uint32_t b) {
2099         LDKC2Tuple_BlockHashChannelManagerZ* ret = MALLOC(sizeof(LDKC2Tuple_BlockHashChannelManagerZ), "LDKC2Tuple_BlockHashChannelManagerZ");
2100         LDKThirtyTwoBytes a_ref;
2101         CHECK(*((uint32_t*)a) == 32);
2102         memcpy(a_ref.data, (uint8_t*)(a + 4), 32);
2103         ret->a = a_ref;
2104         LDKChannelManager b_conv;
2105         b_conv.inner = (void*)(b & (~1));
2106         b_conv.is_owned = (b & 1) || (b == 0);
2107         // Warning: we may need a move here but can't clone!
2108         ret->b = b_conv;
2109         return (long)ret;
2110 }
2111 int8_tArray TS_LDKC2Tuple_BlockHashChannelManagerZ_get_a(uint32_t ptr) {
2112         LDKC2Tuple_BlockHashChannelManagerZ *tuple = (LDKC2Tuple_BlockHashChannelManagerZ*)ptr;
2113         int8_tArray a_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
2114         memcpy((uint8_t*)(a_arr + 4), tuple->a.data, 32);
2115         return a_arr;
2116 }
2117 uint32_t TS_LDKC2Tuple_BlockHashChannelManagerZ_get_b(uint32_t ptr) {
2118         LDKC2Tuple_BlockHashChannelManagerZ *tuple = (LDKC2Tuple_BlockHashChannelManagerZ*)ptr;
2119         LDKChannelManager b_var = tuple->b;
2120         CHECK((((long)b_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2121         CHECK((((long)&b_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2122         long b_ref = (long)b_var.inner & ~1;
2123         return b_ref;
2124 }
2125 jboolean TS_LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ_result_ok(uint32_t arg) {
2126         return ((LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ*)arg)->result_ok;
2127 }
2128 uint32_t TS_LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ_get_ok(uint32_t arg) {
2129         LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ *val = (LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ*)arg;
2130         CHECK(val->result_ok);
2131         long res_ref = (long)&(*val->contents.result);
2132         return res_ref;
2133 }
2134 uint32_t TS_LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ_get_err(uint32_t arg) {
2135         LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ *val = (LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ*)arg;
2136         CHECK(!val->result_ok);
2137         LDKDecodeError err_var = (*val->contents.err);
2138         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2139         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2140         long err_ref = (long)err_var.inner & ~1;
2141         return err_ref;
2142 }
2143 jboolean TS_LDKCResult_NetAddressu8Z_result_ok(uint32_t arg) {
2144         return ((LDKCResult_NetAddressu8Z*)arg)->result_ok;
2145 }
2146 uint32_t TS_LDKCResult_NetAddressu8Z_get_ok(uint32_t arg) {
2147         LDKCResult_NetAddressu8Z *val = (LDKCResult_NetAddressu8Z*)arg;
2148         CHECK(val->result_ok);
2149         long res_ref = (long)&(*val->contents.result);
2150         return res_ref;
2151 }
2152 int8_t TS_LDKCResult_NetAddressu8Z_get_err(uint32_t arg) {
2153         LDKCResult_NetAddressu8Z *val = (LDKCResult_NetAddressu8Z*)arg;
2154         CHECK(!val->result_ok);
2155         return *val->contents.err;
2156 }
2157 static inline LDKCResult_NetAddressu8Z CResult_NetAddressu8Z_clone(const LDKCResult_NetAddressu8Z *orig) {
2158         LDKCResult_NetAddressu8Z res = { .result_ok = orig->result_ok };
2159         if (orig->result_ok) {
2160                 LDKNetAddress* contents = MALLOC(sizeof(LDKNetAddress), "LDKNetAddress result OK clone");
2161                 *contents = NetAddress_clone(orig->contents.result);
2162                 res.contents.result = contents;
2163         } else {
2164                 int8_t* contents = MALLOC(sizeof(int8_t), "int8_t result Err clone");
2165                 *contents = *orig->contents.err;
2166                 res.contents.err = contents;
2167         }
2168         return res;
2169 }
2170 jboolean TS_LDKCResult_CResult_NetAddressu8ZDecodeErrorZ_result_ok(uint32_t arg) {
2171         return ((LDKCResult_CResult_NetAddressu8ZDecodeErrorZ*)arg)->result_ok;
2172 }
2173 uint32_t TS_LDKCResult_CResult_NetAddressu8ZDecodeErrorZ_get_ok(uint32_t arg) {
2174         LDKCResult_CResult_NetAddressu8ZDecodeErrorZ *val = (LDKCResult_CResult_NetAddressu8ZDecodeErrorZ*)arg;
2175         CHECK(val->result_ok);
2176         LDKCResult_NetAddressu8Z* res_conv = MALLOC(sizeof(LDKCResult_NetAddressu8Z), "LDKCResult_NetAddressu8Z");
2177         *res_conv = (*val->contents.result);
2178         *res_conv = CResult_NetAddressu8Z_clone(res_conv);
2179         return (long)res_conv;
2180 }
2181 uint32_t TS_LDKCResult_CResult_NetAddressu8ZDecodeErrorZ_get_err(uint32_t arg) {
2182         LDKCResult_CResult_NetAddressu8ZDecodeErrorZ *val = (LDKCResult_CResult_NetAddressu8ZDecodeErrorZ*)arg;
2183         CHECK(!val->result_ok);
2184         LDKDecodeError err_var = (*val->contents.err);
2185         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2186         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2187         long err_ref = (long)err_var.inner & ~1;
2188         return err_ref;
2189 }
2190 uint32_t TS_LDKCVec_u64Z_new(int64_tArray elems) {
2191         LDKCVec_u64Z *ret = MALLOC(sizeof(LDKCVec_u64Z), "LDKCVec_u64Z");
2192         ret->datalen = *((uint32_t*)elems);
2193         if (ret->datalen == 0) {
2194                 ret->data = NULL;
2195         } else {
2196                 ret->data = MALLOC(sizeof(uint64_t) * ret->datalen, "LDKCVec_u64Z Data");
2197                 int64_t *java_elems = (int64_t*)(elems + 4);
2198                 for (size_t i = 0; i < ret->datalen; i++) {
2199                         ret->data[i] = java_elems[i];
2200                 }
2201         }
2202         return (long)ret;
2203 }
2204 static inline LDKCVec_u64Z CVec_u64Z_clone(const LDKCVec_u64Z *orig) {
2205         LDKCVec_u64Z ret = { .data = MALLOC(sizeof(int64_t) * orig->datalen, "LDKCVec_u64Z clone bytes"), .datalen = orig->datalen };
2206         memcpy(ret.data, orig->data, sizeof(int64_t) * ret.datalen);
2207         return ret;
2208 }
2209 uint32_t TS_LDKCVec_UpdateAddHTLCZ_new(uint32_tArray elems) {
2210         LDKCVec_UpdateAddHTLCZ *ret = MALLOC(sizeof(LDKCVec_UpdateAddHTLCZ), "LDKCVec_UpdateAddHTLCZ");
2211         ret->datalen = *((uint32_t*)elems);
2212         if (ret->datalen == 0) {
2213                 ret->data = NULL;
2214         } else {
2215                 ret->data = MALLOC(sizeof(LDKUpdateAddHTLC) * ret->datalen, "LDKCVec_UpdateAddHTLCZ Data");
2216                 uint32_t *java_elems = (uint32_t*)(elems + 4);
2217                 for (size_t i = 0; i < ret->datalen; i++) {
2218                         uint32_t arr_elem = java_elems[i];
2219                         LDKUpdateAddHTLC arr_elem_conv;
2220                         arr_elem_conv.inner = (void*)(arr_elem & (~1));
2221                         arr_elem_conv.is_owned = (arr_elem & 1) || (arr_elem == 0);
2222                         if (arr_elem_conv.inner != NULL)
2223                                 arr_elem_conv = UpdateAddHTLC_clone(&arr_elem_conv);
2224                         ret->data[i] = arr_elem_conv;
2225                 }
2226         }
2227         return (long)ret;
2228 }
2229 static inline LDKCVec_UpdateAddHTLCZ CVec_UpdateAddHTLCZ_clone(const LDKCVec_UpdateAddHTLCZ *orig) {
2230         LDKCVec_UpdateAddHTLCZ ret = { .data = MALLOC(sizeof(LDKUpdateAddHTLC) * orig->datalen, "LDKCVec_UpdateAddHTLCZ clone bytes"), .datalen = orig->datalen };
2231         for (size_t i = 0; i < ret.datalen; i++) {
2232                 ret.data[i] = UpdateAddHTLC_clone(&orig->data[i]);
2233         }
2234         return ret;
2235 }
2236 uint32_t TS_LDKCVec_UpdateFulfillHTLCZ_new(uint32_tArray elems) {
2237         LDKCVec_UpdateFulfillHTLCZ *ret = MALLOC(sizeof(LDKCVec_UpdateFulfillHTLCZ), "LDKCVec_UpdateFulfillHTLCZ");
2238         ret->datalen = *((uint32_t*)elems);
2239         if (ret->datalen == 0) {
2240                 ret->data = NULL;
2241         } else {
2242                 ret->data = MALLOC(sizeof(LDKUpdateFulfillHTLC) * ret->datalen, "LDKCVec_UpdateFulfillHTLCZ Data");
2243                 uint32_t *java_elems = (uint32_t*)(elems + 4);
2244                 for (size_t i = 0; i < ret->datalen; i++) {
2245                         uint32_t arr_elem = java_elems[i];
2246                         LDKUpdateFulfillHTLC arr_elem_conv;
2247                         arr_elem_conv.inner = (void*)(arr_elem & (~1));
2248                         arr_elem_conv.is_owned = (arr_elem & 1) || (arr_elem == 0);
2249                         if (arr_elem_conv.inner != NULL)
2250                                 arr_elem_conv = UpdateFulfillHTLC_clone(&arr_elem_conv);
2251                         ret->data[i] = arr_elem_conv;
2252                 }
2253         }
2254         return (long)ret;
2255 }
2256 static inline LDKCVec_UpdateFulfillHTLCZ CVec_UpdateFulfillHTLCZ_clone(const LDKCVec_UpdateFulfillHTLCZ *orig) {
2257         LDKCVec_UpdateFulfillHTLCZ ret = { .data = MALLOC(sizeof(LDKUpdateFulfillHTLC) * orig->datalen, "LDKCVec_UpdateFulfillHTLCZ clone bytes"), .datalen = orig->datalen };
2258         for (size_t i = 0; i < ret.datalen; i++) {
2259                 ret.data[i] = UpdateFulfillHTLC_clone(&orig->data[i]);
2260         }
2261         return ret;
2262 }
2263 uint32_t TS_LDKCVec_UpdateFailHTLCZ_new(uint32_tArray elems) {
2264         LDKCVec_UpdateFailHTLCZ *ret = MALLOC(sizeof(LDKCVec_UpdateFailHTLCZ), "LDKCVec_UpdateFailHTLCZ");
2265         ret->datalen = *((uint32_t*)elems);
2266         if (ret->datalen == 0) {
2267                 ret->data = NULL;
2268         } else {
2269                 ret->data = MALLOC(sizeof(LDKUpdateFailHTLC) * ret->datalen, "LDKCVec_UpdateFailHTLCZ Data");
2270                 uint32_t *java_elems = (uint32_t*)(elems + 4);
2271                 for (size_t i = 0; i < ret->datalen; i++) {
2272                         uint32_t arr_elem = java_elems[i];
2273                         LDKUpdateFailHTLC arr_elem_conv;
2274                         arr_elem_conv.inner = (void*)(arr_elem & (~1));
2275                         arr_elem_conv.is_owned = (arr_elem & 1) || (arr_elem == 0);
2276                         if (arr_elem_conv.inner != NULL)
2277                                 arr_elem_conv = UpdateFailHTLC_clone(&arr_elem_conv);
2278                         ret->data[i] = arr_elem_conv;
2279                 }
2280         }
2281         return (long)ret;
2282 }
2283 static inline LDKCVec_UpdateFailHTLCZ CVec_UpdateFailHTLCZ_clone(const LDKCVec_UpdateFailHTLCZ *orig) {
2284         LDKCVec_UpdateFailHTLCZ ret = { .data = MALLOC(sizeof(LDKUpdateFailHTLC) * orig->datalen, "LDKCVec_UpdateFailHTLCZ clone bytes"), .datalen = orig->datalen };
2285         for (size_t i = 0; i < ret.datalen; i++) {
2286                 ret.data[i] = UpdateFailHTLC_clone(&orig->data[i]);
2287         }
2288         return ret;
2289 }
2290 uint32_t TS_LDKCVec_UpdateFailMalformedHTLCZ_new(uint32_tArray elems) {
2291         LDKCVec_UpdateFailMalformedHTLCZ *ret = MALLOC(sizeof(LDKCVec_UpdateFailMalformedHTLCZ), "LDKCVec_UpdateFailMalformedHTLCZ");
2292         ret->datalen = *((uint32_t*)elems);
2293         if (ret->datalen == 0) {
2294                 ret->data = NULL;
2295         } else {
2296                 ret->data = MALLOC(sizeof(LDKUpdateFailMalformedHTLC) * ret->datalen, "LDKCVec_UpdateFailMalformedHTLCZ Data");
2297                 uint32_t *java_elems = (uint32_t*)(elems + 4);
2298                 for (size_t i = 0; i < ret->datalen; i++) {
2299                         uint32_t arr_elem = java_elems[i];
2300                         LDKUpdateFailMalformedHTLC arr_elem_conv;
2301                         arr_elem_conv.inner = (void*)(arr_elem & (~1));
2302                         arr_elem_conv.is_owned = (arr_elem & 1) || (arr_elem == 0);
2303                         if (arr_elem_conv.inner != NULL)
2304                                 arr_elem_conv = UpdateFailMalformedHTLC_clone(&arr_elem_conv);
2305                         ret->data[i] = arr_elem_conv;
2306                 }
2307         }
2308         return (long)ret;
2309 }
2310 static inline LDKCVec_UpdateFailMalformedHTLCZ CVec_UpdateFailMalformedHTLCZ_clone(const LDKCVec_UpdateFailMalformedHTLCZ *orig) {
2311         LDKCVec_UpdateFailMalformedHTLCZ ret = { .data = MALLOC(sizeof(LDKUpdateFailMalformedHTLC) * orig->datalen, "LDKCVec_UpdateFailMalformedHTLCZ clone bytes"), .datalen = orig->datalen };
2312         for (size_t i = 0; i < ret.datalen; i++) {
2313                 ret.data[i] = UpdateFailMalformedHTLC_clone(&orig->data[i]);
2314         }
2315         return ret;
2316 }
2317 jboolean TS_LDKCResult_boolLightningErrorZ_result_ok(uint32_t arg) {
2318         return ((LDKCResult_boolLightningErrorZ*)arg)->result_ok;
2319 }
2320 jboolean TS_LDKCResult_boolLightningErrorZ_get_ok(uint32_t arg) {
2321         LDKCResult_boolLightningErrorZ *val = (LDKCResult_boolLightningErrorZ*)arg;
2322         CHECK(val->result_ok);
2323         return *val->contents.result;
2324 }
2325 uint32_t TS_LDKCResult_boolLightningErrorZ_get_err(uint32_t arg) {
2326         LDKCResult_boolLightningErrorZ *val = (LDKCResult_boolLightningErrorZ*)arg;
2327         CHECK(!val->result_ok);
2328         LDKLightningError err_var = (*val->contents.err);
2329         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2330         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2331         long err_ref = (long)err_var.inner & ~1;
2332         return err_ref;
2333 }
2334 uint32_t TS_LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ_new(uint32_t a, uint32_t b, uint32_t c) {
2335         LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ* ret = MALLOC(sizeof(LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ), "LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ");
2336         LDKChannelAnnouncement a_conv;
2337         a_conv.inner = (void*)(a & (~1));
2338         a_conv.is_owned = (a & 1) || (a == 0);
2339         if (a_conv.inner != NULL)
2340                 a_conv = ChannelAnnouncement_clone(&a_conv);
2341         ret->a = a_conv;
2342         LDKChannelUpdate b_conv;
2343         b_conv.inner = (void*)(b & (~1));
2344         b_conv.is_owned = (b & 1) || (b == 0);
2345         if (b_conv.inner != NULL)
2346                 b_conv = ChannelUpdate_clone(&b_conv);
2347         ret->b = b_conv;
2348         LDKChannelUpdate c_conv;
2349         c_conv.inner = (void*)(c & (~1));
2350         c_conv.is_owned = (c & 1) || (c == 0);
2351         if (c_conv.inner != NULL)
2352                 c_conv = ChannelUpdate_clone(&c_conv);
2353         ret->c = c_conv;
2354         return (long)ret;
2355 }
2356 static inline LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ_clone(const LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ *orig) {
2357         LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ ret = {
2358                 .a = ChannelAnnouncement_clone(&orig->a),
2359                 .b = ChannelUpdate_clone(&orig->b),
2360                 .c = ChannelUpdate_clone(&orig->c),
2361         };
2362         return ret;
2363 }
2364 uint32_t TS_LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ_get_a(uint32_t ptr) {
2365         LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ *tuple = (LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ*)ptr;
2366         LDKChannelAnnouncement a_var = tuple->a;
2367         CHECK((((long)a_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2368         CHECK((((long)&a_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2369         long a_ref = (long)a_var.inner & ~1;
2370         return a_ref;
2371 }
2372 uint32_t TS_LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ_get_b(uint32_t ptr) {
2373         LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ *tuple = (LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ*)ptr;
2374         LDKChannelUpdate b_var = tuple->b;
2375         CHECK((((long)b_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2376         CHECK((((long)&b_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2377         long b_ref = (long)b_var.inner & ~1;
2378         return b_ref;
2379 }
2380 uint32_t TS_LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ_get_c(uint32_t ptr) {
2381         LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ *tuple = (LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ*)ptr;
2382         LDKChannelUpdate c_var = tuple->c;
2383         CHECK((((long)c_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2384         CHECK((((long)&c_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2385         long c_ref = (long)c_var.inner & ~1;
2386         return c_ref;
2387 }
2388 uint32_t TS_LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ_new(uint32_tArray elems) {
2389         LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ *ret = MALLOC(sizeof(LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ), "LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ");
2390         ret->datalen = *((uint32_t*)elems);
2391         if (ret->datalen == 0) {
2392                 ret->data = NULL;
2393         } else {
2394                 ret->data = MALLOC(sizeof(LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ) * ret->datalen, "LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ Data");
2395                 uint32_t *java_elems = (uint32_t*)(elems + 4);
2396                 for (size_t i = 0; i < ret->datalen; i++) {
2397                         uint32_t arr_elem = java_elems[i];
2398                         LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ arr_elem_conv = *(LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ*)arr_elem;
2399                         FREE((void*)arr_elem);
2400                         ret->data[i] = arr_elem_conv;
2401                 }
2402         }
2403         return (long)ret;
2404 }
2405 static inline LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ CVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ_clone(const LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ *orig) {
2406         LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ ret = { .data = MALLOC(sizeof(LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ) * orig->datalen, "LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ clone bytes"), .datalen = orig->datalen };
2407         for (size_t i = 0; i < ret.datalen; i++) {
2408                 ret.data[i] = C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ_clone(&orig->data[i]);
2409         }
2410         return ret;
2411 }
2412 uint32_t TS_LDKCVec_NodeAnnouncementZ_new(uint32_tArray elems) {
2413         LDKCVec_NodeAnnouncementZ *ret = MALLOC(sizeof(LDKCVec_NodeAnnouncementZ), "LDKCVec_NodeAnnouncementZ");
2414         ret->datalen = *((uint32_t*)elems);
2415         if (ret->datalen == 0) {
2416                 ret->data = NULL;
2417         } else {
2418                 ret->data = MALLOC(sizeof(LDKNodeAnnouncement) * ret->datalen, "LDKCVec_NodeAnnouncementZ Data");
2419                 uint32_t *java_elems = (uint32_t*)(elems + 4);
2420                 for (size_t i = 0; i < ret->datalen; i++) {
2421                         uint32_t arr_elem = java_elems[i];
2422                         LDKNodeAnnouncement arr_elem_conv;
2423                         arr_elem_conv.inner = (void*)(arr_elem & (~1));
2424                         arr_elem_conv.is_owned = (arr_elem & 1) || (arr_elem == 0);
2425                         if (arr_elem_conv.inner != NULL)
2426                                 arr_elem_conv = NodeAnnouncement_clone(&arr_elem_conv);
2427                         ret->data[i] = arr_elem_conv;
2428                 }
2429         }
2430         return (long)ret;
2431 }
2432 static inline LDKCVec_NodeAnnouncementZ CVec_NodeAnnouncementZ_clone(const LDKCVec_NodeAnnouncementZ *orig) {
2433         LDKCVec_NodeAnnouncementZ ret = { .data = MALLOC(sizeof(LDKNodeAnnouncement) * orig->datalen, "LDKCVec_NodeAnnouncementZ clone bytes"), .datalen = orig->datalen };
2434         for (size_t i = 0; i < ret.datalen; i++) {
2435                 ret.data[i] = NodeAnnouncement_clone(&orig->data[i]);
2436         }
2437         return ret;
2438 }
2439 jboolean TS_LDKCResult_NoneLightningErrorZ_result_ok(uint32_t arg) {
2440         return ((LDKCResult_NoneLightningErrorZ*)arg)->result_ok;
2441 }
2442 void TS_LDKCResult_NoneLightningErrorZ_get_ok(uint32_t arg) {
2443         LDKCResult_NoneLightningErrorZ *val = (LDKCResult_NoneLightningErrorZ*)arg;
2444         CHECK(val->result_ok);
2445         return *val->contents.result;
2446 }
2447 uint32_t TS_LDKCResult_NoneLightningErrorZ_get_err(uint32_t arg) {
2448         LDKCResult_NoneLightningErrorZ *val = (LDKCResult_NoneLightningErrorZ*)arg;
2449         CHECK(!val->result_ok);
2450         LDKLightningError err_var = (*val->contents.err);
2451         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2452         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2453         long err_ref = (long)err_var.inner & ~1;
2454         return err_ref;
2455 }
2456 jboolean TS_LDKCResult_ChannelReestablishDecodeErrorZ_result_ok(uint32_t arg) {
2457         return ((LDKCResult_ChannelReestablishDecodeErrorZ*)arg)->result_ok;
2458 }
2459 uint32_t TS_LDKCResult_ChannelReestablishDecodeErrorZ_get_ok(uint32_t arg) {
2460         LDKCResult_ChannelReestablishDecodeErrorZ *val = (LDKCResult_ChannelReestablishDecodeErrorZ*)arg;
2461         CHECK(val->result_ok);
2462         LDKChannelReestablish res_var = (*val->contents.result);
2463         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2464         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2465         long res_ref = (long)res_var.inner & ~1;
2466         return res_ref;
2467 }
2468 uint32_t TS_LDKCResult_ChannelReestablishDecodeErrorZ_get_err(uint32_t arg) {
2469         LDKCResult_ChannelReestablishDecodeErrorZ *val = (LDKCResult_ChannelReestablishDecodeErrorZ*)arg;
2470         CHECK(!val->result_ok);
2471         LDKDecodeError err_var = (*val->contents.err);
2472         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2473         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2474         long err_ref = (long)err_var.inner & ~1;
2475         return err_ref;
2476 }
2477 jboolean TS_LDKCResult_InitDecodeErrorZ_result_ok(uint32_t arg) {
2478         return ((LDKCResult_InitDecodeErrorZ*)arg)->result_ok;
2479 }
2480 uint32_t TS_LDKCResult_InitDecodeErrorZ_get_ok(uint32_t arg) {
2481         LDKCResult_InitDecodeErrorZ *val = (LDKCResult_InitDecodeErrorZ*)arg;
2482         CHECK(val->result_ok);
2483         LDKInit res_var = (*val->contents.result);
2484         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2485         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2486         long res_ref = (long)res_var.inner & ~1;
2487         return res_ref;
2488 }
2489 uint32_t TS_LDKCResult_InitDecodeErrorZ_get_err(uint32_t arg) {
2490         LDKCResult_InitDecodeErrorZ *val = (LDKCResult_InitDecodeErrorZ*)arg;
2491         CHECK(!val->result_ok);
2492         LDKDecodeError err_var = (*val->contents.err);
2493         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2494         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2495         long err_ref = (long)err_var.inner & ~1;
2496         return err_ref;
2497 }
2498 jboolean TS_LDKCResult_PingDecodeErrorZ_result_ok(uint32_t arg) {
2499         return ((LDKCResult_PingDecodeErrorZ*)arg)->result_ok;
2500 }
2501 uint32_t TS_LDKCResult_PingDecodeErrorZ_get_ok(uint32_t arg) {
2502         LDKCResult_PingDecodeErrorZ *val = (LDKCResult_PingDecodeErrorZ*)arg;
2503         CHECK(val->result_ok);
2504         LDKPing res_var = (*val->contents.result);
2505         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2506         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2507         long res_ref = (long)res_var.inner & ~1;
2508         return res_ref;
2509 }
2510 uint32_t TS_LDKCResult_PingDecodeErrorZ_get_err(uint32_t arg) {
2511         LDKCResult_PingDecodeErrorZ *val = (LDKCResult_PingDecodeErrorZ*)arg;
2512         CHECK(!val->result_ok);
2513         LDKDecodeError err_var = (*val->contents.err);
2514         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2515         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2516         long err_ref = (long)err_var.inner & ~1;
2517         return err_ref;
2518 }
2519 jboolean TS_LDKCResult_PongDecodeErrorZ_result_ok(uint32_t arg) {
2520         return ((LDKCResult_PongDecodeErrorZ*)arg)->result_ok;
2521 }
2522 uint32_t TS_LDKCResult_PongDecodeErrorZ_get_ok(uint32_t arg) {
2523         LDKCResult_PongDecodeErrorZ *val = (LDKCResult_PongDecodeErrorZ*)arg;
2524         CHECK(val->result_ok);
2525         LDKPong res_var = (*val->contents.result);
2526         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2527         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2528         long res_ref = (long)res_var.inner & ~1;
2529         return res_ref;
2530 }
2531 uint32_t TS_LDKCResult_PongDecodeErrorZ_get_err(uint32_t arg) {
2532         LDKCResult_PongDecodeErrorZ *val = (LDKCResult_PongDecodeErrorZ*)arg;
2533         CHECK(!val->result_ok);
2534         LDKDecodeError err_var = (*val->contents.err);
2535         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2536         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2537         long err_ref = (long)err_var.inner & ~1;
2538         return err_ref;
2539 }
2540 jboolean TS_LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ_result_ok(uint32_t arg) {
2541         return ((LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ*)arg)->result_ok;
2542 }
2543 uint32_t TS_LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ_get_ok(uint32_t arg) {
2544         LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ *val = (LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ*)arg;
2545         CHECK(val->result_ok);
2546         LDKUnsignedChannelAnnouncement res_var = (*val->contents.result);
2547         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2548         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2549         long res_ref = (long)res_var.inner & ~1;
2550         return res_ref;
2551 }
2552 uint32_t TS_LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ_get_err(uint32_t arg) {
2553         LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ *val = (LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ*)arg;
2554         CHECK(!val->result_ok);
2555         LDKDecodeError err_var = (*val->contents.err);
2556         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2557         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2558         long err_ref = (long)err_var.inner & ~1;
2559         return err_ref;
2560 }
2561 jboolean TS_LDKCResult_UnsignedChannelUpdateDecodeErrorZ_result_ok(uint32_t arg) {
2562         return ((LDKCResult_UnsignedChannelUpdateDecodeErrorZ*)arg)->result_ok;
2563 }
2564 uint32_t TS_LDKCResult_UnsignedChannelUpdateDecodeErrorZ_get_ok(uint32_t arg) {
2565         LDKCResult_UnsignedChannelUpdateDecodeErrorZ *val = (LDKCResult_UnsignedChannelUpdateDecodeErrorZ*)arg;
2566         CHECK(val->result_ok);
2567         LDKUnsignedChannelUpdate res_var = (*val->contents.result);
2568         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2569         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2570         long res_ref = (long)res_var.inner & ~1;
2571         return res_ref;
2572 }
2573 uint32_t TS_LDKCResult_UnsignedChannelUpdateDecodeErrorZ_get_err(uint32_t arg) {
2574         LDKCResult_UnsignedChannelUpdateDecodeErrorZ *val = (LDKCResult_UnsignedChannelUpdateDecodeErrorZ*)arg;
2575         CHECK(!val->result_ok);
2576         LDKDecodeError err_var = (*val->contents.err);
2577         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2578         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2579         long err_ref = (long)err_var.inner & ~1;
2580         return err_ref;
2581 }
2582 jboolean TS_LDKCResult_ErrorMessageDecodeErrorZ_result_ok(uint32_t arg) {
2583         return ((LDKCResult_ErrorMessageDecodeErrorZ*)arg)->result_ok;
2584 }
2585 uint32_t TS_LDKCResult_ErrorMessageDecodeErrorZ_get_ok(uint32_t arg) {
2586         LDKCResult_ErrorMessageDecodeErrorZ *val = (LDKCResult_ErrorMessageDecodeErrorZ*)arg;
2587         CHECK(val->result_ok);
2588         LDKErrorMessage res_var = (*val->contents.result);
2589         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2590         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2591         long res_ref = (long)res_var.inner & ~1;
2592         return res_ref;
2593 }
2594 uint32_t TS_LDKCResult_ErrorMessageDecodeErrorZ_get_err(uint32_t arg) {
2595         LDKCResult_ErrorMessageDecodeErrorZ *val = (LDKCResult_ErrorMessageDecodeErrorZ*)arg;
2596         CHECK(!val->result_ok);
2597         LDKDecodeError err_var = (*val->contents.err);
2598         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2599         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2600         long err_ref = (long)err_var.inner & ~1;
2601         return err_ref;
2602 }
2603 jboolean TS_LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ_result_ok(uint32_t arg) {
2604         return ((LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ*)arg)->result_ok;
2605 }
2606 uint32_t TS_LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ_get_ok(uint32_t arg) {
2607         LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ *val = (LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ*)arg;
2608         CHECK(val->result_ok);
2609         LDKUnsignedNodeAnnouncement res_var = (*val->contents.result);
2610         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2611         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2612         long res_ref = (long)res_var.inner & ~1;
2613         return res_ref;
2614 }
2615 uint32_t TS_LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ_get_err(uint32_t arg) {
2616         LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ *val = (LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ*)arg;
2617         CHECK(!val->result_ok);
2618         LDKDecodeError err_var = (*val->contents.err);
2619         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2620         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2621         long err_ref = (long)err_var.inner & ~1;
2622         return err_ref;
2623 }
2624 jboolean TS_LDKCResult_QueryShortChannelIdsDecodeErrorZ_result_ok(uint32_t arg) {
2625         return ((LDKCResult_QueryShortChannelIdsDecodeErrorZ*)arg)->result_ok;
2626 }
2627 uint32_t TS_LDKCResult_QueryShortChannelIdsDecodeErrorZ_get_ok(uint32_t arg) {
2628         LDKCResult_QueryShortChannelIdsDecodeErrorZ *val = (LDKCResult_QueryShortChannelIdsDecodeErrorZ*)arg;
2629         CHECK(val->result_ok);
2630         LDKQueryShortChannelIds res_var = (*val->contents.result);
2631         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2632         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2633         long res_ref = (long)res_var.inner & ~1;
2634         return res_ref;
2635 }
2636 uint32_t TS_LDKCResult_QueryShortChannelIdsDecodeErrorZ_get_err(uint32_t arg) {
2637         LDKCResult_QueryShortChannelIdsDecodeErrorZ *val = (LDKCResult_QueryShortChannelIdsDecodeErrorZ*)arg;
2638         CHECK(!val->result_ok);
2639         LDKDecodeError err_var = (*val->contents.err);
2640         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2641         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2642         long err_ref = (long)err_var.inner & ~1;
2643         return err_ref;
2644 }
2645 jboolean TS_LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ_result_ok(uint32_t arg) {
2646         return ((LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ*)arg)->result_ok;
2647 }
2648 uint32_t TS_LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ_get_ok(uint32_t arg) {
2649         LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ *val = (LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ*)arg;
2650         CHECK(val->result_ok);
2651         LDKReplyShortChannelIdsEnd res_var = (*val->contents.result);
2652         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2653         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2654         long res_ref = (long)res_var.inner & ~1;
2655         return res_ref;
2656 }
2657 uint32_t TS_LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ_get_err(uint32_t arg) {
2658         LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ *val = (LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ*)arg;
2659         CHECK(!val->result_ok);
2660         LDKDecodeError err_var = (*val->contents.err);
2661         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2662         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2663         long err_ref = (long)err_var.inner & ~1;
2664         return err_ref;
2665 }
2666 jboolean TS_LDKCResult_QueryChannelRangeDecodeErrorZ_result_ok(uint32_t arg) {
2667         return ((LDKCResult_QueryChannelRangeDecodeErrorZ*)arg)->result_ok;
2668 }
2669 uint32_t TS_LDKCResult_QueryChannelRangeDecodeErrorZ_get_ok(uint32_t arg) {
2670         LDKCResult_QueryChannelRangeDecodeErrorZ *val = (LDKCResult_QueryChannelRangeDecodeErrorZ*)arg;
2671         CHECK(val->result_ok);
2672         LDKQueryChannelRange res_var = (*val->contents.result);
2673         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2674         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2675         long res_ref = (long)res_var.inner & ~1;
2676         return res_ref;
2677 }
2678 uint32_t TS_LDKCResult_QueryChannelRangeDecodeErrorZ_get_err(uint32_t arg) {
2679         LDKCResult_QueryChannelRangeDecodeErrorZ *val = (LDKCResult_QueryChannelRangeDecodeErrorZ*)arg;
2680         CHECK(!val->result_ok);
2681         LDKDecodeError err_var = (*val->contents.err);
2682         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2683         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2684         long err_ref = (long)err_var.inner & ~1;
2685         return err_ref;
2686 }
2687 jboolean TS_LDKCResult_ReplyChannelRangeDecodeErrorZ_result_ok(uint32_t arg) {
2688         return ((LDKCResult_ReplyChannelRangeDecodeErrorZ*)arg)->result_ok;
2689 }
2690 uint32_t TS_LDKCResult_ReplyChannelRangeDecodeErrorZ_get_ok(uint32_t arg) {
2691         LDKCResult_ReplyChannelRangeDecodeErrorZ *val = (LDKCResult_ReplyChannelRangeDecodeErrorZ*)arg;
2692         CHECK(val->result_ok);
2693         LDKReplyChannelRange res_var = (*val->contents.result);
2694         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2695         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2696         long res_ref = (long)res_var.inner & ~1;
2697         return res_ref;
2698 }
2699 uint32_t TS_LDKCResult_ReplyChannelRangeDecodeErrorZ_get_err(uint32_t arg) {
2700         LDKCResult_ReplyChannelRangeDecodeErrorZ *val = (LDKCResult_ReplyChannelRangeDecodeErrorZ*)arg;
2701         CHECK(!val->result_ok);
2702         LDKDecodeError err_var = (*val->contents.err);
2703         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2704         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2705         long err_ref = (long)err_var.inner & ~1;
2706         return err_ref;
2707 }
2708 jboolean TS_LDKCResult_GossipTimestampFilterDecodeErrorZ_result_ok(uint32_t arg) {
2709         return ((LDKCResult_GossipTimestampFilterDecodeErrorZ*)arg)->result_ok;
2710 }
2711 uint32_t TS_LDKCResult_GossipTimestampFilterDecodeErrorZ_get_ok(uint32_t arg) {
2712         LDKCResult_GossipTimestampFilterDecodeErrorZ *val = (LDKCResult_GossipTimestampFilterDecodeErrorZ*)arg;
2713         CHECK(val->result_ok);
2714         LDKGossipTimestampFilter res_var = (*val->contents.result);
2715         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2716         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2717         long res_ref = (long)res_var.inner & ~1;
2718         return res_ref;
2719 }
2720 uint32_t TS_LDKCResult_GossipTimestampFilterDecodeErrorZ_get_err(uint32_t arg) {
2721         LDKCResult_GossipTimestampFilterDecodeErrorZ *val = (LDKCResult_GossipTimestampFilterDecodeErrorZ*)arg;
2722         CHECK(!val->result_ok);
2723         LDKDecodeError err_var = (*val->contents.err);
2724         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2725         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2726         long err_ref = (long)err_var.inner & ~1;
2727         return err_ref;
2728 }
2729 jboolean TS_LDKCResult_CVec_u8ZPeerHandleErrorZ_result_ok(uint32_t arg) {
2730         return ((LDKCResult_CVec_u8ZPeerHandleErrorZ*)arg)->result_ok;
2731 }
2732 int8_tArray TS_LDKCResult_CVec_u8ZPeerHandleErrorZ_get_ok(uint32_t arg) {
2733         LDKCResult_CVec_u8ZPeerHandleErrorZ *val = (LDKCResult_CVec_u8ZPeerHandleErrorZ*)arg;
2734         CHECK(val->result_ok);
2735         LDKCVec_u8Z res_var = (*val->contents.result);
2736         int8_tArray res_arr = init_arr(res_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
2737         memcpy((uint8_t*)(res_arr + 4), res_var.data, res_var.datalen);
2738         return res_arr;
2739 }
2740 uint32_t TS_LDKCResult_CVec_u8ZPeerHandleErrorZ_get_err(uint32_t arg) {
2741         LDKCResult_CVec_u8ZPeerHandleErrorZ *val = (LDKCResult_CVec_u8ZPeerHandleErrorZ*)arg;
2742         CHECK(!val->result_ok);
2743         LDKPeerHandleError err_var = (*val->contents.err);
2744         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2745         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2746         long err_ref = (long)err_var.inner & ~1;
2747         return err_ref;
2748 }
2749 jboolean TS_LDKCResult_NonePeerHandleErrorZ_result_ok(uint32_t arg) {
2750         return ((LDKCResult_NonePeerHandleErrorZ*)arg)->result_ok;
2751 }
2752 void TS_LDKCResult_NonePeerHandleErrorZ_get_ok(uint32_t arg) {
2753         LDKCResult_NonePeerHandleErrorZ *val = (LDKCResult_NonePeerHandleErrorZ*)arg;
2754         CHECK(val->result_ok);
2755         return *val->contents.result;
2756 }
2757 uint32_t TS_LDKCResult_NonePeerHandleErrorZ_get_err(uint32_t arg) {
2758         LDKCResult_NonePeerHandleErrorZ *val = (LDKCResult_NonePeerHandleErrorZ*)arg;
2759         CHECK(!val->result_ok);
2760         LDKPeerHandleError err_var = (*val->contents.err);
2761         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2762         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2763         long err_ref = (long)err_var.inner & ~1;
2764         return err_ref;
2765 }
2766 jboolean TS_LDKCResult_boolPeerHandleErrorZ_result_ok(uint32_t arg) {
2767         return ((LDKCResult_boolPeerHandleErrorZ*)arg)->result_ok;
2768 }
2769 jboolean TS_LDKCResult_boolPeerHandleErrorZ_get_ok(uint32_t arg) {
2770         LDKCResult_boolPeerHandleErrorZ *val = (LDKCResult_boolPeerHandleErrorZ*)arg;
2771         CHECK(val->result_ok);
2772         return *val->contents.result;
2773 }
2774 uint32_t TS_LDKCResult_boolPeerHandleErrorZ_get_err(uint32_t arg) {
2775         LDKCResult_boolPeerHandleErrorZ *val = (LDKCResult_boolPeerHandleErrorZ*)arg;
2776         CHECK(!val->result_ok);
2777         LDKPeerHandleError err_var = (*val->contents.err);
2778         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2779         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2780         long err_ref = (long)err_var.inner & ~1;
2781         return err_ref;
2782 }
2783 jboolean TS_LDKCResult_SecretKeySecpErrorZ_result_ok(uint32_t arg) {
2784         return ((LDKCResult_SecretKeySecpErrorZ*)arg)->result_ok;
2785 }
2786 int8_tArray TS_LDKCResult_SecretKeySecpErrorZ_get_ok(uint32_t arg) {
2787         LDKCResult_SecretKeySecpErrorZ *val = (LDKCResult_SecretKeySecpErrorZ*)arg;
2788         CHECK(val->result_ok);
2789         int8_tArray res_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
2790         memcpy((uint8_t*)(res_arr + 4), (*val->contents.result).bytes, 32);
2791         return res_arr;
2792 }
2793 uint32_t TS_LDKCResult_SecretKeySecpErrorZ_get_err(uint32_t arg) {
2794         LDKCResult_SecretKeySecpErrorZ *val = (LDKCResult_SecretKeySecpErrorZ*)arg;
2795         CHECK(!val->result_ok);
2796         uint32_t err_conv = LDKSecp256k1Error_to_js((*val->contents.err));
2797         return err_conv;
2798 }
2799 jboolean TS_LDKCResult_PublicKeySecpErrorZ_result_ok(uint32_t arg) {
2800         return ((LDKCResult_PublicKeySecpErrorZ*)arg)->result_ok;
2801 }
2802 int8_tArray TS_LDKCResult_PublicKeySecpErrorZ_get_ok(uint32_t arg) {
2803         LDKCResult_PublicKeySecpErrorZ *val = (LDKCResult_PublicKeySecpErrorZ*)arg;
2804         CHECK(val->result_ok);
2805         int8_tArray res_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
2806         memcpy((uint8_t*)(res_arr + 4), (*val->contents.result).compressed_form, 33);
2807         return res_arr;
2808 }
2809 uint32_t TS_LDKCResult_PublicKeySecpErrorZ_get_err(uint32_t arg) {
2810         LDKCResult_PublicKeySecpErrorZ *val = (LDKCResult_PublicKeySecpErrorZ*)arg;
2811         CHECK(!val->result_ok);
2812         uint32_t err_conv = LDKSecp256k1Error_to_js((*val->contents.err));
2813         return err_conv;
2814 }
2815 jboolean TS_LDKCResult_TxCreationKeysSecpErrorZ_result_ok(uint32_t arg) {
2816         return ((LDKCResult_TxCreationKeysSecpErrorZ*)arg)->result_ok;
2817 }
2818 uint32_t TS_LDKCResult_TxCreationKeysSecpErrorZ_get_ok(uint32_t arg) {
2819         LDKCResult_TxCreationKeysSecpErrorZ *val = (LDKCResult_TxCreationKeysSecpErrorZ*)arg;
2820         CHECK(val->result_ok);
2821         LDKTxCreationKeys res_var = (*val->contents.result);
2822         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2823         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2824         long res_ref = (long)res_var.inner & ~1;
2825         return res_ref;
2826 }
2827 uint32_t TS_LDKCResult_TxCreationKeysSecpErrorZ_get_err(uint32_t arg) {
2828         LDKCResult_TxCreationKeysSecpErrorZ *val = (LDKCResult_TxCreationKeysSecpErrorZ*)arg;
2829         CHECK(!val->result_ok);
2830         uint32_t err_conv = LDKSecp256k1Error_to_js((*val->contents.err));
2831         return err_conv;
2832 }
2833 jboolean TS_LDKCResult_TrustedCommitmentTransactionNoneZ_result_ok(uint32_t arg) {
2834         return ((LDKCResult_TrustedCommitmentTransactionNoneZ*)arg)->result_ok;
2835 }
2836 uint32_t TS_LDKCResult_TrustedCommitmentTransactionNoneZ_get_ok(uint32_t arg) {
2837         LDKCResult_TrustedCommitmentTransactionNoneZ *val = (LDKCResult_TrustedCommitmentTransactionNoneZ*)arg;
2838         CHECK(val->result_ok);
2839         LDKTrustedCommitmentTransaction res_var = (*val->contents.result);
2840         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2841         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2842         long res_ref = (long)res_var.inner & ~1;
2843         return res_ref;
2844 }
2845 void TS_LDKCResult_TrustedCommitmentTransactionNoneZ_get_err(uint32_t arg) {
2846         LDKCResult_TrustedCommitmentTransactionNoneZ *val = (LDKCResult_TrustedCommitmentTransactionNoneZ*)arg;
2847         CHECK(!val->result_ok);
2848         return *val->contents.err;
2849 }
2850 uint32_t TS_LDKCVec_RouteHopZ_new(uint32_tArray elems) {
2851         LDKCVec_RouteHopZ *ret = MALLOC(sizeof(LDKCVec_RouteHopZ), "LDKCVec_RouteHopZ");
2852         ret->datalen = *((uint32_t*)elems);
2853         if (ret->datalen == 0) {
2854                 ret->data = NULL;
2855         } else {
2856                 ret->data = MALLOC(sizeof(LDKRouteHop) * ret->datalen, "LDKCVec_RouteHopZ Data");
2857                 uint32_t *java_elems = (uint32_t*)(elems + 4);
2858                 for (size_t i = 0; i < ret->datalen; i++) {
2859                         uint32_t arr_elem = java_elems[i];
2860                         LDKRouteHop arr_elem_conv;
2861                         arr_elem_conv.inner = (void*)(arr_elem & (~1));
2862                         arr_elem_conv.is_owned = (arr_elem & 1) || (arr_elem == 0);
2863                         if (arr_elem_conv.inner != NULL)
2864                                 arr_elem_conv = RouteHop_clone(&arr_elem_conv);
2865                         ret->data[i] = arr_elem_conv;
2866                 }
2867         }
2868         return (long)ret;
2869 }
2870 static inline LDKCVec_RouteHopZ CVec_RouteHopZ_clone(const LDKCVec_RouteHopZ *orig) {
2871         LDKCVec_RouteHopZ ret = { .data = MALLOC(sizeof(LDKRouteHop) * orig->datalen, "LDKCVec_RouteHopZ clone bytes"), .datalen = orig->datalen };
2872         for (size_t i = 0; i < ret.datalen; i++) {
2873                 ret.data[i] = RouteHop_clone(&orig->data[i]);
2874         }
2875         return ret;
2876 }
2877 static inline LDKCVec_CVec_RouteHopZZ CVec_CVec_RouteHopZZ_clone(const LDKCVec_CVec_RouteHopZZ *orig) {
2878         LDKCVec_CVec_RouteHopZZ ret = { .data = MALLOC(sizeof(LDKCVec_RouteHopZ) * orig->datalen, "LDKCVec_CVec_RouteHopZZ clone bytes"), .datalen = orig->datalen };
2879         for (size_t i = 0; i < ret.datalen; i++) {
2880                 ret.data[i] = CVec_RouteHopZ_clone(&orig->data[i]);
2881         }
2882         return ret;
2883 }
2884 jboolean TS_LDKCResult_RouteDecodeErrorZ_result_ok(uint32_t arg) {
2885         return ((LDKCResult_RouteDecodeErrorZ*)arg)->result_ok;
2886 }
2887 uint32_t TS_LDKCResult_RouteDecodeErrorZ_get_ok(uint32_t arg) {
2888         LDKCResult_RouteDecodeErrorZ *val = (LDKCResult_RouteDecodeErrorZ*)arg;
2889         CHECK(val->result_ok);
2890         LDKRoute res_var = (*val->contents.result);
2891         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2892         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2893         long res_ref = (long)res_var.inner & ~1;
2894         return res_ref;
2895 }
2896 uint32_t TS_LDKCResult_RouteDecodeErrorZ_get_err(uint32_t arg) {
2897         LDKCResult_RouteDecodeErrorZ *val = (LDKCResult_RouteDecodeErrorZ*)arg;
2898         CHECK(!val->result_ok);
2899         LDKDecodeError err_var = (*val->contents.err);
2900         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2901         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2902         long err_ref = (long)err_var.inner & ~1;
2903         return err_ref;
2904 }
2905 uint32_t TS_LDKCVec_RouteHintZ_new(uint32_tArray elems) {
2906         LDKCVec_RouteHintZ *ret = MALLOC(sizeof(LDKCVec_RouteHintZ), "LDKCVec_RouteHintZ");
2907         ret->datalen = *((uint32_t*)elems);
2908         if (ret->datalen == 0) {
2909                 ret->data = NULL;
2910         } else {
2911                 ret->data = MALLOC(sizeof(LDKRouteHint) * ret->datalen, "LDKCVec_RouteHintZ Data");
2912                 uint32_t *java_elems = (uint32_t*)(elems + 4);
2913                 for (size_t i = 0; i < ret->datalen; i++) {
2914                         uint32_t arr_elem = java_elems[i];
2915                         LDKRouteHint arr_elem_conv;
2916                         arr_elem_conv.inner = (void*)(arr_elem & (~1));
2917                         arr_elem_conv.is_owned = (arr_elem & 1) || (arr_elem == 0);
2918                         if (arr_elem_conv.inner != NULL)
2919                                 arr_elem_conv = RouteHint_clone(&arr_elem_conv);
2920                         ret->data[i] = arr_elem_conv;
2921                 }
2922         }
2923         return (long)ret;
2924 }
2925 static inline LDKCVec_RouteHintZ CVec_RouteHintZ_clone(const LDKCVec_RouteHintZ *orig) {
2926         LDKCVec_RouteHintZ ret = { .data = MALLOC(sizeof(LDKRouteHint) * orig->datalen, "LDKCVec_RouteHintZ clone bytes"), .datalen = orig->datalen };
2927         for (size_t i = 0; i < ret.datalen; i++) {
2928                 ret.data[i] = RouteHint_clone(&orig->data[i]);
2929         }
2930         return ret;
2931 }
2932 jboolean TS_LDKCResult_RouteLightningErrorZ_result_ok(uint32_t arg) {
2933         return ((LDKCResult_RouteLightningErrorZ*)arg)->result_ok;
2934 }
2935 uint32_t TS_LDKCResult_RouteLightningErrorZ_get_ok(uint32_t arg) {
2936         LDKCResult_RouteLightningErrorZ *val = (LDKCResult_RouteLightningErrorZ*)arg;
2937         CHECK(val->result_ok);
2938         LDKRoute res_var = (*val->contents.result);
2939         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2940         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2941         long res_ref = (long)res_var.inner & ~1;
2942         return res_ref;
2943 }
2944 uint32_t TS_LDKCResult_RouteLightningErrorZ_get_err(uint32_t arg) {
2945         LDKCResult_RouteLightningErrorZ *val = (LDKCResult_RouteLightningErrorZ*)arg;
2946         CHECK(!val->result_ok);
2947         LDKLightningError err_var = (*val->contents.err);
2948         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2949         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2950         long err_ref = (long)err_var.inner & ~1;
2951         return err_ref;
2952 }
2953 jboolean TS_LDKCResult_RoutingFeesDecodeErrorZ_result_ok(uint32_t arg) {
2954         return ((LDKCResult_RoutingFeesDecodeErrorZ*)arg)->result_ok;
2955 }
2956 uint32_t TS_LDKCResult_RoutingFeesDecodeErrorZ_get_ok(uint32_t arg) {
2957         LDKCResult_RoutingFeesDecodeErrorZ *val = (LDKCResult_RoutingFeesDecodeErrorZ*)arg;
2958         CHECK(val->result_ok);
2959         LDKRoutingFees res_var = (*val->contents.result);
2960         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2961         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2962         long res_ref = (long)res_var.inner & ~1;
2963         return res_ref;
2964 }
2965 uint32_t TS_LDKCResult_RoutingFeesDecodeErrorZ_get_err(uint32_t arg) {
2966         LDKCResult_RoutingFeesDecodeErrorZ *val = (LDKCResult_RoutingFeesDecodeErrorZ*)arg;
2967         CHECK(!val->result_ok);
2968         LDKDecodeError err_var = (*val->contents.err);
2969         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2970         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2971         long err_ref = (long)err_var.inner & ~1;
2972         return err_ref;
2973 }
2974 jboolean TS_LDKCResult_NodeAnnouncementInfoDecodeErrorZ_result_ok(uint32_t arg) {
2975         return ((LDKCResult_NodeAnnouncementInfoDecodeErrorZ*)arg)->result_ok;
2976 }
2977 uint32_t TS_LDKCResult_NodeAnnouncementInfoDecodeErrorZ_get_ok(uint32_t arg) {
2978         LDKCResult_NodeAnnouncementInfoDecodeErrorZ *val = (LDKCResult_NodeAnnouncementInfoDecodeErrorZ*)arg;
2979         CHECK(val->result_ok);
2980         LDKNodeAnnouncementInfo res_var = (*val->contents.result);
2981         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2982         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2983         long res_ref = (long)res_var.inner & ~1;
2984         return res_ref;
2985 }
2986 uint32_t TS_LDKCResult_NodeAnnouncementInfoDecodeErrorZ_get_err(uint32_t arg) {
2987         LDKCResult_NodeAnnouncementInfoDecodeErrorZ *val = (LDKCResult_NodeAnnouncementInfoDecodeErrorZ*)arg;
2988         CHECK(!val->result_ok);
2989         LDKDecodeError err_var = (*val->contents.err);
2990         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2991         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2992         long err_ref = (long)err_var.inner & ~1;
2993         return err_ref;
2994 }
2995 jboolean TS_LDKCResult_NodeInfoDecodeErrorZ_result_ok(uint32_t arg) {
2996         return ((LDKCResult_NodeInfoDecodeErrorZ*)arg)->result_ok;
2997 }
2998 uint32_t TS_LDKCResult_NodeInfoDecodeErrorZ_get_ok(uint32_t arg) {
2999         LDKCResult_NodeInfoDecodeErrorZ *val = (LDKCResult_NodeInfoDecodeErrorZ*)arg;
3000         CHECK(val->result_ok);
3001         LDKNodeInfo res_var = (*val->contents.result);
3002         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3003         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3004         long res_ref = (long)res_var.inner & ~1;
3005         return res_ref;
3006 }
3007 uint32_t TS_LDKCResult_NodeInfoDecodeErrorZ_get_err(uint32_t arg) {
3008         LDKCResult_NodeInfoDecodeErrorZ *val = (LDKCResult_NodeInfoDecodeErrorZ*)arg;
3009         CHECK(!val->result_ok);
3010         LDKDecodeError err_var = (*val->contents.err);
3011         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3012         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3013         long err_ref = (long)err_var.inner & ~1;
3014         return err_ref;
3015 }
3016 jboolean TS_LDKCResult_NetworkGraphDecodeErrorZ_result_ok(uint32_t arg) {
3017         return ((LDKCResult_NetworkGraphDecodeErrorZ*)arg)->result_ok;
3018 }
3019 uint32_t TS_LDKCResult_NetworkGraphDecodeErrorZ_get_ok(uint32_t arg) {
3020         LDKCResult_NetworkGraphDecodeErrorZ *val = (LDKCResult_NetworkGraphDecodeErrorZ*)arg;
3021         CHECK(val->result_ok);
3022         LDKNetworkGraph res_var = (*val->contents.result);
3023         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3024         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3025         long res_ref = (long)res_var.inner & ~1;
3026         return res_ref;
3027 }
3028 uint32_t TS_LDKCResult_NetworkGraphDecodeErrorZ_get_err(uint32_t arg) {
3029         LDKCResult_NetworkGraphDecodeErrorZ *val = (LDKCResult_NetworkGraphDecodeErrorZ*)arg;
3030         CHECK(!val->result_ok);
3031         LDKDecodeError err_var = (*val->contents.err);
3032         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3033         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3034         long err_ref = (long)err_var.inner & ~1;
3035         return err_ref;
3036 }
3037 typedef struct LDKMessageSendEventsProvider_JCalls {
3038         atomic_size_t refcnt;
3039         uint32_t 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                 js_free(j_calls->get_and_clear_pending_msg_events_meth);
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         uint32_tArray arg = js_invoke_function_0(j_calls->get_and_clear_pending_msg_events_meth);
3051         LDKCVec_MessageSendEventZ arg_constr;
3052         arg_constr.datalen = *((uint32_t*)arg);
3053         if (arg_constr.datalen > 0)
3054                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKMessageSendEvent), "LDKCVec_MessageSendEventZ Elements");
3055         else
3056                 arg_constr.data = NULL;
3057         uint32_t* arg_vals = (uint32_t*)(arg + 4);
3058         for (size_t s = 0; s < arg_constr.datalen; s++) {
3059                 uint32_t arr_conv_18 = arg_vals[s];
3060                 LDKMessageSendEvent arr_conv_18_conv = *(LDKMessageSendEvent*)arr_conv_18;
3061                 FREE((void*)arr_conv_18);
3062                 arg_constr.data[s] = arr_conv_18_conv;
3063         }
3064         return arg_constr;
3065 }
3066 static void* LDKMessageSendEventsProvider_JCalls_clone(const void* this_arg) {
3067         LDKMessageSendEventsProvider_JCalls *j_calls = (LDKMessageSendEventsProvider_JCalls*) this_arg;
3068         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
3069         return (void*) this_arg;
3070 }
3071 static inline LDKMessageSendEventsProvider LDKMessageSendEventsProvider_init (/*TODO: JS Object Reference */void* o) {
3072         LDKMessageSendEventsProvider_JCalls *calls = MALLOC(sizeof(LDKMessageSendEventsProvider_JCalls), "LDKMessageSendEventsProvider_JCalls");
3073         atomic_init(&calls->refcnt, 1);
3074         //TODO: Assign calls->o from o
3075
3076         LDKMessageSendEventsProvider ret = {
3077                 .this_arg = (void*) calls,
3078                 .get_and_clear_pending_msg_events = get_and_clear_pending_msg_events_jcall,
3079                 .free = LDKMessageSendEventsProvider_JCalls_free,
3080         };
3081         return ret;
3082 }
3083 long TS_LDKMessageSendEventsProvider_new (/*TODO: JS Object Reference */void* o) {
3084         LDKMessageSendEventsProvider *res_ptr = MALLOC(sizeof(LDKMessageSendEventsProvider), "LDKMessageSendEventsProvider");
3085         *res_ptr = LDKMessageSendEventsProvider_init(o);
3086         return (long)res_ptr;
3087 }
3088 uint32_tArray TS_MessageSendEventsProvider_get_and_clear_pending_msg_events(uint32_t this_arg) {
3089         LDKMessageSendEventsProvider* this_arg_conv = (LDKMessageSendEventsProvider*)this_arg;
3090         LDKCVec_MessageSendEventZ ret_var = (this_arg_conv->get_and_clear_pending_msg_events)(this_arg_conv->this_arg);
3091         uint32_tArray ret_arr = init_arr(ret_var.datalen, sizeof(uint32_t), "Native uint32_tArray Bytes");
3092         uint32_t *ret_arr_ptr = (uint32_t*)(ret_arr + 4);
3093         for (size_t s = 0; s < ret_var.datalen; s++) {
3094                 LDKMessageSendEvent *arr_conv_18_copy = MALLOC(sizeof(LDKMessageSendEvent), "LDKMessageSendEvent");
3095                 *arr_conv_18_copy = MessageSendEvent_clone(&ret_var.data[s]);
3096                 long arr_conv_18_ref = (long)arr_conv_18_copy;
3097                 ret_arr_ptr[s] = arr_conv_18_ref;
3098         }
3099         FREE(ret_var.data);
3100         return ret_arr;
3101 }
3102
3103 typedef struct LDKEventsProvider_JCalls {
3104         atomic_size_t refcnt;
3105         uint32_t get_and_clear_pending_events_meth;
3106 } LDKEventsProvider_JCalls;
3107 static void LDKEventsProvider_JCalls_free(void* this_arg) {
3108         LDKEventsProvider_JCalls *j_calls = (LDKEventsProvider_JCalls*) this_arg;
3109         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
3110                 js_free(j_calls->get_and_clear_pending_events_meth);
3111                 FREE(j_calls);
3112         }
3113 }
3114 LDKCVec_EventZ get_and_clear_pending_events_jcall(const void* this_arg) {
3115         LDKEventsProvider_JCalls *j_calls = (LDKEventsProvider_JCalls*) this_arg;
3116         uint32_tArray arg = js_invoke_function_0(j_calls->get_and_clear_pending_events_meth);
3117         LDKCVec_EventZ arg_constr;
3118         arg_constr.datalen = *((uint32_t*)arg);
3119         if (arg_constr.datalen > 0)
3120                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKEvent), "LDKCVec_EventZ Elements");
3121         else
3122                 arg_constr.data = NULL;
3123         uint32_t* arg_vals = (uint32_t*)(arg + 4);
3124         for (size_t h = 0; h < arg_constr.datalen; h++) {
3125                 uint32_t arr_conv_7 = arg_vals[h];
3126                 LDKEvent arr_conv_7_conv = *(LDKEvent*)arr_conv_7;
3127                 FREE((void*)arr_conv_7);
3128                 arg_constr.data[h] = arr_conv_7_conv;
3129         }
3130         return arg_constr;
3131 }
3132 static void* LDKEventsProvider_JCalls_clone(const void* this_arg) {
3133         LDKEventsProvider_JCalls *j_calls = (LDKEventsProvider_JCalls*) this_arg;
3134         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
3135         return (void*) this_arg;
3136 }
3137 static inline LDKEventsProvider LDKEventsProvider_init (/*TODO: JS Object Reference */void* o) {
3138         LDKEventsProvider_JCalls *calls = MALLOC(sizeof(LDKEventsProvider_JCalls), "LDKEventsProvider_JCalls");
3139         atomic_init(&calls->refcnt, 1);
3140         //TODO: Assign calls->o from o
3141
3142         LDKEventsProvider ret = {
3143                 .this_arg = (void*) calls,
3144                 .get_and_clear_pending_events = get_and_clear_pending_events_jcall,
3145                 .free = LDKEventsProvider_JCalls_free,
3146         };
3147         return ret;
3148 }
3149 long TS_LDKEventsProvider_new (/*TODO: JS Object Reference */void* o) {
3150         LDKEventsProvider *res_ptr = MALLOC(sizeof(LDKEventsProvider), "LDKEventsProvider");
3151         *res_ptr = LDKEventsProvider_init(o);
3152         return (long)res_ptr;
3153 }
3154 uint32_tArray TS_EventsProvider_get_and_clear_pending_events(uint32_t this_arg) {
3155         LDKEventsProvider* this_arg_conv = (LDKEventsProvider*)this_arg;
3156         LDKCVec_EventZ ret_var = (this_arg_conv->get_and_clear_pending_events)(this_arg_conv->this_arg);
3157         uint32_tArray ret_arr = init_arr(ret_var.datalen, sizeof(uint32_t), "Native uint32_tArray Bytes");
3158         uint32_t *ret_arr_ptr = (uint32_t*)(ret_arr + 4);
3159         for (size_t h = 0; h < ret_var.datalen; h++) {
3160                 LDKEvent *arr_conv_7_copy = MALLOC(sizeof(LDKEvent), "LDKEvent");
3161                 *arr_conv_7_copy = Event_clone(&ret_var.data[h]);
3162                 long arr_conv_7_ref = (long)arr_conv_7_copy;
3163                 ret_arr_ptr[h] = arr_conv_7_ref;
3164         }
3165         FREE(ret_var.data);
3166         return ret_arr;
3167 }
3168
3169 typedef struct LDKAccess_JCalls {
3170         atomic_size_t refcnt;
3171         uint32_t get_utxo_meth;
3172 } LDKAccess_JCalls;
3173 static void LDKAccess_JCalls_free(void* this_arg) {
3174         LDKAccess_JCalls *j_calls = (LDKAccess_JCalls*) this_arg;
3175         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
3176                 js_free(j_calls->get_utxo_meth);
3177                 FREE(j_calls);
3178         }
3179 }
3180 LDKCResult_TxOutAccessErrorZ get_utxo_jcall(const void* this_arg, const uint8_t (* genesis_hash)[32], uint64_t short_channel_id) {
3181         LDKAccess_JCalls *j_calls = (LDKAccess_JCalls*) this_arg;
3182         int8_tArray genesis_hash_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
3183         memcpy((uint8_t*)(genesis_hash_arr + 4), *genesis_hash, 32);
3184         LDKCResult_TxOutAccessErrorZ* ret; // TODO: Call get_utxo on j_calls with instance obj, returning a pointer, genesis_hash_arr, short_channel_id);
3185         LDKCResult_TxOutAccessErrorZ ret_conv = *(LDKCResult_TxOutAccessErrorZ*)ret;
3186         FREE((void*)ret);
3187         return ret_conv;
3188 }
3189 static void* LDKAccess_JCalls_clone(const void* this_arg) {
3190         LDKAccess_JCalls *j_calls = (LDKAccess_JCalls*) this_arg;
3191         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
3192         return (void*) this_arg;
3193 }
3194 static inline LDKAccess LDKAccess_init (/*TODO: JS Object Reference */void* o) {
3195         LDKAccess_JCalls *calls = MALLOC(sizeof(LDKAccess_JCalls), "LDKAccess_JCalls");
3196         atomic_init(&calls->refcnt, 1);
3197         //TODO: Assign calls->o from o
3198
3199         LDKAccess ret = {
3200                 .this_arg = (void*) calls,
3201                 .get_utxo = get_utxo_jcall,
3202                 .free = LDKAccess_JCalls_free,
3203         };
3204         return ret;
3205 }
3206 long TS_LDKAccess_new (/*TODO: JS Object Reference */void* o) {
3207         LDKAccess *res_ptr = MALLOC(sizeof(LDKAccess), "LDKAccess");
3208         *res_ptr = LDKAccess_init(o);
3209         return (long)res_ptr;
3210 }
3211 uint32_t TS_Access_get_utxo(uint32_t this_arg, int8_tArray genesis_hash, int64_t short_channel_id) {
3212         LDKAccess* this_arg_conv = (LDKAccess*)this_arg;
3213         unsigned char genesis_hash_arr[32];
3214         CHECK(*((uint32_t*)genesis_hash) == 32);
3215         memcpy(genesis_hash_arr, (uint8_t*)(genesis_hash + 4), 32);
3216         unsigned char (*genesis_hash_ref)[32] = &genesis_hash_arr;
3217         LDKCResult_TxOutAccessErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_TxOutAccessErrorZ), "LDKCResult_TxOutAccessErrorZ");
3218         *ret_conv = (this_arg_conv->get_utxo)(this_arg_conv->this_arg, genesis_hash_ref, short_channel_id);
3219         return (long)ret_conv;
3220 }
3221
3222 typedef struct LDKFilter_JCalls {
3223         atomic_size_t refcnt;
3224         uint32_t register_tx_meth;
3225         uint32_t register_output_meth;
3226 } LDKFilter_JCalls;
3227 static void LDKFilter_JCalls_free(void* this_arg) {
3228         LDKFilter_JCalls *j_calls = (LDKFilter_JCalls*) this_arg;
3229         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
3230                 js_free(j_calls->register_tx_meth);
3231                 js_free(j_calls->register_output_meth);
3232                 FREE(j_calls);
3233         }
3234 }
3235 void register_tx_jcall(const void* this_arg, const uint8_t (* txid)[32], LDKu8slice script_pubkey) {
3236         LDKFilter_JCalls *j_calls = (LDKFilter_JCalls*) this_arg;
3237         int8_tArray txid_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
3238         memcpy((uint8_t*)(txid_arr + 4), *txid, 32);
3239         LDKu8slice script_pubkey_var = script_pubkey;
3240         int8_tArray script_pubkey_arr = init_arr(script_pubkey_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
3241         memcpy((uint8_t*)(script_pubkey_arr + 4), script_pubkey_var.data, script_pubkey_var.datalen);
3242         js_invoke_function_2(j_calls->register_tx_meth, txid_arr, script_pubkey_arr);
3243 }
3244 void register_output_jcall(const void* this_arg, const LDKOutPoint * outpoint, LDKu8slice script_pubkey) {
3245         LDKFilter_JCalls *j_calls = (LDKFilter_JCalls*) this_arg;
3246         LDKOutPoint outpoint_var = *outpoint;
3247         if (outpoint->inner != NULL)
3248                 outpoint_var = OutPoint_clone(outpoint);
3249         CHECK((((long)outpoint_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3250         CHECK((((long)&outpoint_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3251         long outpoint_ref = (long)outpoint_var.inner;
3252         if (outpoint_var.is_owned) {
3253                 outpoint_ref |= 1;
3254         }
3255         LDKu8slice script_pubkey_var = script_pubkey;
3256         int8_tArray script_pubkey_arr = init_arr(script_pubkey_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
3257         memcpy((uint8_t*)(script_pubkey_arr + 4), script_pubkey_var.data, script_pubkey_var.datalen);
3258         js_invoke_function_2(j_calls->register_output_meth, outpoint_ref, script_pubkey_arr);
3259 }
3260 static void* LDKFilter_JCalls_clone(const void* this_arg) {
3261         LDKFilter_JCalls *j_calls = (LDKFilter_JCalls*) this_arg;
3262         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
3263         return (void*) this_arg;
3264 }
3265 static inline LDKFilter LDKFilter_init (/*TODO: JS Object Reference */void* o) {
3266         LDKFilter_JCalls *calls = MALLOC(sizeof(LDKFilter_JCalls), "LDKFilter_JCalls");
3267         atomic_init(&calls->refcnt, 1);
3268         //TODO: Assign calls->o from o
3269
3270         LDKFilter ret = {
3271                 .this_arg = (void*) calls,
3272                 .register_tx = register_tx_jcall,
3273                 .register_output = register_output_jcall,
3274                 .free = LDKFilter_JCalls_free,
3275         };
3276         return ret;
3277 }
3278 long TS_LDKFilter_new (/*TODO: JS Object Reference */void* o) {
3279         LDKFilter *res_ptr = MALLOC(sizeof(LDKFilter), "LDKFilter");
3280         *res_ptr = LDKFilter_init(o);
3281         return (long)res_ptr;
3282 }
3283 void TS_Filter_register_tx(uint32_t this_arg, int8_tArray txid, int8_tArray script_pubkey) {
3284         LDKFilter* this_arg_conv = (LDKFilter*)this_arg;
3285         unsigned char txid_arr[32];
3286         CHECK(*((uint32_t*)txid) == 32);
3287         memcpy(txid_arr, (uint8_t*)(txid + 4), 32);
3288         unsigned char (*txid_ref)[32] = &txid_arr;
3289         LDKu8slice script_pubkey_ref;
3290         script_pubkey_ref.datalen = *((uint32_t*)script_pubkey);
3291         script_pubkey_ref.data = (int8_t*)(script_pubkey + 4);
3292         (this_arg_conv->register_tx)(this_arg_conv->this_arg, txid_ref, script_pubkey_ref);
3293 }
3294
3295 void TS_Filter_register_output(uint32_t this_arg, uint32_t outpoint, int8_tArray script_pubkey) {
3296         LDKFilter* this_arg_conv = (LDKFilter*)this_arg;
3297         LDKOutPoint outpoint_conv;
3298         outpoint_conv.inner = (void*)(outpoint & (~1));
3299         outpoint_conv.is_owned = false;
3300         LDKu8slice script_pubkey_ref;
3301         script_pubkey_ref.datalen = *((uint32_t*)script_pubkey);
3302         script_pubkey_ref.data = (int8_t*)(script_pubkey + 4);
3303         (this_arg_conv->register_output)(this_arg_conv->this_arg, &outpoint_conv, script_pubkey_ref);
3304 }
3305
3306 typedef struct LDKPersist_JCalls {
3307         atomic_size_t refcnt;
3308         uint32_t persist_new_channel_meth;
3309         uint32_t update_persisted_channel_meth;
3310 } LDKPersist_JCalls;
3311 static void LDKPersist_JCalls_free(void* this_arg) {
3312         LDKPersist_JCalls *j_calls = (LDKPersist_JCalls*) this_arg;
3313         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
3314                 js_free(j_calls->persist_new_channel_meth);
3315                 js_free(j_calls->update_persisted_channel_meth);
3316                 FREE(j_calls);
3317         }
3318 }
3319 LDKCResult_NoneChannelMonitorUpdateErrZ persist_new_channel_jcall(const void* this_arg, LDKOutPoint id, const LDKChannelMonitor * data) {
3320         LDKPersist_JCalls *j_calls = (LDKPersist_JCalls*) this_arg;
3321         LDKOutPoint id_var = id;
3322         CHECK((((long)id_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3323         CHECK((((long)&id_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3324         long id_ref = (long)id_var.inner;
3325         if (id_var.is_owned) {
3326                 id_ref |= 1;
3327         }
3328         LDKChannelMonitor data_var = *data;
3329         // Warning: we may need a move here but can't clone!
3330         CHECK((((long)data_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3331         CHECK((((long)&data_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3332         long data_ref = (long)data_var.inner;
3333         if (data_var.is_owned) {
3334                 data_ref |= 1;
3335         }
3336         LDKCResult_NoneChannelMonitorUpdateErrZ* ret; // TODO: Call persist_new_channel on j_calls with instance obj, returning a pointer, id_ref, data_ref);
3337         LDKCResult_NoneChannelMonitorUpdateErrZ ret_conv = *(LDKCResult_NoneChannelMonitorUpdateErrZ*)ret;
3338         FREE((void*)ret);
3339         return ret_conv;
3340 }
3341 LDKCResult_NoneChannelMonitorUpdateErrZ update_persisted_channel_jcall(const void* this_arg, LDKOutPoint id, const LDKChannelMonitorUpdate * update, const LDKChannelMonitor * data) {
3342         LDKPersist_JCalls *j_calls = (LDKPersist_JCalls*) this_arg;
3343         LDKOutPoint id_var = id;
3344         CHECK((((long)id_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3345         CHECK((((long)&id_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3346         long id_ref = (long)id_var.inner;
3347         if (id_var.is_owned) {
3348                 id_ref |= 1;
3349         }
3350         LDKChannelMonitorUpdate update_var = *update;
3351         if (update->inner != NULL)
3352                 update_var = ChannelMonitorUpdate_clone(update);
3353         CHECK((((long)update_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3354         CHECK((((long)&update_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3355         long update_ref = (long)update_var.inner;
3356         if (update_var.is_owned) {
3357                 update_ref |= 1;
3358         }
3359         LDKChannelMonitor data_var = *data;
3360         // Warning: we may need a move here but can't clone!
3361         CHECK((((long)data_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3362         CHECK((((long)&data_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3363         long data_ref = (long)data_var.inner;
3364         if (data_var.is_owned) {
3365                 data_ref |= 1;
3366         }
3367         LDKCResult_NoneChannelMonitorUpdateErrZ* ret; // TODO: Call update_persisted_channel on j_calls with instance obj, returning a pointer, id_ref, update_ref, data_ref);
3368         LDKCResult_NoneChannelMonitorUpdateErrZ ret_conv = *(LDKCResult_NoneChannelMonitorUpdateErrZ*)ret;
3369         FREE((void*)ret);
3370         return ret_conv;
3371 }
3372 static void* LDKPersist_JCalls_clone(const void* this_arg) {
3373         LDKPersist_JCalls *j_calls = (LDKPersist_JCalls*) this_arg;
3374         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
3375         return (void*) this_arg;
3376 }
3377 static inline LDKPersist LDKPersist_init (/*TODO: JS Object Reference */void* o) {
3378         LDKPersist_JCalls *calls = MALLOC(sizeof(LDKPersist_JCalls), "LDKPersist_JCalls");
3379         atomic_init(&calls->refcnt, 1);
3380         //TODO: Assign calls->o from o
3381
3382         LDKPersist ret = {
3383                 .this_arg = (void*) calls,
3384                 .persist_new_channel = persist_new_channel_jcall,
3385                 .update_persisted_channel = update_persisted_channel_jcall,
3386                 .free = LDKPersist_JCalls_free,
3387         };
3388         return ret;
3389 }
3390 long TS_LDKPersist_new (/*TODO: JS Object Reference */void* o) {
3391         LDKPersist *res_ptr = MALLOC(sizeof(LDKPersist), "LDKPersist");
3392         *res_ptr = LDKPersist_init(o);
3393         return (long)res_ptr;
3394 }
3395 uint32_t TS_Persist_persist_new_channel(uint32_t this_arg, uint32_t id, uint32_t data) {
3396         LDKPersist* this_arg_conv = (LDKPersist*)this_arg;
3397         LDKOutPoint id_conv;
3398         id_conv.inner = (void*)(id & (~1));
3399         id_conv.is_owned = (id & 1) || (id == 0);
3400         if (id_conv.inner != NULL)
3401                 id_conv = OutPoint_clone(&id_conv);
3402         LDKChannelMonitor data_conv;
3403         data_conv.inner = (void*)(data & (~1));
3404         data_conv.is_owned = false;
3405         LDKCResult_NoneChannelMonitorUpdateErrZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneChannelMonitorUpdateErrZ), "LDKCResult_NoneChannelMonitorUpdateErrZ");
3406         *ret_conv = (this_arg_conv->persist_new_channel)(this_arg_conv->this_arg, id_conv, &data_conv);
3407         return (long)ret_conv;
3408 }
3409
3410 uint32_t TS_Persist_update_persisted_channel(uint32_t this_arg, uint32_t id, uint32_t update, uint32_t data) {
3411         LDKPersist* this_arg_conv = (LDKPersist*)this_arg;
3412         LDKOutPoint id_conv;
3413         id_conv.inner = (void*)(id & (~1));
3414         id_conv.is_owned = (id & 1) || (id == 0);
3415         if (id_conv.inner != NULL)
3416                 id_conv = OutPoint_clone(&id_conv);
3417         LDKChannelMonitorUpdate update_conv;
3418         update_conv.inner = (void*)(update & (~1));
3419         update_conv.is_owned = false;
3420         LDKChannelMonitor data_conv;
3421         data_conv.inner = (void*)(data & (~1));
3422         data_conv.is_owned = false;
3423         LDKCResult_NoneChannelMonitorUpdateErrZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneChannelMonitorUpdateErrZ), "LDKCResult_NoneChannelMonitorUpdateErrZ");
3424         *ret_conv = (this_arg_conv->update_persisted_channel)(this_arg_conv->this_arg, id_conv, &update_conv, &data_conv);
3425         return (long)ret_conv;
3426 }
3427
3428 typedef struct LDKChannelMessageHandler_JCalls {
3429         atomic_size_t refcnt;
3430         LDKMessageSendEventsProvider_JCalls* MessageSendEventsProvider;
3431         uint32_t handle_open_channel_meth;
3432         uint32_t handle_accept_channel_meth;
3433         uint32_t handle_funding_created_meth;
3434         uint32_t handle_funding_signed_meth;
3435         uint32_t handle_funding_locked_meth;
3436         uint32_t handle_shutdown_meth;
3437         uint32_t handle_closing_signed_meth;
3438         uint32_t handle_update_add_htlc_meth;
3439         uint32_t handle_update_fulfill_htlc_meth;
3440         uint32_t handle_update_fail_htlc_meth;
3441         uint32_t handle_update_fail_malformed_htlc_meth;
3442         uint32_t handle_commitment_signed_meth;
3443         uint32_t handle_revoke_and_ack_meth;
3444         uint32_t handle_update_fee_meth;
3445         uint32_t handle_announcement_signatures_meth;
3446         uint32_t peer_disconnected_meth;
3447         uint32_t peer_connected_meth;
3448         uint32_t handle_channel_reestablish_meth;
3449         uint32_t handle_error_meth;
3450 } LDKChannelMessageHandler_JCalls;
3451 static void LDKChannelMessageHandler_JCalls_free(void* this_arg) {
3452         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3453         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
3454                 js_free(j_calls->handle_open_channel_meth);
3455                 js_free(j_calls->handle_accept_channel_meth);
3456                 js_free(j_calls->handle_funding_created_meth);
3457                 js_free(j_calls->handle_funding_signed_meth);
3458                 js_free(j_calls->handle_funding_locked_meth);
3459                 js_free(j_calls->handle_shutdown_meth);
3460                 js_free(j_calls->handle_closing_signed_meth);
3461                 js_free(j_calls->handle_update_add_htlc_meth);
3462                 js_free(j_calls->handle_update_fulfill_htlc_meth);
3463                 js_free(j_calls->handle_update_fail_htlc_meth);
3464                 js_free(j_calls->handle_update_fail_malformed_htlc_meth);
3465                 js_free(j_calls->handle_commitment_signed_meth);
3466                 js_free(j_calls->handle_revoke_and_ack_meth);
3467                 js_free(j_calls->handle_update_fee_meth);
3468                 js_free(j_calls->handle_announcement_signatures_meth);
3469                 js_free(j_calls->peer_disconnected_meth);
3470                 js_free(j_calls->peer_connected_meth);
3471                 js_free(j_calls->handle_channel_reestablish_meth);
3472                 js_free(j_calls->handle_error_meth);
3473                 FREE(j_calls);
3474         }
3475 }
3476 void handle_open_channel_jcall(const void* this_arg, LDKPublicKey their_node_id, LDKInitFeatures their_features, const LDKOpenChannel * msg) {
3477         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3478         int8_tArray their_node_id_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
3479         memcpy((uint8_t*)(their_node_id_arr + 4), their_node_id.compressed_form, 33);
3480         LDKInitFeatures their_features_var = their_features;
3481         CHECK((((long)their_features_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3482         CHECK((((long)&their_features_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3483         long their_features_ref = (long)their_features_var.inner;
3484         if (their_features_var.is_owned) {
3485                 their_features_ref |= 1;
3486         }
3487         LDKOpenChannel msg_var = *msg;
3488         if (msg->inner != NULL)
3489                 msg_var = OpenChannel_clone(msg);
3490         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3491         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3492         long msg_ref = (long)msg_var.inner;
3493         if (msg_var.is_owned) {
3494                 msg_ref |= 1;
3495         }
3496         js_invoke_function_3(j_calls->handle_open_channel_meth, their_node_id_arr, their_features_ref, msg_ref);
3497 }
3498 void handle_accept_channel_jcall(const void* this_arg, LDKPublicKey their_node_id, LDKInitFeatures their_features, const LDKAcceptChannel * msg) {
3499         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3500         int8_tArray their_node_id_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
3501         memcpy((uint8_t*)(their_node_id_arr + 4), their_node_id.compressed_form, 33);
3502         LDKInitFeatures their_features_var = their_features;
3503         CHECK((((long)their_features_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3504         CHECK((((long)&their_features_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3505         long their_features_ref = (long)their_features_var.inner;
3506         if (their_features_var.is_owned) {
3507                 their_features_ref |= 1;
3508         }
3509         LDKAcceptChannel msg_var = *msg;
3510         if (msg->inner != NULL)
3511                 msg_var = AcceptChannel_clone(msg);
3512         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3513         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3514         long msg_ref = (long)msg_var.inner;
3515         if (msg_var.is_owned) {
3516                 msg_ref |= 1;
3517         }
3518         js_invoke_function_3(j_calls->handle_accept_channel_meth, their_node_id_arr, their_features_ref, msg_ref);
3519 }
3520 void handle_funding_created_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKFundingCreated * msg) {
3521         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3522         int8_tArray their_node_id_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
3523         memcpy((uint8_t*)(their_node_id_arr + 4), their_node_id.compressed_form, 33);
3524         LDKFundingCreated msg_var = *msg;
3525         if (msg->inner != NULL)
3526                 msg_var = FundingCreated_clone(msg);
3527         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3528         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3529         long msg_ref = (long)msg_var.inner;
3530         if (msg_var.is_owned) {
3531                 msg_ref |= 1;
3532         }
3533         js_invoke_function_2(j_calls->handle_funding_created_meth, their_node_id_arr, msg_ref);
3534 }
3535 void handle_funding_signed_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKFundingSigned * msg) {
3536         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3537         int8_tArray their_node_id_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
3538         memcpy((uint8_t*)(their_node_id_arr + 4), their_node_id.compressed_form, 33);
3539         LDKFundingSigned msg_var = *msg;
3540         if (msg->inner != NULL)
3541                 msg_var = FundingSigned_clone(msg);
3542         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3543         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3544         long msg_ref = (long)msg_var.inner;
3545         if (msg_var.is_owned) {
3546                 msg_ref |= 1;
3547         }
3548         js_invoke_function_2(j_calls->handle_funding_signed_meth, their_node_id_arr, msg_ref);
3549 }
3550 void handle_funding_locked_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKFundingLocked * msg) {
3551         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3552         int8_tArray their_node_id_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
3553         memcpy((uint8_t*)(their_node_id_arr + 4), their_node_id.compressed_form, 33);
3554         LDKFundingLocked msg_var = *msg;
3555         if (msg->inner != NULL)
3556                 msg_var = FundingLocked_clone(msg);
3557         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3558         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3559         long msg_ref = (long)msg_var.inner;
3560         if (msg_var.is_owned) {
3561                 msg_ref |= 1;
3562         }
3563         js_invoke_function_2(j_calls->handle_funding_locked_meth, their_node_id_arr, msg_ref);
3564 }
3565 void handle_shutdown_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKShutdown * msg) {
3566         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3567         int8_tArray their_node_id_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
3568         memcpy((uint8_t*)(their_node_id_arr + 4), their_node_id.compressed_form, 33);
3569         LDKShutdown msg_var = *msg;
3570         if (msg->inner != NULL)
3571                 msg_var = Shutdown_clone(msg);
3572         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3573         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3574         long msg_ref = (long)msg_var.inner;
3575         if (msg_var.is_owned) {
3576                 msg_ref |= 1;
3577         }
3578         js_invoke_function_2(j_calls->handle_shutdown_meth, their_node_id_arr, msg_ref);
3579 }
3580 void handle_closing_signed_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKClosingSigned * msg) {
3581         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3582         int8_tArray their_node_id_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
3583         memcpy((uint8_t*)(their_node_id_arr + 4), their_node_id.compressed_form, 33);
3584         LDKClosingSigned msg_var = *msg;
3585         if (msg->inner != NULL)
3586                 msg_var = ClosingSigned_clone(msg);
3587         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3588         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3589         long msg_ref = (long)msg_var.inner;
3590         if (msg_var.is_owned) {
3591                 msg_ref |= 1;
3592         }
3593         js_invoke_function_2(j_calls->handle_closing_signed_meth, their_node_id_arr, msg_ref);
3594 }
3595 void handle_update_add_htlc_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKUpdateAddHTLC * msg) {
3596         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3597         int8_tArray their_node_id_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
3598         memcpy((uint8_t*)(their_node_id_arr + 4), their_node_id.compressed_form, 33);
3599         LDKUpdateAddHTLC msg_var = *msg;
3600         if (msg->inner != NULL)
3601                 msg_var = UpdateAddHTLC_clone(msg);
3602         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3603         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3604         long msg_ref = (long)msg_var.inner;
3605         if (msg_var.is_owned) {
3606                 msg_ref |= 1;
3607         }
3608         js_invoke_function_2(j_calls->handle_update_add_htlc_meth, 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 = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
3613         memcpy((uint8_t*)(their_node_id_arr + 4), 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         js_invoke_function_2(j_calls->handle_update_fulfill_htlc_meth, their_node_id_arr, msg_ref);
3624 }
3625 void handle_update_fail_htlc_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKUpdateFailHTLC * msg) {
3626         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3627         int8_tArray their_node_id_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
3628         memcpy((uint8_t*)(their_node_id_arr + 4), their_node_id.compressed_form, 33);
3629         LDKUpdateFailHTLC msg_var = *msg;
3630         if (msg->inner != NULL)
3631                 msg_var = UpdateFailHTLC_clone(msg);
3632         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3633         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3634         long msg_ref = (long)msg_var.inner;
3635         if (msg_var.is_owned) {
3636                 msg_ref |= 1;
3637         }
3638         js_invoke_function_2(j_calls->handle_update_fail_htlc_meth, their_node_id_arr, msg_ref);
3639 }
3640 void handle_update_fail_malformed_htlc_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKUpdateFailMalformedHTLC * msg) {
3641         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3642         int8_tArray their_node_id_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
3643         memcpy((uint8_t*)(their_node_id_arr + 4), their_node_id.compressed_form, 33);
3644         LDKUpdateFailMalformedHTLC msg_var = *msg;
3645         if (msg->inner != NULL)
3646                 msg_var = UpdateFailMalformedHTLC_clone(msg);
3647         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3648         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3649         long msg_ref = (long)msg_var.inner;
3650         if (msg_var.is_owned) {
3651                 msg_ref |= 1;
3652         }
3653         js_invoke_function_2(j_calls->handle_update_fail_malformed_htlc_meth, their_node_id_arr, msg_ref);
3654 }
3655 void handle_commitment_signed_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKCommitmentSigned * msg) {
3656         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3657         int8_tArray their_node_id_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
3658         memcpy((uint8_t*)(their_node_id_arr + 4), their_node_id.compressed_form, 33);
3659         LDKCommitmentSigned msg_var = *msg;
3660         if (msg->inner != NULL)
3661                 msg_var = CommitmentSigned_clone(msg);
3662         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3663         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3664         long msg_ref = (long)msg_var.inner;
3665         if (msg_var.is_owned) {
3666                 msg_ref |= 1;
3667         }
3668         js_invoke_function_2(j_calls->handle_commitment_signed_meth, their_node_id_arr, msg_ref);
3669 }
3670 void handle_revoke_and_ack_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKRevokeAndACK * msg) {
3671         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3672         int8_tArray their_node_id_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
3673         memcpy((uint8_t*)(their_node_id_arr + 4), their_node_id.compressed_form, 33);
3674         LDKRevokeAndACK msg_var = *msg;
3675         if (msg->inner != NULL)
3676                 msg_var = RevokeAndACK_clone(msg);
3677         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3678         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3679         long msg_ref = (long)msg_var.inner;
3680         if (msg_var.is_owned) {
3681                 msg_ref |= 1;
3682         }
3683         js_invoke_function_2(j_calls->handle_revoke_and_ack_meth, their_node_id_arr, msg_ref);
3684 }
3685 void handle_update_fee_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKUpdateFee * msg) {
3686         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3687         int8_tArray their_node_id_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
3688         memcpy((uint8_t*)(their_node_id_arr + 4), their_node_id.compressed_form, 33);
3689         LDKUpdateFee msg_var = *msg;
3690         if (msg->inner != NULL)
3691                 msg_var = UpdateFee_clone(msg);
3692         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3693         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3694         long msg_ref = (long)msg_var.inner;
3695         if (msg_var.is_owned) {
3696                 msg_ref |= 1;
3697         }
3698         js_invoke_function_2(j_calls->handle_update_fee_meth, their_node_id_arr, msg_ref);
3699 }
3700 void handle_announcement_signatures_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKAnnouncementSignatures * msg) {
3701         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3702         int8_tArray their_node_id_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
3703         memcpy((uint8_t*)(their_node_id_arr + 4), their_node_id.compressed_form, 33);
3704         LDKAnnouncementSignatures msg_var = *msg;
3705         if (msg->inner != NULL)
3706                 msg_var = AnnouncementSignatures_clone(msg);
3707         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3708         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3709         long msg_ref = (long)msg_var.inner;
3710         if (msg_var.is_owned) {
3711                 msg_ref |= 1;
3712         }
3713         js_invoke_function_2(j_calls->handle_announcement_signatures_meth, their_node_id_arr, msg_ref);
3714 }
3715 void peer_disconnected_jcall(const void* this_arg, LDKPublicKey their_node_id, bool no_connection_possible) {
3716         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3717         int8_tArray their_node_id_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
3718         memcpy((uint8_t*)(their_node_id_arr + 4), their_node_id.compressed_form, 33);
3719         js_invoke_function_2(j_calls->peer_disconnected_meth, their_node_id_arr, no_connection_possible);
3720 }
3721 void peer_connected_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKInit * msg) {
3722         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3723         int8_tArray their_node_id_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
3724         memcpy((uint8_t*)(their_node_id_arr + 4), their_node_id.compressed_form, 33);
3725         LDKInit msg_var = *msg;
3726         if (msg->inner != NULL)
3727                 msg_var = Init_clone(msg);
3728         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3729         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3730         long msg_ref = (long)msg_var.inner;
3731         if (msg_var.is_owned) {
3732                 msg_ref |= 1;
3733         }
3734         js_invoke_function_2(j_calls->peer_connected_meth, their_node_id_arr, msg_ref);
3735 }
3736 void handle_channel_reestablish_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKChannelReestablish * msg) {
3737         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3738         int8_tArray their_node_id_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
3739         memcpy((uint8_t*)(their_node_id_arr + 4), their_node_id.compressed_form, 33);
3740         LDKChannelReestablish msg_var = *msg;
3741         if (msg->inner != NULL)
3742                 msg_var = ChannelReestablish_clone(msg);
3743         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3744         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3745         long msg_ref = (long)msg_var.inner;
3746         if (msg_var.is_owned) {
3747                 msg_ref |= 1;
3748         }
3749         js_invoke_function_2(j_calls->handle_channel_reestablish_meth, their_node_id_arr, msg_ref);
3750 }
3751 void handle_error_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKErrorMessage * msg) {
3752         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3753         int8_tArray their_node_id_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
3754         memcpy((uint8_t*)(their_node_id_arr + 4), their_node_id.compressed_form, 33);
3755         LDKErrorMessage msg_var = *msg;
3756         if (msg->inner != NULL)
3757                 msg_var = ErrorMessage_clone(msg);
3758         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3759         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3760         long msg_ref = (long)msg_var.inner;
3761         if (msg_var.is_owned) {
3762                 msg_ref |= 1;
3763         }
3764         js_invoke_function_2(j_calls->handle_error_meth, their_node_id_arr, msg_ref);
3765 }
3766 static void* LDKChannelMessageHandler_JCalls_clone(const void* this_arg) {
3767         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3768         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
3769         atomic_fetch_add_explicit(&j_calls->MessageSendEventsProvider->refcnt, 1, memory_order_release);
3770         return (void*) this_arg;
3771 }
3772 static inline LDKChannelMessageHandler LDKChannelMessageHandler_init (/*TODO: JS Object Reference */void* o, /*TODO: JS Object Reference */void* MessageSendEventsProvider) {
3773         LDKChannelMessageHandler_JCalls *calls = MALLOC(sizeof(LDKChannelMessageHandler_JCalls), "LDKChannelMessageHandler_JCalls");
3774         atomic_init(&calls->refcnt, 1);
3775         //TODO: Assign calls->o from o
3776
3777         LDKChannelMessageHandler ret = {
3778                 .this_arg = (void*) calls,
3779                 .handle_open_channel = handle_open_channel_jcall,
3780                 .handle_accept_channel = handle_accept_channel_jcall,
3781                 .handle_funding_created = handle_funding_created_jcall,
3782                 .handle_funding_signed = handle_funding_signed_jcall,
3783                 .handle_funding_locked = handle_funding_locked_jcall,
3784                 .handle_shutdown = handle_shutdown_jcall,
3785                 .handle_closing_signed = handle_closing_signed_jcall,
3786                 .handle_update_add_htlc = handle_update_add_htlc_jcall,
3787                 .handle_update_fulfill_htlc = handle_update_fulfill_htlc_jcall,
3788                 .handle_update_fail_htlc = handle_update_fail_htlc_jcall,
3789                 .handle_update_fail_malformed_htlc = handle_update_fail_malformed_htlc_jcall,
3790                 .handle_commitment_signed = handle_commitment_signed_jcall,
3791                 .handle_revoke_and_ack = handle_revoke_and_ack_jcall,
3792                 .handle_update_fee = handle_update_fee_jcall,
3793                 .handle_announcement_signatures = handle_announcement_signatures_jcall,
3794                 .peer_disconnected = peer_disconnected_jcall,
3795                 .peer_connected = peer_connected_jcall,
3796                 .handle_channel_reestablish = handle_channel_reestablish_jcall,
3797                 .handle_error = handle_error_jcall,
3798                 .free = LDKChannelMessageHandler_JCalls_free,
3799                 .MessageSendEventsProvider = LDKMessageSendEventsProvider_init(MessageSendEventsProvider),
3800         };
3801         calls->MessageSendEventsProvider = ret.MessageSendEventsProvider.this_arg;
3802         return ret;
3803 }
3804 long TS_LDKChannelMessageHandler_new (/*TODO: JS Object Reference */void* o, /*TODO: JS Object Reference */ void* MessageSendEventsProvider) {
3805         LDKChannelMessageHandler *res_ptr = MALLOC(sizeof(LDKChannelMessageHandler), "LDKChannelMessageHandler");
3806         *res_ptr = LDKChannelMessageHandler_init(o, MessageSendEventsProvider);
3807         return (long)res_ptr;
3808 }
3809 void TS_ChannelMessageHandler_handle_open_channel(uint32_t this_arg, int8_tArray their_node_id, uint32_t their_features, uint32_t msg) {
3810         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
3811         LDKPublicKey their_node_id_ref;
3812         CHECK(*((uint32_t*)their_node_id) == 33);
3813         memcpy(their_node_id_ref.compressed_form, (uint8_t*)(their_node_id + 4), 33);
3814         LDKInitFeatures their_features_conv;
3815         their_features_conv.inner = (void*)(their_features & (~1));
3816         their_features_conv.is_owned = (their_features & 1) || (their_features == 0);
3817         // Warning: we may need a move here but can't clone!
3818         LDKOpenChannel msg_conv;
3819         msg_conv.inner = (void*)(msg & (~1));
3820         msg_conv.is_owned = false;
3821         (this_arg_conv->handle_open_channel)(this_arg_conv->this_arg, their_node_id_ref, their_features_conv, &msg_conv);
3822 }
3823
3824 void TS_ChannelMessageHandler_handle_accept_channel(uint32_t this_arg, int8_tArray their_node_id, uint32_t their_features, uint32_t msg) {
3825         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
3826         LDKPublicKey their_node_id_ref;
3827         CHECK(*((uint32_t*)their_node_id) == 33);
3828         memcpy(their_node_id_ref.compressed_form, (uint8_t*)(their_node_id + 4), 33);
3829         LDKInitFeatures their_features_conv;
3830         their_features_conv.inner = (void*)(their_features & (~1));
3831         their_features_conv.is_owned = (their_features & 1) || (their_features == 0);
3832         // Warning: we may need a move here but can't clone!
3833         LDKAcceptChannel msg_conv;
3834         msg_conv.inner = (void*)(msg & (~1));
3835         msg_conv.is_owned = false;
3836         (this_arg_conv->handle_accept_channel)(this_arg_conv->this_arg, their_node_id_ref, their_features_conv, &msg_conv);
3837 }
3838
3839 void TS_ChannelMessageHandler_handle_funding_created(uint32_t this_arg, int8_tArray their_node_id, uint32_t msg) {
3840         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
3841         LDKPublicKey their_node_id_ref;
3842         CHECK(*((uint32_t*)their_node_id) == 33);
3843         memcpy(their_node_id_ref.compressed_form, (uint8_t*)(their_node_id + 4), 33);
3844         LDKFundingCreated msg_conv;
3845         msg_conv.inner = (void*)(msg & (~1));
3846         msg_conv.is_owned = false;
3847         (this_arg_conv->handle_funding_created)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
3848 }
3849
3850 void TS_ChannelMessageHandler_handle_funding_signed(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(*((uint32_t*)their_node_id) == 33);
3854         memcpy(their_node_id_ref.compressed_form, (uint8_t*)(their_node_id + 4), 33);
3855         LDKFundingSigned msg_conv;
3856         msg_conv.inner = (void*)(msg & (~1));
3857         msg_conv.is_owned = false;
3858         (this_arg_conv->handle_funding_signed)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
3859 }
3860
3861 void TS_ChannelMessageHandler_handle_funding_locked(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(*((uint32_t*)their_node_id) == 33);
3865         memcpy(their_node_id_ref.compressed_form, (uint8_t*)(their_node_id + 4), 33);
3866         LDKFundingLocked msg_conv;
3867         msg_conv.inner = (void*)(msg & (~1));
3868         msg_conv.is_owned = false;
3869         (this_arg_conv->handle_funding_locked)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
3870 }
3871
3872 void TS_ChannelMessageHandler_handle_shutdown(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(*((uint32_t*)their_node_id) == 33);
3876         memcpy(their_node_id_ref.compressed_form, (uint8_t*)(their_node_id + 4), 33);
3877         LDKShutdown msg_conv;
3878         msg_conv.inner = (void*)(msg & (~1));
3879         msg_conv.is_owned = false;
3880         (this_arg_conv->handle_shutdown)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
3881 }
3882
3883 void TS_ChannelMessageHandler_handle_closing_signed(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(*((uint32_t*)their_node_id) == 33);
3887         memcpy(their_node_id_ref.compressed_form, (uint8_t*)(their_node_id + 4), 33);
3888         LDKClosingSigned msg_conv;
3889         msg_conv.inner = (void*)(msg & (~1));
3890         msg_conv.is_owned = false;
3891         (this_arg_conv->handle_closing_signed)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
3892 }
3893
3894 void TS_ChannelMessageHandler_handle_update_add_htlc(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(*((uint32_t*)their_node_id) == 33);
3898         memcpy(their_node_id_ref.compressed_form, (uint8_t*)(their_node_id + 4), 33);
3899         LDKUpdateAddHTLC msg_conv;
3900         msg_conv.inner = (void*)(msg & (~1));
3901         msg_conv.is_owned = false;
3902         (this_arg_conv->handle_update_add_htlc)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
3903 }
3904
3905 void TS_ChannelMessageHandler_handle_update_fulfill_htlc(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(*((uint32_t*)their_node_id) == 33);
3909         memcpy(their_node_id_ref.compressed_form, (uint8_t*)(their_node_id + 4), 33);
3910         LDKUpdateFulfillHTLC msg_conv;
3911         msg_conv.inner = (void*)(msg & (~1));
3912         msg_conv.is_owned = false;
3913         (this_arg_conv->handle_update_fulfill_htlc)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
3914 }
3915
3916 void TS_ChannelMessageHandler_handle_update_fail_htlc(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(*((uint32_t*)their_node_id) == 33);
3920         memcpy(their_node_id_ref.compressed_form, (uint8_t*)(their_node_id + 4), 33);
3921         LDKUpdateFailHTLC msg_conv;
3922         msg_conv.inner = (void*)(msg & (~1));
3923         msg_conv.is_owned = false;
3924         (this_arg_conv->handle_update_fail_htlc)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
3925 }
3926
3927 void TS_ChannelMessageHandler_handle_update_fail_malformed_htlc(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(*((uint32_t*)their_node_id) == 33);
3931         memcpy(their_node_id_ref.compressed_form, (uint8_t*)(their_node_id + 4), 33);
3932         LDKUpdateFailMalformedHTLC msg_conv;
3933         msg_conv.inner = (void*)(msg & (~1));
3934         msg_conv.is_owned = false;
3935         (this_arg_conv->handle_update_fail_malformed_htlc)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
3936 }
3937
3938 void TS_ChannelMessageHandler_handle_commitment_signed(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(*((uint32_t*)their_node_id) == 33);
3942         memcpy(their_node_id_ref.compressed_form, (uint8_t*)(their_node_id + 4), 33);
3943         LDKCommitmentSigned msg_conv;
3944         msg_conv.inner = (void*)(msg & (~1));
3945         msg_conv.is_owned = false;
3946         (this_arg_conv->handle_commitment_signed)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
3947 }
3948
3949 void TS_ChannelMessageHandler_handle_revoke_and_ack(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(*((uint32_t*)their_node_id) == 33);
3953         memcpy(their_node_id_ref.compressed_form, (uint8_t*)(their_node_id + 4), 33);
3954         LDKRevokeAndACK msg_conv;
3955         msg_conv.inner = (void*)(msg & (~1));
3956         msg_conv.is_owned = false;
3957         (this_arg_conv->handle_revoke_and_ack)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
3958 }
3959
3960 void TS_ChannelMessageHandler_handle_update_fee(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(*((uint32_t*)their_node_id) == 33);
3964         memcpy(their_node_id_ref.compressed_form, (uint8_t*)(their_node_id + 4), 33);
3965         LDKUpdateFee msg_conv;
3966         msg_conv.inner = (void*)(msg & (~1));
3967         msg_conv.is_owned = false;
3968         (this_arg_conv->handle_update_fee)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
3969 }
3970
3971 void TS_ChannelMessageHandler_handle_announcement_signatures(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(*((uint32_t*)their_node_id) == 33);
3975         memcpy(their_node_id_ref.compressed_form, (uint8_t*)(their_node_id + 4), 33);
3976         LDKAnnouncementSignatures msg_conv;
3977         msg_conv.inner = (void*)(msg & (~1));
3978         msg_conv.is_owned = false;
3979         (this_arg_conv->handle_announcement_signatures)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
3980 }
3981
3982 void TS_ChannelMessageHandler_peer_disconnected(uint32_t this_arg, int8_tArray their_node_id, jboolean no_connection_possible) {
3983         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
3984         LDKPublicKey their_node_id_ref;
3985         CHECK(*((uint32_t*)their_node_id) == 33);
3986         memcpy(their_node_id_ref.compressed_form, (uint8_t*)(their_node_id + 4), 33);
3987         (this_arg_conv->peer_disconnected)(this_arg_conv->this_arg, their_node_id_ref, no_connection_possible);
3988 }
3989
3990 void TS_ChannelMessageHandler_peer_connected(uint32_t this_arg, int8_tArray their_node_id, uint32_t msg) {
3991         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
3992         LDKPublicKey their_node_id_ref;
3993         CHECK(*((uint32_t*)their_node_id) == 33);
3994         memcpy(their_node_id_ref.compressed_form, (uint8_t*)(their_node_id + 4), 33);
3995         LDKInit msg_conv;
3996         msg_conv.inner = (void*)(msg & (~1));
3997         msg_conv.is_owned = false;
3998         (this_arg_conv->peer_connected)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
3999 }
4000
4001 void TS_ChannelMessageHandler_handle_channel_reestablish(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(*((uint32_t*)their_node_id) == 33);
4005         memcpy(their_node_id_ref.compressed_form, (uint8_t*)(their_node_id + 4), 33);
4006         LDKChannelReestablish msg_conv;
4007         msg_conv.inner = (void*)(msg & (~1));
4008         msg_conv.is_owned = false;
4009         (this_arg_conv->handle_channel_reestablish)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
4010 }
4011
4012 void TS_ChannelMessageHandler_handle_error(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(*((uint32_t*)their_node_id) == 33);
4016         memcpy(their_node_id_ref.compressed_form, (uint8_t*)(their_node_id + 4), 33);
4017         LDKErrorMessage msg_conv;
4018         msg_conv.inner = (void*)(msg & (~1));
4019         msg_conv.is_owned = false;
4020         (this_arg_conv->handle_error)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
4021 }
4022
4023 typedef struct LDKRoutingMessageHandler_JCalls {
4024         atomic_size_t refcnt;
4025         LDKMessageSendEventsProvider_JCalls* MessageSendEventsProvider;
4026         uint32_t handle_node_announcement_meth;
4027         uint32_t handle_channel_announcement_meth;
4028         uint32_t handle_channel_update_meth;
4029         uint32_t handle_htlc_fail_channel_update_meth;
4030         uint32_t get_next_channel_announcements_meth;
4031         uint32_t get_next_node_announcements_meth;
4032         uint32_t sync_routing_table_meth;
4033         uint32_t handle_reply_channel_range_meth;
4034         uint32_t handle_reply_short_channel_ids_end_meth;
4035         uint32_t handle_query_channel_range_meth;
4036         uint32_t handle_query_short_channel_ids_meth;
4037 } LDKRoutingMessageHandler_JCalls;
4038 static void LDKRoutingMessageHandler_JCalls_free(void* this_arg) {
4039         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
4040         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
4041                 js_free(j_calls->handle_node_announcement_meth);
4042                 js_free(j_calls->handle_channel_announcement_meth);
4043                 js_free(j_calls->handle_channel_update_meth);
4044                 js_free(j_calls->handle_htlc_fail_channel_update_meth);
4045                 js_free(j_calls->get_next_channel_announcements_meth);
4046                 js_free(j_calls->get_next_node_announcements_meth);
4047                 js_free(j_calls->sync_routing_table_meth);
4048                 js_free(j_calls->handle_reply_channel_range_meth);
4049                 js_free(j_calls->handle_reply_short_channel_ids_end_meth);
4050                 js_free(j_calls->handle_query_channel_range_meth);
4051                 js_free(j_calls->handle_query_short_channel_ids_meth);
4052                 FREE(j_calls);
4053         }
4054 }
4055 LDKCResult_boolLightningErrorZ handle_node_announcement_jcall(const void* this_arg, const LDKNodeAnnouncement * msg) {
4056         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
4057         LDKNodeAnnouncement msg_var = *msg;
4058         if (msg->inner != NULL)
4059                 msg_var = NodeAnnouncement_clone(msg);
4060         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4061         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4062         long msg_ref = (long)msg_var.inner;
4063         if (msg_var.is_owned) {
4064                 msg_ref |= 1;
4065         }
4066         LDKCResult_boolLightningErrorZ* ret; // TODO: Call handle_node_announcement on j_calls with instance obj, returning a pointer, msg_ref);
4067         LDKCResult_boolLightningErrorZ ret_conv = *(LDKCResult_boolLightningErrorZ*)ret;
4068         FREE((void*)ret);
4069         return ret_conv;
4070 }
4071 LDKCResult_boolLightningErrorZ handle_channel_announcement_jcall(const void* this_arg, const LDKChannelAnnouncement * msg) {
4072         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
4073         LDKChannelAnnouncement msg_var = *msg;
4074         if (msg->inner != NULL)
4075                 msg_var = ChannelAnnouncement_clone(msg);
4076         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4077         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4078         long msg_ref = (long)msg_var.inner;
4079         if (msg_var.is_owned) {
4080                 msg_ref |= 1;
4081         }
4082         LDKCResult_boolLightningErrorZ* ret; // TODO: Call handle_channel_announcement on j_calls with instance obj, returning a pointer, msg_ref);
4083         LDKCResult_boolLightningErrorZ ret_conv = *(LDKCResult_boolLightningErrorZ*)ret;
4084         FREE((void*)ret);
4085         return ret_conv;
4086 }
4087 LDKCResult_boolLightningErrorZ handle_channel_update_jcall(const void* this_arg, const LDKChannelUpdate * msg) {
4088         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
4089         LDKChannelUpdate msg_var = *msg;
4090         if (msg->inner != NULL)
4091                 msg_var = ChannelUpdate_clone(msg);
4092         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4093         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4094         long msg_ref = (long)msg_var.inner;
4095         if (msg_var.is_owned) {
4096                 msg_ref |= 1;
4097         }
4098         LDKCResult_boolLightningErrorZ* ret; // TODO: Call handle_channel_update on j_calls with instance obj, returning a pointer, msg_ref);
4099         LDKCResult_boolLightningErrorZ ret_conv = *(LDKCResult_boolLightningErrorZ*)ret;
4100         FREE((void*)ret);
4101         return ret_conv;
4102 }
4103 void handle_htlc_fail_channel_update_jcall(const void* this_arg, const LDKHTLCFailChannelUpdate * update) {
4104         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
4105         long ret_update = (long)update;
4106         js_invoke_function_1(j_calls->handle_htlc_fail_channel_update_meth, ret_update);
4107 }
4108 LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ get_next_channel_announcements_jcall(const void* this_arg, uint64_t starting_point, uint8_t batch_amount) {
4109         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
4110         uint32_tArray arg = js_invoke_function_2(j_calls->get_next_channel_announcements_meth, starting_point, batch_amount);
4111         LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ arg_constr;
4112         arg_constr.datalen = *((uint32_t*)arg);
4113         if (arg_constr.datalen > 0)
4114                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ), "LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ Elements");
4115         else
4116                 arg_constr.data = NULL;
4117         uint32_t* arg_vals = (uint32_t*)(arg + 4);
4118         for (size_t l = 0; l < arg_constr.datalen; l++) {
4119                 uint32_t arr_conv_63 = arg_vals[l];
4120                 LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ arr_conv_63_conv = *(LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ*)arr_conv_63;
4121                 FREE((void*)arr_conv_63);
4122                 arg_constr.data[l] = arr_conv_63_conv;
4123         }
4124         return arg_constr;
4125 }
4126 LDKCVec_NodeAnnouncementZ get_next_node_announcements_jcall(const void* this_arg, LDKPublicKey starting_point, uint8_t batch_amount) {
4127         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
4128         int8_tArray starting_point_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
4129         memcpy((uint8_t*)(starting_point_arr + 4), starting_point.compressed_form, 33);
4130         uint32_tArray arg = js_invoke_function_2(j_calls->get_next_node_announcements_meth, starting_point_arr, batch_amount);
4131         LDKCVec_NodeAnnouncementZ arg_constr;
4132         arg_constr.datalen = *((uint32_t*)arg);
4133         if (arg_constr.datalen > 0)
4134                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKNodeAnnouncement), "LDKCVec_NodeAnnouncementZ Elements");
4135         else
4136                 arg_constr.data = NULL;
4137         uint32_t* arg_vals = (uint32_t*)(arg + 4);
4138         for (size_t s = 0; s < arg_constr.datalen; s++) {
4139                 uint32_t arr_conv_18 = arg_vals[s];
4140                 LDKNodeAnnouncement arr_conv_18_conv;
4141                 arr_conv_18_conv.inner = (void*)(arr_conv_18 & (~1));
4142                 arr_conv_18_conv.is_owned = (arr_conv_18 & 1) || (arr_conv_18 == 0);
4143                 if (arr_conv_18_conv.inner != NULL)
4144                         arr_conv_18_conv = NodeAnnouncement_clone(&arr_conv_18_conv);
4145                 arg_constr.data[s] = arr_conv_18_conv;
4146         }
4147         return arg_constr;
4148 }
4149 void sync_routing_table_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKInit * init) {
4150         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
4151         int8_tArray their_node_id_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
4152         memcpy((uint8_t*)(their_node_id_arr + 4), their_node_id.compressed_form, 33);
4153         LDKInit init_var = *init;
4154         if (init->inner != NULL)
4155                 init_var = Init_clone(init);
4156         CHECK((((long)init_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4157         CHECK((((long)&init_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4158         long init_ref = (long)init_var.inner;
4159         if (init_var.is_owned) {
4160                 init_ref |= 1;
4161         }
4162         js_invoke_function_2(j_calls->sync_routing_table_meth, their_node_id_arr, init_ref);
4163 }
4164 LDKCResult_NoneLightningErrorZ handle_reply_channel_range_jcall(const void* this_arg, LDKPublicKey their_node_id, LDKReplyChannelRange msg) {
4165         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
4166         int8_tArray their_node_id_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
4167         memcpy((uint8_t*)(their_node_id_arr + 4), their_node_id.compressed_form, 33);
4168         LDKReplyChannelRange msg_var = msg;
4169         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4170         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4171         long msg_ref = (long)msg_var.inner;
4172         if (msg_var.is_owned) {
4173                 msg_ref |= 1;
4174         }
4175         LDKCResult_NoneLightningErrorZ* ret; // TODO: Call handle_reply_channel_range on j_calls with instance obj, returning a pointer, their_node_id_arr, msg_ref);
4176         LDKCResult_NoneLightningErrorZ ret_conv = *(LDKCResult_NoneLightningErrorZ*)ret;
4177         FREE((void*)ret);
4178         return ret_conv;
4179 }
4180 LDKCResult_NoneLightningErrorZ handle_reply_short_channel_ids_end_jcall(const void* this_arg, LDKPublicKey their_node_id, LDKReplyShortChannelIdsEnd msg) {
4181         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
4182         int8_tArray their_node_id_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
4183         memcpy((uint8_t*)(their_node_id_arr + 4), their_node_id.compressed_form, 33);
4184         LDKReplyShortChannelIdsEnd msg_var = msg;
4185         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4186         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4187         long msg_ref = (long)msg_var.inner;
4188         if (msg_var.is_owned) {
4189                 msg_ref |= 1;
4190         }
4191         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);
4192         LDKCResult_NoneLightningErrorZ ret_conv = *(LDKCResult_NoneLightningErrorZ*)ret;
4193         FREE((void*)ret);
4194         return ret_conv;
4195 }
4196 LDKCResult_NoneLightningErrorZ handle_query_channel_range_jcall(const void* this_arg, LDKPublicKey their_node_id, LDKQueryChannelRange msg) {
4197         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
4198         int8_tArray their_node_id_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
4199         memcpy((uint8_t*)(their_node_id_arr + 4), their_node_id.compressed_form, 33);
4200         LDKQueryChannelRange msg_var = msg;
4201         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4202         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4203         long msg_ref = (long)msg_var.inner;
4204         if (msg_var.is_owned) {
4205                 msg_ref |= 1;
4206         }
4207         LDKCResult_NoneLightningErrorZ* ret; // TODO: Call handle_query_channel_range on j_calls with instance obj, returning a pointer, their_node_id_arr, msg_ref);
4208         LDKCResult_NoneLightningErrorZ ret_conv = *(LDKCResult_NoneLightningErrorZ*)ret;
4209         FREE((void*)ret);
4210         return ret_conv;
4211 }
4212 LDKCResult_NoneLightningErrorZ handle_query_short_channel_ids_jcall(const void* this_arg, LDKPublicKey their_node_id, LDKQueryShortChannelIds msg) {
4213         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
4214         int8_tArray their_node_id_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
4215         memcpy((uint8_t*)(their_node_id_arr + 4), their_node_id.compressed_form, 33);
4216         LDKQueryShortChannelIds msg_var = msg;
4217         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4218         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4219         long msg_ref = (long)msg_var.inner;
4220         if (msg_var.is_owned) {
4221                 msg_ref |= 1;
4222         }
4223         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);
4224         LDKCResult_NoneLightningErrorZ ret_conv = *(LDKCResult_NoneLightningErrorZ*)ret;
4225         FREE((void*)ret);
4226         return ret_conv;
4227 }
4228 static void* LDKRoutingMessageHandler_JCalls_clone(const void* this_arg) {
4229         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
4230         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
4231         atomic_fetch_add_explicit(&j_calls->MessageSendEventsProvider->refcnt, 1, memory_order_release);
4232         return (void*) this_arg;
4233 }
4234 static inline LDKRoutingMessageHandler LDKRoutingMessageHandler_init (/*TODO: JS Object Reference */void* o, /*TODO: JS Object Reference */void* MessageSendEventsProvider) {
4235         LDKRoutingMessageHandler_JCalls *calls = MALLOC(sizeof(LDKRoutingMessageHandler_JCalls), "LDKRoutingMessageHandler_JCalls");
4236         atomic_init(&calls->refcnt, 1);
4237         //TODO: Assign calls->o from o
4238
4239         LDKRoutingMessageHandler ret = {
4240                 .this_arg = (void*) calls,
4241                 .handle_node_announcement = handle_node_announcement_jcall,
4242                 .handle_channel_announcement = handle_channel_announcement_jcall,
4243                 .handle_channel_update = handle_channel_update_jcall,
4244                 .handle_htlc_fail_channel_update = handle_htlc_fail_channel_update_jcall,
4245                 .get_next_channel_announcements = get_next_channel_announcements_jcall,
4246                 .get_next_node_announcements = get_next_node_announcements_jcall,
4247                 .sync_routing_table = sync_routing_table_jcall,
4248                 .handle_reply_channel_range = handle_reply_channel_range_jcall,
4249                 .handle_reply_short_channel_ids_end = handle_reply_short_channel_ids_end_jcall,
4250                 .handle_query_channel_range = handle_query_channel_range_jcall,
4251                 .handle_query_short_channel_ids = handle_query_short_channel_ids_jcall,
4252                 .free = LDKRoutingMessageHandler_JCalls_free,
4253                 .MessageSendEventsProvider = LDKMessageSendEventsProvider_init(MessageSendEventsProvider),
4254         };
4255         calls->MessageSendEventsProvider = ret.MessageSendEventsProvider.this_arg;
4256         return ret;
4257 }
4258 long TS_LDKRoutingMessageHandler_new (/*TODO: JS Object Reference */void* o, /*TODO: JS Object Reference */ void* MessageSendEventsProvider) {
4259         LDKRoutingMessageHandler *res_ptr = MALLOC(sizeof(LDKRoutingMessageHandler), "LDKRoutingMessageHandler");
4260         *res_ptr = LDKRoutingMessageHandler_init(o, MessageSendEventsProvider);
4261         return (long)res_ptr;
4262 }
4263 uint32_t TS_RoutingMessageHandler_handle_node_announcement(uint32_t this_arg, uint32_t msg) {
4264         LDKRoutingMessageHandler* this_arg_conv = (LDKRoutingMessageHandler*)this_arg;
4265         LDKNodeAnnouncement msg_conv;
4266         msg_conv.inner = (void*)(msg & (~1));
4267         msg_conv.is_owned = false;
4268         LDKCResult_boolLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_boolLightningErrorZ), "LDKCResult_boolLightningErrorZ");
4269         *ret_conv = (this_arg_conv->handle_node_announcement)(this_arg_conv->this_arg, &msg_conv);
4270         return (long)ret_conv;
4271 }
4272
4273 uint32_t TS_RoutingMessageHandler_handle_channel_announcement(uint32_t this_arg, uint32_t msg) {
4274         LDKRoutingMessageHandler* this_arg_conv = (LDKRoutingMessageHandler*)this_arg;
4275         LDKChannelAnnouncement msg_conv;
4276         msg_conv.inner = (void*)(msg & (~1));
4277         msg_conv.is_owned = false;
4278         LDKCResult_boolLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_boolLightningErrorZ), "LDKCResult_boolLightningErrorZ");
4279         *ret_conv = (this_arg_conv->handle_channel_announcement)(this_arg_conv->this_arg, &msg_conv);
4280         return (long)ret_conv;
4281 }
4282
4283 uint32_t TS_RoutingMessageHandler_handle_channel_update(uint32_t this_arg, uint32_t msg) {
4284         LDKRoutingMessageHandler* this_arg_conv = (LDKRoutingMessageHandler*)this_arg;
4285         LDKChannelUpdate msg_conv;
4286         msg_conv.inner = (void*)(msg & (~1));
4287         msg_conv.is_owned = false;
4288         LDKCResult_boolLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_boolLightningErrorZ), "LDKCResult_boolLightningErrorZ");
4289         *ret_conv = (this_arg_conv->handle_channel_update)(this_arg_conv->this_arg, &msg_conv);
4290         return (long)ret_conv;
4291 }
4292
4293 void TS_RoutingMessageHandler_handle_htlc_fail_channel_update(uint32_t this_arg, uint32_t update) {
4294         LDKRoutingMessageHandler* this_arg_conv = (LDKRoutingMessageHandler*)this_arg;
4295         LDKHTLCFailChannelUpdate* update_conv = (LDKHTLCFailChannelUpdate*)update;
4296         (this_arg_conv->handle_htlc_fail_channel_update)(this_arg_conv->this_arg, update_conv);
4297 }
4298
4299 uint32_tArray TS_RoutingMessageHandler_get_next_channel_announcements(uint32_t this_arg, int64_t starting_point, int8_t batch_amount) {
4300         LDKRoutingMessageHandler* this_arg_conv = (LDKRoutingMessageHandler*)this_arg;
4301         LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ ret_var = (this_arg_conv->get_next_channel_announcements)(this_arg_conv->this_arg, starting_point, batch_amount);
4302         uint32_tArray ret_arr = init_arr(ret_var.datalen, sizeof(uint32_t), "Native uint32_tArray Bytes");
4303         uint32_t *ret_arr_ptr = (uint32_t*)(ret_arr + 4);
4304         for (size_t l = 0; l < ret_var.datalen; l++) {
4305                 LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ* arr_conv_63_ref = MALLOC(sizeof(LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ), "LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ");
4306                 *arr_conv_63_ref = ret_var.data[l];
4307                 arr_conv_63_ref->a = ChannelAnnouncement_clone(&arr_conv_63_ref->a);
4308                 arr_conv_63_ref->b = ChannelUpdate_clone(&arr_conv_63_ref->b);
4309                 arr_conv_63_ref->c = ChannelUpdate_clone(&arr_conv_63_ref->c);
4310                 ret_arr_ptr[l] = (long)arr_conv_63_ref;
4311         }
4312         FREE(ret_var.data);
4313         return ret_arr;
4314 }
4315
4316 uint32_tArray TS_RoutingMessageHandler_get_next_node_announcements(uint32_t this_arg, int8_tArray starting_point, int8_t batch_amount) {
4317         LDKRoutingMessageHandler* this_arg_conv = (LDKRoutingMessageHandler*)this_arg;
4318         LDKPublicKey starting_point_ref;
4319         CHECK(*((uint32_t*)starting_point) == 33);
4320         memcpy(starting_point_ref.compressed_form, (uint8_t*)(starting_point + 4), 33);
4321         LDKCVec_NodeAnnouncementZ ret_var = (this_arg_conv->get_next_node_announcements)(this_arg_conv->this_arg, starting_point_ref, batch_amount);
4322         uint32_tArray ret_arr = init_arr(ret_var.datalen, sizeof(uint32_t), "Native uint32_tArray Bytes");
4323         uint32_t *ret_arr_ptr = (uint32_t*)(ret_arr + 4);
4324         for (size_t s = 0; s < ret_var.datalen; s++) {
4325                 LDKNodeAnnouncement arr_conv_18_var = ret_var.data[s];
4326                 CHECK((((long)arr_conv_18_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4327                 CHECK((((long)&arr_conv_18_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4328                 long arr_conv_18_ref = (long)arr_conv_18_var.inner;
4329                 if (arr_conv_18_var.is_owned) {
4330                         arr_conv_18_ref |= 1;
4331                 }
4332                 ret_arr_ptr[s] = arr_conv_18_ref;
4333         }
4334         FREE(ret_var.data);
4335         return ret_arr;
4336 }
4337
4338 void TS_RoutingMessageHandler_sync_routing_table(uint32_t this_arg, int8_tArray their_node_id, uint32_t init) {
4339         LDKRoutingMessageHandler* this_arg_conv = (LDKRoutingMessageHandler*)this_arg;
4340         LDKPublicKey their_node_id_ref;
4341         CHECK(*((uint32_t*)their_node_id) == 33);
4342         memcpy(their_node_id_ref.compressed_form, (uint8_t*)(their_node_id + 4), 33);
4343         LDKInit init_conv;
4344         init_conv.inner = (void*)(init & (~1));
4345         init_conv.is_owned = false;
4346         (this_arg_conv->sync_routing_table)(this_arg_conv->this_arg, their_node_id_ref, &init_conv);
4347 }
4348
4349 uint32_t TS_RoutingMessageHandler_handle_reply_channel_range(uint32_t this_arg, int8_tArray their_node_id, uint32_t msg) {
4350         LDKRoutingMessageHandler* this_arg_conv = (LDKRoutingMessageHandler*)this_arg;
4351         LDKPublicKey their_node_id_ref;
4352         CHECK(*((uint32_t*)their_node_id) == 33);
4353         memcpy(their_node_id_ref.compressed_form, (uint8_t*)(their_node_id + 4), 33);
4354         LDKReplyChannelRange msg_conv;
4355         msg_conv.inner = (void*)(msg & (~1));
4356         msg_conv.is_owned = (msg & 1) || (msg == 0);
4357         if (msg_conv.inner != NULL)
4358                 msg_conv = ReplyChannelRange_clone(&msg_conv);
4359         LDKCResult_NoneLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneLightningErrorZ), "LDKCResult_NoneLightningErrorZ");
4360         *ret_conv = (this_arg_conv->handle_reply_channel_range)(this_arg_conv->this_arg, their_node_id_ref, msg_conv);
4361         return (long)ret_conv;
4362 }
4363
4364 uint32_t TS_RoutingMessageHandler_handle_reply_short_channel_ids_end(uint32_t this_arg, int8_tArray their_node_id, uint32_t msg) {
4365         LDKRoutingMessageHandler* this_arg_conv = (LDKRoutingMessageHandler*)this_arg;
4366         LDKPublicKey their_node_id_ref;
4367         CHECK(*((uint32_t*)their_node_id) == 33);
4368         memcpy(their_node_id_ref.compressed_form, (uint8_t*)(their_node_id + 4), 33);
4369         LDKReplyShortChannelIdsEnd msg_conv;
4370         msg_conv.inner = (void*)(msg & (~1));
4371         msg_conv.is_owned = (msg & 1) || (msg == 0);
4372         if (msg_conv.inner != NULL)
4373                 msg_conv = ReplyShortChannelIdsEnd_clone(&msg_conv);
4374         LDKCResult_NoneLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneLightningErrorZ), "LDKCResult_NoneLightningErrorZ");
4375         *ret_conv = (this_arg_conv->handle_reply_short_channel_ids_end)(this_arg_conv->this_arg, their_node_id_ref, msg_conv);
4376         return (long)ret_conv;
4377 }
4378
4379 uint32_t TS_RoutingMessageHandler_handle_query_channel_range(uint32_t this_arg, int8_tArray their_node_id, uint32_t msg) {
4380         LDKRoutingMessageHandler* this_arg_conv = (LDKRoutingMessageHandler*)this_arg;
4381         LDKPublicKey their_node_id_ref;
4382         CHECK(*((uint32_t*)their_node_id) == 33);
4383         memcpy(their_node_id_ref.compressed_form, (uint8_t*)(their_node_id + 4), 33);
4384         LDKQueryChannelRange msg_conv;
4385         msg_conv.inner = (void*)(msg & (~1));
4386         msg_conv.is_owned = (msg & 1) || (msg == 0);
4387         if (msg_conv.inner != NULL)
4388                 msg_conv = QueryChannelRange_clone(&msg_conv);
4389         LDKCResult_NoneLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneLightningErrorZ), "LDKCResult_NoneLightningErrorZ");
4390         *ret_conv = (this_arg_conv->handle_query_channel_range)(this_arg_conv->this_arg, their_node_id_ref, msg_conv);
4391         return (long)ret_conv;
4392 }
4393
4394 uint32_t TS_RoutingMessageHandler_handle_query_short_channel_ids(uint32_t this_arg, int8_tArray their_node_id, uint32_t msg) {
4395         LDKRoutingMessageHandler* this_arg_conv = (LDKRoutingMessageHandler*)this_arg;
4396         LDKPublicKey their_node_id_ref;
4397         CHECK(*((uint32_t*)their_node_id) == 33);
4398         memcpy(their_node_id_ref.compressed_form, (uint8_t*)(their_node_id + 4), 33);
4399         LDKQueryShortChannelIds msg_conv;
4400         msg_conv.inner = (void*)(msg & (~1));
4401         msg_conv.is_owned = (msg & 1) || (msg == 0);
4402         if (msg_conv.inner != NULL)
4403                 msg_conv = QueryShortChannelIds_clone(&msg_conv);
4404         LDKCResult_NoneLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneLightningErrorZ), "LDKCResult_NoneLightningErrorZ");
4405         *ret_conv = (this_arg_conv->handle_query_short_channel_ids)(this_arg_conv->this_arg, their_node_id_ref, msg_conv);
4406         return (long)ret_conv;
4407 }
4408
4409 typedef struct LDKSocketDescriptor_JCalls {
4410         atomic_size_t refcnt;
4411         uint32_t send_data_meth;
4412         uint32_t disconnect_socket_meth;
4413         uint32_t eq_meth;
4414         uint32_t hash_meth;
4415 } LDKSocketDescriptor_JCalls;
4416 static void LDKSocketDescriptor_JCalls_free(void* this_arg) {
4417         LDKSocketDescriptor_JCalls *j_calls = (LDKSocketDescriptor_JCalls*) this_arg;
4418         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
4419                 js_free(j_calls->send_data_meth);
4420                 js_free(j_calls->disconnect_socket_meth);
4421                 js_free(j_calls->eq_meth);
4422                 js_free(j_calls->hash_meth);
4423                 FREE(j_calls);
4424         }
4425 }
4426 uintptr_t send_data_jcall(void* this_arg, LDKu8slice data, bool resume_read) {
4427         LDKSocketDescriptor_JCalls *j_calls = (LDKSocketDescriptor_JCalls*) this_arg;
4428         LDKu8slice data_var = data;
4429         int8_tArray data_arr = init_arr(data_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
4430         memcpy((uint8_t*)(data_arr + 4), data_var.data, data_var.datalen);
4431         return js_invoke_function_2(j_calls->send_data_meth, data_arr, resume_read);
4432 }
4433 void disconnect_socket_jcall(void* this_arg) {
4434         LDKSocketDescriptor_JCalls *j_calls = (LDKSocketDescriptor_JCalls*) this_arg;
4435         js_invoke_function_0(j_calls->disconnect_socket_meth);
4436 }
4437 bool eq_jcall(const void* this_arg, const LDKSocketDescriptor * other_arg) {
4438         LDKSocketDescriptor_JCalls *j_calls = (LDKSocketDescriptor_JCalls*) this_arg;
4439         LDKSocketDescriptor *other_arg_clone = MALLOC(sizeof(LDKSocketDescriptor), "LDKSocketDescriptor");
4440         *other_arg_clone = SocketDescriptor_clone(other_arg);
4441         return js_invoke_function_1(j_calls->eq_meth, (long)other_arg_clone);
4442 }
4443 uint64_t hash_jcall(const void* this_arg) {
4444         LDKSocketDescriptor_JCalls *j_calls = (LDKSocketDescriptor_JCalls*) this_arg;
4445         return js_invoke_function_0(j_calls->hash_meth);
4446 }
4447 static void* LDKSocketDescriptor_JCalls_clone(const void* this_arg) {
4448         LDKSocketDescriptor_JCalls *j_calls = (LDKSocketDescriptor_JCalls*) this_arg;
4449         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
4450         return (void*) this_arg;
4451 }
4452 static inline LDKSocketDescriptor LDKSocketDescriptor_init (/*TODO: JS Object Reference */void* o) {
4453         LDKSocketDescriptor_JCalls *calls = MALLOC(sizeof(LDKSocketDescriptor_JCalls), "LDKSocketDescriptor_JCalls");
4454         atomic_init(&calls->refcnt, 1);
4455         //TODO: Assign calls->o from o
4456
4457         LDKSocketDescriptor ret = {
4458                 .this_arg = (void*) calls,
4459                 .send_data = send_data_jcall,
4460                 .disconnect_socket = disconnect_socket_jcall,
4461                 .eq = eq_jcall,
4462                 .hash = hash_jcall,
4463                 .clone = LDKSocketDescriptor_JCalls_clone,
4464                 .free = LDKSocketDescriptor_JCalls_free,
4465         };
4466         return ret;
4467 }
4468 long TS_LDKSocketDescriptor_new (/*TODO: JS Object Reference */void* o) {
4469         LDKSocketDescriptor *res_ptr = MALLOC(sizeof(LDKSocketDescriptor), "LDKSocketDescriptor");
4470         *res_ptr = LDKSocketDescriptor_init(o);
4471         return (long)res_ptr;
4472 }
4473 intptr_t TS_SocketDescriptor_send_data(uint32_t this_arg, int8_tArray data, jboolean resume_read) {
4474         LDKSocketDescriptor* this_arg_conv = (LDKSocketDescriptor*)this_arg;
4475         LDKu8slice data_ref;
4476         data_ref.datalen = *((uint32_t*)data);
4477         data_ref.data = (int8_t*)(data + 4);
4478         intptr_t ret_val = (this_arg_conv->send_data)(this_arg_conv->this_arg, data_ref, resume_read);
4479         return ret_val;
4480 }
4481
4482 void TS_SocketDescriptor_disconnect_socket(uint32_t this_arg) {
4483         LDKSocketDescriptor* this_arg_conv = (LDKSocketDescriptor*)this_arg;
4484         (this_arg_conv->disconnect_socket)(this_arg_conv->this_arg);
4485 }
4486
4487 int64_t TS_SocketDescriptor_hash(uint32_t this_arg) {
4488         LDKSocketDescriptor* this_arg_conv = (LDKSocketDescriptor*)this_arg;
4489         int64_t ret_val = (this_arg_conv->hash)(this_arg_conv->this_arg);
4490         return ret_val;
4491 }
4492
4493 void TS_Transaction_free(int8_tArray _res) {
4494         LDKTransaction _res_ref;
4495         _res_ref.datalen = *((uint32_t*)_res);
4496         _res_ref.data = MALLOC(_res_ref.datalen, "LDKTransaction Bytes");
4497         memcpy(_res_ref.data, (uint8_t*)(_res + 4), _res_ref.datalen);
4498         _res_ref.data_is_owned = true;
4499         Transaction_free(_res_ref);
4500 }
4501
4502 void TS_TxOut_free(uint32_t _res) {
4503         LDKTxOut _res_conv = *(LDKTxOut*)_res;
4504         FREE((void*)_res);
4505         TxOut_free(_res_conv);
4506 }
4507
4508 void TS_CVec_SpendableOutputDescriptorZ_free(uint32_tArray _res) {
4509         LDKCVec_SpendableOutputDescriptorZ _res_constr;
4510         _res_constr.datalen = *((uint32_t*)_res);
4511         if (_res_constr.datalen > 0)
4512                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKSpendableOutputDescriptor), "LDKCVec_SpendableOutputDescriptorZ Elements");
4513         else
4514                 _res_constr.data = NULL;
4515         uint32_t* _res_vals = (uint32_t*)(_res + 4);
4516         for (size_t b = 0; b < _res_constr.datalen; b++) {
4517                 uint32_t arr_conv_27 = _res_vals[b];
4518                 LDKSpendableOutputDescriptor arr_conv_27_conv = *(LDKSpendableOutputDescriptor*)arr_conv_27;
4519                 FREE((void*)arr_conv_27);
4520                 _res_constr.data[b] = arr_conv_27_conv;
4521         }
4522         CVec_SpendableOutputDescriptorZ_free(_res_constr);
4523 }
4524
4525 void TS_CVec_MessageSendEventZ_free(uint32_tArray _res) {
4526         LDKCVec_MessageSendEventZ _res_constr;
4527         _res_constr.datalen = *((uint32_t*)_res);
4528         if (_res_constr.datalen > 0)
4529                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKMessageSendEvent), "LDKCVec_MessageSendEventZ Elements");
4530         else
4531                 _res_constr.data = NULL;
4532         uint32_t* _res_vals = (uint32_t*)(_res + 4);
4533         for (size_t s = 0; s < _res_constr.datalen; s++) {
4534                 uint32_t arr_conv_18 = _res_vals[s];
4535                 LDKMessageSendEvent arr_conv_18_conv = *(LDKMessageSendEvent*)arr_conv_18;
4536                 FREE((void*)arr_conv_18);
4537                 _res_constr.data[s] = arr_conv_18_conv;
4538         }
4539         CVec_MessageSendEventZ_free(_res_constr);
4540 }
4541
4542 void TS_CVec_EventZ_free(uint32_tArray _res) {
4543         LDKCVec_EventZ _res_constr;
4544         _res_constr.datalen = *((uint32_t*)_res);
4545         if (_res_constr.datalen > 0)
4546                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKEvent), "LDKCVec_EventZ Elements");
4547         else
4548                 _res_constr.data = NULL;
4549         uint32_t* _res_vals = (uint32_t*)(_res + 4);
4550         for (size_t h = 0; h < _res_constr.datalen; h++) {
4551                 uint32_t arr_conv_7 = _res_vals[h];
4552                 LDKEvent arr_conv_7_conv = *(LDKEvent*)arr_conv_7;
4553                 FREE((void*)arr_conv_7);
4554                 _res_constr.data[h] = arr_conv_7_conv;
4555         }
4556         CVec_EventZ_free(_res_constr);
4557 }
4558
4559 void TS_C2Tuple_usizeTransactionZ_free(uint32_t _res) {
4560         LDKC2Tuple_usizeTransactionZ _res_conv = *(LDKC2Tuple_usizeTransactionZ*)_res;
4561         FREE((void*)_res);
4562         C2Tuple_usizeTransactionZ_free(_res_conv);
4563 }
4564
4565 uint32_t TS_C2Tuple_usizeTransactionZ_new(intptr_t a, int8_tArray b) {
4566         LDKTransaction b_ref;
4567         b_ref.datalen = *((uint32_t*)b);
4568         b_ref.data = MALLOC(b_ref.datalen, "LDKTransaction Bytes");
4569         memcpy(b_ref.data, (uint8_t*)(b + 4), b_ref.datalen);
4570         b_ref.data_is_owned = true;
4571         LDKC2Tuple_usizeTransactionZ* ret_ref = MALLOC(sizeof(LDKC2Tuple_usizeTransactionZ), "LDKC2Tuple_usizeTransactionZ");
4572         *ret_ref = C2Tuple_usizeTransactionZ_new(a, b_ref);
4573         // XXX: We likely need to clone here, but no _clone fn is available for Uint8Array
4574         return (long)ret_ref;
4575 }
4576
4577 void TS_CVec_C2Tuple_usizeTransactionZZ_free(uint32_tArray _res) {
4578         LDKCVec_C2Tuple_usizeTransactionZZ _res_constr;
4579         _res_constr.datalen = *((uint32_t*)_res);
4580         if (_res_constr.datalen > 0)
4581                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKC2Tuple_usizeTransactionZ), "LDKCVec_C2Tuple_usizeTransactionZZ Elements");
4582         else
4583                 _res_constr.data = NULL;
4584         uint32_t* _res_vals = (uint32_t*)(_res + 4);
4585         for (size_t e = 0; e < _res_constr.datalen; e++) {
4586                 uint32_t arr_conv_30 = _res_vals[e];
4587                 LDKC2Tuple_usizeTransactionZ arr_conv_30_conv = *(LDKC2Tuple_usizeTransactionZ*)arr_conv_30;
4588                 FREE((void*)arr_conv_30);
4589                 _res_constr.data[e] = arr_conv_30_conv;
4590         }
4591         CVec_C2Tuple_usizeTransactionZZ_free(_res_constr);
4592 }
4593
4594 uint32_t TS_CResult_NoneChannelMonitorUpdateErrZ_ok() {
4595         LDKCResult_NoneChannelMonitorUpdateErrZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneChannelMonitorUpdateErrZ), "LDKCResult_NoneChannelMonitorUpdateErrZ");
4596         *ret_conv = CResult_NoneChannelMonitorUpdateErrZ_ok();
4597         return (long)ret_conv;
4598 }
4599
4600 uint32_t TS_CResult_NoneChannelMonitorUpdateErrZ_err(uint32_t e) {
4601         LDKChannelMonitorUpdateErr e_conv = LDKChannelMonitorUpdateErr_from_js(e);
4602         LDKCResult_NoneChannelMonitorUpdateErrZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneChannelMonitorUpdateErrZ), "LDKCResult_NoneChannelMonitorUpdateErrZ");
4603         *ret_conv = CResult_NoneChannelMonitorUpdateErrZ_err(e_conv);
4604         return (long)ret_conv;
4605 }
4606
4607 void TS_CResult_NoneChannelMonitorUpdateErrZ_free(uint32_t _res) {
4608         LDKCResult_NoneChannelMonitorUpdateErrZ _res_conv = *(LDKCResult_NoneChannelMonitorUpdateErrZ*)_res;
4609         FREE((void*)_res);
4610         CResult_NoneChannelMonitorUpdateErrZ_free(_res_conv);
4611 }
4612
4613 void TS_CVec_MonitorEventZ_free(uint32_tArray _res) {
4614         LDKCVec_MonitorEventZ _res_constr;
4615         _res_constr.datalen = *((uint32_t*)_res);
4616         if (_res_constr.datalen > 0)
4617                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKMonitorEvent), "LDKCVec_MonitorEventZ Elements");
4618         else
4619                 _res_constr.data = NULL;
4620         uint32_t* _res_vals = (uint32_t*)(_res + 4);
4621         for (size_t o = 0; o < _res_constr.datalen; o++) {
4622                 uint32_t arr_conv_14 = _res_vals[o];
4623                 LDKMonitorEvent arr_conv_14_conv;
4624                 arr_conv_14_conv.inner = (void*)(arr_conv_14 & (~1));
4625                 arr_conv_14_conv.is_owned = (arr_conv_14 & 1) || (arr_conv_14 == 0);
4626                 _res_constr.data[o] = arr_conv_14_conv;
4627         }
4628         CVec_MonitorEventZ_free(_res_constr);
4629 }
4630
4631 uint32_t TS_CResult_ChannelMonitorUpdateDecodeErrorZ_ok(uint32_t o) {
4632         LDKChannelMonitorUpdate o_conv;
4633         o_conv.inner = (void*)(o & (~1));
4634         o_conv.is_owned = (o & 1) || (o == 0);
4635         if (o_conv.inner != NULL)
4636                 o_conv = ChannelMonitorUpdate_clone(&o_conv);
4637         LDKCResult_ChannelMonitorUpdateDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ChannelMonitorUpdateDecodeErrorZ), "LDKCResult_ChannelMonitorUpdateDecodeErrorZ");
4638         *ret_conv = CResult_ChannelMonitorUpdateDecodeErrorZ_ok(o_conv);
4639         return (long)ret_conv;
4640 }
4641
4642 uint32_t TS_CResult_ChannelMonitorUpdateDecodeErrorZ_err(uint32_t e) {
4643         LDKDecodeError e_conv;
4644         e_conv.inner = (void*)(e & (~1));
4645         e_conv.is_owned = (e & 1) || (e == 0);
4646         // Warning: we may need a move here but can't clone!
4647         LDKCResult_ChannelMonitorUpdateDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ChannelMonitorUpdateDecodeErrorZ), "LDKCResult_ChannelMonitorUpdateDecodeErrorZ");
4648         *ret_conv = CResult_ChannelMonitorUpdateDecodeErrorZ_err(e_conv);
4649         return (long)ret_conv;
4650 }
4651
4652 void TS_CResult_ChannelMonitorUpdateDecodeErrorZ_free(uint32_t _res) {
4653         LDKCResult_ChannelMonitorUpdateDecodeErrorZ _res_conv = *(LDKCResult_ChannelMonitorUpdateDecodeErrorZ*)_res;
4654         FREE((void*)_res);
4655         CResult_ChannelMonitorUpdateDecodeErrorZ_free(_res_conv);
4656 }
4657
4658 uint32_t TS_CResult_NoneMonitorUpdateErrorZ_ok() {
4659         LDKCResult_NoneMonitorUpdateErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneMonitorUpdateErrorZ), "LDKCResult_NoneMonitorUpdateErrorZ");
4660         *ret_conv = CResult_NoneMonitorUpdateErrorZ_ok();
4661         return (long)ret_conv;
4662 }
4663
4664 uint32_t TS_CResult_NoneMonitorUpdateErrorZ_err(uint32_t e) {
4665         LDKMonitorUpdateError e_conv;
4666         e_conv.inner = (void*)(e & (~1));
4667         e_conv.is_owned = (e & 1) || (e == 0);
4668         // Warning: we may need a move here but can't clone!
4669         LDKCResult_NoneMonitorUpdateErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneMonitorUpdateErrorZ), "LDKCResult_NoneMonitorUpdateErrorZ");
4670         *ret_conv = CResult_NoneMonitorUpdateErrorZ_err(e_conv);
4671         return (long)ret_conv;
4672 }
4673
4674 void TS_CResult_NoneMonitorUpdateErrorZ_free(uint32_t _res) {
4675         LDKCResult_NoneMonitorUpdateErrorZ _res_conv = *(LDKCResult_NoneMonitorUpdateErrorZ*)_res;
4676         FREE((void*)_res);
4677         CResult_NoneMonitorUpdateErrorZ_free(_res_conv);
4678 }
4679
4680 void TS_C2Tuple_OutPointScriptZ_free(uint32_t _res) {
4681         LDKC2Tuple_OutPointScriptZ _res_conv = *(LDKC2Tuple_OutPointScriptZ*)_res;
4682         FREE((void*)_res);
4683         C2Tuple_OutPointScriptZ_free(_res_conv);
4684 }
4685
4686 uint32_t TS_C2Tuple_OutPointScriptZ_new(uint32_t a, int8_tArray b) {
4687         LDKOutPoint a_conv;
4688         a_conv.inner = (void*)(a & (~1));
4689         a_conv.is_owned = (a & 1) || (a == 0);
4690         if (a_conv.inner != NULL)
4691                 a_conv = OutPoint_clone(&a_conv);
4692         LDKCVec_u8Z b_ref;
4693         b_ref.datalen = *((uint32_t*)b);
4694         b_ref.data = MALLOC(b_ref.datalen, "LDKCVec_u8Z Bytes");
4695         memcpy(b_ref.data, (uint8_t*)(b + 4), b_ref.datalen);
4696         LDKC2Tuple_OutPointScriptZ* ret_ref = MALLOC(sizeof(LDKC2Tuple_OutPointScriptZ), "LDKC2Tuple_OutPointScriptZ");
4697         *ret_ref = C2Tuple_OutPointScriptZ_new(a_conv, b_ref);
4698         ret_ref->a = OutPoint_clone(&ret_ref->a);
4699         ret_ref->b = CVec_u8Z_clone(&ret_ref->b);
4700         return (long)ret_ref;
4701 }
4702
4703 void TS_CVec_TransactionZ_free(ptrArray _res) {
4704         LDKCVec_TransactionZ _res_constr;
4705         _res_constr.datalen = *((uint32_t*)_res);
4706         if (_res_constr.datalen > 0)
4707                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKTransaction), "LDKCVec_TransactionZ Elements");
4708         else
4709                 _res_constr.data = NULL;
4710         int8_tArray* _res_vals = (int8_tArray*)(_res + 4);
4711         for (size_t m = 0; m < _res_constr.datalen; m++) {
4712                 int8_tArray arr_conv_12 = _res_vals[m];
4713                 LDKTransaction arr_conv_12_ref;
4714                 arr_conv_12_ref.datalen = *((uint32_t*)arr_conv_12);
4715                 arr_conv_12_ref.data = MALLOC(arr_conv_12_ref.datalen, "LDKTransaction Bytes");
4716                 memcpy(arr_conv_12_ref.data, (uint8_t*)(arr_conv_12 + 4), arr_conv_12_ref.datalen);
4717                 arr_conv_12_ref.data_is_owned = true;
4718                 _res_constr.data[m] = arr_conv_12_ref;
4719         }
4720         CVec_TransactionZ_free(_res_constr);
4721 }
4722
4723 void TS_C2Tuple_u32TxOutZ_free(uint32_t _res) {
4724         LDKC2Tuple_u32TxOutZ _res_conv = *(LDKC2Tuple_u32TxOutZ*)_res;
4725         FREE((void*)_res);
4726         C2Tuple_u32TxOutZ_free(_res_conv);
4727 }
4728
4729 uint32_t TS_C2Tuple_u32TxOutZ_new(int32_t a, uint32_t b) {
4730         LDKTxOut b_conv = *(LDKTxOut*)b;
4731         FREE((void*)b);
4732         LDKC2Tuple_u32TxOutZ* ret_ref = MALLOC(sizeof(LDKC2Tuple_u32TxOutZ), "LDKC2Tuple_u32TxOutZ");
4733         *ret_ref = C2Tuple_u32TxOutZ_new(a, b_conv);
4734         // XXX: We likely need to clone here, but no _clone fn is available for TxOut
4735         return (long)ret_ref;
4736 }
4737
4738 void TS_CVec_C2Tuple_u32TxOutZZ_free(uint32_tArray _res) {
4739         LDKCVec_C2Tuple_u32TxOutZZ _res_constr;
4740         _res_constr.datalen = *((uint32_t*)_res);
4741         if (_res_constr.datalen > 0)
4742                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKC2Tuple_u32TxOutZ), "LDKCVec_C2Tuple_u32TxOutZZ Elements");
4743         else
4744                 _res_constr.data = NULL;
4745         uint32_t* _res_vals = (uint32_t*)(_res + 4);
4746         for (size_t z = 0; z < _res_constr.datalen; z++) {
4747                 uint32_t arr_conv_25 = _res_vals[z];
4748                 LDKC2Tuple_u32TxOutZ arr_conv_25_conv = *(LDKC2Tuple_u32TxOutZ*)arr_conv_25;
4749                 FREE((void*)arr_conv_25);
4750                 _res_constr.data[z] = arr_conv_25_conv;
4751         }
4752         CVec_C2Tuple_u32TxOutZZ_free(_res_constr);
4753 }
4754
4755 void TS_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ_free(uint32_t _res) {
4756         LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ _res_conv = *(LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ*)_res;
4757         FREE((void*)_res);
4758         C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ_free(_res_conv);
4759 }
4760
4761 uint32_t TS_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ_new(int8_tArray a, uint32_tArray b) {
4762         LDKThirtyTwoBytes a_ref;
4763         CHECK(*((uint32_t*)a) == 32);
4764         memcpy(a_ref.data, (uint8_t*)(a + 4), 32);
4765         LDKCVec_C2Tuple_u32TxOutZZ b_constr;
4766         b_constr.datalen = *((uint32_t*)b);
4767         if (b_constr.datalen > 0)
4768                 b_constr.data = MALLOC(b_constr.datalen * sizeof(LDKC2Tuple_u32TxOutZ), "LDKCVec_C2Tuple_u32TxOutZZ Elements");
4769         else
4770                 b_constr.data = NULL;
4771         uint32_t* b_vals = (uint32_t*)(b + 4);
4772         for (size_t z = 0; z < b_constr.datalen; z++) {
4773                 uint32_t arr_conv_25 = b_vals[z];
4774                 LDKC2Tuple_u32TxOutZ arr_conv_25_conv = *(LDKC2Tuple_u32TxOutZ*)arr_conv_25;
4775                 FREE((void*)arr_conv_25);
4776                 b_constr.data[z] = arr_conv_25_conv;
4777         }
4778         LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ* ret_ref = MALLOC(sizeof(LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ), "LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ");
4779         *ret_ref = C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ_new(a_ref, b_constr);
4780         ret_ref->a = ThirtyTwoBytes_clone(&ret_ref->a);
4781         // XXX: We likely need to clone here, but no _clone fn is available for TwoTuple<Number, TxOut>[]
4782         return (long)ret_ref;
4783 }
4784
4785 void TS_CVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ_free(uint32_tArray _res) {
4786         LDKCVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ _res_constr;
4787         _res_constr.datalen = *((uint32_t*)_res);
4788         if (_res_constr.datalen > 0)
4789                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ), "LDKCVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ Elements");
4790         else
4791                 _res_constr.data = NULL;
4792         uint32_t* _res_vals = (uint32_t*)(_res + 4);
4793         for (size_t x = 0; x < _res_constr.datalen; x++) {
4794                 uint32_t arr_conv_49 = _res_vals[x];
4795                 LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ arr_conv_49_conv = *(LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ*)arr_conv_49;
4796                 FREE((void*)arr_conv_49);
4797                 _res_constr.data[x] = arr_conv_49_conv;
4798         }
4799         CVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ_free(_res_constr);
4800 }
4801
4802 void TS_C2Tuple_BlockHashChannelMonitorZ_free(uint32_t _res) {
4803         LDKC2Tuple_BlockHashChannelMonitorZ _res_conv = *(LDKC2Tuple_BlockHashChannelMonitorZ*)_res;
4804         FREE((void*)_res);
4805         C2Tuple_BlockHashChannelMonitorZ_free(_res_conv);
4806 }
4807
4808 uint32_t TS_C2Tuple_BlockHashChannelMonitorZ_new(int8_tArray a, uint32_t b) {
4809         LDKThirtyTwoBytes a_ref;
4810         CHECK(*((uint32_t*)a) == 32);
4811         memcpy(a_ref.data, (uint8_t*)(a + 4), 32);
4812         LDKChannelMonitor b_conv;
4813         b_conv.inner = (void*)(b & (~1));
4814         b_conv.is_owned = (b & 1) || (b == 0);
4815         // Warning: we may need a move here but can't clone!
4816         LDKC2Tuple_BlockHashChannelMonitorZ* ret_ref = MALLOC(sizeof(LDKC2Tuple_BlockHashChannelMonitorZ), "LDKC2Tuple_BlockHashChannelMonitorZ");
4817         *ret_ref = C2Tuple_BlockHashChannelMonitorZ_new(a_ref, b_conv);
4818         ret_ref->a = ThirtyTwoBytes_clone(&ret_ref->a);
4819         // XXX: We likely need to clone here, but no _clone fn is available for ChannelMonitor
4820         return (long)ret_ref;
4821 }
4822
4823 uint32_t TS_CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ_ok(uint32_t o) {
4824         LDKC2Tuple_BlockHashChannelMonitorZ o_conv = *(LDKC2Tuple_BlockHashChannelMonitorZ*)o;
4825         FREE((void*)o);
4826         LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ), "LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ");
4827         *ret_conv = CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ_ok(o_conv);
4828         return (long)ret_conv;
4829 }
4830
4831 uint32_t TS_CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ_err(uint32_t e) {
4832         LDKDecodeError e_conv;
4833         e_conv.inner = (void*)(e & (~1));
4834         e_conv.is_owned = (e & 1) || (e == 0);
4835         // Warning: we may need a move here but can't clone!
4836         LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ), "LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ");
4837         *ret_conv = CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ_err(e_conv);
4838         return (long)ret_conv;
4839 }
4840
4841 void TS_CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ_free(uint32_t _res) {
4842         LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ _res_conv = *(LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ*)_res;
4843         FREE((void*)_res);
4844         CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ_free(_res_conv);
4845 }
4846
4847 void TS_C2Tuple_u64u64Z_free(uint32_t _res) {
4848         LDKC2Tuple_u64u64Z _res_conv = *(LDKC2Tuple_u64u64Z*)_res;
4849         FREE((void*)_res);
4850         C2Tuple_u64u64Z_free(_res_conv);
4851 }
4852
4853 uint32_t TS_C2Tuple_u64u64Z_new(int64_t a, int64_t b) {
4854         LDKC2Tuple_u64u64Z* ret_ref = MALLOC(sizeof(LDKC2Tuple_u64u64Z), "LDKC2Tuple_u64u64Z");
4855         *ret_ref = C2Tuple_u64u64Z_new(a, b);
4856         return (long)ret_ref;
4857 }
4858
4859 uint32_t TS_CResult_SpendableOutputDescriptorDecodeErrorZ_ok(uint32_t o) {
4860         LDKSpendableOutputDescriptor o_conv = *(LDKSpendableOutputDescriptor*)o;
4861         FREE((void*)o);
4862         LDKCResult_SpendableOutputDescriptorDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_SpendableOutputDescriptorDecodeErrorZ), "LDKCResult_SpendableOutputDescriptorDecodeErrorZ");
4863         *ret_conv = CResult_SpendableOutputDescriptorDecodeErrorZ_ok(o_conv);
4864         return (long)ret_conv;
4865 }
4866
4867 uint32_t TS_CResult_SpendableOutputDescriptorDecodeErrorZ_err(uint32_t e) {
4868         LDKDecodeError e_conv;
4869         e_conv.inner = (void*)(e & (~1));
4870         e_conv.is_owned = (e & 1) || (e == 0);
4871         // Warning: we may need a move here but can't clone!
4872         LDKCResult_SpendableOutputDescriptorDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_SpendableOutputDescriptorDecodeErrorZ), "LDKCResult_SpendableOutputDescriptorDecodeErrorZ");
4873         *ret_conv = CResult_SpendableOutputDescriptorDecodeErrorZ_err(e_conv);
4874         return (long)ret_conv;
4875 }
4876
4877 void TS_CResult_SpendableOutputDescriptorDecodeErrorZ_free(uint32_t _res) {
4878         LDKCResult_SpendableOutputDescriptorDecodeErrorZ _res_conv = *(LDKCResult_SpendableOutputDescriptorDecodeErrorZ*)_res;
4879         FREE((void*)_res);
4880         CResult_SpendableOutputDescriptorDecodeErrorZ_free(_res_conv);
4881 }
4882
4883 void TS_CVec_SignatureZ_free(ptrArray _res) {
4884         LDKCVec_SignatureZ _res_constr;
4885         _res_constr.datalen = *((uint32_t*)_res);
4886         if (_res_constr.datalen > 0)
4887                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKSignature), "LDKCVec_SignatureZ Elements");
4888         else
4889                 _res_constr.data = NULL;
4890         int8_tArray* _res_vals = (int8_tArray*)(_res + 4);
4891         for (size_t m = 0; m < _res_constr.datalen; m++) {
4892                 int8_tArray arr_conv_12 = _res_vals[m];
4893                 LDKSignature arr_conv_12_ref;
4894                 CHECK(*((uint32_t*)arr_conv_12) == 64);
4895                 memcpy(arr_conv_12_ref.compact_form, (uint8_t*)(arr_conv_12 + 4), 64);
4896                 _res_constr.data[m] = arr_conv_12_ref;
4897         }
4898         CVec_SignatureZ_free(_res_constr);
4899 }
4900
4901 void TS_C2Tuple_SignatureCVec_SignatureZZ_free(uint32_t _res) {
4902         LDKC2Tuple_SignatureCVec_SignatureZZ _res_conv = *(LDKC2Tuple_SignatureCVec_SignatureZZ*)_res;
4903         FREE((void*)_res);
4904         C2Tuple_SignatureCVec_SignatureZZ_free(_res_conv);
4905 }
4906
4907 uint32_t TS_C2Tuple_SignatureCVec_SignatureZZ_new(int8_tArray a, ptrArray b) {
4908         LDKSignature a_ref;
4909         CHECK(*((uint32_t*)a) == 64);
4910         memcpy(a_ref.compact_form, (uint8_t*)(a + 4), 64);
4911         LDKCVec_SignatureZ b_constr;
4912         b_constr.datalen = *((uint32_t*)b);
4913         if (b_constr.datalen > 0)
4914                 b_constr.data = MALLOC(b_constr.datalen * sizeof(LDKSignature), "LDKCVec_SignatureZ Elements");
4915         else
4916                 b_constr.data = NULL;
4917         int8_tArray* b_vals = (int8_tArray*)(b + 4);
4918         for (size_t m = 0; m < b_constr.datalen; m++) {
4919                 int8_tArray arr_conv_12 = b_vals[m];
4920                 LDKSignature arr_conv_12_ref;
4921                 CHECK(*((uint32_t*)arr_conv_12) == 64);
4922                 memcpy(arr_conv_12_ref.compact_form, (uint8_t*)(arr_conv_12 + 4), 64);
4923                 b_constr.data[m] = arr_conv_12_ref;
4924         }
4925         LDKC2Tuple_SignatureCVec_SignatureZZ* ret_ref = MALLOC(sizeof(LDKC2Tuple_SignatureCVec_SignatureZZ), "LDKC2Tuple_SignatureCVec_SignatureZZ");
4926         *ret_ref = C2Tuple_SignatureCVec_SignatureZZ_new(a_ref, b_constr);
4927         // XXX: We likely need to clone here, but no _clone fn is available for Uint8Array
4928         // XXX: We likely need to clone here, but no _clone fn is available for Uint8Array[]
4929         return (long)ret_ref;
4930 }
4931
4932 uint32_t TS_CResult_C2Tuple_SignatureCVec_SignatureZZNoneZ_ok(uint32_t o) {
4933         LDKC2Tuple_SignatureCVec_SignatureZZ o_conv = *(LDKC2Tuple_SignatureCVec_SignatureZZ*)o;
4934         FREE((void*)o);
4935         LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ), "LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ");
4936         *ret_conv = CResult_C2Tuple_SignatureCVec_SignatureZZNoneZ_ok(o_conv);
4937         return (long)ret_conv;
4938 }
4939
4940 uint32_t TS_CResult_C2Tuple_SignatureCVec_SignatureZZNoneZ_err() {
4941         LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ), "LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ");
4942         *ret_conv = CResult_C2Tuple_SignatureCVec_SignatureZZNoneZ_err();
4943         return (long)ret_conv;
4944 }
4945
4946 void TS_CResult_C2Tuple_SignatureCVec_SignatureZZNoneZ_free(uint32_t _res) {
4947         LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ _res_conv = *(LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ*)_res;
4948         FREE((void*)_res);
4949         CResult_C2Tuple_SignatureCVec_SignatureZZNoneZ_free(_res_conv);
4950 }
4951
4952 uint32_t TS_CResult_SignatureNoneZ_ok(int8_tArray o) {
4953         LDKSignature o_ref;
4954         CHECK(*((uint32_t*)o) == 64);
4955         memcpy(o_ref.compact_form, (uint8_t*)(o + 4), 64);
4956         LDKCResult_SignatureNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_SignatureNoneZ), "LDKCResult_SignatureNoneZ");
4957         *ret_conv = CResult_SignatureNoneZ_ok(o_ref);
4958         return (long)ret_conv;
4959 }
4960
4961 uint32_t TS_CResult_SignatureNoneZ_err() {
4962         LDKCResult_SignatureNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_SignatureNoneZ), "LDKCResult_SignatureNoneZ");
4963         *ret_conv = CResult_SignatureNoneZ_err();
4964         return (long)ret_conv;
4965 }
4966
4967 void TS_CResult_SignatureNoneZ_free(uint32_t _res) {
4968         LDKCResult_SignatureNoneZ _res_conv = *(LDKCResult_SignatureNoneZ*)_res;
4969         FREE((void*)_res);
4970         CResult_SignatureNoneZ_free(_res_conv);
4971 }
4972
4973 uint32_t TS_CResult_CVec_SignatureZNoneZ_ok(ptrArray o) {
4974         LDKCVec_SignatureZ o_constr;
4975         o_constr.datalen = *((uint32_t*)o);
4976         if (o_constr.datalen > 0)
4977                 o_constr.data = MALLOC(o_constr.datalen * sizeof(LDKSignature), "LDKCVec_SignatureZ Elements");
4978         else
4979                 o_constr.data = NULL;
4980         int8_tArray* o_vals = (int8_tArray*)(o + 4);
4981         for (size_t m = 0; m < o_constr.datalen; m++) {
4982                 int8_tArray arr_conv_12 = o_vals[m];
4983                 LDKSignature arr_conv_12_ref;
4984                 CHECK(*((uint32_t*)arr_conv_12) == 64);
4985                 memcpy(arr_conv_12_ref.compact_form, (uint8_t*)(arr_conv_12 + 4), 64);
4986                 o_constr.data[m] = arr_conv_12_ref;
4987         }
4988         LDKCResult_CVec_SignatureZNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_CVec_SignatureZNoneZ), "LDKCResult_CVec_SignatureZNoneZ");
4989         *ret_conv = CResult_CVec_SignatureZNoneZ_ok(o_constr);
4990         return (long)ret_conv;
4991 }
4992
4993 uint32_t TS_CResult_CVec_SignatureZNoneZ_err() {
4994         LDKCResult_CVec_SignatureZNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_CVec_SignatureZNoneZ), "LDKCResult_CVec_SignatureZNoneZ");
4995         *ret_conv = CResult_CVec_SignatureZNoneZ_err();
4996         return (long)ret_conv;
4997 }
4998
4999 void TS_CResult_CVec_SignatureZNoneZ_free(uint32_t _res) {
5000         LDKCResult_CVec_SignatureZNoneZ _res_conv = *(LDKCResult_CVec_SignatureZNoneZ*)_res;
5001         FREE((void*)_res);
5002         CResult_CVec_SignatureZNoneZ_free(_res_conv);
5003 }
5004
5005 uint32_t TS_CResult_ChanKeySignerDecodeErrorZ_ok(uint32_t o) {
5006         LDKChannelKeys o_conv = *(LDKChannelKeys*)o;
5007         LDKCResult_ChanKeySignerDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ChanKeySignerDecodeErrorZ), "LDKCResult_ChanKeySignerDecodeErrorZ");
5008         *ret_conv = CResult_ChanKeySignerDecodeErrorZ_ok(o_conv);
5009         return (long)ret_conv;
5010 }
5011
5012 uint32_t TS_CResult_ChanKeySignerDecodeErrorZ_err(uint32_t e) {
5013         LDKDecodeError e_conv;
5014         e_conv.inner = (void*)(e & (~1));
5015         e_conv.is_owned = (e & 1) || (e == 0);
5016         // Warning: we may need a move here but can't clone!
5017         LDKCResult_ChanKeySignerDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ChanKeySignerDecodeErrorZ), "LDKCResult_ChanKeySignerDecodeErrorZ");
5018         *ret_conv = CResult_ChanKeySignerDecodeErrorZ_err(e_conv);
5019         return (long)ret_conv;
5020 }
5021
5022 void TS_CResult_ChanKeySignerDecodeErrorZ_free(uint32_t _res) {
5023         LDKCResult_ChanKeySignerDecodeErrorZ _res_conv = *(LDKCResult_ChanKeySignerDecodeErrorZ*)_res;
5024         FREE((void*)_res);
5025         CResult_ChanKeySignerDecodeErrorZ_free(_res_conv);
5026 }
5027
5028 uint32_t TS_CResult_InMemoryChannelKeysDecodeErrorZ_ok(uint32_t o) {
5029         LDKInMemoryChannelKeys o_conv;
5030         o_conv.inner = (void*)(o & (~1));
5031         o_conv.is_owned = (o & 1) || (o == 0);
5032         if (o_conv.inner != NULL)
5033                 o_conv = InMemoryChannelKeys_clone(&o_conv);
5034         LDKCResult_InMemoryChannelKeysDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_InMemoryChannelKeysDecodeErrorZ), "LDKCResult_InMemoryChannelKeysDecodeErrorZ");
5035         *ret_conv = CResult_InMemoryChannelKeysDecodeErrorZ_ok(o_conv);
5036         return (long)ret_conv;
5037 }
5038
5039 uint32_t TS_CResult_InMemoryChannelKeysDecodeErrorZ_err(uint32_t e) {
5040         LDKDecodeError e_conv;
5041         e_conv.inner = (void*)(e & (~1));
5042         e_conv.is_owned = (e & 1) || (e == 0);
5043         // Warning: we may need a move here but can't clone!
5044         LDKCResult_InMemoryChannelKeysDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_InMemoryChannelKeysDecodeErrorZ), "LDKCResult_InMemoryChannelKeysDecodeErrorZ");
5045         *ret_conv = CResult_InMemoryChannelKeysDecodeErrorZ_err(e_conv);
5046         return (long)ret_conv;
5047 }
5048
5049 void TS_CResult_InMemoryChannelKeysDecodeErrorZ_free(uint32_t _res) {
5050         LDKCResult_InMemoryChannelKeysDecodeErrorZ _res_conv = *(LDKCResult_InMemoryChannelKeysDecodeErrorZ*)_res;
5051         FREE((void*)_res);
5052         CResult_InMemoryChannelKeysDecodeErrorZ_free(_res_conv);
5053 }
5054
5055 uint32_t TS_CResult_TxOutAccessErrorZ_ok(uint32_t o) {
5056         LDKTxOut o_conv = *(LDKTxOut*)o;
5057         FREE((void*)o);
5058         LDKCResult_TxOutAccessErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_TxOutAccessErrorZ), "LDKCResult_TxOutAccessErrorZ");
5059         *ret_conv = CResult_TxOutAccessErrorZ_ok(o_conv);
5060         return (long)ret_conv;
5061 }
5062
5063 uint32_t TS_CResult_TxOutAccessErrorZ_err(uint32_t e) {
5064         LDKAccessError e_conv = LDKAccessError_from_js(e);
5065         LDKCResult_TxOutAccessErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_TxOutAccessErrorZ), "LDKCResult_TxOutAccessErrorZ");
5066         *ret_conv = CResult_TxOutAccessErrorZ_err(e_conv);
5067         return (long)ret_conv;
5068 }
5069
5070 void TS_CResult_TxOutAccessErrorZ_free(uint32_t _res) {
5071         LDKCResult_TxOutAccessErrorZ _res_conv = *(LDKCResult_TxOutAccessErrorZ*)_res;
5072         FREE((void*)_res);
5073         CResult_TxOutAccessErrorZ_free(_res_conv);
5074 }
5075
5076 uint32_t TS_CResult_NoneAPIErrorZ_ok() {
5077         LDKCResult_NoneAPIErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneAPIErrorZ), "LDKCResult_NoneAPIErrorZ");
5078         *ret_conv = CResult_NoneAPIErrorZ_ok();
5079         return (long)ret_conv;
5080 }
5081
5082 uint32_t TS_CResult_NoneAPIErrorZ_err(uint32_t e) {
5083         LDKAPIError e_conv = *(LDKAPIError*)e;
5084         FREE((void*)e);
5085         LDKCResult_NoneAPIErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneAPIErrorZ), "LDKCResult_NoneAPIErrorZ");
5086         *ret_conv = CResult_NoneAPIErrorZ_err(e_conv);
5087         return (long)ret_conv;
5088 }
5089
5090 void TS_CResult_NoneAPIErrorZ_free(uint32_t _res) {
5091         LDKCResult_NoneAPIErrorZ _res_conv = *(LDKCResult_NoneAPIErrorZ*)_res;
5092         FREE((void*)_res);
5093         CResult_NoneAPIErrorZ_free(_res_conv);
5094 }
5095
5096 void TS_CVec_ChannelDetailsZ_free(uint32_tArray _res) {
5097         LDKCVec_ChannelDetailsZ _res_constr;
5098         _res_constr.datalen = *((uint32_t*)_res);
5099         if (_res_constr.datalen > 0)
5100                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKChannelDetails), "LDKCVec_ChannelDetailsZ Elements");
5101         else
5102                 _res_constr.data = NULL;
5103         uint32_t* _res_vals = (uint32_t*)(_res + 4);
5104         for (size_t q = 0; q < _res_constr.datalen; q++) {
5105                 uint32_t arr_conv_16 = _res_vals[q];
5106                 LDKChannelDetails arr_conv_16_conv;
5107                 arr_conv_16_conv.inner = (void*)(arr_conv_16 & (~1));
5108                 arr_conv_16_conv.is_owned = (arr_conv_16 & 1) || (arr_conv_16 == 0);
5109                 _res_constr.data[q] = arr_conv_16_conv;
5110         }
5111         CVec_ChannelDetailsZ_free(_res_constr);
5112 }
5113
5114 uint32_t TS_CResult_NonePaymentSendFailureZ_ok() {
5115         LDKCResult_NonePaymentSendFailureZ* ret_conv = MALLOC(sizeof(LDKCResult_NonePaymentSendFailureZ), "LDKCResult_NonePaymentSendFailureZ");
5116         *ret_conv = CResult_NonePaymentSendFailureZ_ok();
5117         return (long)ret_conv;
5118 }
5119
5120 uint32_t TS_CResult_NonePaymentSendFailureZ_err(uint32_t e) {
5121         LDKPaymentSendFailure e_conv;
5122         e_conv.inner = (void*)(e & (~1));
5123         e_conv.is_owned = (e & 1) || (e == 0);
5124         // Warning: we may need a move here but can't clone!
5125         LDKCResult_NonePaymentSendFailureZ* ret_conv = MALLOC(sizeof(LDKCResult_NonePaymentSendFailureZ), "LDKCResult_NonePaymentSendFailureZ");
5126         *ret_conv = CResult_NonePaymentSendFailureZ_err(e_conv);
5127         return (long)ret_conv;
5128 }
5129
5130 void TS_CResult_NonePaymentSendFailureZ_free(uint32_t _res) {
5131         LDKCResult_NonePaymentSendFailureZ _res_conv = *(LDKCResult_NonePaymentSendFailureZ*)_res;
5132         FREE((void*)_res);
5133         CResult_NonePaymentSendFailureZ_free(_res_conv);
5134 }
5135
5136 void TS_CVec_NetAddressZ_free(uint32_tArray _res) {
5137         LDKCVec_NetAddressZ _res_constr;
5138         _res_constr.datalen = *((uint32_t*)_res);
5139         if (_res_constr.datalen > 0)
5140                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKNetAddress), "LDKCVec_NetAddressZ Elements");
5141         else
5142                 _res_constr.data = NULL;
5143         uint32_t* _res_vals = (uint32_t*)(_res + 4);
5144         for (size_t m = 0; m < _res_constr.datalen; m++) {
5145                 uint32_t arr_conv_12 = _res_vals[m];
5146                 LDKNetAddress arr_conv_12_conv = *(LDKNetAddress*)arr_conv_12;
5147                 FREE((void*)arr_conv_12);
5148                 _res_constr.data[m] = arr_conv_12_conv;
5149         }
5150         CVec_NetAddressZ_free(_res_constr);
5151 }
5152
5153 void TS_CVec_ChannelMonitorZ_free(uint32_tArray _res) {
5154         LDKCVec_ChannelMonitorZ _res_constr;
5155         _res_constr.datalen = *((uint32_t*)_res);
5156         if (_res_constr.datalen > 0)
5157                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKChannelMonitor), "LDKCVec_ChannelMonitorZ Elements");
5158         else
5159                 _res_constr.data = NULL;
5160         uint32_t* _res_vals = (uint32_t*)(_res + 4);
5161         for (size_t q = 0; q < _res_constr.datalen; q++) {
5162                 uint32_t arr_conv_16 = _res_vals[q];
5163                 LDKChannelMonitor arr_conv_16_conv;
5164                 arr_conv_16_conv.inner = (void*)(arr_conv_16 & (~1));
5165                 arr_conv_16_conv.is_owned = (arr_conv_16 & 1) || (arr_conv_16 == 0);
5166                 _res_constr.data[q] = arr_conv_16_conv;
5167         }
5168         CVec_ChannelMonitorZ_free(_res_constr);
5169 }
5170
5171 void TS_C2Tuple_BlockHashChannelManagerZ_free(uint32_t _res) {
5172         LDKC2Tuple_BlockHashChannelManagerZ _res_conv = *(LDKC2Tuple_BlockHashChannelManagerZ*)_res;
5173         FREE((void*)_res);
5174         C2Tuple_BlockHashChannelManagerZ_free(_res_conv);
5175 }
5176
5177 uint32_t TS_C2Tuple_BlockHashChannelManagerZ_new(int8_tArray a, uint32_t b) {
5178         LDKThirtyTwoBytes a_ref;
5179         CHECK(*((uint32_t*)a) == 32);
5180         memcpy(a_ref.data, (uint8_t*)(a + 4), 32);
5181         LDKChannelManager b_conv;
5182         b_conv.inner = (void*)(b & (~1));
5183         b_conv.is_owned = (b & 1) || (b == 0);
5184         // Warning: we may need a move here but can't clone!
5185         LDKC2Tuple_BlockHashChannelManagerZ* ret_ref = MALLOC(sizeof(LDKC2Tuple_BlockHashChannelManagerZ), "LDKC2Tuple_BlockHashChannelManagerZ");
5186         *ret_ref = C2Tuple_BlockHashChannelManagerZ_new(a_ref, b_conv);
5187         ret_ref->a = ThirtyTwoBytes_clone(&ret_ref->a);
5188         // XXX: We likely need to clone here, but no _clone fn is available for ChannelManager
5189         return (long)ret_ref;
5190 }
5191
5192 uint32_t TS_CResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ_ok(uint32_t o) {
5193         LDKC2Tuple_BlockHashChannelManagerZ o_conv = *(LDKC2Tuple_BlockHashChannelManagerZ*)o;
5194         FREE((void*)o);
5195         LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ), "LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ");
5196         *ret_conv = CResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ_ok(o_conv);
5197         return (long)ret_conv;
5198 }
5199
5200 uint32_t TS_CResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ_err(uint32_t e) {
5201         LDKDecodeError e_conv;
5202         e_conv.inner = (void*)(e & (~1));
5203         e_conv.is_owned = (e & 1) || (e == 0);
5204         // Warning: we may need a move here but can't clone!
5205         LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ), "LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ");
5206         *ret_conv = CResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ_err(e_conv);
5207         return (long)ret_conv;
5208 }
5209
5210 void TS_CResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ_free(uint32_t _res) {
5211         LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ _res_conv = *(LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ*)_res;
5212         FREE((void*)_res);
5213         CResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ_free(_res_conv);
5214 }
5215
5216 uint32_t TS_CResult_NetAddressu8Z_ok(uint32_t o) {
5217         LDKNetAddress o_conv = *(LDKNetAddress*)o;
5218         FREE((void*)o);
5219         LDKCResult_NetAddressu8Z* ret_conv = MALLOC(sizeof(LDKCResult_NetAddressu8Z), "LDKCResult_NetAddressu8Z");
5220         *ret_conv = CResult_NetAddressu8Z_ok(o_conv);
5221         return (long)ret_conv;
5222 }
5223
5224 uint32_t TS_CResult_NetAddressu8Z_err(int8_t e) {
5225         LDKCResult_NetAddressu8Z* ret_conv = MALLOC(sizeof(LDKCResult_NetAddressu8Z), "LDKCResult_NetAddressu8Z");
5226         *ret_conv = CResult_NetAddressu8Z_err(e);
5227         return (long)ret_conv;
5228 }
5229
5230 void TS_CResult_NetAddressu8Z_free(uint32_t _res) {
5231         LDKCResult_NetAddressu8Z _res_conv = *(LDKCResult_NetAddressu8Z*)_res;
5232         FREE((void*)_res);
5233         CResult_NetAddressu8Z_free(_res_conv);
5234 }
5235
5236 uint32_t TS_CResult_CResult_NetAddressu8ZDecodeErrorZ_ok(uint32_t o) {
5237         LDKCResult_NetAddressu8Z o_conv = *(LDKCResult_NetAddressu8Z*)o;
5238         FREE((void*)o);
5239         LDKCResult_CResult_NetAddressu8ZDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_CResult_NetAddressu8ZDecodeErrorZ), "LDKCResult_CResult_NetAddressu8ZDecodeErrorZ");
5240         *ret_conv = CResult_CResult_NetAddressu8ZDecodeErrorZ_ok(o_conv);
5241         return (long)ret_conv;
5242 }
5243
5244 uint32_t TS_CResult_CResult_NetAddressu8ZDecodeErrorZ_err(uint32_t e) {
5245         LDKDecodeError e_conv;
5246         e_conv.inner = (void*)(e & (~1));
5247         e_conv.is_owned = (e & 1) || (e == 0);
5248         // Warning: we may need a move here but can't clone!
5249         LDKCResult_CResult_NetAddressu8ZDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_CResult_NetAddressu8ZDecodeErrorZ), "LDKCResult_CResult_NetAddressu8ZDecodeErrorZ");
5250         *ret_conv = CResult_CResult_NetAddressu8ZDecodeErrorZ_err(e_conv);
5251         return (long)ret_conv;
5252 }
5253
5254 void TS_CResult_CResult_NetAddressu8ZDecodeErrorZ_free(uint32_t _res) {
5255         LDKCResult_CResult_NetAddressu8ZDecodeErrorZ _res_conv = *(LDKCResult_CResult_NetAddressu8ZDecodeErrorZ*)_res;
5256         FREE((void*)_res);
5257         CResult_CResult_NetAddressu8ZDecodeErrorZ_free(_res_conv);
5258 }
5259
5260 void TS_CVec_u64Z_free(int64_tArray _res) {
5261         LDKCVec_u64Z _res_constr;
5262         _res_constr.datalen = *((uint32_t*)_res);
5263         if (_res_constr.datalen > 0)
5264                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(int64_t), "LDKCVec_u64Z Elements");
5265         else
5266                 _res_constr.data = NULL;
5267         int64_t* _res_vals = (int64_t*)(_res + 4);
5268         for (size_t i = 0; i < _res_constr.datalen; i++) {
5269                 int64_t arr_conv_8 = _res_vals[i];
5270                 _res_constr.data[i] = arr_conv_8;
5271         }
5272         CVec_u64Z_free(_res_constr);
5273 }
5274
5275 void TS_CVec_UpdateAddHTLCZ_free(uint32_tArray _res) {
5276         LDKCVec_UpdateAddHTLCZ _res_constr;
5277         _res_constr.datalen = *((uint32_t*)_res);
5278         if (_res_constr.datalen > 0)
5279                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKUpdateAddHTLC), "LDKCVec_UpdateAddHTLCZ Elements");
5280         else
5281                 _res_constr.data = NULL;
5282         uint32_t* _res_vals = (uint32_t*)(_res + 4);
5283         for (size_t p = 0; p < _res_constr.datalen; p++) {
5284                 uint32_t arr_conv_15 = _res_vals[p];
5285                 LDKUpdateAddHTLC arr_conv_15_conv;
5286                 arr_conv_15_conv.inner = (void*)(arr_conv_15 & (~1));
5287                 arr_conv_15_conv.is_owned = (arr_conv_15 & 1) || (arr_conv_15 == 0);
5288                 _res_constr.data[p] = arr_conv_15_conv;
5289         }
5290         CVec_UpdateAddHTLCZ_free(_res_constr);
5291 }
5292
5293 void TS_CVec_UpdateFulfillHTLCZ_free(uint32_tArray _res) {
5294         LDKCVec_UpdateFulfillHTLCZ _res_constr;
5295         _res_constr.datalen = *((uint32_t*)_res);
5296         if (_res_constr.datalen > 0)
5297                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKUpdateFulfillHTLC), "LDKCVec_UpdateFulfillHTLCZ Elements");
5298         else
5299                 _res_constr.data = NULL;
5300         uint32_t* _res_vals = (uint32_t*)(_res + 4);
5301         for (size_t t = 0; t < _res_constr.datalen; t++) {
5302                 uint32_t arr_conv_19 = _res_vals[t];
5303                 LDKUpdateFulfillHTLC arr_conv_19_conv;
5304                 arr_conv_19_conv.inner = (void*)(arr_conv_19 & (~1));
5305                 arr_conv_19_conv.is_owned = (arr_conv_19 & 1) || (arr_conv_19 == 0);
5306                 _res_constr.data[t] = arr_conv_19_conv;
5307         }
5308         CVec_UpdateFulfillHTLCZ_free(_res_constr);
5309 }
5310
5311 void TS_CVec_UpdateFailHTLCZ_free(uint32_tArray _res) {
5312         LDKCVec_UpdateFailHTLCZ _res_constr;
5313         _res_constr.datalen = *((uint32_t*)_res);
5314         if (_res_constr.datalen > 0)
5315                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKUpdateFailHTLC), "LDKCVec_UpdateFailHTLCZ Elements");
5316         else
5317                 _res_constr.data = NULL;
5318         uint32_t* _res_vals = (uint32_t*)(_res + 4);
5319         for (size_t q = 0; q < _res_constr.datalen; q++) {
5320                 uint32_t arr_conv_16 = _res_vals[q];
5321                 LDKUpdateFailHTLC arr_conv_16_conv;
5322                 arr_conv_16_conv.inner = (void*)(arr_conv_16 & (~1));
5323                 arr_conv_16_conv.is_owned = (arr_conv_16 & 1) || (arr_conv_16 == 0);
5324                 _res_constr.data[q] = arr_conv_16_conv;
5325         }
5326         CVec_UpdateFailHTLCZ_free(_res_constr);
5327 }
5328
5329 void TS_CVec_UpdateFailMalformedHTLCZ_free(uint32_tArray _res) {
5330         LDKCVec_UpdateFailMalformedHTLCZ _res_constr;
5331         _res_constr.datalen = *((uint32_t*)_res);
5332         if (_res_constr.datalen > 0)
5333                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKUpdateFailMalformedHTLC), "LDKCVec_UpdateFailMalformedHTLCZ Elements");
5334         else
5335                 _res_constr.data = NULL;
5336         uint32_t* _res_vals = (uint32_t*)(_res + 4);
5337         for (size_t z = 0; z < _res_constr.datalen; z++) {
5338                 uint32_t arr_conv_25 = _res_vals[z];
5339                 LDKUpdateFailMalformedHTLC arr_conv_25_conv;
5340                 arr_conv_25_conv.inner = (void*)(arr_conv_25 & (~1));
5341                 arr_conv_25_conv.is_owned = (arr_conv_25 & 1) || (arr_conv_25 == 0);
5342                 _res_constr.data[z] = arr_conv_25_conv;
5343         }
5344         CVec_UpdateFailMalformedHTLCZ_free(_res_constr);
5345 }
5346
5347 uint32_t TS_CResult_boolLightningErrorZ_ok(jboolean o) {
5348         LDKCResult_boolLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_boolLightningErrorZ), "LDKCResult_boolLightningErrorZ");
5349         *ret_conv = CResult_boolLightningErrorZ_ok(o);
5350         return (long)ret_conv;
5351 }
5352
5353 uint32_t TS_CResult_boolLightningErrorZ_err(uint32_t e) {
5354         LDKLightningError e_conv;
5355         e_conv.inner = (void*)(e & (~1));
5356         e_conv.is_owned = (e & 1) || (e == 0);
5357         // Warning: we may need a move here but can't clone!
5358         LDKCResult_boolLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_boolLightningErrorZ), "LDKCResult_boolLightningErrorZ");
5359         *ret_conv = CResult_boolLightningErrorZ_err(e_conv);
5360         return (long)ret_conv;
5361 }
5362
5363 void TS_CResult_boolLightningErrorZ_free(uint32_t _res) {
5364         LDKCResult_boolLightningErrorZ _res_conv = *(LDKCResult_boolLightningErrorZ*)_res;
5365         FREE((void*)_res);
5366         CResult_boolLightningErrorZ_free(_res_conv);
5367 }
5368
5369 void TS_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ_free(uint32_t _res) {
5370         LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ _res_conv = *(LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ*)_res;
5371         FREE((void*)_res);
5372         C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ_free(_res_conv);
5373 }
5374
5375 uint32_t TS_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ_new(uint32_t a, uint32_t b, uint32_t c) {
5376         LDKChannelAnnouncement a_conv;
5377         a_conv.inner = (void*)(a & (~1));
5378         a_conv.is_owned = (a & 1) || (a == 0);
5379         if (a_conv.inner != NULL)
5380                 a_conv = ChannelAnnouncement_clone(&a_conv);
5381         LDKChannelUpdate b_conv;
5382         b_conv.inner = (void*)(b & (~1));
5383         b_conv.is_owned = (b & 1) || (b == 0);
5384         if (b_conv.inner != NULL)
5385                 b_conv = ChannelUpdate_clone(&b_conv);
5386         LDKChannelUpdate c_conv;
5387         c_conv.inner = (void*)(c & (~1));
5388         c_conv.is_owned = (c & 1) || (c == 0);
5389         if (c_conv.inner != NULL)
5390                 c_conv = ChannelUpdate_clone(&c_conv);
5391         LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ* ret_ref = MALLOC(sizeof(LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ), "LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ");
5392         *ret_ref = C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ_new(a_conv, b_conv, c_conv);
5393         ret_ref->a = ChannelAnnouncement_clone(&ret_ref->a);
5394         ret_ref->b = ChannelUpdate_clone(&ret_ref->b);
5395         ret_ref->c = ChannelUpdate_clone(&ret_ref->c);
5396         return (long)ret_ref;
5397 }
5398
5399 void TS_CVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ_free(uint32_tArray _res) {
5400         LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ _res_constr;
5401         _res_constr.datalen = *((uint32_t*)_res);
5402         if (_res_constr.datalen > 0)
5403                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ), "LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ Elements");
5404         else
5405                 _res_constr.data = NULL;
5406         uint32_t* _res_vals = (uint32_t*)(_res + 4);
5407         for (size_t l = 0; l < _res_constr.datalen; l++) {
5408                 uint32_t arr_conv_63 = _res_vals[l];
5409                 LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ arr_conv_63_conv = *(LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ*)arr_conv_63;
5410                 FREE((void*)arr_conv_63);
5411                 _res_constr.data[l] = arr_conv_63_conv;
5412         }
5413         CVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ_free(_res_constr);
5414 }
5415
5416 void TS_CVec_NodeAnnouncementZ_free(uint32_tArray _res) {
5417         LDKCVec_NodeAnnouncementZ _res_constr;
5418         _res_constr.datalen = *((uint32_t*)_res);
5419         if (_res_constr.datalen > 0)
5420                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKNodeAnnouncement), "LDKCVec_NodeAnnouncementZ Elements");
5421         else
5422                 _res_constr.data = NULL;
5423         uint32_t* _res_vals = (uint32_t*)(_res + 4);
5424         for (size_t s = 0; s < _res_constr.datalen; s++) {
5425                 uint32_t arr_conv_18 = _res_vals[s];
5426                 LDKNodeAnnouncement arr_conv_18_conv;
5427                 arr_conv_18_conv.inner = (void*)(arr_conv_18 & (~1));
5428                 arr_conv_18_conv.is_owned = (arr_conv_18 & 1) || (arr_conv_18 == 0);
5429                 _res_constr.data[s] = arr_conv_18_conv;
5430         }
5431         CVec_NodeAnnouncementZ_free(_res_constr);
5432 }
5433
5434 uint32_t TS_CResult_NoneLightningErrorZ_ok() {
5435         LDKCResult_NoneLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneLightningErrorZ), "LDKCResult_NoneLightningErrorZ");
5436         *ret_conv = CResult_NoneLightningErrorZ_ok();
5437         return (long)ret_conv;
5438 }
5439
5440 uint32_t TS_CResult_NoneLightningErrorZ_err(uint32_t e) {
5441         LDKLightningError e_conv;
5442         e_conv.inner = (void*)(e & (~1));
5443         e_conv.is_owned = (e & 1) || (e == 0);
5444         // Warning: we may need a move here but can't clone!
5445         LDKCResult_NoneLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneLightningErrorZ), "LDKCResult_NoneLightningErrorZ");
5446         *ret_conv = CResult_NoneLightningErrorZ_err(e_conv);
5447         return (long)ret_conv;
5448 }
5449
5450 void TS_CResult_NoneLightningErrorZ_free(uint32_t _res) {
5451         LDKCResult_NoneLightningErrorZ _res_conv = *(LDKCResult_NoneLightningErrorZ*)_res;
5452         FREE((void*)_res);
5453         CResult_NoneLightningErrorZ_free(_res_conv);
5454 }
5455
5456 uint32_t TS_CResult_ChannelReestablishDecodeErrorZ_ok(uint32_t o) {
5457         LDKChannelReestablish o_conv;
5458         o_conv.inner = (void*)(o & (~1));
5459         o_conv.is_owned = (o & 1) || (o == 0);
5460         if (o_conv.inner != NULL)
5461                 o_conv = ChannelReestablish_clone(&o_conv);
5462         LDKCResult_ChannelReestablishDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ChannelReestablishDecodeErrorZ), "LDKCResult_ChannelReestablishDecodeErrorZ");
5463         *ret_conv = CResult_ChannelReestablishDecodeErrorZ_ok(o_conv);
5464         return (long)ret_conv;
5465 }
5466
5467 uint32_t TS_CResult_ChannelReestablishDecodeErrorZ_err(uint32_t e) {
5468         LDKDecodeError e_conv;
5469         e_conv.inner = (void*)(e & (~1));
5470         e_conv.is_owned = (e & 1) || (e == 0);
5471         // Warning: we may need a move here but can't clone!
5472         LDKCResult_ChannelReestablishDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ChannelReestablishDecodeErrorZ), "LDKCResult_ChannelReestablishDecodeErrorZ");
5473         *ret_conv = CResult_ChannelReestablishDecodeErrorZ_err(e_conv);
5474         return (long)ret_conv;
5475 }
5476
5477 void TS_CResult_ChannelReestablishDecodeErrorZ_free(uint32_t _res) {
5478         LDKCResult_ChannelReestablishDecodeErrorZ _res_conv = *(LDKCResult_ChannelReestablishDecodeErrorZ*)_res;
5479         FREE((void*)_res);
5480         CResult_ChannelReestablishDecodeErrorZ_free(_res_conv);
5481 }
5482
5483 uint32_t TS_CResult_InitDecodeErrorZ_ok(uint32_t o) {
5484         LDKInit o_conv;
5485         o_conv.inner = (void*)(o & (~1));
5486         o_conv.is_owned = (o & 1) || (o == 0);
5487         if (o_conv.inner != NULL)
5488                 o_conv = Init_clone(&o_conv);
5489         LDKCResult_InitDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_InitDecodeErrorZ), "LDKCResult_InitDecodeErrorZ");
5490         *ret_conv = CResult_InitDecodeErrorZ_ok(o_conv);
5491         return (long)ret_conv;
5492 }
5493
5494 uint32_t TS_CResult_InitDecodeErrorZ_err(uint32_t e) {
5495         LDKDecodeError e_conv;
5496         e_conv.inner = (void*)(e & (~1));
5497         e_conv.is_owned = (e & 1) || (e == 0);
5498         // Warning: we may need a move here but can't clone!
5499         LDKCResult_InitDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_InitDecodeErrorZ), "LDKCResult_InitDecodeErrorZ");
5500         *ret_conv = CResult_InitDecodeErrorZ_err(e_conv);
5501         return (long)ret_conv;
5502 }
5503
5504 void TS_CResult_InitDecodeErrorZ_free(uint32_t _res) {
5505         LDKCResult_InitDecodeErrorZ _res_conv = *(LDKCResult_InitDecodeErrorZ*)_res;
5506         FREE((void*)_res);
5507         CResult_InitDecodeErrorZ_free(_res_conv);
5508 }
5509
5510 uint32_t TS_CResult_PingDecodeErrorZ_ok(uint32_t o) {
5511         LDKPing o_conv;
5512         o_conv.inner = (void*)(o & (~1));
5513         o_conv.is_owned = (o & 1) || (o == 0);
5514         if (o_conv.inner != NULL)
5515                 o_conv = Ping_clone(&o_conv);
5516         LDKCResult_PingDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_PingDecodeErrorZ), "LDKCResult_PingDecodeErrorZ");
5517         *ret_conv = CResult_PingDecodeErrorZ_ok(o_conv);
5518         return (long)ret_conv;
5519 }
5520
5521 uint32_t TS_CResult_PingDecodeErrorZ_err(uint32_t e) {
5522         LDKDecodeError e_conv;
5523         e_conv.inner = (void*)(e & (~1));
5524         e_conv.is_owned = (e & 1) || (e == 0);
5525         // Warning: we may need a move here but can't clone!
5526         LDKCResult_PingDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_PingDecodeErrorZ), "LDKCResult_PingDecodeErrorZ");
5527         *ret_conv = CResult_PingDecodeErrorZ_err(e_conv);
5528         return (long)ret_conv;
5529 }
5530
5531 void TS_CResult_PingDecodeErrorZ_free(uint32_t _res) {
5532         LDKCResult_PingDecodeErrorZ _res_conv = *(LDKCResult_PingDecodeErrorZ*)_res;
5533         FREE((void*)_res);
5534         CResult_PingDecodeErrorZ_free(_res_conv);
5535 }
5536
5537 uint32_t TS_CResult_PongDecodeErrorZ_ok(uint32_t o) {
5538         LDKPong o_conv;
5539         o_conv.inner = (void*)(o & (~1));
5540         o_conv.is_owned = (o & 1) || (o == 0);
5541         if (o_conv.inner != NULL)
5542                 o_conv = Pong_clone(&o_conv);
5543         LDKCResult_PongDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_PongDecodeErrorZ), "LDKCResult_PongDecodeErrorZ");
5544         *ret_conv = CResult_PongDecodeErrorZ_ok(o_conv);
5545         return (long)ret_conv;
5546 }
5547
5548 uint32_t TS_CResult_PongDecodeErrorZ_err(uint32_t e) {
5549         LDKDecodeError e_conv;
5550         e_conv.inner = (void*)(e & (~1));
5551         e_conv.is_owned = (e & 1) || (e == 0);
5552         // Warning: we may need a move here but can't clone!
5553         LDKCResult_PongDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_PongDecodeErrorZ), "LDKCResult_PongDecodeErrorZ");
5554         *ret_conv = CResult_PongDecodeErrorZ_err(e_conv);
5555         return (long)ret_conv;
5556 }
5557
5558 void TS_CResult_PongDecodeErrorZ_free(uint32_t _res) {
5559         LDKCResult_PongDecodeErrorZ _res_conv = *(LDKCResult_PongDecodeErrorZ*)_res;
5560         FREE((void*)_res);
5561         CResult_PongDecodeErrorZ_free(_res_conv);
5562 }
5563
5564 uint32_t TS_CResult_UnsignedChannelAnnouncementDecodeErrorZ_ok(uint32_t o) {
5565         LDKUnsignedChannelAnnouncement o_conv;
5566         o_conv.inner = (void*)(o & (~1));
5567         o_conv.is_owned = (o & 1) || (o == 0);
5568         if (o_conv.inner != NULL)
5569                 o_conv = UnsignedChannelAnnouncement_clone(&o_conv);
5570         LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ), "LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ");
5571         *ret_conv = CResult_UnsignedChannelAnnouncementDecodeErrorZ_ok(o_conv);
5572         return (long)ret_conv;
5573 }
5574
5575 uint32_t TS_CResult_UnsignedChannelAnnouncementDecodeErrorZ_err(uint32_t e) {
5576         LDKDecodeError e_conv;
5577         e_conv.inner = (void*)(e & (~1));
5578         e_conv.is_owned = (e & 1) || (e == 0);
5579         // Warning: we may need a move here but can't clone!
5580         LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ), "LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ");
5581         *ret_conv = CResult_UnsignedChannelAnnouncementDecodeErrorZ_err(e_conv);
5582         return (long)ret_conv;
5583 }
5584
5585 void TS_CResult_UnsignedChannelAnnouncementDecodeErrorZ_free(uint32_t _res) {
5586         LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ _res_conv = *(LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ*)_res;
5587         FREE((void*)_res);
5588         CResult_UnsignedChannelAnnouncementDecodeErrorZ_free(_res_conv);
5589 }
5590
5591 uint32_t TS_CResult_UnsignedChannelUpdateDecodeErrorZ_ok(uint32_t o) {
5592         LDKUnsignedChannelUpdate o_conv;
5593         o_conv.inner = (void*)(o & (~1));
5594         o_conv.is_owned = (o & 1) || (o == 0);
5595         if (o_conv.inner != NULL)
5596                 o_conv = UnsignedChannelUpdate_clone(&o_conv);
5597         LDKCResult_UnsignedChannelUpdateDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_UnsignedChannelUpdateDecodeErrorZ), "LDKCResult_UnsignedChannelUpdateDecodeErrorZ");
5598         *ret_conv = CResult_UnsignedChannelUpdateDecodeErrorZ_ok(o_conv);
5599         return (long)ret_conv;
5600 }
5601
5602 uint32_t TS_CResult_UnsignedChannelUpdateDecodeErrorZ_err(uint32_t e) {
5603         LDKDecodeError e_conv;
5604         e_conv.inner = (void*)(e & (~1));
5605         e_conv.is_owned = (e & 1) || (e == 0);
5606         // Warning: we may need a move here but can't clone!
5607         LDKCResult_UnsignedChannelUpdateDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_UnsignedChannelUpdateDecodeErrorZ), "LDKCResult_UnsignedChannelUpdateDecodeErrorZ");
5608         *ret_conv = CResult_UnsignedChannelUpdateDecodeErrorZ_err(e_conv);
5609         return (long)ret_conv;
5610 }
5611
5612 void TS_CResult_UnsignedChannelUpdateDecodeErrorZ_free(uint32_t _res) {
5613         LDKCResult_UnsignedChannelUpdateDecodeErrorZ _res_conv = *(LDKCResult_UnsignedChannelUpdateDecodeErrorZ*)_res;
5614         FREE((void*)_res);
5615         CResult_UnsignedChannelUpdateDecodeErrorZ_free(_res_conv);
5616 }
5617
5618 uint32_t TS_CResult_ErrorMessageDecodeErrorZ_ok(uint32_t o) {
5619         LDKErrorMessage o_conv;
5620         o_conv.inner = (void*)(o & (~1));
5621         o_conv.is_owned = (o & 1) || (o == 0);
5622         if (o_conv.inner != NULL)
5623                 o_conv = ErrorMessage_clone(&o_conv);
5624         LDKCResult_ErrorMessageDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ErrorMessageDecodeErrorZ), "LDKCResult_ErrorMessageDecodeErrorZ");
5625         *ret_conv = CResult_ErrorMessageDecodeErrorZ_ok(o_conv);
5626         return (long)ret_conv;
5627 }
5628
5629 uint32_t TS_CResult_ErrorMessageDecodeErrorZ_err(uint32_t e) {
5630         LDKDecodeError e_conv;
5631         e_conv.inner = (void*)(e & (~1));
5632         e_conv.is_owned = (e & 1) || (e == 0);
5633         // Warning: we may need a move here but can't clone!
5634         LDKCResult_ErrorMessageDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ErrorMessageDecodeErrorZ), "LDKCResult_ErrorMessageDecodeErrorZ");
5635         *ret_conv = CResult_ErrorMessageDecodeErrorZ_err(e_conv);
5636         return (long)ret_conv;
5637 }
5638
5639 void TS_CResult_ErrorMessageDecodeErrorZ_free(uint32_t _res) {
5640         LDKCResult_ErrorMessageDecodeErrorZ _res_conv = *(LDKCResult_ErrorMessageDecodeErrorZ*)_res;
5641         FREE((void*)_res);
5642         CResult_ErrorMessageDecodeErrorZ_free(_res_conv);
5643 }
5644
5645 uint32_t TS_CResult_UnsignedNodeAnnouncementDecodeErrorZ_ok(uint32_t o) {
5646         LDKUnsignedNodeAnnouncement o_conv;
5647         o_conv.inner = (void*)(o & (~1));
5648         o_conv.is_owned = (o & 1) || (o == 0);
5649         if (o_conv.inner != NULL)
5650                 o_conv = UnsignedNodeAnnouncement_clone(&o_conv);
5651         LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ), "LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ");
5652         *ret_conv = CResult_UnsignedNodeAnnouncementDecodeErrorZ_ok(o_conv);
5653         return (long)ret_conv;
5654 }
5655
5656 uint32_t TS_CResult_UnsignedNodeAnnouncementDecodeErrorZ_err(uint32_t e) {
5657         LDKDecodeError e_conv;
5658         e_conv.inner = (void*)(e & (~1));
5659         e_conv.is_owned = (e & 1) || (e == 0);
5660         // Warning: we may need a move here but can't clone!
5661         LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ), "LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ");
5662         *ret_conv = CResult_UnsignedNodeAnnouncementDecodeErrorZ_err(e_conv);
5663         return (long)ret_conv;
5664 }
5665
5666 void TS_CResult_UnsignedNodeAnnouncementDecodeErrorZ_free(uint32_t _res) {
5667         LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ _res_conv = *(LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ*)_res;
5668         FREE((void*)_res);
5669         CResult_UnsignedNodeAnnouncementDecodeErrorZ_free(_res_conv);
5670 }
5671
5672 uint32_t TS_CResult_QueryShortChannelIdsDecodeErrorZ_ok(uint32_t o) {
5673         LDKQueryShortChannelIds o_conv;
5674         o_conv.inner = (void*)(o & (~1));
5675         o_conv.is_owned = (o & 1) || (o == 0);
5676         if (o_conv.inner != NULL)
5677                 o_conv = QueryShortChannelIds_clone(&o_conv);
5678         LDKCResult_QueryShortChannelIdsDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_QueryShortChannelIdsDecodeErrorZ), "LDKCResult_QueryShortChannelIdsDecodeErrorZ");
5679         *ret_conv = CResult_QueryShortChannelIdsDecodeErrorZ_ok(o_conv);
5680         return (long)ret_conv;
5681 }
5682
5683 uint32_t TS_CResult_QueryShortChannelIdsDecodeErrorZ_err(uint32_t e) {
5684         LDKDecodeError e_conv;
5685         e_conv.inner = (void*)(e & (~1));
5686         e_conv.is_owned = (e & 1) || (e == 0);
5687         // Warning: we may need a move here but can't clone!
5688         LDKCResult_QueryShortChannelIdsDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_QueryShortChannelIdsDecodeErrorZ), "LDKCResult_QueryShortChannelIdsDecodeErrorZ");
5689         *ret_conv = CResult_QueryShortChannelIdsDecodeErrorZ_err(e_conv);
5690         return (long)ret_conv;
5691 }
5692
5693 void TS_CResult_QueryShortChannelIdsDecodeErrorZ_free(uint32_t _res) {
5694         LDKCResult_QueryShortChannelIdsDecodeErrorZ _res_conv = *(LDKCResult_QueryShortChannelIdsDecodeErrorZ*)_res;
5695         FREE((void*)_res);
5696         CResult_QueryShortChannelIdsDecodeErrorZ_free(_res_conv);
5697 }
5698
5699 uint32_t TS_CResult_ReplyShortChannelIdsEndDecodeErrorZ_ok(uint32_t o) {
5700         LDKReplyShortChannelIdsEnd o_conv;
5701         o_conv.inner = (void*)(o & (~1));
5702         o_conv.is_owned = (o & 1) || (o == 0);
5703         if (o_conv.inner != NULL)
5704                 o_conv = ReplyShortChannelIdsEnd_clone(&o_conv);
5705         LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ), "LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ");
5706         *ret_conv = CResult_ReplyShortChannelIdsEndDecodeErrorZ_ok(o_conv);
5707         return (long)ret_conv;
5708 }
5709
5710 uint32_t TS_CResult_ReplyShortChannelIdsEndDecodeErrorZ_err(uint32_t e) {
5711         LDKDecodeError e_conv;
5712         e_conv.inner = (void*)(e & (~1));
5713         e_conv.is_owned = (e & 1) || (e == 0);
5714         // Warning: we may need a move here but can't clone!
5715         LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ), "LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ");
5716         *ret_conv = CResult_ReplyShortChannelIdsEndDecodeErrorZ_err(e_conv);
5717         return (long)ret_conv;
5718 }
5719
5720 void TS_CResult_ReplyShortChannelIdsEndDecodeErrorZ_free(uint32_t _res) {
5721         LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ _res_conv = *(LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ*)_res;
5722         FREE((void*)_res);
5723         CResult_ReplyShortChannelIdsEndDecodeErrorZ_free(_res_conv);
5724 }
5725
5726 uint32_t TS_CResult_QueryChannelRangeDecodeErrorZ_ok(uint32_t o) {
5727         LDKQueryChannelRange o_conv;
5728         o_conv.inner = (void*)(o & (~1));
5729         o_conv.is_owned = (o & 1) || (o == 0);
5730         if (o_conv.inner != NULL)
5731                 o_conv = QueryChannelRange_clone(&o_conv);
5732         LDKCResult_QueryChannelRangeDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_QueryChannelRangeDecodeErrorZ), "LDKCResult_QueryChannelRangeDecodeErrorZ");
5733         *ret_conv = CResult_QueryChannelRangeDecodeErrorZ_ok(o_conv);
5734         return (long)ret_conv;
5735 }
5736
5737 uint32_t TS_CResult_QueryChannelRangeDecodeErrorZ_err(uint32_t e) {
5738         LDKDecodeError e_conv;
5739         e_conv.inner = (void*)(e & (~1));
5740         e_conv.is_owned = (e & 1) || (e == 0);
5741         // Warning: we may need a move here but can't clone!
5742         LDKCResult_QueryChannelRangeDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_QueryChannelRangeDecodeErrorZ), "LDKCResult_QueryChannelRangeDecodeErrorZ");
5743         *ret_conv = CResult_QueryChannelRangeDecodeErrorZ_err(e_conv);
5744         return (long)ret_conv;
5745 }
5746
5747 void TS_CResult_QueryChannelRangeDecodeErrorZ_free(uint32_t _res) {
5748         LDKCResult_QueryChannelRangeDecodeErrorZ _res_conv = *(LDKCResult_QueryChannelRangeDecodeErrorZ*)_res;
5749         FREE((void*)_res);
5750         CResult_QueryChannelRangeDecodeErrorZ_free(_res_conv);
5751 }
5752
5753 uint32_t TS_CResult_ReplyChannelRangeDecodeErrorZ_ok(uint32_t o) {
5754         LDKReplyChannelRange o_conv;
5755         o_conv.inner = (void*)(o & (~1));
5756         o_conv.is_owned = (o & 1) || (o == 0);
5757         if (o_conv.inner != NULL)
5758                 o_conv = ReplyChannelRange_clone(&o_conv);
5759         LDKCResult_ReplyChannelRangeDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ReplyChannelRangeDecodeErrorZ), "LDKCResult_ReplyChannelRangeDecodeErrorZ");
5760         *ret_conv = CResult_ReplyChannelRangeDecodeErrorZ_ok(o_conv);
5761         return (long)ret_conv;
5762 }
5763
5764 uint32_t TS_CResult_ReplyChannelRangeDecodeErrorZ_err(uint32_t e) {
5765         LDKDecodeError e_conv;
5766         e_conv.inner = (void*)(e & (~1));
5767         e_conv.is_owned = (e & 1) || (e == 0);
5768         // Warning: we may need a move here but can't clone!
5769         LDKCResult_ReplyChannelRangeDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ReplyChannelRangeDecodeErrorZ), "LDKCResult_ReplyChannelRangeDecodeErrorZ");
5770         *ret_conv = CResult_ReplyChannelRangeDecodeErrorZ_err(e_conv);
5771         return (long)ret_conv;
5772 }
5773
5774 void TS_CResult_ReplyChannelRangeDecodeErrorZ_free(uint32_t _res) {
5775         LDKCResult_ReplyChannelRangeDecodeErrorZ _res_conv = *(LDKCResult_ReplyChannelRangeDecodeErrorZ*)_res;
5776         FREE((void*)_res);
5777         CResult_ReplyChannelRangeDecodeErrorZ_free(_res_conv);
5778 }
5779
5780 uint32_t TS_CResult_GossipTimestampFilterDecodeErrorZ_ok(uint32_t o) {
5781         LDKGossipTimestampFilter o_conv;
5782         o_conv.inner = (void*)(o & (~1));
5783         o_conv.is_owned = (o & 1) || (o == 0);
5784         if (o_conv.inner != NULL)
5785                 o_conv = GossipTimestampFilter_clone(&o_conv);
5786         LDKCResult_GossipTimestampFilterDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_GossipTimestampFilterDecodeErrorZ), "LDKCResult_GossipTimestampFilterDecodeErrorZ");
5787         *ret_conv = CResult_GossipTimestampFilterDecodeErrorZ_ok(o_conv);
5788         return (long)ret_conv;
5789 }
5790
5791 uint32_t TS_CResult_GossipTimestampFilterDecodeErrorZ_err(uint32_t e) {
5792         LDKDecodeError e_conv;
5793         e_conv.inner = (void*)(e & (~1));
5794         e_conv.is_owned = (e & 1) || (e == 0);
5795         // Warning: we may need a move here but can't clone!
5796         LDKCResult_GossipTimestampFilterDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_GossipTimestampFilterDecodeErrorZ), "LDKCResult_GossipTimestampFilterDecodeErrorZ");
5797         *ret_conv = CResult_GossipTimestampFilterDecodeErrorZ_err(e_conv);
5798         return (long)ret_conv;
5799 }
5800
5801 void TS_CResult_GossipTimestampFilterDecodeErrorZ_free(uint32_t _res) {
5802         LDKCResult_GossipTimestampFilterDecodeErrorZ _res_conv = *(LDKCResult_GossipTimestampFilterDecodeErrorZ*)_res;
5803         FREE((void*)_res);
5804         CResult_GossipTimestampFilterDecodeErrorZ_free(_res_conv);
5805 }
5806
5807 void TS_CVec_PublicKeyZ_free(ptrArray _res) {
5808         LDKCVec_PublicKeyZ _res_constr;
5809         _res_constr.datalen = *((uint32_t*)_res);
5810         if (_res_constr.datalen > 0)
5811                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKPublicKey), "LDKCVec_PublicKeyZ Elements");
5812         else
5813                 _res_constr.data = NULL;
5814         int8_tArray* _res_vals = (int8_tArray*)(_res + 4);
5815         for (size_t m = 0; m < _res_constr.datalen; m++) {
5816                 int8_tArray arr_conv_12 = _res_vals[m];
5817                 LDKPublicKey arr_conv_12_ref;
5818                 CHECK(*((uint32_t*)arr_conv_12) == 33);
5819                 memcpy(arr_conv_12_ref.compressed_form, (uint8_t*)(arr_conv_12 + 4), 33);
5820                 _res_constr.data[m] = arr_conv_12_ref;
5821         }
5822         CVec_PublicKeyZ_free(_res_constr);
5823 }
5824
5825 void TS_CVec_u8Z_free(int8_tArray _res) {
5826         LDKCVec_u8Z _res_ref;
5827         _res_ref.datalen = *((uint32_t*)_res);
5828         _res_ref.data = MALLOC(_res_ref.datalen, "LDKCVec_u8Z Bytes");
5829         memcpy(_res_ref.data, (uint8_t*)(_res + 4), _res_ref.datalen);
5830         CVec_u8Z_free(_res_ref);
5831 }
5832
5833 uint32_t TS_CResult_CVec_u8ZPeerHandleErrorZ_ok(int8_tArray o) {
5834         LDKCVec_u8Z o_ref;
5835         o_ref.datalen = *((uint32_t*)o);
5836         o_ref.data = MALLOC(o_ref.datalen, "LDKCVec_u8Z Bytes");
5837         memcpy(o_ref.data, (uint8_t*)(o + 4), o_ref.datalen);
5838         LDKCResult_CVec_u8ZPeerHandleErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_CVec_u8ZPeerHandleErrorZ), "LDKCResult_CVec_u8ZPeerHandleErrorZ");
5839         *ret_conv = CResult_CVec_u8ZPeerHandleErrorZ_ok(o_ref);
5840         return (long)ret_conv;
5841 }
5842
5843 uint32_t TS_CResult_CVec_u8ZPeerHandleErrorZ_err(uint32_t e) {
5844         LDKPeerHandleError e_conv;
5845         e_conv.inner = (void*)(e & (~1));
5846         e_conv.is_owned = (e & 1) || (e == 0);
5847         // Warning: we may need a move here but can't clone!
5848         LDKCResult_CVec_u8ZPeerHandleErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_CVec_u8ZPeerHandleErrorZ), "LDKCResult_CVec_u8ZPeerHandleErrorZ");
5849         *ret_conv = CResult_CVec_u8ZPeerHandleErrorZ_err(e_conv);
5850         return (long)ret_conv;
5851 }
5852
5853 void TS_CResult_CVec_u8ZPeerHandleErrorZ_free(uint32_t _res) {
5854         LDKCResult_CVec_u8ZPeerHandleErrorZ _res_conv = *(LDKCResult_CVec_u8ZPeerHandleErrorZ*)_res;
5855         FREE((void*)_res);
5856         CResult_CVec_u8ZPeerHandleErrorZ_free(_res_conv);
5857 }
5858
5859 uint32_t TS_CResult_NonePeerHandleErrorZ_ok() {
5860         LDKCResult_NonePeerHandleErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NonePeerHandleErrorZ), "LDKCResult_NonePeerHandleErrorZ");
5861         *ret_conv = CResult_NonePeerHandleErrorZ_ok();
5862         return (long)ret_conv;
5863 }
5864
5865 uint32_t TS_CResult_NonePeerHandleErrorZ_err(uint32_t e) {
5866         LDKPeerHandleError e_conv;
5867         e_conv.inner = (void*)(e & (~1));
5868         e_conv.is_owned = (e & 1) || (e == 0);
5869         // Warning: we may need a move here but can't clone!
5870         LDKCResult_NonePeerHandleErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NonePeerHandleErrorZ), "LDKCResult_NonePeerHandleErrorZ");
5871         *ret_conv = CResult_NonePeerHandleErrorZ_err(e_conv);
5872         return (long)ret_conv;
5873 }
5874
5875 void TS_CResult_NonePeerHandleErrorZ_free(uint32_t _res) {
5876         LDKCResult_NonePeerHandleErrorZ _res_conv = *(LDKCResult_NonePeerHandleErrorZ*)_res;
5877         FREE((void*)_res);
5878         CResult_NonePeerHandleErrorZ_free(_res_conv);
5879 }
5880
5881 uint32_t TS_CResult_boolPeerHandleErrorZ_ok(jboolean o) {
5882         LDKCResult_boolPeerHandleErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_boolPeerHandleErrorZ), "LDKCResult_boolPeerHandleErrorZ");
5883         *ret_conv = CResult_boolPeerHandleErrorZ_ok(o);
5884         return (long)ret_conv;
5885 }
5886
5887 uint32_t TS_CResult_boolPeerHandleErrorZ_err(uint32_t e) {
5888         LDKPeerHandleError e_conv;
5889         e_conv.inner = (void*)(e & (~1));
5890         e_conv.is_owned = (e & 1) || (e == 0);
5891         // Warning: we may need a move here but can't clone!
5892         LDKCResult_boolPeerHandleErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_boolPeerHandleErrorZ), "LDKCResult_boolPeerHandleErrorZ");
5893         *ret_conv = CResult_boolPeerHandleErrorZ_err(e_conv);
5894         return (long)ret_conv;
5895 }
5896
5897 void TS_CResult_boolPeerHandleErrorZ_free(uint32_t _res) {
5898         LDKCResult_boolPeerHandleErrorZ _res_conv = *(LDKCResult_boolPeerHandleErrorZ*)_res;
5899         FREE((void*)_res);
5900         CResult_boolPeerHandleErrorZ_free(_res_conv);
5901 }
5902
5903 uint32_t TS_CResult_SecretKeySecpErrorZ_ok(int8_tArray o) {
5904         LDKSecretKey o_ref;
5905         CHECK(*((uint32_t*)o) == 32);
5906         memcpy(o_ref.bytes, (uint8_t*)(o + 4), 32);
5907         LDKCResult_SecretKeySecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_SecretKeySecpErrorZ), "LDKCResult_SecretKeySecpErrorZ");
5908         *ret_conv = CResult_SecretKeySecpErrorZ_ok(o_ref);
5909         return (long)ret_conv;
5910 }
5911
5912 uint32_t TS_CResult_SecretKeySecpErrorZ_err(uint32_t e) {
5913         LDKSecp256k1Error e_conv = LDKSecp256k1Error_from_js(e);
5914         LDKCResult_SecretKeySecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_SecretKeySecpErrorZ), "LDKCResult_SecretKeySecpErrorZ");
5915         *ret_conv = CResult_SecretKeySecpErrorZ_err(e_conv);
5916         return (long)ret_conv;
5917 }
5918
5919 void TS_CResult_SecretKeySecpErrorZ_free(uint32_t _res) {
5920         LDKCResult_SecretKeySecpErrorZ _res_conv = *(LDKCResult_SecretKeySecpErrorZ*)_res;
5921         FREE((void*)_res);
5922         CResult_SecretKeySecpErrorZ_free(_res_conv);
5923 }
5924
5925 uint32_t TS_CResult_PublicKeySecpErrorZ_ok(int8_tArray o) {
5926         LDKPublicKey o_ref;
5927         CHECK(*((uint32_t*)o) == 33);
5928         memcpy(o_ref.compressed_form, (uint8_t*)(o + 4), 33);
5929         LDKCResult_PublicKeySecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_PublicKeySecpErrorZ), "LDKCResult_PublicKeySecpErrorZ");
5930         *ret_conv = CResult_PublicKeySecpErrorZ_ok(o_ref);
5931         return (long)ret_conv;
5932 }
5933
5934 uint32_t TS_CResult_PublicKeySecpErrorZ_err(uint32_t e) {
5935         LDKSecp256k1Error e_conv = LDKSecp256k1Error_from_js(e);
5936         LDKCResult_PublicKeySecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_PublicKeySecpErrorZ), "LDKCResult_PublicKeySecpErrorZ");
5937         *ret_conv = CResult_PublicKeySecpErrorZ_err(e_conv);
5938         return (long)ret_conv;
5939 }
5940
5941 void TS_CResult_PublicKeySecpErrorZ_free(uint32_t _res) {
5942         LDKCResult_PublicKeySecpErrorZ _res_conv = *(LDKCResult_PublicKeySecpErrorZ*)_res;
5943         FREE((void*)_res);
5944         CResult_PublicKeySecpErrorZ_free(_res_conv);
5945 }
5946
5947 uint32_t TS_CResult_TxCreationKeysSecpErrorZ_ok(uint32_t o) {
5948         LDKTxCreationKeys o_conv;
5949         o_conv.inner = (void*)(o & (~1));
5950         o_conv.is_owned = (o & 1) || (o == 0);
5951         if (o_conv.inner != NULL)
5952                 o_conv = TxCreationKeys_clone(&o_conv);
5953         LDKCResult_TxCreationKeysSecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_TxCreationKeysSecpErrorZ), "LDKCResult_TxCreationKeysSecpErrorZ");
5954         *ret_conv = CResult_TxCreationKeysSecpErrorZ_ok(o_conv);
5955         return (long)ret_conv;
5956 }
5957
5958 uint32_t TS_CResult_TxCreationKeysSecpErrorZ_err(uint32_t e) {
5959         LDKSecp256k1Error e_conv = LDKSecp256k1Error_from_js(e);
5960         LDKCResult_TxCreationKeysSecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_TxCreationKeysSecpErrorZ), "LDKCResult_TxCreationKeysSecpErrorZ");
5961         *ret_conv = CResult_TxCreationKeysSecpErrorZ_err(e_conv);
5962         return (long)ret_conv;
5963 }
5964
5965 void TS_CResult_TxCreationKeysSecpErrorZ_free(uint32_t _res) {
5966         LDKCResult_TxCreationKeysSecpErrorZ _res_conv = *(LDKCResult_TxCreationKeysSecpErrorZ*)_res;
5967         FREE((void*)_res);
5968         CResult_TxCreationKeysSecpErrorZ_free(_res_conv);
5969 }
5970
5971 uint32_t TS_CResult_TrustedCommitmentTransactionNoneZ_ok(uint32_t o) {
5972         LDKTrustedCommitmentTransaction o_conv;
5973         o_conv.inner = (void*)(o & (~1));
5974         o_conv.is_owned = (o & 1) || (o == 0);
5975         // Warning: we may need a move here but can't clone!
5976         LDKCResult_TrustedCommitmentTransactionNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_TrustedCommitmentTransactionNoneZ), "LDKCResult_TrustedCommitmentTransactionNoneZ");
5977         *ret_conv = CResult_TrustedCommitmentTransactionNoneZ_ok(o_conv);
5978         return (long)ret_conv;
5979 }
5980
5981 uint32_t TS_CResult_TrustedCommitmentTransactionNoneZ_err() {
5982         LDKCResult_TrustedCommitmentTransactionNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_TrustedCommitmentTransactionNoneZ), "LDKCResult_TrustedCommitmentTransactionNoneZ");
5983         *ret_conv = CResult_TrustedCommitmentTransactionNoneZ_err();
5984         return (long)ret_conv;
5985 }
5986
5987 void TS_CResult_TrustedCommitmentTransactionNoneZ_free(uint32_t _res) {
5988         LDKCResult_TrustedCommitmentTransactionNoneZ _res_conv = *(LDKCResult_TrustedCommitmentTransactionNoneZ*)_res;
5989         FREE((void*)_res);
5990         CResult_TrustedCommitmentTransactionNoneZ_free(_res_conv);
5991 }
5992
5993 void TS_CVec_RouteHopZ_free(uint32_tArray _res) {
5994         LDKCVec_RouteHopZ _res_constr;
5995         _res_constr.datalen = *((uint32_t*)_res);
5996         if (_res_constr.datalen > 0)
5997                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKRouteHop), "LDKCVec_RouteHopZ Elements");
5998         else
5999                 _res_constr.data = NULL;
6000         uint32_t* _res_vals = (uint32_t*)(_res + 4);
6001         for (size_t k = 0; k < _res_constr.datalen; k++) {
6002                 uint32_t arr_conv_10 = _res_vals[k];
6003                 LDKRouteHop arr_conv_10_conv;
6004                 arr_conv_10_conv.inner = (void*)(arr_conv_10 & (~1));
6005                 arr_conv_10_conv.is_owned = (arr_conv_10 & 1) || (arr_conv_10 == 0);
6006                 _res_constr.data[k] = arr_conv_10_conv;
6007         }
6008         CVec_RouteHopZ_free(_res_constr);
6009 }
6010
6011 void TS_CVec_CVec_RouteHopZZ_free(ptrArray _res) {
6012         LDKCVec_CVec_RouteHopZZ _res_constr;
6013         _res_constr.datalen = *((uint32_t*)_res);
6014         if (_res_constr.datalen > 0)
6015                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKCVec_RouteHopZ), "LDKCVec_CVec_RouteHopZZ Elements");
6016         else
6017                 _res_constr.data = NULL;
6018         uint32_tArray* _res_vals = (uint32_tArray*)(_res + 4);
6019         for (size_t m = 0; m < _res_constr.datalen; m++) {
6020                 uint32_tArray arr_conv_12 = _res_vals[m];
6021                 LDKCVec_RouteHopZ arr_conv_12_constr;
6022                 arr_conv_12_constr.datalen = *((uint32_t*)arr_conv_12);
6023                 if (arr_conv_12_constr.datalen > 0)
6024                         arr_conv_12_constr.data = MALLOC(arr_conv_12_constr.datalen * sizeof(LDKRouteHop), "LDKCVec_RouteHopZ Elements");
6025                 else
6026                         arr_conv_12_constr.data = NULL;
6027                 uint32_t* arr_conv_12_vals = (uint32_t*)(arr_conv_12 + 4);
6028                 for (size_t k = 0; k < arr_conv_12_constr.datalen; k++) {
6029                         uint32_t arr_conv_10 = arr_conv_12_vals[k];
6030                         LDKRouteHop arr_conv_10_conv;
6031                         arr_conv_10_conv.inner = (void*)(arr_conv_10 & (~1));
6032                         arr_conv_10_conv.is_owned = (arr_conv_10 & 1) || (arr_conv_10 == 0);
6033                         arr_conv_12_constr.data[k] = arr_conv_10_conv;
6034                 }
6035                 _res_constr.data[m] = arr_conv_12_constr;
6036         }
6037         CVec_CVec_RouteHopZZ_free(_res_constr);
6038 }
6039
6040 uint32_t TS_CResult_RouteDecodeErrorZ_ok(uint32_t o) {
6041         LDKRoute o_conv;
6042         o_conv.inner = (void*)(o & (~1));
6043         o_conv.is_owned = (o & 1) || (o == 0);
6044         if (o_conv.inner != NULL)
6045                 o_conv = Route_clone(&o_conv);
6046         LDKCResult_RouteDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_RouteDecodeErrorZ), "LDKCResult_RouteDecodeErrorZ");
6047         *ret_conv = CResult_RouteDecodeErrorZ_ok(o_conv);
6048         return (long)ret_conv;
6049 }
6050
6051 uint32_t TS_CResult_RouteDecodeErrorZ_err(uint32_t e) {
6052         LDKDecodeError e_conv;
6053         e_conv.inner = (void*)(e & (~1));
6054         e_conv.is_owned = (e & 1) || (e == 0);
6055         // Warning: we may need a move here but can't clone!
6056         LDKCResult_RouteDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_RouteDecodeErrorZ), "LDKCResult_RouteDecodeErrorZ");
6057         *ret_conv = CResult_RouteDecodeErrorZ_err(e_conv);
6058         return (long)ret_conv;
6059 }
6060
6061 void TS_CResult_RouteDecodeErrorZ_free(uint32_t _res) {
6062         LDKCResult_RouteDecodeErrorZ _res_conv = *(LDKCResult_RouteDecodeErrorZ*)_res;
6063         FREE((void*)_res);
6064         CResult_RouteDecodeErrorZ_free(_res_conv);
6065 }
6066
6067 void TS_CVec_RouteHintZ_free(uint32_tArray _res) {
6068         LDKCVec_RouteHintZ _res_constr;
6069         _res_constr.datalen = *((uint32_t*)_res);
6070         if (_res_constr.datalen > 0)
6071                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKRouteHint), "LDKCVec_RouteHintZ Elements");
6072         else
6073                 _res_constr.data = NULL;
6074         uint32_t* _res_vals = (uint32_t*)(_res + 4);
6075         for (size_t l = 0; l < _res_constr.datalen; l++) {
6076                 uint32_t arr_conv_11 = _res_vals[l];
6077                 LDKRouteHint arr_conv_11_conv;
6078                 arr_conv_11_conv.inner = (void*)(arr_conv_11 & (~1));
6079                 arr_conv_11_conv.is_owned = (arr_conv_11 & 1) || (arr_conv_11 == 0);
6080                 _res_constr.data[l] = arr_conv_11_conv;
6081         }
6082         CVec_RouteHintZ_free(_res_constr);
6083 }
6084
6085 uint32_t TS_CResult_RouteLightningErrorZ_ok(uint32_t o) {
6086         LDKRoute o_conv;
6087         o_conv.inner = (void*)(o & (~1));
6088         o_conv.is_owned = (o & 1) || (o == 0);
6089         if (o_conv.inner != NULL)
6090                 o_conv = Route_clone(&o_conv);
6091         LDKCResult_RouteLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_RouteLightningErrorZ), "LDKCResult_RouteLightningErrorZ");
6092         *ret_conv = CResult_RouteLightningErrorZ_ok(o_conv);
6093         return (long)ret_conv;
6094 }
6095
6096 uint32_t TS_CResult_RouteLightningErrorZ_err(uint32_t e) {
6097         LDKLightningError e_conv;
6098         e_conv.inner = (void*)(e & (~1));
6099         e_conv.is_owned = (e & 1) || (e == 0);
6100         // Warning: we may need a move here but can't clone!
6101         LDKCResult_RouteLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_RouteLightningErrorZ), "LDKCResult_RouteLightningErrorZ");
6102         *ret_conv = CResult_RouteLightningErrorZ_err(e_conv);
6103         return (long)ret_conv;
6104 }
6105
6106 void TS_CResult_RouteLightningErrorZ_free(uint32_t _res) {
6107         LDKCResult_RouteLightningErrorZ _res_conv = *(LDKCResult_RouteLightningErrorZ*)_res;
6108         FREE((void*)_res);
6109         CResult_RouteLightningErrorZ_free(_res_conv);
6110 }
6111
6112 uint32_t TS_CResult_RoutingFeesDecodeErrorZ_ok(uint32_t o) {
6113         LDKRoutingFees o_conv;
6114         o_conv.inner = (void*)(o & (~1));
6115         o_conv.is_owned = (o & 1) || (o == 0);
6116         if (o_conv.inner != NULL)
6117                 o_conv = RoutingFees_clone(&o_conv);
6118         LDKCResult_RoutingFeesDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_RoutingFeesDecodeErrorZ), "LDKCResult_RoutingFeesDecodeErrorZ");
6119         *ret_conv = CResult_RoutingFeesDecodeErrorZ_ok(o_conv);
6120         return (long)ret_conv;
6121 }
6122
6123 uint32_t TS_CResult_RoutingFeesDecodeErrorZ_err(uint32_t e) {
6124         LDKDecodeError e_conv;
6125         e_conv.inner = (void*)(e & (~1));
6126         e_conv.is_owned = (e & 1) || (e == 0);
6127         // Warning: we may need a move here but can't clone!
6128         LDKCResult_RoutingFeesDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_RoutingFeesDecodeErrorZ), "LDKCResult_RoutingFeesDecodeErrorZ");
6129         *ret_conv = CResult_RoutingFeesDecodeErrorZ_err(e_conv);
6130         return (long)ret_conv;
6131 }
6132
6133 void TS_CResult_RoutingFeesDecodeErrorZ_free(uint32_t _res) {
6134         LDKCResult_RoutingFeesDecodeErrorZ _res_conv = *(LDKCResult_RoutingFeesDecodeErrorZ*)_res;
6135         FREE((void*)_res);
6136         CResult_RoutingFeesDecodeErrorZ_free(_res_conv);
6137 }
6138
6139 uint32_t TS_CResult_NodeAnnouncementInfoDecodeErrorZ_ok(uint32_t o) {
6140         LDKNodeAnnouncementInfo o_conv;
6141         o_conv.inner = (void*)(o & (~1));
6142         o_conv.is_owned = (o & 1) || (o == 0);
6143         // Warning: we may need a move here but can't clone!
6144         LDKCResult_NodeAnnouncementInfoDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NodeAnnouncementInfoDecodeErrorZ), "LDKCResult_NodeAnnouncementInfoDecodeErrorZ");
6145         *ret_conv = CResult_NodeAnnouncementInfoDecodeErrorZ_ok(o_conv);
6146         return (long)ret_conv;
6147 }
6148
6149 uint32_t TS_CResult_NodeAnnouncementInfoDecodeErrorZ_err(uint32_t e) {
6150         LDKDecodeError e_conv;
6151         e_conv.inner = (void*)(e & (~1));
6152         e_conv.is_owned = (e & 1) || (e == 0);
6153         // Warning: we may need a move here but can't clone!
6154         LDKCResult_NodeAnnouncementInfoDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NodeAnnouncementInfoDecodeErrorZ), "LDKCResult_NodeAnnouncementInfoDecodeErrorZ");
6155         *ret_conv = CResult_NodeAnnouncementInfoDecodeErrorZ_err(e_conv);
6156         return (long)ret_conv;
6157 }
6158
6159 void TS_CResult_NodeAnnouncementInfoDecodeErrorZ_free(uint32_t _res) {
6160         LDKCResult_NodeAnnouncementInfoDecodeErrorZ _res_conv = *(LDKCResult_NodeAnnouncementInfoDecodeErrorZ*)_res;
6161         FREE((void*)_res);
6162         CResult_NodeAnnouncementInfoDecodeErrorZ_free(_res_conv);
6163 }
6164
6165 uint32_t TS_CResult_NodeInfoDecodeErrorZ_ok(uint32_t o) {
6166         LDKNodeInfo o_conv;
6167         o_conv.inner = (void*)(o & (~1));
6168         o_conv.is_owned = (o & 1) || (o == 0);
6169         // Warning: we may need a move here but can't clone!
6170         LDKCResult_NodeInfoDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NodeInfoDecodeErrorZ), "LDKCResult_NodeInfoDecodeErrorZ");
6171         *ret_conv = CResult_NodeInfoDecodeErrorZ_ok(o_conv);
6172         return (long)ret_conv;
6173 }
6174
6175 uint32_t TS_CResult_NodeInfoDecodeErrorZ_err(uint32_t e) {
6176         LDKDecodeError e_conv;
6177         e_conv.inner = (void*)(e & (~1));
6178         e_conv.is_owned = (e & 1) || (e == 0);
6179         // Warning: we may need a move here but can't clone!
6180         LDKCResult_NodeInfoDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NodeInfoDecodeErrorZ), "LDKCResult_NodeInfoDecodeErrorZ");
6181         *ret_conv = CResult_NodeInfoDecodeErrorZ_err(e_conv);
6182         return (long)ret_conv;
6183 }
6184
6185 void TS_CResult_NodeInfoDecodeErrorZ_free(uint32_t _res) {
6186         LDKCResult_NodeInfoDecodeErrorZ _res_conv = *(LDKCResult_NodeInfoDecodeErrorZ*)_res;
6187         FREE((void*)_res);
6188         CResult_NodeInfoDecodeErrorZ_free(_res_conv);
6189 }
6190
6191 uint32_t TS_CResult_NetworkGraphDecodeErrorZ_ok(uint32_t o) {
6192         LDKNetworkGraph o_conv;
6193         o_conv.inner = (void*)(o & (~1));
6194         o_conv.is_owned = (o & 1) || (o == 0);
6195         // Warning: we may need a move here but can't clone!
6196         LDKCResult_NetworkGraphDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NetworkGraphDecodeErrorZ), "LDKCResult_NetworkGraphDecodeErrorZ");
6197         *ret_conv = CResult_NetworkGraphDecodeErrorZ_ok(o_conv);
6198         return (long)ret_conv;
6199 }
6200
6201 uint32_t TS_CResult_NetworkGraphDecodeErrorZ_err(uint32_t e) {
6202         LDKDecodeError e_conv;
6203         e_conv.inner = (void*)(e & (~1));
6204         e_conv.is_owned = (e & 1) || (e == 0);
6205         // Warning: we may need a move here but can't clone!
6206         LDKCResult_NetworkGraphDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NetworkGraphDecodeErrorZ), "LDKCResult_NetworkGraphDecodeErrorZ");
6207         *ret_conv = CResult_NetworkGraphDecodeErrorZ_err(e_conv);
6208         return (long)ret_conv;
6209 }
6210
6211 void TS_CResult_NetworkGraphDecodeErrorZ_free(uint32_t _res) {
6212         LDKCResult_NetworkGraphDecodeErrorZ _res_conv = *(LDKCResult_NetworkGraphDecodeErrorZ*)_res;
6213         FREE((void*)_res);
6214         CResult_NetworkGraphDecodeErrorZ_free(_res_conv);
6215 }
6216
6217 void TS_Event_free(uint32_t this_ptr) {
6218         LDKEvent this_ptr_conv = *(LDKEvent*)this_ptr;
6219         FREE((void*)this_ptr);
6220         Event_free(this_ptr_conv);
6221 }
6222
6223 uint32_t TS_Event_clone(uint32_t orig) {
6224         LDKEvent* orig_conv = (LDKEvent*)orig;
6225         LDKEvent *ret_copy = MALLOC(sizeof(LDKEvent), "LDKEvent");
6226         *ret_copy = Event_clone(orig_conv);
6227         long ret_ref = (long)ret_copy;
6228         return ret_ref;
6229 }
6230
6231 int8_tArray TS_Event_write(uint32_t obj) {
6232         LDKEvent* obj_conv = (LDKEvent*)obj;
6233         LDKCVec_u8Z arg_var = Event_write(obj_conv);
6234         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
6235         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
6236         CVec_u8Z_free(arg_var);
6237         return arg_arr;
6238 }
6239
6240 void TS_MessageSendEvent_free(uint32_t this_ptr) {
6241         LDKMessageSendEvent this_ptr_conv = *(LDKMessageSendEvent*)this_ptr;
6242         FREE((void*)this_ptr);
6243         MessageSendEvent_free(this_ptr_conv);
6244 }
6245
6246 uint32_t TS_MessageSendEvent_clone(uint32_t orig) {
6247         LDKMessageSendEvent* orig_conv = (LDKMessageSendEvent*)orig;
6248         LDKMessageSendEvent *ret_copy = MALLOC(sizeof(LDKMessageSendEvent), "LDKMessageSendEvent");
6249         *ret_copy = MessageSendEvent_clone(orig_conv);
6250         long ret_ref = (long)ret_copy;
6251         return ret_ref;
6252 }
6253
6254 void TS_MessageSendEventsProvider_free(uint32_t this_ptr) {
6255         LDKMessageSendEventsProvider this_ptr_conv = *(LDKMessageSendEventsProvider*)this_ptr;
6256         FREE((void*)this_ptr);
6257         MessageSendEventsProvider_free(this_ptr_conv);
6258 }
6259
6260 void TS_EventsProvider_free(uint32_t this_ptr) {
6261         LDKEventsProvider this_ptr_conv = *(LDKEventsProvider*)this_ptr;
6262         FREE((void*)this_ptr);
6263         EventsProvider_free(this_ptr_conv);
6264 }
6265
6266 void TS_APIError_free(uint32_t this_ptr) {
6267         LDKAPIError this_ptr_conv = *(LDKAPIError*)this_ptr;
6268         FREE((void*)this_ptr);
6269         APIError_free(this_ptr_conv);
6270 }
6271
6272 uint32_t TS_APIError_clone(uint32_t orig) {
6273         LDKAPIError* orig_conv = (LDKAPIError*)orig;
6274         LDKAPIError *ret_copy = MALLOC(sizeof(LDKAPIError), "LDKAPIError");
6275         *ret_copy = APIError_clone(orig_conv);
6276         long ret_ref = (long)ret_copy;
6277         return ret_ref;
6278 }
6279
6280 uint32_t TS_Level_clone(uint32_t orig) {
6281         LDKLevel* orig_conv = (LDKLevel*)orig;
6282         uint32_t ret_conv = LDKLevel_to_js(Level_clone(orig_conv));
6283         return ret_conv;
6284 }
6285
6286 uint32_t TS_Level_max() {
6287         uint32_t ret_conv = LDKLevel_to_js(Level_max());
6288         return ret_conv;
6289 }
6290
6291 void TS_Logger_free(uint32_t this_ptr) {
6292         LDKLogger this_ptr_conv = *(LDKLogger*)this_ptr;
6293         FREE((void*)this_ptr);
6294         Logger_free(this_ptr_conv);
6295 }
6296
6297 void TS_ChannelHandshakeConfig_free(uint32_t this_ptr) {
6298         LDKChannelHandshakeConfig this_ptr_conv;
6299         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6300         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
6301         ChannelHandshakeConfig_free(this_ptr_conv);
6302 }
6303
6304 uint32_t TS_ChannelHandshakeConfig_clone(uint32_t orig) {
6305         LDKChannelHandshakeConfig orig_conv;
6306         orig_conv.inner = (void*)(orig & (~1));
6307         orig_conv.is_owned = false;
6308         LDKChannelHandshakeConfig ret_var = ChannelHandshakeConfig_clone(&orig_conv);
6309         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6310         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6311         long ret_ref = (long)ret_var.inner;
6312         if (ret_var.is_owned) {
6313                 ret_ref |= 1;
6314         }
6315         return ret_ref;
6316 }
6317
6318 int32_t TS_ChannelHandshakeConfig_get_minimum_depth(uint32_t this_ptr) {
6319         LDKChannelHandshakeConfig this_ptr_conv;
6320         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6321         this_ptr_conv.is_owned = false;
6322         int32_t ret_val = ChannelHandshakeConfig_get_minimum_depth(&this_ptr_conv);
6323         return ret_val;
6324 }
6325
6326 void TS_ChannelHandshakeConfig_set_minimum_depth(uint32_t this_ptr, int32_t val) {
6327         LDKChannelHandshakeConfig this_ptr_conv;
6328         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6329         this_ptr_conv.is_owned = false;
6330         ChannelHandshakeConfig_set_minimum_depth(&this_ptr_conv, val);
6331 }
6332
6333 int16_t TS_ChannelHandshakeConfig_get_our_to_self_delay(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         int16_t ret_val = ChannelHandshakeConfig_get_our_to_self_delay(&this_ptr_conv);
6338         return ret_val;
6339 }
6340
6341 void TS_ChannelHandshakeConfig_set_our_to_self_delay(uint32_t this_ptr, int16_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_our_to_self_delay(&this_ptr_conv, val);
6346 }
6347
6348 int64_t TS_ChannelHandshakeConfig_get_our_htlc_minimum_msat(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         int64_t ret_val = ChannelHandshakeConfig_get_our_htlc_minimum_msat(&this_ptr_conv);
6353         return ret_val;
6354 }
6355
6356 void TS_ChannelHandshakeConfig_set_our_htlc_minimum_msat(uint32_t this_ptr, int64_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_htlc_minimum_msat(&this_ptr_conv, val);
6361 }
6362
6363 uint32_t TS_ChannelHandshakeConfig_new(int32_t minimum_depth_arg, int16_t our_to_self_delay_arg, int64_t our_htlc_minimum_msat_arg) {
6364         LDKChannelHandshakeConfig ret_var = ChannelHandshakeConfig_new(minimum_depth_arg, our_to_self_delay_arg, our_htlc_minimum_msat_arg);
6365         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6366         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6367         long ret_ref = (long)ret_var.inner;
6368         if (ret_var.is_owned) {
6369                 ret_ref |= 1;
6370         }
6371         return ret_ref;
6372 }
6373
6374 uint32_t TS_ChannelHandshakeConfig_default() {
6375         LDKChannelHandshakeConfig ret_var = ChannelHandshakeConfig_default();
6376         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6377         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6378         long ret_ref = (long)ret_var.inner;
6379         if (ret_var.is_owned) {
6380                 ret_ref |= 1;
6381         }
6382         return ret_ref;
6383 }
6384
6385 void TS_ChannelHandshakeLimits_free(uint32_t this_ptr) {
6386         LDKChannelHandshakeLimits this_ptr_conv;
6387         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6388         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
6389         ChannelHandshakeLimits_free(this_ptr_conv);
6390 }
6391
6392 uint32_t TS_ChannelHandshakeLimits_clone(uint32_t orig) {
6393         LDKChannelHandshakeLimits orig_conv;
6394         orig_conv.inner = (void*)(orig & (~1));
6395         orig_conv.is_owned = false;
6396         LDKChannelHandshakeLimits ret_var = ChannelHandshakeLimits_clone(&orig_conv);
6397         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6398         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6399         long ret_ref = (long)ret_var.inner;
6400         if (ret_var.is_owned) {
6401                 ret_ref |= 1;
6402         }
6403         return ret_ref;
6404 }
6405
6406 int64_t TS_ChannelHandshakeLimits_get_min_funding_satoshis(uint32_t this_ptr) {
6407         LDKChannelHandshakeLimits this_ptr_conv;
6408         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6409         this_ptr_conv.is_owned = false;
6410         int64_t ret_val = ChannelHandshakeLimits_get_min_funding_satoshis(&this_ptr_conv);
6411         return ret_val;
6412 }
6413
6414 void TS_ChannelHandshakeLimits_set_min_funding_satoshis(uint32_t this_ptr, int64_t val) {
6415         LDKChannelHandshakeLimits this_ptr_conv;
6416         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6417         this_ptr_conv.is_owned = false;
6418         ChannelHandshakeLimits_set_min_funding_satoshis(&this_ptr_conv, val);
6419 }
6420
6421 int64_t TS_ChannelHandshakeLimits_get_max_htlc_minimum_msat(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_max_htlc_minimum_msat(&this_ptr_conv);
6426         return ret_val;
6427 }
6428
6429 void TS_ChannelHandshakeLimits_set_max_htlc_minimum_msat(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_max_htlc_minimum_msat(&this_ptr_conv, val);
6434 }
6435
6436 int64_t TS_ChannelHandshakeLimits_get_min_max_htlc_value_in_flight_msat(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_min_max_htlc_value_in_flight_msat(&this_ptr_conv);
6441         return ret_val;
6442 }
6443
6444 void TS_ChannelHandshakeLimits_set_min_max_htlc_value_in_flight_msat(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_min_max_htlc_value_in_flight_msat(&this_ptr_conv, val);
6449 }
6450
6451 int64_t TS_ChannelHandshakeLimits_get_max_channel_reserve_satoshis(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_max_channel_reserve_satoshis(&this_ptr_conv);
6456         return ret_val;
6457 }
6458
6459 void TS_ChannelHandshakeLimits_set_max_channel_reserve_satoshis(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_max_channel_reserve_satoshis(&this_ptr_conv, val);
6464 }
6465
6466 int16_t TS_ChannelHandshakeLimits_get_min_max_accepted_htlcs(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         int16_t ret_val = ChannelHandshakeLimits_get_min_max_accepted_htlcs(&this_ptr_conv);
6471         return ret_val;
6472 }
6473
6474 void TS_ChannelHandshakeLimits_set_min_max_accepted_htlcs(uint32_t this_ptr, int16_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_min_max_accepted_htlcs(&this_ptr_conv, val);
6479 }
6480
6481 int64_t TS_ChannelHandshakeLimits_get_min_dust_limit_satoshis(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         int64_t ret_val = ChannelHandshakeLimits_get_min_dust_limit_satoshis(&this_ptr_conv);
6486         return ret_val;
6487 }
6488
6489 void TS_ChannelHandshakeLimits_set_min_dust_limit_satoshis(uint32_t this_ptr, int64_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_dust_limit_satoshis(&this_ptr_conv, val);
6494 }
6495
6496 int64_t TS_ChannelHandshakeLimits_get_max_dust_limit_satoshis(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_max_dust_limit_satoshis(&this_ptr_conv);
6501         return ret_val;
6502 }
6503
6504 void TS_ChannelHandshakeLimits_set_max_dust_limit_satoshis(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_max_dust_limit_satoshis(&this_ptr_conv, val);
6509 }
6510
6511 int32_t TS_ChannelHandshakeLimits_get_max_minimum_depth(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         int32_t ret_val = ChannelHandshakeLimits_get_max_minimum_depth(&this_ptr_conv);
6516         return ret_val;
6517 }
6518
6519 void TS_ChannelHandshakeLimits_set_max_minimum_depth(uint32_t this_ptr, int32_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_minimum_depth(&this_ptr_conv, val);
6524 }
6525
6526 jboolean TS_ChannelHandshakeLimits_get_force_announced_channel_preference(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         jboolean ret_val = ChannelHandshakeLimits_get_force_announced_channel_preference(&this_ptr_conv);
6531         return ret_val;
6532 }
6533
6534 void TS_ChannelHandshakeLimits_set_force_announced_channel_preference(uint32_t this_ptr, jboolean 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_force_announced_channel_preference(&this_ptr_conv, val);
6539 }
6540
6541 int16_t TS_ChannelHandshakeLimits_get_their_to_self_delay(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         int16_t ret_val = ChannelHandshakeLimits_get_their_to_self_delay(&this_ptr_conv);
6546         return ret_val;
6547 }
6548
6549 void TS_ChannelHandshakeLimits_set_their_to_self_delay(uint32_t this_ptr, int16_t 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_their_to_self_delay(&this_ptr_conv, val);
6554 }
6555
6556 uint32_t TS_ChannelHandshakeLimits_new(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) {
6557         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);
6558         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6559         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6560         long ret_ref = (long)ret_var.inner;
6561         if (ret_var.is_owned) {
6562                 ret_ref |= 1;
6563         }
6564         return ret_ref;
6565 }
6566
6567 uint32_t TS_ChannelHandshakeLimits_default() {
6568         LDKChannelHandshakeLimits ret_var = ChannelHandshakeLimits_default();
6569         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6570         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6571         long ret_ref = (long)ret_var.inner;
6572         if (ret_var.is_owned) {
6573                 ret_ref |= 1;
6574         }
6575         return ret_ref;
6576 }
6577
6578 void TS_ChannelConfig_free(uint32_t this_ptr) {
6579         LDKChannelConfig this_ptr_conv;
6580         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6581         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
6582         ChannelConfig_free(this_ptr_conv);
6583 }
6584
6585 uint32_t TS_ChannelConfig_clone(uint32_t orig) {
6586         LDKChannelConfig orig_conv;
6587         orig_conv.inner = (void*)(orig & (~1));
6588         orig_conv.is_owned = false;
6589         LDKChannelConfig ret_var = ChannelConfig_clone(&orig_conv);
6590         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6591         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6592         long ret_ref = (long)ret_var.inner;
6593         if (ret_var.is_owned) {
6594                 ret_ref |= 1;
6595         }
6596         return ret_ref;
6597 }
6598
6599 int32_t TS_ChannelConfig_get_fee_proportional_millionths(uint32_t this_ptr) {
6600         LDKChannelConfig this_ptr_conv;
6601         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6602         this_ptr_conv.is_owned = false;
6603         int32_t ret_val = ChannelConfig_get_fee_proportional_millionths(&this_ptr_conv);
6604         return ret_val;
6605 }
6606
6607 void TS_ChannelConfig_set_fee_proportional_millionths(uint32_t this_ptr, int32_t val) {
6608         LDKChannelConfig this_ptr_conv;
6609         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6610         this_ptr_conv.is_owned = false;
6611         ChannelConfig_set_fee_proportional_millionths(&this_ptr_conv, val);
6612 }
6613
6614 jboolean TS_ChannelConfig_get_announced_channel(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         jboolean ret_val = ChannelConfig_get_announced_channel(&this_ptr_conv);
6619         return ret_val;
6620 }
6621
6622 void TS_ChannelConfig_set_announced_channel(uint32_t this_ptr, jboolean 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_announced_channel(&this_ptr_conv, val);
6627 }
6628
6629 jboolean TS_ChannelConfig_get_commit_upfront_shutdown_pubkey(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_commit_upfront_shutdown_pubkey(&this_ptr_conv);
6634         return ret_val;
6635 }
6636
6637 void TS_ChannelConfig_set_commit_upfront_shutdown_pubkey(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_commit_upfront_shutdown_pubkey(&this_ptr_conv, val);
6642 }
6643
6644 uint32_t TS_ChannelConfig_new(int32_t fee_proportional_millionths_arg, jboolean announced_channel_arg, jboolean commit_upfront_shutdown_pubkey_arg) {
6645         LDKChannelConfig ret_var = ChannelConfig_new(fee_proportional_millionths_arg, announced_channel_arg, commit_upfront_shutdown_pubkey_arg);
6646         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6647         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6648         long ret_ref = (long)ret_var.inner;
6649         if (ret_var.is_owned) {
6650                 ret_ref |= 1;
6651         }
6652         return ret_ref;
6653 }
6654
6655 uint32_t TS_ChannelConfig_default() {
6656         LDKChannelConfig ret_var = ChannelConfig_default();
6657         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6658         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6659         long ret_ref = (long)ret_var.inner;
6660         if (ret_var.is_owned) {
6661                 ret_ref |= 1;
6662         }
6663         return ret_ref;
6664 }
6665
6666 int8_tArray TS_ChannelConfig_write(uint32_t obj) {
6667         LDKChannelConfig obj_conv;
6668         obj_conv.inner = (void*)(obj & (~1));
6669         obj_conv.is_owned = false;
6670         LDKCVec_u8Z arg_var = ChannelConfig_write(&obj_conv);
6671         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
6672         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
6673         CVec_u8Z_free(arg_var);
6674         return arg_arr;
6675 }
6676
6677 uint32_t TS_ChannelConfig_read(int8_tArray ser) {
6678         LDKu8slice ser_ref;
6679         ser_ref.datalen = *((uint32_t*)ser);
6680         ser_ref.data = (int8_t*)(ser + 4);
6681         LDKChannelConfig ret_var = ChannelConfig_read(ser_ref);
6682         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6683         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6684         long ret_ref = (long)ret_var.inner;
6685         if (ret_var.is_owned) {
6686                 ret_ref |= 1;
6687         }
6688         return ret_ref;
6689 }
6690
6691 void TS_UserConfig_free(uint32_t this_ptr) {
6692         LDKUserConfig this_ptr_conv;
6693         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6694         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
6695         UserConfig_free(this_ptr_conv);
6696 }
6697
6698 uint32_t TS_UserConfig_clone(uint32_t orig) {
6699         LDKUserConfig orig_conv;
6700         orig_conv.inner = (void*)(orig & (~1));
6701         orig_conv.is_owned = false;
6702         LDKUserConfig ret_var = UserConfig_clone(&orig_conv);
6703         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6704         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6705         long ret_ref = (long)ret_var.inner;
6706         if (ret_var.is_owned) {
6707                 ret_ref |= 1;
6708         }
6709         return ret_ref;
6710 }
6711
6712 uint32_t TS_UserConfig_get_own_channel_config(uint32_t this_ptr) {
6713         LDKUserConfig this_ptr_conv;
6714         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6715         this_ptr_conv.is_owned = false;
6716         LDKChannelHandshakeConfig ret_var = UserConfig_get_own_channel_config(&this_ptr_conv);
6717         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6718         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6719         long ret_ref = (long)ret_var.inner;
6720         if (ret_var.is_owned) {
6721                 ret_ref |= 1;
6722         }
6723         return ret_ref;
6724 }
6725
6726 void TS_UserConfig_set_own_channel_config(uint32_t this_ptr, uint32_t val) {
6727         LDKUserConfig this_ptr_conv;
6728         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6729         this_ptr_conv.is_owned = false;
6730         LDKChannelHandshakeConfig val_conv;
6731         val_conv.inner = (void*)(val & (~1));
6732         val_conv.is_owned = (val & 1) || (val == 0);
6733         if (val_conv.inner != NULL)
6734                 val_conv = ChannelHandshakeConfig_clone(&val_conv);
6735         UserConfig_set_own_channel_config(&this_ptr_conv, val_conv);
6736 }
6737
6738 uint32_t TS_UserConfig_get_peer_channel_config_limits(uint32_t this_ptr) {
6739         LDKUserConfig this_ptr_conv;
6740         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6741         this_ptr_conv.is_owned = false;
6742         LDKChannelHandshakeLimits ret_var = UserConfig_get_peer_channel_config_limits(&this_ptr_conv);
6743         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6744         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6745         long ret_ref = (long)ret_var.inner;
6746         if (ret_var.is_owned) {
6747                 ret_ref |= 1;
6748         }
6749         return ret_ref;
6750 }
6751
6752 void TS_UserConfig_set_peer_channel_config_limits(uint32_t this_ptr, uint32_t val) {
6753         LDKUserConfig this_ptr_conv;
6754         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6755         this_ptr_conv.is_owned = false;
6756         LDKChannelHandshakeLimits val_conv;
6757         val_conv.inner = (void*)(val & (~1));
6758         val_conv.is_owned = (val & 1) || (val == 0);
6759         if (val_conv.inner != NULL)
6760                 val_conv = ChannelHandshakeLimits_clone(&val_conv);
6761         UserConfig_set_peer_channel_config_limits(&this_ptr_conv, val_conv);
6762 }
6763
6764 uint32_t TS_UserConfig_get_channel_options(uint32_t this_ptr) {
6765         LDKUserConfig this_ptr_conv;
6766         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6767         this_ptr_conv.is_owned = false;
6768         LDKChannelConfig ret_var = UserConfig_get_channel_options(&this_ptr_conv);
6769         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6770         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6771         long ret_ref = (long)ret_var.inner;
6772         if (ret_var.is_owned) {
6773                 ret_ref |= 1;
6774         }
6775         return ret_ref;
6776 }
6777
6778 void TS_UserConfig_set_channel_options(uint32_t this_ptr, uint32_t val) {
6779         LDKUserConfig this_ptr_conv;
6780         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6781         this_ptr_conv.is_owned = false;
6782         LDKChannelConfig val_conv;
6783         val_conv.inner = (void*)(val & (~1));
6784         val_conv.is_owned = (val & 1) || (val == 0);
6785         if (val_conv.inner != NULL)
6786                 val_conv = ChannelConfig_clone(&val_conv);
6787         UserConfig_set_channel_options(&this_ptr_conv, val_conv);
6788 }
6789
6790 uint32_t TS_UserConfig_new(uint32_t own_channel_config_arg, uint32_t peer_channel_config_limits_arg, uint32_t channel_options_arg) {
6791         LDKChannelHandshakeConfig own_channel_config_arg_conv;
6792         own_channel_config_arg_conv.inner = (void*)(own_channel_config_arg & (~1));
6793         own_channel_config_arg_conv.is_owned = (own_channel_config_arg & 1) || (own_channel_config_arg == 0);
6794         if (own_channel_config_arg_conv.inner != NULL)
6795                 own_channel_config_arg_conv = ChannelHandshakeConfig_clone(&own_channel_config_arg_conv);
6796         LDKChannelHandshakeLimits peer_channel_config_limits_arg_conv;
6797         peer_channel_config_limits_arg_conv.inner = (void*)(peer_channel_config_limits_arg & (~1));
6798         peer_channel_config_limits_arg_conv.is_owned = (peer_channel_config_limits_arg & 1) || (peer_channel_config_limits_arg == 0);
6799         if (peer_channel_config_limits_arg_conv.inner != NULL)
6800                 peer_channel_config_limits_arg_conv = ChannelHandshakeLimits_clone(&peer_channel_config_limits_arg_conv);
6801         LDKChannelConfig channel_options_arg_conv;
6802         channel_options_arg_conv.inner = (void*)(channel_options_arg & (~1));
6803         channel_options_arg_conv.is_owned = (channel_options_arg & 1) || (channel_options_arg == 0);
6804         if (channel_options_arg_conv.inner != NULL)
6805                 channel_options_arg_conv = ChannelConfig_clone(&channel_options_arg_conv);
6806         LDKUserConfig ret_var = UserConfig_new(own_channel_config_arg_conv, peer_channel_config_limits_arg_conv, channel_options_arg_conv);
6807         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6808         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6809         long ret_ref = (long)ret_var.inner;
6810         if (ret_var.is_owned) {
6811                 ret_ref |= 1;
6812         }
6813         return ret_ref;
6814 }
6815
6816 uint32_t TS_UserConfig_default() {
6817         LDKUserConfig ret_var = UserConfig_default();
6818         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6819         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6820         long ret_ref = (long)ret_var.inner;
6821         if (ret_var.is_owned) {
6822                 ret_ref |= 1;
6823         }
6824         return ret_ref;
6825 }
6826
6827 uint32_t TS_AccessError_clone(uint32_t orig) {
6828         LDKAccessError* orig_conv = (LDKAccessError*)orig;
6829         uint32_t ret_conv = LDKAccessError_to_js(AccessError_clone(orig_conv));
6830         return ret_conv;
6831 }
6832
6833 void TS_Access_free(uint32_t this_ptr) {
6834         LDKAccess this_ptr_conv = *(LDKAccess*)this_ptr;
6835         FREE((void*)this_ptr);
6836         Access_free(this_ptr_conv);
6837 }
6838
6839 void TS_Watch_free(uint32_t this_ptr) {
6840         LDKWatch this_ptr_conv = *(LDKWatch*)this_ptr;
6841         FREE((void*)this_ptr);
6842         Watch_free(this_ptr_conv);
6843 }
6844
6845 void TS_Filter_free(uint32_t this_ptr) {
6846         LDKFilter this_ptr_conv = *(LDKFilter*)this_ptr;
6847         FREE((void*)this_ptr);
6848         Filter_free(this_ptr_conv);
6849 }
6850
6851 void TS_BroadcasterInterface_free(uint32_t this_ptr) {
6852         LDKBroadcasterInterface this_ptr_conv = *(LDKBroadcasterInterface*)this_ptr;
6853         FREE((void*)this_ptr);
6854         BroadcasterInterface_free(this_ptr_conv);
6855 }
6856
6857 uint32_t TS_ConfirmationTarget_clone(uint32_t orig) {
6858         LDKConfirmationTarget* orig_conv = (LDKConfirmationTarget*)orig;
6859         uint32_t ret_conv = LDKConfirmationTarget_to_js(ConfirmationTarget_clone(orig_conv));
6860         return ret_conv;
6861 }
6862
6863 void TS_FeeEstimator_free(uint32_t this_ptr) {
6864         LDKFeeEstimator this_ptr_conv = *(LDKFeeEstimator*)this_ptr;
6865         FREE((void*)this_ptr);
6866         FeeEstimator_free(this_ptr_conv);
6867 }
6868
6869 void TS_ChainMonitor_free(uint32_t this_ptr) {
6870         LDKChainMonitor this_ptr_conv;
6871         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6872         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
6873         ChainMonitor_free(this_ptr_conv);
6874 }
6875
6876 void TS_ChainMonitor_block_connected(uint32_t this_arg, int8_tArray header, uint32_tArray txdata, int32_t height) {
6877         LDKChainMonitor this_arg_conv;
6878         this_arg_conv.inner = (void*)(this_arg & (~1));
6879         this_arg_conv.is_owned = false;
6880         unsigned char header_arr[80];
6881         CHECK(*((uint32_t*)header) == 80);
6882         memcpy(header_arr, (uint8_t*)(header + 4), 80);
6883         unsigned char (*header_ref)[80] = &header_arr;
6884         LDKCVec_C2Tuple_usizeTransactionZZ txdata_constr;
6885         txdata_constr.datalen = *((uint32_t*)txdata);
6886         if (txdata_constr.datalen > 0)
6887                 txdata_constr.data = MALLOC(txdata_constr.datalen * sizeof(LDKC2Tuple_usizeTransactionZ), "LDKCVec_C2Tuple_usizeTransactionZZ Elements");
6888         else
6889                 txdata_constr.data = NULL;
6890         uint32_t* txdata_vals = (uint32_t*)(txdata + 4);
6891         for (size_t e = 0; e < txdata_constr.datalen; e++) {
6892                 uint32_t arr_conv_30 = txdata_vals[e];
6893                 LDKC2Tuple_usizeTransactionZ arr_conv_30_conv = *(LDKC2Tuple_usizeTransactionZ*)arr_conv_30;
6894                 FREE((void*)arr_conv_30);
6895                 txdata_constr.data[e] = arr_conv_30_conv;
6896         }
6897         ChainMonitor_block_connected(&this_arg_conv, header_ref, txdata_constr, height);
6898 }
6899
6900 void TS_ChainMonitor_block_disconnected(uint32_t this_arg, int8_tArray header, int32_t disconnected_height) {
6901         LDKChainMonitor this_arg_conv;
6902         this_arg_conv.inner = (void*)(this_arg & (~1));
6903         this_arg_conv.is_owned = false;
6904         unsigned char header_arr[80];
6905         CHECK(*((uint32_t*)header) == 80);
6906         memcpy(header_arr, (uint8_t*)(header + 4), 80);
6907         unsigned char (*header_ref)[80] = &header_arr;
6908         ChainMonitor_block_disconnected(&this_arg_conv, header_ref, disconnected_height);
6909 }
6910
6911 uint32_t TS_ChainMonitor_new(uint32_t chain_source, uint32_t broadcaster, uint32_t logger, uint32_t feeest, uint32_t persister) {
6912         LDKFilter* chain_source_conv = (LDKFilter*)chain_source;
6913         LDKBroadcasterInterface broadcaster_conv = *(LDKBroadcasterInterface*)broadcaster;
6914         LDKLogger logger_conv = *(LDKLogger*)logger;
6915         LDKFeeEstimator feeest_conv = *(LDKFeeEstimator*)feeest;
6916         LDKPersist persister_conv = *(LDKPersist*)persister;
6917         LDKChainMonitor ret_var = ChainMonitor_new(chain_source_conv, broadcaster_conv, logger_conv, feeest_conv, persister_conv);
6918         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6919         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6920         long ret_ref = (long)ret_var.inner;
6921         if (ret_var.is_owned) {
6922                 ret_ref |= 1;
6923         }
6924         return ret_ref;
6925 }
6926
6927 uint32_t TS_ChainMonitor_as_Watch(uint32_t this_arg) {
6928         LDKChainMonitor this_arg_conv;
6929         this_arg_conv.inner = (void*)(this_arg & (~1));
6930         this_arg_conv.is_owned = false;
6931         LDKWatch* ret = MALLOC(sizeof(LDKWatch), "LDKWatch");
6932         *ret = ChainMonitor_as_Watch(&this_arg_conv);
6933         return (long)ret;
6934 }
6935
6936 uint32_t TS_ChainMonitor_as_EventsProvider(uint32_t this_arg) {
6937         LDKChainMonitor this_arg_conv;
6938         this_arg_conv.inner = (void*)(this_arg & (~1));
6939         this_arg_conv.is_owned = false;
6940         LDKEventsProvider* ret = MALLOC(sizeof(LDKEventsProvider), "LDKEventsProvider");
6941         *ret = ChainMonitor_as_EventsProvider(&this_arg_conv);
6942         return (long)ret;
6943 }
6944
6945 void TS_ChannelMonitorUpdate_free(uint32_t this_ptr) {
6946         LDKChannelMonitorUpdate this_ptr_conv;
6947         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6948         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
6949         ChannelMonitorUpdate_free(this_ptr_conv);
6950 }
6951
6952 uint32_t TS_ChannelMonitorUpdate_clone(uint32_t orig) {
6953         LDKChannelMonitorUpdate orig_conv;
6954         orig_conv.inner = (void*)(orig & (~1));
6955         orig_conv.is_owned = false;
6956         LDKChannelMonitorUpdate ret_var = ChannelMonitorUpdate_clone(&orig_conv);
6957         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6958         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6959         long ret_ref = (long)ret_var.inner;
6960         if (ret_var.is_owned) {
6961                 ret_ref |= 1;
6962         }
6963         return ret_ref;
6964 }
6965
6966 int64_t TS_ChannelMonitorUpdate_get_update_id(uint32_t this_ptr) {
6967         LDKChannelMonitorUpdate this_ptr_conv;
6968         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6969         this_ptr_conv.is_owned = false;
6970         int64_t ret_val = ChannelMonitorUpdate_get_update_id(&this_ptr_conv);
6971         return ret_val;
6972 }
6973
6974 void TS_ChannelMonitorUpdate_set_update_id(uint32_t this_ptr, int64_t val) {
6975         LDKChannelMonitorUpdate this_ptr_conv;
6976         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6977         this_ptr_conv.is_owned = false;
6978         ChannelMonitorUpdate_set_update_id(&this_ptr_conv, val);
6979 }
6980
6981 int8_tArray TS_ChannelMonitorUpdate_write(uint32_t obj) {
6982         LDKChannelMonitorUpdate obj_conv;
6983         obj_conv.inner = (void*)(obj & (~1));
6984         obj_conv.is_owned = false;
6985         LDKCVec_u8Z arg_var = ChannelMonitorUpdate_write(&obj_conv);
6986         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
6987         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
6988         CVec_u8Z_free(arg_var);
6989         return arg_arr;
6990 }
6991
6992 uint32_t TS_ChannelMonitorUpdate_read(int8_tArray ser) {
6993         LDKu8slice ser_ref;
6994         ser_ref.datalen = *((uint32_t*)ser);
6995         ser_ref.data = (int8_t*)(ser + 4);
6996         LDKCResult_ChannelMonitorUpdateDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ChannelMonitorUpdateDecodeErrorZ), "LDKCResult_ChannelMonitorUpdateDecodeErrorZ");
6997         *ret_conv = ChannelMonitorUpdate_read(ser_ref);
6998         return (long)ret_conv;
6999 }
7000
7001 uint32_t TS_ChannelMonitorUpdateErr_clone(uint32_t orig) {
7002         LDKChannelMonitorUpdateErr* orig_conv = (LDKChannelMonitorUpdateErr*)orig;
7003         uint32_t ret_conv = LDKChannelMonitorUpdateErr_to_js(ChannelMonitorUpdateErr_clone(orig_conv));
7004         return ret_conv;
7005 }
7006
7007 void TS_MonitorUpdateError_free(uint32_t this_ptr) {
7008         LDKMonitorUpdateError this_ptr_conv;
7009         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7010         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7011         MonitorUpdateError_free(this_ptr_conv);
7012 }
7013
7014 void TS_MonitorEvent_free(uint32_t this_ptr) {
7015         LDKMonitorEvent this_ptr_conv;
7016         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7017         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7018         MonitorEvent_free(this_ptr_conv);
7019 }
7020
7021 uint32_t TS_MonitorEvent_clone(uint32_t orig) {
7022         LDKMonitorEvent orig_conv;
7023         orig_conv.inner = (void*)(orig & (~1));
7024         orig_conv.is_owned = false;
7025         LDKMonitorEvent ret_var = MonitorEvent_clone(&orig_conv);
7026         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7027         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7028         long ret_ref = (long)ret_var.inner;
7029         if (ret_var.is_owned) {
7030                 ret_ref |= 1;
7031         }
7032         return ret_ref;
7033 }
7034
7035 void TS_HTLCUpdate_free(uint32_t this_ptr) {
7036         LDKHTLCUpdate this_ptr_conv;
7037         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7038         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7039         HTLCUpdate_free(this_ptr_conv);
7040 }
7041
7042 uint32_t TS_HTLCUpdate_clone(uint32_t orig) {
7043         LDKHTLCUpdate orig_conv;
7044         orig_conv.inner = (void*)(orig & (~1));
7045         orig_conv.is_owned = false;
7046         LDKHTLCUpdate ret_var = HTLCUpdate_clone(&orig_conv);
7047         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7048         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7049         long ret_ref = (long)ret_var.inner;
7050         if (ret_var.is_owned) {
7051                 ret_ref |= 1;
7052         }
7053         return ret_ref;
7054 }
7055
7056 int8_tArray TS_HTLCUpdate_write(uint32_t obj) {
7057         LDKHTLCUpdate obj_conv;
7058         obj_conv.inner = (void*)(obj & (~1));
7059         obj_conv.is_owned = false;
7060         LDKCVec_u8Z arg_var = HTLCUpdate_write(&obj_conv);
7061         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
7062         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
7063         CVec_u8Z_free(arg_var);
7064         return arg_arr;
7065 }
7066
7067 uint32_t TS_HTLCUpdate_read(int8_tArray ser) {
7068         LDKu8slice ser_ref;
7069         ser_ref.datalen = *((uint32_t*)ser);
7070         ser_ref.data = (int8_t*)(ser + 4);
7071         LDKHTLCUpdate ret_var = HTLCUpdate_read(ser_ref);
7072         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7073         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7074         long ret_ref = (long)ret_var.inner;
7075         if (ret_var.is_owned) {
7076                 ret_ref |= 1;
7077         }
7078         return ret_ref;
7079 }
7080
7081 void TS_ChannelMonitor_free(uint32_t this_ptr) {
7082         LDKChannelMonitor this_ptr_conv;
7083         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7084         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7085         ChannelMonitor_free(this_ptr_conv);
7086 }
7087
7088 int8_tArray TS_ChannelMonitor_write(uint32_t obj) {
7089         LDKChannelMonitor obj_conv;
7090         obj_conv.inner = (void*)(obj & (~1));
7091         obj_conv.is_owned = false;
7092         LDKCVec_u8Z arg_var = ChannelMonitor_write(&obj_conv);
7093         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
7094         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
7095         CVec_u8Z_free(arg_var);
7096         return arg_arr;
7097 }
7098
7099 uint32_t TS_ChannelMonitor_update_monitor(uint32_t this_arg, uint32_t updates, uint32_t broadcaster, uint32_t fee_estimator, uint32_t logger) {
7100         LDKChannelMonitor this_arg_conv;
7101         this_arg_conv.inner = (void*)(this_arg & (~1));
7102         this_arg_conv.is_owned = false;
7103         LDKChannelMonitorUpdate updates_conv;
7104         updates_conv.inner = (void*)(updates & (~1));
7105         updates_conv.is_owned = false;
7106         LDKBroadcasterInterface* broadcaster_conv = (LDKBroadcasterInterface*)broadcaster;
7107         LDKFeeEstimator* fee_estimator_conv = (LDKFeeEstimator*)fee_estimator;
7108         LDKLogger* logger_conv = (LDKLogger*)logger;
7109         LDKCResult_NoneMonitorUpdateErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneMonitorUpdateErrorZ), "LDKCResult_NoneMonitorUpdateErrorZ");
7110         *ret_conv = ChannelMonitor_update_monitor(&this_arg_conv, &updates_conv, broadcaster_conv, fee_estimator_conv, logger_conv);
7111         return (long)ret_conv;
7112 }
7113
7114 int64_t TS_ChannelMonitor_get_latest_update_id(uint32_t this_arg) {
7115         LDKChannelMonitor this_arg_conv;
7116         this_arg_conv.inner = (void*)(this_arg & (~1));
7117         this_arg_conv.is_owned = false;
7118         int64_t ret_val = ChannelMonitor_get_latest_update_id(&this_arg_conv);
7119         return ret_val;
7120 }
7121
7122 uint32_t TS_ChannelMonitor_get_funding_txo(uint32_t this_arg) {
7123         LDKChannelMonitor this_arg_conv;
7124         this_arg_conv.inner = (void*)(this_arg & (~1));
7125         this_arg_conv.is_owned = false;
7126         LDKC2Tuple_OutPointScriptZ* ret_ref = MALLOC(sizeof(LDKC2Tuple_OutPointScriptZ), "LDKC2Tuple_OutPointScriptZ");
7127         *ret_ref = ChannelMonitor_get_funding_txo(&this_arg_conv);
7128         ret_ref->a = OutPoint_clone(&ret_ref->a);
7129         ret_ref->b = CVec_u8Z_clone(&ret_ref->b);
7130         return (long)ret_ref;
7131 }
7132
7133 uint32_tArray TS_ChannelMonitor_get_and_clear_pending_monitor_events(uint32_t this_arg) {
7134         LDKChannelMonitor this_arg_conv;
7135         this_arg_conv.inner = (void*)(this_arg & (~1));
7136         this_arg_conv.is_owned = false;
7137         LDKCVec_MonitorEventZ ret_var = ChannelMonitor_get_and_clear_pending_monitor_events(&this_arg_conv);
7138         uint32_tArray ret_arr = init_arr(ret_var.datalen, sizeof(uint32_t), "Native uint32_tArray Bytes");
7139         uint32_t *ret_arr_ptr = (uint32_t*)(ret_arr + 4);
7140         for (size_t o = 0; o < ret_var.datalen; o++) {
7141                 LDKMonitorEvent arr_conv_14_var = ret_var.data[o];
7142                 CHECK((((long)arr_conv_14_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7143                 CHECK((((long)&arr_conv_14_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7144                 long arr_conv_14_ref = (long)arr_conv_14_var.inner;
7145                 if (arr_conv_14_var.is_owned) {
7146                         arr_conv_14_ref |= 1;
7147                 }
7148                 ret_arr_ptr[o] = arr_conv_14_ref;
7149         }
7150         FREE(ret_var.data);
7151         return ret_arr;
7152 }
7153
7154 uint32_tArray TS_ChannelMonitor_get_and_clear_pending_events(uint32_t this_arg) {
7155         LDKChannelMonitor this_arg_conv;
7156         this_arg_conv.inner = (void*)(this_arg & (~1));
7157         this_arg_conv.is_owned = false;
7158         LDKCVec_EventZ ret_var = ChannelMonitor_get_and_clear_pending_events(&this_arg_conv);
7159         uint32_tArray ret_arr = init_arr(ret_var.datalen, sizeof(uint32_t), "Native uint32_tArray Bytes");
7160         uint32_t *ret_arr_ptr = (uint32_t*)(ret_arr + 4);
7161         for (size_t h = 0; h < ret_var.datalen; h++) {
7162                 LDKEvent *arr_conv_7_copy = MALLOC(sizeof(LDKEvent), "LDKEvent");
7163                 *arr_conv_7_copy = Event_clone(&ret_var.data[h]);
7164                 long arr_conv_7_ref = (long)arr_conv_7_copy;
7165                 ret_arr_ptr[h] = arr_conv_7_ref;
7166         }
7167         FREE(ret_var.data);
7168         return ret_arr;
7169 }
7170
7171 ptrArray TS_ChannelMonitor_get_latest_holder_commitment_txn(uint32_t this_arg, uint32_t logger) {
7172         LDKChannelMonitor this_arg_conv;
7173         this_arg_conv.inner = (void*)(this_arg & (~1));
7174         this_arg_conv.is_owned = false;
7175         LDKLogger* logger_conv = (LDKLogger*)logger;
7176         LDKCVec_TransactionZ ret_var = ChannelMonitor_get_latest_holder_commitment_txn(&this_arg_conv, logger_conv);
7177         ptrArray ret_arr = init_arr(ret_var.datalen, sizeof(uint32_t), "Native ptrArray Bytes");
7178         int8_tArray *ret_arr_ptr = (int8_tArray*)(ret_arr + 4);
7179         for (size_t m = 0; m < ret_var.datalen; m++) {
7180                 LDKTransaction arr_conv_12_var = ret_var.data[m];
7181                 int8_tArray arr_conv_12_arr = init_arr(arr_conv_12_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
7182                 memcpy((uint8_t*)(arr_conv_12_arr + 4), arr_conv_12_var.data, arr_conv_12_var.datalen);
7183                 Transaction_free(arr_conv_12_var);
7184                 ret_arr_ptr[m] = arr_conv_12_arr;
7185         }
7186         FREE(ret_var.data);
7187         return ret_arr;
7188 }
7189
7190 uint32_tArray TS_ChannelMonitor_block_connected(uint32_t this_arg, int8_tArray header, uint32_tArray txdata, int32_t height, uint32_t broadcaster, uint32_t fee_estimator, uint32_t logger) {
7191         LDKChannelMonitor this_arg_conv;
7192         this_arg_conv.inner = (void*)(this_arg & (~1));
7193         this_arg_conv.is_owned = false;
7194         unsigned char header_arr[80];
7195         CHECK(*((uint32_t*)header) == 80);
7196         memcpy(header_arr, (uint8_t*)(header + 4), 80);
7197         unsigned char (*header_ref)[80] = &header_arr;
7198         LDKCVec_C2Tuple_usizeTransactionZZ txdata_constr;
7199         txdata_constr.datalen = *((uint32_t*)txdata);
7200         if (txdata_constr.datalen > 0)
7201                 txdata_constr.data = MALLOC(txdata_constr.datalen * sizeof(LDKC2Tuple_usizeTransactionZ), "LDKCVec_C2Tuple_usizeTransactionZZ Elements");
7202         else
7203                 txdata_constr.data = NULL;
7204         uint32_t* txdata_vals = (uint32_t*)(txdata + 4);
7205         for (size_t e = 0; e < txdata_constr.datalen; e++) {
7206                 uint32_t arr_conv_30 = txdata_vals[e];
7207                 LDKC2Tuple_usizeTransactionZ arr_conv_30_conv = *(LDKC2Tuple_usizeTransactionZ*)arr_conv_30;
7208                 FREE((void*)arr_conv_30);
7209                 txdata_constr.data[e] = arr_conv_30_conv;
7210         }
7211         LDKBroadcasterInterface broadcaster_conv = *(LDKBroadcasterInterface*)broadcaster;
7212         LDKFeeEstimator fee_estimator_conv = *(LDKFeeEstimator*)fee_estimator;
7213         LDKLogger logger_conv = *(LDKLogger*)logger;
7214         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);
7215         uint32_tArray ret_arr = init_arr(ret_var.datalen, sizeof(uint32_t), "Native uint32_tArray Bytes");
7216         uint32_t *ret_arr_ptr = (uint32_t*)(ret_arr + 4);
7217         for (size_t x = 0; x < ret_var.datalen; x++) {
7218                 LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ* arr_conv_49_ref = MALLOC(sizeof(LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ), "LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ");
7219                 *arr_conv_49_ref = ret_var.data[x];
7220                 arr_conv_49_ref->a = ThirtyTwoBytes_clone(&arr_conv_49_ref->a);
7221                 // XXX: We likely need to clone here, but no _clone fn is available for TwoTuple<Number, TxOut>[]
7222                 ret_arr_ptr[x] = (long)arr_conv_49_ref;
7223         }
7224         FREE(ret_var.data);
7225         return ret_arr;
7226 }
7227
7228 void TS_ChannelMonitor_block_disconnected(uint32_t this_arg, int8_tArray header, int32_t height, uint32_t broadcaster, uint32_t fee_estimator, uint32_t logger) {
7229         LDKChannelMonitor this_arg_conv;
7230         this_arg_conv.inner = (void*)(this_arg & (~1));
7231         this_arg_conv.is_owned = false;
7232         unsigned char header_arr[80];
7233         CHECK(*((uint32_t*)header) == 80);
7234         memcpy(header_arr, (uint8_t*)(header + 4), 80);
7235         unsigned char (*header_ref)[80] = &header_arr;
7236         LDKBroadcasterInterface broadcaster_conv = *(LDKBroadcasterInterface*)broadcaster;
7237         LDKFeeEstimator fee_estimator_conv = *(LDKFeeEstimator*)fee_estimator;
7238         LDKLogger logger_conv = *(LDKLogger*)logger;
7239         ChannelMonitor_block_disconnected(&this_arg_conv, header_ref, height, broadcaster_conv, fee_estimator_conv, logger_conv);
7240 }
7241
7242 void TS_Persist_free(uint32_t this_ptr) {
7243         LDKPersist this_ptr_conv = *(LDKPersist*)this_ptr;
7244         FREE((void*)this_ptr);
7245         Persist_free(this_ptr_conv);
7246 }
7247
7248 uint32_t TS_C2Tuple_BlockHashChannelMonitorZ_read(int8_tArray ser, uint32_t arg) {
7249         LDKu8slice ser_ref;
7250         ser_ref.datalen = *((uint32_t*)ser);
7251         ser_ref.data = (int8_t*)(ser + 4);
7252         LDKKeysInterface* arg_conv = (LDKKeysInterface*)arg;
7253         LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ), "LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ");
7254         *ret_conv = C2Tuple_BlockHashChannelMonitorZ_read(ser_ref, arg_conv);
7255         return (long)ret_conv;
7256 }
7257
7258 void TS_OutPoint_free(uint32_t this_ptr) {
7259         LDKOutPoint this_ptr_conv;
7260         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7261         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7262         OutPoint_free(this_ptr_conv);
7263 }
7264
7265 uint32_t TS_OutPoint_clone(uint32_t orig) {
7266         LDKOutPoint orig_conv;
7267         orig_conv.inner = (void*)(orig & (~1));
7268         orig_conv.is_owned = false;
7269         LDKOutPoint ret_var = OutPoint_clone(&orig_conv);
7270         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7271         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7272         long ret_ref = (long)ret_var.inner;
7273         if (ret_var.is_owned) {
7274                 ret_ref |= 1;
7275         }
7276         return ret_ref;
7277 }
7278
7279 int8_tArray TS_OutPoint_get_txid(uint32_t this_ptr) {
7280         LDKOutPoint this_ptr_conv;
7281         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7282         this_ptr_conv.is_owned = false;
7283         int8_tArray ret_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
7284         memcpy((uint8_t*)(ret_arr + 4), *OutPoint_get_txid(&this_ptr_conv), 32);
7285         return ret_arr;
7286 }
7287
7288 void TS_OutPoint_set_txid(uint32_t this_ptr, int8_tArray val) {
7289         LDKOutPoint this_ptr_conv;
7290         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7291         this_ptr_conv.is_owned = false;
7292         LDKThirtyTwoBytes val_ref;
7293         CHECK(*((uint32_t*)val) == 32);
7294         memcpy(val_ref.data, (uint8_t*)(val + 4), 32);
7295         OutPoint_set_txid(&this_ptr_conv, val_ref);
7296 }
7297
7298 int16_t TS_OutPoint_get_index(uint32_t this_ptr) {
7299         LDKOutPoint this_ptr_conv;
7300         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7301         this_ptr_conv.is_owned = false;
7302         int16_t ret_val = OutPoint_get_index(&this_ptr_conv);
7303         return ret_val;
7304 }
7305
7306 void TS_OutPoint_set_index(uint32_t this_ptr, int16_t val) {
7307         LDKOutPoint this_ptr_conv;
7308         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7309         this_ptr_conv.is_owned = false;
7310         OutPoint_set_index(&this_ptr_conv, val);
7311 }
7312
7313 uint32_t TS_OutPoint_new(int8_tArray txid_arg, int16_t index_arg) {
7314         LDKThirtyTwoBytes txid_arg_ref;
7315         CHECK(*((uint32_t*)txid_arg) == 32);
7316         memcpy(txid_arg_ref.data, (uint8_t*)(txid_arg + 4), 32);
7317         LDKOutPoint ret_var = OutPoint_new(txid_arg_ref, index_arg);
7318         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7319         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7320         long ret_ref = (long)ret_var.inner;
7321         if (ret_var.is_owned) {
7322                 ret_ref |= 1;
7323         }
7324         return ret_ref;
7325 }
7326
7327 int8_tArray TS_OutPoint_to_channel_id(uint32_t this_arg) {
7328         LDKOutPoint this_arg_conv;
7329         this_arg_conv.inner = (void*)(this_arg & (~1));
7330         this_arg_conv.is_owned = false;
7331         int8_tArray arg_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
7332         memcpy((uint8_t*)(arg_arr + 4), OutPoint_to_channel_id(&this_arg_conv).data, 32);
7333         return arg_arr;
7334 }
7335
7336 int8_tArray TS_OutPoint_write(uint32_t obj) {
7337         LDKOutPoint obj_conv;
7338         obj_conv.inner = (void*)(obj & (~1));
7339         obj_conv.is_owned = false;
7340         LDKCVec_u8Z arg_var = OutPoint_write(&obj_conv);
7341         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
7342         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
7343         CVec_u8Z_free(arg_var);
7344         return arg_arr;
7345 }
7346
7347 uint32_t TS_OutPoint_read(int8_tArray ser) {
7348         LDKu8slice ser_ref;
7349         ser_ref.datalen = *((uint32_t*)ser);
7350         ser_ref.data = (int8_t*)(ser + 4);
7351         LDKOutPoint ret_var = OutPoint_read(ser_ref);
7352         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7353         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7354         long ret_ref = (long)ret_var.inner;
7355         if (ret_var.is_owned) {
7356                 ret_ref |= 1;
7357         }
7358         return ret_ref;
7359 }
7360
7361 void TS_SpendableOutputDescriptor_free(uint32_t this_ptr) {
7362         LDKSpendableOutputDescriptor this_ptr_conv = *(LDKSpendableOutputDescriptor*)this_ptr;
7363         FREE((void*)this_ptr);
7364         SpendableOutputDescriptor_free(this_ptr_conv);
7365 }
7366
7367 uint32_t TS_SpendableOutputDescriptor_clone(uint32_t orig) {
7368         LDKSpendableOutputDescriptor* orig_conv = (LDKSpendableOutputDescriptor*)orig;
7369         LDKSpendableOutputDescriptor *ret_copy = MALLOC(sizeof(LDKSpendableOutputDescriptor), "LDKSpendableOutputDescriptor");
7370         *ret_copy = SpendableOutputDescriptor_clone(orig_conv);
7371         long ret_ref = (long)ret_copy;
7372         return ret_ref;
7373 }
7374
7375 int8_tArray TS_SpendableOutputDescriptor_write(uint32_t obj) {
7376         LDKSpendableOutputDescriptor* obj_conv = (LDKSpendableOutputDescriptor*)obj;
7377         LDKCVec_u8Z arg_var = SpendableOutputDescriptor_write(obj_conv);
7378         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
7379         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
7380         CVec_u8Z_free(arg_var);
7381         return arg_arr;
7382 }
7383
7384 uint32_t TS_SpendableOutputDescriptor_read(int8_tArray ser) {
7385         LDKu8slice ser_ref;
7386         ser_ref.datalen = *((uint32_t*)ser);
7387         ser_ref.data = (int8_t*)(ser + 4);
7388         LDKCResult_SpendableOutputDescriptorDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_SpendableOutputDescriptorDecodeErrorZ), "LDKCResult_SpendableOutputDescriptorDecodeErrorZ");
7389         *ret_conv = SpendableOutputDescriptor_read(ser_ref);
7390         return (long)ret_conv;
7391 }
7392
7393 uint32_t TS_ChannelKeys_clone(uint32_t orig) {
7394         LDKChannelKeys* orig_conv = (LDKChannelKeys*)orig;
7395         LDKChannelKeys* ret = MALLOC(sizeof(LDKChannelKeys), "LDKChannelKeys");
7396         *ret = ChannelKeys_clone(orig_conv);
7397         return (long)ret;
7398 }
7399
7400 void TS_ChannelKeys_free(uint32_t this_ptr) {
7401         LDKChannelKeys this_ptr_conv = *(LDKChannelKeys*)this_ptr;
7402         FREE((void*)this_ptr);
7403         ChannelKeys_free(this_ptr_conv);
7404 }
7405
7406 void TS_KeysInterface_free(uint32_t this_ptr) {
7407         LDKKeysInterface this_ptr_conv = *(LDKKeysInterface*)this_ptr;
7408         FREE((void*)this_ptr);
7409         KeysInterface_free(this_ptr_conv);
7410 }
7411
7412 void TS_InMemoryChannelKeys_free(uint32_t this_ptr) {
7413         LDKInMemoryChannelKeys this_ptr_conv;
7414         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7415         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7416         InMemoryChannelKeys_free(this_ptr_conv);
7417 }
7418
7419 uint32_t TS_InMemoryChannelKeys_clone(uint32_t orig) {
7420         LDKInMemoryChannelKeys orig_conv;
7421         orig_conv.inner = (void*)(orig & (~1));
7422         orig_conv.is_owned = false;
7423         LDKInMemoryChannelKeys ret_var = InMemoryChannelKeys_clone(&orig_conv);
7424         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7425         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7426         long ret_ref = (long)ret_var.inner;
7427         if (ret_var.is_owned) {
7428                 ret_ref |= 1;
7429         }
7430         return ret_ref;
7431 }
7432
7433 int8_tArray TS_InMemoryChannelKeys_get_funding_key(uint32_t this_ptr) {
7434         LDKInMemoryChannelKeys this_ptr_conv;
7435         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7436         this_ptr_conv.is_owned = false;
7437         int8_tArray ret_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
7438         memcpy((uint8_t*)(ret_arr + 4), *InMemoryChannelKeys_get_funding_key(&this_ptr_conv), 32);
7439         return ret_arr;
7440 }
7441
7442 void TS_InMemoryChannelKeys_set_funding_key(uint32_t this_ptr, int8_tArray val) {
7443         LDKInMemoryChannelKeys this_ptr_conv;
7444         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7445         this_ptr_conv.is_owned = false;
7446         LDKSecretKey val_ref;
7447         CHECK(*((uint32_t*)val) == 32);
7448         memcpy(val_ref.bytes, (uint8_t*)(val + 4), 32);
7449         InMemoryChannelKeys_set_funding_key(&this_ptr_conv, val_ref);
7450 }
7451
7452 int8_tArray TS_InMemoryChannelKeys_get_revocation_base_key(uint32_t this_ptr) {
7453         LDKInMemoryChannelKeys this_ptr_conv;
7454         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7455         this_ptr_conv.is_owned = false;
7456         int8_tArray ret_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
7457         memcpy((uint8_t*)(ret_arr + 4), *InMemoryChannelKeys_get_revocation_base_key(&this_ptr_conv), 32);
7458         return ret_arr;
7459 }
7460
7461 void TS_InMemoryChannelKeys_set_revocation_base_key(uint32_t this_ptr, int8_tArray val) {
7462         LDKInMemoryChannelKeys this_ptr_conv;
7463         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7464         this_ptr_conv.is_owned = false;
7465         LDKSecretKey val_ref;
7466         CHECK(*((uint32_t*)val) == 32);
7467         memcpy(val_ref.bytes, (uint8_t*)(val + 4), 32);
7468         InMemoryChannelKeys_set_revocation_base_key(&this_ptr_conv, val_ref);
7469 }
7470
7471 int8_tArray TS_InMemoryChannelKeys_get_payment_key(uint32_t this_ptr) {
7472         LDKInMemoryChannelKeys this_ptr_conv;
7473         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7474         this_ptr_conv.is_owned = false;
7475         int8_tArray ret_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
7476         memcpy((uint8_t*)(ret_arr + 4), *InMemoryChannelKeys_get_payment_key(&this_ptr_conv), 32);
7477         return ret_arr;
7478 }
7479
7480 void TS_InMemoryChannelKeys_set_payment_key(uint32_t this_ptr, int8_tArray val) {
7481         LDKInMemoryChannelKeys this_ptr_conv;
7482         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7483         this_ptr_conv.is_owned = false;
7484         LDKSecretKey val_ref;
7485         CHECK(*((uint32_t*)val) == 32);
7486         memcpy(val_ref.bytes, (uint8_t*)(val + 4), 32);
7487         InMemoryChannelKeys_set_payment_key(&this_ptr_conv, val_ref);
7488 }
7489
7490 int8_tArray TS_InMemoryChannelKeys_get_delayed_payment_base_key(uint32_t this_ptr) {
7491         LDKInMemoryChannelKeys this_ptr_conv;
7492         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7493         this_ptr_conv.is_owned = false;
7494         int8_tArray ret_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
7495         memcpy((uint8_t*)(ret_arr + 4), *InMemoryChannelKeys_get_delayed_payment_base_key(&this_ptr_conv), 32);
7496         return ret_arr;
7497 }
7498
7499 void TS_InMemoryChannelKeys_set_delayed_payment_base_key(uint32_t this_ptr, int8_tArray val) {
7500         LDKInMemoryChannelKeys this_ptr_conv;
7501         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7502         this_ptr_conv.is_owned = false;
7503         LDKSecretKey val_ref;
7504         CHECK(*((uint32_t*)val) == 32);
7505         memcpy(val_ref.bytes, (uint8_t*)(val + 4), 32);
7506         InMemoryChannelKeys_set_delayed_payment_base_key(&this_ptr_conv, val_ref);
7507 }
7508
7509 int8_tArray TS_InMemoryChannelKeys_get_htlc_base_key(uint32_t this_ptr) {
7510         LDKInMemoryChannelKeys this_ptr_conv;
7511         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7512         this_ptr_conv.is_owned = false;
7513         int8_tArray ret_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
7514         memcpy((uint8_t*)(ret_arr + 4), *InMemoryChannelKeys_get_htlc_base_key(&this_ptr_conv), 32);
7515         return ret_arr;
7516 }
7517
7518 void TS_InMemoryChannelKeys_set_htlc_base_key(uint32_t this_ptr, int8_tArray val) {
7519         LDKInMemoryChannelKeys this_ptr_conv;
7520         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7521         this_ptr_conv.is_owned = false;
7522         LDKSecretKey val_ref;
7523         CHECK(*((uint32_t*)val) == 32);
7524         memcpy(val_ref.bytes, (uint8_t*)(val + 4), 32);
7525         InMemoryChannelKeys_set_htlc_base_key(&this_ptr_conv, val_ref);
7526 }
7527
7528 int8_tArray TS_InMemoryChannelKeys_get_commitment_seed(uint32_t this_ptr) {
7529         LDKInMemoryChannelKeys this_ptr_conv;
7530         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7531         this_ptr_conv.is_owned = false;
7532         int8_tArray ret_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
7533         memcpy((uint8_t*)(ret_arr + 4), *InMemoryChannelKeys_get_commitment_seed(&this_ptr_conv), 32);
7534         return ret_arr;
7535 }
7536
7537 void TS_InMemoryChannelKeys_set_commitment_seed(uint32_t this_ptr, int8_tArray val) {
7538         LDKInMemoryChannelKeys this_ptr_conv;
7539         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7540         this_ptr_conv.is_owned = false;
7541         LDKThirtyTwoBytes val_ref;
7542         CHECK(*((uint32_t*)val) == 32);
7543         memcpy(val_ref.data, (uint8_t*)(val + 4), 32);
7544         InMemoryChannelKeys_set_commitment_seed(&this_ptr_conv, val_ref);
7545 }
7546
7547 uint32_t TS_InMemoryChannelKeys_new(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) {
7548         LDKSecretKey funding_key_ref;
7549         CHECK(*((uint32_t*)funding_key) == 32);
7550         memcpy(funding_key_ref.bytes, (uint8_t*)(funding_key + 4), 32);
7551         LDKSecretKey revocation_base_key_ref;
7552         CHECK(*((uint32_t*)revocation_base_key) == 32);
7553         memcpy(revocation_base_key_ref.bytes, (uint8_t*)(revocation_base_key + 4), 32);
7554         LDKSecretKey payment_key_ref;
7555         CHECK(*((uint32_t*)payment_key) == 32);
7556         memcpy(payment_key_ref.bytes, (uint8_t*)(payment_key + 4), 32);
7557         LDKSecretKey delayed_payment_base_key_ref;
7558         CHECK(*((uint32_t*)delayed_payment_base_key) == 32);
7559         memcpy(delayed_payment_base_key_ref.bytes, (uint8_t*)(delayed_payment_base_key + 4), 32);
7560         LDKSecretKey htlc_base_key_ref;
7561         CHECK(*((uint32_t*)htlc_base_key) == 32);
7562         memcpy(htlc_base_key_ref.bytes, (uint8_t*)(htlc_base_key + 4), 32);
7563         LDKThirtyTwoBytes commitment_seed_ref;
7564         CHECK(*((uint32_t*)commitment_seed) == 32);
7565         memcpy(commitment_seed_ref.data, (uint8_t*)(commitment_seed + 4), 32);
7566         LDKC2Tuple_u64u64Z key_derivation_params_conv = *(LDKC2Tuple_u64u64Z*)key_derivation_params;
7567         FREE((void*)key_derivation_params);
7568         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);
7569         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7570         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7571         long ret_ref = (long)ret_var.inner;
7572         if (ret_var.is_owned) {
7573                 ret_ref |= 1;
7574         }
7575         return ret_ref;
7576 }
7577
7578 uint32_t TS_InMemoryChannelKeys_counterparty_pubkeys(uint32_t this_arg) {
7579         LDKInMemoryChannelKeys this_arg_conv;
7580         this_arg_conv.inner = (void*)(this_arg & (~1));
7581         this_arg_conv.is_owned = false;
7582         LDKChannelPublicKeys ret_var = InMemoryChannelKeys_counterparty_pubkeys(&this_arg_conv);
7583         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7584         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7585         long ret_ref = (long)ret_var.inner;
7586         if (ret_var.is_owned) {
7587                 ret_ref |= 1;
7588         }
7589         return ret_ref;
7590 }
7591
7592 int16_t TS_InMemoryChannelKeys_counterparty_selected_contest_delay(uint32_t this_arg) {
7593         LDKInMemoryChannelKeys this_arg_conv;
7594         this_arg_conv.inner = (void*)(this_arg & (~1));
7595         this_arg_conv.is_owned = false;
7596         int16_t ret_val = InMemoryChannelKeys_counterparty_selected_contest_delay(&this_arg_conv);
7597         return ret_val;
7598 }
7599
7600 int16_t TS_InMemoryChannelKeys_holder_selected_contest_delay(uint32_t this_arg) {
7601         LDKInMemoryChannelKeys this_arg_conv;
7602         this_arg_conv.inner = (void*)(this_arg & (~1));
7603         this_arg_conv.is_owned = false;
7604         int16_t ret_val = InMemoryChannelKeys_holder_selected_contest_delay(&this_arg_conv);
7605         return ret_val;
7606 }
7607
7608 jboolean TS_InMemoryChannelKeys_is_outbound(uint32_t this_arg) {
7609         LDKInMemoryChannelKeys this_arg_conv;
7610         this_arg_conv.inner = (void*)(this_arg & (~1));
7611         this_arg_conv.is_owned = false;
7612         jboolean ret_val = InMemoryChannelKeys_is_outbound(&this_arg_conv);
7613         return ret_val;
7614 }
7615
7616 uint32_t TS_InMemoryChannelKeys_funding_outpoint(uint32_t this_arg) {
7617         LDKInMemoryChannelKeys this_arg_conv;
7618         this_arg_conv.inner = (void*)(this_arg & (~1));
7619         this_arg_conv.is_owned = false;
7620         LDKOutPoint ret_var = InMemoryChannelKeys_funding_outpoint(&this_arg_conv);
7621         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7622         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7623         long ret_ref = (long)ret_var.inner;
7624         if (ret_var.is_owned) {
7625                 ret_ref |= 1;
7626         }
7627         return ret_ref;
7628 }
7629
7630 uint32_t TS_InMemoryChannelKeys_get_channel_parameters(uint32_t this_arg) {
7631         LDKInMemoryChannelKeys this_arg_conv;
7632         this_arg_conv.inner = (void*)(this_arg & (~1));
7633         this_arg_conv.is_owned = false;
7634         LDKChannelTransactionParameters ret_var = InMemoryChannelKeys_get_channel_parameters(&this_arg_conv);
7635         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7636         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7637         long ret_ref = (long)ret_var.inner;
7638         if (ret_var.is_owned) {
7639                 ret_ref |= 1;
7640         }
7641         return ret_ref;
7642 }
7643
7644 uint32_t TS_InMemoryChannelKeys_as_ChannelKeys(uint32_t this_arg) {
7645         LDKInMemoryChannelKeys this_arg_conv;
7646         this_arg_conv.inner = (void*)(this_arg & (~1));
7647         this_arg_conv.is_owned = false;
7648         LDKChannelKeys* ret = MALLOC(sizeof(LDKChannelKeys), "LDKChannelKeys");
7649         *ret = InMemoryChannelKeys_as_ChannelKeys(&this_arg_conv);
7650         return (long)ret;
7651 }
7652
7653 int8_tArray TS_InMemoryChannelKeys_write(uint32_t obj) {
7654         LDKInMemoryChannelKeys obj_conv;
7655         obj_conv.inner = (void*)(obj & (~1));
7656         obj_conv.is_owned = false;
7657         LDKCVec_u8Z arg_var = InMemoryChannelKeys_write(&obj_conv);
7658         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
7659         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
7660         CVec_u8Z_free(arg_var);
7661         return arg_arr;
7662 }
7663
7664 uint32_t TS_InMemoryChannelKeys_read(int8_tArray ser) {
7665         LDKu8slice ser_ref;
7666         ser_ref.datalen = *((uint32_t*)ser);
7667         ser_ref.data = (int8_t*)(ser + 4);
7668         LDKCResult_InMemoryChannelKeysDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_InMemoryChannelKeysDecodeErrorZ), "LDKCResult_InMemoryChannelKeysDecodeErrorZ");
7669         *ret_conv = InMemoryChannelKeys_read(ser_ref);
7670         return (long)ret_conv;
7671 }
7672
7673 void TS_KeysManager_free(uint32_t this_ptr) {
7674         LDKKeysManager this_ptr_conv;
7675         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7676         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7677         KeysManager_free(this_ptr_conv);
7678 }
7679
7680 uint32_t TS_KeysManager_new(int8_tArray seed, uint32_t network, int64_t starting_time_secs, int32_t starting_time_nanos) {
7681         unsigned char seed_arr[32];
7682         CHECK(*((uint32_t*)seed) == 32);
7683         memcpy(seed_arr, (uint8_t*)(seed + 4), 32);
7684         unsigned char (*seed_ref)[32] = &seed_arr;
7685         LDKNetwork network_conv = LDKNetwork_from_js(network);
7686         LDKKeysManager ret_var = KeysManager_new(seed_ref, network_conv, starting_time_secs, starting_time_nanos);
7687         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7688         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7689         long ret_ref = (long)ret_var.inner;
7690         if (ret_var.is_owned) {
7691                 ret_ref |= 1;
7692         }
7693         return ret_ref;
7694 }
7695
7696 uint32_t TS_KeysManager_derive_channel_keys(uint32_t this_arg, int64_t channel_value_satoshis, int64_t params_1, int64_t params_2) {
7697         LDKKeysManager this_arg_conv;
7698         this_arg_conv.inner = (void*)(this_arg & (~1));
7699         this_arg_conv.is_owned = false;
7700         LDKInMemoryChannelKeys ret_var = KeysManager_derive_channel_keys(&this_arg_conv, channel_value_satoshis, params_1, params_2);
7701         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7702         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7703         long ret_ref = (long)ret_var.inner;
7704         if (ret_var.is_owned) {
7705                 ret_ref |= 1;
7706         }
7707         return ret_ref;
7708 }
7709
7710 uint32_t TS_KeysManager_as_KeysInterface(uint32_t this_arg) {
7711         LDKKeysManager this_arg_conv;
7712         this_arg_conv.inner = (void*)(this_arg & (~1));
7713         this_arg_conv.is_owned = false;
7714         LDKKeysInterface* ret = MALLOC(sizeof(LDKKeysInterface), "LDKKeysInterface");
7715         *ret = KeysManager_as_KeysInterface(&this_arg_conv);
7716         return (long)ret;
7717 }
7718
7719 void TS_ChannelManager_free(uint32_t this_ptr) {
7720         LDKChannelManager this_ptr_conv;
7721         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7722         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7723         ChannelManager_free(this_ptr_conv);
7724 }
7725
7726 void TS_ChannelDetails_free(uint32_t this_ptr) {
7727         LDKChannelDetails this_ptr_conv;
7728         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7729         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7730         ChannelDetails_free(this_ptr_conv);
7731 }
7732
7733 uint32_t TS_ChannelDetails_clone(uint32_t orig) {
7734         LDKChannelDetails orig_conv;
7735         orig_conv.inner = (void*)(orig & (~1));
7736         orig_conv.is_owned = false;
7737         LDKChannelDetails ret_var = ChannelDetails_clone(&orig_conv);
7738         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7739         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7740         long ret_ref = (long)ret_var.inner;
7741         if (ret_var.is_owned) {
7742                 ret_ref |= 1;
7743         }
7744         return ret_ref;
7745 }
7746
7747 int8_tArray TS_ChannelDetails_get_channel_id(uint32_t this_ptr) {
7748         LDKChannelDetails this_ptr_conv;
7749         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7750         this_ptr_conv.is_owned = false;
7751         int8_tArray ret_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
7752         memcpy((uint8_t*)(ret_arr + 4), *ChannelDetails_get_channel_id(&this_ptr_conv), 32);
7753         return ret_arr;
7754 }
7755
7756 void TS_ChannelDetails_set_channel_id(uint32_t this_ptr, int8_tArray val) {
7757         LDKChannelDetails this_ptr_conv;
7758         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7759         this_ptr_conv.is_owned = false;
7760         LDKThirtyTwoBytes val_ref;
7761         CHECK(*((uint32_t*)val) == 32);
7762         memcpy(val_ref.data, (uint8_t*)(val + 4), 32);
7763         ChannelDetails_set_channel_id(&this_ptr_conv, val_ref);
7764 }
7765
7766 int8_tArray TS_ChannelDetails_get_remote_network_id(uint32_t this_ptr) {
7767         LDKChannelDetails this_ptr_conv;
7768         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7769         this_ptr_conv.is_owned = false;
7770         int8_tArray arg_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
7771         memcpy((uint8_t*)(arg_arr + 4), ChannelDetails_get_remote_network_id(&this_ptr_conv).compressed_form, 33);
7772         return arg_arr;
7773 }
7774
7775 void TS_ChannelDetails_set_remote_network_id(uint32_t this_ptr, int8_tArray val) {
7776         LDKChannelDetails this_ptr_conv;
7777         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7778         this_ptr_conv.is_owned = false;
7779         LDKPublicKey val_ref;
7780         CHECK(*((uint32_t*)val) == 33);
7781         memcpy(val_ref.compressed_form, (uint8_t*)(val + 4), 33);
7782         ChannelDetails_set_remote_network_id(&this_ptr_conv, val_ref);
7783 }
7784
7785 uint32_t TS_ChannelDetails_get_counterparty_features(uint32_t this_ptr) {
7786         LDKChannelDetails this_ptr_conv;
7787         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7788         this_ptr_conv.is_owned = false;
7789         LDKInitFeatures ret_var = ChannelDetails_get_counterparty_features(&this_ptr_conv);
7790         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7791         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7792         long ret_ref = (long)ret_var.inner;
7793         if (ret_var.is_owned) {
7794                 ret_ref |= 1;
7795         }
7796         return ret_ref;
7797 }
7798
7799 void TS_ChannelDetails_set_counterparty_features(uint32_t this_ptr, uint32_t val) {
7800         LDKChannelDetails this_ptr_conv;
7801         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7802         this_ptr_conv.is_owned = false;
7803         LDKInitFeatures val_conv;
7804         val_conv.inner = (void*)(val & (~1));
7805         val_conv.is_owned = (val & 1) || (val == 0);
7806         // Warning: we may need a move here but can't clone!
7807         ChannelDetails_set_counterparty_features(&this_ptr_conv, val_conv);
7808 }
7809
7810 int64_t TS_ChannelDetails_get_channel_value_satoshis(uint32_t this_ptr) {
7811         LDKChannelDetails this_ptr_conv;
7812         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7813         this_ptr_conv.is_owned = false;
7814         int64_t ret_val = ChannelDetails_get_channel_value_satoshis(&this_ptr_conv);
7815         return ret_val;
7816 }
7817
7818 void TS_ChannelDetails_set_channel_value_satoshis(uint32_t this_ptr, int64_t val) {
7819         LDKChannelDetails this_ptr_conv;
7820         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7821         this_ptr_conv.is_owned = false;
7822         ChannelDetails_set_channel_value_satoshis(&this_ptr_conv, val);
7823 }
7824
7825 int64_t TS_ChannelDetails_get_user_id(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_user_id(&this_ptr_conv);
7830         return ret_val;
7831 }
7832
7833 void TS_ChannelDetails_set_user_id(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_user_id(&this_ptr_conv, val);
7838 }
7839
7840 int64_t TS_ChannelDetails_get_outbound_capacity_msat(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_outbound_capacity_msat(&this_ptr_conv);
7845         return ret_val;
7846 }
7847
7848 void TS_ChannelDetails_set_outbound_capacity_msat(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_outbound_capacity_msat(&this_ptr_conv, val);
7853 }
7854
7855 int64_t TS_ChannelDetails_get_inbound_capacity_msat(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_inbound_capacity_msat(&this_ptr_conv);
7860         return ret_val;
7861 }
7862
7863 void TS_ChannelDetails_set_inbound_capacity_msat(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_inbound_capacity_msat(&this_ptr_conv, val);
7868 }
7869
7870 jboolean TS_ChannelDetails_get_is_live(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         jboolean ret_val = ChannelDetails_get_is_live(&this_ptr_conv);
7875         return ret_val;
7876 }
7877
7878 void TS_ChannelDetails_set_is_live(uint32_t this_ptr, jboolean 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_is_live(&this_ptr_conv, val);
7883 }
7884
7885 void TS_PaymentSendFailure_free(uint32_t this_ptr) {
7886         LDKPaymentSendFailure this_ptr_conv;
7887         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7888         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7889         PaymentSendFailure_free(this_ptr_conv);
7890 }
7891
7892 uint32_t TS_ChannelManager_new(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) {
7893         LDKNetwork network_conv = LDKNetwork_from_js(network);
7894         LDKFeeEstimator fee_est_conv = *(LDKFeeEstimator*)fee_est;
7895         LDKWatch chain_monitor_conv = *(LDKWatch*)chain_monitor;
7896         LDKBroadcasterInterface tx_broadcaster_conv = *(LDKBroadcasterInterface*)tx_broadcaster;
7897         LDKLogger logger_conv = *(LDKLogger*)logger;
7898         LDKKeysInterface keys_manager_conv = *(LDKKeysInterface*)keys_manager;
7899         LDKUserConfig config_conv;
7900         config_conv.inner = (void*)(config & (~1));
7901         config_conv.is_owned = (config & 1) || (config == 0);
7902         if (config_conv.inner != NULL)
7903                 config_conv = UserConfig_clone(&config_conv);
7904         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);
7905         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7906         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7907         long ret_ref = (long)ret_var.inner;
7908         if (ret_var.is_owned) {
7909                 ret_ref |= 1;
7910         }
7911         return ret_ref;
7912 }
7913
7914 uint32_t TS_ChannelManager_create_channel(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) {
7915         LDKChannelManager this_arg_conv;
7916         this_arg_conv.inner = (void*)(this_arg & (~1));
7917         this_arg_conv.is_owned = false;
7918         LDKPublicKey their_network_key_ref;
7919         CHECK(*((uint32_t*)their_network_key) == 33);
7920         memcpy(their_network_key_ref.compressed_form, (uint8_t*)(their_network_key + 4), 33);
7921         LDKUserConfig override_config_conv;
7922         override_config_conv.inner = (void*)(override_config & (~1));
7923         override_config_conv.is_owned = (override_config & 1) || (override_config == 0);
7924         if (override_config_conv.inner != NULL)
7925                 override_config_conv = UserConfig_clone(&override_config_conv);
7926         LDKCResult_NoneAPIErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneAPIErrorZ), "LDKCResult_NoneAPIErrorZ");
7927         *ret_conv = ChannelManager_create_channel(&this_arg_conv, their_network_key_ref, channel_value_satoshis, push_msat, user_id, override_config_conv);
7928         return (long)ret_conv;
7929 }
7930
7931 uint32_tArray TS_ChannelManager_list_channels(uint32_t this_arg) {
7932         LDKChannelManager this_arg_conv;
7933         this_arg_conv.inner = (void*)(this_arg & (~1));
7934         this_arg_conv.is_owned = false;
7935         LDKCVec_ChannelDetailsZ ret_var = ChannelManager_list_channels(&this_arg_conv);
7936         uint32_tArray ret_arr = init_arr(ret_var.datalen, sizeof(uint32_t), "Native uint32_tArray Bytes");
7937         uint32_t *ret_arr_ptr = (uint32_t*)(ret_arr + 4);
7938         for (size_t q = 0; q < ret_var.datalen; q++) {
7939                 LDKChannelDetails arr_conv_16_var = ret_var.data[q];
7940                 CHECK((((long)arr_conv_16_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7941                 CHECK((((long)&arr_conv_16_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7942                 long arr_conv_16_ref = (long)arr_conv_16_var.inner;
7943                 if (arr_conv_16_var.is_owned) {
7944                         arr_conv_16_ref |= 1;
7945                 }
7946                 ret_arr_ptr[q] = arr_conv_16_ref;
7947         }
7948         FREE(ret_var.data);
7949         return ret_arr;
7950 }
7951
7952 uint32_tArray TS_ChannelManager_list_usable_channels(uint32_t this_arg) {
7953         LDKChannelManager this_arg_conv;
7954         this_arg_conv.inner = (void*)(this_arg & (~1));
7955         this_arg_conv.is_owned = false;
7956         LDKCVec_ChannelDetailsZ ret_var = ChannelManager_list_usable_channels(&this_arg_conv);
7957         uint32_tArray ret_arr = init_arr(ret_var.datalen, sizeof(uint32_t), "Native uint32_tArray Bytes");
7958         uint32_t *ret_arr_ptr = (uint32_t*)(ret_arr + 4);
7959         for (size_t q = 0; q < ret_var.datalen; q++) {
7960                 LDKChannelDetails arr_conv_16_var = ret_var.data[q];
7961                 CHECK((((long)arr_conv_16_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7962                 CHECK((((long)&arr_conv_16_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7963                 long arr_conv_16_ref = (long)arr_conv_16_var.inner;
7964                 if (arr_conv_16_var.is_owned) {
7965                         arr_conv_16_ref |= 1;
7966                 }
7967                 ret_arr_ptr[q] = arr_conv_16_ref;
7968         }
7969         FREE(ret_var.data);
7970         return ret_arr;
7971 }
7972
7973 uint32_t TS_ChannelManager_close_channel(uint32_t this_arg, int8_tArray channel_id) {
7974         LDKChannelManager this_arg_conv;
7975         this_arg_conv.inner = (void*)(this_arg & (~1));
7976         this_arg_conv.is_owned = false;
7977         unsigned char channel_id_arr[32];
7978         CHECK(*((uint32_t*)channel_id) == 32);
7979         memcpy(channel_id_arr, (uint8_t*)(channel_id + 4), 32);
7980         unsigned char (*channel_id_ref)[32] = &channel_id_arr;
7981         LDKCResult_NoneAPIErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneAPIErrorZ), "LDKCResult_NoneAPIErrorZ");
7982         *ret_conv = ChannelManager_close_channel(&this_arg_conv, channel_id_ref);
7983         return (long)ret_conv;
7984 }
7985
7986 void TS_ChannelManager_force_close_channel(uint32_t this_arg, int8_tArray channel_id) {
7987         LDKChannelManager this_arg_conv;
7988         this_arg_conv.inner = (void*)(this_arg & (~1));
7989         this_arg_conv.is_owned = false;
7990         unsigned char channel_id_arr[32];
7991         CHECK(*((uint32_t*)channel_id) == 32);
7992         memcpy(channel_id_arr, (uint8_t*)(channel_id + 4), 32);
7993         unsigned char (*channel_id_ref)[32] = &channel_id_arr;
7994         ChannelManager_force_close_channel(&this_arg_conv, channel_id_ref);
7995 }
7996
7997 void TS_ChannelManager_force_close_all_channels(uint32_t this_arg) {
7998         LDKChannelManager this_arg_conv;
7999         this_arg_conv.inner = (void*)(this_arg & (~1));
8000         this_arg_conv.is_owned = false;
8001         ChannelManager_force_close_all_channels(&this_arg_conv);
8002 }
8003
8004 uint32_t TS_ChannelManager_send_payment(uint32_t this_arg, uint32_t route, int8_tArray payment_hash, int8_tArray payment_secret) {
8005         LDKChannelManager this_arg_conv;
8006         this_arg_conv.inner = (void*)(this_arg & (~1));
8007         this_arg_conv.is_owned = false;
8008         LDKRoute route_conv;
8009         route_conv.inner = (void*)(route & (~1));
8010         route_conv.is_owned = false;
8011         LDKThirtyTwoBytes payment_hash_ref;
8012         CHECK(*((uint32_t*)payment_hash) == 32);
8013         memcpy(payment_hash_ref.data, (uint8_t*)(payment_hash + 4), 32);
8014         LDKThirtyTwoBytes payment_secret_ref;
8015         CHECK(*((uint32_t*)payment_secret) == 32);
8016         memcpy(payment_secret_ref.data, (uint8_t*)(payment_secret + 4), 32);
8017         LDKCResult_NonePaymentSendFailureZ* ret_conv = MALLOC(sizeof(LDKCResult_NonePaymentSendFailureZ), "LDKCResult_NonePaymentSendFailureZ");
8018         *ret_conv = ChannelManager_send_payment(&this_arg_conv, &route_conv, payment_hash_ref, payment_secret_ref);
8019         return (long)ret_conv;
8020 }
8021
8022 void TS_ChannelManager_funding_transaction_generated(uint32_t this_arg, int8_tArray temporary_channel_id, uint32_t funding_txo) {
8023         LDKChannelManager this_arg_conv;
8024         this_arg_conv.inner = (void*)(this_arg & (~1));
8025         this_arg_conv.is_owned = false;
8026         unsigned char temporary_channel_id_arr[32];
8027         CHECK(*((uint32_t*)temporary_channel_id) == 32);
8028         memcpy(temporary_channel_id_arr, (uint8_t*)(temporary_channel_id + 4), 32);
8029         unsigned char (*temporary_channel_id_ref)[32] = &temporary_channel_id_arr;
8030         LDKOutPoint funding_txo_conv;
8031         funding_txo_conv.inner = (void*)(funding_txo & (~1));
8032         funding_txo_conv.is_owned = (funding_txo & 1) || (funding_txo == 0);
8033         if (funding_txo_conv.inner != NULL)
8034                 funding_txo_conv = OutPoint_clone(&funding_txo_conv);
8035         ChannelManager_funding_transaction_generated(&this_arg_conv, temporary_channel_id_ref, funding_txo_conv);
8036 }
8037
8038 void TS_ChannelManager_broadcast_node_announcement(uint32_t this_arg, int8_tArray rgb, int8_tArray alias, uint32_tArray addresses) {
8039         LDKChannelManager this_arg_conv;
8040         this_arg_conv.inner = (void*)(this_arg & (~1));
8041         this_arg_conv.is_owned = false;
8042         LDKThreeBytes rgb_ref;
8043         CHECK(*((uint32_t*)rgb) == 3);
8044         memcpy(rgb_ref.data, (uint8_t*)(rgb + 4), 3);
8045         LDKThirtyTwoBytes alias_ref;
8046         CHECK(*((uint32_t*)alias) == 32);
8047         memcpy(alias_ref.data, (uint8_t*)(alias + 4), 32);
8048         LDKCVec_NetAddressZ addresses_constr;
8049         addresses_constr.datalen = *((uint32_t*)addresses);
8050         if (addresses_constr.datalen > 0)
8051                 addresses_constr.data = MALLOC(addresses_constr.datalen * sizeof(LDKNetAddress), "LDKCVec_NetAddressZ Elements");
8052         else
8053                 addresses_constr.data = NULL;
8054         uint32_t* addresses_vals = (uint32_t*)(addresses + 4);
8055         for (size_t m = 0; m < addresses_constr.datalen; m++) {
8056                 uint32_t arr_conv_12 = addresses_vals[m];
8057                 LDKNetAddress arr_conv_12_conv = *(LDKNetAddress*)arr_conv_12;
8058                 FREE((void*)arr_conv_12);
8059                 addresses_constr.data[m] = arr_conv_12_conv;
8060         }
8061         ChannelManager_broadcast_node_announcement(&this_arg_conv, rgb_ref, alias_ref, addresses_constr);
8062 }
8063
8064 void TS_ChannelManager_process_pending_htlc_forwards(uint32_t this_arg) {
8065         LDKChannelManager this_arg_conv;
8066         this_arg_conv.inner = (void*)(this_arg & (~1));
8067         this_arg_conv.is_owned = false;
8068         ChannelManager_process_pending_htlc_forwards(&this_arg_conv);
8069 }
8070
8071 void TS_ChannelManager_timer_chan_freshness_every_min(uint32_t this_arg) {
8072         LDKChannelManager this_arg_conv;
8073         this_arg_conv.inner = (void*)(this_arg & (~1));
8074         this_arg_conv.is_owned = false;
8075         ChannelManager_timer_chan_freshness_every_min(&this_arg_conv);
8076 }
8077
8078 jboolean TS_ChannelManager_fail_htlc_backwards(uint32_t this_arg, int8_tArray payment_hash, int8_tArray payment_secret) {
8079         LDKChannelManager this_arg_conv;
8080         this_arg_conv.inner = (void*)(this_arg & (~1));
8081         this_arg_conv.is_owned = false;
8082         unsigned char payment_hash_arr[32];
8083         CHECK(*((uint32_t*)payment_hash) == 32);
8084         memcpy(payment_hash_arr, (uint8_t*)(payment_hash + 4), 32);
8085         unsigned char (*payment_hash_ref)[32] = &payment_hash_arr;
8086         LDKThirtyTwoBytes payment_secret_ref;
8087         CHECK(*((uint32_t*)payment_secret) == 32);
8088         memcpy(payment_secret_ref.data, (uint8_t*)(payment_secret + 4), 32);
8089         jboolean ret_val = ChannelManager_fail_htlc_backwards(&this_arg_conv, payment_hash_ref, payment_secret_ref);
8090         return ret_val;
8091 }
8092
8093 jboolean TS_ChannelManager_claim_funds(uint32_t this_arg, int8_tArray payment_preimage, int8_tArray payment_secret, int64_t expected_amount) {
8094         LDKChannelManager this_arg_conv;
8095         this_arg_conv.inner = (void*)(this_arg & (~1));
8096         this_arg_conv.is_owned = false;
8097         LDKThirtyTwoBytes payment_preimage_ref;
8098         CHECK(*((uint32_t*)payment_preimage) == 32);
8099         memcpy(payment_preimage_ref.data, (uint8_t*)(payment_preimage + 4), 32);
8100         LDKThirtyTwoBytes payment_secret_ref;
8101         CHECK(*((uint32_t*)payment_secret) == 32);
8102         memcpy(payment_secret_ref.data, (uint8_t*)(payment_secret + 4), 32);
8103         jboolean ret_val = ChannelManager_claim_funds(&this_arg_conv, payment_preimage_ref, payment_secret_ref, expected_amount);
8104         return ret_val;
8105 }
8106
8107 int8_tArray TS_ChannelManager_get_our_node_id(uint32_t this_arg) {
8108         LDKChannelManager this_arg_conv;
8109         this_arg_conv.inner = (void*)(this_arg & (~1));
8110         this_arg_conv.is_owned = false;
8111         int8_tArray arg_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
8112         memcpy((uint8_t*)(arg_arr + 4), ChannelManager_get_our_node_id(&this_arg_conv).compressed_form, 33);
8113         return arg_arr;
8114 }
8115
8116 void TS_ChannelManager_channel_monitor_updated(uint32_t this_arg, uint32_t funding_txo, int64_t highest_applied_update_id) {
8117         LDKChannelManager this_arg_conv;
8118         this_arg_conv.inner = (void*)(this_arg & (~1));
8119         this_arg_conv.is_owned = false;
8120         LDKOutPoint funding_txo_conv;
8121         funding_txo_conv.inner = (void*)(funding_txo & (~1));
8122         funding_txo_conv.is_owned = false;
8123         ChannelManager_channel_monitor_updated(&this_arg_conv, &funding_txo_conv, highest_applied_update_id);
8124 }
8125
8126 uint32_t TS_ChannelManager_as_MessageSendEventsProvider(uint32_t this_arg) {
8127         LDKChannelManager this_arg_conv;
8128         this_arg_conv.inner = (void*)(this_arg & (~1));
8129         this_arg_conv.is_owned = false;
8130         LDKMessageSendEventsProvider* ret = MALLOC(sizeof(LDKMessageSendEventsProvider), "LDKMessageSendEventsProvider");
8131         *ret = ChannelManager_as_MessageSendEventsProvider(&this_arg_conv);
8132         return (long)ret;
8133 }
8134
8135 uint32_t TS_ChannelManager_as_EventsProvider(uint32_t this_arg) {
8136         LDKChannelManager this_arg_conv;
8137         this_arg_conv.inner = (void*)(this_arg & (~1));
8138         this_arg_conv.is_owned = false;
8139         LDKEventsProvider* ret = MALLOC(sizeof(LDKEventsProvider), "LDKEventsProvider");
8140         *ret = ChannelManager_as_EventsProvider(&this_arg_conv);
8141         return (long)ret;
8142 }
8143
8144 void TS_ChannelManager_block_connected(uint32_t this_arg, int8_tArray header, uint32_tArray txdata, int32_t height) {
8145         LDKChannelManager this_arg_conv;
8146         this_arg_conv.inner = (void*)(this_arg & (~1));
8147         this_arg_conv.is_owned = false;
8148         unsigned char header_arr[80];
8149         CHECK(*((uint32_t*)header) == 80);
8150         memcpy(header_arr, (uint8_t*)(header + 4), 80);
8151         unsigned char (*header_ref)[80] = &header_arr;
8152         LDKCVec_C2Tuple_usizeTransactionZZ txdata_constr;
8153         txdata_constr.datalen = *((uint32_t*)txdata);
8154         if (txdata_constr.datalen > 0)
8155                 txdata_constr.data = MALLOC(txdata_constr.datalen * sizeof(LDKC2Tuple_usizeTransactionZ), "LDKCVec_C2Tuple_usizeTransactionZZ Elements");
8156         else
8157                 txdata_constr.data = NULL;
8158         uint32_t* txdata_vals = (uint32_t*)(txdata + 4);
8159         for (size_t e = 0; e < txdata_constr.datalen; e++) {
8160                 uint32_t arr_conv_30 = txdata_vals[e];
8161                 LDKC2Tuple_usizeTransactionZ arr_conv_30_conv = *(LDKC2Tuple_usizeTransactionZ*)arr_conv_30;
8162                 FREE((void*)arr_conv_30);
8163                 txdata_constr.data[e] = arr_conv_30_conv;
8164         }
8165         ChannelManager_block_connected(&this_arg_conv, header_ref, txdata_constr, height);
8166 }
8167
8168 void TS_ChannelManager_block_disconnected(uint32_t this_arg, int8_tArray header) {
8169         LDKChannelManager this_arg_conv;
8170         this_arg_conv.inner = (void*)(this_arg & (~1));
8171         this_arg_conv.is_owned = false;
8172         unsigned char header_arr[80];
8173         CHECK(*((uint32_t*)header) == 80);
8174         memcpy(header_arr, (uint8_t*)(header + 4), 80);
8175         unsigned char (*header_ref)[80] = &header_arr;
8176         ChannelManager_block_disconnected(&this_arg_conv, header_ref);
8177 }
8178
8179 uint32_t TS_ChannelManager_as_ChannelMessageHandler(uint32_t this_arg) {
8180         LDKChannelManager this_arg_conv;
8181         this_arg_conv.inner = (void*)(this_arg & (~1));
8182         this_arg_conv.is_owned = false;
8183         LDKChannelMessageHandler* ret = MALLOC(sizeof(LDKChannelMessageHandler), "LDKChannelMessageHandler");
8184         *ret = ChannelManager_as_ChannelMessageHandler(&this_arg_conv);
8185         return (long)ret;
8186 }
8187
8188 int8_tArray TS_ChannelManager_write(uint32_t obj) {
8189         LDKChannelManager obj_conv;
8190         obj_conv.inner = (void*)(obj & (~1));
8191         obj_conv.is_owned = false;
8192         LDKCVec_u8Z arg_var = ChannelManager_write(&obj_conv);
8193         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
8194         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
8195         CVec_u8Z_free(arg_var);
8196         return arg_arr;
8197 }
8198
8199 void TS_ChannelManagerReadArgs_free(uint32_t this_ptr) {
8200         LDKChannelManagerReadArgs this_ptr_conv;
8201         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8202         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8203         ChannelManagerReadArgs_free(this_ptr_conv);
8204 }
8205
8206 uint32_t TS_ChannelManagerReadArgs_get_keys_manager(uint32_t this_ptr) {
8207         LDKChannelManagerReadArgs this_ptr_conv;
8208         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8209         this_ptr_conv.is_owned = false;
8210         long ret_ret = (long)ChannelManagerReadArgs_get_keys_manager(&this_ptr_conv);
8211         return ret_ret;
8212 }
8213
8214 void TS_ChannelManagerReadArgs_set_keys_manager(uint32_t this_ptr, uint32_t val) {
8215         LDKChannelManagerReadArgs this_ptr_conv;
8216         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8217         this_ptr_conv.is_owned = false;
8218         LDKKeysInterface val_conv = *(LDKKeysInterface*)val;
8219         ChannelManagerReadArgs_set_keys_manager(&this_ptr_conv, val_conv);
8220 }
8221
8222 uint32_t TS_ChannelManagerReadArgs_get_fee_estimator(uint32_t this_ptr) {
8223         LDKChannelManagerReadArgs this_ptr_conv;
8224         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8225         this_ptr_conv.is_owned = false;
8226         long ret_ret = (long)ChannelManagerReadArgs_get_fee_estimator(&this_ptr_conv);
8227         return ret_ret;
8228 }
8229
8230 void TS_ChannelManagerReadArgs_set_fee_estimator(uint32_t this_ptr, uint32_t val) {
8231         LDKChannelManagerReadArgs this_ptr_conv;
8232         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8233         this_ptr_conv.is_owned = false;
8234         LDKFeeEstimator val_conv = *(LDKFeeEstimator*)val;
8235         ChannelManagerReadArgs_set_fee_estimator(&this_ptr_conv, val_conv);
8236 }
8237
8238 uint32_t TS_ChannelManagerReadArgs_get_chain_monitor(uint32_t this_ptr) {
8239         LDKChannelManagerReadArgs this_ptr_conv;
8240         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8241         this_ptr_conv.is_owned = false;
8242         long ret_ret = (long)ChannelManagerReadArgs_get_chain_monitor(&this_ptr_conv);
8243         return ret_ret;
8244 }
8245
8246 void TS_ChannelManagerReadArgs_set_chain_monitor(uint32_t this_ptr, uint32_t val) {
8247         LDKChannelManagerReadArgs this_ptr_conv;
8248         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8249         this_ptr_conv.is_owned = false;
8250         LDKWatch val_conv = *(LDKWatch*)val;
8251         ChannelManagerReadArgs_set_chain_monitor(&this_ptr_conv, val_conv);
8252 }
8253
8254 uint32_t TS_ChannelManagerReadArgs_get_tx_broadcaster(uint32_t this_ptr) {
8255         LDKChannelManagerReadArgs this_ptr_conv;
8256         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8257         this_ptr_conv.is_owned = false;
8258         long ret_ret = (long)ChannelManagerReadArgs_get_tx_broadcaster(&this_ptr_conv);
8259         return ret_ret;
8260 }
8261
8262 void TS_ChannelManagerReadArgs_set_tx_broadcaster(uint32_t this_ptr, uint32_t val) {
8263         LDKChannelManagerReadArgs this_ptr_conv;
8264         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8265         this_ptr_conv.is_owned = false;
8266         LDKBroadcasterInterface val_conv = *(LDKBroadcasterInterface*)val;
8267         ChannelManagerReadArgs_set_tx_broadcaster(&this_ptr_conv, val_conv);
8268 }
8269
8270 uint32_t TS_ChannelManagerReadArgs_get_logger(uint32_t this_ptr) {
8271         LDKChannelManagerReadArgs this_ptr_conv;
8272         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8273         this_ptr_conv.is_owned = false;
8274         long ret_ret = (long)ChannelManagerReadArgs_get_logger(&this_ptr_conv);
8275         return ret_ret;
8276 }
8277
8278 void TS_ChannelManagerReadArgs_set_logger(uint32_t this_ptr, uint32_t val) {
8279         LDKChannelManagerReadArgs this_ptr_conv;
8280         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8281         this_ptr_conv.is_owned = false;
8282         LDKLogger val_conv = *(LDKLogger*)val;
8283         ChannelManagerReadArgs_set_logger(&this_ptr_conv, val_conv);
8284 }
8285
8286 uint32_t TS_ChannelManagerReadArgs_get_default_config(uint32_t this_ptr) {
8287         LDKChannelManagerReadArgs this_ptr_conv;
8288         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8289         this_ptr_conv.is_owned = false;
8290         LDKUserConfig ret_var = ChannelManagerReadArgs_get_default_config(&this_ptr_conv);
8291         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8292         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8293         long ret_ref = (long)ret_var.inner;
8294         if (ret_var.is_owned) {
8295                 ret_ref |= 1;
8296         }
8297         return ret_ref;
8298 }
8299
8300 void TS_ChannelManagerReadArgs_set_default_config(uint32_t this_ptr, uint32_t val) {
8301         LDKChannelManagerReadArgs this_ptr_conv;
8302         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8303         this_ptr_conv.is_owned = false;
8304         LDKUserConfig val_conv;
8305         val_conv.inner = (void*)(val & (~1));
8306         val_conv.is_owned = (val & 1) || (val == 0);
8307         if (val_conv.inner != NULL)
8308                 val_conv = UserConfig_clone(&val_conv);
8309         ChannelManagerReadArgs_set_default_config(&this_ptr_conv, val_conv);
8310 }
8311
8312 uint32_t TS_ChannelManagerReadArgs_new(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) {
8313         LDKKeysInterface keys_manager_conv = *(LDKKeysInterface*)keys_manager;
8314         LDKFeeEstimator fee_estimator_conv = *(LDKFeeEstimator*)fee_estimator;
8315         LDKWatch chain_monitor_conv = *(LDKWatch*)chain_monitor;
8316         LDKBroadcasterInterface tx_broadcaster_conv = *(LDKBroadcasterInterface*)tx_broadcaster;
8317         LDKLogger logger_conv = *(LDKLogger*)logger;
8318         LDKUserConfig default_config_conv;
8319         default_config_conv.inner = (void*)(default_config & (~1));
8320         default_config_conv.is_owned = (default_config & 1) || (default_config == 0);
8321         if (default_config_conv.inner != NULL)
8322                 default_config_conv = UserConfig_clone(&default_config_conv);
8323         LDKCVec_ChannelMonitorZ channel_monitors_constr;
8324         channel_monitors_constr.datalen = *((uint32_t*)channel_monitors);
8325         if (channel_monitors_constr.datalen > 0)
8326                 channel_monitors_constr.data = MALLOC(channel_monitors_constr.datalen * sizeof(LDKChannelMonitor), "LDKCVec_ChannelMonitorZ Elements");
8327         else
8328                 channel_monitors_constr.data = NULL;
8329         uint32_t* channel_monitors_vals = (uint32_t*)(channel_monitors + 4);
8330         for (size_t q = 0; q < channel_monitors_constr.datalen; q++) {
8331                 uint32_t arr_conv_16 = channel_monitors_vals[q];
8332                 LDKChannelMonitor arr_conv_16_conv;
8333                 arr_conv_16_conv.inner = (void*)(arr_conv_16 & (~1));
8334                 arr_conv_16_conv.is_owned = (arr_conv_16 & 1) || (arr_conv_16 == 0);
8335                 // Warning: we may need a move here but can't clone!
8336                 channel_monitors_constr.data[q] = arr_conv_16_conv;
8337         }
8338         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);
8339         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8340         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8341         long ret_ref = (long)ret_var.inner;
8342         if (ret_var.is_owned) {
8343                 ret_ref |= 1;
8344         }
8345         return ret_ref;
8346 }
8347
8348 uint32_t TS_C2Tuple_BlockHashChannelManagerZ_read(int8_tArray ser, uint32_t arg) {
8349         LDKu8slice ser_ref;
8350         ser_ref.datalen = *((uint32_t*)ser);
8351         ser_ref.data = (int8_t*)(ser + 4);
8352         LDKChannelManagerReadArgs arg_conv;
8353         arg_conv.inner = (void*)(arg & (~1));
8354         arg_conv.is_owned = (arg & 1) || (arg == 0);
8355         // Warning: we may need a move here but can't clone!
8356         LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ), "LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ");
8357         *ret_conv = C2Tuple_BlockHashChannelManagerZ_read(ser_ref, arg_conv);
8358         return (long)ret_conv;
8359 }
8360
8361 void TS_DecodeError_free(uint32_t this_ptr) {
8362         LDKDecodeError this_ptr_conv;
8363         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8364         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8365         DecodeError_free(this_ptr_conv);
8366 }
8367
8368 void TS_Init_free(uint32_t this_ptr) {
8369         LDKInit this_ptr_conv;
8370         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8371         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8372         Init_free(this_ptr_conv);
8373 }
8374
8375 uint32_t TS_Init_clone(uint32_t orig) {
8376         LDKInit orig_conv;
8377         orig_conv.inner = (void*)(orig & (~1));
8378         orig_conv.is_owned = false;
8379         LDKInit ret_var = Init_clone(&orig_conv);
8380         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8381         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8382         long ret_ref = (long)ret_var.inner;
8383         if (ret_var.is_owned) {
8384                 ret_ref |= 1;
8385         }
8386         return ret_ref;
8387 }
8388
8389 void TS_ErrorMessage_free(uint32_t this_ptr) {
8390         LDKErrorMessage this_ptr_conv;
8391         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8392         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8393         ErrorMessage_free(this_ptr_conv);
8394 }
8395
8396 uint32_t TS_ErrorMessage_clone(uint32_t orig) {
8397         LDKErrorMessage orig_conv;
8398         orig_conv.inner = (void*)(orig & (~1));
8399         orig_conv.is_owned = false;
8400         LDKErrorMessage ret_var = ErrorMessage_clone(&orig_conv);
8401         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8402         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8403         long ret_ref = (long)ret_var.inner;
8404         if (ret_var.is_owned) {
8405                 ret_ref |= 1;
8406         }
8407         return ret_ref;
8408 }
8409
8410 int8_tArray TS_ErrorMessage_get_channel_id(uint32_t this_ptr) {
8411         LDKErrorMessage this_ptr_conv;
8412         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8413         this_ptr_conv.is_owned = false;
8414         int8_tArray ret_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
8415         memcpy((uint8_t*)(ret_arr + 4), *ErrorMessage_get_channel_id(&this_ptr_conv), 32);
8416         return ret_arr;
8417 }
8418
8419 void TS_ErrorMessage_set_channel_id(uint32_t this_ptr, int8_tArray val) {
8420         LDKErrorMessage this_ptr_conv;
8421         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8422         this_ptr_conv.is_owned = false;
8423         LDKThirtyTwoBytes val_ref;
8424         CHECK(*((uint32_t*)val) == 32);
8425         memcpy(val_ref.data, (uint8_t*)(val + 4), 32);
8426         ErrorMessage_set_channel_id(&this_ptr_conv, val_ref);
8427 }
8428
8429 jstring TS_ErrorMessage_get_data(uint32_t this_ptr) {
8430         LDKErrorMessage this_ptr_conv;
8431         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8432         this_ptr_conv.is_owned = false;
8433         LDKStr _str = ErrorMessage_get_data(&this_ptr_conv);
8434         jstring _conv = str_ref_to_ts(_str.chars, _str.len);
8435         return _conv;
8436 }
8437
8438 void TS_ErrorMessage_set_data(uint32_t this_ptr, int8_tArray val) {
8439         LDKErrorMessage this_ptr_conv;
8440         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8441         this_ptr_conv.is_owned = false;
8442         LDKCVec_u8Z val_ref;
8443         val_ref.datalen = *((uint32_t*)val);
8444         val_ref.data = MALLOC(val_ref.datalen, "LDKCVec_u8Z Bytes");
8445         memcpy(val_ref.data, (uint8_t*)(val + 4), val_ref.datalen);
8446         ErrorMessage_set_data(&this_ptr_conv, val_ref);
8447 }
8448
8449 uint32_t TS_ErrorMessage_new(int8_tArray channel_id_arg, int8_tArray data_arg) {
8450         LDKThirtyTwoBytes channel_id_arg_ref;
8451         CHECK(*((uint32_t*)channel_id_arg) == 32);
8452         memcpy(channel_id_arg_ref.data, (uint8_t*)(channel_id_arg + 4), 32);
8453         LDKCVec_u8Z data_arg_ref;
8454         data_arg_ref.datalen = *((uint32_t*)data_arg);
8455         data_arg_ref.data = MALLOC(data_arg_ref.datalen, "LDKCVec_u8Z Bytes");
8456         memcpy(data_arg_ref.data, (uint8_t*)(data_arg + 4), data_arg_ref.datalen);
8457         LDKErrorMessage ret_var = ErrorMessage_new(channel_id_arg_ref, data_arg_ref);
8458         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8459         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8460         long ret_ref = (long)ret_var.inner;
8461         if (ret_var.is_owned) {
8462                 ret_ref |= 1;
8463         }
8464         return ret_ref;
8465 }
8466
8467 void TS_Ping_free(uint32_t this_ptr) {
8468         LDKPing this_ptr_conv;
8469         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8470         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8471         Ping_free(this_ptr_conv);
8472 }
8473
8474 uint32_t TS_Ping_clone(uint32_t orig) {
8475         LDKPing orig_conv;
8476         orig_conv.inner = (void*)(orig & (~1));
8477         orig_conv.is_owned = false;
8478         LDKPing ret_var = Ping_clone(&orig_conv);
8479         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8480         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8481         long ret_ref = (long)ret_var.inner;
8482         if (ret_var.is_owned) {
8483                 ret_ref |= 1;
8484         }
8485         return ret_ref;
8486 }
8487
8488 int16_t TS_Ping_get_ponglen(uint32_t this_ptr) {
8489         LDKPing this_ptr_conv;
8490         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8491         this_ptr_conv.is_owned = false;
8492         int16_t ret_val = Ping_get_ponglen(&this_ptr_conv);
8493         return ret_val;
8494 }
8495
8496 void TS_Ping_set_ponglen(uint32_t this_ptr, int16_t val) {
8497         LDKPing this_ptr_conv;
8498         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8499         this_ptr_conv.is_owned = false;
8500         Ping_set_ponglen(&this_ptr_conv, val);
8501 }
8502
8503 int16_t TS_Ping_get_byteslen(uint32_t this_ptr) {
8504         LDKPing this_ptr_conv;
8505         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8506         this_ptr_conv.is_owned = false;
8507         int16_t ret_val = Ping_get_byteslen(&this_ptr_conv);
8508         return ret_val;
8509 }
8510
8511 void TS_Ping_set_byteslen(uint32_t this_ptr, int16_t val) {
8512         LDKPing this_ptr_conv;
8513         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8514         this_ptr_conv.is_owned = false;
8515         Ping_set_byteslen(&this_ptr_conv, val);
8516 }
8517
8518 uint32_t TS_Ping_new(int16_t ponglen_arg, int16_t byteslen_arg) {
8519         LDKPing ret_var = Ping_new(ponglen_arg, byteslen_arg);
8520         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8521         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8522         long ret_ref = (long)ret_var.inner;
8523         if (ret_var.is_owned) {
8524                 ret_ref |= 1;
8525         }
8526         return ret_ref;
8527 }
8528
8529 void TS_Pong_free(uint32_t this_ptr) {
8530         LDKPong this_ptr_conv;
8531         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8532         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8533         Pong_free(this_ptr_conv);
8534 }
8535
8536 uint32_t TS_Pong_clone(uint32_t orig) {
8537         LDKPong orig_conv;
8538         orig_conv.inner = (void*)(orig & (~1));
8539         orig_conv.is_owned = false;
8540         LDKPong ret_var = Pong_clone(&orig_conv);
8541         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8542         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8543         long ret_ref = (long)ret_var.inner;
8544         if (ret_var.is_owned) {
8545                 ret_ref |= 1;
8546         }
8547         return ret_ref;
8548 }
8549
8550 int16_t TS_Pong_get_byteslen(uint32_t this_ptr) {
8551         LDKPong this_ptr_conv;
8552         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8553         this_ptr_conv.is_owned = false;
8554         int16_t ret_val = Pong_get_byteslen(&this_ptr_conv);
8555         return ret_val;
8556 }
8557
8558 void TS_Pong_set_byteslen(uint32_t this_ptr, int16_t val) {
8559         LDKPong this_ptr_conv;
8560         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8561         this_ptr_conv.is_owned = false;
8562         Pong_set_byteslen(&this_ptr_conv, val);
8563 }
8564
8565 uint32_t TS_Pong_new(int16_t byteslen_arg) {
8566         LDKPong ret_var = Pong_new(byteslen_arg);
8567         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8568         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8569         long ret_ref = (long)ret_var.inner;
8570         if (ret_var.is_owned) {
8571                 ret_ref |= 1;
8572         }
8573         return ret_ref;
8574 }
8575
8576 void TS_OpenChannel_free(uint32_t this_ptr) {
8577         LDKOpenChannel this_ptr_conv;
8578         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8579         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8580         OpenChannel_free(this_ptr_conv);
8581 }
8582
8583 uint32_t TS_OpenChannel_clone(uint32_t orig) {
8584         LDKOpenChannel orig_conv;
8585         orig_conv.inner = (void*)(orig & (~1));
8586         orig_conv.is_owned = false;
8587         LDKOpenChannel ret_var = OpenChannel_clone(&orig_conv);
8588         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8589         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8590         long ret_ref = (long)ret_var.inner;
8591         if (ret_var.is_owned) {
8592                 ret_ref |= 1;
8593         }
8594         return ret_ref;
8595 }
8596
8597 int8_tArray TS_OpenChannel_get_chain_hash(uint32_t this_ptr) {
8598         LDKOpenChannel this_ptr_conv;
8599         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8600         this_ptr_conv.is_owned = false;
8601         int8_tArray ret_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
8602         memcpy((uint8_t*)(ret_arr + 4), *OpenChannel_get_chain_hash(&this_ptr_conv), 32);
8603         return ret_arr;
8604 }
8605
8606 void TS_OpenChannel_set_chain_hash(uint32_t this_ptr, int8_tArray val) {
8607         LDKOpenChannel this_ptr_conv;
8608         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8609         this_ptr_conv.is_owned = false;
8610         LDKThirtyTwoBytes val_ref;
8611         CHECK(*((uint32_t*)val) == 32);
8612         memcpy(val_ref.data, (uint8_t*)(val + 4), 32);
8613         OpenChannel_set_chain_hash(&this_ptr_conv, val_ref);
8614 }
8615
8616 int8_tArray TS_OpenChannel_get_temporary_channel_id(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 = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
8621         memcpy((uint8_t*)(ret_arr + 4), *OpenChannel_get_temporary_channel_id(&this_ptr_conv), 32);
8622         return ret_arr;
8623 }
8624
8625 void TS_OpenChannel_set_temporary_channel_id(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(*((uint32_t*)val) == 32);
8631         memcpy(val_ref.data, (uint8_t*)(val + 4), 32);
8632         OpenChannel_set_temporary_channel_id(&this_ptr_conv, val_ref);
8633 }
8634
8635 int64_t TS_OpenChannel_get_funding_satoshis(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         int64_t ret_val = OpenChannel_get_funding_satoshis(&this_ptr_conv);
8640         return ret_val;
8641 }
8642
8643 void TS_OpenChannel_set_funding_satoshis(uint32_t this_ptr, int64_t val) {
8644         LDKOpenChannel this_ptr_conv;
8645         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8646         this_ptr_conv.is_owned = false;
8647         OpenChannel_set_funding_satoshis(&this_ptr_conv, val);
8648 }
8649
8650 int64_t TS_OpenChannel_get_push_msat(uint32_t this_ptr) {
8651         LDKOpenChannel this_ptr_conv;
8652         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8653         this_ptr_conv.is_owned = false;
8654         int64_t ret_val = OpenChannel_get_push_msat(&this_ptr_conv);
8655         return ret_val;
8656 }
8657
8658 void TS_OpenChannel_set_push_msat(uint32_t this_ptr, int64_t val) {
8659         LDKOpenChannel this_ptr_conv;
8660         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8661         this_ptr_conv.is_owned = false;
8662         OpenChannel_set_push_msat(&this_ptr_conv, val);
8663 }
8664
8665 int64_t TS_OpenChannel_get_dust_limit_satoshis(uint32_t this_ptr) {
8666         LDKOpenChannel this_ptr_conv;
8667         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8668         this_ptr_conv.is_owned = false;
8669         int64_t ret_val = OpenChannel_get_dust_limit_satoshis(&this_ptr_conv);
8670         return ret_val;
8671 }
8672
8673 void TS_OpenChannel_set_dust_limit_satoshis(uint32_t this_ptr, int64_t val) {
8674         LDKOpenChannel this_ptr_conv;
8675         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8676         this_ptr_conv.is_owned = false;
8677         OpenChannel_set_dust_limit_satoshis(&this_ptr_conv, val);
8678 }
8679
8680 int64_t TS_OpenChannel_get_max_htlc_value_in_flight_msat(uint32_t this_ptr) {
8681         LDKOpenChannel this_ptr_conv;
8682         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8683         this_ptr_conv.is_owned = false;
8684         int64_t ret_val = OpenChannel_get_max_htlc_value_in_flight_msat(&this_ptr_conv);
8685         return ret_val;
8686 }
8687
8688 void TS_OpenChannel_set_max_htlc_value_in_flight_msat(uint32_t this_ptr, int64_t val) {
8689         LDKOpenChannel this_ptr_conv;
8690         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8691         this_ptr_conv.is_owned = false;
8692         OpenChannel_set_max_htlc_value_in_flight_msat(&this_ptr_conv, val);
8693 }
8694
8695 int64_t TS_OpenChannel_get_channel_reserve_satoshis(uint32_t this_ptr) {
8696         LDKOpenChannel this_ptr_conv;
8697         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8698         this_ptr_conv.is_owned = false;
8699         int64_t ret_val = OpenChannel_get_channel_reserve_satoshis(&this_ptr_conv);
8700         return ret_val;
8701 }
8702
8703 void TS_OpenChannel_set_channel_reserve_satoshis(uint32_t this_ptr, int64_t val) {
8704         LDKOpenChannel this_ptr_conv;
8705         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8706         this_ptr_conv.is_owned = false;
8707         OpenChannel_set_channel_reserve_satoshis(&this_ptr_conv, val);
8708 }
8709
8710 int64_t TS_OpenChannel_get_htlc_minimum_msat(uint32_t this_ptr) {
8711         LDKOpenChannel this_ptr_conv;
8712         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8713         this_ptr_conv.is_owned = false;
8714         int64_t ret_val = OpenChannel_get_htlc_minimum_msat(&this_ptr_conv);
8715         return ret_val;
8716 }
8717
8718 void TS_OpenChannel_set_htlc_minimum_msat(uint32_t this_ptr, int64_t val) {
8719         LDKOpenChannel this_ptr_conv;
8720         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8721         this_ptr_conv.is_owned = false;
8722         OpenChannel_set_htlc_minimum_msat(&this_ptr_conv, val);
8723 }
8724
8725 int32_t TS_OpenChannel_get_feerate_per_kw(uint32_t this_ptr) {
8726         LDKOpenChannel this_ptr_conv;
8727         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8728         this_ptr_conv.is_owned = false;
8729         int32_t ret_val = OpenChannel_get_feerate_per_kw(&this_ptr_conv);
8730         return ret_val;
8731 }
8732
8733 void TS_OpenChannel_set_feerate_per_kw(uint32_t this_ptr, int32_t val) {
8734         LDKOpenChannel this_ptr_conv;
8735         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8736         this_ptr_conv.is_owned = false;
8737         OpenChannel_set_feerate_per_kw(&this_ptr_conv, val);
8738 }
8739
8740 int16_t TS_OpenChannel_get_to_self_delay(uint32_t this_ptr) {
8741         LDKOpenChannel this_ptr_conv;
8742         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8743         this_ptr_conv.is_owned = false;
8744         int16_t ret_val = OpenChannel_get_to_self_delay(&this_ptr_conv);
8745         return ret_val;
8746 }
8747
8748 void TS_OpenChannel_set_to_self_delay(uint32_t this_ptr, int16_t val) {
8749         LDKOpenChannel this_ptr_conv;
8750         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8751         this_ptr_conv.is_owned = false;
8752         OpenChannel_set_to_self_delay(&this_ptr_conv, val);
8753 }
8754
8755 int16_t TS_OpenChannel_get_max_accepted_htlcs(uint32_t this_ptr) {
8756         LDKOpenChannel this_ptr_conv;
8757         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8758         this_ptr_conv.is_owned = false;
8759         int16_t ret_val = OpenChannel_get_max_accepted_htlcs(&this_ptr_conv);
8760         return ret_val;
8761 }
8762
8763 void TS_OpenChannel_set_max_accepted_htlcs(uint32_t this_ptr, int16_t val) {
8764         LDKOpenChannel this_ptr_conv;
8765         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8766         this_ptr_conv.is_owned = false;
8767         OpenChannel_set_max_accepted_htlcs(&this_ptr_conv, val);
8768 }
8769
8770 int8_tArray TS_OpenChannel_get_funding_pubkey(uint32_t this_ptr) {
8771         LDKOpenChannel this_ptr_conv;
8772         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8773         this_ptr_conv.is_owned = false;
8774         int8_tArray arg_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
8775         memcpy((uint8_t*)(arg_arr + 4), OpenChannel_get_funding_pubkey(&this_ptr_conv).compressed_form, 33);
8776         return arg_arr;
8777 }
8778
8779 void TS_OpenChannel_set_funding_pubkey(uint32_t this_ptr, int8_tArray val) {
8780         LDKOpenChannel this_ptr_conv;
8781         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8782         this_ptr_conv.is_owned = false;
8783         LDKPublicKey val_ref;
8784         CHECK(*((uint32_t*)val) == 33);
8785         memcpy(val_ref.compressed_form, (uint8_t*)(val + 4), 33);
8786         OpenChannel_set_funding_pubkey(&this_ptr_conv, val_ref);
8787 }
8788
8789 int8_tArray TS_OpenChannel_get_revocation_basepoint(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 = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
8794         memcpy((uint8_t*)(arg_arr + 4), OpenChannel_get_revocation_basepoint(&this_ptr_conv).compressed_form, 33);
8795         return arg_arr;
8796 }
8797
8798 void TS_OpenChannel_set_revocation_basepoint(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(*((uint32_t*)val) == 33);
8804         memcpy(val_ref.compressed_form, (uint8_t*)(val + 4), 33);
8805         OpenChannel_set_revocation_basepoint(&this_ptr_conv, val_ref);
8806 }
8807
8808 int8_tArray TS_OpenChannel_get_payment_point(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 = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
8813         memcpy((uint8_t*)(arg_arr + 4), OpenChannel_get_payment_point(&this_ptr_conv).compressed_form, 33);
8814         return arg_arr;
8815 }
8816
8817 void TS_OpenChannel_set_payment_point(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(*((uint32_t*)val) == 33);
8823         memcpy(val_ref.compressed_form, (uint8_t*)(val + 4), 33);
8824         OpenChannel_set_payment_point(&this_ptr_conv, val_ref);
8825 }
8826
8827 int8_tArray TS_OpenChannel_get_delayed_payment_basepoint(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 = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
8832         memcpy((uint8_t*)(arg_arr + 4), OpenChannel_get_delayed_payment_basepoint(&this_ptr_conv).compressed_form, 33);
8833         return arg_arr;
8834 }
8835
8836 void TS_OpenChannel_set_delayed_payment_basepoint(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(*((uint32_t*)val) == 33);
8842         memcpy(val_ref.compressed_form, (uint8_t*)(val + 4), 33);
8843         OpenChannel_set_delayed_payment_basepoint(&this_ptr_conv, val_ref);
8844 }
8845
8846 int8_tArray TS_OpenChannel_get_htlc_basepoint(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 = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
8851         memcpy((uint8_t*)(arg_arr + 4), OpenChannel_get_htlc_basepoint(&this_ptr_conv).compressed_form, 33);
8852         return arg_arr;
8853 }
8854
8855 void TS_OpenChannel_set_htlc_basepoint(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(*((uint32_t*)val) == 33);
8861         memcpy(val_ref.compressed_form, (uint8_t*)(val + 4), 33);
8862         OpenChannel_set_htlc_basepoint(&this_ptr_conv, val_ref);
8863 }
8864
8865 int8_tArray TS_OpenChannel_get_first_per_commitment_point(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 = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
8870         memcpy((uint8_t*)(arg_arr + 4), OpenChannel_get_first_per_commitment_point(&this_ptr_conv).compressed_form, 33);
8871         return arg_arr;
8872 }
8873
8874 void TS_OpenChannel_set_first_per_commitment_point(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(*((uint32_t*)val) == 33);
8880         memcpy(val_ref.compressed_form, (uint8_t*)(val + 4), 33);
8881         OpenChannel_set_first_per_commitment_point(&this_ptr_conv, val_ref);
8882 }
8883
8884 int8_t TS_OpenChannel_get_channel_flags(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_t ret_val = OpenChannel_get_channel_flags(&this_ptr_conv);
8889         return ret_val;
8890 }
8891
8892 void TS_OpenChannel_set_channel_flags(uint32_t this_ptr, int8_t val) {
8893         LDKOpenChannel this_ptr_conv;
8894         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8895         this_ptr_conv.is_owned = false;
8896         OpenChannel_set_channel_flags(&this_ptr_conv, val);
8897 }
8898
8899 void TS_AcceptChannel_free(uint32_t this_ptr) {
8900         LDKAcceptChannel this_ptr_conv;
8901         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8902         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8903         AcceptChannel_free(this_ptr_conv);
8904 }
8905
8906 uint32_t TS_AcceptChannel_clone(uint32_t orig) {
8907         LDKAcceptChannel orig_conv;
8908         orig_conv.inner = (void*)(orig & (~1));
8909         orig_conv.is_owned = false;
8910         LDKAcceptChannel ret_var = AcceptChannel_clone(&orig_conv);
8911         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8912         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8913         long ret_ref = (long)ret_var.inner;
8914         if (ret_var.is_owned) {
8915                 ret_ref |= 1;
8916         }
8917         return ret_ref;
8918 }
8919
8920 int8_tArray TS_AcceptChannel_get_temporary_channel_id(uint32_t this_ptr) {
8921         LDKAcceptChannel this_ptr_conv;
8922         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8923         this_ptr_conv.is_owned = false;
8924         int8_tArray ret_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
8925         memcpy((uint8_t*)(ret_arr + 4), *AcceptChannel_get_temporary_channel_id(&this_ptr_conv), 32);
8926         return ret_arr;
8927 }
8928
8929 void TS_AcceptChannel_set_temporary_channel_id(uint32_t this_ptr, int8_tArray val) {
8930         LDKAcceptChannel this_ptr_conv;
8931         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8932         this_ptr_conv.is_owned = false;
8933         LDKThirtyTwoBytes val_ref;
8934         CHECK(*((uint32_t*)val) == 32);
8935         memcpy(val_ref.data, (uint8_t*)(val + 4), 32);
8936         AcceptChannel_set_temporary_channel_id(&this_ptr_conv, val_ref);
8937 }
8938
8939 int64_t TS_AcceptChannel_get_dust_limit_satoshis(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         int64_t ret_val = AcceptChannel_get_dust_limit_satoshis(&this_ptr_conv);
8944         return ret_val;
8945 }
8946
8947 void TS_AcceptChannel_set_dust_limit_satoshis(uint32_t this_ptr, int64_t val) {
8948         LDKAcceptChannel this_ptr_conv;
8949         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8950         this_ptr_conv.is_owned = false;
8951         AcceptChannel_set_dust_limit_satoshis(&this_ptr_conv, val);
8952 }
8953
8954 int64_t TS_AcceptChannel_get_max_htlc_value_in_flight_msat(uint32_t this_ptr) {
8955         LDKAcceptChannel this_ptr_conv;
8956         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8957         this_ptr_conv.is_owned = false;
8958         int64_t ret_val = AcceptChannel_get_max_htlc_value_in_flight_msat(&this_ptr_conv);
8959         return ret_val;
8960 }
8961
8962 void TS_AcceptChannel_set_max_htlc_value_in_flight_msat(uint32_t this_ptr, int64_t val) {
8963         LDKAcceptChannel this_ptr_conv;
8964         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8965         this_ptr_conv.is_owned = false;
8966         AcceptChannel_set_max_htlc_value_in_flight_msat(&this_ptr_conv, val);
8967 }
8968
8969 int64_t TS_AcceptChannel_get_channel_reserve_satoshis(uint32_t this_ptr) {
8970         LDKAcceptChannel this_ptr_conv;
8971         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8972         this_ptr_conv.is_owned = false;
8973         int64_t ret_val = AcceptChannel_get_channel_reserve_satoshis(&this_ptr_conv);
8974         return ret_val;
8975 }
8976
8977 void TS_AcceptChannel_set_channel_reserve_satoshis(uint32_t this_ptr, int64_t val) {
8978         LDKAcceptChannel this_ptr_conv;
8979         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8980         this_ptr_conv.is_owned = false;
8981         AcceptChannel_set_channel_reserve_satoshis(&this_ptr_conv, val);
8982 }
8983
8984 int64_t TS_AcceptChannel_get_htlc_minimum_msat(uint32_t this_ptr) {
8985         LDKAcceptChannel this_ptr_conv;
8986         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8987         this_ptr_conv.is_owned = false;
8988         int64_t ret_val = AcceptChannel_get_htlc_minimum_msat(&this_ptr_conv);
8989         return ret_val;
8990 }
8991
8992 void TS_AcceptChannel_set_htlc_minimum_msat(uint32_t this_ptr, int64_t val) {
8993         LDKAcceptChannel this_ptr_conv;
8994         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8995         this_ptr_conv.is_owned = false;
8996         AcceptChannel_set_htlc_minimum_msat(&this_ptr_conv, val);
8997 }
8998
8999 int32_t TS_AcceptChannel_get_minimum_depth(uint32_t this_ptr) {
9000         LDKAcceptChannel this_ptr_conv;
9001         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9002         this_ptr_conv.is_owned = false;
9003         int32_t ret_val = AcceptChannel_get_minimum_depth(&this_ptr_conv);
9004         return ret_val;
9005 }
9006
9007 void TS_AcceptChannel_set_minimum_depth(uint32_t this_ptr, int32_t val) {
9008         LDKAcceptChannel this_ptr_conv;
9009         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9010         this_ptr_conv.is_owned = false;
9011         AcceptChannel_set_minimum_depth(&this_ptr_conv, val);
9012 }
9013
9014 int16_t TS_AcceptChannel_get_to_self_delay(uint32_t this_ptr) {
9015         LDKAcceptChannel this_ptr_conv;
9016         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9017         this_ptr_conv.is_owned = false;
9018         int16_t ret_val = AcceptChannel_get_to_self_delay(&this_ptr_conv);
9019         return ret_val;
9020 }
9021
9022 void TS_AcceptChannel_set_to_self_delay(uint32_t this_ptr, int16_t val) {
9023         LDKAcceptChannel this_ptr_conv;
9024         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9025         this_ptr_conv.is_owned = false;
9026         AcceptChannel_set_to_self_delay(&this_ptr_conv, val);
9027 }
9028
9029 int16_t TS_AcceptChannel_get_max_accepted_htlcs(uint32_t this_ptr) {
9030         LDKAcceptChannel this_ptr_conv;
9031         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9032         this_ptr_conv.is_owned = false;
9033         int16_t ret_val = AcceptChannel_get_max_accepted_htlcs(&this_ptr_conv);
9034         return ret_val;
9035 }
9036
9037 void TS_AcceptChannel_set_max_accepted_htlcs(uint32_t this_ptr, int16_t val) {
9038         LDKAcceptChannel this_ptr_conv;
9039         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9040         this_ptr_conv.is_owned = false;
9041         AcceptChannel_set_max_accepted_htlcs(&this_ptr_conv, val);
9042 }
9043
9044 int8_tArray TS_AcceptChannel_get_funding_pubkey(uint32_t this_ptr) {
9045         LDKAcceptChannel this_ptr_conv;
9046         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9047         this_ptr_conv.is_owned = false;
9048         int8_tArray arg_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
9049         memcpy((uint8_t*)(arg_arr + 4), AcceptChannel_get_funding_pubkey(&this_ptr_conv).compressed_form, 33);
9050         return arg_arr;
9051 }
9052
9053 void TS_AcceptChannel_set_funding_pubkey(uint32_t this_ptr, int8_tArray val) {
9054         LDKAcceptChannel this_ptr_conv;
9055         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9056         this_ptr_conv.is_owned = false;
9057         LDKPublicKey val_ref;
9058         CHECK(*((uint32_t*)val) == 33);
9059         memcpy(val_ref.compressed_form, (uint8_t*)(val + 4), 33);
9060         AcceptChannel_set_funding_pubkey(&this_ptr_conv, val_ref);
9061 }
9062
9063 int8_tArray TS_AcceptChannel_get_revocation_basepoint(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 = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
9068         memcpy((uint8_t*)(arg_arr + 4), AcceptChannel_get_revocation_basepoint(&this_ptr_conv).compressed_form, 33);
9069         return arg_arr;
9070 }
9071
9072 void TS_AcceptChannel_set_revocation_basepoint(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(*((uint32_t*)val) == 33);
9078         memcpy(val_ref.compressed_form, (uint8_t*)(val + 4), 33);
9079         AcceptChannel_set_revocation_basepoint(&this_ptr_conv, val_ref);
9080 }
9081
9082 int8_tArray TS_AcceptChannel_get_payment_point(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 = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
9087         memcpy((uint8_t*)(arg_arr + 4), AcceptChannel_get_payment_point(&this_ptr_conv).compressed_form, 33);
9088         return arg_arr;
9089 }
9090
9091 void TS_AcceptChannel_set_payment_point(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(*((uint32_t*)val) == 33);
9097         memcpy(val_ref.compressed_form, (uint8_t*)(val + 4), 33);
9098         AcceptChannel_set_payment_point(&this_ptr_conv, val_ref);
9099 }
9100
9101 int8_tArray TS_AcceptChannel_get_delayed_payment_basepoint(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 = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
9106         memcpy((uint8_t*)(arg_arr + 4), AcceptChannel_get_delayed_payment_basepoint(&this_ptr_conv).compressed_form, 33);
9107         return arg_arr;
9108 }
9109
9110 void TS_AcceptChannel_set_delayed_payment_basepoint(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(*((uint32_t*)val) == 33);
9116         memcpy(val_ref.compressed_form, (uint8_t*)(val + 4), 33);
9117         AcceptChannel_set_delayed_payment_basepoint(&this_ptr_conv, val_ref);
9118 }
9119
9120 int8_tArray TS_AcceptChannel_get_htlc_basepoint(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 = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
9125         memcpy((uint8_t*)(arg_arr + 4), AcceptChannel_get_htlc_basepoint(&this_ptr_conv).compressed_form, 33);
9126         return arg_arr;
9127 }
9128
9129 void TS_AcceptChannel_set_htlc_basepoint(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(*((uint32_t*)val) == 33);
9135         memcpy(val_ref.compressed_form, (uint8_t*)(val + 4), 33);
9136         AcceptChannel_set_htlc_basepoint(&this_ptr_conv, val_ref);
9137 }
9138
9139 int8_tArray TS_AcceptChannel_get_first_per_commitment_point(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 = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
9144         memcpy((uint8_t*)(arg_arr + 4), AcceptChannel_get_first_per_commitment_point(&this_ptr_conv).compressed_form, 33);
9145         return arg_arr;
9146 }
9147
9148 void TS_AcceptChannel_set_first_per_commitment_point(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(*((uint32_t*)val) == 33);
9154         memcpy(val_ref.compressed_form, (uint8_t*)(val + 4), 33);
9155         AcceptChannel_set_first_per_commitment_point(&this_ptr_conv, val_ref);
9156 }
9157
9158 void TS_FundingCreated_free(uint32_t this_ptr) {
9159         LDKFundingCreated this_ptr_conv;
9160         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9161         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9162         FundingCreated_free(this_ptr_conv);
9163 }
9164
9165 uint32_t TS_FundingCreated_clone(uint32_t orig) {
9166         LDKFundingCreated orig_conv;
9167         orig_conv.inner = (void*)(orig & (~1));
9168         orig_conv.is_owned = false;
9169         LDKFundingCreated ret_var = FundingCreated_clone(&orig_conv);
9170         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9171         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9172         long ret_ref = (long)ret_var.inner;
9173         if (ret_var.is_owned) {
9174                 ret_ref |= 1;
9175         }
9176         return ret_ref;
9177 }
9178
9179 int8_tArray TS_FundingCreated_get_temporary_channel_id(uint32_t this_ptr) {
9180         LDKFundingCreated this_ptr_conv;
9181         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9182         this_ptr_conv.is_owned = false;
9183         int8_tArray ret_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
9184         memcpy((uint8_t*)(ret_arr + 4), *FundingCreated_get_temporary_channel_id(&this_ptr_conv), 32);
9185         return ret_arr;
9186 }
9187
9188 void TS_FundingCreated_set_temporary_channel_id(uint32_t this_ptr, int8_tArray val) {
9189         LDKFundingCreated this_ptr_conv;
9190         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9191         this_ptr_conv.is_owned = false;
9192         LDKThirtyTwoBytes val_ref;
9193         CHECK(*((uint32_t*)val) == 32);
9194         memcpy(val_ref.data, (uint8_t*)(val + 4), 32);
9195         FundingCreated_set_temporary_channel_id(&this_ptr_conv, val_ref);
9196 }
9197
9198 int8_tArray TS_FundingCreated_get_funding_txid(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 = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
9203         memcpy((uint8_t*)(ret_arr + 4), *FundingCreated_get_funding_txid(&this_ptr_conv), 32);
9204         return ret_arr;
9205 }
9206
9207 void TS_FundingCreated_set_funding_txid(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(*((uint32_t*)val) == 32);
9213         memcpy(val_ref.data, (uint8_t*)(val + 4), 32);
9214         FundingCreated_set_funding_txid(&this_ptr_conv, val_ref);
9215 }
9216
9217 int16_t TS_FundingCreated_get_funding_output_index(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         int16_t ret_val = FundingCreated_get_funding_output_index(&this_ptr_conv);
9222         return ret_val;
9223 }
9224
9225 void TS_FundingCreated_set_funding_output_index(uint32_t this_ptr, int16_t val) {
9226         LDKFundingCreated this_ptr_conv;
9227         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9228         this_ptr_conv.is_owned = false;
9229         FundingCreated_set_funding_output_index(&this_ptr_conv, val);
9230 }
9231
9232 int8_tArray TS_FundingCreated_get_signature(uint32_t this_ptr) {
9233         LDKFundingCreated this_ptr_conv;
9234         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9235         this_ptr_conv.is_owned = false;
9236         int8_tArray arg_arr = init_arr(64, sizeof(uint8_t), "Native int8_tArray Bytes");
9237         memcpy((uint8_t*)(arg_arr + 4), FundingCreated_get_signature(&this_ptr_conv).compact_form, 64);
9238         return arg_arr;
9239 }
9240
9241 void TS_FundingCreated_set_signature(uint32_t this_ptr, int8_tArray val) {
9242         LDKFundingCreated this_ptr_conv;
9243         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9244         this_ptr_conv.is_owned = false;
9245         LDKSignature val_ref;
9246         CHECK(*((uint32_t*)val) == 64);
9247         memcpy(val_ref.compact_form, (uint8_t*)(val + 4), 64);
9248         FundingCreated_set_signature(&this_ptr_conv, val_ref);
9249 }
9250
9251 uint32_t TS_FundingCreated_new(int8_tArray temporary_channel_id_arg, int8_tArray funding_txid_arg, int16_t funding_output_index_arg, int8_tArray signature_arg) {
9252         LDKThirtyTwoBytes temporary_channel_id_arg_ref;
9253         CHECK(*((uint32_t*)temporary_channel_id_arg) == 32);
9254         memcpy(temporary_channel_id_arg_ref.data, (uint8_t*)(temporary_channel_id_arg + 4), 32);
9255         LDKThirtyTwoBytes funding_txid_arg_ref;
9256         CHECK(*((uint32_t*)funding_txid_arg) == 32);
9257         memcpy(funding_txid_arg_ref.data, (uint8_t*)(funding_txid_arg + 4), 32);
9258         LDKSignature signature_arg_ref;
9259         CHECK(*((uint32_t*)signature_arg) == 64);
9260         memcpy(signature_arg_ref.compact_form, (uint8_t*)(signature_arg + 4), 64);
9261         LDKFundingCreated ret_var = FundingCreated_new(temporary_channel_id_arg_ref, funding_txid_arg_ref, funding_output_index_arg, signature_arg_ref);
9262         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9263         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9264         long ret_ref = (long)ret_var.inner;
9265         if (ret_var.is_owned) {
9266                 ret_ref |= 1;
9267         }
9268         return ret_ref;
9269 }
9270
9271 void TS_FundingSigned_free(uint32_t this_ptr) {
9272         LDKFundingSigned this_ptr_conv;
9273         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9274         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9275         FundingSigned_free(this_ptr_conv);
9276 }
9277
9278 uint32_t TS_FundingSigned_clone(uint32_t orig) {
9279         LDKFundingSigned orig_conv;
9280         orig_conv.inner = (void*)(orig & (~1));
9281         orig_conv.is_owned = false;
9282         LDKFundingSigned ret_var = FundingSigned_clone(&orig_conv);
9283         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9284         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9285         long ret_ref = (long)ret_var.inner;
9286         if (ret_var.is_owned) {
9287                 ret_ref |= 1;
9288         }
9289         return ret_ref;
9290 }
9291
9292 int8_tArray TS_FundingSigned_get_channel_id(uint32_t this_ptr) {
9293         LDKFundingSigned this_ptr_conv;
9294         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9295         this_ptr_conv.is_owned = false;
9296         int8_tArray ret_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
9297         memcpy((uint8_t*)(ret_arr + 4), *FundingSigned_get_channel_id(&this_ptr_conv), 32);
9298         return ret_arr;
9299 }
9300
9301 void TS_FundingSigned_set_channel_id(uint32_t this_ptr, int8_tArray val) {
9302         LDKFundingSigned this_ptr_conv;
9303         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9304         this_ptr_conv.is_owned = false;
9305         LDKThirtyTwoBytes val_ref;
9306         CHECK(*((uint32_t*)val) == 32);
9307         memcpy(val_ref.data, (uint8_t*)(val + 4), 32);
9308         FundingSigned_set_channel_id(&this_ptr_conv, val_ref);
9309 }
9310
9311 int8_tArray TS_FundingSigned_get_signature(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 arg_arr = init_arr(64, sizeof(uint8_t), "Native int8_tArray Bytes");
9316         memcpy((uint8_t*)(arg_arr + 4), FundingSigned_get_signature(&this_ptr_conv).compact_form, 64);
9317         return arg_arr;
9318 }
9319
9320 void TS_FundingSigned_set_signature(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         LDKSignature val_ref;
9325         CHECK(*((uint32_t*)val) == 64);
9326         memcpy(val_ref.compact_form, (uint8_t*)(val + 4), 64);
9327         FundingSigned_set_signature(&this_ptr_conv, val_ref);
9328 }
9329
9330 uint32_t TS_FundingSigned_new(int8_tArray channel_id_arg, int8_tArray signature_arg) {
9331         LDKThirtyTwoBytes channel_id_arg_ref;
9332         CHECK(*((uint32_t*)channel_id_arg) == 32);
9333         memcpy(channel_id_arg_ref.data, (uint8_t*)(channel_id_arg + 4), 32);
9334         LDKSignature signature_arg_ref;
9335         CHECK(*((uint32_t*)signature_arg) == 64);
9336         memcpy(signature_arg_ref.compact_form, (uint8_t*)(signature_arg + 4), 64);
9337         LDKFundingSigned ret_var = FundingSigned_new(channel_id_arg_ref, signature_arg_ref);
9338         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9339         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9340         long ret_ref = (long)ret_var.inner;
9341         if (ret_var.is_owned) {
9342                 ret_ref |= 1;
9343         }
9344         return ret_ref;
9345 }
9346
9347 void TS_FundingLocked_free(uint32_t this_ptr) {
9348         LDKFundingLocked this_ptr_conv;
9349         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9350         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9351         FundingLocked_free(this_ptr_conv);
9352 }
9353
9354 uint32_t TS_FundingLocked_clone(uint32_t orig) {
9355         LDKFundingLocked orig_conv;
9356         orig_conv.inner = (void*)(orig & (~1));
9357         orig_conv.is_owned = false;
9358         LDKFundingLocked ret_var = FundingLocked_clone(&orig_conv);
9359         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9360         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9361         long ret_ref = (long)ret_var.inner;
9362         if (ret_var.is_owned) {
9363                 ret_ref |= 1;
9364         }
9365         return ret_ref;
9366 }
9367
9368 int8_tArray TS_FundingLocked_get_channel_id(uint32_t this_ptr) {
9369         LDKFundingLocked this_ptr_conv;
9370         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9371         this_ptr_conv.is_owned = false;
9372         int8_tArray ret_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
9373         memcpy((uint8_t*)(ret_arr + 4), *FundingLocked_get_channel_id(&this_ptr_conv), 32);
9374         return ret_arr;
9375 }
9376
9377 void TS_FundingLocked_set_channel_id(uint32_t this_ptr, int8_tArray val) {
9378         LDKFundingLocked this_ptr_conv;
9379         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9380         this_ptr_conv.is_owned = false;
9381         LDKThirtyTwoBytes val_ref;
9382         CHECK(*((uint32_t*)val) == 32);
9383         memcpy(val_ref.data, (uint8_t*)(val + 4), 32);
9384         FundingLocked_set_channel_id(&this_ptr_conv, val_ref);
9385 }
9386
9387 int8_tArray TS_FundingLocked_get_next_per_commitment_point(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 arg_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
9392         memcpy((uint8_t*)(arg_arr + 4), FundingLocked_get_next_per_commitment_point(&this_ptr_conv).compressed_form, 33);
9393         return arg_arr;
9394 }
9395
9396 void TS_FundingLocked_set_next_per_commitment_point(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         LDKPublicKey val_ref;
9401         CHECK(*((uint32_t*)val) == 33);
9402         memcpy(val_ref.compressed_form, (uint8_t*)(val + 4), 33);
9403         FundingLocked_set_next_per_commitment_point(&this_ptr_conv, val_ref);
9404 }
9405
9406 uint32_t TS_FundingLocked_new(int8_tArray channel_id_arg, int8_tArray next_per_commitment_point_arg) {
9407         LDKThirtyTwoBytes channel_id_arg_ref;
9408         CHECK(*((uint32_t*)channel_id_arg) == 32);
9409         memcpy(channel_id_arg_ref.data, (uint8_t*)(channel_id_arg + 4), 32);
9410         LDKPublicKey next_per_commitment_point_arg_ref;
9411         CHECK(*((uint32_t*)next_per_commitment_point_arg) == 33);
9412         memcpy(next_per_commitment_point_arg_ref.compressed_form, (uint8_t*)(next_per_commitment_point_arg + 4), 33);
9413         LDKFundingLocked ret_var = FundingLocked_new(channel_id_arg_ref, next_per_commitment_point_arg_ref);
9414         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9415         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9416         long ret_ref = (long)ret_var.inner;
9417         if (ret_var.is_owned) {
9418                 ret_ref |= 1;
9419         }
9420         return ret_ref;
9421 }
9422
9423 void TS_Shutdown_free(uint32_t this_ptr) {
9424         LDKShutdown this_ptr_conv;
9425         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9426         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9427         Shutdown_free(this_ptr_conv);
9428 }
9429
9430 uint32_t TS_Shutdown_clone(uint32_t orig) {
9431         LDKShutdown orig_conv;
9432         orig_conv.inner = (void*)(orig & (~1));
9433         orig_conv.is_owned = false;
9434         LDKShutdown ret_var = Shutdown_clone(&orig_conv);
9435         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9436         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9437         long ret_ref = (long)ret_var.inner;
9438         if (ret_var.is_owned) {
9439                 ret_ref |= 1;
9440         }
9441         return ret_ref;
9442 }
9443
9444 int8_tArray TS_Shutdown_get_channel_id(uint32_t this_ptr) {
9445         LDKShutdown this_ptr_conv;
9446         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9447         this_ptr_conv.is_owned = false;
9448         int8_tArray ret_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
9449         memcpy((uint8_t*)(ret_arr + 4), *Shutdown_get_channel_id(&this_ptr_conv), 32);
9450         return ret_arr;
9451 }
9452
9453 void TS_Shutdown_set_channel_id(uint32_t this_ptr, int8_tArray val) {
9454         LDKShutdown this_ptr_conv;
9455         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9456         this_ptr_conv.is_owned = false;
9457         LDKThirtyTwoBytes val_ref;
9458         CHECK(*((uint32_t*)val) == 32);
9459         memcpy(val_ref.data, (uint8_t*)(val + 4), 32);
9460         Shutdown_set_channel_id(&this_ptr_conv, val_ref);
9461 }
9462
9463 int8_tArray TS_Shutdown_get_scriptpubkey(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         LDKu8slice arg_var = Shutdown_get_scriptpubkey(&this_ptr_conv);
9468         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
9469         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
9470         return arg_arr;
9471 }
9472
9473 void TS_Shutdown_set_scriptpubkey(uint32_t this_ptr, int8_tArray val) {
9474         LDKShutdown this_ptr_conv;
9475         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9476         this_ptr_conv.is_owned = false;
9477         LDKCVec_u8Z val_ref;
9478         val_ref.datalen = *((uint32_t*)val);
9479         val_ref.data = MALLOC(val_ref.datalen, "LDKCVec_u8Z Bytes");
9480         memcpy(val_ref.data, (uint8_t*)(val + 4), val_ref.datalen);
9481         Shutdown_set_scriptpubkey(&this_ptr_conv, val_ref);
9482 }
9483
9484 uint32_t TS_Shutdown_new(int8_tArray channel_id_arg, int8_tArray scriptpubkey_arg) {
9485         LDKThirtyTwoBytes channel_id_arg_ref;
9486         CHECK(*((uint32_t*)channel_id_arg) == 32);
9487         memcpy(channel_id_arg_ref.data, (uint8_t*)(channel_id_arg + 4), 32);
9488         LDKCVec_u8Z scriptpubkey_arg_ref;
9489         scriptpubkey_arg_ref.datalen = *((uint32_t*)scriptpubkey_arg);
9490         scriptpubkey_arg_ref.data = MALLOC(scriptpubkey_arg_ref.datalen, "LDKCVec_u8Z Bytes");
9491         memcpy(scriptpubkey_arg_ref.data, (uint8_t*)(scriptpubkey_arg + 4), scriptpubkey_arg_ref.datalen);
9492         LDKShutdown ret_var = Shutdown_new(channel_id_arg_ref, scriptpubkey_arg_ref);
9493         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9494         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9495         long ret_ref = (long)ret_var.inner;
9496         if (ret_var.is_owned) {
9497                 ret_ref |= 1;
9498         }
9499         return ret_ref;
9500 }
9501
9502 void TS_ClosingSigned_free(uint32_t this_ptr) {
9503         LDKClosingSigned this_ptr_conv;
9504         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9505         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9506         ClosingSigned_free(this_ptr_conv);
9507 }
9508
9509 uint32_t TS_ClosingSigned_clone(uint32_t orig) {
9510         LDKClosingSigned orig_conv;
9511         orig_conv.inner = (void*)(orig & (~1));
9512         orig_conv.is_owned = false;
9513         LDKClosingSigned ret_var = ClosingSigned_clone(&orig_conv);
9514         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9515         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9516         long ret_ref = (long)ret_var.inner;
9517         if (ret_var.is_owned) {
9518                 ret_ref |= 1;
9519         }
9520         return ret_ref;
9521 }
9522
9523 int8_tArray TS_ClosingSigned_get_channel_id(uint32_t this_ptr) {
9524         LDKClosingSigned this_ptr_conv;
9525         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9526         this_ptr_conv.is_owned = false;
9527         int8_tArray ret_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
9528         memcpy((uint8_t*)(ret_arr + 4), *ClosingSigned_get_channel_id(&this_ptr_conv), 32);
9529         return ret_arr;
9530 }
9531
9532 void TS_ClosingSigned_set_channel_id(uint32_t this_ptr, int8_tArray val) {
9533         LDKClosingSigned this_ptr_conv;
9534         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9535         this_ptr_conv.is_owned = false;
9536         LDKThirtyTwoBytes val_ref;
9537         CHECK(*((uint32_t*)val) == 32);
9538         memcpy(val_ref.data, (uint8_t*)(val + 4), 32);
9539         ClosingSigned_set_channel_id(&this_ptr_conv, val_ref);
9540 }
9541
9542 int64_t TS_ClosingSigned_get_fee_satoshis(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         int64_t ret_val = ClosingSigned_get_fee_satoshis(&this_ptr_conv);
9547         return ret_val;
9548 }
9549
9550 void TS_ClosingSigned_set_fee_satoshis(uint32_t this_ptr, int64_t val) {
9551         LDKClosingSigned this_ptr_conv;
9552         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9553         this_ptr_conv.is_owned = false;
9554         ClosingSigned_set_fee_satoshis(&this_ptr_conv, val);
9555 }
9556
9557 int8_tArray TS_ClosingSigned_get_signature(uint32_t this_ptr) {
9558         LDKClosingSigned this_ptr_conv;
9559         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9560         this_ptr_conv.is_owned = false;
9561         int8_tArray arg_arr = init_arr(64, sizeof(uint8_t), "Native int8_tArray Bytes");
9562         memcpy((uint8_t*)(arg_arr + 4), ClosingSigned_get_signature(&this_ptr_conv).compact_form, 64);
9563         return arg_arr;
9564 }
9565
9566 void TS_ClosingSigned_set_signature(uint32_t this_ptr, int8_tArray val) {
9567         LDKClosingSigned this_ptr_conv;
9568         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9569         this_ptr_conv.is_owned = false;
9570         LDKSignature val_ref;
9571         CHECK(*((uint32_t*)val) == 64);
9572         memcpy(val_ref.compact_form, (uint8_t*)(val + 4), 64);
9573         ClosingSigned_set_signature(&this_ptr_conv, val_ref);
9574 }
9575
9576 uint32_t TS_ClosingSigned_new(int8_tArray channel_id_arg, int64_t fee_satoshis_arg, int8_tArray signature_arg) {
9577         LDKThirtyTwoBytes channel_id_arg_ref;
9578         CHECK(*((uint32_t*)channel_id_arg) == 32);
9579         memcpy(channel_id_arg_ref.data, (uint8_t*)(channel_id_arg + 4), 32);
9580         LDKSignature signature_arg_ref;
9581         CHECK(*((uint32_t*)signature_arg) == 64);
9582         memcpy(signature_arg_ref.compact_form, (uint8_t*)(signature_arg + 4), 64);
9583         LDKClosingSigned ret_var = ClosingSigned_new(channel_id_arg_ref, fee_satoshis_arg, signature_arg_ref);
9584         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9585         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9586         long ret_ref = (long)ret_var.inner;
9587         if (ret_var.is_owned) {
9588                 ret_ref |= 1;
9589         }
9590         return ret_ref;
9591 }
9592
9593 void TS_UpdateAddHTLC_free(uint32_t this_ptr) {
9594         LDKUpdateAddHTLC this_ptr_conv;
9595         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9596         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9597         UpdateAddHTLC_free(this_ptr_conv);
9598 }
9599
9600 uint32_t TS_UpdateAddHTLC_clone(uint32_t orig) {
9601         LDKUpdateAddHTLC orig_conv;
9602         orig_conv.inner = (void*)(orig & (~1));
9603         orig_conv.is_owned = false;
9604         LDKUpdateAddHTLC ret_var = UpdateAddHTLC_clone(&orig_conv);
9605         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9606         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9607         long ret_ref = (long)ret_var.inner;
9608         if (ret_var.is_owned) {
9609                 ret_ref |= 1;
9610         }
9611         return ret_ref;
9612 }
9613
9614 int8_tArray TS_UpdateAddHTLC_get_channel_id(uint32_t this_ptr) {
9615         LDKUpdateAddHTLC this_ptr_conv;
9616         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9617         this_ptr_conv.is_owned = false;
9618         int8_tArray ret_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
9619         memcpy((uint8_t*)(ret_arr + 4), *UpdateAddHTLC_get_channel_id(&this_ptr_conv), 32);
9620         return ret_arr;
9621 }
9622
9623 void TS_UpdateAddHTLC_set_channel_id(uint32_t this_ptr, int8_tArray val) {
9624         LDKUpdateAddHTLC this_ptr_conv;
9625         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9626         this_ptr_conv.is_owned = false;
9627         LDKThirtyTwoBytes val_ref;
9628         CHECK(*((uint32_t*)val) == 32);
9629         memcpy(val_ref.data, (uint8_t*)(val + 4), 32);
9630         UpdateAddHTLC_set_channel_id(&this_ptr_conv, val_ref);
9631 }
9632
9633 int64_t TS_UpdateAddHTLC_get_htlc_id(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         int64_t ret_val = UpdateAddHTLC_get_htlc_id(&this_ptr_conv);
9638         return ret_val;
9639 }
9640
9641 void TS_UpdateAddHTLC_set_htlc_id(uint32_t this_ptr, int64_t val) {
9642         LDKUpdateAddHTLC this_ptr_conv;
9643         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9644         this_ptr_conv.is_owned = false;
9645         UpdateAddHTLC_set_htlc_id(&this_ptr_conv, val);
9646 }
9647
9648 int64_t TS_UpdateAddHTLC_get_amount_msat(uint32_t this_ptr) {
9649         LDKUpdateAddHTLC this_ptr_conv;
9650         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9651         this_ptr_conv.is_owned = false;
9652         int64_t ret_val = UpdateAddHTLC_get_amount_msat(&this_ptr_conv);
9653         return ret_val;
9654 }
9655
9656 void TS_UpdateAddHTLC_set_amount_msat(uint32_t this_ptr, int64_t val) {
9657         LDKUpdateAddHTLC this_ptr_conv;
9658         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9659         this_ptr_conv.is_owned = false;
9660         UpdateAddHTLC_set_amount_msat(&this_ptr_conv, val);
9661 }
9662
9663 int8_tArray TS_UpdateAddHTLC_get_payment_hash(uint32_t this_ptr) {
9664         LDKUpdateAddHTLC this_ptr_conv;
9665         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9666         this_ptr_conv.is_owned = false;
9667         int8_tArray ret_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
9668         memcpy((uint8_t*)(ret_arr + 4), *UpdateAddHTLC_get_payment_hash(&this_ptr_conv), 32);
9669         return ret_arr;
9670 }
9671
9672 void TS_UpdateAddHTLC_set_payment_hash(uint32_t this_ptr, int8_tArray val) {
9673         LDKUpdateAddHTLC this_ptr_conv;
9674         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9675         this_ptr_conv.is_owned = false;
9676         LDKThirtyTwoBytes val_ref;
9677         CHECK(*((uint32_t*)val) == 32);
9678         memcpy(val_ref.data, (uint8_t*)(val + 4), 32);
9679         UpdateAddHTLC_set_payment_hash(&this_ptr_conv, val_ref);
9680 }
9681
9682 int32_t TS_UpdateAddHTLC_get_cltv_expiry(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         int32_t ret_val = UpdateAddHTLC_get_cltv_expiry(&this_ptr_conv);
9687         return ret_val;
9688 }
9689
9690 void TS_UpdateAddHTLC_set_cltv_expiry(uint32_t this_ptr, int32_t val) {
9691         LDKUpdateAddHTLC this_ptr_conv;
9692         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9693         this_ptr_conv.is_owned = false;
9694         UpdateAddHTLC_set_cltv_expiry(&this_ptr_conv, val);
9695 }
9696
9697 void TS_UpdateFulfillHTLC_free(uint32_t this_ptr) {
9698         LDKUpdateFulfillHTLC this_ptr_conv;
9699         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9700         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9701         UpdateFulfillHTLC_free(this_ptr_conv);
9702 }
9703
9704 uint32_t TS_UpdateFulfillHTLC_clone(uint32_t orig) {
9705         LDKUpdateFulfillHTLC orig_conv;
9706         orig_conv.inner = (void*)(orig & (~1));
9707         orig_conv.is_owned = false;
9708         LDKUpdateFulfillHTLC ret_var = UpdateFulfillHTLC_clone(&orig_conv);
9709         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9710         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9711         long ret_ref = (long)ret_var.inner;
9712         if (ret_var.is_owned) {
9713                 ret_ref |= 1;
9714         }
9715         return ret_ref;
9716 }
9717
9718 int8_tArray TS_UpdateFulfillHTLC_get_channel_id(uint32_t this_ptr) {
9719         LDKUpdateFulfillHTLC this_ptr_conv;
9720         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9721         this_ptr_conv.is_owned = false;
9722         int8_tArray ret_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
9723         memcpy((uint8_t*)(ret_arr + 4), *UpdateFulfillHTLC_get_channel_id(&this_ptr_conv), 32);
9724         return ret_arr;
9725 }
9726
9727 void TS_UpdateFulfillHTLC_set_channel_id(uint32_t this_ptr, int8_tArray val) {
9728         LDKUpdateFulfillHTLC this_ptr_conv;
9729         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9730         this_ptr_conv.is_owned = false;
9731         LDKThirtyTwoBytes val_ref;
9732         CHECK(*((uint32_t*)val) == 32);
9733         memcpy(val_ref.data, (uint8_t*)(val + 4), 32);
9734         UpdateFulfillHTLC_set_channel_id(&this_ptr_conv, val_ref);
9735 }
9736
9737 int64_t TS_UpdateFulfillHTLC_get_htlc_id(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         int64_t ret_val = UpdateFulfillHTLC_get_htlc_id(&this_ptr_conv);
9742         return ret_val;
9743 }
9744
9745 void TS_UpdateFulfillHTLC_set_htlc_id(uint32_t this_ptr, int64_t val) {
9746         LDKUpdateFulfillHTLC this_ptr_conv;
9747         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9748         this_ptr_conv.is_owned = false;
9749         UpdateFulfillHTLC_set_htlc_id(&this_ptr_conv, val);
9750 }
9751
9752 int8_tArray TS_UpdateFulfillHTLC_get_payment_preimage(uint32_t this_ptr) {
9753         LDKUpdateFulfillHTLC this_ptr_conv;
9754         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9755         this_ptr_conv.is_owned = false;
9756         int8_tArray ret_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
9757         memcpy((uint8_t*)(ret_arr + 4), *UpdateFulfillHTLC_get_payment_preimage(&this_ptr_conv), 32);
9758         return ret_arr;
9759 }
9760
9761 void TS_UpdateFulfillHTLC_set_payment_preimage(uint32_t this_ptr, int8_tArray val) {
9762         LDKUpdateFulfillHTLC this_ptr_conv;
9763         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9764         this_ptr_conv.is_owned = false;
9765         LDKThirtyTwoBytes val_ref;
9766         CHECK(*((uint32_t*)val) == 32);
9767         memcpy(val_ref.data, (uint8_t*)(val + 4), 32);
9768         UpdateFulfillHTLC_set_payment_preimage(&this_ptr_conv, val_ref);
9769 }
9770
9771 uint32_t TS_UpdateFulfillHTLC_new(int8_tArray channel_id_arg, int64_t htlc_id_arg, int8_tArray payment_preimage_arg) {
9772         LDKThirtyTwoBytes channel_id_arg_ref;
9773         CHECK(*((uint32_t*)channel_id_arg) == 32);
9774         memcpy(channel_id_arg_ref.data, (uint8_t*)(channel_id_arg + 4), 32);
9775         LDKThirtyTwoBytes payment_preimage_arg_ref;
9776         CHECK(*((uint32_t*)payment_preimage_arg) == 32);
9777         memcpy(payment_preimage_arg_ref.data, (uint8_t*)(payment_preimage_arg + 4), 32);
9778         LDKUpdateFulfillHTLC ret_var = UpdateFulfillHTLC_new(channel_id_arg_ref, htlc_id_arg, payment_preimage_arg_ref);
9779         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9780         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9781         long ret_ref = (long)ret_var.inner;
9782         if (ret_var.is_owned) {
9783                 ret_ref |= 1;
9784         }
9785         return ret_ref;
9786 }
9787
9788 void TS_UpdateFailHTLC_free(uint32_t this_ptr) {
9789         LDKUpdateFailHTLC this_ptr_conv;
9790         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9791         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9792         UpdateFailHTLC_free(this_ptr_conv);
9793 }
9794
9795 uint32_t TS_UpdateFailHTLC_clone(uint32_t orig) {
9796         LDKUpdateFailHTLC orig_conv;
9797         orig_conv.inner = (void*)(orig & (~1));
9798         orig_conv.is_owned = false;
9799         LDKUpdateFailHTLC ret_var = UpdateFailHTLC_clone(&orig_conv);
9800         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9801         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9802         long ret_ref = (long)ret_var.inner;
9803         if (ret_var.is_owned) {
9804                 ret_ref |= 1;
9805         }
9806         return ret_ref;
9807 }
9808
9809 int8_tArray TS_UpdateFailHTLC_get_channel_id(uint32_t this_ptr) {
9810         LDKUpdateFailHTLC this_ptr_conv;
9811         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9812         this_ptr_conv.is_owned = false;
9813         int8_tArray ret_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
9814         memcpy((uint8_t*)(ret_arr + 4), *UpdateFailHTLC_get_channel_id(&this_ptr_conv), 32);
9815         return ret_arr;
9816 }
9817
9818 void TS_UpdateFailHTLC_set_channel_id(uint32_t this_ptr, int8_tArray val) {
9819         LDKUpdateFailHTLC this_ptr_conv;
9820         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9821         this_ptr_conv.is_owned = false;
9822         LDKThirtyTwoBytes val_ref;
9823         CHECK(*((uint32_t*)val) == 32);
9824         memcpy(val_ref.data, (uint8_t*)(val + 4), 32);
9825         UpdateFailHTLC_set_channel_id(&this_ptr_conv, val_ref);
9826 }
9827
9828 int64_t TS_UpdateFailHTLC_get_htlc_id(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         int64_t ret_val = UpdateFailHTLC_get_htlc_id(&this_ptr_conv);
9833         return ret_val;
9834 }
9835
9836 void TS_UpdateFailHTLC_set_htlc_id(uint32_t this_ptr, int64_t val) {
9837         LDKUpdateFailHTLC this_ptr_conv;
9838         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9839         this_ptr_conv.is_owned = false;
9840         UpdateFailHTLC_set_htlc_id(&this_ptr_conv, val);
9841 }
9842
9843 void TS_UpdateFailMalformedHTLC_free(uint32_t this_ptr) {
9844         LDKUpdateFailMalformedHTLC this_ptr_conv;
9845         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9846         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9847         UpdateFailMalformedHTLC_free(this_ptr_conv);
9848 }
9849
9850 uint32_t TS_UpdateFailMalformedHTLC_clone(uint32_t orig) {
9851         LDKUpdateFailMalformedHTLC orig_conv;
9852         orig_conv.inner = (void*)(orig & (~1));
9853         orig_conv.is_owned = false;
9854         LDKUpdateFailMalformedHTLC ret_var = UpdateFailMalformedHTLC_clone(&orig_conv);
9855         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9856         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9857         long ret_ref = (long)ret_var.inner;
9858         if (ret_var.is_owned) {
9859                 ret_ref |= 1;
9860         }
9861         return ret_ref;
9862 }
9863
9864 int8_tArray TS_UpdateFailMalformedHTLC_get_channel_id(uint32_t this_ptr) {
9865         LDKUpdateFailMalformedHTLC this_ptr_conv;
9866         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9867         this_ptr_conv.is_owned = false;
9868         int8_tArray ret_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
9869         memcpy((uint8_t*)(ret_arr + 4), *UpdateFailMalformedHTLC_get_channel_id(&this_ptr_conv), 32);
9870         return ret_arr;
9871 }
9872
9873 void TS_UpdateFailMalformedHTLC_set_channel_id(uint32_t this_ptr, int8_tArray val) {
9874         LDKUpdateFailMalformedHTLC this_ptr_conv;
9875         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9876         this_ptr_conv.is_owned = false;
9877         LDKThirtyTwoBytes val_ref;
9878         CHECK(*((uint32_t*)val) == 32);
9879         memcpy(val_ref.data, (uint8_t*)(val + 4), 32);
9880         UpdateFailMalformedHTLC_set_channel_id(&this_ptr_conv, val_ref);
9881 }
9882
9883 int64_t TS_UpdateFailMalformedHTLC_get_htlc_id(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         int64_t ret_val = UpdateFailMalformedHTLC_get_htlc_id(&this_ptr_conv);
9888         return ret_val;
9889 }
9890
9891 void TS_UpdateFailMalformedHTLC_set_htlc_id(uint32_t this_ptr, int64_t val) {
9892         LDKUpdateFailMalformedHTLC this_ptr_conv;
9893         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9894         this_ptr_conv.is_owned = false;
9895         UpdateFailMalformedHTLC_set_htlc_id(&this_ptr_conv, val);
9896 }
9897
9898 int16_t TS_UpdateFailMalformedHTLC_get_failure_code(uint32_t this_ptr) {
9899         LDKUpdateFailMalformedHTLC this_ptr_conv;
9900         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9901         this_ptr_conv.is_owned = false;
9902         int16_t ret_val = UpdateFailMalformedHTLC_get_failure_code(&this_ptr_conv);
9903         return ret_val;
9904 }
9905
9906 void TS_UpdateFailMalformedHTLC_set_failure_code(uint32_t this_ptr, int16_t val) {
9907         LDKUpdateFailMalformedHTLC this_ptr_conv;
9908         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9909         this_ptr_conv.is_owned = false;
9910         UpdateFailMalformedHTLC_set_failure_code(&this_ptr_conv, val);
9911 }
9912
9913 void TS_CommitmentSigned_free(uint32_t this_ptr) {
9914         LDKCommitmentSigned this_ptr_conv;
9915         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9916         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9917         CommitmentSigned_free(this_ptr_conv);
9918 }
9919
9920 uint32_t TS_CommitmentSigned_clone(uint32_t orig) {
9921         LDKCommitmentSigned orig_conv;
9922         orig_conv.inner = (void*)(orig & (~1));
9923         orig_conv.is_owned = false;
9924         LDKCommitmentSigned ret_var = CommitmentSigned_clone(&orig_conv);
9925         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9926         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9927         long ret_ref = (long)ret_var.inner;
9928         if (ret_var.is_owned) {
9929                 ret_ref |= 1;
9930         }
9931         return ret_ref;
9932 }
9933
9934 int8_tArray TS_CommitmentSigned_get_channel_id(uint32_t this_ptr) {
9935         LDKCommitmentSigned this_ptr_conv;
9936         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9937         this_ptr_conv.is_owned = false;
9938         int8_tArray ret_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
9939         memcpy((uint8_t*)(ret_arr + 4), *CommitmentSigned_get_channel_id(&this_ptr_conv), 32);
9940         return ret_arr;
9941 }
9942
9943 void TS_CommitmentSigned_set_channel_id(uint32_t this_ptr, int8_tArray val) {
9944         LDKCommitmentSigned this_ptr_conv;
9945         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9946         this_ptr_conv.is_owned = false;
9947         LDKThirtyTwoBytes val_ref;
9948         CHECK(*((uint32_t*)val) == 32);
9949         memcpy(val_ref.data, (uint8_t*)(val + 4), 32);
9950         CommitmentSigned_set_channel_id(&this_ptr_conv, val_ref);
9951 }
9952
9953 int8_tArray TS_CommitmentSigned_get_signature(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 arg_arr = init_arr(64, sizeof(uint8_t), "Native int8_tArray Bytes");
9958         memcpy((uint8_t*)(arg_arr + 4), CommitmentSigned_get_signature(&this_ptr_conv).compact_form, 64);
9959         return arg_arr;
9960 }
9961
9962 void TS_CommitmentSigned_set_signature(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         LDKSignature val_ref;
9967         CHECK(*((uint32_t*)val) == 64);
9968         memcpy(val_ref.compact_form, (uint8_t*)(val + 4), 64);
9969         CommitmentSigned_set_signature(&this_ptr_conv, val_ref);
9970 }
9971
9972 void TS_CommitmentSigned_set_htlc_signatures(uint32_t this_ptr, ptrArray val) {
9973         LDKCommitmentSigned this_ptr_conv;
9974         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9975         this_ptr_conv.is_owned = false;
9976         LDKCVec_SignatureZ val_constr;
9977         val_constr.datalen = *((uint32_t*)val);
9978         if (val_constr.datalen > 0)
9979                 val_constr.data = MALLOC(val_constr.datalen * sizeof(LDKSignature), "LDKCVec_SignatureZ Elements");
9980         else
9981                 val_constr.data = NULL;
9982         int8_tArray* val_vals = (int8_tArray*)(val + 4);
9983         for (size_t m = 0; m < val_constr.datalen; m++) {
9984                 int8_tArray arr_conv_12 = val_vals[m];
9985                 LDKSignature arr_conv_12_ref;
9986                 CHECK(*((uint32_t*)arr_conv_12) == 64);
9987                 memcpy(arr_conv_12_ref.compact_form, (uint8_t*)(arr_conv_12 + 4), 64);
9988                 val_constr.data[m] = arr_conv_12_ref;
9989         }
9990         CommitmentSigned_set_htlc_signatures(&this_ptr_conv, val_constr);
9991 }
9992
9993 uint32_t TS_CommitmentSigned_new(int8_tArray channel_id_arg, int8_tArray signature_arg, ptrArray htlc_signatures_arg) {
9994         LDKThirtyTwoBytes channel_id_arg_ref;
9995         CHECK(*((uint32_t*)channel_id_arg) == 32);
9996         memcpy(channel_id_arg_ref.data, (uint8_t*)(channel_id_arg + 4), 32);
9997         LDKSignature signature_arg_ref;
9998         CHECK(*((uint32_t*)signature_arg) == 64);
9999         memcpy(signature_arg_ref.compact_form, (uint8_t*)(signature_arg + 4), 64);
10000         LDKCVec_SignatureZ htlc_signatures_arg_constr;
10001         htlc_signatures_arg_constr.datalen = *((uint32_t*)htlc_signatures_arg);
10002         if (htlc_signatures_arg_constr.datalen > 0)
10003                 htlc_signatures_arg_constr.data = MALLOC(htlc_signatures_arg_constr.datalen * sizeof(LDKSignature), "LDKCVec_SignatureZ Elements");
10004         else
10005                 htlc_signatures_arg_constr.data = NULL;
10006         int8_tArray* htlc_signatures_arg_vals = (int8_tArray*)(htlc_signatures_arg + 4);
10007         for (size_t m = 0; m < htlc_signatures_arg_constr.datalen; m++) {
10008                 int8_tArray arr_conv_12 = htlc_signatures_arg_vals[m];
10009                 LDKSignature arr_conv_12_ref;
10010                 CHECK(*((uint32_t*)arr_conv_12) == 64);
10011                 memcpy(arr_conv_12_ref.compact_form, (uint8_t*)(arr_conv_12 + 4), 64);
10012                 htlc_signatures_arg_constr.data[m] = arr_conv_12_ref;
10013         }
10014         LDKCommitmentSigned ret_var = CommitmentSigned_new(channel_id_arg_ref, signature_arg_ref, htlc_signatures_arg_constr);
10015         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10016         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10017         long ret_ref = (long)ret_var.inner;
10018         if (ret_var.is_owned) {
10019                 ret_ref |= 1;
10020         }
10021         return ret_ref;
10022 }
10023
10024 void TS_RevokeAndACK_free(uint32_t this_ptr) {
10025         LDKRevokeAndACK this_ptr_conv;
10026         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10027         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10028         RevokeAndACK_free(this_ptr_conv);
10029 }
10030
10031 uint32_t TS_RevokeAndACK_clone(uint32_t orig) {
10032         LDKRevokeAndACK orig_conv;
10033         orig_conv.inner = (void*)(orig & (~1));
10034         orig_conv.is_owned = false;
10035         LDKRevokeAndACK ret_var = RevokeAndACK_clone(&orig_conv);
10036         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10037         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10038         long ret_ref = (long)ret_var.inner;
10039         if (ret_var.is_owned) {
10040                 ret_ref |= 1;
10041         }
10042         return ret_ref;
10043 }
10044
10045 int8_tArray TS_RevokeAndACK_get_channel_id(uint32_t this_ptr) {
10046         LDKRevokeAndACK this_ptr_conv;
10047         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10048         this_ptr_conv.is_owned = false;
10049         int8_tArray ret_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
10050         memcpy((uint8_t*)(ret_arr + 4), *RevokeAndACK_get_channel_id(&this_ptr_conv), 32);
10051         return ret_arr;
10052 }
10053
10054 void TS_RevokeAndACK_set_channel_id(uint32_t this_ptr, int8_tArray val) {
10055         LDKRevokeAndACK this_ptr_conv;
10056         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10057         this_ptr_conv.is_owned = false;
10058         LDKThirtyTwoBytes val_ref;
10059         CHECK(*((uint32_t*)val) == 32);
10060         memcpy(val_ref.data, (uint8_t*)(val + 4), 32);
10061         RevokeAndACK_set_channel_id(&this_ptr_conv, val_ref);
10062 }
10063
10064 int8_tArray TS_RevokeAndACK_get_per_commitment_secret(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 = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
10069         memcpy((uint8_t*)(ret_arr + 4), *RevokeAndACK_get_per_commitment_secret(&this_ptr_conv), 32);
10070         return ret_arr;
10071 }
10072
10073 void TS_RevokeAndACK_set_per_commitment_secret(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(*((uint32_t*)val) == 32);
10079         memcpy(val_ref.data, (uint8_t*)(val + 4), 32);
10080         RevokeAndACK_set_per_commitment_secret(&this_ptr_conv, val_ref);
10081 }
10082
10083 int8_tArray TS_RevokeAndACK_get_next_per_commitment_point(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 arg_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
10088         memcpy((uint8_t*)(arg_arr + 4), RevokeAndACK_get_next_per_commitment_point(&this_ptr_conv).compressed_form, 33);
10089         return arg_arr;
10090 }
10091
10092 void TS_RevokeAndACK_set_next_per_commitment_point(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         LDKPublicKey val_ref;
10097         CHECK(*((uint32_t*)val) == 33);
10098         memcpy(val_ref.compressed_form, (uint8_t*)(val + 4), 33);
10099         RevokeAndACK_set_next_per_commitment_point(&this_ptr_conv, val_ref);
10100 }
10101
10102 uint32_t TS_RevokeAndACK_new(int8_tArray channel_id_arg, int8_tArray per_commitment_secret_arg, int8_tArray next_per_commitment_point_arg) {
10103         LDKThirtyTwoBytes channel_id_arg_ref;
10104         CHECK(*((uint32_t*)channel_id_arg) == 32);
10105         memcpy(channel_id_arg_ref.data, (uint8_t*)(channel_id_arg + 4), 32);
10106         LDKThirtyTwoBytes per_commitment_secret_arg_ref;
10107         CHECK(*((uint32_t*)per_commitment_secret_arg) == 32);
10108         memcpy(per_commitment_secret_arg_ref.data, (uint8_t*)(per_commitment_secret_arg + 4), 32);
10109         LDKPublicKey next_per_commitment_point_arg_ref;
10110         CHECK(*((uint32_t*)next_per_commitment_point_arg) == 33);
10111         memcpy(next_per_commitment_point_arg_ref.compressed_form, (uint8_t*)(next_per_commitment_point_arg + 4), 33);
10112         LDKRevokeAndACK ret_var = RevokeAndACK_new(channel_id_arg_ref, per_commitment_secret_arg_ref, next_per_commitment_point_arg_ref);
10113         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10114         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10115         long ret_ref = (long)ret_var.inner;
10116         if (ret_var.is_owned) {
10117                 ret_ref |= 1;
10118         }
10119         return ret_ref;
10120 }
10121
10122 void TS_UpdateFee_free(uint32_t this_ptr) {
10123         LDKUpdateFee this_ptr_conv;
10124         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10125         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10126         UpdateFee_free(this_ptr_conv);
10127 }
10128
10129 uint32_t TS_UpdateFee_clone(uint32_t orig) {
10130         LDKUpdateFee orig_conv;
10131         orig_conv.inner = (void*)(orig & (~1));
10132         orig_conv.is_owned = false;
10133         LDKUpdateFee ret_var = UpdateFee_clone(&orig_conv);
10134         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10135         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10136         long ret_ref = (long)ret_var.inner;
10137         if (ret_var.is_owned) {
10138                 ret_ref |= 1;
10139         }
10140         return ret_ref;
10141 }
10142
10143 int8_tArray TS_UpdateFee_get_channel_id(uint32_t this_ptr) {
10144         LDKUpdateFee this_ptr_conv;
10145         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10146         this_ptr_conv.is_owned = false;
10147         int8_tArray ret_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
10148         memcpy((uint8_t*)(ret_arr + 4), *UpdateFee_get_channel_id(&this_ptr_conv), 32);
10149         return ret_arr;
10150 }
10151
10152 void TS_UpdateFee_set_channel_id(uint32_t this_ptr, int8_tArray val) {
10153         LDKUpdateFee this_ptr_conv;
10154         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10155         this_ptr_conv.is_owned = false;
10156         LDKThirtyTwoBytes val_ref;
10157         CHECK(*((uint32_t*)val) == 32);
10158         memcpy(val_ref.data, (uint8_t*)(val + 4), 32);
10159         UpdateFee_set_channel_id(&this_ptr_conv, val_ref);
10160 }
10161
10162 int32_t TS_UpdateFee_get_feerate_per_kw(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         int32_t ret_val = UpdateFee_get_feerate_per_kw(&this_ptr_conv);
10167         return ret_val;
10168 }
10169
10170 void TS_UpdateFee_set_feerate_per_kw(uint32_t this_ptr, int32_t val) {
10171         LDKUpdateFee this_ptr_conv;
10172         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10173         this_ptr_conv.is_owned = false;
10174         UpdateFee_set_feerate_per_kw(&this_ptr_conv, val);
10175 }
10176
10177 uint32_t TS_UpdateFee_new(int8_tArray channel_id_arg, int32_t feerate_per_kw_arg) {
10178         LDKThirtyTwoBytes channel_id_arg_ref;
10179         CHECK(*((uint32_t*)channel_id_arg) == 32);
10180         memcpy(channel_id_arg_ref.data, (uint8_t*)(channel_id_arg + 4), 32);
10181         LDKUpdateFee ret_var = UpdateFee_new(channel_id_arg_ref, feerate_per_kw_arg);
10182         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10183         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10184         long ret_ref = (long)ret_var.inner;
10185         if (ret_var.is_owned) {
10186                 ret_ref |= 1;
10187         }
10188         return ret_ref;
10189 }
10190
10191 void TS_DataLossProtect_free(uint32_t this_ptr) {
10192         LDKDataLossProtect this_ptr_conv;
10193         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10194         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10195         DataLossProtect_free(this_ptr_conv);
10196 }
10197
10198 uint32_t TS_DataLossProtect_clone(uint32_t orig) {
10199         LDKDataLossProtect orig_conv;
10200         orig_conv.inner = (void*)(orig & (~1));
10201         orig_conv.is_owned = false;
10202         LDKDataLossProtect ret_var = DataLossProtect_clone(&orig_conv);
10203         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10204         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10205         long ret_ref = (long)ret_var.inner;
10206         if (ret_var.is_owned) {
10207                 ret_ref |= 1;
10208         }
10209         return ret_ref;
10210 }
10211
10212 int8_tArray TS_DataLossProtect_get_your_last_per_commitment_secret(uint32_t this_ptr) {
10213         LDKDataLossProtect this_ptr_conv;
10214         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10215         this_ptr_conv.is_owned = false;
10216         int8_tArray ret_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
10217         memcpy((uint8_t*)(ret_arr + 4), *DataLossProtect_get_your_last_per_commitment_secret(&this_ptr_conv), 32);
10218         return ret_arr;
10219 }
10220
10221 void TS_DataLossProtect_set_your_last_per_commitment_secret(uint32_t this_ptr, int8_tArray val) {
10222         LDKDataLossProtect this_ptr_conv;
10223         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10224         this_ptr_conv.is_owned = false;
10225         LDKThirtyTwoBytes val_ref;
10226         CHECK(*((uint32_t*)val) == 32);
10227         memcpy(val_ref.data, (uint8_t*)(val + 4), 32);
10228         DataLossProtect_set_your_last_per_commitment_secret(&this_ptr_conv, val_ref);
10229 }
10230
10231 int8_tArray TS_DataLossProtect_get_my_current_per_commitment_point(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 arg_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
10236         memcpy((uint8_t*)(arg_arr + 4), DataLossProtect_get_my_current_per_commitment_point(&this_ptr_conv).compressed_form, 33);
10237         return arg_arr;
10238 }
10239
10240 void TS_DataLossProtect_set_my_current_per_commitment_point(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         LDKPublicKey val_ref;
10245         CHECK(*((uint32_t*)val) == 33);
10246         memcpy(val_ref.compressed_form, (uint8_t*)(val + 4), 33);
10247         DataLossProtect_set_my_current_per_commitment_point(&this_ptr_conv, val_ref);
10248 }
10249
10250 uint32_t TS_DataLossProtect_new(int8_tArray your_last_per_commitment_secret_arg, int8_tArray my_current_per_commitment_point_arg) {
10251         LDKThirtyTwoBytes your_last_per_commitment_secret_arg_ref;
10252         CHECK(*((uint32_t*)your_last_per_commitment_secret_arg) == 32);
10253         memcpy(your_last_per_commitment_secret_arg_ref.data, (uint8_t*)(your_last_per_commitment_secret_arg + 4), 32);
10254         LDKPublicKey my_current_per_commitment_point_arg_ref;
10255         CHECK(*((uint32_t*)my_current_per_commitment_point_arg) == 33);
10256         memcpy(my_current_per_commitment_point_arg_ref.compressed_form, (uint8_t*)(my_current_per_commitment_point_arg + 4), 33);
10257         LDKDataLossProtect ret_var = DataLossProtect_new(your_last_per_commitment_secret_arg_ref, my_current_per_commitment_point_arg_ref);
10258         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10259         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10260         long ret_ref = (long)ret_var.inner;
10261         if (ret_var.is_owned) {
10262                 ret_ref |= 1;
10263         }
10264         return ret_ref;
10265 }
10266
10267 void TS_ChannelReestablish_free(uint32_t this_ptr) {
10268         LDKChannelReestablish this_ptr_conv;
10269         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10270         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10271         ChannelReestablish_free(this_ptr_conv);
10272 }
10273
10274 uint32_t TS_ChannelReestablish_clone(uint32_t orig) {
10275         LDKChannelReestablish orig_conv;
10276         orig_conv.inner = (void*)(orig & (~1));
10277         orig_conv.is_owned = false;
10278         LDKChannelReestablish ret_var = ChannelReestablish_clone(&orig_conv);
10279         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10280         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10281         long ret_ref = (long)ret_var.inner;
10282         if (ret_var.is_owned) {
10283                 ret_ref |= 1;
10284         }
10285         return ret_ref;
10286 }
10287
10288 int8_tArray TS_ChannelReestablish_get_channel_id(uint32_t this_ptr) {
10289         LDKChannelReestablish this_ptr_conv;
10290         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10291         this_ptr_conv.is_owned = false;
10292         int8_tArray ret_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
10293         memcpy((uint8_t*)(ret_arr + 4), *ChannelReestablish_get_channel_id(&this_ptr_conv), 32);
10294         return ret_arr;
10295 }
10296
10297 void TS_ChannelReestablish_set_channel_id(uint32_t this_ptr, int8_tArray val) {
10298         LDKChannelReestablish this_ptr_conv;
10299         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10300         this_ptr_conv.is_owned = false;
10301         LDKThirtyTwoBytes val_ref;
10302         CHECK(*((uint32_t*)val) == 32);
10303         memcpy(val_ref.data, (uint8_t*)(val + 4), 32);
10304         ChannelReestablish_set_channel_id(&this_ptr_conv, val_ref);
10305 }
10306
10307 int64_t TS_ChannelReestablish_get_next_local_commitment_number(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         int64_t ret_val = ChannelReestablish_get_next_local_commitment_number(&this_ptr_conv);
10312         return ret_val;
10313 }
10314
10315 void TS_ChannelReestablish_set_next_local_commitment_number(uint32_t this_ptr, int64_t val) {
10316         LDKChannelReestablish this_ptr_conv;
10317         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10318         this_ptr_conv.is_owned = false;
10319         ChannelReestablish_set_next_local_commitment_number(&this_ptr_conv, val);
10320 }
10321
10322 int64_t TS_ChannelReestablish_get_next_remote_commitment_number(uint32_t this_ptr) {
10323         LDKChannelReestablish this_ptr_conv;
10324         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10325         this_ptr_conv.is_owned = false;
10326         int64_t ret_val = ChannelReestablish_get_next_remote_commitment_number(&this_ptr_conv);
10327         return ret_val;
10328 }
10329
10330 void TS_ChannelReestablish_set_next_remote_commitment_number(uint32_t this_ptr, int64_t val) {
10331         LDKChannelReestablish this_ptr_conv;
10332         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10333         this_ptr_conv.is_owned = false;
10334         ChannelReestablish_set_next_remote_commitment_number(&this_ptr_conv, val);
10335 }
10336
10337 void TS_AnnouncementSignatures_free(uint32_t this_ptr) {
10338         LDKAnnouncementSignatures this_ptr_conv;
10339         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10340         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10341         AnnouncementSignatures_free(this_ptr_conv);
10342 }
10343
10344 uint32_t TS_AnnouncementSignatures_clone(uint32_t orig) {
10345         LDKAnnouncementSignatures orig_conv;
10346         orig_conv.inner = (void*)(orig & (~1));
10347         orig_conv.is_owned = false;
10348         LDKAnnouncementSignatures ret_var = AnnouncementSignatures_clone(&orig_conv);
10349         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10350         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10351         long ret_ref = (long)ret_var.inner;
10352         if (ret_var.is_owned) {
10353                 ret_ref |= 1;
10354         }
10355         return ret_ref;
10356 }
10357
10358 int8_tArray TS_AnnouncementSignatures_get_channel_id(uint32_t this_ptr) {
10359         LDKAnnouncementSignatures this_ptr_conv;
10360         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10361         this_ptr_conv.is_owned = false;
10362         int8_tArray ret_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
10363         memcpy((uint8_t*)(ret_arr + 4), *AnnouncementSignatures_get_channel_id(&this_ptr_conv), 32);
10364         return ret_arr;
10365 }
10366
10367 void TS_AnnouncementSignatures_set_channel_id(uint32_t this_ptr, int8_tArray val) {
10368         LDKAnnouncementSignatures this_ptr_conv;
10369         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10370         this_ptr_conv.is_owned = false;
10371         LDKThirtyTwoBytes val_ref;
10372         CHECK(*((uint32_t*)val) == 32);
10373         memcpy(val_ref.data, (uint8_t*)(val + 4), 32);
10374         AnnouncementSignatures_set_channel_id(&this_ptr_conv, val_ref);
10375 }
10376
10377 int64_t TS_AnnouncementSignatures_get_short_channel_id(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         int64_t ret_val = AnnouncementSignatures_get_short_channel_id(&this_ptr_conv);
10382         return ret_val;
10383 }
10384
10385 void TS_AnnouncementSignatures_set_short_channel_id(uint32_t this_ptr, int64_t val) {
10386         LDKAnnouncementSignatures this_ptr_conv;
10387         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10388         this_ptr_conv.is_owned = false;
10389         AnnouncementSignatures_set_short_channel_id(&this_ptr_conv, val);
10390 }
10391
10392 int8_tArray TS_AnnouncementSignatures_get_node_signature(uint32_t this_ptr) {
10393         LDKAnnouncementSignatures this_ptr_conv;
10394         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10395         this_ptr_conv.is_owned = false;
10396         int8_tArray arg_arr = init_arr(64, sizeof(uint8_t), "Native int8_tArray Bytes");
10397         memcpy((uint8_t*)(arg_arr + 4), AnnouncementSignatures_get_node_signature(&this_ptr_conv).compact_form, 64);
10398         return arg_arr;
10399 }
10400
10401 void TS_AnnouncementSignatures_set_node_signature(uint32_t this_ptr, int8_tArray val) {
10402         LDKAnnouncementSignatures this_ptr_conv;
10403         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10404         this_ptr_conv.is_owned = false;
10405         LDKSignature val_ref;
10406         CHECK(*((uint32_t*)val) == 64);
10407         memcpy(val_ref.compact_form, (uint8_t*)(val + 4), 64);
10408         AnnouncementSignatures_set_node_signature(&this_ptr_conv, val_ref);
10409 }
10410
10411 int8_tArray TS_AnnouncementSignatures_get_bitcoin_signature(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 = init_arr(64, sizeof(uint8_t), "Native int8_tArray Bytes");
10416         memcpy((uint8_t*)(arg_arr + 4), AnnouncementSignatures_get_bitcoin_signature(&this_ptr_conv).compact_form, 64);
10417         return arg_arr;
10418 }
10419
10420 void TS_AnnouncementSignatures_set_bitcoin_signature(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(*((uint32_t*)val) == 64);
10426         memcpy(val_ref.compact_form, (uint8_t*)(val + 4), 64);
10427         AnnouncementSignatures_set_bitcoin_signature(&this_ptr_conv, val_ref);
10428 }
10429
10430 uint32_t TS_AnnouncementSignatures_new(int8_tArray channel_id_arg, int64_t short_channel_id_arg, int8_tArray node_signature_arg, int8_tArray bitcoin_signature_arg) {
10431         LDKThirtyTwoBytes channel_id_arg_ref;
10432         CHECK(*((uint32_t*)channel_id_arg) == 32);
10433         memcpy(channel_id_arg_ref.data, (uint8_t*)(channel_id_arg + 4), 32);
10434         LDKSignature node_signature_arg_ref;
10435         CHECK(*((uint32_t*)node_signature_arg) == 64);
10436         memcpy(node_signature_arg_ref.compact_form, (uint8_t*)(node_signature_arg + 4), 64);
10437         LDKSignature bitcoin_signature_arg_ref;
10438         CHECK(*((uint32_t*)bitcoin_signature_arg) == 64);
10439         memcpy(bitcoin_signature_arg_ref.compact_form, (uint8_t*)(bitcoin_signature_arg + 4), 64);
10440         LDKAnnouncementSignatures ret_var = AnnouncementSignatures_new(channel_id_arg_ref, short_channel_id_arg, node_signature_arg_ref, bitcoin_signature_arg_ref);
10441         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10442         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10443         long ret_ref = (long)ret_var.inner;
10444         if (ret_var.is_owned) {
10445                 ret_ref |= 1;
10446         }
10447         return ret_ref;
10448 }
10449
10450 void TS_NetAddress_free(uint32_t this_ptr) {
10451         LDKNetAddress this_ptr_conv = *(LDKNetAddress*)this_ptr;
10452         FREE((void*)this_ptr);
10453         NetAddress_free(this_ptr_conv);
10454 }
10455
10456 uint32_t TS_NetAddress_clone(uint32_t orig) {
10457         LDKNetAddress* orig_conv = (LDKNetAddress*)orig;
10458         LDKNetAddress *ret_copy = MALLOC(sizeof(LDKNetAddress), "LDKNetAddress");
10459         *ret_copy = NetAddress_clone(orig_conv);
10460         long ret_ref = (long)ret_copy;
10461         return ret_ref;
10462 }
10463
10464 int8_tArray TS_NetAddress_write(uint32_t obj) {
10465         LDKNetAddress* obj_conv = (LDKNetAddress*)obj;
10466         LDKCVec_u8Z arg_var = NetAddress_write(obj_conv);
10467         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
10468         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
10469         CVec_u8Z_free(arg_var);
10470         return arg_arr;
10471 }
10472
10473 uint32_t TS_Result_read(int8_tArray ser) {
10474         LDKu8slice ser_ref;
10475         ser_ref.datalen = *((uint32_t*)ser);
10476         ser_ref.data = (int8_t*)(ser + 4);
10477         LDKCResult_CResult_NetAddressu8ZDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_CResult_NetAddressu8ZDecodeErrorZ), "LDKCResult_CResult_NetAddressu8ZDecodeErrorZ");
10478         *ret_conv = Result_read(ser_ref);
10479         return (long)ret_conv;
10480 }
10481
10482 void TS_UnsignedNodeAnnouncement_free(uint32_t this_ptr) {
10483         LDKUnsignedNodeAnnouncement this_ptr_conv;
10484         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10485         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10486         UnsignedNodeAnnouncement_free(this_ptr_conv);
10487 }
10488
10489 uint32_t TS_UnsignedNodeAnnouncement_clone(uint32_t orig) {
10490         LDKUnsignedNodeAnnouncement orig_conv;
10491         orig_conv.inner = (void*)(orig & (~1));
10492         orig_conv.is_owned = false;
10493         LDKUnsignedNodeAnnouncement ret_var = UnsignedNodeAnnouncement_clone(&orig_conv);
10494         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10495         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10496         long ret_ref = (long)ret_var.inner;
10497         if (ret_var.is_owned) {
10498                 ret_ref |= 1;
10499         }
10500         return ret_ref;
10501 }
10502
10503 uint32_t TS_UnsignedNodeAnnouncement_get_features(uint32_t this_ptr) {
10504         LDKUnsignedNodeAnnouncement this_ptr_conv;
10505         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10506         this_ptr_conv.is_owned = false;
10507         LDKNodeFeatures ret_var = UnsignedNodeAnnouncement_get_features(&this_ptr_conv);
10508         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10509         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10510         long ret_ref = (long)ret_var.inner;
10511         if (ret_var.is_owned) {
10512                 ret_ref |= 1;
10513         }
10514         return ret_ref;
10515 }
10516
10517 void TS_UnsignedNodeAnnouncement_set_features(uint32_t this_ptr, uint32_t val) {
10518         LDKUnsignedNodeAnnouncement this_ptr_conv;
10519         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10520         this_ptr_conv.is_owned = false;
10521         LDKNodeFeatures val_conv;
10522         val_conv.inner = (void*)(val & (~1));
10523         val_conv.is_owned = (val & 1) || (val == 0);
10524         // Warning: we may need a move here but can't clone!
10525         UnsignedNodeAnnouncement_set_features(&this_ptr_conv, val_conv);
10526 }
10527
10528 int32_t TS_UnsignedNodeAnnouncement_get_timestamp(uint32_t this_ptr) {
10529         LDKUnsignedNodeAnnouncement this_ptr_conv;
10530         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10531         this_ptr_conv.is_owned = false;
10532         int32_t ret_val = UnsignedNodeAnnouncement_get_timestamp(&this_ptr_conv);
10533         return ret_val;
10534 }
10535
10536 void TS_UnsignedNodeAnnouncement_set_timestamp(uint32_t this_ptr, int32_t val) {
10537         LDKUnsignedNodeAnnouncement this_ptr_conv;
10538         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10539         this_ptr_conv.is_owned = false;
10540         UnsignedNodeAnnouncement_set_timestamp(&this_ptr_conv, val);
10541 }
10542
10543 int8_tArray TS_UnsignedNodeAnnouncement_get_node_id(uint32_t this_ptr) {
10544         LDKUnsignedNodeAnnouncement this_ptr_conv;
10545         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10546         this_ptr_conv.is_owned = false;
10547         int8_tArray arg_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
10548         memcpy((uint8_t*)(arg_arr + 4), UnsignedNodeAnnouncement_get_node_id(&this_ptr_conv).compressed_form, 33);
10549         return arg_arr;
10550 }
10551
10552 void TS_UnsignedNodeAnnouncement_set_node_id(uint32_t this_ptr, int8_tArray val) {
10553         LDKUnsignedNodeAnnouncement this_ptr_conv;
10554         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10555         this_ptr_conv.is_owned = false;
10556         LDKPublicKey val_ref;
10557         CHECK(*((uint32_t*)val) == 33);
10558         memcpy(val_ref.compressed_form, (uint8_t*)(val + 4), 33);
10559         UnsignedNodeAnnouncement_set_node_id(&this_ptr_conv, val_ref);
10560 }
10561
10562 int8_tArray TS_UnsignedNodeAnnouncement_get_rgb(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 ret_arr = init_arr(3, sizeof(uint8_t), "Native int8_tArray Bytes");
10567         memcpy((uint8_t*)(ret_arr + 4), *UnsignedNodeAnnouncement_get_rgb(&this_ptr_conv), 3);
10568         return ret_arr;
10569 }
10570
10571 void TS_UnsignedNodeAnnouncement_set_rgb(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         LDKThreeBytes val_ref;
10576         CHECK(*((uint32_t*)val) == 3);
10577         memcpy(val_ref.data, (uint8_t*)(val + 4), 3);
10578         UnsignedNodeAnnouncement_set_rgb(&this_ptr_conv, val_ref);
10579 }
10580
10581 int8_tArray TS_UnsignedNodeAnnouncement_get_alias(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 = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
10586         memcpy((uint8_t*)(ret_arr + 4), *UnsignedNodeAnnouncement_get_alias(&this_ptr_conv), 32);
10587         return ret_arr;
10588 }
10589
10590 void TS_UnsignedNodeAnnouncement_set_alias(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         LDKThirtyTwoBytes val_ref;
10595         CHECK(*((uint32_t*)val) == 32);
10596         memcpy(val_ref.data, (uint8_t*)(val + 4), 32);
10597         UnsignedNodeAnnouncement_set_alias(&this_ptr_conv, val_ref);
10598 }
10599
10600 void TS_UnsignedNodeAnnouncement_set_addresses(uint32_t this_ptr, uint32_tArray val) {
10601         LDKUnsignedNodeAnnouncement this_ptr_conv;
10602         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10603         this_ptr_conv.is_owned = false;
10604         LDKCVec_NetAddressZ val_constr;
10605         val_constr.datalen = *((uint32_t*)val);
10606         if (val_constr.datalen > 0)
10607                 val_constr.data = MALLOC(val_constr.datalen * sizeof(LDKNetAddress), "LDKCVec_NetAddressZ Elements");
10608         else
10609                 val_constr.data = NULL;
10610         uint32_t* val_vals = (uint32_t*)(val + 4);
10611         for (size_t m = 0; m < val_constr.datalen; m++) {
10612                 uint32_t arr_conv_12 = val_vals[m];
10613                 LDKNetAddress arr_conv_12_conv = *(LDKNetAddress*)arr_conv_12;
10614                 FREE((void*)arr_conv_12);
10615                 val_constr.data[m] = arr_conv_12_conv;
10616         }
10617         UnsignedNodeAnnouncement_set_addresses(&this_ptr_conv, val_constr);
10618 }
10619
10620 void TS_NodeAnnouncement_free(uint32_t this_ptr) {
10621         LDKNodeAnnouncement this_ptr_conv;
10622         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10623         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10624         NodeAnnouncement_free(this_ptr_conv);
10625 }
10626
10627 uint32_t TS_NodeAnnouncement_clone(uint32_t orig) {
10628         LDKNodeAnnouncement orig_conv;
10629         orig_conv.inner = (void*)(orig & (~1));
10630         orig_conv.is_owned = false;
10631         LDKNodeAnnouncement ret_var = NodeAnnouncement_clone(&orig_conv);
10632         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10633         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10634         long ret_ref = (long)ret_var.inner;
10635         if (ret_var.is_owned) {
10636                 ret_ref |= 1;
10637         }
10638         return ret_ref;
10639 }
10640
10641 int8_tArray TS_NodeAnnouncement_get_signature(uint32_t this_ptr) {
10642         LDKNodeAnnouncement this_ptr_conv;
10643         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10644         this_ptr_conv.is_owned = false;
10645         int8_tArray arg_arr = init_arr(64, sizeof(uint8_t), "Native int8_tArray Bytes");
10646         memcpy((uint8_t*)(arg_arr + 4), NodeAnnouncement_get_signature(&this_ptr_conv).compact_form, 64);
10647         return arg_arr;
10648 }
10649
10650 void TS_NodeAnnouncement_set_signature(uint32_t this_ptr, int8_tArray val) {
10651         LDKNodeAnnouncement this_ptr_conv;
10652         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10653         this_ptr_conv.is_owned = false;
10654         LDKSignature val_ref;
10655         CHECK(*((uint32_t*)val) == 64);
10656         memcpy(val_ref.compact_form, (uint8_t*)(val + 4), 64);
10657         NodeAnnouncement_set_signature(&this_ptr_conv, val_ref);
10658 }
10659
10660 uint32_t TS_NodeAnnouncement_get_contents(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         LDKUnsignedNodeAnnouncement ret_var = NodeAnnouncement_get_contents(&this_ptr_conv);
10665         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10666         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10667         long ret_ref = (long)ret_var.inner;
10668         if (ret_var.is_owned) {
10669                 ret_ref |= 1;
10670         }
10671         return ret_ref;
10672 }
10673
10674 void TS_NodeAnnouncement_set_contents(uint32_t this_ptr, uint32_t val) {
10675         LDKNodeAnnouncement this_ptr_conv;
10676         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10677         this_ptr_conv.is_owned = false;
10678         LDKUnsignedNodeAnnouncement val_conv;
10679         val_conv.inner = (void*)(val & (~1));
10680         val_conv.is_owned = (val & 1) || (val == 0);
10681         if (val_conv.inner != NULL)
10682                 val_conv = UnsignedNodeAnnouncement_clone(&val_conv);
10683         NodeAnnouncement_set_contents(&this_ptr_conv, val_conv);
10684 }
10685
10686 uint32_t TS_NodeAnnouncement_new(int8_tArray signature_arg, uint32_t contents_arg) {
10687         LDKSignature signature_arg_ref;
10688         CHECK(*((uint32_t*)signature_arg) == 64);
10689         memcpy(signature_arg_ref.compact_form, (uint8_t*)(signature_arg + 4), 64);
10690         LDKUnsignedNodeAnnouncement contents_arg_conv;
10691         contents_arg_conv.inner = (void*)(contents_arg & (~1));
10692         contents_arg_conv.is_owned = (contents_arg & 1) || (contents_arg == 0);
10693         if (contents_arg_conv.inner != NULL)
10694                 contents_arg_conv = UnsignedNodeAnnouncement_clone(&contents_arg_conv);
10695         LDKNodeAnnouncement ret_var = NodeAnnouncement_new(signature_arg_ref, contents_arg_conv);
10696         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10697         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10698         long ret_ref = (long)ret_var.inner;
10699         if (ret_var.is_owned) {
10700                 ret_ref |= 1;
10701         }
10702         return ret_ref;
10703 }
10704
10705 void TS_UnsignedChannelAnnouncement_free(uint32_t this_ptr) {
10706         LDKUnsignedChannelAnnouncement this_ptr_conv;
10707         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10708         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10709         UnsignedChannelAnnouncement_free(this_ptr_conv);
10710 }
10711
10712 uint32_t TS_UnsignedChannelAnnouncement_clone(uint32_t orig) {
10713         LDKUnsignedChannelAnnouncement orig_conv;
10714         orig_conv.inner = (void*)(orig & (~1));
10715         orig_conv.is_owned = false;
10716         LDKUnsignedChannelAnnouncement ret_var = UnsignedChannelAnnouncement_clone(&orig_conv);
10717         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10718         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10719         long ret_ref = (long)ret_var.inner;
10720         if (ret_var.is_owned) {
10721                 ret_ref |= 1;
10722         }
10723         return ret_ref;
10724 }
10725
10726 uint32_t TS_UnsignedChannelAnnouncement_get_features(uint32_t this_ptr) {
10727         LDKUnsignedChannelAnnouncement this_ptr_conv;
10728         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10729         this_ptr_conv.is_owned = false;
10730         LDKChannelFeatures ret_var = UnsignedChannelAnnouncement_get_features(&this_ptr_conv);
10731         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10732         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10733         long ret_ref = (long)ret_var.inner;
10734         if (ret_var.is_owned) {
10735                 ret_ref |= 1;
10736         }
10737         return ret_ref;
10738 }
10739
10740 void TS_UnsignedChannelAnnouncement_set_features(uint32_t this_ptr, uint32_t val) {
10741         LDKUnsignedChannelAnnouncement this_ptr_conv;
10742         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10743         this_ptr_conv.is_owned = false;
10744         LDKChannelFeatures val_conv;
10745         val_conv.inner = (void*)(val & (~1));
10746         val_conv.is_owned = (val & 1) || (val == 0);
10747         // Warning: we may need a move here but can't clone!
10748         UnsignedChannelAnnouncement_set_features(&this_ptr_conv, val_conv);
10749 }
10750
10751 int8_tArray TS_UnsignedChannelAnnouncement_get_chain_hash(uint32_t this_ptr) {
10752         LDKUnsignedChannelAnnouncement this_ptr_conv;
10753         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10754         this_ptr_conv.is_owned = false;
10755         int8_tArray ret_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
10756         memcpy((uint8_t*)(ret_arr + 4), *UnsignedChannelAnnouncement_get_chain_hash(&this_ptr_conv), 32);
10757         return ret_arr;
10758 }
10759
10760 void TS_UnsignedChannelAnnouncement_set_chain_hash(uint32_t this_ptr, int8_tArray val) {
10761         LDKUnsignedChannelAnnouncement this_ptr_conv;
10762         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10763         this_ptr_conv.is_owned = false;
10764         LDKThirtyTwoBytes val_ref;
10765         CHECK(*((uint32_t*)val) == 32);
10766         memcpy(val_ref.data, (uint8_t*)(val + 4), 32);
10767         UnsignedChannelAnnouncement_set_chain_hash(&this_ptr_conv, val_ref);
10768 }
10769
10770 int64_t TS_UnsignedChannelAnnouncement_get_short_channel_id(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         int64_t ret_val = UnsignedChannelAnnouncement_get_short_channel_id(&this_ptr_conv);
10775         return ret_val;
10776 }
10777
10778 void TS_UnsignedChannelAnnouncement_set_short_channel_id(uint32_t this_ptr, int64_t val) {
10779         LDKUnsignedChannelAnnouncement this_ptr_conv;
10780         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10781         this_ptr_conv.is_owned = false;
10782         UnsignedChannelAnnouncement_set_short_channel_id(&this_ptr_conv, val);
10783 }
10784
10785 int8_tArray TS_UnsignedChannelAnnouncement_get_node_id_1(uint32_t this_ptr) {
10786         LDKUnsignedChannelAnnouncement this_ptr_conv;
10787         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10788         this_ptr_conv.is_owned = false;
10789         int8_tArray arg_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
10790         memcpy((uint8_t*)(arg_arr + 4), UnsignedChannelAnnouncement_get_node_id_1(&this_ptr_conv).compressed_form, 33);
10791         return arg_arr;
10792 }
10793
10794 void TS_UnsignedChannelAnnouncement_set_node_id_1(uint32_t this_ptr, int8_tArray val) {
10795         LDKUnsignedChannelAnnouncement this_ptr_conv;
10796         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10797         this_ptr_conv.is_owned = false;
10798         LDKPublicKey val_ref;
10799         CHECK(*((uint32_t*)val) == 33);
10800         memcpy(val_ref.compressed_form, (uint8_t*)(val + 4), 33);
10801         UnsignedChannelAnnouncement_set_node_id_1(&this_ptr_conv, val_ref);
10802 }
10803
10804 int8_tArray TS_UnsignedChannelAnnouncement_get_node_id_2(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 = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
10809         memcpy((uint8_t*)(arg_arr + 4), UnsignedChannelAnnouncement_get_node_id_2(&this_ptr_conv).compressed_form, 33);
10810         return arg_arr;
10811 }
10812
10813 void TS_UnsignedChannelAnnouncement_set_node_id_2(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(*((uint32_t*)val) == 33);
10819         memcpy(val_ref.compressed_form, (uint8_t*)(val + 4), 33);
10820         UnsignedChannelAnnouncement_set_node_id_2(&this_ptr_conv, val_ref);
10821 }
10822
10823 int8_tArray TS_UnsignedChannelAnnouncement_get_bitcoin_key_1(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 = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
10828         memcpy((uint8_t*)(arg_arr + 4), UnsignedChannelAnnouncement_get_bitcoin_key_1(&this_ptr_conv).compressed_form, 33);
10829         return arg_arr;
10830 }
10831
10832 void TS_UnsignedChannelAnnouncement_set_bitcoin_key_1(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(*((uint32_t*)val) == 33);
10838         memcpy(val_ref.compressed_form, (uint8_t*)(val + 4), 33);
10839         UnsignedChannelAnnouncement_set_bitcoin_key_1(&this_ptr_conv, val_ref);
10840 }
10841
10842 int8_tArray TS_UnsignedChannelAnnouncement_get_bitcoin_key_2(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 = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
10847         memcpy((uint8_t*)(arg_arr + 4), UnsignedChannelAnnouncement_get_bitcoin_key_2(&this_ptr_conv).compressed_form, 33);
10848         return arg_arr;
10849 }
10850
10851 void TS_UnsignedChannelAnnouncement_set_bitcoin_key_2(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(*((uint32_t*)val) == 33);
10857         memcpy(val_ref.compressed_form, (uint8_t*)(val + 4), 33);
10858         UnsignedChannelAnnouncement_set_bitcoin_key_2(&this_ptr_conv, val_ref);
10859 }
10860
10861 void TS_ChannelAnnouncement_free(uint32_t this_ptr) {
10862         LDKChannelAnnouncement this_ptr_conv;
10863         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10864         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10865         ChannelAnnouncement_free(this_ptr_conv);
10866 }
10867
10868 uint32_t TS_ChannelAnnouncement_clone(uint32_t orig) {
10869         LDKChannelAnnouncement orig_conv;
10870         orig_conv.inner = (void*)(orig & (~1));
10871         orig_conv.is_owned = false;
10872         LDKChannelAnnouncement ret_var = ChannelAnnouncement_clone(&orig_conv);
10873         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10874         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10875         long ret_ref = (long)ret_var.inner;
10876         if (ret_var.is_owned) {
10877                 ret_ref |= 1;
10878         }
10879         return ret_ref;
10880 }
10881
10882 int8_tArray TS_ChannelAnnouncement_get_node_signature_1(uint32_t this_ptr) {
10883         LDKChannelAnnouncement this_ptr_conv;
10884         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10885         this_ptr_conv.is_owned = false;
10886         int8_tArray arg_arr = init_arr(64, sizeof(uint8_t), "Native int8_tArray Bytes");
10887         memcpy((uint8_t*)(arg_arr + 4), ChannelAnnouncement_get_node_signature_1(&this_ptr_conv).compact_form, 64);
10888         return arg_arr;
10889 }
10890
10891 void TS_ChannelAnnouncement_set_node_signature_1(uint32_t this_ptr, int8_tArray val) {
10892         LDKChannelAnnouncement this_ptr_conv;
10893         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10894         this_ptr_conv.is_owned = false;
10895         LDKSignature val_ref;
10896         CHECK(*((uint32_t*)val) == 64);
10897         memcpy(val_ref.compact_form, (uint8_t*)(val + 4), 64);
10898         ChannelAnnouncement_set_node_signature_1(&this_ptr_conv, val_ref);
10899 }
10900
10901 int8_tArray TS_ChannelAnnouncement_get_node_signature_2(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 = init_arr(64, sizeof(uint8_t), "Native int8_tArray Bytes");
10906         memcpy((uint8_t*)(arg_arr + 4), ChannelAnnouncement_get_node_signature_2(&this_ptr_conv).compact_form, 64);
10907         return arg_arr;
10908 }
10909
10910 void TS_ChannelAnnouncement_set_node_signature_2(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(*((uint32_t*)val) == 64);
10916         memcpy(val_ref.compact_form, (uint8_t*)(val + 4), 64);
10917         ChannelAnnouncement_set_node_signature_2(&this_ptr_conv, val_ref);
10918 }
10919
10920 int8_tArray TS_ChannelAnnouncement_get_bitcoin_signature_1(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 = init_arr(64, sizeof(uint8_t), "Native int8_tArray Bytes");
10925         memcpy((uint8_t*)(arg_arr + 4), ChannelAnnouncement_get_bitcoin_signature_1(&this_ptr_conv).compact_form, 64);
10926         return arg_arr;
10927 }
10928
10929 void TS_ChannelAnnouncement_set_bitcoin_signature_1(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(*((uint32_t*)val) == 64);
10935         memcpy(val_ref.compact_form, (uint8_t*)(val + 4), 64);
10936         ChannelAnnouncement_set_bitcoin_signature_1(&this_ptr_conv, val_ref);
10937 }
10938
10939 int8_tArray TS_ChannelAnnouncement_get_bitcoin_signature_2(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 = init_arr(64, sizeof(uint8_t), "Native int8_tArray Bytes");
10944         memcpy((uint8_t*)(arg_arr + 4), ChannelAnnouncement_get_bitcoin_signature_2(&this_ptr_conv).compact_form, 64);
10945         return arg_arr;
10946 }
10947
10948 void TS_ChannelAnnouncement_set_bitcoin_signature_2(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(*((uint32_t*)val) == 64);
10954         memcpy(val_ref.compact_form, (uint8_t*)(val + 4), 64);
10955         ChannelAnnouncement_set_bitcoin_signature_2(&this_ptr_conv, val_ref);
10956 }
10957
10958 uint32_t TS_ChannelAnnouncement_get_contents(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         LDKUnsignedChannelAnnouncement ret_var = ChannelAnnouncement_get_contents(&this_ptr_conv);
10963         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10964         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10965         long ret_ref = (long)ret_var.inner;
10966         if (ret_var.is_owned) {
10967                 ret_ref |= 1;
10968         }
10969         return ret_ref;
10970 }
10971
10972 void TS_ChannelAnnouncement_set_contents(uint32_t this_ptr, uint32_t val) {
10973         LDKChannelAnnouncement this_ptr_conv;
10974         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10975         this_ptr_conv.is_owned = false;
10976         LDKUnsignedChannelAnnouncement val_conv;
10977         val_conv.inner = (void*)(val & (~1));
10978         val_conv.is_owned = (val & 1) || (val == 0);
10979         if (val_conv.inner != NULL)
10980                 val_conv = UnsignedChannelAnnouncement_clone(&val_conv);
10981         ChannelAnnouncement_set_contents(&this_ptr_conv, val_conv);
10982 }
10983
10984 uint32_t TS_ChannelAnnouncement_new(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) {
10985         LDKSignature node_signature_1_arg_ref;
10986         CHECK(*((uint32_t*)node_signature_1_arg) == 64);
10987         memcpy(node_signature_1_arg_ref.compact_form, (uint8_t*)(node_signature_1_arg + 4), 64);
10988         LDKSignature node_signature_2_arg_ref;
10989         CHECK(*((uint32_t*)node_signature_2_arg) == 64);
10990         memcpy(node_signature_2_arg_ref.compact_form, (uint8_t*)(node_signature_2_arg + 4), 64);
10991         LDKSignature bitcoin_signature_1_arg_ref;
10992         CHECK(*((uint32_t*)bitcoin_signature_1_arg) == 64);
10993         memcpy(bitcoin_signature_1_arg_ref.compact_form, (uint8_t*)(bitcoin_signature_1_arg + 4), 64);
10994         LDKSignature bitcoin_signature_2_arg_ref;
10995         CHECK(*((uint32_t*)bitcoin_signature_2_arg) == 64);
10996         memcpy(bitcoin_signature_2_arg_ref.compact_form, (uint8_t*)(bitcoin_signature_2_arg + 4), 64);
10997         LDKUnsignedChannelAnnouncement contents_arg_conv;
10998         contents_arg_conv.inner = (void*)(contents_arg & (~1));
10999         contents_arg_conv.is_owned = (contents_arg & 1) || (contents_arg == 0);
11000         if (contents_arg_conv.inner != NULL)
11001                 contents_arg_conv = UnsignedChannelAnnouncement_clone(&contents_arg_conv);
11002         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);
11003         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11004         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11005         long ret_ref = (long)ret_var.inner;
11006         if (ret_var.is_owned) {
11007                 ret_ref |= 1;
11008         }
11009         return ret_ref;
11010 }
11011
11012 void TS_UnsignedChannelUpdate_free(uint32_t this_ptr) {
11013         LDKUnsignedChannelUpdate this_ptr_conv;
11014         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11015         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
11016         UnsignedChannelUpdate_free(this_ptr_conv);
11017 }
11018
11019 uint32_t TS_UnsignedChannelUpdate_clone(uint32_t orig) {
11020         LDKUnsignedChannelUpdate orig_conv;
11021         orig_conv.inner = (void*)(orig & (~1));
11022         orig_conv.is_owned = false;
11023         LDKUnsignedChannelUpdate ret_var = UnsignedChannelUpdate_clone(&orig_conv);
11024         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11025         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11026         long ret_ref = (long)ret_var.inner;
11027         if (ret_var.is_owned) {
11028                 ret_ref |= 1;
11029         }
11030         return ret_ref;
11031 }
11032
11033 int8_tArray TS_UnsignedChannelUpdate_get_chain_hash(uint32_t this_ptr) {
11034         LDKUnsignedChannelUpdate this_ptr_conv;
11035         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11036         this_ptr_conv.is_owned = false;
11037         int8_tArray ret_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
11038         memcpy((uint8_t*)(ret_arr + 4), *UnsignedChannelUpdate_get_chain_hash(&this_ptr_conv), 32);
11039         return ret_arr;
11040 }
11041
11042 void TS_UnsignedChannelUpdate_set_chain_hash(uint32_t this_ptr, int8_tArray val) {
11043         LDKUnsignedChannelUpdate this_ptr_conv;
11044         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11045         this_ptr_conv.is_owned = false;
11046         LDKThirtyTwoBytes val_ref;
11047         CHECK(*((uint32_t*)val) == 32);
11048         memcpy(val_ref.data, (uint8_t*)(val + 4), 32);
11049         UnsignedChannelUpdate_set_chain_hash(&this_ptr_conv, val_ref);
11050 }
11051
11052 int64_t TS_UnsignedChannelUpdate_get_short_channel_id(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         int64_t ret_val = UnsignedChannelUpdate_get_short_channel_id(&this_ptr_conv);
11057         return ret_val;
11058 }
11059
11060 void TS_UnsignedChannelUpdate_set_short_channel_id(uint32_t this_ptr, int64_t val) {
11061         LDKUnsignedChannelUpdate this_ptr_conv;
11062         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11063         this_ptr_conv.is_owned = false;
11064         UnsignedChannelUpdate_set_short_channel_id(&this_ptr_conv, val);
11065 }
11066
11067 int32_t TS_UnsignedChannelUpdate_get_timestamp(uint32_t this_ptr) {
11068         LDKUnsignedChannelUpdate this_ptr_conv;
11069         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11070         this_ptr_conv.is_owned = false;
11071         int32_t ret_val = UnsignedChannelUpdate_get_timestamp(&this_ptr_conv);
11072         return ret_val;
11073 }
11074
11075 void TS_UnsignedChannelUpdate_set_timestamp(uint32_t this_ptr, int32_t val) {
11076         LDKUnsignedChannelUpdate this_ptr_conv;
11077         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11078         this_ptr_conv.is_owned = false;
11079         UnsignedChannelUpdate_set_timestamp(&this_ptr_conv, val);
11080 }
11081
11082 int8_t TS_UnsignedChannelUpdate_get_flags(uint32_t this_ptr) {
11083         LDKUnsignedChannelUpdate this_ptr_conv;
11084         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11085         this_ptr_conv.is_owned = false;
11086         int8_t ret_val = UnsignedChannelUpdate_get_flags(&this_ptr_conv);
11087         return ret_val;
11088 }
11089
11090 void TS_UnsignedChannelUpdate_set_flags(uint32_t this_ptr, int8_t val) {
11091         LDKUnsignedChannelUpdate this_ptr_conv;
11092         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11093         this_ptr_conv.is_owned = false;
11094         UnsignedChannelUpdate_set_flags(&this_ptr_conv, val);
11095 }
11096
11097 int16_t TS_UnsignedChannelUpdate_get_cltv_expiry_delta(uint32_t this_ptr) {
11098         LDKUnsignedChannelUpdate this_ptr_conv;
11099         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11100         this_ptr_conv.is_owned = false;
11101         int16_t ret_val = UnsignedChannelUpdate_get_cltv_expiry_delta(&this_ptr_conv);
11102         return ret_val;
11103 }
11104
11105 void TS_UnsignedChannelUpdate_set_cltv_expiry_delta(uint32_t this_ptr, int16_t val) {
11106         LDKUnsignedChannelUpdate this_ptr_conv;
11107         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11108         this_ptr_conv.is_owned = false;
11109         UnsignedChannelUpdate_set_cltv_expiry_delta(&this_ptr_conv, val);
11110 }
11111
11112 int64_t TS_UnsignedChannelUpdate_get_htlc_minimum_msat(uint32_t this_ptr) {
11113         LDKUnsignedChannelUpdate this_ptr_conv;
11114         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11115         this_ptr_conv.is_owned = false;
11116         int64_t ret_val = UnsignedChannelUpdate_get_htlc_minimum_msat(&this_ptr_conv);
11117         return ret_val;
11118 }
11119
11120 void TS_UnsignedChannelUpdate_set_htlc_minimum_msat(uint32_t this_ptr, int64_t val) {
11121         LDKUnsignedChannelUpdate this_ptr_conv;
11122         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11123         this_ptr_conv.is_owned = false;
11124         UnsignedChannelUpdate_set_htlc_minimum_msat(&this_ptr_conv, val);
11125 }
11126
11127 int32_t TS_UnsignedChannelUpdate_get_fee_base_msat(uint32_t this_ptr) {
11128         LDKUnsignedChannelUpdate this_ptr_conv;
11129         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11130         this_ptr_conv.is_owned = false;
11131         int32_t ret_val = UnsignedChannelUpdate_get_fee_base_msat(&this_ptr_conv);
11132         return ret_val;
11133 }
11134
11135 void TS_UnsignedChannelUpdate_set_fee_base_msat(uint32_t this_ptr, int32_t val) {
11136         LDKUnsignedChannelUpdate this_ptr_conv;
11137         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11138         this_ptr_conv.is_owned = false;
11139         UnsignedChannelUpdate_set_fee_base_msat(&this_ptr_conv, val);
11140 }
11141
11142 int32_t TS_UnsignedChannelUpdate_get_fee_proportional_millionths(uint32_t this_ptr) {
11143         LDKUnsignedChannelUpdate this_ptr_conv;
11144         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11145         this_ptr_conv.is_owned = false;
11146         int32_t ret_val = UnsignedChannelUpdate_get_fee_proportional_millionths(&this_ptr_conv);
11147         return ret_val;
11148 }
11149
11150 void TS_UnsignedChannelUpdate_set_fee_proportional_millionths(uint32_t this_ptr, int32_t val) {
11151         LDKUnsignedChannelUpdate this_ptr_conv;
11152         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11153         this_ptr_conv.is_owned = false;
11154         UnsignedChannelUpdate_set_fee_proportional_millionths(&this_ptr_conv, val);
11155 }
11156
11157 void TS_ChannelUpdate_free(uint32_t this_ptr) {
11158         LDKChannelUpdate this_ptr_conv;
11159         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11160         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
11161         ChannelUpdate_free(this_ptr_conv);
11162 }
11163
11164 uint32_t TS_ChannelUpdate_clone(uint32_t orig) {
11165         LDKChannelUpdate orig_conv;
11166         orig_conv.inner = (void*)(orig & (~1));
11167         orig_conv.is_owned = false;
11168         LDKChannelUpdate ret_var = ChannelUpdate_clone(&orig_conv);
11169         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11170         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11171         long ret_ref = (long)ret_var.inner;
11172         if (ret_var.is_owned) {
11173                 ret_ref |= 1;
11174         }
11175         return ret_ref;
11176 }
11177
11178 int8_tArray TS_ChannelUpdate_get_signature(uint32_t this_ptr) {
11179         LDKChannelUpdate this_ptr_conv;
11180         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11181         this_ptr_conv.is_owned = false;
11182         int8_tArray arg_arr = init_arr(64, sizeof(uint8_t), "Native int8_tArray Bytes");
11183         memcpy((uint8_t*)(arg_arr + 4), ChannelUpdate_get_signature(&this_ptr_conv).compact_form, 64);
11184         return arg_arr;
11185 }
11186
11187 void TS_ChannelUpdate_set_signature(uint32_t this_ptr, int8_tArray val) {
11188         LDKChannelUpdate this_ptr_conv;
11189         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11190         this_ptr_conv.is_owned = false;
11191         LDKSignature val_ref;
11192         CHECK(*((uint32_t*)val) == 64);
11193         memcpy(val_ref.compact_form, (uint8_t*)(val + 4), 64);
11194         ChannelUpdate_set_signature(&this_ptr_conv, val_ref);
11195 }
11196
11197 uint32_t TS_ChannelUpdate_get_contents(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         LDKUnsignedChannelUpdate ret_var = ChannelUpdate_get_contents(&this_ptr_conv);
11202         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11203         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11204         long ret_ref = (long)ret_var.inner;
11205         if (ret_var.is_owned) {
11206                 ret_ref |= 1;
11207         }
11208         return ret_ref;
11209 }
11210
11211 void TS_ChannelUpdate_set_contents(uint32_t this_ptr, uint32_t val) {
11212         LDKChannelUpdate this_ptr_conv;
11213         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11214         this_ptr_conv.is_owned = false;
11215         LDKUnsignedChannelUpdate val_conv;
11216         val_conv.inner = (void*)(val & (~1));
11217         val_conv.is_owned = (val & 1) || (val == 0);
11218         if (val_conv.inner != NULL)
11219                 val_conv = UnsignedChannelUpdate_clone(&val_conv);
11220         ChannelUpdate_set_contents(&this_ptr_conv, val_conv);
11221 }
11222
11223 uint32_t TS_ChannelUpdate_new(int8_tArray signature_arg, uint32_t contents_arg) {
11224         LDKSignature signature_arg_ref;
11225         CHECK(*((uint32_t*)signature_arg) == 64);
11226         memcpy(signature_arg_ref.compact_form, (uint8_t*)(signature_arg + 4), 64);
11227         LDKUnsignedChannelUpdate contents_arg_conv;
11228         contents_arg_conv.inner = (void*)(contents_arg & (~1));
11229         contents_arg_conv.is_owned = (contents_arg & 1) || (contents_arg == 0);
11230         if (contents_arg_conv.inner != NULL)
11231                 contents_arg_conv = UnsignedChannelUpdate_clone(&contents_arg_conv);
11232         LDKChannelUpdate ret_var = ChannelUpdate_new(signature_arg_ref, contents_arg_conv);
11233         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11234         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11235         long ret_ref = (long)ret_var.inner;
11236         if (ret_var.is_owned) {
11237                 ret_ref |= 1;
11238         }
11239         return ret_ref;
11240 }
11241
11242 void TS_QueryChannelRange_free(uint32_t this_ptr) {
11243         LDKQueryChannelRange this_ptr_conv;
11244         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11245         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
11246         QueryChannelRange_free(this_ptr_conv);
11247 }
11248
11249 uint32_t TS_QueryChannelRange_clone(uint32_t orig) {
11250         LDKQueryChannelRange orig_conv;
11251         orig_conv.inner = (void*)(orig & (~1));
11252         orig_conv.is_owned = false;
11253         LDKQueryChannelRange ret_var = QueryChannelRange_clone(&orig_conv);
11254         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11255         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11256         long ret_ref = (long)ret_var.inner;
11257         if (ret_var.is_owned) {
11258                 ret_ref |= 1;
11259         }
11260         return ret_ref;
11261 }
11262
11263 int8_tArray TS_QueryChannelRange_get_chain_hash(uint32_t this_ptr) {
11264         LDKQueryChannelRange this_ptr_conv;
11265         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11266         this_ptr_conv.is_owned = false;
11267         int8_tArray ret_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
11268         memcpy((uint8_t*)(ret_arr + 4), *QueryChannelRange_get_chain_hash(&this_ptr_conv), 32);
11269         return ret_arr;
11270 }
11271
11272 void TS_QueryChannelRange_set_chain_hash(uint32_t this_ptr, int8_tArray val) {
11273         LDKQueryChannelRange this_ptr_conv;
11274         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11275         this_ptr_conv.is_owned = false;
11276         LDKThirtyTwoBytes val_ref;
11277         CHECK(*((uint32_t*)val) == 32);
11278         memcpy(val_ref.data, (uint8_t*)(val + 4), 32);
11279         QueryChannelRange_set_chain_hash(&this_ptr_conv, val_ref);
11280 }
11281
11282 int32_t TS_QueryChannelRange_get_first_blocknum(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         int32_t ret_val = QueryChannelRange_get_first_blocknum(&this_ptr_conv);
11287         return ret_val;
11288 }
11289
11290 void TS_QueryChannelRange_set_first_blocknum(uint32_t this_ptr, int32_t val) {
11291         LDKQueryChannelRange this_ptr_conv;
11292         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11293         this_ptr_conv.is_owned = false;
11294         QueryChannelRange_set_first_blocknum(&this_ptr_conv, val);
11295 }
11296
11297 int32_t TS_QueryChannelRange_get_number_of_blocks(uint32_t this_ptr) {
11298         LDKQueryChannelRange this_ptr_conv;
11299         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11300         this_ptr_conv.is_owned = false;
11301         int32_t ret_val = QueryChannelRange_get_number_of_blocks(&this_ptr_conv);
11302         return ret_val;
11303 }
11304
11305 void TS_QueryChannelRange_set_number_of_blocks(uint32_t this_ptr, int32_t val) {
11306         LDKQueryChannelRange this_ptr_conv;
11307         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11308         this_ptr_conv.is_owned = false;
11309         QueryChannelRange_set_number_of_blocks(&this_ptr_conv, val);
11310 }
11311
11312 uint32_t TS_QueryChannelRange_new(int8_tArray chain_hash_arg, int32_t first_blocknum_arg, int32_t number_of_blocks_arg) {
11313         LDKThirtyTwoBytes chain_hash_arg_ref;
11314         CHECK(*((uint32_t*)chain_hash_arg) == 32);
11315         memcpy(chain_hash_arg_ref.data, (uint8_t*)(chain_hash_arg + 4), 32);
11316         LDKQueryChannelRange ret_var = QueryChannelRange_new(chain_hash_arg_ref, first_blocknum_arg, number_of_blocks_arg);
11317         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11318         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11319         long ret_ref = (long)ret_var.inner;
11320         if (ret_var.is_owned) {
11321                 ret_ref |= 1;
11322         }
11323         return ret_ref;
11324 }
11325
11326 void TS_ReplyChannelRange_free(uint32_t this_ptr) {
11327         LDKReplyChannelRange this_ptr_conv;
11328         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11329         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
11330         ReplyChannelRange_free(this_ptr_conv);
11331 }
11332
11333 uint32_t TS_ReplyChannelRange_clone(uint32_t orig) {
11334         LDKReplyChannelRange orig_conv;
11335         orig_conv.inner = (void*)(orig & (~1));
11336         orig_conv.is_owned = false;
11337         LDKReplyChannelRange ret_var = ReplyChannelRange_clone(&orig_conv);
11338         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11339         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11340         long ret_ref = (long)ret_var.inner;
11341         if (ret_var.is_owned) {
11342                 ret_ref |= 1;
11343         }
11344         return ret_ref;
11345 }
11346
11347 int8_tArray TS_ReplyChannelRange_get_chain_hash(uint32_t this_ptr) {
11348         LDKReplyChannelRange this_ptr_conv;
11349         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11350         this_ptr_conv.is_owned = false;
11351         int8_tArray ret_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
11352         memcpy((uint8_t*)(ret_arr + 4), *ReplyChannelRange_get_chain_hash(&this_ptr_conv), 32);
11353         return ret_arr;
11354 }
11355
11356 void TS_ReplyChannelRange_set_chain_hash(uint32_t this_ptr, int8_tArray val) {
11357         LDKReplyChannelRange this_ptr_conv;
11358         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11359         this_ptr_conv.is_owned = false;
11360         LDKThirtyTwoBytes val_ref;
11361         CHECK(*((uint32_t*)val) == 32);
11362         memcpy(val_ref.data, (uint8_t*)(val + 4), 32);
11363         ReplyChannelRange_set_chain_hash(&this_ptr_conv, val_ref);
11364 }
11365
11366 int32_t TS_ReplyChannelRange_get_first_blocknum(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         int32_t ret_val = ReplyChannelRange_get_first_blocknum(&this_ptr_conv);
11371         return ret_val;
11372 }
11373
11374 void TS_ReplyChannelRange_set_first_blocknum(uint32_t this_ptr, int32_t val) {
11375         LDKReplyChannelRange this_ptr_conv;
11376         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11377         this_ptr_conv.is_owned = false;
11378         ReplyChannelRange_set_first_blocknum(&this_ptr_conv, val);
11379 }
11380
11381 int32_t TS_ReplyChannelRange_get_number_of_blocks(uint32_t this_ptr) {
11382         LDKReplyChannelRange this_ptr_conv;
11383         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11384         this_ptr_conv.is_owned = false;
11385         int32_t ret_val = ReplyChannelRange_get_number_of_blocks(&this_ptr_conv);
11386         return ret_val;
11387 }
11388
11389 void TS_ReplyChannelRange_set_number_of_blocks(uint32_t this_ptr, int32_t val) {
11390         LDKReplyChannelRange this_ptr_conv;
11391         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11392         this_ptr_conv.is_owned = false;
11393         ReplyChannelRange_set_number_of_blocks(&this_ptr_conv, val);
11394 }
11395
11396 jboolean TS_ReplyChannelRange_get_full_information(uint32_t this_ptr) {
11397         LDKReplyChannelRange this_ptr_conv;
11398         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11399         this_ptr_conv.is_owned = false;
11400         jboolean ret_val = ReplyChannelRange_get_full_information(&this_ptr_conv);
11401         return ret_val;
11402 }
11403
11404 void TS_ReplyChannelRange_set_full_information(uint32_t this_ptr, jboolean val) {
11405         LDKReplyChannelRange this_ptr_conv;
11406         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11407         this_ptr_conv.is_owned = false;
11408         ReplyChannelRange_set_full_information(&this_ptr_conv, val);
11409 }
11410
11411 void TS_ReplyChannelRange_set_short_channel_ids(uint32_t this_ptr, int64_tArray val) {
11412         LDKReplyChannelRange this_ptr_conv;
11413         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11414         this_ptr_conv.is_owned = false;
11415         LDKCVec_u64Z val_constr;
11416         val_constr.datalen = *((uint32_t*)val);
11417         if (val_constr.datalen > 0)
11418                 val_constr.data = MALLOC(val_constr.datalen * sizeof(int64_t), "LDKCVec_u64Z Elements");
11419         else
11420                 val_constr.data = NULL;
11421         int64_t* val_vals = (int64_t*)(val + 4);
11422         for (size_t i = 0; i < val_constr.datalen; i++) {
11423                 int64_t arr_conv_8 = val_vals[i];
11424                 val_constr.data[i] = arr_conv_8;
11425         }
11426         ReplyChannelRange_set_short_channel_ids(&this_ptr_conv, val_constr);
11427 }
11428
11429 uint32_t TS_ReplyChannelRange_new(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) {
11430         LDKThirtyTwoBytes chain_hash_arg_ref;
11431         CHECK(*((uint32_t*)chain_hash_arg) == 32);
11432         memcpy(chain_hash_arg_ref.data, (uint8_t*)(chain_hash_arg + 4), 32);
11433         LDKCVec_u64Z short_channel_ids_arg_constr;
11434         short_channel_ids_arg_constr.datalen = *((uint32_t*)short_channel_ids_arg);
11435         if (short_channel_ids_arg_constr.datalen > 0)
11436                 short_channel_ids_arg_constr.data = MALLOC(short_channel_ids_arg_constr.datalen * sizeof(int64_t), "LDKCVec_u64Z Elements");
11437         else
11438                 short_channel_ids_arg_constr.data = NULL;
11439         int64_t* short_channel_ids_arg_vals = (int64_t*)(short_channel_ids_arg + 4);
11440         for (size_t i = 0; i < short_channel_ids_arg_constr.datalen; i++) {
11441                 int64_t arr_conv_8 = short_channel_ids_arg_vals[i];
11442                 short_channel_ids_arg_constr.data[i] = arr_conv_8;
11443         }
11444         LDKReplyChannelRange ret_var = ReplyChannelRange_new(chain_hash_arg_ref, first_blocknum_arg, number_of_blocks_arg, full_information_arg, short_channel_ids_arg_constr);
11445         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11446         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11447         long ret_ref = (long)ret_var.inner;
11448         if (ret_var.is_owned) {
11449                 ret_ref |= 1;
11450         }
11451         return ret_ref;
11452 }
11453
11454 void TS_QueryShortChannelIds_free(uint32_t this_ptr) {
11455         LDKQueryShortChannelIds this_ptr_conv;
11456         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11457         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
11458         QueryShortChannelIds_free(this_ptr_conv);
11459 }
11460
11461 uint32_t TS_QueryShortChannelIds_clone(uint32_t orig) {
11462         LDKQueryShortChannelIds orig_conv;
11463         orig_conv.inner = (void*)(orig & (~1));
11464         orig_conv.is_owned = false;
11465         LDKQueryShortChannelIds ret_var = QueryShortChannelIds_clone(&orig_conv);
11466         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11467         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11468         long ret_ref = (long)ret_var.inner;
11469         if (ret_var.is_owned) {
11470                 ret_ref |= 1;
11471         }
11472         return ret_ref;
11473 }
11474
11475 int8_tArray TS_QueryShortChannelIds_get_chain_hash(uint32_t this_ptr) {
11476         LDKQueryShortChannelIds this_ptr_conv;
11477         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11478         this_ptr_conv.is_owned = false;
11479         int8_tArray ret_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
11480         memcpy((uint8_t*)(ret_arr + 4), *QueryShortChannelIds_get_chain_hash(&this_ptr_conv), 32);
11481         return ret_arr;
11482 }
11483
11484 void TS_QueryShortChannelIds_set_chain_hash(uint32_t this_ptr, int8_tArray val) {
11485         LDKQueryShortChannelIds this_ptr_conv;
11486         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11487         this_ptr_conv.is_owned = false;
11488         LDKThirtyTwoBytes val_ref;
11489         CHECK(*((uint32_t*)val) == 32);
11490         memcpy(val_ref.data, (uint8_t*)(val + 4), 32);
11491         QueryShortChannelIds_set_chain_hash(&this_ptr_conv, val_ref);
11492 }
11493
11494 void TS_QueryShortChannelIds_set_short_channel_ids(uint32_t this_ptr, int64_tArray val) {
11495         LDKQueryShortChannelIds this_ptr_conv;
11496         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11497         this_ptr_conv.is_owned = false;
11498         LDKCVec_u64Z val_constr;
11499         val_constr.datalen = *((uint32_t*)val);
11500         if (val_constr.datalen > 0)
11501                 val_constr.data = MALLOC(val_constr.datalen * sizeof(int64_t), "LDKCVec_u64Z Elements");
11502         else
11503                 val_constr.data = NULL;
11504         int64_t* val_vals = (int64_t*)(val + 4);
11505         for (size_t i = 0; i < val_constr.datalen; i++) {
11506                 int64_t arr_conv_8 = val_vals[i];
11507                 val_constr.data[i] = arr_conv_8;
11508         }
11509         QueryShortChannelIds_set_short_channel_ids(&this_ptr_conv, val_constr);
11510 }
11511
11512 uint32_t TS_QueryShortChannelIds_new(int8_tArray chain_hash_arg, int64_tArray short_channel_ids_arg) {
11513         LDKThirtyTwoBytes chain_hash_arg_ref;
11514         CHECK(*((uint32_t*)chain_hash_arg) == 32);
11515         memcpy(chain_hash_arg_ref.data, (uint8_t*)(chain_hash_arg + 4), 32);
11516         LDKCVec_u64Z short_channel_ids_arg_constr;
11517         short_channel_ids_arg_constr.datalen = *((uint32_t*)short_channel_ids_arg);
11518         if (short_channel_ids_arg_constr.datalen > 0)
11519                 short_channel_ids_arg_constr.data = MALLOC(short_channel_ids_arg_constr.datalen * sizeof(int64_t), "LDKCVec_u64Z Elements");
11520         else
11521                 short_channel_ids_arg_constr.data = NULL;
11522         int64_t* short_channel_ids_arg_vals = (int64_t*)(short_channel_ids_arg + 4);
11523         for (size_t i = 0; i < short_channel_ids_arg_constr.datalen; i++) {
11524                 int64_t arr_conv_8 = short_channel_ids_arg_vals[i];
11525                 short_channel_ids_arg_constr.data[i] = arr_conv_8;
11526         }
11527         LDKQueryShortChannelIds ret_var = QueryShortChannelIds_new(chain_hash_arg_ref, short_channel_ids_arg_constr);
11528         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11529         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11530         long ret_ref = (long)ret_var.inner;
11531         if (ret_var.is_owned) {
11532                 ret_ref |= 1;
11533         }
11534         return ret_ref;
11535 }
11536
11537 void TS_ReplyShortChannelIdsEnd_free(uint32_t this_ptr) {
11538         LDKReplyShortChannelIdsEnd this_ptr_conv;
11539         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11540         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
11541         ReplyShortChannelIdsEnd_free(this_ptr_conv);
11542 }
11543
11544 uint32_t TS_ReplyShortChannelIdsEnd_clone(uint32_t orig) {
11545         LDKReplyShortChannelIdsEnd orig_conv;
11546         orig_conv.inner = (void*)(orig & (~1));
11547         orig_conv.is_owned = false;
11548         LDKReplyShortChannelIdsEnd ret_var = ReplyShortChannelIdsEnd_clone(&orig_conv);
11549         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11550         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11551         long ret_ref = (long)ret_var.inner;
11552         if (ret_var.is_owned) {
11553                 ret_ref |= 1;
11554         }
11555         return ret_ref;
11556 }
11557
11558 int8_tArray TS_ReplyShortChannelIdsEnd_get_chain_hash(uint32_t this_ptr) {
11559         LDKReplyShortChannelIdsEnd this_ptr_conv;
11560         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11561         this_ptr_conv.is_owned = false;
11562         int8_tArray ret_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
11563         memcpy((uint8_t*)(ret_arr + 4), *ReplyShortChannelIdsEnd_get_chain_hash(&this_ptr_conv), 32);
11564         return ret_arr;
11565 }
11566
11567 void TS_ReplyShortChannelIdsEnd_set_chain_hash(uint32_t this_ptr, int8_tArray val) {
11568         LDKReplyShortChannelIdsEnd this_ptr_conv;
11569         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11570         this_ptr_conv.is_owned = false;
11571         LDKThirtyTwoBytes val_ref;
11572         CHECK(*((uint32_t*)val) == 32);
11573         memcpy(val_ref.data, (uint8_t*)(val + 4), 32);
11574         ReplyShortChannelIdsEnd_set_chain_hash(&this_ptr_conv, val_ref);
11575 }
11576
11577 jboolean TS_ReplyShortChannelIdsEnd_get_full_information(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         jboolean ret_val = ReplyShortChannelIdsEnd_get_full_information(&this_ptr_conv);
11582         return ret_val;
11583 }
11584
11585 void TS_ReplyShortChannelIdsEnd_set_full_information(uint32_t this_ptr, jboolean val) {
11586         LDKReplyShortChannelIdsEnd this_ptr_conv;
11587         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11588         this_ptr_conv.is_owned = false;
11589         ReplyShortChannelIdsEnd_set_full_information(&this_ptr_conv, val);
11590 }
11591
11592 uint32_t TS_ReplyShortChannelIdsEnd_new(int8_tArray chain_hash_arg, jboolean full_information_arg) {
11593         LDKThirtyTwoBytes chain_hash_arg_ref;
11594         CHECK(*((uint32_t*)chain_hash_arg) == 32);
11595         memcpy(chain_hash_arg_ref.data, (uint8_t*)(chain_hash_arg + 4), 32);
11596         LDKReplyShortChannelIdsEnd ret_var = ReplyShortChannelIdsEnd_new(chain_hash_arg_ref, full_information_arg);
11597         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11598         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11599         long ret_ref = (long)ret_var.inner;
11600         if (ret_var.is_owned) {
11601                 ret_ref |= 1;
11602         }
11603         return ret_ref;
11604 }
11605
11606 void TS_GossipTimestampFilter_free(uint32_t this_ptr) {
11607         LDKGossipTimestampFilter this_ptr_conv;
11608         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11609         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
11610         GossipTimestampFilter_free(this_ptr_conv);
11611 }
11612
11613 uint32_t TS_GossipTimestampFilter_clone(uint32_t orig) {
11614         LDKGossipTimestampFilter orig_conv;
11615         orig_conv.inner = (void*)(orig & (~1));
11616         orig_conv.is_owned = false;
11617         LDKGossipTimestampFilter ret_var = GossipTimestampFilter_clone(&orig_conv);
11618         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11619         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11620         long ret_ref = (long)ret_var.inner;
11621         if (ret_var.is_owned) {
11622                 ret_ref |= 1;
11623         }
11624         return ret_ref;
11625 }
11626
11627 int8_tArray TS_GossipTimestampFilter_get_chain_hash(uint32_t this_ptr) {
11628         LDKGossipTimestampFilter this_ptr_conv;
11629         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11630         this_ptr_conv.is_owned = false;
11631         int8_tArray ret_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
11632         memcpy((uint8_t*)(ret_arr + 4), *GossipTimestampFilter_get_chain_hash(&this_ptr_conv), 32);
11633         return ret_arr;
11634 }
11635
11636 void TS_GossipTimestampFilter_set_chain_hash(uint32_t this_ptr, int8_tArray val) {
11637         LDKGossipTimestampFilter this_ptr_conv;
11638         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11639         this_ptr_conv.is_owned = false;
11640         LDKThirtyTwoBytes val_ref;
11641         CHECK(*((uint32_t*)val) == 32);
11642         memcpy(val_ref.data, (uint8_t*)(val + 4), 32);
11643         GossipTimestampFilter_set_chain_hash(&this_ptr_conv, val_ref);
11644 }
11645
11646 int32_t TS_GossipTimestampFilter_get_first_timestamp(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         int32_t ret_val = GossipTimestampFilter_get_first_timestamp(&this_ptr_conv);
11651         return ret_val;
11652 }
11653
11654 void TS_GossipTimestampFilter_set_first_timestamp(uint32_t this_ptr, int32_t val) {
11655         LDKGossipTimestampFilter this_ptr_conv;
11656         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11657         this_ptr_conv.is_owned = false;
11658         GossipTimestampFilter_set_first_timestamp(&this_ptr_conv, val);
11659 }
11660
11661 int32_t TS_GossipTimestampFilter_get_timestamp_range(uint32_t this_ptr) {
11662         LDKGossipTimestampFilter this_ptr_conv;
11663         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11664         this_ptr_conv.is_owned = false;
11665         int32_t ret_val = GossipTimestampFilter_get_timestamp_range(&this_ptr_conv);
11666         return ret_val;
11667 }
11668
11669 void TS_GossipTimestampFilter_set_timestamp_range(uint32_t this_ptr, int32_t val) {
11670         LDKGossipTimestampFilter this_ptr_conv;
11671         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11672         this_ptr_conv.is_owned = false;
11673         GossipTimestampFilter_set_timestamp_range(&this_ptr_conv, val);
11674 }
11675
11676 uint32_t TS_GossipTimestampFilter_new(int8_tArray chain_hash_arg, int32_t first_timestamp_arg, int32_t timestamp_range_arg) {
11677         LDKThirtyTwoBytes chain_hash_arg_ref;
11678         CHECK(*((uint32_t*)chain_hash_arg) == 32);
11679         memcpy(chain_hash_arg_ref.data, (uint8_t*)(chain_hash_arg + 4), 32);
11680         LDKGossipTimestampFilter ret_var = GossipTimestampFilter_new(chain_hash_arg_ref, first_timestamp_arg, timestamp_range_arg);
11681         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11682         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11683         long ret_ref = (long)ret_var.inner;
11684         if (ret_var.is_owned) {
11685                 ret_ref |= 1;
11686         }
11687         return ret_ref;
11688 }
11689
11690 void TS_ErrorAction_free(uint32_t this_ptr) {
11691         LDKErrorAction this_ptr_conv = *(LDKErrorAction*)this_ptr;
11692         FREE((void*)this_ptr);
11693         ErrorAction_free(this_ptr_conv);
11694 }
11695
11696 uint32_t TS_ErrorAction_clone(uint32_t orig) {
11697         LDKErrorAction* orig_conv = (LDKErrorAction*)orig;
11698         LDKErrorAction *ret_copy = MALLOC(sizeof(LDKErrorAction), "LDKErrorAction");
11699         *ret_copy = ErrorAction_clone(orig_conv);
11700         long ret_ref = (long)ret_copy;
11701         return ret_ref;
11702 }
11703
11704 void TS_LightningError_free(uint32_t this_ptr) {
11705         LDKLightningError this_ptr_conv;
11706         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11707         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
11708         LightningError_free(this_ptr_conv);
11709 }
11710
11711 jstring TS_LightningError_get_err(uint32_t this_ptr) {
11712         LDKLightningError this_ptr_conv;
11713         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11714         this_ptr_conv.is_owned = false;
11715         LDKStr _str = LightningError_get_err(&this_ptr_conv);
11716         jstring _conv = str_ref_to_ts(_str.chars, _str.len);
11717         return _conv;
11718 }
11719
11720 void TS_LightningError_set_err(uint32_t this_ptr, int8_tArray val) {
11721         LDKLightningError this_ptr_conv;
11722         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11723         this_ptr_conv.is_owned = false;
11724         LDKCVec_u8Z val_ref;
11725         val_ref.datalen = *((uint32_t*)val);
11726         val_ref.data = MALLOC(val_ref.datalen, "LDKCVec_u8Z Bytes");
11727         memcpy(val_ref.data, (uint8_t*)(val + 4), val_ref.datalen);
11728         LightningError_set_err(&this_ptr_conv, val_ref);
11729 }
11730
11731 uint32_t TS_LightningError_get_action(uint32_t this_ptr) {
11732         LDKLightningError this_ptr_conv;
11733         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11734         this_ptr_conv.is_owned = false;
11735         LDKErrorAction *ret_copy = MALLOC(sizeof(LDKErrorAction), "LDKErrorAction");
11736         *ret_copy = LightningError_get_action(&this_ptr_conv);
11737         long ret_ref = (long)ret_copy;
11738         return ret_ref;
11739 }
11740
11741 void TS_LightningError_set_action(uint32_t this_ptr, uint32_t val) {
11742         LDKLightningError this_ptr_conv;
11743         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11744         this_ptr_conv.is_owned = false;
11745         LDKErrorAction val_conv = *(LDKErrorAction*)val;
11746         FREE((void*)val);
11747         LightningError_set_action(&this_ptr_conv, val_conv);
11748 }
11749
11750 uint32_t TS_LightningError_new(int8_tArray err_arg, uint32_t action_arg) {
11751         LDKCVec_u8Z err_arg_ref;
11752         err_arg_ref.datalen = *((uint32_t*)err_arg);
11753         err_arg_ref.data = MALLOC(err_arg_ref.datalen, "LDKCVec_u8Z Bytes");
11754         memcpy(err_arg_ref.data, (uint8_t*)(err_arg + 4), err_arg_ref.datalen);
11755         LDKErrorAction action_arg_conv = *(LDKErrorAction*)action_arg;
11756         FREE((void*)action_arg);
11757         LDKLightningError ret_var = LightningError_new(err_arg_ref, action_arg_conv);
11758         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11759         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11760         long ret_ref = (long)ret_var.inner;
11761         if (ret_var.is_owned) {
11762                 ret_ref |= 1;
11763         }
11764         return ret_ref;
11765 }
11766
11767 void TS_CommitmentUpdate_free(uint32_t this_ptr) {
11768         LDKCommitmentUpdate this_ptr_conv;
11769         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11770         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
11771         CommitmentUpdate_free(this_ptr_conv);
11772 }
11773
11774 uint32_t TS_CommitmentUpdate_clone(uint32_t orig) {
11775         LDKCommitmentUpdate orig_conv;
11776         orig_conv.inner = (void*)(orig & (~1));
11777         orig_conv.is_owned = false;
11778         LDKCommitmentUpdate ret_var = CommitmentUpdate_clone(&orig_conv);
11779         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11780         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11781         long ret_ref = (long)ret_var.inner;
11782         if (ret_var.is_owned) {
11783                 ret_ref |= 1;
11784         }
11785         return ret_ref;
11786 }
11787
11788 void TS_CommitmentUpdate_set_update_add_htlcs(uint32_t this_ptr, uint32_tArray val) {
11789         LDKCommitmentUpdate this_ptr_conv;
11790         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11791         this_ptr_conv.is_owned = false;
11792         LDKCVec_UpdateAddHTLCZ val_constr;
11793         val_constr.datalen = *((uint32_t*)val);
11794         if (val_constr.datalen > 0)
11795                 val_constr.data = MALLOC(val_constr.datalen * sizeof(LDKUpdateAddHTLC), "LDKCVec_UpdateAddHTLCZ Elements");
11796         else
11797                 val_constr.data = NULL;
11798         uint32_t* val_vals = (uint32_t*)(val + 4);
11799         for (size_t p = 0; p < val_constr.datalen; p++) {
11800                 uint32_t arr_conv_15 = val_vals[p];
11801                 LDKUpdateAddHTLC arr_conv_15_conv;
11802                 arr_conv_15_conv.inner = (void*)(arr_conv_15 & (~1));
11803                 arr_conv_15_conv.is_owned = (arr_conv_15 & 1) || (arr_conv_15 == 0);
11804                 if (arr_conv_15_conv.inner != NULL)
11805                         arr_conv_15_conv = UpdateAddHTLC_clone(&arr_conv_15_conv);
11806                 val_constr.data[p] = arr_conv_15_conv;
11807         }
11808         CommitmentUpdate_set_update_add_htlcs(&this_ptr_conv, val_constr);
11809 }
11810
11811 void TS_CommitmentUpdate_set_update_fulfill_htlcs(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_UpdateFulfillHTLCZ val_constr;
11816         val_constr.datalen = *((uint32_t*)val);
11817         if (val_constr.datalen > 0)
11818                 val_constr.data = MALLOC(val_constr.datalen * sizeof(LDKUpdateFulfillHTLC), "LDKCVec_UpdateFulfillHTLCZ Elements");
11819         else
11820                 val_constr.data = NULL;
11821         uint32_t* val_vals = (uint32_t*)(val + 4);
11822         for (size_t t = 0; t < val_constr.datalen; t++) {
11823                 uint32_t arr_conv_19 = val_vals[t];
11824                 LDKUpdateFulfillHTLC arr_conv_19_conv;
11825                 arr_conv_19_conv.inner = (void*)(arr_conv_19 & (~1));
11826                 arr_conv_19_conv.is_owned = (arr_conv_19 & 1) || (arr_conv_19 == 0);
11827                 if (arr_conv_19_conv.inner != NULL)
11828                         arr_conv_19_conv = UpdateFulfillHTLC_clone(&arr_conv_19_conv);
11829                 val_constr.data[t] = arr_conv_19_conv;
11830         }
11831         CommitmentUpdate_set_update_fulfill_htlcs(&this_ptr_conv, val_constr);
11832 }
11833
11834 void TS_CommitmentUpdate_set_update_fail_htlcs(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_UpdateFailHTLCZ val_constr;
11839         val_constr.datalen = *((uint32_t*)val);
11840         if (val_constr.datalen > 0)
11841                 val_constr.data = MALLOC(val_constr.datalen * sizeof(LDKUpdateFailHTLC), "LDKCVec_UpdateFailHTLCZ Elements");
11842         else
11843                 val_constr.data = NULL;
11844         uint32_t* val_vals = (uint32_t*)(val + 4);
11845         for (size_t q = 0; q < val_constr.datalen; q++) {
11846                 uint32_t arr_conv_16 = val_vals[q];
11847                 LDKUpdateFailHTLC arr_conv_16_conv;
11848                 arr_conv_16_conv.inner = (void*)(arr_conv_16 & (~1));
11849                 arr_conv_16_conv.is_owned = (arr_conv_16 & 1) || (arr_conv_16 == 0);
11850                 if (arr_conv_16_conv.inner != NULL)
11851                         arr_conv_16_conv = UpdateFailHTLC_clone(&arr_conv_16_conv);
11852                 val_constr.data[q] = arr_conv_16_conv;
11853         }
11854         CommitmentUpdate_set_update_fail_htlcs(&this_ptr_conv, val_constr);
11855 }
11856
11857 void TS_CommitmentUpdate_set_update_fail_malformed_htlcs(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_UpdateFailMalformedHTLCZ val_constr;
11862         val_constr.datalen = *((uint32_t*)val);
11863         if (val_constr.datalen > 0)
11864                 val_constr.data = MALLOC(val_constr.datalen * sizeof(LDKUpdateFailMalformedHTLC), "LDKCVec_UpdateFailMalformedHTLCZ Elements");
11865         else
11866                 val_constr.data = NULL;
11867         uint32_t* val_vals = (uint32_t*)(val + 4);
11868         for (size_t z = 0; z < val_constr.datalen; z++) {
11869                 uint32_t arr_conv_25 = val_vals[z];
11870                 LDKUpdateFailMalformedHTLC arr_conv_25_conv;
11871                 arr_conv_25_conv.inner = (void*)(arr_conv_25 & (~1));
11872                 arr_conv_25_conv.is_owned = (arr_conv_25 & 1) || (arr_conv_25 == 0);
11873                 if (arr_conv_25_conv.inner != NULL)
11874                         arr_conv_25_conv = UpdateFailMalformedHTLC_clone(&arr_conv_25_conv);
11875                 val_constr.data[z] = arr_conv_25_conv;
11876         }
11877         CommitmentUpdate_set_update_fail_malformed_htlcs(&this_ptr_conv, val_constr);
11878 }
11879
11880 uint32_t TS_CommitmentUpdate_get_update_fee(uint32_t this_ptr) {
11881         LDKCommitmentUpdate this_ptr_conv;
11882         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11883         this_ptr_conv.is_owned = false;
11884         LDKUpdateFee ret_var = CommitmentUpdate_get_update_fee(&this_ptr_conv);
11885         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11886         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11887         long ret_ref = (long)ret_var.inner;
11888         if (ret_var.is_owned) {
11889                 ret_ref |= 1;
11890         }
11891         return ret_ref;
11892 }
11893
11894 void TS_CommitmentUpdate_set_update_fee(uint32_t this_ptr, uint32_t val) {
11895         LDKCommitmentUpdate this_ptr_conv;
11896         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11897         this_ptr_conv.is_owned = false;
11898         LDKUpdateFee val_conv;
11899         val_conv.inner = (void*)(val & (~1));
11900         val_conv.is_owned = (val & 1) || (val == 0);
11901         if (val_conv.inner != NULL)
11902                 val_conv = UpdateFee_clone(&val_conv);
11903         CommitmentUpdate_set_update_fee(&this_ptr_conv, val_conv);
11904 }
11905
11906 uint32_t TS_CommitmentUpdate_get_commitment_signed(uint32_t this_ptr) {
11907         LDKCommitmentUpdate this_ptr_conv;
11908         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11909         this_ptr_conv.is_owned = false;
11910         LDKCommitmentSigned ret_var = CommitmentUpdate_get_commitment_signed(&this_ptr_conv);
11911         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11912         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11913         long ret_ref = (long)ret_var.inner;
11914         if (ret_var.is_owned) {
11915                 ret_ref |= 1;
11916         }
11917         return ret_ref;
11918 }
11919
11920 void TS_CommitmentUpdate_set_commitment_signed(uint32_t this_ptr, uint32_t val) {
11921         LDKCommitmentUpdate this_ptr_conv;
11922         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11923         this_ptr_conv.is_owned = false;
11924         LDKCommitmentSigned val_conv;
11925         val_conv.inner = (void*)(val & (~1));
11926         val_conv.is_owned = (val & 1) || (val == 0);
11927         if (val_conv.inner != NULL)
11928                 val_conv = CommitmentSigned_clone(&val_conv);
11929         CommitmentUpdate_set_commitment_signed(&this_ptr_conv, val_conv);
11930 }
11931
11932 uint32_t TS_CommitmentUpdate_new(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) {
11933         LDKCVec_UpdateAddHTLCZ update_add_htlcs_arg_constr;
11934         update_add_htlcs_arg_constr.datalen = *((uint32_t*)update_add_htlcs_arg);
11935         if (update_add_htlcs_arg_constr.datalen > 0)
11936                 update_add_htlcs_arg_constr.data = MALLOC(update_add_htlcs_arg_constr.datalen * sizeof(LDKUpdateAddHTLC), "LDKCVec_UpdateAddHTLCZ Elements");
11937         else
11938                 update_add_htlcs_arg_constr.data = NULL;
11939         uint32_t* update_add_htlcs_arg_vals = (uint32_t*)(update_add_htlcs_arg + 4);
11940         for (size_t p = 0; p < update_add_htlcs_arg_constr.datalen; p++) {
11941                 uint32_t arr_conv_15 = update_add_htlcs_arg_vals[p];
11942                 LDKUpdateAddHTLC arr_conv_15_conv;
11943                 arr_conv_15_conv.inner = (void*)(arr_conv_15 & (~1));
11944                 arr_conv_15_conv.is_owned = (arr_conv_15 & 1) || (arr_conv_15 == 0);
11945                 if (arr_conv_15_conv.inner != NULL)
11946                         arr_conv_15_conv = UpdateAddHTLC_clone(&arr_conv_15_conv);
11947                 update_add_htlcs_arg_constr.data[p] = arr_conv_15_conv;
11948         }
11949         LDKCVec_UpdateFulfillHTLCZ update_fulfill_htlcs_arg_constr;
11950         update_fulfill_htlcs_arg_constr.datalen = *((uint32_t*)update_fulfill_htlcs_arg);
11951         if (update_fulfill_htlcs_arg_constr.datalen > 0)
11952                 update_fulfill_htlcs_arg_constr.data = MALLOC(update_fulfill_htlcs_arg_constr.datalen * sizeof(LDKUpdateFulfillHTLC), "LDKCVec_UpdateFulfillHTLCZ Elements");
11953         else
11954                 update_fulfill_htlcs_arg_constr.data = NULL;
11955         uint32_t* update_fulfill_htlcs_arg_vals = (uint32_t*)(update_fulfill_htlcs_arg + 4);
11956         for (size_t t = 0; t < update_fulfill_htlcs_arg_constr.datalen; t++) {
11957                 uint32_t arr_conv_19 = update_fulfill_htlcs_arg_vals[t];
11958                 LDKUpdateFulfillHTLC arr_conv_19_conv;
11959                 arr_conv_19_conv.inner = (void*)(arr_conv_19 & (~1));
11960                 arr_conv_19_conv.is_owned = (arr_conv_19 & 1) || (arr_conv_19 == 0);
11961                 if (arr_conv_19_conv.inner != NULL)
11962                         arr_conv_19_conv = UpdateFulfillHTLC_clone(&arr_conv_19_conv);
11963                 update_fulfill_htlcs_arg_constr.data[t] = arr_conv_19_conv;
11964         }
11965         LDKCVec_UpdateFailHTLCZ update_fail_htlcs_arg_constr;
11966         update_fail_htlcs_arg_constr.datalen = *((uint32_t*)update_fail_htlcs_arg);
11967         if (update_fail_htlcs_arg_constr.datalen > 0)
11968                 update_fail_htlcs_arg_constr.data = MALLOC(update_fail_htlcs_arg_constr.datalen * sizeof(LDKUpdateFailHTLC), "LDKCVec_UpdateFailHTLCZ Elements");
11969         else
11970                 update_fail_htlcs_arg_constr.data = NULL;
11971         uint32_t* update_fail_htlcs_arg_vals = (uint32_t*)(update_fail_htlcs_arg + 4);
11972         for (size_t q = 0; q < update_fail_htlcs_arg_constr.datalen; q++) {
11973                 uint32_t arr_conv_16 = update_fail_htlcs_arg_vals[q];
11974                 LDKUpdateFailHTLC arr_conv_16_conv;
11975                 arr_conv_16_conv.inner = (void*)(arr_conv_16 & (~1));
11976                 arr_conv_16_conv.is_owned = (arr_conv_16 & 1) || (arr_conv_16 == 0);
11977                 if (arr_conv_16_conv.inner != NULL)
11978                         arr_conv_16_conv = UpdateFailHTLC_clone(&arr_conv_16_conv);
11979                 update_fail_htlcs_arg_constr.data[q] = arr_conv_16_conv;
11980         }
11981         LDKCVec_UpdateFailMalformedHTLCZ update_fail_malformed_htlcs_arg_constr;
11982         update_fail_malformed_htlcs_arg_constr.datalen = *((uint32_t*)update_fail_malformed_htlcs_arg);
11983         if (update_fail_malformed_htlcs_arg_constr.datalen > 0)
11984                 update_fail_malformed_htlcs_arg_constr.data = MALLOC(update_fail_malformed_htlcs_arg_constr.datalen * sizeof(LDKUpdateFailMalformedHTLC), "LDKCVec_UpdateFailMalformedHTLCZ Elements");
11985         else
11986                 update_fail_malformed_htlcs_arg_constr.data = NULL;
11987         uint32_t* update_fail_malformed_htlcs_arg_vals = (uint32_t*)(update_fail_malformed_htlcs_arg + 4);
11988         for (size_t z = 0; z < update_fail_malformed_htlcs_arg_constr.datalen; z++) {
11989                 uint32_t arr_conv_25 = update_fail_malformed_htlcs_arg_vals[z];
11990                 LDKUpdateFailMalformedHTLC arr_conv_25_conv;
11991                 arr_conv_25_conv.inner = (void*)(arr_conv_25 & (~1));
11992                 arr_conv_25_conv.is_owned = (arr_conv_25 & 1) || (arr_conv_25 == 0);
11993                 if (arr_conv_25_conv.inner != NULL)
11994                         arr_conv_25_conv = UpdateFailMalformedHTLC_clone(&arr_conv_25_conv);
11995                 update_fail_malformed_htlcs_arg_constr.data[z] = arr_conv_25_conv;
11996         }
11997         LDKUpdateFee update_fee_arg_conv;
11998         update_fee_arg_conv.inner = (void*)(update_fee_arg & (~1));
11999         update_fee_arg_conv.is_owned = (update_fee_arg & 1) || (update_fee_arg == 0);
12000         if (update_fee_arg_conv.inner != NULL)
12001                 update_fee_arg_conv = UpdateFee_clone(&update_fee_arg_conv);
12002         LDKCommitmentSigned commitment_signed_arg_conv;
12003         commitment_signed_arg_conv.inner = (void*)(commitment_signed_arg & (~1));
12004         commitment_signed_arg_conv.is_owned = (commitment_signed_arg & 1) || (commitment_signed_arg == 0);
12005         if (commitment_signed_arg_conv.inner != NULL)
12006                 commitment_signed_arg_conv = CommitmentSigned_clone(&commitment_signed_arg_conv);
12007         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);
12008         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12009         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12010         long ret_ref = (long)ret_var.inner;
12011         if (ret_var.is_owned) {
12012                 ret_ref |= 1;
12013         }
12014         return ret_ref;
12015 }
12016
12017 void TS_HTLCFailChannelUpdate_free(uint32_t this_ptr) {
12018         LDKHTLCFailChannelUpdate this_ptr_conv = *(LDKHTLCFailChannelUpdate*)this_ptr;
12019         FREE((void*)this_ptr);
12020         HTLCFailChannelUpdate_free(this_ptr_conv);
12021 }
12022
12023 uint32_t TS_HTLCFailChannelUpdate_clone(uint32_t orig) {
12024         LDKHTLCFailChannelUpdate* orig_conv = (LDKHTLCFailChannelUpdate*)orig;
12025         LDKHTLCFailChannelUpdate *ret_copy = MALLOC(sizeof(LDKHTLCFailChannelUpdate), "LDKHTLCFailChannelUpdate");
12026         *ret_copy = HTLCFailChannelUpdate_clone(orig_conv);
12027         long ret_ref = (long)ret_copy;
12028         return ret_ref;
12029 }
12030
12031 void TS_ChannelMessageHandler_free(uint32_t this_ptr) {
12032         LDKChannelMessageHandler this_ptr_conv = *(LDKChannelMessageHandler*)this_ptr;
12033         FREE((void*)this_ptr);
12034         ChannelMessageHandler_free(this_ptr_conv);
12035 }
12036
12037 void TS_RoutingMessageHandler_free(uint32_t this_ptr) {
12038         LDKRoutingMessageHandler this_ptr_conv = *(LDKRoutingMessageHandler*)this_ptr;
12039         FREE((void*)this_ptr);
12040         RoutingMessageHandler_free(this_ptr_conv);
12041 }
12042
12043 int8_tArray TS_AcceptChannel_write(uint32_t obj) {
12044         LDKAcceptChannel obj_conv;
12045         obj_conv.inner = (void*)(obj & (~1));
12046         obj_conv.is_owned = false;
12047         LDKCVec_u8Z arg_var = AcceptChannel_write(&obj_conv);
12048         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
12049         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
12050         CVec_u8Z_free(arg_var);
12051         return arg_arr;
12052 }
12053
12054 uint32_t TS_AcceptChannel_read(int8_tArray ser) {
12055         LDKu8slice ser_ref;
12056         ser_ref.datalen = *((uint32_t*)ser);
12057         ser_ref.data = (int8_t*)(ser + 4);
12058         LDKAcceptChannel ret_var = AcceptChannel_read(ser_ref);
12059         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12060         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12061         long ret_ref = (long)ret_var.inner;
12062         if (ret_var.is_owned) {
12063                 ret_ref |= 1;
12064         }
12065         return ret_ref;
12066 }
12067
12068 int8_tArray TS_AnnouncementSignatures_write(uint32_t obj) {
12069         LDKAnnouncementSignatures obj_conv;
12070         obj_conv.inner = (void*)(obj & (~1));
12071         obj_conv.is_owned = false;
12072         LDKCVec_u8Z arg_var = AnnouncementSignatures_write(&obj_conv);
12073         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
12074         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
12075         CVec_u8Z_free(arg_var);
12076         return arg_arr;
12077 }
12078
12079 uint32_t TS_AnnouncementSignatures_read(int8_tArray ser) {
12080         LDKu8slice ser_ref;
12081         ser_ref.datalen = *((uint32_t*)ser);
12082         ser_ref.data = (int8_t*)(ser + 4);
12083         LDKAnnouncementSignatures ret_var = AnnouncementSignatures_read(ser_ref);
12084         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12085         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12086         long ret_ref = (long)ret_var.inner;
12087         if (ret_var.is_owned) {
12088                 ret_ref |= 1;
12089         }
12090         return ret_ref;
12091 }
12092
12093 int8_tArray TS_ChannelReestablish_write(uint32_t obj) {
12094         LDKChannelReestablish obj_conv;
12095         obj_conv.inner = (void*)(obj & (~1));
12096         obj_conv.is_owned = false;
12097         LDKCVec_u8Z arg_var = ChannelReestablish_write(&obj_conv);
12098         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
12099         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
12100         CVec_u8Z_free(arg_var);
12101         return arg_arr;
12102 }
12103
12104 uint32_t TS_ChannelReestablish_read(int8_tArray ser) {
12105         LDKu8slice ser_ref;
12106         ser_ref.datalen = *((uint32_t*)ser);
12107         ser_ref.data = (int8_t*)(ser + 4);
12108         LDKCResult_ChannelReestablishDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ChannelReestablishDecodeErrorZ), "LDKCResult_ChannelReestablishDecodeErrorZ");
12109         *ret_conv = ChannelReestablish_read(ser_ref);
12110         return (long)ret_conv;
12111 }
12112
12113 int8_tArray TS_ClosingSigned_write(uint32_t obj) {
12114         LDKClosingSigned obj_conv;
12115         obj_conv.inner = (void*)(obj & (~1));
12116         obj_conv.is_owned = false;
12117         LDKCVec_u8Z arg_var = ClosingSigned_write(&obj_conv);
12118         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
12119         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
12120         CVec_u8Z_free(arg_var);
12121         return arg_arr;
12122 }
12123
12124 uint32_t TS_ClosingSigned_read(int8_tArray ser) {
12125         LDKu8slice ser_ref;
12126         ser_ref.datalen = *((uint32_t*)ser);
12127         ser_ref.data = (int8_t*)(ser + 4);
12128         LDKClosingSigned ret_var = ClosingSigned_read(ser_ref);
12129         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12130         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12131         long ret_ref = (long)ret_var.inner;
12132         if (ret_var.is_owned) {
12133                 ret_ref |= 1;
12134         }
12135         return ret_ref;
12136 }
12137
12138 int8_tArray TS_CommitmentSigned_write(uint32_t obj) {
12139         LDKCommitmentSigned obj_conv;
12140         obj_conv.inner = (void*)(obj & (~1));
12141         obj_conv.is_owned = false;
12142         LDKCVec_u8Z arg_var = CommitmentSigned_write(&obj_conv);
12143         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
12144         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
12145         CVec_u8Z_free(arg_var);
12146         return arg_arr;
12147 }
12148
12149 uint32_t TS_CommitmentSigned_read(int8_tArray ser) {
12150         LDKu8slice ser_ref;
12151         ser_ref.datalen = *((uint32_t*)ser);
12152         ser_ref.data = (int8_t*)(ser + 4);
12153         LDKCommitmentSigned ret_var = CommitmentSigned_read(ser_ref);
12154         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12155         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12156         long ret_ref = (long)ret_var.inner;
12157         if (ret_var.is_owned) {
12158                 ret_ref |= 1;
12159         }
12160         return ret_ref;
12161 }
12162
12163 int8_tArray TS_FundingCreated_write(uint32_t obj) {
12164         LDKFundingCreated obj_conv;
12165         obj_conv.inner = (void*)(obj & (~1));
12166         obj_conv.is_owned = false;
12167         LDKCVec_u8Z arg_var = FundingCreated_write(&obj_conv);
12168         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
12169         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
12170         CVec_u8Z_free(arg_var);
12171         return arg_arr;
12172 }
12173
12174 uint32_t TS_FundingCreated_read(int8_tArray ser) {
12175         LDKu8slice ser_ref;
12176         ser_ref.datalen = *((uint32_t*)ser);
12177         ser_ref.data = (int8_t*)(ser + 4);
12178         LDKFundingCreated ret_var = FundingCreated_read(ser_ref);
12179         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12180         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12181         long ret_ref = (long)ret_var.inner;
12182         if (ret_var.is_owned) {
12183                 ret_ref |= 1;
12184         }
12185         return ret_ref;
12186 }
12187
12188 int8_tArray TS_FundingSigned_write(uint32_t obj) {
12189         LDKFundingSigned obj_conv;
12190         obj_conv.inner = (void*)(obj & (~1));
12191         obj_conv.is_owned = false;
12192         LDKCVec_u8Z arg_var = FundingSigned_write(&obj_conv);
12193         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
12194         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
12195         CVec_u8Z_free(arg_var);
12196         return arg_arr;
12197 }
12198
12199 uint32_t TS_FundingSigned_read(int8_tArray ser) {
12200         LDKu8slice ser_ref;
12201         ser_ref.datalen = *((uint32_t*)ser);
12202         ser_ref.data = (int8_t*)(ser + 4);
12203         LDKFundingSigned ret_var = FundingSigned_read(ser_ref);
12204         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12205         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12206         long ret_ref = (long)ret_var.inner;
12207         if (ret_var.is_owned) {
12208                 ret_ref |= 1;
12209         }
12210         return ret_ref;
12211 }
12212
12213 int8_tArray TS_FundingLocked_write(uint32_t obj) {
12214         LDKFundingLocked obj_conv;
12215         obj_conv.inner = (void*)(obj & (~1));
12216         obj_conv.is_owned = false;
12217         LDKCVec_u8Z arg_var = FundingLocked_write(&obj_conv);
12218         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
12219         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
12220         CVec_u8Z_free(arg_var);
12221         return arg_arr;
12222 }
12223
12224 uint32_t TS_FundingLocked_read(int8_tArray ser) {
12225         LDKu8slice ser_ref;
12226         ser_ref.datalen = *((uint32_t*)ser);
12227         ser_ref.data = (int8_t*)(ser + 4);
12228         LDKFundingLocked ret_var = FundingLocked_read(ser_ref);
12229         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12230         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12231         long ret_ref = (long)ret_var.inner;
12232         if (ret_var.is_owned) {
12233                 ret_ref |= 1;
12234         }
12235         return ret_ref;
12236 }
12237
12238 int8_tArray TS_Init_write(uint32_t obj) {
12239         LDKInit obj_conv;
12240         obj_conv.inner = (void*)(obj & (~1));
12241         obj_conv.is_owned = false;
12242         LDKCVec_u8Z arg_var = Init_write(&obj_conv);
12243         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
12244         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
12245         CVec_u8Z_free(arg_var);
12246         return arg_arr;
12247 }
12248
12249 uint32_t TS_Init_read(int8_tArray ser) {
12250         LDKu8slice ser_ref;
12251         ser_ref.datalen = *((uint32_t*)ser);
12252         ser_ref.data = (int8_t*)(ser + 4);
12253         LDKCResult_InitDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_InitDecodeErrorZ), "LDKCResult_InitDecodeErrorZ");
12254         *ret_conv = Init_read(ser_ref);
12255         return (long)ret_conv;
12256 }
12257
12258 int8_tArray TS_OpenChannel_write(uint32_t obj) {
12259         LDKOpenChannel obj_conv;
12260         obj_conv.inner = (void*)(obj & (~1));
12261         obj_conv.is_owned = false;
12262         LDKCVec_u8Z arg_var = OpenChannel_write(&obj_conv);
12263         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
12264         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
12265         CVec_u8Z_free(arg_var);
12266         return arg_arr;
12267 }
12268
12269 uint32_t TS_OpenChannel_read(int8_tArray ser) {
12270         LDKu8slice ser_ref;
12271         ser_ref.datalen = *((uint32_t*)ser);
12272         ser_ref.data = (int8_t*)(ser + 4);
12273         LDKOpenChannel ret_var = OpenChannel_read(ser_ref);
12274         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12275         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12276         long ret_ref = (long)ret_var.inner;
12277         if (ret_var.is_owned) {
12278                 ret_ref |= 1;
12279         }
12280         return ret_ref;
12281 }
12282
12283 int8_tArray TS_RevokeAndACK_write(uint32_t obj) {
12284         LDKRevokeAndACK obj_conv;
12285         obj_conv.inner = (void*)(obj & (~1));
12286         obj_conv.is_owned = false;
12287         LDKCVec_u8Z arg_var = RevokeAndACK_write(&obj_conv);
12288         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
12289         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
12290         CVec_u8Z_free(arg_var);
12291         return arg_arr;
12292 }
12293
12294 uint32_t TS_RevokeAndACK_read(int8_tArray ser) {
12295         LDKu8slice ser_ref;
12296         ser_ref.datalen = *((uint32_t*)ser);
12297         ser_ref.data = (int8_t*)(ser + 4);
12298         LDKRevokeAndACK ret_var = RevokeAndACK_read(ser_ref);
12299         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12300         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12301         long ret_ref = (long)ret_var.inner;
12302         if (ret_var.is_owned) {
12303                 ret_ref |= 1;
12304         }
12305         return ret_ref;
12306 }
12307
12308 int8_tArray TS_Shutdown_write(uint32_t obj) {
12309         LDKShutdown obj_conv;
12310         obj_conv.inner = (void*)(obj & (~1));
12311         obj_conv.is_owned = false;
12312         LDKCVec_u8Z arg_var = Shutdown_write(&obj_conv);
12313         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
12314         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
12315         CVec_u8Z_free(arg_var);
12316         return arg_arr;
12317 }
12318
12319 uint32_t TS_Shutdown_read(int8_tArray ser) {
12320         LDKu8slice ser_ref;
12321         ser_ref.datalen = *((uint32_t*)ser);
12322         ser_ref.data = (int8_t*)(ser + 4);
12323         LDKShutdown ret_var = Shutdown_read(ser_ref);
12324         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12325         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12326         long ret_ref = (long)ret_var.inner;
12327         if (ret_var.is_owned) {
12328                 ret_ref |= 1;
12329         }
12330         return ret_ref;
12331 }
12332
12333 int8_tArray TS_UpdateFailHTLC_write(uint32_t obj) {
12334         LDKUpdateFailHTLC obj_conv;
12335         obj_conv.inner = (void*)(obj & (~1));
12336         obj_conv.is_owned = false;
12337         LDKCVec_u8Z arg_var = UpdateFailHTLC_write(&obj_conv);
12338         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
12339         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
12340         CVec_u8Z_free(arg_var);
12341         return arg_arr;
12342 }
12343
12344 uint32_t TS_UpdateFailHTLC_read(int8_tArray ser) {
12345         LDKu8slice ser_ref;
12346         ser_ref.datalen = *((uint32_t*)ser);
12347         ser_ref.data = (int8_t*)(ser + 4);
12348         LDKUpdateFailHTLC ret_var = UpdateFailHTLC_read(ser_ref);
12349         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12350         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12351         long ret_ref = (long)ret_var.inner;
12352         if (ret_var.is_owned) {
12353                 ret_ref |= 1;
12354         }
12355         return ret_ref;
12356 }
12357
12358 int8_tArray TS_UpdateFailMalformedHTLC_write(uint32_t obj) {
12359         LDKUpdateFailMalformedHTLC obj_conv;
12360         obj_conv.inner = (void*)(obj & (~1));
12361         obj_conv.is_owned = false;
12362         LDKCVec_u8Z arg_var = UpdateFailMalformedHTLC_write(&obj_conv);
12363         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
12364         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
12365         CVec_u8Z_free(arg_var);
12366         return arg_arr;
12367 }
12368
12369 uint32_t TS_UpdateFailMalformedHTLC_read(int8_tArray ser) {
12370         LDKu8slice ser_ref;
12371         ser_ref.datalen = *((uint32_t*)ser);
12372         ser_ref.data = (int8_t*)(ser + 4);
12373         LDKUpdateFailMalformedHTLC ret_var = UpdateFailMalformedHTLC_read(ser_ref);
12374         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12375         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12376         long ret_ref = (long)ret_var.inner;
12377         if (ret_var.is_owned) {
12378                 ret_ref |= 1;
12379         }
12380         return ret_ref;
12381 }
12382
12383 int8_tArray TS_UpdateFee_write(uint32_t obj) {
12384         LDKUpdateFee obj_conv;
12385         obj_conv.inner = (void*)(obj & (~1));
12386         obj_conv.is_owned = false;
12387         LDKCVec_u8Z arg_var = UpdateFee_write(&obj_conv);
12388         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
12389         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
12390         CVec_u8Z_free(arg_var);
12391         return arg_arr;
12392 }
12393
12394 uint32_t TS_UpdateFee_read(int8_tArray ser) {
12395         LDKu8slice ser_ref;
12396         ser_ref.datalen = *((uint32_t*)ser);
12397         ser_ref.data = (int8_t*)(ser + 4);
12398         LDKUpdateFee ret_var = UpdateFee_read(ser_ref);
12399         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12400         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12401         long ret_ref = (long)ret_var.inner;
12402         if (ret_var.is_owned) {
12403                 ret_ref |= 1;
12404         }
12405         return ret_ref;
12406 }
12407
12408 int8_tArray TS_UpdateFulfillHTLC_write(uint32_t obj) {
12409         LDKUpdateFulfillHTLC obj_conv;
12410         obj_conv.inner = (void*)(obj & (~1));
12411         obj_conv.is_owned = false;
12412         LDKCVec_u8Z arg_var = UpdateFulfillHTLC_write(&obj_conv);
12413         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
12414         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
12415         CVec_u8Z_free(arg_var);
12416         return arg_arr;
12417 }
12418
12419 uint32_t TS_UpdateFulfillHTLC_read(int8_tArray ser) {
12420         LDKu8slice ser_ref;
12421         ser_ref.datalen = *((uint32_t*)ser);
12422         ser_ref.data = (int8_t*)(ser + 4);
12423         LDKUpdateFulfillHTLC ret_var = UpdateFulfillHTLC_read(ser_ref);
12424         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12425         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12426         long ret_ref = (long)ret_var.inner;
12427         if (ret_var.is_owned) {
12428                 ret_ref |= 1;
12429         }
12430         return ret_ref;
12431 }
12432
12433 int8_tArray TS_UpdateAddHTLC_write(uint32_t obj) {
12434         LDKUpdateAddHTLC obj_conv;
12435         obj_conv.inner = (void*)(obj & (~1));
12436         obj_conv.is_owned = false;
12437         LDKCVec_u8Z arg_var = UpdateAddHTLC_write(&obj_conv);
12438         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
12439         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
12440         CVec_u8Z_free(arg_var);
12441         return arg_arr;
12442 }
12443
12444 uint32_t TS_UpdateAddHTLC_read(int8_tArray ser) {
12445         LDKu8slice ser_ref;
12446         ser_ref.datalen = *((uint32_t*)ser);
12447         ser_ref.data = (int8_t*)(ser + 4);
12448         LDKUpdateAddHTLC ret_var = UpdateAddHTLC_read(ser_ref);
12449         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12450         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12451         long ret_ref = (long)ret_var.inner;
12452         if (ret_var.is_owned) {
12453                 ret_ref |= 1;
12454         }
12455         return ret_ref;
12456 }
12457
12458 int8_tArray TS_Ping_write(uint32_t obj) {
12459         LDKPing obj_conv;
12460         obj_conv.inner = (void*)(obj & (~1));
12461         obj_conv.is_owned = false;
12462         LDKCVec_u8Z arg_var = Ping_write(&obj_conv);
12463         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
12464         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
12465         CVec_u8Z_free(arg_var);
12466         return arg_arr;
12467 }
12468
12469 uint32_t TS_Ping_read(int8_tArray ser) {
12470         LDKu8slice ser_ref;
12471         ser_ref.datalen = *((uint32_t*)ser);
12472         ser_ref.data = (int8_t*)(ser + 4);
12473         LDKCResult_PingDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_PingDecodeErrorZ), "LDKCResult_PingDecodeErrorZ");
12474         *ret_conv = Ping_read(ser_ref);
12475         return (long)ret_conv;
12476 }
12477
12478 int8_tArray TS_Pong_write(uint32_t obj) {
12479         LDKPong obj_conv;
12480         obj_conv.inner = (void*)(obj & (~1));
12481         obj_conv.is_owned = false;
12482         LDKCVec_u8Z arg_var = Pong_write(&obj_conv);
12483         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
12484         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
12485         CVec_u8Z_free(arg_var);
12486         return arg_arr;
12487 }
12488
12489 uint32_t TS_Pong_read(int8_tArray ser) {
12490         LDKu8slice ser_ref;
12491         ser_ref.datalen = *((uint32_t*)ser);
12492         ser_ref.data = (int8_t*)(ser + 4);
12493         LDKCResult_PongDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_PongDecodeErrorZ), "LDKCResult_PongDecodeErrorZ");
12494         *ret_conv = Pong_read(ser_ref);
12495         return (long)ret_conv;
12496 }
12497
12498 int8_tArray TS_UnsignedChannelAnnouncement_write(uint32_t obj) {
12499         LDKUnsignedChannelAnnouncement obj_conv;
12500         obj_conv.inner = (void*)(obj & (~1));
12501         obj_conv.is_owned = false;
12502         LDKCVec_u8Z arg_var = UnsignedChannelAnnouncement_write(&obj_conv);
12503         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
12504         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
12505         CVec_u8Z_free(arg_var);
12506         return arg_arr;
12507 }
12508
12509 uint32_t TS_UnsignedChannelAnnouncement_read(int8_tArray ser) {
12510         LDKu8slice ser_ref;
12511         ser_ref.datalen = *((uint32_t*)ser);
12512         ser_ref.data = (int8_t*)(ser + 4);
12513         LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ), "LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ");
12514         *ret_conv = UnsignedChannelAnnouncement_read(ser_ref);
12515         return (long)ret_conv;
12516 }
12517
12518 int8_tArray TS_ChannelAnnouncement_write(uint32_t obj) {
12519         LDKChannelAnnouncement obj_conv;
12520         obj_conv.inner = (void*)(obj & (~1));
12521         obj_conv.is_owned = false;
12522         LDKCVec_u8Z arg_var = ChannelAnnouncement_write(&obj_conv);
12523         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
12524         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
12525         CVec_u8Z_free(arg_var);
12526         return arg_arr;
12527 }
12528
12529 uint32_t TS_ChannelAnnouncement_read(int8_tArray ser) {
12530         LDKu8slice ser_ref;
12531         ser_ref.datalen = *((uint32_t*)ser);
12532         ser_ref.data = (int8_t*)(ser + 4);
12533         LDKChannelAnnouncement ret_var = ChannelAnnouncement_read(ser_ref);
12534         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12535         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12536         long ret_ref = (long)ret_var.inner;
12537         if (ret_var.is_owned) {
12538                 ret_ref |= 1;
12539         }
12540         return ret_ref;
12541 }
12542
12543 int8_tArray TS_UnsignedChannelUpdate_write(uint32_t obj) {
12544         LDKUnsignedChannelUpdate obj_conv;
12545         obj_conv.inner = (void*)(obj & (~1));
12546         obj_conv.is_owned = false;
12547         LDKCVec_u8Z arg_var = UnsignedChannelUpdate_write(&obj_conv);
12548         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
12549         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
12550         CVec_u8Z_free(arg_var);
12551         return arg_arr;
12552 }
12553
12554 uint32_t TS_UnsignedChannelUpdate_read(int8_tArray ser) {
12555         LDKu8slice ser_ref;
12556         ser_ref.datalen = *((uint32_t*)ser);
12557         ser_ref.data = (int8_t*)(ser + 4);
12558         LDKCResult_UnsignedChannelUpdateDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_UnsignedChannelUpdateDecodeErrorZ), "LDKCResult_UnsignedChannelUpdateDecodeErrorZ");
12559         *ret_conv = UnsignedChannelUpdate_read(ser_ref);
12560         return (long)ret_conv;
12561 }
12562
12563 int8_tArray TS_ChannelUpdate_write(uint32_t obj) {
12564         LDKChannelUpdate obj_conv;
12565         obj_conv.inner = (void*)(obj & (~1));
12566         obj_conv.is_owned = false;
12567         LDKCVec_u8Z arg_var = ChannelUpdate_write(&obj_conv);
12568         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
12569         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
12570         CVec_u8Z_free(arg_var);
12571         return arg_arr;
12572 }
12573
12574 uint32_t TS_ChannelUpdate_read(int8_tArray ser) {
12575         LDKu8slice ser_ref;
12576         ser_ref.datalen = *((uint32_t*)ser);
12577         ser_ref.data = (int8_t*)(ser + 4);
12578         LDKChannelUpdate ret_var = ChannelUpdate_read(ser_ref);
12579         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12580         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12581         long ret_ref = (long)ret_var.inner;
12582         if (ret_var.is_owned) {
12583                 ret_ref |= 1;
12584         }
12585         return ret_ref;
12586 }
12587
12588 int8_tArray TS_ErrorMessage_write(uint32_t obj) {
12589         LDKErrorMessage obj_conv;
12590         obj_conv.inner = (void*)(obj & (~1));
12591         obj_conv.is_owned = false;
12592         LDKCVec_u8Z arg_var = ErrorMessage_write(&obj_conv);
12593         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
12594         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
12595         CVec_u8Z_free(arg_var);
12596         return arg_arr;
12597 }
12598
12599 uint32_t TS_ErrorMessage_read(int8_tArray ser) {
12600         LDKu8slice ser_ref;
12601         ser_ref.datalen = *((uint32_t*)ser);
12602         ser_ref.data = (int8_t*)(ser + 4);
12603         LDKCResult_ErrorMessageDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ErrorMessageDecodeErrorZ), "LDKCResult_ErrorMessageDecodeErrorZ");
12604         *ret_conv = ErrorMessage_read(ser_ref);
12605         return (long)ret_conv;
12606 }
12607
12608 int8_tArray TS_UnsignedNodeAnnouncement_write(uint32_t obj) {
12609         LDKUnsignedNodeAnnouncement obj_conv;
12610         obj_conv.inner = (void*)(obj & (~1));
12611         obj_conv.is_owned = false;
12612         LDKCVec_u8Z arg_var = UnsignedNodeAnnouncement_write(&obj_conv);
12613         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
12614         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
12615         CVec_u8Z_free(arg_var);
12616         return arg_arr;
12617 }
12618
12619 uint32_t TS_UnsignedNodeAnnouncement_read(int8_tArray ser) {
12620         LDKu8slice ser_ref;
12621         ser_ref.datalen = *((uint32_t*)ser);
12622         ser_ref.data = (int8_t*)(ser + 4);
12623         LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ), "LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ");
12624         *ret_conv = UnsignedNodeAnnouncement_read(ser_ref);
12625         return (long)ret_conv;
12626 }
12627
12628 int8_tArray TS_NodeAnnouncement_write(uint32_t obj) {
12629         LDKNodeAnnouncement obj_conv;
12630         obj_conv.inner = (void*)(obj & (~1));
12631         obj_conv.is_owned = false;
12632         LDKCVec_u8Z arg_var = NodeAnnouncement_write(&obj_conv);
12633         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
12634         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
12635         CVec_u8Z_free(arg_var);
12636         return arg_arr;
12637 }
12638
12639 uint32_t TS_NodeAnnouncement_read(int8_tArray ser) {
12640         LDKu8slice ser_ref;
12641         ser_ref.datalen = *((uint32_t*)ser);
12642         ser_ref.data = (int8_t*)(ser + 4);
12643         LDKNodeAnnouncement ret_var = NodeAnnouncement_read(ser_ref);
12644         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12645         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12646         long ret_ref = (long)ret_var.inner;
12647         if (ret_var.is_owned) {
12648                 ret_ref |= 1;
12649         }
12650         return ret_ref;
12651 }
12652
12653 uint32_t TS_QueryShortChannelIds_read(int8_tArray ser) {
12654         LDKu8slice ser_ref;
12655         ser_ref.datalen = *((uint32_t*)ser);
12656         ser_ref.data = (int8_t*)(ser + 4);
12657         LDKCResult_QueryShortChannelIdsDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_QueryShortChannelIdsDecodeErrorZ), "LDKCResult_QueryShortChannelIdsDecodeErrorZ");
12658         *ret_conv = QueryShortChannelIds_read(ser_ref);
12659         return (long)ret_conv;
12660 }
12661
12662 int8_tArray TS_QueryShortChannelIds_write(uint32_t obj) {
12663         LDKQueryShortChannelIds obj_conv;
12664         obj_conv.inner = (void*)(obj & (~1));
12665         obj_conv.is_owned = false;
12666         LDKCVec_u8Z arg_var = QueryShortChannelIds_write(&obj_conv);
12667         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
12668         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
12669         CVec_u8Z_free(arg_var);
12670         return arg_arr;
12671 }
12672
12673 uint32_t TS_ReplyShortChannelIdsEnd_read(int8_tArray ser) {
12674         LDKu8slice ser_ref;
12675         ser_ref.datalen = *((uint32_t*)ser);
12676         ser_ref.data = (int8_t*)(ser + 4);
12677         LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ), "LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ");
12678         *ret_conv = ReplyShortChannelIdsEnd_read(ser_ref);
12679         return (long)ret_conv;
12680 }
12681
12682 int8_tArray TS_ReplyShortChannelIdsEnd_write(uint32_t obj) {
12683         LDKReplyShortChannelIdsEnd obj_conv;
12684         obj_conv.inner = (void*)(obj & (~1));
12685         obj_conv.is_owned = false;
12686         LDKCVec_u8Z arg_var = ReplyShortChannelIdsEnd_write(&obj_conv);
12687         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
12688         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
12689         CVec_u8Z_free(arg_var);
12690         return arg_arr;
12691 }
12692
12693 uint32_t TS_QueryChannelRange_read(int8_tArray ser) {
12694         LDKu8slice ser_ref;
12695         ser_ref.datalen = *((uint32_t*)ser);
12696         ser_ref.data = (int8_t*)(ser + 4);
12697         LDKCResult_QueryChannelRangeDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_QueryChannelRangeDecodeErrorZ), "LDKCResult_QueryChannelRangeDecodeErrorZ");
12698         *ret_conv = QueryChannelRange_read(ser_ref);
12699         return (long)ret_conv;
12700 }
12701
12702 int8_tArray TS_QueryChannelRange_write(uint32_t obj) {
12703         LDKQueryChannelRange obj_conv;
12704         obj_conv.inner = (void*)(obj & (~1));
12705         obj_conv.is_owned = false;
12706         LDKCVec_u8Z arg_var = QueryChannelRange_write(&obj_conv);
12707         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
12708         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
12709         CVec_u8Z_free(arg_var);
12710         return arg_arr;
12711 }
12712
12713 uint32_t TS_ReplyChannelRange_read(int8_tArray ser) {
12714         LDKu8slice ser_ref;
12715         ser_ref.datalen = *((uint32_t*)ser);
12716         ser_ref.data = (int8_t*)(ser + 4);
12717         LDKCResult_ReplyChannelRangeDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ReplyChannelRangeDecodeErrorZ), "LDKCResult_ReplyChannelRangeDecodeErrorZ");
12718         *ret_conv = ReplyChannelRange_read(ser_ref);
12719         return (long)ret_conv;
12720 }
12721
12722 int8_tArray TS_ReplyChannelRange_write(uint32_t obj) {
12723         LDKReplyChannelRange obj_conv;
12724         obj_conv.inner = (void*)(obj & (~1));
12725         obj_conv.is_owned = false;
12726         LDKCVec_u8Z arg_var = ReplyChannelRange_write(&obj_conv);
12727         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
12728         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
12729         CVec_u8Z_free(arg_var);
12730         return arg_arr;
12731 }
12732
12733 uint32_t TS_GossipTimestampFilter_read(int8_tArray ser) {
12734         LDKu8slice ser_ref;
12735         ser_ref.datalen = *((uint32_t*)ser);
12736         ser_ref.data = (int8_t*)(ser + 4);
12737         LDKCResult_GossipTimestampFilterDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_GossipTimestampFilterDecodeErrorZ), "LDKCResult_GossipTimestampFilterDecodeErrorZ");
12738         *ret_conv = GossipTimestampFilter_read(ser_ref);
12739         return (long)ret_conv;
12740 }
12741
12742 int8_tArray TS_GossipTimestampFilter_write(uint32_t obj) {
12743         LDKGossipTimestampFilter obj_conv;
12744         obj_conv.inner = (void*)(obj & (~1));
12745         obj_conv.is_owned = false;
12746         LDKCVec_u8Z arg_var = GossipTimestampFilter_write(&obj_conv);
12747         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
12748         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
12749         CVec_u8Z_free(arg_var);
12750         return arg_arr;
12751 }
12752
12753 void TS_MessageHandler_free(uint32_t this_ptr) {
12754         LDKMessageHandler this_ptr_conv;
12755         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12756         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12757         MessageHandler_free(this_ptr_conv);
12758 }
12759
12760 uint32_t TS_MessageHandler_get_chan_handler(uint32_t this_ptr) {
12761         LDKMessageHandler this_ptr_conv;
12762         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12763         this_ptr_conv.is_owned = false;
12764         long ret_ret = (long)MessageHandler_get_chan_handler(&this_ptr_conv);
12765         return ret_ret;
12766 }
12767
12768 void TS_MessageHandler_set_chan_handler(uint32_t this_ptr, uint32_t val) {
12769         LDKMessageHandler this_ptr_conv;
12770         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12771         this_ptr_conv.is_owned = false;
12772         LDKChannelMessageHandler val_conv = *(LDKChannelMessageHandler*)val;
12773         MessageHandler_set_chan_handler(&this_ptr_conv, val_conv);
12774 }
12775
12776 uint32_t TS_MessageHandler_get_route_handler(uint32_t this_ptr) {
12777         LDKMessageHandler this_ptr_conv;
12778         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12779         this_ptr_conv.is_owned = false;
12780         long ret_ret = (long)MessageHandler_get_route_handler(&this_ptr_conv);
12781         return ret_ret;
12782 }
12783
12784 void TS_MessageHandler_set_route_handler(uint32_t this_ptr, uint32_t val) {
12785         LDKMessageHandler this_ptr_conv;
12786         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12787         this_ptr_conv.is_owned = false;
12788         LDKRoutingMessageHandler val_conv = *(LDKRoutingMessageHandler*)val;
12789         MessageHandler_set_route_handler(&this_ptr_conv, val_conv);
12790 }
12791
12792 uint32_t TS_MessageHandler_new(uint32_t chan_handler_arg, uint32_t route_handler_arg) {
12793         LDKChannelMessageHandler chan_handler_arg_conv = *(LDKChannelMessageHandler*)chan_handler_arg;
12794         LDKRoutingMessageHandler route_handler_arg_conv = *(LDKRoutingMessageHandler*)route_handler_arg;
12795         LDKMessageHandler ret_var = MessageHandler_new(chan_handler_arg_conv, route_handler_arg_conv);
12796         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12797         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12798         long ret_ref = (long)ret_var.inner;
12799         if (ret_var.is_owned) {
12800                 ret_ref |= 1;
12801         }
12802         return ret_ref;
12803 }
12804
12805 uint32_t TS_SocketDescriptor_clone(uint32_t orig) {
12806         LDKSocketDescriptor* orig_conv = (LDKSocketDescriptor*)orig;
12807         LDKSocketDescriptor* ret = MALLOC(sizeof(LDKSocketDescriptor), "LDKSocketDescriptor");
12808         *ret = SocketDescriptor_clone(orig_conv);
12809         return (long)ret;
12810 }
12811
12812 void TS_SocketDescriptor_free(uint32_t this_ptr) {
12813         LDKSocketDescriptor this_ptr_conv = *(LDKSocketDescriptor*)this_ptr;
12814         FREE((void*)this_ptr);
12815         SocketDescriptor_free(this_ptr_conv);
12816 }
12817
12818 void TS_PeerHandleError_free(uint32_t this_ptr) {
12819         LDKPeerHandleError this_ptr_conv;
12820         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12821         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12822         PeerHandleError_free(this_ptr_conv);
12823 }
12824
12825 jboolean TS_PeerHandleError_get_no_connection_possible(uint32_t this_ptr) {
12826         LDKPeerHandleError this_ptr_conv;
12827         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12828         this_ptr_conv.is_owned = false;
12829         jboolean ret_val = PeerHandleError_get_no_connection_possible(&this_ptr_conv);
12830         return ret_val;
12831 }
12832
12833 void TS_PeerHandleError_set_no_connection_possible(uint32_t this_ptr, jboolean val) {
12834         LDKPeerHandleError this_ptr_conv;
12835         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12836         this_ptr_conv.is_owned = false;
12837         PeerHandleError_set_no_connection_possible(&this_ptr_conv, val);
12838 }
12839
12840 uint32_t TS_PeerHandleError_new(jboolean no_connection_possible_arg) {
12841         LDKPeerHandleError ret_var = PeerHandleError_new(no_connection_possible_arg);
12842         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12843         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12844         long ret_ref = (long)ret_var.inner;
12845         if (ret_var.is_owned) {
12846                 ret_ref |= 1;
12847         }
12848         return ret_ref;
12849 }
12850
12851 void TS_PeerManager_free(uint32_t this_ptr) {
12852         LDKPeerManager this_ptr_conv;
12853         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12854         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12855         PeerManager_free(this_ptr_conv);
12856 }
12857
12858 uint32_t TS_PeerManager_new(uint32_t message_handler, int8_tArray our_node_secret, int8_tArray ephemeral_random_data, uint32_t logger) {
12859         LDKMessageHandler message_handler_conv;
12860         message_handler_conv.inner = (void*)(message_handler & (~1));
12861         message_handler_conv.is_owned = (message_handler & 1) || (message_handler == 0);
12862         // Warning: we may need a move here but can't clone!
12863         LDKSecretKey our_node_secret_ref;
12864         CHECK(*((uint32_t*)our_node_secret) == 32);
12865         memcpy(our_node_secret_ref.bytes, (uint8_t*)(our_node_secret + 4), 32);
12866         unsigned char ephemeral_random_data_arr[32];
12867         CHECK(*((uint32_t*)ephemeral_random_data) == 32);
12868         memcpy(ephemeral_random_data_arr, (uint8_t*)(ephemeral_random_data + 4), 32);
12869         unsigned char (*ephemeral_random_data_ref)[32] = &ephemeral_random_data_arr;
12870         LDKLogger logger_conv = *(LDKLogger*)logger;
12871         LDKPeerManager ret_var = PeerManager_new(message_handler_conv, our_node_secret_ref, ephemeral_random_data_ref, logger_conv);
12872         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12873         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12874         long ret_ref = (long)ret_var.inner;
12875         if (ret_var.is_owned) {
12876                 ret_ref |= 1;
12877         }
12878         return ret_ref;
12879 }
12880
12881 ptrArray TS_PeerManager_get_peer_node_ids(uint32_t this_arg) {
12882         LDKPeerManager this_arg_conv;
12883         this_arg_conv.inner = (void*)(this_arg & (~1));
12884         this_arg_conv.is_owned = false;
12885         LDKCVec_PublicKeyZ ret_var = PeerManager_get_peer_node_ids(&this_arg_conv);
12886         ptrArray ret_arr = init_arr(ret_var.datalen, sizeof(uint32_t), "Native ptrArray Bytes");
12887         int8_tArray *ret_arr_ptr = (int8_tArray*)(ret_arr + 4);
12888         for (size_t m = 0; m < ret_var.datalen; m++) {
12889                 int8_tArray arr_conv_12_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
12890                 memcpy((uint8_t*)(arr_conv_12_arr + 4), ret_var.data[m].compressed_form, 33);
12891                 ret_arr_ptr[m] = arr_conv_12_arr;
12892         }
12893         FREE(ret_var.data);
12894         return ret_arr;
12895 }
12896
12897 uint32_t TS_PeerManager_new_outbound_connection(uint32_t this_arg, int8_tArray their_node_id, uint32_t descriptor) {
12898         LDKPeerManager this_arg_conv;
12899         this_arg_conv.inner = (void*)(this_arg & (~1));
12900         this_arg_conv.is_owned = false;
12901         LDKPublicKey their_node_id_ref;
12902         CHECK(*((uint32_t*)their_node_id) == 33);
12903         memcpy(their_node_id_ref.compressed_form, (uint8_t*)(their_node_id + 4), 33);
12904         LDKSocketDescriptor descriptor_conv = *(LDKSocketDescriptor*)descriptor;
12905         LDKCResult_CVec_u8ZPeerHandleErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_CVec_u8ZPeerHandleErrorZ), "LDKCResult_CVec_u8ZPeerHandleErrorZ");
12906         *ret_conv = PeerManager_new_outbound_connection(&this_arg_conv, their_node_id_ref, descriptor_conv);
12907         return (long)ret_conv;
12908 }
12909
12910 uint32_t TS_PeerManager_new_inbound_connection(uint32_t this_arg, uint32_t descriptor) {
12911         LDKPeerManager this_arg_conv;
12912         this_arg_conv.inner = (void*)(this_arg & (~1));
12913         this_arg_conv.is_owned = false;
12914         LDKSocketDescriptor descriptor_conv = *(LDKSocketDescriptor*)descriptor;
12915         LDKCResult_NonePeerHandleErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NonePeerHandleErrorZ), "LDKCResult_NonePeerHandleErrorZ");
12916         *ret_conv = PeerManager_new_inbound_connection(&this_arg_conv, descriptor_conv);
12917         return (long)ret_conv;
12918 }
12919
12920 uint32_t TS_PeerManager_write_buffer_space_avail(uint32_t this_arg, 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         LDKSocketDescriptor* descriptor_conv = (LDKSocketDescriptor*)descriptor;
12925         LDKCResult_NonePeerHandleErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NonePeerHandleErrorZ), "LDKCResult_NonePeerHandleErrorZ");
12926         *ret_conv = PeerManager_write_buffer_space_avail(&this_arg_conv, descriptor_conv);
12927         return (long)ret_conv;
12928 }
12929
12930 uint32_t TS_PeerManager_read_event(uint32_t this_arg, uint32_t peer_descriptor, int8_tArray data) {
12931         LDKPeerManager this_arg_conv;
12932         this_arg_conv.inner = (void*)(this_arg & (~1));
12933         this_arg_conv.is_owned = false;
12934         LDKSocketDescriptor* peer_descriptor_conv = (LDKSocketDescriptor*)peer_descriptor;
12935         LDKu8slice data_ref;
12936         data_ref.datalen = *((uint32_t*)data);
12937         data_ref.data = (int8_t*)(data + 4);
12938         LDKCResult_boolPeerHandleErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_boolPeerHandleErrorZ), "LDKCResult_boolPeerHandleErrorZ");
12939         *ret_conv = PeerManager_read_event(&this_arg_conv, peer_descriptor_conv, data_ref);
12940         return (long)ret_conv;
12941 }
12942
12943 void TS_PeerManager_process_events(uint32_t this_arg) {
12944         LDKPeerManager this_arg_conv;
12945         this_arg_conv.inner = (void*)(this_arg & (~1));
12946         this_arg_conv.is_owned = false;
12947         PeerManager_process_events(&this_arg_conv);
12948 }
12949
12950 void TS_PeerManager_socket_disconnected(uint32_t this_arg, uint32_t descriptor) {
12951         LDKPeerManager this_arg_conv;
12952         this_arg_conv.inner = (void*)(this_arg & (~1));
12953         this_arg_conv.is_owned = false;
12954         LDKSocketDescriptor* descriptor_conv = (LDKSocketDescriptor*)descriptor;
12955         PeerManager_socket_disconnected(&this_arg_conv, descriptor_conv);
12956 }
12957
12958 void TS_PeerManager_timer_tick_occured(uint32_t this_arg) {
12959         LDKPeerManager this_arg_conv;
12960         this_arg_conv.inner = (void*)(this_arg & (~1));
12961         this_arg_conv.is_owned = false;
12962         PeerManager_timer_tick_occured(&this_arg_conv);
12963 }
12964
12965 int8_tArray TS_build_commitment_secret(int8_tArray commitment_seed, int64_t idx) {
12966         unsigned char commitment_seed_arr[32];
12967         CHECK(*((uint32_t*)commitment_seed) == 32);
12968         memcpy(commitment_seed_arr, (uint8_t*)(commitment_seed + 4), 32);
12969         unsigned char (*commitment_seed_ref)[32] = &commitment_seed_arr;
12970         int8_tArray arg_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
12971         memcpy((uint8_t*)(arg_arr + 4), build_commitment_secret(commitment_seed_ref, idx).data, 32);
12972         return arg_arr;
12973 }
12974
12975 uint32_t TS_derive_private_key(int8_tArray per_commitment_point, int8_tArray base_secret) {
12976         LDKPublicKey per_commitment_point_ref;
12977         CHECK(*((uint32_t*)per_commitment_point) == 33);
12978         memcpy(per_commitment_point_ref.compressed_form, (uint8_t*)(per_commitment_point + 4), 33);
12979         unsigned char base_secret_arr[32];
12980         CHECK(*((uint32_t*)base_secret) == 32);
12981         memcpy(base_secret_arr, (uint8_t*)(base_secret + 4), 32);
12982         unsigned char (*base_secret_ref)[32] = &base_secret_arr;
12983         LDKCResult_SecretKeySecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_SecretKeySecpErrorZ), "LDKCResult_SecretKeySecpErrorZ");
12984         *ret_conv = derive_private_key(per_commitment_point_ref, base_secret_ref);
12985         return (long)ret_conv;
12986 }
12987
12988 uint32_t TS_derive_public_key(int8_tArray per_commitment_point, int8_tArray base_point) {
12989         LDKPublicKey per_commitment_point_ref;
12990         CHECK(*((uint32_t*)per_commitment_point) == 33);
12991         memcpy(per_commitment_point_ref.compressed_form, (uint8_t*)(per_commitment_point + 4), 33);
12992         LDKPublicKey base_point_ref;
12993         CHECK(*((uint32_t*)base_point) == 33);
12994         memcpy(base_point_ref.compressed_form, (uint8_t*)(base_point + 4), 33);
12995         LDKCResult_PublicKeySecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_PublicKeySecpErrorZ), "LDKCResult_PublicKeySecpErrorZ");
12996         *ret_conv = derive_public_key(per_commitment_point_ref, base_point_ref);
12997         return (long)ret_conv;
12998 }
12999
13000 uint32_t TS_derive_private_revocation_key(int8_tArray per_commitment_secret, int8_tArray countersignatory_revocation_base_secret) {
13001         unsigned char per_commitment_secret_arr[32];
13002         CHECK(*((uint32_t*)per_commitment_secret) == 32);
13003         memcpy(per_commitment_secret_arr, (uint8_t*)(per_commitment_secret + 4), 32);
13004         unsigned char (*per_commitment_secret_ref)[32] = &per_commitment_secret_arr;
13005         unsigned char countersignatory_revocation_base_secret_arr[32];
13006         CHECK(*((uint32_t*)countersignatory_revocation_base_secret) == 32);
13007         memcpy(countersignatory_revocation_base_secret_arr, (uint8_t*)(countersignatory_revocation_base_secret + 4), 32);
13008         unsigned char (*countersignatory_revocation_base_secret_ref)[32] = &countersignatory_revocation_base_secret_arr;
13009         LDKCResult_SecretKeySecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_SecretKeySecpErrorZ), "LDKCResult_SecretKeySecpErrorZ");
13010         *ret_conv = derive_private_revocation_key(per_commitment_secret_ref, countersignatory_revocation_base_secret_ref);
13011         return (long)ret_conv;
13012 }
13013
13014 uint32_t TS_derive_public_revocation_key(int8_tArray per_commitment_point, int8_tArray countersignatory_revocation_base_point) {
13015         LDKPublicKey per_commitment_point_ref;
13016         CHECK(*((uint32_t*)per_commitment_point) == 33);
13017         memcpy(per_commitment_point_ref.compressed_form, (uint8_t*)(per_commitment_point + 4), 33);
13018         LDKPublicKey countersignatory_revocation_base_point_ref;
13019         CHECK(*((uint32_t*)countersignatory_revocation_base_point) == 33);
13020         memcpy(countersignatory_revocation_base_point_ref.compressed_form, (uint8_t*)(countersignatory_revocation_base_point + 4), 33);
13021         LDKCResult_PublicKeySecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_PublicKeySecpErrorZ), "LDKCResult_PublicKeySecpErrorZ");
13022         *ret_conv = derive_public_revocation_key(per_commitment_point_ref, countersignatory_revocation_base_point_ref);
13023         return (long)ret_conv;
13024 }
13025
13026 void TS_TxCreationKeys_free(uint32_t this_ptr) {
13027         LDKTxCreationKeys this_ptr_conv;
13028         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13029         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13030         TxCreationKeys_free(this_ptr_conv);
13031 }
13032
13033 uint32_t TS_TxCreationKeys_clone(uint32_t orig) {
13034         LDKTxCreationKeys orig_conv;
13035         orig_conv.inner = (void*)(orig & (~1));
13036         orig_conv.is_owned = false;
13037         LDKTxCreationKeys ret_var = TxCreationKeys_clone(&orig_conv);
13038         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13039         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13040         long ret_ref = (long)ret_var.inner;
13041         if (ret_var.is_owned) {
13042                 ret_ref |= 1;
13043         }
13044         return ret_ref;
13045 }
13046
13047 int8_tArray TS_TxCreationKeys_get_per_commitment_point(uint32_t this_ptr) {
13048         LDKTxCreationKeys this_ptr_conv;
13049         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13050         this_ptr_conv.is_owned = false;
13051         int8_tArray arg_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
13052         memcpy((uint8_t*)(arg_arr + 4), TxCreationKeys_get_per_commitment_point(&this_ptr_conv).compressed_form, 33);
13053         return arg_arr;
13054 }
13055
13056 void TS_TxCreationKeys_set_per_commitment_point(uint32_t this_ptr, int8_tArray val) {
13057         LDKTxCreationKeys this_ptr_conv;
13058         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13059         this_ptr_conv.is_owned = false;
13060         LDKPublicKey val_ref;
13061         CHECK(*((uint32_t*)val) == 33);
13062         memcpy(val_ref.compressed_form, (uint8_t*)(val + 4), 33);
13063         TxCreationKeys_set_per_commitment_point(&this_ptr_conv, val_ref);
13064 }
13065
13066 int8_tArray TS_TxCreationKeys_get_revocation_key(uint32_t this_ptr) {
13067         LDKTxCreationKeys this_ptr_conv;
13068         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13069         this_ptr_conv.is_owned = false;
13070         int8_tArray arg_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
13071         memcpy((uint8_t*)(arg_arr + 4), TxCreationKeys_get_revocation_key(&this_ptr_conv).compressed_form, 33);
13072         return arg_arr;
13073 }
13074
13075 void TS_TxCreationKeys_set_revocation_key(uint32_t this_ptr, int8_tArray val) {
13076         LDKTxCreationKeys this_ptr_conv;
13077         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13078         this_ptr_conv.is_owned = false;
13079         LDKPublicKey val_ref;
13080         CHECK(*((uint32_t*)val) == 33);
13081         memcpy(val_ref.compressed_form, (uint8_t*)(val + 4), 33);
13082         TxCreationKeys_set_revocation_key(&this_ptr_conv, val_ref);
13083 }
13084
13085 int8_tArray TS_TxCreationKeys_get_broadcaster_htlc_key(uint32_t this_ptr) {
13086         LDKTxCreationKeys this_ptr_conv;
13087         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13088         this_ptr_conv.is_owned = false;
13089         int8_tArray arg_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
13090         memcpy((uint8_t*)(arg_arr + 4), TxCreationKeys_get_broadcaster_htlc_key(&this_ptr_conv).compressed_form, 33);
13091         return arg_arr;
13092 }
13093
13094 void TS_TxCreationKeys_set_broadcaster_htlc_key(uint32_t this_ptr, int8_tArray val) {
13095         LDKTxCreationKeys this_ptr_conv;
13096         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13097         this_ptr_conv.is_owned = false;
13098         LDKPublicKey val_ref;
13099         CHECK(*((uint32_t*)val) == 33);
13100         memcpy(val_ref.compressed_form, (uint8_t*)(val + 4), 33);
13101         TxCreationKeys_set_broadcaster_htlc_key(&this_ptr_conv, val_ref);
13102 }
13103
13104 int8_tArray TS_TxCreationKeys_get_countersignatory_htlc_key(uint32_t this_ptr) {
13105         LDKTxCreationKeys this_ptr_conv;
13106         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13107         this_ptr_conv.is_owned = false;
13108         int8_tArray arg_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
13109         memcpy((uint8_t*)(arg_arr + 4), TxCreationKeys_get_countersignatory_htlc_key(&this_ptr_conv).compressed_form, 33);
13110         return arg_arr;
13111 }
13112
13113 void TS_TxCreationKeys_set_countersignatory_htlc_key(uint32_t this_ptr, int8_tArray val) {
13114         LDKTxCreationKeys this_ptr_conv;
13115         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13116         this_ptr_conv.is_owned = false;
13117         LDKPublicKey val_ref;
13118         CHECK(*((uint32_t*)val) == 33);
13119         memcpy(val_ref.compressed_form, (uint8_t*)(val + 4), 33);
13120         TxCreationKeys_set_countersignatory_htlc_key(&this_ptr_conv, val_ref);
13121 }
13122
13123 int8_tArray TS_TxCreationKeys_get_broadcaster_delayed_payment_key(uint32_t this_ptr) {
13124         LDKTxCreationKeys this_ptr_conv;
13125         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13126         this_ptr_conv.is_owned = false;
13127         int8_tArray arg_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
13128         memcpy((uint8_t*)(arg_arr + 4), TxCreationKeys_get_broadcaster_delayed_payment_key(&this_ptr_conv).compressed_form, 33);
13129         return arg_arr;
13130 }
13131
13132 void TS_TxCreationKeys_set_broadcaster_delayed_payment_key(uint32_t this_ptr, int8_tArray val) {
13133         LDKTxCreationKeys this_ptr_conv;
13134         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13135         this_ptr_conv.is_owned = false;
13136         LDKPublicKey val_ref;
13137         CHECK(*((uint32_t*)val) == 33);
13138         memcpy(val_ref.compressed_form, (uint8_t*)(val + 4), 33);
13139         TxCreationKeys_set_broadcaster_delayed_payment_key(&this_ptr_conv, val_ref);
13140 }
13141
13142 uint32_t TS_TxCreationKeys_new(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) {
13143         LDKPublicKey per_commitment_point_arg_ref;
13144         CHECK(*((uint32_t*)per_commitment_point_arg) == 33);
13145         memcpy(per_commitment_point_arg_ref.compressed_form, (uint8_t*)(per_commitment_point_arg + 4), 33);
13146         LDKPublicKey revocation_key_arg_ref;
13147         CHECK(*((uint32_t*)revocation_key_arg) == 33);
13148         memcpy(revocation_key_arg_ref.compressed_form, (uint8_t*)(revocation_key_arg + 4), 33);
13149         LDKPublicKey broadcaster_htlc_key_arg_ref;
13150         CHECK(*((uint32_t*)broadcaster_htlc_key_arg) == 33);
13151         memcpy(broadcaster_htlc_key_arg_ref.compressed_form, (uint8_t*)(broadcaster_htlc_key_arg + 4), 33);
13152         LDKPublicKey countersignatory_htlc_key_arg_ref;
13153         CHECK(*((uint32_t*)countersignatory_htlc_key_arg) == 33);
13154         memcpy(countersignatory_htlc_key_arg_ref.compressed_form, (uint8_t*)(countersignatory_htlc_key_arg + 4), 33);
13155         LDKPublicKey broadcaster_delayed_payment_key_arg_ref;
13156         CHECK(*((uint32_t*)broadcaster_delayed_payment_key_arg) == 33);
13157         memcpy(broadcaster_delayed_payment_key_arg_ref.compressed_form, (uint8_t*)(broadcaster_delayed_payment_key_arg + 4), 33);
13158         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);
13159         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13160         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13161         long ret_ref = (long)ret_var.inner;
13162         if (ret_var.is_owned) {
13163                 ret_ref |= 1;
13164         }
13165         return ret_ref;
13166 }
13167
13168 int8_tArray TS_TxCreationKeys_write(uint32_t obj) {
13169         LDKTxCreationKeys obj_conv;
13170         obj_conv.inner = (void*)(obj & (~1));
13171         obj_conv.is_owned = false;
13172         LDKCVec_u8Z arg_var = TxCreationKeys_write(&obj_conv);
13173         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
13174         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
13175         CVec_u8Z_free(arg_var);
13176         return arg_arr;
13177 }
13178
13179 uint32_t TS_TxCreationKeys_read(int8_tArray ser) {
13180         LDKu8slice ser_ref;
13181         ser_ref.datalen = *((uint32_t*)ser);
13182         ser_ref.data = (int8_t*)(ser + 4);
13183         LDKTxCreationKeys ret_var = TxCreationKeys_read(ser_ref);
13184         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13185         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13186         long ret_ref = (long)ret_var.inner;
13187         if (ret_var.is_owned) {
13188                 ret_ref |= 1;
13189         }
13190         return ret_ref;
13191 }
13192
13193 void TS_ChannelPublicKeys_free(uint32_t this_ptr) {
13194         LDKChannelPublicKeys this_ptr_conv;
13195         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13196         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13197         ChannelPublicKeys_free(this_ptr_conv);
13198 }
13199
13200 uint32_t TS_ChannelPublicKeys_clone(uint32_t orig) {
13201         LDKChannelPublicKeys orig_conv;
13202         orig_conv.inner = (void*)(orig & (~1));
13203         orig_conv.is_owned = false;
13204         LDKChannelPublicKeys ret_var = ChannelPublicKeys_clone(&orig_conv);
13205         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13206         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13207         long ret_ref = (long)ret_var.inner;
13208         if (ret_var.is_owned) {
13209                 ret_ref |= 1;
13210         }
13211         return ret_ref;
13212 }
13213
13214 int8_tArray TS_ChannelPublicKeys_get_funding_pubkey(uint32_t this_ptr) {
13215         LDKChannelPublicKeys this_ptr_conv;
13216         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13217         this_ptr_conv.is_owned = false;
13218         int8_tArray arg_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
13219         memcpy((uint8_t*)(arg_arr + 4), ChannelPublicKeys_get_funding_pubkey(&this_ptr_conv).compressed_form, 33);
13220         return arg_arr;
13221 }
13222
13223 void TS_ChannelPublicKeys_set_funding_pubkey(uint32_t this_ptr, int8_tArray val) {
13224         LDKChannelPublicKeys this_ptr_conv;
13225         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13226         this_ptr_conv.is_owned = false;
13227         LDKPublicKey val_ref;
13228         CHECK(*((uint32_t*)val) == 33);
13229         memcpy(val_ref.compressed_form, (uint8_t*)(val + 4), 33);
13230         ChannelPublicKeys_set_funding_pubkey(&this_ptr_conv, val_ref);
13231 }
13232
13233 int8_tArray TS_ChannelPublicKeys_get_revocation_basepoint(uint32_t this_ptr) {
13234         LDKChannelPublicKeys this_ptr_conv;
13235         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13236         this_ptr_conv.is_owned = false;
13237         int8_tArray arg_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
13238         memcpy((uint8_t*)(arg_arr + 4), ChannelPublicKeys_get_revocation_basepoint(&this_ptr_conv).compressed_form, 33);
13239         return arg_arr;
13240 }
13241
13242 void TS_ChannelPublicKeys_set_revocation_basepoint(uint32_t this_ptr, int8_tArray val) {
13243         LDKChannelPublicKeys this_ptr_conv;
13244         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13245         this_ptr_conv.is_owned = false;
13246         LDKPublicKey val_ref;
13247         CHECK(*((uint32_t*)val) == 33);
13248         memcpy(val_ref.compressed_form, (uint8_t*)(val + 4), 33);
13249         ChannelPublicKeys_set_revocation_basepoint(&this_ptr_conv, val_ref);
13250 }
13251
13252 int8_tArray TS_ChannelPublicKeys_get_payment_point(uint32_t this_ptr) {
13253         LDKChannelPublicKeys this_ptr_conv;
13254         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13255         this_ptr_conv.is_owned = false;
13256         int8_tArray arg_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
13257         memcpy((uint8_t*)(arg_arr + 4), ChannelPublicKeys_get_payment_point(&this_ptr_conv).compressed_form, 33);
13258         return arg_arr;
13259 }
13260
13261 void TS_ChannelPublicKeys_set_payment_point(uint32_t this_ptr, int8_tArray val) {
13262         LDKChannelPublicKeys this_ptr_conv;
13263         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13264         this_ptr_conv.is_owned = false;
13265         LDKPublicKey val_ref;
13266         CHECK(*((uint32_t*)val) == 33);
13267         memcpy(val_ref.compressed_form, (uint8_t*)(val + 4), 33);
13268         ChannelPublicKeys_set_payment_point(&this_ptr_conv, val_ref);
13269 }
13270
13271 int8_tArray TS_ChannelPublicKeys_get_delayed_payment_basepoint(uint32_t this_ptr) {
13272         LDKChannelPublicKeys this_ptr_conv;
13273         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13274         this_ptr_conv.is_owned = false;
13275         int8_tArray arg_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
13276         memcpy((uint8_t*)(arg_arr + 4), ChannelPublicKeys_get_delayed_payment_basepoint(&this_ptr_conv).compressed_form, 33);
13277         return arg_arr;
13278 }
13279
13280 void TS_ChannelPublicKeys_set_delayed_payment_basepoint(uint32_t this_ptr, int8_tArray val) {
13281         LDKChannelPublicKeys this_ptr_conv;
13282         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13283         this_ptr_conv.is_owned = false;
13284         LDKPublicKey val_ref;
13285         CHECK(*((uint32_t*)val) == 33);
13286         memcpy(val_ref.compressed_form, (uint8_t*)(val + 4), 33);
13287         ChannelPublicKeys_set_delayed_payment_basepoint(&this_ptr_conv, val_ref);
13288 }
13289
13290 int8_tArray TS_ChannelPublicKeys_get_htlc_basepoint(uint32_t this_ptr) {
13291         LDKChannelPublicKeys this_ptr_conv;
13292         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13293         this_ptr_conv.is_owned = false;
13294         int8_tArray arg_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
13295         memcpy((uint8_t*)(arg_arr + 4), ChannelPublicKeys_get_htlc_basepoint(&this_ptr_conv).compressed_form, 33);
13296         return arg_arr;
13297 }
13298
13299 void TS_ChannelPublicKeys_set_htlc_basepoint(uint32_t this_ptr, int8_tArray val) {
13300         LDKChannelPublicKeys this_ptr_conv;
13301         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13302         this_ptr_conv.is_owned = false;
13303         LDKPublicKey val_ref;
13304         CHECK(*((uint32_t*)val) == 33);
13305         memcpy(val_ref.compressed_form, (uint8_t*)(val + 4), 33);
13306         ChannelPublicKeys_set_htlc_basepoint(&this_ptr_conv, val_ref);
13307 }
13308
13309 uint32_t TS_ChannelPublicKeys_new(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) {
13310         LDKPublicKey funding_pubkey_arg_ref;
13311         CHECK(*((uint32_t*)funding_pubkey_arg) == 33);
13312         memcpy(funding_pubkey_arg_ref.compressed_form, (uint8_t*)(funding_pubkey_arg + 4), 33);
13313         LDKPublicKey revocation_basepoint_arg_ref;
13314         CHECK(*((uint32_t*)revocation_basepoint_arg) == 33);
13315         memcpy(revocation_basepoint_arg_ref.compressed_form, (uint8_t*)(revocation_basepoint_arg + 4), 33);
13316         LDKPublicKey payment_point_arg_ref;
13317         CHECK(*((uint32_t*)payment_point_arg) == 33);
13318         memcpy(payment_point_arg_ref.compressed_form, (uint8_t*)(payment_point_arg + 4), 33);
13319         LDKPublicKey delayed_payment_basepoint_arg_ref;
13320         CHECK(*((uint32_t*)delayed_payment_basepoint_arg) == 33);
13321         memcpy(delayed_payment_basepoint_arg_ref.compressed_form, (uint8_t*)(delayed_payment_basepoint_arg + 4), 33);
13322         LDKPublicKey htlc_basepoint_arg_ref;
13323         CHECK(*((uint32_t*)htlc_basepoint_arg) == 33);
13324         memcpy(htlc_basepoint_arg_ref.compressed_form, (uint8_t*)(htlc_basepoint_arg + 4), 33);
13325         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);
13326         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13327         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13328         long ret_ref = (long)ret_var.inner;
13329         if (ret_var.is_owned) {
13330                 ret_ref |= 1;
13331         }
13332         return ret_ref;
13333 }
13334
13335 int8_tArray TS_ChannelPublicKeys_write(uint32_t obj) {
13336         LDKChannelPublicKeys obj_conv;
13337         obj_conv.inner = (void*)(obj & (~1));
13338         obj_conv.is_owned = false;
13339         LDKCVec_u8Z arg_var = ChannelPublicKeys_write(&obj_conv);
13340         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
13341         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
13342         CVec_u8Z_free(arg_var);
13343         return arg_arr;
13344 }
13345
13346 uint32_t TS_ChannelPublicKeys_read(int8_tArray ser) {
13347         LDKu8slice ser_ref;
13348         ser_ref.datalen = *((uint32_t*)ser);
13349         ser_ref.data = (int8_t*)(ser + 4);
13350         LDKChannelPublicKeys ret_var = ChannelPublicKeys_read(ser_ref);
13351         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13352         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13353         long ret_ref = (long)ret_var.inner;
13354         if (ret_var.is_owned) {
13355                 ret_ref |= 1;
13356         }
13357         return ret_ref;
13358 }
13359
13360 uint32_t TS_TxCreationKeys_derive_new(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) {
13361         LDKPublicKey per_commitment_point_ref;
13362         CHECK(*((uint32_t*)per_commitment_point) == 33);
13363         memcpy(per_commitment_point_ref.compressed_form, (uint8_t*)(per_commitment_point + 4), 33);
13364         LDKPublicKey broadcaster_delayed_payment_base_ref;
13365         CHECK(*((uint32_t*)broadcaster_delayed_payment_base) == 33);
13366         memcpy(broadcaster_delayed_payment_base_ref.compressed_form, (uint8_t*)(broadcaster_delayed_payment_base + 4), 33);
13367         LDKPublicKey broadcaster_htlc_base_ref;
13368         CHECK(*((uint32_t*)broadcaster_htlc_base) == 33);
13369         memcpy(broadcaster_htlc_base_ref.compressed_form, (uint8_t*)(broadcaster_htlc_base + 4), 33);
13370         LDKPublicKey countersignatory_revocation_base_ref;
13371         CHECK(*((uint32_t*)countersignatory_revocation_base) == 33);
13372         memcpy(countersignatory_revocation_base_ref.compressed_form, (uint8_t*)(countersignatory_revocation_base + 4), 33);
13373         LDKPublicKey countersignatory_htlc_base_ref;
13374         CHECK(*((uint32_t*)countersignatory_htlc_base) == 33);
13375         memcpy(countersignatory_htlc_base_ref.compressed_form, (uint8_t*)(countersignatory_htlc_base + 4), 33);
13376         LDKCResult_TxCreationKeysSecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_TxCreationKeysSecpErrorZ), "LDKCResult_TxCreationKeysSecpErrorZ");
13377         *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);
13378         return (long)ret_conv;
13379 }
13380
13381 uint32_t TS_TxCreationKeys_from_channel_static_keys(int8_tArray per_commitment_point, uint32_t broadcaster_keys, uint32_t countersignatory_keys) {
13382         LDKPublicKey per_commitment_point_ref;
13383         CHECK(*((uint32_t*)per_commitment_point) == 33);
13384         memcpy(per_commitment_point_ref.compressed_form, (uint8_t*)(per_commitment_point + 4), 33);
13385         LDKChannelPublicKeys broadcaster_keys_conv;
13386         broadcaster_keys_conv.inner = (void*)(broadcaster_keys & (~1));
13387         broadcaster_keys_conv.is_owned = false;
13388         LDKChannelPublicKeys countersignatory_keys_conv;
13389         countersignatory_keys_conv.inner = (void*)(countersignatory_keys & (~1));
13390         countersignatory_keys_conv.is_owned = false;
13391         LDKCResult_TxCreationKeysSecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_TxCreationKeysSecpErrorZ), "LDKCResult_TxCreationKeysSecpErrorZ");
13392         *ret_conv = TxCreationKeys_from_channel_static_keys(per_commitment_point_ref, &broadcaster_keys_conv, &countersignatory_keys_conv);
13393         return (long)ret_conv;
13394 }
13395
13396 int8_tArray TS_get_revokeable_redeemscript(int8_tArray revocation_key, int16_t contest_delay, int8_tArray broadcaster_delayed_payment_key) {
13397         LDKPublicKey revocation_key_ref;
13398         CHECK(*((uint32_t*)revocation_key) == 33);
13399         memcpy(revocation_key_ref.compressed_form, (uint8_t*)(revocation_key + 4), 33);
13400         LDKPublicKey broadcaster_delayed_payment_key_ref;
13401         CHECK(*((uint32_t*)broadcaster_delayed_payment_key) == 33);
13402         memcpy(broadcaster_delayed_payment_key_ref.compressed_form, (uint8_t*)(broadcaster_delayed_payment_key + 4), 33);
13403         LDKCVec_u8Z arg_var = get_revokeable_redeemscript(revocation_key_ref, contest_delay, broadcaster_delayed_payment_key_ref);
13404         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
13405         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
13406         CVec_u8Z_free(arg_var);
13407         return arg_arr;
13408 }
13409
13410 void TS_HTLCOutputInCommitment_free(uint32_t this_ptr) {
13411         LDKHTLCOutputInCommitment this_ptr_conv;
13412         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13413         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13414         HTLCOutputInCommitment_free(this_ptr_conv);
13415 }
13416
13417 uint32_t TS_HTLCOutputInCommitment_clone(uint32_t orig) {
13418         LDKHTLCOutputInCommitment orig_conv;
13419         orig_conv.inner = (void*)(orig & (~1));
13420         orig_conv.is_owned = false;
13421         LDKHTLCOutputInCommitment ret_var = HTLCOutputInCommitment_clone(&orig_conv);
13422         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13423         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13424         long ret_ref = (long)ret_var.inner;
13425         if (ret_var.is_owned) {
13426                 ret_ref |= 1;
13427         }
13428         return ret_ref;
13429 }
13430
13431 jboolean TS_HTLCOutputInCommitment_get_offered(uint32_t this_ptr) {
13432         LDKHTLCOutputInCommitment this_ptr_conv;
13433         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13434         this_ptr_conv.is_owned = false;
13435         jboolean ret_val = HTLCOutputInCommitment_get_offered(&this_ptr_conv);
13436         return ret_val;
13437 }
13438
13439 void TS_HTLCOutputInCommitment_set_offered(uint32_t this_ptr, jboolean val) {
13440         LDKHTLCOutputInCommitment this_ptr_conv;
13441         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13442         this_ptr_conv.is_owned = false;
13443         HTLCOutputInCommitment_set_offered(&this_ptr_conv, val);
13444 }
13445
13446 int64_t TS_HTLCOutputInCommitment_get_amount_msat(uint32_t this_ptr) {
13447         LDKHTLCOutputInCommitment this_ptr_conv;
13448         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13449         this_ptr_conv.is_owned = false;
13450         int64_t ret_val = HTLCOutputInCommitment_get_amount_msat(&this_ptr_conv);
13451         return ret_val;
13452 }
13453
13454 void TS_HTLCOutputInCommitment_set_amount_msat(uint32_t this_ptr, int64_t val) {
13455         LDKHTLCOutputInCommitment this_ptr_conv;
13456         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13457         this_ptr_conv.is_owned = false;
13458         HTLCOutputInCommitment_set_amount_msat(&this_ptr_conv, val);
13459 }
13460
13461 int32_t TS_HTLCOutputInCommitment_get_cltv_expiry(uint32_t this_ptr) {
13462         LDKHTLCOutputInCommitment this_ptr_conv;
13463         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13464         this_ptr_conv.is_owned = false;
13465         int32_t ret_val = HTLCOutputInCommitment_get_cltv_expiry(&this_ptr_conv);
13466         return ret_val;
13467 }
13468
13469 void TS_HTLCOutputInCommitment_set_cltv_expiry(uint32_t this_ptr, int32_t val) {
13470         LDKHTLCOutputInCommitment this_ptr_conv;
13471         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13472         this_ptr_conv.is_owned = false;
13473         HTLCOutputInCommitment_set_cltv_expiry(&this_ptr_conv, val);
13474 }
13475
13476 int8_tArray TS_HTLCOutputInCommitment_get_payment_hash(uint32_t this_ptr) {
13477         LDKHTLCOutputInCommitment this_ptr_conv;
13478         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13479         this_ptr_conv.is_owned = false;
13480         int8_tArray ret_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
13481         memcpy((uint8_t*)(ret_arr + 4), *HTLCOutputInCommitment_get_payment_hash(&this_ptr_conv), 32);
13482         return ret_arr;
13483 }
13484
13485 void TS_HTLCOutputInCommitment_set_payment_hash(uint32_t this_ptr, int8_tArray val) {
13486         LDKHTLCOutputInCommitment this_ptr_conv;
13487         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13488         this_ptr_conv.is_owned = false;
13489         LDKThirtyTwoBytes val_ref;
13490         CHECK(*((uint32_t*)val) == 32);
13491         memcpy(val_ref.data, (uint8_t*)(val + 4), 32);
13492         HTLCOutputInCommitment_set_payment_hash(&this_ptr_conv, val_ref);
13493 }
13494
13495 int8_tArray TS_HTLCOutputInCommitment_write(uint32_t obj) {
13496         LDKHTLCOutputInCommitment obj_conv;
13497         obj_conv.inner = (void*)(obj & (~1));
13498         obj_conv.is_owned = false;
13499         LDKCVec_u8Z arg_var = HTLCOutputInCommitment_write(&obj_conv);
13500         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
13501         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
13502         CVec_u8Z_free(arg_var);
13503         return arg_arr;
13504 }
13505
13506 uint32_t TS_HTLCOutputInCommitment_read(int8_tArray ser) {
13507         LDKu8slice ser_ref;
13508         ser_ref.datalen = *((uint32_t*)ser);
13509         ser_ref.data = (int8_t*)(ser + 4);
13510         LDKHTLCOutputInCommitment ret_var = HTLCOutputInCommitment_read(ser_ref);
13511         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13512         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13513         long ret_ref = (long)ret_var.inner;
13514         if (ret_var.is_owned) {
13515                 ret_ref |= 1;
13516         }
13517         return ret_ref;
13518 }
13519
13520 int8_tArray TS_get_htlc_redeemscript(uint32_t htlc, uint32_t keys) {
13521         LDKHTLCOutputInCommitment htlc_conv;
13522         htlc_conv.inner = (void*)(htlc & (~1));
13523         htlc_conv.is_owned = false;
13524         LDKTxCreationKeys keys_conv;
13525         keys_conv.inner = (void*)(keys & (~1));
13526         keys_conv.is_owned = false;
13527         LDKCVec_u8Z arg_var = get_htlc_redeemscript(&htlc_conv, &keys_conv);
13528         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
13529         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
13530         CVec_u8Z_free(arg_var);
13531         return arg_arr;
13532 }
13533
13534 int8_tArray TS_make_funding_redeemscript(int8_tArray broadcaster, int8_tArray countersignatory) {
13535         LDKPublicKey broadcaster_ref;
13536         CHECK(*((uint32_t*)broadcaster) == 33);
13537         memcpy(broadcaster_ref.compressed_form, (uint8_t*)(broadcaster + 4), 33);
13538         LDKPublicKey countersignatory_ref;
13539         CHECK(*((uint32_t*)countersignatory) == 33);
13540         memcpy(countersignatory_ref.compressed_form, (uint8_t*)(countersignatory + 4), 33);
13541         LDKCVec_u8Z arg_var = make_funding_redeemscript(broadcaster_ref, countersignatory_ref);
13542         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
13543         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
13544         CVec_u8Z_free(arg_var);
13545         return arg_arr;
13546 }
13547
13548 int8_tArray TS_build_htlc_transaction(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) {
13549         unsigned char prev_hash_arr[32];
13550         CHECK(*((uint32_t*)prev_hash) == 32);
13551         memcpy(prev_hash_arr, (uint8_t*)(prev_hash + 4), 32);
13552         unsigned char (*prev_hash_ref)[32] = &prev_hash_arr;
13553         LDKHTLCOutputInCommitment htlc_conv;
13554         htlc_conv.inner = (void*)(htlc & (~1));
13555         htlc_conv.is_owned = false;
13556         LDKPublicKey broadcaster_delayed_payment_key_ref;
13557         CHECK(*((uint32_t*)broadcaster_delayed_payment_key) == 33);
13558         memcpy(broadcaster_delayed_payment_key_ref.compressed_form, (uint8_t*)(broadcaster_delayed_payment_key + 4), 33);
13559         LDKPublicKey revocation_key_ref;
13560         CHECK(*((uint32_t*)revocation_key) == 33);
13561         memcpy(revocation_key_ref.compressed_form, (uint8_t*)(revocation_key + 4), 33);
13562         LDKTransaction arg_var = build_htlc_transaction(prev_hash_ref, feerate_per_kw, contest_delay, &htlc_conv, broadcaster_delayed_payment_key_ref, revocation_key_ref);
13563         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
13564         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
13565         Transaction_free(arg_var);
13566         return arg_arr;
13567 }
13568
13569 void TS_ChannelTransactionParameters_free(uint32_t this_ptr) {
13570         LDKChannelTransactionParameters this_ptr_conv;
13571         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13572         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13573         ChannelTransactionParameters_free(this_ptr_conv);
13574 }
13575
13576 uint32_t TS_ChannelTransactionParameters_clone(uint32_t orig) {
13577         LDKChannelTransactionParameters orig_conv;
13578         orig_conv.inner = (void*)(orig & (~1));
13579         orig_conv.is_owned = false;
13580         LDKChannelTransactionParameters ret_var = ChannelTransactionParameters_clone(&orig_conv);
13581         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13582         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13583         long ret_ref = (long)ret_var.inner;
13584         if (ret_var.is_owned) {
13585                 ret_ref |= 1;
13586         }
13587         return ret_ref;
13588 }
13589
13590 uint32_t TS_ChannelTransactionParameters_get_holder_pubkeys(uint32_t this_ptr) {
13591         LDKChannelTransactionParameters this_ptr_conv;
13592         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13593         this_ptr_conv.is_owned = false;
13594         LDKChannelPublicKeys ret_var = ChannelTransactionParameters_get_holder_pubkeys(&this_ptr_conv);
13595         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13596         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13597         long ret_ref = (long)ret_var.inner;
13598         if (ret_var.is_owned) {
13599                 ret_ref |= 1;
13600         }
13601         return ret_ref;
13602 }
13603
13604 void TS_ChannelTransactionParameters_set_holder_pubkeys(uint32_t this_ptr, uint32_t val) {
13605         LDKChannelTransactionParameters this_ptr_conv;
13606         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13607         this_ptr_conv.is_owned = false;
13608         LDKChannelPublicKeys val_conv;
13609         val_conv.inner = (void*)(val & (~1));
13610         val_conv.is_owned = (val & 1) || (val == 0);
13611         if (val_conv.inner != NULL)
13612                 val_conv = ChannelPublicKeys_clone(&val_conv);
13613         ChannelTransactionParameters_set_holder_pubkeys(&this_ptr_conv, val_conv);
13614 }
13615
13616 int16_t TS_ChannelTransactionParameters_get_holder_selected_contest_delay(uint32_t this_ptr) {
13617         LDKChannelTransactionParameters this_ptr_conv;
13618         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13619         this_ptr_conv.is_owned = false;
13620         int16_t ret_val = ChannelTransactionParameters_get_holder_selected_contest_delay(&this_ptr_conv);
13621         return ret_val;
13622 }
13623
13624 void TS_ChannelTransactionParameters_set_holder_selected_contest_delay(uint32_t this_ptr, int16_t val) {
13625         LDKChannelTransactionParameters this_ptr_conv;
13626         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13627         this_ptr_conv.is_owned = false;
13628         ChannelTransactionParameters_set_holder_selected_contest_delay(&this_ptr_conv, val);
13629 }
13630
13631 jboolean TS_ChannelTransactionParameters_get_is_outbound_from_holder(uint32_t this_ptr) {
13632         LDKChannelTransactionParameters this_ptr_conv;
13633         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13634         this_ptr_conv.is_owned = false;
13635         jboolean ret_val = ChannelTransactionParameters_get_is_outbound_from_holder(&this_ptr_conv);
13636         return ret_val;
13637 }
13638
13639 void TS_ChannelTransactionParameters_set_is_outbound_from_holder(uint32_t this_ptr, jboolean val) {
13640         LDKChannelTransactionParameters this_ptr_conv;
13641         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13642         this_ptr_conv.is_owned = false;
13643         ChannelTransactionParameters_set_is_outbound_from_holder(&this_ptr_conv, val);
13644 }
13645
13646 uint32_t TS_ChannelTransactionParameters_get_counterparty_parameters(uint32_t this_ptr) {
13647         LDKChannelTransactionParameters this_ptr_conv;
13648         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13649         this_ptr_conv.is_owned = false;
13650         LDKCounterpartyChannelTransactionParameters ret_var = ChannelTransactionParameters_get_counterparty_parameters(&this_ptr_conv);
13651         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13652         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13653         long ret_ref = (long)ret_var.inner;
13654         if (ret_var.is_owned) {
13655                 ret_ref |= 1;
13656         }
13657         return ret_ref;
13658 }
13659
13660 void TS_ChannelTransactionParameters_set_counterparty_parameters(uint32_t this_ptr, uint32_t val) {
13661         LDKChannelTransactionParameters this_ptr_conv;
13662         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13663         this_ptr_conv.is_owned = false;
13664         LDKCounterpartyChannelTransactionParameters val_conv;
13665         val_conv.inner = (void*)(val & (~1));
13666         val_conv.is_owned = (val & 1) || (val == 0);
13667         if (val_conv.inner != NULL)
13668                 val_conv = CounterpartyChannelTransactionParameters_clone(&val_conv);
13669         ChannelTransactionParameters_set_counterparty_parameters(&this_ptr_conv, val_conv);
13670 }
13671
13672 uint32_t TS_ChannelTransactionParameters_get_funding_outpoint(uint32_t this_ptr) {
13673         LDKChannelTransactionParameters this_ptr_conv;
13674         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13675         this_ptr_conv.is_owned = false;
13676         LDKOutPoint ret_var = ChannelTransactionParameters_get_funding_outpoint(&this_ptr_conv);
13677         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13678         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13679         long ret_ref = (long)ret_var.inner;
13680         if (ret_var.is_owned) {
13681                 ret_ref |= 1;
13682         }
13683         return ret_ref;
13684 }
13685
13686 void TS_ChannelTransactionParameters_set_funding_outpoint(uint32_t this_ptr, uint32_t val) {
13687         LDKChannelTransactionParameters this_ptr_conv;
13688         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13689         this_ptr_conv.is_owned = false;
13690         LDKOutPoint val_conv;
13691         val_conv.inner = (void*)(val & (~1));
13692         val_conv.is_owned = (val & 1) || (val == 0);
13693         if (val_conv.inner != NULL)
13694                 val_conv = OutPoint_clone(&val_conv);
13695         ChannelTransactionParameters_set_funding_outpoint(&this_ptr_conv, val_conv);
13696 }
13697
13698 uint32_t TS_ChannelTransactionParameters_new(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) {
13699         LDKChannelPublicKeys holder_pubkeys_arg_conv;
13700         holder_pubkeys_arg_conv.inner = (void*)(holder_pubkeys_arg & (~1));
13701         holder_pubkeys_arg_conv.is_owned = (holder_pubkeys_arg & 1) || (holder_pubkeys_arg == 0);
13702         if (holder_pubkeys_arg_conv.inner != NULL)
13703                 holder_pubkeys_arg_conv = ChannelPublicKeys_clone(&holder_pubkeys_arg_conv);
13704         LDKCounterpartyChannelTransactionParameters counterparty_parameters_arg_conv;
13705         counterparty_parameters_arg_conv.inner = (void*)(counterparty_parameters_arg & (~1));
13706         counterparty_parameters_arg_conv.is_owned = (counterparty_parameters_arg & 1) || (counterparty_parameters_arg == 0);
13707         if (counterparty_parameters_arg_conv.inner != NULL)
13708                 counterparty_parameters_arg_conv = CounterpartyChannelTransactionParameters_clone(&counterparty_parameters_arg_conv);
13709         LDKOutPoint funding_outpoint_arg_conv;
13710         funding_outpoint_arg_conv.inner = (void*)(funding_outpoint_arg & (~1));
13711         funding_outpoint_arg_conv.is_owned = (funding_outpoint_arg & 1) || (funding_outpoint_arg == 0);
13712         if (funding_outpoint_arg_conv.inner != NULL)
13713                 funding_outpoint_arg_conv = OutPoint_clone(&funding_outpoint_arg_conv);
13714         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);
13715         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13716         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13717         long ret_ref = (long)ret_var.inner;
13718         if (ret_var.is_owned) {
13719                 ret_ref |= 1;
13720         }
13721         return ret_ref;
13722 }
13723
13724 void TS_CounterpartyChannelTransactionParameters_free(uint32_t this_ptr) {
13725         LDKCounterpartyChannelTransactionParameters this_ptr_conv;
13726         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13727         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13728         CounterpartyChannelTransactionParameters_free(this_ptr_conv);
13729 }
13730
13731 uint32_t TS_CounterpartyChannelTransactionParameters_clone(uint32_t orig) {
13732         LDKCounterpartyChannelTransactionParameters orig_conv;
13733         orig_conv.inner = (void*)(orig & (~1));
13734         orig_conv.is_owned = false;
13735         LDKCounterpartyChannelTransactionParameters ret_var = CounterpartyChannelTransactionParameters_clone(&orig_conv);
13736         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13737         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13738         long ret_ref = (long)ret_var.inner;
13739         if (ret_var.is_owned) {
13740                 ret_ref |= 1;
13741         }
13742         return ret_ref;
13743 }
13744
13745 uint32_t TS_CounterpartyChannelTransactionParameters_get_pubkeys(uint32_t this_ptr) {
13746         LDKCounterpartyChannelTransactionParameters this_ptr_conv;
13747         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13748         this_ptr_conv.is_owned = false;
13749         LDKChannelPublicKeys ret_var = CounterpartyChannelTransactionParameters_get_pubkeys(&this_ptr_conv);
13750         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13751         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13752         long ret_ref = (long)ret_var.inner;
13753         if (ret_var.is_owned) {
13754                 ret_ref |= 1;
13755         }
13756         return ret_ref;
13757 }
13758
13759 void TS_CounterpartyChannelTransactionParameters_set_pubkeys(uint32_t this_ptr, uint32_t val) {
13760         LDKCounterpartyChannelTransactionParameters this_ptr_conv;
13761         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13762         this_ptr_conv.is_owned = false;
13763         LDKChannelPublicKeys val_conv;
13764         val_conv.inner = (void*)(val & (~1));
13765         val_conv.is_owned = (val & 1) || (val == 0);
13766         if (val_conv.inner != NULL)
13767                 val_conv = ChannelPublicKeys_clone(&val_conv);
13768         CounterpartyChannelTransactionParameters_set_pubkeys(&this_ptr_conv, val_conv);
13769 }
13770
13771 int16_t TS_CounterpartyChannelTransactionParameters_get_selected_contest_delay(uint32_t this_ptr) {
13772         LDKCounterpartyChannelTransactionParameters this_ptr_conv;
13773         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13774         this_ptr_conv.is_owned = false;
13775         int16_t ret_val = CounterpartyChannelTransactionParameters_get_selected_contest_delay(&this_ptr_conv);
13776         return ret_val;
13777 }
13778
13779 void TS_CounterpartyChannelTransactionParameters_set_selected_contest_delay(uint32_t this_ptr, int16_t val) {
13780         LDKCounterpartyChannelTransactionParameters this_ptr_conv;
13781         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13782         this_ptr_conv.is_owned = false;
13783         CounterpartyChannelTransactionParameters_set_selected_contest_delay(&this_ptr_conv, val);
13784 }
13785
13786 uint32_t TS_CounterpartyChannelTransactionParameters_new(uint32_t pubkeys_arg, int16_t selected_contest_delay_arg) {
13787         LDKChannelPublicKeys pubkeys_arg_conv;
13788         pubkeys_arg_conv.inner = (void*)(pubkeys_arg & (~1));
13789         pubkeys_arg_conv.is_owned = (pubkeys_arg & 1) || (pubkeys_arg == 0);
13790         if (pubkeys_arg_conv.inner != NULL)
13791                 pubkeys_arg_conv = ChannelPublicKeys_clone(&pubkeys_arg_conv);
13792         LDKCounterpartyChannelTransactionParameters ret_var = CounterpartyChannelTransactionParameters_new(pubkeys_arg_conv, selected_contest_delay_arg);
13793         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13794         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13795         long ret_ref = (long)ret_var.inner;
13796         if (ret_var.is_owned) {
13797                 ret_ref |= 1;
13798         }
13799         return ret_ref;
13800 }
13801
13802 jboolean TS_ChannelTransactionParameters_is_populated(uint32_t this_arg) {
13803         LDKChannelTransactionParameters this_arg_conv;
13804         this_arg_conv.inner = (void*)(this_arg & (~1));
13805         this_arg_conv.is_owned = false;
13806         jboolean ret_val = ChannelTransactionParameters_is_populated(&this_arg_conv);
13807         return ret_val;
13808 }
13809
13810 uint32_t TS_ChannelTransactionParameters_as_holder_broadcastable(uint32_t this_arg) {
13811         LDKChannelTransactionParameters this_arg_conv;
13812         this_arg_conv.inner = (void*)(this_arg & (~1));
13813         this_arg_conv.is_owned = false;
13814         LDKDirectedChannelTransactionParameters ret_var = ChannelTransactionParameters_as_holder_broadcastable(&this_arg_conv);
13815         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13816         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13817         long ret_ref = (long)ret_var.inner;
13818         if (ret_var.is_owned) {
13819                 ret_ref |= 1;
13820         }
13821         return ret_ref;
13822 }
13823
13824 uint32_t TS_ChannelTransactionParameters_as_counterparty_broadcastable(uint32_t this_arg) {
13825         LDKChannelTransactionParameters this_arg_conv;
13826         this_arg_conv.inner = (void*)(this_arg & (~1));
13827         this_arg_conv.is_owned = false;
13828         LDKDirectedChannelTransactionParameters ret_var = ChannelTransactionParameters_as_counterparty_broadcastable(&this_arg_conv);
13829         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13830         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13831         long ret_ref = (long)ret_var.inner;
13832         if (ret_var.is_owned) {
13833                 ret_ref |= 1;
13834         }
13835         return ret_ref;
13836 }
13837
13838 int8_tArray TS_CounterpartyChannelTransactionParameters_write(uint32_t obj) {
13839         LDKCounterpartyChannelTransactionParameters obj_conv;
13840         obj_conv.inner = (void*)(obj & (~1));
13841         obj_conv.is_owned = false;
13842         LDKCVec_u8Z arg_var = CounterpartyChannelTransactionParameters_write(&obj_conv);
13843         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
13844         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
13845         CVec_u8Z_free(arg_var);
13846         return arg_arr;
13847 }
13848
13849 uint32_t TS_CounterpartyChannelTransactionParameters_read(int8_tArray ser) {
13850         LDKu8slice ser_ref;
13851         ser_ref.datalen = *((uint32_t*)ser);
13852         ser_ref.data = (int8_t*)(ser + 4);
13853         LDKCounterpartyChannelTransactionParameters ret_var = CounterpartyChannelTransactionParameters_read(ser_ref);
13854         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13855         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13856         long ret_ref = (long)ret_var.inner;
13857         if (ret_var.is_owned) {
13858                 ret_ref |= 1;
13859         }
13860         return ret_ref;
13861 }
13862
13863 int8_tArray TS_ChannelTransactionParameters_write(uint32_t obj) {
13864         LDKChannelTransactionParameters obj_conv;
13865         obj_conv.inner = (void*)(obj & (~1));
13866         obj_conv.is_owned = false;
13867         LDKCVec_u8Z arg_var = ChannelTransactionParameters_write(&obj_conv);
13868         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
13869         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
13870         CVec_u8Z_free(arg_var);
13871         return arg_arr;
13872 }
13873
13874 uint32_t TS_ChannelTransactionParameters_read(int8_tArray ser) {
13875         LDKu8slice ser_ref;
13876         ser_ref.datalen = *((uint32_t*)ser);
13877         ser_ref.data = (int8_t*)(ser + 4);
13878         LDKChannelTransactionParameters ret_var = ChannelTransactionParameters_read(ser_ref);
13879         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13880         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13881         long ret_ref = (long)ret_var.inner;
13882         if (ret_var.is_owned) {
13883                 ret_ref |= 1;
13884         }
13885         return ret_ref;
13886 }
13887
13888 void TS_DirectedChannelTransactionParameters_free(uint32_t this_ptr) {
13889         LDKDirectedChannelTransactionParameters this_ptr_conv;
13890         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13891         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13892         DirectedChannelTransactionParameters_free(this_ptr_conv);
13893 }
13894
13895 uint32_t TS_DirectedChannelTransactionParameters_broadcaster_pubkeys(uint32_t this_arg) {
13896         LDKDirectedChannelTransactionParameters this_arg_conv;
13897         this_arg_conv.inner = (void*)(this_arg & (~1));
13898         this_arg_conv.is_owned = false;
13899         LDKChannelPublicKeys ret_var = DirectedChannelTransactionParameters_broadcaster_pubkeys(&this_arg_conv);
13900         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13901         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13902         long ret_ref = (long)ret_var.inner;
13903         if (ret_var.is_owned) {
13904                 ret_ref |= 1;
13905         }
13906         return ret_ref;
13907 }
13908
13909 uint32_t TS_DirectedChannelTransactionParameters_countersignatory_pubkeys(uint32_t this_arg) {
13910         LDKDirectedChannelTransactionParameters this_arg_conv;
13911         this_arg_conv.inner = (void*)(this_arg & (~1));
13912         this_arg_conv.is_owned = false;
13913         LDKChannelPublicKeys ret_var = DirectedChannelTransactionParameters_countersignatory_pubkeys(&this_arg_conv);
13914         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13915         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13916         long ret_ref = (long)ret_var.inner;
13917         if (ret_var.is_owned) {
13918                 ret_ref |= 1;
13919         }
13920         return ret_ref;
13921 }
13922
13923 int16_t TS_DirectedChannelTransactionParameters_contest_delay(uint32_t this_arg) {
13924         LDKDirectedChannelTransactionParameters this_arg_conv;
13925         this_arg_conv.inner = (void*)(this_arg & (~1));
13926         this_arg_conv.is_owned = false;
13927         int16_t ret_val = DirectedChannelTransactionParameters_contest_delay(&this_arg_conv);
13928         return ret_val;
13929 }
13930
13931 jboolean TS_DirectedChannelTransactionParameters_is_outbound(uint32_t this_arg) {
13932         LDKDirectedChannelTransactionParameters this_arg_conv;
13933         this_arg_conv.inner = (void*)(this_arg & (~1));
13934         this_arg_conv.is_owned = false;
13935         jboolean ret_val = DirectedChannelTransactionParameters_is_outbound(&this_arg_conv);
13936         return ret_val;
13937 }
13938
13939 uint32_t TS_DirectedChannelTransactionParameters_funding_outpoint(uint32_t this_arg) {
13940         LDKDirectedChannelTransactionParameters this_arg_conv;
13941         this_arg_conv.inner = (void*)(this_arg & (~1));
13942         this_arg_conv.is_owned = false;
13943         LDKOutPoint ret_var = DirectedChannelTransactionParameters_funding_outpoint(&this_arg_conv);
13944         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13945         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13946         long ret_ref = (long)ret_var.inner;
13947         if (ret_var.is_owned) {
13948                 ret_ref |= 1;
13949         }
13950         return ret_ref;
13951 }
13952
13953 void TS_HolderCommitmentTransaction_free(uint32_t this_ptr) {
13954         LDKHolderCommitmentTransaction this_ptr_conv;
13955         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13956         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13957         HolderCommitmentTransaction_free(this_ptr_conv);
13958 }
13959
13960 uint32_t TS_HolderCommitmentTransaction_clone(uint32_t orig) {
13961         LDKHolderCommitmentTransaction orig_conv;
13962         orig_conv.inner = (void*)(orig & (~1));
13963         orig_conv.is_owned = false;
13964         LDKHolderCommitmentTransaction ret_var = HolderCommitmentTransaction_clone(&orig_conv);
13965         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13966         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13967         long ret_ref = (long)ret_var.inner;
13968         if (ret_var.is_owned) {
13969                 ret_ref |= 1;
13970         }
13971         return ret_ref;
13972 }
13973
13974 int8_tArray TS_HolderCommitmentTransaction_get_counterparty_sig(uint32_t this_ptr) {
13975         LDKHolderCommitmentTransaction this_ptr_conv;
13976         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13977         this_ptr_conv.is_owned = false;
13978         int8_tArray arg_arr = init_arr(64, sizeof(uint8_t), "Native int8_tArray Bytes");
13979         memcpy((uint8_t*)(arg_arr + 4), HolderCommitmentTransaction_get_counterparty_sig(&this_ptr_conv).compact_form, 64);
13980         return arg_arr;
13981 }
13982
13983 void TS_HolderCommitmentTransaction_set_counterparty_sig(uint32_t this_ptr, int8_tArray val) {
13984         LDKHolderCommitmentTransaction this_ptr_conv;
13985         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13986         this_ptr_conv.is_owned = false;
13987         LDKSignature val_ref;
13988         CHECK(*((uint32_t*)val) == 64);
13989         memcpy(val_ref.compact_form, (uint8_t*)(val + 4), 64);
13990         HolderCommitmentTransaction_set_counterparty_sig(&this_ptr_conv, val_ref);
13991 }
13992
13993 void TS_HolderCommitmentTransaction_set_counterparty_htlc_sigs(uint32_t this_ptr, ptrArray val) {
13994         LDKHolderCommitmentTransaction this_ptr_conv;
13995         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13996         this_ptr_conv.is_owned = false;
13997         LDKCVec_SignatureZ val_constr;
13998         val_constr.datalen = *((uint32_t*)val);
13999         if (val_constr.datalen > 0)
14000                 val_constr.data = MALLOC(val_constr.datalen * sizeof(LDKSignature), "LDKCVec_SignatureZ Elements");
14001         else
14002                 val_constr.data = NULL;
14003         int8_tArray* val_vals = (int8_tArray*)(val + 4);
14004         for (size_t m = 0; m < val_constr.datalen; m++) {
14005                 int8_tArray arr_conv_12 = val_vals[m];
14006                 LDKSignature arr_conv_12_ref;
14007                 CHECK(*((uint32_t*)arr_conv_12) == 64);
14008                 memcpy(arr_conv_12_ref.compact_form, (uint8_t*)(arr_conv_12 + 4), 64);
14009                 val_constr.data[m] = arr_conv_12_ref;
14010         }
14011         HolderCommitmentTransaction_set_counterparty_htlc_sigs(&this_ptr_conv, val_constr);
14012 }
14013
14014 int8_tArray TS_HolderCommitmentTransaction_write(uint32_t obj) {
14015         LDKHolderCommitmentTransaction obj_conv;
14016         obj_conv.inner = (void*)(obj & (~1));
14017         obj_conv.is_owned = false;
14018         LDKCVec_u8Z arg_var = HolderCommitmentTransaction_write(&obj_conv);
14019         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
14020         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
14021         CVec_u8Z_free(arg_var);
14022         return arg_arr;
14023 }
14024
14025 uint32_t TS_HolderCommitmentTransaction_read(int8_tArray ser) {
14026         LDKu8slice ser_ref;
14027         ser_ref.datalen = *((uint32_t*)ser);
14028         ser_ref.data = (int8_t*)(ser + 4);
14029         LDKHolderCommitmentTransaction ret_var = HolderCommitmentTransaction_read(ser_ref);
14030         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14031         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14032         long ret_ref = (long)ret_var.inner;
14033         if (ret_var.is_owned) {
14034                 ret_ref |= 1;
14035         }
14036         return ret_ref;
14037 }
14038
14039 uint32_t TS_HolderCommitmentTransaction_new(uint32_t commitment_tx, int8_tArray counterparty_sig, ptrArray counterparty_htlc_sigs, int8_tArray holder_funding_key, int8_tArray counterparty_funding_key) {
14040         LDKCommitmentTransaction commitment_tx_conv;
14041         commitment_tx_conv.inner = (void*)(commitment_tx & (~1));
14042         commitment_tx_conv.is_owned = (commitment_tx & 1) || (commitment_tx == 0);
14043         if (commitment_tx_conv.inner != NULL)
14044                 commitment_tx_conv = CommitmentTransaction_clone(&commitment_tx_conv);
14045         LDKSignature counterparty_sig_ref;
14046         CHECK(*((uint32_t*)counterparty_sig) == 64);
14047         memcpy(counterparty_sig_ref.compact_form, (uint8_t*)(counterparty_sig + 4), 64);
14048         LDKCVec_SignatureZ counterparty_htlc_sigs_constr;
14049         counterparty_htlc_sigs_constr.datalen = *((uint32_t*)counterparty_htlc_sigs);
14050         if (counterparty_htlc_sigs_constr.datalen > 0)
14051                 counterparty_htlc_sigs_constr.data = MALLOC(counterparty_htlc_sigs_constr.datalen * sizeof(LDKSignature), "LDKCVec_SignatureZ Elements");
14052         else
14053                 counterparty_htlc_sigs_constr.data = NULL;
14054         int8_tArray* counterparty_htlc_sigs_vals = (int8_tArray*)(counterparty_htlc_sigs + 4);
14055         for (size_t m = 0; m < counterparty_htlc_sigs_constr.datalen; m++) {
14056                 int8_tArray arr_conv_12 = counterparty_htlc_sigs_vals[m];
14057                 LDKSignature arr_conv_12_ref;
14058                 CHECK(*((uint32_t*)arr_conv_12) == 64);
14059                 memcpy(arr_conv_12_ref.compact_form, (uint8_t*)(arr_conv_12 + 4), 64);
14060                 counterparty_htlc_sigs_constr.data[m] = arr_conv_12_ref;
14061         }
14062         LDKPublicKey holder_funding_key_ref;
14063         CHECK(*((uint32_t*)holder_funding_key) == 33);
14064         memcpy(holder_funding_key_ref.compressed_form, (uint8_t*)(holder_funding_key + 4), 33);
14065         LDKPublicKey counterparty_funding_key_ref;
14066         CHECK(*((uint32_t*)counterparty_funding_key) == 33);
14067         memcpy(counterparty_funding_key_ref.compressed_form, (uint8_t*)(counterparty_funding_key + 4), 33);
14068         LDKHolderCommitmentTransaction ret_var = HolderCommitmentTransaction_new(commitment_tx_conv, counterparty_sig_ref, counterparty_htlc_sigs_constr, holder_funding_key_ref, counterparty_funding_key_ref);
14069         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14070         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14071         long ret_ref = (long)ret_var.inner;
14072         if (ret_var.is_owned) {
14073                 ret_ref |= 1;
14074         }
14075         return ret_ref;
14076 }
14077
14078 void TS_BuiltCommitmentTransaction_free(uint32_t this_ptr) {
14079         LDKBuiltCommitmentTransaction this_ptr_conv;
14080         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14081         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
14082         BuiltCommitmentTransaction_free(this_ptr_conv);
14083 }
14084
14085 uint32_t TS_BuiltCommitmentTransaction_clone(uint32_t orig) {
14086         LDKBuiltCommitmentTransaction orig_conv;
14087         orig_conv.inner = (void*)(orig & (~1));
14088         orig_conv.is_owned = false;
14089         LDKBuiltCommitmentTransaction ret_var = BuiltCommitmentTransaction_clone(&orig_conv);
14090         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14091         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14092         long ret_ref = (long)ret_var.inner;
14093         if (ret_var.is_owned) {
14094                 ret_ref |= 1;
14095         }
14096         return ret_ref;
14097 }
14098
14099 int8_tArray TS_BuiltCommitmentTransaction_get_transaction(uint32_t this_ptr) {
14100         LDKBuiltCommitmentTransaction this_ptr_conv;
14101         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14102         this_ptr_conv.is_owned = false;
14103         LDKTransaction arg_var = BuiltCommitmentTransaction_get_transaction(&this_ptr_conv);
14104         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
14105         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
14106         Transaction_free(arg_var);
14107         return arg_arr;
14108 }
14109
14110 void TS_BuiltCommitmentTransaction_set_transaction(uint32_t this_ptr, int8_tArray val) {
14111         LDKBuiltCommitmentTransaction this_ptr_conv;
14112         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14113         this_ptr_conv.is_owned = false;
14114         LDKTransaction val_ref;
14115         val_ref.datalen = *((uint32_t*)val);
14116         val_ref.data = MALLOC(val_ref.datalen, "LDKTransaction Bytes");
14117         memcpy(val_ref.data, (uint8_t*)(val + 4), val_ref.datalen);
14118         val_ref.data_is_owned = true;
14119         BuiltCommitmentTransaction_set_transaction(&this_ptr_conv, val_ref);
14120 }
14121
14122 int8_tArray TS_BuiltCommitmentTransaction_get_txid(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         int8_tArray ret_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
14127         memcpy((uint8_t*)(ret_arr + 4), *BuiltCommitmentTransaction_get_txid(&this_ptr_conv), 32);
14128         return ret_arr;
14129 }
14130
14131 void TS_BuiltCommitmentTransaction_set_txid(uint32_t this_ptr, int8_tArray val) {
14132         LDKBuiltCommitmentTransaction this_ptr_conv;
14133         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14134         this_ptr_conv.is_owned = false;
14135         LDKThirtyTwoBytes val_ref;
14136         CHECK(*((uint32_t*)val) == 32);
14137         memcpy(val_ref.data, (uint8_t*)(val + 4), 32);
14138         BuiltCommitmentTransaction_set_txid(&this_ptr_conv, val_ref);
14139 }
14140
14141 uint32_t TS_BuiltCommitmentTransaction_new(int8_tArray transaction_arg, int8_tArray txid_arg) {
14142         LDKTransaction transaction_arg_ref;
14143         transaction_arg_ref.datalen = *((uint32_t*)transaction_arg);
14144         transaction_arg_ref.data = MALLOC(transaction_arg_ref.datalen, "LDKTransaction Bytes");
14145         memcpy(transaction_arg_ref.data, (uint8_t*)(transaction_arg + 4), transaction_arg_ref.datalen);
14146         transaction_arg_ref.data_is_owned = true;
14147         LDKThirtyTwoBytes txid_arg_ref;
14148         CHECK(*((uint32_t*)txid_arg) == 32);
14149         memcpy(txid_arg_ref.data, (uint8_t*)(txid_arg + 4), 32);
14150         LDKBuiltCommitmentTransaction ret_var = BuiltCommitmentTransaction_new(transaction_arg_ref, txid_arg_ref);
14151         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14152         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14153         long ret_ref = (long)ret_var.inner;
14154         if (ret_var.is_owned) {
14155                 ret_ref |= 1;
14156         }
14157         return ret_ref;
14158 }
14159
14160 int8_tArray TS_BuiltCommitmentTransaction_write(uint32_t obj) {
14161         LDKBuiltCommitmentTransaction obj_conv;
14162         obj_conv.inner = (void*)(obj & (~1));
14163         obj_conv.is_owned = false;
14164         LDKCVec_u8Z arg_var = BuiltCommitmentTransaction_write(&obj_conv);
14165         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
14166         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
14167         CVec_u8Z_free(arg_var);
14168         return arg_arr;
14169 }
14170
14171 uint32_t TS_BuiltCommitmentTransaction_read(int8_tArray ser) {
14172         LDKu8slice ser_ref;
14173         ser_ref.datalen = *((uint32_t*)ser);
14174         ser_ref.data = (int8_t*)(ser + 4);
14175         LDKBuiltCommitmentTransaction ret_var = BuiltCommitmentTransaction_read(ser_ref);
14176         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14177         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14178         long ret_ref = (long)ret_var.inner;
14179         if (ret_var.is_owned) {
14180                 ret_ref |= 1;
14181         }
14182         return ret_ref;
14183 }
14184
14185 int8_tArray TS_BuiltCommitmentTransaction_get_sighash_all(uint32_t this_arg, int8_tArray funding_redeemscript, int64_t channel_value_satoshis) {
14186         LDKBuiltCommitmentTransaction this_arg_conv;
14187         this_arg_conv.inner = (void*)(this_arg & (~1));
14188         this_arg_conv.is_owned = false;
14189         LDKu8slice funding_redeemscript_ref;
14190         funding_redeemscript_ref.datalen = *((uint32_t*)funding_redeemscript);
14191         funding_redeemscript_ref.data = (int8_t*)(funding_redeemscript + 4);
14192         int8_tArray arg_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
14193         memcpy((uint8_t*)(arg_arr + 4), BuiltCommitmentTransaction_get_sighash_all(&this_arg_conv, funding_redeemscript_ref, channel_value_satoshis).data, 32);
14194         return arg_arr;
14195 }
14196
14197 int8_tArray TS_BuiltCommitmentTransaction_sign(uint32_t this_arg, int8_tArray funding_key, int8_tArray funding_redeemscript, int64_t channel_value_satoshis) {
14198         LDKBuiltCommitmentTransaction this_arg_conv;
14199         this_arg_conv.inner = (void*)(this_arg & (~1));
14200         this_arg_conv.is_owned = false;
14201         unsigned char funding_key_arr[32];
14202         CHECK(*((uint32_t*)funding_key) == 32);
14203         memcpy(funding_key_arr, (uint8_t*)(funding_key + 4), 32);
14204         unsigned char (*funding_key_ref)[32] = &funding_key_arr;
14205         LDKu8slice funding_redeemscript_ref;
14206         funding_redeemscript_ref.datalen = *((uint32_t*)funding_redeemscript);
14207         funding_redeemscript_ref.data = (int8_t*)(funding_redeemscript + 4);
14208         int8_tArray arg_arr = init_arr(64, sizeof(uint8_t), "Native int8_tArray Bytes");
14209         memcpy((uint8_t*)(arg_arr + 4), BuiltCommitmentTransaction_sign(&this_arg_conv, funding_key_ref, funding_redeemscript_ref, channel_value_satoshis).compact_form, 64);
14210         return arg_arr;
14211 }
14212
14213 void TS_CommitmentTransaction_free(uint32_t this_ptr) {
14214         LDKCommitmentTransaction this_ptr_conv;
14215         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14216         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
14217         CommitmentTransaction_free(this_ptr_conv);
14218 }
14219
14220 uint32_t TS_CommitmentTransaction_clone(uint32_t orig) {
14221         LDKCommitmentTransaction orig_conv;
14222         orig_conv.inner = (void*)(orig & (~1));
14223         orig_conv.is_owned = false;
14224         LDKCommitmentTransaction ret_var = CommitmentTransaction_clone(&orig_conv);
14225         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14226         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14227         long ret_ref = (long)ret_var.inner;
14228         if (ret_var.is_owned) {
14229                 ret_ref |= 1;
14230         }
14231         return ret_ref;
14232 }
14233
14234 int8_tArray TS_CommitmentTransaction_write(uint32_t obj) {
14235         LDKCommitmentTransaction obj_conv;
14236         obj_conv.inner = (void*)(obj & (~1));
14237         obj_conv.is_owned = false;
14238         LDKCVec_u8Z arg_var = CommitmentTransaction_write(&obj_conv);
14239         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
14240         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
14241         CVec_u8Z_free(arg_var);
14242         return arg_arr;
14243 }
14244
14245 uint32_t TS_CommitmentTransaction_read(int8_tArray ser) {
14246         LDKu8slice ser_ref;
14247         ser_ref.datalen = *((uint32_t*)ser);
14248         ser_ref.data = (int8_t*)(ser + 4);
14249         LDKCommitmentTransaction ret_var = CommitmentTransaction_read(ser_ref);
14250         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14251         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14252         long ret_ref = (long)ret_var.inner;
14253         if (ret_var.is_owned) {
14254                 ret_ref |= 1;
14255         }
14256         return ret_ref;
14257 }
14258
14259 int64_t TS_CommitmentTransaction_commitment_number(uint32_t this_arg) {
14260         LDKCommitmentTransaction this_arg_conv;
14261         this_arg_conv.inner = (void*)(this_arg & (~1));
14262         this_arg_conv.is_owned = false;
14263         int64_t ret_val = CommitmentTransaction_commitment_number(&this_arg_conv);
14264         return ret_val;
14265 }
14266
14267 int64_t TS_CommitmentTransaction_to_broadcaster_value_sat(uint32_t this_arg) {
14268         LDKCommitmentTransaction this_arg_conv;
14269         this_arg_conv.inner = (void*)(this_arg & (~1));
14270         this_arg_conv.is_owned = false;
14271         int64_t ret_val = CommitmentTransaction_to_broadcaster_value_sat(&this_arg_conv);
14272         return ret_val;
14273 }
14274
14275 int64_t TS_CommitmentTransaction_to_countersignatory_value_sat(uint32_t this_arg) {
14276         LDKCommitmentTransaction this_arg_conv;
14277         this_arg_conv.inner = (void*)(this_arg & (~1));
14278         this_arg_conv.is_owned = false;
14279         int64_t ret_val = CommitmentTransaction_to_countersignatory_value_sat(&this_arg_conv);
14280         return ret_val;
14281 }
14282
14283 int32_t TS_CommitmentTransaction_feerate_per_kw(uint32_t this_arg) {
14284         LDKCommitmentTransaction this_arg_conv;
14285         this_arg_conv.inner = (void*)(this_arg & (~1));
14286         this_arg_conv.is_owned = false;
14287         int32_t ret_val = CommitmentTransaction_feerate_per_kw(&this_arg_conv);
14288         return ret_val;
14289 }
14290
14291 uint32_t TS_CommitmentTransaction_trust(uint32_t this_arg) {
14292         LDKCommitmentTransaction this_arg_conv;
14293         this_arg_conv.inner = (void*)(this_arg & (~1));
14294         this_arg_conv.is_owned = false;
14295         LDKTrustedCommitmentTransaction ret_var = CommitmentTransaction_trust(&this_arg_conv);
14296         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14297         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14298         long ret_ref = (long)ret_var.inner;
14299         if (ret_var.is_owned) {
14300                 ret_ref |= 1;
14301         }
14302         return ret_ref;
14303 }
14304
14305 uint32_t TS_CommitmentTransaction_verify(uint32_t this_arg, uint32_t channel_parameters, uint32_t broadcaster_keys, uint32_t countersignatory_keys) {
14306         LDKCommitmentTransaction this_arg_conv;
14307         this_arg_conv.inner = (void*)(this_arg & (~1));
14308         this_arg_conv.is_owned = false;
14309         LDKDirectedChannelTransactionParameters channel_parameters_conv;
14310         channel_parameters_conv.inner = (void*)(channel_parameters & (~1));
14311         channel_parameters_conv.is_owned = false;
14312         LDKChannelPublicKeys broadcaster_keys_conv;
14313         broadcaster_keys_conv.inner = (void*)(broadcaster_keys & (~1));
14314         broadcaster_keys_conv.is_owned = false;
14315         LDKChannelPublicKeys countersignatory_keys_conv;
14316         countersignatory_keys_conv.inner = (void*)(countersignatory_keys & (~1));
14317         countersignatory_keys_conv.is_owned = false;
14318         LDKCResult_TrustedCommitmentTransactionNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_TrustedCommitmentTransactionNoneZ), "LDKCResult_TrustedCommitmentTransactionNoneZ");
14319         *ret_conv = CommitmentTransaction_verify(&this_arg_conv, &channel_parameters_conv, &broadcaster_keys_conv, &countersignatory_keys_conv);
14320         return (long)ret_conv;
14321 }
14322
14323 void TS_TrustedCommitmentTransaction_free(uint32_t this_ptr) {
14324         LDKTrustedCommitmentTransaction this_ptr_conv;
14325         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14326         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
14327         TrustedCommitmentTransaction_free(this_ptr_conv);
14328 }
14329
14330 int8_tArray TS_TrustedCommitmentTransaction_txid(uint32_t this_arg) {
14331         LDKTrustedCommitmentTransaction this_arg_conv;
14332         this_arg_conv.inner = (void*)(this_arg & (~1));
14333         this_arg_conv.is_owned = false;
14334         int8_tArray arg_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
14335         memcpy((uint8_t*)(arg_arr + 4), TrustedCommitmentTransaction_txid(&this_arg_conv).data, 32);
14336         return arg_arr;
14337 }
14338
14339 uint32_t TS_TrustedCommitmentTransaction_built_transaction(uint32_t this_arg) {
14340         LDKTrustedCommitmentTransaction this_arg_conv;
14341         this_arg_conv.inner = (void*)(this_arg & (~1));
14342         this_arg_conv.is_owned = false;
14343         LDKBuiltCommitmentTransaction ret_var = TrustedCommitmentTransaction_built_transaction(&this_arg_conv);
14344         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14345         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14346         long ret_ref = (long)ret_var.inner;
14347         if (ret_var.is_owned) {
14348                 ret_ref |= 1;
14349         }
14350         return ret_ref;
14351 }
14352
14353 uint32_t TS_TrustedCommitmentTransaction_keys(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         LDKTxCreationKeys ret_var = TrustedCommitmentTransaction_keys(&this_arg_conv);
14358         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14359         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14360         long ret_ref = (long)ret_var.inner;
14361         if (ret_var.is_owned) {
14362                 ret_ref |= 1;
14363         }
14364         return ret_ref;
14365 }
14366
14367 uint32_t TS_TrustedCommitmentTransaction_get_htlc_sigs(uint32_t this_arg, int8_tArray htlc_base_key, uint32_t channel_parameters) {
14368         LDKTrustedCommitmentTransaction this_arg_conv;
14369         this_arg_conv.inner = (void*)(this_arg & (~1));
14370         this_arg_conv.is_owned = false;
14371         unsigned char htlc_base_key_arr[32];
14372         CHECK(*((uint32_t*)htlc_base_key) == 32);
14373         memcpy(htlc_base_key_arr, (uint8_t*)(htlc_base_key + 4), 32);
14374         unsigned char (*htlc_base_key_ref)[32] = &htlc_base_key_arr;
14375         LDKDirectedChannelTransactionParameters channel_parameters_conv;
14376         channel_parameters_conv.inner = (void*)(channel_parameters & (~1));
14377         channel_parameters_conv.is_owned = false;
14378         LDKCResult_CVec_SignatureZNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_CVec_SignatureZNoneZ), "LDKCResult_CVec_SignatureZNoneZ");
14379         *ret_conv = TrustedCommitmentTransaction_get_htlc_sigs(&this_arg_conv, htlc_base_key_ref, &channel_parameters_conv);
14380         return (long)ret_conv;
14381 }
14382
14383 int64_t TS_get_commitment_transaction_number_obscure_factor(int8_tArray broadcaster_payment_basepoint, int8_tArray countersignatory_payment_basepoint, jboolean outbound_from_broadcaster) {
14384         LDKPublicKey broadcaster_payment_basepoint_ref;
14385         CHECK(*((uint32_t*)broadcaster_payment_basepoint) == 33);
14386         memcpy(broadcaster_payment_basepoint_ref.compressed_form, (uint8_t*)(broadcaster_payment_basepoint + 4), 33);
14387         LDKPublicKey countersignatory_payment_basepoint_ref;
14388         CHECK(*((uint32_t*)countersignatory_payment_basepoint) == 33);
14389         memcpy(countersignatory_payment_basepoint_ref.compressed_form, (uint8_t*)(countersignatory_payment_basepoint + 4), 33);
14390         int64_t ret_val = get_commitment_transaction_number_obscure_factor(broadcaster_payment_basepoint_ref, countersignatory_payment_basepoint_ref, outbound_from_broadcaster);
14391         return ret_val;
14392 }
14393
14394 void TS_InitFeatures_free(uint32_t this_ptr) {
14395         LDKInitFeatures this_ptr_conv;
14396         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14397         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
14398         InitFeatures_free(this_ptr_conv);
14399 }
14400
14401 void TS_NodeFeatures_free(uint32_t this_ptr) {
14402         LDKNodeFeatures this_ptr_conv;
14403         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14404         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
14405         NodeFeatures_free(this_ptr_conv);
14406 }
14407
14408 void TS_ChannelFeatures_free(uint32_t this_ptr) {
14409         LDKChannelFeatures this_ptr_conv;
14410         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14411         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
14412         ChannelFeatures_free(this_ptr_conv);
14413 }
14414
14415 void TS_RouteHop_free(uint32_t this_ptr) {
14416         LDKRouteHop this_ptr_conv;
14417         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14418         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
14419         RouteHop_free(this_ptr_conv);
14420 }
14421
14422 uint32_t TS_RouteHop_clone(uint32_t orig) {
14423         LDKRouteHop orig_conv;
14424         orig_conv.inner = (void*)(orig & (~1));
14425         orig_conv.is_owned = false;
14426         LDKRouteHop ret_var = RouteHop_clone(&orig_conv);
14427         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14428         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14429         long ret_ref = (long)ret_var.inner;
14430         if (ret_var.is_owned) {
14431                 ret_ref |= 1;
14432         }
14433         return ret_ref;
14434 }
14435
14436 int8_tArray TS_RouteHop_get_pubkey(uint32_t this_ptr) {
14437         LDKRouteHop this_ptr_conv;
14438         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14439         this_ptr_conv.is_owned = false;
14440         int8_tArray arg_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
14441         memcpy((uint8_t*)(arg_arr + 4), RouteHop_get_pubkey(&this_ptr_conv).compressed_form, 33);
14442         return arg_arr;
14443 }
14444
14445 void TS_RouteHop_set_pubkey(uint32_t this_ptr, int8_tArray val) {
14446         LDKRouteHop this_ptr_conv;
14447         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14448         this_ptr_conv.is_owned = false;
14449         LDKPublicKey val_ref;
14450         CHECK(*((uint32_t*)val) == 33);
14451         memcpy(val_ref.compressed_form, (uint8_t*)(val + 4), 33);
14452         RouteHop_set_pubkey(&this_ptr_conv, val_ref);
14453 }
14454
14455 uint32_t TS_RouteHop_get_node_features(uint32_t this_ptr) {
14456         LDKRouteHop this_ptr_conv;
14457         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14458         this_ptr_conv.is_owned = false;
14459         LDKNodeFeatures ret_var = RouteHop_get_node_features(&this_ptr_conv);
14460         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14461         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14462         long ret_ref = (long)ret_var.inner;
14463         if (ret_var.is_owned) {
14464                 ret_ref |= 1;
14465         }
14466         return ret_ref;
14467 }
14468
14469 void TS_RouteHop_set_node_features(uint32_t this_ptr, uint32_t val) {
14470         LDKRouteHop this_ptr_conv;
14471         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14472         this_ptr_conv.is_owned = false;
14473         LDKNodeFeatures val_conv;
14474         val_conv.inner = (void*)(val & (~1));
14475         val_conv.is_owned = (val & 1) || (val == 0);
14476         // Warning: we may need a move here but can't clone!
14477         RouteHop_set_node_features(&this_ptr_conv, val_conv);
14478 }
14479
14480 int64_t TS_RouteHop_get_short_channel_id(uint32_t this_ptr) {
14481         LDKRouteHop this_ptr_conv;
14482         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14483         this_ptr_conv.is_owned = false;
14484         int64_t ret_val = RouteHop_get_short_channel_id(&this_ptr_conv);
14485         return ret_val;
14486 }
14487
14488 void TS_RouteHop_set_short_channel_id(uint32_t this_ptr, int64_t val) {
14489         LDKRouteHop this_ptr_conv;
14490         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14491         this_ptr_conv.is_owned = false;
14492         RouteHop_set_short_channel_id(&this_ptr_conv, val);
14493 }
14494
14495 uint32_t TS_RouteHop_get_channel_features(uint32_t this_ptr) {
14496         LDKRouteHop this_ptr_conv;
14497         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14498         this_ptr_conv.is_owned = false;
14499         LDKChannelFeatures ret_var = RouteHop_get_channel_features(&this_ptr_conv);
14500         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14501         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14502         long ret_ref = (long)ret_var.inner;
14503         if (ret_var.is_owned) {
14504                 ret_ref |= 1;
14505         }
14506         return ret_ref;
14507 }
14508
14509 void TS_RouteHop_set_channel_features(uint32_t this_ptr, uint32_t val) {
14510         LDKRouteHop this_ptr_conv;
14511         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14512         this_ptr_conv.is_owned = false;
14513         LDKChannelFeatures val_conv;
14514         val_conv.inner = (void*)(val & (~1));
14515         val_conv.is_owned = (val & 1) || (val == 0);
14516         // Warning: we may need a move here but can't clone!
14517         RouteHop_set_channel_features(&this_ptr_conv, val_conv);
14518 }
14519
14520 int64_t TS_RouteHop_get_fee_msat(uint32_t this_ptr) {
14521         LDKRouteHop this_ptr_conv;
14522         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14523         this_ptr_conv.is_owned = false;
14524         int64_t ret_val = RouteHop_get_fee_msat(&this_ptr_conv);
14525         return ret_val;
14526 }
14527
14528 void TS_RouteHop_set_fee_msat(uint32_t this_ptr, int64_t val) {
14529         LDKRouteHop this_ptr_conv;
14530         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14531         this_ptr_conv.is_owned = false;
14532         RouteHop_set_fee_msat(&this_ptr_conv, val);
14533 }
14534
14535 int32_t TS_RouteHop_get_cltv_expiry_delta(uint32_t this_ptr) {
14536         LDKRouteHop this_ptr_conv;
14537         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14538         this_ptr_conv.is_owned = false;
14539         int32_t ret_val = RouteHop_get_cltv_expiry_delta(&this_ptr_conv);
14540         return ret_val;
14541 }
14542
14543 void TS_RouteHop_set_cltv_expiry_delta(uint32_t this_ptr, int32_t val) {
14544         LDKRouteHop this_ptr_conv;
14545         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14546         this_ptr_conv.is_owned = false;
14547         RouteHop_set_cltv_expiry_delta(&this_ptr_conv, val);
14548 }
14549
14550 uint32_t TS_RouteHop_new(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) {
14551         LDKPublicKey pubkey_arg_ref;
14552         CHECK(*((uint32_t*)pubkey_arg) == 33);
14553         memcpy(pubkey_arg_ref.compressed_form, (uint8_t*)(pubkey_arg + 4), 33);
14554         LDKNodeFeatures node_features_arg_conv;
14555         node_features_arg_conv.inner = (void*)(node_features_arg & (~1));
14556         node_features_arg_conv.is_owned = (node_features_arg & 1) || (node_features_arg == 0);
14557         // Warning: we may need a move here but can't clone!
14558         LDKChannelFeatures channel_features_arg_conv;
14559         channel_features_arg_conv.inner = (void*)(channel_features_arg & (~1));
14560         channel_features_arg_conv.is_owned = (channel_features_arg & 1) || (channel_features_arg == 0);
14561         // Warning: we may need a move here but can't clone!
14562         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);
14563         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14564         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14565         long ret_ref = (long)ret_var.inner;
14566         if (ret_var.is_owned) {
14567                 ret_ref |= 1;
14568         }
14569         return ret_ref;
14570 }
14571
14572 void TS_Route_free(uint32_t this_ptr) {
14573         LDKRoute this_ptr_conv;
14574         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14575         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
14576         Route_free(this_ptr_conv);
14577 }
14578
14579 uint32_t TS_Route_clone(uint32_t orig) {
14580         LDKRoute orig_conv;
14581         orig_conv.inner = (void*)(orig & (~1));
14582         orig_conv.is_owned = false;
14583         LDKRoute ret_var = Route_clone(&orig_conv);
14584         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14585         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14586         long ret_ref = (long)ret_var.inner;
14587         if (ret_var.is_owned) {
14588                 ret_ref |= 1;
14589         }
14590         return ret_ref;
14591 }
14592
14593 void TS_Route_set_paths(uint32_t this_ptr, ptrArray val) {
14594         LDKRoute this_ptr_conv;
14595         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14596         this_ptr_conv.is_owned = false;
14597         LDKCVec_CVec_RouteHopZZ val_constr;
14598         val_constr.datalen = *((uint32_t*)val);
14599         if (val_constr.datalen > 0)
14600                 val_constr.data = MALLOC(val_constr.datalen * sizeof(LDKCVec_RouteHopZ), "LDKCVec_CVec_RouteHopZZ Elements");
14601         else
14602                 val_constr.data = NULL;
14603         uint32_tArray* val_vals = (uint32_tArray*)(val + 4);
14604         for (size_t m = 0; m < val_constr.datalen; m++) {
14605                 uint32_tArray arr_conv_12 = val_vals[m];
14606                 LDKCVec_RouteHopZ arr_conv_12_constr;
14607                 arr_conv_12_constr.datalen = *((uint32_t*)arr_conv_12);
14608                 if (arr_conv_12_constr.datalen > 0)
14609                         arr_conv_12_constr.data = MALLOC(arr_conv_12_constr.datalen * sizeof(LDKRouteHop), "LDKCVec_RouteHopZ Elements");
14610                 else
14611                         arr_conv_12_constr.data = NULL;
14612                 uint32_t* arr_conv_12_vals = (uint32_t*)(arr_conv_12 + 4);
14613                 for (size_t k = 0; k < arr_conv_12_constr.datalen; k++) {
14614                         uint32_t arr_conv_10 = arr_conv_12_vals[k];
14615                         LDKRouteHop arr_conv_10_conv;
14616                         arr_conv_10_conv.inner = (void*)(arr_conv_10 & (~1));
14617                         arr_conv_10_conv.is_owned = (arr_conv_10 & 1) || (arr_conv_10 == 0);
14618                         if (arr_conv_10_conv.inner != NULL)
14619                                 arr_conv_10_conv = RouteHop_clone(&arr_conv_10_conv);
14620                         arr_conv_12_constr.data[k] = arr_conv_10_conv;
14621                 }
14622                 val_constr.data[m] = arr_conv_12_constr;
14623         }
14624         Route_set_paths(&this_ptr_conv, val_constr);
14625 }
14626
14627 uint32_t TS_Route_new(ptrArray paths_arg) {
14628         LDKCVec_CVec_RouteHopZZ paths_arg_constr;
14629         paths_arg_constr.datalen = *((uint32_t*)paths_arg);
14630         if (paths_arg_constr.datalen > 0)
14631                 paths_arg_constr.data = MALLOC(paths_arg_constr.datalen * sizeof(LDKCVec_RouteHopZ), "LDKCVec_CVec_RouteHopZZ Elements");
14632         else
14633                 paths_arg_constr.data = NULL;
14634         uint32_tArray* paths_arg_vals = (uint32_tArray*)(paths_arg + 4);
14635         for (size_t m = 0; m < paths_arg_constr.datalen; m++) {
14636                 uint32_tArray arr_conv_12 = paths_arg_vals[m];
14637                 LDKCVec_RouteHopZ arr_conv_12_constr;
14638                 arr_conv_12_constr.datalen = *((uint32_t*)arr_conv_12);
14639                 if (arr_conv_12_constr.datalen > 0)
14640                         arr_conv_12_constr.data = MALLOC(arr_conv_12_constr.datalen * sizeof(LDKRouteHop), "LDKCVec_RouteHopZ Elements");
14641                 else
14642                         arr_conv_12_constr.data = NULL;
14643                 uint32_t* arr_conv_12_vals = (uint32_t*)(arr_conv_12 + 4);
14644                 for (size_t k = 0; k < arr_conv_12_constr.datalen; k++) {
14645                         uint32_t arr_conv_10 = arr_conv_12_vals[k];
14646                         LDKRouteHop arr_conv_10_conv;
14647                         arr_conv_10_conv.inner = (void*)(arr_conv_10 & (~1));
14648                         arr_conv_10_conv.is_owned = (arr_conv_10 & 1) || (arr_conv_10 == 0);
14649                         if (arr_conv_10_conv.inner != NULL)
14650                                 arr_conv_10_conv = RouteHop_clone(&arr_conv_10_conv);
14651                         arr_conv_12_constr.data[k] = arr_conv_10_conv;
14652                 }
14653                 paths_arg_constr.data[m] = arr_conv_12_constr;
14654         }
14655         LDKRoute ret_var = Route_new(paths_arg_constr);
14656         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14657         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14658         long ret_ref = (long)ret_var.inner;
14659         if (ret_var.is_owned) {
14660                 ret_ref |= 1;
14661         }
14662         return ret_ref;
14663 }
14664
14665 int8_tArray TS_Route_write(uint32_t obj) {
14666         LDKRoute obj_conv;
14667         obj_conv.inner = (void*)(obj & (~1));
14668         obj_conv.is_owned = false;
14669         LDKCVec_u8Z arg_var = Route_write(&obj_conv);
14670         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
14671         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
14672         CVec_u8Z_free(arg_var);
14673         return arg_arr;
14674 }
14675
14676 uint32_t TS_Route_read(int8_tArray ser) {
14677         LDKu8slice ser_ref;
14678         ser_ref.datalen = *((uint32_t*)ser);
14679         ser_ref.data = (int8_t*)(ser + 4);
14680         LDKCResult_RouteDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_RouteDecodeErrorZ), "LDKCResult_RouteDecodeErrorZ");
14681         *ret_conv = Route_read(ser_ref);
14682         return (long)ret_conv;
14683 }
14684
14685 void TS_RouteHint_free(uint32_t this_ptr) {
14686         LDKRouteHint this_ptr_conv;
14687         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14688         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
14689         RouteHint_free(this_ptr_conv);
14690 }
14691
14692 uint32_t TS_RouteHint_clone(uint32_t orig) {
14693         LDKRouteHint orig_conv;
14694         orig_conv.inner = (void*)(orig & (~1));
14695         orig_conv.is_owned = false;
14696         LDKRouteHint ret_var = RouteHint_clone(&orig_conv);
14697         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14698         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14699         long ret_ref = (long)ret_var.inner;
14700         if (ret_var.is_owned) {
14701                 ret_ref |= 1;
14702         }
14703         return ret_ref;
14704 }
14705
14706 int8_tArray TS_RouteHint_get_src_node_id(uint32_t this_ptr) {
14707         LDKRouteHint this_ptr_conv;
14708         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14709         this_ptr_conv.is_owned = false;
14710         int8_tArray arg_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
14711         memcpy((uint8_t*)(arg_arr + 4), RouteHint_get_src_node_id(&this_ptr_conv).compressed_form, 33);
14712         return arg_arr;
14713 }
14714
14715 void TS_RouteHint_set_src_node_id(uint32_t this_ptr, int8_tArray val) {
14716         LDKRouteHint this_ptr_conv;
14717         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14718         this_ptr_conv.is_owned = false;
14719         LDKPublicKey val_ref;
14720         CHECK(*((uint32_t*)val) == 33);
14721         memcpy(val_ref.compressed_form, (uint8_t*)(val + 4), 33);
14722         RouteHint_set_src_node_id(&this_ptr_conv, val_ref);
14723 }
14724
14725 int64_t TS_RouteHint_get_short_channel_id(uint32_t this_ptr) {
14726         LDKRouteHint this_ptr_conv;
14727         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14728         this_ptr_conv.is_owned = false;
14729         int64_t ret_val = RouteHint_get_short_channel_id(&this_ptr_conv);
14730         return ret_val;
14731 }
14732
14733 void TS_RouteHint_set_short_channel_id(uint32_t this_ptr, int64_t val) {
14734         LDKRouteHint this_ptr_conv;
14735         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14736         this_ptr_conv.is_owned = false;
14737         RouteHint_set_short_channel_id(&this_ptr_conv, val);
14738 }
14739
14740 uint32_t TS_RouteHint_get_fees(uint32_t this_ptr) {
14741         LDKRouteHint this_ptr_conv;
14742         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14743         this_ptr_conv.is_owned = false;
14744         LDKRoutingFees ret_var = RouteHint_get_fees(&this_ptr_conv);
14745         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14746         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14747         long ret_ref = (long)ret_var.inner;
14748         if (ret_var.is_owned) {
14749                 ret_ref |= 1;
14750         }
14751         return ret_ref;
14752 }
14753
14754 void TS_RouteHint_set_fees(uint32_t this_ptr, uint32_t val) {
14755         LDKRouteHint this_ptr_conv;
14756         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14757         this_ptr_conv.is_owned = false;
14758         LDKRoutingFees val_conv;
14759         val_conv.inner = (void*)(val & (~1));
14760         val_conv.is_owned = (val & 1) || (val == 0);
14761         if (val_conv.inner != NULL)
14762                 val_conv = RoutingFees_clone(&val_conv);
14763         RouteHint_set_fees(&this_ptr_conv, val_conv);
14764 }
14765
14766 int16_t TS_RouteHint_get_cltv_expiry_delta(uint32_t this_ptr) {
14767         LDKRouteHint this_ptr_conv;
14768         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14769         this_ptr_conv.is_owned = false;
14770         int16_t ret_val = RouteHint_get_cltv_expiry_delta(&this_ptr_conv);
14771         return ret_val;
14772 }
14773
14774 void TS_RouteHint_set_cltv_expiry_delta(uint32_t this_ptr, int16_t val) {
14775         LDKRouteHint this_ptr_conv;
14776         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14777         this_ptr_conv.is_owned = false;
14778         RouteHint_set_cltv_expiry_delta(&this_ptr_conv, val);
14779 }
14780
14781 int64_t TS_RouteHint_get_htlc_minimum_msat(uint32_t this_ptr) {
14782         LDKRouteHint this_ptr_conv;
14783         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14784         this_ptr_conv.is_owned = false;
14785         int64_t ret_val = RouteHint_get_htlc_minimum_msat(&this_ptr_conv);
14786         return ret_val;
14787 }
14788
14789 void TS_RouteHint_set_htlc_minimum_msat(uint32_t this_ptr, int64_t val) {
14790         LDKRouteHint this_ptr_conv;
14791         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14792         this_ptr_conv.is_owned = false;
14793         RouteHint_set_htlc_minimum_msat(&this_ptr_conv, val);
14794 }
14795
14796 uint32_t TS_RouteHint_new(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) {
14797         LDKPublicKey src_node_id_arg_ref;
14798         CHECK(*((uint32_t*)src_node_id_arg) == 33);
14799         memcpy(src_node_id_arg_ref.compressed_form, (uint8_t*)(src_node_id_arg + 4), 33);
14800         LDKRoutingFees fees_arg_conv;
14801         fees_arg_conv.inner = (void*)(fees_arg & (~1));
14802         fees_arg_conv.is_owned = (fees_arg & 1) || (fees_arg == 0);
14803         if (fees_arg_conv.inner != NULL)
14804                 fees_arg_conv = RoutingFees_clone(&fees_arg_conv);
14805         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);
14806         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14807         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14808         long ret_ref = (long)ret_var.inner;
14809         if (ret_var.is_owned) {
14810                 ret_ref |= 1;
14811         }
14812         return ret_ref;
14813 }
14814
14815 uint32_t TS_get_route(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) {
14816         LDKPublicKey our_node_id_ref;
14817         CHECK(*((uint32_t*)our_node_id) == 33);
14818         memcpy(our_node_id_ref.compressed_form, (uint8_t*)(our_node_id + 4), 33);
14819         LDKNetworkGraph network_conv;
14820         network_conv.inner = (void*)(network & (~1));
14821         network_conv.is_owned = false;
14822         LDKPublicKey target_ref;
14823         CHECK(*((uint32_t*)target) == 33);
14824         memcpy(target_ref.compressed_form, (uint8_t*)(target + 4), 33);
14825         LDKCVec_ChannelDetailsZ first_hops_constr;
14826         first_hops_constr.datalen = *((uint32_t*)first_hops);
14827         if (first_hops_constr.datalen > 0)
14828                 first_hops_constr.data = MALLOC(first_hops_constr.datalen * sizeof(LDKChannelDetails), "LDKCVec_ChannelDetailsZ Elements");
14829         else
14830                 first_hops_constr.data = NULL;
14831         uint32_t* first_hops_vals = (uint32_t*)(first_hops + 4);
14832         for (size_t q = 0; q < first_hops_constr.datalen; q++) {
14833                 uint32_t arr_conv_16 = first_hops_vals[q];
14834                 LDKChannelDetails arr_conv_16_conv;
14835                 arr_conv_16_conv.inner = (void*)(arr_conv_16 & (~1));
14836                 arr_conv_16_conv.is_owned = (arr_conv_16 & 1) || (arr_conv_16 == 0);
14837                 first_hops_constr.data[q] = arr_conv_16_conv;
14838         }
14839         LDKCVec_RouteHintZ last_hops_constr;
14840         last_hops_constr.datalen = *((uint32_t*)last_hops);
14841         if (last_hops_constr.datalen > 0)
14842                 last_hops_constr.data = MALLOC(last_hops_constr.datalen * sizeof(LDKRouteHint), "LDKCVec_RouteHintZ Elements");
14843         else
14844                 last_hops_constr.data = NULL;
14845         uint32_t* last_hops_vals = (uint32_t*)(last_hops + 4);
14846         for (size_t l = 0; l < last_hops_constr.datalen; l++) {
14847                 uint32_t arr_conv_11 = last_hops_vals[l];
14848                 LDKRouteHint arr_conv_11_conv;
14849                 arr_conv_11_conv.inner = (void*)(arr_conv_11 & (~1));
14850                 arr_conv_11_conv.is_owned = (arr_conv_11 & 1) || (arr_conv_11 == 0);
14851                 if (arr_conv_11_conv.inner != NULL)
14852                         arr_conv_11_conv = RouteHint_clone(&arr_conv_11_conv);
14853                 last_hops_constr.data[l] = arr_conv_11_conv;
14854         }
14855         LDKLogger logger_conv = *(LDKLogger*)logger;
14856         LDKCResult_RouteLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_RouteLightningErrorZ), "LDKCResult_RouteLightningErrorZ");
14857         *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);
14858         FREE(first_hops_constr.data);
14859         return (long)ret_conv;
14860 }
14861
14862 void TS_NetworkGraph_free(uint32_t this_ptr) {
14863         LDKNetworkGraph this_ptr_conv;
14864         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14865         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
14866         NetworkGraph_free(this_ptr_conv);
14867 }
14868
14869 void TS_LockedNetworkGraph_free(uint32_t this_ptr) {
14870         LDKLockedNetworkGraph this_ptr_conv;
14871         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14872         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
14873         LockedNetworkGraph_free(this_ptr_conv);
14874 }
14875
14876 void TS_NetGraphMsgHandler_free(uint32_t this_ptr) {
14877         LDKNetGraphMsgHandler this_ptr_conv;
14878         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14879         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
14880         NetGraphMsgHandler_free(this_ptr_conv);
14881 }
14882
14883 uint32_t TS_NetGraphMsgHandler_new(int8_tArray genesis_hash, uint32_t chain_access, uint32_t logger) {
14884         LDKThirtyTwoBytes genesis_hash_ref;
14885         CHECK(*((uint32_t*)genesis_hash) == 32);
14886         memcpy(genesis_hash_ref.data, (uint8_t*)(genesis_hash + 4), 32);
14887         LDKAccess* chain_access_conv = (LDKAccess*)chain_access;
14888         LDKLogger logger_conv = *(LDKLogger*)logger;
14889         LDKNetGraphMsgHandler ret_var = NetGraphMsgHandler_new(genesis_hash_ref, chain_access_conv, logger_conv);
14890         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14891         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14892         long ret_ref = (long)ret_var.inner;
14893         if (ret_var.is_owned) {
14894                 ret_ref |= 1;
14895         }
14896         return ret_ref;
14897 }
14898
14899 uint32_t TS_NetGraphMsgHandler_from_net_graph(uint32_t chain_access, uint32_t logger, uint32_t network_graph) {
14900         LDKAccess* chain_access_conv = (LDKAccess*)chain_access;
14901         LDKLogger logger_conv = *(LDKLogger*)logger;
14902         LDKNetworkGraph network_graph_conv;
14903         network_graph_conv.inner = (void*)(network_graph & (~1));
14904         network_graph_conv.is_owned = (network_graph & 1) || (network_graph == 0);
14905         // Warning: we may need a move here but can't clone!
14906         LDKNetGraphMsgHandler ret_var = NetGraphMsgHandler_from_net_graph(chain_access_conv, logger_conv, network_graph_conv);
14907         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14908         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14909         long ret_ref = (long)ret_var.inner;
14910         if (ret_var.is_owned) {
14911                 ret_ref |= 1;
14912         }
14913         return ret_ref;
14914 }
14915
14916 uint32_t TS_NetGraphMsgHandler_read_locked_graph(uint32_t this_arg) {
14917         LDKNetGraphMsgHandler this_arg_conv;
14918         this_arg_conv.inner = (void*)(this_arg & (~1));
14919         this_arg_conv.is_owned = false;
14920         LDKLockedNetworkGraph ret_var = NetGraphMsgHandler_read_locked_graph(&this_arg_conv);
14921         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14922         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14923         long ret_ref = (long)ret_var.inner;
14924         if (ret_var.is_owned) {
14925                 ret_ref |= 1;
14926         }
14927         return ret_ref;
14928 }
14929
14930 uint32_t TS_LockedNetworkGraph_graph(uint32_t this_arg) {
14931         LDKLockedNetworkGraph this_arg_conv;
14932         this_arg_conv.inner = (void*)(this_arg & (~1));
14933         this_arg_conv.is_owned = false;
14934         LDKNetworkGraph ret_var = LockedNetworkGraph_graph(&this_arg_conv);
14935         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14936         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14937         long ret_ref = (long)ret_var.inner;
14938         if (ret_var.is_owned) {
14939                 ret_ref |= 1;
14940         }
14941         return ret_ref;
14942 }
14943
14944 uint32_t TS_NetGraphMsgHandler_as_RoutingMessageHandler(uint32_t this_arg) {
14945         LDKNetGraphMsgHandler this_arg_conv;
14946         this_arg_conv.inner = (void*)(this_arg & (~1));
14947         this_arg_conv.is_owned = false;
14948         LDKRoutingMessageHandler* ret = MALLOC(sizeof(LDKRoutingMessageHandler), "LDKRoutingMessageHandler");
14949         *ret = NetGraphMsgHandler_as_RoutingMessageHandler(&this_arg_conv);
14950         return (long)ret;
14951 }
14952
14953 uint32_t TS_NetGraphMsgHandler_as_MessageSendEventsProvider(uint32_t this_arg) {
14954         LDKNetGraphMsgHandler this_arg_conv;
14955         this_arg_conv.inner = (void*)(this_arg & (~1));
14956         this_arg_conv.is_owned = false;
14957         LDKMessageSendEventsProvider* ret = MALLOC(sizeof(LDKMessageSendEventsProvider), "LDKMessageSendEventsProvider");
14958         *ret = NetGraphMsgHandler_as_MessageSendEventsProvider(&this_arg_conv);
14959         return (long)ret;
14960 }
14961
14962 void TS_DirectionalChannelInfo_free(uint32_t this_ptr) {
14963         LDKDirectionalChannelInfo this_ptr_conv;
14964         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14965         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
14966         DirectionalChannelInfo_free(this_ptr_conv);
14967 }
14968
14969 int32_t TS_DirectionalChannelInfo_get_last_update(uint32_t this_ptr) {
14970         LDKDirectionalChannelInfo this_ptr_conv;
14971         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14972         this_ptr_conv.is_owned = false;
14973         int32_t ret_val = DirectionalChannelInfo_get_last_update(&this_ptr_conv);
14974         return ret_val;
14975 }
14976
14977 void TS_DirectionalChannelInfo_set_last_update(uint32_t this_ptr, int32_t val) {
14978         LDKDirectionalChannelInfo this_ptr_conv;
14979         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14980         this_ptr_conv.is_owned = false;
14981         DirectionalChannelInfo_set_last_update(&this_ptr_conv, val);
14982 }
14983
14984 jboolean TS_DirectionalChannelInfo_get_enabled(uint32_t this_ptr) {
14985         LDKDirectionalChannelInfo this_ptr_conv;
14986         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14987         this_ptr_conv.is_owned = false;
14988         jboolean ret_val = DirectionalChannelInfo_get_enabled(&this_ptr_conv);
14989         return ret_val;
14990 }
14991
14992 void TS_DirectionalChannelInfo_set_enabled(uint32_t this_ptr, jboolean val) {
14993         LDKDirectionalChannelInfo this_ptr_conv;
14994         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14995         this_ptr_conv.is_owned = false;
14996         DirectionalChannelInfo_set_enabled(&this_ptr_conv, val);
14997 }
14998
14999 int16_t TS_DirectionalChannelInfo_get_cltv_expiry_delta(uint32_t this_ptr) {
15000         LDKDirectionalChannelInfo this_ptr_conv;
15001         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15002         this_ptr_conv.is_owned = false;
15003         int16_t ret_val = DirectionalChannelInfo_get_cltv_expiry_delta(&this_ptr_conv);
15004         return ret_val;
15005 }
15006
15007 void TS_DirectionalChannelInfo_set_cltv_expiry_delta(uint32_t this_ptr, int16_t val) {
15008         LDKDirectionalChannelInfo this_ptr_conv;
15009         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15010         this_ptr_conv.is_owned = false;
15011         DirectionalChannelInfo_set_cltv_expiry_delta(&this_ptr_conv, val);
15012 }
15013
15014 int64_t TS_DirectionalChannelInfo_get_htlc_minimum_msat(uint32_t this_ptr) {
15015         LDKDirectionalChannelInfo this_ptr_conv;
15016         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15017         this_ptr_conv.is_owned = false;
15018         int64_t ret_val = DirectionalChannelInfo_get_htlc_minimum_msat(&this_ptr_conv);
15019         return ret_val;
15020 }
15021
15022 void TS_DirectionalChannelInfo_set_htlc_minimum_msat(uint32_t this_ptr, int64_t val) {
15023         LDKDirectionalChannelInfo this_ptr_conv;
15024         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15025         this_ptr_conv.is_owned = false;
15026         DirectionalChannelInfo_set_htlc_minimum_msat(&this_ptr_conv, val);
15027 }
15028
15029 uint32_t TS_DirectionalChannelInfo_get_fees(uint32_t this_ptr) {
15030         LDKDirectionalChannelInfo this_ptr_conv;
15031         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15032         this_ptr_conv.is_owned = false;
15033         LDKRoutingFees ret_var = DirectionalChannelInfo_get_fees(&this_ptr_conv);
15034         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15035         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15036         long ret_ref = (long)ret_var.inner;
15037         if (ret_var.is_owned) {
15038                 ret_ref |= 1;
15039         }
15040         return ret_ref;
15041 }
15042
15043 void TS_DirectionalChannelInfo_set_fees(uint32_t this_ptr, uint32_t val) {
15044         LDKDirectionalChannelInfo this_ptr_conv;
15045         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15046         this_ptr_conv.is_owned = false;
15047         LDKRoutingFees val_conv;
15048         val_conv.inner = (void*)(val & (~1));
15049         val_conv.is_owned = (val & 1) || (val == 0);
15050         if (val_conv.inner != NULL)
15051                 val_conv = RoutingFees_clone(&val_conv);
15052         DirectionalChannelInfo_set_fees(&this_ptr_conv, val_conv);
15053 }
15054
15055 uint32_t TS_DirectionalChannelInfo_get_last_update_message(uint32_t this_ptr) {
15056         LDKDirectionalChannelInfo this_ptr_conv;
15057         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15058         this_ptr_conv.is_owned = false;
15059         LDKChannelUpdate ret_var = DirectionalChannelInfo_get_last_update_message(&this_ptr_conv);
15060         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15061         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15062         long ret_ref = (long)ret_var.inner;
15063         if (ret_var.is_owned) {
15064                 ret_ref |= 1;
15065         }
15066         return ret_ref;
15067 }
15068
15069 void TS_DirectionalChannelInfo_set_last_update_message(uint32_t this_ptr, uint32_t val) {
15070         LDKDirectionalChannelInfo this_ptr_conv;
15071         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15072         this_ptr_conv.is_owned = false;
15073         LDKChannelUpdate val_conv;
15074         val_conv.inner = (void*)(val & (~1));
15075         val_conv.is_owned = (val & 1) || (val == 0);
15076         if (val_conv.inner != NULL)
15077                 val_conv = ChannelUpdate_clone(&val_conv);
15078         DirectionalChannelInfo_set_last_update_message(&this_ptr_conv, val_conv);
15079 }
15080
15081 int8_tArray TS_DirectionalChannelInfo_write(uint32_t obj) {
15082         LDKDirectionalChannelInfo obj_conv;
15083         obj_conv.inner = (void*)(obj & (~1));
15084         obj_conv.is_owned = false;
15085         LDKCVec_u8Z arg_var = DirectionalChannelInfo_write(&obj_conv);
15086         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
15087         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
15088         CVec_u8Z_free(arg_var);
15089         return arg_arr;
15090 }
15091
15092 uint32_t TS_DirectionalChannelInfo_read(int8_tArray ser) {
15093         LDKu8slice ser_ref;
15094         ser_ref.datalen = *((uint32_t*)ser);
15095         ser_ref.data = (int8_t*)(ser + 4);
15096         LDKDirectionalChannelInfo ret_var = DirectionalChannelInfo_read(ser_ref);
15097         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15098         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15099         long ret_ref = (long)ret_var.inner;
15100         if (ret_var.is_owned) {
15101                 ret_ref |= 1;
15102         }
15103         return ret_ref;
15104 }
15105
15106 void TS_ChannelInfo_free(uint32_t this_ptr) {
15107         LDKChannelInfo this_ptr_conv;
15108         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15109         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
15110         ChannelInfo_free(this_ptr_conv);
15111 }
15112
15113 uint32_t TS_ChannelInfo_get_features(uint32_t this_ptr) {
15114         LDKChannelInfo this_ptr_conv;
15115         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15116         this_ptr_conv.is_owned = false;
15117         LDKChannelFeatures ret_var = ChannelInfo_get_features(&this_ptr_conv);
15118         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15119         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15120         long ret_ref = (long)ret_var.inner;
15121         if (ret_var.is_owned) {
15122                 ret_ref |= 1;
15123         }
15124         return ret_ref;
15125 }
15126
15127 void TS_ChannelInfo_set_features(uint32_t this_ptr, uint32_t val) {
15128         LDKChannelInfo this_ptr_conv;
15129         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15130         this_ptr_conv.is_owned = false;
15131         LDKChannelFeatures val_conv;
15132         val_conv.inner = (void*)(val & (~1));
15133         val_conv.is_owned = (val & 1) || (val == 0);
15134         // Warning: we may need a move here but can't clone!
15135         ChannelInfo_set_features(&this_ptr_conv, val_conv);
15136 }
15137
15138 int8_tArray TS_ChannelInfo_get_node_one(uint32_t this_ptr) {
15139         LDKChannelInfo this_ptr_conv;
15140         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15141         this_ptr_conv.is_owned = false;
15142         int8_tArray arg_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
15143         memcpy((uint8_t*)(arg_arr + 4), ChannelInfo_get_node_one(&this_ptr_conv).compressed_form, 33);
15144         return arg_arr;
15145 }
15146
15147 void TS_ChannelInfo_set_node_one(uint32_t this_ptr, int8_tArray val) {
15148         LDKChannelInfo this_ptr_conv;
15149         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15150         this_ptr_conv.is_owned = false;
15151         LDKPublicKey val_ref;
15152         CHECK(*((uint32_t*)val) == 33);
15153         memcpy(val_ref.compressed_form, (uint8_t*)(val + 4), 33);
15154         ChannelInfo_set_node_one(&this_ptr_conv, val_ref);
15155 }
15156
15157 uint32_t TS_ChannelInfo_get_one_to_two(uint32_t this_ptr) {
15158         LDKChannelInfo this_ptr_conv;
15159         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15160         this_ptr_conv.is_owned = false;
15161         LDKDirectionalChannelInfo ret_var = ChannelInfo_get_one_to_two(&this_ptr_conv);
15162         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15163         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15164         long ret_ref = (long)ret_var.inner;
15165         if (ret_var.is_owned) {
15166                 ret_ref |= 1;
15167         }
15168         return ret_ref;
15169 }
15170
15171 void TS_ChannelInfo_set_one_to_two(uint32_t this_ptr, uint32_t val) {
15172         LDKChannelInfo this_ptr_conv;
15173         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15174         this_ptr_conv.is_owned = false;
15175         LDKDirectionalChannelInfo val_conv;
15176         val_conv.inner = (void*)(val & (~1));
15177         val_conv.is_owned = (val & 1) || (val == 0);
15178         // Warning: we may need a move here but can't clone!
15179         ChannelInfo_set_one_to_two(&this_ptr_conv, val_conv);
15180 }
15181
15182 int8_tArray TS_ChannelInfo_get_node_two(uint32_t this_ptr) {
15183         LDKChannelInfo this_ptr_conv;
15184         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15185         this_ptr_conv.is_owned = false;
15186         int8_tArray arg_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
15187         memcpy((uint8_t*)(arg_arr + 4), ChannelInfo_get_node_two(&this_ptr_conv).compressed_form, 33);
15188         return arg_arr;
15189 }
15190
15191 void TS_ChannelInfo_set_node_two(uint32_t this_ptr, int8_tArray val) {
15192         LDKChannelInfo this_ptr_conv;
15193         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15194         this_ptr_conv.is_owned = false;
15195         LDKPublicKey val_ref;
15196         CHECK(*((uint32_t*)val) == 33);
15197         memcpy(val_ref.compressed_form, (uint8_t*)(val + 4), 33);
15198         ChannelInfo_set_node_two(&this_ptr_conv, val_ref);
15199 }
15200
15201 uint32_t TS_ChannelInfo_get_two_to_one(uint32_t this_ptr) {
15202         LDKChannelInfo this_ptr_conv;
15203         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15204         this_ptr_conv.is_owned = false;
15205         LDKDirectionalChannelInfo ret_var = ChannelInfo_get_two_to_one(&this_ptr_conv);
15206         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15207         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15208         long ret_ref = (long)ret_var.inner;
15209         if (ret_var.is_owned) {
15210                 ret_ref |= 1;
15211         }
15212         return ret_ref;
15213 }
15214
15215 void TS_ChannelInfo_set_two_to_one(uint32_t this_ptr, uint32_t val) {
15216         LDKChannelInfo this_ptr_conv;
15217         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15218         this_ptr_conv.is_owned = false;
15219         LDKDirectionalChannelInfo val_conv;
15220         val_conv.inner = (void*)(val & (~1));
15221         val_conv.is_owned = (val & 1) || (val == 0);
15222         // Warning: we may need a move here but can't clone!
15223         ChannelInfo_set_two_to_one(&this_ptr_conv, val_conv);
15224 }
15225
15226 uint32_t TS_ChannelInfo_get_announcement_message(uint32_t this_ptr) {
15227         LDKChannelInfo this_ptr_conv;
15228         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15229         this_ptr_conv.is_owned = false;
15230         LDKChannelAnnouncement ret_var = ChannelInfo_get_announcement_message(&this_ptr_conv);
15231         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15232         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15233         long ret_ref = (long)ret_var.inner;
15234         if (ret_var.is_owned) {
15235                 ret_ref |= 1;
15236         }
15237         return ret_ref;
15238 }
15239
15240 void TS_ChannelInfo_set_announcement_message(uint32_t this_ptr, uint32_t val) {
15241         LDKChannelInfo this_ptr_conv;
15242         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15243         this_ptr_conv.is_owned = false;
15244         LDKChannelAnnouncement val_conv;
15245         val_conv.inner = (void*)(val & (~1));
15246         val_conv.is_owned = (val & 1) || (val == 0);
15247         if (val_conv.inner != NULL)
15248                 val_conv = ChannelAnnouncement_clone(&val_conv);
15249         ChannelInfo_set_announcement_message(&this_ptr_conv, val_conv);
15250 }
15251
15252 int8_tArray TS_ChannelInfo_write(uint32_t obj) {
15253         LDKChannelInfo obj_conv;
15254         obj_conv.inner = (void*)(obj & (~1));
15255         obj_conv.is_owned = false;
15256         LDKCVec_u8Z arg_var = ChannelInfo_write(&obj_conv);
15257         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
15258         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
15259         CVec_u8Z_free(arg_var);
15260         return arg_arr;
15261 }
15262
15263 uint32_t TS_ChannelInfo_read(int8_tArray ser) {
15264         LDKu8slice ser_ref;
15265         ser_ref.datalen = *((uint32_t*)ser);
15266         ser_ref.data = (int8_t*)(ser + 4);
15267         LDKChannelInfo ret_var = ChannelInfo_read(ser_ref);
15268         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15269         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15270         long ret_ref = (long)ret_var.inner;
15271         if (ret_var.is_owned) {
15272                 ret_ref |= 1;
15273         }
15274         return ret_ref;
15275 }
15276
15277 void TS_RoutingFees_free(uint32_t this_ptr) {
15278         LDKRoutingFees this_ptr_conv;
15279         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15280         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
15281         RoutingFees_free(this_ptr_conv);
15282 }
15283
15284 uint32_t TS_RoutingFees_clone(uint32_t orig) {
15285         LDKRoutingFees orig_conv;
15286         orig_conv.inner = (void*)(orig & (~1));
15287         orig_conv.is_owned = false;
15288         LDKRoutingFees ret_var = RoutingFees_clone(&orig_conv);
15289         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15290         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15291         long ret_ref = (long)ret_var.inner;
15292         if (ret_var.is_owned) {
15293                 ret_ref |= 1;
15294         }
15295         return ret_ref;
15296 }
15297
15298 int32_t TS_RoutingFees_get_base_msat(uint32_t this_ptr) {
15299         LDKRoutingFees this_ptr_conv;
15300         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15301         this_ptr_conv.is_owned = false;
15302         int32_t ret_val = RoutingFees_get_base_msat(&this_ptr_conv);
15303         return ret_val;
15304 }
15305
15306 void TS_RoutingFees_set_base_msat(uint32_t this_ptr, int32_t val) {
15307         LDKRoutingFees this_ptr_conv;
15308         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15309         this_ptr_conv.is_owned = false;
15310         RoutingFees_set_base_msat(&this_ptr_conv, val);
15311 }
15312
15313 int32_t TS_RoutingFees_get_proportional_millionths(uint32_t this_ptr) {
15314         LDKRoutingFees this_ptr_conv;
15315         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15316         this_ptr_conv.is_owned = false;
15317         int32_t ret_val = RoutingFees_get_proportional_millionths(&this_ptr_conv);
15318         return ret_val;
15319 }
15320
15321 void TS_RoutingFees_set_proportional_millionths(uint32_t this_ptr, int32_t val) {
15322         LDKRoutingFees this_ptr_conv;
15323         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15324         this_ptr_conv.is_owned = false;
15325         RoutingFees_set_proportional_millionths(&this_ptr_conv, val);
15326 }
15327
15328 uint32_t TS_RoutingFees_new(int32_t base_msat_arg, int32_t proportional_millionths_arg) {
15329         LDKRoutingFees ret_var = RoutingFees_new(base_msat_arg, proportional_millionths_arg);
15330         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15331         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15332         long ret_ref = (long)ret_var.inner;
15333         if (ret_var.is_owned) {
15334                 ret_ref |= 1;
15335         }
15336         return ret_ref;
15337 }
15338
15339 uint32_t TS_RoutingFees_read(int8_tArray ser) {
15340         LDKu8slice ser_ref;
15341         ser_ref.datalen = *((uint32_t*)ser);
15342         ser_ref.data = (int8_t*)(ser + 4);
15343         LDKCResult_RoutingFeesDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_RoutingFeesDecodeErrorZ), "LDKCResult_RoutingFeesDecodeErrorZ");
15344         *ret_conv = RoutingFees_read(ser_ref);
15345         return (long)ret_conv;
15346 }
15347
15348 int8_tArray TS_RoutingFees_write(uint32_t obj) {
15349         LDKRoutingFees obj_conv;
15350         obj_conv.inner = (void*)(obj & (~1));
15351         obj_conv.is_owned = false;
15352         LDKCVec_u8Z arg_var = RoutingFees_write(&obj_conv);
15353         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
15354         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
15355         CVec_u8Z_free(arg_var);
15356         return arg_arr;
15357 }
15358
15359 void TS_NodeAnnouncementInfo_free(uint32_t this_ptr) {
15360         LDKNodeAnnouncementInfo this_ptr_conv;
15361         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15362         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
15363         NodeAnnouncementInfo_free(this_ptr_conv);
15364 }
15365
15366 uint32_t TS_NodeAnnouncementInfo_get_features(uint32_t this_ptr) {
15367         LDKNodeAnnouncementInfo this_ptr_conv;
15368         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15369         this_ptr_conv.is_owned = false;
15370         LDKNodeFeatures ret_var = NodeAnnouncementInfo_get_features(&this_ptr_conv);
15371         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15372         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15373         long ret_ref = (long)ret_var.inner;
15374         if (ret_var.is_owned) {
15375                 ret_ref |= 1;
15376         }
15377         return ret_ref;
15378 }
15379
15380 void TS_NodeAnnouncementInfo_set_features(uint32_t this_ptr, uint32_t val) {
15381         LDKNodeAnnouncementInfo this_ptr_conv;
15382         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15383         this_ptr_conv.is_owned = false;
15384         LDKNodeFeatures val_conv;
15385         val_conv.inner = (void*)(val & (~1));
15386         val_conv.is_owned = (val & 1) || (val == 0);
15387         // Warning: we may need a move here but can't clone!
15388         NodeAnnouncementInfo_set_features(&this_ptr_conv, val_conv);
15389 }
15390
15391 int32_t TS_NodeAnnouncementInfo_get_last_update(uint32_t this_ptr) {
15392         LDKNodeAnnouncementInfo this_ptr_conv;
15393         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15394         this_ptr_conv.is_owned = false;
15395         int32_t ret_val = NodeAnnouncementInfo_get_last_update(&this_ptr_conv);
15396         return ret_val;
15397 }
15398
15399 void TS_NodeAnnouncementInfo_set_last_update(uint32_t this_ptr, int32_t val) {
15400         LDKNodeAnnouncementInfo this_ptr_conv;
15401         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15402         this_ptr_conv.is_owned = false;
15403         NodeAnnouncementInfo_set_last_update(&this_ptr_conv, val);
15404 }
15405
15406 int8_tArray TS_NodeAnnouncementInfo_get_rgb(uint32_t this_ptr) {
15407         LDKNodeAnnouncementInfo this_ptr_conv;
15408         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15409         this_ptr_conv.is_owned = false;
15410         int8_tArray ret_arr = init_arr(3, sizeof(uint8_t), "Native int8_tArray Bytes");
15411         memcpy((uint8_t*)(ret_arr + 4), *NodeAnnouncementInfo_get_rgb(&this_ptr_conv), 3);
15412         return ret_arr;
15413 }
15414
15415 void TS_NodeAnnouncementInfo_set_rgb(uint32_t this_ptr, int8_tArray val) {
15416         LDKNodeAnnouncementInfo this_ptr_conv;
15417         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15418         this_ptr_conv.is_owned = false;
15419         LDKThreeBytes val_ref;
15420         CHECK(*((uint32_t*)val) == 3);
15421         memcpy(val_ref.data, (uint8_t*)(val + 4), 3);
15422         NodeAnnouncementInfo_set_rgb(&this_ptr_conv, val_ref);
15423 }
15424
15425 int8_tArray TS_NodeAnnouncementInfo_get_alias(uint32_t this_ptr) {
15426         LDKNodeAnnouncementInfo this_ptr_conv;
15427         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15428         this_ptr_conv.is_owned = false;
15429         int8_tArray ret_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
15430         memcpy((uint8_t*)(ret_arr + 4), *NodeAnnouncementInfo_get_alias(&this_ptr_conv), 32);
15431         return ret_arr;
15432 }
15433
15434 void TS_NodeAnnouncementInfo_set_alias(uint32_t this_ptr, int8_tArray val) {
15435         LDKNodeAnnouncementInfo this_ptr_conv;
15436         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15437         this_ptr_conv.is_owned = false;
15438         LDKThirtyTwoBytes val_ref;
15439         CHECK(*((uint32_t*)val) == 32);
15440         memcpy(val_ref.data, (uint8_t*)(val + 4), 32);
15441         NodeAnnouncementInfo_set_alias(&this_ptr_conv, val_ref);
15442 }
15443
15444 void TS_NodeAnnouncementInfo_set_addresses(uint32_t this_ptr, uint32_tArray val) {
15445         LDKNodeAnnouncementInfo this_ptr_conv;
15446         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15447         this_ptr_conv.is_owned = false;
15448         LDKCVec_NetAddressZ val_constr;
15449         val_constr.datalen = *((uint32_t*)val);
15450         if (val_constr.datalen > 0)
15451                 val_constr.data = MALLOC(val_constr.datalen * sizeof(LDKNetAddress), "LDKCVec_NetAddressZ Elements");
15452         else
15453                 val_constr.data = NULL;
15454         uint32_t* val_vals = (uint32_t*)(val + 4);
15455         for (size_t m = 0; m < val_constr.datalen; m++) {
15456                 uint32_t arr_conv_12 = val_vals[m];
15457                 LDKNetAddress arr_conv_12_conv = *(LDKNetAddress*)arr_conv_12;
15458                 FREE((void*)arr_conv_12);
15459                 val_constr.data[m] = arr_conv_12_conv;
15460         }
15461         NodeAnnouncementInfo_set_addresses(&this_ptr_conv, val_constr);
15462 }
15463
15464 uint32_t TS_NodeAnnouncementInfo_get_announcement_message(uint32_t this_ptr) {
15465         LDKNodeAnnouncementInfo this_ptr_conv;
15466         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15467         this_ptr_conv.is_owned = false;
15468         LDKNodeAnnouncement ret_var = NodeAnnouncementInfo_get_announcement_message(&this_ptr_conv);
15469         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15470         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15471         long ret_ref = (long)ret_var.inner;
15472         if (ret_var.is_owned) {
15473                 ret_ref |= 1;
15474         }
15475         return ret_ref;
15476 }
15477
15478 void TS_NodeAnnouncementInfo_set_announcement_message(uint32_t this_ptr, uint32_t val) {
15479         LDKNodeAnnouncementInfo this_ptr_conv;
15480         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15481         this_ptr_conv.is_owned = false;
15482         LDKNodeAnnouncement val_conv;
15483         val_conv.inner = (void*)(val & (~1));
15484         val_conv.is_owned = (val & 1) || (val == 0);
15485         if (val_conv.inner != NULL)
15486                 val_conv = NodeAnnouncement_clone(&val_conv);
15487         NodeAnnouncementInfo_set_announcement_message(&this_ptr_conv, val_conv);
15488 }
15489
15490 uint32_t TS_NodeAnnouncementInfo_new(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) {
15491         LDKNodeFeatures features_arg_conv;
15492         features_arg_conv.inner = (void*)(features_arg & (~1));
15493         features_arg_conv.is_owned = (features_arg & 1) || (features_arg == 0);
15494         // Warning: we may need a move here but can't clone!
15495         LDKThreeBytes rgb_arg_ref;
15496         CHECK(*((uint32_t*)rgb_arg) == 3);
15497         memcpy(rgb_arg_ref.data, (uint8_t*)(rgb_arg + 4), 3);
15498         LDKThirtyTwoBytes alias_arg_ref;
15499         CHECK(*((uint32_t*)alias_arg) == 32);
15500         memcpy(alias_arg_ref.data, (uint8_t*)(alias_arg + 4), 32);
15501         LDKCVec_NetAddressZ addresses_arg_constr;
15502         addresses_arg_constr.datalen = *((uint32_t*)addresses_arg);
15503         if (addresses_arg_constr.datalen > 0)
15504                 addresses_arg_constr.data = MALLOC(addresses_arg_constr.datalen * sizeof(LDKNetAddress), "LDKCVec_NetAddressZ Elements");
15505         else
15506                 addresses_arg_constr.data = NULL;
15507         uint32_t* addresses_arg_vals = (uint32_t*)(addresses_arg + 4);
15508         for (size_t m = 0; m < addresses_arg_constr.datalen; m++) {
15509                 uint32_t arr_conv_12 = addresses_arg_vals[m];
15510                 LDKNetAddress arr_conv_12_conv = *(LDKNetAddress*)arr_conv_12;
15511                 FREE((void*)arr_conv_12);
15512                 addresses_arg_constr.data[m] = arr_conv_12_conv;
15513         }
15514         LDKNodeAnnouncement announcement_message_arg_conv;
15515         announcement_message_arg_conv.inner = (void*)(announcement_message_arg & (~1));
15516         announcement_message_arg_conv.is_owned = (announcement_message_arg & 1) || (announcement_message_arg == 0);
15517         if (announcement_message_arg_conv.inner != NULL)
15518                 announcement_message_arg_conv = NodeAnnouncement_clone(&announcement_message_arg_conv);
15519         LDKNodeAnnouncementInfo ret_var = NodeAnnouncementInfo_new(features_arg_conv, last_update_arg, rgb_arg_ref, alias_arg_ref, addresses_arg_constr, announcement_message_arg_conv);
15520         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15521         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15522         long ret_ref = (long)ret_var.inner;
15523         if (ret_var.is_owned) {
15524                 ret_ref |= 1;
15525         }
15526         return ret_ref;
15527 }
15528
15529 int8_tArray TS_NodeAnnouncementInfo_write(uint32_t obj) {
15530         LDKNodeAnnouncementInfo obj_conv;
15531         obj_conv.inner = (void*)(obj & (~1));
15532         obj_conv.is_owned = false;
15533         LDKCVec_u8Z arg_var = NodeAnnouncementInfo_write(&obj_conv);
15534         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
15535         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
15536         CVec_u8Z_free(arg_var);
15537         return arg_arr;
15538 }
15539
15540 uint32_t TS_NodeAnnouncementInfo_read(int8_tArray ser) {
15541         LDKu8slice ser_ref;
15542         ser_ref.datalen = *((uint32_t*)ser);
15543         ser_ref.data = (int8_t*)(ser + 4);
15544         LDKCResult_NodeAnnouncementInfoDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NodeAnnouncementInfoDecodeErrorZ), "LDKCResult_NodeAnnouncementInfoDecodeErrorZ");
15545         *ret_conv = NodeAnnouncementInfo_read(ser_ref);
15546         return (long)ret_conv;
15547 }
15548
15549 void TS_NodeInfo_free(uint32_t this_ptr) {
15550         LDKNodeInfo this_ptr_conv;
15551         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15552         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
15553         NodeInfo_free(this_ptr_conv);
15554 }
15555
15556 void TS_NodeInfo_set_channels(uint32_t this_ptr, int64_tArray val) {
15557         LDKNodeInfo this_ptr_conv;
15558         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15559         this_ptr_conv.is_owned = false;
15560         LDKCVec_u64Z val_constr;
15561         val_constr.datalen = *((uint32_t*)val);
15562         if (val_constr.datalen > 0)
15563                 val_constr.data = MALLOC(val_constr.datalen * sizeof(int64_t), "LDKCVec_u64Z Elements");
15564         else
15565                 val_constr.data = NULL;
15566         int64_t* val_vals = (int64_t*)(val + 4);
15567         for (size_t i = 0; i < val_constr.datalen; i++) {
15568                 int64_t arr_conv_8 = val_vals[i];
15569                 val_constr.data[i] = arr_conv_8;
15570         }
15571         NodeInfo_set_channels(&this_ptr_conv, val_constr);
15572 }
15573
15574 uint32_t TS_NodeInfo_get_lowest_inbound_channel_fees(uint32_t this_ptr) {
15575         LDKNodeInfo this_ptr_conv;
15576         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15577         this_ptr_conv.is_owned = false;
15578         LDKRoutingFees ret_var = NodeInfo_get_lowest_inbound_channel_fees(&this_ptr_conv);
15579         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15580         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15581         long ret_ref = (long)ret_var.inner;
15582         if (ret_var.is_owned) {
15583                 ret_ref |= 1;
15584         }
15585         return ret_ref;
15586 }
15587
15588 void TS_NodeInfo_set_lowest_inbound_channel_fees(uint32_t this_ptr, uint32_t val) {
15589         LDKNodeInfo this_ptr_conv;
15590         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15591         this_ptr_conv.is_owned = false;
15592         LDKRoutingFees val_conv;
15593         val_conv.inner = (void*)(val & (~1));
15594         val_conv.is_owned = (val & 1) || (val == 0);
15595         if (val_conv.inner != NULL)
15596                 val_conv = RoutingFees_clone(&val_conv);
15597         NodeInfo_set_lowest_inbound_channel_fees(&this_ptr_conv, val_conv);
15598 }
15599
15600 uint32_t TS_NodeInfo_get_announcement_info(uint32_t this_ptr) {
15601         LDKNodeInfo this_ptr_conv;
15602         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15603         this_ptr_conv.is_owned = false;
15604         LDKNodeAnnouncementInfo ret_var = NodeInfo_get_announcement_info(&this_ptr_conv);
15605         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15606         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15607         long ret_ref = (long)ret_var.inner;
15608         if (ret_var.is_owned) {
15609                 ret_ref |= 1;
15610         }
15611         return ret_ref;
15612 }
15613
15614 void TS_NodeInfo_set_announcement_info(uint32_t this_ptr, uint32_t val) {
15615         LDKNodeInfo this_ptr_conv;
15616         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15617         this_ptr_conv.is_owned = false;
15618         LDKNodeAnnouncementInfo val_conv;
15619         val_conv.inner = (void*)(val & (~1));
15620         val_conv.is_owned = (val & 1) || (val == 0);
15621         // Warning: we may need a move here but can't clone!
15622         NodeInfo_set_announcement_info(&this_ptr_conv, val_conv);
15623 }
15624
15625 uint32_t TS_NodeInfo_new(int64_tArray channels_arg, uint32_t lowest_inbound_channel_fees_arg, uint32_t announcement_info_arg) {
15626         LDKCVec_u64Z channels_arg_constr;
15627         channels_arg_constr.datalen = *((uint32_t*)channels_arg);
15628         if (channels_arg_constr.datalen > 0)
15629                 channels_arg_constr.data = MALLOC(channels_arg_constr.datalen * sizeof(int64_t), "LDKCVec_u64Z Elements");
15630         else
15631                 channels_arg_constr.data = NULL;
15632         int64_t* channels_arg_vals = (int64_t*)(channels_arg + 4);
15633         for (size_t i = 0; i < channels_arg_constr.datalen; i++) {
15634                 int64_t arr_conv_8 = channels_arg_vals[i];
15635                 channels_arg_constr.data[i] = arr_conv_8;
15636         }
15637         LDKRoutingFees lowest_inbound_channel_fees_arg_conv;
15638         lowest_inbound_channel_fees_arg_conv.inner = (void*)(lowest_inbound_channel_fees_arg & (~1));
15639         lowest_inbound_channel_fees_arg_conv.is_owned = (lowest_inbound_channel_fees_arg & 1) || (lowest_inbound_channel_fees_arg == 0);
15640         if (lowest_inbound_channel_fees_arg_conv.inner != NULL)
15641                 lowest_inbound_channel_fees_arg_conv = RoutingFees_clone(&lowest_inbound_channel_fees_arg_conv);
15642         LDKNodeAnnouncementInfo announcement_info_arg_conv;
15643         announcement_info_arg_conv.inner = (void*)(announcement_info_arg & (~1));
15644         announcement_info_arg_conv.is_owned = (announcement_info_arg & 1) || (announcement_info_arg == 0);
15645         // Warning: we may need a move here but can't clone!
15646         LDKNodeInfo ret_var = NodeInfo_new(channels_arg_constr, lowest_inbound_channel_fees_arg_conv, announcement_info_arg_conv);
15647         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15648         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15649         long ret_ref = (long)ret_var.inner;
15650         if (ret_var.is_owned) {
15651                 ret_ref |= 1;
15652         }
15653         return ret_ref;
15654 }
15655
15656 int8_tArray TS_NodeInfo_write(uint32_t obj) {
15657         LDKNodeInfo obj_conv;
15658         obj_conv.inner = (void*)(obj & (~1));
15659         obj_conv.is_owned = false;
15660         LDKCVec_u8Z arg_var = NodeInfo_write(&obj_conv);
15661         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
15662         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
15663         CVec_u8Z_free(arg_var);
15664         return arg_arr;
15665 }
15666
15667 uint32_t TS_NodeInfo_read(int8_tArray ser) {
15668         LDKu8slice ser_ref;
15669         ser_ref.datalen = *((uint32_t*)ser);
15670         ser_ref.data = (int8_t*)(ser + 4);
15671         LDKCResult_NodeInfoDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NodeInfoDecodeErrorZ), "LDKCResult_NodeInfoDecodeErrorZ");
15672         *ret_conv = NodeInfo_read(ser_ref);
15673         return (long)ret_conv;
15674 }
15675
15676 int8_tArray TS_NetworkGraph_write(uint32_t obj) {
15677         LDKNetworkGraph obj_conv;
15678         obj_conv.inner = (void*)(obj & (~1));
15679         obj_conv.is_owned = false;
15680         LDKCVec_u8Z arg_var = NetworkGraph_write(&obj_conv);
15681         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
15682         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
15683         CVec_u8Z_free(arg_var);
15684         return arg_arr;
15685 }
15686
15687 uint32_t TS_NetworkGraph_read(int8_tArray ser) {
15688         LDKu8slice ser_ref;
15689         ser_ref.datalen = *((uint32_t*)ser);
15690         ser_ref.data = (int8_t*)(ser + 4);
15691         LDKCResult_NetworkGraphDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NetworkGraphDecodeErrorZ), "LDKCResult_NetworkGraphDecodeErrorZ");
15692         *ret_conv = NetworkGraph_read(ser_ref);
15693         return (long)ret_conv;
15694 }
15695
15696 uint32_t TS_NetworkGraph_new(int8_tArray genesis_hash) {
15697         LDKThirtyTwoBytes genesis_hash_ref;
15698         CHECK(*((uint32_t*)genesis_hash) == 32);
15699         memcpy(genesis_hash_ref.data, (uint8_t*)(genesis_hash + 4), 32);
15700         LDKNetworkGraph ret_var = NetworkGraph_new(genesis_hash_ref);
15701         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15702         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15703         long ret_ref = (long)ret_var.inner;
15704         if (ret_var.is_owned) {
15705                 ret_ref |= 1;
15706         }
15707         return ret_ref;
15708 }
15709
15710 uint32_t TS_NetworkGraph_update_node_from_announcement(uint32_t this_arg, uint32_t msg) {
15711         LDKNetworkGraph this_arg_conv;
15712         this_arg_conv.inner = (void*)(this_arg & (~1));
15713         this_arg_conv.is_owned = false;
15714         LDKNodeAnnouncement msg_conv;
15715         msg_conv.inner = (void*)(msg & (~1));
15716         msg_conv.is_owned = false;
15717         LDKCResult_NoneLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneLightningErrorZ), "LDKCResult_NoneLightningErrorZ");
15718         *ret_conv = NetworkGraph_update_node_from_announcement(&this_arg_conv, &msg_conv);
15719         return (long)ret_conv;
15720 }
15721
15722 uint32_t TS_NetworkGraph_update_node_from_unsigned_announcement(uint32_t this_arg, uint32_t msg) {
15723         LDKNetworkGraph this_arg_conv;
15724         this_arg_conv.inner = (void*)(this_arg & (~1));
15725         this_arg_conv.is_owned = false;
15726         LDKUnsignedNodeAnnouncement msg_conv;
15727         msg_conv.inner = (void*)(msg & (~1));
15728         msg_conv.is_owned = false;
15729         LDKCResult_NoneLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneLightningErrorZ), "LDKCResult_NoneLightningErrorZ");
15730         *ret_conv = NetworkGraph_update_node_from_unsigned_announcement(&this_arg_conv, &msg_conv);
15731         return (long)ret_conv;
15732 }
15733
15734 uint32_t TS_NetworkGraph_update_channel_from_announcement(uint32_t this_arg, uint32_t msg, uint32_t chain_access) {
15735         LDKNetworkGraph this_arg_conv;
15736         this_arg_conv.inner = (void*)(this_arg & (~1));
15737         this_arg_conv.is_owned = false;
15738         LDKChannelAnnouncement msg_conv;
15739         msg_conv.inner = (void*)(msg & (~1));
15740         msg_conv.is_owned = false;
15741         LDKAccess* chain_access_conv = (LDKAccess*)chain_access;
15742         LDKCResult_NoneLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneLightningErrorZ), "LDKCResult_NoneLightningErrorZ");
15743         *ret_conv = NetworkGraph_update_channel_from_announcement(&this_arg_conv, &msg_conv, chain_access_conv);
15744         return (long)ret_conv;
15745 }
15746
15747 uint32_t TS_NetworkGraph_update_channel_from_unsigned_announcement(uint32_t this_arg, uint32_t msg, uint32_t chain_access) {
15748         LDKNetworkGraph this_arg_conv;
15749         this_arg_conv.inner = (void*)(this_arg & (~1));
15750         this_arg_conv.is_owned = false;
15751         LDKUnsignedChannelAnnouncement msg_conv;
15752         msg_conv.inner = (void*)(msg & (~1));
15753         msg_conv.is_owned = false;
15754         LDKAccess* chain_access_conv = (LDKAccess*)chain_access;
15755         LDKCResult_NoneLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneLightningErrorZ), "LDKCResult_NoneLightningErrorZ");
15756         *ret_conv = NetworkGraph_update_channel_from_unsigned_announcement(&this_arg_conv, &msg_conv, chain_access_conv);
15757         return (long)ret_conv;
15758 }
15759
15760 void TS_NetworkGraph_close_channel_from_update(uint32_t this_arg, int64_t short_channel_id, jboolean is_permanent) {
15761         LDKNetworkGraph this_arg_conv;
15762         this_arg_conv.inner = (void*)(this_arg & (~1));
15763         this_arg_conv.is_owned = false;
15764         NetworkGraph_close_channel_from_update(&this_arg_conv, short_channel_id, is_permanent);
15765 }
15766
15767 uint32_t TS_NetworkGraph_update_channel(uint32_t this_arg, uint32_t msg) {
15768         LDKNetworkGraph this_arg_conv;
15769         this_arg_conv.inner = (void*)(this_arg & (~1));
15770         this_arg_conv.is_owned = false;
15771         LDKChannelUpdate msg_conv;
15772         msg_conv.inner = (void*)(msg & (~1));
15773         msg_conv.is_owned = false;
15774         LDKCResult_NoneLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneLightningErrorZ), "LDKCResult_NoneLightningErrorZ");
15775         *ret_conv = NetworkGraph_update_channel(&this_arg_conv, &msg_conv);
15776         return (long)ret_conv;
15777 }
15778
15779 uint32_t TS_NetworkGraph_update_channel_unsigned(uint32_t this_arg, uint32_t msg) {
15780         LDKNetworkGraph this_arg_conv;
15781         this_arg_conv.inner = (void*)(this_arg & (~1));
15782         this_arg_conv.is_owned = false;
15783         LDKUnsignedChannelUpdate msg_conv;
15784         msg_conv.inner = (void*)(msg & (~1));
15785         msg_conv.is_owned = false;
15786         LDKCResult_NoneLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneLightningErrorZ), "LDKCResult_NoneLightningErrorZ");
15787         *ret_conv = NetworkGraph_update_channel_unsigned(&this_arg_conv, &msg_conv);
15788         return (long)ret_conv;
15789 }
15790