a383cb9d6749a4218c060c3333fd0019e32d0eb8
[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 static inline void assert(bool expression) {
13         if (!expression) { abort(); }
14 }
15
16 // Always run a, then assert it is true:
17 #define DO_ASSERT(a) do { bool _assert_val = (a); assert(_assert_val); } while(0)
18 // Assert a is true or do nothing
19 #define CHECK(a) DO_ASSERT(a)
20
21 // Running a leak check across all the allocations and frees of the JDK is a mess,
22 // so instead we implement our own naive leak checker here, relying on the -wrap
23 // linker option to wrap malloc/calloc/realloc/free, tracking everyhing allocated
24 // and free'd in Rust or C across the generated bindings shared library.
25
26 #define BT_MAX 128
27 typedef struct allocation {
28         struct allocation* next;
29         void* ptr;
30         const char* struct_name;
31 } allocation;
32 static allocation* allocation_ll = NULL;
33
34 void* __real_malloc(size_t len);
35 void* __real_calloc(size_t nmemb, size_t len);
36 static void new_allocation(void* res, const char* struct_name) {
37         allocation* new_alloc = __real_malloc(sizeof(allocation));
38         new_alloc->ptr = res;
39         new_alloc->struct_name = struct_name;
40         new_alloc->next = allocation_ll;
41         allocation_ll = new_alloc;
42 }
43 static void* MALLOC(size_t len, const char* struct_name) {
44         void* res = __real_malloc(len);
45         new_allocation(res, struct_name);
46         return res;
47 }
48 void __real_free(void* ptr);
49 static void alloc_freed(void* ptr) {
50         allocation* p = NULL;
51         allocation* it = allocation_ll;
52         while (it->ptr != ptr) {
53                 p = it; it = it->next;
54                 if (it == NULL) {
55                         //XXX: fprintf(stderr, "Tried to free unknown pointer %p\n", ptr);
56                         return; // addrsan should catch malloc-unknown and print more info than we have
57                 }
58         }
59         if (p) { p->next = it->next; } else { allocation_ll = it->next; }
60         DO_ASSERT(it->ptr == ptr);
61         __real_free(it);
62 }
63 static void FREE(void* ptr) {
64         if ((long)ptr < 1024) return; // Rust loves to create pointers to the NULL page for dummys
65         alloc_freed(ptr);
66         __real_free(ptr);
67 }
68
69 void* __wrap_malloc(size_t len) {
70         void* res = __real_malloc(len);
71         new_allocation(res, "malloc call");
72         return res;
73 }
74 void* __wrap_calloc(size_t nmemb, size_t len) {
75         void* res = __real_calloc(nmemb, len);
76         new_allocation(res, "calloc call");
77         return res;
78 }
79 void __wrap_free(void* ptr) {
80         if (ptr == NULL) return;
81         alloc_freed(ptr);
82         __real_free(ptr);
83 }
84
85 void* __real_realloc(void* ptr, size_t newlen);
86 void* __wrap_realloc(void* ptr, size_t len) {
87         if (ptr != NULL) alloc_freed(ptr);
88         void* res = __real_realloc(ptr, len);
89         new_allocation(res, "realloc call");
90         return res;
91 }
92 void __wrap_reallocarray(void* ptr, size_t new_sz) {
93         // Rust doesn't seem to use reallocarray currently
94         DO_ASSERT(false);
95 }
96
97 void __attribute__((destructor)) check_leaks() {
98         for (allocation* a = allocation_ll; a != NULL; a = a->next) {
99                 //XXX: fprintf(stderr, "%s %p remains\n", a->struct_name, a->ptr);
100         }
101         DO_ASSERT(allocation_ll == NULL);
102 }
103
104 // We assume that CVec_u8Z and u8slice are the same size and layout (and thus pointers to the two can be mixed)
105 _Static_assert(sizeof(LDKCVec_u8Z) == sizeof(LDKu8slice), "Vec<u8> and [u8] need to have been mapped identically");
106 _Static_assert(offsetof(LDKCVec_u8Z, data) == offsetof(LDKu8slice, data), "Vec<u8> and [u8] need to have been mapped identically");
107 _Static_assert(offsetof(LDKCVec_u8Z, datalen) == offsetof(LDKu8slice, datalen), "Vec<u8> and [u8] need to have been mapped identically");
108
109 _Static_assert(sizeof(void*) == 4, "Pointers mut be 32 bits");
110
111 typedef uint32_t int64_tArray;
112 typedef uint32_t int8_tArray;
113 typedef uint32_t uint32_tArray;
114 typedef uint32_t ptrArray;
115 typedef uint32_t jstring;
116
117 static inline uint32_t init_arr(size_t arr_len, size_t elem_size, const char *type_desc) {
118         uint32_t *elems = (uint32_t*)MALLOC(arr_len * elem_size + 4, type_desc);
119         elems[0] = arr_len;
120         return (uint32_t)elems;
121 }
122
123 jstring str_ref_to_ts(const char* chars, size_t len) {
124         char* err_buf = MALLOC(len + 4, "str conv buf");
125         *((uint32_t*)err_buf) = len;
126         memcpy(err_buf + 4, chars, len);
127         return (uint32_t) err_buf;
128 }
129
130 typedef bool jboolean;
131
132 uint32_t __attribute__((visibility("default"))) TS_malloc(uint32_t size) {
133         return (uint32_t)MALLOC(size, "JS-Called malloc");
134 }
135 void __attribute__((visibility("default"))) TS_free(uint32_t ptr) {
136         FREE((void*)ptr);
137 }
138 static inline struct LDKThirtyTwoBytes ThirtyTwoBytes_clone(const struct LDKThirtyTwoBytes *orig) { struct LDKThirtyTwoBytes ret; memcpy(ret.data, orig->data, 32); return ret; }
139 static inline LDKAccessError LDKAccessError_from_js(int32_t ord) {
140         switch (ord) {
141                 case 0: return LDKAccessError_UnknownChain;
142                 case 1: return LDKAccessError_UnknownTx;
143         }
144         abort();
145 }
146 static inline int32_t LDKAccessError_to_js(LDKAccessError val) {
147         switch (val) {
148                 case LDKAccessError_UnknownChain: return 0;
149                 case LDKAccessError_UnknownTx: return 1;
150                 default: abort();
151         }
152 }
153 static inline LDKChannelMonitorUpdateErr LDKChannelMonitorUpdateErr_from_js(int32_t ord) {
154         switch (ord) {
155                 case 0: return LDKChannelMonitorUpdateErr_TemporaryFailure;
156                 case 1: return LDKChannelMonitorUpdateErr_PermanentFailure;
157         }
158         abort();
159 }
160 static inline int32_t LDKChannelMonitorUpdateErr_to_js(LDKChannelMonitorUpdateErr val) {
161         switch (val) {
162                 case LDKChannelMonitorUpdateErr_TemporaryFailure: return 0;
163                 case LDKChannelMonitorUpdateErr_PermanentFailure: return 1;
164                 default: abort();
165         }
166 }
167 static inline LDKConfirmationTarget LDKConfirmationTarget_from_js(int32_t ord) {
168         switch (ord) {
169                 case 0: return LDKConfirmationTarget_Background;
170                 case 1: return LDKConfirmationTarget_Normal;
171                 case 2: return LDKConfirmationTarget_HighPriority;
172         }
173         abort();
174 }
175 static inline int32_t LDKConfirmationTarget_to_js(LDKConfirmationTarget val) {
176         switch (val) {
177                 case LDKConfirmationTarget_Background: return 0;
178                 case LDKConfirmationTarget_Normal: return 1;
179                 case LDKConfirmationTarget_HighPriority: return 2;
180                 default: abort();
181         }
182 }
183 static inline LDKLevel LDKLevel_from_js(int32_t ord) {
184         switch (ord) {
185                 case 0: return LDKLevel_Off;
186                 case 1: return LDKLevel_Error;
187                 case 2: return LDKLevel_Warn;
188                 case 3: return LDKLevel_Info;
189                 case 4: return LDKLevel_Debug;
190                 case 5: return LDKLevel_Trace;
191         }
192         abort();
193 }
194 static inline int32_t LDKLevel_to_js(LDKLevel val) {
195         switch (val) {
196                 case LDKLevel_Off: return 0;
197                 case LDKLevel_Error: return 1;
198                 case LDKLevel_Warn: return 2;
199                 case LDKLevel_Info: return 3;
200                 case LDKLevel_Debug: return 4;
201                 case LDKLevel_Trace: return 5;
202                 default: abort();
203         }
204 }
205 static inline LDKNetwork LDKNetwork_from_js(int32_t ord) {
206         switch (ord) {
207                 case 0: return LDKNetwork_Bitcoin;
208                 case 1: return LDKNetwork_Testnet;
209                 case 2: return LDKNetwork_Regtest;
210         }
211         abort();
212 }
213 static inline int32_t LDKNetwork_to_js(LDKNetwork val) {
214         switch (val) {
215                 case LDKNetwork_Bitcoin: return 0;
216                 case LDKNetwork_Testnet: return 1;
217                 case LDKNetwork_Regtest: return 2;
218                 default: abort();
219         }
220 }
221 static inline LDKSecp256k1Error LDKSecp256k1Error_from_js(int32_t ord) {
222         switch (ord) {
223                 case 0: return LDKSecp256k1Error_IncorrectSignature;
224                 case 1: return LDKSecp256k1Error_InvalidMessage;
225                 case 2: return LDKSecp256k1Error_InvalidPublicKey;
226                 case 3: return LDKSecp256k1Error_InvalidSignature;
227                 case 4: return LDKSecp256k1Error_InvalidSecretKey;
228                 case 5: return LDKSecp256k1Error_InvalidRecoveryId;
229                 case 6: return LDKSecp256k1Error_InvalidTweak;
230                 case 7: return LDKSecp256k1Error_TweakCheckFailed;
231                 case 8: return LDKSecp256k1Error_NotEnoughMemory;
232         }
233         abort();
234 }
235 static inline int32_t LDKSecp256k1Error_to_js(LDKSecp256k1Error val) {
236         switch (val) {
237                 case LDKSecp256k1Error_IncorrectSignature: return 0;
238                 case LDKSecp256k1Error_InvalidMessage: return 1;
239                 case LDKSecp256k1Error_InvalidPublicKey: return 2;
240                 case LDKSecp256k1Error_InvalidSignature: return 3;
241                 case LDKSecp256k1Error_InvalidSecretKey: return 4;
242                 case LDKSecp256k1Error_InvalidRecoveryId: return 5;
243                 case LDKSecp256k1Error_InvalidTweak: return 6;
244                 case LDKSecp256k1Error_TweakCheckFailed: return 7;
245                 case LDKSecp256k1Error_NotEnoughMemory: return 8;
246                 default: abort();
247         }
248 }
249 uint32_t  __attribute__((visibility("default"))) TS_LDKCVec_u8Z_new(int8_tArray elems) {
250         LDKCVec_u8Z *ret = MALLOC(sizeof(LDKCVec_u8Z), "LDKCVec_u8Z");
251         ret->datalen = *((uint32_t*)elems);
252         if (ret->datalen == 0) {
253                 ret->data = NULL;
254         } else {
255                 ret->data = MALLOC(sizeof(uint8_t) * ret->datalen, "LDKCVec_u8Z Data");
256                 int8_t *java_elems = (int8_t*)(elems + 4);
257                 for (size_t i = 0; i < ret->datalen; i++) {
258                         ret->data[i] = java_elems[i];
259                 }
260         }
261         return (long)ret;
262 }
263 static inline LDKCVec_u8Z CVec_u8Z_clone(const LDKCVec_u8Z *orig) {
264         LDKCVec_u8Z ret = { .data = MALLOC(sizeof(int8_t) * orig->datalen, "LDKCVec_u8Z clone bytes"), .datalen = orig->datalen };
265         memcpy(ret.data, orig->data, sizeof(int8_t) * ret.datalen);
266         return ret;
267 }
268 uint32_t  __attribute__((visibility("default"))) TS_LDKC2Tuple_u64u64Z_new(int64_t a, int64_t b) {
269         LDKC2Tuple_u64u64Z* ret = MALLOC(sizeof(LDKC2Tuple_u64u64Z), "LDKC2Tuple_u64u64Z");
270         ret->a = a;
271         ret->b = b;
272         return (long)ret;
273 }
274 int64_t  __attribute__((visibility("default"))) TS_LDKC2Tuple_u64u64Z_get_a(uint32_t ptr) {
275         LDKC2Tuple_u64u64Z *tuple = (LDKC2Tuple_u64u64Z*)(ptr & ~1);
276         return tuple->a;
277 }
278 int64_t  __attribute__((visibility("default"))) TS_LDKC2Tuple_u64u64Z_get_b(uint32_t ptr) {
279         LDKC2Tuple_u64u64Z *tuple = (LDKC2Tuple_u64u64Z*)(ptr & ~1);
280         return tuple->b;
281 }
282 uint32_t __attribute__((visibility("default"))) TS_LDKSpendableOutputDescriptor_ref_from_ptr(uint32_t ptr) {
283         LDKSpendableOutputDescriptor *obj = (LDKSpendableOutputDescriptor*)ptr;
284         switch(obj->tag) {
285                 case LDKSpendableOutputDescriptor_StaticOutput: {
286                         LDKOutPoint outpoint_var = obj->static_output.outpoint;
287                         CHECK((((long)outpoint_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
288                         CHECK((((long)&outpoint_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
289                         long outpoint_ref = (long)outpoint_var.inner & ~1;
290                         long output_ref = ((long)&obj->static_output.output) | 1;
291                         return 0 /* LDKSpendableOutputDescriptor - StaticOutput */; (void) outpoint_ref; (void) (long)output_ref;
292                 }
293                 case LDKSpendableOutputDescriptor_DynamicOutputP2WSH: {
294                         LDKOutPoint outpoint_var = obj->dynamic_output_p2wsh.outpoint;
295                         CHECK((((long)outpoint_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
296                         CHECK((((long)&outpoint_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
297                         long outpoint_ref = (long)outpoint_var.inner & ~1;
298                         int8_tArray per_commitment_point_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
299                         memcpy((uint8_t*)(per_commitment_point_arr + 4), obj->dynamic_output_p2wsh.per_commitment_point.compressed_form, 33);
300                         long output_ref = ((long)&obj->dynamic_output_p2wsh.output) | 1;
301                         long key_derivation_params_ref = (long)(&obj->dynamic_output_p2wsh.key_derivation_params) | 1;
302                         int8_tArray revocation_pubkey_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
303                         memcpy((uint8_t*)(revocation_pubkey_arr + 4), obj->dynamic_output_p2wsh.revocation_pubkey.compressed_form, 33);
304                         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;
305                 }
306                 case LDKSpendableOutputDescriptor_StaticOutputCounterpartyPayment: {
307                         LDKOutPoint outpoint_var = obj->static_output_counterparty_payment.outpoint;
308                         CHECK((((long)outpoint_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
309                         CHECK((((long)&outpoint_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
310                         long outpoint_ref = (long)outpoint_var.inner & ~1;
311                         long output_ref = ((long)&obj->static_output_counterparty_payment.output) | 1;
312                         long key_derivation_params_ref = (long)(&obj->static_output_counterparty_payment.key_derivation_params) | 1;
313                         return 0 /* LDKSpendableOutputDescriptor - StaticOutputCounterpartyPayment */; (void) outpoint_ref; (void) (long)output_ref; (void) key_derivation_params_ref;
314                 }
315                 default: abort();
316         }
317 }
318 uint32_t  __attribute__((visibility("default"))) TS_LDKCVec_SpendableOutputDescriptorZ_new(uint32_tArray elems) {
319         LDKCVec_SpendableOutputDescriptorZ *ret = MALLOC(sizeof(LDKCVec_SpendableOutputDescriptorZ), "LDKCVec_SpendableOutputDescriptorZ");
320         ret->datalen = *((uint32_t*)elems);
321         if (ret->datalen == 0) {
322                 ret->data = NULL;
323         } else {
324                 ret->data = MALLOC(sizeof(LDKSpendableOutputDescriptor) * ret->datalen, "LDKCVec_SpendableOutputDescriptorZ Data");
325                 uint32_t *java_elems = (uint32_t*)(elems + 4);
326                 for (size_t i = 0; i < ret->datalen; i++) {
327                         uint32_t arr_elem = java_elems[i];
328                         LDKSpendableOutputDescriptor arr_elem_conv = *(LDKSpendableOutputDescriptor*)(((uint64_t)arr_elem) & ~1);
329                         FREE((void*)arr_elem);
330                         ret->data[i] = arr_elem_conv;
331                 }
332         }
333         return (long)ret;
334 }
335 static inline LDKCVec_SpendableOutputDescriptorZ CVec_SpendableOutputDescriptorZ_clone(const LDKCVec_SpendableOutputDescriptorZ *orig) {
336         LDKCVec_SpendableOutputDescriptorZ ret = { .data = MALLOC(sizeof(LDKSpendableOutputDescriptor) * orig->datalen, "LDKCVec_SpendableOutputDescriptorZ clone bytes"), .datalen = orig->datalen };
337         for (size_t i = 0; i < ret.datalen; i++) {
338                 ret.data[i] = SpendableOutputDescriptor_clone(&orig->data[i]);
339         }
340         return ret;
341 }
342 uint32_t __attribute__((visibility("default"))) TS_LDKErrorAction_ref_from_ptr(uint32_t ptr) {
343         LDKErrorAction *obj = (LDKErrorAction*)ptr;
344         switch(obj->tag) {
345                 case LDKErrorAction_DisconnectPeer: {
346                         LDKErrorMessage msg_var = obj->disconnect_peer.msg;
347                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
348                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
349                         long msg_ref = (long)msg_var.inner & ~1;
350                         return 0 /* LDKErrorAction - DisconnectPeer */; (void) msg_ref;
351                 }
352                 case LDKErrorAction_IgnoreError: {
353                         return 0 /* LDKErrorAction - IgnoreError */;
354                 }
355                 case LDKErrorAction_SendErrorMessage: {
356                         LDKErrorMessage msg_var = obj->send_error_message.msg;
357                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
358                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
359                         long msg_ref = (long)msg_var.inner & ~1;
360                         return 0 /* LDKErrorAction - SendErrorMessage */; (void) msg_ref;
361                 }
362                 default: abort();
363         }
364 }
365 uint32_t __attribute__((visibility("default"))) TS_LDKHTLCFailChannelUpdate_ref_from_ptr(uint32_t ptr) {
366         LDKHTLCFailChannelUpdate *obj = (LDKHTLCFailChannelUpdate*)ptr;
367         switch(obj->tag) {
368                 case LDKHTLCFailChannelUpdate_ChannelUpdateMessage: {
369                         LDKChannelUpdate msg_var = obj->channel_update_message.msg;
370                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
371                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
372                         long msg_ref = (long)msg_var.inner & ~1;
373                         return 0 /* LDKHTLCFailChannelUpdate - ChannelUpdateMessage */; (void) msg_ref;
374                 }
375                 case LDKHTLCFailChannelUpdate_ChannelClosed: {
376                         return 0 /* LDKHTLCFailChannelUpdate - ChannelClosed */; (void) obj->channel_closed.short_channel_id; (void) obj->channel_closed.is_permanent;
377                 }
378                 case LDKHTLCFailChannelUpdate_NodeFailure: {
379                         int8_tArray node_id_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
380                         memcpy((uint8_t*)(node_id_arr + 4), obj->node_failure.node_id.compressed_form, 33);
381                         return 0 /* LDKHTLCFailChannelUpdate - NodeFailure */; (void) node_id_arr; (void) obj->node_failure.is_permanent;
382                 }
383                 default: abort();
384         }
385 }
386 uint32_t __attribute__((visibility("default"))) TS_LDKMessageSendEvent_ref_from_ptr(uint32_t ptr) {
387         LDKMessageSendEvent *obj = (LDKMessageSendEvent*)ptr;
388         switch(obj->tag) {
389                 case LDKMessageSendEvent_SendAcceptChannel: {
390                         int8_tArray node_id_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
391                         memcpy((uint8_t*)(node_id_arr + 4), obj->send_accept_channel.node_id.compressed_form, 33);
392                         LDKAcceptChannel msg_var = obj->send_accept_channel.msg;
393                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
394                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
395                         long msg_ref = (long)msg_var.inner & ~1;
396                         return 0 /* LDKMessageSendEvent - SendAcceptChannel */; (void) node_id_arr; (void) msg_ref;
397                 }
398                 case LDKMessageSendEvent_SendOpenChannel: {
399                         int8_tArray node_id_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
400                         memcpy((uint8_t*)(node_id_arr + 4), obj->send_open_channel.node_id.compressed_form, 33);
401                         LDKOpenChannel msg_var = obj->send_open_channel.msg;
402                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
403                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
404                         long msg_ref = (long)msg_var.inner & ~1;
405                         return 0 /* LDKMessageSendEvent - SendOpenChannel */; (void) node_id_arr; (void) msg_ref;
406                 }
407                 case LDKMessageSendEvent_SendFundingCreated: {
408                         int8_tArray node_id_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
409                         memcpy((uint8_t*)(node_id_arr + 4), obj->send_funding_created.node_id.compressed_form, 33);
410                         LDKFundingCreated msg_var = obj->send_funding_created.msg;
411                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
412                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
413                         long msg_ref = (long)msg_var.inner & ~1;
414                         return 0 /* LDKMessageSendEvent - SendFundingCreated */; (void) node_id_arr; (void) msg_ref;
415                 }
416                 case LDKMessageSendEvent_SendFundingSigned: {
417                         int8_tArray node_id_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
418                         memcpy((uint8_t*)(node_id_arr + 4), obj->send_funding_signed.node_id.compressed_form, 33);
419                         LDKFundingSigned msg_var = obj->send_funding_signed.msg;
420                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
421                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
422                         long msg_ref = (long)msg_var.inner & ~1;
423                         return 0 /* LDKMessageSendEvent - SendFundingSigned */; (void) node_id_arr; (void) msg_ref;
424                 }
425                 case LDKMessageSendEvent_SendFundingLocked: {
426                         int8_tArray node_id_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
427                         memcpy((uint8_t*)(node_id_arr + 4), obj->send_funding_locked.node_id.compressed_form, 33);
428                         LDKFundingLocked msg_var = obj->send_funding_locked.msg;
429                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
430                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
431                         long msg_ref = (long)msg_var.inner & ~1;
432                         return 0 /* LDKMessageSendEvent - SendFundingLocked */; (void) node_id_arr; (void) msg_ref;
433                 }
434                 case LDKMessageSendEvent_SendAnnouncementSignatures: {
435                         int8_tArray node_id_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
436                         memcpy((uint8_t*)(node_id_arr + 4), obj->send_announcement_signatures.node_id.compressed_form, 33);
437                         LDKAnnouncementSignatures msg_var = obj->send_announcement_signatures.msg;
438                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
439                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
440                         long msg_ref = (long)msg_var.inner & ~1;
441                         return 0 /* LDKMessageSendEvent - SendAnnouncementSignatures */; (void) node_id_arr; (void) msg_ref;
442                 }
443                 case LDKMessageSendEvent_UpdateHTLCs: {
444                         int8_tArray node_id_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
445                         memcpy((uint8_t*)(node_id_arr + 4), obj->update_htl_cs.node_id.compressed_form, 33);
446                         LDKCommitmentUpdate updates_var = obj->update_htl_cs.updates;
447                         CHECK((((long)updates_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
448                         CHECK((((long)&updates_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
449                         long updates_ref = (long)updates_var.inner & ~1;
450                         return 0 /* LDKMessageSendEvent - UpdateHTLCs */; (void) node_id_arr; (void) updates_ref;
451                 }
452                 case LDKMessageSendEvent_SendRevokeAndACK: {
453                         int8_tArray node_id_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
454                         memcpy((uint8_t*)(node_id_arr + 4), obj->send_revoke_and_ack.node_id.compressed_form, 33);
455                         LDKRevokeAndACK msg_var = obj->send_revoke_and_ack.msg;
456                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
457                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
458                         long msg_ref = (long)msg_var.inner & ~1;
459                         return 0 /* LDKMessageSendEvent - SendRevokeAndACK */; (void) node_id_arr; (void) msg_ref;
460                 }
461                 case LDKMessageSendEvent_SendClosingSigned: {
462                         int8_tArray node_id_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
463                         memcpy((uint8_t*)(node_id_arr + 4), obj->send_closing_signed.node_id.compressed_form, 33);
464                         LDKClosingSigned msg_var = obj->send_closing_signed.msg;
465                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
466                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
467                         long msg_ref = (long)msg_var.inner & ~1;
468                         return 0 /* LDKMessageSendEvent - SendClosingSigned */; (void) node_id_arr; (void) msg_ref;
469                 }
470                 case LDKMessageSendEvent_SendShutdown: {
471                         int8_tArray node_id_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
472                         memcpy((uint8_t*)(node_id_arr + 4), obj->send_shutdown.node_id.compressed_form, 33);
473                         LDKShutdown msg_var = obj->send_shutdown.msg;
474                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
475                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
476                         long msg_ref = (long)msg_var.inner & ~1;
477                         return 0 /* LDKMessageSendEvent - SendShutdown */; (void) node_id_arr; (void) msg_ref;
478                 }
479                 case LDKMessageSendEvent_SendChannelReestablish: {
480                         int8_tArray node_id_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
481                         memcpy((uint8_t*)(node_id_arr + 4), obj->send_channel_reestablish.node_id.compressed_form, 33);
482                         LDKChannelReestablish msg_var = obj->send_channel_reestablish.msg;
483                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
484                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
485                         long msg_ref = (long)msg_var.inner & ~1;
486                         return 0 /* LDKMessageSendEvent - SendChannelReestablish */; (void) node_id_arr; (void) msg_ref;
487                 }
488                 case LDKMessageSendEvent_BroadcastChannelAnnouncement: {
489                         LDKChannelAnnouncement msg_var = obj->broadcast_channel_announcement.msg;
490                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
491                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
492                         long msg_ref = (long)msg_var.inner & ~1;
493                         LDKChannelUpdate update_msg_var = obj->broadcast_channel_announcement.update_msg;
494                         CHECK((((long)update_msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
495                         CHECK((((long)&update_msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
496                         long update_msg_ref = (long)update_msg_var.inner & ~1;
497                         return 0 /* LDKMessageSendEvent - BroadcastChannelAnnouncement */; (void) msg_ref; (void) update_msg_ref;
498                 }
499                 case LDKMessageSendEvent_BroadcastNodeAnnouncement: {
500                         LDKNodeAnnouncement msg_var = obj->broadcast_node_announcement.msg;
501                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
502                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
503                         long msg_ref = (long)msg_var.inner & ~1;
504                         return 0 /* LDKMessageSendEvent - BroadcastNodeAnnouncement */; (void) msg_ref;
505                 }
506                 case LDKMessageSendEvent_BroadcastChannelUpdate: {
507                         LDKChannelUpdate msg_var = obj->broadcast_channel_update.msg;
508                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
509                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
510                         long msg_ref = (long)msg_var.inner & ~1;
511                         return 0 /* LDKMessageSendEvent - BroadcastChannelUpdate */; (void) msg_ref;
512                 }
513                 case LDKMessageSendEvent_HandleError: {
514                         int8_tArray node_id_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
515                         memcpy((uint8_t*)(node_id_arr + 4), obj->handle_error.node_id.compressed_form, 33);
516                         long action_ref = ((long)&obj->handle_error.action) | 1;
517                         return 0 /* LDKMessageSendEvent - HandleError */; (void) node_id_arr; (void) action_ref;
518                 }
519                 case LDKMessageSendEvent_PaymentFailureNetworkUpdate: {
520                         long update_ref = ((long)&obj->payment_failure_network_update.update) | 1;
521                         return 0 /* LDKMessageSendEvent - PaymentFailureNetworkUpdate */; (void) update_ref;
522                 }
523                 case LDKMessageSendEvent_SendChannelRangeQuery: {
524                         int8_tArray node_id_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
525                         memcpy((uint8_t*)(node_id_arr + 4), obj->send_channel_range_query.node_id.compressed_form, 33);
526                         LDKQueryChannelRange msg_var = obj->send_channel_range_query.msg;
527                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
528                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
529                         long msg_ref = (long)msg_var.inner & ~1;
530                         return 0 /* LDKMessageSendEvent - SendChannelRangeQuery */; (void) node_id_arr; (void) msg_ref;
531                 }
532                 case LDKMessageSendEvent_SendShortIdsQuery: {
533                         int8_tArray node_id_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
534                         memcpy((uint8_t*)(node_id_arr + 4), obj->send_short_ids_query.node_id.compressed_form, 33);
535                         LDKQueryShortChannelIds msg_var = obj->send_short_ids_query.msg;
536                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
537                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
538                         long msg_ref = (long)msg_var.inner & ~1;
539                         return 0 /* LDKMessageSendEvent - SendShortIdsQuery */; (void) node_id_arr; (void) msg_ref;
540                 }
541                 default: abort();
542         }
543 }
544 uint32_t  __attribute__((visibility("default"))) TS_LDKCVec_MessageSendEventZ_new(uint32_tArray elems) {
545         LDKCVec_MessageSendEventZ *ret = MALLOC(sizeof(LDKCVec_MessageSendEventZ), "LDKCVec_MessageSendEventZ");
546         ret->datalen = *((uint32_t*)elems);
547         if (ret->datalen == 0) {
548                 ret->data = NULL;
549         } else {
550                 ret->data = MALLOC(sizeof(LDKMessageSendEvent) * ret->datalen, "LDKCVec_MessageSendEventZ Data");
551                 uint32_t *java_elems = (uint32_t*)(elems + 4);
552                 for (size_t i = 0; i < ret->datalen; i++) {
553                         uint32_t arr_elem = java_elems[i];
554                         LDKMessageSendEvent arr_elem_conv = *(LDKMessageSendEvent*)(((uint64_t)arr_elem) & ~1);
555                         FREE((void*)arr_elem);
556                         ret->data[i] = arr_elem_conv;
557                 }
558         }
559         return (long)ret;
560 }
561 static inline LDKCVec_MessageSendEventZ CVec_MessageSendEventZ_clone(const LDKCVec_MessageSendEventZ *orig) {
562         LDKCVec_MessageSendEventZ ret = { .data = MALLOC(sizeof(LDKMessageSendEvent) * orig->datalen, "LDKCVec_MessageSendEventZ clone bytes"), .datalen = orig->datalen };
563         for (size_t i = 0; i < ret.datalen; i++) {
564                 ret.data[i] = MessageSendEvent_clone(&orig->data[i]);
565         }
566         return ret;
567 }
568 uint32_t __attribute__((visibility("default"))) TS_LDKEvent_ref_from_ptr(uint32_t ptr) {
569         LDKEvent *obj = (LDKEvent*)ptr;
570         switch(obj->tag) {
571                 case LDKEvent_FundingGenerationReady: {
572                         int8_tArray temporary_channel_id_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
573                         memcpy((uint8_t*)(temporary_channel_id_arr + 4), obj->funding_generation_ready.temporary_channel_id.data, 32);
574                         LDKCVec_u8Z output_script_var = obj->funding_generation_ready.output_script;
575                         int8_tArray output_script_arr = init_arr(output_script_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
576                         memcpy((uint8_t*)(output_script_arr + 4), output_script_var.data, output_script_var.datalen);
577                         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;
578                 }
579                 case LDKEvent_FundingBroadcastSafe: {
580                         LDKOutPoint funding_txo_var = obj->funding_broadcast_safe.funding_txo;
581                         CHECK((((long)funding_txo_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
582                         CHECK((((long)&funding_txo_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
583                         long funding_txo_ref = (long)funding_txo_var.inner & ~1;
584                         return 0 /* LDKEvent - FundingBroadcastSafe */; (void) funding_txo_ref; (void) obj->funding_broadcast_safe.user_channel_id;
585                 }
586                 case LDKEvent_PaymentReceived: {
587                         int8_tArray payment_hash_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
588                         memcpy((uint8_t*)(payment_hash_arr + 4), obj->payment_received.payment_hash.data, 32);
589                         int8_tArray payment_secret_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
590                         memcpy((uint8_t*)(payment_secret_arr + 4), obj->payment_received.payment_secret.data, 32);
591                         return 0 /* LDKEvent - PaymentReceived */; (void) payment_hash_arr; (void) payment_secret_arr; (void) obj->payment_received.amt;
592                 }
593                 case LDKEvent_PaymentSent: {
594                         int8_tArray payment_preimage_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
595                         memcpy((uint8_t*)(payment_preimage_arr + 4), obj->payment_sent.payment_preimage.data, 32);
596                         return 0 /* LDKEvent - PaymentSent */; (void) payment_preimage_arr;
597                 }
598                 case LDKEvent_PaymentFailed: {
599                         int8_tArray payment_hash_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
600                         memcpy((uint8_t*)(payment_hash_arr + 4), obj->payment_failed.payment_hash.data, 32);
601                         return 0 /* LDKEvent - PaymentFailed */; (void) payment_hash_arr; (void) obj->payment_failed.rejected_by_dest;
602                 }
603                 case LDKEvent_PendingHTLCsForwardable: {
604                         return 0 /* LDKEvent - PendingHTLCsForwardable */; (void) obj->pending_htl_cs_forwardable.time_forwardable;
605                 }
606                 case LDKEvent_SpendableOutputs: {
607                         LDKCVec_SpendableOutputDescriptorZ outputs_var = obj->spendable_outputs.outputs;
608                         uint32_tArray outputs_arr = init_arr(outputs_var.datalen, sizeof(uint32_t), "Native uint32_tArray Bytes");
609                         uint32_t *outputs_arr_ptr = (uint32_t*)(outputs_arr + 4);
610                         for (size_t b = 0; b < outputs_var.datalen; b++) {
611                                 long arr_conv_27_ref = ((long)&outputs_var.data[b]) | 1;
612                                 outputs_arr_ptr[b] = arr_conv_27_ref;
613                         }
614                         return 0 /* LDKEvent - SpendableOutputs */; (void) outputs_arr;
615                 }
616                 default: abort();
617         }
618 }
619 uint32_t  __attribute__((visibility("default"))) TS_LDKCVec_EventZ_new(uint32_tArray elems) {
620         LDKCVec_EventZ *ret = MALLOC(sizeof(LDKCVec_EventZ), "LDKCVec_EventZ");
621         ret->datalen = *((uint32_t*)elems);
622         if (ret->datalen == 0) {
623                 ret->data = NULL;
624         } else {
625                 ret->data = MALLOC(sizeof(LDKEvent) * ret->datalen, "LDKCVec_EventZ Data");
626                 uint32_t *java_elems = (uint32_t*)(elems + 4);
627                 for (size_t i = 0; i < ret->datalen; i++) {
628                         uint32_t arr_elem = java_elems[i];
629                         LDKEvent arr_elem_conv = *(LDKEvent*)(((uint64_t)arr_elem) & ~1);
630                         FREE((void*)arr_elem);
631                         ret->data[i] = arr_elem_conv;
632                 }
633         }
634         return (long)ret;
635 }
636 static inline LDKCVec_EventZ CVec_EventZ_clone(const LDKCVec_EventZ *orig) {
637         LDKCVec_EventZ ret = { .data = MALLOC(sizeof(LDKEvent) * orig->datalen, "LDKCVec_EventZ clone bytes"), .datalen = orig->datalen };
638         for (size_t i = 0; i < ret.datalen; i++) {
639                 ret.data[i] = Event_clone(&orig->data[i]);
640         }
641         return ret;
642 }
643 uint32_t  __attribute__((visibility("default"))) TS_LDKC2Tuple_usizeTransactionZ_new(intptr_t a, int8_tArray b) {
644         LDKC2Tuple_usizeTransactionZ* ret = MALLOC(sizeof(LDKC2Tuple_usizeTransactionZ), "LDKC2Tuple_usizeTransactionZ");
645         ret->a = a;
646         LDKTransaction b_ref;
647         b_ref.datalen = *((uint32_t*)b);
648         b_ref.data = MALLOC(b_ref.datalen, "LDKTransaction Bytes");
649         memcpy(b_ref.data, (uint8_t*)(b + 4), b_ref.datalen);
650         b_ref.data_is_owned = false;
651         ret->b = b_ref;
652         return (long)ret;
653 }
654 intptr_t  __attribute__((visibility("default"))) TS_LDKC2Tuple_usizeTransactionZ_get_a(uint32_t ptr) {
655         LDKC2Tuple_usizeTransactionZ *tuple = (LDKC2Tuple_usizeTransactionZ*)(ptr & ~1);
656         return tuple->a;
657 }
658 int8_tArray  __attribute__((visibility("default"))) TS_LDKC2Tuple_usizeTransactionZ_get_b(uint32_t ptr) {
659         LDKC2Tuple_usizeTransactionZ *tuple = (LDKC2Tuple_usizeTransactionZ*)(ptr & ~1);
660         LDKTransaction b_var = tuple->b;
661         int8_tArray b_arr = init_arr(b_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
662         memcpy((uint8_t*)(b_arr + 4), b_var.data, b_var.datalen);
663         return b_arr;
664 }
665 uint32_t  __attribute__((visibility("default"))) TS_LDKCVec_C2Tuple_usizeTransactionZZ_new(uint32_tArray elems) {
666         LDKCVec_C2Tuple_usizeTransactionZZ *ret = MALLOC(sizeof(LDKCVec_C2Tuple_usizeTransactionZZ), "LDKCVec_C2Tuple_usizeTransactionZZ");
667         ret->datalen = *((uint32_t*)elems);
668         if (ret->datalen == 0) {
669                 ret->data = NULL;
670         } else {
671                 ret->data = MALLOC(sizeof(LDKC2Tuple_usizeTransactionZ) * ret->datalen, "LDKCVec_C2Tuple_usizeTransactionZZ Data");
672                 uint32_t *java_elems = (uint32_t*)(elems + 4);
673                 for (size_t i = 0; i < ret->datalen; i++) {
674                         uint32_t arr_elem = java_elems[i];
675                         LDKC2Tuple_usizeTransactionZ arr_elem_conv = *(LDKC2Tuple_usizeTransactionZ*)(((uint64_t)arr_elem) & ~1);
676                         FREE((void*)arr_elem);
677                         ret->data[i] = arr_elem_conv;
678                 }
679         }
680         return (long)ret;
681 }
682 jboolean  __attribute__((visibility("default"))) TS_LDKCResult_NoneChannelMonitorUpdateErrZ_result_ok(uint32_t arg) {
683         return ((LDKCResult_NoneChannelMonitorUpdateErrZ*)arg)->result_ok;
684 }
685 void  __attribute__((visibility("default"))) TS_LDKCResult_NoneChannelMonitorUpdateErrZ_get_ok(uint32_t arg) {
686         LDKCResult_NoneChannelMonitorUpdateErrZ *val = (LDKCResult_NoneChannelMonitorUpdateErrZ*)(arg & ~1);
687         CHECK(val->result_ok);
688         return *val->contents.result;
689 }
690 uint32_t  __attribute__((visibility("default"))) TS_LDKCResult_NoneChannelMonitorUpdateErrZ_get_err(uint32_t arg) {
691         LDKCResult_NoneChannelMonitorUpdateErrZ *val = (LDKCResult_NoneChannelMonitorUpdateErrZ*)(arg & ~1);
692         CHECK(!val->result_ok);
693         uint32_t err_conv = LDKChannelMonitorUpdateErr_to_js((*val->contents.err));
694         return err_conv;
695 }
696 uint32_t  __attribute__((visibility("default"))) TS_LDKCVec_MonitorEventZ_new(uint32_tArray elems) {
697         LDKCVec_MonitorEventZ *ret = MALLOC(sizeof(LDKCVec_MonitorEventZ), "LDKCVec_MonitorEventZ");
698         ret->datalen = *((uint32_t*)elems);
699         if (ret->datalen == 0) {
700                 ret->data = NULL;
701         } else {
702                 ret->data = MALLOC(sizeof(LDKMonitorEvent) * ret->datalen, "LDKCVec_MonitorEventZ Data");
703                 uint32_t *java_elems = (uint32_t*)(elems + 4);
704                 for (size_t i = 0; i < ret->datalen; i++) {
705                         uint32_t arr_elem = java_elems[i];
706                         LDKMonitorEvent arr_elem_conv;
707                         arr_elem_conv.inner = (void*)(arr_elem & (~1));
708                         arr_elem_conv.is_owned = (arr_elem & 1) || (arr_elem == 0);
709                         arr_elem_conv = MonitorEvent_clone(&arr_elem_conv);
710                         ret->data[i] = arr_elem_conv;
711                 }
712         }
713         return (long)ret;
714 }
715 static inline LDKCVec_MonitorEventZ CVec_MonitorEventZ_clone(const LDKCVec_MonitorEventZ *orig) {
716         LDKCVec_MonitorEventZ ret = { .data = MALLOC(sizeof(LDKMonitorEvent) * orig->datalen, "LDKCVec_MonitorEventZ clone bytes"), .datalen = orig->datalen };
717         for (size_t i = 0; i < ret.datalen; i++) {
718                 ret.data[i] = MonitorEvent_clone(&orig->data[i]);
719         }
720         return ret;
721 }
722 jboolean  __attribute__((visibility("default"))) TS_LDKCResult_ChannelMonitorUpdateDecodeErrorZ_result_ok(uint32_t arg) {
723         return ((LDKCResult_ChannelMonitorUpdateDecodeErrorZ*)arg)->result_ok;
724 }
725 uint32_t  __attribute__((visibility("default"))) TS_LDKCResult_ChannelMonitorUpdateDecodeErrorZ_get_ok(uint32_t arg) {
726         LDKCResult_ChannelMonitorUpdateDecodeErrorZ *val = (LDKCResult_ChannelMonitorUpdateDecodeErrorZ*)(arg & ~1);
727         CHECK(val->result_ok);
728         LDKChannelMonitorUpdate res_var = (*val->contents.result);
729         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
730         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
731         long res_ref = (long)res_var.inner & ~1;
732         return res_ref;
733 }
734 uint32_t  __attribute__((visibility("default"))) TS_LDKCResult_ChannelMonitorUpdateDecodeErrorZ_get_err(uint32_t arg) {
735         LDKCResult_ChannelMonitorUpdateDecodeErrorZ *val = (LDKCResult_ChannelMonitorUpdateDecodeErrorZ*)(arg & ~1);
736         CHECK(!val->result_ok);
737         LDKDecodeError err_var = (*val->contents.err);
738         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
739         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
740         long err_ref = (long)err_var.inner & ~1;
741         return err_ref;
742 }
743 jboolean  __attribute__((visibility("default"))) TS_LDKCResult_NoneMonitorUpdateErrorZ_result_ok(uint32_t arg) {
744         return ((LDKCResult_NoneMonitorUpdateErrorZ*)arg)->result_ok;
745 }
746 void  __attribute__((visibility("default"))) TS_LDKCResult_NoneMonitorUpdateErrorZ_get_ok(uint32_t arg) {
747         LDKCResult_NoneMonitorUpdateErrorZ *val = (LDKCResult_NoneMonitorUpdateErrorZ*)(arg & ~1);
748         CHECK(val->result_ok);
749         return *val->contents.result;
750 }
751 uint32_t  __attribute__((visibility("default"))) TS_LDKCResult_NoneMonitorUpdateErrorZ_get_err(uint32_t arg) {
752         LDKCResult_NoneMonitorUpdateErrorZ *val = (LDKCResult_NoneMonitorUpdateErrorZ*)(arg & ~1);
753         CHECK(!val->result_ok);
754         LDKMonitorUpdateError err_var = (*val->contents.err);
755         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
756         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
757         long err_ref = (long)err_var.inner & ~1;
758         return err_ref;
759 }
760 uint32_t  __attribute__((visibility("default"))) TS_LDKC2Tuple_OutPointScriptZ_new(uint32_t a, int8_tArray b) {
761         LDKC2Tuple_OutPointScriptZ* ret = MALLOC(sizeof(LDKC2Tuple_OutPointScriptZ), "LDKC2Tuple_OutPointScriptZ");
762         LDKOutPoint a_conv;
763         a_conv.inner = (void*)(a & (~1));
764         a_conv.is_owned = (a & 1) || (a == 0);
765         a_conv = OutPoint_clone(&a_conv);
766         ret->a = a_conv;
767         LDKCVec_u8Z b_ref;
768         b_ref.datalen = *((uint32_t*)b);
769         b_ref.data = MALLOC(b_ref.datalen, "LDKCVec_u8Z Bytes");
770         memcpy(b_ref.data, (uint8_t*)(b + 4), b_ref.datalen);
771         ret->b = b_ref;
772         return (long)ret;
773 }
774 uint32_t  __attribute__((visibility("default"))) TS_LDKC2Tuple_OutPointScriptZ_get_a(uint32_t ptr) {
775         LDKC2Tuple_OutPointScriptZ *tuple = (LDKC2Tuple_OutPointScriptZ*)(ptr & ~1);
776         LDKOutPoint a_var = tuple->a;
777         CHECK((((long)a_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
778         CHECK((((long)&a_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
779         long a_ref = (long)a_var.inner & ~1;
780         return a_ref;
781 }
782 int8_tArray  __attribute__((visibility("default"))) TS_LDKC2Tuple_OutPointScriptZ_get_b(uint32_t ptr) {
783         LDKC2Tuple_OutPointScriptZ *tuple = (LDKC2Tuple_OutPointScriptZ*)(ptr & ~1);
784         LDKCVec_u8Z b_var = tuple->b;
785         int8_tArray b_arr = init_arr(b_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
786         memcpy((uint8_t*)(b_arr + 4), b_var.data, b_var.datalen);
787         return b_arr;
788 }
789 uint32_t  __attribute__((visibility("default"))) TS_LDKC2Tuple_u32TxOutZ_new(int32_t a, uint32_t b) {
790         LDKC2Tuple_u32TxOutZ* ret = MALLOC(sizeof(LDKC2Tuple_u32TxOutZ), "LDKC2Tuple_u32TxOutZ");
791         ret->a = a;
792         LDKTxOut b_conv = *(LDKTxOut*)(((uint64_t)b) & ~1);
793         FREE((void*)b);
794         ret->b = b_conv;
795         return (long)ret;
796 }
797 int32_t  __attribute__((visibility("default"))) TS_LDKC2Tuple_u32TxOutZ_get_a(uint32_t ptr) {
798         LDKC2Tuple_u32TxOutZ *tuple = (LDKC2Tuple_u32TxOutZ*)(ptr & ~1);
799         return tuple->a;
800 }
801 uint32_t  __attribute__((visibility("default"))) TS_LDKC2Tuple_u32TxOutZ_get_b(uint32_t ptr) {
802         LDKC2Tuple_u32TxOutZ *tuple = (LDKC2Tuple_u32TxOutZ*)(ptr & ~1);
803         long b_ref = ((long)&tuple->b) | 1;
804         return (long)b_ref;
805 }
806 uint32_t  __attribute__((visibility("default"))) TS_LDKCVec_C2Tuple_u32TxOutZZ_new(uint32_tArray elems) {
807         LDKCVec_C2Tuple_u32TxOutZZ *ret = MALLOC(sizeof(LDKCVec_C2Tuple_u32TxOutZZ), "LDKCVec_C2Tuple_u32TxOutZZ");
808         ret->datalen = *((uint32_t*)elems);
809         if (ret->datalen == 0) {
810                 ret->data = NULL;
811         } else {
812                 ret->data = MALLOC(sizeof(LDKC2Tuple_u32TxOutZ) * ret->datalen, "LDKCVec_C2Tuple_u32TxOutZZ Data");
813                 uint32_t *java_elems = (uint32_t*)(elems + 4);
814                 for (size_t i = 0; i < ret->datalen; i++) {
815                         uint32_t arr_elem = java_elems[i];
816                         LDKC2Tuple_u32TxOutZ arr_elem_conv = *(LDKC2Tuple_u32TxOutZ*)(((uint64_t)arr_elem) & ~1);
817                         FREE((void*)arr_elem);
818                         ret->data[i] = arr_elem_conv;
819                 }
820         }
821         return (long)ret;
822 }
823 static inline LDKCVec_C2Tuple_u32TxOutZZ CVec_C2Tuple_u32TxOutZZ_clone(const LDKCVec_C2Tuple_u32TxOutZZ *orig) {
824         LDKCVec_C2Tuple_u32TxOutZZ ret = { .data = MALLOC(sizeof(LDKC2Tuple_u32TxOutZ) * orig->datalen, "LDKCVec_C2Tuple_u32TxOutZZ clone bytes"), .datalen = orig->datalen };
825         for (size_t i = 0; i < ret.datalen; i++) {
826                 ret.data[i] = C2Tuple_u32TxOutZ_clone(&orig->data[i]);
827         }
828         return ret;
829 }
830 uint32_t  __attribute__((visibility("default"))) TS_LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ_new(int8_tArray a, uint32_tArray b) {
831         LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ* ret = MALLOC(sizeof(LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ), "LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ");
832         LDKThirtyTwoBytes a_ref;
833         CHECK(*((uint32_t*)a) == 32);
834         memcpy(a_ref.data, (uint8_t*)(a + 4), 32);
835         ret->a = a_ref;
836         LDKCVec_C2Tuple_u32TxOutZZ b_constr;
837         b_constr.datalen = *((uint32_t*)b);
838         if (b_constr.datalen > 0)
839                 b_constr.data = MALLOC(b_constr.datalen * sizeof(LDKC2Tuple_u32TxOutZ), "LDKCVec_C2Tuple_u32TxOutZZ Elements");
840         else
841                 b_constr.data = NULL;
842         uint32_t* b_vals = (uint32_t*)(b + 4);
843         for (size_t z = 0; z < b_constr.datalen; z++) {
844                 uint32_t arr_conv_25 = b_vals[z];
845                 LDKC2Tuple_u32TxOutZ arr_conv_25_conv = *(LDKC2Tuple_u32TxOutZ*)(((uint64_t)arr_conv_25) & ~1);
846                 FREE((void*)arr_conv_25);
847                 b_constr.data[z] = arr_conv_25_conv;
848         }
849         ret->b = b_constr;
850         return (long)ret;
851 }
852 int8_tArray  __attribute__((visibility("default"))) TS_LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ_get_a(uint32_t ptr) {
853         LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ *tuple = (LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ*)(ptr & ~1);
854         int8_tArray a_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
855         memcpy((uint8_t*)(a_arr + 4), tuple->a.data, 32);
856         return a_arr;
857 }
858 uint32_tArray  __attribute__((visibility("default"))) TS_LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ_get_b(uint32_t ptr) {
859         LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ *tuple = (LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ*)(ptr & ~1);
860         LDKCVec_C2Tuple_u32TxOutZZ b_var = tuple->b;
861         uint32_tArray b_arr = init_arr(b_var.datalen, sizeof(uint32_t), "Native uint32_tArray Bytes");
862         uint32_t *b_arr_ptr = (uint32_t*)(b_arr + 4);
863         for (size_t z = 0; z < b_var.datalen; z++) {
864                 long arr_conv_25_ref = (long)(&b_var.data[z]) | 1;
865                 b_arr_ptr[z] = arr_conv_25_ref;
866         }
867         return b_arr;
868 }
869 uint32_t  __attribute__((visibility("default"))) TS_LDKCVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ_new(uint32_tArray elems) {
870         LDKCVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ *ret = MALLOC(sizeof(LDKCVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ), "LDKCVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ");
871         ret->datalen = *((uint32_t*)elems);
872         if (ret->datalen == 0) {
873                 ret->data = NULL;
874         } else {
875                 ret->data = MALLOC(sizeof(LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ) * ret->datalen, "LDKCVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ Data");
876                 uint32_t *java_elems = (uint32_t*)(elems + 4);
877                 for (size_t i = 0; i < ret->datalen; i++) {
878                         uint32_t arr_elem = java_elems[i];
879                         LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ arr_elem_conv = *(LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ*)(((uint64_t)arr_elem) & ~1);
880                         FREE((void*)arr_elem);
881                         ret->data[i] = arr_elem_conv;
882                 }
883         }
884         return (long)ret;
885 }
886 uint32_t  __attribute__((visibility("default"))) TS_LDKC2Tuple_SignatureCVec_SignatureZZ_new(int8_tArray a, ptrArray b) {
887         LDKC2Tuple_SignatureCVec_SignatureZZ* ret = MALLOC(sizeof(LDKC2Tuple_SignatureCVec_SignatureZZ), "LDKC2Tuple_SignatureCVec_SignatureZZ");
888         LDKSignature a_ref;
889         CHECK(*((uint32_t*)a) == 64);
890         memcpy(a_ref.compact_form, (uint8_t*)(a + 4), 64);
891         ret->a = a_ref;
892         LDKCVec_SignatureZ b_constr;
893         b_constr.datalen = *((uint32_t*)b);
894         if (b_constr.datalen > 0)
895                 b_constr.data = MALLOC(b_constr.datalen * sizeof(LDKSignature), "LDKCVec_SignatureZ Elements");
896         else
897                 b_constr.data = NULL;
898         int8_tArray* b_vals = (int8_tArray*)(b + 4);
899         for (size_t m = 0; m < b_constr.datalen; m++) {
900                 int8_tArray arr_conv_12 = b_vals[m];
901                 LDKSignature arr_conv_12_ref;
902                 CHECK(*((uint32_t*)arr_conv_12) == 64);
903                 memcpy(arr_conv_12_ref.compact_form, (uint8_t*)(arr_conv_12 + 4), 64);
904                 b_constr.data[m] = arr_conv_12_ref;
905         }
906         ret->b = b_constr;
907         return (long)ret;
908 }
909 int8_tArray  __attribute__((visibility("default"))) TS_LDKC2Tuple_SignatureCVec_SignatureZZ_get_a(uint32_t ptr) {
910         LDKC2Tuple_SignatureCVec_SignatureZZ *tuple = (LDKC2Tuple_SignatureCVec_SignatureZZ*)(ptr & ~1);
911         int8_tArray a_arr = init_arr(64, sizeof(uint8_t), "Native int8_tArray Bytes");
912         memcpy((uint8_t*)(a_arr + 4), tuple->a.compact_form, 64);
913         return a_arr;
914 }
915 ptrArray  __attribute__((visibility("default"))) TS_LDKC2Tuple_SignatureCVec_SignatureZZ_get_b(uint32_t ptr) {
916         LDKC2Tuple_SignatureCVec_SignatureZZ *tuple = (LDKC2Tuple_SignatureCVec_SignatureZZ*)(ptr & ~1);
917         LDKCVec_SignatureZ b_var = tuple->b;
918         ptrArray b_arr = init_arr(b_var.datalen, sizeof(uint32_t), "Native ptrArray Bytes");
919         int8_tArray *b_arr_ptr = (int8_tArray*)(b_arr + 4);
920         for (size_t m = 0; m < b_var.datalen; m++) {
921                 int8_tArray arr_conv_12_arr = init_arr(64, sizeof(uint8_t), "Native int8_tArray Bytes");
922                 memcpy((uint8_t*)(arr_conv_12_arr + 4), b_var.data[m].compact_form, 64);
923                 b_arr_ptr[m] = arr_conv_12_arr;
924         }
925         return b_arr;
926 }
927 jboolean  __attribute__((visibility("default"))) TS_LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ_result_ok(uint32_t arg) {
928         return ((LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ*)arg)->result_ok;
929 }
930 uint32_t  __attribute__((visibility("default"))) TS_LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ_get_ok(uint32_t arg) {
931         LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ *val = (LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ*)(arg & ~1);
932         CHECK(val->result_ok);
933         long res_ref = (long)(&(*val->contents.result)) | 1;
934         return res_ref;
935 }
936 void  __attribute__((visibility("default"))) TS_LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ_get_err(uint32_t arg) {
937         LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ *val = (LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ*)(arg & ~1);
938         CHECK(!val->result_ok);
939         return *val->contents.err;
940 }
941 jboolean  __attribute__((visibility("default"))) TS_LDKCResult_SignatureNoneZ_result_ok(uint32_t arg) {
942         return ((LDKCResult_SignatureNoneZ*)arg)->result_ok;
943 }
944 int8_tArray  __attribute__((visibility("default"))) TS_LDKCResult_SignatureNoneZ_get_ok(uint32_t arg) {
945         LDKCResult_SignatureNoneZ *val = (LDKCResult_SignatureNoneZ*)(arg & ~1);
946         CHECK(val->result_ok);
947         int8_tArray res_arr = init_arr(64, sizeof(uint8_t), "Native int8_tArray Bytes");
948         memcpy((uint8_t*)(res_arr + 4), (*val->contents.result).compact_form, 64);
949         return res_arr;
950 }
951 void  __attribute__((visibility("default"))) TS_LDKCResult_SignatureNoneZ_get_err(uint32_t arg) {
952         LDKCResult_SignatureNoneZ *val = (LDKCResult_SignatureNoneZ*)(arg & ~1);
953         CHECK(!val->result_ok);
954         return *val->contents.err;
955 }
956 typedef struct LDKChannelKeys_JCalls {
957         atomic_size_t refcnt;
958         uint32_t get_per_commitment_point_meth;
959         uint32_t release_commitment_secret_meth;
960         uint32_t key_derivation_params_meth;
961         uint32_t sign_counterparty_commitment_meth;
962         uint32_t sign_holder_commitment_and_htlcs_meth;
963         uint32_t sign_justice_transaction_meth;
964         uint32_t sign_counterparty_htlc_transaction_meth;
965         uint32_t sign_closing_transaction_meth;
966         uint32_t sign_channel_announcement_meth;
967         uint32_t ready_channel_meth;
968         uint32_t write_meth;
969 } LDKChannelKeys_JCalls;
970 static void LDKChannelKeys_JCalls_free(void* this_arg) {
971         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
972         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
973                 js_free(j_calls->get_per_commitment_point_meth);
974                 js_free(j_calls->release_commitment_secret_meth);
975                 js_free(j_calls->key_derivation_params_meth);
976                 js_free(j_calls->sign_counterparty_commitment_meth);
977                 js_free(j_calls->sign_holder_commitment_and_htlcs_meth);
978                 js_free(j_calls->sign_justice_transaction_meth);
979                 js_free(j_calls->sign_counterparty_htlc_transaction_meth);
980                 js_free(j_calls->sign_closing_transaction_meth);
981                 js_free(j_calls->sign_channel_announcement_meth);
982                 js_free(j_calls->ready_channel_meth);
983                 js_free(j_calls->write_meth);
984                 FREE(j_calls);
985         }
986 }
987 LDKPublicKey get_per_commitment_point_jcall(const void* this_arg, uint64_t idx) {
988         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
989         int8_tArray arg = js_invoke_function_1(j_calls->get_per_commitment_point_meth, idx);
990         LDKPublicKey arg_ref;
991         CHECK(*((uint32_t*)arg) == 33);
992         memcpy(arg_ref.compressed_form, (uint8_t*)(arg + 4), 33);
993         return arg_ref;
994 }
995 LDKThirtyTwoBytes release_commitment_secret_jcall(const void* this_arg, uint64_t idx) {
996         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
997         int8_tArray arg = js_invoke_function_1(j_calls->release_commitment_secret_meth, idx);
998         LDKThirtyTwoBytes arg_ref;
999         CHECK(*((uint32_t*)arg) == 32);
1000         memcpy(arg_ref.data, (uint8_t*)(arg + 4), 32);
1001         return arg_ref;
1002 }
1003 LDKC2Tuple_u64u64Z key_derivation_params_jcall(const void* this_arg) {
1004         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1005         LDKC2Tuple_u64u64Z* ret = (LDKC2Tuple_u64u64Z*)js_invoke_function_0(j_calls->key_derivation_params_meth);
1006         LDKC2Tuple_u64u64Z ret_conv = *(LDKC2Tuple_u64u64Z*)(((uint64_t)ret) & ~1);
1007         ret_conv = C2Tuple_u64u64Z_clone((LDKC2Tuple_u64u64Z*)ret);
1008         return ret_conv;
1009 }
1010 LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ sign_counterparty_commitment_jcall(const void* this_arg, const LDKCommitmentTransaction * commitment_tx) {
1011         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1012         LDKCommitmentTransaction commitment_tx_var = *commitment_tx;
1013         commitment_tx_var = CommitmentTransaction_clone(commitment_tx);
1014         CHECK((((long)commitment_tx_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1015         CHECK((((long)&commitment_tx_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1016         long commitment_tx_ref = (long)commitment_tx_var.inner;
1017         if (commitment_tx_var.is_owned) {
1018                 commitment_tx_ref |= 1;
1019         }
1020         LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ* ret = (LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ*)js_invoke_function_1(j_calls->sign_counterparty_commitment_meth, commitment_tx_ref);
1021         LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ ret_conv = *(LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ*)(((uint64_t)ret) & ~1);
1022         ret_conv = CResult_C2Tuple_SignatureCVec_SignatureZZNoneZ_clone((LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ*)ret);
1023         return ret_conv;
1024 }
1025 LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ sign_holder_commitment_and_htlcs_jcall(const void* this_arg, const LDKHolderCommitmentTransaction * commitment_tx) {
1026         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1027         LDKHolderCommitmentTransaction commitment_tx_var = *commitment_tx;
1028         commitment_tx_var = HolderCommitmentTransaction_clone(commitment_tx);
1029         CHECK((((long)commitment_tx_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1030         CHECK((((long)&commitment_tx_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1031         long commitment_tx_ref = (long)commitment_tx_var.inner;
1032         if (commitment_tx_var.is_owned) {
1033                 commitment_tx_ref |= 1;
1034         }
1035         LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ* ret = (LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ*)js_invoke_function_1(j_calls->sign_holder_commitment_and_htlcs_meth, commitment_tx_ref);
1036         LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ ret_conv = *(LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ*)(((uint64_t)ret) & ~1);
1037         ret_conv = CResult_C2Tuple_SignatureCVec_SignatureZZNoneZ_clone((LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ*)ret);
1038         return ret_conv;
1039 }
1040 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) {
1041         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1042         LDKTransaction justice_tx_var = justice_tx;
1043         int8_tArray justice_tx_arr = init_arr(justice_tx_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
1044         memcpy((uint8_t*)(justice_tx_arr + 4), justice_tx_var.data, justice_tx_var.datalen);
1045         Transaction_free(justice_tx_var);
1046         int8_tArray per_commitment_key_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
1047         memcpy((uint8_t*)(per_commitment_key_arr + 4), *per_commitment_key, 32);
1048         LDKHTLCOutputInCommitment htlc_var = *htlc;
1049         htlc_var = HTLCOutputInCommitment_clone(htlc);
1050         CHECK((((long)htlc_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1051         CHECK((((long)&htlc_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1052         long htlc_ref = (long)htlc_var.inner;
1053         if (htlc_var.is_owned) {
1054                 htlc_ref |= 1;
1055         }
1056         LDKCResult_SignatureNoneZ* ret = (LDKCResult_SignatureNoneZ*)js_invoke_function_5(j_calls->sign_justice_transaction_meth, justice_tx_arr, input, amount, per_commitment_key_arr, htlc_ref);
1057         LDKCResult_SignatureNoneZ ret_conv = *(LDKCResult_SignatureNoneZ*)(((uint64_t)ret) & ~1);
1058         ret_conv = CResult_SignatureNoneZ_clone((LDKCResult_SignatureNoneZ*)ret);
1059         return ret_conv;
1060 }
1061 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) {
1062         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1063         LDKTransaction htlc_tx_var = htlc_tx;
1064         int8_tArray htlc_tx_arr = init_arr(htlc_tx_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
1065         memcpy((uint8_t*)(htlc_tx_arr + 4), htlc_tx_var.data, htlc_tx_var.datalen);
1066         Transaction_free(htlc_tx_var);
1067         int8_tArray per_commitment_point_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
1068         memcpy((uint8_t*)(per_commitment_point_arr + 4), per_commitment_point.compressed_form, 33);
1069         LDKHTLCOutputInCommitment htlc_var = *htlc;
1070         htlc_var = HTLCOutputInCommitment_clone(htlc);
1071         CHECK((((long)htlc_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1072         CHECK((((long)&htlc_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1073         long htlc_ref = (long)htlc_var.inner;
1074         if (htlc_var.is_owned) {
1075                 htlc_ref |= 1;
1076         }
1077         LDKCResult_SignatureNoneZ* ret = (LDKCResult_SignatureNoneZ*)js_invoke_function_5(j_calls->sign_counterparty_htlc_transaction_meth, htlc_tx_arr, input, amount, per_commitment_point_arr, htlc_ref);
1078         LDKCResult_SignatureNoneZ ret_conv = *(LDKCResult_SignatureNoneZ*)(((uint64_t)ret) & ~1);
1079         ret_conv = CResult_SignatureNoneZ_clone((LDKCResult_SignatureNoneZ*)ret);
1080         return ret_conv;
1081 }
1082 LDKCResult_SignatureNoneZ sign_closing_transaction_jcall(const void* this_arg, LDKTransaction closing_tx) {
1083         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1084         LDKTransaction closing_tx_var = closing_tx;
1085         int8_tArray closing_tx_arr = init_arr(closing_tx_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
1086         memcpy((uint8_t*)(closing_tx_arr + 4), closing_tx_var.data, closing_tx_var.datalen);
1087         Transaction_free(closing_tx_var);
1088         LDKCResult_SignatureNoneZ* ret = (LDKCResult_SignatureNoneZ*)js_invoke_function_1(j_calls->sign_closing_transaction_meth, closing_tx_arr);
1089         LDKCResult_SignatureNoneZ ret_conv = *(LDKCResult_SignatureNoneZ*)(((uint64_t)ret) & ~1);
1090         ret_conv = CResult_SignatureNoneZ_clone((LDKCResult_SignatureNoneZ*)ret);
1091         return ret_conv;
1092 }
1093 LDKCResult_SignatureNoneZ sign_channel_announcement_jcall(const void* this_arg, const LDKUnsignedChannelAnnouncement * msg) {
1094         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1095         LDKUnsignedChannelAnnouncement msg_var = *msg;
1096         msg_var = UnsignedChannelAnnouncement_clone(msg);
1097         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1098         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1099         long msg_ref = (long)msg_var.inner;
1100         if (msg_var.is_owned) {
1101                 msg_ref |= 1;
1102         }
1103         LDKCResult_SignatureNoneZ* ret = (LDKCResult_SignatureNoneZ*)js_invoke_function_1(j_calls->sign_channel_announcement_meth, msg_ref);
1104         LDKCResult_SignatureNoneZ ret_conv = *(LDKCResult_SignatureNoneZ*)(((uint64_t)ret) & ~1);
1105         ret_conv = CResult_SignatureNoneZ_clone((LDKCResult_SignatureNoneZ*)ret);
1106         return ret_conv;
1107 }
1108 void ready_channel_jcall(void* this_arg, const LDKChannelTransactionParameters * channel_parameters) {
1109         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1110         LDKChannelTransactionParameters channel_parameters_var = *channel_parameters;
1111         channel_parameters_var = ChannelTransactionParameters_clone(channel_parameters);
1112         CHECK((((long)channel_parameters_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1113         CHECK((((long)&channel_parameters_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1114         long channel_parameters_ref = (long)channel_parameters_var.inner;
1115         if (channel_parameters_var.is_owned) {
1116                 channel_parameters_ref |= 1;
1117         }
1118         js_invoke_function_1(j_calls->ready_channel_meth, channel_parameters_ref);
1119 }
1120 LDKCVec_u8Z write_jcall(const void* this_arg) {
1121         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1122         int8_tArray arg = js_invoke_function_0(j_calls->write_meth);
1123         LDKCVec_u8Z arg_ref;
1124         arg_ref.datalen = *((uint32_t*)arg);
1125         arg_ref.data = MALLOC(arg_ref.datalen, "LDKCVec_u8Z Bytes");
1126         memcpy(arg_ref.data, (uint8_t*)(arg + 4), arg_ref.datalen);
1127         return arg_ref;
1128 }
1129 static void* LDKChannelKeys_JCalls_clone(const void* this_arg) {
1130         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1131         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
1132         return (void*) this_arg;
1133 }
1134 static inline LDKChannelKeys LDKChannelKeys_init (/*TODO: JS Object Reference */void* o, uint32_t pubkeys) {
1135         LDKChannelKeys_JCalls *calls = MALLOC(sizeof(LDKChannelKeys_JCalls), "LDKChannelKeys_JCalls");
1136         atomic_init(&calls->refcnt, 1);
1137         //TODO: Assign calls->o from o
1138
1139         LDKChannelPublicKeys pubkeys_conv;
1140         pubkeys_conv.inner = (void*)(pubkeys & (~1));
1141         pubkeys_conv.is_owned = (pubkeys & 1) || (pubkeys == 0);
1142         pubkeys_conv = ChannelPublicKeys_clone(&pubkeys_conv);
1143
1144         LDKChannelKeys ret = {
1145                 .this_arg = (void*) calls,
1146                 .get_per_commitment_point = get_per_commitment_point_jcall,
1147                 .release_commitment_secret = release_commitment_secret_jcall,
1148                 .key_derivation_params = key_derivation_params_jcall,
1149                 .sign_counterparty_commitment = sign_counterparty_commitment_jcall,
1150                 .sign_holder_commitment_and_htlcs = sign_holder_commitment_and_htlcs_jcall,
1151                 .sign_justice_transaction = sign_justice_transaction_jcall,
1152                 .sign_counterparty_htlc_transaction = sign_counterparty_htlc_transaction_jcall,
1153                 .sign_closing_transaction = sign_closing_transaction_jcall,
1154                 .sign_channel_announcement = sign_channel_announcement_jcall,
1155                 .ready_channel = ready_channel_jcall,
1156                 .clone = LDKChannelKeys_JCalls_clone,
1157                 .write = write_jcall,
1158                 .free = LDKChannelKeys_JCalls_free,
1159                 .pubkeys = pubkeys_conv,
1160                 .set_pubkeys = NULL,
1161         };
1162         return ret;
1163 }
1164 long  __attribute__((visibility("default"))) TS_LDKChannelKeys_new(/*TODO: JS Object Reference */void* o, uint32_t pubkeys) {
1165         LDKChannelKeys *res_ptr = MALLOC(sizeof(LDKChannelKeys), "LDKChannelKeys");
1166         *res_ptr = LDKChannelKeys_init(o, pubkeys);
1167         return (long)res_ptr;
1168 }
1169 int8_tArray  __attribute__((visibility("default"))) TS_ChannelKeys_get_per_commitment_point(uint32_t this_arg, int64_t idx) {
1170         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
1171         int8_tArray arg_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
1172         memcpy((uint8_t*)(arg_arr + 4), (this_arg_conv->get_per_commitment_point)(this_arg_conv->this_arg, idx).compressed_form, 33);
1173         return arg_arr;
1174 }
1175
1176 int8_tArray  __attribute__((visibility("default"))) TS_ChannelKeys_release_commitment_secret(uint32_t this_arg, int64_t idx) {
1177         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
1178         int8_tArray arg_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
1179         memcpy((uint8_t*)(arg_arr + 4), (this_arg_conv->release_commitment_secret)(this_arg_conv->this_arg, idx).data, 32);
1180         return arg_arr;
1181 }
1182
1183 uint32_t  __attribute__((visibility("default"))) TS_ChannelKeys_key_derivation_params(uint32_t this_arg) {
1184         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
1185         LDKC2Tuple_u64u64Z* ret_ref = MALLOC(sizeof(LDKC2Tuple_u64u64Z), "LDKC2Tuple_u64u64Z");
1186         *ret_ref = (this_arg_conv->key_derivation_params)(this_arg_conv->this_arg);
1187         return (long)ret_ref;
1188 }
1189
1190 uint32_t  __attribute__((visibility("default"))) TS_ChannelKeys_sign_counterparty_commitment(uint32_t this_arg, uint32_t commitment_tx) {
1191         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
1192         LDKCommitmentTransaction commitment_tx_conv;
1193         commitment_tx_conv.inner = (void*)(commitment_tx & (~1));
1194         commitment_tx_conv.is_owned = false;
1195         LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ), "LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ");
1196         *ret_conv = (this_arg_conv->sign_counterparty_commitment)(this_arg_conv->this_arg, &commitment_tx_conv);
1197         return (long)ret_conv;
1198 }
1199
1200 uint32_t  __attribute__((visibility("default"))) TS_ChannelKeys_sign_holder_commitment_and_htlcs(uint32_t this_arg, uint32_t commitment_tx) {
1201         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
1202         LDKHolderCommitmentTransaction commitment_tx_conv;
1203         commitment_tx_conv.inner = (void*)(commitment_tx & (~1));
1204         commitment_tx_conv.is_owned = false;
1205         LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ), "LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ");
1206         *ret_conv = (this_arg_conv->sign_holder_commitment_and_htlcs)(this_arg_conv->this_arg, &commitment_tx_conv);
1207         return (long)ret_conv;
1208 }
1209
1210 uint32_t  __attribute__((visibility("default"))) 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) {
1211         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
1212         LDKTransaction justice_tx_ref;
1213         justice_tx_ref.datalen = *((uint32_t*)justice_tx);
1214         justice_tx_ref.data = MALLOC(justice_tx_ref.datalen, "LDKTransaction Bytes");
1215         memcpy(justice_tx_ref.data, (uint8_t*)(justice_tx + 4), justice_tx_ref.datalen);
1216         justice_tx_ref.data_is_owned = true;
1217         unsigned char per_commitment_key_arr[32];
1218         CHECK(*((uint32_t*)per_commitment_key) == 32);
1219         memcpy(per_commitment_key_arr, (uint8_t*)(per_commitment_key + 4), 32);
1220         unsigned char (*per_commitment_key_ref)[32] = &per_commitment_key_arr;
1221         LDKHTLCOutputInCommitment htlc_conv;
1222         htlc_conv.inner = (void*)(htlc & (~1));
1223         htlc_conv.is_owned = false;
1224         LDKCResult_SignatureNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_SignatureNoneZ), "LDKCResult_SignatureNoneZ");
1225         *ret_conv = (this_arg_conv->sign_justice_transaction)(this_arg_conv->this_arg, justice_tx_ref, input, amount, per_commitment_key_ref, &htlc_conv);
1226         return (long)ret_conv;
1227 }
1228
1229 uint32_t  __attribute__((visibility("default"))) 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) {
1230         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
1231         LDKTransaction htlc_tx_ref;
1232         htlc_tx_ref.datalen = *((uint32_t*)htlc_tx);
1233         htlc_tx_ref.data = MALLOC(htlc_tx_ref.datalen, "LDKTransaction Bytes");
1234         memcpy(htlc_tx_ref.data, (uint8_t*)(htlc_tx + 4), htlc_tx_ref.datalen);
1235         htlc_tx_ref.data_is_owned = true;
1236         LDKPublicKey per_commitment_point_ref;
1237         CHECK(*((uint32_t*)per_commitment_point) == 33);
1238         memcpy(per_commitment_point_ref.compressed_form, (uint8_t*)(per_commitment_point + 4), 33);
1239         LDKHTLCOutputInCommitment htlc_conv;
1240         htlc_conv.inner = (void*)(htlc & (~1));
1241         htlc_conv.is_owned = false;
1242         LDKCResult_SignatureNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_SignatureNoneZ), "LDKCResult_SignatureNoneZ");
1243         *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);
1244         return (long)ret_conv;
1245 }
1246
1247 uint32_t  __attribute__((visibility("default"))) TS_ChannelKeys_sign_closing_transaction(uint32_t this_arg, int8_tArray closing_tx) {
1248         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
1249         LDKTransaction closing_tx_ref;
1250         closing_tx_ref.datalen = *((uint32_t*)closing_tx);
1251         closing_tx_ref.data = MALLOC(closing_tx_ref.datalen, "LDKTransaction Bytes");
1252         memcpy(closing_tx_ref.data, (uint8_t*)(closing_tx + 4), closing_tx_ref.datalen);
1253         closing_tx_ref.data_is_owned = true;
1254         LDKCResult_SignatureNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_SignatureNoneZ), "LDKCResult_SignatureNoneZ");
1255         *ret_conv = (this_arg_conv->sign_closing_transaction)(this_arg_conv->this_arg, closing_tx_ref);
1256         return (long)ret_conv;
1257 }
1258
1259 uint32_t  __attribute__((visibility("default"))) TS_ChannelKeys_sign_channel_announcement(uint32_t this_arg, uint32_t msg) {
1260         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
1261         LDKUnsignedChannelAnnouncement msg_conv;
1262         msg_conv.inner = (void*)(msg & (~1));
1263         msg_conv.is_owned = false;
1264         LDKCResult_SignatureNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_SignatureNoneZ), "LDKCResult_SignatureNoneZ");
1265         *ret_conv = (this_arg_conv->sign_channel_announcement)(this_arg_conv->this_arg, &msg_conv);
1266         return (long)ret_conv;
1267 }
1268
1269 void  __attribute__((visibility("default"))) TS_ChannelKeys_ready_channel(uint32_t this_arg, uint32_t channel_parameters) {
1270         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
1271         LDKChannelTransactionParameters channel_parameters_conv;
1272         channel_parameters_conv.inner = (void*)(channel_parameters & (~1));
1273         channel_parameters_conv.is_owned = false;
1274         (this_arg_conv->ready_channel)(this_arg_conv->this_arg, &channel_parameters_conv);
1275 }
1276
1277 int8_tArray  __attribute__((visibility("default"))) TS_ChannelKeys_write(uint32_t this_arg) {
1278         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
1279         LDKCVec_u8Z arg_var = (this_arg_conv->write)(this_arg_conv->this_arg);
1280         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
1281         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
1282         CVec_u8Z_free(arg_var);
1283         return arg_arr;
1284 }
1285
1286 LDKChannelPublicKeys LDKChannelKeys_set_get_pubkeys(LDKChannelKeys* this_arg) {
1287         if (this_arg->set_pubkeys != NULL)
1288                 this_arg->set_pubkeys(this_arg);
1289         return this_arg->pubkeys;
1290 }
1291 uint32_t  __attribute__((visibility("default"))) TS_ChannelKeys_get_pubkeys(uint32_t this_arg) {
1292         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
1293         LDKChannelPublicKeys ret_var = LDKChannelKeys_set_get_pubkeys(this_arg_conv);
1294         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1295         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1296         long ret_ref = (long)ret_var.inner;
1297         if (ret_var.is_owned) {
1298                 ret_ref |= 1;
1299         }
1300         return ret_ref;
1301 }
1302
1303 uint32_t  __attribute__((visibility("default"))) TS_LDKC2Tuple_BlockHashChannelMonitorZ_new(int8_tArray a, uint32_t b) {
1304         LDKC2Tuple_BlockHashChannelMonitorZ* ret = MALLOC(sizeof(LDKC2Tuple_BlockHashChannelMonitorZ), "LDKC2Tuple_BlockHashChannelMonitorZ");
1305         LDKThirtyTwoBytes a_ref;
1306         CHECK(*((uint32_t*)a) == 32);
1307         memcpy(a_ref.data, (uint8_t*)(a + 4), 32);
1308         ret->a = a_ref;
1309         LDKChannelMonitor b_conv;
1310         b_conv.inner = (void*)(b & (~1));
1311         b_conv.is_owned = (b & 1) || (b == 0);
1312         b_conv = ChannelMonitor_clone(&b_conv);
1313         ret->b = b_conv;
1314         return (long)ret;
1315 }
1316 int8_tArray  __attribute__((visibility("default"))) TS_LDKC2Tuple_BlockHashChannelMonitorZ_get_a(uint32_t ptr) {
1317         LDKC2Tuple_BlockHashChannelMonitorZ *tuple = (LDKC2Tuple_BlockHashChannelMonitorZ*)(ptr & ~1);
1318         int8_tArray a_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
1319         memcpy((uint8_t*)(a_arr + 4), tuple->a.data, 32);
1320         return a_arr;
1321 }
1322 uint32_t  __attribute__((visibility("default"))) TS_LDKC2Tuple_BlockHashChannelMonitorZ_get_b(uint32_t ptr) {
1323         LDKC2Tuple_BlockHashChannelMonitorZ *tuple = (LDKC2Tuple_BlockHashChannelMonitorZ*)(ptr & ~1);
1324         LDKChannelMonitor b_var = tuple->b;
1325         CHECK((((long)b_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1326         CHECK((((long)&b_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1327         long b_ref = (long)b_var.inner & ~1;
1328         return b_ref;
1329 }
1330 jboolean  __attribute__((visibility("default"))) TS_LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ_result_ok(uint32_t arg) {
1331         return ((LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ*)arg)->result_ok;
1332 }
1333 uint32_t  __attribute__((visibility("default"))) TS_LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ_get_ok(uint32_t arg) {
1334         LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ *val = (LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ*)(arg & ~1);
1335         CHECK(val->result_ok);
1336         long res_ref = (long)(&(*val->contents.result)) | 1;
1337         return res_ref;
1338 }
1339 uint32_t  __attribute__((visibility("default"))) TS_LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ_get_err(uint32_t arg) {
1340         LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ *val = (LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ*)(arg & ~1);
1341         CHECK(!val->result_ok);
1342         LDKDecodeError err_var = (*val->contents.err);
1343         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1344         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1345         long err_ref = (long)err_var.inner & ~1;
1346         return err_ref;
1347 }
1348 jboolean  __attribute__((visibility("default"))) TS_LDKCResult_SpendableOutputDescriptorDecodeErrorZ_result_ok(uint32_t arg) {
1349         return ((LDKCResult_SpendableOutputDescriptorDecodeErrorZ*)arg)->result_ok;
1350 }
1351 uint32_t  __attribute__((visibility("default"))) TS_LDKCResult_SpendableOutputDescriptorDecodeErrorZ_get_ok(uint32_t arg) {
1352         LDKCResult_SpendableOutputDescriptorDecodeErrorZ *val = (LDKCResult_SpendableOutputDescriptorDecodeErrorZ*)(arg & ~1);
1353         CHECK(val->result_ok);
1354         long res_ref = ((long)&(*val->contents.result)) | 1;
1355         return res_ref;
1356 }
1357 uint32_t  __attribute__((visibility("default"))) TS_LDKCResult_SpendableOutputDescriptorDecodeErrorZ_get_err(uint32_t arg) {
1358         LDKCResult_SpendableOutputDescriptorDecodeErrorZ *val = (LDKCResult_SpendableOutputDescriptorDecodeErrorZ*)(arg & ~1);
1359         CHECK(!val->result_ok);
1360         LDKDecodeError err_var = (*val->contents.err);
1361         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1362         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1363         long err_ref = (long)err_var.inner & ~1;
1364         return err_ref;
1365 }
1366 jboolean  __attribute__((visibility("default"))) TS_LDKCResult_ChanKeySignerDecodeErrorZ_result_ok(uint32_t arg) {
1367         return ((LDKCResult_ChanKeySignerDecodeErrorZ*)arg)->result_ok;
1368 }
1369 uint32_t  __attribute__((visibility("default"))) TS_LDKCResult_ChanKeySignerDecodeErrorZ_get_ok(uint32_t arg) {
1370         LDKCResult_ChanKeySignerDecodeErrorZ *val = (LDKCResult_ChanKeySignerDecodeErrorZ*)(arg & ~1);
1371         CHECK(val->result_ok);
1372         LDKChannelKeys* ret = MALLOC(sizeof(LDKChannelKeys), "LDKChannelKeys");
1373         *ret = ChannelKeys_clone(&(*val->contents.result));
1374         return (long)ret;
1375 }
1376 uint32_t  __attribute__((visibility("default"))) TS_LDKCResult_ChanKeySignerDecodeErrorZ_get_err(uint32_t arg) {
1377         LDKCResult_ChanKeySignerDecodeErrorZ *val = (LDKCResult_ChanKeySignerDecodeErrorZ*)(arg & ~1);
1378         CHECK(!val->result_ok);
1379         LDKDecodeError err_var = (*val->contents.err);
1380         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1381         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1382         long err_ref = (long)err_var.inner & ~1;
1383         return err_ref;
1384 }
1385 jboolean  __attribute__((visibility("default"))) TS_LDKCResult_InMemoryChannelKeysDecodeErrorZ_result_ok(uint32_t arg) {
1386         return ((LDKCResult_InMemoryChannelKeysDecodeErrorZ*)arg)->result_ok;
1387 }
1388 uint32_t  __attribute__((visibility("default"))) TS_LDKCResult_InMemoryChannelKeysDecodeErrorZ_get_ok(uint32_t arg) {
1389         LDKCResult_InMemoryChannelKeysDecodeErrorZ *val = (LDKCResult_InMemoryChannelKeysDecodeErrorZ*)(arg & ~1);
1390         CHECK(val->result_ok);
1391         LDKInMemoryChannelKeys res_var = (*val->contents.result);
1392         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1393         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1394         long res_ref = (long)res_var.inner & ~1;
1395         return res_ref;
1396 }
1397 uint32_t  __attribute__((visibility("default"))) TS_LDKCResult_InMemoryChannelKeysDecodeErrorZ_get_err(uint32_t arg) {
1398         LDKCResult_InMemoryChannelKeysDecodeErrorZ *val = (LDKCResult_InMemoryChannelKeysDecodeErrorZ*)(arg & ~1);
1399         CHECK(!val->result_ok);
1400         LDKDecodeError err_var = (*val->contents.err);
1401         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1402         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1403         long err_ref = (long)err_var.inner & ~1;
1404         return err_ref;
1405 }
1406 jboolean  __attribute__((visibility("default"))) TS_LDKCResult_TxOutAccessErrorZ_result_ok(uint32_t arg) {
1407         return ((LDKCResult_TxOutAccessErrorZ*)arg)->result_ok;
1408 }
1409 uint32_t  __attribute__((visibility("default"))) TS_LDKCResult_TxOutAccessErrorZ_get_ok(uint32_t arg) {
1410         LDKCResult_TxOutAccessErrorZ *val = (LDKCResult_TxOutAccessErrorZ*)(arg & ~1);
1411         CHECK(val->result_ok);
1412         long res_ref = ((long)&(*val->contents.result)) | 1;
1413         return (long)res_ref;
1414 }
1415 uint32_t  __attribute__((visibility("default"))) TS_LDKCResult_TxOutAccessErrorZ_get_err(uint32_t arg) {
1416         LDKCResult_TxOutAccessErrorZ *val = (LDKCResult_TxOutAccessErrorZ*)(arg & ~1);
1417         CHECK(!val->result_ok);
1418         uint32_t err_conv = LDKAccessError_to_js((*val->contents.err));
1419         return err_conv;
1420 }
1421 uint32_t __attribute__((visibility("default"))) TS_LDKAPIError_ref_from_ptr(uint32_t ptr) {
1422         LDKAPIError *obj = (LDKAPIError*)ptr;
1423         switch(obj->tag) {
1424                 case LDKAPIError_APIMisuseError: {
1425                         LDKCVec_u8Z err_var = obj->api_misuse_error.err;
1426                         int8_tArray err_arr = init_arr(err_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
1427                         memcpy((uint8_t*)(err_arr + 4), err_var.data, err_var.datalen);
1428                         return 0 /* LDKAPIError - APIMisuseError */; (void) err_arr;
1429                 }
1430                 case LDKAPIError_FeeRateTooHigh: {
1431                         LDKCVec_u8Z err_var = obj->fee_rate_too_high.err;
1432                         int8_tArray err_arr = init_arr(err_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
1433                         memcpy((uint8_t*)(err_arr + 4), err_var.data, err_var.datalen);
1434                         return 0 /* LDKAPIError - FeeRateTooHigh */; (void) err_arr; (void) obj->fee_rate_too_high.feerate;
1435                 }
1436                 case LDKAPIError_RouteError: {
1437                         LDKStr err_str = obj->route_error.err;
1438                         jstring err_conv = str_ref_to_ts(err_str.chars, err_str.len);
1439                         return 0 /* LDKAPIError - RouteError */; (void) err_conv;
1440                 }
1441                 case LDKAPIError_ChannelUnavailable: {
1442                         LDKCVec_u8Z err_var = obj->channel_unavailable.err;
1443                         int8_tArray err_arr = init_arr(err_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
1444                         memcpy((uint8_t*)(err_arr + 4), err_var.data, err_var.datalen);
1445                         return 0 /* LDKAPIError - ChannelUnavailable */; (void) err_arr;
1446                 }
1447                 case LDKAPIError_MonitorUpdateFailed: {
1448                         return 0 /* LDKAPIError - MonitorUpdateFailed */;
1449                 }
1450                 default: abort();
1451         }
1452 }
1453 jboolean  __attribute__((visibility("default"))) TS_LDKCResult_NoneAPIErrorZ_result_ok(uint32_t arg) {
1454         return ((LDKCResult_NoneAPIErrorZ*)arg)->result_ok;
1455 }
1456 void  __attribute__((visibility("default"))) TS_LDKCResult_NoneAPIErrorZ_get_ok(uint32_t arg) {
1457         LDKCResult_NoneAPIErrorZ *val = (LDKCResult_NoneAPIErrorZ*)(arg & ~1);
1458         CHECK(val->result_ok);
1459         return *val->contents.result;
1460 }
1461 uint32_t  __attribute__((visibility("default"))) TS_LDKCResult_NoneAPIErrorZ_get_err(uint32_t arg) {
1462         LDKCResult_NoneAPIErrorZ *val = (LDKCResult_NoneAPIErrorZ*)(arg & ~1);
1463         CHECK(!val->result_ok);
1464         long err_ref = ((long)&(*val->contents.err)) | 1;
1465         return err_ref;
1466 }
1467 uint32_t  __attribute__((visibility("default"))) TS_LDKCVec_ChannelDetailsZ_new(uint32_tArray elems) {
1468         LDKCVec_ChannelDetailsZ *ret = MALLOC(sizeof(LDKCVec_ChannelDetailsZ), "LDKCVec_ChannelDetailsZ");
1469         ret->datalen = *((uint32_t*)elems);
1470         if (ret->datalen == 0) {
1471                 ret->data = NULL;
1472         } else {
1473                 ret->data = MALLOC(sizeof(LDKChannelDetails) * ret->datalen, "LDKCVec_ChannelDetailsZ Data");
1474                 uint32_t *java_elems = (uint32_t*)(elems + 4);
1475                 for (size_t i = 0; i < ret->datalen; i++) {
1476                         uint32_t arr_elem = java_elems[i];
1477                         LDKChannelDetails arr_elem_conv;
1478                         arr_elem_conv.inner = (void*)(arr_elem & (~1));
1479                         arr_elem_conv.is_owned = (arr_elem & 1) || (arr_elem == 0);
1480                         arr_elem_conv = ChannelDetails_clone(&arr_elem_conv);
1481                         ret->data[i] = arr_elem_conv;
1482                 }
1483         }
1484         return (long)ret;
1485 }
1486 static inline LDKCVec_ChannelDetailsZ CVec_ChannelDetailsZ_clone(const LDKCVec_ChannelDetailsZ *orig) {
1487         LDKCVec_ChannelDetailsZ ret = { .data = MALLOC(sizeof(LDKChannelDetails) * orig->datalen, "LDKCVec_ChannelDetailsZ clone bytes"), .datalen = orig->datalen };
1488         for (size_t i = 0; i < ret.datalen; i++) {
1489                 ret.data[i] = ChannelDetails_clone(&orig->data[i]);
1490         }
1491         return ret;
1492 }
1493 jboolean  __attribute__((visibility("default"))) TS_LDKCResult_NonePaymentSendFailureZ_result_ok(uint32_t arg) {
1494         return ((LDKCResult_NonePaymentSendFailureZ*)arg)->result_ok;
1495 }
1496 void  __attribute__((visibility("default"))) TS_LDKCResult_NonePaymentSendFailureZ_get_ok(uint32_t arg) {
1497         LDKCResult_NonePaymentSendFailureZ *val = (LDKCResult_NonePaymentSendFailureZ*)(arg & ~1);
1498         CHECK(val->result_ok);
1499         return *val->contents.result;
1500 }
1501 uint32_t  __attribute__((visibility("default"))) TS_LDKCResult_NonePaymentSendFailureZ_get_err(uint32_t arg) {
1502         LDKCResult_NonePaymentSendFailureZ *val = (LDKCResult_NonePaymentSendFailureZ*)(arg & ~1);
1503         CHECK(!val->result_ok);
1504         LDKPaymentSendFailure err_var = (*val->contents.err);
1505         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1506         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1507         long err_ref = (long)err_var.inner & ~1;
1508         return err_ref;
1509 }
1510 uint32_t __attribute__((visibility("default"))) TS_LDKNetAddress_ref_from_ptr(uint32_t ptr) {
1511         LDKNetAddress *obj = (LDKNetAddress*)ptr;
1512         switch(obj->tag) {
1513                 case LDKNetAddress_IPv4: {
1514                         int8_tArray addr_arr = init_arr(4, sizeof(uint8_t), "Native int8_tArray Bytes");
1515                         memcpy((uint8_t*)(addr_arr + 4), obj->i_pv4.addr.data, 4);
1516                         return 0 /* LDKNetAddress - IPv4 */; (void) addr_arr; (void) obj->i_pv4.port;
1517                 }
1518                 case LDKNetAddress_IPv6: {
1519                         int8_tArray addr_arr = init_arr(16, sizeof(uint8_t), "Native int8_tArray Bytes");
1520                         memcpy((uint8_t*)(addr_arr + 4), obj->i_pv6.addr.data, 16);
1521                         return 0 /* LDKNetAddress - IPv6 */; (void) addr_arr; (void) obj->i_pv6.port;
1522                 }
1523                 case LDKNetAddress_OnionV2: {
1524                         int8_tArray addr_arr = init_arr(10, sizeof(uint8_t), "Native int8_tArray Bytes");
1525                         memcpy((uint8_t*)(addr_arr + 4), obj->onion_v2.addr.data, 10);
1526                         return 0 /* LDKNetAddress - OnionV2 */; (void) addr_arr; (void) obj->onion_v2.port;
1527                 }
1528                 case LDKNetAddress_OnionV3: {
1529                         int8_tArray ed25519_pubkey_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
1530                         memcpy((uint8_t*)(ed25519_pubkey_arr + 4), obj->onion_v3.ed25519_pubkey.data, 32);
1531                         return 0 /* LDKNetAddress - OnionV3 */; (void) ed25519_pubkey_arr; (void) obj->onion_v3.checksum; (void) obj->onion_v3.version; (void) obj->onion_v3.port;
1532                 }
1533                 default: abort();
1534         }
1535 }
1536 uint32_t  __attribute__((visibility("default"))) TS_LDKCVec_NetAddressZ_new(uint32_tArray elems) {
1537         LDKCVec_NetAddressZ *ret = MALLOC(sizeof(LDKCVec_NetAddressZ), "LDKCVec_NetAddressZ");
1538         ret->datalen = *((uint32_t*)elems);
1539         if (ret->datalen == 0) {
1540                 ret->data = NULL;
1541         } else {
1542                 ret->data = MALLOC(sizeof(LDKNetAddress) * ret->datalen, "LDKCVec_NetAddressZ Data");
1543                 uint32_t *java_elems = (uint32_t*)(elems + 4);
1544                 for (size_t i = 0; i < ret->datalen; i++) {
1545                         uint32_t arr_elem = java_elems[i];
1546                         LDKNetAddress arr_elem_conv = *(LDKNetAddress*)(((uint64_t)arr_elem) & ~1);
1547                         FREE((void*)arr_elem);
1548                         ret->data[i] = arr_elem_conv;
1549                 }
1550         }
1551         return (long)ret;
1552 }
1553 static inline LDKCVec_NetAddressZ CVec_NetAddressZ_clone(const LDKCVec_NetAddressZ *orig) {
1554         LDKCVec_NetAddressZ ret = { .data = MALLOC(sizeof(LDKNetAddress) * orig->datalen, "LDKCVec_NetAddressZ clone bytes"), .datalen = orig->datalen };
1555         for (size_t i = 0; i < ret.datalen; i++) {
1556                 ret.data[i] = NetAddress_clone(&orig->data[i]);
1557         }
1558         return ret;
1559 }
1560 uint32_t  __attribute__((visibility("default"))) TS_LDKCVec_ChannelMonitorZ_new(uint32_tArray elems) {
1561         LDKCVec_ChannelMonitorZ *ret = MALLOC(sizeof(LDKCVec_ChannelMonitorZ), "LDKCVec_ChannelMonitorZ");
1562         ret->datalen = *((uint32_t*)elems);
1563         if (ret->datalen == 0) {
1564                 ret->data = NULL;
1565         } else {
1566                 ret->data = MALLOC(sizeof(LDKChannelMonitor) * ret->datalen, "LDKCVec_ChannelMonitorZ Data");
1567                 uint32_t *java_elems = (uint32_t*)(elems + 4);
1568                 for (size_t i = 0; i < ret->datalen; i++) {
1569                         uint32_t arr_elem = java_elems[i];
1570                         LDKChannelMonitor arr_elem_conv;
1571                         arr_elem_conv.inner = (void*)(arr_elem & (~1));
1572                         arr_elem_conv.is_owned = (arr_elem & 1) || (arr_elem == 0);
1573                         arr_elem_conv = ChannelMonitor_clone(&arr_elem_conv);
1574                         ret->data[i] = arr_elem_conv;
1575                 }
1576         }
1577         return (long)ret;
1578 }
1579 static inline LDKCVec_ChannelMonitorZ CVec_ChannelMonitorZ_clone(const LDKCVec_ChannelMonitorZ *orig) {
1580         LDKCVec_ChannelMonitorZ ret = { .data = MALLOC(sizeof(LDKChannelMonitor) * orig->datalen, "LDKCVec_ChannelMonitorZ clone bytes"), .datalen = orig->datalen };
1581         for (size_t i = 0; i < ret.datalen; i++) {
1582                 ret.data[i] = ChannelMonitor_clone(&orig->data[i]);
1583         }
1584         return ret;
1585 }
1586 typedef struct LDKWatch_JCalls {
1587         atomic_size_t refcnt;
1588         uint32_t watch_channel_meth;
1589         uint32_t update_channel_meth;
1590         uint32_t release_pending_monitor_events_meth;
1591 } LDKWatch_JCalls;
1592 static void LDKWatch_JCalls_free(void* this_arg) {
1593         LDKWatch_JCalls *j_calls = (LDKWatch_JCalls*) this_arg;
1594         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
1595                 js_free(j_calls->watch_channel_meth);
1596                 js_free(j_calls->update_channel_meth);
1597                 js_free(j_calls->release_pending_monitor_events_meth);
1598                 FREE(j_calls);
1599         }
1600 }
1601 LDKCResult_NoneChannelMonitorUpdateErrZ watch_channel_jcall(const void* this_arg, LDKOutPoint funding_txo, LDKChannelMonitor monitor) {
1602         LDKWatch_JCalls *j_calls = (LDKWatch_JCalls*) this_arg;
1603         LDKOutPoint funding_txo_var = funding_txo;
1604         CHECK((((long)funding_txo_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1605         CHECK((((long)&funding_txo_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1606         long funding_txo_ref = (long)funding_txo_var.inner;
1607         if (funding_txo_var.is_owned) {
1608                 funding_txo_ref |= 1;
1609         }
1610         LDKChannelMonitor monitor_var = monitor;
1611         CHECK((((long)monitor_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1612         CHECK((((long)&monitor_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1613         long monitor_ref = (long)monitor_var.inner;
1614         if (monitor_var.is_owned) {
1615                 monitor_ref |= 1;
1616         }
1617         LDKCResult_NoneChannelMonitorUpdateErrZ* ret = (LDKCResult_NoneChannelMonitorUpdateErrZ*)js_invoke_function_2(j_calls->watch_channel_meth, funding_txo_ref, monitor_ref);
1618         LDKCResult_NoneChannelMonitorUpdateErrZ ret_conv = *(LDKCResult_NoneChannelMonitorUpdateErrZ*)(((uint64_t)ret) & ~1);
1619         ret_conv = CResult_NoneChannelMonitorUpdateErrZ_clone((LDKCResult_NoneChannelMonitorUpdateErrZ*)ret);
1620         return ret_conv;
1621 }
1622 LDKCResult_NoneChannelMonitorUpdateErrZ update_channel_jcall(const void* this_arg, LDKOutPoint funding_txo, LDKChannelMonitorUpdate update) {
1623         LDKWatch_JCalls *j_calls = (LDKWatch_JCalls*) this_arg;
1624         LDKOutPoint funding_txo_var = funding_txo;
1625         CHECK((((long)funding_txo_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1626         CHECK((((long)&funding_txo_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1627         long funding_txo_ref = (long)funding_txo_var.inner;
1628         if (funding_txo_var.is_owned) {
1629                 funding_txo_ref |= 1;
1630         }
1631         LDKChannelMonitorUpdate update_var = update;
1632         CHECK((((long)update_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1633         CHECK((((long)&update_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1634         long update_ref = (long)update_var.inner;
1635         if (update_var.is_owned) {
1636                 update_ref |= 1;
1637         }
1638         LDKCResult_NoneChannelMonitorUpdateErrZ* ret = (LDKCResult_NoneChannelMonitorUpdateErrZ*)js_invoke_function_2(j_calls->update_channel_meth, funding_txo_ref, update_ref);
1639         LDKCResult_NoneChannelMonitorUpdateErrZ ret_conv = *(LDKCResult_NoneChannelMonitorUpdateErrZ*)(((uint64_t)ret) & ~1);
1640         ret_conv = CResult_NoneChannelMonitorUpdateErrZ_clone((LDKCResult_NoneChannelMonitorUpdateErrZ*)ret);
1641         return ret_conv;
1642 }
1643 LDKCVec_MonitorEventZ release_pending_monitor_events_jcall(const void* this_arg) {
1644         LDKWatch_JCalls *j_calls = (LDKWatch_JCalls*) this_arg;
1645         uint32_tArray arg = js_invoke_function_0(j_calls->release_pending_monitor_events_meth);
1646         LDKCVec_MonitorEventZ arg_constr;
1647         arg_constr.datalen = *((uint32_t*)arg);
1648         if (arg_constr.datalen > 0)
1649                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKMonitorEvent), "LDKCVec_MonitorEventZ Elements");
1650         else
1651                 arg_constr.data = NULL;
1652         uint32_t* arg_vals = (uint32_t*)(arg + 4);
1653         for (size_t o = 0; o < arg_constr.datalen; o++) {
1654                 uint32_t arr_conv_14 = arg_vals[o];
1655                 LDKMonitorEvent arr_conv_14_conv;
1656                 arr_conv_14_conv.inner = (void*)(arr_conv_14 & (~1));
1657                 arr_conv_14_conv.is_owned = (arr_conv_14 & 1) || (arr_conv_14 == 0);
1658                 arr_conv_14_conv = MonitorEvent_clone(&arr_conv_14_conv);
1659                 arg_constr.data[o] = arr_conv_14_conv;
1660         }
1661         return arg_constr;
1662 }
1663 static void* LDKWatch_JCalls_clone(const void* this_arg) {
1664         LDKWatch_JCalls *j_calls = (LDKWatch_JCalls*) this_arg;
1665         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
1666         return (void*) this_arg;
1667 }
1668 static inline LDKWatch LDKWatch_init (/*TODO: JS Object Reference */void* o) {
1669         LDKWatch_JCalls *calls = MALLOC(sizeof(LDKWatch_JCalls), "LDKWatch_JCalls");
1670         atomic_init(&calls->refcnt, 1);
1671         //TODO: Assign calls->o from o
1672
1673         LDKWatch ret = {
1674                 .this_arg = (void*) calls,
1675                 .watch_channel = watch_channel_jcall,
1676                 .update_channel = update_channel_jcall,
1677                 .release_pending_monitor_events = release_pending_monitor_events_jcall,
1678                 .free = LDKWatch_JCalls_free,
1679         };
1680         return ret;
1681 }
1682 long  __attribute__((visibility("default"))) TS_LDKWatch_new(/*TODO: JS Object Reference */void* o) {
1683         LDKWatch *res_ptr = MALLOC(sizeof(LDKWatch), "LDKWatch");
1684         *res_ptr = LDKWatch_init(o);
1685         return (long)res_ptr;
1686 }
1687 uint32_t  __attribute__((visibility("default"))) TS_Watch_watch_channel(uint32_t this_arg, uint32_t funding_txo, uint32_t monitor) {
1688         LDKWatch* this_arg_conv = (LDKWatch*)this_arg;
1689         LDKOutPoint funding_txo_conv;
1690         funding_txo_conv.inner = (void*)(funding_txo & (~1));
1691         funding_txo_conv.is_owned = (funding_txo & 1) || (funding_txo == 0);
1692         funding_txo_conv = OutPoint_clone(&funding_txo_conv);
1693         LDKChannelMonitor monitor_conv;
1694         monitor_conv.inner = (void*)(monitor & (~1));
1695         monitor_conv.is_owned = (monitor & 1) || (monitor == 0);
1696         monitor_conv = ChannelMonitor_clone(&monitor_conv);
1697         LDKCResult_NoneChannelMonitorUpdateErrZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneChannelMonitorUpdateErrZ), "LDKCResult_NoneChannelMonitorUpdateErrZ");
1698         *ret_conv = (this_arg_conv->watch_channel)(this_arg_conv->this_arg, funding_txo_conv, monitor_conv);
1699         return (long)ret_conv;
1700 }
1701
1702 uint32_t  __attribute__((visibility("default"))) TS_Watch_update_channel(uint32_t this_arg, uint32_t funding_txo, uint32_t update) {
1703         LDKWatch* this_arg_conv = (LDKWatch*)this_arg;
1704         LDKOutPoint funding_txo_conv;
1705         funding_txo_conv.inner = (void*)(funding_txo & (~1));
1706         funding_txo_conv.is_owned = (funding_txo & 1) || (funding_txo == 0);
1707         funding_txo_conv = OutPoint_clone(&funding_txo_conv);
1708         LDKChannelMonitorUpdate update_conv;
1709         update_conv.inner = (void*)(update & (~1));
1710         update_conv.is_owned = (update & 1) || (update == 0);
1711         update_conv = ChannelMonitorUpdate_clone(&update_conv);
1712         LDKCResult_NoneChannelMonitorUpdateErrZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneChannelMonitorUpdateErrZ), "LDKCResult_NoneChannelMonitorUpdateErrZ");
1713         *ret_conv = (this_arg_conv->update_channel)(this_arg_conv->this_arg, funding_txo_conv, update_conv);
1714         return (long)ret_conv;
1715 }
1716
1717 uint32_tArray  __attribute__((visibility("default"))) TS_Watch_release_pending_monitor_events(uint32_t this_arg) {
1718         LDKWatch* this_arg_conv = (LDKWatch*)this_arg;
1719         LDKCVec_MonitorEventZ ret_var = (this_arg_conv->release_pending_monitor_events)(this_arg_conv->this_arg);
1720         uint32_tArray ret_arr = init_arr(ret_var.datalen, sizeof(uint32_t), "Native uint32_tArray Bytes");
1721         uint32_t *ret_arr_ptr = (uint32_t*)(ret_arr + 4);
1722         for (size_t o = 0; o < ret_var.datalen; o++) {
1723                 LDKMonitorEvent arr_conv_14_var = ret_var.data[o];
1724                 CHECK((((long)arr_conv_14_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1725                 CHECK((((long)&arr_conv_14_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1726                 long arr_conv_14_ref = (long)arr_conv_14_var.inner;
1727                 if (arr_conv_14_var.is_owned) {
1728                         arr_conv_14_ref |= 1;
1729                 }
1730                 ret_arr_ptr[o] = arr_conv_14_ref;
1731         }
1732         FREE(ret_var.data);
1733         return ret_arr;
1734 }
1735
1736 typedef struct LDKBroadcasterInterface_JCalls {
1737         atomic_size_t refcnt;
1738         uint32_t broadcast_transaction_meth;
1739 } LDKBroadcasterInterface_JCalls;
1740 static void LDKBroadcasterInterface_JCalls_free(void* this_arg) {
1741         LDKBroadcasterInterface_JCalls *j_calls = (LDKBroadcasterInterface_JCalls*) this_arg;
1742         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
1743                 js_free(j_calls->broadcast_transaction_meth);
1744                 FREE(j_calls);
1745         }
1746 }
1747 void broadcast_transaction_jcall(const void* this_arg, LDKTransaction tx) {
1748         LDKBroadcasterInterface_JCalls *j_calls = (LDKBroadcasterInterface_JCalls*) this_arg;
1749         LDKTransaction tx_var = tx;
1750         int8_tArray tx_arr = init_arr(tx_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
1751         memcpy((uint8_t*)(tx_arr + 4), tx_var.data, tx_var.datalen);
1752         Transaction_free(tx_var);
1753         js_invoke_function_1(j_calls->broadcast_transaction_meth, tx_arr);
1754 }
1755 static void* LDKBroadcasterInterface_JCalls_clone(const void* this_arg) {
1756         LDKBroadcasterInterface_JCalls *j_calls = (LDKBroadcasterInterface_JCalls*) this_arg;
1757         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
1758         return (void*) this_arg;
1759 }
1760 static inline LDKBroadcasterInterface LDKBroadcasterInterface_init (/*TODO: JS Object Reference */void* o) {
1761         LDKBroadcasterInterface_JCalls *calls = MALLOC(sizeof(LDKBroadcasterInterface_JCalls), "LDKBroadcasterInterface_JCalls");
1762         atomic_init(&calls->refcnt, 1);
1763         //TODO: Assign calls->o from o
1764
1765         LDKBroadcasterInterface ret = {
1766                 .this_arg = (void*) calls,
1767                 .broadcast_transaction = broadcast_transaction_jcall,
1768                 .free = LDKBroadcasterInterface_JCalls_free,
1769         };
1770         return ret;
1771 }
1772 long  __attribute__((visibility("default"))) TS_LDKBroadcasterInterface_new(/*TODO: JS Object Reference */void* o) {
1773         LDKBroadcasterInterface *res_ptr = MALLOC(sizeof(LDKBroadcasterInterface), "LDKBroadcasterInterface");
1774         *res_ptr = LDKBroadcasterInterface_init(o);
1775         return (long)res_ptr;
1776 }
1777 void  __attribute__((visibility("default"))) TS_BroadcasterInterface_broadcast_transaction(uint32_t this_arg, int8_tArray tx) {
1778         LDKBroadcasterInterface* this_arg_conv = (LDKBroadcasterInterface*)this_arg;
1779         LDKTransaction tx_ref;
1780         tx_ref.datalen = *((uint32_t*)tx);
1781         tx_ref.data = MALLOC(tx_ref.datalen, "LDKTransaction Bytes");
1782         memcpy(tx_ref.data, (uint8_t*)(tx + 4), tx_ref.datalen);
1783         tx_ref.data_is_owned = true;
1784         (this_arg_conv->broadcast_transaction)(this_arg_conv->this_arg, tx_ref);
1785 }
1786
1787 typedef struct LDKKeysInterface_JCalls {
1788         atomic_size_t refcnt;
1789         uint32_t get_node_secret_meth;
1790         uint32_t get_destination_script_meth;
1791         uint32_t get_shutdown_pubkey_meth;
1792         uint32_t get_channel_keys_meth;
1793         uint32_t get_secure_random_bytes_meth;
1794         uint32_t read_chan_signer_meth;
1795 } LDKKeysInterface_JCalls;
1796 static void LDKKeysInterface_JCalls_free(void* this_arg) {
1797         LDKKeysInterface_JCalls *j_calls = (LDKKeysInterface_JCalls*) this_arg;
1798         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
1799                 js_free(j_calls->get_node_secret_meth);
1800                 js_free(j_calls->get_destination_script_meth);
1801                 js_free(j_calls->get_shutdown_pubkey_meth);
1802                 js_free(j_calls->get_channel_keys_meth);
1803                 js_free(j_calls->get_secure_random_bytes_meth);
1804                 js_free(j_calls->read_chan_signer_meth);
1805                 FREE(j_calls);
1806         }
1807 }
1808 LDKSecretKey get_node_secret_jcall(const void* this_arg) {
1809         LDKKeysInterface_JCalls *j_calls = (LDKKeysInterface_JCalls*) this_arg;
1810         int8_tArray arg = js_invoke_function_0(j_calls->get_node_secret_meth);
1811         LDKSecretKey arg_ref;
1812         CHECK(*((uint32_t*)arg) == 32);
1813         memcpy(arg_ref.bytes, (uint8_t*)(arg + 4), 32);
1814         return arg_ref;
1815 }
1816 LDKCVec_u8Z get_destination_script_jcall(const void* this_arg) {
1817         LDKKeysInterface_JCalls *j_calls = (LDKKeysInterface_JCalls*) this_arg;
1818         int8_tArray arg = js_invoke_function_0(j_calls->get_destination_script_meth);
1819         LDKCVec_u8Z arg_ref;
1820         arg_ref.datalen = *((uint32_t*)arg);
1821         arg_ref.data = MALLOC(arg_ref.datalen, "LDKCVec_u8Z Bytes");
1822         memcpy(arg_ref.data, (uint8_t*)(arg + 4), arg_ref.datalen);
1823         return arg_ref;
1824 }
1825 LDKPublicKey get_shutdown_pubkey_jcall(const void* this_arg) {
1826         LDKKeysInterface_JCalls *j_calls = (LDKKeysInterface_JCalls*) this_arg;
1827         int8_tArray arg = js_invoke_function_0(j_calls->get_shutdown_pubkey_meth);
1828         LDKPublicKey arg_ref;
1829         CHECK(*((uint32_t*)arg) == 33);
1830         memcpy(arg_ref.compressed_form, (uint8_t*)(arg + 4), 33);
1831         return arg_ref;
1832 }
1833 LDKChannelKeys get_channel_keys_jcall(const void* this_arg, bool inbound, uint64_t channel_value_satoshis) {
1834         LDKKeysInterface_JCalls *j_calls = (LDKKeysInterface_JCalls*) this_arg;
1835         LDKChannelKeys* ret = (LDKChannelKeys*)js_invoke_function_2(j_calls->get_channel_keys_meth, inbound, channel_value_satoshis);
1836         LDKChannelKeys ret_conv = *(LDKChannelKeys*)(((uint64_t)ret) & ~1);
1837         ret_conv = ChannelKeys_clone(ret);
1838         return ret_conv;
1839 }
1840 LDKThirtyTwoBytes get_secure_random_bytes_jcall(const void* this_arg) {
1841         LDKKeysInterface_JCalls *j_calls = (LDKKeysInterface_JCalls*) this_arg;
1842         int8_tArray arg = js_invoke_function_0(j_calls->get_secure_random_bytes_meth);
1843         LDKThirtyTwoBytes arg_ref;
1844         CHECK(*((uint32_t*)arg) == 32);
1845         memcpy(arg_ref.data, (uint8_t*)(arg + 4), 32);
1846         return arg_ref;
1847 }
1848 LDKCResult_ChanKeySignerDecodeErrorZ read_chan_signer_jcall(const void* this_arg, LDKu8slice reader) {
1849         LDKKeysInterface_JCalls *j_calls = (LDKKeysInterface_JCalls*) this_arg;
1850         LDKu8slice reader_var = reader;
1851         int8_tArray reader_arr = init_arr(reader_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
1852         memcpy((uint8_t*)(reader_arr + 4), reader_var.data, reader_var.datalen);
1853         LDKCResult_ChanKeySignerDecodeErrorZ* ret = (LDKCResult_ChanKeySignerDecodeErrorZ*)js_invoke_function_1(j_calls->read_chan_signer_meth, reader_arr);
1854         LDKCResult_ChanKeySignerDecodeErrorZ ret_conv = *(LDKCResult_ChanKeySignerDecodeErrorZ*)(((uint64_t)ret) & ~1);
1855         ret_conv = CResult_ChanKeySignerDecodeErrorZ_clone((LDKCResult_ChanKeySignerDecodeErrorZ*)ret);
1856         return ret_conv;
1857 }
1858 static void* LDKKeysInterface_JCalls_clone(const void* this_arg) {
1859         LDKKeysInterface_JCalls *j_calls = (LDKKeysInterface_JCalls*) this_arg;
1860         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
1861         return (void*) this_arg;
1862 }
1863 static inline LDKKeysInterface LDKKeysInterface_init (/*TODO: JS Object Reference */void* o) {
1864         LDKKeysInterface_JCalls *calls = MALLOC(sizeof(LDKKeysInterface_JCalls), "LDKKeysInterface_JCalls");
1865         atomic_init(&calls->refcnt, 1);
1866         //TODO: Assign calls->o from o
1867
1868         LDKKeysInterface ret = {
1869                 .this_arg = (void*) calls,
1870                 .get_node_secret = get_node_secret_jcall,
1871                 .get_destination_script = get_destination_script_jcall,
1872                 .get_shutdown_pubkey = get_shutdown_pubkey_jcall,
1873                 .get_channel_keys = get_channel_keys_jcall,
1874                 .get_secure_random_bytes = get_secure_random_bytes_jcall,
1875                 .read_chan_signer = read_chan_signer_jcall,
1876                 .free = LDKKeysInterface_JCalls_free,
1877         };
1878         return ret;
1879 }
1880 long  __attribute__((visibility("default"))) TS_LDKKeysInterface_new(/*TODO: JS Object Reference */void* o) {
1881         LDKKeysInterface *res_ptr = MALLOC(sizeof(LDKKeysInterface), "LDKKeysInterface");
1882         *res_ptr = LDKKeysInterface_init(o);
1883         return (long)res_ptr;
1884 }
1885 int8_tArray  __attribute__((visibility("default"))) TS_KeysInterface_get_node_secret(uint32_t this_arg) {
1886         LDKKeysInterface* this_arg_conv = (LDKKeysInterface*)this_arg;
1887         int8_tArray arg_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
1888         memcpy((uint8_t*)(arg_arr + 4), (this_arg_conv->get_node_secret)(this_arg_conv->this_arg).bytes, 32);
1889         return arg_arr;
1890 }
1891
1892 int8_tArray  __attribute__((visibility("default"))) TS_KeysInterface_get_destination_script(uint32_t this_arg) {
1893         LDKKeysInterface* this_arg_conv = (LDKKeysInterface*)this_arg;
1894         LDKCVec_u8Z arg_var = (this_arg_conv->get_destination_script)(this_arg_conv->this_arg);
1895         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
1896         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
1897         CVec_u8Z_free(arg_var);
1898         return arg_arr;
1899 }
1900
1901 int8_tArray  __attribute__((visibility("default"))) TS_KeysInterface_get_shutdown_pubkey(uint32_t this_arg) {
1902         LDKKeysInterface* this_arg_conv = (LDKKeysInterface*)this_arg;
1903         int8_tArray arg_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
1904         memcpy((uint8_t*)(arg_arr + 4), (this_arg_conv->get_shutdown_pubkey)(this_arg_conv->this_arg).compressed_form, 33);
1905         return arg_arr;
1906 }
1907
1908 uint32_t  __attribute__((visibility("default"))) TS_KeysInterface_get_channel_keys(uint32_t this_arg, jboolean inbound, int64_t channel_value_satoshis) {
1909         LDKKeysInterface* this_arg_conv = (LDKKeysInterface*)this_arg;
1910         LDKChannelKeys* ret = MALLOC(sizeof(LDKChannelKeys), "LDKChannelKeys");
1911         *ret = (this_arg_conv->get_channel_keys)(this_arg_conv->this_arg, inbound, channel_value_satoshis);
1912         return (long)ret;
1913 }
1914
1915 int8_tArray  __attribute__((visibility("default"))) TS_KeysInterface_get_secure_random_bytes(uint32_t this_arg) {
1916         LDKKeysInterface* this_arg_conv = (LDKKeysInterface*)this_arg;
1917         int8_tArray arg_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
1918         memcpy((uint8_t*)(arg_arr + 4), (this_arg_conv->get_secure_random_bytes)(this_arg_conv->this_arg).data, 32);
1919         return arg_arr;
1920 }
1921
1922 uint32_t  __attribute__((visibility("default"))) TS_KeysInterface_read_chan_signer(uint32_t this_arg, int8_tArray reader) {
1923         LDKKeysInterface* this_arg_conv = (LDKKeysInterface*)this_arg;
1924         LDKu8slice reader_ref;
1925         reader_ref.datalen = *((uint32_t*)reader);
1926         reader_ref.data = (int8_t*)(reader + 4);
1927         LDKCResult_ChanKeySignerDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ChanKeySignerDecodeErrorZ), "LDKCResult_ChanKeySignerDecodeErrorZ");
1928         *ret_conv = (this_arg_conv->read_chan_signer)(this_arg_conv->this_arg, reader_ref);
1929         return (long)ret_conv;
1930 }
1931
1932 typedef struct LDKFeeEstimator_JCalls {
1933         atomic_size_t refcnt;
1934         uint32_t get_est_sat_per_1000_weight_meth;
1935 } LDKFeeEstimator_JCalls;
1936 static void LDKFeeEstimator_JCalls_free(void* this_arg) {
1937         LDKFeeEstimator_JCalls *j_calls = (LDKFeeEstimator_JCalls*) this_arg;
1938         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
1939                 js_free(j_calls->get_est_sat_per_1000_weight_meth);
1940                 FREE(j_calls);
1941         }
1942 }
1943 uint32_t get_est_sat_per_1000_weight_jcall(const void* this_arg, LDKConfirmationTarget confirmation_target) {
1944         LDKFeeEstimator_JCalls *j_calls = (LDKFeeEstimator_JCalls*) this_arg;
1945         uint32_t confirmation_target_conv = LDKConfirmationTarget_to_js(confirmation_target);
1946         return js_invoke_function_1(j_calls->get_est_sat_per_1000_weight_meth, confirmation_target_conv);
1947 }
1948 static void* LDKFeeEstimator_JCalls_clone(const void* this_arg) {
1949         LDKFeeEstimator_JCalls *j_calls = (LDKFeeEstimator_JCalls*) this_arg;
1950         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
1951         return (void*) this_arg;
1952 }
1953 static inline LDKFeeEstimator LDKFeeEstimator_init (/*TODO: JS Object Reference */void* o) {
1954         LDKFeeEstimator_JCalls *calls = MALLOC(sizeof(LDKFeeEstimator_JCalls), "LDKFeeEstimator_JCalls");
1955         atomic_init(&calls->refcnt, 1);
1956         //TODO: Assign calls->o from o
1957
1958         LDKFeeEstimator ret = {
1959                 .this_arg = (void*) calls,
1960                 .get_est_sat_per_1000_weight = get_est_sat_per_1000_weight_jcall,
1961                 .free = LDKFeeEstimator_JCalls_free,
1962         };
1963         return ret;
1964 }
1965 long  __attribute__((visibility("default"))) TS_LDKFeeEstimator_new(/*TODO: JS Object Reference */void* o) {
1966         LDKFeeEstimator *res_ptr = MALLOC(sizeof(LDKFeeEstimator), "LDKFeeEstimator");
1967         *res_ptr = LDKFeeEstimator_init(o);
1968         return (long)res_ptr;
1969 }
1970 int32_t  __attribute__((visibility("default"))) TS_FeeEstimator_get_est_sat_per_1000_weight(uint32_t this_arg, uint32_t confirmation_target) {
1971         LDKFeeEstimator* this_arg_conv = (LDKFeeEstimator*)this_arg;
1972         LDKConfirmationTarget confirmation_target_conv = LDKConfirmationTarget_from_js(confirmation_target);
1973         int32_t ret_val = (this_arg_conv->get_est_sat_per_1000_weight)(this_arg_conv->this_arg, confirmation_target_conv);
1974         return ret_val;
1975 }
1976
1977 typedef struct LDKLogger_JCalls {
1978         atomic_size_t refcnt;
1979         uint32_t log_meth;
1980 } LDKLogger_JCalls;
1981 static void LDKLogger_JCalls_free(void* this_arg) {
1982         LDKLogger_JCalls *j_calls = (LDKLogger_JCalls*) this_arg;
1983         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
1984                 js_free(j_calls->log_meth);
1985                 FREE(j_calls);
1986         }
1987 }
1988 void log_jcall(const void* this_arg, const char* record) {
1989         LDKLogger_JCalls *j_calls = (LDKLogger_JCalls*) this_arg;
1990         const char* record_str = record;
1991         jstring record_conv = str_ref_to_ts(record_str, strlen(record_str));
1992         js_invoke_function_1(j_calls->log_meth, record_conv);
1993 }
1994 static void* LDKLogger_JCalls_clone(const void* this_arg) {
1995         LDKLogger_JCalls *j_calls = (LDKLogger_JCalls*) this_arg;
1996         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
1997         return (void*) this_arg;
1998 }
1999 static inline LDKLogger LDKLogger_init (/*TODO: JS Object Reference */void* o) {
2000         LDKLogger_JCalls *calls = MALLOC(sizeof(LDKLogger_JCalls), "LDKLogger_JCalls");
2001         atomic_init(&calls->refcnt, 1);
2002         //TODO: Assign calls->o from o
2003
2004         LDKLogger ret = {
2005                 .this_arg = (void*) calls,
2006                 .log = log_jcall,
2007                 .free = LDKLogger_JCalls_free,
2008         };
2009         return ret;
2010 }
2011 long  __attribute__((visibility("default"))) TS_LDKLogger_new(/*TODO: JS Object Reference */void* o) {
2012         LDKLogger *res_ptr = MALLOC(sizeof(LDKLogger), "LDKLogger");
2013         *res_ptr = LDKLogger_init(o);
2014         return (long)res_ptr;
2015 }
2016 uint32_t  __attribute__((visibility("default"))) TS_LDKC2Tuple_BlockHashChannelManagerZ_new(int8_tArray a, uint32_t b) {
2017         LDKC2Tuple_BlockHashChannelManagerZ* ret = MALLOC(sizeof(LDKC2Tuple_BlockHashChannelManagerZ), "LDKC2Tuple_BlockHashChannelManagerZ");
2018         LDKThirtyTwoBytes a_ref;
2019         CHECK(*((uint32_t*)a) == 32);
2020         memcpy(a_ref.data, (uint8_t*)(a + 4), 32);
2021         ret->a = a_ref;
2022         LDKChannelManager b_conv;
2023         b_conv.inner = (void*)(b & (~1));
2024         b_conv.is_owned = (b & 1) || (b == 0);
2025         // Warning: we need a move here but no clone is available for LDKChannelManager
2026         ret->b = b_conv;
2027         return (long)ret;
2028 }
2029 int8_tArray  __attribute__((visibility("default"))) TS_LDKC2Tuple_BlockHashChannelManagerZ_get_a(uint32_t ptr) {
2030         LDKC2Tuple_BlockHashChannelManagerZ *tuple = (LDKC2Tuple_BlockHashChannelManagerZ*)(ptr & ~1);
2031         int8_tArray a_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
2032         memcpy((uint8_t*)(a_arr + 4), tuple->a.data, 32);
2033         return a_arr;
2034 }
2035 uint32_t  __attribute__((visibility("default"))) TS_LDKC2Tuple_BlockHashChannelManagerZ_get_b(uint32_t ptr) {
2036         LDKC2Tuple_BlockHashChannelManagerZ *tuple = (LDKC2Tuple_BlockHashChannelManagerZ*)(ptr & ~1);
2037         LDKChannelManager b_var = tuple->b;
2038         CHECK((((long)b_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2039         CHECK((((long)&b_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2040         long b_ref = (long)b_var.inner & ~1;
2041         return b_ref;
2042 }
2043 jboolean  __attribute__((visibility("default"))) TS_LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ_result_ok(uint32_t arg) {
2044         return ((LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ*)arg)->result_ok;
2045 }
2046 uint32_t  __attribute__((visibility("default"))) TS_LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ_get_ok(uint32_t arg) {
2047         LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ *val = (LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ*)(arg & ~1);
2048         CHECK(val->result_ok);
2049         long res_ref = (long)(&(*val->contents.result)) | 1;
2050         return res_ref;
2051 }
2052 uint32_t  __attribute__((visibility("default"))) TS_LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ_get_err(uint32_t arg) {
2053         LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ *val = (LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ*)(arg & ~1);
2054         CHECK(!val->result_ok);
2055         LDKDecodeError err_var = (*val->contents.err);
2056         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2057         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2058         long err_ref = (long)err_var.inner & ~1;
2059         return err_ref;
2060 }
2061 jboolean  __attribute__((visibility("default"))) TS_LDKCResult_NetAddressu8Z_result_ok(uint32_t arg) {
2062         return ((LDKCResult_NetAddressu8Z*)arg)->result_ok;
2063 }
2064 uint32_t  __attribute__((visibility("default"))) TS_LDKCResult_NetAddressu8Z_get_ok(uint32_t arg) {
2065         LDKCResult_NetAddressu8Z *val = (LDKCResult_NetAddressu8Z*)(arg & ~1);
2066         CHECK(val->result_ok);
2067         long res_ref = ((long)&(*val->contents.result)) | 1;
2068         return res_ref;
2069 }
2070 int8_t  __attribute__((visibility("default"))) TS_LDKCResult_NetAddressu8Z_get_err(uint32_t arg) {
2071         LDKCResult_NetAddressu8Z *val = (LDKCResult_NetAddressu8Z*)(arg & ~1);
2072         CHECK(!val->result_ok);
2073         return *val->contents.err;
2074 }
2075 jboolean  __attribute__((visibility("default"))) TS_LDKCResult_CResult_NetAddressu8ZDecodeErrorZ_result_ok(uint32_t arg) {
2076         return ((LDKCResult_CResult_NetAddressu8ZDecodeErrorZ*)arg)->result_ok;
2077 }
2078 uint32_t  __attribute__((visibility("default"))) TS_LDKCResult_CResult_NetAddressu8ZDecodeErrorZ_get_ok(uint32_t arg) {
2079         LDKCResult_CResult_NetAddressu8ZDecodeErrorZ *val = (LDKCResult_CResult_NetAddressu8ZDecodeErrorZ*)(arg & ~1);
2080         CHECK(val->result_ok);
2081         LDKCResult_NetAddressu8Z* res_conv = MALLOC(sizeof(LDKCResult_NetAddressu8Z), "LDKCResult_NetAddressu8Z");
2082         *res_conv = (*val->contents.result);
2083         *res_conv = CResult_NetAddressu8Z_clone(res_conv);
2084         return (long)res_conv;
2085 }
2086 uint32_t  __attribute__((visibility("default"))) TS_LDKCResult_CResult_NetAddressu8ZDecodeErrorZ_get_err(uint32_t arg) {
2087         LDKCResult_CResult_NetAddressu8ZDecodeErrorZ *val = (LDKCResult_CResult_NetAddressu8ZDecodeErrorZ*)(arg & ~1);
2088         CHECK(!val->result_ok);
2089         LDKDecodeError err_var = (*val->contents.err);
2090         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2091         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2092         long err_ref = (long)err_var.inner & ~1;
2093         return err_ref;
2094 }
2095 uint32_t  __attribute__((visibility("default"))) TS_LDKCVec_u64Z_new(int64_tArray elems) {
2096         LDKCVec_u64Z *ret = MALLOC(sizeof(LDKCVec_u64Z), "LDKCVec_u64Z");
2097         ret->datalen = *((uint32_t*)elems);
2098         if (ret->datalen == 0) {
2099                 ret->data = NULL;
2100         } else {
2101                 ret->data = MALLOC(sizeof(uint64_t) * ret->datalen, "LDKCVec_u64Z Data");
2102                 int64_t *java_elems = (int64_t*)(elems + 4);
2103                 for (size_t i = 0; i < ret->datalen; i++) {
2104                         ret->data[i] = java_elems[i];
2105                 }
2106         }
2107         return (long)ret;
2108 }
2109 static inline LDKCVec_u64Z CVec_u64Z_clone(const LDKCVec_u64Z *orig) {
2110         LDKCVec_u64Z ret = { .data = MALLOC(sizeof(int64_t) * orig->datalen, "LDKCVec_u64Z clone bytes"), .datalen = orig->datalen };
2111         memcpy(ret.data, orig->data, sizeof(int64_t) * ret.datalen);
2112         return ret;
2113 }
2114 uint32_t  __attribute__((visibility("default"))) TS_LDKCVec_UpdateAddHTLCZ_new(uint32_tArray elems) {
2115         LDKCVec_UpdateAddHTLCZ *ret = MALLOC(sizeof(LDKCVec_UpdateAddHTLCZ), "LDKCVec_UpdateAddHTLCZ");
2116         ret->datalen = *((uint32_t*)elems);
2117         if (ret->datalen == 0) {
2118                 ret->data = NULL;
2119         } else {
2120                 ret->data = MALLOC(sizeof(LDKUpdateAddHTLC) * ret->datalen, "LDKCVec_UpdateAddHTLCZ Data");
2121                 uint32_t *java_elems = (uint32_t*)(elems + 4);
2122                 for (size_t i = 0; i < ret->datalen; i++) {
2123                         uint32_t arr_elem = java_elems[i];
2124                         LDKUpdateAddHTLC arr_elem_conv;
2125                         arr_elem_conv.inner = (void*)(arr_elem & (~1));
2126                         arr_elem_conv.is_owned = (arr_elem & 1) || (arr_elem == 0);
2127                         arr_elem_conv = UpdateAddHTLC_clone(&arr_elem_conv);
2128                         ret->data[i] = arr_elem_conv;
2129                 }
2130         }
2131         return (long)ret;
2132 }
2133 static inline LDKCVec_UpdateAddHTLCZ CVec_UpdateAddHTLCZ_clone(const LDKCVec_UpdateAddHTLCZ *orig) {
2134         LDKCVec_UpdateAddHTLCZ ret = { .data = MALLOC(sizeof(LDKUpdateAddHTLC) * orig->datalen, "LDKCVec_UpdateAddHTLCZ clone bytes"), .datalen = orig->datalen };
2135         for (size_t i = 0; i < ret.datalen; i++) {
2136                 ret.data[i] = UpdateAddHTLC_clone(&orig->data[i]);
2137         }
2138         return ret;
2139 }
2140 uint32_t  __attribute__((visibility("default"))) TS_LDKCVec_UpdateFulfillHTLCZ_new(uint32_tArray elems) {
2141         LDKCVec_UpdateFulfillHTLCZ *ret = MALLOC(sizeof(LDKCVec_UpdateFulfillHTLCZ), "LDKCVec_UpdateFulfillHTLCZ");
2142         ret->datalen = *((uint32_t*)elems);
2143         if (ret->datalen == 0) {
2144                 ret->data = NULL;
2145         } else {
2146                 ret->data = MALLOC(sizeof(LDKUpdateFulfillHTLC) * ret->datalen, "LDKCVec_UpdateFulfillHTLCZ Data");
2147                 uint32_t *java_elems = (uint32_t*)(elems + 4);
2148                 for (size_t i = 0; i < ret->datalen; i++) {
2149                         uint32_t arr_elem = java_elems[i];
2150                         LDKUpdateFulfillHTLC arr_elem_conv;
2151                         arr_elem_conv.inner = (void*)(arr_elem & (~1));
2152                         arr_elem_conv.is_owned = (arr_elem & 1) || (arr_elem == 0);
2153                         arr_elem_conv = UpdateFulfillHTLC_clone(&arr_elem_conv);
2154                         ret->data[i] = arr_elem_conv;
2155                 }
2156         }
2157         return (long)ret;
2158 }
2159 static inline LDKCVec_UpdateFulfillHTLCZ CVec_UpdateFulfillHTLCZ_clone(const LDKCVec_UpdateFulfillHTLCZ *orig) {
2160         LDKCVec_UpdateFulfillHTLCZ ret = { .data = MALLOC(sizeof(LDKUpdateFulfillHTLC) * orig->datalen, "LDKCVec_UpdateFulfillHTLCZ clone bytes"), .datalen = orig->datalen };
2161         for (size_t i = 0; i < ret.datalen; i++) {
2162                 ret.data[i] = UpdateFulfillHTLC_clone(&orig->data[i]);
2163         }
2164         return ret;
2165 }
2166 uint32_t  __attribute__((visibility("default"))) TS_LDKCVec_UpdateFailHTLCZ_new(uint32_tArray elems) {
2167         LDKCVec_UpdateFailHTLCZ *ret = MALLOC(sizeof(LDKCVec_UpdateFailHTLCZ), "LDKCVec_UpdateFailHTLCZ");
2168         ret->datalen = *((uint32_t*)elems);
2169         if (ret->datalen == 0) {
2170                 ret->data = NULL;
2171         } else {
2172                 ret->data = MALLOC(sizeof(LDKUpdateFailHTLC) * ret->datalen, "LDKCVec_UpdateFailHTLCZ Data");
2173                 uint32_t *java_elems = (uint32_t*)(elems + 4);
2174                 for (size_t i = 0; i < ret->datalen; i++) {
2175                         uint32_t arr_elem = java_elems[i];
2176                         LDKUpdateFailHTLC arr_elem_conv;
2177                         arr_elem_conv.inner = (void*)(arr_elem & (~1));
2178                         arr_elem_conv.is_owned = (arr_elem & 1) || (arr_elem == 0);
2179                         arr_elem_conv = UpdateFailHTLC_clone(&arr_elem_conv);
2180                         ret->data[i] = arr_elem_conv;
2181                 }
2182         }
2183         return (long)ret;
2184 }
2185 static inline LDKCVec_UpdateFailHTLCZ CVec_UpdateFailHTLCZ_clone(const LDKCVec_UpdateFailHTLCZ *orig) {
2186         LDKCVec_UpdateFailHTLCZ ret = { .data = MALLOC(sizeof(LDKUpdateFailHTLC) * orig->datalen, "LDKCVec_UpdateFailHTLCZ clone bytes"), .datalen = orig->datalen };
2187         for (size_t i = 0; i < ret.datalen; i++) {
2188                 ret.data[i] = UpdateFailHTLC_clone(&orig->data[i]);
2189         }
2190         return ret;
2191 }
2192 uint32_t  __attribute__((visibility("default"))) TS_LDKCVec_UpdateFailMalformedHTLCZ_new(uint32_tArray elems) {
2193         LDKCVec_UpdateFailMalformedHTLCZ *ret = MALLOC(sizeof(LDKCVec_UpdateFailMalformedHTLCZ), "LDKCVec_UpdateFailMalformedHTLCZ");
2194         ret->datalen = *((uint32_t*)elems);
2195         if (ret->datalen == 0) {
2196                 ret->data = NULL;
2197         } else {
2198                 ret->data = MALLOC(sizeof(LDKUpdateFailMalformedHTLC) * ret->datalen, "LDKCVec_UpdateFailMalformedHTLCZ Data");
2199                 uint32_t *java_elems = (uint32_t*)(elems + 4);
2200                 for (size_t i = 0; i < ret->datalen; i++) {
2201                         uint32_t arr_elem = java_elems[i];
2202                         LDKUpdateFailMalformedHTLC arr_elem_conv;
2203                         arr_elem_conv.inner = (void*)(arr_elem & (~1));
2204                         arr_elem_conv.is_owned = (arr_elem & 1) || (arr_elem == 0);
2205                         arr_elem_conv = UpdateFailMalformedHTLC_clone(&arr_elem_conv);
2206                         ret->data[i] = arr_elem_conv;
2207                 }
2208         }
2209         return (long)ret;
2210 }
2211 static inline LDKCVec_UpdateFailMalformedHTLCZ CVec_UpdateFailMalformedHTLCZ_clone(const LDKCVec_UpdateFailMalformedHTLCZ *orig) {
2212         LDKCVec_UpdateFailMalformedHTLCZ ret = { .data = MALLOC(sizeof(LDKUpdateFailMalformedHTLC) * orig->datalen, "LDKCVec_UpdateFailMalformedHTLCZ clone bytes"), .datalen = orig->datalen };
2213         for (size_t i = 0; i < ret.datalen; i++) {
2214                 ret.data[i] = UpdateFailMalformedHTLC_clone(&orig->data[i]);
2215         }
2216         return ret;
2217 }
2218 jboolean  __attribute__((visibility("default"))) TS_LDKCResult_boolLightningErrorZ_result_ok(uint32_t arg) {
2219         return ((LDKCResult_boolLightningErrorZ*)arg)->result_ok;
2220 }
2221 jboolean  __attribute__((visibility("default"))) TS_LDKCResult_boolLightningErrorZ_get_ok(uint32_t arg) {
2222         LDKCResult_boolLightningErrorZ *val = (LDKCResult_boolLightningErrorZ*)(arg & ~1);
2223         CHECK(val->result_ok);
2224         return *val->contents.result;
2225 }
2226 uint32_t  __attribute__((visibility("default"))) TS_LDKCResult_boolLightningErrorZ_get_err(uint32_t arg) {
2227         LDKCResult_boolLightningErrorZ *val = (LDKCResult_boolLightningErrorZ*)(arg & ~1);
2228         CHECK(!val->result_ok);
2229         LDKLightningError err_var = (*val->contents.err);
2230         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2231         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2232         long err_ref = (long)err_var.inner & ~1;
2233         return err_ref;
2234 }
2235 uint32_t  __attribute__((visibility("default"))) TS_LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ_new(uint32_t a, uint32_t b, uint32_t c) {
2236         LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ* ret = MALLOC(sizeof(LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ), "LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ");
2237         LDKChannelAnnouncement a_conv;
2238         a_conv.inner = (void*)(a & (~1));
2239         a_conv.is_owned = (a & 1) || (a == 0);
2240         a_conv = ChannelAnnouncement_clone(&a_conv);
2241         ret->a = a_conv;
2242         LDKChannelUpdate b_conv;
2243         b_conv.inner = (void*)(b & (~1));
2244         b_conv.is_owned = (b & 1) || (b == 0);
2245         b_conv = ChannelUpdate_clone(&b_conv);
2246         ret->b = b_conv;
2247         LDKChannelUpdate c_conv;
2248         c_conv.inner = (void*)(c & (~1));
2249         c_conv.is_owned = (c & 1) || (c == 0);
2250         c_conv = ChannelUpdate_clone(&c_conv);
2251         ret->c = c_conv;
2252         return (long)ret;
2253 }
2254 uint32_t  __attribute__((visibility("default"))) TS_LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ_get_a(uint32_t ptr) {
2255         LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ *tuple = (LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ*)(ptr & ~1);
2256         LDKChannelAnnouncement a_var = tuple->a;
2257         CHECK((((long)a_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2258         CHECK((((long)&a_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2259         long a_ref = (long)a_var.inner & ~1;
2260         return a_ref;
2261 }
2262 uint32_t  __attribute__((visibility("default"))) TS_LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ_get_b(uint32_t ptr) {
2263         LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ *tuple = (LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ*)(ptr & ~1);
2264         LDKChannelUpdate b_var = tuple->b;
2265         CHECK((((long)b_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2266         CHECK((((long)&b_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2267         long b_ref = (long)b_var.inner & ~1;
2268         return b_ref;
2269 }
2270 uint32_t  __attribute__((visibility("default"))) TS_LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ_get_c(uint32_t ptr) {
2271         LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ *tuple = (LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ*)(ptr & ~1);
2272         LDKChannelUpdate c_var = tuple->c;
2273         CHECK((((long)c_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2274         CHECK((((long)&c_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2275         long c_ref = (long)c_var.inner & ~1;
2276         return c_ref;
2277 }
2278 uint32_t  __attribute__((visibility("default"))) TS_LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ_new(uint32_tArray elems) {
2279         LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ *ret = MALLOC(sizeof(LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ), "LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ");
2280         ret->datalen = *((uint32_t*)elems);
2281         if (ret->datalen == 0) {
2282                 ret->data = NULL;
2283         } else {
2284                 ret->data = MALLOC(sizeof(LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ) * ret->datalen, "LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ Data");
2285                 uint32_t *java_elems = (uint32_t*)(elems + 4);
2286                 for (size_t i = 0; i < ret->datalen; i++) {
2287                         uint32_t arr_elem = java_elems[i];
2288                         LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ arr_elem_conv = *(LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ*)(((uint64_t)arr_elem) & ~1);
2289                         FREE((void*)arr_elem);
2290                         ret->data[i] = arr_elem_conv;
2291                 }
2292         }
2293         return (long)ret;
2294 }
2295 uint32_t  __attribute__((visibility("default"))) TS_LDKCVec_NodeAnnouncementZ_new(uint32_tArray elems) {
2296         LDKCVec_NodeAnnouncementZ *ret = MALLOC(sizeof(LDKCVec_NodeAnnouncementZ), "LDKCVec_NodeAnnouncementZ");
2297         ret->datalen = *((uint32_t*)elems);
2298         if (ret->datalen == 0) {
2299                 ret->data = NULL;
2300         } else {
2301                 ret->data = MALLOC(sizeof(LDKNodeAnnouncement) * ret->datalen, "LDKCVec_NodeAnnouncementZ Data");
2302                 uint32_t *java_elems = (uint32_t*)(elems + 4);
2303                 for (size_t i = 0; i < ret->datalen; i++) {
2304                         uint32_t arr_elem = java_elems[i];
2305                         LDKNodeAnnouncement arr_elem_conv;
2306                         arr_elem_conv.inner = (void*)(arr_elem & (~1));
2307                         arr_elem_conv.is_owned = (arr_elem & 1) || (arr_elem == 0);
2308                         arr_elem_conv = NodeAnnouncement_clone(&arr_elem_conv);
2309                         ret->data[i] = arr_elem_conv;
2310                 }
2311         }
2312         return (long)ret;
2313 }
2314 static inline LDKCVec_NodeAnnouncementZ CVec_NodeAnnouncementZ_clone(const LDKCVec_NodeAnnouncementZ *orig) {
2315         LDKCVec_NodeAnnouncementZ ret = { .data = MALLOC(sizeof(LDKNodeAnnouncement) * orig->datalen, "LDKCVec_NodeAnnouncementZ clone bytes"), .datalen = orig->datalen };
2316         for (size_t i = 0; i < ret.datalen; i++) {
2317                 ret.data[i] = NodeAnnouncement_clone(&orig->data[i]);
2318         }
2319         return ret;
2320 }
2321 jboolean  __attribute__((visibility("default"))) TS_LDKCResult_NoneLightningErrorZ_result_ok(uint32_t arg) {
2322         return ((LDKCResult_NoneLightningErrorZ*)arg)->result_ok;
2323 }
2324 void  __attribute__((visibility("default"))) TS_LDKCResult_NoneLightningErrorZ_get_ok(uint32_t arg) {
2325         LDKCResult_NoneLightningErrorZ *val = (LDKCResult_NoneLightningErrorZ*)(arg & ~1);
2326         CHECK(val->result_ok);
2327         return *val->contents.result;
2328 }
2329 uint32_t  __attribute__((visibility("default"))) TS_LDKCResult_NoneLightningErrorZ_get_err(uint32_t arg) {
2330         LDKCResult_NoneLightningErrorZ *val = (LDKCResult_NoneLightningErrorZ*)(arg & ~1);
2331         CHECK(!val->result_ok);
2332         LDKLightningError err_var = (*val->contents.err);
2333         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2334         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2335         long err_ref = (long)err_var.inner & ~1;
2336         return err_ref;
2337 }
2338 jboolean  __attribute__((visibility("default"))) TS_LDKCResult_ChannelReestablishDecodeErrorZ_result_ok(uint32_t arg) {
2339         return ((LDKCResult_ChannelReestablishDecodeErrorZ*)arg)->result_ok;
2340 }
2341 uint32_t  __attribute__((visibility("default"))) TS_LDKCResult_ChannelReestablishDecodeErrorZ_get_ok(uint32_t arg) {
2342         LDKCResult_ChannelReestablishDecodeErrorZ *val = (LDKCResult_ChannelReestablishDecodeErrorZ*)(arg & ~1);
2343         CHECK(val->result_ok);
2344         LDKChannelReestablish res_var = (*val->contents.result);
2345         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2346         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2347         long res_ref = (long)res_var.inner & ~1;
2348         return res_ref;
2349 }
2350 uint32_t  __attribute__((visibility("default"))) TS_LDKCResult_ChannelReestablishDecodeErrorZ_get_err(uint32_t arg) {
2351         LDKCResult_ChannelReestablishDecodeErrorZ *val = (LDKCResult_ChannelReestablishDecodeErrorZ*)(arg & ~1);
2352         CHECK(!val->result_ok);
2353         LDKDecodeError err_var = (*val->contents.err);
2354         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2355         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2356         long err_ref = (long)err_var.inner & ~1;
2357         return err_ref;
2358 }
2359 jboolean  __attribute__((visibility("default"))) TS_LDKCResult_InitDecodeErrorZ_result_ok(uint32_t arg) {
2360         return ((LDKCResult_InitDecodeErrorZ*)arg)->result_ok;
2361 }
2362 uint32_t  __attribute__((visibility("default"))) TS_LDKCResult_InitDecodeErrorZ_get_ok(uint32_t arg) {
2363         LDKCResult_InitDecodeErrorZ *val = (LDKCResult_InitDecodeErrorZ*)(arg & ~1);
2364         CHECK(val->result_ok);
2365         LDKInit res_var = (*val->contents.result);
2366         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2367         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2368         long res_ref = (long)res_var.inner & ~1;
2369         return res_ref;
2370 }
2371 uint32_t  __attribute__((visibility("default"))) TS_LDKCResult_InitDecodeErrorZ_get_err(uint32_t arg) {
2372         LDKCResult_InitDecodeErrorZ *val = (LDKCResult_InitDecodeErrorZ*)(arg & ~1);
2373         CHECK(!val->result_ok);
2374         LDKDecodeError err_var = (*val->contents.err);
2375         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2376         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2377         long err_ref = (long)err_var.inner & ~1;
2378         return err_ref;
2379 }
2380 jboolean  __attribute__((visibility("default"))) TS_LDKCResult_PingDecodeErrorZ_result_ok(uint32_t arg) {
2381         return ((LDKCResult_PingDecodeErrorZ*)arg)->result_ok;
2382 }
2383 uint32_t  __attribute__((visibility("default"))) TS_LDKCResult_PingDecodeErrorZ_get_ok(uint32_t arg) {
2384         LDKCResult_PingDecodeErrorZ *val = (LDKCResult_PingDecodeErrorZ*)(arg & ~1);
2385         CHECK(val->result_ok);
2386         LDKPing res_var = (*val->contents.result);
2387         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2388         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2389         long res_ref = (long)res_var.inner & ~1;
2390         return res_ref;
2391 }
2392 uint32_t  __attribute__((visibility("default"))) TS_LDKCResult_PingDecodeErrorZ_get_err(uint32_t arg) {
2393         LDKCResult_PingDecodeErrorZ *val = (LDKCResult_PingDecodeErrorZ*)(arg & ~1);
2394         CHECK(!val->result_ok);
2395         LDKDecodeError err_var = (*val->contents.err);
2396         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2397         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2398         long err_ref = (long)err_var.inner & ~1;
2399         return err_ref;
2400 }
2401 jboolean  __attribute__((visibility("default"))) TS_LDKCResult_PongDecodeErrorZ_result_ok(uint32_t arg) {
2402         return ((LDKCResult_PongDecodeErrorZ*)arg)->result_ok;
2403 }
2404 uint32_t  __attribute__((visibility("default"))) TS_LDKCResult_PongDecodeErrorZ_get_ok(uint32_t arg) {
2405         LDKCResult_PongDecodeErrorZ *val = (LDKCResult_PongDecodeErrorZ*)(arg & ~1);
2406         CHECK(val->result_ok);
2407         LDKPong res_var = (*val->contents.result);
2408         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2409         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2410         long res_ref = (long)res_var.inner & ~1;
2411         return res_ref;
2412 }
2413 uint32_t  __attribute__((visibility("default"))) TS_LDKCResult_PongDecodeErrorZ_get_err(uint32_t arg) {
2414         LDKCResult_PongDecodeErrorZ *val = (LDKCResult_PongDecodeErrorZ*)(arg & ~1);
2415         CHECK(!val->result_ok);
2416         LDKDecodeError err_var = (*val->contents.err);
2417         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2418         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2419         long err_ref = (long)err_var.inner & ~1;
2420         return err_ref;
2421 }
2422 jboolean  __attribute__((visibility("default"))) TS_LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ_result_ok(uint32_t arg) {
2423         return ((LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ*)arg)->result_ok;
2424 }
2425 uint32_t  __attribute__((visibility("default"))) TS_LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ_get_ok(uint32_t arg) {
2426         LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ *val = (LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ*)(arg & ~1);
2427         CHECK(val->result_ok);
2428         LDKUnsignedChannelAnnouncement res_var = (*val->contents.result);
2429         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2430         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2431         long res_ref = (long)res_var.inner & ~1;
2432         return res_ref;
2433 }
2434 uint32_t  __attribute__((visibility("default"))) TS_LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ_get_err(uint32_t arg) {
2435         LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ *val = (LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ*)(arg & ~1);
2436         CHECK(!val->result_ok);
2437         LDKDecodeError err_var = (*val->contents.err);
2438         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2439         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2440         long err_ref = (long)err_var.inner & ~1;
2441         return err_ref;
2442 }
2443 jboolean  __attribute__((visibility("default"))) TS_LDKCResult_UnsignedChannelUpdateDecodeErrorZ_result_ok(uint32_t arg) {
2444         return ((LDKCResult_UnsignedChannelUpdateDecodeErrorZ*)arg)->result_ok;
2445 }
2446 uint32_t  __attribute__((visibility("default"))) TS_LDKCResult_UnsignedChannelUpdateDecodeErrorZ_get_ok(uint32_t arg) {
2447         LDKCResult_UnsignedChannelUpdateDecodeErrorZ *val = (LDKCResult_UnsignedChannelUpdateDecodeErrorZ*)(arg & ~1);
2448         CHECK(val->result_ok);
2449         LDKUnsignedChannelUpdate res_var = (*val->contents.result);
2450         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2451         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2452         long res_ref = (long)res_var.inner & ~1;
2453         return res_ref;
2454 }
2455 uint32_t  __attribute__((visibility("default"))) TS_LDKCResult_UnsignedChannelUpdateDecodeErrorZ_get_err(uint32_t arg) {
2456         LDKCResult_UnsignedChannelUpdateDecodeErrorZ *val = (LDKCResult_UnsignedChannelUpdateDecodeErrorZ*)(arg & ~1);
2457         CHECK(!val->result_ok);
2458         LDKDecodeError err_var = (*val->contents.err);
2459         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2460         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2461         long err_ref = (long)err_var.inner & ~1;
2462         return err_ref;
2463 }
2464 jboolean  __attribute__((visibility("default"))) TS_LDKCResult_ErrorMessageDecodeErrorZ_result_ok(uint32_t arg) {
2465         return ((LDKCResult_ErrorMessageDecodeErrorZ*)arg)->result_ok;
2466 }
2467 uint32_t  __attribute__((visibility("default"))) TS_LDKCResult_ErrorMessageDecodeErrorZ_get_ok(uint32_t arg) {
2468         LDKCResult_ErrorMessageDecodeErrorZ *val = (LDKCResult_ErrorMessageDecodeErrorZ*)(arg & ~1);
2469         CHECK(val->result_ok);
2470         LDKErrorMessage res_var = (*val->contents.result);
2471         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2472         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2473         long res_ref = (long)res_var.inner & ~1;
2474         return res_ref;
2475 }
2476 uint32_t  __attribute__((visibility("default"))) TS_LDKCResult_ErrorMessageDecodeErrorZ_get_err(uint32_t arg) {
2477         LDKCResult_ErrorMessageDecodeErrorZ *val = (LDKCResult_ErrorMessageDecodeErrorZ*)(arg & ~1);
2478         CHECK(!val->result_ok);
2479         LDKDecodeError err_var = (*val->contents.err);
2480         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2481         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2482         long err_ref = (long)err_var.inner & ~1;
2483         return err_ref;
2484 }
2485 jboolean  __attribute__((visibility("default"))) TS_LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ_result_ok(uint32_t arg) {
2486         return ((LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ*)arg)->result_ok;
2487 }
2488 uint32_t  __attribute__((visibility("default"))) TS_LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ_get_ok(uint32_t arg) {
2489         LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ *val = (LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ*)(arg & ~1);
2490         CHECK(val->result_ok);
2491         LDKUnsignedNodeAnnouncement res_var = (*val->contents.result);
2492         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2493         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2494         long res_ref = (long)res_var.inner & ~1;
2495         return res_ref;
2496 }
2497 uint32_t  __attribute__((visibility("default"))) TS_LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ_get_err(uint32_t arg) {
2498         LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ *val = (LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ*)(arg & ~1);
2499         CHECK(!val->result_ok);
2500         LDKDecodeError err_var = (*val->contents.err);
2501         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2502         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2503         long err_ref = (long)err_var.inner & ~1;
2504         return err_ref;
2505 }
2506 jboolean  __attribute__((visibility("default"))) TS_LDKCResult_QueryShortChannelIdsDecodeErrorZ_result_ok(uint32_t arg) {
2507         return ((LDKCResult_QueryShortChannelIdsDecodeErrorZ*)arg)->result_ok;
2508 }
2509 uint32_t  __attribute__((visibility("default"))) TS_LDKCResult_QueryShortChannelIdsDecodeErrorZ_get_ok(uint32_t arg) {
2510         LDKCResult_QueryShortChannelIdsDecodeErrorZ *val = (LDKCResult_QueryShortChannelIdsDecodeErrorZ*)(arg & ~1);
2511         CHECK(val->result_ok);
2512         LDKQueryShortChannelIds res_var = (*val->contents.result);
2513         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2514         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2515         long res_ref = (long)res_var.inner & ~1;
2516         return res_ref;
2517 }
2518 uint32_t  __attribute__((visibility("default"))) TS_LDKCResult_QueryShortChannelIdsDecodeErrorZ_get_err(uint32_t arg) {
2519         LDKCResult_QueryShortChannelIdsDecodeErrorZ *val = (LDKCResult_QueryShortChannelIdsDecodeErrorZ*)(arg & ~1);
2520         CHECK(!val->result_ok);
2521         LDKDecodeError err_var = (*val->contents.err);
2522         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2523         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2524         long err_ref = (long)err_var.inner & ~1;
2525         return err_ref;
2526 }
2527 jboolean  __attribute__((visibility("default"))) TS_LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ_result_ok(uint32_t arg) {
2528         return ((LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ*)arg)->result_ok;
2529 }
2530 uint32_t  __attribute__((visibility("default"))) TS_LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ_get_ok(uint32_t arg) {
2531         LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ *val = (LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ*)(arg & ~1);
2532         CHECK(val->result_ok);
2533         LDKReplyShortChannelIdsEnd res_var = (*val->contents.result);
2534         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2535         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2536         long res_ref = (long)res_var.inner & ~1;
2537         return res_ref;
2538 }
2539 uint32_t  __attribute__((visibility("default"))) TS_LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ_get_err(uint32_t arg) {
2540         LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ *val = (LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ*)(arg & ~1);
2541         CHECK(!val->result_ok);
2542         LDKDecodeError err_var = (*val->contents.err);
2543         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2544         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2545         long err_ref = (long)err_var.inner & ~1;
2546         return err_ref;
2547 }
2548 jboolean  __attribute__((visibility("default"))) TS_LDKCResult_QueryChannelRangeDecodeErrorZ_result_ok(uint32_t arg) {
2549         return ((LDKCResult_QueryChannelRangeDecodeErrorZ*)arg)->result_ok;
2550 }
2551 uint32_t  __attribute__((visibility("default"))) TS_LDKCResult_QueryChannelRangeDecodeErrorZ_get_ok(uint32_t arg) {
2552         LDKCResult_QueryChannelRangeDecodeErrorZ *val = (LDKCResult_QueryChannelRangeDecodeErrorZ*)(arg & ~1);
2553         CHECK(val->result_ok);
2554         LDKQueryChannelRange res_var = (*val->contents.result);
2555         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2556         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2557         long res_ref = (long)res_var.inner & ~1;
2558         return res_ref;
2559 }
2560 uint32_t  __attribute__((visibility("default"))) TS_LDKCResult_QueryChannelRangeDecodeErrorZ_get_err(uint32_t arg) {
2561         LDKCResult_QueryChannelRangeDecodeErrorZ *val = (LDKCResult_QueryChannelRangeDecodeErrorZ*)(arg & ~1);
2562         CHECK(!val->result_ok);
2563         LDKDecodeError err_var = (*val->contents.err);
2564         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2565         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2566         long err_ref = (long)err_var.inner & ~1;
2567         return err_ref;
2568 }
2569 jboolean  __attribute__((visibility("default"))) TS_LDKCResult_ReplyChannelRangeDecodeErrorZ_result_ok(uint32_t arg) {
2570         return ((LDKCResult_ReplyChannelRangeDecodeErrorZ*)arg)->result_ok;
2571 }
2572 uint32_t  __attribute__((visibility("default"))) TS_LDKCResult_ReplyChannelRangeDecodeErrorZ_get_ok(uint32_t arg) {
2573         LDKCResult_ReplyChannelRangeDecodeErrorZ *val = (LDKCResult_ReplyChannelRangeDecodeErrorZ*)(arg & ~1);
2574         CHECK(val->result_ok);
2575         LDKReplyChannelRange res_var = (*val->contents.result);
2576         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2577         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2578         long res_ref = (long)res_var.inner & ~1;
2579         return res_ref;
2580 }
2581 uint32_t  __attribute__((visibility("default"))) TS_LDKCResult_ReplyChannelRangeDecodeErrorZ_get_err(uint32_t arg) {
2582         LDKCResult_ReplyChannelRangeDecodeErrorZ *val = (LDKCResult_ReplyChannelRangeDecodeErrorZ*)(arg & ~1);
2583         CHECK(!val->result_ok);
2584         LDKDecodeError err_var = (*val->contents.err);
2585         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2586         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2587         long err_ref = (long)err_var.inner & ~1;
2588         return err_ref;
2589 }
2590 jboolean  __attribute__((visibility("default"))) TS_LDKCResult_GossipTimestampFilterDecodeErrorZ_result_ok(uint32_t arg) {
2591         return ((LDKCResult_GossipTimestampFilterDecodeErrorZ*)arg)->result_ok;
2592 }
2593 uint32_t  __attribute__((visibility("default"))) TS_LDKCResult_GossipTimestampFilterDecodeErrorZ_get_ok(uint32_t arg) {
2594         LDKCResult_GossipTimestampFilterDecodeErrorZ *val = (LDKCResult_GossipTimestampFilterDecodeErrorZ*)(arg & ~1);
2595         CHECK(val->result_ok);
2596         LDKGossipTimestampFilter res_var = (*val->contents.result);
2597         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2598         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2599         long res_ref = (long)res_var.inner & ~1;
2600         return res_ref;
2601 }
2602 uint32_t  __attribute__((visibility("default"))) TS_LDKCResult_GossipTimestampFilterDecodeErrorZ_get_err(uint32_t arg) {
2603         LDKCResult_GossipTimestampFilterDecodeErrorZ *val = (LDKCResult_GossipTimestampFilterDecodeErrorZ*)(arg & ~1);
2604         CHECK(!val->result_ok);
2605         LDKDecodeError err_var = (*val->contents.err);
2606         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2607         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2608         long err_ref = (long)err_var.inner & ~1;
2609         return err_ref;
2610 }
2611 jboolean  __attribute__((visibility("default"))) TS_LDKCResult_CVec_u8ZPeerHandleErrorZ_result_ok(uint32_t arg) {
2612         return ((LDKCResult_CVec_u8ZPeerHandleErrorZ*)arg)->result_ok;
2613 }
2614 int8_tArray  __attribute__((visibility("default"))) TS_LDKCResult_CVec_u8ZPeerHandleErrorZ_get_ok(uint32_t arg) {
2615         LDKCResult_CVec_u8ZPeerHandleErrorZ *val = (LDKCResult_CVec_u8ZPeerHandleErrorZ*)(arg & ~1);
2616         CHECK(val->result_ok);
2617         LDKCVec_u8Z res_var = (*val->contents.result);
2618         int8_tArray res_arr = init_arr(res_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
2619         memcpy((uint8_t*)(res_arr + 4), res_var.data, res_var.datalen);
2620         return res_arr;
2621 }
2622 uint32_t  __attribute__((visibility("default"))) TS_LDKCResult_CVec_u8ZPeerHandleErrorZ_get_err(uint32_t arg) {
2623         LDKCResult_CVec_u8ZPeerHandleErrorZ *val = (LDKCResult_CVec_u8ZPeerHandleErrorZ*)(arg & ~1);
2624         CHECK(!val->result_ok);
2625         LDKPeerHandleError err_var = (*val->contents.err);
2626         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2627         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2628         long err_ref = (long)err_var.inner & ~1;
2629         return err_ref;
2630 }
2631 jboolean  __attribute__((visibility("default"))) TS_LDKCResult_NonePeerHandleErrorZ_result_ok(uint32_t arg) {
2632         return ((LDKCResult_NonePeerHandleErrorZ*)arg)->result_ok;
2633 }
2634 void  __attribute__((visibility("default"))) TS_LDKCResult_NonePeerHandleErrorZ_get_ok(uint32_t arg) {
2635         LDKCResult_NonePeerHandleErrorZ *val = (LDKCResult_NonePeerHandleErrorZ*)(arg & ~1);
2636         CHECK(val->result_ok);
2637         return *val->contents.result;
2638 }
2639 uint32_t  __attribute__((visibility("default"))) TS_LDKCResult_NonePeerHandleErrorZ_get_err(uint32_t arg) {
2640         LDKCResult_NonePeerHandleErrorZ *val = (LDKCResult_NonePeerHandleErrorZ*)(arg & ~1);
2641         CHECK(!val->result_ok);
2642         LDKPeerHandleError err_var = (*val->contents.err);
2643         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2644         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2645         long err_ref = (long)err_var.inner & ~1;
2646         return err_ref;
2647 }
2648 jboolean  __attribute__((visibility("default"))) TS_LDKCResult_boolPeerHandleErrorZ_result_ok(uint32_t arg) {
2649         return ((LDKCResult_boolPeerHandleErrorZ*)arg)->result_ok;
2650 }
2651 jboolean  __attribute__((visibility("default"))) TS_LDKCResult_boolPeerHandleErrorZ_get_ok(uint32_t arg) {
2652         LDKCResult_boolPeerHandleErrorZ *val = (LDKCResult_boolPeerHandleErrorZ*)(arg & ~1);
2653         CHECK(val->result_ok);
2654         return *val->contents.result;
2655 }
2656 uint32_t  __attribute__((visibility("default"))) TS_LDKCResult_boolPeerHandleErrorZ_get_err(uint32_t arg) {
2657         LDKCResult_boolPeerHandleErrorZ *val = (LDKCResult_boolPeerHandleErrorZ*)(arg & ~1);
2658         CHECK(!val->result_ok);
2659         LDKPeerHandleError err_var = (*val->contents.err);
2660         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2661         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2662         long err_ref = (long)err_var.inner & ~1;
2663         return err_ref;
2664 }
2665 jboolean  __attribute__((visibility("default"))) TS_LDKCResult_SecretKeySecpErrorZ_result_ok(uint32_t arg) {
2666         return ((LDKCResult_SecretKeySecpErrorZ*)arg)->result_ok;
2667 }
2668 int8_tArray  __attribute__((visibility("default"))) TS_LDKCResult_SecretKeySecpErrorZ_get_ok(uint32_t arg) {
2669         LDKCResult_SecretKeySecpErrorZ *val = (LDKCResult_SecretKeySecpErrorZ*)(arg & ~1);
2670         CHECK(val->result_ok);
2671         int8_tArray res_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
2672         memcpy((uint8_t*)(res_arr + 4), (*val->contents.result).bytes, 32);
2673         return res_arr;
2674 }
2675 uint32_t  __attribute__((visibility("default"))) TS_LDKCResult_SecretKeySecpErrorZ_get_err(uint32_t arg) {
2676         LDKCResult_SecretKeySecpErrorZ *val = (LDKCResult_SecretKeySecpErrorZ*)(arg & ~1);
2677         CHECK(!val->result_ok);
2678         uint32_t err_conv = LDKSecp256k1Error_to_js((*val->contents.err));
2679         return err_conv;
2680 }
2681 jboolean  __attribute__((visibility("default"))) TS_LDKCResult_PublicKeySecpErrorZ_result_ok(uint32_t arg) {
2682         return ((LDKCResult_PublicKeySecpErrorZ*)arg)->result_ok;
2683 }
2684 int8_tArray  __attribute__((visibility("default"))) TS_LDKCResult_PublicKeySecpErrorZ_get_ok(uint32_t arg) {
2685         LDKCResult_PublicKeySecpErrorZ *val = (LDKCResult_PublicKeySecpErrorZ*)(arg & ~1);
2686         CHECK(val->result_ok);
2687         int8_tArray res_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
2688         memcpy((uint8_t*)(res_arr + 4), (*val->contents.result).compressed_form, 33);
2689         return res_arr;
2690 }
2691 uint32_t  __attribute__((visibility("default"))) TS_LDKCResult_PublicKeySecpErrorZ_get_err(uint32_t arg) {
2692         LDKCResult_PublicKeySecpErrorZ *val = (LDKCResult_PublicKeySecpErrorZ*)(arg & ~1);
2693         CHECK(!val->result_ok);
2694         uint32_t err_conv = LDKSecp256k1Error_to_js((*val->contents.err));
2695         return err_conv;
2696 }
2697 jboolean  __attribute__((visibility("default"))) TS_LDKCResult_TxCreationKeysSecpErrorZ_result_ok(uint32_t arg) {
2698         return ((LDKCResult_TxCreationKeysSecpErrorZ*)arg)->result_ok;
2699 }
2700 uint32_t  __attribute__((visibility("default"))) TS_LDKCResult_TxCreationKeysSecpErrorZ_get_ok(uint32_t arg) {
2701         LDKCResult_TxCreationKeysSecpErrorZ *val = (LDKCResult_TxCreationKeysSecpErrorZ*)(arg & ~1);
2702         CHECK(val->result_ok);
2703         LDKTxCreationKeys res_var = (*val->contents.result);
2704         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2705         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2706         long res_ref = (long)res_var.inner & ~1;
2707         return res_ref;
2708 }
2709 uint32_t  __attribute__((visibility("default"))) TS_LDKCResult_TxCreationKeysSecpErrorZ_get_err(uint32_t arg) {
2710         LDKCResult_TxCreationKeysSecpErrorZ *val = (LDKCResult_TxCreationKeysSecpErrorZ*)(arg & ~1);
2711         CHECK(!val->result_ok);
2712         uint32_t err_conv = LDKSecp256k1Error_to_js((*val->contents.err));
2713         return err_conv;
2714 }
2715 jboolean  __attribute__((visibility("default"))) TS_LDKCResult_TrustedCommitmentTransactionNoneZ_result_ok(uint32_t arg) {
2716         return ((LDKCResult_TrustedCommitmentTransactionNoneZ*)arg)->result_ok;
2717 }
2718 uint32_t  __attribute__((visibility("default"))) TS_LDKCResult_TrustedCommitmentTransactionNoneZ_get_ok(uint32_t arg) {
2719         LDKCResult_TrustedCommitmentTransactionNoneZ *val = (LDKCResult_TrustedCommitmentTransactionNoneZ*)(arg & ~1);
2720         CHECK(val->result_ok);
2721         LDKTrustedCommitmentTransaction res_var = (*val->contents.result);
2722         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2723         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2724         long res_ref = (long)res_var.inner & ~1;
2725         return res_ref;
2726 }
2727 void  __attribute__((visibility("default"))) TS_LDKCResult_TrustedCommitmentTransactionNoneZ_get_err(uint32_t arg) {
2728         LDKCResult_TrustedCommitmentTransactionNoneZ *val = (LDKCResult_TrustedCommitmentTransactionNoneZ*)(arg & ~1);
2729         CHECK(!val->result_ok);
2730         return *val->contents.err;
2731 }
2732 jboolean  __attribute__((visibility("default"))) TS_LDKCResult_CVec_SignatureZNoneZ_result_ok(uint32_t arg) {
2733         return ((LDKCResult_CVec_SignatureZNoneZ*)arg)->result_ok;
2734 }
2735 ptrArray  __attribute__((visibility("default"))) TS_LDKCResult_CVec_SignatureZNoneZ_get_ok(uint32_t arg) {
2736         LDKCResult_CVec_SignatureZNoneZ *val = (LDKCResult_CVec_SignatureZNoneZ*)(arg & ~1);
2737         CHECK(val->result_ok);
2738         LDKCVec_SignatureZ res_var = (*val->contents.result);
2739         ptrArray res_arr = init_arr(res_var.datalen, sizeof(uint32_t), "Native ptrArray Bytes");
2740         int8_tArray *res_arr_ptr = (int8_tArray*)(res_arr + 4);
2741         for (size_t m = 0; m < res_var.datalen; m++) {
2742                 int8_tArray arr_conv_12_arr = init_arr(64, sizeof(uint8_t), "Native int8_tArray Bytes");
2743                 memcpy((uint8_t*)(arr_conv_12_arr + 4), res_var.data[m].compact_form, 64);
2744                 res_arr_ptr[m] = arr_conv_12_arr;
2745         }
2746         return res_arr;
2747 }
2748 void  __attribute__((visibility("default"))) TS_LDKCResult_CVec_SignatureZNoneZ_get_err(uint32_t arg) {
2749         LDKCResult_CVec_SignatureZNoneZ *val = (LDKCResult_CVec_SignatureZNoneZ*)(arg & ~1);
2750         CHECK(!val->result_ok);
2751         return *val->contents.err;
2752 }
2753 uint32_t  __attribute__((visibility("default"))) TS_LDKCVec_RouteHopZ_new(uint32_tArray elems) {
2754         LDKCVec_RouteHopZ *ret = MALLOC(sizeof(LDKCVec_RouteHopZ), "LDKCVec_RouteHopZ");
2755         ret->datalen = *((uint32_t*)elems);
2756         if (ret->datalen == 0) {
2757                 ret->data = NULL;
2758         } else {
2759                 ret->data = MALLOC(sizeof(LDKRouteHop) * ret->datalen, "LDKCVec_RouteHopZ Data");
2760                 uint32_t *java_elems = (uint32_t*)(elems + 4);
2761                 for (size_t i = 0; i < ret->datalen; i++) {
2762                         uint32_t arr_elem = java_elems[i];
2763                         LDKRouteHop arr_elem_conv;
2764                         arr_elem_conv.inner = (void*)(arr_elem & (~1));
2765                         arr_elem_conv.is_owned = (arr_elem & 1) || (arr_elem == 0);
2766                         arr_elem_conv = RouteHop_clone(&arr_elem_conv);
2767                         ret->data[i] = arr_elem_conv;
2768                 }
2769         }
2770         return (long)ret;
2771 }
2772 static inline LDKCVec_RouteHopZ CVec_RouteHopZ_clone(const LDKCVec_RouteHopZ *orig) {
2773         LDKCVec_RouteHopZ ret = { .data = MALLOC(sizeof(LDKRouteHop) * orig->datalen, "LDKCVec_RouteHopZ clone bytes"), .datalen = orig->datalen };
2774         for (size_t i = 0; i < ret.datalen; i++) {
2775                 ret.data[i] = RouteHop_clone(&orig->data[i]);
2776         }
2777         return ret;
2778 }
2779 static inline LDKCVec_CVec_RouteHopZZ CVec_CVec_RouteHopZZ_clone(const LDKCVec_CVec_RouteHopZZ *orig) {
2780         LDKCVec_CVec_RouteHopZZ ret = { .data = MALLOC(sizeof(LDKCVec_RouteHopZ) * orig->datalen, "LDKCVec_CVec_RouteHopZZ clone bytes"), .datalen = orig->datalen };
2781         for (size_t i = 0; i < ret.datalen; i++) {
2782                 ret.data[i] = CVec_RouteHopZ_clone(&orig->data[i]);
2783         }
2784         return ret;
2785 }
2786 jboolean  __attribute__((visibility("default"))) TS_LDKCResult_RouteDecodeErrorZ_result_ok(uint32_t arg) {
2787         return ((LDKCResult_RouteDecodeErrorZ*)arg)->result_ok;
2788 }
2789 uint32_t  __attribute__((visibility("default"))) TS_LDKCResult_RouteDecodeErrorZ_get_ok(uint32_t arg) {
2790         LDKCResult_RouteDecodeErrorZ *val = (LDKCResult_RouteDecodeErrorZ*)(arg & ~1);
2791         CHECK(val->result_ok);
2792         LDKRoute res_var = (*val->contents.result);
2793         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2794         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2795         long res_ref = (long)res_var.inner & ~1;
2796         return res_ref;
2797 }
2798 uint32_t  __attribute__((visibility("default"))) TS_LDKCResult_RouteDecodeErrorZ_get_err(uint32_t arg) {
2799         LDKCResult_RouteDecodeErrorZ *val = (LDKCResult_RouteDecodeErrorZ*)(arg & ~1);
2800         CHECK(!val->result_ok);
2801         LDKDecodeError err_var = (*val->contents.err);
2802         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2803         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2804         long err_ref = (long)err_var.inner & ~1;
2805         return err_ref;
2806 }
2807 uint32_t  __attribute__((visibility("default"))) TS_LDKCVec_RouteHintZ_new(uint32_tArray elems) {
2808         LDKCVec_RouteHintZ *ret = MALLOC(sizeof(LDKCVec_RouteHintZ), "LDKCVec_RouteHintZ");
2809         ret->datalen = *((uint32_t*)elems);
2810         if (ret->datalen == 0) {
2811                 ret->data = NULL;
2812         } else {
2813                 ret->data = MALLOC(sizeof(LDKRouteHint) * ret->datalen, "LDKCVec_RouteHintZ Data");
2814                 uint32_t *java_elems = (uint32_t*)(elems + 4);
2815                 for (size_t i = 0; i < ret->datalen; i++) {
2816                         uint32_t arr_elem = java_elems[i];
2817                         LDKRouteHint arr_elem_conv;
2818                         arr_elem_conv.inner = (void*)(arr_elem & (~1));
2819                         arr_elem_conv.is_owned = (arr_elem & 1) || (arr_elem == 0);
2820                         arr_elem_conv = RouteHint_clone(&arr_elem_conv);
2821                         ret->data[i] = arr_elem_conv;
2822                 }
2823         }
2824         return (long)ret;
2825 }
2826 static inline LDKCVec_RouteHintZ CVec_RouteHintZ_clone(const LDKCVec_RouteHintZ *orig) {
2827         LDKCVec_RouteHintZ ret = { .data = MALLOC(sizeof(LDKRouteHint) * orig->datalen, "LDKCVec_RouteHintZ clone bytes"), .datalen = orig->datalen };
2828         for (size_t i = 0; i < ret.datalen; i++) {
2829                 ret.data[i] = RouteHint_clone(&orig->data[i]);
2830         }
2831         return ret;
2832 }
2833 jboolean  __attribute__((visibility("default"))) TS_LDKCResult_RouteLightningErrorZ_result_ok(uint32_t arg) {
2834         return ((LDKCResult_RouteLightningErrorZ*)arg)->result_ok;
2835 }
2836 uint32_t  __attribute__((visibility("default"))) TS_LDKCResult_RouteLightningErrorZ_get_ok(uint32_t arg) {
2837         LDKCResult_RouteLightningErrorZ *val = (LDKCResult_RouteLightningErrorZ*)(arg & ~1);
2838         CHECK(val->result_ok);
2839         LDKRoute 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 uint32_t  __attribute__((visibility("default"))) TS_LDKCResult_RouteLightningErrorZ_get_err(uint32_t arg) {
2846         LDKCResult_RouteLightningErrorZ *val = (LDKCResult_RouteLightningErrorZ*)(arg & ~1);
2847         CHECK(!val->result_ok);
2848         LDKLightningError err_var = (*val->contents.err);
2849         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2850         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2851         long err_ref = (long)err_var.inner & ~1;
2852         return err_ref;
2853 }
2854 jboolean  __attribute__((visibility("default"))) TS_LDKCResult_RoutingFeesDecodeErrorZ_result_ok(uint32_t arg) {
2855         return ((LDKCResult_RoutingFeesDecodeErrorZ*)arg)->result_ok;
2856 }
2857 uint32_t  __attribute__((visibility("default"))) TS_LDKCResult_RoutingFeesDecodeErrorZ_get_ok(uint32_t arg) {
2858         LDKCResult_RoutingFeesDecodeErrorZ *val = (LDKCResult_RoutingFeesDecodeErrorZ*)(arg & ~1);
2859         CHECK(val->result_ok);
2860         LDKRoutingFees res_var = (*val->contents.result);
2861         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2862         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2863         long res_ref = (long)res_var.inner & ~1;
2864         return res_ref;
2865 }
2866 uint32_t  __attribute__((visibility("default"))) TS_LDKCResult_RoutingFeesDecodeErrorZ_get_err(uint32_t arg) {
2867         LDKCResult_RoutingFeesDecodeErrorZ *val = (LDKCResult_RoutingFeesDecodeErrorZ*)(arg & ~1);
2868         CHECK(!val->result_ok);
2869         LDKDecodeError err_var = (*val->contents.err);
2870         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2871         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2872         long err_ref = (long)err_var.inner & ~1;
2873         return err_ref;
2874 }
2875 jboolean  __attribute__((visibility("default"))) TS_LDKCResult_NodeAnnouncementInfoDecodeErrorZ_result_ok(uint32_t arg) {
2876         return ((LDKCResult_NodeAnnouncementInfoDecodeErrorZ*)arg)->result_ok;
2877 }
2878 uint32_t  __attribute__((visibility("default"))) TS_LDKCResult_NodeAnnouncementInfoDecodeErrorZ_get_ok(uint32_t arg) {
2879         LDKCResult_NodeAnnouncementInfoDecodeErrorZ *val = (LDKCResult_NodeAnnouncementInfoDecodeErrorZ*)(arg & ~1);
2880         CHECK(val->result_ok);
2881         LDKNodeAnnouncementInfo res_var = (*val->contents.result);
2882         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2883         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2884         long res_ref = (long)res_var.inner & ~1;
2885         return res_ref;
2886 }
2887 uint32_t  __attribute__((visibility("default"))) TS_LDKCResult_NodeAnnouncementInfoDecodeErrorZ_get_err(uint32_t arg) {
2888         LDKCResult_NodeAnnouncementInfoDecodeErrorZ *val = (LDKCResult_NodeAnnouncementInfoDecodeErrorZ*)(arg & ~1);
2889         CHECK(!val->result_ok);
2890         LDKDecodeError err_var = (*val->contents.err);
2891         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2892         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2893         long err_ref = (long)err_var.inner & ~1;
2894         return err_ref;
2895 }
2896 jboolean  __attribute__((visibility("default"))) TS_LDKCResult_NodeInfoDecodeErrorZ_result_ok(uint32_t arg) {
2897         return ((LDKCResult_NodeInfoDecodeErrorZ*)arg)->result_ok;
2898 }
2899 uint32_t  __attribute__((visibility("default"))) TS_LDKCResult_NodeInfoDecodeErrorZ_get_ok(uint32_t arg) {
2900         LDKCResult_NodeInfoDecodeErrorZ *val = (LDKCResult_NodeInfoDecodeErrorZ*)(arg & ~1);
2901         CHECK(val->result_ok);
2902         LDKNodeInfo res_var = (*val->contents.result);
2903         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2904         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2905         long res_ref = (long)res_var.inner & ~1;
2906         return res_ref;
2907 }
2908 uint32_t  __attribute__((visibility("default"))) TS_LDKCResult_NodeInfoDecodeErrorZ_get_err(uint32_t arg) {
2909         LDKCResult_NodeInfoDecodeErrorZ *val = (LDKCResult_NodeInfoDecodeErrorZ*)(arg & ~1);
2910         CHECK(!val->result_ok);
2911         LDKDecodeError err_var = (*val->contents.err);
2912         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2913         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2914         long err_ref = (long)err_var.inner & ~1;
2915         return err_ref;
2916 }
2917 jboolean  __attribute__((visibility("default"))) TS_LDKCResult_NetworkGraphDecodeErrorZ_result_ok(uint32_t arg) {
2918         return ((LDKCResult_NetworkGraphDecodeErrorZ*)arg)->result_ok;
2919 }
2920 uint32_t  __attribute__((visibility("default"))) TS_LDKCResult_NetworkGraphDecodeErrorZ_get_ok(uint32_t arg) {
2921         LDKCResult_NetworkGraphDecodeErrorZ *val = (LDKCResult_NetworkGraphDecodeErrorZ*)(arg & ~1);
2922         CHECK(val->result_ok);
2923         LDKNetworkGraph res_var = (*val->contents.result);
2924         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2925         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2926         long res_ref = (long)res_var.inner & ~1;
2927         return res_ref;
2928 }
2929 uint32_t  __attribute__((visibility("default"))) TS_LDKCResult_NetworkGraphDecodeErrorZ_get_err(uint32_t arg) {
2930         LDKCResult_NetworkGraphDecodeErrorZ *val = (LDKCResult_NetworkGraphDecodeErrorZ*)(arg & ~1);
2931         CHECK(!val->result_ok);
2932         LDKDecodeError err_var = (*val->contents.err);
2933         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2934         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2935         long err_ref = (long)err_var.inner & ~1;
2936         return err_ref;
2937 }
2938 typedef struct LDKMessageSendEventsProvider_JCalls {
2939         atomic_size_t refcnt;
2940         uint32_t get_and_clear_pending_msg_events_meth;
2941 } LDKMessageSendEventsProvider_JCalls;
2942 static void LDKMessageSendEventsProvider_JCalls_free(void* this_arg) {
2943         LDKMessageSendEventsProvider_JCalls *j_calls = (LDKMessageSendEventsProvider_JCalls*) this_arg;
2944         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
2945                 js_free(j_calls->get_and_clear_pending_msg_events_meth);
2946                 FREE(j_calls);
2947         }
2948 }
2949 LDKCVec_MessageSendEventZ get_and_clear_pending_msg_events_jcall(const void* this_arg) {
2950         LDKMessageSendEventsProvider_JCalls *j_calls = (LDKMessageSendEventsProvider_JCalls*) this_arg;
2951         uint32_tArray arg = js_invoke_function_0(j_calls->get_and_clear_pending_msg_events_meth);
2952         LDKCVec_MessageSendEventZ arg_constr;
2953         arg_constr.datalen = *((uint32_t*)arg);
2954         if (arg_constr.datalen > 0)
2955                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKMessageSendEvent), "LDKCVec_MessageSendEventZ Elements");
2956         else
2957                 arg_constr.data = NULL;
2958         uint32_t* arg_vals = (uint32_t*)(arg + 4);
2959         for (size_t s = 0; s < arg_constr.datalen; s++) {
2960                 uint32_t arr_conv_18 = arg_vals[s];
2961                 LDKMessageSendEvent arr_conv_18_conv = *(LDKMessageSendEvent*)(((uint64_t)arr_conv_18) & ~1);
2962                 FREE((void*)arr_conv_18);
2963                 arg_constr.data[s] = arr_conv_18_conv;
2964         }
2965         return arg_constr;
2966 }
2967 static void* LDKMessageSendEventsProvider_JCalls_clone(const void* this_arg) {
2968         LDKMessageSendEventsProvider_JCalls *j_calls = (LDKMessageSendEventsProvider_JCalls*) this_arg;
2969         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
2970         return (void*) this_arg;
2971 }
2972 static inline LDKMessageSendEventsProvider LDKMessageSendEventsProvider_init (/*TODO: JS Object Reference */void* o) {
2973         LDKMessageSendEventsProvider_JCalls *calls = MALLOC(sizeof(LDKMessageSendEventsProvider_JCalls), "LDKMessageSendEventsProvider_JCalls");
2974         atomic_init(&calls->refcnt, 1);
2975         //TODO: Assign calls->o from o
2976
2977         LDKMessageSendEventsProvider ret = {
2978                 .this_arg = (void*) calls,
2979                 .get_and_clear_pending_msg_events = get_and_clear_pending_msg_events_jcall,
2980                 .free = LDKMessageSendEventsProvider_JCalls_free,
2981         };
2982         return ret;
2983 }
2984 long  __attribute__((visibility("default"))) TS_LDKMessageSendEventsProvider_new(/*TODO: JS Object Reference */void* o) {
2985         LDKMessageSendEventsProvider *res_ptr = MALLOC(sizeof(LDKMessageSendEventsProvider), "LDKMessageSendEventsProvider");
2986         *res_ptr = LDKMessageSendEventsProvider_init(o);
2987         return (long)res_ptr;
2988 }
2989 uint32_tArray  __attribute__((visibility("default"))) TS_MessageSendEventsProvider_get_and_clear_pending_msg_events(uint32_t this_arg) {
2990         LDKMessageSendEventsProvider* this_arg_conv = (LDKMessageSendEventsProvider*)this_arg;
2991         LDKCVec_MessageSendEventZ ret_var = (this_arg_conv->get_and_clear_pending_msg_events)(this_arg_conv->this_arg);
2992         uint32_tArray ret_arr = init_arr(ret_var.datalen, sizeof(uint32_t), "Native uint32_tArray Bytes");
2993         uint32_t *ret_arr_ptr = (uint32_t*)(ret_arr + 4);
2994         for (size_t s = 0; s < ret_var.datalen; s++) {
2995                 LDKMessageSendEvent *arr_conv_18_copy = MALLOC(sizeof(LDKMessageSendEvent), "LDKMessageSendEvent");
2996                 *arr_conv_18_copy = MessageSendEvent_clone(&ret_var.data[s]);
2997                 long arr_conv_18_ref = (long)arr_conv_18_copy;
2998                 ret_arr_ptr[s] = arr_conv_18_ref;
2999         }
3000         FREE(ret_var.data);
3001         return ret_arr;
3002 }
3003
3004 typedef struct LDKEventsProvider_JCalls {
3005         atomic_size_t refcnt;
3006         uint32_t get_and_clear_pending_events_meth;
3007 } LDKEventsProvider_JCalls;
3008 static void LDKEventsProvider_JCalls_free(void* this_arg) {
3009         LDKEventsProvider_JCalls *j_calls = (LDKEventsProvider_JCalls*) this_arg;
3010         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
3011                 js_free(j_calls->get_and_clear_pending_events_meth);
3012                 FREE(j_calls);
3013         }
3014 }
3015 LDKCVec_EventZ get_and_clear_pending_events_jcall(const void* this_arg) {
3016         LDKEventsProvider_JCalls *j_calls = (LDKEventsProvider_JCalls*) this_arg;
3017         uint32_tArray arg = js_invoke_function_0(j_calls->get_and_clear_pending_events_meth);
3018         LDKCVec_EventZ arg_constr;
3019         arg_constr.datalen = *((uint32_t*)arg);
3020         if (arg_constr.datalen > 0)
3021                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKEvent), "LDKCVec_EventZ Elements");
3022         else
3023                 arg_constr.data = NULL;
3024         uint32_t* arg_vals = (uint32_t*)(arg + 4);
3025         for (size_t h = 0; h < arg_constr.datalen; h++) {
3026                 uint32_t arr_conv_7 = arg_vals[h];
3027                 LDKEvent arr_conv_7_conv = *(LDKEvent*)(((uint64_t)arr_conv_7) & ~1);
3028                 FREE((void*)arr_conv_7);
3029                 arg_constr.data[h] = arr_conv_7_conv;
3030         }
3031         return arg_constr;
3032 }
3033 static void* LDKEventsProvider_JCalls_clone(const void* this_arg) {
3034         LDKEventsProvider_JCalls *j_calls = (LDKEventsProvider_JCalls*) this_arg;
3035         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
3036         return (void*) this_arg;
3037 }
3038 static inline LDKEventsProvider LDKEventsProvider_init (/*TODO: JS Object Reference */void* o) {
3039         LDKEventsProvider_JCalls *calls = MALLOC(sizeof(LDKEventsProvider_JCalls), "LDKEventsProvider_JCalls");
3040         atomic_init(&calls->refcnt, 1);
3041         //TODO: Assign calls->o from o
3042
3043         LDKEventsProvider ret = {
3044                 .this_arg = (void*) calls,
3045                 .get_and_clear_pending_events = get_and_clear_pending_events_jcall,
3046                 .free = LDKEventsProvider_JCalls_free,
3047         };
3048         return ret;
3049 }
3050 long  __attribute__((visibility("default"))) TS_LDKEventsProvider_new(/*TODO: JS Object Reference */void* o) {
3051         LDKEventsProvider *res_ptr = MALLOC(sizeof(LDKEventsProvider), "LDKEventsProvider");
3052         *res_ptr = LDKEventsProvider_init(o);
3053         return (long)res_ptr;
3054 }
3055 uint32_tArray  __attribute__((visibility("default"))) TS_EventsProvider_get_and_clear_pending_events(uint32_t this_arg) {
3056         LDKEventsProvider* this_arg_conv = (LDKEventsProvider*)this_arg;
3057         LDKCVec_EventZ ret_var = (this_arg_conv->get_and_clear_pending_events)(this_arg_conv->this_arg);
3058         uint32_tArray ret_arr = init_arr(ret_var.datalen, sizeof(uint32_t), "Native uint32_tArray Bytes");
3059         uint32_t *ret_arr_ptr = (uint32_t*)(ret_arr + 4);
3060         for (size_t h = 0; h < ret_var.datalen; h++) {
3061                 LDKEvent *arr_conv_7_copy = MALLOC(sizeof(LDKEvent), "LDKEvent");
3062                 *arr_conv_7_copy = Event_clone(&ret_var.data[h]);
3063                 long arr_conv_7_ref = (long)arr_conv_7_copy;
3064                 ret_arr_ptr[h] = arr_conv_7_ref;
3065         }
3066         FREE(ret_var.data);
3067         return ret_arr;
3068 }
3069
3070 typedef struct LDKAccess_JCalls {
3071         atomic_size_t refcnt;
3072         uint32_t get_utxo_meth;
3073 } LDKAccess_JCalls;
3074 static void LDKAccess_JCalls_free(void* this_arg) {
3075         LDKAccess_JCalls *j_calls = (LDKAccess_JCalls*) this_arg;
3076         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
3077                 js_free(j_calls->get_utxo_meth);
3078                 FREE(j_calls);
3079         }
3080 }
3081 LDKCResult_TxOutAccessErrorZ get_utxo_jcall(const void* this_arg, const uint8_t (* genesis_hash)[32], uint64_t short_channel_id) {
3082         LDKAccess_JCalls *j_calls = (LDKAccess_JCalls*) this_arg;
3083         int8_tArray genesis_hash_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
3084         memcpy((uint8_t*)(genesis_hash_arr + 4), *genesis_hash, 32);
3085         LDKCResult_TxOutAccessErrorZ* ret = (LDKCResult_TxOutAccessErrorZ*)js_invoke_function_2(j_calls->get_utxo_meth, genesis_hash_arr, short_channel_id);
3086         LDKCResult_TxOutAccessErrorZ ret_conv = *(LDKCResult_TxOutAccessErrorZ*)(((uint64_t)ret) & ~1);
3087         ret_conv = CResult_TxOutAccessErrorZ_clone((LDKCResult_TxOutAccessErrorZ*)ret);
3088         return ret_conv;
3089 }
3090 static void* LDKAccess_JCalls_clone(const void* this_arg) {
3091         LDKAccess_JCalls *j_calls = (LDKAccess_JCalls*) this_arg;
3092         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
3093         return (void*) this_arg;
3094 }
3095 static inline LDKAccess LDKAccess_init (/*TODO: JS Object Reference */void* o) {
3096         LDKAccess_JCalls *calls = MALLOC(sizeof(LDKAccess_JCalls), "LDKAccess_JCalls");
3097         atomic_init(&calls->refcnt, 1);
3098         //TODO: Assign calls->o from o
3099
3100         LDKAccess ret = {
3101                 .this_arg = (void*) calls,
3102                 .get_utxo = get_utxo_jcall,
3103                 .free = LDKAccess_JCalls_free,
3104         };
3105         return ret;
3106 }
3107 long  __attribute__((visibility("default"))) TS_LDKAccess_new(/*TODO: JS Object Reference */void* o) {
3108         LDKAccess *res_ptr = MALLOC(sizeof(LDKAccess), "LDKAccess");
3109         *res_ptr = LDKAccess_init(o);
3110         return (long)res_ptr;
3111 }
3112 uint32_t  __attribute__((visibility("default"))) TS_Access_get_utxo(uint32_t this_arg, int8_tArray genesis_hash, int64_t short_channel_id) {
3113         LDKAccess* this_arg_conv = (LDKAccess*)this_arg;
3114         unsigned char genesis_hash_arr[32];
3115         CHECK(*((uint32_t*)genesis_hash) == 32);
3116         memcpy(genesis_hash_arr, (uint8_t*)(genesis_hash + 4), 32);
3117         unsigned char (*genesis_hash_ref)[32] = &genesis_hash_arr;
3118         LDKCResult_TxOutAccessErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_TxOutAccessErrorZ), "LDKCResult_TxOutAccessErrorZ");
3119         *ret_conv = (this_arg_conv->get_utxo)(this_arg_conv->this_arg, genesis_hash_ref, short_channel_id);
3120         return (long)ret_conv;
3121 }
3122
3123 typedef struct LDKFilter_JCalls {
3124         atomic_size_t refcnt;
3125         uint32_t register_tx_meth;
3126         uint32_t register_output_meth;
3127 } LDKFilter_JCalls;
3128 static void LDKFilter_JCalls_free(void* this_arg) {
3129         LDKFilter_JCalls *j_calls = (LDKFilter_JCalls*) this_arg;
3130         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
3131                 js_free(j_calls->register_tx_meth);
3132                 js_free(j_calls->register_output_meth);
3133                 FREE(j_calls);
3134         }
3135 }
3136 void register_tx_jcall(const void* this_arg, const uint8_t (* txid)[32], LDKu8slice script_pubkey) {
3137         LDKFilter_JCalls *j_calls = (LDKFilter_JCalls*) this_arg;
3138         int8_tArray txid_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
3139         memcpy((uint8_t*)(txid_arr + 4), *txid, 32);
3140         LDKu8slice script_pubkey_var = script_pubkey;
3141         int8_tArray script_pubkey_arr = init_arr(script_pubkey_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
3142         memcpy((uint8_t*)(script_pubkey_arr + 4), script_pubkey_var.data, script_pubkey_var.datalen);
3143         js_invoke_function_2(j_calls->register_tx_meth, txid_arr, script_pubkey_arr);
3144 }
3145 void register_output_jcall(const void* this_arg, const LDKOutPoint * outpoint, LDKu8slice script_pubkey) {
3146         LDKFilter_JCalls *j_calls = (LDKFilter_JCalls*) this_arg;
3147         LDKOutPoint outpoint_var = *outpoint;
3148         outpoint_var = OutPoint_clone(outpoint);
3149         CHECK((((long)outpoint_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3150         CHECK((((long)&outpoint_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3151         long outpoint_ref = (long)outpoint_var.inner;
3152         if (outpoint_var.is_owned) {
3153                 outpoint_ref |= 1;
3154         }
3155         LDKu8slice script_pubkey_var = script_pubkey;
3156         int8_tArray script_pubkey_arr = init_arr(script_pubkey_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
3157         memcpy((uint8_t*)(script_pubkey_arr + 4), script_pubkey_var.data, script_pubkey_var.datalen);
3158         js_invoke_function_2(j_calls->register_output_meth, outpoint_ref, script_pubkey_arr);
3159 }
3160 static void* LDKFilter_JCalls_clone(const void* this_arg) {
3161         LDKFilter_JCalls *j_calls = (LDKFilter_JCalls*) this_arg;
3162         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
3163         return (void*) this_arg;
3164 }
3165 static inline LDKFilter LDKFilter_init (/*TODO: JS Object Reference */void* o) {
3166         LDKFilter_JCalls *calls = MALLOC(sizeof(LDKFilter_JCalls), "LDKFilter_JCalls");
3167         atomic_init(&calls->refcnt, 1);
3168         //TODO: Assign calls->o from o
3169
3170         LDKFilter ret = {
3171                 .this_arg = (void*) calls,
3172                 .register_tx = register_tx_jcall,
3173                 .register_output = register_output_jcall,
3174                 .free = LDKFilter_JCalls_free,
3175         };
3176         return ret;
3177 }
3178 long  __attribute__((visibility("default"))) TS_LDKFilter_new(/*TODO: JS Object Reference */void* o) {
3179         LDKFilter *res_ptr = MALLOC(sizeof(LDKFilter), "LDKFilter");
3180         *res_ptr = LDKFilter_init(o);
3181         return (long)res_ptr;
3182 }
3183 void  __attribute__((visibility("default"))) TS_Filter_register_tx(uint32_t this_arg, int8_tArray txid, int8_tArray script_pubkey) {
3184         LDKFilter* this_arg_conv = (LDKFilter*)this_arg;
3185         unsigned char txid_arr[32];
3186         CHECK(*((uint32_t*)txid) == 32);
3187         memcpy(txid_arr, (uint8_t*)(txid + 4), 32);
3188         unsigned char (*txid_ref)[32] = &txid_arr;
3189         LDKu8slice script_pubkey_ref;
3190         script_pubkey_ref.datalen = *((uint32_t*)script_pubkey);
3191         script_pubkey_ref.data = (int8_t*)(script_pubkey + 4);
3192         (this_arg_conv->register_tx)(this_arg_conv->this_arg, txid_ref, script_pubkey_ref);
3193 }
3194
3195 void  __attribute__((visibility("default"))) TS_Filter_register_output(uint32_t this_arg, uint32_t outpoint, int8_tArray script_pubkey) {
3196         LDKFilter* this_arg_conv = (LDKFilter*)this_arg;
3197         LDKOutPoint outpoint_conv;
3198         outpoint_conv.inner = (void*)(outpoint & (~1));
3199         outpoint_conv.is_owned = false;
3200         LDKu8slice script_pubkey_ref;
3201         script_pubkey_ref.datalen = *((uint32_t*)script_pubkey);
3202         script_pubkey_ref.data = (int8_t*)(script_pubkey + 4);
3203         (this_arg_conv->register_output)(this_arg_conv->this_arg, &outpoint_conv, script_pubkey_ref);
3204 }
3205
3206 typedef struct LDKPersist_JCalls {
3207         atomic_size_t refcnt;
3208         uint32_t persist_new_channel_meth;
3209         uint32_t update_persisted_channel_meth;
3210 } LDKPersist_JCalls;
3211 static void LDKPersist_JCalls_free(void* this_arg) {
3212         LDKPersist_JCalls *j_calls = (LDKPersist_JCalls*) this_arg;
3213         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
3214                 js_free(j_calls->persist_new_channel_meth);
3215                 js_free(j_calls->update_persisted_channel_meth);
3216                 FREE(j_calls);
3217         }
3218 }
3219 LDKCResult_NoneChannelMonitorUpdateErrZ persist_new_channel_jcall(const void* this_arg, LDKOutPoint id, const LDKChannelMonitor * data) {
3220         LDKPersist_JCalls *j_calls = (LDKPersist_JCalls*) this_arg;
3221         LDKOutPoint id_var = id;
3222         CHECK((((long)id_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3223         CHECK((((long)&id_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3224         long id_ref = (long)id_var.inner;
3225         if (id_var.is_owned) {
3226                 id_ref |= 1;
3227         }
3228         LDKChannelMonitor data_var = *data;
3229         data_var = ChannelMonitor_clone(data);
3230         CHECK((((long)data_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3231         CHECK((((long)&data_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3232         long data_ref = (long)data_var.inner;
3233         if (data_var.is_owned) {
3234                 data_ref |= 1;
3235         }
3236         LDKCResult_NoneChannelMonitorUpdateErrZ* ret = (LDKCResult_NoneChannelMonitorUpdateErrZ*)js_invoke_function_2(j_calls->persist_new_channel_meth, id_ref, data_ref);
3237         LDKCResult_NoneChannelMonitorUpdateErrZ ret_conv = *(LDKCResult_NoneChannelMonitorUpdateErrZ*)(((uint64_t)ret) & ~1);
3238         ret_conv = CResult_NoneChannelMonitorUpdateErrZ_clone((LDKCResult_NoneChannelMonitorUpdateErrZ*)ret);
3239         return ret_conv;
3240 }
3241 LDKCResult_NoneChannelMonitorUpdateErrZ update_persisted_channel_jcall(const void* this_arg, LDKOutPoint id, const LDKChannelMonitorUpdate * update, const LDKChannelMonitor * data) {
3242         LDKPersist_JCalls *j_calls = (LDKPersist_JCalls*) this_arg;
3243         LDKOutPoint id_var = id;
3244         CHECK((((long)id_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3245         CHECK((((long)&id_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3246         long id_ref = (long)id_var.inner;
3247         if (id_var.is_owned) {
3248                 id_ref |= 1;
3249         }
3250         LDKChannelMonitorUpdate update_var = *update;
3251         update_var = ChannelMonitorUpdate_clone(update);
3252         CHECK((((long)update_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3253         CHECK((((long)&update_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3254         long update_ref = (long)update_var.inner;
3255         if (update_var.is_owned) {
3256                 update_ref |= 1;
3257         }
3258         LDKChannelMonitor data_var = *data;
3259         data_var = ChannelMonitor_clone(data);
3260         CHECK((((long)data_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3261         CHECK((((long)&data_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3262         long data_ref = (long)data_var.inner;
3263         if (data_var.is_owned) {
3264                 data_ref |= 1;
3265         }
3266         LDKCResult_NoneChannelMonitorUpdateErrZ* ret = (LDKCResult_NoneChannelMonitorUpdateErrZ*)js_invoke_function_3(j_calls->update_persisted_channel_meth, id_ref, update_ref, data_ref);
3267         LDKCResult_NoneChannelMonitorUpdateErrZ ret_conv = *(LDKCResult_NoneChannelMonitorUpdateErrZ*)(((uint64_t)ret) & ~1);
3268         ret_conv = CResult_NoneChannelMonitorUpdateErrZ_clone((LDKCResult_NoneChannelMonitorUpdateErrZ*)ret);
3269         return ret_conv;
3270 }
3271 static void* LDKPersist_JCalls_clone(const void* this_arg) {
3272         LDKPersist_JCalls *j_calls = (LDKPersist_JCalls*) this_arg;
3273         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
3274         return (void*) this_arg;
3275 }
3276 static inline LDKPersist LDKPersist_init (/*TODO: JS Object Reference */void* o) {
3277         LDKPersist_JCalls *calls = MALLOC(sizeof(LDKPersist_JCalls), "LDKPersist_JCalls");
3278         atomic_init(&calls->refcnt, 1);
3279         //TODO: Assign calls->o from o
3280
3281         LDKPersist ret = {
3282                 .this_arg = (void*) calls,
3283                 .persist_new_channel = persist_new_channel_jcall,
3284                 .update_persisted_channel = update_persisted_channel_jcall,
3285                 .free = LDKPersist_JCalls_free,
3286         };
3287         return ret;
3288 }
3289 long  __attribute__((visibility("default"))) TS_LDKPersist_new(/*TODO: JS Object Reference */void* o) {
3290         LDKPersist *res_ptr = MALLOC(sizeof(LDKPersist), "LDKPersist");
3291         *res_ptr = LDKPersist_init(o);
3292         return (long)res_ptr;
3293 }
3294 uint32_t  __attribute__((visibility("default"))) TS_Persist_persist_new_channel(uint32_t this_arg, uint32_t id, uint32_t data) {
3295         LDKPersist* this_arg_conv = (LDKPersist*)this_arg;
3296         LDKOutPoint id_conv;
3297         id_conv.inner = (void*)(id & (~1));
3298         id_conv.is_owned = (id & 1) || (id == 0);
3299         id_conv = OutPoint_clone(&id_conv);
3300         LDKChannelMonitor data_conv;
3301         data_conv.inner = (void*)(data & (~1));
3302         data_conv.is_owned = false;
3303         LDKCResult_NoneChannelMonitorUpdateErrZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneChannelMonitorUpdateErrZ), "LDKCResult_NoneChannelMonitorUpdateErrZ");
3304         *ret_conv = (this_arg_conv->persist_new_channel)(this_arg_conv->this_arg, id_conv, &data_conv);
3305         return (long)ret_conv;
3306 }
3307
3308 uint32_t  __attribute__((visibility("default"))) TS_Persist_update_persisted_channel(uint32_t this_arg, uint32_t id, uint32_t update, uint32_t data) {
3309         LDKPersist* this_arg_conv = (LDKPersist*)this_arg;
3310         LDKOutPoint id_conv;
3311         id_conv.inner = (void*)(id & (~1));
3312         id_conv.is_owned = (id & 1) || (id == 0);
3313         id_conv = OutPoint_clone(&id_conv);
3314         LDKChannelMonitorUpdate update_conv;
3315         update_conv.inner = (void*)(update & (~1));
3316         update_conv.is_owned = false;
3317         LDKChannelMonitor data_conv;
3318         data_conv.inner = (void*)(data & (~1));
3319         data_conv.is_owned = false;
3320         LDKCResult_NoneChannelMonitorUpdateErrZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneChannelMonitorUpdateErrZ), "LDKCResult_NoneChannelMonitorUpdateErrZ");
3321         *ret_conv = (this_arg_conv->update_persisted_channel)(this_arg_conv->this_arg, id_conv, &update_conv, &data_conv);
3322         return (long)ret_conv;
3323 }
3324
3325 typedef struct LDKChannelMessageHandler_JCalls {
3326         atomic_size_t refcnt;
3327         LDKMessageSendEventsProvider_JCalls* MessageSendEventsProvider;
3328         uint32_t handle_open_channel_meth;
3329         uint32_t handle_accept_channel_meth;
3330         uint32_t handle_funding_created_meth;
3331         uint32_t handle_funding_signed_meth;
3332         uint32_t handle_funding_locked_meth;
3333         uint32_t handle_shutdown_meth;
3334         uint32_t handle_closing_signed_meth;
3335         uint32_t handle_update_add_htlc_meth;
3336         uint32_t handle_update_fulfill_htlc_meth;
3337         uint32_t handle_update_fail_htlc_meth;
3338         uint32_t handle_update_fail_malformed_htlc_meth;
3339         uint32_t handle_commitment_signed_meth;
3340         uint32_t handle_revoke_and_ack_meth;
3341         uint32_t handle_update_fee_meth;
3342         uint32_t handle_announcement_signatures_meth;
3343         uint32_t peer_disconnected_meth;
3344         uint32_t peer_connected_meth;
3345         uint32_t handle_channel_reestablish_meth;
3346         uint32_t handle_error_meth;
3347 } LDKChannelMessageHandler_JCalls;
3348 static void LDKChannelMessageHandler_JCalls_free(void* this_arg) {
3349         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3350         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
3351                 js_free(j_calls->handle_open_channel_meth);
3352                 js_free(j_calls->handle_accept_channel_meth);
3353                 js_free(j_calls->handle_funding_created_meth);
3354                 js_free(j_calls->handle_funding_signed_meth);
3355                 js_free(j_calls->handle_funding_locked_meth);
3356                 js_free(j_calls->handle_shutdown_meth);
3357                 js_free(j_calls->handle_closing_signed_meth);
3358                 js_free(j_calls->handle_update_add_htlc_meth);
3359                 js_free(j_calls->handle_update_fulfill_htlc_meth);
3360                 js_free(j_calls->handle_update_fail_htlc_meth);
3361                 js_free(j_calls->handle_update_fail_malformed_htlc_meth);
3362                 js_free(j_calls->handle_commitment_signed_meth);
3363                 js_free(j_calls->handle_revoke_and_ack_meth);
3364                 js_free(j_calls->handle_update_fee_meth);
3365                 js_free(j_calls->handle_announcement_signatures_meth);
3366                 js_free(j_calls->peer_disconnected_meth);
3367                 js_free(j_calls->peer_connected_meth);
3368                 js_free(j_calls->handle_channel_reestablish_meth);
3369                 js_free(j_calls->handle_error_meth);
3370                 FREE(j_calls);
3371         }
3372 }
3373 void handle_open_channel_jcall(const void* this_arg, LDKPublicKey their_node_id, LDKInitFeatures their_features, const LDKOpenChannel * msg) {
3374         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3375         int8_tArray their_node_id_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
3376         memcpy((uint8_t*)(their_node_id_arr + 4), their_node_id.compressed_form, 33);
3377         LDKInitFeatures their_features_var = their_features;
3378         CHECK((((long)their_features_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3379         CHECK((((long)&their_features_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3380         long their_features_ref = (long)their_features_var.inner;
3381         if (their_features_var.is_owned) {
3382                 their_features_ref |= 1;
3383         }
3384         LDKOpenChannel msg_var = *msg;
3385         msg_var = OpenChannel_clone(msg);
3386         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3387         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3388         long msg_ref = (long)msg_var.inner;
3389         if (msg_var.is_owned) {
3390                 msg_ref |= 1;
3391         }
3392         js_invoke_function_3(j_calls->handle_open_channel_meth, their_node_id_arr, their_features_ref, msg_ref);
3393 }
3394 void handle_accept_channel_jcall(const void* this_arg, LDKPublicKey their_node_id, LDKInitFeatures their_features, const LDKAcceptChannel * msg) {
3395         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3396         int8_tArray their_node_id_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
3397         memcpy((uint8_t*)(their_node_id_arr + 4), their_node_id.compressed_form, 33);
3398         LDKInitFeatures their_features_var = their_features;
3399         CHECK((((long)their_features_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3400         CHECK((((long)&their_features_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3401         long their_features_ref = (long)their_features_var.inner;
3402         if (their_features_var.is_owned) {
3403                 their_features_ref |= 1;
3404         }
3405         LDKAcceptChannel msg_var = *msg;
3406         msg_var = AcceptChannel_clone(msg);
3407         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3408         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3409         long msg_ref = (long)msg_var.inner;
3410         if (msg_var.is_owned) {
3411                 msg_ref |= 1;
3412         }
3413         js_invoke_function_3(j_calls->handle_accept_channel_meth, their_node_id_arr, their_features_ref, msg_ref);
3414 }
3415 void handle_funding_created_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKFundingCreated * msg) {
3416         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3417         int8_tArray their_node_id_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
3418         memcpy((uint8_t*)(their_node_id_arr + 4), their_node_id.compressed_form, 33);
3419         LDKFundingCreated msg_var = *msg;
3420         msg_var = FundingCreated_clone(msg);
3421         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3422         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3423         long msg_ref = (long)msg_var.inner;
3424         if (msg_var.is_owned) {
3425                 msg_ref |= 1;
3426         }
3427         js_invoke_function_2(j_calls->handle_funding_created_meth, their_node_id_arr, msg_ref);
3428 }
3429 void handle_funding_signed_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKFundingSigned * msg) {
3430         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3431         int8_tArray their_node_id_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
3432         memcpy((uint8_t*)(their_node_id_arr + 4), their_node_id.compressed_form, 33);
3433         LDKFundingSigned msg_var = *msg;
3434         msg_var = FundingSigned_clone(msg);
3435         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3436         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3437         long msg_ref = (long)msg_var.inner;
3438         if (msg_var.is_owned) {
3439                 msg_ref |= 1;
3440         }
3441         js_invoke_function_2(j_calls->handle_funding_signed_meth, their_node_id_arr, msg_ref);
3442 }
3443 void handle_funding_locked_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKFundingLocked * msg) {
3444         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3445         int8_tArray their_node_id_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
3446         memcpy((uint8_t*)(their_node_id_arr + 4), their_node_id.compressed_form, 33);
3447         LDKFundingLocked msg_var = *msg;
3448         msg_var = FundingLocked_clone(msg);
3449         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3450         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3451         long msg_ref = (long)msg_var.inner;
3452         if (msg_var.is_owned) {
3453                 msg_ref |= 1;
3454         }
3455         js_invoke_function_2(j_calls->handle_funding_locked_meth, their_node_id_arr, msg_ref);
3456 }
3457 void handle_shutdown_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKShutdown * msg) {
3458         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3459         int8_tArray their_node_id_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
3460         memcpy((uint8_t*)(their_node_id_arr + 4), their_node_id.compressed_form, 33);
3461         LDKShutdown msg_var = *msg;
3462         msg_var = Shutdown_clone(msg);
3463         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3464         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3465         long msg_ref = (long)msg_var.inner;
3466         if (msg_var.is_owned) {
3467                 msg_ref |= 1;
3468         }
3469         js_invoke_function_2(j_calls->handle_shutdown_meth, their_node_id_arr, msg_ref);
3470 }
3471 void handle_closing_signed_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKClosingSigned * msg) {
3472         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3473         int8_tArray their_node_id_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
3474         memcpy((uint8_t*)(their_node_id_arr + 4), their_node_id.compressed_form, 33);
3475         LDKClosingSigned msg_var = *msg;
3476         msg_var = ClosingSigned_clone(msg);
3477         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3478         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3479         long msg_ref = (long)msg_var.inner;
3480         if (msg_var.is_owned) {
3481                 msg_ref |= 1;
3482         }
3483         js_invoke_function_2(j_calls->handle_closing_signed_meth, their_node_id_arr, msg_ref);
3484 }
3485 void handle_update_add_htlc_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKUpdateAddHTLC * msg) {
3486         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3487         int8_tArray their_node_id_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
3488         memcpy((uint8_t*)(their_node_id_arr + 4), their_node_id.compressed_form, 33);
3489         LDKUpdateAddHTLC msg_var = *msg;
3490         msg_var = UpdateAddHTLC_clone(msg);
3491         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3492         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3493         long msg_ref = (long)msg_var.inner;
3494         if (msg_var.is_owned) {
3495                 msg_ref |= 1;
3496         }
3497         js_invoke_function_2(j_calls->handle_update_add_htlc_meth, their_node_id_arr, msg_ref);
3498 }
3499 void handle_update_fulfill_htlc_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKUpdateFulfillHTLC * msg) {
3500         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3501         int8_tArray their_node_id_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
3502         memcpy((uint8_t*)(their_node_id_arr + 4), their_node_id.compressed_form, 33);
3503         LDKUpdateFulfillHTLC msg_var = *msg;
3504         msg_var = UpdateFulfillHTLC_clone(msg);
3505         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3506         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3507         long msg_ref = (long)msg_var.inner;
3508         if (msg_var.is_owned) {
3509                 msg_ref |= 1;
3510         }
3511         js_invoke_function_2(j_calls->handle_update_fulfill_htlc_meth, their_node_id_arr, msg_ref);
3512 }
3513 void handle_update_fail_htlc_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKUpdateFailHTLC * msg) {
3514         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3515         int8_tArray their_node_id_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
3516         memcpy((uint8_t*)(their_node_id_arr + 4), their_node_id.compressed_form, 33);
3517         LDKUpdateFailHTLC msg_var = *msg;
3518         msg_var = UpdateFailHTLC_clone(msg);
3519         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3520         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3521         long msg_ref = (long)msg_var.inner;
3522         if (msg_var.is_owned) {
3523                 msg_ref |= 1;
3524         }
3525         js_invoke_function_2(j_calls->handle_update_fail_htlc_meth, their_node_id_arr, msg_ref);
3526 }
3527 void handle_update_fail_malformed_htlc_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKUpdateFailMalformedHTLC * msg) {
3528         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3529         int8_tArray their_node_id_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
3530         memcpy((uint8_t*)(their_node_id_arr + 4), their_node_id.compressed_form, 33);
3531         LDKUpdateFailMalformedHTLC msg_var = *msg;
3532         msg_var = UpdateFailMalformedHTLC_clone(msg);
3533         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3534         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3535         long msg_ref = (long)msg_var.inner;
3536         if (msg_var.is_owned) {
3537                 msg_ref |= 1;
3538         }
3539         js_invoke_function_2(j_calls->handle_update_fail_malformed_htlc_meth, their_node_id_arr, msg_ref);
3540 }
3541 void handle_commitment_signed_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKCommitmentSigned * msg) {
3542         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3543         int8_tArray their_node_id_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
3544         memcpy((uint8_t*)(their_node_id_arr + 4), their_node_id.compressed_form, 33);
3545         LDKCommitmentSigned msg_var = *msg;
3546         msg_var = CommitmentSigned_clone(msg);
3547         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3548         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3549         long msg_ref = (long)msg_var.inner;
3550         if (msg_var.is_owned) {
3551                 msg_ref |= 1;
3552         }
3553         js_invoke_function_2(j_calls->handle_commitment_signed_meth, their_node_id_arr, msg_ref);
3554 }
3555 void handle_revoke_and_ack_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKRevokeAndACK * msg) {
3556         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3557         int8_tArray their_node_id_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
3558         memcpy((uint8_t*)(their_node_id_arr + 4), their_node_id.compressed_form, 33);
3559         LDKRevokeAndACK msg_var = *msg;
3560         msg_var = RevokeAndACK_clone(msg);
3561         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3562         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3563         long msg_ref = (long)msg_var.inner;
3564         if (msg_var.is_owned) {
3565                 msg_ref |= 1;
3566         }
3567         js_invoke_function_2(j_calls->handle_revoke_and_ack_meth, their_node_id_arr, msg_ref);
3568 }
3569 void handle_update_fee_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKUpdateFee * msg) {
3570         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3571         int8_tArray their_node_id_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
3572         memcpy((uint8_t*)(their_node_id_arr + 4), their_node_id.compressed_form, 33);
3573         LDKUpdateFee msg_var = *msg;
3574         msg_var = UpdateFee_clone(msg);
3575         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3576         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3577         long msg_ref = (long)msg_var.inner;
3578         if (msg_var.is_owned) {
3579                 msg_ref |= 1;
3580         }
3581         js_invoke_function_2(j_calls->handle_update_fee_meth, their_node_id_arr, msg_ref);
3582 }
3583 void handle_announcement_signatures_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKAnnouncementSignatures * msg) {
3584         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3585         int8_tArray their_node_id_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
3586         memcpy((uint8_t*)(their_node_id_arr + 4), their_node_id.compressed_form, 33);
3587         LDKAnnouncementSignatures msg_var = *msg;
3588         msg_var = AnnouncementSignatures_clone(msg);
3589         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3590         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3591         long msg_ref = (long)msg_var.inner;
3592         if (msg_var.is_owned) {
3593                 msg_ref |= 1;
3594         }
3595         js_invoke_function_2(j_calls->handle_announcement_signatures_meth, their_node_id_arr, msg_ref);
3596 }
3597 void peer_disconnected_jcall(const void* this_arg, LDKPublicKey their_node_id, bool no_connection_possible) {
3598         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3599         int8_tArray their_node_id_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
3600         memcpy((uint8_t*)(their_node_id_arr + 4), their_node_id.compressed_form, 33);
3601         js_invoke_function_2(j_calls->peer_disconnected_meth, their_node_id_arr, no_connection_possible);
3602 }
3603 void peer_connected_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKInit * msg) {
3604         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3605         int8_tArray their_node_id_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
3606         memcpy((uint8_t*)(their_node_id_arr + 4), their_node_id.compressed_form, 33);
3607         LDKInit msg_var = *msg;
3608         msg_var = Init_clone(msg);
3609         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3610         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3611         long msg_ref = (long)msg_var.inner;
3612         if (msg_var.is_owned) {
3613                 msg_ref |= 1;
3614         }
3615         js_invoke_function_2(j_calls->peer_connected_meth, their_node_id_arr, msg_ref);
3616 }
3617 void handle_channel_reestablish_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKChannelReestablish * msg) {
3618         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3619         int8_tArray their_node_id_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
3620         memcpy((uint8_t*)(their_node_id_arr + 4), their_node_id.compressed_form, 33);
3621         LDKChannelReestablish msg_var = *msg;
3622         msg_var = ChannelReestablish_clone(msg);
3623         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3624         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3625         long msg_ref = (long)msg_var.inner;
3626         if (msg_var.is_owned) {
3627                 msg_ref |= 1;
3628         }
3629         js_invoke_function_2(j_calls->handle_channel_reestablish_meth, their_node_id_arr, msg_ref);
3630 }
3631 void handle_error_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKErrorMessage * msg) {
3632         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3633         int8_tArray their_node_id_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
3634         memcpy((uint8_t*)(their_node_id_arr + 4), their_node_id.compressed_form, 33);
3635         LDKErrorMessage msg_var = *msg;
3636         msg_var = ErrorMessage_clone(msg);
3637         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3638         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3639         long msg_ref = (long)msg_var.inner;
3640         if (msg_var.is_owned) {
3641                 msg_ref |= 1;
3642         }
3643         js_invoke_function_2(j_calls->handle_error_meth, their_node_id_arr, msg_ref);
3644 }
3645 static void* LDKChannelMessageHandler_JCalls_clone(const void* this_arg) {
3646         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3647         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
3648         atomic_fetch_add_explicit(&j_calls->MessageSendEventsProvider->refcnt, 1, memory_order_release);
3649         return (void*) this_arg;
3650 }
3651 static inline LDKChannelMessageHandler LDKChannelMessageHandler_init (/*TODO: JS Object Reference */void* o, /*TODO: JS Object Reference */void* MessageSendEventsProvider) {
3652         LDKChannelMessageHandler_JCalls *calls = MALLOC(sizeof(LDKChannelMessageHandler_JCalls), "LDKChannelMessageHandler_JCalls");
3653         atomic_init(&calls->refcnt, 1);
3654         //TODO: Assign calls->o from o
3655
3656         LDKChannelMessageHandler ret = {
3657                 .this_arg = (void*) calls,
3658                 .handle_open_channel = handle_open_channel_jcall,
3659                 .handle_accept_channel = handle_accept_channel_jcall,
3660                 .handle_funding_created = handle_funding_created_jcall,
3661                 .handle_funding_signed = handle_funding_signed_jcall,
3662                 .handle_funding_locked = handle_funding_locked_jcall,
3663                 .handle_shutdown = handle_shutdown_jcall,
3664                 .handle_closing_signed = handle_closing_signed_jcall,
3665                 .handle_update_add_htlc = handle_update_add_htlc_jcall,
3666                 .handle_update_fulfill_htlc = handle_update_fulfill_htlc_jcall,
3667                 .handle_update_fail_htlc = handle_update_fail_htlc_jcall,
3668                 .handle_update_fail_malformed_htlc = handle_update_fail_malformed_htlc_jcall,
3669                 .handle_commitment_signed = handle_commitment_signed_jcall,
3670                 .handle_revoke_and_ack = handle_revoke_and_ack_jcall,
3671                 .handle_update_fee = handle_update_fee_jcall,
3672                 .handle_announcement_signatures = handle_announcement_signatures_jcall,
3673                 .peer_disconnected = peer_disconnected_jcall,
3674                 .peer_connected = peer_connected_jcall,
3675                 .handle_channel_reestablish = handle_channel_reestablish_jcall,
3676                 .handle_error = handle_error_jcall,
3677                 .free = LDKChannelMessageHandler_JCalls_free,
3678                 .MessageSendEventsProvider = LDKMessageSendEventsProvider_init(MessageSendEventsProvider),
3679         };
3680         calls->MessageSendEventsProvider = ret.MessageSendEventsProvider.this_arg;
3681         return ret;
3682 }
3683 long  __attribute__((visibility("default"))) TS_LDKChannelMessageHandler_new(/*TODO: JS Object Reference */void* o, /*TODO: JS Object Reference */ void* MessageSendEventsProvider) {
3684         LDKChannelMessageHandler *res_ptr = MALLOC(sizeof(LDKChannelMessageHandler), "LDKChannelMessageHandler");
3685         *res_ptr = LDKChannelMessageHandler_init(o, MessageSendEventsProvider);
3686         return (long)res_ptr;
3687 }
3688 void  __attribute__((visibility("default"))) TS_ChannelMessageHandler_handle_open_channel(uint32_t this_arg, int8_tArray their_node_id, uint32_t their_features, uint32_t msg) {
3689         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
3690         LDKPublicKey their_node_id_ref;
3691         CHECK(*((uint32_t*)their_node_id) == 33);
3692         memcpy(their_node_id_ref.compressed_form, (uint8_t*)(their_node_id + 4), 33);
3693         LDKInitFeatures their_features_conv;
3694         their_features_conv.inner = (void*)(their_features & (~1));
3695         their_features_conv.is_owned = (their_features & 1) || (their_features == 0);
3696         // Warning: we need a move here but no clone is available for LDKInitFeatures
3697         LDKOpenChannel msg_conv;
3698         msg_conv.inner = (void*)(msg & (~1));
3699         msg_conv.is_owned = false;
3700         (this_arg_conv->handle_open_channel)(this_arg_conv->this_arg, their_node_id_ref, their_features_conv, &msg_conv);
3701 }
3702
3703 void  __attribute__((visibility("default"))) TS_ChannelMessageHandler_handle_accept_channel(uint32_t this_arg, int8_tArray their_node_id, uint32_t their_features, uint32_t msg) {
3704         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
3705         LDKPublicKey their_node_id_ref;
3706         CHECK(*((uint32_t*)their_node_id) == 33);
3707         memcpy(their_node_id_ref.compressed_form, (uint8_t*)(their_node_id + 4), 33);
3708         LDKInitFeatures their_features_conv;
3709         their_features_conv.inner = (void*)(their_features & (~1));
3710         their_features_conv.is_owned = (their_features & 1) || (their_features == 0);
3711         // Warning: we need a move here but no clone is available for LDKInitFeatures
3712         LDKAcceptChannel msg_conv;
3713         msg_conv.inner = (void*)(msg & (~1));
3714         msg_conv.is_owned = false;
3715         (this_arg_conv->handle_accept_channel)(this_arg_conv->this_arg, their_node_id_ref, their_features_conv, &msg_conv);
3716 }
3717
3718 void  __attribute__((visibility("default"))) TS_ChannelMessageHandler_handle_funding_created(uint32_t this_arg, int8_tArray their_node_id, uint32_t msg) {
3719         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
3720         LDKPublicKey their_node_id_ref;
3721         CHECK(*((uint32_t*)their_node_id) == 33);
3722         memcpy(their_node_id_ref.compressed_form, (uint8_t*)(their_node_id + 4), 33);
3723         LDKFundingCreated msg_conv;
3724         msg_conv.inner = (void*)(msg & (~1));
3725         msg_conv.is_owned = false;
3726         (this_arg_conv->handle_funding_created)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
3727 }
3728
3729 void  __attribute__((visibility("default"))) TS_ChannelMessageHandler_handle_funding_signed(uint32_t this_arg, int8_tArray their_node_id, uint32_t msg) {
3730         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
3731         LDKPublicKey their_node_id_ref;
3732         CHECK(*((uint32_t*)their_node_id) == 33);
3733         memcpy(their_node_id_ref.compressed_form, (uint8_t*)(their_node_id + 4), 33);
3734         LDKFundingSigned msg_conv;
3735         msg_conv.inner = (void*)(msg & (~1));
3736         msg_conv.is_owned = false;
3737         (this_arg_conv->handle_funding_signed)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
3738 }
3739
3740 void  __attribute__((visibility("default"))) TS_ChannelMessageHandler_handle_funding_locked(uint32_t this_arg, int8_tArray their_node_id, uint32_t msg) {
3741         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
3742         LDKPublicKey their_node_id_ref;
3743         CHECK(*((uint32_t*)their_node_id) == 33);
3744         memcpy(their_node_id_ref.compressed_form, (uint8_t*)(their_node_id + 4), 33);
3745         LDKFundingLocked msg_conv;
3746         msg_conv.inner = (void*)(msg & (~1));
3747         msg_conv.is_owned = false;
3748         (this_arg_conv->handle_funding_locked)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
3749 }
3750
3751 void  __attribute__((visibility("default"))) TS_ChannelMessageHandler_handle_shutdown(uint32_t this_arg, int8_tArray their_node_id, uint32_t msg) {
3752         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
3753         LDKPublicKey their_node_id_ref;
3754         CHECK(*((uint32_t*)their_node_id) == 33);
3755         memcpy(their_node_id_ref.compressed_form, (uint8_t*)(their_node_id + 4), 33);
3756         LDKShutdown msg_conv;
3757         msg_conv.inner = (void*)(msg & (~1));
3758         msg_conv.is_owned = false;
3759         (this_arg_conv->handle_shutdown)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
3760 }
3761
3762 void  __attribute__((visibility("default"))) TS_ChannelMessageHandler_handle_closing_signed(uint32_t this_arg, int8_tArray their_node_id, uint32_t msg) {
3763         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
3764         LDKPublicKey their_node_id_ref;
3765         CHECK(*((uint32_t*)their_node_id) == 33);
3766         memcpy(their_node_id_ref.compressed_form, (uint8_t*)(their_node_id + 4), 33);
3767         LDKClosingSigned msg_conv;
3768         msg_conv.inner = (void*)(msg & (~1));
3769         msg_conv.is_owned = false;
3770         (this_arg_conv->handle_closing_signed)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
3771 }
3772
3773 void  __attribute__((visibility("default"))) TS_ChannelMessageHandler_handle_update_add_htlc(uint32_t this_arg, int8_tArray their_node_id, uint32_t msg) {
3774         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
3775         LDKPublicKey their_node_id_ref;
3776         CHECK(*((uint32_t*)their_node_id) == 33);
3777         memcpy(their_node_id_ref.compressed_form, (uint8_t*)(their_node_id + 4), 33);
3778         LDKUpdateAddHTLC msg_conv;
3779         msg_conv.inner = (void*)(msg & (~1));
3780         msg_conv.is_owned = false;
3781         (this_arg_conv->handle_update_add_htlc)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
3782 }
3783
3784 void  __attribute__((visibility("default"))) TS_ChannelMessageHandler_handle_update_fulfill_htlc(uint32_t this_arg, int8_tArray their_node_id, uint32_t msg) {
3785         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
3786         LDKPublicKey their_node_id_ref;
3787         CHECK(*((uint32_t*)their_node_id) == 33);
3788         memcpy(their_node_id_ref.compressed_form, (uint8_t*)(their_node_id + 4), 33);
3789         LDKUpdateFulfillHTLC msg_conv;
3790         msg_conv.inner = (void*)(msg & (~1));
3791         msg_conv.is_owned = false;
3792         (this_arg_conv->handle_update_fulfill_htlc)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
3793 }
3794
3795 void  __attribute__((visibility("default"))) TS_ChannelMessageHandler_handle_update_fail_htlc(uint32_t this_arg, int8_tArray their_node_id, uint32_t msg) {
3796         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
3797         LDKPublicKey their_node_id_ref;
3798         CHECK(*((uint32_t*)their_node_id) == 33);
3799         memcpy(their_node_id_ref.compressed_form, (uint8_t*)(their_node_id + 4), 33);
3800         LDKUpdateFailHTLC msg_conv;
3801         msg_conv.inner = (void*)(msg & (~1));
3802         msg_conv.is_owned = false;
3803         (this_arg_conv->handle_update_fail_htlc)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
3804 }
3805
3806 void  __attribute__((visibility("default"))) TS_ChannelMessageHandler_handle_update_fail_malformed_htlc(uint32_t this_arg, int8_tArray their_node_id, uint32_t msg) {
3807         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
3808         LDKPublicKey their_node_id_ref;
3809         CHECK(*((uint32_t*)their_node_id) == 33);
3810         memcpy(their_node_id_ref.compressed_form, (uint8_t*)(their_node_id + 4), 33);
3811         LDKUpdateFailMalformedHTLC msg_conv;
3812         msg_conv.inner = (void*)(msg & (~1));
3813         msg_conv.is_owned = false;
3814         (this_arg_conv->handle_update_fail_malformed_htlc)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
3815 }
3816
3817 void  __attribute__((visibility("default"))) TS_ChannelMessageHandler_handle_commitment_signed(uint32_t this_arg, int8_tArray their_node_id, uint32_t msg) {
3818         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
3819         LDKPublicKey their_node_id_ref;
3820         CHECK(*((uint32_t*)their_node_id) == 33);
3821         memcpy(their_node_id_ref.compressed_form, (uint8_t*)(their_node_id + 4), 33);
3822         LDKCommitmentSigned msg_conv;
3823         msg_conv.inner = (void*)(msg & (~1));
3824         msg_conv.is_owned = false;
3825         (this_arg_conv->handle_commitment_signed)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
3826 }
3827
3828 void  __attribute__((visibility("default"))) TS_ChannelMessageHandler_handle_revoke_and_ack(uint32_t this_arg, int8_tArray their_node_id, uint32_t msg) {
3829         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
3830         LDKPublicKey their_node_id_ref;
3831         CHECK(*((uint32_t*)their_node_id) == 33);
3832         memcpy(their_node_id_ref.compressed_form, (uint8_t*)(their_node_id + 4), 33);
3833         LDKRevokeAndACK msg_conv;
3834         msg_conv.inner = (void*)(msg & (~1));
3835         msg_conv.is_owned = false;
3836         (this_arg_conv->handle_revoke_and_ack)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
3837 }
3838
3839 void  __attribute__((visibility("default"))) TS_ChannelMessageHandler_handle_update_fee(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         LDKUpdateFee msg_conv;
3845         msg_conv.inner = (void*)(msg & (~1));
3846         msg_conv.is_owned = false;
3847         (this_arg_conv->handle_update_fee)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
3848 }
3849
3850 void  __attribute__((visibility("default"))) TS_ChannelMessageHandler_handle_announcement_signatures(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         LDKAnnouncementSignatures msg_conv;
3856         msg_conv.inner = (void*)(msg & (~1));
3857         msg_conv.is_owned = false;
3858         (this_arg_conv->handle_announcement_signatures)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
3859 }
3860
3861 void  __attribute__((visibility("default"))) TS_ChannelMessageHandler_peer_disconnected(uint32_t this_arg, int8_tArray their_node_id, jboolean no_connection_possible) {
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         (this_arg_conv->peer_disconnected)(this_arg_conv->this_arg, their_node_id_ref, no_connection_possible);
3867 }
3868
3869 void  __attribute__((visibility("default"))) TS_ChannelMessageHandler_peer_connected(uint32_t this_arg, int8_tArray their_node_id, uint32_t msg) {
3870         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
3871         LDKPublicKey their_node_id_ref;
3872         CHECK(*((uint32_t*)their_node_id) == 33);
3873         memcpy(their_node_id_ref.compressed_form, (uint8_t*)(their_node_id + 4), 33);
3874         LDKInit msg_conv;
3875         msg_conv.inner = (void*)(msg & (~1));
3876         msg_conv.is_owned = false;
3877         (this_arg_conv->peer_connected)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
3878 }
3879
3880 void  __attribute__((visibility("default"))) TS_ChannelMessageHandler_handle_channel_reestablish(uint32_t this_arg, int8_tArray their_node_id, uint32_t msg) {
3881         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
3882         LDKPublicKey their_node_id_ref;
3883         CHECK(*((uint32_t*)their_node_id) == 33);
3884         memcpy(their_node_id_ref.compressed_form, (uint8_t*)(their_node_id + 4), 33);
3885         LDKChannelReestablish msg_conv;
3886         msg_conv.inner = (void*)(msg & (~1));
3887         msg_conv.is_owned = false;
3888         (this_arg_conv->handle_channel_reestablish)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
3889 }
3890
3891 void  __attribute__((visibility("default"))) TS_ChannelMessageHandler_handle_error(uint32_t this_arg, int8_tArray their_node_id, uint32_t msg) {
3892         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
3893         LDKPublicKey their_node_id_ref;
3894         CHECK(*((uint32_t*)their_node_id) == 33);
3895         memcpy(their_node_id_ref.compressed_form, (uint8_t*)(their_node_id + 4), 33);
3896         LDKErrorMessage msg_conv;
3897         msg_conv.inner = (void*)(msg & (~1));
3898         msg_conv.is_owned = false;
3899         (this_arg_conv->handle_error)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
3900 }
3901
3902 typedef struct LDKRoutingMessageHandler_JCalls {
3903         atomic_size_t refcnt;
3904         LDKMessageSendEventsProvider_JCalls* MessageSendEventsProvider;
3905         uint32_t handle_node_announcement_meth;
3906         uint32_t handle_channel_announcement_meth;
3907         uint32_t handle_channel_update_meth;
3908         uint32_t handle_htlc_fail_channel_update_meth;
3909         uint32_t get_next_channel_announcements_meth;
3910         uint32_t get_next_node_announcements_meth;
3911         uint32_t sync_routing_table_meth;
3912         uint32_t handle_reply_channel_range_meth;
3913         uint32_t handle_reply_short_channel_ids_end_meth;
3914         uint32_t handle_query_channel_range_meth;
3915         uint32_t handle_query_short_channel_ids_meth;
3916 } LDKRoutingMessageHandler_JCalls;
3917 static void LDKRoutingMessageHandler_JCalls_free(void* this_arg) {
3918         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
3919         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
3920                 js_free(j_calls->handle_node_announcement_meth);
3921                 js_free(j_calls->handle_channel_announcement_meth);
3922                 js_free(j_calls->handle_channel_update_meth);
3923                 js_free(j_calls->handle_htlc_fail_channel_update_meth);
3924                 js_free(j_calls->get_next_channel_announcements_meth);
3925                 js_free(j_calls->get_next_node_announcements_meth);
3926                 js_free(j_calls->sync_routing_table_meth);
3927                 js_free(j_calls->handle_reply_channel_range_meth);
3928                 js_free(j_calls->handle_reply_short_channel_ids_end_meth);
3929                 js_free(j_calls->handle_query_channel_range_meth);
3930                 js_free(j_calls->handle_query_short_channel_ids_meth);
3931                 FREE(j_calls);
3932         }
3933 }
3934 LDKCResult_boolLightningErrorZ handle_node_announcement_jcall(const void* this_arg, const LDKNodeAnnouncement * msg) {
3935         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
3936         LDKNodeAnnouncement msg_var = *msg;
3937         msg_var = NodeAnnouncement_clone(msg);
3938         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3939         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3940         long msg_ref = (long)msg_var.inner;
3941         if (msg_var.is_owned) {
3942                 msg_ref |= 1;
3943         }
3944         LDKCResult_boolLightningErrorZ* ret = (LDKCResult_boolLightningErrorZ*)js_invoke_function_1(j_calls->handle_node_announcement_meth, msg_ref);
3945         LDKCResult_boolLightningErrorZ ret_conv = *(LDKCResult_boolLightningErrorZ*)(((uint64_t)ret) & ~1);
3946         ret_conv = CResult_boolLightningErrorZ_clone((LDKCResult_boolLightningErrorZ*)ret);
3947         return ret_conv;
3948 }
3949 LDKCResult_boolLightningErrorZ handle_channel_announcement_jcall(const void* this_arg, const LDKChannelAnnouncement * msg) {
3950         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
3951         LDKChannelAnnouncement msg_var = *msg;
3952         msg_var = ChannelAnnouncement_clone(msg);
3953         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3954         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3955         long msg_ref = (long)msg_var.inner;
3956         if (msg_var.is_owned) {
3957                 msg_ref |= 1;
3958         }
3959         LDKCResult_boolLightningErrorZ* ret = (LDKCResult_boolLightningErrorZ*)js_invoke_function_1(j_calls->handle_channel_announcement_meth, msg_ref);
3960         LDKCResult_boolLightningErrorZ ret_conv = *(LDKCResult_boolLightningErrorZ*)(((uint64_t)ret) & ~1);
3961         ret_conv = CResult_boolLightningErrorZ_clone((LDKCResult_boolLightningErrorZ*)ret);
3962         return ret_conv;
3963 }
3964 LDKCResult_boolLightningErrorZ handle_channel_update_jcall(const void* this_arg, const LDKChannelUpdate * msg) {
3965         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
3966         LDKChannelUpdate msg_var = *msg;
3967         msg_var = ChannelUpdate_clone(msg);
3968         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3969         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3970         long msg_ref = (long)msg_var.inner;
3971         if (msg_var.is_owned) {
3972                 msg_ref |= 1;
3973         }
3974         LDKCResult_boolLightningErrorZ* ret = (LDKCResult_boolLightningErrorZ*)js_invoke_function_1(j_calls->handle_channel_update_meth, msg_ref);
3975         LDKCResult_boolLightningErrorZ ret_conv = *(LDKCResult_boolLightningErrorZ*)(((uint64_t)ret) & ~1);
3976         ret_conv = CResult_boolLightningErrorZ_clone((LDKCResult_boolLightningErrorZ*)ret);
3977         return ret_conv;
3978 }
3979 void handle_htlc_fail_channel_update_jcall(const void* this_arg, const LDKHTLCFailChannelUpdate * update) {
3980         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
3981         long ret_update = (long)update;
3982         js_invoke_function_1(j_calls->handle_htlc_fail_channel_update_meth, ret_update);
3983 }
3984 LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ get_next_channel_announcements_jcall(const void* this_arg, uint64_t starting_point, uint8_t batch_amount) {
3985         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
3986         uint32_tArray arg = js_invoke_function_2(j_calls->get_next_channel_announcements_meth, starting_point, batch_amount);
3987         LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ arg_constr;
3988         arg_constr.datalen = *((uint32_t*)arg);
3989         if (arg_constr.datalen > 0)
3990                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ), "LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ Elements");
3991         else
3992                 arg_constr.data = NULL;
3993         uint32_t* arg_vals = (uint32_t*)(arg + 4);
3994         for (size_t l = 0; l < arg_constr.datalen; l++) {
3995                 uint32_t arr_conv_63 = arg_vals[l];
3996                 LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ arr_conv_63_conv = *(LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ*)(((uint64_t)arr_conv_63) & ~1);
3997                 FREE((void*)arr_conv_63);
3998                 arg_constr.data[l] = arr_conv_63_conv;
3999         }
4000         return arg_constr;
4001 }
4002 LDKCVec_NodeAnnouncementZ get_next_node_announcements_jcall(const void* this_arg, LDKPublicKey starting_point, uint8_t batch_amount) {
4003         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
4004         int8_tArray starting_point_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
4005         memcpy((uint8_t*)(starting_point_arr + 4), starting_point.compressed_form, 33);
4006         uint32_tArray arg = js_invoke_function_2(j_calls->get_next_node_announcements_meth, starting_point_arr, batch_amount);
4007         LDKCVec_NodeAnnouncementZ arg_constr;
4008         arg_constr.datalen = *((uint32_t*)arg);
4009         if (arg_constr.datalen > 0)
4010                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKNodeAnnouncement), "LDKCVec_NodeAnnouncementZ Elements");
4011         else
4012                 arg_constr.data = NULL;
4013         uint32_t* arg_vals = (uint32_t*)(arg + 4);
4014         for (size_t s = 0; s < arg_constr.datalen; s++) {
4015                 uint32_t arr_conv_18 = arg_vals[s];
4016                 LDKNodeAnnouncement arr_conv_18_conv;
4017                 arr_conv_18_conv.inner = (void*)(arr_conv_18 & (~1));
4018                 arr_conv_18_conv.is_owned = (arr_conv_18 & 1) || (arr_conv_18 == 0);
4019                 arr_conv_18_conv = NodeAnnouncement_clone(&arr_conv_18_conv);
4020                 arg_constr.data[s] = arr_conv_18_conv;
4021         }
4022         return arg_constr;
4023 }
4024 void sync_routing_table_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKInit * init) {
4025         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
4026         int8_tArray their_node_id_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
4027         memcpy((uint8_t*)(their_node_id_arr + 4), their_node_id.compressed_form, 33);
4028         LDKInit init_var = *init;
4029         init_var = Init_clone(init);
4030         CHECK((((long)init_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4031         CHECK((((long)&init_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4032         long init_ref = (long)init_var.inner;
4033         if (init_var.is_owned) {
4034                 init_ref |= 1;
4035         }
4036         js_invoke_function_2(j_calls->sync_routing_table_meth, their_node_id_arr, init_ref);
4037 }
4038 LDKCResult_NoneLightningErrorZ handle_reply_channel_range_jcall(const void* this_arg, LDKPublicKey their_node_id, LDKReplyChannelRange msg) {
4039         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
4040         int8_tArray their_node_id_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
4041         memcpy((uint8_t*)(their_node_id_arr + 4), their_node_id.compressed_form, 33);
4042         LDKReplyChannelRange msg_var = msg;
4043         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4044         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4045         long msg_ref = (long)msg_var.inner;
4046         if (msg_var.is_owned) {
4047                 msg_ref |= 1;
4048         }
4049         LDKCResult_NoneLightningErrorZ* ret = (LDKCResult_NoneLightningErrorZ*)js_invoke_function_2(j_calls->handle_reply_channel_range_meth, their_node_id_arr, msg_ref);
4050         LDKCResult_NoneLightningErrorZ ret_conv = *(LDKCResult_NoneLightningErrorZ*)(((uint64_t)ret) & ~1);
4051         ret_conv = CResult_NoneLightningErrorZ_clone((LDKCResult_NoneLightningErrorZ*)ret);
4052         return ret_conv;
4053 }
4054 LDKCResult_NoneLightningErrorZ handle_reply_short_channel_ids_end_jcall(const void* this_arg, LDKPublicKey their_node_id, LDKReplyShortChannelIdsEnd msg) {
4055         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
4056         int8_tArray their_node_id_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
4057         memcpy((uint8_t*)(their_node_id_arr + 4), their_node_id.compressed_form, 33);
4058         LDKReplyShortChannelIdsEnd msg_var = msg;
4059         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4060         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4061         long msg_ref = (long)msg_var.inner;
4062         if (msg_var.is_owned) {
4063                 msg_ref |= 1;
4064         }
4065         LDKCResult_NoneLightningErrorZ* ret = (LDKCResult_NoneLightningErrorZ*)js_invoke_function_2(j_calls->handle_reply_short_channel_ids_end_meth, their_node_id_arr, msg_ref);
4066         LDKCResult_NoneLightningErrorZ ret_conv = *(LDKCResult_NoneLightningErrorZ*)(((uint64_t)ret) & ~1);
4067         ret_conv = CResult_NoneLightningErrorZ_clone((LDKCResult_NoneLightningErrorZ*)ret);
4068         return ret_conv;
4069 }
4070 LDKCResult_NoneLightningErrorZ handle_query_channel_range_jcall(const void* this_arg, LDKPublicKey their_node_id, LDKQueryChannelRange msg) {
4071         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
4072         int8_tArray their_node_id_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
4073         memcpy((uint8_t*)(their_node_id_arr + 4), their_node_id.compressed_form, 33);
4074         LDKQueryChannelRange msg_var = msg;
4075         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4076         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4077         long msg_ref = (long)msg_var.inner;
4078         if (msg_var.is_owned) {
4079                 msg_ref |= 1;
4080         }
4081         LDKCResult_NoneLightningErrorZ* ret = (LDKCResult_NoneLightningErrorZ*)js_invoke_function_2(j_calls->handle_query_channel_range_meth, their_node_id_arr, msg_ref);
4082         LDKCResult_NoneLightningErrorZ ret_conv = *(LDKCResult_NoneLightningErrorZ*)(((uint64_t)ret) & ~1);
4083         ret_conv = CResult_NoneLightningErrorZ_clone((LDKCResult_NoneLightningErrorZ*)ret);
4084         return ret_conv;
4085 }
4086 LDKCResult_NoneLightningErrorZ handle_query_short_channel_ids_jcall(const void* this_arg, LDKPublicKey their_node_id, LDKQueryShortChannelIds msg) {
4087         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
4088         int8_tArray their_node_id_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
4089         memcpy((uint8_t*)(their_node_id_arr + 4), their_node_id.compressed_form, 33);
4090         LDKQueryShortChannelIds msg_var = msg;
4091         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4092         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4093         long msg_ref = (long)msg_var.inner;
4094         if (msg_var.is_owned) {
4095                 msg_ref |= 1;
4096         }
4097         LDKCResult_NoneLightningErrorZ* ret = (LDKCResult_NoneLightningErrorZ*)js_invoke_function_2(j_calls->handle_query_short_channel_ids_meth, their_node_id_arr, msg_ref);
4098         LDKCResult_NoneLightningErrorZ ret_conv = *(LDKCResult_NoneLightningErrorZ*)(((uint64_t)ret) & ~1);
4099         ret_conv = CResult_NoneLightningErrorZ_clone((LDKCResult_NoneLightningErrorZ*)ret);
4100         return ret_conv;
4101 }
4102 static void* LDKRoutingMessageHandler_JCalls_clone(const void* this_arg) {
4103         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
4104         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
4105         atomic_fetch_add_explicit(&j_calls->MessageSendEventsProvider->refcnt, 1, memory_order_release);
4106         return (void*) this_arg;
4107 }
4108 static inline LDKRoutingMessageHandler LDKRoutingMessageHandler_init (/*TODO: JS Object Reference */void* o, /*TODO: JS Object Reference */void* MessageSendEventsProvider) {
4109         LDKRoutingMessageHandler_JCalls *calls = MALLOC(sizeof(LDKRoutingMessageHandler_JCalls), "LDKRoutingMessageHandler_JCalls");
4110         atomic_init(&calls->refcnt, 1);
4111         //TODO: Assign calls->o from o
4112
4113         LDKRoutingMessageHandler ret = {
4114                 .this_arg = (void*) calls,
4115                 .handle_node_announcement = handle_node_announcement_jcall,
4116                 .handle_channel_announcement = handle_channel_announcement_jcall,
4117                 .handle_channel_update = handle_channel_update_jcall,
4118                 .handle_htlc_fail_channel_update = handle_htlc_fail_channel_update_jcall,
4119                 .get_next_channel_announcements = get_next_channel_announcements_jcall,
4120                 .get_next_node_announcements = get_next_node_announcements_jcall,
4121                 .sync_routing_table = sync_routing_table_jcall,
4122                 .handle_reply_channel_range = handle_reply_channel_range_jcall,
4123                 .handle_reply_short_channel_ids_end = handle_reply_short_channel_ids_end_jcall,
4124                 .handle_query_channel_range = handle_query_channel_range_jcall,
4125                 .handle_query_short_channel_ids = handle_query_short_channel_ids_jcall,
4126                 .free = LDKRoutingMessageHandler_JCalls_free,
4127                 .MessageSendEventsProvider = LDKMessageSendEventsProvider_init(MessageSendEventsProvider),
4128         };
4129         calls->MessageSendEventsProvider = ret.MessageSendEventsProvider.this_arg;
4130         return ret;
4131 }
4132 long  __attribute__((visibility("default"))) TS_LDKRoutingMessageHandler_new(/*TODO: JS Object Reference */void* o, /*TODO: JS Object Reference */ void* MessageSendEventsProvider) {
4133         LDKRoutingMessageHandler *res_ptr = MALLOC(sizeof(LDKRoutingMessageHandler), "LDKRoutingMessageHandler");
4134         *res_ptr = LDKRoutingMessageHandler_init(o, MessageSendEventsProvider);
4135         return (long)res_ptr;
4136 }
4137 uint32_t  __attribute__((visibility("default"))) TS_RoutingMessageHandler_handle_node_announcement(uint32_t this_arg, uint32_t msg) {
4138         LDKRoutingMessageHandler* this_arg_conv = (LDKRoutingMessageHandler*)this_arg;
4139         LDKNodeAnnouncement msg_conv;
4140         msg_conv.inner = (void*)(msg & (~1));
4141         msg_conv.is_owned = false;
4142         LDKCResult_boolLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_boolLightningErrorZ), "LDKCResult_boolLightningErrorZ");
4143         *ret_conv = (this_arg_conv->handle_node_announcement)(this_arg_conv->this_arg, &msg_conv);
4144         return (long)ret_conv;
4145 }
4146
4147 uint32_t  __attribute__((visibility("default"))) TS_RoutingMessageHandler_handle_channel_announcement(uint32_t this_arg, uint32_t msg) {
4148         LDKRoutingMessageHandler* this_arg_conv = (LDKRoutingMessageHandler*)this_arg;
4149         LDKChannelAnnouncement msg_conv;
4150         msg_conv.inner = (void*)(msg & (~1));
4151         msg_conv.is_owned = false;
4152         LDKCResult_boolLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_boolLightningErrorZ), "LDKCResult_boolLightningErrorZ");
4153         *ret_conv = (this_arg_conv->handle_channel_announcement)(this_arg_conv->this_arg, &msg_conv);
4154         return (long)ret_conv;
4155 }
4156
4157 uint32_t  __attribute__((visibility("default"))) TS_RoutingMessageHandler_handle_channel_update(uint32_t this_arg, uint32_t msg) {
4158         LDKRoutingMessageHandler* this_arg_conv = (LDKRoutingMessageHandler*)this_arg;
4159         LDKChannelUpdate msg_conv;
4160         msg_conv.inner = (void*)(msg & (~1));
4161         msg_conv.is_owned = false;
4162         LDKCResult_boolLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_boolLightningErrorZ), "LDKCResult_boolLightningErrorZ");
4163         *ret_conv = (this_arg_conv->handle_channel_update)(this_arg_conv->this_arg, &msg_conv);
4164         return (long)ret_conv;
4165 }
4166
4167 void  __attribute__((visibility("default"))) TS_RoutingMessageHandler_handle_htlc_fail_channel_update(uint32_t this_arg, uint32_t update) {
4168         LDKRoutingMessageHandler* this_arg_conv = (LDKRoutingMessageHandler*)this_arg;
4169         LDKHTLCFailChannelUpdate* update_conv = (LDKHTLCFailChannelUpdate*)update;
4170         (this_arg_conv->handle_htlc_fail_channel_update)(this_arg_conv->this_arg, update_conv);
4171 }
4172
4173 uint32_tArray  __attribute__((visibility("default"))) TS_RoutingMessageHandler_get_next_channel_announcements(uint32_t this_arg, int64_t starting_point, int8_t batch_amount) {
4174         LDKRoutingMessageHandler* this_arg_conv = (LDKRoutingMessageHandler*)this_arg;
4175         LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ ret_var = (this_arg_conv->get_next_channel_announcements)(this_arg_conv->this_arg, starting_point, batch_amount);
4176         uint32_tArray ret_arr = init_arr(ret_var.datalen, sizeof(uint32_t), "Native uint32_tArray Bytes");
4177         uint32_t *ret_arr_ptr = (uint32_t*)(ret_arr + 4);
4178         for (size_t l = 0; l < ret_var.datalen; l++) {
4179                 LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ* arr_conv_63_ref = MALLOC(sizeof(LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ), "LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ");
4180                 *arr_conv_63_ref = ret_var.data[l];
4181                 ret_arr_ptr[l] = (long)arr_conv_63_ref;
4182         }
4183         FREE(ret_var.data);
4184         return ret_arr;
4185 }
4186
4187 uint32_tArray  __attribute__((visibility("default"))) TS_RoutingMessageHandler_get_next_node_announcements(uint32_t this_arg, int8_tArray starting_point, int8_t batch_amount) {
4188         LDKRoutingMessageHandler* this_arg_conv = (LDKRoutingMessageHandler*)this_arg;
4189         LDKPublicKey starting_point_ref;
4190         CHECK(*((uint32_t*)starting_point) == 33);
4191         memcpy(starting_point_ref.compressed_form, (uint8_t*)(starting_point + 4), 33);
4192         LDKCVec_NodeAnnouncementZ ret_var = (this_arg_conv->get_next_node_announcements)(this_arg_conv->this_arg, starting_point_ref, batch_amount);
4193         uint32_tArray ret_arr = init_arr(ret_var.datalen, sizeof(uint32_t), "Native uint32_tArray Bytes");
4194         uint32_t *ret_arr_ptr = (uint32_t*)(ret_arr + 4);
4195         for (size_t s = 0; s < ret_var.datalen; s++) {
4196                 LDKNodeAnnouncement arr_conv_18_var = ret_var.data[s];
4197                 CHECK((((long)arr_conv_18_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4198                 CHECK((((long)&arr_conv_18_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4199                 long arr_conv_18_ref = (long)arr_conv_18_var.inner;
4200                 if (arr_conv_18_var.is_owned) {
4201                         arr_conv_18_ref |= 1;
4202                 }
4203                 ret_arr_ptr[s] = arr_conv_18_ref;
4204         }
4205         FREE(ret_var.data);
4206         return ret_arr;
4207 }
4208
4209 void  __attribute__((visibility("default"))) TS_RoutingMessageHandler_sync_routing_table(uint32_t this_arg, int8_tArray their_node_id, uint32_t init) {
4210         LDKRoutingMessageHandler* this_arg_conv = (LDKRoutingMessageHandler*)this_arg;
4211         LDKPublicKey their_node_id_ref;
4212         CHECK(*((uint32_t*)their_node_id) == 33);
4213         memcpy(their_node_id_ref.compressed_form, (uint8_t*)(their_node_id + 4), 33);
4214         LDKInit init_conv;
4215         init_conv.inner = (void*)(init & (~1));
4216         init_conv.is_owned = false;
4217         (this_arg_conv->sync_routing_table)(this_arg_conv->this_arg, their_node_id_ref, &init_conv);
4218 }
4219
4220 uint32_t  __attribute__((visibility("default"))) TS_RoutingMessageHandler_handle_reply_channel_range(uint32_t this_arg, int8_tArray their_node_id, uint32_t msg) {
4221         LDKRoutingMessageHandler* this_arg_conv = (LDKRoutingMessageHandler*)this_arg;
4222         LDKPublicKey their_node_id_ref;
4223         CHECK(*((uint32_t*)their_node_id) == 33);
4224         memcpy(their_node_id_ref.compressed_form, (uint8_t*)(their_node_id + 4), 33);
4225         LDKReplyChannelRange msg_conv;
4226         msg_conv.inner = (void*)(msg & (~1));
4227         msg_conv.is_owned = (msg & 1) || (msg == 0);
4228         msg_conv = ReplyChannelRange_clone(&msg_conv);
4229         LDKCResult_NoneLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneLightningErrorZ), "LDKCResult_NoneLightningErrorZ");
4230         *ret_conv = (this_arg_conv->handle_reply_channel_range)(this_arg_conv->this_arg, their_node_id_ref, msg_conv);
4231         return (long)ret_conv;
4232 }
4233
4234 uint32_t  __attribute__((visibility("default"))) TS_RoutingMessageHandler_handle_reply_short_channel_ids_end(uint32_t this_arg, int8_tArray their_node_id, uint32_t msg) {
4235         LDKRoutingMessageHandler* this_arg_conv = (LDKRoutingMessageHandler*)this_arg;
4236         LDKPublicKey their_node_id_ref;
4237         CHECK(*((uint32_t*)their_node_id) == 33);
4238         memcpy(their_node_id_ref.compressed_form, (uint8_t*)(their_node_id + 4), 33);
4239         LDKReplyShortChannelIdsEnd msg_conv;
4240         msg_conv.inner = (void*)(msg & (~1));
4241         msg_conv.is_owned = (msg & 1) || (msg == 0);
4242         msg_conv = ReplyShortChannelIdsEnd_clone(&msg_conv);
4243         LDKCResult_NoneLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneLightningErrorZ), "LDKCResult_NoneLightningErrorZ");
4244         *ret_conv = (this_arg_conv->handle_reply_short_channel_ids_end)(this_arg_conv->this_arg, their_node_id_ref, msg_conv);
4245         return (long)ret_conv;
4246 }
4247
4248 uint32_t  __attribute__((visibility("default"))) TS_RoutingMessageHandler_handle_query_channel_range(uint32_t this_arg, int8_tArray their_node_id, uint32_t msg) {
4249         LDKRoutingMessageHandler* this_arg_conv = (LDKRoutingMessageHandler*)this_arg;
4250         LDKPublicKey their_node_id_ref;
4251         CHECK(*((uint32_t*)their_node_id) == 33);
4252         memcpy(their_node_id_ref.compressed_form, (uint8_t*)(their_node_id + 4), 33);
4253         LDKQueryChannelRange msg_conv;
4254         msg_conv.inner = (void*)(msg & (~1));
4255         msg_conv.is_owned = (msg & 1) || (msg == 0);
4256         msg_conv = QueryChannelRange_clone(&msg_conv);
4257         LDKCResult_NoneLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneLightningErrorZ), "LDKCResult_NoneLightningErrorZ");
4258         *ret_conv = (this_arg_conv->handle_query_channel_range)(this_arg_conv->this_arg, their_node_id_ref, msg_conv);
4259         return (long)ret_conv;
4260 }
4261
4262 uint32_t  __attribute__((visibility("default"))) TS_RoutingMessageHandler_handle_query_short_channel_ids(uint32_t this_arg, int8_tArray their_node_id, uint32_t msg) {
4263         LDKRoutingMessageHandler* this_arg_conv = (LDKRoutingMessageHandler*)this_arg;
4264         LDKPublicKey their_node_id_ref;
4265         CHECK(*((uint32_t*)their_node_id) == 33);
4266         memcpy(their_node_id_ref.compressed_form, (uint8_t*)(their_node_id + 4), 33);
4267         LDKQueryShortChannelIds msg_conv;
4268         msg_conv.inner = (void*)(msg & (~1));
4269         msg_conv.is_owned = (msg & 1) || (msg == 0);
4270         msg_conv = QueryShortChannelIds_clone(&msg_conv);
4271         LDKCResult_NoneLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneLightningErrorZ), "LDKCResult_NoneLightningErrorZ");
4272         *ret_conv = (this_arg_conv->handle_query_short_channel_ids)(this_arg_conv->this_arg, their_node_id_ref, msg_conv);
4273         return (long)ret_conv;
4274 }
4275
4276 typedef struct LDKSocketDescriptor_JCalls {
4277         atomic_size_t refcnt;
4278         uint32_t send_data_meth;
4279         uint32_t disconnect_socket_meth;
4280         uint32_t eq_meth;
4281         uint32_t hash_meth;
4282 } LDKSocketDescriptor_JCalls;
4283 static void LDKSocketDescriptor_JCalls_free(void* this_arg) {
4284         LDKSocketDescriptor_JCalls *j_calls = (LDKSocketDescriptor_JCalls*) this_arg;
4285         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
4286                 js_free(j_calls->send_data_meth);
4287                 js_free(j_calls->disconnect_socket_meth);
4288                 js_free(j_calls->eq_meth);
4289                 js_free(j_calls->hash_meth);
4290                 FREE(j_calls);
4291         }
4292 }
4293 uintptr_t send_data_jcall(void* this_arg, LDKu8slice data, bool resume_read) {
4294         LDKSocketDescriptor_JCalls *j_calls = (LDKSocketDescriptor_JCalls*) this_arg;
4295         LDKu8slice data_var = data;
4296         int8_tArray data_arr = init_arr(data_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
4297         memcpy((uint8_t*)(data_arr + 4), data_var.data, data_var.datalen);
4298         return js_invoke_function_2(j_calls->send_data_meth, data_arr, resume_read);
4299 }
4300 void disconnect_socket_jcall(void* this_arg) {
4301         LDKSocketDescriptor_JCalls *j_calls = (LDKSocketDescriptor_JCalls*) this_arg;
4302         js_invoke_function_0(j_calls->disconnect_socket_meth);
4303 }
4304 bool eq_jcall(const void* this_arg, const LDKSocketDescriptor * other_arg) {
4305         LDKSocketDescriptor_JCalls *j_calls = (LDKSocketDescriptor_JCalls*) this_arg;
4306         LDKSocketDescriptor *other_arg_clone = MALLOC(sizeof(LDKSocketDescriptor), "LDKSocketDescriptor");
4307         *other_arg_clone = SocketDescriptor_clone(other_arg);
4308         return js_invoke_function_1(j_calls->eq_meth, (long)other_arg_clone);
4309 }
4310 uint64_t hash_jcall(const void* this_arg) {
4311         LDKSocketDescriptor_JCalls *j_calls = (LDKSocketDescriptor_JCalls*) this_arg;
4312         return js_invoke_function_0(j_calls->hash_meth);
4313 }
4314 static void* LDKSocketDescriptor_JCalls_clone(const void* this_arg) {
4315         LDKSocketDescriptor_JCalls *j_calls = (LDKSocketDescriptor_JCalls*) this_arg;
4316         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
4317         return (void*) this_arg;
4318 }
4319 static inline LDKSocketDescriptor LDKSocketDescriptor_init (/*TODO: JS Object Reference */void* o) {
4320         LDKSocketDescriptor_JCalls *calls = MALLOC(sizeof(LDKSocketDescriptor_JCalls), "LDKSocketDescriptor_JCalls");
4321         atomic_init(&calls->refcnt, 1);
4322         //TODO: Assign calls->o from o
4323
4324         LDKSocketDescriptor ret = {
4325                 .this_arg = (void*) calls,
4326                 .send_data = send_data_jcall,
4327                 .disconnect_socket = disconnect_socket_jcall,
4328                 .eq = eq_jcall,
4329                 .hash = hash_jcall,
4330                 .clone = LDKSocketDescriptor_JCalls_clone,
4331                 .free = LDKSocketDescriptor_JCalls_free,
4332         };
4333         return ret;
4334 }
4335 long  __attribute__((visibility("default"))) TS_LDKSocketDescriptor_new(/*TODO: JS Object Reference */void* o) {
4336         LDKSocketDescriptor *res_ptr = MALLOC(sizeof(LDKSocketDescriptor), "LDKSocketDescriptor");
4337         *res_ptr = LDKSocketDescriptor_init(o);
4338         return (long)res_ptr;
4339 }
4340 intptr_t  __attribute__((visibility("default"))) TS_SocketDescriptor_send_data(uint32_t this_arg, int8_tArray data, jboolean resume_read) {
4341         LDKSocketDescriptor* this_arg_conv = (LDKSocketDescriptor*)this_arg;
4342         LDKu8slice data_ref;
4343         data_ref.datalen = *((uint32_t*)data);
4344         data_ref.data = (int8_t*)(data + 4);
4345         intptr_t ret_val = (this_arg_conv->send_data)(this_arg_conv->this_arg, data_ref, resume_read);
4346         return ret_val;
4347 }
4348
4349 void  __attribute__((visibility("default"))) TS_SocketDescriptor_disconnect_socket(uint32_t this_arg) {
4350         LDKSocketDescriptor* this_arg_conv = (LDKSocketDescriptor*)this_arg;
4351         (this_arg_conv->disconnect_socket)(this_arg_conv->this_arg);
4352 }
4353
4354 int64_t  __attribute__((visibility("default"))) TS_SocketDescriptor_hash(uint32_t this_arg) {
4355         LDKSocketDescriptor* this_arg_conv = (LDKSocketDescriptor*)this_arg;
4356         int64_t ret_val = (this_arg_conv->hash)(this_arg_conv->this_arg);
4357         return ret_val;
4358 }
4359
4360 void  __attribute__((visibility("default"))) TS_Transaction_free(int8_tArray _res) {
4361         LDKTransaction _res_ref;
4362         _res_ref.datalen = *((uint32_t*)_res);
4363         _res_ref.data = MALLOC(_res_ref.datalen, "LDKTransaction Bytes");
4364         memcpy(_res_ref.data, (uint8_t*)(_res + 4), _res_ref.datalen);
4365         _res_ref.data_is_owned = true;
4366         Transaction_free(_res_ref);
4367 }
4368
4369 void  __attribute__((visibility("default"))) TS_TxOut_free(uint32_t _res) {
4370         if ((_res & 1) != 0) return;
4371         LDKTxOut _res_conv = *(LDKTxOut*)(((uint64_t)_res) & ~1);
4372         FREE((void*)_res);
4373         TxOut_free(_res_conv);
4374 }
4375
4376 uint32_t  __attribute__((visibility("default"))) TS_TxOut_clone(uint32_t orig) {
4377         LDKTxOut* orig_conv = (LDKTxOut*)(orig & ~1);
4378         LDKTxOut* ret_ref = MALLOC(sizeof(LDKTxOut), "LDKTxOut");
4379         *ret_ref = TxOut_clone(orig_conv);
4380         return (long)ret_ref;
4381 }
4382
4383 void  __attribute__((visibility("default"))) TS_CVec_SpendableOutputDescriptorZ_free(uint32_tArray _res) {
4384         LDKCVec_SpendableOutputDescriptorZ _res_constr;
4385         _res_constr.datalen = *((uint32_t*)_res);
4386         if (_res_constr.datalen > 0)
4387                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKSpendableOutputDescriptor), "LDKCVec_SpendableOutputDescriptorZ Elements");
4388         else
4389                 _res_constr.data = NULL;
4390         uint32_t* _res_vals = (uint32_t*)(_res + 4);
4391         for (size_t b = 0; b < _res_constr.datalen; b++) {
4392                 uint32_t arr_conv_27 = _res_vals[b];
4393                 LDKSpendableOutputDescriptor arr_conv_27_conv = *(LDKSpendableOutputDescriptor*)(((uint64_t)arr_conv_27) & ~1);
4394                 FREE((void*)arr_conv_27);
4395                 _res_constr.data[b] = arr_conv_27_conv;
4396         }
4397         CVec_SpendableOutputDescriptorZ_free(_res_constr);
4398 }
4399
4400 void  __attribute__((visibility("default"))) TS_CVec_MessageSendEventZ_free(uint32_tArray _res) {
4401         LDKCVec_MessageSendEventZ _res_constr;
4402         _res_constr.datalen = *((uint32_t*)_res);
4403         if (_res_constr.datalen > 0)
4404                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKMessageSendEvent), "LDKCVec_MessageSendEventZ Elements");
4405         else
4406                 _res_constr.data = NULL;
4407         uint32_t* _res_vals = (uint32_t*)(_res + 4);
4408         for (size_t s = 0; s < _res_constr.datalen; s++) {
4409                 uint32_t arr_conv_18 = _res_vals[s];
4410                 LDKMessageSendEvent arr_conv_18_conv = *(LDKMessageSendEvent*)(((uint64_t)arr_conv_18) & ~1);
4411                 FREE((void*)arr_conv_18);
4412                 _res_constr.data[s] = arr_conv_18_conv;
4413         }
4414         CVec_MessageSendEventZ_free(_res_constr);
4415 }
4416
4417 void  __attribute__((visibility("default"))) TS_CVec_EventZ_free(uint32_tArray _res) {
4418         LDKCVec_EventZ _res_constr;
4419         _res_constr.datalen = *((uint32_t*)_res);
4420         if (_res_constr.datalen > 0)
4421                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKEvent), "LDKCVec_EventZ Elements");
4422         else
4423                 _res_constr.data = NULL;
4424         uint32_t* _res_vals = (uint32_t*)(_res + 4);
4425         for (size_t h = 0; h < _res_constr.datalen; h++) {
4426                 uint32_t arr_conv_7 = _res_vals[h];
4427                 LDKEvent arr_conv_7_conv = *(LDKEvent*)(((uint64_t)arr_conv_7) & ~1);
4428                 FREE((void*)arr_conv_7);
4429                 _res_constr.data[h] = arr_conv_7_conv;
4430         }
4431         CVec_EventZ_free(_res_constr);
4432 }
4433
4434 void  __attribute__((visibility("default"))) TS_C2Tuple_usizeTransactionZ_free(uint32_t _res) {
4435         if ((_res & 1) != 0) return;
4436         LDKC2Tuple_usizeTransactionZ _res_conv = *(LDKC2Tuple_usizeTransactionZ*)(((uint64_t)_res) & ~1);
4437         FREE((void*)_res);
4438         C2Tuple_usizeTransactionZ_free(_res_conv);
4439 }
4440
4441 uint32_t  __attribute__((visibility("default"))) TS_C2Tuple_usizeTransactionZ_new(intptr_t a, int8_tArray b) {
4442         LDKTransaction b_ref;
4443         b_ref.datalen = *((uint32_t*)b);
4444         b_ref.data = MALLOC(b_ref.datalen, "LDKTransaction Bytes");
4445         memcpy(b_ref.data, (uint8_t*)(b + 4), b_ref.datalen);
4446         b_ref.data_is_owned = true;
4447         LDKC2Tuple_usizeTransactionZ* ret_ref = MALLOC(sizeof(LDKC2Tuple_usizeTransactionZ), "LDKC2Tuple_usizeTransactionZ");
4448         *ret_ref = C2Tuple_usizeTransactionZ_new(a, b_ref);
4449         return (long)ret_ref;
4450 }
4451
4452 void  __attribute__((visibility("default"))) TS_CVec_C2Tuple_usizeTransactionZZ_free(uint32_tArray _res) {
4453         LDKCVec_C2Tuple_usizeTransactionZZ _res_constr;
4454         _res_constr.datalen = *((uint32_t*)_res);
4455         if (_res_constr.datalen > 0)
4456                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKC2Tuple_usizeTransactionZ), "LDKCVec_C2Tuple_usizeTransactionZZ Elements");
4457         else
4458                 _res_constr.data = NULL;
4459         uint32_t* _res_vals = (uint32_t*)(_res + 4);
4460         for (size_t e = 0; e < _res_constr.datalen; e++) {
4461                 uint32_t arr_conv_30 = _res_vals[e];
4462                 LDKC2Tuple_usizeTransactionZ arr_conv_30_conv = *(LDKC2Tuple_usizeTransactionZ*)(((uint64_t)arr_conv_30) & ~1);
4463                 FREE((void*)arr_conv_30);
4464                 _res_constr.data[e] = arr_conv_30_conv;
4465         }
4466         CVec_C2Tuple_usizeTransactionZZ_free(_res_constr);
4467 }
4468
4469 uint32_t  __attribute__((visibility("default"))) TS_CResult_NoneChannelMonitorUpdateErrZ_ok() {
4470         LDKCResult_NoneChannelMonitorUpdateErrZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneChannelMonitorUpdateErrZ), "LDKCResult_NoneChannelMonitorUpdateErrZ");
4471         *ret_conv = CResult_NoneChannelMonitorUpdateErrZ_ok();
4472         return (long)ret_conv;
4473 }
4474
4475 uint32_t  __attribute__((visibility("default"))) TS_CResult_NoneChannelMonitorUpdateErrZ_err(uint32_t e) {
4476         LDKChannelMonitorUpdateErr e_conv = LDKChannelMonitorUpdateErr_from_js(e);
4477         LDKCResult_NoneChannelMonitorUpdateErrZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneChannelMonitorUpdateErrZ), "LDKCResult_NoneChannelMonitorUpdateErrZ");
4478         *ret_conv = CResult_NoneChannelMonitorUpdateErrZ_err(e_conv);
4479         return (long)ret_conv;
4480 }
4481
4482 void  __attribute__((visibility("default"))) TS_CResult_NoneChannelMonitorUpdateErrZ_free(uint32_t _res) {
4483         if ((_res & 1) != 0) return;
4484         LDKCResult_NoneChannelMonitorUpdateErrZ _res_conv = *(LDKCResult_NoneChannelMonitorUpdateErrZ*)(((uint64_t)_res) & ~1);
4485         FREE((void*)_res);
4486         CResult_NoneChannelMonitorUpdateErrZ_free(_res_conv);
4487 }
4488
4489 uint32_t  __attribute__((visibility("default"))) TS_CResult_NoneChannelMonitorUpdateErrZ_clone(uint32_t orig) {
4490         LDKCResult_NoneChannelMonitorUpdateErrZ* orig_conv = (LDKCResult_NoneChannelMonitorUpdateErrZ*)(orig & ~1);
4491         LDKCResult_NoneChannelMonitorUpdateErrZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneChannelMonitorUpdateErrZ), "LDKCResult_NoneChannelMonitorUpdateErrZ");
4492         *ret_conv = CResult_NoneChannelMonitorUpdateErrZ_clone(orig_conv);
4493         return (long)ret_conv;
4494 }
4495
4496 void  __attribute__((visibility("default"))) TS_CVec_MonitorEventZ_free(uint32_tArray _res) {
4497         LDKCVec_MonitorEventZ _res_constr;
4498         _res_constr.datalen = *((uint32_t*)_res);
4499         if (_res_constr.datalen > 0)
4500                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKMonitorEvent), "LDKCVec_MonitorEventZ Elements");
4501         else
4502                 _res_constr.data = NULL;
4503         uint32_t* _res_vals = (uint32_t*)(_res + 4);
4504         for (size_t o = 0; o < _res_constr.datalen; o++) {
4505                 uint32_t arr_conv_14 = _res_vals[o];
4506                 LDKMonitorEvent arr_conv_14_conv;
4507                 arr_conv_14_conv.inner = (void*)(arr_conv_14 & (~1));
4508                 arr_conv_14_conv.is_owned = (arr_conv_14 & 1) || (arr_conv_14 == 0);
4509                 _res_constr.data[o] = arr_conv_14_conv;
4510         }
4511         CVec_MonitorEventZ_free(_res_constr);
4512 }
4513
4514 uint32_t  __attribute__((visibility("default"))) TS_CResult_ChannelMonitorUpdateDecodeErrorZ_ok(uint32_t o) {
4515         LDKChannelMonitorUpdate o_conv;
4516         o_conv.inner = (void*)(o & (~1));
4517         o_conv.is_owned = (o & 1) || (o == 0);
4518         o_conv = ChannelMonitorUpdate_clone(&o_conv);
4519         LDKCResult_ChannelMonitorUpdateDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ChannelMonitorUpdateDecodeErrorZ), "LDKCResult_ChannelMonitorUpdateDecodeErrorZ");
4520         *ret_conv = CResult_ChannelMonitorUpdateDecodeErrorZ_ok(o_conv);
4521         return (long)ret_conv;
4522 }
4523
4524 uint32_t  __attribute__((visibility("default"))) TS_CResult_ChannelMonitorUpdateDecodeErrorZ_err(uint32_t e) {
4525         LDKDecodeError e_conv;
4526         e_conv.inner = (void*)(e & (~1));
4527         e_conv.is_owned = (e & 1) || (e == 0);
4528         e_conv = DecodeError_clone(&e_conv);
4529         LDKCResult_ChannelMonitorUpdateDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ChannelMonitorUpdateDecodeErrorZ), "LDKCResult_ChannelMonitorUpdateDecodeErrorZ");
4530         *ret_conv = CResult_ChannelMonitorUpdateDecodeErrorZ_err(e_conv);
4531         return (long)ret_conv;
4532 }
4533
4534 void  __attribute__((visibility("default"))) TS_CResult_ChannelMonitorUpdateDecodeErrorZ_free(uint32_t _res) {
4535         if ((_res & 1) != 0) return;
4536         LDKCResult_ChannelMonitorUpdateDecodeErrorZ _res_conv = *(LDKCResult_ChannelMonitorUpdateDecodeErrorZ*)(((uint64_t)_res) & ~1);
4537         FREE((void*)_res);
4538         CResult_ChannelMonitorUpdateDecodeErrorZ_free(_res_conv);
4539 }
4540
4541 uint32_t  __attribute__((visibility("default"))) TS_CResult_NoneMonitorUpdateErrorZ_ok() {
4542         LDKCResult_NoneMonitorUpdateErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneMonitorUpdateErrorZ), "LDKCResult_NoneMonitorUpdateErrorZ");
4543         *ret_conv = CResult_NoneMonitorUpdateErrorZ_ok();
4544         return (long)ret_conv;
4545 }
4546
4547 uint32_t  __attribute__((visibility("default"))) TS_CResult_NoneMonitorUpdateErrorZ_err(uint32_t e) {
4548         LDKMonitorUpdateError e_conv;
4549         e_conv.inner = (void*)(e & (~1));
4550         e_conv.is_owned = (e & 1) || (e == 0);
4551         e_conv = MonitorUpdateError_clone(&e_conv);
4552         LDKCResult_NoneMonitorUpdateErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneMonitorUpdateErrorZ), "LDKCResult_NoneMonitorUpdateErrorZ");
4553         *ret_conv = CResult_NoneMonitorUpdateErrorZ_err(e_conv);
4554         return (long)ret_conv;
4555 }
4556
4557 void  __attribute__((visibility("default"))) TS_CResult_NoneMonitorUpdateErrorZ_free(uint32_t _res) {
4558         if ((_res & 1) != 0) return;
4559         LDKCResult_NoneMonitorUpdateErrorZ _res_conv = *(LDKCResult_NoneMonitorUpdateErrorZ*)(((uint64_t)_res) & ~1);
4560         FREE((void*)_res);
4561         CResult_NoneMonitorUpdateErrorZ_free(_res_conv);
4562 }
4563
4564 uint32_t  __attribute__((visibility("default"))) TS_CResult_NoneMonitorUpdateErrorZ_clone(uint32_t orig) {
4565         LDKCResult_NoneMonitorUpdateErrorZ* orig_conv = (LDKCResult_NoneMonitorUpdateErrorZ*)(orig & ~1);
4566         LDKCResult_NoneMonitorUpdateErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneMonitorUpdateErrorZ), "LDKCResult_NoneMonitorUpdateErrorZ");
4567         *ret_conv = CResult_NoneMonitorUpdateErrorZ_clone(orig_conv);
4568         return (long)ret_conv;
4569 }
4570
4571 void  __attribute__((visibility("default"))) TS_C2Tuple_OutPointScriptZ_free(uint32_t _res) {
4572         if ((_res & 1) != 0) return;
4573         LDKC2Tuple_OutPointScriptZ _res_conv = *(LDKC2Tuple_OutPointScriptZ*)(((uint64_t)_res) & ~1);
4574         FREE((void*)_res);
4575         C2Tuple_OutPointScriptZ_free(_res_conv);
4576 }
4577
4578 uint32_t  __attribute__((visibility("default"))) TS_C2Tuple_OutPointScriptZ_new(uint32_t a, int8_tArray b) {
4579         LDKOutPoint a_conv;
4580         a_conv.inner = (void*)(a & (~1));
4581         a_conv.is_owned = (a & 1) || (a == 0);
4582         a_conv = OutPoint_clone(&a_conv);
4583         LDKCVec_u8Z b_ref;
4584         b_ref.datalen = *((uint32_t*)b);
4585         b_ref.data = MALLOC(b_ref.datalen, "LDKCVec_u8Z Bytes");
4586         memcpy(b_ref.data, (uint8_t*)(b + 4), b_ref.datalen);
4587         LDKC2Tuple_OutPointScriptZ* ret_ref = MALLOC(sizeof(LDKC2Tuple_OutPointScriptZ), "LDKC2Tuple_OutPointScriptZ");
4588         *ret_ref = C2Tuple_OutPointScriptZ_new(a_conv, b_ref);
4589         return (long)ret_ref;
4590 }
4591
4592 void  __attribute__((visibility("default"))) TS_CVec_TransactionZ_free(ptrArray _res) {
4593         LDKCVec_TransactionZ _res_constr;
4594         _res_constr.datalen = *((uint32_t*)_res);
4595         if (_res_constr.datalen > 0)
4596                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKTransaction), "LDKCVec_TransactionZ Elements");
4597         else
4598                 _res_constr.data = NULL;
4599         int8_tArray* _res_vals = (int8_tArray*)(_res + 4);
4600         for (size_t m = 0; m < _res_constr.datalen; m++) {
4601                 int8_tArray arr_conv_12 = _res_vals[m];
4602                 LDKTransaction arr_conv_12_ref;
4603                 arr_conv_12_ref.datalen = *((uint32_t*)arr_conv_12);
4604                 arr_conv_12_ref.data = MALLOC(arr_conv_12_ref.datalen, "LDKTransaction Bytes");
4605                 memcpy(arr_conv_12_ref.data, (uint8_t*)(arr_conv_12 + 4), arr_conv_12_ref.datalen);
4606                 arr_conv_12_ref.data_is_owned = true;
4607                 _res_constr.data[m] = arr_conv_12_ref;
4608         }
4609         CVec_TransactionZ_free(_res_constr);
4610 }
4611
4612 uint32_t  __attribute__((visibility("default"))) TS_C2Tuple_u32TxOutZ_clone(uint32_t orig) {
4613         LDKC2Tuple_u32TxOutZ* orig_conv = (LDKC2Tuple_u32TxOutZ*)(orig & ~1);
4614         LDKC2Tuple_u32TxOutZ* ret_ref = MALLOC(sizeof(LDKC2Tuple_u32TxOutZ), "LDKC2Tuple_u32TxOutZ");
4615         *ret_ref = C2Tuple_u32TxOutZ_clone(orig_conv);
4616         return (long)ret_ref;
4617 }
4618
4619 void  __attribute__((visibility("default"))) TS_C2Tuple_u32TxOutZ_free(uint32_t _res) {
4620         if ((_res & 1) != 0) return;
4621         LDKC2Tuple_u32TxOutZ _res_conv = *(LDKC2Tuple_u32TxOutZ*)(((uint64_t)_res) & ~1);
4622         FREE((void*)_res);
4623         C2Tuple_u32TxOutZ_free(_res_conv);
4624 }
4625
4626 uint32_t  __attribute__((visibility("default"))) TS_C2Tuple_u32TxOutZ_new(int32_t a, uint32_t b) {
4627         LDKTxOut b_conv = *(LDKTxOut*)(((uint64_t)b) & ~1);
4628         FREE((void*)b);
4629         LDKC2Tuple_u32TxOutZ* ret_ref = MALLOC(sizeof(LDKC2Tuple_u32TxOutZ), "LDKC2Tuple_u32TxOutZ");
4630         *ret_ref = C2Tuple_u32TxOutZ_new(a, b_conv);
4631         return (long)ret_ref;
4632 }
4633
4634 void  __attribute__((visibility("default"))) TS_CVec_C2Tuple_u32TxOutZZ_free(uint32_tArray _res) {
4635         LDKCVec_C2Tuple_u32TxOutZZ _res_constr;
4636         _res_constr.datalen = *((uint32_t*)_res);
4637         if (_res_constr.datalen > 0)
4638                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKC2Tuple_u32TxOutZ), "LDKCVec_C2Tuple_u32TxOutZZ Elements");
4639         else
4640                 _res_constr.data = NULL;
4641         uint32_t* _res_vals = (uint32_t*)(_res + 4);
4642         for (size_t z = 0; z < _res_constr.datalen; z++) {
4643                 uint32_t arr_conv_25 = _res_vals[z];
4644                 LDKC2Tuple_u32TxOutZ arr_conv_25_conv = *(LDKC2Tuple_u32TxOutZ*)(((uint64_t)arr_conv_25) & ~1);
4645                 FREE((void*)arr_conv_25);
4646                 _res_constr.data[z] = arr_conv_25_conv;
4647         }
4648         CVec_C2Tuple_u32TxOutZZ_free(_res_constr);
4649 }
4650
4651 void  __attribute__((visibility("default"))) TS_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ_free(uint32_t _res) {
4652         if ((_res & 1) != 0) return;
4653         LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ _res_conv = *(LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ*)(((uint64_t)_res) & ~1);
4654         FREE((void*)_res);
4655         C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ_free(_res_conv);
4656 }
4657
4658 uint32_t  __attribute__((visibility("default"))) TS_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ_new(int8_tArray a, uint32_tArray b) {
4659         LDKThirtyTwoBytes a_ref;
4660         CHECK(*((uint32_t*)a) == 32);
4661         memcpy(a_ref.data, (uint8_t*)(a + 4), 32);
4662         LDKCVec_C2Tuple_u32TxOutZZ b_constr;
4663         b_constr.datalen = *((uint32_t*)b);
4664         if (b_constr.datalen > 0)
4665                 b_constr.data = MALLOC(b_constr.datalen * sizeof(LDKC2Tuple_u32TxOutZ), "LDKCVec_C2Tuple_u32TxOutZZ Elements");
4666         else
4667                 b_constr.data = NULL;
4668         uint32_t* b_vals = (uint32_t*)(b + 4);
4669         for (size_t z = 0; z < b_constr.datalen; z++) {
4670                 uint32_t arr_conv_25 = b_vals[z];
4671                 LDKC2Tuple_u32TxOutZ arr_conv_25_conv = *(LDKC2Tuple_u32TxOutZ*)(((uint64_t)arr_conv_25) & ~1);
4672                 FREE((void*)arr_conv_25);
4673                 b_constr.data[z] = arr_conv_25_conv;
4674         }
4675         LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ* ret_ref = MALLOC(sizeof(LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ), "LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ");
4676         *ret_ref = C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ_new(a_ref, b_constr);
4677         return (long)ret_ref;
4678 }
4679
4680 void  __attribute__((visibility("default"))) TS_CVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ_free(uint32_tArray _res) {
4681         LDKCVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ _res_constr;
4682         _res_constr.datalen = *((uint32_t*)_res);
4683         if (_res_constr.datalen > 0)
4684                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ), "LDKCVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ Elements");
4685         else
4686                 _res_constr.data = NULL;
4687         uint32_t* _res_vals = (uint32_t*)(_res + 4);
4688         for (size_t x = 0; x < _res_constr.datalen; x++) {
4689                 uint32_t arr_conv_49 = _res_vals[x];
4690                 LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ arr_conv_49_conv = *(LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ*)(((uint64_t)arr_conv_49) & ~1);
4691                 FREE((void*)arr_conv_49);
4692                 _res_constr.data[x] = arr_conv_49_conv;
4693         }
4694         CVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ_free(_res_constr);
4695 }
4696
4697 void  __attribute__((visibility("default"))) TS_C2Tuple_BlockHashChannelMonitorZ_free(uint32_t _res) {
4698         if ((_res & 1) != 0) return;
4699         LDKC2Tuple_BlockHashChannelMonitorZ _res_conv = *(LDKC2Tuple_BlockHashChannelMonitorZ*)(((uint64_t)_res) & ~1);
4700         FREE((void*)_res);
4701         C2Tuple_BlockHashChannelMonitorZ_free(_res_conv);
4702 }
4703
4704 uint32_t  __attribute__((visibility("default"))) TS_C2Tuple_BlockHashChannelMonitorZ_new(int8_tArray a, uint32_t b) {
4705         LDKThirtyTwoBytes a_ref;
4706         CHECK(*((uint32_t*)a) == 32);
4707         memcpy(a_ref.data, (uint8_t*)(a + 4), 32);
4708         LDKChannelMonitor b_conv;
4709         b_conv.inner = (void*)(b & (~1));
4710         b_conv.is_owned = (b & 1) || (b == 0);
4711         b_conv = ChannelMonitor_clone(&b_conv);
4712         LDKC2Tuple_BlockHashChannelMonitorZ* ret_ref = MALLOC(sizeof(LDKC2Tuple_BlockHashChannelMonitorZ), "LDKC2Tuple_BlockHashChannelMonitorZ");
4713         *ret_ref = C2Tuple_BlockHashChannelMonitorZ_new(a_ref, b_conv);
4714         return (long)ret_ref;
4715 }
4716
4717 uint32_t  __attribute__((visibility("default"))) TS_CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ_ok(uint32_t o) {
4718         LDKC2Tuple_BlockHashChannelMonitorZ o_conv = *(LDKC2Tuple_BlockHashChannelMonitorZ*)(((uint64_t)o) & ~1);
4719         FREE((void*)o);
4720         LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ), "LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ");
4721         *ret_conv = CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ_ok(o_conv);
4722         return (long)ret_conv;
4723 }
4724
4725 uint32_t  __attribute__((visibility("default"))) TS_CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ_err(uint32_t e) {
4726         LDKDecodeError e_conv;
4727         e_conv.inner = (void*)(e & (~1));
4728         e_conv.is_owned = (e & 1) || (e == 0);
4729         e_conv = DecodeError_clone(&e_conv);
4730         LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ), "LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ");
4731         *ret_conv = CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ_err(e_conv);
4732         return (long)ret_conv;
4733 }
4734
4735 void  __attribute__((visibility("default"))) TS_CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ_free(uint32_t _res) {
4736         if ((_res & 1) != 0) return;
4737         LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ _res_conv = *(LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ*)(((uint64_t)_res) & ~1);
4738         FREE((void*)_res);
4739         CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ_free(_res_conv);
4740 }
4741
4742 uint32_t  __attribute__((visibility("default"))) TS_C2Tuple_u64u64Z_clone(uint32_t orig) {
4743         LDKC2Tuple_u64u64Z* orig_conv = (LDKC2Tuple_u64u64Z*)(orig & ~1);
4744         LDKC2Tuple_u64u64Z* ret_ref = MALLOC(sizeof(LDKC2Tuple_u64u64Z), "LDKC2Tuple_u64u64Z");
4745         *ret_ref = C2Tuple_u64u64Z_clone(orig_conv);
4746         return (long)ret_ref;
4747 }
4748
4749 void  __attribute__((visibility("default"))) TS_C2Tuple_u64u64Z_free(uint32_t _res) {
4750         if ((_res & 1) != 0) return;
4751         LDKC2Tuple_u64u64Z _res_conv = *(LDKC2Tuple_u64u64Z*)(((uint64_t)_res) & ~1);
4752         FREE((void*)_res);
4753         C2Tuple_u64u64Z_free(_res_conv);
4754 }
4755
4756 uint32_t  __attribute__((visibility("default"))) TS_C2Tuple_u64u64Z_new(int64_t a, int64_t b) {
4757         LDKC2Tuple_u64u64Z* ret_ref = MALLOC(sizeof(LDKC2Tuple_u64u64Z), "LDKC2Tuple_u64u64Z");
4758         *ret_ref = C2Tuple_u64u64Z_new(a, b);
4759         return (long)ret_ref;
4760 }
4761
4762 uint32_t  __attribute__((visibility("default"))) TS_CResult_SpendableOutputDescriptorDecodeErrorZ_ok(uint32_t o) {
4763         LDKSpendableOutputDescriptor o_conv = *(LDKSpendableOutputDescriptor*)(((uint64_t)o) & ~1);
4764         FREE((void*)o);
4765         LDKCResult_SpendableOutputDescriptorDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_SpendableOutputDescriptorDecodeErrorZ), "LDKCResult_SpendableOutputDescriptorDecodeErrorZ");
4766         *ret_conv = CResult_SpendableOutputDescriptorDecodeErrorZ_ok(o_conv);
4767         return (long)ret_conv;
4768 }
4769
4770 uint32_t  __attribute__((visibility("default"))) TS_CResult_SpendableOutputDescriptorDecodeErrorZ_err(uint32_t e) {
4771         LDKDecodeError e_conv;
4772         e_conv.inner = (void*)(e & (~1));
4773         e_conv.is_owned = (e & 1) || (e == 0);
4774         e_conv = DecodeError_clone(&e_conv);
4775         LDKCResult_SpendableOutputDescriptorDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_SpendableOutputDescriptorDecodeErrorZ), "LDKCResult_SpendableOutputDescriptorDecodeErrorZ");
4776         *ret_conv = CResult_SpendableOutputDescriptorDecodeErrorZ_err(e_conv);
4777         return (long)ret_conv;
4778 }
4779
4780 void  __attribute__((visibility("default"))) TS_CResult_SpendableOutputDescriptorDecodeErrorZ_free(uint32_t _res) {
4781         if ((_res & 1) != 0) return;
4782         LDKCResult_SpendableOutputDescriptorDecodeErrorZ _res_conv = *(LDKCResult_SpendableOutputDescriptorDecodeErrorZ*)(((uint64_t)_res) & ~1);
4783         FREE((void*)_res);
4784         CResult_SpendableOutputDescriptorDecodeErrorZ_free(_res_conv);
4785 }
4786
4787 uint32_t  __attribute__((visibility("default"))) TS_CResult_SpendableOutputDescriptorDecodeErrorZ_clone(uint32_t orig) {
4788         LDKCResult_SpendableOutputDescriptorDecodeErrorZ* orig_conv = (LDKCResult_SpendableOutputDescriptorDecodeErrorZ*)(orig & ~1);
4789         LDKCResult_SpendableOutputDescriptorDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_SpendableOutputDescriptorDecodeErrorZ), "LDKCResult_SpendableOutputDescriptorDecodeErrorZ");
4790         *ret_conv = CResult_SpendableOutputDescriptorDecodeErrorZ_clone(orig_conv);
4791         return (long)ret_conv;
4792 }
4793
4794 void  __attribute__((visibility("default"))) TS_CVec_SignatureZ_free(ptrArray _res) {
4795         LDKCVec_SignatureZ _res_constr;
4796         _res_constr.datalen = *((uint32_t*)_res);
4797         if (_res_constr.datalen > 0)
4798                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKSignature), "LDKCVec_SignatureZ Elements");
4799         else
4800                 _res_constr.data = NULL;
4801         int8_tArray* _res_vals = (int8_tArray*)(_res + 4);
4802         for (size_t m = 0; m < _res_constr.datalen; m++) {
4803                 int8_tArray arr_conv_12 = _res_vals[m];
4804                 LDKSignature arr_conv_12_ref;
4805                 CHECK(*((uint32_t*)arr_conv_12) == 64);
4806                 memcpy(arr_conv_12_ref.compact_form, (uint8_t*)(arr_conv_12 + 4), 64);
4807                 _res_constr.data[m] = arr_conv_12_ref;
4808         }
4809         CVec_SignatureZ_free(_res_constr);
4810 }
4811
4812 uint32_t  __attribute__((visibility("default"))) TS_C2Tuple_SignatureCVec_SignatureZZ_clone(uint32_t orig) {
4813         LDKC2Tuple_SignatureCVec_SignatureZZ* orig_conv = (LDKC2Tuple_SignatureCVec_SignatureZZ*)(orig & ~1);
4814         LDKC2Tuple_SignatureCVec_SignatureZZ* ret_ref = MALLOC(sizeof(LDKC2Tuple_SignatureCVec_SignatureZZ), "LDKC2Tuple_SignatureCVec_SignatureZZ");
4815         *ret_ref = C2Tuple_SignatureCVec_SignatureZZ_clone(orig_conv);
4816         return (long)ret_ref;
4817 }
4818
4819 void  __attribute__((visibility("default"))) TS_C2Tuple_SignatureCVec_SignatureZZ_free(uint32_t _res) {
4820         if ((_res & 1) != 0) return;
4821         LDKC2Tuple_SignatureCVec_SignatureZZ _res_conv = *(LDKC2Tuple_SignatureCVec_SignatureZZ*)(((uint64_t)_res) & ~1);
4822         FREE((void*)_res);
4823         C2Tuple_SignatureCVec_SignatureZZ_free(_res_conv);
4824 }
4825
4826 uint32_t  __attribute__((visibility("default"))) TS_C2Tuple_SignatureCVec_SignatureZZ_new(int8_tArray a, ptrArray b) {
4827         LDKSignature a_ref;
4828         CHECK(*((uint32_t*)a) == 64);
4829         memcpy(a_ref.compact_form, (uint8_t*)(a + 4), 64);
4830         LDKCVec_SignatureZ b_constr;
4831         b_constr.datalen = *((uint32_t*)b);
4832         if (b_constr.datalen > 0)
4833                 b_constr.data = MALLOC(b_constr.datalen * sizeof(LDKSignature), "LDKCVec_SignatureZ Elements");
4834         else
4835                 b_constr.data = NULL;
4836         int8_tArray* b_vals = (int8_tArray*)(b + 4);
4837         for (size_t m = 0; m < b_constr.datalen; m++) {
4838                 int8_tArray arr_conv_12 = b_vals[m];
4839                 LDKSignature arr_conv_12_ref;
4840                 CHECK(*((uint32_t*)arr_conv_12) == 64);
4841                 memcpy(arr_conv_12_ref.compact_form, (uint8_t*)(arr_conv_12 + 4), 64);
4842                 b_constr.data[m] = arr_conv_12_ref;
4843         }
4844         LDKC2Tuple_SignatureCVec_SignatureZZ* ret_ref = MALLOC(sizeof(LDKC2Tuple_SignatureCVec_SignatureZZ), "LDKC2Tuple_SignatureCVec_SignatureZZ");
4845         *ret_ref = C2Tuple_SignatureCVec_SignatureZZ_new(a_ref, b_constr);
4846         return (long)ret_ref;
4847 }
4848
4849 uint32_t  __attribute__((visibility("default"))) TS_CResult_C2Tuple_SignatureCVec_SignatureZZNoneZ_ok(uint32_t o) {
4850         LDKC2Tuple_SignatureCVec_SignatureZZ o_conv = *(LDKC2Tuple_SignatureCVec_SignatureZZ*)(((uint64_t)o) & ~1);
4851         FREE((void*)o);
4852         LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ), "LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ");
4853         *ret_conv = CResult_C2Tuple_SignatureCVec_SignatureZZNoneZ_ok(o_conv);
4854         return (long)ret_conv;
4855 }
4856
4857 uint32_t  __attribute__((visibility("default"))) TS_CResult_C2Tuple_SignatureCVec_SignatureZZNoneZ_err() {
4858         LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ), "LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ");
4859         *ret_conv = CResult_C2Tuple_SignatureCVec_SignatureZZNoneZ_err();
4860         return (long)ret_conv;
4861 }
4862
4863 void  __attribute__((visibility("default"))) TS_CResult_C2Tuple_SignatureCVec_SignatureZZNoneZ_free(uint32_t _res) {
4864         if ((_res & 1) != 0) return;
4865         LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ _res_conv = *(LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ*)(((uint64_t)_res) & ~1);
4866         FREE((void*)_res);
4867         CResult_C2Tuple_SignatureCVec_SignatureZZNoneZ_free(_res_conv);
4868 }
4869
4870 uint32_t  __attribute__((visibility("default"))) TS_CResult_C2Tuple_SignatureCVec_SignatureZZNoneZ_clone(uint32_t orig) {
4871         LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ* orig_conv = (LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ*)(orig & ~1);
4872         LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ), "LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ");
4873         *ret_conv = CResult_C2Tuple_SignatureCVec_SignatureZZNoneZ_clone(orig_conv);
4874         return (long)ret_conv;
4875 }
4876
4877 uint32_t  __attribute__((visibility("default"))) TS_CResult_SignatureNoneZ_ok(int8_tArray o) {
4878         LDKSignature o_ref;
4879         CHECK(*((uint32_t*)o) == 64);
4880         memcpy(o_ref.compact_form, (uint8_t*)(o + 4), 64);
4881         LDKCResult_SignatureNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_SignatureNoneZ), "LDKCResult_SignatureNoneZ");
4882         *ret_conv = CResult_SignatureNoneZ_ok(o_ref);
4883         return (long)ret_conv;
4884 }
4885
4886 uint32_t  __attribute__((visibility("default"))) TS_CResult_SignatureNoneZ_err() {
4887         LDKCResult_SignatureNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_SignatureNoneZ), "LDKCResult_SignatureNoneZ");
4888         *ret_conv = CResult_SignatureNoneZ_err();
4889         return (long)ret_conv;
4890 }
4891
4892 void  __attribute__((visibility("default"))) TS_CResult_SignatureNoneZ_free(uint32_t _res) {
4893         if ((_res & 1) != 0) return;
4894         LDKCResult_SignatureNoneZ _res_conv = *(LDKCResult_SignatureNoneZ*)(((uint64_t)_res) & ~1);
4895         FREE((void*)_res);
4896         CResult_SignatureNoneZ_free(_res_conv);
4897 }
4898
4899 uint32_t  __attribute__((visibility("default"))) TS_CResult_SignatureNoneZ_clone(uint32_t orig) {
4900         LDKCResult_SignatureNoneZ* orig_conv = (LDKCResult_SignatureNoneZ*)(orig & ~1);
4901         LDKCResult_SignatureNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_SignatureNoneZ), "LDKCResult_SignatureNoneZ");
4902         *ret_conv = CResult_SignatureNoneZ_clone(orig_conv);
4903         return (long)ret_conv;
4904 }
4905
4906 uint32_t  __attribute__((visibility("default"))) TS_CResult_ChanKeySignerDecodeErrorZ_ok(uint32_t o) {
4907         LDKChannelKeys o_conv = *(LDKChannelKeys*)(((uint64_t)o) & ~1);
4908         LDKCResult_ChanKeySignerDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ChanKeySignerDecodeErrorZ), "LDKCResult_ChanKeySignerDecodeErrorZ");
4909         *ret_conv = CResult_ChanKeySignerDecodeErrorZ_ok(o_conv);
4910         return (long)ret_conv;
4911 }
4912
4913 uint32_t  __attribute__((visibility("default"))) TS_CResult_ChanKeySignerDecodeErrorZ_err(uint32_t e) {
4914         LDKDecodeError e_conv;
4915         e_conv.inner = (void*)(e & (~1));
4916         e_conv.is_owned = (e & 1) || (e == 0);
4917         e_conv = DecodeError_clone(&e_conv);
4918         LDKCResult_ChanKeySignerDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ChanKeySignerDecodeErrorZ), "LDKCResult_ChanKeySignerDecodeErrorZ");
4919         *ret_conv = CResult_ChanKeySignerDecodeErrorZ_err(e_conv);
4920         return (long)ret_conv;
4921 }
4922
4923 void  __attribute__((visibility("default"))) TS_CResult_ChanKeySignerDecodeErrorZ_free(uint32_t _res) {
4924         if ((_res & 1) != 0) return;
4925         LDKCResult_ChanKeySignerDecodeErrorZ _res_conv = *(LDKCResult_ChanKeySignerDecodeErrorZ*)(((uint64_t)_res) & ~1);
4926         FREE((void*)_res);
4927         CResult_ChanKeySignerDecodeErrorZ_free(_res_conv);
4928 }
4929
4930 uint32_t  __attribute__((visibility("default"))) TS_CResult_ChanKeySignerDecodeErrorZ_clone(uint32_t orig) {
4931         LDKCResult_ChanKeySignerDecodeErrorZ* orig_conv = (LDKCResult_ChanKeySignerDecodeErrorZ*)(orig & ~1);
4932         LDKCResult_ChanKeySignerDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ChanKeySignerDecodeErrorZ), "LDKCResult_ChanKeySignerDecodeErrorZ");
4933         *ret_conv = CResult_ChanKeySignerDecodeErrorZ_clone(orig_conv);
4934         return (long)ret_conv;
4935 }
4936
4937 uint32_t  __attribute__((visibility("default"))) TS_CResult_InMemoryChannelKeysDecodeErrorZ_ok(uint32_t o) {
4938         LDKInMemoryChannelKeys o_conv;
4939         o_conv.inner = (void*)(o & (~1));
4940         o_conv.is_owned = (o & 1) || (o == 0);
4941         o_conv = InMemoryChannelKeys_clone(&o_conv);
4942         LDKCResult_InMemoryChannelKeysDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_InMemoryChannelKeysDecodeErrorZ), "LDKCResult_InMemoryChannelKeysDecodeErrorZ");
4943         *ret_conv = CResult_InMemoryChannelKeysDecodeErrorZ_ok(o_conv);
4944         return (long)ret_conv;
4945 }
4946
4947 uint32_t  __attribute__((visibility("default"))) TS_CResult_InMemoryChannelKeysDecodeErrorZ_err(uint32_t e) {
4948         LDKDecodeError e_conv;
4949         e_conv.inner = (void*)(e & (~1));
4950         e_conv.is_owned = (e & 1) || (e == 0);
4951         e_conv = DecodeError_clone(&e_conv);
4952         LDKCResult_InMemoryChannelKeysDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_InMemoryChannelKeysDecodeErrorZ), "LDKCResult_InMemoryChannelKeysDecodeErrorZ");
4953         *ret_conv = CResult_InMemoryChannelKeysDecodeErrorZ_err(e_conv);
4954         return (long)ret_conv;
4955 }
4956
4957 void  __attribute__((visibility("default"))) TS_CResult_InMemoryChannelKeysDecodeErrorZ_free(uint32_t _res) {
4958         if ((_res & 1) != 0) return;
4959         LDKCResult_InMemoryChannelKeysDecodeErrorZ _res_conv = *(LDKCResult_InMemoryChannelKeysDecodeErrorZ*)(((uint64_t)_res) & ~1);
4960         FREE((void*)_res);
4961         CResult_InMemoryChannelKeysDecodeErrorZ_free(_res_conv);
4962 }
4963
4964 uint32_t  __attribute__((visibility("default"))) TS_CResult_TxOutAccessErrorZ_ok(uint32_t o) {
4965         LDKTxOut o_conv = *(LDKTxOut*)(((uint64_t)o) & ~1);
4966         FREE((void*)o);
4967         LDKCResult_TxOutAccessErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_TxOutAccessErrorZ), "LDKCResult_TxOutAccessErrorZ");
4968         *ret_conv = CResult_TxOutAccessErrorZ_ok(o_conv);
4969         return (long)ret_conv;
4970 }
4971
4972 uint32_t  __attribute__((visibility("default"))) TS_CResult_TxOutAccessErrorZ_err(uint32_t e) {
4973         LDKAccessError e_conv = LDKAccessError_from_js(e);
4974         LDKCResult_TxOutAccessErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_TxOutAccessErrorZ), "LDKCResult_TxOutAccessErrorZ");
4975         *ret_conv = CResult_TxOutAccessErrorZ_err(e_conv);
4976         return (long)ret_conv;
4977 }
4978
4979 void  __attribute__((visibility("default"))) TS_CResult_TxOutAccessErrorZ_free(uint32_t _res) {
4980         if ((_res & 1) != 0) return;
4981         LDKCResult_TxOutAccessErrorZ _res_conv = *(LDKCResult_TxOutAccessErrorZ*)(((uint64_t)_res) & ~1);
4982         FREE((void*)_res);
4983         CResult_TxOutAccessErrorZ_free(_res_conv);
4984 }
4985
4986 uint32_t  __attribute__((visibility("default"))) TS_CResult_TxOutAccessErrorZ_clone(uint32_t orig) {
4987         LDKCResult_TxOutAccessErrorZ* orig_conv = (LDKCResult_TxOutAccessErrorZ*)(orig & ~1);
4988         LDKCResult_TxOutAccessErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_TxOutAccessErrorZ), "LDKCResult_TxOutAccessErrorZ");
4989         *ret_conv = CResult_TxOutAccessErrorZ_clone(orig_conv);
4990         return (long)ret_conv;
4991 }
4992
4993 uint32_t  __attribute__((visibility("default"))) TS_CResult_NoneAPIErrorZ_ok() {
4994         LDKCResult_NoneAPIErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneAPIErrorZ), "LDKCResult_NoneAPIErrorZ");
4995         *ret_conv = CResult_NoneAPIErrorZ_ok();
4996         return (long)ret_conv;
4997 }
4998
4999 uint32_t  __attribute__((visibility("default"))) TS_CResult_NoneAPIErrorZ_err(uint32_t e) {
5000         LDKAPIError e_conv = *(LDKAPIError*)(((uint64_t)e) & ~1);
5001         FREE((void*)e);
5002         LDKCResult_NoneAPIErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneAPIErrorZ), "LDKCResult_NoneAPIErrorZ");
5003         *ret_conv = CResult_NoneAPIErrorZ_err(e_conv);
5004         return (long)ret_conv;
5005 }
5006
5007 void  __attribute__((visibility("default"))) TS_CResult_NoneAPIErrorZ_free(uint32_t _res) {
5008         if ((_res & 1) != 0) return;
5009         LDKCResult_NoneAPIErrorZ _res_conv = *(LDKCResult_NoneAPIErrorZ*)(((uint64_t)_res) & ~1);
5010         FREE((void*)_res);
5011         CResult_NoneAPIErrorZ_free(_res_conv);
5012 }
5013
5014 void  __attribute__((visibility("default"))) TS_CVec_ChannelDetailsZ_free(uint32_tArray _res) {
5015         LDKCVec_ChannelDetailsZ _res_constr;
5016         _res_constr.datalen = *((uint32_t*)_res);
5017         if (_res_constr.datalen > 0)
5018                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKChannelDetails), "LDKCVec_ChannelDetailsZ Elements");
5019         else
5020                 _res_constr.data = NULL;
5021         uint32_t* _res_vals = (uint32_t*)(_res + 4);
5022         for (size_t q = 0; q < _res_constr.datalen; q++) {
5023                 uint32_t arr_conv_16 = _res_vals[q];
5024                 LDKChannelDetails arr_conv_16_conv;
5025                 arr_conv_16_conv.inner = (void*)(arr_conv_16 & (~1));
5026                 arr_conv_16_conv.is_owned = (arr_conv_16 & 1) || (arr_conv_16 == 0);
5027                 _res_constr.data[q] = arr_conv_16_conv;
5028         }
5029         CVec_ChannelDetailsZ_free(_res_constr);
5030 }
5031
5032 uint32_t  __attribute__((visibility("default"))) TS_CResult_NonePaymentSendFailureZ_ok() {
5033         LDKCResult_NonePaymentSendFailureZ* ret_conv = MALLOC(sizeof(LDKCResult_NonePaymentSendFailureZ), "LDKCResult_NonePaymentSendFailureZ");
5034         *ret_conv = CResult_NonePaymentSendFailureZ_ok();
5035         return (long)ret_conv;
5036 }
5037
5038 uint32_t  __attribute__((visibility("default"))) TS_CResult_NonePaymentSendFailureZ_err(uint32_t e) {
5039         LDKPaymentSendFailure e_conv;
5040         e_conv.inner = (void*)(e & (~1));
5041         e_conv.is_owned = (e & 1) || (e == 0);
5042         e_conv = PaymentSendFailure_clone(&e_conv);
5043         LDKCResult_NonePaymentSendFailureZ* ret_conv = MALLOC(sizeof(LDKCResult_NonePaymentSendFailureZ), "LDKCResult_NonePaymentSendFailureZ");
5044         *ret_conv = CResult_NonePaymentSendFailureZ_err(e_conv);
5045         return (long)ret_conv;
5046 }
5047
5048 void  __attribute__((visibility("default"))) TS_CResult_NonePaymentSendFailureZ_free(uint32_t _res) {
5049         if ((_res & 1) != 0) return;
5050         LDKCResult_NonePaymentSendFailureZ _res_conv = *(LDKCResult_NonePaymentSendFailureZ*)(((uint64_t)_res) & ~1);
5051         FREE((void*)_res);
5052         CResult_NonePaymentSendFailureZ_free(_res_conv);
5053 }
5054
5055 uint32_t  __attribute__((visibility("default"))) TS_CResult_NonePaymentSendFailureZ_clone(uint32_t orig) {
5056         LDKCResult_NonePaymentSendFailureZ* orig_conv = (LDKCResult_NonePaymentSendFailureZ*)(orig & ~1);
5057         LDKCResult_NonePaymentSendFailureZ* ret_conv = MALLOC(sizeof(LDKCResult_NonePaymentSendFailureZ), "LDKCResult_NonePaymentSendFailureZ");
5058         *ret_conv = CResult_NonePaymentSendFailureZ_clone(orig_conv);
5059         return (long)ret_conv;
5060 }
5061
5062 void  __attribute__((visibility("default"))) TS_CVec_NetAddressZ_free(uint32_tArray _res) {
5063         LDKCVec_NetAddressZ _res_constr;
5064         _res_constr.datalen = *((uint32_t*)_res);
5065         if (_res_constr.datalen > 0)
5066                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKNetAddress), "LDKCVec_NetAddressZ Elements");
5067         else
5068                 _res_constr.data = NULL;
5069         uint32_t* _res_vals = (uint32_t*)(_res + 4);
5070         for (size_t m = 0; m < _res_constr.datalen; m++) {
5071                 uint32_t arr_conv_12 = _res_vals[m];
5072                 LDKNetAddress arr_conv_12_conv = *(LDKNetAddress*)(((uint64_t)arr_conv_12) & ~1);
5073                 FREE((void*)arr_conv_12);
5074                 _res_constr.data[m] = arr_conv_12_conv;
5075         }
5076         CVec_NetAddressZ_free(_res_constr);
5077 }
5078
5079 void  __attribute__((visibility("default"))) TS_CVec_ChannelMonitorZ_free(uint32_tArray _res) {
5080         LDKCVec_ChannelMonitorZ _res_constr;
5081         _res_constr.datalen = *((uint32_t*)_res);
5082         if (_res_constr.datalen > 0)
5083                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKChannelMonitor), "LDKCVec_ChannelMonitorZ Elements");
5084         else
5085                 _res_constr.data = NULL;
5086         uint32_t* _res_vals = (uint32_t*)(_res + 4);
5087         for (size_t q = 0; q < _res_constr.datalen; q++) {
5088                 uint32_t arr_conv_16 = _res_vals[q];
5089                 LDKChannelMonitor arr_conv_16_conv;
5090                 arr_conv_16_conv.inner = (void*)(arr_conv_16 & (~1));
5091                 arr_conv_16_conv.is_owned = (arr_conv_16 & 1) || (arr_conv_16 == 0);
5092                 _res_constr.data[q] = arr_conv_16_conv;
5093         }
5094         CVec_ChannelMonitorZ_free(_res_constr);
5095 }
5096
5097 void  __attribute__((visibility("default"))) TS_C2Tuple_BlockHashChannelManagerZ_free(uint32_t _res) {
5098         if ((_res & 1) != 0) return;
5099         LDKC2Tuple_BlockHashChannelManagerZ _res_conv = *(LDKC2Tuple_BlockHashChannelManagerZ*)(((uint64_t)_res) & ~1);
5100         FREE((void*)_res);
5101         C2Tuple_BlockHashChannelManagerZ_free(_res_conv);
5102 }
5103
5104 uint32_t  __attribute__((visibility("default"))) TS_C2Tuple_BlockHashChannelManagerZ_new(int8_tArray a, uint32_t b) {
5105         LDKThirtyTwoBytes a_ref;
5106         CHECK(*((uint32_t*)a) == 32);
5107         memcpy(a_ref.data, (uint8_t*)(a + 4), 32);
5108         LDKChannelManager b_conv;
5109         b_conv.inner = (void*)(b & (~1));
5110         b_conv.is_owned = (b & 1) || (b == 0);
5111         // Warning: we need a move here but no clone is available for LDKChannelManager
5112         LDKC2Tuple_BlockHashChannelManagerZ* ret_ref = MALLOC(sizeof(LDKC2Tuple_BlockHashChannelManagerZ), "LDKC2Tuple_BlockHashChannelManagerZ");
5113         *ret_ref = C2Tuple_BlockHashChannelManagerZ_new(a_ref, b_conv);
5114         return (long)ret_ref;
5115 }
5116
5117 uint32_t  __attribute__((visibility("default"))) TS_CResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ_ok(uint32_t o) {
5118         LDKC2Tuple_BlockHashChannelManagerZ o_conv = *(LDKC2Tuple_BlockHashChannelManagerZ*)(((uint64_t)o) & ~1);
5119         FREE((void*)o);
5120         LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ), "LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ");
5121         *ret_conv = CResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ_ok(o_conv);
5122         return (long)ret_conv;
5123 }
5124
5125 uint32_t  __attribute__((visibility("default"))) TS_CResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ_err(uint32_t e) {
5126         LDKDecodeError e_conv;
5127         e_conv.inner = (void*)(e & (~1));
5128         e_conv.is_owned = (e & 1) || (e == 0);
5129         e_conv = DecodeError_clone(&e_conv);
5130         LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ), "LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ");
5131         *ret_conv = CResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ_err(e_conv);
5132         return (long)ret_conv;
5133 }
5134
5135 void  __attribute__((visibility("default"))) TS_CResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ_free(uint32_t _res) {
5136         if ((_res & 1) != 0) return;
5137         LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ _res_conv = *(LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ*)(((uint64_t)_res) & ~1);
5138         FREE((void*)_res);
5139         CResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ_free(_res_conv);
5140 }
5141
5142 uint32_t  __attribute__((visibility("default"))) TS_CResult_NetAddressu8Z_ok(uint32_t o) {
5143         LDKNetAddress o_conv = *(LDKNetAddress*)(((uint64_t)o) & ~1);
5144         FREE((void*)o);
5145         LDKCResult_NetAddressu8Z* ret_conv = MALLOC(sizeof(LDKCResult_NetAddressu8Z), "LDKCResult_NetAddressu8Z");
5146         *ret_conv = CResult_NetAddressu8Z_ok(o_conv);
5147         return (long)ret_conv;
5148 }
5149
5150 uint32_t  __attribute__((visibility("default"))) TS_CResult_NetAddressu8Z_err(int8_t e) {
5151         LDKCResult_NetAddressu8Z* ret_conv = MALLOC(sizeof(LDKCResult_NetAddressu8Z), "LDKCResult_NetAddressu8Z");
5152         *ret_conv = CResult_NetAddressu8Z_err(e);
5153         return (long)ret_conv;
5154 }
5155
5156 void  __attribute__((visibility("default"))) TS_CResult_NetAddressu8Z_free(uint32_t _res) {
5157         if ((_res & 1) != 0) return;
5158         LDKCResult_NetAddressu8Z _res_conv = *(LDKCResult_NetAddressu8Z*)(((uint64_t)_res) & ~1);
5159         FREE((void*)_res);
5160         CResult_NetAddressu8Z_free(_res_conv);
5161 }
5162
5163 uint32_t  __attribute__((visibility("default"))) TS_CResult_NetAddressu8Z_clone(uint32_t orig) {
5164         LDKCResult_NetAddressu8Z* orig_conv = (LDKCResult_NetAddressu8Z*)(orig & ~1);
5165         LDKCResult_NetAddressu8Z* ret_conv = MALLOC(sizeof(LDKCResult_NetAddressu8Z), "LDKCResult_NetAddressu8Z");
5166         *ret_conv = CResult_NetAddressu8Z_clone(orig_conv);
5167         return (long)ret_conv;
5168 }
5169
5170 uint32_t  __attribute__((visibility("default"))) TS_CResult_CResult_NetAddressu8ZDecodeErrorZ_ok(uint32_t o) {
5171         LDKCResult_NetAddressu8Z o_conv = *(LDKCResult_NetAddressu8Z*)(((uint64_t)o) & ~1);
5172         FREE((void*)o);
5173         LDKCResult_CResult_NetAddressu8ZDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_CResult_NetAddressu8ZDecodeErrorZ), "LDKCResult_CResult_NetAddressu8ZDecodeErrorZ");
5174         *ret_conv = CResult_CResult_NetAddressu8ZDecodeErrorZ_ok(o_conv);
5175         return (long)ret_conv;
5176 }
5177
5178 uint32_t  __attribute__((visibility("default"))) TS_CResult_CResult_NetAddressu8ZDecodeErrorZ_err(uint32_t e) {
5179         LDKDecodeError e_conv;
5180         e_conv.inner = (void*)(e & (~1));
5181         e_conv.is_owned = (e & 1) || (e == 0);
5182         e_conv = DecodeError_clone(&e_conv);
5183         LDKCResult_CResult_NetAddressu8ZDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_CResult_NetAddressu8ZDecodeErrorZ), "LDKCResult_CResult_NetAddressu8ZDecodeErrorZ");
5184         *ret_conv = CResult_CResult_NetAddressu8ZDecodeErrorZ_err(e_conv);
5185         return (long)ret_conv;
5186 }
5187
5188 void  __attribute__((visibility("default"))) TS_CResult_CResult_NetAddressu8ZDecodeErrorZ_free(uint32_t _res) {
5189         if ((_res & 1) != 0) return;
5190         LDKCResult_CResult_NetAddressu8ZDecodeErrorZ _res_conv = *(LDKCResult_CResult_NetAddressu8ZDecodeErrorZ*)(((uint64_t)_res) & ~1);
5191         FREE((void*)_res);
5192         CResult_CResult_NetAddressu8ZDecodeErrorZ_free(_res_conv);
5193 }
5194
5195 void  __attribute__((visibility("default"))) TS_CVec_u64Z_free(int64_tArray _res) {
5196         LDKCVec_u64Z _res_constr;
5197         _res_constr.datalen = *((uint32_t*)_res);
5198         if (_res_constr.datalen > 0)
5199                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(int64_t), "LDKCVec_u64Z Elements");
5200         else
5201                 _res_constr.data = NULL;
5202         int64_t* _res_vals = (int64_t*)(_res + 4);
5203         for (size_t i = 0; i < _res_constr.datalen; i++) {
5204                 int64_t arr_conv_8 = _res_vals[i];
5205                 _res_constr.data[i] = arr_conv_8;
5206         }
5207         CVec_u64Z_free(_res_constr);
5208 }
5209
5210 void  __attribute__((visibility("default"))) TS_CVec_UpdateAddHTLCZ_free(uint32_tArray _res) {
5211         LDKCVec_UpdateAddHTLCZ _res_constr;
5212         _res_constr.datalen = *((uint32_t*)_res);
5213         if (_res_constr.datalen > 0)
5214                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKUpdateAddHTLC), "LDKCVec_UpdateAddHTLCZ Elements");
5215         else
5216                 _res_constr.data = NULL;
5217         uint32_t* _res_vals = (uint32_t*)(_res + 4);
5218         for (size_t p = 0; p < _res_constr.datalen; p++) {
5219                 uint32_t arr_conv_15 = _res_vals[p];
5220                 LDKUpdateAddHTLC arr_conv_15_conv;
5221                 arr_conv_15_conv.inner = (void*)(arr_conv_15 & (~1));
5222                 arr_conv_15_conv.is_owned = (arr_conv_15 & 1) || (arr_conv_15 == 0);
5223                 _res_constr.data[p] = arr_conv_15_conv;
5224         }
5225         CVec_UpdateAddHTLCZ_free(_res_constr);
5226 }
5227
5228 void  __attribute__((visibility("default"))) TS_CVec_UpdateFulfillHTLCZ_free(uint32_tArray _res) {
5229         LDKCVec_UpdateFulfillHTLCZ _res_constr;
5230         _res_constr.datalen = *((uint32_t*)_res);
5231         if (_res_constr.datalen > 0)
5232                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKUpdateFulfillHTLC), "LDKCVec_UpdateFulfillHTLCZ Elements");
5233         else
5234                 _res_constr.data = NULL;
5235         uint32_t* _res_vals = (uint32_t*)(_res + 4);
5236         for (size_t t = 0; t < _res_constr.datalen; t++) {
5237                 uint32_t arr_conv_19 = _res_vals[t];
5238                 LDKUpdateFulfillHTLC arr_conv_19_conv;
5239                 arr_conv_19_conv.inner = (void*)(arr_conv_19 & (~1));
5240                 arr_conv_19_conv.is_owned = (arr_conv_19 & 1) || (arr_conv_19 == 0);
5241                 _res_constr.data[t] = arr_conv_19_conv;
5242         }
5243         CVec_UpdateFulfillHTLCZ_free(_res_constr);
5244 }
5245
5246 void  __attribute__((visibility("default"))) TS_CVec_UpdateFailHTLCZ_free(uint32_tArray _res) {
5247         LDKCVec_UpdateFailHTLCZ _res_constr;
5248         _res_constr.datalen = *((uint32_t*)_res);
5249         if (_res_constr.datalen > 0)
5250                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKUpdateFailHTLC), "LDKCVec_UpdateFailHTLCZ Elements");
5251         else
5252                 _res_constr.data = NULL;
5253         uint32_t* _res_vals = (uint32_t*)(_res + 4);
5254         for (size_t q = 0; q < _res_constr.datalen; q++) {
5255                 uint32_t arr_conv_16 = _res_vals[q];
5256                 LDKUpdateFailHTLC arr_conv_16_conv;
5257                 arr_conv_16_conv.inner = (void*)(arr_conv_16 & (~1));
5258                 arr_conv_16_conv.is_owned = (arr_conv_16 & 1) || (arr_conv_16 == 0);
5259                 _res_constr.data[q] = arr_conv_16_conv;
5260         }
5261         CVec_UpdateFailHTLCZ_free(_res_constr);
5262 }
5263
5264 void  __attribute__((visibility("default"))) TS_CVec_UpdateFailMalformedHTLCZ_free(uint32_tArray _res) {
5265         LDKCVec_UpdateFailMalformedHTLCZ _res_constr;
5266         _res_constr.datalen = *((uint32_t*)_res);
5267         if (_res_constr.datalen > 0)
5268                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKUpdateFailMalformedHTLC), "LDKCVec_UpdateFailMalformedHTLCZ Elements");
5269         else
5270                 _res_constr.data = NULL;
5271         uint32_t* _res_vals = (uint32_t*)(_res + 4);
5272         for (size_t z = 0; z < _res_constr.datalen; z++) {
5273                 uint32_t arr_conv_25 = _res_vals[z];
5274                 LDKUpdateFailMalformedHTLC arr_conv_25_conv;
5275                 arr_conv_25_conv.inner = (void*)(arr_conv_25 & (~1));
5276                 arr_conv_25_conv.is_owned = (arr_conv_25 & 1) || (arr_conv_25 == 0);
5277                 _res_constr.data[z] = arr_conv_25_conv;
5278         }
5279         CVec_UpdateFailMalformedHTLCZ_free(_res_constr);
5280 }
5281
5282 uint32_t  __attribute__((visibility("default"))) TS_CResult_boolLightningErrorZ_ok(jboolean o) {
5283         LDKCResult_boolLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_boolLightningErrorZ), "LDKCResult_boolLightningErrorZ");
5284         *ret_conv = CResult_boolLightningErrorZ_ok(o);
5285         return (long)ret_conv;
5286 }
5287
5288 uint32_t  __attribute__((visibility("default"))) TS_CResult_boolLightningErrorZ_err(uint32_t e) {
5289         LDKLightningError e_conv;
5290         e_conv.inner = (void*)(e & (~1));
5291         e_conv.is_owned = (e & 1) || (e == 0);
5292         e_conv = LightningError_clone(&e_conv);
5293         LDKCResult_boolLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_boolLightningErrorZ), "LDKCResult_boolLightningErrorZ");
5294         *ret_conv = CResult_boolLightningErrorZ_err(e_conv);
5295         return (long)ret_conv;
5296 }
5297
5298 void  __attribute__((visibility("default"))) TS_CResult_boolLightningErrorZ_free(uint32_t _res) {
5299         if ((_res & 1) != 0) return;
5300         LDKCResult_boolLightningErrorZ _res_conv = *(LDKCResult_boolLightningErrorZ*)(((uint64_t)_res) & ~1);
5301         FREE((void*)_res);
5302         CResult_boolLightningErrorZ_free(_res_conv);
5303 }
5304
5305 uint32_t  __attribute__((visibility("default"))) TS_CResult_boolLightningErrorZ_clone(uint32_t orig) {
5306         LDKCResult_boolLightningErrorZ* orig_conv = (LDKCResult_boolLightningErrorZ*)(orig & ~1);
5307         LDKCResult_boolLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_boolLightningErrorZ), "LDKCResult_boolLightningErrorZ");
5308         *ret_conv = CResult_boolLightningErrorZ_clone(orig_conv);
5309         return (long)ret_conv;
5310 }
5311
5312 void  __attribute__((visibility("default"))) TS_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ_free(uint32_t _res) {
5313         if ((_res & 1) != 0) return;
5314         LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ _res_conv = *(LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ*)(((uint64_t)_res) & ~1);
5315         FREE((void*)_res);
5316         C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ_free(_res_conv);
5317 }
5318
5319 uint32_t  __attribute__((visibility("default"))) TS_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ_new(uint32_t a, uint32_t b, uint32_t c) {
5320         LDKChannelAnnouncement a_conv;
5321         a_conv.inner = (void*)(a & (~1));
5322         a_conv.is_owned = (a & 1) || (a == 0);
5323         a_conv = ChannelAnnouncement_clone(&a_conv);
5324         LDKChannelUpdate b_conv;
5325         b_conv.inner = (void*)(b & (~1));
5326         b_conv.is_owned = (b & 1) || (b == 0);
5327         b_conv = ChannelUpdate_clone(&b_conv);
5328         LDKChannelUpdate c_conv;
5329         c_conv.inner = (void*)(c & (~1));
5330         c_conv.is_owned = (c & 1) || (c == 0);
5331         c_conv = ChannelUpdate_clone(&c_conv);
5332         LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ* ret_ref = MALLOC(sizeof(LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ), "LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ");
5333         *ret_ref = C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ_new(a_conv, b_conv, c_conv);
5334         return (long)ret_ref;
5335 }
5336
5337 void  __attribute__((visibility("default"))) TS_CVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ_free(uint32_tArray _res) {
5338         LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ _res_constr;
5339         _res_constr.datalen = *((uint32_t*)_res);
5340         if (_res_constr.datalen > 0)
5341                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ), "LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ Elements");
5342         else
5343                 _res_constr.data = NULL;
5344         uint32_t* _res_vals = (uint32_t*)(_res + 4);
5345         for (size_t l = 0; l < _res_constr.datalen; l++) {
5346                 uint32_t arr_conv_63 = _res_vals[l];
5347                 LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ arr_conv_63_conv = *(LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ*)(((uint64_t)arr_conv_63) & ~1);
5348                 FREE((void*)arr_conv_63);
5349                 _res_constr.data[l] = arr_conv_63_conv;
5350         }
5351         CVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ_free(_res_constr);
5352 }
5353
5354 void  __attribute__((visibility("default"))) TS_CVec_NodeAnnouncementZ_free(uint32_tArray _res) {
5355         LDKCVec_NodeAnnouncementZ _res_constr;
5356         _res_constr.datalen = *((uint32_t*)_res);
5357         if (_res_constr.datalen > 0)
5358                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKNodeAnnouncement), "LDKCVec_NodeAnnouncementZ Elements");
5359         else
5360                 _res_constr.data = NULL;
5361         uint32_t* _res_vals = (uint32_t*)(_res + 4);
5362         for (size_t s = 0; s < _res_constr.datalen; s++) {
5363                 uint32_t arr_conv_18 = _res_vals[s];
5364                 LDKNodeAnnouncement arr_conv_18_conv;
5365                 arr_conv_18_conv.inner = (void*)(arr_conv_18 & (~1));
5366                 arr_conv_18_conv.is_owned = (arr_conv_18 & 1) || (arr_conv_18 == 0);
5367                 _res_constr.data[s] = arr_conv_18_conv;
5368         }
5369         CVec_NodeAnnouncementZ_free(_res_constr);
5370 }
5371
5372 uint32_t  __attribute__((visibility("default"))) TS_CResult_NoneLightningErrorZ_ok() {
5373         LDKCResult_NoneLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneLightningErrorZ), "LDKCResult_NoneLightningErrorZ");
5374         *ret_conv = CResult_NoneLightningErrorZ_ok();
5375         return (long)ret_conv;
5376 }
5377
5378 uint32_t  __attribute__((visibility("default"))) TS_CResult_NoneLightningErrorZ_err(uint32_t e) {
5379         LDKLightningError e_conv;
5380         e_conv.inner = (void*)(e & (~1));
5381         e_conv.is_owned = (e & 1) || (e == 0);
5382         e_conv = LightningError_clone(&e_conv);
5383         LDKCResult_NoneLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneLightningErrorZ), "LDKCResult_NoneLightningErrorZ");
5384         *ret_conv = CResult_NoneLightningErrorZ_err(e_conv);
5385         return (long)ret_conv;
5386 }
5387
5388 void  __attribute__((visibility("default"))) TS_CResult_NoneLightningErrorZ_free(uint32_t _res) {
5389         if ((_res & 1) != 0) return;
5390         LDKCResult_NoneLightningErrorZ _res_conv = *(LDKCResult_NoneLightningErrorZ*)(((uint64_t)_res) & ~1);
5391         FREE((void*)_res);
5392         CResult_NoneLightningErrorZ_free(_res_conv);
5393 }
5394
5395 uint32_t  __attribute__((visibility("default"))) TS_CResult_NoneLightningErrorZ_clone(uint32_t orig) {
5396         LDKCResult_NoneLightningErrorZ* orig_conv = (LDKCResult_NoneLightningErrorZ*)(orig & ~1);
5397         LDKCResult_NoneLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneLightningErrorZ), "LDKCResult_NoneLightningErrorZ");
5398         *ret_conv = CResult_NoneLightningErrorZ_clone(orig_conv);
5399         return (long)ret_conv;
5400 }
5401
5402 uint32_t  __attribute__((visibility("default"))) TS_CResult_ChannelReestablishDecodeErrorZ_ok(uint32_t o) {
5403         LDKChannelReestablish o_conv;
5404         o_conv.inner = (void*)(o & (~1));
5405         o_conv.is_owned = (o & 1) || (o == 0);
5406         o_conv = ChannelReestablish_clone(&o_conv);
5407         LDKCResult_ChannelReestablishDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ChannelReestablishDecodeErrorZ), "LDKCResult_ChannelReestablishDecodeErrorZ");
5408         *ret_conv = CResult_ChannelReestablishDecodeErrorZ_ok(o_conv);
5409         return (long)ret_conv;
5410 }
5411
5412 uint32_t  __attribute__((visibility("default"))) TS_CResult_ChannelReestablishDecodeErrorZ_err(uint32_t e) {
5413         LDKDecodeError e_conv;
5414         e_conv.inner = (void*)(e & (~1));
5415         e_conv.is_owned = (e & 1) || (e == 0);
5416         e_conv = DecodeError_clone(&e_conv);
5417         LDKCResult_ChannelReestablishDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ChannelReestablishDecodeErrorZ), "LDKCResult_ChannelReestablishDecodeErrorZ");
5418         *ret_conv = CResult_ChannelReestablishDecodeErrorZ_err(e_conv);
5419         return (long)ret_conv;
5420 }
5421
5422 void  __attribute__((visibility("default"))) TS_CResult_ChannelReestablishDecodeErrorZ_free(uint32_t _res) {
5423         if ((_res & 1) != 0) return;
5424         LDKCResult_ChannelReestablishDecodeErrorZ _res_conv = *(LDKCResult_ChannelReestablishDecodeErrorZ*)(((uint64_t)_res) & ~1);
5425         FREE((void*)_res);
5426         CResult_ChannelReestablishDecodeErrorZ_free(_res_conv);
5427 }
5428
5429 uint32_t  __attribute__((visibility("default"))) TS_CResult_InitDecodeErrorZ_ok(uint32_t o) {
5430         LDKInit o_conv;
5431         o_conv.inner = (void*)(o & (~1));
5432         o_conv.is_owned = (o & 1) || (o == 0);
5433         o_conv = Init_clone(&o_conv);
5434         LDKCResult_InitDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_InitDecodeErrorZ), "LDKCResult_InitDecodeErrorZ");
5435         *ret_conv = CResult_InitDecodeErrorZ_ok(o_conv);
5436         return (long)ret_conv;
5437 }
5438
5439 uint32_t  __attribute__((visibility("default"))) TS_CResult_InitDecodeErrorZ_err(uint32_t e) {
5440         LDKDecodeError e_conv;
5441         e_conv.inner = (void*)(e & (~1));
5442         e_conv.is_owned = (e & 1) || (e == 0);
5443         e_conv = DecodeError_clone(&e_conv);
5444         LDKCResult_InitDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_InitDecodeErrorZ), "LDKCResult_InitDecodeErrorZ");
5445         *ret_conv = CResult_InitDecodeErrorZ_err(e_conv);
5446         return (long)ret_conv;
5447 }
5448
5449 void  __attribute__((visibility("default"))) TS_CResult_InitDecodeErrorZ_free(uint32_t _res) {
5450         if ((_res & 1) != 0) return;
5451         LDKCResult_InitDecodeErrorZ _res_conv = *(LDKCResult_InitDecodeErrorZ*)(((uint64_t)_res) & ~1);
5452         FREE((void*)_res);
5453         CResult_InitDecodeErrorZ_free(_res_conv);
5454 }
5455
5456 uint32_t  __attribute__((visibility("default"))) TS_CResult_PingDecodeErrorZ_ok(uint32_t o) {
5457         LDKPing o_conv;
5458         o_conv.inner = (void*)(o & (~1));
5459         o_conv.is_owned = (o & 1) || (o == 0);
5460         o_conv = Ping_clone(&o_conv);
5461         LDKCResult_PingDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_PingDecodeErrorZ), "LDKCResult_PingDecodeErrorZ");
5462         *ret_conv = CResult_PingDecodeErrorZ_ok(o_conv);
5463         return (long)ret_conv;
5464 }
5465
5466 uint32_t  __attribute__((visibility("default"))) TS_CResult_PingDecodeErrorZ_err(uint32_t e) {
5467         LDKDecodeError e_conv;
5468         e_conv.inner = (void*)(e & (~1));
5469         e_conv.is_owned = (e & 1) || (e == 0);
5470         e_conv = DecodeError_clone(&e_conv);
5471         LDKCResult_PingDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_PingDecodeErrorZ), "LDKCResult_PingDecodeErrorZ");
5472         *ret_conv = CResult_PingDecodeErrorZ_err(e_conv);
5473         return (long)ret_conv;
5474 }
5475
5476 void  __attribute__((visibility("default"))) TS_CResult_PingDecodeErrorZ_free(uint32_t _res) {
5477         if ((_res & 1) != 0) return;
5478         LDKCResult_PingDecodeErrorZ _res_conv = *(LDKCResult_PingDecodeErrorZ*)(((uint64_t)_res) & ~1);
5479         FREE((void*)_res);
5480         CResult_PingDecodeErrorZ_free(_res_conv);
5481 }
5482
5483 uint32_t  __attribute__((visibility("default"))) TS_CResult_PongDecodeErrorZ_ok(uint32_t o) {
5484         LDKPong o_conv;
5485         o_conv.inner = (void*)(o & (~1));
5486         o_conv.is_owned = (o & 1) || (o == 0);
5487         o_conv = Pong_clone(&o_conv);
5488         LDKCResult_PongDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_PongDecodeErrorZ), "LDKCResult_PongDecodeErrorZ");
5489         *ret_conv = CResult_PongDecodeErrorZ_ok(o_conv);
5490         return (long)ret_conv;
5491 }
5492
5493 uint32_t  __attribute__((visibility("default"))) TS_CResult_PongDecodeErrorZ_err(uint32_t e) {
5494         LDKDecodeError e_conv;
5495         e_conv.inner = (void*)(e & (~1));
5496         e_conv.is_owned = (e & 1) || (e == 0);
5497         e_conv = DecodeError_clone(&e_conv);
5498         LDKCResult_PongDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_PongDecodeErrorZ), "LDKCResult_PongDecodeErrorZ");
5499         *ret_conv = CResult_PongDecodeErrorZ_err(e_conv);
5500         return (long)ret_conv;
5501 }
5502
5503 void  __attribute__((visibility("default"))) TS_CResult_PongDecodeErrorZ_free(uint32_t _res) {
5504         if ((_res & 1) != 0) return;
5505         LDKCResult_PongDecodeErrorZ _res_conv = *(LDKCResult_PongDecodeErrorZ*)(((uint64_t)_res) & ~1);
5506         FREE((void*)_res);
5507         CResult_PongDecodeErrorZ_free(_res_conv);
5508 }
5509
5510 uint32_t  __attribute__((visibility("default"))) TS_CResult_UnsignedChannelAnnouncementDecodeErrorZ_ok(uint32_t o) {
5511         LDKUnsignedChannelAnnouncement o_conv;
5512         o_conv.inner = (void*)(o & (~1));
5513         o_conv.is_owned = (o & 1) || (o == 0);
5514         o_conv = UnsignedChannelAnnouncement_clone(&o_conv);
5515         LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ), "LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ");
5516         *ret_conv = CResult_UnsignedChannelAnnouncementDecodeErrorZ_ok(o_conv);
5517         return (long)ret_conv;
5518 }
5519
5520 uint32_t  __attribute__((visibility("default"))) TS_CResult_UnsignedChannelAnnouncementDecodeErrorZ_err(uint32_t e) {
5521         LDKDecodeError e_conv;
5522         e_conv.inner = (void*)(e & (~1));
5523         e_conv.is_owned = (e & 1) || (e == 0);
5524         e_conv = DecodeError_clone(&e_conv);
5525         LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ), "LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ");
5526         *ret_conv = CResult_UnsignedChannelAnnouncementDecodeErrorZ_err(e_conv);
5527         return (long)ret_conv;
5528 }
5529
5530 void  __attribute__((visibility("default"))) TS_CResult_UnsignedChannelAnnouncementDecodeErrorZ_free(uint32_t _res) {
5531         if ((_res & 1) != 0) return;
5532         LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ _res_conv = *(LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ*)(((uint64_t)_res) & ~1);
5533         FREE((void*)_res);
5534         CResult_UnsignedChannelAnnouncementDecodeErrorZ_free(_res_conv);
5535 }
5536
5537 uint32_t  __attribute__((visibility("default"))) TS_CResult_UnsignedChannelUpdateDecodeErrorZ_ok(uint32_t o) {
5538         LDKUnsignedChannelUpdate o_conv;
5539         o_conv.inner = (void*)(o & (~1));
5540         o_conv.is_owned = (o & 1) || (o == 0);
5541         o_conv = UnsignedChannelUpdate_clone(&o_conv);
5542         LDKCResult_UnsignedChannelUpdateDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_UnsignedChannelUpdateDecodeErrorZ), "LDKCResult_UnsignedChannelUpdateDecodeErrorZ");
5543         *ret_conv = CResult_UnsignedChannelUpdateDecodeErrorZ_ok(o_conv);
5544         return (long)ret_conv;
5545 }
5546
5547 uint32_t  __attribute__((visibility("default"))) TS_CResult_UnsignedChannelUpdateDecodeErrorZ_err(uint32_t e) {
5548         LDKDecodeError e_conv;
5549         e_conv.inner = (void*)(e & (~1));
5550         e_conv.is_owned = (e & 1) || (e == 0);
5551         e_conv = DecodeError_clone(&e_conv);
5552         LDKCResult_UnsignedChannelUpdateDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_UnsignedChannelUpdateDecodeErrorZ), "LDKCResult_UnsignedChannelUpdateDecodeErrorZ");
5553         *ret_conv = CResult_UnsignedChannelUpdateDecodeErrorZ_err(e_conv);
5554         return (long)ret_conv;
5555 }
5556
5557 void  __attribute__((visibility("default"))) TS_CResult_UnsignedChannelUpdateDecodeErrorZ_free(uint32_t _res) {
5558         if ((_res & 1) != 0) return;
5559         LDKCResult_UnsignedChannelUpdateDecodeErrorZ _res_conv = *(LDKCResult_UnsignedChannelUpdateDecodeErrorZ*)(((uint64_t)_res) & ~1);
5560         FREE((void*)_res);
5561         CResult_UnsignedChannelUpdateDecodeErrorZ_free(_res_conv);
5562 }
5563
5564 uint32_t  __attribute__((visibility("default"))) TS_CResult_ErrorMessageDecodeErrorZ_ok(uint32_t o) {
5565         LDKErrorMessage o_conv;
5566         o_conv.inner = (void*)(o & (~1));
5567         o_conv.is_owned = (o & 1) || (o == 0);
5568         o_conv = ErrorMessage_clone(&o_conv);
5569         LDKCResult_ErrorMessageDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ErrorMessageDecodeErrorZ), "LDKCResult_ErrorMessageDecodeErrorZ");
5570         *ret_conv = CResult_ErrorMessageDecodeErrorZ_ok(o_conv);
5571         return (long)ret_conv;
5572 }
5573
5574 uint32_t  __attribute__((visibility("default"))) TS_CResult_ErrorMessageDecodeErrorZ_err(uint32_t e) {
5575         LDKDecodeError e_conv;
5576         e_conv.inner = (void*)(e & (~1));
5577         e_conv.is_owned = (e & 1) || (e == 0);
5578         e_conv = DecodeError_clone(&e_conv);
5579         LDKCResult_ErrorMessageDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ErrorMessageDecodeErrorZ), "LDKCResult_ErrorMessageDecodeErrorZ");
5580         *ret_conv = CResult_ErrorMessageDecodeErrorZ_err(e_conv);
5581         return (long)ret_conv;
5582 }
5583
5584 void  __attribute__((visibility("default"))) TS_CResult_ErrorMessageDecodeErrorZ_free(uint32_t _res) {
5585         if ((_res & 1) != 0) return;
5586         LDKCResult_ErrorMessageDecodeErrorZ _res_conv = *(LDKCResult_ErrorMessageDecodeErrorZ*)(((uint64_t)_res) & ~1);
5587         FREE((void*)_res);
5588         CResult_ErrorMessageDecodeErrorZ_free(_res_conv);
5589 }
5590
5591 uint32_t  __attribute__((visibility("default"))) TS_CResult_UnsignedNodeAnnouncementDecodeErrorZ_ok(uint32_t o) {
5592         LDKUnsignedNodeAnnouncement o_conv;
5593         o_conv.inner = (void*)(o & (~1));
5594         o_conv.is_owned = (o & 1) || (o == 0);
5595         o_conv = UnsignedNodeAnnouncement_clone(&o_conv);
5596         LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ), "LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ");
5597         *ret_conv = CResult_UnsignedNodeAnnouncementDecodeErrorZ_ok(o_conv);
5598         return (long)ret_conv;
5599 }
5600
5601 uint32_t  __attribute__((visibility("default"))) TS_CResult_UnsignedNodeAnnouncementDecodeErrorZ_err(uint32_t e) {
5602         LDKDecodeError e_conv;
5603         e_conv.inner = (void*)(e & (~1));
5604         e_conv.is_owned = (e & 1) || (e == 0);
5605         e_conv = DecodeError_clone(&e_conv);
5606         LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ), "LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ");
5607         *ret_conv = CResult_UnsignedNodeAnnouncementDecodeErrorZ_err(e_conv);
5608         return (long)ret_conv;
5609 }
5610
5611 void  __attribute__((visibility("default"))) TS_CResult_UnsignedNodeAnnouncementDecodeErrorZ_free(uint32_t _res) {
5612         if ((_res & 1) != 0) return;
5613         LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ _res_conv = *(LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ*)(((uint64_t)_res) & ~1);
5614         FREE((void*)_res);
5615         CResult_UnsignedNodeAnnouncementDecodeErrorZ_free(_res_conv);
5616 }
5617
5618 uint32_t  __attribute__((visibility("default"))) TS_CResult_QueryShortChannelIdsDecodeErrorZ_ok(uint32_t o) {
5619         LDKQueryShortChannelIds o_conv;
5620         o_conv.inner = (void*)(o & (~1));
5621         o_conv.is_owned = (o & 1) || (o == 0);
5622         o_conv = QueryShortChannelIds_clone(&o_conv);
5623         LDKCResult_QueryShortChannelIdsDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_QueryShortChannelIdsDecodeErrorZ), "LDKCResult_QueryShortChannelIdsDecodeErrorZ");
5624         *ret_conv = CResult_QueryShortChannelIdsDecodeErrorZ_ok(o_conv);
5625         return (long)ret_conv;
5626 }
5627
5628 uint32_t  __attribute__((visibility("default"))) TS_CResult_QueryShortChannelIdsDecodeErrorZ_err(uint32_t e) {
5629         LDKDecodeError e_conv;
5630         e_conv.inner = (void*)(e & (~1));
5631         e_conv.is_owned = (e & 1) || (e == 0);
5632         e_conv = DecodeError_clone(&e_conv);
5633         LDKCResult_QueryShortChannelIdsDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_QueryShortChannelIdsDecodeErrorZ), "LDKCResult_QueryShortChannelIdsDecodeErrorZ");
5634         *ret_conv = CResult_QueryShortChannelIdsDecodeErrorZ_err(e_conv);
5635         return (long)ret_conv;
5636 }
5637
5638 void  __attribute__((visibility("default"))) TS_CResult_QueryShortChannelIdsDecodeErrorZ_free(uint32_t _res) {
5639         if ((_res & 1) != 0) return;
5640         LDKCResult_QueryShortChannelIdsDecodeErrorZ _res_conv = *(LDKCResult_QueryShortChannelIdsDecodeErrorZ*)(((uint64_t)_res) & ~1);
5641         FREE((void*)_res);
5642         CResult_QueryShortChannelIdsDecodeErrorZ_free(_res_conv);
5643 }
5644
5645 uint32_t  __attribute__((visibility("default"))) TS_CResult_ReplyShortChannelIdsEndDecodeErrorZ_ok(uint32_t o) {
5646         LDKReplyShortChannelIdsEnd o_conv;
5647         o_conv.inner = (void*)(o & (~1));
5648         o_conv.is_owned = (o & 1) || (o == 0);
5649         o_conv = ReplyShortChannelIdsEnd_clone(&o_conv);
5650         LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ), "LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ");
5651         *ret_conv = CResult_ReplyShortChannelIdsEndDecodeErrorZ_ok(o_conv);
5652         return (long)ret_conv;
5653 }
5654
5655 uint32_t  __attribute__((visibility("default"))) TS_CResult_ReplyShortChannelIdsEndDecodeErrorZ_err(uint32_t e) {
5656         LDKDecodeError e_conv;
5657         e_conv.inner = (void*)(e & (~1));
5658         e_conv.is_owned = (e & 1) || (e == 0);
5659         e_conv = DecodeError_clone(&e_conv);
5660         LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ), "LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ");
5661         *ret_conv = CResult_ReplyShortChannelIdsEndDecodeErrorZ_err(e_conv);
5662         return (long)ret_conv;
5663 }
5664
5665 void  __attribute__((visibility("default"))) TS_CResult_ReplyShortChannelIdsEndDecodeErrorZ_free(uint32_t _res) {
5666         if ((_res & 1) != 0) return;
5667         LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ _res_conv = *(LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ*)(((uint64_t)_res) & ~1);
5668         FREE((void*)_res);
5669         CResult_ReplyShortChannelIdsEndDecodeErrorZ_free(_res_conv);
5670 }
5671
5672 uint32_t  __attribute__((visibility("default"))) TS_CResult_QueryChannelRangeDecodeErrorZ_ok(uint32_t o) {
5673         LDKQueryChannelRange o_conv;
5674         o_conv.inner = (void*)(o & (~1));
5675         o_conv.is_owned = (o & 1) || (o == 0);
5676         o_conv = QueryChannelRange_clone(&o_conv);
5677         LDKCResult_QueryChannelRangeDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_QueryChannelRangeDecodeErrorZ), "LDKCResult_QueryChannelRangeDecodeErrorZ");
5678         *ret_conv = CResult_QueryChannelRangeDecodeErrorZ_ok(o_conv);
5679         return (long)ret_conv;
5680 }
5681
5682 uint32_t  __attribute__((visibility("default"))) TS_CResult_QueryChannelRangeDecodeErrorZ_err(uint32_t e) {
5683         LDKDecodeError e_conv;
5684         e_conv.inner = (void*)(e & (~1));
5685         e_conv.is_owned = (e & 1) || (e == 0);
5686         e_conv = DecodeError_clone(&e_conv);
5687         LDKCResult_QueryChannelRangeDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_QueryChannelRangeDecodeErrorZ), "LDKCResult_QueryChannelRangeDecodeErrorZ");
5688         *ret_conv = CResult_QueryChannelRangeDecodeErrorZ_err(e_conv);
5689         return (long)ret_conv;
5690 }
5691
5692 void  __attribute__((visibility("default"))) TS_CResult_QueryChannelRangeDecodeErrorZ_free(uint32_t _res) {
5693         if ((_res & 1) != 0) return;
5694         LDKCResult_QueryChannelRangeDecodeErrorZ _res_conv = *(LDKCResult_QueryChannelRangeDecodeErrorZ*)(((uint64_t)_res) & ~1);
5695         FREE((void*)_res);
5696         CResult_QueryChannelRangeDecodeErrorZ_free(_res_conv);
5697 }
5698
5699 uint32_t  __attribute__((visibility("default"))) TS_CResult_ReplyChannelRangeDecodeErrorZ_ok(uint32_t o) {
5700         LDKReplyChannelRange o_conv;
5701         o_conv.inner = (void*)(o & (~1));
5702         o_conv.is_owned = (o & 1) || (o == 0);
5703         o_conv = ReplyChannelRange_clone(&o_conv);
5704         LDKCResult_ReplyChannelRangeDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ReplyChannelRangeDecodeErrorZ), "LDKCResult_ReplyChannelRangeDecodeErrorZ");
5705         *ret_conv = CResult_ReplyChannelRangeDecodeErrorZ_ok(o_conv);
5706         return (long)ret_conv;
5707 }
5708
5709 uint32_t  __attribute__((visibility("default"))) TS_CResult_ReplyChannelRangeDecodeErrorZ_err(uint32_t e) {
5710         LDKDecodeError e_conv;
5711         e_conv.inner = (void*)(e & (~1));
5712         e_conv.is_owned = (e & 1) || (e == 0);
5713         e_conv = DecodeError_clone(&e_conv);
5714         LDKCResult_ReplyChannelRangeDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ReplyChannelRangeDecodeErrorZ), "LDKCResult_ReplyChannelRangeDecodeErrorZ");
5715         *ret_conv = CResult_ReplyChannelRangeDecodeErrorZ_err(e_conv);
5716         return (long)ret_conv;
5717 }
5718
5719 void  __attribute__((visibility("default"))) TS_CResult_ReplyChannelRangeDecodeErrorZ_free(uint32_t _res) {
5720         if ((_res & 1) != 0) return;
5721         LDKCResult_ReplyChannelRangeDecodeErrorZ _res_conv = *(LDKCResult_ReplyChannelRangeDecodeErrorZ*)(((uint64_t)_res) & ~1);
5722         FREE((void*)_res);
5723         CResult_ReplyChannelRangeDecodeErrorZ_free(_res_conv);
5724 }
5725
5726 uint32_t  __attribute__((visibility("default"))) TS_CResult_GossipTimestampFilterDecodeErrorZ_ok(uint32_t o) {
5727         LDKGossipTimestampFilter o_conv;
5728         o_conv.inner = (void*)(o & (~1));
5729         o_conv.is_owned = (o & 1) || (o == 0);
5730         o_conv = GossipTimestampFilter_clone(&o_conv);
5731         LDKCResult_GossipTimestampFilterDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_GossipTimestampFilterDecodeErrorZ), "LDKCResult_GossipTimestampFilterDecodeErrorZ");
5732         *ret_conv = CResult_GossipTimestampFilterDecodeErrorZ_ok(o_conv);
5733         return (long)ret_conv;
5734 }
5735
5736 uint32_t  __attribute__((visibility("default"))) TS_CResult_GossipTimestampFilterDecodeErrorZ_err(uint32_t e) {
5737         LDKDecodeError e_conv;
5738         e_conv.inner = (void*)(e & (~1));
5739         e_conv.is_owned = (e & 1) || (e == 0);
5740         e_conv = DecodeError_clone(&e_conv);
5741         LDKCResult_GossipTimestampFilterDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_GossipTimestampFilterDecodeErrorZ), "LDKCResult_GossipTimestampFilterDecodeErrorZ");
5742         *ret_conv = CResult_GossipTimestampFilterDecodeErrorZ_err(e_conv);
5743         return (long)ret_conv;
5744 }
5745
5746 void  __attribute__((visibility("default"))) TS_CResult_GossipTimestampFilterDecodeErrorZ_free(uint32_t _res) {
5747         if ((_res & 1) != 0) return;
5748         LDKCResult_GossipTimestampFilterDecodeErrorZ _res_conv = *(LDKCResult_GossipTimestampFilterDecodeErrorZ*)(((uint64_t)_res) & ~1);
5749         FREE((void*)_res);
5750         CResult_GossipTimestampFilterDecodeErrorZ_free(_res_conv);
5751 }
5752
5753 void  __attribute__((visibility("default"))) TS_CVec_PublicKeyZ_free(ptrArray _res) {
5754         LDKCVec_PublicKeyZ _res_constr;
5755         _res_constr.datalen = *((uint32_t*)_res);
5756         if (_res_constr.datalen > 0)
5757                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKPublicKey), "LDKCVec_PublicKeyZ Elements");
5758         else
5759                 _res_constr.data = NULL;
5760         int8_tArray* _res_vals = (int8_tArray*)(_res + 4);
5761         for (size_t m = 0; m < _res_constr.datalen; m++) {
5762                 int8_tArray arr_conv_12 = _res_vals[m];
5763                 LDKPublicKey arr_conv_12_ref;
5764                 CHECK(*((uint32_t*)arr_conv_12) == 33);
5765                 memcpy(arr_conv_12_ref.compressed_form, (uint8_t*)(arr_conv_12 + 4), 33);
5766                 _res_constr.data[m] = arr_conv_12_ref;
5767         }
5768         CVec_PublicKeyZ_free(_res_constr);
5769 }
5770
5771 void  __attribute__((visibility("default"))) TS_CVec_u8Z_free(int8_tArray _res) {
5772         LDKCVec_u8Z _res_ref;
5773         _res_ref.datalen = *((uint32_t*)_res);
5774         _res_ref.data = MALLOC(_res_ref.datalen, "LDKCVec_u8Z Bytes");
5775         memcpy(_res_ref.data, (uint8_t*)(_res + 4), _res_ref.datalen);
5776         CVec_u8Z_free(_res_ref);
5777 }
5778
5779 uint32_t  __attribute__((visibility("default"))) TS_CResult_CVec_u8ZPeerHandleErrorZ_ok(int8_tArray o) {
5780         LDKCVec_u8Z o_ref;
5781         o_ref.datalen = *((uint32_t*)o);
5782         o_ref.data = MALLOC(o_ref.datalen, "LDKCVec_u8Z Bytes");
5783         memcpy(o_ref.data, (uint8_t*)(o + 4), o_ref.datalen);
5784         LDKCResult_CVec_u8ZPeerHandleErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_CVec_u8ZPeerHandleErrorZ), "LDKCResult_CVec_u8ZPeerHandleErrorZ");
5785         *ret_conv = CResult_CVec_u8ZPeerHandleErrorZ_ok(o_ref);
5786         return (long)ret_conv;
5787 }
5788
5789 uint32_t  __attribute__((visibility("default"))) TS_CResult_CVec_u8ZPeerHandleErrorZ_err(uint32_t e) {
5790         LDKPeerHandleError e_conv;
5791         e_conv.inner = (void*)(e & (~1));
5792         e_conv.is_owned = (e & 1) || (e == 0);
5793         e_conv = PeerHandleError_clone(&e_conv);
5794         LDKCResult_CVec_u8ZPeerHandleErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_CVec_u8ZPeerHandleErrorZ), "LDKCResult_CVec_u8ZPeerHandleErrorZ");
5795         *ret_conv = CResult_CVec_u8ZPeerHandleErrorZ_err(e_conv);
5796         return (long)ret_conv;
5797 }
5798
5799 void  __attribute__((visibility("default"))) TS_CResult_CVec_u8ZPeerHandleErrorZ_free(uint32_t _res) {
5800         if ((_res & 1) != 0) return;
5801         LDKCResult_CVec_u8ZPeerHandleErrorZ _res_conv = *(LDKCResult_CVec_u8ZPeerHandleErrorZ*)(((uint64_t)_res) & ~1);
5802         FREE((void*)_res);
5803         CResult_CVec_u8ZPeerHandleErrorZ_free(_res_conv);
5804 }
5805
5806 uint32_t  __attribute__((visibility("default"))) TS_CResult_CVec_u8ZPeerHandleErrorZ_clone(uint32_t orig) {
5807         LDKCResult_CVec_u8ZPeerHandleErrorZ* orig_conv = (LDKCResult_CVec_u8ZPeerHandleErrorZ*)(orig & ~1);
5808         LDKCResult_CVec_u8ZPeerHandleErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_CVec_u8ZPeerHandleErrorZ), "LDKCResult_CVec_u8ZPeerHandleErrorZ");
5809         *ret_conv = CResult_CVec_u8ZPeerHandleErrorZ_clone(orig_conv);
5810         return (long)ret_conv;
5811 }
5812
5813 uint32_t  __attribute__((visibility("default"))) TS_CResult_NonePeerHandleErrorZ_ok() {
5814         LDKCResult_NonePeerHandleErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NonePeerHandleErrorZ), "LDKCResult_NonePeerHandleErrorZ");
5815         *ret_conv = CResult_NonePeerHandleErrorZ_ok();
5816         return (long)ret_conv;
5817 }
5818
5819 uint32_t  __attribute__((visibility("default"))) TS_CResult_NonePeerHandleErrorZ_err(uint32_t e) {
5820         LDKPeerHandleError e_conv;
5821         e_conv.inner = (void*)(e & (~1));
5822         e_conv.is_owned = (e & 1) || (e == 0);
5823         e_conv = PeerHandleError_clone(&e_conv);
5824         LDKCResult_NonePeerHandleErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NonePeerHandleErrorZ), "LDKCResult_NonePeerHandleErrorZ");
5825         *ret_conv = CResult_NonePeerHandleErrorZ_err(e_conv);
5826         return (long)ret_conv;
5827 }
5828
5829 void  __attribute__((visibility("default"))) TS_CResult_NonePeerHandleErrorZ_free(uint32_t _res) {
5830         if ((_res & 1) != 0) return;
5831         LDKCResult_NonePeerHandleErrorZ _res_conv = *(LDKCResult_NonePeerHandleErrorZ*)(((uint64_t)_res) & ~1);
5832         FREE((void*)_res);
5833         CResult_NonePeerHandleErrorZ_free(_res_conv);
5834 }
5835
5836 uint32_t  __attribute__((visibility("default"))) TS_CResult_NonePeerHandleErrorZ_clone(uint32_t orig) {
5837         LDKCResult_NonePeerHandleErrorZ* orig_conv = (LDKCResult_NonePeerHandleErrorZ*)(orig & ~1);
5838         LDKCResult_NonePeerHandleErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NonePeerHandleErrorZ), "LDKCResult_NonePeerHandleErrorZ");
5839         *ret_conv = CResult_NonePeerHandleErrorZ_clone(orig_conv);
5840         return (long)ret_conv;
5841 }
5842
5843 uint32_t  __attribute__((visibility("default"))) TS_CResult_boolPeerHandleErrorZ_ok(jboolean o) {
5844         LDKCResult_boolPeerHandleErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_boolPeerHandleErrorZ), "LDKCResult_boolPeerHandleErrorZ");
5845         *ret_conv = CResult_boolPeerHandleErrorZ_ok(o);
5846         return (long)ret_conv;
5847 }
5848
5849 uint32_t  __attribute__((visibility("default"))) TS_CResult_boolPeerHandleErrorZ_err(uint32_t e) {
5850         LDKPeerHandleError e_conv;
5851         e_conv.inner = (void*)(e & (~1));
5852         e_conv.is_owned = (e & 1) || (e == 0);
5853         e_conv = PeerHandleError_clone(&e_conv);
5854         LDKCResult_boolPeerHandleErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_boolPeerHandleErrorZ), "LDKCResult_boolPeerHandleErrorZ");
5855         *ret_conv = CResult_boolPeerHandleErrorZ_err(e_conv);
5856         return (long)ret_conv;
5857 }
5858
5859 void  __attribute__((visibility("default"))) TS_CResult_boolPeerHandleErrorZ_free(uint32_t _res) {
5860         if ((_res & 1) != 0) return;
5861         LDKCResult_boolPeerHandleErrorZ _res_conv = *(LDKCResult_boolPeerHandleErrorZ*)(((uint64_t)_res) & ~1);
5862         FREE((void*)_res);
5863         CResult_boolPeerHandleErrorZ_free(_res_conv);
5864 }
5865
5866 uint32_t  __attribute__((visibility("default"))) TS_CResult_boolPeerHandleErrorZ_clone(uint32_t orig) {
5867         LDKCResult_boolPeerHandleErrorZ* orig_conv = (LDKCResult_boolPeerHandleErrorZ*)(orig & ~1);
5868         LDKCResult_boolPeerHandleErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_boolPeerHandleErrorZ), "LDKCResult_boolPeerHandleErrorZ");
5869         *ret_conv = CResult_boolPeerHandleErrorZ_clone(orig_conv);
5870         return (long)ret_conv;
5871 }
5872
5873 uint32_t  __attribute__((visibility("default"))) TS_CResult_SecretKeySecpErrorZ_ok(int8_tArray o) {
5874         LDKSecretKey o_ref;
5875         CHECK(*((uint32_t*)o) == 32);
5876         memcpy(o_ref.bytes, (uint8_t*)(o + 4), 32);
5877         LDKCResult_SecretKeySecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_SecretKeySecpErrorZ), "LDKCResult_SecretKeySecpErrorZ");
5878         *ret_conv = CResult_SecretKeySecpErrorZ_ok(o_ref);
5879         return (long)ret_conv;
5880 }
5881
5882 uint32_t  __attribute__((visibility("default"))) TS_CResult_SecretKeySecpErrorZ_err(uint32_t e) {
5883         LDKSecp256k1Error e_conv = LDKSecp256k1Error_from_js(e);
5884         LDKCResult_SecretKeySecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_SecretKeySecpErrorZ), "LDKCResult_SecretKeySecpErrorZ");
5885         *ret_conv = CResult_SecretKeySecpErrorZ_err(e_conv);
5886         return (long)ret_conv;
5887 }
5888
5889 void  __attribute__((visibility("default"))) TS_CResult_SecretKeySecpErrorZ_free(uint32_t _res) {
5890         if ((_res & 1) != 0) return;
5891         LDKCResult_SecretKeySecpErrorZ _res_conv = *(LDKCResult_SecretKeySecpErrorZ*)(((uint64_t)_res) & ~1);
5892         FREE((void*)_res);
5893         CResult_SecretKeySecpErrorZ_free(_res_conv);
5894 }
5895
5896 uint32_t  __attribute__((visibility("default"))) TS_CResult_PublicKeySecpErrorZ_ok(int8_tArray o) {
5897         LDKPublicKey o_ref;
5898         CHECK(*((uint32_t*)o) == 33);
5899         memcpy(o_ref.compressed_form, (uint8_t*)(o + 4), 33);
5900         LDKCResult_PublicKeySecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_PublicKeySecpErrorZ), "LDKCResult_PublicKeySecpErrorZ");
5901         *ret_conv = CResult_PublicKeySecpErrorZ_ok(o_ref);
5902         return (long)ret_conv;
5903 }
5904
5905 uint32_t  __attribute__((visibility("default"))) TS_CResult_PublicKeySecpErrorZ_err(uint32_t e) {
5906         LDKSecp256k1Error e_conv = LDKSecp256k1Error_from_js(e);
5907         LDKCResult_PublicKeySecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_PublicKeySecpErrorZ), "LDKCResult_PublicKeySecpErrorZ");
5908         *ret_conv = CResult_PublicKeySecpErrorZ_err(e_conv);
5909         return (long)ret_conv;
5910 }
5911
5912 void  __attribute__((visibility("default"))) TS_CResult_PublicKeySecpErrorZ_free(uint32_t _res) {
5913         if ((_res & 1) != 0) return;
5914         LDKCResult_PublicKeySecpErrorZ _res_conv = *(LDKCResult_PublicKeySecpErrorZ*)(((uint64_t)_res) & ~1);
5915         FREE((void*)_res);
5916         CResult_PublicKeySecpErrorZ_free(_res_conv);
5917 }
5918
5919 uint32_t  __attribute__((visibility("default"))) TS_CResult_TxCreationKeysSecpErrorZ_ok(uint32_t o) {
5920         LDKTxCreationKeys o_conv;
5921         o_conv.inner = (void*)(o & (~1));
5922         o_conv.is_owned = (o & 1) || (o == 0);
5923         o_conv = TxCreationKeys_clone(&o_conv);
5924         LDKCResult_TxCreationKeysSecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_TxCreationKeysSecpErrorZ), "LDKCResult_TxCreationKeysSecpErrorZ");
5925         *ret_conv = CResult_TxCreationKeysSecpErrorZ_ok(o_conv);
5926         return (long)ret_conv;
5927 }
5928
5929 uint32_t  __attribute__((visibility("default"))) TS_CResult_TxCreationKeysSecpErrorZ_err(uint32_t e) {
5930         LDKSecp256k1Error e_conv = LDKSecp256k1Error_from_js(e);
5931         LDKCResult_TxCreationKeysSecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_TxCreationKeysSecpErrorZ), "LDKCResult_TxCreationKeysSecpErrorZ");
5932         *ret_conv = CResult_TxCreationKeysSecpErrorZ_err(e_conv);
5933         return (long)ret_conv;
5934 }
5935
5936 void  __attribute__((visibility("default"))) TS_CResult_TxCreationKeysSecpErrorZ_free(uint32_t _res) {
5937         if ((_res & 1) != 0) return;
5938         LDKCResult_TxCreationKeysSecpErrorZ _res_conv = *(LDKCResult_TxCreationKeysSecpErrorZ*)(((uint64_t)_res) & ~1);
5939         FREE((void*)_res);
5940         CResult_TxCreationKeysSecpErrorZ_free(_res_conv);
5941 }
5942
5943 uint32_t  __attribute__((visibility("default"))) TS_CResult_TrustedCommitmentTransactionNoneZ_ok(uint32_t o) {
5944         LDKTrustedCommitmentTransaction o_conv;
5945         o_conv.inner = (void*)(o & (~1));
5946         o_conv.is_owned = (o & 1) || (o == 0);
5947         // Warning: we need a move here but no clone is available for LDKTrustedCommitmentTransaction
5948         LDKCResult_TrustedCommitmentTransactionNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_TrustedCommitmentTransactionNoneZ), "LDKCResult_TrustedCommitmentTransactionNoneZ");
5949         *ret_conv = CResult_TrustedCommitmentTransactionNoneZ_ok(o_conv);
5950         return (long)ret_conv;
5951 }
5952
5953 uint32_t  __attribute__((visibility("default"))) TS_CResult_TrustedCommitmentTransactionNoneZ_err() {
5954         LDKCResult_TrustedCommitmentTransactionNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_TrustedCommitmentTransactionNoneZ), "LDKCResult_TrustedCommitmentTransactionNoneZ");
5955         *ret_conv = CResult_TrustedCommitmentTransactionNoneZ_err();
5956         return (long)ret_conv;
5957 }
5958
5959 void  __attribute__((visibility("default"))) TS_CResult_TrustedCommitmentTransactionNoneZ_free(uint32_t _res) {
5960         if ((_res & 1) != 0) return;
5961         LDKCResult_TrustedCommitmentTransactionNoneZ _res_conv = *(LDKCResult_TrustedCommitmentTransactionNoneZ*)(((uint64_t)_res) & ~1);
5962         FREE((void*)_res);
5963         CResult_TrustedCommitmentTransactionNoneZ_free(_res_conv);
5964 }
5965
5966 uint32_t  __attribute__((visibility("default"))) TS_CResult_CVec_SignatureZNoneZ_ok(ptrArray o) {
5967         LDKCVec_SignatureZ o_constr;
5968         o_constr.datalen = *((uint32_t*)o);
5969         if (o_constr.datalen > 0)
5970                 o_constr.data = MALLOC(o_constr.datalen * sizeof(LDKSignature), "LDKCVec_SignatureZ Elements");
5971         else
5972                 o_constr.data = NULL;
5973         int8_tArray* o_vals = (int8_tArray*)(o + 4);
5974         for (size_t m = 0; m < o_constr.datalen; m++) {
5975                 int8_tArray arr_conv_12 = o_vals[m];
5976                 LDKSignature arr_conv_12_ref;
5977                 CHECK(*((uint32_t*)arr_conv_12) == 64);
5978                 memcpy(arr_conv_12_ref.compact_form, (uint8_t*)(arr_conv_12 + 4), 64);
5979                 o_constr.data[m] = arr_conv_12_ref;
5980         }
5981         LDKCResult_CVec_SignatureZNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_CVec_SignatureZNoneZ), "LDKCResult_CVec_SignatureZNoneZ");
5982         *ret_conv = CResult_CVec_SignatureZNoneZ_ok(o_constr);
5983         return (long)ret_conv;
5984 }
5985
5986 uint32_t  __attribute__((visibility("default"))) TS_CResult_CVec_SignatureZNoneZ_err() {
5987         LDKCResult_CVec_SignatureZNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_CVec_SignatureZNoneZ), "LDKCResult_CVec_SignatureZNoneZ");
5988         *ret_conv = CResult_CVec_SignatureZNoneZ_err();
5989         return (long)ret_conv;
5990 }
5991
5992 void  __attribute__((visibility("default"))) TS_CResult_CVec_SignatureZNoneZ_free(uint32_t _res) {
5993         if ((_res & 1) != 0) return;
5994         LDKCResult_CVec_SignatureZNoneZ _res_conv = *(LDKCResult_CVec_SignatureZNoneZ*)(((uint64_t)_res) & ~1);
5995         FREE((void*)_res);
5996         CResult_CVec_SignatureZNoneZ_free(_res_conv);
5997 }
5998
5999 uint32_t  __attribute__((visibility("default"))) TS_CResult_CVec_SignatureZNoneZ_clone(uint32_t orig) {
6000         LDKCResult_CVec_SignatureZNoneZ* orig_conv = (LDKCResult_CVec_SignatureZNoneZ*)(orig & ~1);
6001         LDKCResult_CVec_SignatureZNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_CVec_SignatureZNoneZ), "LDKCResult_CVec_SignatureZNoneZ");
6002         *ret_conv = CResult_CVec_SignatureZNoneZ_clone(orig_conv);
6003         return (long)ret_conv;
6004 }
6005
6006 void  __attribute__((visibility("default"))) TS_CVec_RouteHopZ_free(uint32_tArray _res) {
6007         LDKCVec_RouteHopZ _res_constr;
6008         _res_constr.datalen = *((uint32_t*)_res);
6009         if (_res_constr.datalen > 0)
6010                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKRouteHop), "LDKCVec_RouteHopZ Elements");
6011         else
6012                 _res_constr.data = NULL;
6013         uint32_t* _res_vals = (uint32_t*)(_res + 4);
6014         for (size_t k = 0; k < _res_constr.datalen; k++) {
6015                 uint32_t arr_conv_10 = _res_vals[k];
6016                 LDKRouteHop arr_conv_10_conv;
6017                 arr_conv_10_conv.inner = (void*)(arr_conv_10 & (~1));
6018                 arr_conv_10_conv.is_owned = (arr_conv_10 & 1) || (arr_conv_10 == 0);
6019                 _res_constr.data[k] = arr_conv_10_conv;
6020         }
6021         CVec_RouteHopZ_free(_res_constr);
6022 }
6023
6024 void  __attribute__((visibility("default"))) TS_CVec_CVec_RouteHopZZ_free(ptrArray _res) {
6025         LDKCVec_CVec_RouteHopZZ _res_constr;
6026         _res_constr.datalen = *((uint32_t*)_res);
6027         if (_res_constr.datalen > 0)
6028                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKCVec_RouteHopZ), "LDKCVec_CVec_RouteHopZZ Elements");
6029         else
6030                 _res_constr.data = NULL;
6031         uint32_tArray* _res_vals = (uint32_tArray*)(_res + 4);
6032         for (size_t m = 0; m < _res_constr.datalen; m++) {
6033                 uint32_tArray arr_conv_12 = _res_vals[m];
6034                 LDKCVec_RouteHopZ arr_conv_12_constr;
6035                 arr_conv_12_constr.datalen = *((uint32_t*)arr_conv_12);
6036                 if (arr_conv_12_constr.datalen > 0)
6037                         arr_conv_12_constr.data = MALLOC(arr_conv_12_constr.datalen * sizeof(LDKRouteHop), "LDKCVec_RouteHopZ Elements");
6038                 else
6039                         arr_conv_12_constr.data = NULL;
6040                 uint32_t* arr_conv_12_vals = (uint32_t*)(arr_conv_12 + 4);
6041                 for (size_t k = 0; k < arr_conv_12_constr.datalen; k++) {
6042                         uint32_t arr_conv_10 = arr_conv_12_vals[k];
6043                         LDKRouteHop arr_conv_10_conv;
6044                         arr_conv_10_conv.inner = (void*)(arr_conv_10 & (~1));
6045                         arr_conv_10_conv.is_owned = (arr_conv_10 & 1) || (arr_conv_10 == 0);
6046                         arr_conv_12_constr.data[k] = arr_conv_10_conv;
6047                 }
6048                 _res_constr.data[m] = arr_conv_12_constr;
6049         }
6050         CVec_CVec_RouteHopZZ_free(_res_constr);
6051 }
6052
6053 uint32_t  __attribute__((visibility("default"))) TS_CResult_RouteDecodeErrorZ_ok(uint32_t o) {
6054         LDKRoute o_conv;
6055         o_conv.inner = (void*)(o & (~1));
6056         o_conv.is_owned = (o & 1) || (o == 0);
6057         o_conv = Route_clone(&o_conv);
6058         LDKCResult_RouteDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_RouteDecodeErrorZ), "LDKCResult_RouteDecodeErrorZ");
6059         *ret_conv = CResult_RouteDecodeErrorZ_ok(o_conv);
6060         return (long)ret_conv;
6061 }
6062
6063 uint32_t  __attribute__((visibility("default"))) TS_CResult_RouteDecodeErrorZ_err(uint32_t e) {
6064         LDKDecodeError e_conv;
6065         e_conv.inner = (void*)(e & (~1));
6066         e_conv.is_owned = (e & 1) || (e == 0);
6067         e_conv = DecodeError_clone(&e_conv);
6068         LDKCResult_RouteDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_RouteDecodeErrorZ), "LDKCResult_RouteDecodeErrorZ");
6069         *ret_conv = CResult_RouteDecodeErrorZ_err(e_conv);
6070         return (long)ret_conv;
6071 }
6072
6073 void  __attribute__((visibility("default"))) TS_CResult_RouteDecodeErrorZ_free(uint32_t _res) {
6074         if ((_res & 1) != 0) return;
6075         LDKCResult_RouteDecodeErrorZ _res_conv = *(LDKCResult_RouteDecodeErrorZ*)(((uint64_t)_res) & ~1);
6076         FREE((void*)_res);
6077         CResult_RouteDecodeErrorZ_free(_res_conv);
6078 }
6079
6080 void  __attribute__((visibility("default"))) TS_CVec_RouteHintZ_free(uint32_tArray _res) {
6081         LDKCVec_RouteHintZ _res_constr;
6082         _res_constr.datalen = *((uint32_t*)_res);
6083         if (_res_constr.datalen > 0)
6084                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKRouteHint), "LDKCVec_RouteHintZ Elements");
6085         else
6086                 _res_constr.data = NULL;
6087         uint32_t* _res_vals = (uint32_t*)(_res + 4);
6088         for (size_t l = 0; l < _res_constr.datalen; l++) {
6089                 uint32_t arr_conv_11 = _res_vals[l];
6090                 LDKRouteHint arr_conv_11_conv;
6091                 arr_conv_11_conv.inner = (void*)(arr_conv_11 & (~1));
6092                 arr_conv_11_conv.is_owned = (arr_conv_11 & 1) || (arr_conv_11 == 0);
6093                 _res_constr.data[l] = arr_conv_11_conv;
6094         }
6095         CVec_RouteHintZ_free(_res_constr);
6096 }
6097
6098 uint32_t  __attribute__((visibility("default"))) TS_CResult_RouteLightningErrorZ_ok(uint32_t o) {
6099         LDKRoute o_conv;
6100         o_conv.inner = (void*)(o & (~1));
6101         o_conv.is_owned = (o & 1) || (o == 0);
6102         o_conv = Route_clone(&o_conv);
6103         LDKCResult_RouteLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_RouteLightningErrorZ), "LDKCResult_RouteLightningErrorZ");
6104         *ret_conv = CResult_RouteLightningErrorZ_ok(o_conv);
6105         return (long)ret_conv;
6106 }
6107
6108 uint32_t  __attribute__((visibility("default"))) TS_CResult_RouteLightningErrorZ_err(uint32_t e) {
6109         LDKLightningError e_conv;
6110         e_conv.inner = (void*)(e & (~1));
6111         e_conv.is_owned = (e & 1) || (e == 0);
6112         e_conv = LightningError_clone(&e_conv);
6113         LDKCResult_RouteLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_RouteLightningErrorZ), "LDKCResult_RouteLightningErrorZ");
6114         *ret_conv = CResult_RouteLightningErrorZ_err(e_conv);
6115         return (long)ret_conv;
6116 }
6117
6118 void  __attribute__((visibility("default"))) TS_CResult_RouteLightningErrorZ_free(uint32_t _res) {
6119         if ((_res & 1) != 0) return;
6120         LDKCResult_RouteLightningErrorZ _res_conv = *(LDKCResult_RouteLightningErrorZ*)(((uint64_t)_res) & ~1);
6121         FREE((void*)_res);
6122         CResult_RouteLightningErrorZ_free(_res_conv);
6123 }
6124
6125 uint32_t  __attribute__((visibility("default"))) TS_CResult_RoutingFeesDecodeErrorZ_ok(uint32_t o) {
6126         LDKRoutingFees o_conv;
6127         o_conv.inner = (void*)(o & (~1));
6128         o_conv.is_owned = (o & 1) || (o == 0);
6129         o_conv = RoutingFees_clone(&o_conv);
6130         LDKCResult_RoutingFeesDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_RoutingFeesDecodeErrorZ), "LDKCResult_RoutingFeesDecodeErrorZ");
6131         *ret_conv = CResult_RoutingFeesDecodeErrorZ_ok(o_conv);
6132         return (long)ret_conv;
6133 }
6134
6135 uint32_t  __attribute__((visibility("default"))) TS_CResult_RoutingFeesDecodeErrorZ_err(uint32_t e) {
6136         LDKDecodeError e_conv;
6137         e_conv.inner = (void*)(e & (~1));
6138         e_conv.is_owned = (e & 1) || (e == 0);
6139         e_conv = DecodeError_clone(&e_conv);
6140         LDKCResult_RoutingFeesDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_RoutingFeesDecodeErrorZ), "LDKCResult_RoutingFeesDecodeErrorZ");
6141         *ret_conv = CResult_RoutingFeesDecodeErrorZ_err(e_conv);
6142         return (long)ret_conv;
6143 }
6144
6145 void  __attribute__((visibility("default"))) TS_CResult_RoutingFeesDecodeErrorZ_free(uint32_t _res) {
6146         if ((_res & 1) != 0) return;
6147         LDKCResult_RoutingFeesDecodeErrorZ _res_conv = *(LDKCResult_RoutingFeesDecodeErrorZ*)(((uint64_t)_res) & ~1);
6148         FREE((void*)_res);
6149         CResult_RoutingFeesDecodeErrorZ_free(_res_conv);
6150 }
6151
6152 uint32_t  __attribute__((visibility("default"))) TS_CResult_NodeAnnouncementInfoDecodeErrorZ_ok(uint32_t o) {
6153         LDKNodeAnnouncementInfo o_conv;
6154         o_conv.inner = (void*)(o & (~1));
6155         o_conv.is_owned = (o & 1) || (o == 0);
6156         o_conv = NodeAnnouncementInfo_clone(&o_conv);
6157         LDKCResult_NodeAnnouncementInfoDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NodeAnnouncementInfoDecodeErrorZ), "LDKCResult_NodeAnnouncementInfoDecodeErrorZ");
6158         *ret_conv = CResult_NodeAnnouncementInfoDecodeErrorZ_ok(o_conv);
6159         return (long)ret_conv;
6160 }
6161
6162 uint32_t  __attribute__((visibility("default"))) TS_CResult_NodeAnnouncementInfoDecodeErrorZ_err(uint32_t e) {
6163         LDKDecodeError e_conv;
6164         e_conv.inner = (void*)(e & (~1));
6165         e_conv.is_owned = (e & 1) || (e == 0);
6166         e_conv = DecodeError_clone(&e_conv);
6167         LDKCResult_NodeAnnouncementInfoDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NodeAnnouncementInfoDecodeErrorZ), "LDKCResult_NodeAnnouncementInfoDecodeErrorZ");
6168         *ret_conv = CResult_NodeAnnouncementInfoDecodeErrorZ_err(e_conv);
6169         return (long)ret_conv;
6170 }
6171
6172 void  __attribute__((visibility("default"))) TS_CResult_NodeAnnouncementInfoDecodeErrorZ_free(uint32_t _res) {
6173         if ((_res & 1) != 0) return;
6174         LDKCResult_NodeAnnouncementInfoDecodeErrorZ _res_conv = *(LDKCResult_NodeAnnouncementInfoDecodeErrorZ*)(((uint64_t)_res) & ~1);
6175         FREE((void*)_res);
6176         CResult_NodeAnnouncementInfoDecodeErrorZ_free(_res_conv);
6177 }
6178
6179 uint32_t  __attribute__((visibility("default"))) TS_CResult_NodeAnnouncementInfoDecodeErrorZ_clone(uint32_t orig) {
6180         LDKCResult_NodeAnnouncementInfoDecodeErrorZ* orig_conv = (LDKCResult_NodeAnnouncementInfoDecodeErrorZ*)(orig & ~1);
6181         LDKCResult_NodeAnnouncementInfoDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NodeAnnouncementInfoDecodeErrorZ), "LDKCResult_NodeAnnouncementInfoDecodeErrorZ");
6182         *ret_conv = CResult_NodeAnnouncementInfoDecodeErrorZ_clone(orig_conv);
6183         return (long)ret_conv;
6184 }
6185
6186 uint32_t  __attribute__((visibility("default"))) TS_CResult_NodeInfoDecodeErrorZ_ok(uint32_t o) {
6187         LDKNodeInfo o_conv;
6188         o_conv.inner = (void*)(o & (~1));
6189         o_conv.is_owned = (o & 1) || (o == 0);
6190         o_conv = NodeInfo_clone(&o_conv);
6191         LDKCResult_NodeInfoDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NodeInfoDecodeErrorZ), "LDKCResult_NodeInfoDecodeErrorZ");
6192         *ret_conv = CResult_NodeInfoDecodeErrorZ_ok(o_conv);
6193         return (long)ret_conv;
6194 }
6195
6196 uint32_t  __attribute__((visibility("default"))) TS_CResult_NodeInfoDecodeErrorZ_err(uint32_t e) {
6197         LDKDecodeError e_conv;
6198         e_conv.inner = (void*)(e & (~1));
6199         e_conv.is_owned = (e & 1) || (e == 0);
6200         e_conv = DecodeError_clone(&e_conv);
6201         LDKCResult_NodeInfoDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NodeInfoDecodeErrorZ), "LDKCResult_NodeInfoDecodeErrorZ");
6202         *ret_conv = CResult_NodeInfoDecodeErrorZ_err(e_conv);
6203         return (long)ret_conv;
6204 }
6205
6206 void  __attribute__((visibility("default"))) TS_CResult_NodeInfoDecodeErrorZ_free(uint32_t _res) {
6207         if ((_res & 1) != 0) return;
6208         LDKCResult_NodeInfoDecodeErrorZ _res_conv = *(LDKCResult_NodeInfoDecodeErrorZ*)(((uint64_t)_res) & ~1);
6209         FREE((void*)_res);
6210         CResult_NodeInfoDecodeErrorZ_free(_res_conv);
6211 }
6212
6213 uint32_t  __attribute__((visibility("default"))) TS_CResult_NodeInfoDecodeErrorZ_clone(uint32_t orig) {
6214         LDKCResult_NodeInfoDecodeErrorZ* orig_conv = (LDKCResult_NodeInfoDecodeErrorZ*)(orig & ~1);
6215         LDKCResult_NodeInfoDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NodeInfoDecodeErrorZ), "LDKCResult_NodeInfoDecodeErrorZ");
6216         *ret_conv = CResult_NodeInfoDecodeErrorZ_clone(orig_conv);
6217         return (long)ret_conv;
6218 }
6219
6220 uint32_t  __attribute__((visibility("default"))) TS_CResult_NetworkGraphDecodeErrorZ_ok(uint32_t o) {
6221         LDKNetworkGraph o_conv;
6222         o_conv.inner = (void*)(o & (~1));
6223         o_conv.is_owned = (o & 1) || (o == 0);
6224         // Warning: we need a move here but no clone is available for LDKNetworkGraph
6225         LDKCResult_NetworkGraphDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NetworkGraphDecodeErrorZ), "LDKCResult_NetworkGraphDecodeErrorZ");
6226         *ret_conv = CResult_NetworkGraphDecodeErrorZ_ok(o_conv);
6227         return (long)ret_conv;
6228 }
6229
6230 uint32_t  __attribute__((visibility("default"))) TS_CResult_NetworkGraphDecodeErrorZ_err(uint32_t e) {
6231         LDKDecodeError e_conv;
6232         e_conv.inner = (void*)(e & (~1));
6233         e_conv.is_owned = (e & 1) || (e == 0);
6234         e_conv = DecodeError_clone(&e_conv);
6235         LDKCResult_NetworkGraphDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NetworkGraphDecodeErrorZ), "LDKCResult_NetworkGraphDecodeErrorZ");
6236         *ret_conv = CResult_NetworkGraphDecodeErrorZ_err(e_conv);
6237         return (long)ret_conv;
6238 }
6239
6240 void  __attribute__((visibility("default"))) TS_CResult_NetworkGraphDecodeErrorZ_free(uint32_t _res) {
6241         if ((_res & 1) != 0) return;
6242         LDKCResult_NetworkGraphDecodeErrorZ _res_conv = *(LDKCResult_NetworkGraphDecodeErrorZ*)(((uint64_t)_res) & ~1);
6243         FREE((void*)_res);
6244         CResult_NetworkGraphDecodeErrorZ_free(_res_conv);
6245 }
6246
6247 void  __attribute__((visibility("default"))) TS_Event_free(uint32_t this_ptr) {
6248         if ((this_ptr & 1) != 0) return;
6249         LDKEvent this_ptr_conv = *(LDKEvent*)(((uint64_t)this_ptr) & ~1);
6250         FREE((void*)this_ptr);
6251         Event_free(this_ptr_conv);
6252 }
6253
6254 uint32_t  __attribute__((visibility("default"))) TS_Event_clone(uint32_t orig) {
6255         LDKEvent* orig_conv = (LDKEvent*)orig;
6256         LDKEvent *ret_copy = MALLOC(sizeof(LDKEvent), "LDKEvent");
6257         *ret_copy = Event_clone(orig_conv);
6258         long ret_ref = (long)ret_copy;
6259         return ret_ref;
6260 }
6261
6262 int8_tArray  __attribute__((visibility("default"))) TS_Event_write(uint32_t obj) {
6263         LDKEvent* obj_conv = (LDKEvent*)obj;
6264         LDKCVec_u8Z arg_var = Event_write(obj_conv);
6265         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
6266         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
6267         CVec_u8Z_free(arg_var);
6268         return arg_arr;
6269 }
6270
6271 void  __attribute__((visibility("default"))) TS_MessageSendEvent_free(uint32_t this_ptr) {
6272         if ((this_ptr & 1) != 0) return;
6273         LDKMessageSendEvent this_ptr_conv = *(LDKMessageSendEvent*)(((uint64_t)this_ptr) & ~1);
6274         FREE((void*)this_ptr);
6275         MessageSendEvent_free(this_ptr_conv);
6276 }
6277
6278 uint32_t  __attribute__((visibility("default"))) TS_MessageSendEvent_clone(uint32_t orig) {
6279         LDKMessageSendEvent* orig_conv = (LDKMessageSendEvent*)orig;
6280         LDKMessageSendEvent *ret_copy = MALLOC(sizeof(LDKMessageSendEvent), "LDKMessageSendEvent");
6281         *ret_copy = MessageSendEvent_clone(orig_conv);
6282         long ret_ref = (long)ret_copy;
6283         return ret_ref;
6284 }
6285
6286 void  __attribute__((visibility("default"))) TS_MessageSendEventsProvider_free(uint32_t this_ptr) {
6287         if ((this_ptr & 1) != 0) return;
6288         LDKMessageSendEventsProvider this_ptr_conv = *(LDKMessageSendEventsProvider*)(((uint64_t)this_ptr) & ~1);
6289         FREE((void*)this_ptr);
6290         MessageSendEventsProvider_free(this_ptr_conv);
6291 }
6292
6293 void  __attribute__((visibility("default"))) TS_EventsProvider_free(uint32_t this_ptr) {
6294         if ((this_ptr & 1) != 0) return;
6295         LDKEventsProvider this_ptr_conv = *(LDKEventsProvider*)(((uint64_t)this_ptr) & ~1);
6296         FREE((void*)this_ptr);
6297         EventsProvider_free(this_ptr_conv);
6298 }
6299
6300 void  __attribute__((visibility("default"))) TS_APIError_free(uint32_t this_ptr) {
6301         if ((this_ptr & 1) != 0) return;
6302         LDKAPIError this_ptr_conv = *(LDKAPIError*)(((uint64_t)this_ptr) & ~1);
6303         FREE((void*)this_ptr);
6304         APIError_free(this_ptr_conv);
6305 }
6306
6307 uint32_t  __attribute__((visibility("default"))) TS_APIError_clone(uint32_t orig) {
6308         LDKAPIError* orig_conv = (LDKAPIError*)orig;
6309         LDKAPIError *ret_copy = MALLOC(sizeof(LDKAPIError), "LDKAPIError");
6310         *ret_copy = APIError_clone(orig_conv);
6311         long ret_ref = (long)ret_copy;
6312         return ret_ref;
6313 }
6314
6315 uint32_t  __attribute__((visibility("default"))) TS_Level_clone(uint32_t orig) {
6316         LDKLevel* orig_conv = (LDKLevel*)(orig & ~1);
6317         uint32_t ret_conv = LDKLevel_to_js(Level_clone(orig_conv));
6318         return ret_conv;
6319 }
6320
6321 uint32_t  __attribute__((visibility("default"))) TS_Level_max() {
6322         uint32_t ret_conv = LDKLevel_to_js(Level_max());
6323         return ret_conv;
6324 }
6325
6326 void  __attribute__((visibility("default"))) TS_Logger_free(uint32_t this_ptr) {
6327         if ((this_ptr & 1) != 0) return;
6328         LDKLogger this_ptr_conv = *(LDKLogger*)(((uint64_t)this_ptr) & ~1);
6329         FREE((void*)this_ptr);
6330         Logger_free(this_ptr_conv);
6331 }
6332
6333 void  __attribute__((visibility("default"))) TS_ChannelHandshakeConfig_free(uint32_t this_ptr) {
6334         LDKChannelHandshakeConfig this_ptr_conv;
6335         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6336         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
6337         ChannelHandshakeConfig_free(this_ptr_conv);
6338 }
6339
6340 uint32_t  __attribute__((visibility("default"))) TS_ChannelHandshakeConfig_clone(uint32_t orig) {
6341         LDKChannelHandshakeConfig orig_conv;
6342         orig_conv.inner = (void*)(orig & (~1));
6343         orig_conv.is_owned = false;
6344         LDKChannelHandshakeConfig ret_var = ChannelHandshakeConfig_clone(&orig_conv);
6345         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6346         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6347         long ret_ref = (long)ret_var.inner;
6348         if (ret_var.is_owned) {
6349                 ret_ref |= 1;
6350         }
6351         return ret_ref;
6352 }
6353
6354 int32_t  __attribute__((visibility("default"))) TS_ChannelHandshakeConfig_get_minimum_depth(uint32_t this_ptr) {
6355         LDKChannelHandshakeConfig this_ptr_conv;
6356         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6357         this_ptr_conv.is_owned = false;
6358         int32_t ret_val = ChannelHandshakeConfig_get_minimum_depth(&this_ptr_conv);
6359         return ret_val;
6360 }
6361
6362 void  __attribute__((visibility("default"))) TS_ChannelHandshakeConfig_set_minimum_depth(uint32_t this_ptr, int32_t val) {
6363         LDKChannelHandshakeConfig this_ptr_conv;
6364         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6365         this_ptr_conv.is_owned = false;
6366         ChannelHandshakeConfig_set_minimum_depth(&this_ptr_conv, val);
6367 }
6368
6369 int16_t  __attribute__((visibility("default"))) TS_ChannelHandshakeConfig_get_our_to_self_delay(uint32_t this_ptr) {
6370         LDKChannelHandshakeConfig this_ptr_conv;
6371         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6372         this_ptr_conv.is_owned = false;
6373         int16_t ret_val = ChannelHandshakeConfig_get_our_to_self_delay(&this_ptr_conv);
6374         return ret_val;
6375 }
6376
6377 void  __attribute__((visibility("default"))) TS_ChannelHandshakeConfig_set_our_to_self_delay(uint32_t this_ptr, int16_t val) {
6378         LDKChannelHandshakeConfig this_ptr_conv;
6379         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6380         this_ptr_conv.is_owned = false;
6381         ChannelHandshakeConfig_set_our_to_self_delay(&this_ptr_conv, val);
6382 }
6383
6384 int64_t  __attribute__((visibility("default"))) TS_ChannelHandshakeConfig_get_our_htlc_minimum_msat(uint32_t this_ptr) {
6385         LDKChannelHandshakeConfig this_ptr_conv;
6386         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6387         this_ptr_conv.is_owned = false;
6388         int64_t ret_val = ChannelHandshakeConfig_get_our_htlc_minimum_msat(&this_ptr_conv);
6389         return ret_val;
6390 }
6391
6392 void  __attribute__((visibility("default"))) TS_ChannelHandshakeConfig_set_our_htlc_minimum_msat(uint32_t this_ptr, int64_t val) {
6393         LDKChannelHandshakeConfig this_ptr_conv;
6394         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6395         this_ptr_conv.is_owned = false;
6396         ChannelHandshakeConfig_set_our_htlc_minimum_msat(&this_ptr_conv, val);
6397 }
6398
6399 uint32_t  __attribute__((visibility("default"))) TS_ChannelHandshakeConfig_new(int32_t minimum_depth_arg, int16_t our_to_self_delay_arg, int64_t our_htlc_minimum_msat_arg) {
6400         LDKChannelHandshakeConfig ret_var = ChannelHandshakeConfig_new(minimum_depth_arg, our_to_self_delay_arg, our_htlc_minimum_msat_arg);
6401         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6402         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6403         long ret_ref = (long)ret_var.inner;
6404         if (ret_var.is_owned) {
6405                 ret_ref |= 1;
6406         }
6407         return ret_ref;
6408 }
6409
6410 uint32_t  __attribute__((visibility("default"))) TS_ChannelHandshakeConfig_default() {
6411         LDKChannelHandshakeConfig ret_var = ChannelHandshakeConfig_default();
6412         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6413         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6414         long ret_ref = (long)ret_var.inner;
6415         if (ret_var.is_owned) {
6416                 ret_ref |= 1;
6417         }
6418         return ret_ref;
6419 }
6420
6421 void  __attribute__((visibility("default"))) TS_ChannelHandshakeLimits_free(uint32_t this_ptr) {
6422         LDKChannelHandshakeLimits this_ptr_conv;
6423         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6424         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
6425         ChannelHandshakeLimits_free(this_ptr_conv);
6426 }
6427
6428 uint32_t  __attribute__((visibility("default"))) TS_ChannelHandshakeLimits_clone(uint32_t orig) {
6429         LDKChannelHandshakeLimits orig_conv;
6430         orig_conv.inner = (void*)(orig & (~1));
6431         orig_conv.is_owned = false;
6432         LDKChannelHandshakeLimits ret_var = ChannelHandshakeLimits_clone(&orig_conv);
6433         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6434         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6435         long ret_ref = (long)ret_var.inner;
6436         if (ret_var.is_owned) {
6437                 ret_ref |= 1;
6438         }
6439         return ret_ref;
6440 }
6441
6442 int64_t  __attribute__((visibility("default"))) TS_ChannelHandshakeLimits_get_min_funding_satoshis(uint32_t this_ptr) {
6443         LDKChannelHandshakeLimits this_ptr_conv;
6444         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6445         this_ptr_conv.is_owned = false;
6446         int64_t ret_val = ChannelHandshakeLimits_get_min_funding_satoshis(&this_ptr_conv);
6447         return ret_val;
6448 }
6449
6450 void  __attribute__((visibility("default"))) TS_ChannelHandshakeLimits_set_min_funding_satoshis(uint32_t this_ptr, int64_t val) {
6451         LDKChannelHandshakeLimits this_ptr_conv;
6452         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6453         this_ptr_conv.is_owned = false;
6454         ChannelHandshakeLimits_set_min_funding_satoshis(&this_ptr_conv, val);
6455 }
6456
6457 int64_t  __attribute__((visibility("default"))) TS_ChannelHandshakeLimits_get_max_htlc_minimum_msat(uint32_t this_ptr) {
6458         LDKChannelHandshakeLimits this_ptr_conv;
6459         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6460         this_ptr_conv.is_owned = false;
6461         int64_t ret_val = ChannelHandshakeLimits_get_max_htlc_minimum_msat(&this_ptr_conv);
6462         return ret_val;
6463 }
6464
6465 void  __attribute__((visibility("default"))) TS_ChannelHandshakeLimits_set_max_htlc_minimum_msat(uint32_t this_ptr, int64_t val) {
6466         LDKChannelHandshakeLimits this_ptr_conv;
6467         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6468         this_ptr_conv.is_owned = false;
6469         ChannelHandshakeLimits_set_max_htlc_minimum_msat(&this_ptr_conv, val);
6470 }
6471
6472 int64_t  __attribute__((visibility("default"))) TS_ChannelHandshakeLimits_get_min_max_htlc_value_in_flight_msat(uint32_t this_ptr) {
6473         LDKChannelHandshakeLimits this_ptr_conv;
6474         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6475         this_ptr_conv.is_owned = false;
6476         int64_t ret_val = ChannelHandshakeLimits_get_min_max_htlc_value_in_flight_msat(&this_ptr_conv);
6477         return ret_val;
6478 }
6479
6480 void  __attribute__((visibility("default"))) TS_ChannelHandshakeLimits_set_min_max_htlc_value_in_flight_msat(uint32_t this_ptr, int64_t val) {
6481         LDKChannelHandshakeLimits this_ptr_conv;
6482         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6483         this_ptr_conv.is_owned = false;
6484         ChannelHandshakeLimits_set_min_max_htlc_value_in_flight_msat(&this_ptr_conv, val);
6485 }
6486
6487 int64_t  __attribute__((visibility("default"))) TS_ChannelHandshakeLimits_get_max_channel_reserve_satoshis(uint32_t this_ptr) {
6488         LDKChannelHandshakeLimits this_ptr_conv;
6489         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6490         this_ptr_conv.is_owned = false;
6491         int64_t ret_val = ChannelHandshakeLimits_get_max_channel_reserve_satoshis(&this_ptr_conv);
6492         return ret_val;
6493 }
6494
6495 void  __attribute__((visibility("default"))) TS_ChannelHandshakeLimits_set_max_channel_reserve_satoshis(uint32_t this_ptr, int64_t val) {
6496         LDKChannelHandshakeLimits this_ptr_conv;
6497         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6498         this_ptr_conv.is_owned = false;
6499         ChannelHandshakeLimits_set_max_channel_reserve_satoshis(&this_ptr_conv, val);
6500 }
6501
6502 int16_t  __attribute__((visibility("default"))) TS_ChannelHandshakeLimits_get_min_max_accepted_htlcs(uint32_t this_ptr) {
6503         LDKChannelHandshakeLimits this_ptr_conv;
6504         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6505         this_ptr_conv.is_owned = false;
6506         int16_t ret_val = ChannelHandshakeLimits_get_min_max_accepted_htlcs(&this_ptr_conv);
6507         return ret_val;
6508 }
6509
6510 void  __attribute__((visibility("default"))) TS_ChannelHandshakeLimits_set_min_max_accepted_htlcs(uint32_t this_ptr, int16_t val) {
6511         LDKChannelHandshakeLimits this_ptr_conv;
6512         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6513         this_ptr_conv.is_owned = false;
6514         ChannelHandshakeLimits_set_min_max_accepted_htlcs(&this_ptr_conv, val);
6515 }
6516
6517 int64_t  __attribute__((visibility("default"))) TS_ChannelHandshakeLimits_get_min_dust_limit_satoshis(uint32_t this_ptr) {
6518         LDKChannelHandshakeLimits this_ptr_conv;
6519         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6520         this_ptr_conv.is_owned = false;
6521         int64_t ret_val = ChannelHandshakeLimits_get_min_dust_limit_satoshis(&this_ptr_conv);
6522         return ret_val;
6523 }
6524
6525 void  __attribute__((visibility("default"))) TS_ChannelHandshakeLimits_set_min_dust_limit_satoshis(uint32_t this_ptr, int64_t val) {
6526         LDKChannelHandshakeLimits this_ptr_conv;
6527         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6528         this_ptr_conv.is_owned = false;
6529         ChannelHandshakeLimits_set_min_dust_limit_satoshis(&this_ptr_conv, val);
6530 }
6531
6532 int64_t  __attribute__((visibility("default"))) TS_ChannelHandshakeLimits_get_max_dust_limit_satoshis(uint32_t this_ptr) {
6533         LDKChannelHandshakeLimits this_ptr_conv;
6534         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6535         this_ptr_conv.is_owned = false;
6536         int64_t ret_val = ChannelHandshakeLimits_get_max_dust_limit_satoshis(&this_ptr_conv);
6537         return ret_val;
6538 }
6539
6540 void  __attribute__((visibility("default"))) TS_ChannelHandshakeLimits_set_max_dust_limit_satoshis(uint32_t this_ptr, int64_t val) {
6541         LDKChannelHandshakeLimits this_ptr_conv;
6542         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6543         this_ptr_conv.is_owned = false;
6544         ChannelHandshakeLimits_set_max_dust_limit_satoshis(&this_ptr_conv, val);
6545 }
6546
6547 int32_t  __attribute__((visibility("default"))) TS_ChannelHandshakeLimits_get_max_minimum_depth(uint32_t this_ptr) {
6548         LDKChannelHandshakeLimits this_ptr_conv;
6549         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6550         this_ptr_conv.is_owned = false;
6551         int32_t ret_val = ChannelHandshakeLimits_get_max_minimum_depth(&this_ptr_conv);
6552         return ret_val;
6553 }
6554
6555 void  __attribute__((visibility("default"))) TS_ChannelHandshakeLimits_set_max_minimum_depth(uint32_t this_ptr, int32_t val) {
6556         LDKChannelHandshakeLimits this_ptr_conv;
6557         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6558         this_ptr_conv.is_owned = false;
6559         ChannelHandshakeLimits_set_max_minimum_depth(&this_ptr_conv, val);
6560 }
6561
6562 jboolean  __attribute__((visibility("default"))) TS_ChannelHandshakeLimits_get_force_announced_channel_preference(uint32_t this_ptr) {
6563         LDKChannelHandshakeLimits this_ptr_conv;
6564         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6565         this_ptr_conv.is_owned = false;
6566         jboolean ret_val = ChannelHandshakeLimits_get_force_announced_channel_preference(&this_ptr_conv);
6567         return ret_val;
6568 }
6569
6570 void  __attribute__((visibility("default"))) TS_ChannelHandshakeLimits_set_force_announced_channel_preference(uint32_t this_ptr, jboolean val) {
6571         LDKChannelHandshakeLimits this_ptr_conv;
6572         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6573         this_ptr_conv.is_owned = false;
6574         ChannelHandshakeLimits_set_force_announced_channel_preference(&this_ptr_conv, val);
6575 }
6576
6577 int16_t  __attribute__((visibility("default"))) TS_ChannelHandshakeLimits_get_their_to_self_delay(uint32_t this_ptr) {
6578         LDKChannelHandshakeLimits this_ptr_conv;
6579         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6580         this_ptr_conv.is_owned = false;
6581         int16_t ret_val = ChannelHandshakeLimits_get_their_to_self_delay(&this_ptr_conv);
6582         return ret_val;
6583 }
6584
6585 void  __attribute__((visibility("default"))) TS_ChannelHandshakeLimits_set_their_to_self_delay(uint32_t this_ptr, int16_t val) {
6586         LDKChannelHandshakeLimits this_ptr_conv;
6587         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6588         this_ptr_conv.is_owned = false;
6589         ChannelHandshakeLimits_set_their_to_self_delay(&this_ptr_conv, val);
6590 }
6591
6592 uint32_t  __attribute__((visibility("default"))) 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) {
6593         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);
6594         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6595         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6596         long ret_ref = (long)ret_var.inner;
6597         if (ret_var.is_owned) {
6598                 ret_ref |= 1;
6599         }
6600         return ret_ref;
6601 }
6602
6603 uint32_t  __attribute__((visibility("default"))) TS_ChannelHandshakeLimits_default() {
6604         LDKChannelHandshakeLimits ret_var = ChannelHandshakeLimits_default();
6605         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6606         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6607         long ret_ref = (long)ret_var.inner;
6608         if (ret_var.is_owned) {
6609                 ret_ref |= 1;
6610         }
6611         return ret_ref;
6612 }
6613
6614 void  __attribute__((visibility("default"))) TS_ChannelConfig_free(uint32_t this_ptr) {
6615         LDKChannelConfig this_ptr_conv;
6616         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6617         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
6618         ChannelConfig_free(this_ptr_conv);
6619 }
6620
6621 uint32_t  __attribute__((visibility("default"))) TS_ChannelConfig_clone(uint32_t orig) {
6622         LDKChannelConfig orig_conv;
6623         orig_conv.inner = (void*)(orig & (~1));
6624         orig_conv.is_owned = false;
6625         LDKChannelConfig ret_var = ChannelConfig_clone(&orig_conv);
6626         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6627         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6628         long ret_ref = (long)ret_var.inner;
6629         if (ret_var.is_owned) {
6630                 ret_ref |= 1;
6631         }
6632         return ret_ref;
6633 }
6634
6635 int32_t  __attribute__((visibility("default"))) TS_ChannelConfig_get_fee_proportional_millionths(uint32_t this_ptr) {
6636         LDKChannelConfig this_ptr_conv;
6637         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6638         this_ptr_conv.is_owned = false;
6639         int32_t ret_val = ChannelConfig_get_fee_proportional_millionths(&this_ptr_conv);
6640         return ret_val;
6641 }
6642
6643 void  __attribute__((visibility("default"))) TS_ChannelConfig_set_fee_proportional_millionths(uint32_t this_ptr, int32_t val) {
6644         LDKChannelConfig this_ptr_conv;
6645         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6646         this_ptr_conv.is_owned = false;
6647         ChannelConfig_set_fee_proportional_millionths(&this_ptr_conv, val);
6648 }
6649
6650 jboolean  __attribute__((visibility("default"))) TS_ChannelConfig_get_announced_channel(uint32_t this_ptr) {
6651         LDKChannelConfig this_ptr_conv;
6652         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6653         this_ptr_conv.is_owned = false;
6654         jboolean ret_val = ChannelConfig_get_announced_channel(&this_ptr_conv);
6655         return ret_val;
6656 }
6657
6658 void  __attribute__((visibility("default"))) TS_ChannelConfig_set_announced_channel(uint32_t this_ptr, jboolean val) {
6659         LDKChannelConfig this_ptr_conv;
6660         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6661         this_ptr_conv.is_owned = false;
6662         ChannelConfig_set_announced_channel(&this_ptr_conv, val);
6663 }
6664
6665 jboolean  __attribute__((visibility("default"))) TS_ChannelConfig_get_commit_upfront_shutdown_pubkey(uint32_t this_ptr) {
6666         LDKChannelConfig this_ptr_conv;
6667         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6668         this_ptr_conv.is_owned = false;
6669         jboolean ret_val = ChannelConfig_get_commit_upfront_shutdown_pubkey(&this_ptr_conv);
6670         return ret_val;
6671 }
6672
6673 void  __attribute__((visibility("default"))) TS_ChannelConfig_set_commit_upfront_shutdown_pubkey(uint32_t this_ptr, jboolean val) {
6674         LDKChannelConfig this_ptr_conv;
6675         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6676         this_ptr_conv.is_owned = false;
6677         ChannelConfig_set_commit_upfront_shutdown_pubkey(&this_ptr_conv, val);
6678 }
6679
6680 uint32_t  __attribute__((visibility("default"))) TS_ChannelConfig_new(int32_t fee_proportional_millionths_arg, jboolean announced_channel_arg, jboolean commit_upfront_shutdown_pubkey_arg) {
6681         LDKChannelConfig ret_var = ChannelConfig_new(fee_proportional_millionths_arg, announced_channel_arg, commit_upfront_shutdown_pubkey_arg);
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 uint32_t  __attribute__((visibility("default"))) TS_ChannelConfig_default() {
6692         LDKChannelConfig ret_var = ChannelConfig_default();
6693         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6694         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6695         long ret_ref = (long)ret_var.inner;
6696         if (ret_var.is_owned) {
6697                 ret_ref |= 1;
6698         }
6699         return ret_ref;
6700 }
6701
6702 int8_tArray  __attribute__((visibility("default"))) TS_ChannelConfig_write(uint32_t obj) {
6703         LDKChannelConfig obj_conv;
6704         obj_conv.inner = (void*)(obj & (~1));
6705         obj_conv.is_owned = false;
6706         LDKCVec_u8Z arg_var = ChannelConfig_write(&obj_conv);
6707         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
6708         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
6709         CVec_u8Z_free(arg_var);
6710         return arg_arr;
6711 }
6712
6713 uint32_t  __attribute__((visibility("default"))) TS_ChannelConfig_read(int8_tArray ser) {
6714         LDKu8slice ser_ref;
6715         ser_ref.datalen = *((uint32_t*)ser);
6716         ser_ref.data = (int8_t*)(ser + 4);
6717         LDKChannelConfig ret_var = ChannelConfig_read(ser_ref);
6718         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6719         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6720         long ret_ref = (long)ret_var.inner;
6721         if (ret_var.is_owned) {
6722                 ret_ref |= 1;
6723         }
6724         return ret_ref;
6725 }
6726
6727 void  __attribute__((visibility("default"))) TS_UserConfig_free(uint32_t this_ptr) {
6728         LDKUserConfig this_ptr_conv;
6729         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6730         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
6731         UserConfig_free(this_ptr_conv);
6732 }
6733
6734 uint32_t  __attribute__((visibility("default"))) TS_UserConfig_clone(uint32_t orig) {
6735         LDKUserConfig orig_conv;
6736         orig_conv.inner = (void*)(orig & (~1));
6737         orig_conv.is_owned = false;
6738         LDKUserConfig ret_var = UserConfig_clone(&orig_conv);
6739         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6740         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6741         long ret_ref = (long)ret_var.inner;
6742         if (ret_var.is_owned) {
6743                 ret_ref |= 1;
6744         }
6745         return ret_ref;
6746 }
6747
6748 uint32_t  __attribute__((visibility("default"))) TS_UserConfig_get_own_channel_config(uint32_t this_ptr) {
6749         LDKUserConfig this_ptr_conv;
6750         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6751         this_ptr_conv.is_owned = false;
6752         LDKChannelHandshakeConfig ret_var = UserConfig_get_own_channel_config(&this_ptr_conv);
6753         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6754         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6755         long ret_ref = (long)ret_var.inner;
6756         if (ret_var.is_owned) {
6757                 ret_ref |= 1;
6758         }
6759         return ret_ref;
6760 }
6761
6762 void  __attribute__((visibility("default"))) TS_UserConfig_set_own_channel_config(uint32_t this_ptr, uint32_t val) {
6763         LDKUserConfig this_ptr_conv;
6764         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6765         this_ptr_conv.is_owned = false;
6766         LDKChannelHandshakeConfig val_conv;
6767         val_conv.inner = (void*)(val & (~1));
6768         val_conv.is_owned = (val & 1) || (val == 0);
6769         val_conv = ChannelHandshakeConfig_clone(&val_conv);
6770         UserConfig_set_own_channel_config(&this_ptr_conv, val_conv);
6771 }
6772
6773 uint32_t  __attribute__((visibility("default"))) TS_UserConfig_get_peer_channel_config_limits(uint32_t this_ptr) {
6774         LDKUserConfig this_ptr_conv;
6775         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6776         this_ptr_conv.is_owned = false;
6777         LDKChannelHandshakeLimits ret_var = UserConfig_get_peer_channel_config_limits(&this_ptr_conv);
6778         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6779         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6780         long ret_ref = (long)ret_var.inner;
6781         if (ret_var.is_owned) {
6782                 ret_ref |= 1;
6783         }
6784         return ret_ref;
6785 }
6786
6787 void  __attribute__((visibility("default"))) TS_UserConfig_set_peer_channel_config_limits(uint32_t this_ptr, uint32_t val) {
6788         LDKUserConfig this_ptr_conv;
6789         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6790         this_ptr_conv.is_owned = false;
6791         LDKChannelHandshakeLimits val_conv;
6792         val_conv.inner = (void*)(val & (~1));
6793         val_conv.is_owned = (val & 1) || (val == 0);
6794         val_conv = ChannelHandshakeLimits_clone(&val_conv);
6795         UserConfig_set_peer_channel_config_limits(&this_ptr_conv, val_conv);
6796 }
6797
6798 uint32_t  __attribute__((visibility("default"))) TS_UserConfig_get_channel_options(uint32_t this_ptr) {
6799         LDKUserConfig this_ptr_conv;
6800         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6801         this_ptr_conv.is_owned = false;
6802         LDKChannelConfig ret_var = UserConfig_get_channel_options(&this_ptr_conv);
6803         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6804         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6805         long ret_ref = (long)ret_var.inner;
6806         if (ret_var.is_owned) {
6807                 ret_ref |= 1;
6808         }
6809         return ret_ref;
6810 }
6811
6812 void  __attribute__((visibility("default"))) TS_UserConfig_set_channel_options(uint32_t this_ptr, uint32_t val) {
6813         LDKUserConfig this_ptr_conv;
6814         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6815         this_ptr_conv.is_owned = false;
6816         LDKChannelConfig val_conv;
6817         val_conv.inner = (void*)(val & (~1));
6818         val_conv.is_owned = (val & 1) || (val == 0);
6819         val_conv = ChannelConfig_clone(&val_conv);
6820         UserConfig_set_channel_options(&this_ptr_conv, val_conv);
6821 }
6822
6823 uint32_t  __attribute__((visibility("default"))) TS_UserConfig_new(uint32_t own_channel_config_arg, uint32_t peer_channel_config_limits_arg, uint32_t channel_options_arg) {
6824         LDKChannelHandshakeConfig own_channel_config_arg_conv;
6825         own_channel_config_arg_conv.inner = (void*)(own_channel_config_arg & (~1));
6826         own_channel_config_arg_conv.is_owned = (own_channel_config_arg & 1) || (own_channel_config_arg == 0);
6827         own_channel_config_arg_conv = ChannelHandshakeConfig_clone(&own_channel_config_arg_conv);
6828         LDKChannelHandshakeLimits peer_channel_config_limits_arg_conv;
6829         peer_channel_config_limits_arg_conv.inner = (void*)(peer_channel_config_limits_arg & (~1));
6830         peer_channel_config_limits_arg_conv.is_owned = (peer_channel_config_limits_arg & 1) || (peer_channel_config_limits_arg == 0);
6831         peer_channel_config_limits_arg_conv = ChannelHandshakeLimits_clone(&peer_channel_config_limits_arg_conv);
6832         LDKChannelConfig channel_options_arg_conv;
6833         channel_options_arg_conv.inner = (void*)(channel_options_arg & (~1));
6834         channel_options_arg_conv.is_owned = (channel_options_arg & 1) || (channel_options_arg == 0);
6835         channel_options_arg_conv = ChannelConfig_clone(&channel_options_arg_conv);
6836         LDKUserConfig ret_var = UserConfig_new(own_channel_config_arg_conv, peer_channel_config_limits_arg_conv, channel_options_arg_conv);
6837         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6838         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6839         long ret_ref = (long)ret_var.inner;
6840         if (ret_var.is_owned) {
6841                 ret_ref |= 1;
6842         }
6843         return ret_ref;
6844 }
6845
6846 uint32_t  __attribute__((visibility("default"))) TS_UserConfig_default() {
6847         LDKUserConfig ret_var = UserConfig_default();
6848         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6849         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6850         long ret_ref = (long)ret_var.inner;
6851         if (ret_var.is_owned) {
6852                 ret_ref |= 1;
6853         }
6854         return ret_ref;
6855 }
6856
6857 uint32_t  __attribute__((visibility("default"))) TS_AccessError_clone(uint32_t orig) {
6858         LDKAccessError* orig_conv = (LDKAccessError*)(orig & ~1);
6859         uint32_t ret_conv = LDKAccessError_to_js(AccessError_clone(orig_conv));
6860         return ret_conv;
6861 }
6862
6863 void  __attribute__((visibility("default"))) TS_Access_free(uint32_t this_ptr) {
6864         if ((this_ptr & 1) != 0) return;
6865         LDKAccess this_ptr_conv = *(LDKAccess*)(((uint64_t)this_ptr) & ~1);
6866         FREE((void*)this_ptr);
6867         Access_free(this_ptr_conv);
6868 }
6869
6870 void  __attribute__((visibility("default"))) TS_Watch_free(uint32_t this_ptr) {
6871         if ((this_ptr & 1) != 0) return;
6872         LDKWatch this_ptr_conv = *(LDKWatch*)(((uint64_t)this_ptr) & ~1);
6873         FREE((void*)this_ptr);
6874         Watch_free(this_ptr_conv);
6875 }
6876
6877 void  __attribute__((visibility("default"))) TS_Filter_free(uint32_t this_ptr) {
6878         if ((this_ptr & 1) != 0) return;
6879         LDKFilter this_ptr_conv = *(LDKFilter*)(((uint64_t)this_ptr) & ~1);
6880         FREE((void*)this_ptr);
6881         Filter_free(this_ptr_conv);
6882 }
6883
6884 void  __attribute__((visibility("default"))) TS_BroadcasterInterface_free(uint32_t this_ptr) {
6885         if ((this_ptr & 1) != 0) return;
6886         LDKBroadcasterInterface this_ptr_conv = *(LDKBroadcasterInterface*)(((uint64_t)this_ptr) & ~1);
6887         FREE((void*)this_ptr);
6888         BroadcasterInterface_free(this_ptr_conv);
6889 }
6890
6891 uint32_t  __attribute__((visibility("default"))) TS_ConfirmationTarget_clone(uint32_t orig) {
6892         LDKConfirmationTarget* orig_conv = (LDKConfirmationTarget*)(orig & ~1);
6893         uint32_t ret_conv = LDKConfirmationTarget_to_js(ConfirmationTarget_clone(orig_conv));
6894         return ret_conv;
6895 }
6896
6897 void  __attribute__((visibility("default"))) TS_FeeEstimator_free(uint32_t this_ptr) {
6898         if ((this_ptr & 1) != 0) return;
6899         LDKFeeEstimator this_ptr_conv = *(LDKFeeEstimator*)(((uint64_t)this_ptr) & ~1);
6900         FREE((void*)this_ptr);
6901         FeeEstimator_free(this_ptr_conv);
6902 }
6903
6904 void  __attribute__((visibility("default"))) TS_ChainMonitor_free(uint32_t this_ptr) {
6905         LDKChainMonitor this_ptr_conv;
6906         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6907         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
6908         ChainMonitor_free(this_ptr_conv);
6909 }
6910
6911 void  __attribute__((visibility("default"))) TS_ChainMonitor_block_connected(uint32_t this_arg, int8_tArray header, uint32_tArray txdata, int32_t height) {
6912         LDKChainMonitor this_arg_conv;
6913         this_arg_conv.inner = (void*)(this_arg & (~1));
6914         this_arg_conv.is_owned = false;
6915         unsigned char header_arr[80];
6916         CHECK(*((uint32_t*)header) == 80);
6917         memcpy(header_arr, (uint8_t*)(header + 4), 80);
6918         unsigned char (*header_ref)[80] = &header_arr;
6919         LDKCVec_C2Tuple_usizeTransactionZZ txdata_constr;
6920         txdata_constr.datalen = *((uint32_t*)txdata);
6921         if (txdata_constr.datalen > 0)
6922                 txdata_constr.data = MALLOC(txdata_constr.datalen * sizeof(LDKC2Tuple_usizeTransactionZ), "LDKCVec_C2Tuple_usizeTransactionZZ Elements");
6923         else
6924                 txdata_constr.data = NULL;
6925         uint32_t* txdata_vals = (uint32_t*)(txdata + 4);
6926         for (size_t e = 0; e < txdata_constr.datalen; e++) {
6927                 uint32_t arr_conv_30 = txdata_vals[e];
6928                 LDKC2Tuple_usizeTransactionZ arr_conv_30_conv = *(LDKC2Tuple_usizeTransactionZ*)(((uint64_t)arr_conv_30) & ~1);
6929                 FREE((void*)arr_conv_30);
6930                 txdata_constr.data[e] = arr_conv_30_conv;
6931         }
6932         ChainMonitor_block_connected(&this_arg_conv, header_ref, txdata_constr, height);
6933 }
6934
6935 void  __attribute__((visibility("default"))) TS_ChainMonitor_block_disconnected(uint32_t this_arg, int8_tArray header, int32_t disconnected_height) {
6936         LDKChainMonitor this_arg_conv;
6937         this_arg_conv.inner = (void*)(this_arg & (~1));
6938         this_arg_conv.is_owned = false;
6939         unsigned char header_arr[80];
6940         CHECK(*((uint32_t*)header) == 80);
6941         memcpy(header_arr, (uint8_t*)(header + 4), 80);
6942         unsigned char (*header_ref)[80] = &header_arr;
6943         ChainMonitor_block_disconnected(&this_arg_conv, header_ref, disconnected_height);
6944 }
6945
6946 uint32_t  __attribute__((visibility("default"))) TS_ChainMonitor_new(uint32_t chain_source, uint32_t broadcaster, uint32_t logger, uint32_t feeest, uint32_t persister) {
6947         LDKFilter* chain_source_conv = (LDKFilter*)chain_source;
6948         LDKBroadcasterInterface broadcaster_conv = *(LDKBroadcasterInterface*)(((uint64_t)broadcaster) & ~1);
6949         LDKLogger logger_conv = *(LDKLogger*)(((uint64_t)logger) & ~1);
6950         LDKFeeEstimator feeest_conv = *(LDKFeeEstimator*)(((uint64_t)feeest) & ~1);
6951         LDKPersist persister_conv = *(LDKPersist*)(((uint64_t)persister) & ~1);
6952         LDKChainMonitor ret_var = ChainMonitor_new(chain_source_conv, broadcaster_conv, logger_conv, feeest_conv, persister_conv);
6953         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6954         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6955         long ret_ref = (long)ret_var.inner;
6956         if (ret_var.is_owned) {
6957                 ret_ref |= 1;
6958         }
6959         return ret_ref;
6960 }
6961
6962 uint32_t  __attribute__((visibility("default"))) TS_ChainMonitor_as_Watch(uint32_t this_arg) {
6963         LDKChainMonitor this_arg_conv;
6964         this_arg_conv.inner = (void*)(this_arg & (~1));
6965         this_arg_conv.is_owned = false;
6966         LDKWatch* ret = MALLOC(sizeof(LDKWatch), "LDKWatch");
6967         *ret = ChainMonitor_as_Watch(&this_arg_conv);
6968         return (long)ret;
6969 }
6970
6971 uint32_t  __attribute__((visibility("default"))) TS_ChainMonitor_as_EventsProvider(uint32_t this_arg) {
6972         LDKChainMonitor this_arg_conv;
6973         this_arg_conv.inner = (void*)(this_arg & (~1));
6974         this_arg_conv.is_owned = false;
6975         LDKEventsProvider* ret = MALLOC(sizeof(LDKEventsProvider), "LDKEventsProvider");
6976         *ret = ChainMonitor_as_EventsProvider(&this_arg_conv);
6977         return (long)ret;
6978 }
6979
6980 void  __attribute__((visibility("default"))) TS_ChannelMonitorUpdate_free(uint32_t this_ptr) {
6981         LDKChannelMonitorUpdate this_ptr_conv;
6982         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6983         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
6984         ChannelMonitorUpdate_free(this_ptr_conv);
6985 }
6986
6987 uint32_t  __attribute__((visibility("default"))) TS_ChannelMonitorUpdate_clone(uint32_t orig) {
6988         LDKChannelMonitorUpdate orig_conv;
6989         orig_conv.inner = (void*)(orig & (~1));
6990         orig_conv.is_owned = false;
6991         LDKChannelMonitorUpdate ret_var = ChannelMonitorUpdate_clone(&orig_conv);
6992         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6993         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6994         long ret_ref = (long)ret_var.inner;
6995         if (ret_var.is_owned) {
6996                 ret_ref |= 1;
6997         }
6998         return ret_ref;
6999 }
7000
7001 int64_t  __attribute__((visibility("default"))) TS_ChannelMonitorUpdate_get_update_id(uint32_t this_ptr) {
7002         LDKChannelMonitorUpdate this_ptr_conv;
7003         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7004         this_ptr_conv.is_owned = false;
7005         int64_t ret_val = ChannelMonitorUpdate_get_update_id(&this_ptr_conv);
7006         return ret_val;
7007 }
7008
7009 void  __attribute__((visibility("default"))) TS_ChannelMonitorUpdate_set_update_id(uint32_t this_ptr, int64_t val) {
7010         LDKChannelMonitorUpdate this_ptr_conv;
7011         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7012         this_ptr_conv.is_owned = false;
7013         ChannelMonitorUpdate_set_update_id(&this_ptr_conv, val);
7014 }
7015
7016 int8_tArray  __attribute__((visibility("default"))) TS_ChannelMonitorUpdate_write(uint32_t obj) {
7017         LDKChannelMonitorUpdate obj_conv;
7018         obj_conv.inner = (void*)(obj & (~1));
7019         obj_conv.is_owned = false;
7020         LDKCVec_u8Z arg_var = ChannelMonitorUpdate_write(&obj_conv);
7021         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
7022         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
7023         CVec_u8Z_free(arg_var);
7024         return arg_arr;
7025 }
7026
7027 uint32_t  __attribute__((visibility("default"))) TS_ChannelMonitorUpdate_read(int8_tArray ser) {
7028         LDKu8slice ser_ref;
7029         ser_ref.datalen = *((uint32_t*)ser);
7030         ser_ref.data = (int8_t*)(ser + 4);
7031         LDKCResult_ChannelMonitorUpdateDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ChannelMonitorUpdateDecodeErrorZ), "LDKCResult_ChannelMonitorUpdateDecodeErrorZ");
7032         *ret_conv = ChannelMonitorUpdate_read(ser_ref);
7033         return (long)ret_conv;
7034 }
7035
7036 uint32_t  __attribute__((visibility("default"))) TS_ChannelMonitorUpdateErr_clone(uint32_t orig) {
7037         LDKChannelMonitorUpdateErr* orig_conv = (LDKChannelMonitorUpdateErr*)(orig & ~1);
7038         uint32_t ret_conv = LDKChannelMonitorUpdateErr_to_js(ChannelMonitorUpdateErr_clone(orig_conv));
7039         return ret_conv;
7040 }
7041
7042 void  __attribute__((visibility("default"))) TS_MonitorUpdateError_free(uint32_t this_ptr) {
7043         LDKMonitorUpdateError this_ptr_conv;
7044         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7045         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7046         MonitorUpdateError_free(this_ptr_conv);
7047 }
7048
7049 uint32_t  __attribute__((visibility("default"))) TS_MonitorUpdateError_clone(uint32_t orig) {
7050         LDKMonitorUpdateError orig_conv;
7051         orig_conv.inner = (void*)(orig & (~1));
7052         orig_conv.is_owned = false;
7053         LDKMonitorUpdateError ret_var = MonitorUpdateError_clone(&orig_conv);
7054         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7055         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7056         long ret_ref = (long)ret_var.inner;
7057         if (ret_var.is_owned) {
7058                 ret_ref |= 1;
7059         }
7060         return ret_ref;
7061 }
7062
7063 void  __attribute__((visibility("default"))) TS_MonitorEvent_free(uint32_t this_ptr) {
7064         LDKMonitorEvent this_ptr_conv;
7065         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7066         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7067         MonitorEvent_free(this_ptr_conv);
7068 }
7069
7070 uint32_t  __attribute__((visibility("default"))) TS_MonitorEvent_clone(uint32_t orig) {
7071         LDKMonitorEvent orig_conv;
7072         orig_conv.inner = (void*)(orig & (~1));
7073         orig_conv.is_owned = false;
7074         LDKMonitorEvent ret_var = MonitorEvent_clone(&orig_conv);
7075         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7076         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7077         long ret_ref = (long)ret_var.inner;
7078         if (ret_var.is_owned) {
7079                 ret_ref |= 1;
7080         }
7081         return ret_ref;
7082 }
7083
7084 void  __attribute__((visibility("default"))) TS_HTLCUpdate_free(uint32_t this_ptr) {
7085         LDKHTLCUpdate this_ptr_conv;
7086         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7087         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7088         HTLCUpdate_free(this_ptr_conv);
7089 }
7090
7091 uint32_t  __attribute__((visibility("default"))) TS_HTLCUpdate_clone(uint32_t orig) {
7092         LDKHTLCUpdate orig_conv;
7093         orig_conv.inner = (void*)(orig & (~1));
7094         orig_conv.is_owned = false;
7095         LDKHTLCUpdate ret_var = HTLCUpdate_clone(&orig_conv);
7096         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7097         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7098         long ret_ref = (long)ret_var.inner;
7099         if (ret_var.is_owned) {
7100                 ret_ref |= 1;
7101         }
7102         return ret_ref;
7103 }
7104
7105 int8_tArray  __attribute__((visibility("default"))) TS_HTLCUpdate_write(uint32_t obj) {
7106         LDKHTLCUpdate obj_conv;
7107         obj_conv.inner = (void*)(obj & (~1));
7108         obj_conv.is_owned = false;
7109         LDKCVec_u8Z arg_var = HTLCUpdate_write(&obj_conv);
7110         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
7111         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
7112         CVec_u8Z_free(arg_var);
7113         return arg_arr;
7114 }
7115
7116 uint32_t  __attribute__((visibility("default"))) TS_HTLCUpdate_read(int8_tArray ser) {
7117         LDKu8slice ser_ref;
7118         ser_ref.datalen = *((uint32_t*)ser);
7119         ser_ref.data = (int8_t*)(ser + 4);
7120         LDKHTLCUpdate ret_var = HTLCUpdate_read(ser_ref);
7121         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7122         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7123         long ret_ref = (long)ret_var.inner;
7124         if (ret_var.is_owned) {
7125                 ret_ref |= 1;
7126         }
7127         return ret_ref;
7128 }
7129
7130 void  __attribute__((visibility("default"))) TS_ChannelMonitor_free(uint32_t this_ptr) {
7131         LDKChannelMonitor this_ptr_conv;
7132         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7133         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7134         ChannelMonitor_free(this_ptr_conv);
7135 }
7136
7137 uint32_t  __attribute__((visibility("default"))) TS_ChannelMonitor_clone(uint32_t orig) {
7138         LDKChannelMonitor orig_conv;
7139         orig_conv.inner = (void*)(orig & (~1));
7140         orig_conv.is_owned = false;
7141         LDKChannelMonitor ret_var = ChannelMonitor_clone(&orig_conv);
7142         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7143         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7144         long ret_ref = (long)ret_var.inner;
7145         if (ret_var.is_owned) {
7146                 ret_ref |= 1;
7147         }
7148         return ret_ref;
7149 }
7150
7151 int8_tArray  __attribute__((visibility("default"))) TS_ChannelMonitor_write(uint32_t obj) {
7152         LDKChannelMonitor obj_conv;
7153         obj_conv.inner = (void*)(obj & (~1));
7154         obj_conv.is_owned = false;
7155         LDKCVec_u8Z arg_var = ChannelMonitor_write(&obj_conv);
7156         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
7157         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
7158         CVec_u8Z_free(arg_var);
7159         return arg_arr;
7160 }
7161
7162 uint32_t  __attribute__((visibility("default"))) TS_ChannelMonitor_update_monitor(uint32_t this_arg, uint32_t updates, uint32_t broadcaster, uint32_t fee_estimator, uint32_t logger) {
7163         LDKChannelMonitor this_arg_conv;
7164         this_arg_conv.inner = (void*)(this_arg & (~1));
7165         this_arg_conv.is_owned = false;
7166         LDKChannelMonitorUpdate updates_conv;
7167         updates_conv.inner = (void*)(updates & (~1));
7168         updates_conv.is_owned = false;
7169         LDKBroadcasterInterface* broadcaster_conv = (LDKBroadcasterInterface*)broadcaster;
7170         LDKFeeEstimator* fee_estimator_conv = (LDKFeeEstimator*)fee_estimator;
7171         LDKLogger* logger_conv = (LDKLogger*)logger;
7172         LDKCResult_NoneMonitorUpdateErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneMonitorUpdateErrorZ), "LDKCResult_NoneMonitorUpdateErrorZ");
7173         *ret_conv = ChannelMonitor_update_monitor(&this_arg_conv, &updates_conv, broadcaster_conv, fee_estimator_conv, logger_conv);
7174         return (long)ret_conv;
7175 }
7176
7177 int64_t  __attribute__((visibility("default"))) TS_ChannelMonitor_get_latest_update_id(uint32_t this_arg) {
7178         LDKChannelMonitor this_arg_conv;
7179         this_arg_conv.inner = (void*)(this_arg & (~1));
7180         this_arg_conv.is_owned = false;
7181         int64_t ret_val = ChannelMonitor_get_latest_update_id(&this_arg_conv);
7182         return ret_val;
7183 }
7184
7185 uint32_t  __attribute__((visibility("default"))) TS_ChannelMonitor_get_funding_txo(uint32_t this_arg) {
7186         LDKChannelMonitor this_arg_conv;
7187         this_arg_conv.inner = (void*)(this_arg & (~1));
7188         this_arg_conv.is_owned = false;
7189         LDKC2Tuple_OutPointScriptZ* ret_ref = MALLOC(sizeof(LDKC2Tuple_OutPointScriptZ), "LDKC2Tuple_OutPointScriptZ");
7190         *ret_ref = ChannelMonitor_get_funding_txo(&this_arg_conv);
7191         return (long)ret_ref;
7192 }
7193
7194 uint32_tArray  __attribute__((visibility("default"))) TS_ChannelMonitor_get_and_clear_pending_monitor_events(uint32_t this_arg) {
7195         LDKChannelMonitor this_arg_conv;
7196         this_arg_conv.inner = (void*)(this_arg & (~1));
7197         this_arg_conv.is_owned = false;
7198         LDKCVec_MonitorEventZ ret_var = ChannelMonitor_get_and_clear_pending_monitor_events(&this_arg_conv);
7199         uint32_tArray ret_arr = init_arr(ret_var.datalen, sizeof(uint32_t), "Native uint32_tArray Bytes");
7200         uint32_t *ret_arr_ptr = (uint32_t*)(ret_arr + 4);
7201         for (size_t o = 0; o < ret_var.datalen; o++) {
7202                 LDKMonitorEvent arr_conv_14_var = ret_var.data[o];
7203                 CHECK((((long)arr_conv_14_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7204                 CHECK((((long)&arr_conv_14_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7205                 long arr_conv_14_ref = (long)arr_conv_14_var.inner;
7206                 if (arr_conv_14_var.is_owned) {
7207                         arr_conv_14_ref |= 1;
7208                 }
7209                 ret_arr_ptr[o] = arr_conv_14_ref;
7210         }
7211         FREE(ret_var.data);
7212         return ret_arr;
7213 }
7214
7215 uint32_tArray  __attribute__((visibility("default"))) TS_ChannelMonitor_get_and_clear_pending_events(uint32_t this_arg) {
7216         LDKChannelMonitor this_arg_conv;
7217         this_arg_conv.inner = (void*)(this_arg & (~1));
7218         this_arg_conv.is_owned = false;
7219         LDKCVec_EventZ ret_var = ChannelMonitor_get_and_clear_pending_events(&this_arg_conv);
7220         uint32_tArray ret_arr = init_arr(ret_var.datalen, sizeof(uint32_t), "Native uint32_tArray Bytes");
7221         uint32_t *ret_arr_ptr = (uint32_t*)(ret_arr + 4);
7222         for (size_t h = 0; h < ret_var.datalen; h++) {
7223                 LDKEvent *arr_conv_7_copy = MALLOC(sizeof(LDKEvent), "LDKEvent");
7224                 *arr_conv_7_copy = Event_clone(&ret_var.data[h]);
7225                 long arr_conv_7_ref = (long)arr_conv_7_copy;
7226                 ret_arr_ptr[h] = arr_conv_7_ref;
7227         }
7228         FREE(ret_var.data);
7229         return ret_arr;
7230 }
7231
7232 ptrArray  __attribute__((visibility("default"))) TS_ChannelMonitor_get_latest_holder_commitment_txn(uint32_t this_arg, uint32_t logger) {
7233         LDKChannelMonitor this_arg_conv;
7234         this_arg_conv.inner = (void*)(this_arg & (~1));
7235         this_arg_conv.is_owned = false;
7236         LDKLogger* logger_conv = (LDKLogger*)logger;
7237         LDKCVec_TransactionZ ret_var = ChannelMonitor_get_latest_holder_commitment_txn(&this_arg_conv, logger_conv);
7238         ptrArray ret_arr = init_arr(ret_var.datalen, sizeof(uint32_t), "Native ptrArray Bytes");
7239         int8_tArray *ret_arr_ptr = (int8_tArray*)(ret_arr + 4);
7240         for (size_t m = 0; m < ret_var.datalen; m++) {
7241                 LDKTransaction arr_conv_12_var = ret_var.data[m];
7242                 int8_tArray arr_conv_12_arr = init_arr(arr_conv_12_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
7243                 memcpy((uint8_t*)(arr_conv_12_arr + 4), arr_conv_12_var.data, arr_conv_12_var.datalen);
7244                 Transaction_free(arr_conv_12_var);
7245                 ret_arr_ptr[m] = arr_conv_12_arr;
7246         }
7247         FREE(ret_var.data);
7248         return ret_arr;
7249 }
7250
7251 uint32_tArray  __attribute__((visibility("default"))) 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) {
7252         LDKChannelMonitor this_arg_conv;
7253         this_arg_conv.inner = (void*)(this_arg & (~1));
7254         this_arg_conv.is_owned = false;
7255         unsigned char header_arr[80];
7256         CHECK(*((uint32_t*)header) == 80);
7257         memcpy(header_arr, (uint8_t*)(header + 4), 80);
7258         unsigned char (*header_ref)[80] = &header_arr;
7259         LDKCVec_C2Tuple_usizeTransactionZZ txdata_constr;
7260         txdata_constr.datalen = *((uint32_t*)txdata);
7261         if (txdata_constr.datalen > 0)
7262                 txdata_constr.data = MALLOC(txdata_constr.datalen * sizeof(LDKC2Tuple_usizeTransactionZ), "LDKCVec_C2Tuple_usizeTransactionZZ Elements");
7263         else
7264                 txdata_constr.data = NULL;
7265         uint32_t* txdata_vals = (uint32_t*)(txdata + 4);
7266         for (size_t e = 0; e < txdata_constr.datalen; e++) {
7267                 uint32_t arr_conv_30 = txdata_vals[e];
7268                 LDKC2Tuple_usizeTransactionZ arr_conv_30_conv = *(LDKC2Tuple_usizeTransactionZ*)(((uint64_t)arr_conv_30) & ~1);
7269                 FREE((void*)arr_conv_30);
7270                 txdata_constr.data[e] = arr_conv_30_conv;
7271         }
7272         LDKBroadcasterInterface broadcaster_conv = *(LDKBroadcasterInterface*)(((uint64_t)broadcaster) & ~1);
7273         LDKFeeEstimator fee_estimator_conv = *(LDKFeeEstimator*)(((uint64_t)fee_estimator) & ~1);
7274         LDKLogger logger_conv = *(LDKLogger*)(((uint64_t)logger) & ~1);
7275         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);
7276         uint32_tArray ret_arr = init_arr(ret_var.datalen, sizeof(uint32_t), "Native uint32_tArray Bytes");
7277         uint32_t *ret_arr_ptr = (uint32_t*)(ret_arr + 4);
7278         for (size_t x = 0; x < ret_var.datalen; x++) {
7279                 LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ* arr_conv_49_ref = MALLOC(sizeof(LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ), "LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ");
7280                 *arr_conv_49_ref = ret_var.data[x];
7281                 ret_arr_ptr[x] = (long)arr_conv_49_ref;
7282         }
7283         FREE(ret_var.data);
7284         return ret_arr;
7285 }
7286
7287 void  __attribute__((visibility("default"))) TS_ChannelMonitor_block_disconnected(uint32_t this_arg, int8_tArray header, int32_t height, uint32_t broadcaster, uint32_t fee_estimator, uint32_t logger) {
7288         LDKChannelMonitor this_arg_conv;
7289         this_arg_conv.inner = (void*)(this_arg & (~1));
7290         this_arg_conv.is_owned = false;
7291         unsigned char header_arr[80];
7292         CHECK(*((uint32_t*)header) == 80);
7293         memcpy(header_arr, (uint8_t*)(header + 4), 80);
7294         unsigned char (*header_ref)[80] = &header_arr;
7295         LDKBroadcasterInterface broadcaster_conv = *(LDKBroadcasterInterface*)(((uint64_t)broadcaster) & ~1);
7296         LDKFeeEstimator fee_estimator_conv = *(LDKFeeEstimator*)(((uint64_t)fee_estimator) & ~1);
7297         LDKLogger logger_conv = *(LDKLogger*)(((uint64_t)logger) & ~1);
7298         ChannelMonitor_block_disconnected(&this_arg_conv, header_ref, height, broadcaster_conv, fee_estimator_conv, logger_conv);
7299 }
7300
7301 void  __attribute__((visibility("default"))) TS_Persist_free(uint32_t this_ptr) {
7302         if ((this_ptr & 1) != 0) return;
7303         LDKPersist this_ptr_conv = *(LDKPersist*)(((uint64_t)this_ptr) & ~1);
7304         FREE((void*)this_ptr);
7305         Persist_free(this_ptr_conv);
7306 }
7307
7308 uint32_t  __attribute__((visibility("default"))) TS_C2Tuple_BlockHashChannelMonitorZ_read(int8_tArray ser, uint32_t arg) {
7309         LDKu8slice ser_ref;
7310         ser_ref.datalen = *((uint32_t*)ser);
7311         ser_ref.data = (int8_t*)(ser + 4);
7312         LDKKeysInterface* arg_conv = (LDKKeysInterface*)arg;
7313         LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ), "LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ");
7314         *ret_conv = C2Tuple_BlockHashChannelMonitorZ_read(ser_ref, arg_conv);
7315         return (long)ret_conv;
7316 }
7317
7318 void  __attribute__((visibility("default"))) TS_OutPoint_free(uint32_t this_ptr) {
7319         LDKOutPoint this_ptr_conv;
7320         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7321         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7322         OutPoint_free(this_ptr_conv);
7323 }
7324
7325 uint32_t  __attribute__((visibility("default"))) TS_OutPoint_clone(uint32_t orig) {
7326         LDKOutPoint orig_conv;
7327         orig_conv.inner = (void*)(orig & (~1));
7328         orig_conv.is_owned = false;
7329         LDKOutPoint ret_var = OutPoint_clone(&orig_conv);
7330         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7331         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7332         long ret_ref = (long)ret_var.inner;
7333         if (ret_var.is_owned) {
7334                 ret_ref |= 1;
7335         }
7336         return ret_ref;
7337 }
7338
7339 int8_tArray  __attribute__((visibility("default"))) TS_OutPoint_get_txid(uint32_t this_ptr) {
7340         LDKOutPoint this_ptr_conv;
7341         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7342         this_ptr_conv.is_owned = false;
7343         int8_tArray ret_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
7344         memcpy((uint8_t*)(ret_arr + 4), *OutPoint_get_txid(&this_ptr_conv), 32);
7345         return ret_arr;
7346 }
7347
7348 void  __attribute__((visibility("default"))) TS_OutPoint_set_txid(uint32_t this_ptr, int8_tArray val) {
7349         LDKOutPoint this_ptr_conv;
7350         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7351         this_ptr_conv.is_owned = false;
7352         LDKThirtyTwoBytes val_ref;
7353         CHECK(*((uint32_t*)val) == 32);
7354         memcpy(val_ref.data, (uint8_t*)(val + 4), 32);
7355         OutPoint_set_txid(&this_ptr_conv, val_ref);
7356 }
7357
7358 int16_t  __attribute__((visibility("default"))) TS_OutPoint_get_index(uint32_t this_ptr) {
7359         LDKOutPoint this_ptr_conv;
7360         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7361         this_ptr_conv.is_owned = false;
7362         int16_t ret_val = OutPoint_get_index(&this_ptr_conv);
7363         return ret_val;
7364 }
7365
7366 void  __attribute__((visibility("default"))) TS_OutPoint_set_index(uint32_t this_ptr, int16_t val) {
7367         LDKOutPoint this_ptr_conv;
7368         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7369         this_ptr_conv.is_owned = false;
7370         OutPoint_set_index(&this_ptr_conv, val);
7371 }
7372
7373 uint32_t  __attribute__((visibility("default"))) TS_OutPoint_new(int8_tArray txid_arg, int16_t index_arg) {
7374         LDKThirtyTwoBytes txid_arg_ref;
7375         CHECK(*((uint32_t*)txid_arg) == 32);
7376         memcpy(txid_arg_ref.data, (uint8_t*)(txid_arg + 4), 32);
7377         LDKOutPoint ret_var = OutPoint_new(txid_arg_ref, index_arg);
7378         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7379         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7380         long ret_ref = (long)ret_var.inner;
7381         if (ret_var.is_owned) {
7382                 ret_ref |= 1;
7383         }
7384         return ret_ref;
7385 }
7386
7387 int8_tArray  __attribute__((visibility("default"))) TS_OutPoint_to_channel_id(uint32_t this_arg) {
7388         LDKOutPoint this_arg_conv;
7389         this_arg_conv.inner = (void*)(this_arg & (~1));
7390         this_arg_conv.is_owned = false;
7391         int8_tArray arg_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
7392         memcpy((uint8_t*)(arg_arr + 4), OutPoint_to_channel_id(&this_arg_conv).data, 32);
7393         return arg_arr;
7394 }
7395
7396 int8_tArray  __attribute__((visibility("default"))) TS_OutPoint_write(uint32_t obj) {
7397         LDKOutPoint obj_conv;
7398         obj_conv.inner = (void*)(obj & (~1));
7399         obj_conv.is_owned = false;
7400         LDKCVec_u8Z arg_var = OutPoint_write(&obj_conv);
7401         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
7402         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
7403         CVec_u8Z_free(arg_var);
7404         return arg_arr;
7405 }
7406
7407 uint32_t  __attribute__((visibility("default"))) TS_OutPoint_read(int8_tArray ser) {
7408         LDKu8slice ser_ref;
7409         ser_ref.datalen = *((uint32_t*)ser);
7410         ser_ref.data = (int8_t*)(ser + 4);
7411         LDKOutPoint ret_var = OutPoint_read(ser_ref);
7412         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7413         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7414         long ret_ref = (long)ret_var.inner;
7415         if (ret_var.is_owned) {
7416                 ret_ref |= 1;
7417         }
7418         return ret_ref;
7419 }
7420
7421 void  __attribute__((visibility("default"))) TS_SpendableOutputDescriptor_free(uint32_t this_ptr) {
7422         if ((this_ptr & 1) != 0) return;
7423         LDKSpendableOutputDescriptor this_ptr_conv = *(LDKSpendableOutputDescriptor*)(((uint64_t)this_ptr) & ~1);
7424         FREE((void*)this_ptr);
7425         SpendableOutputDescriptor_free(this_ptr_conv);
7426 }
7427
7428 uint32_t  __attribute__((visibility("default"))) TS_SpendableOutputDescriptor_clone(uint32_t orig) {
7429         LDKSpendableOutputDescriptor* orig_conv = (LDKSpendableOutputDescriptor*)orig;
7430         LDKSpendableOutputDescriptor *ret_copy = MALLOC(sizeof(LDKSpendableOutputDescriptor), "LDKSpendableOutputDescriptor");
7431         *ret_copy = SpendableOutputDescriptor_clone(orig_conv);
7432         long ret_ref = (long)ret_copy;
7433         return ret_ref;
7434 }
7435
7436 int8_tArray  __attribute__((visibility("default"))) TS_SpendableOutputDescriptor_write(uint32_t obj) {
7437         LDKSpendableOutputDescriptor* obj_conv = (LDKSpendableOutputDescriptor*)obj;
7438         LDKCVec_u8Z arg_var = SpendableOutputDescriptor_write(obj_conv);
7439         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
7440         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
7441         CVec_u8Z_free(arg_var);
7442         return arg_arr;
7443 }
7444
7445 uint32_t  __attribute__((visibility("default"))) TS_SpendableOutputDescriptor_read(int8_tArray ser) {
7446         LDKu8slice ser_ref;
7447         ser_ref.datalen = *((uint32_t*)ser);
7448         ser_ref.data = (int8_t*)(ser + 4);
7449         LDKCResult_SpendableOutputDescriptorDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_SpendableOutputDescriptorDecodeErrorZ), "LDKCResult_SpendableOutputDescriptorDecodeErrorZ");
7450         *ret_conv = SpendableOutputDescriptor_read(ser_ref);
7451         return (long)ret_conv;
7452 }
7453
7454 uint32_t  __attribute__((visibility("default"))) TS_ChannelKeys_clone(uint32_t orig) {
7455         LDKChannelKeys* orig_conv = (LDKChannelKeys*)orig;
7456         LDKChannelKeys* ret = MALLOC(sizeof(LDKChannelKeys), "LDKChannelKeys");
7457         *ret = ChannelKeys_clone(orig_conv);
7458         return (long)ret;
7459 }
7460
7461 void  __attribute__((visibility("default"))) TS_ChannelKeys_free(uint32_t this_ptr) {
7462         if ((this_ptr & 1) != 0) return;
7463         LDKChannelKeys this_ptr_conv = *(LDKChannelKeys*)(((uint64_t)this_ptr) & ~1);
7464         FREE((void*)this_ptr);
7465         ChannelKeys_free(this_ptr_conv);
7466 }
7467
7468 void  __attribute__((visibility("default"))) TS_KeysInterface_free(uint32_t this_ptr) {
7469         if ((this_ptr & 1) != 0) return;
7470         LDKKeysInterface this_ptr_conv = *(LDKKeysInterface*)(((uint64_t)this_ptr) & ~1);
7471         FREE((void*)this_ptr);
7472         KeysInterface_free(this_ptr_conv);
7473 }
7474
7475 void  __attribute__((visibility("default"))) TS_InMemoryChannelKeys_free(uint32_t this_ptr) {
7476         LDKInMemoryChannelKeys this_ptr_conv;
7477         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7478         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7479         InMemoryChannelKeys_free(this_ptr_conv);
7480 }
7481
7482 uint32_t  __attribute__((visibility("default"))) TS_InMemoryChannelKeys_clone(uint32_t orig) {
7483         LDKInMemoryChannelKeys orig_conv;
7484         orig_conv.inner = (void*)(orig & (~1));
7485         orig_conv.is_owned = false;
7486         LDKInMemoryChannelKeys ret_var = InMemoryChannelKeys_clone(&orig_conv);
7487         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7488         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7489         long ret_ref = (long)ret_var.inner;
7490         if (ret_var.is_owned) {
7491                 ret_ref |= 1;
7492         }
7493         return ret_ref;
7494 }
7495
7496 int8_tArray  __attribute__((visibility("default"))) TS_InMemoryChannelKeys_get_funding_key(uint32_t this_ptr) {
7497         LDKInMemoryChannelKeys this_ptr_conv;
7498         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7499         this_ptr_conv.is_owned = false;
7500         int8_tArray ret_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
7501         memcpy((uint8_t*)(ret_arr + 4), *InMemoryChannelKeys_get_funding_key(&this_ptr_conv), 32);
7502         return ret_arr;
7503 }
7504
7505 void  __attribute__((visibility("default"))) TS_InMemoryChannelKeys_set_funding_key(uint32_t this_ptr, int8_tArray val) {
7506         LDKInMemoryChannelKeys this_ptr_conv;
7507         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7508         this_ptr_conv.is_owned = false;
7509         LDKSecretKey val_ref;
7510         CHECK(*((uint32_t*)val) == 32);
7511         memcpy(val_ref.bytes, (uint8_t*)(val + 4), 32);
7512         InMemoryChannelKeys_set_funding_key(&this_ptr_conv, val_ref);
7513 }
7514
7515 int8_tArray  __attribute__((visibility("default"))) TS_InMemoryChannelKeys_get_revocation_base_key(uint32_t this_ptr) {
7516         LDKInMemoryChannelKeys this_ptr_conv;
7517         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7518         this_ptr_conv.is_owned = false;
7519         int8_tArray ret_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
7520         memcpy((uint8_t*)(ret_arr + 4), *InMemoryChannelKeys_get_revocation_base_key(&this_ptr_conv), 32);
7521         return ret_arr;
7522 }
7523
7524 void  __attribute__((visibility("default"))) TS_InMemoryChannelKeys_set_revocation_base_key(uint32_t this_ptr, int8_tArray val) {
7525         LDKInMemoryChannelKeys this_ptr_conv;
7526         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7527         this_ptr_conv.is_owned = false;
7528         LDKSecretKey val_ref;
7529         CHECK(*((uint32_t*)val) == 32);
7530         memcpy(val_ref.bytes, (uint8_t*)(val + 4), 32);
7531         InMemoryChannelKeys_set_revocation_base_key(&this_ptr_conv, val_ref);
7532 }
7533
7534 int8_tArray  __attribute__((visibility("default"))) TS_InMemoryChannelKeys_get_payment_key(uint32_t this_ptr) {
7535         LDKInMemoryChannelKeys this_ptr_conv;
7536         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7537         this_ptr_conv.is_owned = false;
7538         int8_tArray ret_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
7539         memcpy((uint8_t*)(ret_arr + 4), *InMemoryChannelKeys_get_payment_key(&this_ptr_conv), 32);
7540         return ret_arr;
7541 }
7542
7543 void  __attribute__((visibility("default"))) TS_InMemoryChannelKeys_set_payment_key(uint32_t this_ptr, int8_tArray val) {
7544         LDKInMemoryChannelKeys this_ptr_conv;
7545         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7546         this_ptr_conv.is_owned = false;
7547         LDKSecretKey val_ref;
7548         CHECK(*((uint32_t*)val) == 32);
7549         memcpy(val_ref.bytes, (uint8_t*)(val + 4), 32);
7550         InMemoryChannelKeys_set_payment_key(&this_ptr_conv, val_ref);
7551 }
7552
7553 int8_tArray  __attribute__((visibility("default"))) TS_InMemoryChannelKeys_get_delayed_payment_base_key(uint32_t this_ptr) {
7554         LDKInMemoryChannelKeys this_ptr_conv;
7555         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7556         this_ptr_conv.is_owned = false;
7557         int8_tArray ret_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
7558         memcpy((uint8_t*)(ret_arr + 4), *InMemoryChannelKeys_get_delayed_payment_base_key(&this_ptr_conv), 32);
7559         return ret_arr;
7560 }
7561
7562 void  __attribute__((visibility("default"))) TS_InMemoryChannelKeys_set_delayed_payment_base_key(uint32_t this_ptr, int8_tArray val) {
7563         LDKInMemoryChannelKeys this_ptr_conv;
7564         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7565         this_ptr_conv.is_owned = false;
7566         LDKSecretKey val_ref;
7567         CHECK(*((uint32_t*)val) == 32);
7568         memcpy(val_ref.bytes, (uint8_t*)(val + 4), 32);
7569         InMemoryChannelKeys_set_delayed_payment_base_key(&this_ptr_conv, val_ref);
7570 }
7571
7572 int8_tArray  __attribute__((visibility("default"))) TS_InMemoryChannelKeys_get_htlc_base_key(uint32_t this_ptr) {
7573         LDKInMemoryChannelKeys this_ptr_conv;
7574         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7575         this_ptr_conv.is_owned = false;
7576         int8_tArray ret_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
7577         memcpy((uint8_t*)(ret_arr + 4), *InMemoryChannelKeys_get_htlc_base_key(&this_ptr_conv), 32);
7578         return ret_arr;
7579 }
7580
7581 void  __attribute__((visibility("default"))) TS_InMemoryChannelKeys_set_htlc_base_key(uint32_t this_ptr, int8_tArray val) {
7582         LDKInMemoryChannelKeys this_ptr_conv;
7583         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7584         this_ptr_conv.is_owned = false;
7585         LDKSecretKey val_ref;
7586         CHECK(*((uint32_t*)val) == 32);
7587         memcpy(val_ref.bytes, (uint8_t*)(val + 4), 32);
7588         InMemoryChannelKeys_set_htlc_base_key(&this_ptr_conv, val_ref);
7589 }
7590
7591 int8_tArray  __attribute__((visibility("default"))) TS_InMemoryChannelKeys_get_commitment_seed(uint32_t this_ptr) {
7592         LDKInMemoryChannelKeys this_ptr_conv;
7593         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7594         this_ptr_conv.is_owned = false;
7595         int8_tArray ret_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
7596         memcpy((uint8_t*)(ret_arr + 4), *InMemoryChannelKeys_get_commitment_seed(&this_ptr_conv), 32);
7597         return ret_arr;
7598 }
7599
7600 void  __attribute__((visibility("default"))) TS_InMemoryChannelKeys_set_commitment_seed(uint32_t this_ptr, int8_tArray val) {
7601         LDKInMemoryChannelKeys this_ptr_conv;
7602         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7603         this_ptr_conv.is_owned = false;
7604         LDKThirtyTwoBytes val_ref;
7605         CHECK(*((uint32_t*)val) == 32);
7606         memcpy(val_ref.data, (uint8_t*)(val + 4), 32);
7607         InMemoryChannelKeys_set_commitment_seed(&this_ptr_conv, val_ref);
7608 }
7609
7610 uint32_t  __attribute__((visibility("default"))) 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) {
7611         LDKSecretKey funding_key_ref;
7612         CHECK(*((uint32_t*)funding_key) == 32);
7613         memcpy(funding_key_ref.bytes, (uint8_t*)(funding_key + 4), 32);
7614         LDKSecretKey revocation_base_key_ref;
7615         CHECK(*((uint32_t*)revocation_base_key) == 32);
7616         memcpy(revocation_base_key_ref.bytes, (uint8_t*)(revocation_base_key + 4), 32);
7617         LDKSecretKey payment_key_ref;
7618         CHECK(*((uint32_t*)payment_key) == 32);
7619         memcpy(payment_key_ref.bytes, (uint8_t*)(payment_key + 4), 32);
7620         LDKSecretKey delayed_payment_base_key_ref;
7621         CHECK(*((uint32_t*)delayed_payment_base_key) == 32);
7622         memcpy(delayed_payment_base_key_ref.bytes, (uint8_t*)(delayed_payment_base_key + 4), 32);
7623         LDKSecretKey htlc_base_key_ref;
7624         CHECK(*((uint32_t*)htlc_base_key) == 32);
7625         memcpy(htlc_base_key_ref.bytes, (uint8_t*)(htlc_base_key + 4), 32);
7626         LDKThirtyTwoBytes commitment_seed_ref;
7627         CHECK(*((uint32_t*)commitment_seed) == 32);
7628         memcpy(commitment_seed_ref.data, (uint8_t*)(commitment_seed + 4), 32);
7629         LDKC2Tuple_u64u64Z key_derivation_params_conv = *(LDKC2Tuple_u64u64Z*)(((uint64_t)key_derivation_params) & ~1);
7630         FREE((void*)key_derivation_params);
7631         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);
7632         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7633         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7634         long ret_ref = (long)ret_var.inner;
7635         if (ret_var.is_owned) {
7636                 ret_ref |= 1;
7637         }
7638         return ret_ref;
7639 }
7640
7641 uint32_t  __attribute__((visibility("default"))) TS_InMemoryChannelKeys_counterparty_pubkeys(uint32_t this_arg) {
7642         LDKInMemoryChannelKeys this_arg_conv;
7643         this_arg_conv.inner = (void*)(this_arg & (~1));
7644         this_arg_conv.is_owned = false;
7645         LDKChannelPublicKeys ret_var = InMemoryChannelKeys_counterparty_pubkeys(&this_arg_conv);
7646         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7647         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7648         long ret_ref = (long)ret_var.inner;
7649         if (ret_var.is_owned) {
7650                 ret_ref |= 1;
7651         }
7652         return ret_ref;
7653 }
7654
7655 int16_t  __attribute__((visibility("default"))) TS_InMemoryChannelKeys_counterparty_selected_contest_delay(uint32_t this_arg) {
7656         LDKInMemoryChannelKeys this_arg_conv;
7657         this_arg_conv.inner = (void*)(this_arg & (~1));
7658         this_arg_conv.is_owned = false;
7659         int16_t ret_val = InMemoryChannelKeys_counterparty_selected_contest_delay(&this_arg_conv);
7660         return ret_val;
7661 }
7662
7663 int16_t  __attribute__((visibility("default"))) TS_InMemoryChannelKeys_holder_selected_contest_delay(uint32_t this_arg) {
7664         LDKInMemoryChannelKeys this_arg_conv;
7665         this_arg_conv.inner = (void*)(this_arg & (~1));
7666         this_arg_conv.is_owned = false;
7667         int16_t ret_val = InMemoryChannelKeys_holder_selected_contest_delay(&this_arg_conv);
7668         return ret_val;
7669 }
7670
7671 jboolean  __attribute__((visibility("default"))) TS_InMemoryChannelKeys_is_outbound(uint32_t this_arg) {
7672         LDKInMemoryChannelKeys this_arg_conv;
7673         this_arg_conv.inner = (void*)(this_arg & (~1));
7674         this_arg_conv.is_owned = false;
7675         jboolean ret_val = InMemoryChannelKeys_is_outbound(&this_arg_conv);
7676         return ret_val;
7677 }
7678
7679 uint32_t  __attribute__((visibility("default"))) TS_InMemoryChannelKeys_funding_outpoint(uint32_t this_arg) {
7680         LDKInMemoryChannelKeys this_arg_conv;
7681         this_arg_conv.inner = (void*)(this_arg & (~1));
7682         this_arg_conv.is_owned = false;
7683         LDKOutPoint ret_var = InMemoryChannelKeys_funding_outpoint(&this_arg_conv);
7684         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7685         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7686         long ret_ref = (long)ret_var.inner;
7687         if (ret_var.is_owned) {
7688                 ret_ref |= 1;
7689         }
7690         return ret_ref;
7691 }
7692
7693 uint32_t  __attribute__((visibility("default"))) TS_InMemoryChannelKeys_get_channel_parameters(uint32_t this_arg) {
7694         LDKInMemoryChannelKeys this_arg_conv;
7695         this_arg_conv.inner = (void*)(this_arg & (~1));
7696         this_arg_conv.is_owned = false;
7697         LDKChannelTransactionParameters ret_var = InMemoryChannelKeys_get_channel_parameters(&this_arg_conv);
7698         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7699         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7700         long ret_ref = (long)ret_var.inner;
7701         if (ret_var.is_owned) {
7702                 ret_ref |= 1;
7703         }
7704         return ret_ref;
7705 }
7706
7707 uint32_t  __attribute__((visibility("default"))) TS_InMemoryChannelKeys_as_ChannelKeys(uint32_t this_arg) {
7708         LDKInMemoryChannelKeys this_arg_conv;
7709         this_arg_conv.inner = (void*)(this_arg & (~1));
7710         this_arg_conv.is_owned = false;
7711         LDKChannelKeys* ret = MALLOC(sizeof(LDKChannelKeys), "LDKChannelKeys");
7712         *ret = InMemoryChannelKeys_as_ChannelKeys(&this_arg_conv);
7713         return (long)ret;
7714 }
7715
7716 int8_tArray  __attribute__((visibility("default"))) TS_InMemoryChannelKeys_write(uint32_t obj) {
7717         LDKInMemoryChannelKeys obj_conv;
7718         obj_conv.inner = (void*)(obj & (~1));
7719         obj_conv.is_owned = false;
7720         LDKCVec_u8Z arg_var = InMemoryChannelKeys_write(&obj_conv);
7721         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
7722         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
7723         CVec_u8Z_free(arg_var);
7724         return arg_arr;
7725 }
7726
7727 uint32_t  __attribute__((visibility("default"))) TS_InMemoryChannelKeys_read(int8_tArray ser) {
7728         LDKu8slice ser_ref;
7729         ser_ref.datalen = *((uint32_t*)ser);
7730         ser_ref.data = (int8_t*)(ser + 4);
7731         LDKCResult_InMemoryChannelKeysDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_InMemoryChannelKeysDecodeErrorZ), "LDKCResult_InMemoryChannelKeysDecodeErrorZ");
7732         *ret_conv = InMemoryChannelKeys_read(ser_ref);
7733         return (long)ret_conv;
7734 }
7735
7736 void  __attribute__((visibility("default"))) TS_KeysManager_free(uint32_t this_ptr) {
7737         LDKKeysManager this_ptr_conv;
7738         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7739         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7740         KeysManager_free(this_ptr_conv);
7741 }
7742
7743 uint32_t  __attribute__((visibility("default"))) TS_KeysManager_new(int8_tArray seed, uint32_t network, int64_t starting_time_secs, int32_t starting_time_nanos) {
7744         unsigned char seed_arr[32];
7745         CHECK(*((uint32_t*)seed) == 32);
7746         memcpy(seed_arr, (uint8_t*)(seed + 4), 32);
7747         unsigned char (*seed_ref)[32] = &seed_arr;
7748         LDKNetwork network_conv = LDKNetwork_from_js(network);
7749         LDKKeysManager ret_var = KeysManager_new(seed_ref, network_conv, starting_time_secs, starting_time_nanos);
7750         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7751         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7752         long ret_ref = (long)ret_var.inner;
7753         if (ret_var.is_owned) {
7754                 ret_ref |= 1;
7755         }
7756         return ret_ref;
7757 }
7758
7759 uint32_t  __attribute__((visibility("default"))) TS_KeysManager_derive_channel_keys(uint32_t this_arg, int64_t channel_value_satoshis, int64_t params_1, int64_t params_2) {
7760         LDKKeysManager this_arg_conv;
7761         this_arg_conv.inner = (void*)(this_arg & (~1));
7762         this_arg_conv.is_owned = false;
7763         LDKInMemoryChannelKeys ret_var = KeysManager_derive_channel_keys(&this_arg_conv, channel_value_satoshis, params_1, params_2);
7764         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7765         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7766         long ret_ref = (long)ret_var.inner;
7767         if (ret_var.is_owned) {
7768                 ret_ref |= 1;
7769         }
7770         return ret_ref;
7771 }
7772
7773 uint32_t  __attribute__((visibility("default"))) TS_KeysManager_as_KeysInterface(uint32_t this_arg) {
7774         LDKKeysManager this_arg_conv;
7775         this_arg_conv.inner = (void*)(this_arg & (~1));
7776         this_arg_conv.is_owned = false;
7777         LDKKeysInterface* ret = MALLOC(sizeof(LDKKeysInterface), "LDKKeysInterface");
7778         *ret = KeysManager_as_KeysInterface(&this_arg_conv);
7779         return (long)ret;
7780 }
7781
7782 void  __attribute__((visibility("default"))) TS_ChannelManager_free(uint32_t this_ptr) {
7783         LDKChannelManager this_ptr_conv;
7784         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7785         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7786         ChannelManager_free(this_ptr_conv);
7787 }
7788
7789 void  __attribute__((visibility("default"))) TS_ChannelDetails_free(uint32_t this_ptr) {
7790         LDKChannelDetails this_ptr_conv;
7791         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7792         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7793         ChannelDetails_free(this_ptr_conv);
7794 }
7795
7796 uint32_t  __attribute__((visibility("default"))) TS_ChannelDetails_clone(uint32_t orig) {
7797         LDKChannelDetails orig_conv;
7798         orig_conv.inner = (void*)(orig & (~1));
7799         orig_conv.is_owned = false;
7800         LDKChannelDetails ret_var = ChannelDetails_clone(&orig_conv);
7801         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7802         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7803         long ret_ref = (long)ret_var.inner;
7804         if (ret_var.is_owned) {
7805                 ret_ref |= 1;
7806         }
7807         return ret_ref;
7808 }
7809
7810 int8_tArray  __attribute__((visibility("default"))) TS_ChannelDetails_get_channel_id(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         int8_tArray ret_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
7815         memcpy((uint8_t*)(ret_arr + 4), *ChannelDetails_get_channel_id(&this_ptr_conv), 32);
7816         return ret_arr;
7817 }
7818
7819 void  __attribute__((visibility("default"))) TS_ChannelDetails_set_channel_id(uint32_t this_ptr, int8_tArray val) {
7820         LDKChannelDetails this_ptr_conv;
7821         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7822         this_ptr_conv.is_owned = false;
7823         LDKThirtyTwoBytes val_ref;
7824         CHECK(*((uint32_t*)val) == 32);
7825         memcpy(val_ref.data, (uint8_t*)(val + 4), 32);
7826         ChannelDetails_set_channel_id(&this_ptr_conv, val_ref);
7827 }
7828
7829 int8_tArray  __attribute__((visibility("default"))) TS_ChannelDetails_get_remote_network_id(uint32_t this_ptr) {
7830         LDKChannelDetails this_ptr_conv;
7831         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7832         this_ptr_conv.is_owned = false;
7833         int8_tArray arg_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
7834         memcpy((uint8_t*)(arg_arr + 4), ChannelDetails_get_remote_network_id(&this_ptr_conv).compressed_form, 33);
7835         return arg_arr;
7836 }
7837
7838 void  __attribute__((visibility("default"))) TS_ChannelDetails_set_remote_network_id(uint32_t this_ptr, int8_tArray val) {
7839         LDKChannelDetails this_ptr_conv;
7840         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7841         this_ptr_conv.is_owned = false;
7842         LDKPublicKey val_ref;
7843         CHECK(*((uint32_t*)val) == 33);
7844         memcpy(val_ref.compressed_form, (uint8_t*)(val + 4), 33);
7845         ChannelDetails_set_remote_network_id(&this_ptr_conv, val_ref);
7846 }
7847
7848 uint32_t  __attribute__((visibility("default"))) TS_ChannelDetails_get_counterparty_features(uint32_t this_ptr) {
7849         LDKChannelDetails this_ptr_conv;
7850         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7851         this_ptr_conv.is_owned = false;
7852         LDKInitFeatures ret_var = ChannelDetails_get_counterparty_features(&this_ptr_conv);
7853         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7854         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7855         long ret_ref = (long)ret_var.inner;
7856         if (ret_var.is_owned) {
7857                 ret_ref |= 1;
7858         }
7859         return ret_ref;
7860 }
7861
7862 void  __attribute__((visibility("default"))) TS_ChannelDetails_set_counterparty_features(uint32_t this_ptr, uint32_t val) {
7863         LDKChannelDetails this_ptr_conv;
7864         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7865         this_ptr_conv.is_owned = false;
7866         LDKInitFeatures val_conv;
7867         val_conv.inner = (void*)(val & (~1));
7868         val_conv.is_owned = (val & 1) || (val == 0);
7869         // Warning: we need a move here but no clone is available for LDKInitFeatures
7870         ChannelDetails_set_counterparty_features(&this_ptr_conv, val_conv);
7871 }
7872
7873 int64_t  __attribute__((visibility("default"))) TS_ChannelDetails_get_channel_value_satoshis(uint32_t this_ptr) {
7874         LDKChannelDetails this_ptr_conv;
7875         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7876         this_ptr_conv.is_owned = false;
7877         int64_t ret_val = ChannelDetails_get_channel_value_satoshis(&this_ptr_conv);
7878         return ret_val;
7879 }
7880
7881 void  __attribute__((visibility("default"))) TS_ChannelDetails_set_channel_value_satoshis(uint32_t this_ptr, int64_t val) {
7882         LDKChannelDetails this_ptr_conv;
7883         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7884         this_ptr_conv.is_owned = false;
7885         ChannelDetails_set_channel_value_satoshis(&this_ptr_conv, val);
7886 }
7887
7888 int64_t  __attribute__((visibility("default"))) TS_ChannelDetails_get_user_id(uint32_t this_ptr) {
7889         LDKChannelDetails this_ptr_conv;
7890         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7891         this_ptr_conv.is_owned = false;
7892         int64_t ret_val = ChannelDetails_get_user_id(&this_ptr_conv);
7893         return ret_val;
7894 }
7895
7896 void  __attribute__((visibility("default"))) TS_ChannelDetails_set_user_id(uint32_t this_ptr, int64_t val) {
7897         LDKChannelDetails this_ptr_conv;
7898         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7899         this_ptr_conv.is_owned = false;
7900         ChannelDetails_set_user_id(&this_ptr_conv, val);
7901 }
7902
7903 int64_t  __attribute__((visibility("default"))) TS_ChannelDetails_get_outbound_capacity_msat(uint32_t this_ptr) {
7904         LDKChannelDetails this_ptr_conv;
7905         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7906         this_ptr_conv.is_owned = false;
7907         int64_t ret_val = ChannelDetails_get_outbound_capacity_msat(&this_ptr_conv);
7908         return ret_val;
7909 }
7910
7911 void  __attribute__((visibility("default"))) TS_ChannelDetails_set_outbound_capacity_msat(uint32_t this_ptr, int64_t val) {
7912         LDKChannelDetails this_ptr_conv;
7913         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7914         this_ptr_conv.is_owned = false;
7915         ChannelDetails_set_outbound_capacity_msat(&this_ptr_conv, val);
7916 }
7917
7918 int64_t  __attribute__((visibility("default"))) TS_ChannelDetails_get_inbound_capacity_msat(uint32_t this_ptr) {
7919         LDKChannelDetails this_ptr_conv;
7920         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7921         this_ptr_conv.is_owned = false;
7922         int64_t ret_val = ChannelDetails_get_inbound_capacity_msat(&this_ptr_conv);
7923         return ret_val;
7924 }
7925
7926 void  __attribute__((visibility("default"))) TS_ChannelDetails_set_inbound_capacity_msat(uint32_t this_ptr, int64_t val) {
7927         LDKChannelDetails this_ptr_conv;
7928         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7929         this_ptr_conv.is_owned = false;
7930         ChannelDetails_set_inbound_capacity_msat(&this_ptr_conv, val);
7931 }
7932
7933 jboolean  __attribute__((visibility("default"))) TS_ChannelDetails_get_is_live(uint32_t this_ptr) {
7934         LDKChannelDetails this_ptr_conv;
7935         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7936         this_ptr_conv.is_owned = false;
7937         jboolean ret_val = ChannelDetails_get_is_live(&this_ptr_conv);
7938         return ret_val;
7939 }
7940
7941 void  __attribute__((visibility("default"))) TS_ChannelDetails_set_is_live(uint32_t this_ptr, jboolean val) {
7942         LDKChannelDetails this_ptr_conv;
7943         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7944         this_ptr_conv.is_owned = false;
7945         ChannelDetails_set_is_live(&this_ptr_conv, val);
7946 }
7947
7948 void  __attribute__((visibility("default"))) TS_PaymentSendFailure_free(uint32_t this_ptr) {
7949         LDKPaymentSendFailure this_ptr_conv;
7950         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7951         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7952         PaymentSendFailure_free(this_ptr_conv);
7953 }
7954
7955 uint32_t  __attribute__((visibility("default"))) TS_PaymentSendFailure_clone(uint32_t orig) {
7956         LDKPaymentSendFailure orig_conv;
7957         orig_conv.inner = (void*)(orig & (~1));
7958         orig_conv.is_owned = false;
7959         LDKPaymentSendFailure ret_var = PaymentSendFailure_clone(&orig_conv);
7960         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7961         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7962         long ret_ref = (long)ret_var.inner;
7963         if (ret_var.is_owned) {
7964                 ret_ref |= 1;
7965         }
7966         return ret_ref;
7967 }
7968
7969 uint32_t  __attribute__((visibility("default"))) 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) {
7970         LDKNetwork network_conv = LDKNetwork_from_js(network);
7971         LDKFeeEstimator fee_est_conv = *(LDKFeeEstimator*)(((uint64_t)fee_est) & ~1);
7972         LDKWatch chain_monitor_conv = *(LDKWatch*)(((uint64_t)chain_monitor) & ~1);
7973         LDKBroadcasterInterface tx_broadcaster_conv = *(LDKBroadcasterInterface*)(((uint64_t)tx_broadcaster) & ~1);
7974         LDKLogger logger_conv = *(LDKLogger*)(((uint64_t)logger) & ~1);
7975         LDKKeysInterface keys_manager_conv = *(LDKKeysInterface*)(((uint64_t)keys_manager) & ~1);
7976         LDKUserConfig config_conv;
7977         config_conv.inner = (void*)(config & (~1));
7978         config_conv.is_owned = (config & 1) || (config == 0);
7979         config_conv = UserConfig_clone(&config_conv);
7980         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);
7981         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7982         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7983         long ret_ref = (long)ret_var.inner;
7984         if (ret_var.is_owned) {
7985                 ret_ref |= 1;
7986         }
7987         return ret_ref;
7988 }
7989
7990 uint32_t  __attribute__((visibility("default"))) 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) {
7991         LDKChannelManager this_arg_conv;
7992         this_arg_conv.inner = (void*)(this_arg & (~1));
7993         this_arg_conv.is_owned = false;
7994         LDKPublicKey their_network_key_ref;
7995         CHECK(*((uint32_t*)their_network_key) == 33);
7996         memcpy(their_network_key_ref.compressed_form, (uint8_t*)(their_network_key + 4), 33);
7997         LDKUserConfig override_config_conv;
7998         override_config_conv.inner = (void*)(override_config & (~1));
7999         override_config_conv.is_owned = (override_config & 1) || (override_config == 0);
8000         override_config_conv = UserConfig_clone(&override_config_conv);
8001         LDKCResult_NoneAPIErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneAPIErrorZ), "LDKCResult_NoneAPIErrorZ");
8002         *ret_conv = ChannelManager_create_channel(&this_arg_conv, their_network_key_ref, channel_value_satoshis, push_msat, user_id, override_config_conv);
8003         return (long)ret_conv;
8004 }
8005
8006 uint32_tArray  __attribute__((visibility("default"))) TS_ChannelManager_list_channels(uint32_t this_arg) {
8007         LDKChannelManager this_arg_conv;
8008         this_arg_conv.inner = (void*)(this_arg & (~1));
8009         this_arg_conv.is_owned = false;
8010         LDKCVec_ChannelDetailsZ ret_var = ChannelManager_list_channels(&this_arg_conv);
8011         uint32_tArray ret_arr = init_arr(ret_var.datalen, sizeof(uint32_t), "Native uint32_tArray Bytes");
8012         uint32_t *ret_arr_ptr = (uint32_t*)(ret_arr + 4);
8013         for (size_t q = 0; q < ret_var.datalen; q++) {
8014                 LDKChannelDetails arr_conv_16_var = ret_var.data[q];
8015                 CHECK((((long)arr_conv_16_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8016                 CHECK((((long)&arr_conv_16_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8017                 long arr_conv_16_ref = (long)arr_conv_16_var.inner;
8018                 if (arr_conv_16_var.is_owned) {
8019                         arr_conv_16_ref |= 1;
8020                 }
8021                 ret_arr_ptr[q] = arr_conv_16_ref;
8022         }
8023         FREE(ret_var.data);
8024         return ret_arr;
8025 }
8026
8027 uint32_tArray  __attribute__((visibility("default"))) TS_ChannelManager_list_usable_channels(uint32_t this_arg) {
8028         LDKChannelManager this_arg_conv;
8029         this_arg_conv.inner = (void*)(this_arg & (~1));
8030         this_arg_conv.is_owned = false;
8031         LDKCVec_ChannelDetailsZ ret_var = ChannelManager_list_usable_channels(&this_arg_conv);
8032         uint32_tArray ret_arr = init_arr(ret_var.datalen, sizeof(uint32_t), "Native uint32_tArray Bytes");
8033         uint32_t *ret_arr_ptr = (uint32_t*)(ret_arr + 4);
8034         for (size_t q = 0; q < ret_var.datalen; q++) {
8035                 LDKChannelDetails arr_conv_16_var = ret_var.data[q];
8036                 CHECK((((long)arr_conv_16_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8037                 CHECK((((long)&arr_conv_16_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8038                 long arr_conv_16_ref = (long)arr_conv_16_var.inner;
8039                 if (arr_conv_16_var.is_owned) {
8040                         arr_conv_16_ref |= 1;
8041                 }
8042                 ret_arr_ptr[q] = arr_conv_16_ref;
8043         }
8044         FREE(ret_var.data);
8045         return ret_arr;
8046 }
8047
8048 uint32_t  __attribute__((visibility("default"))) TS_ChannelManager_close_channel(uint32_t this_arg, int8_tArray channel_id) {
8049         LDKChannelManager this_arg_conv;
8050         this_arg_conv.inner = (void*)(this_arg & (~1));
8051         this_arg_conv.is_owned = false;
8052         unsigned char channel_id_arr[32];
8053         CHECK(*((uint32_t*)channel_id) == 32);
8054         memcpy(channel_id_arr, (uint8_t*)(channel_id + 4), 32);
8055         unsigned char (*channel_id_ref)[32] = &channel_id_arr;
8056         LDKCResult_NoneAPIErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneAPIErrorZ), "LDKCResult_NoneAPIErrorZ");
8057         *ret_conv = ChannelManager_close_channel(&this_arg_conv, channel_id_ref);
8058         return (long)ret_conv;
8059 }
8060
8061 uint32_t  __attribute__((visibility("default"))) TS_ChannelManager_force_close_channel(uint32_t this_arg, int8_tArray channel_id) {
8062         LDKChannelManager this_arg_conv;
8063         this_arg_conv.inner = (void*)(this_arg & (~1));
8064         this_arg_conv.is_owned = false;
8065         unsigned char channel_id_arr[32];
8066         CHECK(*((uint32_t*)channel_id) == 32);
8067         memcpy(channel_id_arr, (uint8_t*)(channel_id + 4), 32);
8068         unsigned char (*channel_id_ref)[32] = &channel_id_arr;
8069         LDKCResult_NoneAPIErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneAPIErrorZ), "LDKCResult_NoneAPIErrorZ");
8070         *ret_conv = ChannelManager_force_close_channel(&this_arg_conv, channel_id_ref);
8071         return (long)ret_conv;
8072 }
8073
8074 void  __attribute__((visibility("default"))) TS_ChannelManager_force_close_all_channels(uint32_t this_arg) {
8075         LDKChannelManager this_arg_conv;
8076         this_arg_conv.inner = (void*)(this_arg & (~1));
8077         this_arg_conv.is_owned = false;
8078         ChannelManager_force_close_all_channels(&this_arg_conv);
8079 }
8080
8081 uint32_t  __attribute__((visibility("default"))) TS_ChannelManager_send_payment(uint32_t this_arg, uint32_t route, int8_tArray payment_hash, int8_tArray payment_secret) {
8082         LDKChannelManager this_arg_conv;
8083         this_arg_conv.inner = (void*)(this_arg & (~1));
8084         this_arg_conv.is_owned = false;
8085         LDKRoute route_conv;
8086         route_conv.inner = (void*)(route & (~1));
8087         route_conv.is_owned = false;
8088         LDKThirtyTwoBytes payment_hash_ref;
8089         CHECK(*((uint32_t*)payment_hash) == 32);
8090         memcpy(payment_hash_ref.data, (uint8_t*)(payment_hash + 4), 32);
8091         LDKThirtyTwoBytes payment_secret_ref;
8092         CHECK(*((uint32_t*)payment_secret) == 32);
8093         memcpy(payment_secret_ref.data, (uint8_t*)(payment_secret + 4), 32);
8094         LDKCResult_NonePaymentSendFailureZ* ret_conv = MALLOC(sizeof(LDKCResult_NonePaymentSendFailureZ), "LDKCResult_NonePaymentSendFailureZ");
8095         *ret_conv = ChannelManager_send_payment(&this_arg_conv, &route_conv, payment_hash_ref, payment_secret_ref);
8096         return (long)ret_conv;
8097 }
8098
8099 void  __attribute__((visibility("default"))) TS_ChannelManager_funding_transaction_generated(uint32_t this_arg, int8_tArray temporary_channel_id, uint32_t funding_txo) {
8100         LDKChannelManager this_arg_conv;
8101         this_arg_conv.inner = (void*)(this_arg & (~1));
8102         this_arg_conv.is_owned = false;
8103         unsigned char temporary_channel_id_arr[32];
8104         CHECK(*((uint32_t*)temporary_channel_id) == 32);
8105         memcpy(temporary_channel_id_arr, (uint8_t*)(temporary_channel_id + 4), 32);
8106         unsigned char (*temporary_channel_id_ref)[32] = &temporary_channel_id_arr;
8107         LDKOutPoint funding_txo_conv;
8108         funding_txo_conv.inner = (void*)(funding_txo & (~1));
8109         funding_txo_conv.is_owned = (funding_txo & 1) || (funding_txo == 0);
8110         funding_txo_conv = OutPoint_clone(&funding_txo_conv);
8111         ChannelManager_funding_transaction_generated(&this_arg_conv, temporary_channel_id_ref, funding_txo_conv);
8112 }
8113
8114 void  __attribute__((visibility("default"))) TS_ChannelManager_broadcast_node_announcement(uint32_t this_arg, int8_tArray rgb, int8_tArray alias, uint32_tArray addresses) {
8115         LDKChannelManager this_arg_conv;
8116         this_arg_conv.inner = (void*)(this_arg & (~1));
8117         this_arg_conv.is_owned = false;
8118         LDKThreeBytes rgb_ref;
8119         CHECK(*((uint32_t*)rgb) == 3);
8120         memcpy(rgb_ref.data, (uint8_t*)(rgb + 4), 3);
8121         LDKThirtyTwoBytes alias_ref;
8122         CHECK(*((uint32_t*)alias) == 32);
8123         memcpy(alias_ref.data, (uint8_t*)(alias + 4), 32);
8124         LDKCVec_NetAddressZ addresses_constr;
8125         addresses_constr.datalen = *((uint32_t*)addresses);
8126         if (addresses_constr.datalen > 0)
8127                 addresses_constr.data = MALLOC(addresses_constr.datalen * sizeof(LDKNetAddress), "LDKCVec_NetAddressZ Elements");
8128         else
8129                 addresses_constr.data = NULL;
8130         uint32_t* addresses_vals = (uint32_t*)(addresses + 4);
8131         for (size_t m = 0; m < addresses_constr.datalen; m++) {
8132                 uint32_t arr_conv_12 = addresses_vals[m];
8133                 LDKNetAddress arr_conv_12_conv = *(LDKNetAddress*)(((uint64_t)arr_conv_12) & ~1);
8134                 FREE((void*)arr_conv_12);
8135                 addresses_constr.data[m] = arr_conv_12_conv;
8136         }
8137         ChannelManager_broadcast_node_announcement(&this_arg_conv, rgb_ref, alias_ref, addresses_constr);
8138 }
8139
8140 void  __attribute__((visibility("default"))) TS_ChannelManager_process_pending_htlc_forwards(uint32_t this_arg) {
8141         LDKChannelManager this_arg_conv;
8142         this_arg_conv.inner = (void*)(this_arg & (~1));
8143         this_arg_conv.is_owned = false;
8144         ChannelManager_process_pending_htlc_forwards(&this_arg_conv);
8145 }
8146
8147 void  __attribute__((visibility("default"))) TS_ChannelManager_timer_chan_freshness_every_min(uint32_t this_arg) {
8148         LDKChannelManager this_arg_conv;
8149         this_arg_conv.inner = (void*)(this_arg & (~1));
8150         this_arg_conv.is_owned = false;
8151         ChannelManager_timer_chan_freshness_every_min(&this_arg_conv);
8152 }
8153
8154 jboolean  __attribute__((visibility("default"))) TS_ChannelManager_fail_htlc_backwards(uint32_t this_arg, int8_tArray payment_hash, int8_tArray payment_secret) {
8155         LDKChannelManager this_arg_conv;
8156         this_arg_conv.inner = (void*)(this_arg & (~1));
8157         this_arg_conv.is_owned = false;
8158         unsigned char payment_hash_arr[32];
8159         CHECK(*((uint32_t*)payment_hash) == 32);
8160         memcpy(payment_hash_arr, (uint8_t*)(payment_hash + 4), 32);
8161         unsigned char (*payment_hash_ref)[32] = &payment_hash_arr;
8162         LDKThirtyTwoBytes payment_secret_ref;
8163         CHECK(*((uint32_t*)payment_secret) == 32);
8164         memcpy(payment_secret_ref.data, (uint8_t*)(payment_secret + 4), 32);
8165         jboolean ret_val = ChannelManager_fail_htlc_backwards(&this_arg_conv, payment_hash_ref, payment_secret_ref);
8166         return ret_val;
8167 }
8168
8169 jboolean  __attribute__((visibility("default"))) TS_ChannelManager_claim_funds(uint32_t this_arg, int8_tArray payment_preimage, int8_tArray payment_secret, int64_t expected_amount) {
8170         LDKChannelManager this_arg_conv;
8171         this_arg_conv.inner = (void*)(this_arg & (~1));
8172         this_arg_conv.is_owned = false;
8173         LDKThirtyTwoBytes payment_preimage_ref;
8174         CHECK(*((uint32_t*)payment_preimage) == 32);
8175         memcpy(payment_preimage_ref.data, (uint8_t*)(payment_preimage + 4), 32);
8176         LDKThirtyTwoBytes payment_secret_ref;
8177         CHECK(*((uint32_t*)payment_secret) == 32);
8178         memcpy(payment_secret_ref.data, (uint8_t*)(payment_secret + 4), 32);
8179         jboolean ret_val = ChannelManager_claim_funds(&this_arg_conv, payment_preimage_ref, payment_secret_ref, expected_amount);
8180         return ret_val;
8181 }
8182
8183 int8_tArray  __attribute__((visibility("default"))) TS_ChannelManager_get_our_node_id(uint32_t this_arg) {
8184         LDKChannelManager this_arg_conv;
8185         this_arg_conv.inner = (void*)(this_arg & (~1));
8186         this_arg_conv.is_owned = false;
8187         int8_tArray arg_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
8188         memcpy((uint8_t*)(arg_arr + 4), ChannelManager_get_our_node_id(&this_arg_conv).compressed_form, 33);
8189         return arg_arr;
8190 }
8191
8192 void  __attribute__((visibility("default"))) TS_ChannelManager_channel_monitor_updated(uint32_t this_arg, uint32_t funding_txo, int64_t highest_applied_update_id) {
8193         LDKChannelManager this_arg_conv;
8194         this_arg_conv.inner = (void*)(this_arg & (~1));
8195         this_arg_conv.is_owned = false;
8196         LDKOutPoint funding_txo_conv;
8197         funding_txo_conv.inner = (void*)(funding_txo & (~1));
8198         funding_txo_conv.is_owned = false;
8199         ChannelManager_channel_monitor_updated(&this_arg_conv, &funding_txo_conv, highest_applied_update_id);
8200 }
8201
8202 uint32_t  __attribute__((visibility("default"))) TS_ChannelManager_as_MessageSendEventsProvider(uint32_t this_arg) {
8203         LDKChannelManager this_arg_conv;
8204         this_arg_conv.inner = (void*)(this_arg & (~1));
8205         this_arg_conv.is_owned = false;
8206         LDKMessageSendEventsProvider* ret = MALLOC(sizeof(LDKMessageSendEventsProvider), "LDKMessageSendEventsProvider");
8207         *ret = ChannelManager_as_MessageSendEventsProvider(&this_arg_conv);
8208         return (long)ret;
8209 }
8210
8211 uint32_t  __attribute__((visibility("default"))) TS_ChannelManager_as_EventsProvider(uint32_t this_arg) {
8212         LDKChannelManager this_arg_conv;
8213         this_arg_conv.inner = (void*)(this_arg & (~1));
8214         this_arg_conv.is_owned = false;
8215         LDKEventsProvider* ret = MALLOC(sizeof(LDKEventsProvider), "LDKEventsProvider");
8216         *ret = ChannelManager_as_EventsProvider(&this_arg_conv);
8217         return (long)ret;
8218 }
8219
8220 void  __attribute__((visibility("default"))) TS_ChannelManager_block_connected(uint32_t this_arg, int8_tArray header, uint32_tArray txdata, int32_t height) {
8221         LDKChannelManager this_arg_conv;
8222         this_arg_conv.inner = (void*)(this_arg & (~1));
8223         this_arg_conv.is_owned = false;
8224         unsigned char header_arr[80];
8225         CHECK(*((uint32_t*)header) == 80);
8226         memcpy(header_arr, (uint8_t*)(header + 4), 80);
8227         unsigned char (*header_ref)[80] = &header_arr;
8228         LDKCVec_C2Tuple_usizeTransactionZZ txdata_constr;
8229         txdata_constr.datalen = *((uint32_t*)txdata);
8230         if (txdata_constr.datalen > 0)
8231                 txdata_constr.data = MALLOC(txdata_constr.datalen * sizeof(LDKC2Tuple_usizeTransactionZ), "LDKCVec_C2Tuple_usizeTransactionZZ Elements");
8232         else
8233                 txdata_constr.data = NULL;
8234         uint32_t* txdata_vals = (uint32_t*)(txdata + 4);
8235         for (size_t e = 0; e < txdata_constr.datalen; e++) {
8236                 uint32_t arr_conv_30 = txdata_vals[e];
8237                 LDKC2Tuple_usizeTransactionZ arr_conv_30_conv = *(LDKC2Tuple_usizeTransactionZ*)(((uint64_t)arr_conv_30) & ~1);
8238                 FREE((void*)arr_conv_30);
8239                 txdata_constr.data[e] = arr_conv_30_conv;
8240         }
8241         ChannelManager_block_connected(&this_arg_conv, header_ref, txdata_constr, height);
8242 }
8243
8244 void  __attribute__((visibility("default"))) TS_ChannelManager_block_disconnected(uint32_t this_arg, int8_tArray header) {
8245         LDKChannelManager this_arg_conv;
8246         this_arg_conv.inner = (void*)(this_arg & (~1));
8247         this_arg_conv.is_owned = false;
8248         unsigned char header_arr[80];
8249         CHECK(*((uint32_t*)header) == 80);
8250         memcpy(header_arr, (uint8_t*)(header + 4), 80);
8251         unsigned char (*header_ref)[80] = &header_arr;
8252         ChannelManager_block_disconnected(&this_arg_conv, header_ref);
8253 }
8254
8255 uint32_t  __attribute__((visibility("default"))) TS_ChannelManager_as_ChannelMessageHandler(uint32_t this_arg) {
8256         LDKChannelManager this_arg_conv;
8257         this_arg_conv.inner = (void*)(this_arg & (~1));
8258         this_arg_conv.is_owned = false;
8259         LDKChannelMessageHandler* ret = MALLOC(sizeof(LDKChannelMessageHandler), "LDKChannelMessageHandler");
8260         *ret = ChannelManager_as_ChannelMessageHandler(&this_arg_conv);
8261         return (long)ret;
8262 }
8263
8264 int8_tArray  __attribute__((visibility("default"))) TS_ChannelManager_write(uint32_t obj) {
8265         LDKChannelManager obj_conv;
8266         obj_conv.inner = (void*)(obj & (~1));
8267         obj_conv.is_owned = false;
8268         LDKCVec_u8Z arg_var = ChannelManager_write(&obj_conv);
8269         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
8270         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
8271         CVec_u8Z_free(arg_var);
8272         return arg_arr;
8273 }
8274
8275 void  __attribute__((visibility("default"))) TS_ChannelManagerReadArgs_free(uint32_t this_ptr) {
8276         LDKChannelManagerReadArgs this_ptr_conv;
8277         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8278         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8279         ChannelManagerReadArgs_free(this_ptr_conv);
8280 }
8281
8282 uint32_t  __attribute__((visibility("default"))) TS_ChannelManagerReadArgs_get_keys_manager(uint32_t this_ptr) {
8283         LDKChannelManagerReadArgs this_ptr_conv;
8284         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8285         this_ptr_conv.is_owned = false;
8286         long ret_ret = (long)ChannelManagerReadArgs_get_keys_manager(&this_ptr_conv);
8287         return ret_ret;
8288 }
8289
8290 void  __attribute__((visibility("default"))) TS_ChannelManagerReadArgs_set_keys_manager(uint32_t this_ptr, uint32_t val) {
8291         LDKChannelManagerReadArgs this_ptr_conv;
8292         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8293         this_ptr_conv.is_owned = false;
8294         LDKKeysInterface val_conv = *(LDKKeysInterface*)(((uint64_t)val) & ~1);
8295         ChannelManagerReadArgs_set_keys_manager(&this_ptr_conv, val_conv);
8296 }
8297
8298 uint32_t  __attribute__((visibility("default"))) TS_ChannelManagerReadArgs_get_fee_estimator(uint32_t this_ptr) {
8299         LDKChannelManagerReadArgs this_ptr_conv;
8300         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8301         this_ptr_conv.is_owned = false;
8302         long ret_ret = (long)ChannelManagerReadArgs_get_fee_estimator(&this_ptr_conv);
8303         return ret_ret;
8304 }
8305
8306 void  __attribute__((visibility("default"))) TS_ChannelManagerReadArgs_set_fee_estimator(uint32_t this_ptr, uint32_t val) {
8307         LDKChannelManagerReadArgs this_ptr_conv;
8308         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8309         this_ptr_conv.is_owned = false;
8310         LDKFeeEstimator val_conv = *(LDKFeeEstimator*)(((uint64_t)val) & ~1);
8311         ChannelManagerReadArgs_set_fee_estimator(&this_ptr_conv, val_conv);
8312 }
8313
8314 uint32_t  __attribute__((visibility("default"))) TS_ChannelManagerReadArgs_get_chain_monitor(uint32_t this_ptr) {
8315         LDKChannelManagerReadArgs this_ptr_conv;
8316         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8317         this_ptr_conv.is_owned = false;
8318         long ret_ret = (long)ChannelManagerReadArgs_get_chain_monitor(&this_ptr_conv);
8319         return ret_ret;
8320 }
8321
8322 void  __attribute__((visibility("default"))) TS_ChannelManagerReadArgs_set_chain_monitor(uint32_t this_ptr, uint32_t val) {
8323         LDKChannelManagerReadArgs this_ptr_conv;
8324         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8325         this_ptr_conv.is_owned = false;
8326         LDKWatch val_conv = *(LDKWatch*)(((uint64_t)val) & ~1);
8327         ChannelManagerReadArgs_set_chain_monitor(&this_ptr_conv, val_conv);
8328 }
8329
8330 uint32_t  __attribute__((visibility("default"))) TS_ChannelManagerReadArgs_get_tx_broadcaster(uint32_t this_ptr) {
8331         LDKChannelManagerReadArgs this_ptr_conv;
8332         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8333         this_ptr_conv.is_owned = false;
8334         long ret_ret = (long)ChannelManagerReadArgs_get_tx_broadcaster(&this_ptr_conv);
8335         return ret_ret;
8336 }
8337
8338 void  __attribute__((visibility("default"))) TS_ChannelManagerReadArgs_set_tx_broadcaster(uint32_t this_ptr, uint32_t val) {
8339         LDKChannelManagerReadArgs this_ptr_conv;
8340         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8341         this_ptr_conv.is_owned = false;
8342         LDKBroadcasterInterface val_conv = *(LDKBroadcasterInterface*)(((uint64_t)val) & ~1);
8343         ChannelManagerReadArgs_set_tx_broadcaster(&this_ptr_conv, val_conv);
8344 }
8345
8346 uint32_t  __attribute__((visibility("default"))) TS_ChannelManagerReadArgs_get_logger(uint32_t this_ptr) {
8347         LDKChannelManagerReadArgs this_ptr_conv;
8348         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8349         this_ptr_conv.is_owned = false;
8350         long ret_ret = (long)ChannelManagerReadArgs_get_logger(&this_ptr_conv);
8351         return ret_ret;
8352 }
8353
8354 void  __attribute__((visibility("default"))) TS_ChannelManagerReadArgs_set_logger(uint32_t this_ptr, uint32_t val) {
8355         LDKChannelManagerReadArgs this_ptr_conv;
8356         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8357         this_ptr_conv.is_owned = false;
8358         LDKLogger val_conv = *(LDKLogger*)(((uint64_t)val) & ~1);
8359         ChannelManagerReadArgs_set_logger(&this_ptr_conv, val_conv);
8360 }
8361
8362 uint32_t  __attribute__((visibility("default"))) TS_ChannelManagerReadArgs_get_default_config(uint32_t this_ptr) {
8363         LDKChannelManagerReadArgs this_ptr_conv;
8364         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8365         this_ptr_conv.is_owned = false;
8366         LDKUserConfig ret_var = ChannelManagerReadArgs_get_default_config(&this_ptr_conv);
8367         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8368         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8369         long ret_ref = (long)ret_var.inner;
8370         if (ret_var.is_owned) {
8371                 ret_ref |= 1;
8372         }
8373         return ret_ref;
8374 }
8375
8376 void  __attribute__((visibility("default"))) TS_ChannelManagerReadArgs_set_default_config(uint32_t this_ptr, uint32_t val) {
8377         LDKChannelManagerReadArgs this_ptr_conv;
8378         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8379         this_ptr_conv.is_owned = false;
8380         LDKUserConfig val_conv;
8381         val_conv.inner = (void*)(val & (~1));
8382         val_conv.is_owned = (val & 1) || (val == 0);
8383         val_conv = UserConfig_clone(&val_conv);
8384         ChannelManagerReadArgs_set_default_config(&this_ptr_conv, val_conv);
8385 }
8386
8387 uint32_t  __attribute__((visibility("default"))) 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) {
8388         LDKKeysInterface keys_manager_conv = *(LDKKeysInterface*)(((uint64_t)keys_manager) & ~1);
8389         LDKFeeEstimator fee_estimator_conv = *(LDKFeeEstimator*)(((uint64_t)fee_estimator) & ~1);
8390         LDKWatch chain_monitor_conv = *(LDKWatch*)(((uint64_t)chain_monitor) & ~1);
8391         LDKBroadcasterInterface tx_broadcaster_conv = *(LDKBroadcasterInterface*)(((uint64_t)tx_broadcaster) & ~1);
8392         LDKLogger logger_conv = *(LDKLogger*)(((uint64_t)logger) & ~1);
8393         LDKUserConfig default_config_conv;
8394         default_config_conv.inner = (void*)(default_config & (~1));
8395         default_config_conv.is_owned = (default_config & 1) || (default_config == 0);
8396         default_config_conv = UserConfig_clone(&default_config_conv);
8397         LDKCVec_ChannelMonitorZ channel_monitors_constr;
8398         channel_monitors_constr.datalen = *((uint32_t*)channel_monitors);
8399         if (channel_monitors_constr.datalen > 0)
8400                 channel_monitors_constr.data = MALLOC(channel_monitors_constr.datalen * sizeof(LDKChannelMonitor), "LDKCVec_ChannelMonitorZ Elements");
8401         else
8402                 channel_monitors_constr.data = NULL;
8403         uint32_t* channel_monitors_vals = (uint32_t*)(channel_monitors + 4);
8404         for (size_t q = 0; q < channel_monitors_constr.datalen; q++) {
8405                 uint32_t arr_conv_16 = channel_monitors_vals[q];
8406                 LDKChannelMonitor arr_conv_16_conv;
8407                 arr_conv_16_conv.inner = (void*)(arr_conv_16 & (~1));
8408                 arr_conv_16_conv.is_owned = (arr_conv_16 & 1) || (arr_conv_16 == 0);
8409                 channel_monitors_constr.data[q] = arr_conv_16_conv;
8410         }
8411         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);
8412         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8413         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8414         long ret_ref = (long)ret_var.inner;
8415         if (ret_var.is_owned) {
8416                 ret_ref |= 1;
8417         }
8418         return ret_ref;
8419 }
8420
8421 uint32_t  __attribute__((visibility("default"))) TS_C2Tuple_BlockHashChannelManagerZ_read(int8_tArray ser, uint32_t arg) {
8422         LDKu8slice ser_ref;
8423         ser_ref.datalen = *((uint32_t*)ser);
8424         ser_ref.data = (int8_t*)(ser + 4);
8425         LDKChannelManagerReadArgs arg_conv;
8426         arg_conv.inner = (void*)(arg & (~1));
8427         arg_conv.is_owned = (arg & 1) || (arg == 0);
8428         // Warning: we need a move here but no clone is available for LDKChannelManagerReadArgs
8429         LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ), "LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ");
8430         *ret_conv = C2Tuple_BlockHashChannelManagerZ_read(ser_ref, arg_conv);
8431         return (long)ret_conv;
8432 }
8433
8434 void  __attribute__((visibility("default"))) TS_DecodeError_free(uint32_t this_ptr) {
8435         LDKDecodeError this_ptr_conv;
8436         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8437         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8438         DecodeError_free(this_ptr_conv);
8439 }
8440
8441 uint32_t  __attribute__((visibility("default"))) TS_DecodeError_clone(uint32_t orig) {
8442         LDKDecodeError orig_conv;
8443         orig_conv.inner = (void*)(orig & (~1));
8444         orig_conv.is_owned = false;
8445         LDKDecodeError ret_var = DecodeError_clone(&orig_conv);
8446         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8447         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8448         long ret_ref = (long)ret_var.inner;
8449         if (ret_var.is_owned) {
8450                 ret_ref |= 1;
8451         }
8452         return ret_ref;
8453 }
8454
8455 void  __attribute__((visibility("default"))) TS_Init_free(uint32_t this_ptr) {
8456         LDKInit this_ptr_conv;
8457         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8458         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8459         Init_free(this_ptr_conv);
8460 }
8461
8462 uint32_t  __attribute__((visibility("default"))) TS_Init_clone(uint32_t orig) {
8463         LDKInit orig_conv;
8464         orig_conv.inner = (void*)(orig & (~1));
8465         orig_conv.is_owned = false;
8466         LDKInit ret_var = Init_clone(&orig_conv);
8467         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8468         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8469         long ret_ref = (long)ret_var.inner;
8470         if (ret_var.is_owned) {
8471                 ret_ref |= 1;
8472         }
8473         return ret_ref;
8474 }
8475
8476 void  __attribute__((visibility("default"))) TS_ErrorMessage_free(uint32_t this_ptr) {
8477         LDKErrorMessage this_ptr_conv;
8478         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8479         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8480         ErrorMessage_free(this_ptr_conv);
8481 }
8482
8483 uint32_t  __attribute__((visibility("default"))) TS_ErrorMessage_clone(uint32_t orig) {
8484         LDKErrorMessage orig_conv;
8485         orig_conv.inner = (void*)(orig & (~1));
8486         orig_conv.is_owned = false;
8487         LDKErrorMessage ret_var = ErrorMessage_clone(&orig_conv);
8488         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8489         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8490         long ret_ref = (long)ret_var.inner;
8491         if (ret_var.is_owned) {
8492                 ret_ref |= 1;
8493         }
8494         return ret_ref;
8495 }
8496
8497 int8_tArray  __attribute__((visibility("default"))) TS_ErrorMessage_get_channel_id(uint32_t this_ptr) {
8498         LDKErrorMessage this_ptr_conv;
8499         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8500         this_ptr_conv.is_owned = false;
8501         int8_tArray ret_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
8502         memcpy((uint8_t*)(ret_arr + 4), *ErrorMessage_get_channel_id(&this_ptr_conv), 32);
8503         return ret_arr;
8504 }
8505
8506 void  __attribute__((visibility("default"))) TS_ErrorMessage_set_channel_id(uint32_t this_ptr, int8_tArray val) {
8507         LDKErrorMessage this_ptr_conv;
8508         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8509         this_ptr_conv.is_owned = false;
8510         LDKThirtyTwoBytes val_ref;
8511         CHECK(*((uint32_t*)val) == 32);
8512         memcpy(val_ref.data, (uint8_t*)(val + 4), 32);
8513         ErrorMessage_set_channel_id(&this_ptr_conv, val_ref);
8514 }
8515
8516 jstring  __attribute__((visibility("default"))) TS_ErrorMessage_get_data(uint32_t this_ptr) {
8517         LDKErrorMessage this_ptr_conv;
8518         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8519         this_ptr_conv.is_owned = false;
8520         LDKStr _str = ErrorMessage_get_data(&this_ptr_conv);
8521         jstring _conv = str_ref_to_ts(_str.chars, _str.len);
8522         return _conv;
8523 }
8524
8525 void  __attribute__((visibility("default"))) TS_ErrorMessage_set_data(uint32_t this_ptr, int8_tArray val) {
8526         LDKErrorMessage this_ptr_conv;
8527         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8528         this_ptr_conv.is_owned = false;
8529         LDKCVec_u8Z val_ref;
8530         val_ref.datalen = *((uint32_t*)val);
8531         val_ref.data = MALLOC(val_ref.datalen, "LDKCVec_u8Z Bytes");
8532         memcpy(val_ref.data, (uint8_t*)(val + 4), val_ref.datalen);
8533         ErrorMessage_set_data(&this_ptr_conv, val_ref);
8534 }
8535
8536 uint32_t  __attribute__((visibility("default"))) TS_ErrorMessage_new(int8_tArray channel_id_arg, int8_tArray data_arg) {
8537         LDKThirtyTwoBytes channel_id_arg_ref;
8538         CHECK(*((uint32_t*)channel_id_arg) == 32);
8539         memcpy(channel_id_arg_ref.data, (uint8_t*)(channel_id_arg + 4), 32);
8540         LDKCVec_u8Z data_arg_ref;
8541         data_arg_ref.datalen = *((uint32_t*)data_arg);
8542         data_arg_ref.data = MALLOC(data_arg_ref.datalen, "LDKCVec_u8Z Bytes");
8543         memcpy(data_arg_ref.data, (uint8_t*)(data_arg + 4), data_arg_ref.datalen);
8544         LDKErrorMessage ret_var = ErrorMessage_new(channel_id_arg_ref, data_arg_ref);
8545         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8546         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8547         long ret_ref = (long)ret_var.inner;
8548         if (ret_var.is_owned) {
8549                 ret_ref |= 1;
8550         }
8551         return ret_ref;
8552 }
8553
8554 void  __attribute__((visibility("default"))) TS_Ping_free(uint32_t this_ptr) {
8555         LDKPing this_ptr_conv;
8556         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8557         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8558         Ping_free(this_ptr_conv);
8559 }
8560
8561 uint32_t  __attribute__((visibility("default"))) TS_Ping_clone(uint32_t orig) {
8562         LDKPing orig_conv;
8563         orig_conv.inner = (void*)(orig & (~1));
8564         orig_conv.is_owned = false;
8565         LDKPing ret_var = Ping_clone(&orig_conv);
8566         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8567         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8568         long ret_ref = (long)ret_var.inner;
8569         if (ret_var.is_owned) {
8570                 ret_ref |= 1;
8571         }
8572         return ret_ref;
8573 }
8574
8575 int16_t  __attribute__((visibility("default"))) TS_Ping_get_ponglen(uint32_t this_ptr) {
8576         LDKPing this_ptr_conv;
8577         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8578         this_ptr_conv.is_owned = false;
8579         int16_t ret_val = Ping_get_ponglen(&this_ptr_conv);
8580         return ret_val;
8581 }
8582
8583 void  __attribute__((visibility("default"))) TS_Ping_set_ponglen(uint32_t this_ptr, int16_t val) {
8584         LDKPing this_ptr_conv;
8585         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8586         this_ptr_conv.is_owned = false;
8587         Ping_set_ponglen(&this_ptr_conv, val);
8588 }
8589
8590 int16_t  __attribute__((visibility("default"))) TS_Ping_get_byteslen(uint32_t this_ptr) {
8591         LDKPing this_ptr_conv;
8592         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8593         this_ptr_conv.is_owned = false;
8594         int16_t ret_val = Ping_get_byteslen(&this_ptr_conv);
8595         return ret_val;
8596 }
8597
8598 void  __attribute__((visibility("default"))) TS_Ping_set_byteslen(uint32_t this_ptr, int16_t val) {
8599         LDKPing this_ptr_conv;
8600         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8601         this_ptr_conv.is_owned = false;
8602         Ping_set_byteslen(&this_ptr_conv, val);
8603 }
8604
8605 uint32_t  __attribute__((visibility("default"))) TS_Ping_new(int16_t ponglen_arg, int16_t byteslen_arg) {
8606         LDKPing ret_var = Ping_new(ponglen_arg, byteslen_arg);
8607         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8608         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8609         long ret_ref = (long)ret_var.inner;
8610         if (ret_var.is_owned) {
8611                 ret_ref |= 1;
8612         }
8613         return ret_ref;
8614 }
8615
8616 void  __attribute__((visibility("default"))) TS_Pong_free(uint32_t this_ptr) {
8617         LDKPong this_ptr_conv;
8618         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8619         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8620         Pong_free(this_ptr_conv);
8621 }
8622
8623 uint32_t  __attribute__((visibility("default"))) TS_Pong_clone(uint32_t orig) {
8624         LDKPong orig_conv;
8625         orig_conv.inner = (void*)(orig & (~1));
8626         orig_conv.is_owned = false;
8627         LDKPong ret_var = Pong_clone(&orig_conv);
8628         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8629         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8630         long ret_ref = (long)ret_var.inner;
8631         if (ret_var.is_owned) {
8632                 ret_ref |= 1;
8633         }
8634         return ret_ref;
8635 }
8636
8637 int16_t  __attribute__((visibility("default"))) TS_Pong_get_byteslen(uint32_t this_ptr) {
8638         LDKPong this_ptr_conv;
8639         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8640         this_ptr_conv.is_owned = false;
8641         int16_t ret_val = Pong_get_byteslen(&this_ptr_conv);
8642         return ret_val;
8643 }
8644
8645 void  __attribute__((visibility("default"))) TS_Pong_set_byteslen(uint32_t this_ptr, int16_t val) {
8646         LDKPong this_ptr_conv;
8647         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8648         this_ptr_conv.is_owned = false;
8649         Pong_set_byteslen(&this_ptr_conv, val);
8650 }
8651
8652 uint32_t  __attribute__((visibility("default"))) TS_Pong_new(int16_t byteslen_arg) {
8653         LDKPong ret_var = Pong_new(byteslen_arg);
8654         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8655         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8656         long ret_ref = (long)ret_var.inner;
8657         if (ret_var.is_owned) {
8658                 ret_ref |= 1;
8659         }
8660         return ret_ref;
8661 }
8662
8663 void  __attribute__((visibility("default"))) TS_OpenChannel_free(uint32_t this_ptr) {
8664         LDKOpenChannel this_ptr_conv;
8665         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8666         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8667         OpenChannel_free(this_ptr_conv);
8668 }
8669
8670 uint32_t  __attribute__((visibility("default"))) TS_OpenChannel_clone(uint32_t orig) {
8671         LDKOpenChannel orig_conv;
8672         orig_conv.inner = (void*)(orig & (~1));
8673         orig_conv.is_owned = false;
8674         LDKOpenChannel ret_var = OpenChannel_clone(&orig_conv);
8675         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8676         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8677         long ret_ref = (long)ret_var.inner;
8678         if (ret_var.is_owned) {
8679                 ret_ref |= 1;
8680         }
8681         return ret_ref;
8682 }
8683
8684 int8_tArray  __attribute__((visibility("default"))) TS_OpenChannel_get_chain_hash(uint32_t this_ptr) {
8685         LDKOpenChannel this_ptr_conv;
8686         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8687         this_ptr_conv.is_owned = false;
8688         int8_tArray ret_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
8689         memcpy((uint8_t*)(ret_arr + 4), *OpenChannel_get_chain_hash(&this_ptr_conv), 32);
8690         return ret_arr;
8691 }
8692
8693 void  __attribute__((visibility("default"))) TS_OpenChannel_set_chain_hash(uint32_t this_ptr, int8_tArray val) {
8694         LDKOpenChannel this_ptr_conv;
8695         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8696         this_ptr_conv.is_owned = false;
8697         LDKThirtyTwoBytes val_ref;
8698         CHECK(*((uint32_t*)val) == 32);
8699         memcpy(val_ref.data, (uint8_t*)(val + 4), 32);
8700         OpenChannel_set_chain_hash(&this_ptr_conv, val_ref);
8701 }
8702
8703 int8_tArray  __attribute__((visibility("default"))) TS_OpenChannel_get_temporary_channel_id(uint32_t this_ptr) {
8704         LDKOpenChannel this_ptr_conv;
8705         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8706         this_ptr_conv.is_owned = false;
8707         int8_tArray ret_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
8708         memcpy((uint8_t*)(ret_arr + 4), *OpenChannel_get_temporary_channel_id(&this_ptr_conv), 32);
8709         return ret_arr;
8710 }
8711
8712 void  __attribute__((visibility("default"))) TS_OpenChannel_set_temporary_channel_id(uint32_t this_ptr, int8_tArray val) {
8713         LDKOpenChannel this_ptr_conv;
8714         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8715         this_ptr_conv.is_owned = false;
8716         LDKThirtyTwoBytes val_ref;
8717         CHECK(*((uint32_t*)val) == 32);
8718         memcpy(val_ref.data, (uint8_t*)(val + 4), 32);
8719         OpenChannel_set_temporary_channel_id(&this_ptr_conv, val_ref);
8720 }
8721
8722 int64_t  __attribute__((visibility("default"))) TS_OpenChannel_get_funding_satoshis(uint32_t this_ptr) {
8723         LDKOpenChannel this_ptr_conv;
8724         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8725         this_ptr_conv.is_owned = false;
8726         int64_t ret_val = OpenChannel_get_funding_satoshis(&this_ptr_conv);
8727         return ret_val;
8728 }
8729
8730 void  __attribute__((visibility("default"))) TS_OpenChannel_set_funding_satoshis(uint32_t this_ptr, int64_t val) {
8731         LDKOpenChannel this_ptr_conv;
8732         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8733         this_ptr_conv.is_owned = false;
8734         OpenChannel_set_funding_satoshis(&this_ptr_conv, val);
8735 }
8736
8737 int64_t  __attribute__((visibility("default"))) TS_OpenChannel_get_push_msat(uint32_t this_ptr) {
8738         LDKOpenChannel this_ptr_conv;
8739         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8740         this_ptr_conv.is_owned = false;
8741         int64_t ret_val = OpenChannel_get_push_msat(&this_ptr_conv);
8742         return ret_val;
8743 }
8744
8745 void  __attribute__((visibility("default"))) TS_OpenChannel_set_push_msat(uint32_t this_ptr, int64_t val) {
8746         LDKOpenChannel this_ptr_conv;
8747         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8748         this_ptr_conv.is_owned = false;
8749         OpenChannel_set_push_msat(&this_ptr_conv, val);
8750 }
8751
8752 int64_t  __attribute__((visibility("default"))) TS_OpenChannel_get_dust_limit_satoshis(uint32_t this_ptr) {
8753         LDKOpenChannel this_ptr_conv;
8754         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8755         this_ptr_conv.is_owned = false;
8756         int64_t ret_val = OpenChannel_get_dust_limit_satoshis(&this_ptr_conv);
8757         return ret_val;
8758 }
8759
8760 void  __attribute__((visibility("default"))) TS_OpenChannel_set_dust_limit_satoshis(uint32_t this_ptr, int64_t val) {
8761         LDKOpenChannel this_ptr_conv;
8762         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8763         this_ptr_conv.is_owned = false;
8764         OpenChannel_set_dust_limit_satoshis(&this_ptr_conv, val);
8765 }
8766
8767 int64_t  __attribute__((visibility("default"))) TS_OpenChannel_get_max_htlc_value_in_flight_msat(uint32_t this_ptr) {
8768         LDKOpenChannel this_ptr_conv;
8769         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8770         this_ptr_conv.is_owned = false;
8771         int64_t ret_val = OpenChannel_get_max_htlc_value_in_flight_msat(&this_ptr_conv);
8772         return ret_val;
8773 }
8774
8775 void  __attribute__((visibility("default"))) TS_OpenChannel_set_max_htlc_value_in_flight_msat(uint32_t this_ptr, int64_t val) {
8776         LDKOpenChannel this_ptr_conv;
8777         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8778         this_ptr_conv.is_owned = false;
8779         OpenChannel_set_max_htlc_value_in_flight_msat(&this_ptr_conv, val);
8780 }
8781
8782 int64_t  __attribute__((visibility("default"))) TS_OpenChannel_get_channel_reserve_satoshis(uint32_t this_ptr) {
8783         LDKOpenChannel this_ptr_conv;
8784         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8785         this_ptr_conv.is_owned = false;
8786         int64_t ret_val = OpenChannel_get_channel_reserve_satoshis(&this_ptr_conv);
8787         return ret_val;
8788 }
8789
8790 void  __attribute__((visibility("default"))) TS_OpenChannel_set_channel_reserve_satoshis(uint32_t this_ptr, int64_t val) {
8791         LDKOpenChannel this_ptr_conv;
8792         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8793         this_ptr_conv.is_owned = false;
8794         OpenChannel_set_channel_reserve_satoshis(&this_ptr_conv, val);
8795 }
8796
8797 int64_t  __attribute__((visibility("default"))) TS_OpenChannel_get_htlc_minimum_msat(uint32_t this_ptr) {
8798         LDKOpenChannel this_ptr_conv;
8799         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8800         this_ptr_conv.is_owned = false;
8801         int64_t ret_val = OpenChannel_get_htlc_minimum_msat(&this_ptr_conv);
8802         return ret_val;
8803 }
8804
8805 void  __attribute__((visibility("default"))) TS_OpenChannel_set_htlc_minimum_msat(uint32_t this_ptr, int64_t val) {
8806         LDKOpenChannel this_ptr_conv;
8807         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8808         this_ptr_conv.is_owned = false;
8809         OpenChannel_set_htlc_minimum_msat(&this_ptr_conv, val);
8810 }
8811
8812 int32_t  __attribute__((visibility("default"))) TS_OpenChannel_get_feerate_per_kw(uint32_t this_ptr) {
8813         LDKOpenChannel this_ptr_conv;
8814         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8815         this_ptr_conv.is_owned = false;
8816         int32_t ret_val = OpenChannel_get_feerate_per_kw(&this_ptr_conv);
8817         return ret_val;
8818 }
8819
8820 void  __attribute__((visibility("default"))) TS_OpenChannel_set_feerate_per_kw(uint32_t this_ptr, int32_t val) {
8821         LDKOpenChannel this_ptr_conv;
8822         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8823         this_ptr_conv.is_owned = false;
8824         OpenChannel_set_feerate_per_kw(&this_ptr_conv, val);
8825 }
8826
8827 int16_t  __attribute__((visibility("default"))) TS_OpenChannel_get_to_self_delay(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         int16_t ret_val = OpenChannel_get_to_self_delay(&this_ptr_conv);
8832         return ret_val;
8833 }
8834
8835 void  __attribute__((visibility("default"))) TS_OpenChannel_set_to_self_delay(uint32_t this_ptr, int16_t val) {
8836         LDKOpenChannel this_ptr_conv;
8837         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8838         this_ptr_conv.is_owned = false;
8839         OpenChannel_set_to_self_delay(&this_ptr_conv, val);
8840 }
8841
8842 int16_t  __attribute__((visibility("default"))) TS_OpenChannel_get_max_accepted_htlcs(uint32_t this_ptr) {
8843         LDKOpenChannel this_ptr_conv;
8844         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8845         this_ptr_conv.is_owned = false;
8846         int16_t ret_val = OpenChannel_get_max_accepted_htlcs(&this_ptr_conv);
8847         return ret_val;
8848 }
8849
8850 void  __attribute__((visibility("default"))) TS_OpenChannel_set_max_accepted_htlcs(uint32_t this_ptr, int16_t val) {
8851         LDKOpenChannel this_ptr_conv;
8852         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8853         this_ptr_conv.is_owned = false;
8854         OpenChannel_set_max_accepted_htlcs(&this_ptr_conv, val);
8855 }
8856
8857 int8_tArray  __attribute__((visibility("default"))) TS_OpenChannel_get_funding_pubkey(uint32_t this_ptr) {
8858         LDKOpenChannel this_ptr_conv;
8859         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8860         this_ptr_conv.is_owned = false;
8861         int8_tArray arg_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
8862         memcpy((uint8_t*)(arg_arr + 4), OpenChannel_get_funding_pubkey(&this_ptr_conv).compressed_form, 33);
8863         return arg_arr;
8864 }
8865
8866 void  __attribute__((visibility("default"))) TS_OpenChannel_set_funding_pubkey(uint32_t this_ptr, int8_tArray val) {
8867         LDKOpenChannel this_ptr_conv;
8868         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8869         this_ptr_conv.is_owned = false;
8870         LDKPublicKey val_ref;
8871         CHECK(*((uint32_t*)val) == 33);
8872         memcpy(val_ref.compressed_form, (uint8_t*)(val + 4), 33);
8873         OpenChannel_set_funding_pubkey(&this_ptr_conv, val_ref);
8874 }
8875
8876 int8_tArray  __attribute__((visibility("default"))) TS_OpenChannel_get_revocation_basepoint(uint32_t this_ptr) {
8877         LDKOpenChannel this_ptr_conv;
8878         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8879         this_ptr_conv.is_owned = false;
8880         int8_tArray arg_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
8881         memcpy((uint8_t*)(arg_arr + 4), OpenChannel_get_revocation_basepoint(&this_ptr_conv).compressed_form, 33);
8882         return arg_arr;
8883 }
8884
8885 void  __attribute__((visibility("default"))) TS_OpenChannel_set_revocation_basepoint(uint32_t this_ptr, int8_tArray val) {
8886         LDKOpenChannel this_ptr_conv;
8887         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8888         this_ptr_conv.is_owned = false;
8889         LDKPublicKey val_ref;
8890         CHECK(*((uint32_t*)val) == 33);
8891         memcpy(val_ref.compressed_form, (uint8_t*)(val + 4), 33);
8892         OpenChannel_set_revocation_basepoint(&this_ptr_conv, val_ref);
8893 }
8894
8895 int8_tArray  __attribute__((visibility("default"))) TS_OpenChannel_get_payment_point(uint32_t this_ptr) {
8896         LDKOpenChannel this_ptr_conv;
8897         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8898         this_ptr_conv.is_owned = false;
8899         int8_tArray arg_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
8900         memcpy((uint8_t*)(arg_arr + 4), OpenChannel_get_payment_point(&this_ptr_conv).compressed_form, 33);
8901         return arg_arr;
8902 }
8903
8904 void  __attribute__((visibility("default"))) TS_OpenChannel_set_payment_point(uint32_t this_ptr, int8_tArray val) {
8905         LDKOpenChannel this_ptr_conv;
8906         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8907         this_ptr_conv.is_owned = false;
8908         LDKPublicKey val_ref;
8909         CHECK(*((uint32_t*)val) == 33);
8910         memcpy(val_ref.compressed_form, (uint8_t*)(val + 4), 33);
8911         OpenChannel_set_payment_point(&this_ptr_conv, val_ref);
8912 }
8913
8914 int8_tArray  __attribute__((visibility("default"))) TS_OpenChannel_get_delayed_payment_basepoint(uint32_t this_ptr) {
8915         LDKOpenChannel this_ptr_conv;
8916         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8917         this_ptr_conv.is_owned = false;
8918         int8_tArray arg_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
8919         memcpy((uint8_t*)(arg_arr + 4), OpenChannel_get_delayed_payment_basepoint(&this_ptr_conv).compressed_form, 33);
8920         return arg_arr;
8921 }
8922
8923 void  __attribute__((visibility("default"))) TS_OpenChannel_set_delayed_payment_basepoint(uint32_t this_ptr, int8_tArray val) {
8924         LDKOpenChannel this_ptr_conv;
8925         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8926         this_ptr_conv.is_owned = false;
8927         LDKPublicKey val_ref;
8928         CHECK(*((uint32_t*)val) == 33);
8929         memcpy(val_ref.compressed_form, (uint8_t*)(val + 4), 33);
8930         OpenChannel_set_delayed_payment_basepoint(&this_ptr_conv, val_ref);
8931 }
8932
8933 int8_tArray  __attribute__((visibility("default"))) TS_OpenChannel_get_htlc_basepoint(uint32_t this_ptr) {
8934         LDKOpenChannel this_ptr_conv;
8935         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8936         this_ptr_conv.is_owned = false;
8937         int8_tArray arg_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
8938         memcpy((uint8_t*)(arg_arr + 4), OpenChannel_get_htlc_basepoint(&this_ptr_conv).compressed_form, 33);
8939         return arg_arr;
8940 }
8941
8942 void  __attribute__((visibility("default"))) TS_OpenChannel_set_htlc_basepoint(uint32_t this_ptr, int8_tArray val) {
8943         LDKOpenChannel this_ptr_conv;
8944         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8945         this_ptr_conv.is_owned = false;
8946         LDKPublicKey val_ref;
8947         CHECK(*((uint32_t*)val) == 33);
8948         memcpy(val_ref.compressed_form, (uint8_t*)(val + 4), 33);
8949         OpenChannel_set_htlc_basepoint(&this_ptr_conv, val_ref);
8950 }
8951
8952 int8_tArray  __attribute__((visibility("default"))) TS_OpenChannel_get_first_per_commitment_point(uint32_t this_ptr) {
8953         LDKOpenChannel this_ptr_conv;
8954         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8955         this_ptr_conv.is_owned = false;
8956         int8_tArray arg_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
8957         memcpy((uint8_t*)(arg_arr + 4), OpenChannel_get_first_per_commitment_point(&this_ptr_conv).compressed_form, 33);
8958         return arg_arr;
8959 }
8960
8961 void  __attribute__((visibility("default"))) TS_OpenChannel_set_first_per_commitment_point(uint32_t this_ptr, int8_tArray val) {
8962         LDKOpenChannel this_ptr_conv;
8963         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8964         this_ptr_conv.is_owned = false;
8965         LDKPublicKey val_ref;
8966         CHECK(*((uint32_t*)val) == 33);
8967         memcpy(val_ref.compressed_form, (uint8_t*)(val + 4), 33);
8968         OpenChannel_set_first_per_commitment_point(&this_ptr_conv, val_ref);
8969 }
8970
8971 int8_t  __attribute__((visibility("default"))) TS_OpenChannel_get_channel_flags(uint32_t this_ptr) {
8972         LDKOpenChannel this_ptr_conv;
8973         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8974         this_ptr_conv.is_owned = false;
8975         int8_t ret_val = OpenChannel_get_channel_flags(&this_ptr_conv);
8976         return ret_val;
8977 }
8978
8979 void  __attribute__((visibility("default"))) TS_OpenChannel_set_channel_flags(uint32_t this_ptr, int8_t val) {
8980         LDKOpenChannel this_ptr_conv;
8981         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8982         this_ptr_conv.is_owned = false;
8983         OpenChannel_set_channel_flags(&this_ptr_conv, val);
8984 }
8985
8986 void  __attribute__((visibility("default"))) TS_AcceptChannel_free(uint32_t this_ptr) {
8987         LDKAcceptChannel this_ptr_conv;
8988         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8989         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8990         AcceptChannel_free(this_ptr_conv);
8991 }
8992
8993 uint32_t  __attribute__((visibility("default"))) TS_AcceptChannel_clone(uint32_t orig) {
8994         LDKAcceptChannel orig_conv;
8995         orig_conv.inner = (void*)(orig & (~1));
8996         orig_conv.is_owned = false;
8997         LDKAcceptChannel ret_var = AcceptChannel_clone(&orig_conv);
8998         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8999         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9000         long ret_ref = (long)ret_var.inner;
9001         if (ret_var.is_owned) {
9002                 ret_ref |= 1;
9003         }
9004         return ret_ref;
9005 }
9006
9007 int8_tArray  __attribute__((visibility("default"))) TS_AcceptChannel_get_temporary_channel_id(uint32_t this_ptr) {
9008         LDKAcceptChannel this_ptr_conv;
9009         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9010         this_ptr_conv.is_owned = false;
9011         int8_tArray ret_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
9012         memcpy((uint8_t*)(ret_arr + 4), *AcceptChannel_get_temporary_channel_id(&this_ptr_conv), 32);
9013         return ret_arr;
9014 }
9015
9016 void  __attribute__((visibility("default"))) TS_AcceptChannel_set_temporary_channel_id(uint32_t this_ptr, int8_tArray val) {
9017         LDKAcceptChannel this_ptr_conv;
9018         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9019         this_ptr_conv.is_owned = false;
9020         LDKThirtyTwoBytes val_ref;
9021         CHECK(*((uint32_t*)val) == 32);
9022         memcpy(val_ref.data, (uint8_t*)(val + 4), 32);
9023         AcceptChannel_set_temporary_channel_id(&this_ptr_conv, val_ref);
9024 }
9025
9026 int64_t  __attribute__((visibility("default"))) TS_AcceptChannel_get_dust_limit_satoshis(uint32_t this_ptr) {
9027         LDKAcceptChannel this_ptr_conv;
9028         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9029         this_ptr_conv.is_owned = false;
9030         int64_t ret_val = AcceptChannel_get_dust_limit_satoshis(&this_ptr_conv);
9031         return ret_val;
9032 }
9033
9034 void  __attribute__((visibility("default"))) TS_AcceptChannel_set_dust_limit_satoshis(uint32_t this_ptr, int64_t val) {
9035         LDKAcceptChannel this_ptr_conv;
9036         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9037         this_ptr_conv.is_owned = false;
9038         AcceptChannel_set_dust_limit_satoshis(&this_ptr_conv, val);
9039 }
9040
9041 int64_t  __attribute__((visibility("default"))) TS_AcceptChannel_get_max_htlc_value_in_flight_msat(uint32_t this_ptr) {
9042         LDKAcceptChannel this_ptr_conv;
9043         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9044         this_ptr_conv.is_owned = false;
9045         int64_t ret_val = AcceptChannel_get_max_htlc_value_in_flight_msat(&this_ptr_conv);
9046         return ret_val;
9047 }
9048
9049 void  __attribute__((visibility("default"))) TS_AcceptChannel_set_max_htlc_value_in_flight_msat(uint32_t this_ptr, int64_t val) {
9050         LDKAcceptChannel this_ptr_conv;
9051         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9052         this_ptr_conv.is_owned = false;
9053         AcceptChannel_set_max_htlc_value_in_flight_msat(&this_ptr_conv, val);
9054 }
9055
9056 int64_t  __attribute__((visibility("default"))) TS_AcceptChannel_get_channel_reserve_satoshis(uint32_t this_ptr) {
9057         LDKAcceptChannel this_ptr_conv;
9058         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9059         this_ptr_conv.is_owned = false;
9060         int64_t ret_val = AcceptChannel_get_channel_reserve_satoshis(&this_ptr_conv);
9061         return ret_val;
9062 }
9063
9064 void  __attribute__((visibility("default"))) TS_AcceptChannel_set_channel_reserve_satoshis(uint32_t this_ptr, int64_t val) {
9065         LDKAcceptChannel this_ptr_conv;
9066         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9067         this_ptr_conv.is_owned = false;
9068         AcceptChannel_set_channel_reserve_satoshis(&this_ptr_conv, val);
9069 }
9070
9071 int64_t  __attribute__((visibility("default"))) TS_AcceptChannel_get_htlc_minimum_msat(uint32_t this_ptr) {
9072         LDKAcceptChannel this_ptr_conv;
9073         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9074         this_ptr_conv.is_owned = false;
9075         int64_t ret_val = AcceptChannel_get_htlc_minimum_msat(&this_ptr_conv);
9076         return ret_val;
9077 }
9078
9079 void  __attribute__((visibility("default"))) TS_AcceptChannel_set_htlc_minimum_msat(uint32_t this_ptr, int64_t val) {
9080         LDKAcceptChannel this_ptr_conv;
9081         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9082         this_ptr_conv.is_owned = false;
9083         AcceptChannel_set_htlc_minimum_msat(&this_ptr_conv, val);
9084 }
9085
9086 int32_t  __attribute__((visibility("default"))) TS_AcceptChannel_get_minimum_depth(uint32_t this_ptr) {
9087         LDKAcceptChannel this_ptr_conv;
9088         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9089         this_ptr_conv.is_owned = false;
9090         int32_t ret_val = AcceptChannel_get_minimum_depth(&this_ptr_conv);
9091         return ret_val;
9092 }
9093
9094 void  __attribute__((visibility("default"))) TS_AcceptChannel_set_minimum_depth(uint32_t this_ptr, int32_t val) {
9095         LDKAcceptChannel this_ptr_conv;
9096         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9097         this_ptr_conv.is_owned = false;
9098         AcceptChannel_set_minimum_depth(&this_ptr_conv, val);
9099 }
9100
9101 int16_t  __attribute__((visibility("default"))) TS_AcceptChannel_get_to_self_delay(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         int16_t ret_val = AcceptChannel_get_to_self_delay(&this_ptr_conv);
9106         return ret_val;
9107 }
9108
9109 void  __attribute__((visibility("default"))) TS_AcceptChannel_set_to_self_delay(uint32_t this_ptr, int16_t val) {
9110         LDKAcceptChannel this_ptr_conv;
9111         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9112         this_ptr_conv.is_owned = false;
9113         AcceptChannel_set_to_self_delay(&this_ptr_conv, val);
9114 }
9115
9116 int16_t  __attribute__((visibility("default"))) TS_AcceptChannel_get_max_accepted_htlcs(uint32_t this_ptr) {
9117         LDKAcceptChannel this_ptr_conv;
9118         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9119         this_ptr_conv.is_owned = false;
9120         int16_t ret_val = AcceptChannel_get_max_accepted_htlcs(&this_ptr_conv);
9121         return ret_val;
9122 }
9123
9124 void  __attribute__((visibility("default"))) TS_AcceptChannel_set_max_accepted_htlcs(uint32_t this_ptr, int16_t val) {
9125         LDKAcceptChannel this_ptr_conv;
9126         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9127         this_ptr_conv.is_owned = false;
9128         AcceptChannel_set_max_accepted_htlcs(&this_ptr_conv, val);
9129 }
9130
9131 int8_tArray  __attribute__((visibility("default"))) TS_AcceptChannel_get_funding_pubkey(uint32_t this_ptr) {
9132         LDKAcceptChannel this_ptr_conv;
9133         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9134         this_ptr_conv.is_owned = false;
9135         int8_tArray arg_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
9136         memcpy((uint8_t*)(arg_arr + 4), AcceptChannel_get_funding_pubkey(&this_ptr_conv).compressed_form, 33);
9137         return arg_arr;
9138 }
9139
9140 void  __attribute__((visibility("default"))) TS_AcceptChannel_set_funding_pubkey(uint32_t this_ptr, int8_tArray val) {
9141         LDKAcceptChannel this_ptr_conv;
9142         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9143         this_ptr_conv.is_owned = false;
9144         LDKPublicKey val_ref;
9145         CHECK(*((uint32_t*)val) == 33);
9146         memcpy(val_ref.compressed_form, (uint8_t*)(val + 4), 33);
9147         AcceptChannel_set_funding_pubkey(&this_ptr_conv, val_ref);
9148 }
9149
9150 int8_tArray  __attribute__((visibility("default"))) TS_AcceptChannel_get_revocation_basepoint(uint32_t this_ptr) {
9151         LDKAcceptChannel this_ptr_conv;
9152         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9153         this_ptr_conv.is_owned = false;
9154         int8_tArray arg_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
9155         memcpy((uint8_t*)(arg_arr + 4), AcceptChannel_get_revocation_basepoint(&this_ptr_conv).compressed_form, 33);
9156         return arg_arr;
9157 }
9158
9159 void  __attribute__((visibility("default"))) TS_AcceptChannel_set_revocation_basepoint(uint32_t this_ptr, int8_tArray val) {
9160         LDKAcceptChannel this_ptr_conv;
9161         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9162         this_ptr_conv.is_owned = false;
9163         LDKPublicKey val_ref;
9164         CHECK(*((uint32_t*)val) == 33);
9165         memcpy(val_ref.compressed_form, (uint8_t*)(val + 4), 33);
9166         AcceptChannel_set_revocation_basepoint(&this_ptr_conv, val_ref);
9167 }
9168
9169 int8_tArray  __attribute__((visibility("default"))) TS_AcceptChannel_get_payment_point(uint32_t this_ptr) {
9170         LDKAcceptChannel this_ptr_conv;
9171         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9172         this_ptr_conv.is_owned = false;
9173         int8_tArray arg_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
9174         memcpy((uint8_t*)(arg_arr + 4), AcceptChannel_get_payment_point(&this_ptr_conv).compressed_form, 33);
9175         return arg_arr;
9176 }
9177
9178 void  __attribute__((visibility("default"))) TS_AcceptChannel_set_payment_point(uint32_t this_ptr, int8_tArray val) {
9179         LDKAcceptChannel this_ptr_conv;
9180         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9181         this_ptr_conv.is_owned = false;
9182         LDKPublicKey val_ref;
9183         CHECK(*((uint32_t*)val) == 33);
9184         memcpy(val_ref.compressed_form, (uint8_t*)(val + 4), 33);
9185         AcceptChannel_set_payment_point(&this_ptr_conv, val_ref);
9186 }
9187
9188 int8_tArray  __attribute__((visibility("default"))) TS_AcceptChannel_get_delayed_payment_basepoint(uint32_t this_ptr) {
9189         LDKAcceptChannel this_ptr_conv;
9190         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9191         this_ptr_conv.is_owned = false;
9192         int8_tArray arg_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
9193         memcpy((uint8_t*)(arg_arr + 4), AcceptChannel_get_delayed_payment_basepoint(&this_ptr_conv).compressed_form, 33);
9194         return arg_arr;
9195 }
9196
9197 void  __attribute__((visibility("default"))) TS_AcceptChannel_set_delayed_payment_basepoint(uint32_t this_ptr, int8_tArray val) {
9198         LDKAcceptChannel this_ptr_conv;
9199         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9200         this_ptr_conv.is_owned = false;
9201         LDKPublicKey val_ref;
9202         CHECK(*((uint32_t*)val) == 33);
9203         memcpy(val_ref.compressed_form, (uint8_t*)(val + 4), 33);
9204         AcceptChannel_set_delayed_payment_basepoint(&this_ptr_conv, val_ref);
9205 }
9206
9207 int8_tArray  __attribute__((visibility("default"))) TS_AcceptChannel_get_htlc_basepoint(uint32_t this_ptr) {
9208         LDKAcceptChannel this_ptr_conv;
9209         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9210         this_ptr_conv.is_owned = false;
9211         int8_tArray arg_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
9212         memcpy((uint8_t*)(arg_arr + 4), AcceptChannel_get_htlc_basepoint(&this_ptr_conv).compressed_form, 33);
9213         return arg_arr;
9214 }
9215
9216 void  __attribute__((visibility("default"))) TS_AcceptChannel_set_htlc_basepoint(uint32_t this_ptr, int8_tArray val) {
9217         LDKAcceptChannel this_ptr_conv;
9218         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9219         this_ptr_conv.is_owned = false;
9220         LDKPublicKey val_ref;
9221         CHECK(*((uint32_t*)val) == 33);
9222         memcpy(val_ref.compressed_form, (uint8_t*)(val + 4), 33);
9223         AcceptChannel_set_htlc_basepoint(&this_ptr_conv, val_ref);
9224 }
9225
9226 int8_tArray  __attribute__((visibility("default"))) TS_AcceptChannel_get_first_per_commitment_point(uint32_t this_ptr) {
9227         LDKAcceptChannel this_ptr_conv;
9228         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9229         this_ptr_conv.is_owned = false;
9230         int8_tArray arg_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
9231         memcpy((uint8_t*)(arg_arr + 4), AcceptChannel_get_first_per_commitment_point(&this_ptr_conv).compressed_form, 33);
9232         return arg_arr;
9233 }
9234
9235 void  __attribute__((visibility("default"))) TS_AcceptChannel_set_first_per_commitment_point(uint32_t this_ptr, int8_tArray val) {
9236         LDKAcceptChannel this_ptr_conv;
9237         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9238         this_ptr_conv.is_owned = false;
9239         LDKPublicKey val_ref;
9240         CHECK(*((uint32_t*)val) == 33);
9241         memcpy(val_ref.compressed_form, (uint8_t*)(val + 4), 33);
9242         AcceptChannel_set_first_per_commitment_point(&this_ptr_conv, val_ref);
9243 }
9244
9245 void  __attribute__((visibility("default"))) TS_FundingCreated_free(uint32_t this_ptr) {
9246         LDKFundingCreated this_ptr_conv;
9247         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9248         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9249         FundingCreated_free(this_ptr_conv);
9250 }
9251
9252 uint32_t  __attribute__((visibility("default"))) TS_FundingCreated_clone(uint32_t orig) {
9253         LDKFundingCreated orig_conv;
9254         orig_conv.inner = (void*)(orig & (~1));
9255         orig_conv.is_owned = false;
9256         LDKFundingCreated ret_var = FundingCreated_clone(&orig_conv);
9257         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9258         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9259         long ret_ref = (long)ret_var.inner;
9260         if (ret_var.is_owned) {
9261                 ret_ref |= 1;
9262         }
9263         return ret_ref;
9264 }
9265
9266 int8_tArray  __attribute__((visibility("default"))) TS_FundingCreated_get_temporary_channel_id(uint32_t this_ptr) {
9267         LDKFundingCreated this_ptr_conv;
9268         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9269         this_ptr_conv.is_owned = false;
9270         int8_tArray ret_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
9271         memcpy((uint8_t*)(ret_arr + 4), *FundingCreated_get_temporary_channel_id(&this_ptr_conv), 32);
9272         return ret_arr;
9273 }
9274
9275 void  __attribute__((visibility("default"))) TS_FundingCreated_set_temporary_channel_id(uint32_t this_ptr, int8_tArray val) {
9276         LDKFundingCreated this_ptr_conv;
9277         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9278         this_ptr_conv.is_owned = false;
9279         LDKThirtyTwoBytes val_ref;
9280         CHECK(*((uint32_t*)val) == 32);
9281         memcpy(val_ref.data, (uint8_t*)(val + 4), 32);
9282         FundingCreated_set_temporary_channel_id(&this_ptr_conv, val_ref);
9283 }
9284
9285 int8_tArray  __attribute__((visibility("default"))) TS_FundingCreated_get_funding_txid(uint32_t this_ptr) {
9286         LDKFundingCreated this_ptr_conv;
9287         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9288         this_ptr_conv.is_owned = false;
9289         int8_tArray ret_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
9290         memcpy((uint8_t*)(ret_arr + 4), *FundingCreated_get_funding_txid(&this_ptr_conv), 32);
9291         return ret_arr;
9292 }
9293
9294 void  __attribute__((visibility("default"))) TS_FundingCreated_set_funding_txid(uint32_t this_ptr, int8_tArray val) {
9295         LDKFundingCreated this_ptr_conv;
9296         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9297         this_ptr_conv.is_owned = false;
9298         LDKThirtyTwoBytes val_ref;
9299         CHECK(*((uint32_t*)val) == 32);
9300         memcpy(val_ref.data, (uint8_t*)(val + 4), 32);
9301         FundingCreated_set_funding_txid(&this_ptr_conv, val_ref);
9302 }
9303
9304 int16_t  __attribute__((visibility("default"))) TS_FundingCreated_get_funding_output_index(uint32_t this_ptr) {
9305         LDKFundingCreated this_ptr_conv;
9306         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9307         this_ptr_conv.is_owned = false;
9308         int16_t ret_val = FundingCreated_get_funding_output_index(&this_ptr_conv);
9309         return ret_val;
9310 }
9311
9312 void  __attribute__((visibility("default"))) TS_FundingCreated_set_funding_output_index(uint32_t this_ptr, int16_t val) {
9313         LDKFundingCreated this_ptr_conv;
9314         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9315         this_ptr_conv.is_owned = false;
9316         FundingCreated_set_funding_output_index(&this_ptr_conv, val);
9317 }
9318
9319 int8_tArray  __attribute__((visibility("default"))) TS_FundingCreated_get_signature(uint32_t this_ptr) {
9320         LDKFundingCreated this_ptr_conv;
9321         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9322         this_ptr_conv.is_owned = false;
9323         int8_tArray arg_arr = init_arr(64, sizeof(uint8_t), "Native int8_tArray Bytes");
9324         memcpy((uint8_t*)(arg_arr + 4), FundingCreated_get_signature(&this_ptr_conv).compact_form, 64);
9325         return arg_arr;
9326 }
9327
9328 void  __attribute__((visibility("default"))) TS_FundingCreated_set_signature(uint32_t this_ptr, int8_tArray val) {
9329         LDKFundingCreated this_ptr_conv;
9330         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9331         this_ptr_conv.is_owned = false;
9332         LDKSignature val_ref;
9333         CHECK(*((uint32_t*)val) == 64);
9334         memcpy(val_ref.compact_form, (uint8_t*)(val + 4), 64);
9335         FundingCreated_set_signature(&this_ptr_conv, val_ref);
9336 }
9337
9338 uint32_t  __attribute__((visibility("default"))) TS_FundingCreated_new(int8_tArray temporary_channel_id_arg, int8_tArray funding_txid_arg, int16_t funding_output_index_arg, int8_tArray signature_arg) {
9339         LDKThirtyTwoBytes temporary_channel_id_arg_ref;
9340         CHECK(*((uint32_t*)temporary_channel_id_arg) == 32);
9341         memcpy(temporary_channel_id_arg_ref.data, (uint8_t*)(temporary_channel_id_arg + 4), 32);
9342         LDKThirtyTwoBytes funding_txid_arg_ref;
9343         CHECK(*((uint32_t*)funding_txid_arg) == 32);
9344         memcpy(funding_txid_arg_ref.data, (uint8_t*)(funding_txid_arg + 4), 32);
9345         LDKSignature signature_arg_ref;
9346         CHECK(*((uint32_t*)signature_arg) == 64);
9347         memcpy(signature_arg_ref.compact_form, (uint8_t*)(signature_arg + 4), 64);
9348         LDKFundingCreated ret_var = FundingCreated_new(temporary_channel_id_arg_ref, funding_txid_arg_ref, funding_output_index_arg, signature_arg_ref);
9349         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9350         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9351         long ret_ref = (long)ret_var.inner;
9352         if (ret_var.is_owned) {
9353                 ret_ref |= 1;
9354         }
9355         return ret_ref;
9356 }
9357
9358 void  __attribute__((visibility("default"))) TS_FundingSigned_free(uint32_t this_ptr) {
9359         LDKFundingSigned this_ptr_conv;
9360         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9361         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9362         FundingSigned_free(this_ptr_conv);
9363 }
9364
9365 uint32_t  __attribute__((visibility("default"))) TS_FundingSigned_clone(uint32_t orig) {
9366         LDKFundingSigned orig_conv;
9367         orig_conv.inner = (void*)(orig & (~1));
9368         orig_conv.is_owned = false;
9369         LDKFundingSigned ret_var = FundingSigned_clone(&orig_conv);
9370         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9371         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9372         long ret_ref = (long)ret_var.inner;
9373         if (ret_var.is_owned) {
9374                 ret_ref |= 1;
9375         }
9376         return ret_ref;
9377 }
9378
9379 int8_tArray  __attribute__((visibility("default"))) TS_FundingSigned_get_channel_id(uint32_t this_ptr) {
9380         LDKFundingSigned this_ptr_conv;
9381         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9382         this_ptr_conv.is_owned = false;
9383         int8_tArray ret_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
9384         memcpy((uint8_t*)(ret_arr + 4), *FundingSigned_get_channel_id(&this_ptr_conv), 32);
9385         return ret_arr;
9386 }
9387
9388 void  __attribute__((visibility("default"))) TS_FundingSigned_set_channel_id(uint32_t this_ptr, int8_tArray val) {
9389         LDKFundingSigned this_ptr_conv;
9390         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9391         this_ptr_conv.is_owned = false;
9392         LDKThirtyTwoBytes val_ref;
9393         CHECK(*((uint32_t*)val) == 32);
9394         memcpy(val_ref.data, (uint8_t*)(val + 4), 32);
9395         FundingSigned_set_channel_id(&this_ptr_conv, val_ref);
9396 }
9397
9398 int8_tArray  __attribute__((visibility("default"))) TS_FundingSigned_get_signature(uint32_t this_ptr) {
9399         LDKFundingSigned this_ptr_conv;
9400         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9401         this_ptr_conv.is_owned = false;
9402         int8_tArray arg_arr = init_arr(64, sizeof(uint8_t), "Native int8_tArray Bytes");
9403         memcpy((uint8_t*)(arg_arr + 4), FundingSigned_get_signature(&this_ptr_conv).compact_form, 64);
9404         return arg_arr;
9405 }
9406
9407 void  __attribute__((visibility("default"))) TS_FundingSigned_set_signature(uint32_t this_ptr, int8_tArray val) {
9408         LDKFundingSigned this_ptr_conv;
9409         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9410         this_ptr_conv.is_owned = false;
9411         LDKSignature val_ref;
9412         CHECK(*((uint32_t*)val) == 64);
9413         memcpy(val_ref.compact_form, (uint8_t*)(val + 4), 64);
9414         FundingSigned_set_signature(&this_ptr_conv, val_ref);
9415 }
9416
9417 uint32_t  __attribute__((visibility("default"))) TS_FundingSigned_new(int8_tArray channel_id_arg, int8_tArray signature_arg) {
9418         LDKThirtyTwoBytes channel_id_arg_ref;
9419         CHECK(*((uint32_t*)channel_id_arg) == 32);
9420         memcpy(channel_id_arg_ref.data, (uint8_t*)(channel_id_arg + 4), 32);
9421         LDKSignature signature_arg_ref;
9422         CHECK(*((uint32_t*)signature_arg) == 64);
9423         memcpy(signature_arg_ref.compact_form, (uint8_t*)(signature_arg + 4), 64);
9424         LDKFundingSigned ret_var = FundingSigned_new(channel_id_arg_ref, signature_arg_ref);
9425         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9426         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9427         long ret_ref = (long)ret_var.inner;
9428         if (ret_var.is_owned) {
9429                 ret_ref |= 1;
9430         }
9431         return ret_ref;
9432 }
9433
9434 void  __attribute__((visibility("default"))) TS_FundingLocked_free(uint32_t this_ptr) {
9435         LDKFundingLocked this_ptr_conv;
9436         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9437         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9438         FundingLocked_free(this_ptr_conv);
9439 }
9440
9441 uint32_t  __attribute__((visibility("default"))) TS_FundingLocked_clone(uint32_t orig) {
9442         LDKFundingLocked orig_conv;
9443         orig_conv.inner = (void*)(orig & (~1));
9444         orig_conv.is_owned = false;
9445         LDKFundingLocked ret_var = FundingLocked_clone(&orig_conv);
9446         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9447         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9448         long ret_ref = (long)ret_var.inner;
9449         if (ret_var.is_owned) {
9450                 ret_ref |= 1;
9451         }
9452         return ret_ref;
9453 }
9454
9455 int8_tArray  __attribute__((visibility("default"))) TS_FundingLocked_get_channel_id(uint32_t this_ptr) {
9456         LDKFundingLocked this_ptr_conv;
9457         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9458         this_ptr_conv.is_owned = false;
9459         int8_tArray ret_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
9460         memcpy((uint8_t*)(ret_arr + 4), *FundingLocked_get_channel_id(&this_ptr_conv), 32);
9461         return ret_arr;
9462 }
9463
9464 void  __attribute__((visibility("default"))) TS_FundingLocked_set_channel_id(uint32_t this_ptr, int8_tArray val) {
9465         LDKFundingLocked this_ptr_conv;
9466         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9467         this_ptr_conv.is_owned = false;
9468         LDKThirtyTwoBytes val_ref;
9469         CHECK(*((uint32_t*)val) == 32);
9470         memcpy(val_ref.data, (uint8_t*)(val + 4), 32);
9471         FundingLocked_set_channel_id(&this_ptr_conv, val_ref);
9472 }
9473
9474 int8_tArray  __attribute__((visibility("default"))) TS_FundingLocked_get_next_per_commitment_point(uint32_t this_ptr) {
9475         LDKFundingLocked this_ptr_conv;
9476         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9477         this_ptr_conv.is_owned = false;
9478         int8_tArray arg_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
9479         memcpy((uint8_t*)(arg_arr + 4), FundingLocked_get_next_per_commitment_point(&this_ptr_conv).compressed_form, 33);
9480         return arg_arr;
9481 }
9482
9483 void  __attribute__((visibility("default"))) TS_FundingLocked_set_next_per_commitment_point(uint32_t this_ptr, int8_tArray val) {
9484         LDKFundingLocked this_ptr_conv;
9485         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9486         this_ptr_conv.is_owned = false;
9487         LDKPublicKey val_ref;
9488         CHECK(*((uint32_t*)val) == 33);
9489         memcpy(val_ref.compressed_form, (uint8_t*)(val + 4), 33);
9490         FundingLocked_set_next_per_commitment_point(&this_ptr_conv, val_ref);
9491 }
9492
9493 uint32_t  __attribute__((visibility("default"))) TS_FundingLocked_new(int8_tArray channel_id_arg, int8_tArray next_per_commitment_point_arg) {
9494         LDKThirtyTwoBytes channel_id_arg_ref;
9495         CHECK(*((uint32_t*)channel_id_arg) == 32);
9496         memcpy(channel_id_arg_ref.data, (uint8_t*)(channel_id_arg + 4), 32);
9497         LDKPublicKey next_per_commitment_point_arg_ref;
9498         CHECK(*((uint32_t*)next_per_commitment_point_arg) == 33);
9499         memcpy(next_per_commitment_point_arg_ref.compressed_form, (uint8_t*)(next_per_commitment_point_arg + 4), 33);
9500         LDKFundingLocked ret_var = FundingLocked_new(channel_id_arg_ref, next_per_commitment_point_arg_ref);
9501         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9502         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9503         long ret_ref = (long)ret_var.inner;
9504         if (ret_var.is_owned) {
9505                 ret_ref |= 1;
9506         }
9507         return ret_ref;
9508 }
9509
9510 void  __attribute__((visibility("default"))) TS_Shutdown_free(uint32_t this_ptr) {
9511         LDKShutdown this_ptr_conv;
9512         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9513         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9514         Shutdown_free(this_ptr_conv);
9515 }
9516
9517 uint32_t  __attribute__((visibility("default"))) TS_Shutdown_clone(uint32_t orig) {
9518         LDKShutdown orig_conv;
9519         orig_conv.inner = (void*)(orig & (~1));
9520         orig_conv.is_owned = false;
9521         LDKShutdown ret_var = Shutdown_clone(&orig_conv);
9522         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9523         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9524         long ret_ref = (long)ret_var.inner;
9525         if (ret_var.is_owned) {
9526                 ret_ref |= 1;
9527         }
9528         return ret_ref;
9529 }
9530
9531 int8_tArray  __attribute__((visibility("default"))) TS_Shutdown_get_channel_id(uint32_t this_ptr) {
9532         LDKShutdown this_ptr_conv;
9533         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9534         this_ptr_conv.is_owned = false;
9535         int8_tArray ret_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
9536         memcpy((uint8_t*)(ret_arr + 4), *Shutdown_get_channel_id(&this_ptr_conv), 32);
9537         return ret_arr;
9538 }
9539
9540 void  __attribute__((visibility("default"))) TS_Shutdown_set_channel_id(uint32_t this_ptr, int8_tArray val) {
9541         LDKShutdown this_ptr_conv;
9542         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9543         this_ptr_conv.is_owned = false;
9544         LDKThirtyTwoBytes val_ref;
9545         CHECK(*((uint32_t*)val) == 32);
9546         memcpy(val_ref.data, (uint8_t*)(val + 4), 32);
9547         Shutdown_set_channel_id(&this_ptr_conv, val_ref);
9548 }
9549
9550 int8_tArray  __attribute__((visibility("default"))) TS_Shutdown_get_scriptpubkey(uint32_t this_ptr) {
9551         LDKShutdown this_ptr_conv;
9552         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9553         this_ptr_conv.is_owned = false;
9554         LDKu8slice arg_var = Shutdown_get_scriptpubkey(&this_ptr_conv);
9555         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
9556         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
9557         return arg_arr;
9558 }
9559
9560 void  __attribute__((visibility("default"))) TS_Shutdown_set_scriptpubkey(uint32_t this_ptr, int8_tArray val) {
9561         LDKShutdown this_ptr_conv;
9562         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9563         this_ptr_conv.is_owned = false;
9564         LDKCVec_u8Z val_ref;
9565         val_ref.datalen = *((uint32_t*)val);
9566         val_ref.data = MALLOC(val_ref.datalen, "LDKCVec_u8Z Bytes");
9567         memcpy(val_ref.data, (uint8_t*)(val + 4), val_ref.datalen);
9568         Shutdown_set_scriptpubkey(&this_ptr_conv, val_ref);
9569 }
9570
9571 uint32_t  __attribute__((visibility("default"))) TS_Shutdown_new(int8_tArray channel_id_arg, int8_tArray scriptpubkey_arg) {
9572         LDKThirtyTwoBytes channel_id_arg_ref;
9573         CHECK(*((uint32_t*)channel_id_arg) == 32);
9574         memcpy(channel_id_arg_ref.data, (uint8_t*)(channel_id_arg + 4), 32);
9575         LDKCVec_u8Z scriptpubkey_arg_ref;
9576         scriptpubkey_arg_ref.datalen = *((uint32_t*)scriptpubkey_arg);
9577         scriptpubkey_arg_ref.data = MALLOC(scriptpubkey_arg_ref.datalen, "LDKCVec_u8Z Bytes");
9578         memcpy(scriptpubkey_arg_ref.data, (uint8_t*)(scriptpubkey_arg + 4), scriptpubkey_arg_ref.datalen);
9579         LDKShutdown ret_var = Shutdown_new(channel_id_arg_ref, scriptpubkey_arg_ref);
9580         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9581         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9582         long ret_ref = (long)ret_var.inner;
9583         if (ret_var.is_owned) {
9584                 ret_ref |= 1;
9585         }
9586         return ret_ref;
9587 }
9588
9589 void  __attribute__((visibility("default"))) TS_ClosingSigned_free(uint32_t this_ptr) {
9590         LDKClosingSigned this_ptr_conv;
9591         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9592         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9593         ClosingSigned_free(this_ptr_conv);
9594 }
9595
9596 uint32_t  __attribute__((visibility("default"))) TS_ClosingSigned_clone(uint32_t orig) {
9597         LDKClosingSigned orig_conv;
9598         orig_conv.inner = (void*)(orig & (~1));
9599         orig_conv.is_owned = false;
9600         LDKClosingSigned ret_var = ClosingSigned_clone(&orig_conv);
9601         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9602         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9603         long ret_ref = (long)ret_var.inner;
9604         if (ret_var.is_owned) {
9605                 ret_ref |= 1;
9606         }
9607         return ret_ref;
9608 }
9609
9610 int8_tArray  __attribute__((visibility("default"))) TS_ClosingSigned_get_channel_id(uint32_t this_ptr) {
9611         LDKClosingSigned this_ptr_conv;
9612         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9613         this_ptr_conv.is_owned = false;
9614         int8_tArray ret_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
9615         memcpy((uint8_t*)(ret_arr + 4), *ClosingSigned_get_channel_id(&this_ptr_conv), 32);
9616         return ret_arr;
9617 }
9618
9619 void  __attribute__((visibility("default"))) TS_ClosingSigned_set_channel_id(uint32_t this_ptr, int8_tArray val) {
9620         LDKClosingSigned this_ptr_conv;
9621         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9622         this_ptr_conv.is_owned = false;
9623         LDKThirtyTwoBytes val_ref;
9624         CHECK(*((uint32_t*)val) == 32);
9625         memcpy(val_ref.data, (uint8_t*)(val + 4), 32);
9626         ClosingSigned_set_channel_id(&this_ptr_conv, val_ref);
9627 }
9628
9629 int64_t  __attribute__((visibility("default"))) TS_ClosingSigned_get_fee_satoshis(uint32_t this_ptr) {
9630         LDKClosingSigned this_ptr_conv;
9631         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9632         this_ptr_conv.is_owned = false;
9633         int64_t ret_val = ClosingSigned_get_fee_satoshis(&this_ptr_conv);
9634         return ret_val;
9635 }
9636
9637 void  __attribute__((visibility("default"))) TS_ClosingSigned_set_fee_satoshis(uint32_t this_ptr, int64_t val) {
9638         LDKClosingSigned this_ptr_conv;
9639         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9640         this_ptr_conv.is_owned = false;
9641         ClosingSigned_set_fee_satoshis(&this_ptr_conv, val);
9642 }
9643
9644 int8_tArray  __attribute__((visibility("default"))) TS_ClosingSigned_get_signature(uint32_t this_ptr) {
9645         LDKClosingSigned this_ptr_conv;
9646         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9647         this_ptr_conv.is_owned = false;
9648         int8_tArray arg_arr = init_arr(64, sizeof(uint8_t), "Native int8_tArray Bytes");
9649         memcpy((uint8_t*)(arg_arr + 4), ClosingSigned_get_signature(&this_ptr_conv).compact_form, 64);
9650         return arg_arr;
9651 }
9652
9653 void  __attribute__((visibility("default"))) TS_ClosingSigned_set_signature(uint32_t this_ptr, int8_tArray val) {
9654         LDKClosingSigned this_ptr_conv;
9655         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9656         this_ptr_conv.is_owned = false;
9657         LDKSignature val_ref;
9658         CHECK(*((uint32_t*)val) == 64);
9659         memcpy(val_ref.compact_form, (uint8_t*)(val + 4), 64);
9660         ClosingSigned_set_signature(&this_ptr_conv, val_ref);
9661 }
9662
9663 uint32_t  __attribute__((visibility("default"))) TS_ClosingSigned_new(int8_tArray channel_id_arg, int64_t fee_satoshis_arg, int8_tArray signature_arg) {
9664         LDKThirtyTwoBytes channel_id_arg_ref;
9665         CHECK(*((uint32_t*)channel_id_arg) == 32);
9666         memcpy(channel_id_arg_ref.data, (uint8_t*)(channel_id_arg + 4), 32);
9667         LDKSignature signature_arg_ref;
9668         CHECK(*((uint32_t*)signature_arg) == 64);
9669         memcpy(signature_arg_ref.compact_form, (uint8_t*)(signature_arg + 4), 64);
9670         LDKClosingSigned ret_var = ClosingSigned_new(channel_id_arg_ref, fee_satoshis_arg, signature_arg_ref);
9671         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9672         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9673         long ret_ref = (long)ret_var.inner;
9674         if (ret_var.is_owned) {
9675                 ret_ref |= 1;
9676         }
9677         return ret_ref;
9678 }
9679
9680 void  __attribute__((visibility("default"))) TS_UpdateAddHTLC_free(uint32_t this_ptr) {
9681         LDKUpdateAddHTLC this_ptr_conv;
9682         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9683         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9684         UpdateAddHTLC_free(this_ptr_conv);
9685 }
9686
9687 uint32_t  __attribute__((visibility("default"))) TS_UpdateAddHTLC_clone(uint32_t orig) {
9688         LDKUpdateAddHTLC orig_conv;
9689         orig_conv.inner = (void*)(orig & (~1));
9690         orig_conv.is_owned = false;
9691         LDKUpdateAddHTLC ret_var = UpdateAddHTLC_clone(&orig_conv);
9692         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9693         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9694         long ret_ref = (long)ret_var.inner;
9695         if (ret_var.is_owned) {
9696                 ret_ref |= 1;
9697         }
9698         return ret_ref;
9699 }
9700
9701 int8_tArray  __attribute__((visibility("default"))) TS_UpdateAddHTLC_get_channel_id(uint32_t this_ptr) {
9702         LDKUpdateAddHTLC this_ptr_conv;
9703         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9704         this_ptr_conv.is_owned = false;
9705         int8_tArray ret_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
9706         memcpy((uint8_t*)(ret_arr + 4), *UpdateAddHTLC_get_channel_id(&this_ptr_conv), 32);
9707         return ret_arr;
9708 }
9709
9710 void  __attribute__((visibility("default"))) TS_UpdateAddHTLC_set_channel_id(uint32_t this_ptr, int8_tArray val) {
9711         LDKUpdateAddHTLC this_ptr_conv;
9712         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9713         this_ptr_conv.is_owned = false;
9714         LDKThirtyTwoBytes val_ref;
9715         CHECK(*((uint32_t*)val) == 32);
9716         memcpy(val_ref.data, (uint8_t*)(val + 4), 32);
9717         UpdateAddHTLC_set_channel_id(&this_ptr_conv, val_ref);
9718 }
9719
9720 int64_t  __attribute__((visibility("default"))) TS_UpdateAddHTLC_get_htlc_id(uint32_t this_ptr) {
9721         LDKUpdateAddHTLC this_ptr_conv;
9722         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9723         this_ptr_conv.is_owned = false;
9724         int64_t ret_val = UpdateAddHTLC_get_htlc_id(&this_ptr_conv);
9725         return ret_val;
9726 }
9727
9728 void  __attribute__((visibility("default"))) TS_UpdateAddHTLC_set_htlc_id(uint32_t this_ptr, int64_t val) {
9729         LDKUpdateAddHTLC this_ptr_conv;
9730         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9731         this_ptr_conv.is_owned = false;
9732         UpdateAddHTLC_set_htlc_id(&this_ptr_conv, val);
9733 }
9734
9735 int64_t  __attribute__((visibility("default"))) TS_UpdateAddHTLC_get_amount_msat(uint32_t this_ptr) {
9736         LDKUpdateAddHTLC this_ptr_conv;
9737         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9738         this_ptr_conv.is_owned = false;
9739         int64_t ret_val = UpdateAddHTLC_get_amount_msat(&this_ptr_conv);
9740         return ret_val;
9741 }
9742
9743 void  __attribute__((visibility("default"))) TS_UpdateAddHTLC_set_amount_msat(uint32_t this_ptr, int64_t val) {
9744         LDKUpdateAddHTLC this_ptr_conv;
9745         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9746         this_ptr_conv.is_owned = false;
9747         UpdateAddHTLC_set_amount_msat(&this_ptr_conv, val);
9748 }
9749
9750 int8_tArray  __attribute__((visibility("default"))) TS_UpdateAddHTLC_get_payment_hash(uint32_t this_ptr) {
9751         LDKUpdateAddHTLC this_ptr_conv;
9752         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9753         this_ptr_conv.is_owned = false;
9754         int8_tArray ret_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
9755         memcpy((uint8_t*)(ret_arr + 4), *UpdateAddHTLC_get_payment_hash(&this_ptr_conv), 32);
9756         return ret_arr;
9757 }
9758
9759 void  __attribute__((visibility("default"))) TS_UpdateAddHTLC_set_payment_hash(uint32_t this_ptr, int8_tArray val) {
9760         LDKUpdateAddHTLC this_ptr_conv;
9761         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9762         this_ptr_conv.is_owned = false;
9763         LDKThirtyTwoBytes val_ref;
9764         CHECK(*((uint32_t*)val) == 32);
9765         memcpy(val_ref.data, (uint8_t*)(val + 4), 32);
9766         UpdateAddHTLC_set_payment_hash(&this_ptr_conv, val_ref);
9767 }
9768
9769 int32_t  __attribute__((visibility("default"))) TS_UpdateAddHTLC_get_cltv_expiry(uint32_t this_ptr) {
9770         LDKUpdateAddHTLC this_ptr_conv;
9771         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9772         this_ptr_conv.is_owned = false;
9773         int32_t ret_val = UpdateAddHTLC_get_cltv_expiry(&this_ptr_conv);
9774         return ret_val;
9775 }
9776
9777 void  __attribute__((visibility("default"))) TS_UpdateAddHTLC_set_cltv_expiry(uint32_t this_ptr, int32_t val) {
9778         LDKUpdateAddHTLC this_ptr_conv;
9779         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9780         this_ptr_conv.is_owned = false;
9781         UpdateAddHTLC_set_cltv_expiry(&this_ptr_conv, val);
9782 }
9783
9784 void  __attribute__((visibility("default"))) TS_UpdateFulfillHTLC_free(uint32_t this_ptr) {
9785         LDKUpdateFulfillHTLC this_ptr_conv;
9786         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9787         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9788         UpdateFulfillHTLC_free(this_ptr_conv);
9789 }
9790
9791 uint32_t  __attribute__((visibility("default"))) TS_UpdateFulfillHTLC_clone(uint32_t orig) {
9792         LDKUpdateFulfillHTLC orig_conv;
9793         orig_conv.inner = (void*)(orig & (~1));
9794         orig_conv.is_owned = false;
9795         LDKUpdateFulfillHTLC ret_var = UpdateFulfillHTLC_clone(&orig_conv);
9796         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9797         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9798         long ret_ref = (long)ret_var.inner;
9799         if (ret_var.is_owned) {
9800                 ret_ref |= 1;
9801         }
9802         return ret_ref;
9803 }
9804
9805 int8_tArray  __attribute__((visibility("default"))) TS_UpdateFulfillHTLC_get_channel_id(uint32_t this_ptr) {
9806         LDKUpdateFulfillHTLC this_ptr_conv;
9807         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9808         this_ptr_conv.is_owned = false;
9809         int8_tArray ret_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
9810         memcpy((uint8_t*)(ret_arr + 4), *UpdateFulfillHTLC_get_channel_id(&this_ptr_conv), 32);
9811         return ret_arr;
9812 }
9813
9814 void  __attribute__((visibility("default"))) TS_UpdateFulfillHTLC_set_channel_id(uint32_t this_ptr, int8_tArray val) {
9815         LDKUpdateFulfillHTLC this_ptr_conv;
9816         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9817         this_ptr_conv.is_owned = false;
9818         LDKThirtyTwoBytes val_ref;
9819         CHECK(*((uint32_t*)val) == 32);
9820         memcpy(val_ref.data, (uint8_t*)(val + 4), 32);
9821         UpdateFulfillHTLC_set_channel_id(&this_ptr_conv, val_ref);
9822 }
9823
9824 int64_t  __attribute__((visibility("default"))) TS_UpdateFulfillHTLC_get_htlc_id(uint32_t this_ptr) {
9825         LDKUpdateFulfillHTLC this_ptr_conv;
9826         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9827         this_ptr_conv.is_owned = false;
9828         int64_t ret_val = UpdateFulfillHTLC_get_htlc_id(&this_ptr_conv);
9829         return ret_val;
9830 }
9831
9832 void  __attribute__((visibility("default"))) TS_UpdateFulfillHTLC_set_htlc_id(uint32_t this_ptr, int64_t val) {
9833         LDKUpdateFulfillHTLC this_ptr_conv;
9834         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9835         this_ptr_conv.is_owned = false;
9836         UpdateFulfillHTLC_set_htlc_id(&this_ptr_conv, val);
9837 }
9838
9839 int8_tArray  __attribute__((visibility("default"))) TS_UpdateFulfillHTLC_get_payment_preimage(uint32_t this_ptr) {
9840         LDKUpdateFulfillHTLC this_ptr_conv;
9841         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9842         this_ptr_conv.is_owned = false;
9843         int8_tArray ret_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
9844         memcpy((uint8_t*)(ret_arr + 4), *UpdateFulfillHTLC_get_payment_preimage(&this_ptr_conv), 32);
9845         return ret_arr;
9846 }
9847
9848 void  __attribute__((visibility("default"))) TS_UpdateFulfillHTLC_set_payment_preimage(uint32_t this_ptr, int8_tArray val) {
9849         LDKUpdateFulfillHTLC this_ptr_conv;
9850         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9851         this_ptr_conv.is_owned = false;
9852         LDKThirtyTwoBytes val_ref;
9853         CHECK(*((uint32_t*)val) == 32);
9854         memcpy(val_ref.data, (uint8_t*)(val + 4), 32);
9855         UpdateFulfillHTLC_set_payment_preimage(&this_ptr_conv, val_ref);
9856 }
9857
9858 uint32_t  __attribute__((visibility("default"))) TS_UpdateFulfillHTLC_new(int8_tArray channel_id_arg, int64_t htlc_id_arg, int8_tArray payment_preimage_arg) {
9859         LDKThirtyTwoBytes channel_id_arg_ref;
9860         CHECK(*((uint32_t*)channel_id_arg) == 32);
9861         memcpy(channel_id_arg_ref.data, (uint8_t*)(channel_id_arg + 4), 32);
9862         LDKThirtyTwoBytes payment_preimage_arg_ref;
9863         CHECK(*((uint32_t*)payment_preimage_arg) == 32);
9864         memcpy(payment_preimage_arg_ref.data, (uint8_t*)(payment_preimage_arg + 4), 32);
9865         LDKUpdateFulfillHTLC ret_var = UpdateFulfillHTLC_new(channel_id_arg_ref, htlc_id_arg, payment_preimage_arg_ref);
9866         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9867         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9868         long ret_ref = (long)ret_var.inner;
9869         if (ret_var.is_owned) {
9870                 ret_ref |= 1;
9871         }
9872         return ret_ref;
9873 }
9874
9875 void  __attribute__((visibility("default"))) TS_UpdateFailHTLC_free(uint32_t this_ptr) {
9876         LDKUpdateFailHTLC this_ptr_conv;
9877         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9878         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9879         UpdateFailHTLC_free(this_ptr_conv);
9880 }
9881
9882 uint32_t  __attribute__((visibility("default"))) TS_UpdateFailHTLC_clone(uint32_t orig) {
9883         LDKUpdateFailHTLC orig_conv;
9884         orig_conv.inner = (void*)(orig & (~1));
9885         orig_conv.is_owned = false;
9886         LDKUpdateFailHTLC ret_var = UpdateFailHTLC_clone(&orig_conv);
9887         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9888         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9889         long ret_ref = (long)ret_var.inner;
9890         if (ret_var.is_owned) {
9891                 ret_ref |= 1;
9892         }
9893         return ret_ref;
9894 }
9895
9896 int8_tArray  __attribute__((visibility("default"))) TS_UpdateFailHTLC_get_channel_id(uint32_t this_ptr) {
9897         LDKUpdateFailHTLC this_ptr_conv;
9898         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9899         this_ptr_conv.is_owned = false;
9900         int8_tArray ret_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
9901         memcpy((uint8_t*)(ret_arr + 4), *UpdateFailHTLC_get_channel_id(&this_ptr_conv), 32);
9902         return ret_arr;
9903 }
9904
9905 void  __attribute__((visibility("default"))) TS_UpdateFailHTLC_set_channel_id(uint32_t this_ptr, int8_tArray val) {
9906         LDKUpdateFailHTLC this_ptr_conv;
9907         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9908         this_ptr_conv.is_owned = false;
9909         LDKThirtyTwoBytes val_ref;
9910         CHECK(*((uint32_t*)val) == 32);
9911         memcpy(val_ref.data, (uint8_t*)(val + 4), 32);
9912         UpdateFailHTLC_set_channel_id(&this_ptr_conv, val_ref);
9913 }
9914
9915 int64_t  __attribute__((visibility("default"))) TS_UpdateFailHTLC_get_htlc_id(uint32_t this_ptr) {
9916         LDKUpdateFailHTLC this_ptr_conv;
9917         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9918         this_ptr_conv.is_owned = false;
9919         int64_t ret_val = UpdateFailHTLC_get_htlc_id(&this_ptr_conv);
9920         return ret_val;
9921 }
9922
9923 void  __attribute__((visibility("default"))) TS_UpdateFailHTLC_set_htlc_id(uint32_t this_ptr, int64_t val) {
9924         LDKUpdateFailHTLC this_ptr_conv;
9925         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9926         this_ptr_conv.is_owned = false;
9927         UpdateFailHTLC_set_htlc_id(&this_ptr_conv, val);
9928 }
9929
9930 void  __attribute__((visibility("default"))) TS_UpdateFailMalformedHTLC_free(uint32_t this_ptr) {
9931         LDKUpdateFailMalformedHTLC this_ptr_conv;
9932         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9933         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9934         UpdateFailMalformedHTLC_free(this_ptr_conv);
9935 }
9936
9937 uint32_t  __attribute__((visibility("default"))) TS_UpdateFailMalformedHTLC_clone(uint32_t orig) {
9938         LDKUpdateFailMalformedHTLC orig_conv;
9939         orig_conv.inner = (void*)(orig & (~1));
9940         orig_conv.is_owned = false;
9941         LDKUpdateFailMalformedHTLC ret_var = UpdateFailMalformedHTLC_clone(&orig_conv);
9942         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9943         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9944         long ret_ref = (long)ret_var.inner;
9945         if (ret_var.is_owned) {
9946                 ret_ref |= 1;
9947         }
9948         return ret_ref;
9949 }
9950
9951 int8_tArray  __attribute__((visibility("default"))) TS_UpdateFailMalformedHTLC_get_channel_id(uint32_t this_ptr) {
9952         LDKUpdateFailMalformedHTLC this_ptr_conv;
9953         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9954         this_ptr_conv.is_owned = false;
9955         int8_tArray ret_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
9956         memcpy((uint8_t*)(ret_arr + 4), *UpdateFailMalformedHTLC_get_channel_id(&this_ptr_conv), 32);
9957         return ret_arr;
9958 }
9959
9960 void  __attribute__((visibility("default"))) TS_UpdateFailMalformedHTLC_set_channel_id(uint32_t this_ptr, int8_tArray val) {
9961         LDKUpdateFailMalformedHTLC this_ptr_conv;
9962         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9963         this_ptr_conv.is_owned = false;
9964         LDKThirtyTwoBytes val_ref;
9965         CHECK(*((uint32_t*)val) == 32);
9966         memcpy(val_ref.data, (uint8_t*)(val + 4), 32);
9967         UpdateFailMalformedHTLC_set_channel_id(&this_ptr_conv, val_ref);
9968 }
9969
9970 int64_t  __attribute__((visibility("default"))) TS_UpdateFailMalformedHTLC_get_htlc_id(uint32_t this_ptr) {
9971         LDKUpdateFailMalformedHTLC this_ptr_conv;
9972         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9973         this_ptr_conv.is_owned = false;
9974         int64_t ret_val = UpdateFailMalformedHTLC_get_htlc_id(&this_ptr_conv);
9975         return ret_val;
9976 }
9977
9978 void  __attribute__((visibility("default"))) TS_UpdateFailMalformedHTLC_set_htlc_id(uint32_t this_ptr, int64_t val) {
9979         LDKUpdateFailMalformedHTLC this_ptr_conv;
9980         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9981         this_ptr_conv.is_owned = false;
9982         UpdateFailMalformedHTLC_set_htlc_id(&this_ptr_conv, val);
9983 }
9984
9985 int16_t  __attribute__((visibility("default"))) TS_UpdateFailMalformedHTLC_get_failure_code(uint32_t this_ptr) {
9986         LDKUpdateFailMalformedHTLC this_ptr_conv;
9987         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9988         this_ptr_conv.is_owned = false;
9989         int16_t ret_val = UpdateFailMalformedHTLC_get_failure_code(&this_ptr_conv);
9990         return ret_val;
9991 }
9992
9993 void  __attribute__((visibility("default"))) TS_UpdateFailMalformedHTLC_set_failure_code(uint32_t this_ptr, int16_t val) {
9994         LDKUpdateFailMalformedHTLC this_ptr_conv;
9995         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9996         this_ptr_conv.is_owned = false;
9997         UpdateFailMalformedHTLC_set_failure_code(&this_ptr_conv, val);
9998 }
9999
10000 void  __attribute__((visibility("default"))) TS_CommitmentSigned_free(uint32_t this_ptr) {
10001         LDKCommitmentSigned this_ptr_conv;
10002         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10003         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10004         CommitmentSigned_free(this_ptr_conv);
10005 }
10006
10007 uint32_t  __attribute__((visibility("default"))) TS_CommitmentSigned_clone(uint32_t orig) {
10008         LDKCommitmentSigned orig_conv;
10009         orig_conv.inner = (void*)(orig & (~1));
10010         orig_conv.is_owned = false;
10011         LDKCommitmentSigned ret_var = CommitmentSigned_clone(&orig_conv);
10012         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10013         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10014         long ret_ref = (long)ret_var.inner;
10015         if (ret_var.is_owned) {
10016                 ret_ref |= 1;
10017         }
10018         return ret_ref;
10019 }
10020
10021 int8_tArray  __attribute__((visibility("default"))) TS_CommitmentSigned_get_channel_id(uint32_t this_ptr) {
10022         LDKCommitmentSigned this_ptr_conv;
10023         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10024         this_ptr_conv.is_owned = false;
10025         int8_tArray ret_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
10026         memcpy((uint8_t*)(ret_arr + 4), *CommitmentSigned_get_channel_id(&this_ptr_conv), 32);
10027         return ret_arr;
10028 }
10029
10030 void  __attribute__((visibility("default"))) TS_CommitmentSigned_set_channel_id(uint32_t this_ptr, int8_tArray val) {
10031         LDKCommitmentSigned this_ptr_conv;
10032         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10033         this_ptr_conv.is_owned = false;
10034         LDKThirtyTwoBytes val_ref;
10035         CHECK(*((uint32_t*)val) == 32);
10036         memcpy(val_ref.data, (uint8_t*)(val + 4), 32);
10037         CommitmentSigned_set_channel_id(&this_ptr_conv, val_ref);
10038 }
10039
10040 int8_tArray  __attribute__((visibility("default"))) TS_CommitmentSigned_get_signature(uint32_t this_ptr) {
10041         LDKCommitmentSigned this_ptr_conv;
10042         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10043         this_ptr_conv.is_owned = false;
10044         int8_tArray arg_arr = init_arr(64, sizeof(uint8_t), "Native int8_tArray Bytes");
10045         memcpy((uint8_t*)(arg_arr + 4), CommitmentSigned_get_signature(&this_ptr_conv).compact_form, 64);
10046         return arg_arr;
10047 }
10048
10049 void  __attribute__((visibility("default"))) TS_CommitmentSigned_set_signature(uint32_t this_ptr, int8_tArray val) {
10050         LDKCommitmentSigned this_ptr_conv;
10051         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10052         this_ptr_conv.is_owned = false;
10053         LDKSignature val_ref;
10054         CHECK(*((uint32_t*)val) == 64);
10055         memcpy(val_ref.compact_form, (uint8_t*)(val + 4), 64);
10056         CommitmentSigned_set_signature(&this_ptr_conv, val_ref);
10057 }
10058
10059 void  __attribute__((visibility("default"))) TS_CommitmentSigned_set_htlc_signatures(uint32_t this_ptr, ptrArray val) {
10060         LDKCommitmentSigned this_ptr_conv;
10061         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10062         this_ptr_conv.is_owned = false;
10063         LDKCVec_SignatureZ val_constr;
10064         val_constr.datalen = *((uint32_t*)val);
10065         if (val_constr.datalen > 0)
10066                 val_constr.data = MALLOC(val_constr.datalen * sizeof(LDKSignature), "LDKCVec_SignatureZ Elements");
10067         else
10068                 val_constr.data = NULL;
10069         int8_tArray* val_vals = (int8_tArray*)(val + 4);
10070         for (size_t m = 0; m < val_constr.datalen; m++) {
10071                 int8_tArray arr_conv_12 = val_vals[m];
10072                 LDKSignature arr_conv_12_ref;
10073                 CHECK(*((uint32_t*)arr_conv_12) == 64);
10074                 memcpy(arr_conv_12_ref.compact_form, (uint8_t*)(arr_conv_12 + 4), 64);
10075                 val_constr.data[m] = arr_conv_12_ref;
10076         }
10077         CommitmentSigned_set_htlc_signatures(&this_ptr_conv, val_constr);
10078 }
10079
10080 uint32_t  __attribute__((visibility("default"))) TS_CommitmentSigned_new(int8_tArray channel_id_arg, int8_tArray signature_arg, ptrArray htlc_signatures_arg) {
10081         LDKThirtyTwoBytes channel_id_arg_ref;
10082         CHECK(*((uint32_t*)channel_id_arg) == 32);
10083         memcpy(channel_id_arg_ref.data, (uint8_t*)(channel_id_arg + 4), 32);
10084         LDKSignature signature_arg_ref;
10085         CHECK(*((uint32_t*)signature_arg) == 64);
10086         memcpy(signature_arg_ref.compact_form, (uint8_t*)(signature_arg + 4), 64);
10087         LDKCVec_SignatureZ htlc_signatures_arg_constr;
10088         htlc_signatures_arg_constr.datalen = *((uint32_t*)htlc_signatures_arg);
10089         if (htlc_signatures_arg_constr.datalen > 0)
10090                 htlc_signatures_arg_constr.data = MALLOC(htlc_signatures_arg_constr.datalen * sizeof(LDKSignature), "LDKCVec_SignatureZ Elements");
10091         else
10092                 htlc_signatures_arg_constr.data = NULL;
10093         int8_tArray* htlc_signatures_arg_vals = (int8_tArray*)(htlc_signatures_arg + 4);
10094         for (size_t m = 0; m < htlc_signatures_arg_constr.datalen; m++) {
10095                 int8_tArray arr_conv_12 = htlc_signatures_arg_vals[m];
10096                 LDKSignature arr_conv_12_ref;
10097                 CHECK(*((uint32_t*)arr_conv_12) == 64);
10098                 memcpy(arr_conv_12_ref.compact_form, (uint8_t*)(arr_conv_12 + 4), 64);
10099                 htlc_signatures_arg_constr.data[m] = arr_conv_12_ref;
10100         }
10101         LDKCommitmentSigned ret_var = CommitmentSigned_new(channel_id_arg_ref, signature_arg_ref, htlc_signatures_arg_constr);
10102         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10103         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10104         long ret_ref = (long)ret_var.inner;
10105         if (ret_var.is_owned) {
10106                 ret_ref |= 1;
10107         }
10108         return ret_ref;
10109 }
10110
10111 void  __attribute__((visibility("default"))) TS_RevokeAndACK_free(uint32_t this_ptr) {
10112         LDKRevokeAndACK this_ptr_conv;
10113         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10114         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10115         RevokeAndACK_free(this_ptr_conv);
10116 }
10117
10118 uint32_t  __attribute__((visibility("default"))) TS_RevokeAndACK_clone(uint32_t orig) {
10119         LDKRevokeAndACK orig_conv;
10120         orig_conv.inner = (void*)(orig & (~1));
10121         orig_conv.is_owned = false;
10122         LDKRevokeAndACK ret_var = RevokeAndACK_clone(&orig_conv);
10123         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10124         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10125         long ret_ref = (long)ret_var.inner;
10126         if (ret_var.is_owned) {
10127                 ret_ref |= 1;
10128         }
10129         return ret_ref;
10130 }
10131
10132 int8_tArray  __attribute__((visibility("default"))) TS_RevokeAndACK_get_channel_id(uint32_t this_ptr) {
10133         LDKRevokeAndACK this_ptr_conv;
10134         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10135         this_ptr_conv.is_owned = false;
10136         int8_tArray ret_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
10137         memcpy((uint8_t*)(ret_arr + 4), *RevokeAndACK_get_channel_id(&this_ptr_conv), 32);
10138         return ret_arr;
10139 }
10140
10141 void  __attribute__((visibility("default"))) TS_RevokeAndACK_set_channel_id(uint32_t this_ptr, int8_tArray val) {
10142         LDKRevokeAndACK this_ptr_conv;
10143         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10144         this_ptr_conv.is_owned = false;
10145         LDKThirtyTwoBytes val_ref;
10146         CHECK(*((uint32_t*)val) == 32);
10147         memcpy(val_ref.data, (uint8_t*)(val + 4), 32);
10148         RevokeAndACK_set_channel_id(&this_ptr_conv, val_ref);
10149 }
10150
10151 int8_tArray  __attribute__((visibility("default"))) TS_RevokeAndACK_get_per_commitment_secret(uint32_t this_ptr) {
10152         LDKRevokeAndACK this_ptr_conv;
10153         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10154         this_ptr_conv.is_owned = false;
10155         int8_tArray ret_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
10156         memcpy((uint8_t*)(ret_arr + 4), *RevokeAndACK_get_per_commitment_secret(&this_ptr_conv), 32);
10157         return ret_arr;
10158 }
10159
10160 void  __attribute__((visibility("default"))) TS_RevokeAndACK_set_per_commitment_secret(uint32_t this_ptr, int8_tArray val) {
10161         LDKRevokeAndACK this_ptr_conv;
10162         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10163         this_ptr_conv.is_owned = false;
10164         LDKThirtyTwoBytes val_ref;
10165         CHECK(*((uint32_t*)val) == 32);
10166         memcpy(val_ref.data, (uint8_t*)(val + 4), 32);
10167         RevokeAndACK_set_per_commitment_secret(&this_ptr_conv, val_ref);
10168 }
10169
10170 int8_tArray  __attribute__((visibility("default"))) TS_RevokeAndACK_get_next_per_commitment_point(uint32_t this_ptr) {
10171         LDKRevokeAndACK this_ptr_conv;
10172         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10173         this_ptr_conv.is_owned = false;
10174         int8_tArray arg_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
10175         memcpy((uint8_t*)(arg_arr + 4), RevokeAndACK_get_next_per_commitment_point(&this_ptr_conv).compressed_form, 33);
10176         return arg_arr;
10177 }
10178
10179 void  __attribute__((visibility("default"))) TS_RevokeAndACK_set_next_per_commitment_point(uint32_t this_ptr, int8_tArray val) {
10180         LDKRevokeAndACK this_ptr_conv;
10181         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10182         this_ptr_conv.is_owned = false;
10183         LDKPublicKey val_ref;
10184         CHECK(*((uint32_t*)val) == 33);
10185         memcpy(val_ref.compressed_form, (uint8_t*)(val + 4), 33);
10186         RevokeAndACK_set_next_per_commitment_point(&this_ptr_conv, val_ref);
10187 }
10188
10189 uint32_t  __attribute__((visibility("default"))) TS_RevokeAndACK_new(int8_tArray channel_id_arg, int8_tArray per_commitment_secret_arg, int8_tArray next_per_commitment_point_arg) {
10190         LDKThirtyTwoBytes channel_id_arg_ref;
10191         CHECK(*((uint32_t*)channel_id_arg) == 32);
10192         memcpy(channel_id_arg_ref.data, (uint8_t*)(channel_id_arg + 4), 32);
10193         LDKThirtyTwoBytes per_commitment_secret_arg_ref;
10194         CHECK(*((uint32_t*)per_commitment_secret_arg) == 32);
10195         memcpy(per_commitment_secret_arg_ref.data, (uint8_t*)(per_commitment_secret_arg + 4), 32);
10196         LDKPublicKey next_per_commitment_point_arg_ref;
10197         CHECK(*((uint32_t*)next_per_commitment_point_arg) == 33);
10198         memcpy(next_per_commitment_point_arg_ref.compressed_form, (uint8_t*)(next_per_commitment_point_arg + 4), 33);
10199         LDKRevokeAndACK ret_var = RevokeAndACK_new(channel_id_arg_ref, per_commitment_secret_arg_ref, next_per_commitment_point_arg_ref);
10200         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10201         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10202         long ret_ref = (long)ret_var.inner;
10203         if (ret_var.is_owned) {
10204                 ret_ref |= 1;
10205         }
10206         return ret_ref;
10207 }
10208
10209 void  __attribute__((visibility("default"))) TS_UpdateFee_free(uint32_t this_ptr) {
10210         LDKUpdateFee this_ptr_conv;
10211         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10212         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10213         UpdateFee_free(this_ptr_conv);
10214 }
10215
10216 uint32_t  __attribute__((visibility("default"))) TS_UpdateFee_clone(uint32_t orig) {
10217         LDKUpdateFee orig_conv;
10218         orig_conv.inner = (void*)(orig & (~1));
10219         orig_conv.is_owned = false;
10220         LDKUpdateFee ret_var = UpdateFee_clone(&orig_conv);
10221         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10222         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10223         long ret_ref = (long)ret_var.inner;
10224         if (ret_var.is_owned) {
10225                 ret_ref |= 1;
10226         }
10227         return ret_ref;
10228 }
10229
10230 int8_tArray  __attribute__((visibility("default"))) TS_UpdateFee_get_channel_id(uint32_t this_ptr) {
10231         LDKUpdateFee this_ptr_conv;
10232         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10233         this_ptr_conv.is_owned = false;
10234         int8_tArray ret_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
10235         memcpy((uint8_t*)(ret_arr + 4), *UpdateFee_get_channel_id(&this_ptr_conv), 32);
10236         return ret_arr;
10237 }
10238
10239 void  __attribute__((visibility("default"))) TS_UpdateFee_set_channel_id(uint32_t this_ptr, int8_tArray val) {
10240         LDKUpdateFee this_ptr_conv;
10241         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10242         this_ptr_conv.is_owned = false;
10243         LDKThirtyTwoBytes val_ref;
10244         CHECK(*((uint32_t*)val) == 32);
10245         memcpy(val_ref.data, (uint8_t*)(val + 4), 32);
10246         UpdateFee_set_channel_id(&this_ptr_conv, val_ref);
10247 }
10248
10249 int32_t  __attribute__((visibility("default"))) TS_UpdateFee_get_feerate_per_kw(uint32_t this_ptr) {
10250         LDKUpdateFee this_ptr_conv;
10251         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10252         this_ptr_conv.is_owned = false;
10253         int32_t ret_val = UpdateFee_get_feerate_per_kw(&this_ptr_conv);
10254         return ret_val;
10255 }
10256
10257 void  __attribute__((visibility("default"))) TS_UpdateFee_set_feerate_per_kw(uint32_t this_ptr, int32_t val) {
10258         LDKUpdateFee this_ptr_conv;
10259         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10260         this_ptr_conv.is_owned = false;
10261         UpdateFee_set_feerate_per_kw(&this_ptr_conv, val);
10262 }
10263
10264 uint32_t  __attribute__((visibility("default"))) TS_UpdateFee_new(int8_tArray channel_id_arg, int32_t feerate_per_kw_arg) {
10265         LDKThirtyTwoBytes channel_id_arg_ref;
10266         CHECK(*((uint32_t*)channel_id_arg) == 32);
10267         memcpy(channel_id_arg_ref.data, (uint8_t*)(channel_id_arg + 4), 32);
10268         LDKUpdateFee ret_var = UpdateFee_new(channel_id_arg_ref, feerate_per_kw_arg);
10269         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10270         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10271         long ret_ref = (long)ret_var.inner;
10272         if (ret_var.is_owned) {
10273                 ret_ref |= 1;
10274         }
10275         return ret_ref;
10276 }
10277
10278 void  __attribute__((visibility("default"))) TS_DataLossProtect_free(uint32_t this_ptr) {
10279         LDKDataLossProtect this_ptr_conv;
10280         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10281         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10282         DataLossProtect_free(this_ptr_conv);
10283 }
10284
10285 uint32_t  __attribute__((visibility("default"))) TS_DataLossProtect_clone(uint32_t orig) {
10286         LDKDataLossProtect orig_conv;
10287         orig_conv.inner = (void*)(orig & (~1));
10288         orig_conv.is_owned = false;
10289         LDKDataLossProtect ret_var = DataLossProtect_clone(&orig_conv);
10290         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10291         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10292         long ret_ref = (long)ret_var.inner;
10293         if (ret_var.is_owned) {
10294                 ret_ref |= 1;
10295         }
10296         return ret_ref;
10297 }
10298
10299 int8_tArray  __attribute__((visibility("default"))) TS_DataLossProtect_get_your_last_per_commitment_secret(uint32_t this_ptr) {
10300         LDKDataLossProtect this_ptr_conv;
10301         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10302         this_ptr_conv.is_owned = false;
10303         int8_tArray ret_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
10304         memcpy((uint8_t*)(ret_arr + 4), *DataLossProtect_get_your_last_per_commitment_secret(&this_ptr_conv), 32);
10305         return ret_arr;
10306 }
10307
10308 void  __attribute__((visibility("default"))) TS_DataLossProtect_set_your_last_per_commitment_secret(uint32_t this_ptr, int8_tArray val) {
10309         LDKDataLossProtect this_ptr_conv;
10310         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10311         this_ptr_conv.is_owned = false;
10312         LDKThirtyTwoBytes val_ref;
10313         CHECK(*((uint32_t*)val) == 32);
10314         memcpy(val_ref.data, (uint8_t*)(val + 4), 32);
10315         DataLossProtect_set_your_last_per_commitment_secret(&this_ptr_conv, val_ref);
10316 }
10317
10318 int8_tArray  __attribute__((visibility("default"))) TS_DataLossProtect_get_my_current_per_commitment_point(uint32_t this_ptr) {
10319         LDKDataLossProtect this_ptr_conv;
10320         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10321         this_ptr_conv.is_owned = false;
10322         int8_tArray arg_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
10323         memcpy((uint8_t*)(arg_arr + 4), DataLossProtect_get_my_current_per_commitment_point(&this_ptr_conv).compressed_form, 33);
10324         return arg_arr;
10325 }
10326
10327 void  __attribute__((visibility("default"))) TS_DataLossProtect_set_my_current_per_commitment_point(uint32_t this_ptr, int8_tArray val) {
10328         LDKDataLossProtect this_ptr_conv;
10329         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10330         this_ptr_conv.is_owned = false;
10331         LDKPublicKey val_ref;
10332         CHECK(*((uint32_t*)val) == 33);
10333         memcpy(val_ref.compressed_form, (uint8_t*)(val + 4), 33);
10334         DataLossProtect_set_my_current_per_commitment_point(&this_ptr_conv, val_ref);
10335 }
10336
10337 uint32_t  __attribute__((visibility("default"))) TS_DataLossProtect_new(int8_tArray your_last_per_commitment_secret_arg, int8_tArray my_current_per_commitment_point_arg) {
10338         LDKThirtyTwoBytes your_last_per_commitment_secret_arg_ref;
10339         CHECK(*((uint32_t*)your_last_per_commitment_secret_arg) == 32);
10340         memcpy(your_last_per_commitment_secret_arg_ref.data, (uint8_t*)(your_last_per_commitment_secret_arg + 4), 32);
10341         LDKPublicKey my_current_per_commitment_point_arg_ref;
10342         CHECK(*((uint32_t*)my_current_per_commitment_point_arg) == 33);
10343         memcpy(my_current_per_commitment_point_arg_ref.compressed_form, (uint8_t*)(my_current_per_commitment_point_arg + 4), 33);
10344         LDKDataLossProtect ret_var = DataLossProtect_new(your_last_per_commitment_secret_arg_ref, my_current_per_commitment_point_arg_ref);
10345         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10346         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10347         long ret_ref = (long)ret_var.inner;
10348         if (ret_var.is_owned) {
10349                 ret_ref |= 1;
10350         }
10351         return ret_ref;
10352 }
10353
10354 void  __attribute__((visibility("default"))) TS_ChannelReestablish_free(uint32_t this_ptr) {
10355         LDKChannelReestablish this_ptr_conv;
10356         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10357         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10358         ChannelReestablish_free(this_ptr_conv);
10359 }
10360
10361 uint32_t  __attribute__((visibility("default"))) TS_ChannelReestablish_clone(uint32_t orig) {
10362         LDKChannelReestablish orig_conv;
10363         orig_conv.inner = (void*)(orig & (~1));
10364         orig_conv.is_owned = false;
10365         LDKChannelReestablish ret_var = ChannelReestablish_clone(&orig_conv);
10366         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10367         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10368         long ret_ref = (long)ret_var.inner;
10369         if (ret_var.is_owned) {
10370                 ret_ref |= 1;
10371         }
10372         return ret_ref;
10373 }
10374
10375 int8_tArray  __attribute__((visibility("default"))) TS_ChannelReestablish_get_channel_id(uint32_t this_ptr) {
10376         LDKChannelReestablish this_ptr_conv;
10377         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10378         this_ptr_conv.is_owned = false;
10379         int8_tArray ret_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
10380         memcpy((uint8_t*)(ret_arr + 4), *ChannelReestablish_get_channel_id(&this_ptr_conv), 32);
10381         return ret_arr;
10382 }
10383
10384 void  __attribute__((visibility("default"))) TS_ChannelReestablish_set_channel_id(uint32_t this_ptr, int8_tArray val) {
10385         LDKChannelReestablish this_ptr_conv;
10386         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10387         this_ptr_conv.is_owned = false;
10388         LDKThirtyTwoBytes val_ref;
10389         CHECK(*((uint32_t*)val) == 32);
10390         memcpy(val_ref.data, (uint8_t*)(val + 4), 32);
10391         ChannelReestablish_set_channel_id(&this_ptr_conv, val_ref);
10392 }
10393
10394 int64_t  __attribute__((visibility("default"))) TS_ChannelReestablish_get_next_local_commitment_number(uint32_t this_ptr) {
10395         LDKChannelReestablish this_ptr_conv;
10396         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10397         this_ptr_conv.is_owned = false;
10398         int64_t ret_val = ChannelReestablish_get_next_local_commitment_number(&this_ptr_conv);
10399         return ret_val;
10400 }
10401
10402 void  __attribute__((visibility("default"))) TS_ChannelReestablish_set_next_local_commitment_number(uint32_t this_ptr, int64_t val) {
10403         LDKChannelReestablish this_ptr_conv;
10404         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10405         this_ptr_conv.is_owned = false;
10406         ChannelReestablish_set_next_local_commitment_number(&this_ptr_conv, val);
10407 }
10408
10409 int64_t  __attribute__((visibility("default"))) TS_ChannelReestablish_get_next_remote_commitment_number(uint32_t this_ptr) {
10410         LDKChannelReestablish this_ptr_conv;
10411         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10412         this_ptr_conv.is_owned = false;
10413         int64_t ret_val = ChannelReestablish_get_next_remote_commitment_number(&this_ptr_conv);
10414         return ret_val;
10415 }
10416
10417 void  __attribute__((visibility("default"))) TS_ChannelReestablish_set_next_remote_commitment_number(uint32_t this_ptr, int64_t val) {
10418         LDKChannelReestablish this_ptr_conv;
10419         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10420         this_ptr_conv.is_owned = false;
10421         ChannelReestablish_set_next_remote_commitment_number(&this_ptr_conv, val);
10422 }
10423
10424 void  __attribute__((visibility("default"))) TS_AnnouncementSignatures_free(uint32_t this_ptr) {
10425         LDKAnnouncementSignatures this_ptr_conv;
10426         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10427         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10428         AnnouncementSignatures_free(this_ptr_conv);
10429 }
10430
10431 uint32_t  __attribute__((visibility("default"))) TS_AnnouncementSignatures_clone(uint32_t orig) {
10432         LDKAnnouncementSignatures orig_conv;
10433         orig_conv.inner = (void*)(orig & (~1));
10434         orig_conv.is_owned = false;
10435         LDKAnnouncementSignatures ret_var = AnnouncementSignatures_clone(&orig_conv);
10436         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10437         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10438         long ret_ref = (long)ret_var.inner;
10439         if (ret_var.is_owned) {
10440                 ret_ref |= 1;
10441         }
10442         return ret_ref;
10443 }
10444
10445 int8_tArray  __attribute__((visibility("default"))) TS_AnnouncementSignatures_get_channel_id(uint32_t this_ptr) {
10446         LDKAnnouncementSignatures this_ptr_conv;
10447         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10448         this_ptr_conv.is_owned = false;
10449         int8_tArray ret_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
10450         memcpy((uint8_t*)(ret_arr + 4), *AnnouncementSignatures_get_channel_id(&this_ptr_conv), 32);
10451         return ret_arr;
10452 }
10453
10454 void  __attribute__((visibility("default"))) TS_AnnouncementSignatures_set_channel_id(uint32_t this_ptr, int8_tArray val) {
10455         LDKAnnouncementSignatures this_ptr_conv;
10456         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10457         this_ptr_conv.is_owned = false;
10458         LDKThirtyTwoBytes val_ref;
10459         CHECK(*((uint32_t*)val) == 32);
10460         memcpy(val_ref.data, (uint8_t*)(val + 4), 32);
10461         AnnouncementSignatures_set_channel_id(&this_ptr_conv, val_ref);
10462 }
10463
10464 int64_t  __attribute__((visibility("default"))) TS_AnnouncementSignatures_get_short_channel_id(uint32_t this_ptr) {
10465         LDKAnnouncementSignatures this_ptr_conv;
10466         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10467         this_ptr_conv.is_owned = false;
10468         int64_t ret_val = AnnouncementSignatures_get_short_channel_id(&this_ptr_conv);
10469         return ret_val;
10470 }
10471
10472 void  __attribute__((visibility("default"))) TS_AnnouncementSignatures_set_short_channel_id(uint32_t this_ptr, int64_t val) {
10473         LDKAnnouncementSignatures this_ptr_conv;
10474         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10475         this_ptr_conv.is_owned = false;
10476         AnnouncementSignatures_set_short_channel_id(&this_ptr_conv, val);
10477 }
10478
10479 int8_tArray  __attribute__((visibility("default"))) TS_AnnouncementSignatures_get_node_signature(uint32_t this_ptr) {
10480         LDKAnnouncementSignatures this_ptr_conv;
10481         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10482         this_ptr_conv.is_owned = false;
10483         int8_tArray arg_arr = init_arr(64, sizeof(uint8_t), "Native int8_tArray Bytes");
10484         memcpy((uint8_t*)(arg_arr + 4), AnnouncementSignatures_get_node_signature(&this_ptr_conv).compact_form, 64);
10485         return arg_arr;
10486 }
10487
10488 void  __attribute__((visibility("default"))) TS_AnnouncementSignatures_set_node_signature(uint32_t this_ptr, int8_tArray val) {
10489         LDKAnnouncementSignatures this_ptr_conv;
10490         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10491         this_ptr_conv.is_owned = false;
10492         LDKSignature val_ref;
10493         CHECK(*((uint32_t*)val) == 64);
10494         memcpy(val_ref.compact_form, (uint8_t*)(val + 4), 64);
10495         AnnouncementSignatures_set_node_signature(&this_ptr_conv, val_ref);
10496 }
10497
10498 int8_tArray  __attribute__((visibility("default"))) TS_AnnouncementSignatures_get_bitcoin_signature(uint32_t this_ptr) {
10499         LDKAnnouncementSignatures this_ptr_conv;
10500         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10501         this_ptr_conv.is_owned = false;
10502         int8_tArray arg_arr = init_arr(64, sizeof(uint8_t), "Native int8_tArray Bytes");
10503         memcpy((uint8_t*)(arg_arr + 4), AnnouncementSignatures_get_bitcoin_signature(&this_ptr_conv).compact_form, 64);
10504         return arg_arr;
10505 }
10506
10507 void  __attribute__((visibility("default"))) TS_AnnouncementSignatures_set_bitcoin_signature(uint32_t this_ptr, int8_tArray val) {
10508         LDKAnnouncementSignatures this_ptr_conv;
10509         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10510         this_ptr_conv.is_owned = false;
10511         LDKSignature val_ref;
10512         CHECK(*((uint32_t*)val) == 64);
10513         memcpy(val_ref.compact_form, (uint8_t*)(val + 4), 64);
10514         AnnouncementSignatures_set_bitcoin_signature(&this_ptr_conv, val_ref);
10515 }
10516
10517 uint32_t  __attribute__((visibility("default"))) TS_AnnouncementSignatures_new(int8_tArray channel_id_arg, int64_t short_channel_id_arg, int8_tArray node_signature_arg, int8_tArray bitcoin_signature_arg) {
10518         LDKThirtyTwoBytes channel_id_arg_ref;
10519         CHECK(*((uint32_t*)channel_id_arg) == 32);
10520         memcpy(channel_id_arg_ref.data, (uint8_t*)(channel_id_arg + 4), 32);
10521         LDKSignature node_signature_arg_ref;
10522         CHECK(*((uint32_t*)node_signature_arg) == 64);
10523         memcpy(node_signature_arg_ref.compact_form, (uint8_t*)(node_signature_arg + 4), 64);
10524         LDKSignature bitcoin_signature_arg_ref;
10525         CHECK(*((uint32_t*)bitcoin_signature_arg) == 64);
10526         memcpy(bitcoin_signature_arg_ref.compact_form, (uint8_t*)(bitcoin_signature_arg + 4), 64);
10527         LDKAnnouncementSignatures ret_var = AnnouncementSignatures_new(channel_id_arg_ref, short_channel_id_arg, node_signature_arg_ref, bitcoin_signature_arg_ref);
10528         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10529         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10530         long ret_ref = (long)ret_var.inner;
10531         if (ret_var.is_owned) {
10532                 ret_ref |= 1;
10533         }
10534         return ret_ref;
10535 }
10536
10537 void  __attribute__((visibility("default"))) TS_NetAddress_free(uint32_t this_ptr) {
10538         if ((this_ptr & 1) != 0) return;
10539         LDKNetAddress this_ptr_conv = *(LDKNetAddress*)(((uint64_t)this_ptr) & ~1);
10540         FREE((void*)this_ptr);
10541         NetAddress_free(this_ptr_conv);
10542 }
10543
10544 uint32_t  __attribute__((visibility("default"))) TS_NetAddress_clone(uint32_t orig) {
10545         LDKNetAddress* orig_conv = (LDKNetAddress*)orig;
10546         LDKNetAddress *ret_copy = MALLOC(sizeof(LDKNetAddress), "LDKNetAddress");
10547         *ret_copy = NetAddress_clone(orig_conv);
10548         long ret_ref = (long)ret_copy;
10549         return ret_ref;
10550 }
10551
10552 int8_tArray  __attribute__((visibility("default"))) TS_NetAddress_write(uint32_t obj) {
10553         LDKNetAddress* obj_conv = (LDKNetAddress*)obj;
10554         LDKCVec_u8Z arg_var = NetAddress_write(obj_conv);
10555         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
10556         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
10557         CVec_u8Z_free(arg_var);
10558         return arg_arr;
10559 }
10560
10561 uint32_t  __attribute__((visibility("default"))) TS_Result_read(int8_tArray ser) {
10562         LDKu8slice ser_ref;
10563         ser_ref.datalen = *((uint32_t*)ser);
10564         ser_ref.data = (int8_t*)(ser + 4);
10565         LDKCResult_CResult_NetAddressu8ZDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_CResult_NetAddressu8ZDecodeErrorZ), "LDKCResult_CResult_NetAddressu8ZDecodeErrorZ");
10566         *ret_conv = Result_read(ser_ref);
10567         return (long)ret_conv;
10568 }
10569
10570 void  __attribute__((visibility("default"))) TS_UnsignedNodeAnnouncement_free(uint32_t this_ptr) {
10571         LDKUnsignedNodeAnnouncement this_ptr_conv;
10572         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10573         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10574         UnsignedNodeAnnouncement_free(this_ptr_conv);
10575 }
10576
10577 uint32_t  __attribute__((visibility("default"))) TS_UnsignedNodeAnnouncement_clone(uint32_t orig) {
10578         LDKUnsignedNodeAnnouncement orig_conv;
10579         orig_conv.inner = (void*)(orig & (~1));
10580         orig_conv.is_owned = false;
10581         LDKUnsignedNodeAnnouncement ret_var = UnsignedNodeAnnouncement_clone(&orig_conv);
10582         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10583         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10584         long ret_ref = (long)ret_var.inner;
10585         if (ret_var.is_owned) {
10586                 ret_ref |= 1;
10587         }
10588         return ret_ref;
10589 }
10590
10591 uint32_t  __attribute__((visibility("default"))) TS_UnsignedNodeAnnouncement_get_features(uint32_t this_ptr) {
10592         LDKUnsignedNodeAnnouncement this_ptr_conv;
10593         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10594         this_ptr_conv.is_owned = false;
10595         LDKNodeFeatures ret_var = UnsignedNodeAnnouncement_get_features(&this_ptr_conv);
10596         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10597         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10598         long ret_ref = (long)ret_var.inner;
10599         if (ret_var.is_owned) {
10600                 ret_ref |= 1;
10601         }
10602         return ret_ref;
10603 }
10604
10605 void  __attribute__((visibility("default"))) TS_UnsignedNodeAnnouncement_set_features(uint32_t this_ptr, uint32_t val) {
10606         LDKUnsignedNodeAnnouncement this_ptr_conv;
10607         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10608         this_ptr_conv.is_owned = false;
10609         LDKNodeFeatures val_conv;
10610         val_conv.inner = (void*)(val & (~1));
10611         val_conv.is_owned = (val & 1) || (val == 0);
10612         // Warning: we need a move here but no clone is available for LDKNodeFeatures
10613         UnsignedNodeAnnouncement_set_features(&this_ptr_conv, val_conv);
10614 }
10615
10616 int32_t  __attribute__((visibility("default"))) TS_UnsignedNodeAnnouncement_get_timestamp(uint32_t this_ptr) {
10617         LDKUnsignedNodeAnnouncement this_ptr_conv;
10618         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10619         this_ptr_conv.is_owned = false;
10620         int32_t ret_val = UnsignedNodeAnnouncement_get_timestamp(&this_ptr_conv);
10621         return ret_val;
10622 }
10623
10624 void  __attribute__((visibility("default"))) TS_UnsignedNodeAnnouncement_set_timestamp(uint32_t this_ptr, int32_t val) {
10625         LDKUnsignedNodeAnnouncement this_ptr_conv;
10626         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10627         this_ptr_conv.is_owned = false;
10628         UnsignedNodeAnnouncement_set_timestamp(&this_ptr_conv, val);
10629 }
10630
10631 int8_tArray  __attribute__((visibility("default"))) TS_UnsignedNodeAnnouncement_get_node_id(uint32_t this_ptr) {
10632         LDKUnsignedNodeAnnouncement this_ptr_conv;
10633         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10634         this_ptr_conv.is_owned = false;
10635         int8_tArray arg_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
10636         memcpy((uint8_t*)(arg_arr + 4), UnsignedNodeAnnouncement_get_node_id(&this_ptr_conv).compressed_form, 33);
10637         return arg_arr;
10638 }
10639
10640 void  __attribute__((visibility("default"))) TS_UnsignedNodeAnnouncement_set_node_id(uint32_t this_ptr, int8_tArray val) {
10641         LDKUnsignedNodeAnnouncement this_ptr_conv;
10642         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10643         this_ptr_conv.is_owned = false;
10644         LDKPublicKey val_ref;
10645         CHECK(*((uint32_t*)val) == 33);
10646         memcpy(val_ref.compressed_form, (uint8_t*)(val + 4), 33);
10647         UnsignedNodeAnnouncement_set_node_id(&this_ptr_conv, val_ref);
10648 }
10649
10650 int8_tArray  __attribute__((visibility("default"))) TS_UnsignedNodeAnnouncement_get_rgb(uint32_t this_ptr) {
10651         LDKUnsignedNodeAnnouncement this_ptr_conv;
10652         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10653         this_ptr_conv.is_owned = false;
10654         int8_tArray ret_arr = init_arr(3, sizeof(uint8_t), "Native int8_tArray Bytes");
10655         memcpy((uint8_t*)(ret_arr + 4), *UnsignedNodeAnnouncement_get_rgb(&this_ptr_conv), 3);
10656         return ret_arr;
10657 }
10658
10659 void  __attribute__((visibility("default"))) TS_UnsignedNodeAnnouncement_set_rgb(uint32_t this_ptr, int8_tArray val) {
10660         LDKUnsignedNodeAnnouncement this_ptr_conv;
10661         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10662         this_ptr_conv.is_owned = false;
10663         LDKThreeBytes val_ref;
10664         CHECK(*((uint32_t*)val) == 3);
10665         memcpy(val_ref.data, (uint8_t*)(val + 4), 3);
10666         UnsignedNodeAnnouncement_set_rgb(&this_ptr_conv, val_ref);
10667 }
10668
10669 int8_tArray  __attribute__((visibility("default"))) TS_UnsignedNodeAnnouncement_get_alias(uint32_t this_ptr) {
10670         LDKUnsignedNodeAnnouncement this_ptr_conv;
10671         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10672         this_ptr_conv.is_owned = false;
10673         int8_tArray ret_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
10674         memcpy((uint8_t*)(ret_arr + 4), *UnsignedNodeAnnouncement_get_alias(&this_ptr_conv), 32);
10675         return ret_arr;
10676 }
10677
10678 void  __attribute__((visibility("default"))) TS_UnsignedNodeAnnouncement_set_alias(uint32_t this_ptr, int8_tArray val) {
10679         LDKUnsignedNodeAnnouncement this_ptr_conv;
10680         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10681         this_ptr_conv.is_owned = false;
10682         LDKThirtyTwoBytes val_ref;
10683         CHECK(*((uint32_t*)val) == 32);
10684         memcpy(val_ref.data, (uint8_t*)(val + 4), 32);
10685         UnsignedNodeAnnouncement_set_alias(&this_ptr_conv, val_ref);
10686 }
10687
10688 void  __attribute__((visibility("default"))) TS_UnsignedNodeAnnouncement_set_addresses(uint32_t this_ptr, uint32_tArray val) {
10689         LDKUnsignedNodeAnnouncement this_ptr_conv;
10690         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10691         this_ptr_conv.is_owned = false;
10692         LDKCVec_NetAddressZ val_constr;
10693         val_constr.datalen = *((uint32_t*)val);
10694         if (val_constr.datalen > 0)
10695                 val_constr.data = MALLOC(val_constr.datalen * sizeof(LDKNetAddress), "LDKCVec_NetAddressZ Elements");
10696         else
10697                 val_constr.data = NULL;
10698         uint32_t* val_vals = (uint32_t*)(val + 4);
10699         for (size_t m = 0; m < val_constr.datalen; m++) {
10700                 uint32_t arr_conv_12 = val_vals[m];
10701                 LDKNetAddress arr_conv_12_conv = *(LDKNetAddress*)(((uint64_t)arr_conv_12) & ~1);
10702                 FREE((void*)arr_conv_12);
10703                 val_constr.data[m] = arr_conv_12_conv;
10704         }
10705         UnsignedNodeAnnouncement_set_addresses(&this_ptr_conv, val_constr);
10706 }
10707
10708 void  __attribute__((visibility("default"))) TS_NodeAnnouncement_free(uint32_t this_ptr) {
10709         LDKNodeAnnouncement this_ptr_conv;
10710         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10711         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10712         NodeAnnouncement_free(this_ptr_conv);
10713 }
10714
10715 uint32_t  __attribute__((visibility("default"))) TS_NodeAnnouncement_clone(uint32_t orig) {
10716         LDKNodeAnnouncement orig_conv;
10717         orig_conv.inner = (void*)(orig & (~1));
10718         orig_conv.is_owned = false;
10719         LDKNodeAnnouncement ret_var = NodeAnnouncement_clone(&orig_conv);
10720         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10721         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10722         long ret_ref = (long)ret_var.inner;
10723         if (ret_var.is_owned) {
10724                 ret_ref |= 1;
10725         }
10726         return ret_ref;
10727 }
10728
10729 int8_tArray  __attribute__((visibility("default"))) TS_NodeAnnouncement_get_signature(uint32_t this_ptr) {
10730         LDKNodeAnnouncement this_ptr_conv;
10731         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10732         this_ptr_conv.is_owned = false;
10733         int8_tArray arg_arr = init_arr(64, sizeof(uint8_t), "Native int8_tArray Bytes");
10734         memcpy((uint8_t*)(arg_arr + 4), NodeAnnouncement_get_signature(&this_ptr_conv).compact_form, 64);
10735         return arg_arr;
10736 }
10737
10738 void  __attribute__((visibility("default"))) TS_NodeAnnouncement_set_signature(uint32_t this_ptr, int8_tArray val) {
10739         LDKNodeAnnouncement this_ptr_conv;
10740         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10741         this_ptr_conv.is_owned = false;
10742         LDKSignature val_ref;
10743         CHECK(*((uint32_t*)val) == 64);
10744         memcpy(val_ref.compact_form, (uint8_t*)(val + 4), 64);
10745         NodeAnnouncement_set_signature(&this_ptr_conv, val_ref);
10746 }
10747
10748 uint32_t  __attribute__((visibility("default"))) TS_NodeAnnouncement_get_contents(uint32_t this_ptr) {
10749         LDKNodeAnnouncement this_ptr_conv;
10750         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10751         this_ptr_conv.is_owned = false;
10752         LDKUnsignedNodeAnnouncement ret_var = NodeAnnouncement_get_contents(&this_ptr_conv);
10753         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10754         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10755         long ret_ref = (long)ret_var.inner;
10756         if (ret_var.is_owned) {
10757                 ret_ref |= 1;
10758         }
10759         return ret_ref;
10760 }
10761
10762 void  __attribute__((visibility("default"))) TS_NodeAnnouncement_set_contents(uint32_t this_ptr, uint32_t val) {
10763         LDKNodeAnnouncement this_ptr_conv;
10764         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10765         this_ptr_conv.is_owned = false;
10766         LDKUnsignedNodeAnnouncement val_conv;
10767         val_conv.inner = (void*)(val & (~1));
10768         val_conv.is_owned = (val & 1) || (val == 0);
10769         val_conv = UnsignedNodeAnnouncement_clone(&val_conv);
10770         NodeAnnouncement_set_contents(&this_ptr_conv, val_conv);
10771 }
10772
10773 uint32_t  __attribute__((visibility("default"))) TS_NodeAnnouncement_new(int8_tArray signature_arg, uint32_t contents_arg) {
10774         LDKSignature signature_arg_ref;
10775         CHECK(*((uint32_t*)signature_arg) == 64);
10776         memcpy(signature_arg_ref.compact_form, (uint8_t*)(signature_arg + 4), 64);
10777         LDKUnsignedNodeAnnouncement contents_arg_conv;
10778         contents_arg_conv.inner = (void*)(contents_arg & (~1));
10779         contents_arg_conv.is_owned = (contents_arg & 1) || (contents_arg == 0);
10780         contents_arg_conv = UnsignedNodeAnnouncement_clone(&contents_arg_conv);
10781         LDKNodeAnnouncement ret_var = NodeAnnouncement_new(signature_arg_ref, contents_arg_conv);
10782         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10783         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10784         long ret_ref = (long)ret_var.inner;
10785         if (ret_var.is_owned) {
10786                 ret_ref |= 1;
10787         }
10788         return ret_ref;
10789 }
10790
10791 void  __attribute__((visibility("default"))) TS_UnsignedChannelAnnouncement_free(uint32_t this_ptr) {
10792         LDKUnsignedChannelAnnouncement this_ptr_conv;
10793         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10794         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10795         UnsignedChannelAnnouncement_free(this_ptr_conv);
10796 }
10797
10798 uint32_t  __attribute__((visibility("default"))) TS_UnsignedChannelAnnouncement_clone(uint32_t orig) {
10799         LDKUnsignedChannelAnnouncement orig_conv;
10800         orig_conv.inner = (void*)(orig & (~1));
10801         orig_conv.is_owned = false;
10802         LDKUnsignedChannelAnnouncement ret_var = UnsignedChannelAnnouncement_clone(&orig_conv);
10803         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10804         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10805         long ret_ref = (long)ret_var.inner;
10806         if (ret_var.is_owned) {
10807                 ret_ref |= 1;
10808         }
10809         return ret_ref;
10810 }
10811
10812 uint32_t  __attribute__((visibility("default"))) TS_UnsignedChannelAnnouncement_get_features(uint32_t this_ptr) {
10813         LDKUnsignedChannelAnnouncement this_ptr_conv;
10814         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10815         this_ptr_conv.is_owned = false;
10816         LDKChannelFeatures ret_var = UnsignedChannelAnnouncement_get_features(&this_ptr_conv);
10817         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10818         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10819         long ret_ref = (long)ret_var.inner;
10820         if (ret_var.is_owned) {
10821                 ret_ref |= 1;
10822         }
10823         return ret_ref;
10824 }
10825
10826 void  __attribute__((visibility("default"))) TS_UnsignedChannelAnnouncement_set_features(uint32_t this_ptr, uint32_t val) {
10827         LDKUnsignedChannelAnnouncement this_ptr_conv;
10828         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10829         this_ptr_conv.is_owned = false;
10830         LDKChannelFeatures val_conv;
10831         val_conv.inner = (void*)(val & (~1));
10832         val_conv.is_owned = (val & 1) || (val == 0);
10833         // Warning: we need a move here but no clone is available for LDKChannelFeatures
10834         UnsignedChannelAnnouncement_set_features(&this_ptr_conv, val_conv);
10835 }
10836
10837 int8_tArray  __attribute__((visibility("default"))) TS_UnsignedChannelAnnouncement_get_chain_hash(uint32_t this_ptr) {
10838         LDKUnsignedChannelAnnouncement this_ptr_conv;
10839         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10840         this_ptr_conv.is_owned = false;
10841         int8_tArray ret_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
10842         memcpy((uint8_t*)(ret_arr + 4), *UnsignedChannelAnnouncement_get_chain_hash(&this_ptr_conv), 32);
10843         return ret_arr;
10844 }
10845
10846 void  __attribute__((visibility("default"))) TS_UnsignedChannelAnnouncement_set_chain_hash(uint32_t this_ptr, int8_tArray val) {
10847         LDKUnsignedChannelAnnouncement this_ptr_conv;
10848         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10849         this_ptr_conv.is_owned = false;
10850         LDKThirtyTwoBytes val_ref;
10851         CHECK(*((uint32_t*)val) == 32);
10852         memcpy(val_ref.data, (uint8_t*)(val + 4), 32);
10853         UnsignedChannelAnnouncement_set_chain_hash(&this_ptr_conv, val_ref);
10854 }
10855
10856 int64_t  __attribute__((visibility("default"))) TS_UnsignedChannelAnnouncement_get_short_channel_id(uint32_t this_ptr) {
10857         LDKUnsignedChannelAnnouncement this_ptr_conv;
10858         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10859         this_ptr_conv.is_owned = false;
10860         int64_t ret_val = UnsignedChannelAnnouncement_get_short_channel_id(&this_ptr_conv);
10861         return ret_val;
10862 }
10863
10864 void  __attribute__((visibility("default"))) TS_UnsignedChannelAnnouncement_set_short_channel_id(uint32_t this_ptr, int64_t val) {
10865         LDKUnsignedChannelAnnouncement this_ptr_conv;
10866         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10867         this_ptr_conv.is_owned = false;
10868         UnsignedChannelAnnouncement_set_short_channel_id(&this_ptr_conv, val);
10869 }
10870
10871 int8_tArray  __attribute__((visibility("default"))) TS_UnsignedChannelAnnouncement_get_node_id_1(uint32_t this_ptr) {
10872         LDKUnsignedChannelAnnouncement this_ptr_conv;
10873         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10874         this_ptr_conv.is_owned = false;
10875         int8_tArray arg_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
10876         memcpy((uint8_t*)(arg_arr + 4), UnsignedChannelAnnouncement_get_node_id_1(&this_ptr_conv).compressed_form, 33);
10877         return arg_arr;
10878 }
10879
10880 void  __attribute__((visibility("default"))) TS_UnsignedChannelAnnouncement_set_node_id_1(uint32_t this_ptr, int8_tArray val) {
10881         LDKUnsignedChannelAnnouncement this_ptr_conv;
10882         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10883         this_ptr_conv.is_owned = false;
10884         LDKPublicKey val_ref;
10885         CHECK(*((uint32_t*)val) == 33);
10886         memcpy(val_ref.compressed_form, (uint8_t*)(val + 4), 33);
10887         UnsignedChannelAnnouncement_set_node_id_1(&this_ptr_conv, val_ref);
10888 }
10889
10890 int8_tArray  __attribute__((visibility("default"))) TS_UnsignedChannelAnnouncement_get_node_id_2(uint32_t this_ptr) {
10891         LDKUnsignedChannelAnnouncement this_ptr_conv;
10892         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10893         this_ptr_conv.is_owned = false;
10894         int8_tArray arg_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
10895         memcpy((uint8_t*)(arg_arr + 4), UnsignedChannelAnnouncement_get_node_id_2(&this_ptr_conv).compressed_form, 33);
10896         return arg_arr;
10897 }
10898
10899 void  __attribute__((visibility("default"))) TS_UnsignedChannelAnnouncement_set_node_id_2(uint32_t this_ptr, int8_tArray val) {
10900         LDKUnsignedChannelAnnouncement this_ptr_conv;
10901         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10902         this_ptr_conv.is_owned = false;
10903         LDKPublicKey val_ref;
10904         CHECK(*((uint32_t*)val) == 33);
10905         memcpy(val_ref.compressed_form, (uint8_t*)(val + 4), 33);
10906         UnsignedChannelAnnouncement_set_node_id_2(&this_ptr_conv, val_ref);
10907 }
10908
10909 int8_tArray  __attribute__((visibility("default"))) TS_UnsignedChannelAnnouncement_get_bitcoin_key_1(uint32_t this_ptr) {
10910         LDKUnsignedChannelAnnouncement this_ptr_conv;
10911         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10912         this_ptr_conv.is_owned = false;
10913         int8_tArray arg_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
10914         memcpy((uint8_t*)(arg_arr + 4), UnsignedChannelAnnouncement_get_bitcoin_key_1(&this_ptr_conv).compressed_form, 33);
10915         return arg_arr;
10916 }
10917
10918 void  __attribute__((visibility("default"))) TS_UnsignedChannelAnnouncement_set_bitcoin_key_1(uint32_t this_ptr, int8_tArray val) {
10919         LDKUnsignedChannelAnnouncement this_ptr_conv;
10920         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10921         this_ptr_conv.is_owned = false;
10922         LDKPublicKey val_ref;
10923         CHECK(*((uint32_t*)val) == 33);
10924         memcpy(val_ref.compressed_form, (uint8_t*)(val + 4), 33);
10925         UnsignedChannelAnnouncement_set_bitcoin_key_1(&this_ptr_conv, val_ref);
10926 }
10927
10928 int8_tArray  __attribute__((visibility("default"))) TS_UnsignedChannelAnnouncement_get_bitcoin_key_2(uint32_t this_ptr) {
10929         LDKUnsignedChannelAnnouncement this_ptr_conv;
10930         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10931         this_ptr_conv.is_owned = false;
10932         int8_tArray arg_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
10933         memcpy((uint8_t*)(arg_arr + 4), UnsignedChannelAnnouncement_get_bitcoin_key_2(&this_ptr_conv).compressed_form, 33);
10934         return arg_arr;
10935 }
10936
10937 void  __attribute__((visibility("default"))) TS_UnsignedChannelAnnouncement_set_bitcoin_key_2(uint32_t this_ptr, int8_tArray val) {
10938         LDKUnsignedChannelAnnouncement this_ptr_conv;
10939         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10940         this_ptr_conv.is_owned = false;
10941         LDKPublicKey val_ref;
10942         CHECK(*((uint32_t*)val) == 33);
10943         memcpy(val_ref.compressed_form, (uint8_t*)(val + 4), 33);
10944         UnsignedChannelAnnouncement_set_bitcoin_key_2(&this_ptr_conv, val_ref);
10945 }
10946
10947 void  __attribute__((visibility("default"))) TS_ChannelAnnouncement_free(uint32_t this_ptr) {
10948         LDKChannelAnnouncement this_ptr_conv;
10949         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10950         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10951         ChannelAnnouncement_free(this_ptr_conv);
10952 }
10953
10954 uint32_t  __attribute__((visibility("default"))) TS_ChannelAnnouncement_clone(uint32_t orig) {
10955         LDKChannelAnnouncement orig_conv;
10956         orig_conv.inner = (void*)(orig & (~1));
10957         orig_conv.is_owned = false;
10958         LDKChannelAnnouncement ret_var = ChannelAnnouncement_clone(&orig_conv);
10959         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10960         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10961         long ret_ref = (long)ret_var.inner;
10962         if (ret_var.is_owned) {
10963                 ret_ref |= 1;
10964         }
10965         return ret_ref;
10966 }
10967
10968 int8_tArray  __attribute__((visibility("default"))) TS_ChannelAnnouncement_get_node_signature_1(uint32_t this_ptr) {
10969         LDKChannelAnnouncement this_ptr_conv;
10970         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10971         this_ptr_conv.is_owned = false;
10972         int8_tArray arg_arr = init_arr(64, sizeof(uint8_t), "Native int8_tArray Bytes");
10973         memcpy((uint8_t*)(arg_arr + 4), ChannelAnnouncement_get_node_signature_1(&this_ptr_conv).compact_form, 64);
10974         return arg_arr;
10975 }
10976
10977 void  __attribute__((visibility("default"))) TS_ChannelAnnouncement_set_node_signature_1(uint32_t this_ptr, int8_tArray val) {
10978         LDKChannelAnnouncement this_ptr_conv;
10979         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10980         this_ptr_conv.is_owned = false;
10981         LDKSignature val_ref;
10982         CHECK(*((uint32_t*)val) == 64);
10983         memcpy(val_ref.compact_form, (uint8_t*)(val + 4), 64);
10984         ChannelAnnouncement_set_node_signature_1(&this_ptr_conv, val_ref);
10985 }
10986
10987 int8_tArray  __attribute__((visibility("default"))) TS_ChannelAnnouncement_get_node_signature_2(uint32_t this_ptr) {
10988         LDKChannelAnnouncement this_ptr_conv;
10989         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10990         this_ptr_conv.is_owned = false;
10991         int8_tArray arg_arr = init_arr(64, sizeof(uint8_t), "Native int8_tArray Bytes");
10992         memcpy((uint8_t*)(arg_arr + 4), ChannelAnnouncement_get_node_signature_2(&this_ptr_conv).compact_form, 64);
10993         return arg_arr;
10994 }
10995
10996 void  __attribute__((visibility("default"))) TS_ChannelAnnouncement_set_node_signature_2(uint32_t this_ptr, int8_tArray val) {
10997         LDKChannelAnnouncement this_ptr_conv;
10998         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10999         this_ptr_conv.is_owned = false;
11000         LDKSignature val_ref;
11001         CHECK(*((uint32_t*)val) == 64);
11002         memcpy(val_ref.compact_form, (uint8_t*)(val + 4), 64);
11003         ChannelAnnouncement_set_node_signature_2(&this_ptr_conv, val_ref);
11004 }
11005
11006 int8_tArray  __attribute__((visibility("default"))) TS_ChannelAnnouncement_get_bitcoin_signature_1(uint32_t this_ptr) {
11007         LDKChannelAnnouncement this_ptr_conv;
11008         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11009         this_ptr_conv.is_owned = false;
11010         int8_tArray arg_arr = init_arr(64, sizeof(uint8_t), "Native int8_tArray Bytes");
11011         memcpy((uint8_t*)(arg_arr + 4), ChannelAnnouncement_get_bitcoin_signature_1(&this_ptr_conv).compact_form, 64);
11012         return arg_arr;
11013 }
11014
11015 void  __attribute__((visibility("default"))) TS_ChannelAnnouncement_set_bitcoin_signature_1(uint32_t this_ptr, int8_tArray val) {
11016         LDKChannelAnnouncement this_ptr_conv;
11017         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11018         this_ptr_conv.is_owned = false;
11019         LDKSignature val_ref;
11020         CHECK(*((uint32_t*)val) == 64);
11021         memcpy(val_ref.compact_form, (uint8_t*)(val + 4), 64);
11022         ChannelAnnouncement_set_bitcoin_signature_1(&this_ptr_conv, val_ref);
11023 }
11024
11025 int8_tArray  __attribute__((visibility("default"))) TS_ChannelAnnouncement_get_bitcoin_signature_2(uint32_t this_ptr) {
11026         LDKChannelAnnouncement this_ptr_conv;
11027         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11028         this_ptr_conv.is_owned = false;
11029         int8_tArray arg_arr = init_arr(64, sizeof(uint8_t), "Native int8_tArray Bytes");
11030         memcpy((uint8_t*)(arg_arr + 4), ChannelAnnouncement_get_bitcoin_signature_2(&this_ptr_conv).compact_form, 64);
11031         return arg_arr;
11032 }
11033
11034 void  __attribute__((visibility("default"))) TS_ChannelAnnouncement_set_bitcoin_signature_2(uint32_t this_ptr, int8_tArray val) {
11035         LDKChannelAnnouncement this_ptr_conv;
11036         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11037         this_ptr_conv.is_owned = false;
11038         LDKSignature val_ref;
11039         CHECK(*((uint32_t*)val) == 64);
11040         memcpy(val_ref.compact_form, (uint8_t*)(val + 4), 64);
11041         ChannelAnnouncement_set_bitcoin_signature_2(&this_ptr_conv, val_ref);
11042 }
11043
11044 uint32_t  __attribute__((visibility("default"))) TS_ChannelAnnouncement_get_contents(uint32_t this_ptr) {
11045         LDKChannelAnnouncement this_ptr_conv;
11046         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11047         this_ptr_conv.is_owned = false;
11048         LDKUnsignedChannelAnnouncement ret_var = ChannelAnnouncement_get_contents(&this_ptr_conv);
11049         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11050         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11051         long ret_ref = (long)ret_var.inner;
11052         if (ret_var.is_owned) {
11053                 ret_ref |= 1;
11054         }
11055         return ret_ref;
11056 }
11057
11058 void  __attribute__((visibility("default"))) TS_ChannelAnnouncement_set_contents(uint32_t this_ptr, uint32_t val) {
11059         LDKChannelAnnouncement this_ptr_conv;
11060         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11061         this_ptr_conv.is_owned = false;
11062         LDKUnsignedChannelAnnouncement val_conv;
11063         val_conv.inner = (void*)(val & (~1));
11064         val_conv.is_owned = (val & 1) || (val == 0);
11065         val_conv = UnsignedChannelAnnouncement_clone(&val_conv);
11066         ChannelAnnouncement_set_contents(&this_ptr_conv, val_conv);
11067 }
11068
11069 uint32_t  __attribute__((visibility("default"))) 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) {
11070         LDKSignature node_signature_1_arg_ref;
11071         CHECK(*((uint32_t*)node_signature_1_arg) == 64);
11072         memcpy(node_signature_1_arg_ref.compact_form, (uint8_t*)(node_signature_1_arg + 4), 64);
11073         LDKSignature node_signature_2_arg_ref;
11074         CHECK(*((uint32_t*)node_signature_2_arg) == 64);
11075         memcpy(node_signature_2_arg_ref.compact_form, (uint8_t*)(node_signature_2_arg + 4), 64);
11076         LDKSignature bitcoin_signature_1_arg_ref;
11077         CHECK(*((uint32_t*)bitcoin_signature_1_arg) == 64);
11078         memcpy(bitcoin_signature_1_arg_ref.compact_form, (uint8_t*)(bitcoin_signature_1_arg + 4), 64);
11079         LDKSignature bitcoin_signature_2_arg_ref;
11080         CHECK(*((uint32_t*)bitcoin_signature_2_arg) == 64);
11081         memcpy(bitcoin_signature_2_arg_ref.compact_form, (uint8_t*)(bitcoin_signature_2_arg + 4), 64);
11082         LDKUnsignedChannelAnnouncement contents_arg_conv;
11083         contents_arg_conv.inner = (void*)(contents_arg & (~1));
11084         contents_arg_conv.is_owned = (contents_arg & 1) || (contents_arg == 0);
11085         contents_arg_conv = UnsignedChannelAnnouncement_clone(&contents_arg_conv);
11086         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);
11087         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11088         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11089         long ret_ref = (long)ret_var.inner;
11090         if (ret_var.is_owned) {
11091                 ret_ref |= 1;
11092         }
11093         return ret_ref;
11094 }
11095
11096 void  __attribute__((visibility("default"))) TS_UnsignedChannelUpdate_free(uint32_t this_ptr) {
11097         LDKUnsignedChannelUpdate this_ptr_conv;
11098         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11099         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
11100         UnsignedChannelUpdate_free(this_ptr_conv);
11101 }
11102
11103 uint32_t  __attribute__((visibility("default"))) TS_UnsignedChannelUpdate_clone(uint32_t orig) {
11104         LDKUnsignedChannelUpdate orig_conv;
11105         orig_conv.inner = (void*)(orig & (~1));
11106         orig_conv.is_owned = false;
11107         LDKUnsignedChannelUpdate ret_var = UnsignedChannelUpdate_clone(&orig_conv);
11108         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11109         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11110         long ret_ref = (long)ret_var.inner;
11111         if (ret_var.is_owned) {
11112                 ret_ref |= 1;
11113         }
11114         return ret_ref;
11115 }
11116
11117 int8_tArray  __attribute__((visibility("default"))) TS_UnsignedChannelUpdate_get_chain_hash(uint32_t this_ptr) {
11118         LDKUnsignedChannelUpdate this_ptr_conv;
11119         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11120         this_ptr_conv.is_owned = false;
11121         int8_tArray ret_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
11122         memcpy((uint8_t*)(ret_arr + 4), *UnsignedChannelUpdate_get_chain_hash(&this_ptr_conv), 32);
11123         return ret_arr;
11124 }
11125
11126 void  __attribute__((visibility("default"))) TS_UnsignedChannelUpdate_set_chain_hash(uint32_t this_ptr, int8_tArray val) {
11127         LDKUnsignedChannelUpdate this_ptr_conv;
11128         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11129         this_ptr_conv.is_owned = false;
11130         LDKThirtyTwoBytes val_ref;
11131         CHECK(*((uint32_t*)val) == 32);
11132         memcpy(val_ref.data, (uint8_t*)(val + 4), 32);
11133         UnsignedChannelUpdate_set_chain_hash(&this_ptr_conv, val_ref);
11134 }
11135
11136 int64_t  __attribute__((visibility("default"))) TS_UnsignedChannelUpdate_get_short_channel_id(uint32_t this_ptr) {
11137         LDKUnsignedChannelUpdate this_ptr_conv;
11138         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11139         this_ptr_conv.is_owned = false;
11140         int64_t ret_val = UnsignedChannelUpdate_get_short_channel_id(&this_ptr_conv);
11141         return ret_val;
11142 }
11143
11144 void  __attribute__((visibility("default"))) TS_UnsignedChannelUpdate_set_short_channel_id(uint32_t this_ptr, int64_t val) {
11145         LDKUnsignedChannelUpdate this_ptr_conv;
11146         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11147         this_ptr_conv.is_owned = false;
11148         UnsignedChannelUpdate_set_short_channel_id(&this_ptr_conv, val);
11149 }
11150
11151 int32_t  __attribute__((visibility("default"))) TS_UnsignedChannelUpdate_get_timestamp(uint32_t this_ptr) {
11152         LDKUnsignedChannelUpdate this_ptr_conv;
11153         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11154         this_ptr_conv.is_owned = false;
11155         int32_t ret_val = UnsignedChannelUpdate_get_timestamp(&this_ptr_conv);
11156         return ret_val;
11157 }
11158
11159 void  __attribute__((visibility("default"))) TS_UnsignedChannelUpdate_set_timestamp(uint32_t this_ptr, int32_t val) {
11160         LDKUnsignedChannelUpdate this_ptr_conv;
11161         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11162         this_ptr_conv.is_owned = false;
11163         UnsignedChannelUpdate_set_timestamp(&this_ptr_conv, val);
11164 }
11165
11166 int8_t  __attribute__((visibility("default"))) TS_UnsignedChannelUpdate_get_flags(uint32_t this_ptr) {
11167         LDKUnsignedChannelUpdate this_ptr_conv;
11168         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11169         this_ptr_conv.is_owned = false;
11170         int8_t ret_val = UnsignedChannelUpdate_get_flags(&this_ptr_conv);
11171         return ret_val;
11172 }
11173
11174 void  __attribute__((visibility("default"))) TS_UnsignedChannelUpdate_set_flags(uint32_t this_ptr, int8_t val) {
11175         LDKUnsignedChannelUpdate this_ptr_conv;
11176         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11177         this_ptr_conv.is_owned = false;
11178         UnsignedChannelUpdate_set_flags(&this_ptr_conv, val);
11179 }
11180
11181 int16_t  __attribute__((visibility("default"))) TS_UnsignedChannelUpdate_get_cltv_expiry_delta(uint32_t this_ptr) {
11182         LDKUnsignedChannelUpdate this_ptr_conv;
11183         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11184         this_ptr_conv.is_owned = false;
11185         int16_t ret_val = UnsignedChannelUpdate_get_cltv_expiry_delta(&this_ptr_conv);
11186         return ret_val;
11187 }
11188
11189 void  __attribute__((visibility("default"))) TS_UnsignedChannelUpdate_set_cltv_expiry_delta(uint32_t this_ptr, int16_t val) {
11190         LDKUnsignedChannelUpdate this_ptr_conv;
11191         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11192         this_ptr_conv.is_owned = false;
11193         UnsignedChannelUpdate_set_cltv_expiry_delta(&this_ptr_conv, val);
11194 }
11195
11196 int64_t  __attribute__((visibility("default"))) TS_UnsignedChannelUpdate_get_htlc_minimum_msat(uint32_t this_ptr) {
11197         LDKUnsignedChannelUpdate this_ptr_conv;
11198         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11199         this_ptr_conv.is_owned = false;
11200         int64_t ret_val = UnsignedChannelUpdate_get_htlc_minimum_msat(&this_ptr_conv);
11201         return ret_val;
11202 }
11203
11204 void  __attribute__((visibility("default"))) TS_UnsignedChannelUpdate_set_htlc_minimum_msat(uint32_t this_ptr, int64_t val) {
11205         LDKUnsignedChannelUpdate this_ptr_conv;
11206         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11207         this_ptr_conv.is_owned = false;
11208         UnsignedChannelUpdate_set_htlc_minimum_msat(&this_ptr_conv, val);
11209 }
11210
11211 int32_t  __attribute__((visibility("default"))) TS_UnsignedChannelUpdate_get_fee_base_msat(uint32_t this_ptr) {
11212         LDKUnsignedChannelUpdate this_ptr_conv;
11213         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11214         this_ptr_conv.is_owned = false;
11215         int32_t ret_val = UnsignedChannelUpdate_get_fee_base_msat(&this_ptr_conv);
11216         return ret_val;
11217 }
11218
11219 void  __attribute__((visibility("default"))) TS_UnsignedChannelUpdate_set_fee_base_msat(uint32_t this_ptr, int32_t val) {
11220         LDKUnsignedChannelUpdate this_ptr_conv;
11221         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11222         this_ptr_conv.is_owned = false;
11223         UnsignedChannelUpdate_set_fee_base_msat(&this_ptr_conv, val);
11224 }
11225
11226 int32_t  __attribute__((visibility("default"))) TS_UnsignedChannelUpdate_get_fee_proportional_millionths(uint32_t this_ptr) {
11227         LDKUnsignedChannelUpdate this_ptr_conv;
11228         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11229         this_ptr_conv.is_owned = false;
11230         int32_t ret_val = UnsignedChannelUpdate_get_fee_proportional_millionths(&this_ptr_conv);
11231         return ret_val;
11232 }
11233
11234 void  __attribute__((visibility("default"))) TS_UnsignedChannelUpdate_set_fee_proportional_millionths(uint32_t this_ptr, int32_t val) {
11235         LDKUnsignedChannelUpdate this_ptr_conv;
11236         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11237         this_ptr_conv.is_owned = false;
11238         UnsignedChannelUpdate_set_fee_proportional_millionths(&this_ptr_conv, val);
11239 }
11240
11241 void  __attribute__((visibility("default"))) TS_ChannelUpdate_free(uint32_t this_ptr) {
11242         LDKChannelUpdate this_ptr_conv;
11243         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11244         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
11245         ChannelUpdate_free(this_ptr_conv);
11246 }
11247
11248 uint32_t  __attribute__((visibility("default"))) TS_ChannelUpdate_clone(uint32_t orig) {
11249         LDKChannelUpdate orig_conv;
11250         orig_conv.inner = (void*)(orig & (~1));
11251         orig_conv.is_owned = false;
11252         LDKChannelUpdate ret_var = ChannelUpdate_clone(&orig_conv);
11253         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11254         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11255         long ret_ref = (long)ret_var.inner;
11256         if (ret_var.is_owned) {
11257                 ret_ref |= 1;
11258         }
11259         return ret_ref;
11260 }
11261
11262 int8_tArray  __attribute__((visibility("default"))) TS_ChannelUpdate_get_signature(uint32_t this_ptr) {
11263         LDKChannelUpdate this_ptr_conv;
11264         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11265         this_ptr_conv.is_owned = false;
11266         int8_tArray arg_arr = init_arr(64, sizeof(uint8_t), "Native int8_tArray Bytes");
11267         memcpy((uint8_t*)(arg_arr + 4), ChannelUpdate_get_signature(&this_ptr_conv).compact_form, 64);
11268         return arg_arr;
11269 }
11270
11271 void  __attribute__((visibility("default"))) TS_ChannelUpdate_set_signature(uint32_t this_ptr, int8_tArray val) {
11272         LDKChannelUpdate this_ptr_conv;
11273         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11274         this_ptr_conv.is_owned = false;
11275         LDKSignature val_ref;
11276         CHECK(*((uint32_t*)val) == 64);
11277         memcpy(val_ref.compact_form, (uint8_t*)(val + 4), 64);
11278         ChannelUpdate_set_signature(&this_ptr_conv, val_ref);
11279 }
11280
11281 uint32_t  __attribute__((visibility("default"))) TS_ChannelUpdate_get_contents(uint32_t this_ptr) {
11282         LDKChannelUpdate this_ptr_conv;
11283         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11284         this_ptr_conv.is_owned = false;
11285         LDKUnsignedChannelUpdate ret_var = ChannelUpdate_get_contents(&this_ptr_conv);
11286         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11287         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11288         long ret_ref = (long)ret_var.inner;
11289         if (ret_var.is_owned) {
11290                 ret_ref |= 1;
11291         }
11292         return ret_ref;
11293 }
11294
11295 void  __attribute__((visibility("default"))) TS_ChannelUpdate_set_contents(uint32_t this_ptr, uint32_t val) {
11296         LDKChannelUpdate this_ptr_conv;
11297         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11298         this_ptr_conv.is_owned = false;
11299         LDKUnsignedChannelUpdate val_conv;
11300         val_conv.inner = (void*)(val & (~1));
11301         val_conv.is_owned = (val & 1) || (val == 0);
11302         val_conv = UnsignedChannelUpdate_clone(&val_conv);
11303         ChannelUpdate_set_contents(&this_ptr_conv, val_conv);
11304 }
11305
11306 uint32_t  __attribute__((visibility("default"))) TS_ChannelUpdate_new(int8_tArray signature_arg, uint32_t contents_arg) {
11307         LDKSignature signature_arg_ref;
11308         CHECK(*((uint32_t*)signature_arg) == 64);
11309         memcpy(signature_arg_ref.compact_form, (uint8_t*)(signature_arg + 4), 64);
11310         LDKUnsignedChannelUpdate contents_arg_conv;
11311         contents_arg_conv.inner = (void*)(contents_arg & (~1));
11312         contents_arg_conv.is_owned = (contents_arg & 1) || (contents_arg == 0);
11313         contents_arg_conv = UnsignedChannelUpdate_clone(&contents_arg_conv);
11314         LDKChannelUpdate ret_var = ChannelUpdate_new(signature_arg_ref, contents_arg_conv);
11315         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11316         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11317         long ret_ref = (long)ret_var.inner;
11318         if (ret_var.is_owned) {
11319                 ret_ref |= 1;
11320         }
11321         return ret_ref;
11322 }
11323
11324 void  __attribute__((visibility("default"))) TS_QueryChannelRange_free(uint32_t this_ptr) {
11325         LDKQueryChannelRange this_ptr_conv;
11326         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11327         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
11328         QueryChannelRange_free(this_ptr_conv);
11329 }
11330
11331 uint32_t  __attribute__((visibility("default"))) TS_QueryChannelRange_clone(uint32_t orig) {
11332         LDKQueryChannelRange orig_conv;
11333         orig_conv.inner = (void*)(orig & (~1));
11334         orig_conv.is_owned = false;
11335         LDKQueryChannelRange ret_var = QueryChannelRange_clone(&orig_conv);
11336         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11337         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11338         long ret_ref = (long)ret_var.inner;
11339         if (ret_var.is_owned) {
11340                 ret_ref |= 1;
11341         }
11342         return ret_ref;
11343 }
11344
11345 int8_tArray  __attribute__((visibility("default"))) TS_QueryChannelRange_get_chain_hash(uint32_t this_ptr) {
11346         LDKQueryChannelRange this_ptr_conv;
11347         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11348         this_ptr_conv.is_owned = false;
11349         int8_tArray ret_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
11350         memcpy((uint8_t*)(ret_arr + 4), *QueryChannelRange_get_chain_hash(&this_ptr_conv), 32);
11351         return ret_arr;
11352 }
11353
11354 void  __attribute__((visibility("default"))) TS_QueryChannelRange_set_chain_hash(uint32_t this_ptr, int8_tArray val) {
11355         LDKQueryChannelRange this_ptr_conv;
11356         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11357         this_ptr_conv.is_owned = false;
11358         LDKThirtyTwoBytes val_ref;
11359         CHECK(*((uint32_t*)val) == 32);
11360         memcpy(val_ref.data, (uint8_t*)(val + 4), 32);
11361         QueryChannelRange_set_chain_hash(&this_ptr_conv, val_ref);
11362 }
11363
11364 int32_t  __attribute__((visibility("default"))) TS_QueryChannelRange_get_first_blocknum(uint32_t this_ptr) {
11365         LDKQueryChannelRange this_ptr_conv;
11366         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11367         this_ptr_conv.is_owned = false;
11368         int32_t ret_val = QueryChannelRange_get_first_blocknum(&this_ptr_conv);
11369         return ret_val;
11370 }
11371
11372 void  __attribute__((visibility("default"))) TS_QueryChannelRange_set_first_blocknum(uint32_t this_ptr, int32_t val) {
11373         LDKQueryChannelRange this_ptr_conv;
11374         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11375         this_ptr_conv.is_owned = false;
11376         QueryChannelRange_set_first_blocknum(&this_ptr_conv, val);
11377 }
11378
11379 int32_t  __attribute__((visibility("default"))) TS_QueryChannelRange_get_number_of_blocks(uint32_t this_ptr) {
11380         LDKQueryChannelRange this_ptr_conv;
11381         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11382         this_ptr_conv.is_owned = false;
11383         int32_t ret_val = QueryChannelRange_get_number_of_blocks(&this_ptr_conv);
11384         return ret_val;
11385 }
11386
11387 void  __attribute__((visibility("default"))) TS_QueryChannelRange_set_number_of_blocks(uint32_t this_ptr, int32_t val) {
11388         LDKQueryChannelRange this_ptr_conv;
11389         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11390         this_ptr_conv.is_owned = false;
11391         QueryChannelRange_set_number_of_blocks(&this_ptr_conv, val);
11392 }
11393
11394 uint32_t  __attribute__((visibility("default"))) TS_QueryChannelRange_new(int8_tArray chain_hash_arg, int32_t first_blocknum_arg, int32_t number_of_blocks_arg) {
11395         LDKThirtyTwoBytes chain_hash_arg_ref;
11396         CHECK(*((uint32_t*)chain_hash_arg) == 32);
11397         memcpy(chain_hash_arg_ref.data, (uint8_t*)(chain_hash_arg + 4), 32);
11398         LDKQueryChannelRange ret_var = QueryChannelRange_new(chain_hash_arg_ref, first_blocknum_arg, number_of_blocks_arg);
11399         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11400         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11401         long ret_ref = (long)ret_var.inner;
11402         if (ret_var.is_owned) {
11403                 ret_ref |= 1;
11404         }
11405         return ret_ref;
11406 }
11407
11408 void  __attribute__((visibility("default"))) TS_ReplyChannelRange_free(uint32_t this_ptr) {
11409         LDKReplyChannelRange this_ptr_conv;
11410         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11411         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
11412         ReplyChannelRange_free(this_ptr_conv);
11413 }
11414
11415 uint32_t  __attribute__((visibility("default"))) TS_ReplyChannelRange_clone(uint32_t orig) {
11416         LDKReplyChannelRange orig_conv;
11417         orig_conv.inner = (void*)(orig & (~1));
11418         orig_conv.is_owned = false;
11419         LDKReplyChannelRange ret_var = ReplyChannelRange_clone(&orig_conv);
11420         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11421         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11422         long ret_ref = (long)ret_var.inner;
11423         if (ret_var.is_owned) {
11424                 ret_ref |= 1;
11425         }
11426         return ret_ref;
11427 }
11428
11429 int8_tArray  __attribute__((visibility("default"))) TS_ReplyChannelRange_get_chain_hash(uint32_t this_ptr) {
11430         LDKReplyChannelRange this_ptr_conv;
11431         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11432         this_ptr_conv.is_owned = false;
11433         int8_tArray ret_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
11434         memcpy((uint8_t*)(ret_arr + 4), *ReplyChannelRange_get_chain_hash(&this_ptr_conv), 32);
11435         return ret_arr;
11436 }
11437
11438 void  __attribute__((visibility("default"))) TS_ReplyChannelRange_set_chain_hash(uint32_t this_ptr, int8_tArray val) {
11439         LDKReplyChannelRange this_ptr_conv;
11440         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11441         this_ptr_conv.is_owned = false;
11442         LDKThirtyTwoBytes val_ref;
11443         CHECK(*((uint32_t*)val) == 32);
11444         memcpy(val_ref.data, (uint8_t*)(val + 4), 32);
11445         ReplyChannelRange_set_chain_hash(&this_ptr_conv, val_ref);
11446 }
11447
11448 int32_t  __attribute__((visibility("default"))) TS_ReplyChannelRange_get_first_blocknum(uint32_t this_ptr) {
11449         LDKReplyChannelRange this_ptr_conv;
11450         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11451         this_ptr_conv.is_owned = false;
11452         int32_t ret_val = ReplyChannelRange_get_first_blocknum(&this_ptr_conv);
11453         return ret_val;
11454 }
11455
11456 void  __attribute__((visibility("default"))) TS_ReplyChannelRange_set_first_blocknum(uint32_t this_ptr, int32_t val) {
11457         LDKReplyChannelRange this_ptr_conv;
11458         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11459         this_ptr_conv.is_owned = false;
11460         ReplyChannelRange_set_first_blocknum(&this_ptr_conv, val);
11461 }
11462
11463 int32_t  __attribute__((visibility("default"))) TS_ReplyChannelRange_get_number_of_blocks(uint32_t this_ptr) {
11464         LDKReplyChannelRange this_ptr_conv;
11465         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11466         this_ptr_conv.is_owned = false;
11467         int32_t ret_val = ReplyChannelRange_get_number_of_blocks(&this_ptr_conv);
11468         return ret_val;
11469 }
11470
11471 void  __attribute__((visibility("default"))) TS_ReplyChannelRange_set_number_of_blocks(uint32_t this_ptr, int32_t val) {
11472         LDKReplyChannelRange this_ptr_conv;
11473         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11474         this_ptr_conv.is_owned = false;
11475         ReplyChannelRange_set_number_of_blocks(&this_ptr_conv, val);
11476 }
11477
11478 jboolean  __attribute__((visibility("default"))) TS_ReplyChannelRange_get_full_information(uint32_t this_ptr) {
11479         LDKReplyChannelRange this_ptr_conv;
11480         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11481         this_ptr_conv.is_owned = false;
11482         jboolean ret_val = ReplyChannelRange_get_full_information(&this_ptr_conv);
11483         return ret_val;
11484 }
11485
11486 void  __attribute__((visibility("default"))) TS_ReplyChannelRange_set_full_information(uint32_t this_ptr, jboolean val) {
11487         LDKReplyChannelRange this_ptr_conv;
11488         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11489         this_ptr_conv.is_owned = false;
11490         ReplyChannelRange_set_full_information(&this_ptr_conv, val);
11491 }
11492
11493 void  __attribute__((visibility("default"))) TS_ReplyChannelRange_set_short_channel_ids(uint32_t this_ptr, int64_tArray val) {
11494         LDKReplyChannelRange this_ptr_conv;
11495         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11496         this_ptr_conv.is_owned = false;
11497         LDKCVec_u64Z val_constr;
11498         val_constr.datalen = *((uint32_t*)val);
11499         if (val_constr.datalen > 0)
11500                 val_constr.data = MALLOC(val_constr.datalen * sizeof(int64_t), "LDKCVec_u64Z Elements");
11501         else
11502                 val_constr.data = NULL;
11503         int64_t* val_vals = (int64_t*)(val + 4);
11504         for (size_t i = 0; i < val_constr.datalen; i++) {
11505                 int64_t arr_conv_8 = val_vals[i];
11506                 val_constr.data[i] = arr_conv_8;
11507         }
11508         ReplyChannelRange_set_short_channel_ids(&this_ptr_conv, val_constr);
11509 }
11510
11511 uint32_t  __attribute__((visibility("default"))) 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) {
11512         LDKThirtyTwoBytes chain_hash_arg_ref;
11513         CHECK(*((uint32_t*)chain_hash_arg) == 32);
11514         memcpy(chain_hash_arg_ref.data, (uint8_t*)(chain_hash_arg + 4), 32);
11515         LDKCVec_u64Z short_channel_ids_arg_constr;
11516         short_channel_ids_arg_constr.datalen = *((uint32_t*)short_channel_ids_arg);
11517         if (short_channel_ids_arg_constr.datalen > 0)
11518                 short_channel_ids_arg_constr.data = MALLOC(short_channel_ids_arg_constr.datalen * sizeof(int64_t), "LDKCVec_u64Z Elements");
11519         else
11520                 short_channel_ids_arg_constr.data = NULL;
11521         int64_t* short_channel_ids_arg_vals = (int64_t*)(short_channel_ids_arg + 4);
11522         for (size_t i = 0; i < short_channel_ids_arg_constr.datalen; i++) {
11523                 int64_t arr_conv_8 = short_channel_ids_arg_vals[i];
11524                 short_channel_ids_arg_constr.data[i] = arr_conv_8;
11525         }
11526         LDKReplyChannelRange ret_var = ReplyChannelRange_new(chain_hash_arg_ref, first_blocknum_arg, number_of_blocks_arg, full_information_arg, short_channel_ids_arg_constr);
11527         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11528         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11529         long ret_ref = (long)ret_var.inner;
11530         if (ret_var.is_owned) {
11531                 ret_ref |= 1;
11532         }
11533         return ret_ref;
11534 }
11535
11536 void  __attribute__((visibility("default"))) TS_QueryShortChannelIds_free(uint32_t this_ptr) {
11537         LDKQueryShortChannelIds this_ptr_conv;
11538         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11539         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
11540         QueryShortChannelIds_free(this_ptr_conv);
11541 }
11542
11543 uint32_t  __attribute__((visibility("default"))) TS_QueryShortChannelIds_clone(uint32_t orig) {
11544         LDKQueryShortChannelIds orig_conv;
11545         orig_conv.inner = (void*)(orig & (~1));
11546         orig_conv.is_owned = false;
11547         LDKQueryShortChannelIds ret_var = QueryShortChannelIds_clone(&orig_conv);
11548         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11549         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11550         long ret_ref = (long)ret_var.inner;
11551         if (ret_var.is_owned) {
11552                 ret_ref |= 1;
11553         }
11554         return ret_ref;
11555 }
11556
11557 int8_tArray  __attribute__((visibility("default"))) TS_QueryShortChannelIds_get_chain_hash(uint32_t this_ptr) {
11558         LDKQueryShortChannelIds this_ptr_conv;
11559         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11560         this_ptr_conv.is_owned = false;
11561         int8_tArray ret_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
11562         memcpy((uint8_t*)(ret_arr + 4), *QueryShortChannelIds_get_chain_hash(&this_ptr_conv), 32);
11563         return ret_arr;
11564 }
11565
11566 void  __attribute__((visibility("default"))) TS_QueryShortChannelIds_set_chain_hash(uint32_t this_ptr, int8_tArray val) {
11567         LDKQueryShortChannelIds this_ptr_conv;
11568         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11569         this_ptr_conv.is_owned = false;
11570         LDKThirtyTwoBytes val_ref;
11571         CHECK(*((uint32_t*)val) == 32);
11572         memcpy(val_ref.data, (uint8_t*)(val + 4), 32);
11573         QueryShortChannelIds_set_chain_hash(&this_ptr_conv, val_ref);
11574 }
11575
11576 void  __attribute__((visibility("default"))) TS_QueryShortChannelIds_set_short_channel_ids(uint32_t this_ptr, int64_tArray val) {
11577         LDKQueryShortChannelIds this_ptr_conv;
11578         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11579         this_ptr_conv.is_owned = false;
11580         LDKCVec_u64Z val_constr;
11581         val_constr.datalen = *((uint32_t*)val);
11582         if (val_constr.datalen > 0)
11583                 val_constr.data = MALLOC(val_constr.datalen * sizeof(int64_t), "LDKCVec_u64Z Elements");
11584         else
11585                 val_constr.data = NULL;
11586         int64_t* val_vals = (int64_t*)(val + 4);
11587         for (size_t i = 0; i < val_constr.datalen; i++) {
11588                 int64_t arr_conv_8 = val_vals[i];
11589                 val_constr.data[i] = arr_conv_8;
11590         }
11591         QueryShortChannelIds_set_short_channel_ids(&this_ptr_conv, val_constr);
11592 }
11593
11594 uint32_t  __attribute__((visibility("default"))) TS_QueryShortChannelIds_new(int8_tArray chain_hash_arg, int64_tArray short_channel_ids_arg) {
11595         LDKThirtyTwoBytes chain_hash_arg_ref;
11596         CHECK(*((uint32_t*)chain_hash_arg) == 32);
11597         memcpy(chain_hash_arg_ref.data, (uint8_t*)(chain_hash_arg + 4), 32);
11598         LDKCVec_u64Z short_channel_ids_arg_constr;
11599         short_channel_ids_arg_constr.datalen = *((uint32_t*)short_channel_ids_arg);
11600         if (short_channel_ids_arg_constr.datalen > 0)
11601                 short_channel_ids_arg_constr.data = MALLOC(short_channel_ids_arg_constr.datalen * sizeof(int64_t), "LDKCVec_u64Z Elements");
11602         else
11603                 short_channel_ids_arg_constr.data = NULL;
11604         int64_t* short_channel_ids_arg_vals = (int64_t*)(short_channel_ids_arg + 4);
11605         for (size_t i = 0; i < short_channel_ids_arg_constr.datalen; i++) {
11606                 int64_t arr_conv_8 = short_channel_ids_arg_vals[i];
11607                 short_channel_ids_arg_constr.data[i] = arr_conv_8;
11608         }
11609         LDKQueryShortChannelIds ret_var = QueryShortChannelIds_new(chain_hash_arg_ref, short_channel_ids_arg_constr);
11610         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11611         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11612         long ret_ref = (long)ret_var.inner;
11613         if (ret_var.is_owned) {
11614                 ret_ref |= 1;
11615         }
11616         return ret_ref;
11617 }
11618
11619 void  __attribute__((visibility("default"))) TS_ReplyShortChannelIdsEnd_free(uint32_t this_ptr) {
11620         LDKReplyShortChannelIdsEnd this_ptr_conv;
11621         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11622         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
11623         ReplyShortChannelIdsEnd_free(this_ptr_conv);
11624 }
11625
11626 uint32_t  __attribute__((visibility("default"))) TS_ReplyShortChannelIdsEnd_clone(uint32_t orig) {
11627         LDKReplyShortChannelIdsEnd orig_conv;
11628         orig_conv.inner = (void*)(orig & (~1));
11629         orig_conv.is_owned = false;
11630         LDKReplyShortChannelIdsEnd ret_var = ReplyShortChannelIdsEnd_clone(&orig_conv);
11631         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11632         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11633         long ret_ref = (long)ret_var.inner;
11634         if (ret_var.is_owned) {
11635                 ret_ref |= 1;
11636         }
11637         return ret_ref;
11638 }
11639
11640 int8_tArray  __attribute__((visibility("default"))) TS_ReplyShortChannelIdsEnd_get_chain_hash(uint32_t this_ptr) {
11641         LDKReplyShortChannelIdsEnd this_ptr_conv;
11642         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11643         this_ptr_conv.is_owned = false;
11644         int8_tArray ret_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
11645         memcpy((uint8_t*)(ret_arr + 4), *ReplyShortChannelIdsEnd_get_chain_hash(&this_ptr_conv), 32);
11646         return ret_arr;
11647 }
11648
11649 void  __attribute__((visibility("default"))) TS_ReplyShortChannelIdsEnd_set_chain_hash(uint32_t this_ptr, int8_tArray val) {
11650         LDKReplyShortChannelIdsEnd this_ptr_conv;
11651         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11652         this_ptr_conv.is_owned = false;
11653         LDKThirtyTwoBytes val_ref;
11654         CHECK(*((uint32_t*)val) == 32);
11655         memcpy(val_ref.data, (uint8_t*)(val + 4), 32);
11656         ReplyShortChannelIdsEnd_set_chain_hash(&this_ptr_conv, val_ref);
11657 }
11658
11659 jboolean  __attribute__((visibility("default"))) TS_ReplyShortChannelIdsEnd_get_full_information(uint32_t this_ptr) {
11660         LDKReplyShortChannelIdsEnd this_ptr_conv;
11661         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11662         this_ptr_conv.is_owned = false;
11663         jboolean ret_val = ReplyShortChannelIdsEnd_get_full_information(&this_ptr_conv);
11664         return ret_val;
11665 }
11666
11667 void  __attribute__((visibility("default"))) TS_ReplyShortChannelIdsEnd_set_full_information(uint32_t this_ptr, jboolean val) {
11668         LDKReplyShortChannelIdsEnd this_ptr_conv;
11669         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11670         this_ptr_conv.is_owned = false;
11671         ReplyShortChannelIdsEnd_set_full_information(&this_ptr_conv, val);
11672 }
11673
11674 uint32_t  __attribute__((visibility("default"))) TS_ReplyShortChannelIdsEnd_new(int8_tArray chain_hash_arg, jboolean full_information_arg) {
11675         LDKThirtyTwoBytes chain_hash_arg_ref;
11676         CHECK(*((uint32_t*)chain_hash_arg) == 32);
11677         memcpy(chain_hash_arg_ref.data, (uint8_t*)(chain_hash_arg + 4), 32);
11678         LDKReplyShortChannelIdsEnd ret_var = ReplyShortChannelIdsEnd_new(chain_hash_arg_ref, full_information_arg);
11679         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11680         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11681         long ret_ref = (long)ret_var.inner;
11682         if (ret_var.is_owned) {
11683                 ret_ref |= 1;
11684         }
11685         return ret_ref;
11686 }
11687
11688 void  __attribute__((visibility("default"))) TS_GossipTimestampFilter_free(uint32_t this_ptr) {
11689         LDKGossipTimestampFilter this_ptr_conv;
11690         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11691         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
11692         GossipTimestampFilter_free(this_ptr_conv);
11693 }
11694
11695 uint32_t  __attribute__((visibility("default"))) TS_GossipTimestampFilter_clone(uint32_t orig) {
11696         LDKGossipTimestampFilter orig_conv;
11697         orig_conv.inner = (void*)(orig & (~1));
11698         orig_conv.is_owned = false;
11699         LDKGossipTimestampFilter ret_var = GossipTimestampFilter_clone(&orig_conv);
11700         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11701         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11702         long ret_ref = (long)ret_var.inner;
11703         if (ret_var.is_owned) {
11704                 ret_ref |= 1;
11705         }
11706         return ret_ref;
11707 }
11708
11709 int8_tArray  __attribute__((visibility("default"))) TS_GossipTimestampFilter_get_chain_hash(uint32_t this_ptr) {
11710         LDKGossipTimestampFilter this_ptr_conv;
11711         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11712         this_ptr_conv.is_owned = false;
11713         int8_tArray ret_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
11714         memcpy((uint8_t*)(ret_arr + 4), *GossipTimestampFilter_get_chain_hash(&this_ptr_conv), 32);
11715         return ret_arr;
11716 }
11717
11718 void  __attribute__((visibility("default"))) TS_GossipTimestampFilter_set_chain_hash(uint32_t this_ptr, int8_tArray val) {
11719         LDKGossipTimestampFilter this_ptr_conv;
11720         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11721         this_ptr_conv.is_owned = false;
11722         LDKThirtyTwoBytes val_ref;
11723         CHECK(*((uint32_t*)val) == 32);
11724         memcpy(val_ref.data, (uint8_t*)(val + 4), 32);
11725         GossipTimestampFilter_set_chain_hash(&this_ptr_conv, val_ref);
11726 }
11727
11728 int32_t  __attribute__((visibility("default"))) TS_GossipTimestampFilter_get_first_timestamp(uint32_t this_ptr) {
11729         LDKGossipTimestampFilter this_ptr_conv;
11730         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11731         this_ptr_conv.is_owned = false;
11732         int32_t ret_val = GossipTimestampFilter_get_first_timestamp(&this_ptr_conv);
11733         return ret_val;
11734 }
11735
11736 void  __attribute__((visibility("default"))) TS_GossipTimestampFilter_set_first_timestamp(uint32_t this_ptr, int32_t val) {
11737         LDKGossipTimestampFilter this_ptr_conv;
11738         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11739         this_ptr_conv.is_owned = false;
11740         GossipTimestampFilter_set_first_timestamp(&this_ptr_conv, val);
11741 }
11742
11743 int32_t  __attribute__((visibility("default"))) TS_GossipTimestampFilter_get_timestamp_range(uint32_t this_ptr) {
11744         LDKGossipTimestampFilter this_ptr_conv;
11745         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11746         this_ptr_conv.is_owned = false;
11747         int32_t ret_val = GossipTimestampFilter_get_timestamp_range(&this_ptr_conv);
11748         return ret_val;
11749 }
11750
11751 void  __attribute__((visibility("default"))) TS_GossipTimestampFilter_set_timestamp_range(uint32_t this_ptr, int32_t val) {
11752         LDKGossipTimestampFilter this_ptr_conv;
11753         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11754         this_ptr_conv.is_owned = false;
11755         GossipTimestampFilter_set_timestamp_range(&this_ptr_conv, val);
11756 }
11757
11758 uint32_t  __attribute__((visibility("default"))) TS_GossipTimestampFilter_new(int8_tArray chain_hash_arg, int32_t first_timestamp_arg, int32_t timestamp_range_arg) {
11759         LDKThirtyTwoBytes chain_hash_arg_ref;
11760         CHECK(*((uint32_t*)chain_hash_arg) == 32);
11761         memcpy(chain_hash_arg_ref.data, (uint8_t*)(chain_hash_arg + 4), 32);
11762         LDKGossipTimestampFilter ret_var = GossipTimestampFilter_new(chain_hash_arg_ref, first_timestamp_arg, timestamp_range_arg);
11763         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11764         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11765         long ret_ref = (long)ret_var.inner;
11766         if (ret_var.is_owned) {
11767                 ret_ref |= 1;
11768         }
11769         return ret_ref;
11770 }
11771
11772 void  __attribute__((visibility("default"))) TS_ErrorAction_free(uint32_t this_ptr) {
11773         if ((this_ptr & 1) != 0) return;
11774         LDKErrorAction this_ptr_conv = *(LDKErrorAction*)(((uint64_t)this_ptr) & ~1);
11775         FREE((void*)this_ptr);
11776         ErrorAction_free(this_ptr_conv);
11777 }
11778
11779 uint32_t  __attribute__((visibility("default"))) TS_ErrorAction_clone(uint32_t orig) {
11780         LDKErrorAction* orig_conv = (LDKErrorAction*)orig;
11781         LDKErrorAction *ret_copy = MALLOC(sizeof(LDKErrorAction), "LDKErrorAction");
11782         *ret_copy = ErrorAction_clone(orig_conv);
11783         long ret_ref = (long)ret_copy;
11784         return ret_ref;
11785 }
11786
11787 void  __attribute__((visibility("default"))) TS_LightningError_free(uint32_t this_ptr) {
11788         LDKLightningError this_ptr_conv;
11789         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11790         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
11791         LightningError_free(this_ptr_conv);
11792 }
11793
11794 uint32_t  __attribute__((visibility("default"))) TS_LightningError_clone(uint32_t orig) {
11795         LDKLightningError orig_conv;
11796         orig_conv.inner = (void*)(orig & (~1));
11797         orig_conv.is_owned = false;
11798         LDKLightningError ret_var = LightningError_clone(&orig_conv);
11799         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11800         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11801         long ret_ref = (long)ret_var.inner;
11802         if (ret_var.is_owned) {
11803                 ret_ref |= 1;
11804         }
11805         return ret_ref;
11806 }
11807
11808 jstring  __attribute__((visibility("default"))) TS_LightningError_get_err(uint32_t this_ptr) {
11809         LDKLightningError this_ptr_conv;
11810         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11811         this_ptr_conv.is_owned = false;
11812         LDKStr _str = LightningError_get_err(&this_ptr_conv);
11813         jstring _conv = str_ref_to_ts(_str.chars, _str.len);
11814         return _conv;
11815 }
11816
11817 void  __attribute__((visibility("default"))) TS_LightningError_set_err(uint32_t this_ptr, int8_tArray val) {
11818         LDKLightningError this_ptr_conv;
11819         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11820         this_ptr_conv.is_owned = false;
11821         LDKCVec_u8Z val_ref;
11822         val_ref.datalen = *((uint32_t*)val);
11823         val_ref.data = MALLOC(val_ref.datalen, "LDKCVec_u8Z Bytes");
11824         memcpy(val_ref.data, (uint8_t*)(val + 4), val_ref.datalen);
11825         LightningError_set_err(&this_ptr_conv, val_ref);
11826 }
11827
11828 uint32_t  __attribute__((visibility("default"))) TS_LightningError_get_action(uint32_t this_ptr) {
11829         LDKLightningError this_ptr_conv;
11830         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11831         this_ptr_conv.is_owned = false;
11832         LDKErrorAction *ret_copy = MALLOC(sizeof(LDKErrorAction), "LDKErrorAction");
11833         *ret_copy = LightningError_get_action(&this_ptr_conv);
11834         long ret_ref = (long)ret_copy;
11835         return ret_ref;
11836 }
11837
11838 void  __attribute__((visibility("default"))) TS_LightningError_set_action(uint32_t this_ptr, uint32_t val) {
11839         LDKLightningError this_ptr_conv;
11840         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11841         this_ptr_conv.is_owned = false;
11842         LDKErrorAction val_conv = *(LDKErrorAction*)(((uint64_t)val) & ~1);
11843         FREE((void*)val);
11844         LightningError_set_action(&this_ptr_conv, val_conv);
11845 }
11846
11847 uint32_t  __attribute__((visibility("default"))) TS_LightningError_new(int8_tArray err_arg, uint32_t action_arg) {
11848         LDKCVec_u8Z err_arg_ref;
11849         err_arg_ref.datalen = *((uint32_t*)err_arg);
11850         err_arg_ref.data = MALLOC(err_arg_ref.datalen, "LDKCVec_u8Z Bytes");
11851         memcpy(err_arg_ref.data, (uint8_t*)(err_arg + 4), err_arg_ref.datalen);
11852         LDKErrorAction action_arg_conv = *(LDKErrorAction*)(((uint64_t)action_arg) & ~1);
11853         FREE((void*)action_arg);
11854         LDKLightningError ret_var = LightningError_new(err_arg_ref, action_arg_conv);
11855         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11856         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11857         long ret_ref = (long)ret_var.inner;
11858         if (ret_var.is_owned) {
11859                 ret_ref |= 1;
11860         }
11861         return ret_ref;
11862 }
11863
11864 void  __attribute__((visibility("default"))) TS_CommitmentUpdate_free(uint32_t this_ptr) {
11865         LDKCommitmentUpdate this_ptr_conv;
11866         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11867         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
11868         CommitmentUpdate_free(this_ptr_conv);
11869 }
11870
11871 uint32_t  __attribute__((visibility("default"))) TS_CommitmentUpdate_clone(uint32_t orig) {
11872         LDKCommitmentUpdate orig_conv;
11873         orig_conv.inner = (void*)(orig & (~1));
11874         orig_conv.is_owned = false;
11875         LDKCommitmentUpdate ret_var = CommitmentUpdate_clone(&orig_conv);
11876         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11877         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11878         long ret_ref = (long)ret_var.inner;
11879         if (ret_var.is_owned) {
11880                 ret_ref |= 1;
11881         }
11882         return ret_ref;
11883 }
11884
11885 void  __attribute__((visibility("default"))) TS_CommitmentUpdate_set_update_add_htlcs(uint32_t this_ptr, uint32_tArray val) {
11886         LDKCommitmentUpdate this_ptr_conv;
11887         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11888         this_ptr_conv.is_owned = false;
11889         LDKCVec_UpdateAddHTLCZ val_constr;
11890         val_constr.datalen = *((uint32_t*)val);
11891         if (val_constr.datalen > 0)
11892                 val_constr.data = MALLOC(val_constr.datalen * sizeof(LDKUpdateAddHTLC), "LDKCVec_UpdateAddHTLCZ Elements");
11893         else
11894                 val_constr.data = NULL;
11895         uint32_t* val_vals = (uint32_t*)(val + 4);
11896         for (size_t p = 0; p < val_constr.datalen; p++) {
11897                 uint32_t arr_conv_15 = val_vals[p];
11898                 LDKUpdateAddHTLC arr_conv_15_conv;
11899                 arr_conv_15_conv.inner = (void*)(arr_conv_15 & (~1));
11900                 arr_conv_15_conv.is_owned = (arr_conv_15 & 1) || (arr_conv_15 == 0);
11901                 arr_conv_15_conv = UpdateAddHTLC_clone(&arr_conv_15_conv);
11902                 val_constr.data[p] = arr_conv_15_conv;
11903         }
11904         CommitmentUpdate_set_update_add_htlcs(&this_ptr_conv, val_constr);
11905 }
11906
11907 void  __attribute__((visibility("default"))) TS_CommitmentUpdate_set_update_fulfill_htlcs(uint32_t this_ptr, uint32_tArray val) {
11908         LDKCommitmentUpdate this_ptr_conv;
11909         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11910         this_ptr_conv.is_owned = false;
11911         LDKCVec_UpdateFulfillHTLCZ val_constr;
11912         val_constr.datalen = *((uint32_t*)val);
11913         if (val_constr.datalen > 0)
11914                 val_constr.data = MALLOC(val_constr.datalen * sizeof(LDKUpdateFulfillHTLC), "LDKCVec_UpdateFulfillHTLCZ Elements");
11915         else
11916                 val_constr.data = NULL;
11917         uint32_t* val_vals = (uint32_t*)(val + 4);
11918         for (size_t t = 0; t < val_constr.datalen; t++) {
11919                 uint32_t arr_conv_19 = val_vals[t];
11920                 LDKUpdateFulfillHTLC arr_conv_19_conv;
11921                 arr_conv_19_conv.inner = (void*)(arr_conv_19 & (~1));
11922                 arr_conv_19_conv.is_owned = (arr_conv_19 & 1) || (arr_conv_19 == 0);
11923                 arr_conv_19_conv = UpdateFulfillHTLC_clone(&arr_conv_19_conv);
11924                 val_constr.data[t] = arr_conv_19_conv;
11925         }
11926         CommitmentUpdate_set_update_fulfill_htlcs(&this_ptr_conv, val_constr);
11927 }
11928
11929 void  __attribute__((visibility("default"))) TS_CommitmentUpdate_set_update_fail_htlcs(uint32_t this_ptr, uint32_tArray val) {
11930         LDKCommitmentUpdate this_ptr_conv;
11931         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11932         this_ptr_conv.is_owned = false;
11933         LDKCVec_UpdateFailHTLCZ val_constr;
11934         val_constr.datalen = *((uint32_t*)val);
11935         if (val_constr.datalen > 0)
11936                 val_constr.data = MALLOC(val_constr.datalen * sizeof(LDKUpdateFailHTLC), "LDKCVec_UpdateFailHTLCZ Elements");
11937         else
11938                 val_constr.data = NULL;
11939         uint32_t* val_vals = (uint32_t*)(val + 4);
11940         for (size_t q = 0; q < val_constr.datalen; q++) {
11941                 uint32_t arr_conv_16 = val_vals[q];
11942                 LDKUpdateFailHTLC arr_conv_16_conv;
11943                 arr_conv_16_conv.inner = (void*)(arr_conv_16 & (~1));
11944                 arr_conv_16_conv.is_owned = (arr_conv_16 & 1) || (arr_conv_16 == 0);
11945                 arr_conv_16_conv = UpdateFailHTLC_clone(&arr_conv_16_conv);
11946                 val_constr.data[q] = arr_conv_16_conv;
11947         }
11948         CommitmentUpdate_set_update_fail_htlcs(&this_ptr_conv, val_constr);
11949 }
11950
11951 void  __attribute__((visibility("default"))) TS_CommitmentUpdate_set_update_fail_malformed_htlcs(uint32_t this_ptr, uint32_tArray val) {
11952         LDKCommitmentUpdate this_ptr_conv;
11953         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11954         this_ptr_conv.is_owned = false;
11955         LDKCVec_UpdateFailMalformedHTLCZ val_constr;
11956         val_constr.datalen = *((uint32_t*)val);
11957         if (val_constr.datalen > 0)
11958                 val_constr.data = MALLOC(val_constr.datalen * sizeof(LDKUpdateFailMalformedHTLC), "LDKCVec_UpdateFailMalformedHTLCZ Elements");
11959         else
11960                 val_constr.data = NULL;
11961         uint32_t* val_vals = (uint32_t*)(val + 4);
11962         for (size_t z = 0; z < val_constr.datalen; z++) {
11963                 uint32_t arr_conv_25 = val_vals[z];
11964                 LDKUpdateFailMalformedHTLC arr_conv_25_conv;
11965                 arr_conv_25_conv.inner = (void*)(arr_conv_25 & (~1));
11966                 arr_conv_25_conv.is_owned = (arr_conv_25 & 1) || (arr_conv_25 == 0);
11967                 arr_conv_25_conv = UpdateFailMalformedHTLC_clone(&arr_conv_25_conv);
11968                 val_constr.data[z] = arr_conv_25_conv;
11969         }
11970         CommitmentUpdate_set_update_fail_malformed_htlcs(&this_ptr_conv, val_constr);
11971 }
11972
11973 uint32_t  __attribute__((visibility("default"))) TS_CommitmentUpdate_get_update_fee(uint32_t this_ptr) {
11974         LDKCommitmentUpdate this_ptr_conv;
11975         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11976         this_ptr_conv.is_owned = false;
11977         LDKUpdateFee ret_var = CommitmentUpdate_get_update_fee(&this_ptr_conv);
11978         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11979         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11980         long ret_ref = (long)ret_var.inner;
11981         if (ret_var.is_owned) {
11982                 ret_ref |= 1;
11983         }
11984         return ret_ref;
11985 }
11986
11987 void  __attribute__((visibility("default"))) TS_CommitmentUpdate_set_update_fee(uint32_t this_ptr, uint32_t val) {
11988         LDKCommitmentUpdate this_ptr_conv;
11989         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11990         this_ptr_conv.is_owned = false;
11991         LDKUpdateFee val_conv;
11992         val_conv.inner = (void*)(val & (~1));
11993         val_conv.is_owned = (val & 1) || (val == 0);
11994         val_conv = UpdateFee_clone(&val_conv);
11995         CommitmentUpdate_set_update_fee(&this_ptr_conv, val_conv);
11996 }
11997
11998 uint32_t  __attribute__((visibility("default"))) TS_CommitmentUpdate_get_commitment_signed(uint32_t this_ptr) {
11999         LDKCommitmentUpdate this_ptr_conv;
12000         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12001         this_ptr_conv.is_owned = false;
12002         LDKCommitmentSigned ret_var = CommitmentUpdate_get_commitment_signed(&this_ptr_conv);
12003         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12004         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12005         long ret_ref = (long)ret_var.inner;
12006         if (ret_var.is_owned) {
12007                 ret_ref |= 1;
12008         }
12009         return ret_ref;
12010 }
12011
12012 void  __attribute__((visibility("default"))) TS_CommitmentUpdate_set_commitment_signed(uint32_t this_ptr, uint32_t val) {
12013         LDKCommitmentUpdate this_ptr_conv;
12014         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12015         this_ptr_conv.is_owned = false;
12016         LDKCommitmentSigned val_conv;
12017         val_conv.inner = (void*)(val & (~1));
12018         val_conv.is_owned = (val & 1) || (val == 0);
12019         val_conv = CommitmentSigned_clone(&val_conv);
12020         CommitmentUpdate_set_commitment_signed(&this_ptr_conv, val_conv);
12021 }
12022
12023 uint32_t  __attribute__((visibility("default"))) 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) {
12024         LDKCVec_UpdateAddHTLCZ update_add_htlcs_arg_constr;
12025         update_add_htlcs_arg_constr.datalen = *((uint32_t*)update_add_htlcs_arg);
12026         if (update_add_htlcs_arg_constr.datalen > 0)
12027                 update_add_htlcs_arg_constr.data = MALLOC(update_add_htlcs_arg_constr.datalen * sizeof(LDKUpdateAddHTLC), "LDKCVec_UpdateAddHTLCZ Elements");
12028         else
12029                 update_add_htlcs_arg_constr.data = NULL;
12030         uint32_t* update_add_htlcs_arg_vals = (uint32_t*)(update_add_htlcs_arg + 4);
12031         for (size_t p = 0; p < update_add_htlcs_arg_constr.datalen; p++) {
12032                 uint32_t arr_conv_15 = update_add_htlcs_arg_vals[p];
12033                 LDKUpdateAddHTLC arr_conv_15_conv;
12034                 arr_conv_15_conv.inner = (void*)(arr_conv_15 & (~1));
12035                 arr_conv_15_conv.is_owned = (arr_conv_15 & 1) || (arr_conv_15 == 0);
12036                 arr_conv_15_conv = UpdateAddHTLC_clone(&arr_conv_15_conv);
12037                 update_add_htlcs_arg_constr.data[p] = arr_conv_15_conv;
12038         }
12039         LDKCVec_UpdateFulfillHTLCZ update_fulfill_htlcs_arg_constr;
12040         update_fulfill_htlcs_arg_constr.datalen = *((uint32_t*)update_fulfill_htlcs_arg);
12041         if (update_fulfill_htlcs_arg_constr.datalen > 0)
12042                 update_fulfill_htlcs_arg_constr.data = MALLOC(update_fulfill_htlcs_arg_constr.datalen * sizeof(LDKUpdateFulfillHTLC), "LDKCVec_UpdateFulfillHTLCZ Elements");
12043         else
12044                 update_fulfill_htlcs_arg_constr.data = NULL;
12045         uint32_t* update_fulfill_htlcs_arg_vals = (uint32_t*)(update_fulfill_htlcs_arg + 4);
12046         for (size_t t = 0; t < update_fulfill_htlcs_arg_constr.datalen; t++) {
12047                 uint32_t arr_conv_19 = update_fulfill_htlcs_arg_vals[t];
12048                 LDKUpdateFulfillHTLC arr_conv_19_conv;
12049                 arr_conv_19_conv.inner = (void*)(arr_conv_19 & (~1));
12050                 arr_conv_19_conv.is_owned = (arr_conv_19 & 1) || (arr_conv_19 == 0);
12051                 arr_conv_19_conv = UpdateFulfillHTLC_clone(&arr_conv_19_conv);
12052                 update_fulfill_htlcs_arg_constr.data[t] = arr_conv_19_conv;
12053         }
12054         LDKCVec_UpdateFailHTLCZ update_fail_htlcs_arg_constr;
12055         update_fail_htlcs_arg_constr.datalen = *((uint32_t*)update_fail_htlcs_arg);
12056         if (update_fail_htlcs_arg_constr.datalen > 0)
12057                 update_fail_htlcs_arg_constr.data = MALLOC(update_fail_htlcs_arg_constr.datalen * sizeof(LDKUpdateFailHTLC), "LDKCVec_UpdateFailHTLCZ Elements");
12058         else
12059                 update_fail_htlcs_arg_constr.data = NULL;
12060         uint32_t* update_fail_htlcs_arg_vals = (uint32_t*)(update_fail_htlcs_arg + 4);
12061         for (size_t q = 0; q < update_fail_htlcs_arg_constr.datalen; q++) {
12062                 uint32_t arr_conv_16 = update_fail_htlcs_arg_vals[q];
12063                 LDKUpdateFailHTLC arr_conv_16_conv;
12064                 arr_conv_16_conv.inner = (void*)(arr_conv_16 & (~1));
12065                 arr_conv_16_conv.is_owned = (arr_conv_16 & 1) || (arr_conv_16 == 0);
12066                 arr_conv_16_conv = UpdateFailHTLC_clone(&arr_conv_16_conv);
12067                 update_fail_htlcs_arg_constr.data[q] = arr_conv_16_conv;
12068         }
12069         LDKCVec_UpdateFailMalformedHTLCZ update_fail_malformed_htlcs_arg_constr;
12070         update_fail_malformed_htlcs_arg_constr.datalen = *((uint32_t*)update_fail_malformed_htlcs_arg);
12071         if (update_fail_malformed_htlcs_arg_constr.datalen > 0)
12072                 update_fail_malformed_htlcs_arg_constr.data = MALLOC(update_fail_malformed_htlcs_arg_constr.datalen * sizeof(LDKUpdateFailMalformedHTLC), "LDKCVec_UpdateFailMalformedHTLCZ Elements");
12073         else
12074                 update_fail_malformed_htlcs_arg_constr.data = NULL;
12075         uint32_t* update_fail_malformed_htlcs_arg_vals = (uint32_t*)(update_fail_malformed_htlcs_arg + 4);
12076         for (size_t z = 0; z < update_fail_malformed_htlcs_arg_constr.datalen; z++) {
12077                 uint32_t arr_conv_25 = update_fail_malformed_htlcs_arg_vals[z];
12078                 LDKUpdateFailMalformedHTLC arr_conv_25_conv;
12079                 arr_conv_25_conv.inner = (void*)(arr_conv_25 & (~1));
12080                 arr_conv_25_conv.is_owned = (arr_conv_25 & 1) || (arr_conv_25 == 0);
12081                 arr_conv_25_conv = UpdateFailMalformedHTLC_clone(&arr_conv_25_conv);
12082                 update_fail_malformed_htlcs_arg_constr.data[z] = arr_conv_25_conv;
12083         }
12084         LDKUpdateFee update_fee_arg_conv;
12085         update_fee_arg_conv.inner = (void*)(update_fee_arg & (~1));
12086         update_fee_arg_conv.is_owned = (update_fee_arg & 1) || (update_fee_arg == 0);
12087         update_fee_arg_conv = UpdateFee_clone(&update_fee_arg_conv);
12088         LDKCommitmentSigned commitment_signed_arg_conv;
12089         commitment_signed_arg_conv.inner = (void*)(commitment_signed_arg & (~1));
12090         commitment_signed_arg_conv.is_owned = (commitment_signed_arg & 1) || (commitment_signed_arg == 0);
12091         commitment_signed_arg_conv = CommitmentSigned_clone(&commitment_signed_arg_conv);
12092         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);
12093         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12094         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12095         long ret_ref = (long)ret_var.inner;
12096         if (ret_var.is_owned) {
12097                 ret_ref |= 1;
12098         }
12099         return ret_ref;
12100 }
12101
12102 void  __attribute__((visibility("default"))) TS_HTLCFailChannelUpdate_free(uint32_t this_ptr) {
12103         if ((this_ptr & 1) != 0) return;
12104         LDKHTLCFailChannelUpdate this_ptr_conv = *(LDKHTLCFailChannelUpdate*)(((uint64_t)this_ptr) & ~1);
12105         FREE((void*)this_ptr);
12106         HTLCFailChannelUpdate_free(this_ptr_conv);
12107 }
12108
12109 uint32_t  __attribute__((visibility("default"))) TS_HTLCFailChannelUpdate_clone(uint32_t orig) {
12110         LDKHTLCFailChannelUpdate* orig_conv = (LDKHTLCFailChannelUpdate*)orig;
12111         LDKHTLCFailChannelUpdate *ret_copy = MALLOC(sizeof(LDKHTLCFailChannelUpdate), "LDKHTLCFailChannelUpdate");
12112         *ret_copy = HTLCFailChannelUpdate_clone(orig_conv);
12113         long ret_ref = (long)ret_copy;
12114         return ret_ref;
12115 }
12116
12117 void  __attribute__((visibility("default"))) TS_ChannelMessageHandler_free(uint32_t this_ptr) {
12118         if ((this_ptr & 1) != 0) return;
12119         LDKChannelMessageHandler this_ptr_conv = *(LDKChannelMessageHandler*)(((uint64_t)this_ptr) & ~1);
12120         FREE((void*)this_ptr);
12121         ChannelMessageHandler_free(this_ptr_conv);
12122 }
12123
12124 void  __attribute__((visibility("default"))) TS_RoutingMessageHandler_free(uint32_t this_ptr) {
12125         if ((this_ptr & 1) != 0) return;
12126         LDKRoutingMessageHandler this_ptr_conv = *(LDKRoutingMessageHandler*)(((uint64_t)this_ptr) & ~1);
12127         FREE((void*)this_ptr);
12128         RoutingMessageHandler_free(this_ptr_conv);
12129 }
12130
12131 int8_tArray  __attribute__((visibility("default"))) TS_AcceptChannel_write(uint32_t obj) {
12132         LDKAcceptChannel obj_conv;
12133         obj_conv.inner = (void*)(obj & (~1));
12134         obj_conv.is_owned = false;
12135         LDKCVec_u8Z arg_var = AcceptChannel_write(&obj_conv);
12136         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
12137         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
12138         CVec_u8Z_free(arg_var);
12139         return arg_arr;
12140 }
12141
12142 uint32_t  __attribute__((visibility("default"))) TS_AcceptChannel_read(int8_tArray ser) {
12143         LDKu8slice ser_ref;
12144         ser_ref.datalen = *((uint32_t*)ser);
12145         ser_ref.data = (int8_t*)(ser + 4);
12146         LDKAcceptChannel ret_var = AcceptChannel_read(ser_ref);
12147         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12148         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12149         long ret_ref = (long)ret_var.inner;
12150         if (ret_var.is_owned) {
12151                 ret_ref |= 1;
12152         }
12153         return ret_ref;
12154 }
12155
12156 int8_tArray  __attribute__((visibility("default"))) TS_AnnouncementSignatures_write(uint32_t obj) {
12157         LDKAnnouncementSignatures obj_conv;
12158         obj_conv.inner = (void*)(obj & (~1));
12159         obj_conv.is_owned = false;
12160         LDKCVec_u8Z arg_var = AnnouncementSignatures_write(&obj_conv);
12161         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
12162         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
12163         CVec_u8Z_free(arg_var);
12164         return arg_arr;
12165 }
12166
12167 uint32_t  __attribute__((visibility("default"))) TS_AnnouncementSignatures_read(int8_tArray ser) {
12168         LDKu8slice ser_ref;
12169         ser_ref.datalen = *((uint32_t*)ser);
12170         ser_ref.data = (int8_t*)(ser + 4);
12171         LDKAnnouncementSignatures ret_var = AnnouncementSignatures_read(ser_ref);
12172         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12173         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12174         long ret_ref = (long)ret_var.inner;
12175         if (ret_var.is_owned) {
12176                 ret_ref |= 1;
12177         }
12178         return ret_ref;
12179 }
12180
12181 int8_tArray  __attribute__((visibility("default"))) TS_ChannelReestablish_write(uint32_t obj) {
12182         LDKChannelReestablish obj_conv;
12183         obj_conv.inner = (void*)(obj & (~1));
12184         obj_conv.is_owned = false;
12185         LDKCVec_u8Z arg_var = ChannelReestablish_write(&obj_conv);
12186         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
12187         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
12188         CVec_u8Z_free(arg_var);
12189         return arg_arr;
12190 }
12191
12192 uint32_t  __attribute__((visibility("default"))) TS_ChannelReestablish_read(int8_tArray ser) {
12193         LDKu8slice ser_ref;
12194         ser_ref.datalen = *((uint32_t*)ser);
12195         ser_ref.data = (int8_t*)(ser + 4);
12196         LDKCResult_ChannelReestablishDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ChannelReestablishDecodeErrorZ), "LDKCResult_ChannelReestablishDecodeErrorZ");
12197         *ret_conv = ChannelReestablish_read(ser_ref);
12198         return (long)ret_conv;
12199 }
12200
12201 int8_tArray  __attribute__((visibility("default"))) TS_ClosingSigned_write(uint32_t obj) {
12202         LDKClosingSigned obj_conv;
12203         obj_conv.inner = (void*)(obj & (~1));
12204         obj_conv.is_owned = false;
12205         LDKCVec_u8Z arg_var = ClosingSigned_write(&obj_conv);
12206         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
12207         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
12208         CVec_u8Z_free(arg_var);
12209         return arg_arr;
12210 }
12211
12212 uint32_t  __attribute__((visibility("default"))) TS_ClosingSigned_read(int8_tArray ser) {
12213         LDKu8slice ser_ref;
12214         ser_ref.datalen = *((uint32_t*)ser);
12215         ser_ref.data = (int8_t*)(ser + 4);
12216         LDKClosingSigned ret_var = ClosingSigned_read(ser_ref);
12217         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12218         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12219         long ret_ref = (long)ret_var.inner;
12220         if (ret_var.is_owned) {
12221                 ret_ref |= 1;
12222         }
12223         return ret_ref;
12224 }
12225
12226 int8_tArray  __attribute__((visibility("default"))) TS_CommitmentSigned_write(uint32_t obj) {
12227         LDKCommitmentSigned obj_conv;
12228         obj_conv.inner = (void*)(obj & (~1));
12229         obj_conv.is_owned = false;
12230         LDKCVec_u8Z arg_var = CommitmentSigned_write(&obj_conv);
12231         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
12232         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
12233         CVec_u8Z_free(arg_var);
12234         return arg_arr;
12235 }
12236
12237 uint32_t  __attribute__((visibility("default"))) TS_CommitmentSigned_read(int8_tArray ser) {
12238         LDKu8slice ser_ref;
12239         ser_ref.datalen = *((uint32_t*)ser);
12240         ser_ref.data = (int8_t*)(ser + 4);
12241         LDKCommitmentSigned ret_var = CommitmentSigned_read(ser_ref);
12242         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12243         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12244         long ret_ref = (long)ret_var.inner;
12245         if (ret_var.is_owned) {
12246                 ret_ref |= 1;
12247         }
12248         return ret_ref;
12249 }
12250
12251 int8_tArray  __attribute__((visibility("default"))) TS_FundingCreated_write(uint32_t obj) {
12252         LDKFundingCreated obj_conv;
12253         obj_conv.inner = (void*)(obj & (~1));
12254         obj_conv.is_owned = false;
12255         LDKCVec_u8Z arg_var = FundingCreated_write(&obj_conv);
12256         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
12257         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
12258         CVec_u8Z_free(arg_var);
12259         return arg_arr;
12260 }
12261
12262 uint32_t  __attribute__((visibility("default"))) TS_FundingCreated_read(int8_tArray ser) {
12263         LDKu8slice ser_ref;
12264         ser_ref.datalen = *((uint32_t*)ser);
12265         ser_ref.data = (int8_t*)(ser + 4);
12266         LDKFundingCreated ret_var = FundingCreated_read(ser_ref);
12267         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12268         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12269         long ret_ref = (long)ret_var.inner;
12270         if (ret_var.is_owned) {
12271                 ret_ref |= 1;
12272         }
12273         return ret_ref;
12274 }
12275
12276 int8_tArray  __attribute__((visibility("default"))) TS_FundingSigned_write(uint32_t obj) {
12277         LDKFundingSigned obj_conv;
12278         obj_conv.inner = (void*)(obj & (~1));
12279         obj_conv.is_owned = false;
12280         LDKCVec_u8Z arg_var = FundingSigned_write(&obj_conv);
12281         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
12282         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
12283         CVec_u8Z_free(arg_var);
12284         return arg_arr;
12285 }
12286
12287 uint32_t  __attribute__((visibility("default"))) TS_FundingSigned_read(int8_tArray ser) {
12288         LDKu8slice ser_ref;
12289         ser_ref.datalen = *((uint32_t*)ser);
12290         ser_ref.data = (int8_t*)(ser + 4);
12291         LDKFundingSigned ret_var = FundingSigned_read(ser_ref);
12292         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12293         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12294         long ret_ref = (long)ret_var.inner;
12295         if (ret_var.is_owned) {
12296                 ret_ref |= 1;
12297         }
12298         return ret_ref;
12299 }
12300
12301 int8_tArray  __attribute__((visibility("default"))) TS_FundingLocked_write(uint32_t obj) {
12302         LDKFundingLocked obj_conv;
12303         obj_conv.inner = (void*)(obj & (~1));
12304         obj_conv.is_owned = false;
12305         LDKCVec_u8Z arg_var = FundingLocked_write(&obj_conv);
12306         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
12307         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
12308         CVec_u8Z_free(arg_var);
12309         return arg_arr;
12310 }
12311
12312 uint32_t  __attribute__((visibility("default"))) TS_FundingLocked_read(int8_tArray ser) {
12313         LDKu8slice ser_ref;
12314         ser_ref.datalen = *((uint32_t*)ser);
12315         ser_ref.data = (int8_t*)(ser + 4);
12316         LDKFundingLocked ret_var = FundingLocked_read(ser_ref);
12317         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12318         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12319         long ret_ref = (long)ret_var.inner;
12320         if (ret_var.is_owned) {
12321                 ret_ref |= 1;
12322         }
12323         return ret_ref;
12324 }
12325
12326 int8_tArray  __attribute__((visibility("default"))) TS_Init_write(uint32_t obj) {
12327         LDKInit obj_conv;
12328         obj_conv.inner = (void*)(obj & (~1));
12329         obj_conv.is_owned = false;
12330         LDKCVec_u8Z arg_var = Init_write(&obj_conv);
12331         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
12332         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
12333         CVec_u8Z_free(arg_var);
12334         return arg_arr;
12335 }
12336
12337 uint32_t  __attribute__((visibility("default"))) TS_Init_read(int8_tArray ser) {
12338         LDKu8slice ser_ref;
12339         ser_ref.datalen = *((uint32_t*)ser);
12340         ser_ref.data = (int8_t*)(ser + 4);
12341         LDKCResult_InitDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_InitDecodeErrorZ), "LDKCResult_InitDecodeErrorZ");
12342         *ret_conv = Init_read(ser_ref);
12343         return (long)ret_conv;
12344 }
12345
12346 int8_tArray  __attribute__((visibility("default"))) TS_OpenChannel_write(uint32_t obj) {
12347         LDKOpenChannel obj_conv;
12348         obj_conv.inner = (void*)(obj & (~1));
12349         obj_conv.is_owned = false;
12350         LDKCVec_u8Z arg_var = OpenChannel_write(&obj_conv);
12351         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
12352         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
12353         CVec_u8Z_free(arg_var);
12354         return arg_arr;
12355 }
12356
12357 uint32_t  __attribute__((visibility("default"))) TS_OpenChannel_read(int8_tArray ser) {
12358         LDKu8slice ser_ref;
12359         ser_ref.datalen = *((uint32_t*)ser);
12360         ser_ref.data = (int8_t*)(ser + 4);
12361         LDKOpenChannel ret_var = OpenChannel_read(ser_ref);
12362         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12363         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12364         long ret_ref = (long)ret_var.inner;
12365         if (ret_var.is_owned) {
12366                 ret_ref |= 1;
12367         }
12368         return ret_ref;
12369 }
12370
12371 int8_tArray  __attribute__((visibility("default"))) TS_RevokeAndACK_write(uint32_t obj) {
12372         LDKRevokeAndACK obj_conv;
12373         obj_conv.inner = (void*)(obj & (~1));
12374         obj_conv.is_owned = false;
12375         LDKCVec_u8Z arg_var = RevokeAndACK_write(&obj_conv);
12376         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
12377         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
12378         CVec_u8Z_free(arg_var);
12379         return arg_arr;
12380 }
12381
12382 uint32_t  __attribute__((visibility("default"))) TS_RevokeAndACK_read(int8_tArray ser) {
12383         LDKu8slice ser_ref;
12384         ser_ref.datalen = *((uint32_t*)ser);
12385         ser_ref.data = (int8_t*)(ser + 4);
12386         LDKRevokeAndACK ret_var = RevokeAndACK_read(ser_ref);
12387         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12388         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12389         long ret_ref = (long)ret_var.inner;
12390         if (ret_var.is_owned) {
12391                 ret_ref |= 1;
12392         }
12393         return ret_ref;
12394 }
12395
12396 int8_tArray  __attribute__((visibility("default"))) TS_Shutdown_write(uint32_t obj) {
12397         LDKShutdown obj_conv;
12398         obj_conv.inner = (void*)(obj & (~1));
12399         obj_conv.is_owned = false;
12400         LDKCVec_u8Z arg_var = Shutdown_write(&obj_conv);
12401         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
12402         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
12403         CVec_u8Z_free(arg_var);
12404         return arg_arr;
12405 }
12406
12407 uint32_t  __attribute__((visibility("default"))) TS_Shutdown_read(int8_tArray ser) {
12408         LDKu8slice ser_ref;
12409         ser_ref.datalen = *((uint32_t*)ser);
12410         ser_ref.data = (int8_t*)(ser + 4);
12411         LDKShutdown ret_var = Shutdown_read(ser_ref);
12412         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12413         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12414         long ret_ref = (long)ret_var.inner;
12415         if (ret_var.is_owned) {
12416                 ret_ref |= 1;
12417         }
12418         return ret_ref;
12419 }
12420
12421 int8_tArray  __attribute__((visibility("default"))) TS_UpdateFailHTLC_write(uint32_t obj) {
12422         LDKUpdateFailHTLC obj_conv;
12423         obj_conv.inner = (void*)(obj & (~1));
12424         obj_conv.is_owned = false;
12425         LDKCVec_u8Z arg_var = UpdateFailHTLC_write(&obj_conv);
12426         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
12427         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
12428         CVec_u8Z_free(arg_var);
12429         return arg_arr;
12430 }
12431
12432 uint32_t  __attribute__((visibility("default"))) TS_UpdateFailHTLC_read(int8_tArray ser) {
12433         LDKu8slice ser_ref;
12434         ser_ref.datalen = *((uint32_t*)ser);
12435         ser_ref.data = (int8_t*)(ser + 4);
12436         LDKUpdateFailHTLC ret_var = UpdateFailHTLC_read(ser_ref);
12437         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12438         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12439         long ret_ref = (long)ret_var.inner;
12440         if (ret_var.is_owned) {
12441                 ret_ref |= 1;
12442         }
12443         return ret_ref;
12444 }
12445
12446 int8_tArray  __attribute__((visibility("default"))) TS_UpdateFailMalformedHTLC_write(uint32_t obj) {
12447         LDKUpdateFailMalformedHTLC obj_conv;
12448         obj_conv.inner = (void*)(obj & (~1));
12449         obj_conv.is_owned = false;
12450         LDKCVec_u8Z arg_var = UpdateFailMalformedHTLC_write(&obj_conv);
12451         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
12452         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
12453         CVec_u8Z_free(arg_var);
12454         return arg_arr;
12455 }
12456
12457 uint32_t  __attribute__((visibility("default"))) TS_UpdateFailMalformedHTLC_read(int8_tArray ser) {
12458         LDKu8slice ser_ref;
12459         ser_ref.datalen = *((uint32_t*)ser);
12460         ser_ref.data = (int8_t*)(ser + 4);
12461         LDKUpdateFailMalformedHTLC ret_var = UpdateFailMalformedHTLC_read(ser_ref);
12462         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12463         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12464         long ret_ref = (long)ret_var.inner;
12465         if (ret_var.is_owned) {
12466                 ret_ref |= 1;
12467         }
12468         return ret_ref;
12469 }
12470
12471 int8_tArray  __attribute__((visibility("default"))) TS_UpdateFee_write(uint32_t obj) {
12472         LDKUpdateFee obj_conv;
12473         obj_conv.inner = (void*)(obj & (~1));
12474         obj_conv.is_owned = false;
12475         LDKCVec_u8Z arg_var = UpdateFee_write(&obj_conv);
12476         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
12477         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
12478         CVec_u8Z_free(arg_var);
12479         return arg_arr;
12480 }
12481
12482 uint32_t  __attribute__((visibility("default"))) TS_UpdateFee_read(int8_tArray ser) {
12483         LDKu8slice ser_ref;
12484         ser_ref.datalen = *((uint32_t*)ser);
12485         ser_ref.data = (int8_t*)(ser + 4);
12486         LDKUpdateFee ret_var = UpdateFee_read(ser_ref);
12487         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12488         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12489         long ret_ref = (long)ret_var.inner;
12490         if (ret_var.is_owned) {
12491                 ret_ref |= 1;
12492         }
12493         return ret_ref;
12494 }
12495
12496 int8_tArray  __attribute__((visibility("default"))) TS_UpdateFulfillHTLC_write(uint32_t obj) {
12497         LDKUpdateFulfillHTLC obj_conv;
12498         obj_conv.inner = (void*)(obj & (~1));
12499         obj_conv.is_owned = false;
12500         LDKCVec_u8Z arg_var = UpdateFulfillHTLC_write(&obj_conv);
12501         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
12502         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
12503         CVec_u8Z_free(arg_var);
12504         return arg_arr;
12505 }
12506
12507 uint32_t  __attribute__((visibility("default"))) TS_UpdateFulfillHTLC_read(int8_tArray ser) {
12508         LDKu8slice ser_ref;
12509         ser_ref.datalen = *((uint32_t*)ser);
12510         ser_ref.data = (int8_t*)(ser + 4);
12511         LDKUpdateFulfillHTLC ret_var = UpdateFulfillHTLC_read(ser_ref);
12512         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12513         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12514         long ret_ref = (long)ret_var.inner;
12515         if (ret_var.is_owned) {
12516                 ret_ref |= 1;
12517         }
12518         return ret_ref;
12519 }
12520
12521 int8_tArray  __attribute__((visibility("default"))) TS_UpdateAddHTLC_write(uint32_t obj) {
12522         LDKUpdateAddHTLC obj_conv;
12523         obj_conv.inner = (void*)(obj & (~1));
12524         obj_conv.is_owned = false;
12525         LDKCVec_u8Z arg_var = UpdateAddHTLC_write(&obj_conv);
12526         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
12527         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
12528         CVec_u8Z_free(arg_var);
12529         return arg_arr;
12530 }
12531
12532 uint32_t  __attribute__((visibility("default"))) TS_UpdateAddHTLC_read(int8_tArray ser) {
12533         LDKu8slice ser_ref;
12534         ser_ref.datalen = *((uint32_t*)ser);
12535         ser_ref.data = (int8_t*)(ser + 4);
12536         LDKUpdateAddHTLC ret_var = UpdateAddHTLC_read(ser_ref);
12537         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12538         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12539         long ret_ref = (long)ret_var.inner;
12540         if (ret_var.is_owned) {
12541                 ret_ref |= 1;
12542         }
12543         return ret_ref;
12544 }
12545
12546 int8_tArray  __attribute__((visibility("default"))) TS_Ping_write(uint32_t obj) {
12547         LDKPing obj_conv;
12548         obj_conv.inner = (void*)(obj & (~1));
12549         obj_conv.is_owned = false;
12550         LDKCVec_u8Z arg_var = Ping_write(&obj_conv);
12551         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
12552         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
12553         CVec_u8Z_free(arg_var);
12554         return arg_arr;
12555 }
12556
12557 uint32_t  __attribute__((visibility("default"))) TS_Ping_read(int8_tArray ser) {
12558         LDKu8slice ser_ref;
12559         ser_ref.datalen = *((uint32_t*)ser);
12560         ser_ref.data = (int8_t*)(ser + 4);
12561         LDKCResult_PingDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_PingDecodeErrorZ), "LDKCResult_PingDecodeErrorZ");
12562         *ret_conv = Ping_read(ser_ref);
12563         return (long)ret_conv;
12564 }
12565
12566 int8_tArray  __attribute__((visibility("default"))) TS_Pong_write(uint32_t obj) {
12567         LDKPong obj_conv;
12568         obj_conv.inner = (void*)(obj & (~1));
12569         obj_conv.is_owned = false;
12570         LDKCVec_u8Z arg_var = Pong_write(&obj_conv);
12571         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
12572         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
12573         CVec_u8Z_free(arg_var);
12574         return arg_arr;
12575 }
12576
12577 uint32_t  __attribute__((visibility("default"))) TS_Pong_read(int8_tArray ser) {
12578         LDKu8slice ser_ref;
12579         ser_ref.datalen = *((uint32_t*)ser);
12580         ser_ref.data = (int8_t*)(ser + 4);
12581         LDKCResult_PongDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_PongDecodeErrorZ), "LDKCResult_PongDecodeErrorZ");
12582         *ret_conv = Pong_read(ser_ref);
12583         return (long)ret_conv;
12584 }
12585
12586 int8_tArray  __attribute__((visibility("default"))) TS_UnsignedChannelAnnouncement_write(uint32_t obj) {
12587         LDKUnsignedChannelAnnouncement obj_conv;
12588         obj_conv.inner = (void*)(obj & (~1));
12589         obj_conv.is_owned = false;
12590         LDKCVec_u8Z arg_var = UnsignedChannelAnnouncement_write(&obj_conv);
12591         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
12592         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
12593         CVec_u8Z_free(arg_var);
12594         return arg_arr;
12595 }
12596
12597 uint32_t  __attribute__((visibility("default"))) TS_UnsignedChannelAnnouncement_read(int8_tArray ser) {
12598         LDKu8slice ser_ref;
12599         ser_ref.datalen = *((uint32_t*)ser);
12600         ser_ref.data = (int8_t*)(ser + 4);
12601         LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ), "LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ");
12602         *ret_conv = UnsignedChannelAnnouncement_read(ser_ref);
12603         return (long)ret_conv;
12604 }
12605
12606 int8_tArray  __attribute__((visibility("default"))) TS_ChannelAnnouncement_write(uint32_t obj) {
12607         LDKChannelAnnouncement obj_conv;
12608         obj_conv.inner = (void*)(obj & (~1));
12609         obj_conv.is_owned = false;
12610         LDKCVec_u8Z arg_var = ChannelAnnouncement_write(&obj_conv);
12611         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
12612         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
12613         CVec_u8Z_free(arg_var);
12614         return arg_arr;
12615 }
12616
12617 uint32_t  __attribute__((visibility("default"))) TS_ChannelAnnouncement_read(int8_tArray ser) {
12618         LDKu8slice ser_ref;
12619         ser_ref.datalen = *((uint32_t*)ser);
12620         ser_ref.data = (int8_t*)(ser + 4);
12621         LDKChannelAnnouncement ret_var = ChannelAnnouncement_read(ser_ref);
12622         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12623         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12624         long ret_ref = (long)ret_var.inner;
12625         if (ret_var.is_owned) {
12626                 ret_ref |= 1;
12627         }
12628         return ret_ref;
12629 }
12630
12631 int8_tArray  __attribute__((visibility("default"))) TS_UnsignedChannelUpdate_write(uint32_t obj) {
12632         LDKUnsignedChannelUpdate obj_conv;
12633         obj_conv.inner = (void*)(obj & (~1));
12634         obj_conv.is_owned = false;
12635         LDKCVec_u8Z arg_var = UnsignedChannelUpdate_write(&obj_conv);
12636         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
12637         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
12638         CVec_u8Z_free(arg_var);
12639         return arg_arr;
12640 }
12641
12642 uint32_t  __attribute__((visibility("default"))) TS_UnsignedChannelUpdate_read(int8_tArray ser) {
12643         LDKu8slice ser_ref;
12644         ser_ref.datalen = *((uint32_t*)ser);
12645         ser_ref.data = (int8_t*)(ser + 4);
12646         LDKCResult_UnsignedChannelUpdateDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_UnsignedChannelUpdateDecodeErrorZ), "LDKCResult_UnsignedChannelUpdateDecodeErrorZ");
12647         *ret_conv = UnsignedChannelUpdate_read(ser_ref);
12648         return (long)ret_conv;
12649 }
12650
12651 int8_tArray  __attribute__((visibility("default"))) TS_ChannelUpdate_write(uint32_t obj) {
12652         LDKChannelUpdate obj_conv;
12653         obj_conv.inner = (void*)(obj & (~1));
12654         obj_conv.is_owned = false;
12655         LDKCVec_u8Z arg_var = ChannelUpdate_write(&obj_conv);
12656         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
12657         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
12658         CVec_u8Z_free(arg_var);
12659         return arg_arr;
12660 }
12661
12662 uint32_t  __attribute__((visibility("default"))) TS_ChannelUpdate_read(int8_tArray ser) {
12663         LDKu8slice ser_ref;
12664         ser_ref.datalen = *((uint32_t*)ser);
12665         ser_ref.data = (int8_t*)(ser + 4);
12666         LDKChannelUpdate ret_var = ChannelUpdate_read(ser_ref);
12667         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12668         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12669         long ret_ref = (long)ret_var.inner;
12670         if (ret_var.is_owned) {
12671                 ret_ref |= 1;
12672         }
12673         return ret_ref;
12674 }
12675
12676 int8_tArray  __attribute__((visibility("default"))) TS_ErrorMessage_write(uint32_t obj) {
12677         LDKErrorMessage obj_conv;
12678         obj_conv.inner = (void*)(obj & (~1));
12679         obj_conv.is_owned = false;
12680         LDKCVec_u8Z arg_var = ErrorMessage_write(&obj_conv);
12681         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
12682         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
12683         CVec_u8Z_free(arg_var);
12684         return arg_arr;
12685 }
12686
12687 uint32_t  __attribute__((visibility("default"))) TS_ErrorMessage_read(int8_tArray ser) {
12688         LDKu8slice ser_ref;
12689         ser_ref.datalen = *((uint32_t*)ser);
12690         ser_ref.data = (int8_t*)(ser + 4);
12691         LDKCResult_ErrorMessageDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ErrorMessageDecodeErrorZ), "LDKCResult_ErrorMessageDecodeErrorZ");
12692         *ret_conv = ErrorMessage_read(ser_ref);
12693         return (long)ret_conv;
12694 }
12695
12696 int8_tArray  __attribute__((visibility("default"))) TS_UnsignedNodeAnnouncement_write(uint32_t obj) {
12697         LDKUnsignedNodeAnnouncement obj_conv;
12698         obj_conv.inner = (void*)(obj & (~1));
12699         obj_conv.is_owned = false;
12700         LDKCVec_u8Z arg_var = UnsignedNodeAnnouncement_write(&obj_conv);
12701         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
12702         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
12703         CVec_u8Z_free(arg_var);
12704         return arg_arr;
12705 }
12706
12707 uint32_t  __attribute__((visibility("default"))) TS_UnsignedNodeAnnouncement_read(int8_tArray ser) {
12708         LDKu8slice ser_ref;
12709         ser_ref.datalen = *((uint32_t*)ser);
12710         ser_ref.data = (int8_t*)(ser + 4);
12711         LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ), "LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ");
12712         *ret_conv = UnsignedNodeAnnouncement_read(ser_ref);
12713         return (long)ret_conv;
12714 }
12715
12716 int8_tArray  __attribute__((visibility("default"))) TS_NodeAnnouncement_write(uint32_t obj) {
12717         LDKNodeAnnouncement obj_conv;
12718         obj_conv.inner = (void*)(obj & (~1));
12719         obj_conv.is_owned = false;
12720         LDKCVec_u8Z arg_var = NodeAnnouncement_write(&obj_conv);
12721         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
12722         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
12723         CVec_u8Z_free(arg_var);
12724         return arg_arr;
12725 }
12726
12727 uint32_t  __attribute__((visibility("default"))) TS_NodeAnnouncement_read(int8_tArray ser) {
12728         LDKu8slice ser_ref;
12729         ser_ref.datalen = *((uint32_t*)ser);
12730         ser_ref.data = (int8_t*)(ser + 4);
12731         LDKNodeAnnouncement ret_var = NodeAnnouncement_read(ser_ref);
12732         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12733         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12734         long ret_ref = (long)ret_var.inner;
12735         if (ret_var.is_owned) {
12736                 ret_ref |= 1;
12737         }
12738         return ret_ref;
12739 }
12740
12741 uint32_t  __attribute__((visibility("default"))) TS_QueryShortChannelIds_read(int8_tArray ser) {
12742         LDKu8slice ser_ref;
12743         ser_ref.datalen = *((uint32_t*)ser);
12744         ser_ref.data = (int8_t*)(ser + 4);
12745         LDKCResult_QueryShortChannelIdsDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_QueryShortChannelIdsDecodeErrorZ), "LDKCResult_QueryShortChannelIdsDecodeErrorZ");
12746         *ret_conv = QueryShortChannelIds_read(ser_ref);
12747         return (long)ret_conv;
12748 }
12749
12750 int8_tArray  __attribute__((visibility("default"))) TS_QueryShortChannelIds_write(uint32_t obj) {
12751         LDKQueryShortChannelIds obj_conv;
12752         obj_conv.inner = (void*)(obj & (~1));
12753         obj_conv.is_owned = false;
12754         LDKCVec_u8Z arg_var = QueryShortChannelIds_write(&obj_conv);
12755         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
12756         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
12757         CVec_u8Z_free(arg_var);
12758         return arg_arr;
12759 }
12760
12761 uint32_t  __attribute__((visibility("default"))) TS_ReplyShortChannelIdsEnd_read(int8_tArray ser) {
12762         LDKu8slice ser_ref;
12763         ser_ref.datalen = *((uint32_t*)ser);
12764         ser_ref.data = (int8_t*)(ser + 4);
12765         LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ), "LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ");
12766         *ret_conv = ReplyShortChannelIdsEnd_read(ser_ref);
12767         return (long)ret_conv;
12768 }
12769
12770 int8_tArray  __attribute__((visibility("default"))) TS_ReplyShortChannelIdsEnd_write(uint32_t obj) {
12771         LDKReplyShortChannelIdsEnd obj_conv;
12772         obj_conv.inner = (void*)(obj & (~1));
12773         obj_conv.is_owned = false;
12774         LDKCVec_u8Z arg_var = ReplyShortChannelIdsEnd_write(&obj_conv);
12775         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
12776         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
12777         CVec_u8Z_free(arg_var);
12778         return arg_arr;
12779 }
12780
12781 uint32_t  __attribute__((visibility("default"))) TS_QueryChannelRange_read(int8_tArray ser) {
12782         LDKu8slice ser_ref;
12783         ser_ref.datalen = *((uint32_t*)ser);
12784         ser_ref.data = (int8_t*)(ser + 4);
12785         LDKCResult_QueryChannelRangeDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_QueryChannelRangeDecodeErrorZ), "LDKCResult_QueryChannelRangeDecodeErrorZ");
12786         *ret_conv = QueryChannelRange_read(ser_ref);
12787         return (long)ret_conv;
12788 }
12789
12790 int8_tArray  __attribute__((visibility("default"))) TS_QueryChannelRange_write(uint32_t obj) {
12791         LDKQueryChannelRange obj_conv;
12792         obj_conv.inner = (void*)(obj & (~1));
12793         obj_conv.is_owned = false;
12794         LDKCVec_u8Z arg_var = QueryChannelRange_write(&obj_conv);
12795         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
12796         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
12797         CVec_u8Z_free(arg_var);
12798         return arg_arr;
12799 }
12800
12801 uint32_t  __attribute__((visibility("default"))) TS_ReplyChannelRange_read(int8_tArray ser) {
12802         LDKu8slice ser_ref;
12803         ser_ref.datalen = *((uint32_t*)ser);
12804         ser_ref.data = (int8_t*)(ser + 4);
12805         LDKCResult_ReplyChannelRangeDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ReplyChannelRangeDecodeErrorZ), "LDKCResult_ReplyChannelRangeDecodeErrorZ");
12806         *ret_conv = ReplyChannelRange_read(ser_ref);
12807         return (long)ret_conv;
12808 }
12809
12810 int8_tArray  __attribute__((visibility("default"))) TS_ReplyChannelRange_write(uint32_t obj) {
12811         LDKReplyChannelRange obj_conv;
12812         obj_conv.inner = (void*)(obj & (~1));
12813         obj_conv.is_owned = false;
12814         LDKCVec_u8Z arg_var = ReplyChannelRange_write(&obj_conv);
12815         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
12816         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
12817         CVec_u8Z_free(arg_var);
12818         return arg_arr;
12819 }
12820
12821 uint32_t  __attribute__((visibility("default"))) TS_GossipTimestampFilter_read(int8_tArray ser) {
12822         LDKu8slice ser_ref;
12823         ser_ref.datalen = *((uint32_t*)ser);
12824         ser_ref.data = (int8_t*)(ser + 4);
12825         LDKCResult_GossipTimestampFilterDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_GossipTimestampFilterDecodeErrorZ), "LDKCResult_GossipTimestampFilterDecodeErrorZ");
12826         *ret_conv = GossipTimestampFilter_read(ser_ref);
12827         return (long)ret_conv;
12828 }
12829
12830 int8_tArray  __attribute__((visibility("default"))) TS_GossipTimestampFilter_write(uint32_t obj) {
12831         LDKGossipTimestampFilter obj_conv;
12832         obj_conv.inner = (void*)(obj & (~1));
12833         obj_conv.is_owned = false;
12834         LDKCVec_u8Z arg_var = GossipTimestampFilter_write(&obj_conv);
12835         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
12836         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
12837         CVec_u8Z_free(arg_var);
12838         return arg_arr;
12839 }
12840
12841 void  __attribute__((visibility("default"))) TS_MessageHandler_free(uint32_t this_ptr) {
12842         LDKMessageHandler this_ptr_conv;
12843         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12844         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12845         MessageHandler_free(this_ptr_conv);
12846 }
12847
12848 uint32_t  __attribute__((visibility("default"))) TS_MessageHandler_get_chan_handler(uint32_t this_ptr) {
12849         LDKMessageHandler this_ptr_conv;
12850         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12851         this_ptr_conv.is_owned = false;
12852         long ret_ret = (long)MessageHandler_get_chan_handler(&this_ptr_conv);
12853         return ret_ret;
12854 }
12855
12856 void  __attribute__((visibility("default"))) TS_MessageHandler_set_chan_handler(uint32_t this_ptr, uint32_t val) {
12857         LDKMessageHandler this_ptr_conv;
12858         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12859         this_ptr_conv.is_owned = false;
12860         LDKChannelMessageHandler val_conv = *(LDKChannelMessageHandler*)(((uint64_t)val) & ~1);
12861         MessageHandler_set_chan_handler(&this_ptr_conv, val_conv);
12862 }
12863
12864 uint32_t  __attribute__((visibility("default"))) TS_MessageHandler_get_route_handler(uint32_t this_ptr) {
12865         LDKMessageHandler this_ptr_conv;
12866         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12867         this_ptr_conv.is_owned = false;
12868         long ret_ret = (long)MessageHandler_get_route_handler(&this_ptr_conv);
12869         return ret_ret;
12870 }
12871
12872 void  __attribute__((visibility("default"))) TS_MessageHandler_set_route_handler(uint32_t this_ptr, uint32_t val) {
12873         LDKMessageHandler this_ptr_conv;
12874         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12875         this_ptr_conv.is_owned = false;
12876         LDKRoutingMessageHandler val_conv = *(LDKRoutingMessageHandler*)(((uint64_t)val) & ~1);
12877         MessageHandler_set_route_handler(&this_ptr_conv, val_conv);
12878 }
12879
12880 uint32_t  __attribute__((visibility("default"))) TS_MessageHandler_new(uint32_t chan_handler_arg, uint32_t route_handler_arg) {
12881         LDKChannelMessageHandler chan_handler_arg_conv = *(LDKChannelMessageHandler*)(((uint64_t)chan_handler_arg) & ~1);
12882         LDKRoutingMessageHandler route_handler_arg_conv = *(LDKRoutingMessageHandler*)(((uint64_t)route_handler_arg) & ~1);
12883         LDKMessageHandler ret_var = MessageHandler_new(chan_handler_arg_conv, route_handler_arg_conv);
12884         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12885         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12886         long ret_ref = (long)ret_var.inner;
12887         if (ret_var.is_owned) {
12888                 ret_ref |= 1;
12889         }
12890         return ret_ref;
12891 }
12892
12893 uint32_t  __attribute__((visibility("default"))) TS_SocketDescriptor_clone(uint32_t orig) {
12894         LDKSocketDescriptor* orig_conv = (LDKSocketDescriptor*)orig;
12895         LDKSocketDescriptor* ret = MALLOC(sizeof(LDKSocketDescriptor), "LDKSocketDescriptor");
12896         *ret = SocketDescriptor_clone(orig_conv);
12897         return (long)ret;
12898 }
12899
12900 void  __attribute__((visibility("default"))) TS_SocketDescriptor_free(uint32_t this_ptr) {
12901         if ((this_ptr & 1) != 0) return;
12902         LDKSocketDescriptor this_ptr_conv = *(LDKSocketDescriptor*)(((uint64_t)this_ptr) & ~1);
12903         FREE((void*)this_ptr);
12904         SocketDescriptor_free(this_ptr_conv);
12905 }
12906
12907 void  __attribute__((visibility("default"))) TS_PeerHandleError_free(uint32_t this_ptr) {
12908         LDKPeerHandleError this_ptr_conv;
12909         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12910         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12911         PeerHandleError_free(this_ptr_conv);
12912 }
12913
12914 uint32_t  __attribute__((visibility("default"))) TS_PeerHandleError_clone(uint32_t orig) {
12915         LDKPeerHandleError orig_conv;
12916         orig_conv.inner = (void*)(orig & (~1));
12917         orig_conv.is_owned = false;
12918         LDKPeerHandleError ret_var = PeerHandleError_clone(&orig_conv);
12919         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12920         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12921         long ret_ref = (long)ret_var.inner;
12922         if (ret_var.is_owned) {
12923                 ret_ref |= 1;
12924         }
12925         return ret_ref;
12926 }
12927
12928 jboolean  __attribute__((visibility("default"))) TS_PeerHandleError_get_no_connection_possible(uint32_t this_ptr) {
12929         LDKPeerHandleError this_ptr_conv;
12930         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12931         this_ptr_conv.is_owned = false;
12932         jboolean ret_val = PeerHandleError_get_no_connection_possible(&this_ptr_conv);
12933         return ret_val;
12934 }
12935
12936 void  __attribute__((visibility("default"))) TS_PeerHandleError_set_no_connection_possible(uint32_t this_ptr, jboolean val) {
12937         LDKPeerHandleError this_ptr_conv;
12938         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12939         this_ptr_conv.is_owned = false;
12940         PeerHandleError_set_no_connection_possible(&this_ptr_conv, val);
12941 }
12942
12943 uint32_t  __attribute__((visibility("default"))) TS_PeerHandleError_new(jboolean no_connection_possible_arg) {
12944         LDKPeerHandleError ret_var = PeerHandleError_new(no_connection_possible_arg);
12945         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12946         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12947         long ret_ref = (long)ret_var.inner;
12948         if (ret_var.is_owned) {
12949                 ret_ref |= 1;
12950         }
12951         return ret_ref;
12952 }
12953
12954 void  __attribute__((visibility("default"))) TS_PeerManager_free(uint32_t this_ptr) {
12955         LDKPeerManager this_ptr_conv;
12956         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12957         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12958         PeerManager_free(this_ptr_conv);
12959 }
12960
12961 uint32_t  __attribute__((visibility("default"))) TS_PeerManager_new(uint32_t message_handler, int8_tArray our_node_secret, int8_tArray ephemeral_random_data, uint32_t logger) {
12962         LDKMessageHandler message_handler_conv;
12963         message_handler_conv.inner = (void*)(message_handler & (~1));
12964         message_handler_conv.is_owned = (message_handler & 1) || (message_handler == 0);
12965         // Warning: we need a move here but no clone is available for LDKMessageHandler
12966         LDKSecretKey our_node_secret_ref;
12967         CHECK(*((uint32_t*)our_node_secret) == 32);
12968         memcpy(our_node_secret_ref.bytes, (uint8_t*)(our_node_secret + 4), 32);
12969         unsigned char ephemeral_random_data_arr[32];
12970         CHECK(*((uint32_t*)ephemeral_random_data) == 32);
12971         memcpy(ephemeral_random_data_arr, (uint8_t*)(ephemeral_random_data + 4), 32);
12972         unsigned char (*ephemeral_random_data_ref)[32] = &ephemeral_random_data_arr;
12973         LDKLogger logger_conv = *(LDKLogger*)(((uint64_t)logger) & ~1);
12974         LDKPeerManager ret_var = PeerManager_new(message_handler_conv, our_node_secret_ref, ephemeral_random_data_ref, logger_conv);
12975         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12976         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12977         long ret_ref = (long)ret_var.inner;
12978         if (ret_var.is_owned) {
12979                 ret_ref |= 1;
12980         }
12981         return ret_ref;
12982 }
12983
12984 ptrArray  __attribute__((visibility("default"))) TS_PeerManager_get_peer_node_ids(uint32_t this_arg) {
12985         LDKPeerManager this_arg_conv;
12986         this_arg_conv.inner = (void*)(this_arg & (~1));
12987         this_arg_conv.is_owned = false;
12988         LDKCVec_PublicKeyZ ret_var = PeerManager_get_peer_node_ids(&this_arg_conv);
12989         ptrArray ret_arr = init_arr(ret_var.datalen, sizeof(uint32_t), "Native ptrArray Bytes");
12990         int8_tArray *ret_arr_ptr = (int8_tArray*)(ret_arr + 4);
12991         for (size_t m = 0; m < ret_var.datalen; m++) {
12992                 int8_tArray arr_conv_12_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
12993                 memcpy((uint8_t*)(arr_conv_12_arr + 4), ret_var.data[m].compressed_form, 33);
12994                 ret_arr_ptr[m] = arr_conv_12_arr;
12995         }
12996         FREE(ret_var.data);
12997         return ret_arr;
12998 }
12999
13000 uint32_t  __attribute__((visibility("default"))) TS_PeerManager_new_outbound_connection(uint32_t this_arg, int8_tArray their_node_id, uint32_t descriptor) {
13001         LDKPeerManager this_arg_conv;
13002         this_arg_conv.inner = (void*)(this_arg & (~1));
13003         this_arg_conv.is_owned = false;
13004         LDKPublicKey their_node_id_ref;
13005         CHECK(*((uint32_t*)their_node_id) == 33);
13006         memcpy(their_node_id_ref.compressed_form, (uint8_t*)(their_node_id + 4), 33);
13007         LDKSocketDescriptor descriptor_conv = *(LDKSocketDescriptor*)(((uint64_t)descriptor) & ~1);
13008         LDKCResult_CVec_u8ZPeerHandleErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_CVec_u8ZPeerHandleErrorZ), "LDKCResult_CVec_u8ZPeerHandleErrorZ");
13009         *ret_conv = PeerManager_new_outbound_connection(&this_arg_conv, their_node_id_ref, descriptor_conv);
13010         return (long)ret_conv;
13011 }
13012
13013 uint32_t  __attribute__((visibility("default"))) TS_PeerManager_new_inbound_connection(uint32_t this_arg, uint32_t descriptor) {
13014         LDKPeerManager this_arg_conv;
13015         this_arg_conv.inner = (void*)(this_arg & (~1));
13016         this_arg_conv.is_owned = false;
13017         LDKSocketDescriptor descriptor_conv = *(LDKSocketDescriptor*)(((uint64_t)descriptor) & ~1);
13018         LDKCResult_NonePeerHandleErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NonePeerHandleErrorZ), "LDKCResult_NonePeerHandleErrorZ");
13019         *ret_conv = PeerManager_new_inbound_connection(&this_arg_conv, descriptor_conv);
13020         return (long)ret_conv;
13021 }
13022
13023 uint32_t  __attribute__((visibility("default"))) TS_PeerManager_write_buffer_space_avail(uint32_t this_arg, uint32_t descriptor) {
13024         LDKPeerManager this_arg_conv;
13025         this_arg_conv.inner = (void*)(this_arg & (~1));
13026         this_arg_conv.is_owned = false;
13027         LDKSocketDescriptor* descriptor_conv = (LDKSocketDescriptor*)descriptor;
13028         LDKCResult_NonePeerHandleErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NonePeerHandleErrorZ), "LDKCResult_NonePeerHandleErrorZ");
13029         *ret_conv = PeerManager_write_buffer_space_avail(&this_arg_conv, descriptor_conv);
13030         return (long)ret_conv;
13031 }
13032
13033 uint32_t  __attribute__((visibility("default"))) TS_PeerManager_read_event(uint32_t this_arg, uint32_t peer_descriptor, int8_tArray data) {
13034         LDKPeerManager this_arg_conv;
13035         this_arg_conv.inner = (void*)(this_arg & (~1));
13036         this_arg_conv.is_owned = false;
13037         LDKSocketDescriptor* peer_descriptor_conv = (LDKSocketDescriptor*)peer_descriptor;
13038         LDKu8slice data_ref;
13039         data_ref.datalen = *((uint32_t*)data);
13040         data_ref.data = (int8_t*)(data + 4);
13041         LDKCResult_boolPeerHandleErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_boolPeerHandleErrorZ), "LDKCResult_boolPeerHandleErrorZ");
13042         *ret_conv = PeerManager_read_event(&this_arg_conv, peer_descriptor_conv, data_ref);
13043         return (long)ret_conv;
13044 }
13045
13046 void  __attribute__((visibility("default"))) TS_PeerManager_process_events(uint32_t this_arg) {
13047         LDKPeerManager this_arg_conv;
13048         this_arg_conv.inner = (void*)(this_arg & (~1));
13049         this_arg_conv.is_owned = false;
13050         PeerManager_process_events(&this_arg_conv);
13051 }
13052
13053 void  __attribute__((visibility("default"))) TS_PeerManager_socket_disconnected(uint32_t this_arg, uint32_t descriptor) {
13054         LDKPeerManager this_arg_conv;
13055         this_arg_conv.inner = (void*)(this_arg & (~1));
13056         this_arg_conv.is_owned = false;
13057         LDKSocketDescriptor* descriptor_conv = (LDKSocketDescriptor*)descriptor;
13058         PeerManager_socket_disconnected(&this_arg_conv, descriptor_conv);
13059 }
13060
13061 void  __attribute__((visibility("default"))) TS_PeerManager_timer_tick_occured(uint32_t this_arg) {
13062         LDKPeerManager this_arg_conv;
13063         this_arg_conv.inner = (void*)(this_arg & (~1));
13064         this_arg_conv.is_owned = false;
13065         PeerManager_timer_tick_occured(&this_arg_conv);
13066 }
13067
13068 int8_tArray  __attribute__((visibility("default"))) TS_build_commitment_secret(int8_tArray commitment_seed, int64_t idx) {
13069         unsigned char commitment_seed_arr[32];
13070         CHECK(*((uint32_t*)commitment_seed) == 32);
13071         memcpy(commitment_seed_arr, (uint8_t*)(commitment_seed + 4), 32);
13072         unsigned char (*commitment_seed_ref)[32] = &commitment_seed_arr;
13073         int8_tArray arg_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
13074         memcpy((uint8_t*)(arg_arr + 4), build_commitment_secret(commitment_seed_ref, idx).data, 32);
13075         return arg_arr;
13076 }
13077
13078 uint32_t  __attribute__((visibility("default"))) TS_derive_private_key(int8_tArray per_commitment_point, int8_tArray base_secret) {
13079         LDKPublicKey per_commitment_point_ref;
13080         CHECK(*((uint32_t*)per_commitment_point) == 33);
13081         memcpy(per_commitment_point_ref.compressed_form, (uint8_t*)(per_commitment_point + 4), 33);
13082         unsigned char base_secret_arr[32];
13083         CHECK(*((uint32_t*)base_secret) == 32);
13084         memcpy(base_secret_arr, (uint8_t*)(base_secret + 4), 32);
13085         unsigned char (*base_secret_ref)[32] = &base_secret_arr;
13086         LDKCResult_SecretKeySecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_SecretKeySecpErrorZ), "LDKCResult_SecretKeySecpErrorZ");
13087         *ret_conv = derive_private_key(per_commitment_point_ref, base_secret_ref);
13088         return (long)ret_conv;
13089 }
13090
13091 uint32_t  __attribute__((visibility("default"))) TS_derive_public_key(int8_tArray per_commitment_point, int8_tArray base_point) {
13092         LDKPublicKey per_commitment_point_ref;
13093         CHECK(*((uint32_t*)per_commitment_point) == 33);
13094         memcpy(per_commitment_point_ref.compressed_form, (uint8_t*)(per_commitment_point + 4), 33);
13095         LDKPublicKey base_point_ref;
13096         CHECK(*((uint32_t*)base_point) == 33);
13097         memcpy(base_point_ref.compressed_form, (uint8_t*)(base_point + 4), 33);
13098         LDKCResult_PublicKeySecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_PublicKeySecpErrorZ), "LDKCResult_PublicKeySecpErrorZ");
13099         *ret_conv = derive_public_key(per_commitment_point_ref, base_point_ref);
13100         return (long)ret_conv;
13101 }
13102
13103 uint32_t  __attribute__((visibility("default"))) TS_derive_private_revocation_key(int8_tArray per_commitment_secret, int8_tArray countersignatory_revocation_base_secret) {
13104         unsigned char per_commitment_secret_arr[32];
13105         CHECK(*((uint32_t*)per_commitment_secret) == 32);
13106         memcpy(per_commitment_secret_arr, (uint8_t*)(per_commitment_secret + 4), 32);
13107         unsigned char (*per_commitment_secret_ref)[32] = &per_commitment_secret_arr;
13108         unsigned char countersignatory_revocation_base_secret_arr[32];
13109         CHECK(*((uint32_t*)countersignatory_revocation_base_secret) == 32);
13110         memcpy(countersignatory_revocation_base_secret_arr, (uint8_t*)(countersignatory_revocation_base_secret + 4), 32);
13111         unsigned char (*countersignatory_revocation_base_secret_ref)[32] = &countersignatory_revocation_base_secret_arr;
13112         LDKCResult_SecretKeySecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_SecretKeySecpErrorZ), "LDKCResult_SecretKeySecpErrorZ");
13113         *ret_conv = derive_private_revocation_key(per_commitment_secret_ref, countersignatory_revocation_base_secret_ref);
13114         return (long)ret_conv;
13115 }
13116
13117 uint32_t  __attribute__((visibility("default"))) TS_derive_public_revocation_key(int8_tArray per_commitment_point, int8_tArray countersignatory_revocation_base_point) {
13118         LDKPublicKey per_commitment_point_ref;
13119         CHECK(*((uint32_t*)per_commitment_point) == 33);
13120         memcpy(per_commitment_point_ref.compressed_form, (uint8_t*)(per_commitment_point + 4), 33);
13121         LDKPublicKey countersignatory_revocation_base_point_ref;
13122         CHECK(*((uint32_t*)countersignatory_revocation_base_point) == 33);
13123         memcpy(countersignatory_revocation_base_point_ref.compressed_form, (uint8_t*)(countersignatory_revocation_base_point + 4), 33);
13124         LDKCResult_PublicKeySecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_PublicKeySecpErrorZ), "LDKCResult_PublicKeySecpErrorZ");
13125         *ret_conv = derive_public_revocation_key(per_commitment_point_ref, countersignatory_revocation_base_point_ref);
13126         return (long)ret_conv;
13127 }
13128
13129 void  __attribute__((visibility("default"))) TS_TxCreationKeys_free(uint32_t this_ptr) {
13130         LDKTxCreationKeys this_ptr_conv;
13131         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13132         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13133         TxCreationKeys_free(this_ptr_conv);
13134 }
13135
13136 uint32_t  __attribute__((visibility("default"))) TS_TxCreationKeys_clone(uint32_t orig) {
13137         LDKTxCreationKeys orig_conv;
13138         orig_conv.inner = (void*)(orig & (~1));
13139         orig_conv.is_owned = false;
13140         LDKTxCreationKeys ret_var = TxCreationKeys_clone(&orig_conv);
13141         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13142         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13143         long ret_ref = (long)ret_var.inner;
13144         if (ret_var.is_owned) {
13145                 ret_ref |= 1;
13146         }
13147         return ret_ref;
13148 }
13149
13150 int8_tArray  __attribute__((visibility("default"))) TS_TxCreationKeys_get_per_commitment_point(uint32_t this_ptr) {
13151         LDKTxCreationKeys this_ptr_conv;
13152         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13153         this_ptr_conv.is_owned = false;
13154         int8_tArray arg_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
13155         memcpy((uint8_t*)(arg_arr + 4), TxCreationKeys_get_per_commitment_point(&this_ptr_conv).compressed_form, 33);
13156         return arg_arr;
13157 }
13158
13159 void  __attribute__((visibility("default"))) TS_TxCreationKeys_set_per_commitment_point(uint32_t this_ptr, int8_tArray val) {
13160         LDKTxCreationKeys this_ptr_conv;
13161         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13162         this_ptr_conv.is_owned = false;
13163         LDKPublicKey val_ref;
13164         CHECK(*((uint32_t*)val) == 33);
13165         memcpy(val_ref.compressed_form, (uint8_t*)(val + 4), 33);
13166         TxCreationKeys_set_per_commitment_point(&this_ptr_conv, val_ref);
13167 }
13168
13169 int8_tArray  __attribute__((visibility("default"))) TS_TxCreationKeys_get_revocation_key(uint32_t this_ptr) {
13170         LDKTxCreationKeys this_ptr_conv;
13171         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13172         this_ptr_conv.is_owned = false;
13173         int8_tArray arg_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
13174         memcpy((uint8_t*)(arg_arr + 4), TxCreationKeys_get_revocation_key(&this_ptr_conv).compressed_form, 33);
13175         return arg_arr;
13176 }
13177
13178 void  __attribute__((visibility("default"))) TS_TxCreationKeys_set_revocation_key(uint32_t this_ptr, int8_tArray val) {
13179         LDKTxCreationKeys this_ptr_conv;
13180         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13181         this_ptr_conv.is_owned = false;
13182         LDKPublicKey val_ref;
13183         CHECK(*((uint32_t*)val) == 33);
13184         memcpy(val_ref.compressed_form, (uint8_t*)(val + 4), 33);
13185         TxCreationKeys_set_revocation_key(&this_ptr_conv, val_ref);
13186 }
13187
13188 int8_tArray  __attribute__((visibility("default"))) TS_TxCreationKeys_get_broadcaster_htlc_key(uint32_t this_ptr) {
13189         LDKTxCreationKeys this_ptr_conv;
13190         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13191         this_ptr_conv.is_owned = false;
13192         int8_tArray arg_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
13193         memcpy((uint8_t*)(arg_arr + 4), TxCreationKeys_get_broadcaster_htlc_key(&this_ptr_conv).compressed_form, 33);
13194         return arg_arr;
13195 }
13196
13197 void  __attribute__((visibility("default"))) TS_TxCreationKeys_set_broadcaster_htlc_key(uint32_t this_ptr, int8_tArray val) {
13198         LDKTxCreationKeys this_ptr_conv;
13199         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13200         this_ptr_conv.is_owned = false;
13201         LDKPublicKey val_ref;
13202         CHECK(*((uint32_t*)val) == 33);
13203         memcpy(val_ref.compressed_form, (uint8_t*)(val + 4), 33);
13204         TxCreationKeys_set_broadcaster_htlc_key(&this_ptr_conv, val_ref);
13205 }
13206
13207 int8_tArray  __attribute__((visibility("default"))) TS_TxCreationKeys_get_countersignatory_htlc_key(uint32_t this_ptr) {
13208         LDKTxCreationKeys this_ptr_conv;
13209         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13210         this_ptr_conv.is_owned = false;
13211         int8_tArray arg_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
13212         memcpy((uint8_t*)(arg_arr + 4), TxCreationKeys_get_countersignatory_htlc_key(&this_ptr_conv).compressed_form, 33);
13213         return arg_arr;
13214 }
13215
13216 void  __attribute__((visibility("default"))) TS_TxCreationKeys_set_countersignatory_htlc_key(uint32_t this_ptr, int8_tArray val) {
13217         LDKTxCreationKeys this_ptr_conv;
13218         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13219         this_ptr_conv.is_owned = false;
13220         LDKPublicKey val_ref;
13221         CHECK(*((uint32_t*)val) == 33);
13222         memcpy(val_ref.compressed_form, (uint8_t*)(val + 4), 33);
13223         TxCreationKeys_set_countersignatory_htlc_key(&this_ptr_conv, val_ref);
13224 }
13225
13226 int8_tArray  __attribute__((visibility("default"))) TS_TxCreationKeys_get_broadcaster_delayed_payment_key(uint32_t this_ptr) {
13227         LDKTxCreationKeys this_ptr_conv;
13228         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13229         this_ptr_conv.is_owned = false;
13230         int8_tArray arg_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
13231         memcpy((uint8_t*)(arg_arr + 4), TxCreationKeys_get_broadcaster_delayed_payment_key(&this_ptr_conv).compressed_form, 33);
13232         return arg_arr;
13233 }
13234
13235 void  __attribute__((visibility("default"))) TS_TxCreationKeys_set_broadcaster_delayed_payment_key(uint32_t this_ptr, int8_tArray val) {
13236         LDKTxCreationKeys this_ptr_conv;
13237         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13238         this_ptr_conv.is_owned = false;
13239         LDKPublicKey val_ref;
13240         CHECK(*((uint32_t*)val) == 33);
13241         memcpy(val_ref.compressed_form, (uint8_t*)(val + 4), 33);
13242         TxCreationKeys_set_broadcaster_delayed_payment_key(&this_ptr_conv, val_ref);
13243 }
13244
13245 uint32_t  __attribute__((visibility("default"))) 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) {
13246         LDKPublicKey per_commitment_point_arg_ref;
13247         CHECK(*((uint32_t*)per_commitment_point_arg) == 33);
13248         memcpy(per_commitment_point_arg_ref.compressed_form, (uint8_t*)(per_commitment_point_arg + 4), 33);
13249         LDKPublicKey revocation_key_arg_ref;
13250         CHECK(*((uint32_t*)revocation_key_arg) == 33);
13251         memcpy(revocation_key_arg_ref.compressed_form, (uint8_t*)(revocation_key_arg + 4), 33);
13252         LDKPublicKey broadcaster_htlc_key_arg_ref;
13253         CHECK(*((uint32_t*)broadcaster_htlc_key_arg) == 33);
13254         memcpy(broadcaster_htlc_key_arg_ref.compressed_form, (uint8_t*)(broadcaster_htlc_key_arg + 4), 33);
13255         LDKPublicKey countersignatory_htlc_key_arg_ref;
13256         CHECK(*((uint32_t*)countersignatory_htlc_key_arg) == 33);
13257         memcpy(countersignatory_htlc_key_arg_ref.compressed_form, (uint8_t*)(countersignatory_htlc_key_arg + 4), 33);
13258         LDKPublicKey broadcaster_delayed_payment_key_arg_ref;
13259         CHECK(*((uint32_t*)broadcaster_delayed_payment_key_arg) == 33);
13260         memcpy(broadcaster_delayed_payment_key_arg_ref.compressed_form, (uint8_t*)(broadcaster_delayed_payment_key_arg + 4), 33);
13261         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);
13262         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13263         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13264         long ret_ref = (long)ret_var.inner;
13265         if (ret_var.is_owned) {
13266                 ret_ref |= 1;
13267         }
13268         return ret_ref;
13269 }
13270
13271 int8_tArray  __attribute__((visibility("default"))) TS_TxCreationKeys_write(uint32_t obj) {
13272         LDKTxCreationKeys obj_conv;
13273         obj_conv.inner = (void*)(obj & (~1));
13274         obj_conv.is_owned = false;
13275         LDKCVec_u8Z arg_var = TxCreationKeys_write(&obj_conv);
13276         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
13277         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
13278         CVec_u8Z_free(arg_var);
13279         return arg_arr;
13280 }
13281
13282 uint32_t  __attribute__((visibility("default"))) TS_TxCreationKeys_read(int8_tArray ser) {
13283         LDKu8slice ser_ref;
13284         ser_ref.datalen = *((uint32_t*)ser);
13285         ser_ref.data = (int8_t*)(ser + 4);
13286         LDKTxCreationKeys ret_var = TxCreationKeys_read(ser_ref);
13287         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13288         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13289         long ret_ref = (long)ret_var.inner;
13290         if (ret_var.is_owned) {
13291                 ret_ref |= 1;
13292         }
13293         return ret_ref;
13294 }
13295
13296 void  __attribute__((visibility("default"))) TS_ChannelPublicKeys_free(uint32_t this_ptr) {
13297         LDKChannelPublicKeys this_ptr_conv;
13298         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13299         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13300         ChannelPublicKeys_free(this_ptr_conv);
13301 }
13302
13303 uint32_t  __attribute__((visibility("default"))) TS_ChannelPublicKeys_clone(uint32_t orig) {
13304         LDKChannelPublicKeys orig_conv;
13305         orig_conv.inner = (void*)(orig & (~1));
13306         orig_conv.is_owned = false;
13307         LDKChannelPublicKeys ret_var = ChannelPublicKeys_clone(&orig_conv);
13308         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13309         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13310         long ret_ref = (long)ret_var.inner;
13311         if (ret_var.is_owned) {
13312                 ret_ref |= 1;
13313         }
13314         return ret_ref;
13315 }
13316
13317 int8_tArray  __attribute__((visibility("default"))) TS_ChannelPublicKeys_get_funding_pubkey(uint32_t this_ptr) {
13318         LDKChannelPublicKeys this_ptr_conv;
13319         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13320         this_ptr_conv.is_owned = false;
13321         int8_tArray arg_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
13322         memcpy((uint8_t*)(arg_arr + 4), ChannelPublicKeys_get_funding_pubkey(&this_ptr_conv).compressed_form, 33);
13323         return arg_arr;
13324 }
13325
13326 void  __attribute__((visibility("default"))) TS_ChannelPublicKeys_set_funding_pubkey(uint32_t this_ptr, int8_tArray val) {
13327         LDKChannelPublicKeys this_ptr_conv;
13328         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13329         this_ptr_conv.is_owned = false;
13330         LDKPublicKey val_ref;
13331         CHECK(*((uint32_t*)val) == 33);
13332         memcpy(val_ref.compressed_form, (uint8_t*)(val + 4), 33);
13333         ChannelPublicKeys_set_funding_pubkey(&this_ptr_conv, val_ref);
13334 }
13335
13336 int8_tArray  __attribute__((visibility("default"))) TS_ChannelPublicKeys_get_revocation_basepoint(uint32_t this_ptr) {
13337         LDKChannelPublicKeys this_ptr_conv;
13338         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13339         this_ptr_conv.is_owned = false;
13340         int8_tArray arg_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
13341         memcpy((uint8_t*)(arg_arr + 4), ChannelPublicKeys_get_revocation_basepoint(&this_ptr_conv).compressed_form, 33);
13342         return arg_arr;
13343 }
13344
13345 void  __attribute__((visibility("default"))) TS_ChannelPublicKeys_set_revocation_basepoint(uint32_t this_ptr, int8_tArray val) {
13346         LDKChannelPublicKeys this_ptr_conv;
13347         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13348         this_ptr_conv.is_owned = false;
13349         LDKPublicKey val_ref;
13350         CHECK(*((uint32_t*)val) == 33);
13351         memcpy(val_ref.compressed_form, (uint8_t*)(val + 4), 33);
13352         ChannelPublicKeys_set_revocation_basepoint(&this_ptr_conv, val_ref);
13353 }
13354
13355 int8_tArray  __attribute__((visibility("default"))) TS_ChannelPublicKeys_get_payment_point(uint32_t this_ptr) {
13356         LDKChannelPublicKeys this_ptr_conv;
13357         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13358         this_ptr_conv.is_owned = false;
13359         int8_tArray arg_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
13360         memcpy((uint8_t*)(arg_arr + 4), ChannelPublicKeys_get_payment_point(&this_ptr_conv).compressed_form, 33);
13361         return arg_arr;
13362 }
13363
13364 void  __attribute__((visibility("default"))) TS_ChannelPublicKeys_set_payment_point(uint32_t this_ptr, int8_tArray val) {
13365         LDKChannelPublicKeys this_ptr_conv;
13366         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13367         this_ptr_conv.is_owned = false;
13368         LDKPublicKey val_ref;
13369         CHECK(*((uint32_t*)val) == 33);
13370         memcpy(val_ref.compressed_form, (uint8_t*)(val + 4), 33);
13371         ChannelPublicKeys_set_payment_point(&this_ptr_conv, val_ref);
13372 }
13373
13374 int8_tArray  __attribute__((visibility("default"))) TS_ChannelPublicKeys_get_delayed_payment_basepoint(uint32_t this_ptr) {
13375         LDKChannelPublicKeys this_ptr_conv;
13376         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13377         this_ptr_conv.is_owned = false;
13378         int8_tArray arg_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
13379         memcpy((uint8_t*)(arg_arr + 4), ChannelPublicKeys_get_delayed_payment_basepoint(&this_ptr_conv).compressed_form, 33);
13380         return arg_arr;
13381 }
13382
13383 void  __attribute__((visibility("default"))) TS_ChannelPublicKeys_set_delayed_payment_basepoint(uint32_t this_ptr, int8_tArray val) {
13384         LDKChannelPublicKeys this_ptr_conv;
13385         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13386         this_ptr_conv.is_owned = false;
13387         LDKPublicKey val_ref;
13388         CHECK(*((uint32_t*)val) == 33);
13389         memcpy(val_ref.compressed_form, (uint8_t*)(val + 4), 33);
13390         ChannelPublicKeys_set_delayed_payment_basepoint(&this_ptr_conv, val_ref);
13391 }
13392
13393 int8_tArray  __attribute__((visibility("default"))) TS_ChannelPublicKeys_get_htlc_basepoint(uint32_t this_ptr) {
13394         LDKChannelPublicKeys this_ptr_conv;
13395         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13396         this_ptr_conv.is_owned = false;
13397         int8_tArray arg_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
13398         memcpy((uint8_t*)(arg_arr + 4), ChannelPublicKeys_get_htlc_basepoint(&this_ptr_conv).compressed_form, 33);
13399         return arg_arr;
13400 }
13401
13402 void  __attribute__((visibility("default"))) TS_ChannelPublicKeys_set_htlc_basepoint(uint32_t this_ptr, int8_tArray val) {
13403         LDKChannelPublicKeys this_ptr_conv;
13404         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13405         this_ptr_conv.is_owned = false;
13406         LDKPublicKey val_ref;
13407         CHECK(*((uint32_t*)val) == 33);
13408         memcpy(val_ref.compressed_form, (uint8_t*)(val + 4), 33);
13409         ChannelPublicKeys_set_htlc_basepoint(&this_ptr_conv, val_ref);
13410 }
13411
13412 uint32_t  __attribute__((visibility("default"))) 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) {
13413         LDKPublicKey funding_pubkey_arg_ref;
13414         CHECK(*((uint32_t*)funding_pubkey_arg) == 33);
13415         memcpy(funding_pubkey_arg_ref.compressed_form, (uint8_t*)(funding_pubkey_arg + 4), 33);
13416         LDKPublicKey revocation_basepoint_arg_ref;
13417         CHECK(*((uint32_t*)revocation_basepoint_arg) == 33);
13418         memcpy(revocation_basepoint_arg_ref.compressed_form, (uint8_t*)(revocation_basepoint_arg + 4), 33);
13419         LDKPublicKey payment_point_arg_ref;
13420         CHECK(*((uint32_t*)payment_point_arg) == 33);
13421         memcpy(payment_point_arg_ref.compressed_form, (uint8_t*)(payment_point_arg + 4), 33);
13422         LDKPublicKey delayed_payment_basepoint_arg_ref;
13423         CHECK(*((uint32_t*)delayed_payment_basepoint_arg) == 33);
13424         memcpy(delayed_payment_basepoint_arg_ref.compressed_form, (uint8_t*)(delayed_payment_basepoint_arg + 4), 33);
13425         LDKPublicKey htlc_basepoint_arg_ref;
13426         CHECK(*((uint32_t*)htlc_basepoint_arg) == 33);
13427         memcpy(htlc_basepoint_arg_ref.compressed_form, (uint8_t*)(htlc_basepoint_arg + 4), 33);
13428         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);
13429         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13430         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13431         long ret_ref = (long)ret_var.inner;
13432         if (ret_var.is_owned) {
13433                 ret_ref |= 1;
13434         }
13435         return ret_ref;
13436 }
13437
13438 int8_tArray  __attribute__((visibility("default"))) TS_ChannelPublicKeys_write(uint32_t obj) {
13439         LDKChannelPublicKeys obj_conv;
13440         obj_conv.inner = (void*)(obj & (~1));
13441         obj_conv.is_owned = false;
13442         LDKCVec_u8Z arg_var = ChannelPublicKeys_write(&obj_conv);
13443         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
13444         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
13445         CVec_u8Z_free(arg_var);
13446         return arg_arr;
13447 }
13448
13449 uint32_t  __attribute__((visibility("default"))) TS_ChannelPublicKeys_read(int8_tArray ser) {
13450         LDKu8slice ser_ref;
13451         ser_ref.datalen = *((uint32_t*)ser);
13452         ser_ref.data = (int8_t*)(ser + 4);
13453         LDKChannelPublicKeys ret_var = ChannelPublicKeys_read(ser_ref);
13454         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13455         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13456         long ret_ref = (long)ret_var.inner;
13457         if (ret_var.is_owned) {
13458                 ret_ref |= 1;
13459         }
13460         return ret_ref;
13461 }
13462
13463 uint32_t  __attribute__((visibility("default"))) 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) {
13464         LDKPublicKey per_commitment_point_ref;
13465         CHECK(*((uint32_t*)per_commitment_point) == 33);
13466         memcpy(per_commitment_point_ref.compressed_form, (uint8_t*)(per_commitment_point + 4), 33);
13467         LDKPublicKey broadcaster_delayed_payment_base_ref;
13468         CHECK(*((uint32_t*)broadcaster_delayed_payment_base) == 33);
13469         memcpy(broadcaster_delayed_payment_base_ref.compressed_form, (uint8_t*)(broadcaster_delayed_payment_base + 4), 33);
13470         LDKPublicKey broadcaster_htlc_base_ref;
13471         CHECK(*((uint32_t*)broadcaster_htlc_base) == 33);
13472         memcpy(broadcaster_htlc_base_ref.compressed_form, (uint8_t*)(broadcaster_htlc_base + 4), 33);
13473         LDKPublicKey countersignatory_revocation_base_ref;
13474         CHECK(*((uint32_t*)countersignatory_revocation_base) == 33);
13475         memcpy(countersignatory_revocation_base_ref.compressed_form, (uint8_t*)(countersignatory_revocation_base + 4), 33);
13476         LDKPublicKey countersignatory_htlc_base_ref;
13477         CHECK(*((uint32_t*)countersignatory_htlc_base) == 33);
13478         memcpy(countersignatory_htlc_base_ref.compressed_form, (uint8_t*)(countersignatory_htlc_base + 4), 33);
13479         LDKCResult_TxCreationKeysSecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_TxCreationKeysSecpErrorZ), "LDKCResult_TxCreationKeysSecpErrorZ");
13480         *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);
13481         return (long)ret_conv;
13482 }
13483
13484 uint32_t  __attribute__((visibility("default"))) TS_TxCreationKeys_from_channel_static_keys(int8_tArray per_commitment_point, uint32_t broadcaster_keys, uint32_t countersignatory_keys) {
13485         LDKPublicKey per_commitment_point_ref;
13486         CHECK(*((uint32_t*)per_commitment_point) == 33);
13487         memcpy(per_commitment_point_ref.compressed_form, (uint8_t*)(per_commitment_point + 4), 33);
13488         LDKChannelPublicKeys broadcaster_keys_conv;
13489         broadcaster_keys_conv.inner = (void*)(broadcaster_keys & (~1));
13490         broadcaster_keys_conv.is_owned = false;
13491         LDKChannelPublicKeys countersignatory_keys_conv;
13492         countersignatory_keys_conv.inner = (void*)(countersignatory_keys & (~1));
13493         countersignatory_keys_conv.is_owned = false;
13494         LDKCResult_TxCreationKeysSecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_TxCreationKeysSecpErrorZ), "LDKCResult_TxCreationKeysSecpErrorZ");
13495         *ret_conv = TxCreationKeys_from_channel_static_keys(per_commitment_point_ref, &broadcaster_keys_conv, &countersignatory_keys_conv);
13496         return (long)ret_conv;
13497 }
13498
13499 int8_tArray  __attribute__((visibility("default"))) TS_get_revokeable_redeemscript(int8_tArray revocation_key, int16_t contest_delay, int8_tArray broadcaster_delayed_payment_key) {
13500         LDKPublicKey revocation_key_ref;
13501         CHECK(*((uint32_t*)revocation_key) == 33);
13502         memcpy(revocation_key_ref.compressed_form, (uint8_t*)(revocation_key + 4), 33);
13503         LDKPublicKey broadcaster_delayed_payment_key_ref;
13504         CHECK(*((uint32_t*)broadcaster_delayed_payment_key) == 33);
13505         memcpy(broadcaster_delayed_payment_key_ref.compressed_form, (uint8_t*)(broadcaster_delayed_payment_key + 4), 33);
13506         LDKCVec_u8Z arg_var = get_revokeable_redeemscript(revocation_key_ref, contest_delay, broadcaster_delayed_payment_key_ref);
13507         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
13508         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
13509         CVec_u8Z_free(arg_var);
13510         return arg_arr;
13511 }
13512
13513 void  __attribute__((visibility("default"))) TS_HTLCOutputInCommitment_free(uint32_t this_ptr) {
13514         LDKHTLCOutputInCommitment this_ptr_conv;
13515         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13516         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13517         HTLCOutputInCommitment_free(this_ptr_conv);
13518 }
13519
13520 uint32_t  __attribute__((visibility("default"))) TS_HTLCOutputInCommitment_clone(uint32_t orig) {
13521         LDKHTLCOutputInCommitment orig_conv;
13522         orig_conv.inner = (void*)(orig & (~1));
13523         orig_conv.is_owned = false;
13524         LDKHTLCOutputInCommitment ret_var = HTLCOutputInCommitment_clone(&orig_conv);
13525         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13526         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13527         long ret_ref = (long)ret_var.inner;
13528         if (ret_var.is_owned) {
13529                 ret_ref |= 1;
13530         }
13531         return ret_ref;
13532 }
13533
13534 jboolean  __attribute__((visibility("default"))) TS_HTLCOutputInCommitment_get_offered(uint32_t this_ptr) {
13535         LDKHTLCOutputInCommitment this_ptr_conv;
13536         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13537         this_ptr_conv.is_owned = false;
13538         jboolean ret_val = HTLCOutputInCommitment_get_offered(&this_ptr_conv);
13539         return ret_val;
13540 }
13541
13542 void  __attribute__((visibility("default"))) TS_HTLCOutputInCommitment_set_offered(uint32_t this_ptr, jboolean val) {
13543         LDKHTLCOutputInCommitment this_ptr_conv;
13544         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13545         this_ptr_conv.is_owned = false;
13546         HTLCOutputInCommitment_set_offered(&this_ptr_conv, val);
13547 }
13548
13549 int64_t  __attribute__((visibility("default"))) TS_HTLCOutputInCommitment_get_amount_msat(uint32_t this_ptr) {
13550         LDKHTLCOutputInCommitment this_ptr_conv;
13551         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13552         this_ptr_conv.is_owned = false;
13553         int64_t ret_val = HTLCOutputInCommitment_get_amount_msat(&this_ptr_conv);
13554         return ret_val;
13555 }
13556
13557 void  __attribute__((visibility("default"))) TS_HTLCOutputInCommitment_set_amount_msat(uint32_t this_ptr, int64_t val) {
13558         LDKHTLCOutputInCommitment this_ptr_conv;
13559         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13560         this_ptr_conv.is_owned = false;
13561         HTLCOutputInCommitment_set_amount_msat(&this_ptr_conv, val);
13562 }
13563
13564 int32_t  __attribute__((visibility("default"))) TS_HTLCOutputInCommitment_get_cltv_expiry(uint32_t this_ptr) {
13565         LDKHTLCOutputInCommitment this_ptr_conv;
13566         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13567         this_ptr_conv.is_owned = false;
13568         int32_t ret_val = HTLCOutputInCommitment_get_cltv_expiry(&this_ptr_conv);
13569         return ret_val;
13570 }
13571
13572 void  __attribute__((visibility("default"))) TS_HTLCOutputInCommitment_set_cltv_expiry(uint32_t this_ptr, int32_t val) {
13573         LDKHTLCOutputInCommitment this_ptr_conv;
13574         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13575         this_ptr_conv.is_owned = false;
13576         HTLCOutputInCommitment_set_cltv_expiry(&this_ptr_conv, val);
13577 }
13578
13579 int8_tArray  __attribute__((visibility("default"))) TS_HTLCOutputInCommitment_get_payment_hash(uint32_t this_ptr) {
13580         LDKHTLCOutputInCommitment this_ptr_conv;
13581         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13582         this_ptr_conv.is_owned = false;
13583         int8_tArray ret_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
13584         memcpy((uint8_t*)(ret_arr + 4), *HTLCOutputInCommitment_get_payment_hash(&this_ptr_conv), 32);
13585         return ret_arr;
13586 }
13587
13588 void  __attribute__((visibility("default"))) TS_HTLCOutputInCommitment_set_payment_hash(uint32_t this_ptr, int8_tArray val) {
13589         LDKHTLCOutputInCommitment this_ptr_conv;
13590         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13591         this_ptr_conv.is_owned = false;
13592         LDKThirtyTwoBytes val_ref;
13593         CHECK(*((uint32_t*)val) == 32);
13594         memcpy(val_ref.data, (uint8_t*)(val + 4), 32);
13595         HTLCOutputInCommitment_set_payment_hash(&this_ptr_conv, val_ref);
13596 }
13597
13598 int8_tArray  __attribute__((visibility("default"))) TS_HTLCOutputInCommitment_write(uint32_t obj) {
13599         LDKHTLCOutputInCommitment obj_conv;
13600         obj_conv.inner = (void*)(obj & (~1));
13601         obj_conv.is_owned = false;
13602         LDKCVec_u8Z arg_var = HTLCOutputInCommitment_write(&obj_conv);
13603         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
13604         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
13605         CVec_u8Z_free(arg_var);
13606         return arg_arr;
13607 }
13608
13609 uint32_t  __attribute__((visibility("default"))) TS_HTLCOutputInCommitment_read(int8_tArray ser) {
13610         LDKu8slice ser_ref;
13611         ser_ref.datalen = *((uint32_t*)ser);
13612         ser_ref.data = (int8_t*)(ser + 4);
13613         LDKHTLCOutputInCommitment ret_var = HTLCOutputInCommitment_read(ser_ref);
13614         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13615         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13616         long ret_ref = (long)ret_var.inner;
13617         if (ret_var.is_owned) {
13618                 ret_ref |= 1;
13619         }
13620         return ret_ref;
13621 }
13622
13623 int8_tArray  __attribute__((visibility("default"))) TS_get_htlc_redeemscript(uint32_t htlc, uint32_t keys) {
13624         LDKHTLCOutputInCommitment htlc_conv;
13625         htlc_conv.inner = (void*)(htlc & (~1));
13626         htlc_conv.is_owned = false;
13627         LDKTxCreationKeys keys_conv;
13628         keys_conv.inner = (void*)(keys & (~1));
13629         keys_conv.is_owned = false;
13630         LDKCVec_u8Z arg_var = get_htlc_redeemscript(&htlc_conv, &keys_conv);
13631         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
13632         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
13633         CVec_u8Z_free(arg_var);
13634         return arg_arr;
13635 }
13636
13637 int8_tArray  __attribute__((visibility("default"))) TS_make_funding_redeemscript(int8_tArray broadcaster, int8_tArray countersignatory) {
13638         LDKPublicKey broadcaster_ref;
13639         CHECK(*((uint32_t*)broadcaster) == 33);
13640         memcpy(broadcaster_ref.compressed_form, (uint8_t*)(broadcaster + 4), 33);
13641         LDKPublicKey countersignatory_ref;
13642         CHECK(*((uint32_t*)countersignatory) == 33);
13643         memcpy(countersignatory_ref.compressed_form, (uint8_t*)(countersignatory + 4), 33);
13644         LDKCVec_u8Z arg_var = make_funding_redeemscript(broadcaster_ref, countersignatory_ref);
13645         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
13646         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
13647         CVec_u8Z_free(arg_var);
13648         return arg_arr;
13649 }
13650
13651 int8_tArray  __attribute__((visibility("default"))) 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) {
13652         unsigned char prev_hash_arr[32];
13653         CHECK(*((uint32_t*)prev_hash) == 32);
13654         memcpy(prev_hash_arr, (uint8_t*)(prev_hash + 4), 32);
13655         unsigned char (*prev_hash_ref)[32] = &prev_hash_arr;
13656         LDKHTLCOutputInCommitment htlc_conv;
13657         htlc_conv.inner = (void*)(htlc & (~1));
13658         htlc_conv.is_owned = false;
13659         LDKPublicKey broadcaster_delayed_payment_key_ref;
13660         CHECK(*((uint32_t*)broadcaster_delayed_payment_key) == 33);
13661         memcpy(broadcaster_delayed_payment_key_ref.compressed_form, (uint8_t*)(broadcaster_delayed_payment_key + 4), 33);
13662         LDKPublicKey revocation_key_ref;
13663         CHECK(*((uint32_t*)revocation_key) == 33);
13664         memcpy(revocation_key_ref.compressed_form, (uint8_t*)(revocation_key + 4), 33);
13665         LDKTransaction arg_var = build_htlc_transaction(prev_hash_ref, feerate_per_kw, contest_delay, &htlc_conv, broadcaster_delayed_payment_key_ref, revocation_key_ref);
13666         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
13667         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
13668         Transaction_free(arg_var);
13669         return arg_arr;
13670 }
13671
13672 void  __attribute__((visibility("default"))) TS_ChannelTransactionParameters_free(uint32_t this_ptr) {
13673         LDKChannelTransactionParameters this_ptr_conv;
13674         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13675         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13676         ChannelTransactionParameters_free(this_ptr_conv);
13677 }
13678
13679 uint32_t  __attribute__((visibility("default"))) TS_ChannelTransactionParameters_clone(uint32_t orig) {
13680         LDKChannelTransactionParameters orig_conv;
13681         orig_conv.inner = (void*)(orig & (~1));
13682         orig_conv.is_owned = false;
13683         LDKChannelTransactionParameters ret_var = ChannelTransactionParameters_clone(&orig_conv);
13684         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13685         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13686         long ret_ref = (long)ret_var.inner;
13687         if (ret_var.is_owned) {
13688                 ret_ref |= 1;
13689         }
13690         return ret_ref;
13691 }
13692
13693 uint32_t  __attribute__((visibility("default"))) TS_ChannelTransactionParameters_get_holder_pubkeys(uint32_t this_ptr) {
13694         LDKChannelTransactionParameters this_ptr_conv;
13695         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13696         this_ptr_conv.is_owned = false;
13697         LDKChannelPublicKeys ret_var = ChannelTransactionParameters_get_holder_pubkeys(&this_ptr_conv);
13698         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13699         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13700         long ret_ref = (long)ret_var.inner;
13701         if (ret_var.is_owned) {
13702                 ret_ref |= 1;
13703         }
13704         return ret_ref;
13705 }
13706
13707 void  __attribute__((visibility("default"))) TS_ChannelTransactionParameters_set_holder_pubkeys(uint32_t this_ptr, uint32_t val) {
13708         LDKChannelTransactionParameters this_ptr_conv;
13709         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13710         this_ptr_conv.is_owned = false;
13711         LDKChannelPublicKeys val_conv;
13712         val_conv.inner = (void*)(val & (~1));
13713         val_conv.is_owned = (val & 1) || (val == 0);
13714         val_conv = ChannelPublicKeys_clone(&val_conv);
13715         ChannelTransactionParameters_set_holder_pubkeys(&this_ptr_conv, val_conv);
13716 }
13717
13718 int16_t  __attribute__((visibility("default"))) TS_ChannelTransactionParameters_get_holder_selected_contest_delay(uint32_t this_ptr) {
13719         LDKChannelTransactionParameters this_ptr_conv;
13720         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13721         this_ptr_conv.is_owned = false;
13722         int16_t ret_val = ChannelTransactionParameters_get_holder_selected_contest_delay(&this_ptr_conv);
13723         return ret_val;
13724 }
13725
13726 void  __attribute__((visibility("default"))) TS_ChannelTransactionParameters_set_holder_selected_contest_delay(uint32_t this_ptr, int16_t val) {
13727         LDKChannelTransactionParameters this_ptr_conv;
13728         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13729         this_ptr_conv.is_owned = false;
13730         ChannelTransactionParameters_set_holder_selected_contest_delay(&this_ptr_conv, val);
13731 }
13732
13733 jboolean  __attribute__((visibility("default"))) TS_ChannelTransactionParameters_get_is_outbound_from_holder(uint32_t this_ptr) {
13734         LDKChannelTransactionParameters this_ptr_conv;
13735         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13736         this_ptr_conv.is_owned = false;
13737         jboolean ret_val = ChannelTransactionParameters_get_is_outbound_from_holder(&this_ptr_conv);
13738         return ret_val;
13739 }
13740
13741 void  __attribute__((visibility("default"))) TS_ChannelTransactionParameters_set_is_outbound_from_holder(uint32_t this_ptr, jboolean val) {
13742         LDKChannelTransactionParameters this_ptr_conv;
13743         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13744         this_ptr_conv.is_owned = false;
13745         ChannelTransactionParameters_set_is_outbound_from_holder(&this_ptr_conv, val);
13746 }
13747
13748 uint32_t  __attribute__((visibility("default"))) TS_ChannelTransactionParameters_get_counterparty_parameters(uint32_t this_ptr) {
13749         LDKChannelTransactionParameters this_ptr_conv;
13750         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13751         this_ptr_conv.is_owned = false;
13752         LDKCounterpartyChannelTransactionParameters ret_var = ChannelTransactionParameters_get_counterparty_parameters(&this_ptr_conv);
13753         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13754         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13755         long ret_ref = (long)ret_var.inner;
13756         if (ret_var.is_owned) {
13757                 ret_ref |= 1;
13758         }
13759         return ret_ref;
13760 }
13761
13762 void  __attribute__((visibility("default"))) TS_ChannelTransactionParameters_set_counterparty_parameters(uint32_t this_ptr, uint32_t val) {
13763         LDKChannelTransactionParameters this_ptr_conv;
13764         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13765         this_ptr_conv.is_owned = false;
13766         LDKCounterpartyChannelTransactionParameters val_conv;
13767         val_conv.inner = (void*)(val & (~1));
13768         val_conv.is_owned = (val & 1) || (val == 0);
13769         val_conv = CounterpartyChannelTransactionParameters_clone(&val_conv);
13770         ChannelTransactionParameters_set_counterparty_parameters(&this_ptr_conv, val_conv);
13771 }
13772
13773 uint32_t  __attribute__((visibility("default"))) TS_ChannelTransactionParameters_get_funding_outpoint(uint32_t this_ptr) {
13774         LDKChannelTransactionParameters this_ptr_conv;
13775         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13776         this_ptr_conv.is_owned = false;
13777         LDKOutPoint ret_var = ChannelTransactionParameters_get_funding_outpoint(&this_ptr_conv);
13778         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13779         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13780         long ret_ref = (long)ret_var.inner;
13781         if (ret_var.is_owned) {
13782                 ret_ref |= 1;
13783         }
13784         return ret_ref;
13785 }
13786
13787 void  __attribute__((visibility("default"))) TS_ChannelTransactionParameters_set_funding_outpoint(uint32_t this_ptr, uint32_t val) {
13788         LDKChannelTransactionParameters this_ptr_conv;
13789         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13790         this_ptr_conv.is_owned = false;
13791         LDKOutPoint val_conv;
13792         val_conv.inner = (void*)(val & (~1));
13793         val_conv.is_owned = (val & 1) || (val == 0);
13794         val_conv = OutPoint_clone(&val_conv);
13795         ChannelTransactionParameters_set_funding_outpoint(&this_ptr_conv, val_conv);
13796 }
13797
13798 uint32_t  __attribute__((visibility("default"))) 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) {
13799         LDKChannelPublicKeys holder_pubkeys_arg_conv;
13800         holder_pubkeys_arg_conv.inner = (void*)(holder_pubkeys_arg & (~1));
13801         holder_pubkeys_arg_conv.is_owned = (holder_pubkeys_arg & 1) || (holder_pubkeys_arg == 0);
13802         holder_pubkeys_arg_conv = ChannelPublicKeys_clone(&holder_pubkeys_arg_conv);
13803         LDKCounterpartyChannelTransactionParameters counterparty_parameters_arg_conv;
13804         counterparty_parameters_arg_conv.inner = (void*)(counterparty_parameters_arg & (~1));
13805         counterparty_parameters_arg_conv.is_owned = (counterparty_parameters_arg & 1) || (counterparty_parameters_arg == 0);
13806         counterparty_parameters_arg_conv = CounterpartyChannelTransactionParameters_clone(&counterparty_parameters_arg_conv);
13807         LDKOutPoint funding_outpoint_arg_conv;
13808         funding_outpoint_arg_conv.inner = (void*)(funding_outpoint_arg & (~1));
13809         funding_outpoint_arg_conv.is_owned = (funding_outpoint_arg & 1) || (funding_outpoint_arg == 0);
13810         funding_outpoint_arg_conv = OutPoint_clone(&funding_outpoint_arg_conv);
13811         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);
13812         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13813         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13814         long ret_ref = (long)ret_var.inner;
13815         if (ret_var.is_owned) {
13816                 ret_ref |= 1;
13817         }
13818         return ret_ref;
13819 }
13820
13821 void  __attribute__((visibility("default"))) TS_CounterpartyChannelTransactionParameters_free(uint32_t this_ptr) {
13822         LDKCounterpartyChannelTransactionParameters this_ptr_conv;
13823         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13824         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13825         CounterpartyChannelTransactionParameters_free(this_ptr_conv);
13826 }
13827
13828 uint32_t  __attribute__((visibility("default"))) TS_CounterpartyChannelTransactionParameters_clone(uint32_t orig) {
13829         LDKCounterpartyChannelTransactionParameters orig_conv;
13830         orig_conv.inner = (void*)(orig & (~1));
13831         orig_conv.is_owned = false;
13832         LDKCounterpartyChannelTransactionParameters ret_var = CounterpartyChannelTransactionParameters_clone(&orig_conv);
13833         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13834         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13835         long ret_ref = (long)ret_var.inner;
13836         if (ret_var.is_owned) {
13837                 ret_ref |= 1;
13838         }
13839         return ret_ref;
13840 }
13841
13842 uint32_t  __attribute__((visibility("default"))) TS_CounterpartyChannelTransactionParameters_get_pubkeys(uint32_t this_ptr) {
13843         LDKCounterpartyChannelTransactionParameters this_ptr_conv;
13844         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13845         this_ptr_conv.is_owned = false;
13846         LDKChannelPublicKeys ret_var = CounterpartyChannelTransactionParameters_get_pubkeys(&this_ptr_conv);
13847         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13848         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13849         long ret_ref = (long)ret_var.inner;
13850         if (ret_var.is_owned) {
13851                 ret_ref |= 1;
13852         }
13853         return ret_ref;
13854 }
13855
13856 void  __attribute__((visibility("default"))) TS_CounterpartyChannelTransactionParameters_set_pubkeys(uint32_t this_ptr, uint32_t val) {
13857         LDKCounterpartyChannelTransactionParameters this_ptr_conv;
13858         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13859         this_ptr_conv.is_owned = false;
13860         LDKChannelPublicKeys val_conv;
13861         val_conv.inner = (void*)(val & (~1));
13862         val_conv.is_owned = (val & 1) || (val == 0);
13863         val_conv = ChannelPublicKeys_clone(&val_conv);
13864         CounterpartyChannelTransactionParameters_set_pubkeys(&this_ptr_conv, val_conv);
13865 }
13866
13867 int16_t  __attribute__((visibility("default"))) TS_CounterpartyChannelTransactionParameters_get_selected_contest_delay(uint32_t this_ptr) {
13868         LDKCounterpartyChannelTransactionParameters this_ptr_conv;
13869         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13870         this_ptr_conv.is_owned = false;
13871         int16_t ret_val = CounterpartyChannelTransactionParameters_get_selected_contest_delay(&this_ptr_conv);
13872         return ret_val;
13873 }
13874
13875 void  __attribute__((visibility("default"))) TS_CounterpartyChannelTransactionParameters_set_selected_contest_delay(uint32_t this_ptr, int16_t val) {
13876         LDKCounterpartyChannelTransactionParameters this_ptr_conv;
13877         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13878         this_ptr_conv.is_owned = false;
13879         CounterpartyChannelTransactionParameters_set_selected_contest_delay(&this_ptr_conv, val);
13880 }
13881
13882 uint32_t  __attribute__((visibility("default"))) TS_CounterpartyChannelTransactionParameters_new(uint32_t pubkeys_arg, int16_t selected_contest_delay_arg) {
13883         LDKChannelPublicKeys pubkeys_arg_conv;
13884         pubkeys_arg_conv.inner = (void*)(pubkeys_arg & (~1));
13885         pubkeys_arg_conv.is_owned = (pubkeys_arg & 1) || (pubkeys_arg == 0);
13886         pubkeys_arg_conv = ChannelPublicKeys_clone(&pubkeys_arg_conv);
13887         LDKCounterpartyChannelTransactionParameters ret_var = CounterpartyChannelTransactionParameters_new(pubkeys_arg_conv, selected_contest_delay_arg);
13888         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13889         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13890         long ret_ref = (long)ret_var.inner;
13891         if (ret_var.is_owned) {
13892                 ret_ref |= 1;
13893         }
13894         return ret_ref;
13895 }
13896
13897 jboolean  __attribute__((visibility("default"))) TS_ChannelTransactionParameters_is_populated(uint32_t this_arg) {
13898         LDKChannelTransactionParameters this_arg_conv;
13899         this_arg_conv.inner = (void*)(this_arg & (~1));
13900         this_arg_conv.is_owned = false;
13901         jboolean ret_val = ChannelTransactionParameters_is_populated(&this_arg_conv);
13902         return ret_val;
13903 }
13904
13905 uint32_t  __attribute__((visibility("default"))) TS_ChannelTransactionParameters_as_holder_broadcastable(uint32_t this_arg) {
13906         LDKChannelTransactionParameters this_arg_conv;
13907         this_arg_conv.inner = (void*)(this_arg & (~1));
13908         this_arg_conv.is_owned = false;
13909         LDKDirectedChannelTransactionParameters ret_var = ChannelTransactionParameters_as_holder_broadcastable(&this_arg_conv);
13910         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13911         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13912         long ret_ref = (long)ret_var.inner;
13913         if (ret_var.is_owned) {
13914                 ret_ref |= 1;
13915         }
13916         return ret_ref;
13917 }
13918
13919 uint32_t  __attribute__((visibility("default"))) TS_ChannelTransactionParameters_as_counterparty_broadcastable(uint32_t this_arg) {
13920         LDKChannelTransactionParameters this_arg_conv;
13921         this_arg_conv.inner = (void*)(this_arg & (~1));
13922         this_arg_conv.is_owned = false;
13923         LDKDirectedChannelTransactionParameters ret_var = ChannelTransactionParameters_as_counterparty_broadcastable(&this_arg_conv);
13924         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13925         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13926         long ret_ref = (long)ret_var.inner;
13927         if (ret_var.is_owned) {
13928                 ret_ref |= 1;
13929         }
13930         return ret_ref;
13931 }
13932
13933 int8_tArray  __attribute__((visibility("default"))) TS_CounterpartyChannelTransactionParameters_write(uint32_t obj) {
13934         LDKCounterpartyChannelTransactionParameters obj_conv;
13935         obj_conv.inner = (void*)(obj & (~1));
13936         obj_conv.is_owned = false;
13937         LDKCVec_u8Z arg_var = CounterpartyChannelTransactionParameters_write(&obj_conv);
13938         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
13939         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
13940         CVec_u8Z_free(arg_var);
13941         return arg_arr;
13942 }
13943
13944 uint32_t  __attribute__((visibility("default"))) TS_CounterpartyChannelTransactionParameters_read(int8_tArray ser) {
13945         LDKu8slice ser_ref;
13946         ser_ref.datalen = *((uint32_t*)ser);
13947         ser_ref.data = (int8_t*)(ser + 4);
13948         LDKCounterpartyChannelTransactionParameters ret_var = CounterpartyChannelTransactionParameters_read(ser_ref);
13949         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13950         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13951         long ret_ref = (long)ret_var.inner;
13952         if (ret_var.is_owned) {
13953                 ret_ref |= 1;
13954         }
13955         return ret_ref;
13956 }
13957
13958 int8_tArray  __attribute__((visibility("default"))) TS_ChannelTransactionParameters_write(uint32_t obj) {
13959         LDKChannelTransactionParameters obj_conv;
13960         obj_conv.inner = (void*)(obj & (~1));
13961         obj_conv.is_owned = false;
13962         LDKCVec_u8Z arg_var = ChannelTransactionParameters_write(&obj_conv);
13963         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
13964         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
13965         CVec_u8Z_free(arg_var);
13966         return arg_arr;
13967 }
13968
13969 uint32_t  __attribute__((visibility("default"))) TS_ChannelTransactionParameters_read(int8_tArray ser) {
13970         LDKu8slice ser_ref;
13971         ser_ref.datalen = *((uint32_t*)ser);
13972         ser_ref.data = (int8_t*)(ser + 4);
13973         LDKChannelTransactionParameters ret_var = ChannelTransactionParameters_read(ser_ref);
13974         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13975         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13976         long ret_ref = (long)ret_var.inner;
13977         if (ret_var.is_owned) {
13978                 ret_ref |= 1;
13979         }
13980         return ret_ref;
13981 }
13982
13983 void  __attribute__((visibility("default"))) TS_DirectedChannelTransactionParameters_free(uint32_t this_ptr) {
13984         LDKDirectedChannelTransactionParameters this_ptr_conv;
13985         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13986         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13987         DirectedChannelTransactionParameters_free(this_ptr_conv);
13988 }
13989
13990 uint32_t  __attribute__((visibility("default"))) TS_DirectedChannelTransactionParameters_broadcaster_pubkeys(uint32_t this_arg) {
13991         LDKDirectedChannelTransactionParameters this_arg_conv;
13992         this_arg_conv.inner = (void*)(this_arg & (~1));
13993         this_arg_conv.is_owned = false;
13994         LDKChannelPublicKeys ret_var = DirectedChannelTransactionParameters_broadcaster_pubkeys(&this_arg_conv);
13995         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13996         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13997         long ret_ref = (long)ret_var.inner;
13998         if (ret_var.is_owned) {
13999                 ret_ref |= 1;
14000         }
14001         return ret_ref;
14002 }
14003
14004 uint32_t  __attribute__((visibility("default"))) TS_DirectedChannelTransactionParameters_countersignatory_pubkeys(uint32_t this_arg) {
14005         LDKDirectedChannelTransactionParameters this_arg_conv;
14006         this_arg_conv.inner = (void*)(this_arg & (~1));
14007         this_arg_conv.is_owned = false;
14008         LDKChannelPublicKeys ret_var = DirectedChannelTransactionParameters_countersignatory_pubkeys(&this_arg_conv);
14009         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14010         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14011         long ret_ref = (long)ret_var.inner;
14012         if (ret_var.is_owned) {
14013                 ret_ref |= 1;
14014         }
14015         return ret_ref;
14016 }
14017
14018 int16_t  __attribute__((visibility("default"))) TS_DirectedChannelTransactionParameters_contest_delay(uint32_t this_arg) {
14019         LDKDirectedChannelTransactionParameters this_arg_conv;
14020         this_arg_conv.inner = (void*)(this_arg & (~1));
14021         this_arg_conv.is_owned = false;
14022         int16_t ret_val = DirectedChannelTransactionParameters_contest_delay(&this_arg_conv);
14023         return ret_val;
14024 }
14025
14026 jboolean  __attribute__((visibility("default"))) TS_DirectedChannelTransactionParameters_is_outbound(uint32_t this_arg) {
14027         LDKDirectedChannelTransactionParameters this_arg_conv;
14028         this_arg_conv.inner = (void*)(this_arg & (~1));
14029         this_arg_conv.is_owned = false;
14030         jboolean ret_val = DirectedChannelTransactionParameters_is_outbound(&this_arg_conv);
14031         return ret_val;
14032 }
14033
14034 uint32_t  __attribute__((visibility("default"))) TS_DirectedChannelTransactionParameters_funding_outpoint(uint32_t this_arg) {
14035         LDKDirectedChannelTransactionParameters this_arg_conv;
14036         this_arg_conv.inner = (void*)(this_arg & (~1));
14037         this_arg_conv.is_owned = false;
14038         LDKOutPoint ret_var = DirectedChannelTransactionParameters_funding_outpoint(&this_arg_conv);
14039         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14040         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14041         long ret_ref = (long)ret_var.inner;
14042         if (ret_var.is_owned) {
14043                 ret_ref |= 1;
14044         }
14045         return ret_ref;
14046 }
14047
14048 void  __attribute__((visibility("default"))) TS_HolderCommitmentTransaction_free(uint32_t this_ptr) {
14049         LDKHolderCommitmentTransaction this_ptr_conv;
14050         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14051         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
14052         HolderCommitmentTransaction_free(this_ptr_conv);
14053 }
14054
14055 uint32_t  __attribute__((visibility("default"))) TS_HolderCommitmentTransaction_clone(uint32_t orig) {
14056         LDKHolderCommitmentTransaction orig_conv;
14057         orig_conv.inner = (void*)(orig & (~1));
14058         orig_conv.is_owned = false;
14059         LDKHolderCommitmentTransaction ret_var = HolderCommitmentTransaction_clone(&orig_conv);
14060         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14061         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14062         long ret_ref = (long)ret_var.inner;
14063         if (ret_var.is_owned) {
14064                 ret_ref |= 1;
14065         }
14066         return ret_ref;
14067 }
14068
14069 int8_tArray  __attribute__((visibility("default"))) TS_HolderCommitmentTransaction_get_counterparty_sig(uint32_t this_ptr) {
14070         LDKHolderCommitmentTransaction this_ptr_conv;
14071         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14072         this_ptr_conv.is_owned = false;
14073         int8_tArray arg_arr = init_arr(64, sizeof(uint8_t), "Native int8_tArray Bytes");
14074         memcpy((uint8_t*)(arg_arr + 4), HolderCommitmentTransaction_get_counterparty_sig(&this_ptr_conv).compact_form, 64);
14075         return arg_arr;
14076 }
14077
14078 void  __attribute__((visibility("default"))) TS_HolderCommitmentTransaction_set_counterparty_sig(uint32_t this_ptr, int8_tArray val) {
14079         LDKHolderCommitmentTransaction this_ptr_conv;
14080         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14081         this_ptr_conv.is_owned = false;
14082         LDKSignature val_ref;
14083         CHECK(*((uint32_t*)val) == 64);
14084         memcpy(val_ref.compact_form, (uint8_t*)(val + 4), 64);
14085         HolderCommitmentTransaction_set_counterparty_sig(&this_ptr_conv, val_ref);
14086 }
14087
14088 void  __attribute__((visibility("default"))) TS_HolderCommitmentTransaction_set_counterparty_htlc_sigs(uint32_t this_ptr, ptrArray val) {
14089         LDKHolderCommitmentTransaction this_ptr_conv;
14090         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14091         this_ptr_conv.is_owned = false;
14092         LDKCVec_SignatureZ val_constr;
14093         val_constr.datalen = *((uint32_t*)val);
14094         if (val_constr.datalen > 0)
14095                 val_constr.data = MALLOC(val_constr.datalen * sizeof(LDKSignature), "LDKCVec_SignatureZ Elements");
14096         else
14097                 val_constr.data = NULL;
14098         int8_tArray* val_vals = (int8_tArray*)(val + 4);
14099         for (size_t m = 0; m < val_constr.datalen; m++) {
14100                 int8_tArray arr_conv_12 = val_vals[m];
14101                 LDKSignature arr_conv_12_ref;
14102                 CHECK(*((uint32_t*)arr_conv_12) == 64);
14103                 memcpy(arr_conv_12_ref.compact_form, (uint8_t*)(arr_conv_12 + 4), 64);
14104                 val_constr.data[m] = arr_conv_12_ref;
14105         }
14106         HolderCommitmentTransaction_set_counterparty_htlc_sigs(&this_ptr_conv, val_constr);
14107 }
14108
14109 int8_tArray  __attribute__((visibility("default"))) TS_HolderCommitmentTransaction_write(uint32_t obj) {
14110         LDKHolderCommitmentTransaction obj_conv;
14111         obj_conv.inner = (void*)(obj & (~1));
14112         obj_conv.is_owned = false;
14113         LDKCVec_u8Z arg_var = HolderCommitmentTransaction_write(&obj_conv);
14114         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
14115         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
14116         CVec_u8Z_free(arg_var);
14117         return arg_arr;
14118 }
14119
14120 uint32_t  __attribute__((visibility("default"))) TS_HolderCommitmentTransaction_read(int8_tArray ser) {
14121         LDKu8slice ser_ref;
14122         ser_ref.datalen = *((uint32_t*)ser);
14123         ser_ref.data = (int8_t*)(ser + 4);
14124         LDKHolderCommitmentTransaction ret_var = HolderCommitmentTransaction_read(ser_ref);
14125         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14126         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14127         long ret_ref = (long)ret_var.inner;
14128         if (ret_var.is_owned) {
14129                 ret_ref |= 1;
14130         }
14131         return ret_ref;
14132 }
14133
14134 uint32_t  __attribute__((visibility("default"))) 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) {
14135         LDKCommitmentTransaction commitment_tx_conv;
14136         commitment_tx_conv.inner = (void*)(commitment_tx & (~1));
14137         commitment_tx_conv.is_owned = (commitment_tx & 1) || (commitment_tx == 0);
14138         commitment_tx_conv = CommitmentTransaction_clone(&commitment_tx_conv);
14139         LDKSignature counterparty_sig_ref;
14140         CHECK(*((uint32_t*)counterparty_sig) == 64);
14141         memcpy(counterparty_sig_ref.compact_form, (uint8_t*)(counterparty_sig + 4), 64);
14142         LDKCVec_SignatureZ counterparty_htlc_sigs_constr;
14143         counterparty_htlc_sigs_constr.datalen = *((uint32_t*)counterparty_htlc_sigs);
14144         if (counterparty_htlc_sigs_constr.datalen > 0)
14145                 counterparty_htlc_sigs_constr.data = MALLOC(counterparty_htlc_sigs_constr.datalen * sizeof(LDKSignature), "LDKCVec_SignatureZ Elements");
14146         else
14147                 counterparty_htlc_sigs_constr.data = NULL;
14148         int8_tArray* counterparty_htlc_sigs_vals = (int8_tArray*)(counterparty_htlc_sigs + 4);
14149         for (size_t m = 0; m < counterparty_htlc_sigs_constr.datalen; m++) {
14150                 int8_tArray arr_conv_12 = counterparty_htlc_sigs_vals[m];
14151                 LDKSignature arr_conv_12_ref;
14152                 CHECK(*((uint32_t*)arr_conv_12) == 64);
14153                 memcpy(arr_conv_12_ref.compact_form, (uint8_t*)(arr_conv_12 + 4), 64);
14154                 counterparty_htlc_sigs_constr.data[m] = arr_conv_12_ref;
14155         }
14156         LDKPublicKey holder_funding_key_ref;
14157         CHECK(*((uint32_t*)holder_funding_key) == 33);
14158         memcpy(holder_funding_key_ref.compressed_form, (uint8_t*)(holder_funding_key + 4), 33);
14159         LDKPublicKey counterparty_funding_key_ref;
14160         CHECK(*((uint32_t*)counterparty_funding_key) == 33);
14161         memcpy(counterparty_funding_key_ref.compressed_form, (uint8_t*)(counterparty_funding_key + 4), 33);
14162         LDKHolderCommitmentTransaction ret_var = HolderCommitmentTransaction_new(commitment_tx_conv, counterparty_sig_ref, counterparty_htlc_sigs_constr, holder_funding_key_ref, counterparty_funding_key_ref);
14163         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14164         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14165         long ret_ref = (long)ret_var.inner;
14166         if (ret_var.is_owned) {
14167                 ret_ref |= 1;
14168         }
14169         return ret_ref;
14170 }
14171
14172 void  __attribute__((visibility("default"))) TS_BuiltCommitmentTransaction_free(uint32_t this_ptr) {
14173         LDKBuiltCommitmentTransaction this_ptr_conv;
14174         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14175         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
14176         BuiltCommitmentTransaction_free(this_ptr_conv);
14177 }
14178
14179 uint32_t  __attribute__((visibility("default"))) TS_BuiltCommitmentTransaction_clone(uint32_t orig) {
14180         LDKBuiltCommitmentTransaction orig_conv;
14181         orig_conv.inner = (void*)(orig & (~1));
14182         orig_conv.is_owned = false;
14183         LDKBuiltCommitmentTransaction ret_var = BuiltCommitmentTransaction_clone(&orig_conv);
14184         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14185         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14186         long ret_ref = (long)ret_var.inner;
14187         if (ret_var.is_owned) {
14188                 ret_ref |= 1;
14189         }
14190         return ret_ref;
14191 }
14192
14193 int8_tArray  __attribute__((visibility("default"))) TS_BuiltCommitmentTransaction_get_transaction(uint32_t this_ptr) {
14194         LDKBuiltCommitmentTransaction this_ptr_conv;
14195         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14196         this_ptr_conv.is_owned = false;
14197         LDKTransaction arg_var = BuiltCommitmentTransaction_get_transaction(&this_ptr_conv);
14198         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
14199         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
14200         Transaction_free(arg_var);
14201         return arg_arr;
14202 }
14203
14204 void  __attribute__((visibility("default"))) TS_BuiltCommitmentTransaction_set_transaction(uint32_t this_ptr, int8_tArray val) {
14205         LDKBuiltCommitmentTransaction this_ptr_conv;
14206         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14207         this_ptr_conv.is_owned = false;
14208         LDKTransaction val_ref;
14209         val_ref.datalen = *((uint32_t*)val);
14210         val_ref.data = MALLOC(val_ref.datalen, "LDKTransaction Bytes");
14211         memcpy(val_ref.data, (uint8_t*)(val + 4), val_ref.datalen);
14212         val_ref.data_is_owned = true;
14213         BuiltCommitmentTransaction_set_transaction(&this_ptr_conv, val_ref);
14214 }
14215
14216 int8_tArray  __attribute__((visibility("default"))) TS_BuiltCommitmentTransaction_get_txid(uint32_t this_ptr) {
14217         LDKBuiltCommitmentTransaction this_ptr_conv;
14218         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14219         this_ptr_conv.is_owned = false;
14220         int8_tArray ret_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
14221         memcpy((uint8_t*)(ret_arr + 4), *BuiltCommitmentTransaction_get_txid(&this_ptr_conv), 32);
14222         return ret_arr;
14223 }
14224
14225 void  __attribute__((visibility("default"))) TS_BuiltCommitmentTransaction_set_txid(uint32_t this_ptr, int8_tArray val) {
14226         LDKBuiltCommitmentTransaction this_ptr_conv;
14227         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14228         this_ptr_conv.is_owned = false;
14229         LDKThirtyTwoBytes val_ref;
14230         CHECK(*((uint32_t*)val) == 32);
14231         memcpy(val_ref.data, (uint8_t*)(val + 4), 32);
14232         BuiltCommitmentTransaction_set_txid(&this_ptr_conv, val_ref);
14233 }
14234
14235 uint32_t  __attribute__((visibility("default"))) TS_BuiltCommitmentTransaction_new(int8_tArray transaction_arg, int8_tArray txid_arg) {
14236         LDKTransaction transaction_arg_ref;
14237         transaction_arg_ref.datalen = *((uint32_t*)transaction_arg);
14238         transaction_arg_ref.data = MALLOC(transaction_arg_ref.datalen, "LDKTransaction Bytes");
14239         memcpy(transaction_arg_ref.data, (uint8_t*)(transaction_arg + 4), transaction_arg_ref.datalen);
14240         transaction_arg_ref.data_is_owned = true;
14241         LDKThirtyTwoBytes txid_arg_ref;
14242         CHECK(*((uint32_t*)txid_arg) == 32);
14243         memcpy(txid_arg_ref.data, (uint8_t*)(txid_arg + 4), 32);
14244         LDKBuiltCommitmentTransaction ret_var = BuiltCommitmentTransaction_new(transaction_arg_ref, txid_arg_ref);
14245         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14246         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14247         long ret_ref = (long)ret_var.inner;
14248         if (ret_var.is_owned) {
14249                 ret_ref |= 1;
14250         }
14251         return ret_ref;
14252 }
14253
14254 int8_tArray  __attribute__((visibility("default"))) TS_BuiltCommitmentTransaction_write(uint32_t obj) {
14255         LDKBuiltCommitmentTransaction obj_conv;
14256         obj_conv.inner = (void*)(obj & (~1));
14257         obj_conv.is_owned = false;
14258         LDKCVec_u8Z arg_var = BuiltCommitmentTransaction_write(&obj_conv);
14259         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
14260         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
14261         CVec_u8Z_free(arg_var);
14262         return arg_arr;
14263 }
14264
14265 uint32_t  __attribute__((visibility("default"))) TS_BuiltCommitmentTransaction_read(int8_tArray ser) {
14266         LDKu8slice ser_ref;
14267         ser_ref.datalen = *((uint32_t*)ser);
14268         ser_ref.data = (int8_t*)(ser + 4);
14269         LDKBuiltCommitmentTransaction ret_var = BuiltCommitmentTransaction_read(ser_ref);
14270         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14271         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14272         long ret_ref = (long)ret_var.inner;
14273         if (ret_var.is_owned) {
14274                 ret_ref |= 1;
14275         }
14276         return ret_ref;
14277 }
14278
14279 int8_tArray  __attribute__((visibility("default"))) TS_BuiltCommitmentTransaction_get_sighash_all(uint32_t this_arg, int8_tArray funding_redeemscript, int64_t channel_value_satoshis) {
14280         LDKBuiltCommitmentTransaction this_arg_conv;
14281         this_arg_conv.inner = (void*)(this_arg & (~1));
14282         this_arg_conv.is_owned = false;
14283         LDKu8slice funding_redeemscript_ref;
14284         funding_redeemscript_ref.datalen = *((uint32_t*)funding_redeemscript);
14285         funding_redeemscript_ref.data = (int8_t*)(funding_redeemscript + 4);
14286         int8_tArray arg_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
14287         memcpy((uint8_t*)(arg_arr + 4), BuiltCommitmentTransaction_get_sighash_all(&this_arg_conv, funding_redeemscript_ref, channel_value_satoshis).data, 32);
14288         return arg_arr;
14289 }
14290
14291 int8_tArray  __attribute__((visibility("default"))) TS_BuiltCommitmentTransaction_sign(uint32_t this_arg, int8_tArray funding_key, int8_tArray funding_redeemscript, int64_t channel_value_satoshis) {
14292         LDKBuiltCommitmentTransaction this_arg_conv;
14293         this_arg_conv.inner = (void*)(this_arg & (~1));
14294         this_arg_conv.is_owned = false;
14295         unsigned char funding_key_arr[32];
14296         CHECK(*((uint32_t*)funding_key) == 32);
14297         memcpy(funding_key_arr, (uint8_t*)(funding_key + 4), 32);
14298         unsigned char (*funding_key_ref)[32] = &funding_key_arr;
14299         LDKu8slice funding_redeemscript_ref;
14300         funding_redeemscript_ref.datalen = *((uint32_t*)funding_redeemscript);
14301         funding_redeemscript_ref.data = (int8_t*)(funding_redeemscript + 4);
14302         int8_tArray arg_arr = init_arr(64, sizeof(uint8_t), "Native int8_tArray Bytes");
14303         memcpy((uint8_t*)(arg_arr + 4), BuiltCommitmentTransaction_sign(&this_arg_conv, funding_key_ref, funding_redeemscript_ref, channel_value_satoshis).compact_form, 64);
14304         return arg_arr;
14305 }
14306
14307 void  __attribute__((visibility("default"))) TS_CommitmentTransaction_free(uint32_t this_ptr) {
14308         LDKCommitmentTransaction this_ptr_conv;
14309         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14310         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
14311         CommitmentTransaction_free(this_ptr_conv);
14312 }
14313
14314 uint32_t  __attribute__((visibility("default"))) TS_CommitmentTransaction_clone(uint32_t orig) {
14315         LDKCommitmentTransaction orig_conv;
14316         orig_conv.inner = (void*)(orig & (~1));
14317         orig_conv.is_owned = false;
14318         LDKCommitmentTransaction ret_var = CommitmentTransaction_clone(&orig_conv);
14319         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14320         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14321         long ret_ref = (long)ret_var.inner;
14322         if (ret_var.is_owned) {
14323                 ret_ref |= 1;
14324         }
14325         return ret_ref;
14326 }
14327
14328 int8_tArray  __attribute__((visibility("default"))) TS_CommitmentTransaction_write(uint32_t obj) {
14329         LDKCommitmentTransaction obj_conv;
14330         obj_conv.inner = (void*)(obj & (~1));
14331         obj_conv.is_owned = false;
14332         LDKCVec_u8Z arg_var = CommitmentTransaction_write(&obj_conv);
14333         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
14334         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
14335         CVec_u8Z_free(arg_var);
14336         return arg_arr;
14337 }
14338
14339 uint32_t  __attribute__((visibility("default"))) TS_CommitmentTransaction_read(int8_tArray ser) {
14340         LDKu8slice ser_ref;
14341         ser_ref.datalen = *((uint32_t*)ser);
14342         ser_ref.data = (int8_t*)(ser + 4);
14343         LDKCommitmentTransaction ret_var = CommitmentTransaction_read(ser_ref);
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 int64_t  __attribute__((visibility("default"))) TS_CommitmentTransaction_commitment_number(uint32_t this_arg) {
14354         LDKCommitmentTransaction this_arg_conv;
14355         this_arg_conv.inner = (void*)(this_arg & (~1));
14356         this_arg_conv.is_owned = false;
14357         int64_t ret_val = CommitmentTransaction_commitment_number(&this_arg_conv);
14358         return ret_val;
14359 }
14360
14361 int64_t  __attribute__((visibility("default"))) TS_CommitmentTransaction_to_broadcaster_value_sat(uint32_t this_arg) {
14362         LDKCommitmentTransaction this_arg_conv;
14363         this_arg_conv.inner = (void*)(this_arg & (~1));
14364         this_arg_conv.is_owned = false;
14365         int64_t ret_val = CommitmentTransaction_to_broadcaster_value_sat(&this_arg_conv);
14366         return ret_val;
14367 }
14368
14369 int64_t  __attribute__((visibility("default"))) TS_CommitmentTransaction_to_countersignatory_value_sat(uint32_t this_arg) {
14370         LDKCommitmentTransaction this_arg_conv;
14371         this_arg_conv.inner = (void*)(this_arg & (~1));
14372         this_arg_conv.is_owned = false;
14373         int64_t ret_val = CommitmentTransaction_to_countersignatory_value_sat(&this_arg_conv);
14374         return ret_val;
14375 }
14376
14377 int32_t  __attribute__((visibility("default"))) TS_CommitmentTransaction_feerate_per_kw(uint32_t this_arg) {
14378         LDKCommitmentTransaction this_arg_conv;
14379         this_arg_conv.inner = (void*)(this_arg & (~1));
14380         this_arg_conv.is_owned = false;
14381         int32_t ret_val = CommitmentTransaction_feerate_per_kw(&this_arg_conv);
14382         return ret_val;
14383 }
14384
14385 uint32_t  __attribute__((visibility("default"))) TS_CommitmentTransaction_trust(uint32_t this_arg) {
14386         LDKCommitmentTransaction this_arg_conv;
14387         this_arg_conv.inner = (void*)(this_arg & (~1));
14388         this_arg_conv.is_owned = false;
14389         LDKTrustedCommitmentTransaction ret_var = CommitmentTransaction_trust(&this_arg_conv);
14390         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14391         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14392         long ret_ref = (long)ret_var.inner;
14393         if (ret_var.is_owned) {
14394                 ret_ref |= 1;
14395         }
14396         return ret_ref;
14397 }
14398
14399 uint32_t  __attribute__((visibility("default"))) TS_CommitmentTransaction_verify(uint32_t this_arg, uint32_t channel_parameters, uint32_t broadcaster_keys, uint32_t countersignatory_keys) {
14400         LDKCommitmentTransaction this_arg_conv;
14401         this_arg_conv.inner = (void*)(this_arg & (~1));
14402         this_arg_conv.is_owned = false;
14403         LDKDirectedChannelTransactionParameters channel_parameters_conv;
14404         channel_parameters_conv.inner = (void*)(channel_parameters & (~1));
14405         channel_parameters_conv.is_owned = false;
14406         LDKChannelPublicKeys broadcaster_keys_conv;
14407         broadcaster_keys_conv.inner = (void*)(broadcaster_keys & (~1));
14408         broadcaster_keys_conv.is_owned = false;
14409         LDKChannelPublicKeys countersignatory_keys_conv;
14410         countersignatory_keys_conv.inner = (void*)(countersignatory_keys & (~1));
14411         countersignatory_keys_conv.is_owned = false;
14412         LDKCResult_TrustedCommitmentTransactionNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_TrustedCommitmentTransactionNoneZ), "LDKCResult_TrustedCommitmentTransactionNoneZ");
14413         *ret_conv = CommitmentTransaction_verify(&this_arg_conv, &channel_parameters_conv, &broadcaster_keys_conv, &countersignatory_keys_conv);
14414         return (long)ret_conv;
14415 }
14416
14417 void  __attribute__((visibility("default"))) TS_TrustedCommitmentTransaction_free(uint32_t this_ptr) {
14418         LDKTrustedCommitmentTransaction this_ptr_conv;
14419         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14420         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
14421         TrustedCommitmentTransaction_free(this_ptr_conv);
14422 }
14423
14424 int8_tArray  __attribute__((visibility("default"))) TS_TrustedCommitmentTransaction_txid(uint32_t this_arg) {
14425         LDKTrustedCommitmentTransaction this_arg_conv;
14426         this_arg_conv.inner = (void*)(this_arg & (~1));
14427         this_arg_conv.is_owned = false;
14428         int8_tArray arg_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
14429         memcpy((uint8_t*)(arg_arr + 4), TrustedCommitmentTransaction_txid(&this_arg_conv).data, 32);
14430         return arg_arr;
14431 }
14432
14433 uint32_t  __attribute__((visibility("default"))) TS_TrustedCommitmentTransaction_built_transaction(uint32_t this_arg) {
14434         LDKTrustedCommitmentTransaction this_arg_conv;
14435         this_arg_conv.inner = (void*)(this_arg & (~1));
14436         this_arg_conv.is_owned = false;
14437         LDKBuiltCommitmentTransaction ret_var = TrustedCommitmentTransaction_built_transaction(&this_arg_conv);
14438         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14439         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14440         long ret_ref = (long)ret_var.inner;
14441         if (ret_var.is_owned) {
14442                 ret_ref |= 1;
14443         }
14444         return ret_ref;
14445 }
14446
14447 uint32_t  __attribute__((visibility("default"))) TS_TrustedCommitmentTransaction_keys(uint32_t this_arg) {
14448         LDKTrustedCommitmentTransaction this_arg_conv;
14449         this_arg_conv.inner = (void*)(this_arg & (~1));
14450         this_arg_conv.is_owned = false;
14451         LDKTxCreationKeys ret_var = TrustedCommitmentTransaction_keys(&this_arg_conv);
14452         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14453         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14454         long ret_ref = (long)ret_var.inner;
14455         if (ret_var.is_owned) {
14456                 ret_ref |= 1;
14457         }
14458         return ret_ref;
14459 }
14460
14461 uint32_t  __attribute__((visibility("default"))) TS_TrustedCommitmentTransaction_get_htlc_sigs(uint32_t this_arg, int8_tArray htlc_base_key, uint32_t channel_parameters) {
14462         LDKTrustedCommitmentTransaction this_arg_conv;
14463         this_arg_conv.inner = (void*)(this_arg & (~1));
14464         this_arg_conv.is_owned = false;
14465         unsigned char htlc_base_key_arr[32];
14466         CHECK(*((uint32_t*)htlc_base_key) == 32);
14467         memcpy(htlc_base_key_arr, (uint8_t*)(htlc_base_key + 4), 32);
14468         unsigned char (*htlc_base_key_ref)[32] = &htlc_base_key_arr;
14469         LDKDirectedChannelTransactionParameters channel_parameters_conv;
14470         channel_parameters_conv.inner = (void*)(channel_parameters & (~1));
14471         channel_parameters_conv.is_owned = false;
14472         LDKCResult_CVec_SignatureZNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_CVec_SignatureZNoneZ), "LDKCResult_CVec_SignatureZNoneZ");
14473         *ret_conv = TrustedCommitmentTransaction_get_htlc_sigs(&this_arg_conv, htlc_base_key_ref, &channel_parameters_conv);
14474         return (long)ret_conv;
14475 }
14476
14477 int64_t  __attribute__((visibility("default"))) TS_get_commitment_transaction_number_obscure_factor(int8_tArray broadcaster_payment_basepoint, int8_tArray countersignatory_payment_basepoint, jboolean outbound_from_broadcaster) {
14478         LDKPublicKey broadcaster_payment_basepoint_ref;
14479         CHECK(*((uint32_t*)broadcaster_payment_basepoint) == 33);
14480         memcpy(broadcaster_payment_basepoint_ref.compressed_form, (uint8_t*)(broadcaster_payment_basepoint + 4), 33);
14481         LDKPublicKey countersignatory_payment_basepoint_ref;
14482         CHECK(*((uint32_t*)countersignatory_payment_basepoint) == 33);
14483         memcpy(countersignatory_payment_basepoint_ref.compressed_form, (uint8_t*)(countersignatory_payment_basepoint + 4), 33);
14484         int64_t ret_val = get_commitment_transaction_number_obscure_factor(broadcaster_payment_basepoint_ref, countersignatory_payment_basepoint_ref, outbound_from_broadcaster);
14485         return ret_val;
14486 }
14487
14488 void  __attribute__((visibility("default"))) TS_InitFeatures_free(uint32_t this_ptr) {
14489         LDKInitFeatures this_ptr_conv;
14490         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14491         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
14492         InitFeatures_free(this_ptr_conv);
14493 }
14494
14495 void  __attribute__((visibility("default"))) TS_NodeFeatures_free(uint32_t this_ptr) {
14496         LDKNodeFeatures this_ptr_conv;
14497         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14498         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
14499         NodeFeatures_free(this_ptr_conv);
14500 }
14501
14502 void  __attribute__((visibility("default"))) TS_ChannelFeatures_free(uint32_t this_ptr) {
14503         LDKChannelFeatures this_ptr_conv;
14504         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14505         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
14506         ChannelFeatures_free(this_ptr_conv);
14507 }
14508
14509 void  __attribute__((visibility("default"))) TS_RouteHop_free(uint32_t this_ptr) {
14510         LDKRouteHop this_ptr_conv;
14511         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14512         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
14513         RouteHop_free(this_ptr_conv);
14514 }
14515
14516 uint32_t  __attribute__((visibility("default"))) TS_RouteHop_clone(uint32_t orig) {
14517         LDKRouteHop orig_conv;
14518         orig_conv.inner = (void*)(orig & (~1));
14519         orig_conv.is_owned = false;
14520         LDKRouteHop ret_var = RouteHop_clone(&orig_conv);
14521         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14522         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14523         long ret_ref = (long)ret_var.inner;
14524         if (ret_var.is_owned) {
14525                 ret_ref |= 1;
14526         }
14527         return ret_ref;
14528 }
14529
14530 int8_tArray  __attribute__((visibility("default"))) TS_RouteHop_get_pubkey(uint32_t this_ptr) {
14531         LDKRouteHop this_ptr_conv;
14532         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14533         this_ptr_conv.is_owned = false;
14534         int8_tArray arg_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
14535         memcpy((uint8_t*)(arg_arr + 4), RouteHop_get_pubkey(&this_ptr_conv).compressed_form, 33);
14536         return arg_arr;
14537 }
14538
14539 void  __attribute__((visibility("default"))) TS_RouteHop_set_pubkey(uint32_t this_ptr, int8_tArray val) {
14540         LDKRouteHop this_ptr_conv;
14541         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14542         this_ptr_conv.is_owned = false;
14543         LDKPublicKey val_ref;
14544         CHECK(*((uint32_t*)val) == 33);
14545         memcpy(val_ref.compressed_form, (uint8_t*)(val + 4), 33);
14546         RouteHop_set_pubkey(&this_ptr_conv, val_ref);
14547 }
14548
14549 uint32_t  __attribute__((visibility("default"))) TS_RouteHop_get_node_features(uint32_t this_ptr) {
14550         LDKRouteHop this_ptr_conv;
14551         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14552         this_ptr_conv.is_owned = false;
14553         LDKNodeFeatures ret_var = RouteHop_get_node_features(&this_ptr_conv);
14554         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14555         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14556         long ret_ref = (long)ret_var.inner;
14557         if (ret_var.is_owned) {
14558                 ret_ref |= 1;
14559         }
14560         return ret_ref;
14561 }
14562
14563 void  __attribute__((visibility("default"))) TS_RouteHop_set_node_features(uint32_t this_ptr, uint32_t val) {
14564         LDKRouteHop this_ptr_conv;
14565         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14566         this_ptr_conv.is_owned = false;
14567         LDKNodeFeatures val_conv;
14568         val_conv.inner = (void*)(val & (~1));
14569         val_conv.is_owned = (val & 1) || (val == 0);
14570         // Warning: we need a move here but no clone is available for LDKNodeFeatures
14571         RouteHop_set_node_features(&this_ptr_conv, val_conv);
14572 }
14573
14574 int64_t  __attribute__((visibility("default"))) TS_RouteHop_get_short_channel_id(uint32_t this_ptr) {
14575         LDKRouteHop this_ptr_conv;
14576         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14577         this_ptr_conv.is_owned = false;
14578         int64_t ret_val = RouteHop_get_short_channel_id(&this_ptr_conv);
14579         return ret_val;
14580 }
14581
14582 void  __attribute__((visibility("default"))) TS_RouteHop_set_short_channel_id(uint32_t this_ptr, int64_t val) {
14583         LDKRouteHop this_ptr_conv;
14584         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14585         this_ptr_conv.is_owned = false;
14586         RouteHop_set_short_channel_id(&this_ptr_conv, val);
14587 }
14588
14589 uint32_t  __attribute__((visibility("default"))) TS_RouteHop_get_channel_features(uint32_t this_ptr) {
14590         LDKRouteHop this_ptr_conv;
14591         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14592         this_ptr_conv.is_owned = false;
14593         LDKChannelFeatures ret_var = RouteHop_get_channel_features(&this_ptr_conv);
14594         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14595         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14596         long ret_ref = (long)ret_var.inner;
14597         if (ret_var.is_owned) {
14598                 ret_ref |= 1;
14599         }
14600         return ret_ref;
14601 }
14602
14603 void  __attribute__((visibility("default"))) TS_RouteHop_set_channel_features(uint32_t this_ptr, uint32_t val) {
14604         LDKRouteHop this_ptr_conv;
14605         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14606         this_ptr_conv.is_owned = false;
14607         LDKChannelFeatures val_conv;
14608         val_conv.inner = (void*)(val & (~1));
14609         val_conv.is_owned = (val & 1) || (val == 0);
14610         // Warning: we need a move here but no clone is available for LDKChannelFeatures
14611         RouteHop_set_channel_features(&this_ptr_conv, val_conv);
14612 }
14613
14614 int64_t  __attribute__((visibility("default"))) TS_RouteHop_get_fee_msat(uint32_t this_ptr) {
14615         LDKRouteHop this_ptr_conv;
14616         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14617         this_ptr_conv.is_owned = false;
14618         int64_t ret_val = RouteHop_get_fee_msat(&this_ptr_conv);
14619         return ret_val;
14620 }
14621
14622 void  __attribute__((visibility("default"))) TS_RouteHop_set_fee_msat(uint32_t this_ptr, int64_t val) {
14623         LDKRouteHop this_ptr_conv;
14624         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14625         this_ptr_conv.is_owned = false;
14626         RouteHop_set_fee_msat(&this_ptr_conv, val);
14627 }
14628
14629 int32_t  __attribute__((visibility("default"))) TS_RouteHop_get_cltv_expiry_delta(uint32_t this_ptr) {
14630         LDKRouteHop this_ptr_conv;
14631         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14632         this_ptr_conv.is_owned = false;
14633         int32_t ret_val = RouteHop_get_cltv_expiry_delta(&this_ptr_conv);
14634         return ret_val;
14635 }
14636
14637 void  __attribute__((visibility("default"))) TS_RouteHop_set_cltv_expiry_delta(uint32_t this_ptr, int32_t val) {
14638         LDKRouteHop this_ptr_conv;
14639         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14640         this_ptr_conv.is_owned = false;
14641         RouteHop_set_cltv_expiry_delta(&this_ptr_conv, val);
14642 }
14643
14644 uint32_t  __attribute__((visibility("default"))) 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) {
14645         LDKPublicKey pubkey_arg_ref;
14646         CHECK(*((uint32_t*)pubkey_arg) == 33);
14647         memcpy(pubkey_arg_ref.compressed_form, (uint8_t*)(pubkey_arg + 4), 33);
14648         LDKNodeFeatures node_features_arg_conv;
14649         node_features_arg_conv.inner = (void*)(node_features_arg & (~1));
14650         node_features_arg_conv.is_owned = (node_features_arg & 1) || (node_features_arg == 0);
14651         // Warning: we need a move here but no clone is available for LDKNodeFeatures
14652         LDKChannelFeatures channel_features_arg_conv;
14653         channel_features_arg_conv.inner = (void*)(channel_features_arg & (~1));
14654         channel_features_arg_conv.is_owned = (channel_features_arg & 1) || (channel_features_arg == 0);
14655         // Warning: we need a move here but no clone is available for LDKChannelFeatures
14656         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);
14657         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14658         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14659         long ret_ref = (long)ret_var.inner;
14660         if (ret_var.is_owned) {
14661                 ret_ref |= 1;
14662         }
14663         return ret_ref;
14664 }
14665
14666 void  __attribute__((visibility("default"))) TS_Route_free(uint32_t this_ptr) {
14667         LDKRoute this_ptr_conv;
14668         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14669         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
14670         Route_free(this_ptr_conv);
14671 }
14672
14673 uint32_t  __attribute__((visibility("default"))) TS_Route_clone(uint32_t orig) {
14674         LDKRoute orig_conv;
14675         orig_conv.inner = (void*)(orig & (~1));
14676         orig_conv.is_owned = false;
14677         LDKRoute ret_var = Route_clone(&orig_conv);
14678         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14679         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14680         long ret_ref = (long)ret_var.inner;
14681         if (ret_var.is_owned) {
14682                 ret_ref |= 1;
14683         }
14684         return ret_ref;
14685 }
14686
14687 void  __attribute__((visibility("default"))) TS_Route_set_paths(uint32_t this_ptr, ptrArray val) {
14688         LDKRoute this_ptr_conv;
14689         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14690         this_ptr_conv.is_owned = false;
14691         LDKCVec_CVec_RouteHopZZ val_constr;
14692         val_constr.datalen = *((uint32_t*)val);
14693         if (val_constr.datalen > 0)
14694                 val_constr.data = MALLOC(val_constr.datalen * sizeof(LDKCVec_RouteHopZ), "LDKCVec_CVec_RouteHopZZ Elements");
14695         else
14696                 val_constr.data = NULL;
14697         uint32_tArray* val_vals = (uint32_tArray*)(val + 4);
14698         for (size_t m = 0; m < val_constr.datalen; m++) {
14699                 uint32_tArray arr_conv_12 = val_vals[m];
14700                 LDKCVec_RouteHopZ arr_conv_12_constr;
14701                 arr_conv_12_constr.datalen = *((uint32_t*)arr_conv_12);
14702                 if (arr_conv_12_constr.datalen > 0)
14703                         arr_conv_12_constr.data = MALLOC(arr_conv_12_constr.datalen * sizeof(LDKRouteHop), "LDKCVec_RouteHopZ Elements");
14704                 else
14705                         arr_conv_12_constr.data = NULL;
14706                 uint32_t* arr_conv_12_vals = (uint32_t*)(arr_conv_12 + 4);
14707                 for (size_t k = 0; k < arr_conv_12_constr.datalen; k++) {
14708                         uint32_t arr_conv_10 = arr_conv_12_vals[k];
14709                         LDKRouteHop arr_conv_10_conv;
14710                         arr_conv_10_conv.inner = (void*)(arr_conv_10 & (~1));
14711                         arr_conv_10_conv.is_owned = (arr_conv_10 & 1) || (arr_conv_10 == 0);
14712                         arr_conv_10_conv = RouteHop_clone(&arr_conv_10_conv);
14713                         arr_conv_12_constr.data[k] = arr_conv_10_conv;
14714                 }
14715                 val_constr.data[m] = arr_conv_12_constr;
14716         }
14717         Route_set_paths(&this_ptr_conv, val_constr);
14718 }
14719
14720 uint32_t  __attribute__((visibility("default"))) TS_Route_new(ptrArray paths_arg) {
14721         LDKCVec_CVec_RouteHopZZ paths_arg_constr;
14722         paths_arg_constr.datalen = *((uint32_t*)paths_arg);
14723         if (paths_arg_constr.datalen > 0)
14724                 paths_arg_constr.data = MALLOC(paths_arg_constr.datalen * sizeof(LDKCVec_RouteHopZ), "LDKCVec_CVec_RouteHopZZ Elements");
14725         else
14726                 paths_arg_constr.data = NULL;
14727         uint32_tArray* paths_arg_vals = (uint32_tArray*)(paths_arg + 4);
14728         for (size_t m = 0; m < paths_arg_constr.datalen; m++) {
14729                 uint32_tArray arr_conv_12 = paths_arg_vals[m];
14730                 LDKCVec_RouteHopZ arr_conv_12_constr;
14731                 arr_conv_12_constr.datalen = *((uint32_t*)arr_conv_12);
14732                 if (arr_conv_12_constr.datalen > 0)
14733                         arr_conv_12_constr.data = MALLOC(arr_conv_12_constr.datalen * sizeof(LDKRouteHop), "LDKCVec_RouteHopZ Elements");
14734                 else
14735                         arr_conv_12_constr.data = NULL;
14736                 uint32_t* arr_conv_12_vals = (uint32_t*)(arr_conv_12 + 4);
14737                 for (size_t k = 0; k < arr_conv_12_constr.datalen; k++) {
14738                         uint32_t arr_conv_10 = arr_conv_12_vals[k];
14739                         LDKRouteHop arr_conv_10_conv;
14740                         arr_conv_10_conv.inner = (void*)(arr_conv_10 & (~1));
14741                         arr_conv_10_conv.is_owned = (arr_conv_10 & 1) || (arr_conv_10 == 0);
14742                         arr_conv_10_conv = RouteHop_clone(&arr_conv_10_conv);
14743                         arr_conv_12_constr.data[k] = arr_conv_10_conv;
14744                 }
14745                 paths_arg_constr.data[m] = arr_conv_12_constr;
14746         }
14747         LDKRoute ret_var = Route_new(paths_arg_constr);
14748         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14749         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14750         long ret_ref = (long)ret_var.inner;
14751         if (ret_var.is_owned) {
14752                 ret_ref |= 1;
14753         }
14754         return ret_ref;
14755 }
14756
14757 int8_tArray  __attribute__((visibility("default"))) TS_Route_write(uint32_t obj) {
14758         LDKRoute obj_conv;
14759         obj_conv.inner = (void*)(obj & (~1));
14760         obj_conv.is_owned = false;
14761         LDKCVec_u8Z arg_var = Route_write(&obj_conv);
14762         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
14763         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
14764         CVec_u8Z_free(arg_var);
14765         return arg_arr;
14766 }
14767
14768 uint32_t  __attribute__((visibility("default"))) TS_Route_read(int8_tArray ser) {
14769         LDKu8slice ser_ref;
14770         ser_ref.datalen = *((uint32_t*)ser);
14771         ser_ref.data = (int8_t*)(ser + 4);
14772         LDKCResult_RouteDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_RouteDecodeErrorZ), "LDKCResult_RouteDecodeErrorZ");
14773         *ret_conv = Route_read(ser_ref);
14774         return (long)ret_conv;
14775 }
14776
14777 void  __attribute__((visibility("default"))) TS_RouteHint_free(uint32_t this_ptr) {
14778         LDKRouteHint this_ptr_conv;
14779         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14780         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
14781         RouteHint_free(this_ptr_conv);
14782 }
14783
14784 uint32_t  __attribute__((visibility("default"))) TS_RouteHint_clone(uint32_t orig) {
14785         LDKRouteHint orig_conv;
14786         orig_conv.inner = (void*)(orig & (~1));
14787         orig_conv.is_owned = false;
14788         LDKRouteHint ret_var = RouteHint_clone(&orig_conv);
14789         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14790         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14791         long ret_ref = (long)ret_var.inner;
14792         if (ret_var.is_owned) {
14793                 ret_ref |= 1;
14794         }
14795         return ret_ref;
14796 }
14797
14798 int8_tArray  __attribute__((visibility("default"))) TS_RouteHint_get_src_node_id(uint32_t this_ptr) {
14799         LDKRouteHint this_ptr_conv;
14800         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14801         this_ptr_conv.is_owned = false;
14802         int8_tArray arg_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
14803         memcpy((uint8_t*)(arg_arr + 4), RouteHint_get_src_node_id(&this_ptr_conv).compressed_form, 33);
14804         return arg_arr;
14805 }
14806
14807 void  __attribute__((visibility("default"))) TS_RouteHint_set_src_node_id(uint32_t this_ptr, int8_tArray val) {
14808         LDKRouteHint this_ptr_conv;
14809         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14810         this_ptr_conv.is_owned = false;
14811         LDKPublicKey val_ref;
14812         CHECK(*((uint32_t*)val) == 33);
14813         memcpy(val_ref.compressed_form, (uint8_t*)(val + 4), 33);
14814         RouteHint_set_src_node_id(&this_ptr_conv, val_ref);
14815 }
14816
14817 int64_t  __attribute__((visibility("default"))) TS_RouteHint_get_short_channel_id(uint32_t this_ptr) {
14818         LDKRouteHint this_ptr_conv;
14819         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14820         this_ptr_conv.is_owned = false;
14821         int64_t ret_val = RouteHint_get_short_channel_id(&this_ptr_conv);
14822         return ret_val;
14823 }
14824
14825 void  __attribute__((visibility("default"))) TS_RouteHint_set_short_channel_id(uint32_t this_ptr, int64_t val) {
14826         LDKRouteHint this_ptr_conv;
14827         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14828         this_ptr_conv.is_owned = false;
14829         RouteHint_set_short_channel_id(&this_ptr_conv, val);
14830 }
14831
14832 uint32_t  __attribute__((visibility("default"))) TS_RouteHint_get_fees(uint32_t this_ptr) {
14833         LDKRouteHint this_ptr_conv;
14834         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14835         this_ptr_conv.is_owned = false;
14836         LDKRoutingFees ret_var = RouteHint_get_fees(&this_ptr_conv);
14837         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14838         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14839         long ret_ref = (long)ret_var.inner;
14840         if (ret_var.is_owned) {
14841                 ret_ref |= 1;
14842         }
14843         return ret_ref;
14844 }
14845
14846 void  __attribute__((visibility("default"))) TS_RouteHint_set_fees(uint32_t this_ptr, uint32_t val) {
14847         LDKRouteHint this_ptr_conv;
14848         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14849         this_ptr_conv.is_owned = false;
14850         LDKRoutingFees val_conv;
14851         val_conv.inner = (void*)(val & (~1));
14852         val_conv.is_owned = (val & 1) || (val == 0);
14853         val_conv = RoutingFees_clone(&val_conv);
14854         RouteHint_set_fees(&this_ptr_conv, val_conv);
14855 }
14856
14857 int16_t  __attribute__((visibility("default"))) TS_RouteHint_get_cltv_expiry_delta(uint32_t this_ptr) {
14858         LDKRouteHint this_ptr_conv;
14859         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14860         this_ptr_conv.is_owned = false;
14861         int16_t ret_val = RouteHint_get_cltv_expiry_delta(&this_ptr_conv);
14862         return ret_val;
14863 }
14864
14865 void  __attribute__((visibility("default"))) TS_RouteHint_set_cltv_expiry_delta(uint32_t this_ptr, int16_t val) {
14866         LDKRouteHint this_ptr_conv;
14867         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14868         this_ptr_conv.is_owned = false;
14869         RouteHint_set_cltv_expiry_delta(&this_ptr_conv, val);
14870 }
14871
14872 int64_t  __attribute__((visibility("default"))) TS_RouteHint_get_htlc_minimum_msat(uint32_t this_ptr) {
14873         LDKRouteHint this_ptr_conv;
14874         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14875         this_ptr_conv.is_owned = false;
14876         int64_t ret_val = RouteHint_get_htlc_minimum_msat(&this_ptr_conv);
14877         return ret_val;
14878 }
14879
14880 void  __attribute__((visibility("default"))) TS_RouteHint_set_htlc_minimum_msat(uint32_t this_ptr, int64_t val) {
14881         LDKRouteHint this_ptr_conv;
14882         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14883         this_ptr_conv.is_owned = false;
14884         RouteHint_set_htlc_minimum_msat(&this_ptr_conv, val);
14885 }
14886
14887 uint32_t  __attribute__((visibility("default"))) 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) {
14888         LDKPublicKey src_node_id_arg_ref;
14889         CHECK(*((uint32_t*)src_node_id_arg) == 33);
14890         memcpy(src_node_id_arg_ref.compressed_form, (uint8_t*)(src_node_id_arg + 4), 33);
14891         LDKRoutingFees fees_arg_conv;
14892         fees_arg_conv.inner = (void*)(fees_arg & (~1));
14893         fees_arg_conv.is_owned = (fees_arg & 1) || (fees_arg == 0);
14894         fees_arg_conv = RoutingFees_clone(&fees_arg_conv);
14895         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);
14896         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14897         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14898         long ret_ref = (long)ret_var.inner;
14899         if (ret_var.is_owned) {
14900                 ret_ref |= 1;
14901         }
14902         return ret_ref;
14903 }
14904
14905 uint32_t  __attribute__((visibility("default"))) 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) {
14906         LDKPublicKey our_node_id_ref;
14907         CHECK(*((uint32_t*)our_node_id) == 33);
14908         memcpy(our_node_id_ref.compressed_form, (uint8_t*)(our_node_id + 4), 33);
14909         LDKNetworkGraph network_conv;
14910         network_conv.inner = (void*)(network & (~1));
14911         network_conv.is_owned = false;
14912         LDKPublicKey target_ref;
14913         CHECK(*((uint32_t*)target) == 33);
14914         memcpy(target_ref.compressed_form, (uint8_t*)(target + 4), 33);
14915         LDKCVec_ChannelDetailsZ first_hops_constr;
14916         first_hops_constr.datalen = *((uint32_t*)first_hops);
14917         if (first_hops_constr.datalen > 0)
14918                 first_hops_constr.data = MALLOC(first_hops_constr.datalen * sizeof(LDKChannelDetails), "LDKCVec_ChannelDetailsZ Elements");
14919         else
14920                 first_hops_constr.data = NULL;
14921         uint32_t* first_hops_vals = (uint32_t*)(first_hops + 4);
14922         for (size_t q = 0; q < first_hops_constr.datalen; q++) {
14923                 uint32_t arr_conv_16 = first_hops_vals[q];
14924                 LDKChannelDetails arr_conv_16_conv;
14925                 arr_conv_16_conv.inner = (void*)(arr_conv_16 & (~1));
14926                 arr_conv_16_conv.is_owned = (arr_conv_16 & 1) || (arr_conv_16 == 0);
14927                 first_hops_constr.data[q] = arr_conv_16_conv;
14928         }
14929         LDKCVec_RouteHintZ last_hops_constr;
14930         last_hops_constr.datalen = *((uint32_t*)last_hops);
14931         if (last_hops_constr.datalen > 0)
14932                 last_hops_constr.data = MALLOC(last_hops_constr.datalen * sizeof(LDKRouteHint), "LDKCVec_RouteHintZ Elements");
14933         else
14934                 last_hops_constr.data = NULL;
14935         uint32_t* last_hops_vals = (uint32_t*)(last_hops + 4);
14936         for (size_t l = 0; l < last_hops_constr.datalen; l++) {
14937                 uint32_t arr_conv_11 = last_hops_vals[l];
14938                 LDKRouteHint arr_conv_11_conv;
14939                 arr_conv_11_conv.inner = (void*)(arr_conv_11 & (~1));
14940                 arr_conv_11_conv.is_owned = (arr_conv_11 & 1) || (arr_conv_11 == 0);
14941                 arr_conv_11_conv = RouteHint_clone(&arr_conv_11_conv);
14942                 last_hops_constr.data[l] = arr_conv_11_conv;
14943         }
14944         LDKLogger logger_conv = *(LDKLogger*)(((uint64_t)logger) & ~1);
14945         LDKCResult_RouteLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_RouteLightningErrorZ), "LDKCResult_RouteLightningErrorZ");
14946         *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);
14947         FREE(first_hops_constr.data);
14948         return (long)ret_conv;
14949 }
14950
14951 void  __attribute__((visibility("default"))) TS_NetworkGraph_free(uint32_t this_ptr) {
14952         LDKNetworkGraph this_ptr_conv;
14953         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14954         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
14955         NetworkGraph_free(this_ptr_conv);
14956 }
14957
14958 void  __attribute__((visibility("default"))) TS_LockedNetworkGraph_free(uint32_t this_ptr) {
14959         LDKLockedNetworkGraph this_ptr_conv;
14960         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14961         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
14962         LockedNetworkGraph_free(this_ptr_conv);
14963 }
14964
14965 void  __attribute__((visibility("default"))) TS_NetGraphMsgHandler_free(uint32_t this_ptr) {
14966         LDKNetGraphMsgHandler this_ptr_conv;
14967         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14968         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
14969         NetGraphMsgHandler_free(this_ptr_conv);
14970 }
14971
14972 uint32_t  __attribute__((visibility("default"))) TS_NetGraphMsgHandler_new(int8_tArray genesis_hash, uint32_t chain_access, uint32_t logger) {
14973         LDKThirtyTwoBytes genesis_hash_ref;
14974         CHECK(*((uint32_t*)genesis_hash) == 32);
14975         memcpy(genesis_hash_ref.data, (uint8_t*)(genesis_hash + 4), 32);
14976         LDKAccess* chain_access_conv = (LDKAccess*)chain_access;
14977         LDKLogger logger_conv = *(LDKLogger*)(((uint64_t)logger) & ~1);
14978         LDKNetGraphMsgHandler ret_var = NetGraphMsgHandler_new(genesis_hash_ref, chain_access_conv, logger_conv);
14979         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14980         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14981         long ret_ref = (long)ret_var.inner;
14982         if (ret_var.is_owned) {
14983                 ret_ref |= 1;
14984         }
14985         return ret_ref;
14986 }
14987
14988 uint32_t  __attribute__((visibility("default"))) TS_NetGraphMsgHandler_from_net_graph(uint32_t chain_access, uint32_t logger, uint32_t network_graph) {
14989         LDKAccess* chain_access_conv = (LDKAccess*)chain_access;
14990         LDKLogger logger_conv = *(LDKLogger*)(((uint64_t)logger) & ~1);
14991         LDKNetworkGraph network_graph_conv;
14992         network_graph_conv.inner = (void*)(network_graph & (~1));
14993         network_graph_conv.is_owned = (network_graph & 1) || (network_graph == 0);
14994         // Warning: we need a move here but no clone is available for LDKNetworkGraph
14995         LDKNetGraphMsgHandler ret_var = NetGraphMsgHandler_from_net_graph(chain_access_conv, logger_conv, network_graph_conv);
14996         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14997         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14998         long ret_ref = (long)ret_var.inner;
14999         if (ret_var.is_owned) {
15000                 ret_ref |= 1;
15001         }
15002         return ret_ref;
15003 }
15004
15005 uint32_t  __attribute__((visibility("default"))) TS_NetGraphMsgHandler_read_locked_graph(uint32_t this_arg) {
15006         LDKNetGraphMsgHandler this_arg_conv;
15007         this_arg_conv.inner = (void*)(this_arg & (~1));
15008         this_arg_conv.is_owned = false;
15009         LDKLockedNetworkGraph ret_var = NetGraphMsgHandler_read_locked_graph(&this_arg_conv);
15010         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15011         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15012         long ret_ref = (long)ret_var.inner;
15013         if (ret_var.is_owned) {
15014                 ret_ref |= 1;
15015         }
15016         return ret_ref;
15017 }
15018
15019 uint32_t  __attribute__((visibility("default"))) TS_LockedNetworkGraph_graph(uint32_t this_arg) {
15020         LDKLockedNetworkGraph this_arg_conv;
15021         this_arg_conv.inner = (void*)(this_arg & (~1));
15022         this_arg_conv.is_owned = false;
15023         LDKNetworkGraph ret_var = LockedNetworkGraph_graph(&this_arg_conv);
15024         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15025         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15026         long ret_ref = (long)ret_var.inner;
15027         if (ret_var.is_owned) {
15028                 ret_ref |= 1;
15029         }
15030         return ret_ref;
15031 }
15032
15033 uint32_t  __attribute__((visibility("default"))) TS_NetGraphMsgHandler_as_RoutingMessageHandler(uint32_t this_arg) {
15034         LDKNetGraphMsgHandler this_arg_conv;
15035         this_arg_conv.inner = (void*)(this_arg & (~1));
15036         this_arg_conv.is_owned = false;
15037         LDKRoutingMessageHandler* ret = MALLOC(sizeof(LDKRoutingMessageHandler), "LDKRoutingMessageHandler");
15038         *ret = NetGraphMsgHandler_as_RoutingMessageHandler(&this_arg_conv);
15039         return (long)ret;
15040 }
15041
15042 uint32_t  __attribute__((visibility("default"))) TS_NetGraphMsgHandler_as_MessageSendEventsProvider(uint32_t this_arg) {
15043         LDKNetGraphMsgHandler this_arg_conv;
15044         this_arg_conv.inner = (void*)(this_arg & (~1));
15045         this_arg_conv.is_owned = false;
15046         LDKMessageSendEventsProvider* ret = MALLOC(sizeof(LDKMessageSendEventsProvider), "LDKMessageSendEventsProvider");
15047         *ret = NetGraphMsgHandler_as_MessageSendEventsProvider(&this_arg_conv);
15048         return (long)ret;
15049 }
15050
15051 void  __attribute__((visibility("default"))) TS_DirectionalChannelInfo_free(uint32_t this_ptr) {
15052         LDKDirectionalChannelInfo this_ptr_conv;
15053         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15054         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
15055         DirectionalChannelInfo_free(this_ptr_conv);
15056 }
15057
15058 uint32_t  __attribute__((visibility("default"))) TS_DirectionalChannelInfo_clone(uint32_t orig) {
15059         LDKDirectionalChannelInfo orig_conv;
15060         orig_conv.inner = (void*)(orig & (~1));
15061         orig_conv.is_owned = false;
15062         LDKDirectionalChannelInfo ret_var = DirectionalChannelInfo_clone(&orig_conv);
15063         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15064         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15065         long ret_ref = (long)ret_var.inner;
15066         if (ret_var.is_owned) {
15067                 ret_ref |= 1;
15068         }
15069         return ret_ref;
15070 }
15071
15072 int32_t  __attribute__((visibility("default"))) TS_DirectionalChannelInfo_get_last_update(uint32_t this_ptr) {
15073         LDKDirectionalChannelInfo this_ptr_conv;
15074         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15075         this_ptr_conv.is_owned = false;
15076         int32_t ret_val = DirectionalChannelInfo_get_last_update(&this_ptr_conv);
15077         return ret_val;
15078 }
15079
15080 void  __attribute__((visibility("default"))) TS_DirectionalChannelInfo_set_last_update(uint32_t this_ptr, int32_t val) {
15081         LDKDirectionalChannelInfo this_ptr_conv;
15082         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15083         this_ptr_conv.is_owned = false;
15084         DirectionalChannelInfo_set_last_update(&this_ptr_conv, val);
15085 }
15086
15087 jboolean  __attribute__((visibility("default"))) TS_DirectionalChannelInfo_get_enabled(uint32_t this_ptr) {
15088         LDKDirectionalChannelInfo this_ptr_conv;
15089         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15090         this_ptr_conv.is_owned = false;
15091         jboolean ret_val = DirectionalChannelInfo_get_enabled(&this_ptr_conv);
15092         return ret_val;
15093 }
15094
15095 void  __attribute__((visibility("default"))) TS_DirectionalChannelInfo_set_enabled(uint32_t this_ptr, jboolean val) {
15096         LDKDirectionalChannelInfo this_ptr_conv;
15097         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15098         this_ptr_conv.is_owned = false;
15099         DirectionalChannelInfo_set_enabled(&this_ptr_conv, val);
15100 }
15101
15102 int16_t  __attribute__((visibility("default"))) TS_DirectionalChannelInfo_get_cltv_expiry_delta(uint32_t this_ptr) {
15103         LDKDirectionalChannelInfo this_ptr_conv;
15104         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15105         this_ptr_conv.is_owned = false;
15106         int16_t ret_val = DirectionalChannelInfo_get_cltv_expiry_delta(&this_ptr_conv);
15107         return ret_val;
15108 }
15109
15110 void  __attribute__((visibility("default"))) TS_DirectionalChannelInfo_set_cltv_expiry_delta(uint32_t this_ptr, int16_t val) {
15111         LDKDirectionalChannelInfo this_ptr_conv;
15112         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15113         this_ptr_conv.is_owned = false;
15114         DirectionalChannelInfo_set_cltv_expiry_delta(&this_ptr_conv, val);
15115 }
15116
15117 int64_t  __attribute__((visibility("default"))) TS_DirectionalChannelInfo_get_htlc_minimum_msat(uint32_t this_ptr) {
15118         LDKDirectionalChannelInfo this_ptr_conv;
15119         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15120         this_ptr_conv.is_owned = false;
15121         int64_t ret_val = DirectionalChannelInfo_get_htlc_minimum_msat(&this_ptr_conv);
15122         return ret_val;
15123 }
15124
15125 void  __attribute__((visibility("default"))) TS_DirectionalChannelInfo_set_htlc_minimum_msat(uint32_t this_ptr, int64_t val) {
15126         LDKDirectionalChannelInfo this_ptr_conv;
15127         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15128         this_ptr_conv.is_owned = false;
15129         DirectionalChannelInfo_set_htlc_minimum_msat(&this_ptr_conv, val);
15130 }
15131
15132 uint32_t  __attribute__((visibility("default"))) TS_DirectionalChannelInfo_get_fees(uint32_t this_ptr) {
15133         LDKDirectionalChannelInfo this_ptr_conv;
15134         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15135         this_ptr_conv.is_owned = false;
15136         LDKRoutingFees ret_var = DirectionalChannelInfo_get_fees(&this_ptr_conv);
15137         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15138         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15139         long ret_ref = (long)ret_var.inner;
15140         if (ret_var.is_owned) {
15141                 ret_ref |= 1;
15142         }
15143         return ret_ref;
15144 }
15145
15146 void  __attribute__((visibility("default"))) TS_DirectionalChannelInfo_set_fees(uint32_t this_ptr, uint32_t val) {
15147         LDKDirectionalChannelInfo this_ptr_conv;
15148         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15149         this_ptr_conv.is_owned = false;
15150         LDKRoutingFees val_conv;
15151         val_conv.inner = (void*)(val & (~1));
15152         val_conv.is_owned = (val & 1) || (val == 0);
15153         val_conv = RoutingFees_clone(&val_conv);
15154         DirectionalChannelInfo_set_fees(&this_ptr_conv, val_conv);
15155 }
15156
15157 uint32_t  __attribute__((visibility("default"))) TS_DirectionalChannelInfo_get_last_update_message(uint32_t this_ptr) {
15158         LDKDirectionalChannelInfo this_ptr_conv;
15159         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15160         this_ptr_conv.is_owned = false;
15161         LDKChannelUpdate ret_var = DirectionalChannelInfo_get_last_update_message(&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  __attribute__((visibility("default"))) TS_DirectionalChannelInfo_set_last_update_message(uint32_t this_ptr, uint32_t val) {
15172         LDKDirectionalChannelInfo this_ptr_conv;
15173         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15174         this_ptr_conv.is_owned = false;
15175         LDKChannelUpdate val_conv;
15176         val_conv.inner = (void*)(val & (~1));
15177         val_conv.is_owned = (val & 1) || (val == 0);
15178         val_conv = ChannelUpdate_clone(&val_conv);
15179         DirectionalChannelInfo_set_last_update_message(&this_ptr_conv, val_conv);
15180 }
15181
15182 int8_tArray  __attribute__((visibility("default"))) TS_DirectionalChannelInfo_write(uint32_t obj) {
15183         LDKDirectionalChannelInfo obj_conv;
15184         obj_conv.inner = (void*)(obj & (~1));
15185         obj_conv.is_owned = false;
15186         LDKCVec_u8Z arg_var = DirectionalChannelInfo_write(&obj_conv);
15187         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
15188         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
15189         CVec_u8Z_free(arg_var);
15190         return arg_arr;
15191 }
15192
15193 uint32_t  __attribute__((visibility("default"))) TS_DirectionalChannelInfo_read(int8_tArray ser) {
15194         LDKu8slice ser_ref;
15195         ser_ref.datalen = *((uint32_t*)ser);
15196         ser_ref.data = (int8_t*)(ser + 4);
15197         LDKDirectionalChannelInfo ret_var = DirectionalChannelInfo_read(ser_ref);
15198         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15199         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15200         long ret_ref = (long)ret_var.inner;
15201         if (ret_var.is_owned) {
15202                 ret_ref |= 1;
15203         }
15204         return ret_ref;
15205 }
15206
15207 void  __attribute__((visibility("default"))) TS_ChannelInfo_free(uint32_t this_ptr) {
15208         LDKChannelInfo this_ptr_conv;
15209         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15210         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
15211         ChannelInfo_free(this_ptr_conv);
15212 }
15213
15214 uint32_t  __attribute__((visibility("default"))) TS_ChannelInfo_get_features(uint32_t this_ptr) {
15215         LDKChannelInfo this_ptr_conv;
15216         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15217         this_ptr_conv.is_owned = false;
15218         LDKChannelFeatures ret_var = ChannelInfo_get_features(&this_ptr_conv);
15219         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15220         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15221         long ret_ref = (long)ret_var.inner;
15222         if (ret_var.is_owned) {
15223                 ret_ref |= 1;
15224         }
15225         return ret_ref;
15226 }
15227
15228 void  __attribute__((visibility("default"))) TS_ChannelInfo_set_features(uint32_t this_ptr, uint32_t val) {
15229         LDKChannelInfo this_ptr_conv;
15230         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15231         this_ptr_conv.is_owned = false;
15232         LDKChannelFeatures val_conv;
15233         val_conv.inner = (void*)(val & (~1));
15234         val_conv.is_owned = (val & 1) || (val == 0);
15235         // Warning: we need a move here but no clone is available for LDKChannelFeatures
15236         ChannelInfo_set_features(&this_ptr_conv, val_conv);
15237 }
15238
15239 int8_tArray  __attribute__((visibility("default"))) TS_ChannelInfo_get_node_one(uint32_t this_ptr) {
15240         LDKChannelInfo this_ptr_conv;
15241         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15242         this_ptr_conv.is_owned = false;
15243         int8_tArray arg_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
15244         memcpy((uint8_t*)(arg_arr + 4), ChannelInfo_get_node_one(&this_ptr_conv).compressed_form, 33);
15245         return arg_arr;
15246 }
15247
15248 void  __attribute__((visibility("default"))) TS_ChannelInfo_set_node_one(uint32_t this_ptr, int8_tArray val) {
15249         LDKChannelInfo this_ptr_conv;
15250         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15251         this_ptr_conv.is_owned = false;
15252         LDKPublicKey val_ref;
15253         CHECK(*((uint32_t*)val) == 33);
15254         memcpy(val_ref.compressed_form, (uint8_t*)(val + 4), 33);
15255         ChannelInfo_set_node_one(&this_ptr_conv, val_ref);
15256 }
15257
15258 uint32_t  __attribute__((visibility("default"))) TS_ChannelInfo_get_one_to_two(uint32_t this_ptr) {
15259         LDKChannelInfo this_ptr_conv;
15260         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15261         this_ptr_conv.is_owned = false;
15262         LDKDirectionalChannelInfo ret_var = ChannelInfo_get_one_to_two(&this_ptr_conv);
15263         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15264         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15265         long ret_ref = (long)ret_var.inner;
15266         if (ret_var.is_owned) {
15267                 ret_ref |= 1;
15268         }
15269         return ret_ref;
15270 }
15271
15272 void  __attribute__((visibility("default"))) TS_ChannelInfo_set_one_to_two(uint32_t this_ptr, uint32_t val) {
15273         LDKChannelInfo this_ptr_conv;
15274         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15275         this_ptr_conv.is_owned = false;
15276         LDKDirectionalChannelInfo val_conv;
15277         val_conv.inner = (void*)(val & (~1));
15278         val_conv.is_owned = (val & 1) || (val == 0);
15279         val_conv = DirectionalChannelInfo_clone(&val_conv);
15280         ChannelInfo_set_one_to_two(&this_ptr_conv, val_conv);
15281 }
15282
15283 int8_tArray  __attribute__((visibility("default"))) TS_ChannelInfo_get_node_two(uint32_t this_ptr) {
15284         LDKChannelInfo this_ptr_conv;
15285         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15286         this_ptr_conv.is_owned = false;
15287         int8_tArray arg_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
15288         memcpy((uint8_t*)(arg_arr + 4), ChannelInfo_get_node_two(&this_ptr_conv).compressed_form, 33);
15289         return arg_arr;
15290 }
15291
15292 void  __attribute__((visibility("default"))) TS_ChannelInfo_set_node_two(uint32_t this_ptr, int8_tArray val) {
15293         LDKChannelInfo this_ptr_conv;
15294         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15295         this_ptr_conv.is_owned = false;
15296         LDKPublicKey val_ref;
15297         CHECK(*((uint32_t*)val) == 33);
15298         memcpy(val_ref.compressed_form, (uint8_t*)(val + 4), 33);
15299         ChannelInfo_set_node_two(&this_ptr_conv, val_ref);
15300 }
15301
15302 uint32_t  __attribute__((visibility("default"))) TS_ChannelInfo_get_two_to_one(uint32_t this_ptr) {
15303         LDKChannelInfo this_ptr_conv;
15304         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15305         this_ptr_conv.is_owned = false;
15306         LDKDirectionalChannelInfo ret_var = ChannelInfo_get_two_to_one(&this_ptr_conv);
15307         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15308         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15309         long ret_ref = (long)ret_var.inner;
15310         if (ret_var.is_owned) {
15311                 ret_ref |= 1;
15312         }
15313         return ret_ref;
15314 }
15315
15316 void  __attribute__((visibility("default"))) TS_ChannelInfo_set_two_to_one(uint32_t this_ptr, uint32_t val) {
15317         LDKChannelInfo this_ptr_conv;
15318         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15319         this_ptr_conv.is_owned = false;
15320         LDKDirectionalChannelInfo val_conv;
15321         val_conv.inner = (void*)(val & (~1));
15322         val_conv.is_owned = (val & 1) || (val == 0);
15323         val_conv = DirectionalChannelInfo_clone(&val_conv);
15324         ChannelInfo_set_two_to_one(&this_ptr_conv, val_conv);
15325 }
15326
15327 uint32_t  __attribute__((visibility("default"))) TS_ChannelInfo_get_announcement_message(uint32_t this_ptr) {
15328         LDKChannelInfo this_ptr_conv;
15329         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15330         this_ptr_conv.is_owned = false;
15331         LDKChannelAnnouncement ret_var = ChannelInfo_get_announcement_message(&this_ptr_conv);
15332         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15333         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15334         long ret_ref = (long)ret_var.inner;
15335         if (ret_var.is_owned) {
15336                 ret_ref |= 1;
15337         }
15338         return ret_ref;
15339 }
15340
15341 void  __attribute__((visibility("default"))) TS_ChannelInfo_set_announcement_message(uint32_t this_ptr, uint32_t val) {
15342         LDKChannelInfo this_ptr_conv;
15343         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15344         this_ptr_conv.is_owned = false;
15345         LDKChannelAnnouncement val_conv;
15346         val_conv.inner = (void*)(val & (~1));
15347         val_conv.is_owned = (val & 1) || (val == 0);
15348         val_conv = ChannelAnnouncement_clone(&val_conv);
15349         ChannelInfo_set_announcement_message(&this_ptr_conv, val_conv);
15350 }
15351
15352 int8_tArray  __attribute__((visibility("default"))) TS_ChannelInfo_write(uint32_t obj) {
15353         LDKChannelInfo obj_conv;
15354         obj_conv.inner = (void*)(obj & (~1));
15355         obj_conv.is_owned = false;
15356         LDKCVec_u8Z arg_var = ChannelInfo_write(&obj_conv);
15357         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
15358         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
15359         CVec_u8Z_free(arg_var);
15360         return arg_arr;
15361 }
15362
15363 uint32_t  __attribute__((visibility("default"))) TS_ChannelInfo_read(int8_tArray ser) {
15364         LDKu8slice ser_ref;
15365         ser_ref.datalen = *((uint32_t*)ser);
15366         ser_ref.data = (int8_t*)(ser + 4);
15367         LDKChannelInfo ret_var = ChannelInfo_read(ser_ref);
15368         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15369         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15370         long ret_ref = (long)ret_var.inner;
15371         if (ret_var.is_owned) {
15372                 ret_ref |= 1;
15373         }
15374         return ret_ref;
15375 }
15376
15377 void  __attribute__((visibility("default"))) TS_RoutingFees_free(uint32_t this_ptr) {
15378         LDKRoutingFees this_ptr_conv;
15379         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15380         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
15381         RoutingFees_free(this_ptr_conv);
15382 }
15383
15384 uint32_t  __attribute__((visibility("default"))) TS_RoutingFees_clone(uint32_t orig) {
15385         LDKRoutingFees orig_conv;
15386         orig_conv.inner = (void*)(orig & (~1));
15387         orig_conv.is_owned = false;
15388         LDKRoutingFees ret_var = RoutingFees_clone(&orig_conv);
15389         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15390         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15391         long ret_ref = (long)ret_var.inner;
15392         if (ret_var.is_owned) {
15393                 ret_ref |= 1;
15394         }
15395         return ret_ref;
15396 }
15397
15398 int32_t  __attribute__((visibility("default"))) TS_RoutingFees_get_base_msat(uint32_t this_ptr) {
15399         LDKRoutingFees this_ptr_conv;
15400         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15401         this_ptr_conv.is_owned = false;
15402         int32_t ret_val = RoutingFees_get_base_msat(&this_ptr_conv);
15403         return ret_val;
15404 }
15405
15406 void  __attribute__((visibility("default"))) TS_RoutingFees_set_base_msat(uint32_t this_ptr, int32_t val) {
15407         LDKRoutingFees this_ptr_conv;
15408         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15409         this_ptr_conv.is_owned = false;
15410         RoutingFees_set_base_msat(&this_ptr_conv, val);
15411 }
15412
15413 int32_t  __attribute__((visibility("default"))) TS_RoutingFees_get_proportional_millionths(uint32_t this_ptr) {
15414         LDKRoutingFees this_ptr_conv;
15415         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15416         this_ptr_conv.is_owned = false;
15417         int32_t ret_val = RoutingFees_get_proportional_millionths(&this_ptr_conv);
15418         return ret_val;
15419 }
15420
15421 void  __attribute__((visibility("default"))) TS_RoutingFees_set_proportional_millionths(uint32_t this_ptr, int32_t val) {
15422         LDKRoutingFees this_ptr_conv;
15423         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15424         this_ptr_conv.is_owned = false;
15425         RoutingFees_set_proportional_millionths(&this_ptr_conv, val);
15426 }
15427
15428 uint32_t  __attribute__((visibility("default"))) TS_RoutingFees_new(int32_t base_msat_arg, int32_t proportional_millionths_arg) {
15429         LDKRoutingFees ret_var = RoutingFees_new(base_msat_arg, proportional_millionths_arg);
15430         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15431         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15432         long ret_ref = (long)ret_var.inner;
15433         if (ret_var.is_owned) {
15434                 ret_ref |= 1;
15435         }
15436         return ret_ref;
15437 }
15438
15439 uint32_t  __attribute__((visibility("default"))) TS_RoutingFees_read(int8_tArray ser) {
15440         LDKu8slice ser_ref;
15441         ser_ref.datalen = *((uint32_t*)ser);
15442         ser_ref.data = (int8_t*)(ser + 4);
15443         LDKCResult_RoutingFeesDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_RoutingFeesDecodeErrorZ), "LDKCResult_RoutingFeesDecodeErrorZ");
15444         *ret_conv = RoutingFees_read(ser_ref);
15445         return (long)ret_conv;
15446 }
15447
15448 int8_tArray  __attribute__((visibility("default"))) TS_RoutingFees_write(uint32_t obj) {
15449         LDKRoutingFees obj_conv;
15450         obj_conv.inner = (void*)(obj & (~1));
15451         obj_conv.is_owned = false;
15452         LDKCVec_u8Z arg_var = RoutingFees_write(&obj_conv);
15453         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
15454         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
15455         CVec_u8Z_free(arg_var);
15456         return arg_arr;
15457 }
15458
15459 void  __attribute__((visibility("default"))) TS_NodeAnnouncementInfo_free(uint32_t this_ptr) {
15460         LDKNodeAnnouncementInfo this_ptr_conv;
15461         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15462         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
15463         NodeAnnouncementInfo_free(this_ptr_conv);
15464 }
15465
15466 uint32_t  __attribute__((visibility("default"))) TS_NodeAnnouncementInfo_clone(uint32_t orig) {
15467         LDKNodeAnnouncementInfo orig_conv;
15468         orig_conv.inner = (void*)(orig & (~1));
15469         orig_conv.is_owned = false;
15470         LDKNodeAnnouncementInfo ret_var = NodeAnnouncementInfo_clone(&orig_conv);
15471         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15472         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15473         long ret_ref = (long)ret_var.inner;
15474         if (ret_var.is_owned) {
15475                 ret_ref |= 1;
15476         }
15477         return ret_ref;
15478 }
15479
15480 uint32_t  __attribute__((visibility("default"))) TS_NodeAnnouncementInfo_get_features(uint32_t this_ptr) {
15481         LDKNodeAnnouncementInfo this_ptr_conv;
15482         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15483         this_ptr_conv.is_owned = false;
15484         LDKNodeFeatures ret_var = NodeAnnouncementInfo_get_features(&this_ptr_conv);
15485         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15486         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15487         long ret_ref = (long)ret_var.inner;
15488         if (ret_var.is_owned) {
15489                 ret_ref |= 1;
15490         }
15491         return ret_ref;
15492 }
15493
15494 void  __attribute__((visibility("default"))) TS_NodeAnnouncementInfo_set_features(uint32_t this_ptr, uint32_t val) {
15495         LDKNodeAnnouncementInfo this_ptr_conv;
15496         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15497         this_ptr_conv.is_owned = false;
15498         LDKNodeFeatures val_conv;
15499         val_conv.inner = (void*)(val & (~1));
15500         val_conv.is_owned = (val & 1) || (val == 0);
15501         // Warning: we need a move here but no clone is available for LDKNodeFeatures
15502         NodeAnnouncementInfo_set_features(&this_ptr_conv, val_conv);
15503 }
15504
15505 int32_t  __attribute__((visibility("default"))) TS_NodeAnnouncementInfo_get_last_update(uint32_t this_ptr) {
15506         LDKNodeAnnouncementInfo this_ptr_conv;
15507         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15508         this_ptr_conv.is_owned = false;
15509         int32_t ret_val = NodeAnnouncementInfo_get_last_update(&this_ptr_conv);
15510         return ret_val;
15511 }
15512
15513 void  __attribute__((visibility("default"))) TS_NodeAnnouncementInfo_set_last_update(uint32_t this_ptr, int32_t val) {
15514         LDKNodeAnnouncementInfo this_ptr_conv;
15515         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15516         this_ptr_conv.is_owned = false;
15517         NodeAnnouncementInfo_set_last_update(&this_ptr_conv, val);
15518 }
15519
15520 int8_tArray  __attribute__((visibility("default"))) TS_NodeAnnouncementInfo_get_rgb(uint32_t this_ptr) {
15521         LDKNodeAnnouncementInfo this_ptr_conv;
15522         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15523         this_ptr_conv.is_owned = false;
15524         int8_tArray ret_arr = init_arr(3, sizeof(uint8_t), "Native int8_tArray Bytes");
15525         memcpy((uint8_t*)(ret_arr + 4), *NodeAnnouncementInfo_get_rgb(&this_ptr_conv), 3);
15526         return ret_arr;
15527 }
15528
15529 void  __attribute__((visibility("default"))) TS_NodeAnnouncementInfo_set_rgb(uint32_t this_ptr, int8_tArray val) {
15530         LDKNodeAnnouncementInfo this_ptr_conv;
15531         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15532         this_ptr_conv.is_owned = false;
15533         LDKThreeBytes val_ref;
15534         CHECK(*((uint32_t*)val) == 3);
15535         memcpy(val_ref.data, (uint8_t*)(val + 4), 3);
15536         NodeAnnouncementInfo_set_rgb(&this_ptr_conv, val_ref);
15537 }
15538
15539 int8_tArray  __attribute__((visibility("default"))) TS_NodeAnnouncementInfo_get_alias(uint32_t this_ptr) {
15540         LDKNodeAnnouncementInfo this_ptr_conv;
15541         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15542         this_ptr_conv.is_owned = false;
15543         int8_tArray ret_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
15544         memcpy((uint8_t*)(ret_arr + 4), *NodeAnnouncementInfo_get_alias(&this_ptr_conv), 32);
15545         return ret_arr;
15546 }
15547
15548 void  __attribute__((visibility("default"))) TS_NodeAnnouncementInfo_set_alias(uint32_t this_ptr, int8_tArray val) {
15549         LDKNodeAnnouncementInfo this_ptr_conv;
15550         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15551         this_ptr_conv.is_owned = false;
15552         LDKThirtyTwoBytes val_ref;
15553         CHECK(*((uint32_t*)val) == 32);
15554         memcpy(val_ref.data, (uint8_t*)(val + 4), 32);
15555         NodeAnnouncementInfo_set_alias(&this_ptr_conv, val_ref);
15556 }
15557
15558 void  __attribute__((visibility("default"))) TS_NodeAnnouncementInfo_set_addresses(uint32_t this_ptr, uint32_tArray val) {
15559         LDKNodeAnnouncementInfo this_ptr_conv;
15560         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15561         this_ptr_conv.is_owned = false;
15562         LDKCVec_NetAddressZ val_constr;
15563         val_constr.datalen = *((uint32_t*)val);
15564         if (val_constr.datalen > 0)
15565                 val_constr.data = MALLOC(val_constr.datalen * sizeof(LDKNetAddress), "LDKCVec_NetAddressZ Elements");
15566         else
15567                 val_constr.data = NULL;
15568         uint32_t* val_vals = (uint32_t*)(val + 4);
15569         for (size_t m = 0; m < val_constr.datalen; m++) {
15570                 uint32_t arr_conv_12 = val_vals[m];
15571                 LDKNetAddress arr_conv_12_conv = *(LDKNetAddress*)(((uint64_t)arr_conv_12) & ~1);
15572                 FREE((void*)arr_conv_12);
15573                 val_constr.data[m] = arr_conv_12_conv;
15574         }
15575         NodeAnnouncementInfo_set_addresses(&this_ptr_conv, val_constr);
15576 }
15577
15578 uint32_t  __attribute__((visibility("default"))) TS_NodeAnnouncementInfo_get_announcement_message(uint32_t this_ptr) {
15579         LDKNodeAnnouncementInfo this_ptr_conv;
15580         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15581         this_ptr_conv.is_owned = false;
15582         LDKNodeAnnouncement ret_var = NodeAnnouncementInfo_get_announcement_message(&this_ptr_conv);
15583         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15584         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15585         long ret_ref = (long)ret_var.inner;
15586         if (ret_var.is_owned) {
15587                 ret_ref |= 1;
15588         }
15589         return ret_ref;
15590 }
15591
15592 void  __attribute__((visibility("default"))) TS_NodeAnnouncementInfo_set_announcement_message(uint32_t this_ptr, uint32_t val) {
15593         LDKNodeAnnouncementInfo this_ptr_conv;
15594         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15595         this_ptr_conv.is_owned = false;
15596         LDKNodeAnnouncement val_conv;
15597         val_conv.inner = (void*)(val & (~1));
15598         val_conv.is_owned = (val & 1) || (val == 0);
15599         val_conv = NodeAnnouncement_clone(&val_conv);
15600         NodeAnnouncementInfo_set_announcement_message(&this_ptr_conv, val_conv);
15601 }
15602
15603 uint32_t  __attribute__((visibility("default"))) 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) {
15604         LDKNodeFeatures features_arg_conv;
15605         features_arg_conv.inner = (void*)(features_arg & (~1));
15606         features_arg_conv.is_owned = (features_arg & 1) || (features_arg == 0);
15607         // Warning: we need a move here but no clone is available for LDKNodeFeatures
15608         LDKThreeBytes rgb_arg_ref;
15609         CHECK(*((uint32_t*)rgb_arg) == 3);
15610         memcpy(rgb_arg_ref.data, (uint8_t*)(rgb_arg + 4), 3);
15611         LDKThirtyTwoBytes alias_arg_ref;
15612         CHECK(*((uint32_t*)alias_arg) == 32);
15613         memcpy(alias_arg_ref.data, (uint8_t*)(alias_arg + 4), 32);
15614         LDKCVec_NetAddressZ addresses_arg_constr;
15615         addresses_arg_constr.datalen = *((uint32_t*)addresses_arg);
15616         if (addresses_arg_constr.datalen > 0)
15617                 addresses_arg_constr.data = MALLOC(addresses_arg_constr.datalen * sizeof(LDKNetAddress), "LDKCVec_NetAddressZ Elements");
15618         else
15619                 addresses_arg_constr.data = NULL;
15620         uint32_t* addresses_arg_vals = (uint32_t*)(addresses_arg + 4);
15621         for (size_t m = 0; m < addresses_arg_constr.datalen; m++) {
15622                 uint32_t arr_conv_12 = addresses_arg_vals[m];
15623                 LDKNetAddress arr_conv_12_conv = *(LDKNetAddress*)(((uint64_t)arr_conv_12) & ~1);
15624                 FREE((void*)arr_conv_12);
15625                 addresses_arg_constr.data[m] = arr_conv_12_conv;
15626         }
15627         LDKNodeAnnouncement announcement_message_arg_conv;
15628         announcement_message_arg_conv.inner = (void*)(announcement_message_arg & (~1));
15629         announcement_message_arg_conv.is_owned = (announcement_message_arg & 1) || (announcement_message_arg == 0);
15630         announcement_message_arg_conv = NodeAnnouncement_clone(&announcement_message_arg_conv);
15631         LDKNodeAnnouncementInfo ret_var = NodeAnnouncementInfo_new(features_arg_conv, last_update_arg, rgb_arg_ref, alias_arg_ref, addresses_arg_constr, announcement_message_arg_conv);
15632         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15633         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15634         long ret_ref = (long)ret_var.inner;
15635         if (ret_var.is_owned) {
15636                 ret_ref |= 1;
15637         }
15638         return ret_ref;
15639 }
15640
15641 int8_tArray  __attribute__((visibility("default"))) TS_NodeAnnouncementInfo_write(uint32_t obj) {
15642         LDKNodeAnnouncementInfo obj_conv;
15643         obj_conv.inner = (void*)(obj & (~1));
15644         obj_conv.is_owned = false;
15645         LDKCVec_u8Z arg_var = NodeAnnouncementInfo_write(&obj_conv);
15646         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
15647         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
15648         CVec_u8Z_free(arg_var);
15649         return arg_arr;
15650 }
15651
15652 uint32_t  __attribute__((visibility("default"))) TS_NodeAnnouncementInfo_read(int8_tArray ser) {
15653         LDKu8slice ser_ref;
15654         ser_ref.datalen = *((uint32_t*)ser);
15655         ser_ref.data = (int8_t*)(ser + 4);
15656         LDKCResult_NodeAnnouncementInfoDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NodeAnnouncementInfoDecodeErrorZ), "LDKCResult_NodeAnnouncementInfoDecodeErrorZ");
15657         *ret_conv = NodeAnnouncementInfo_read(ser_ref);
15658         return (long)ret_conv;
15659 }
15660
15661 void  __attribute__((visibility("default"))) TS_NodeInfo_free(uint32_t this_ptr) {
15662         LDKNodeInfo this_ptr_conv;
15663         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15664         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
15665         NodeInfo_free(this_ptr_conv);
15666 }
15667
15668 uint32_t  __attribute__((visibility("default"))) TS_NodeInfo_clone(uint32_t orig) {
15669         LDKNodeInfo orig_conv;
15670         orig_conv.inner = (void*)(orig & (~1));
15671         orig_conv.is_owned = false;
15672         LDKNodeInfo ret_var = NodeInfo_clone(&orig_conv);
15673         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15674         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15675         long ret_ref = (long)ret_var.inner;
15676         if (ret_var.is_owned) {
15677                 ret_ref |= 1;
15678         }
15679         return ret_ref;
15680 }
15681
15682 void  __attribute__((visibility("default"))) TS_NodeInfo_set_channels(uint32_t this_ptr, int64_tArray val) {
15683         LDKNodeInfo this_ptr_conv;
15684         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15685         this_ptr_conv.is_owned = false;
15686         LDKCVec_u64Z val_constr;
15687         val_constr.datalen = *((uint32_t*)val);
15688         if (val_constr.datalen > 0)
15689                 val_constr.data = MALLOC(val_constr.datalen * sizeof(int64_t), "LDKCVec_u64Z Elements");
15690         else
15691                 val_constr.data = NULL;
15692         int64_t* val_vals = (int64_t*)(val + 4);
15693         for (size_t i = 0; i < val_constr.datalen; i++) {
15694                 int64_t arr_conv_8 = val_vals[i];
15695                 val_constr.data[i] = arr_conv_8;
15696         }
15697         NodeInfo_set_channels(&this_ptr_conv, val_constr);
15698 }
15699
15700 uint32_t  __attribute__((visibility("default"))) TS_NodeInfo_get_lowest_inbound_channel_fees(uint32_t this_ptr) {
15701         LDKNodeInfo this_ptr_conv;
15702         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15703         this_ptr_conv.is_owned = false;
15704         LDKRoutingFees ret_var = NodeInfo_get_lowest_inbound_channel_fees(&this_ptr_conv);
15705         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15706         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15707         long ret_ref = (long)ret_var.inner;
15708         if (ret_var.is_owned) {
15709                 ret_ref |= 1;
15710         }
15711         return ret_ref;
15712 }
15713
15714 void  __attribute__((visibility("default"))) TS_NodeInfo_set_lowest_inbound_channel_fees(uint32_t this_ptr, uint32_t val) {
15715         LDKNodeInfo this_ptr_conv;
15716         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15717         this_ptr_conv.is_owned = false;
15718         LDKRoutingFees val_conv;
15719         val_conv.inner = (void*)(val & (~1));
15720         val_conv.is_owned = (val & 1) || (val == 0);
15721         val_conv = RoutingFees_clone(&val_conv);
15722         NodeInfo_set_lowest_inbound_channel_fees(&this_ptr_conv, val_conv);
15723 }
15724
15725 uint32_t  __attribute__((visibility("default"))) TS_NodeInfo_get_announcement_info(uint32_t this_ptr) {
15726         LDKNodeInfo this_ptr_conv;
15727         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15728         this_ptr_conv.is_owned = false;
15729         LDKNodeAnnouncementInfo ret_var = NodeInfo_get_announcement_info(&this_ptr_conv);
15730         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15731         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15732         long ret_ref = (long)ret_var.inner;
15733         if (ret_var.is_owned) {
15734                 ret_ref |= 1;
15735         }
15736         return ret_ref;
15737 }
15738
15739 void  __attribute__((visibility("default"))) TS_NodeInfo_set_announcement_info(uint32_t this_ptr, uint32_t val) {
15740         LDKNodeInfo this_ptr_conv;
15741         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15742         this_ptr_conv.is_owned = false;
15743         LDKNodeAnnouncementInfo val_conv;
15744         val_conv.inner = (void*)(val & (~1));
15745         val_conv.is_owned = (val & 1) || (val == 0);
15746         val_conv = NodeAnnouncementInfo_clone(&val_conv);
15747         NodeInfo_set_announcement_info(&this_ptr_conv, val_conv);
15748 }
15749
15750 uint32_t  __attribute__((visibility("default"))) TS_NodeInfo_new(int64_tArray channels_arg, uint32_t lowest_inbound_channel_fees_arg, uint32_t announcement_info_arg) {
15751         LDKCVec_u64Z channels_arg_constr;
15752         channels_arg_constr.datalen = *((uint32_t*)channels_arg);
15753         if (channels_arg_constr.datalen > 0)
15754                 channels_arg_constr.data = MALLOC(channels_arg_constr.datalen * sizeof(int64_t), "LDKCVec_u64Z Elements");
15755         else
15756                 channels_arg_constr.data = NULL;
15757         int64_t* channels_arg_vals = (int64_t*)(channels_arg + 4);
15758         for (size_t i = 0; i < channels_arg_constr.datalen; i++) {
15759                 int64_t arr_conv_8 = channels_arg_vals[i];
15760                 channels_arg_constr.data[i] = arr_conv_8;
15761         }
15762         LDKRoutingFees lowest_inbound_channel_fees_arg_conv;
15763         lowest_inbound_channel_fees_arg_conv.inner = (void*)(lowest_inbound_channel_fees_arg & (~1));
15764         lowest_inbound_channel_fees_arg_conv.is_owned = (lowest_inbound_channel_fees_arg & 1) || (lowest_inbound_channel_fees_arg == 0);
15765         lowest_inbound_channel_fees_arg_conv = RoutingFees_clone(&lowest_inbound_channel_fees_arg_conv);
15766         LDKNodeAnnouncementInfo announcement_info_arg_conv;
15767         announcement_info_arg_conv.inner = (void*)(announcement_info_arg & (~1));
15768         announcement_info_arg_conv.is_owned = (announcement_info_arg & 1) || (announcement_info_arg == 0);
15769         announcement_info_arg_conv = NodeAnnouncementInfo_clone(&announcement_info_arg_conv);
15770         LDKNodeInfo ret_var = NodeInfo_new(channels_arg_constr, lowest_inbound_channel_fees_arg_conv, announcement_info_arg_conv);
15771         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15772         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15773         long ret_ref = (long)ret_var.inner;
15774         if (ret_var.is_owned) {
15775                 ret_ref |= 1;
15776         }
15777         return ret_ref;
15778 }
15779
15780 int8_tArray  __attribute__((visibility("default"))) TS_NodeInfo_write(uint32_t obj) {
15781         LDKNodeInfo obj_conv;
15782         obj_conv.inner = (void*)(obj & (~1));
15783         obj_conv.is_owned = false;
15784         LDKCVec_u8Z arg_var = NodeInfo_write(&obj_conv);
15785         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
15786         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
15787         CVec_u8Z_free(arg_var);
15788         return arg_arr;
15789 }
15790
15791 uint32_t  __attribute__((visibility("default"))) TS_NodeInfo_read(int8_tArray ser) {
15792         LDKu8slice ser_ref;
15793         ser_ref.datalen = *((uint32_t*)ser);
15794         ser_ref.data = (int8_t*)(ser + 4);
15795         LDKCResult_NodeInfoDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NodeInfoDecodeErrorZ), "LDKCResult_NodeInfoDecodeErrorZ");
15796         *ret_conv = NodeInfo_read(ser_ref);
15797         return (long)ret_conv;
15798 }
15799
15800 int8_tArray  __attribute__((visibility("default"))) TS_NetworkGraph_write(uint32_t obj) {
15801         LDKNetworkGraph obj_conv;
15802         obj_conv.inner = (void*)(obj & (~1));
15803         obj_conv.is_owned = false;
15804         LDKCVec_u8Z arg_var = NetworkGraph_write(&obj_conv);
15805         int8_tArray arg_arr = init_arr(arg_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
15806         memcpy((uint8_t*)(arg_arr + 4), arg_var.data, arg_var.datalen);
15807         CVec_u8Z_free(arg_var);
15808         return arg_arr;
15809 }
15810
15811 uint32_t  __attribute__((visibility("default"))) TS_NetworkGraph_read(int8_tArray ser) {
15812         LDKu8slice ser_ref;
15813         ser_ref.datalen = *((uint32_t*)ser);
15814         ser_ref.data = (int8_t*)(ser + 4);
15815         LDKCResult_NetworkGraphDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NetworkGraphDecodeErrorZ), "LDKCResult_NetworkGraphDecodeErrorZ");
15816         *ret_conv = NetworkGraph_read(ser_ref);
15817         return (long)ret_conv;
15818 }
15819
15820 uint32_t  __attribute__((visibility("default"))) TS_NetworkGraph_new(int8_tArray genesis_hash) {
15821         LDKThirtyTwoBytes genesis_hash_ref;
15822         CHECK(*((uint32_t*)genesis_hash) == 32);
15823         memcpy(genesis_hash_ref.data, (uint8_t*)(genesis_hash + 4), 32);
15824         LDKNetworkGraph ret_var = NetworkGraph_new(genesis_hash_ref);
15825         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15826         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15827         long ret_ref = (long)ret_var.inner;
15828         if (ret_var.is_owned) {
15829                 ret_ref |= 1;
15830         }
15831         return ret_ref;
15832 }
15833
15834 uint32_t  __attribute__((visibility("default"))) TS_NetworkGraph_update_node_from_announcement(uint32_t this_arg, uint32_t msg) {
15835         LDKNetworkGraph this_arg_conv;
15836         this_arg_conv.inner = (void*)(this_arg & (~1));
15837         this_arg_conv.is_owned = false;
15838         LDKNodeAnnouncement msg_conv;
15839         msg_conv.inner = (void*)(msg & (~1));
15840         msg_conv.is_owned = false;
15841         LDKCResult_NoneLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneLightningErrorZ), "LDKCResult_NoneLightningErrorZ");
15842         *ret_conv = NetworkGraph_update_node_from_announcement(&this_arg_conv, &msg_conv);
15843         return (long)ret_conv;
15844 }
15845
15846 uint32_t  __attribute__((visibility("default"))) TS_NetworkGraph_update_node_from_unsigned_announcement(uint32_t this_arg, uint32_t msg) {
15847         LDKNetworkGraph this_arg_conv;
15848         this_arg_conv.inner = (void*)(this_arg & (~1));
15849         this_arg_conv.is_owned = false;
15850         LDKUnsignedNodeAnnouncement msg_conv;
15851         msg_conv.inner = (void*)(msg & (~1));
15852         msg_conv.is_owned = false;
15853         LDKCResult_NoneLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneLightningErrorZ), "LDKCResult_NoneLightningErrorZ");
15854         *ret_conv = NetworkGraph_update_node_from_unsigned_announcement(&this_arg_conv, &msg_conv);
15855         return (long)ret_conv;
15856 }
15857
15858 uint32_t  __attribute__((visibility("default"))) TS_NetworkGraph_update_channel_from_announcement(uint32_t this_arg, uint32_t msg, uint32_t chain_access) {
15859         LDKNetworkGraph this_arg_conv;
15860         this_arg_conv.inner = (void*)(this_arg & (~1));
15861         this_arg_conv.is_owned = false;
15862         LDKChannelAnnouncement msg_conv;
15863         msg_conv.inner = (void*)(msg & (~1));
15864         msg_conv.is_owned = false;
15865         LDKAccess* chain_access_conv = (LDKAccess*)chain_access;
15866         LDKCResult_NoneLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneLightningErrorZ), "LDKCResult_NoneLightningErrorZ");
15867         *ret_conv = NetworkGraph_update_channel_from_announcement(&this_arg_conv, &msg_conv, chain_access_conv);
15868         return (long)ret_conv;
15869 }
15870
15871 uint32_t  __attribute__((visibility("default"))) TS_NetworkGraph_update_channel_from_unsigned_announcement(uint32_t this_arg, uint32_t msg, uint32_t chain_access) {
15872         LDKNetworkGraph this_arg_conv;
15873         this_arg_conv.inner = (void*)(this_arg & (~1));
15874         this_arg_conv.is_owned = false;
15875         LDKUnsignedChannelAnnouncement msg_conv;
15876         msg_conv.inner = (void*)(msg & (~1));
15877         msg_conv.is_owned = false;
15878         LDKAccess* chain_access_conv = (LDKAccess*)chain_access;
15879         LDKCResult_NoneLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneLightningErrorZ), "LDKCResult_NoneLightningErrorZ");
15880         *ret_conv = NetworkGraph_update_channel_from_unsigned_announcement(&this_arg_conv, &msg_conv, chain_access_conv);
15881         return (long)ret_conv;
15882 }
15883
15884 void  __attribute__((visibility("default"))) TS_NetworkGraph_close_channel_from_update(uint32_t this_arg, int64_t short_channel_id, jboolean is_permanent) {
15885         LDKNetworkGraph this_arg_conv;
15886         this_arg_conv.inner = (void*)(this_arg & (~1));
15887         this_arg_conv.is_owned = false;
15888         NetworkGraph_close_channel_from_update(&this_arg_conv, short_channel_id, is_permanent);
15889 }
15890
15891 uint32_t  __attribute__((visibility("default"))) TS_NetworkGraph_update_channel(uint32_t this_arg, uint32_t msg) {
15892         LDKNetworkGraph this_arg_conv;
15893         this_arg_conv.inner = (void*)(this_arg & (~1));
15894         this_arg_conv.is_owned = false;
15895         LDKChannelUpdate msg_conv;
15896         msg_conv.inner = (void*)(msg & (~1));
15897         msg_conv.is_owned = false;
15898         LDKCResult_NoneLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneLightningErrorZ), "LDKCResult_NoneLightningErrorZ");
15899         *ret_conv = NetworkGraph_update_channel(&this_arg_conv, &msg_conv);
15900         return (long)ret_conv;
15901 }
15902
15903 uint32_t  __attribute__((visibility("default"))) TS_NetworkGraph_update_channel_unsigned(uint32_t this_arg, uint32_t msg) {
15904         LDKNetworkGraph this_arg_conv;
15905         this_arg_conv.inner = (void*)(this_arg & (~1));
15906         this_arg_conv.is_owned = false;
15907         LDKUnsignedChannelUpdate msg_conv;
15908         msg_conv.inner = (void*)(msg & (~1));
15909         msg_conv.is_owned = false;
15910         LDKCResult_NoneLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneLightningErrorZ), "LDKCResult_NoneLightningErrorZ");
15911         *ret_conv = NetworkGraph_update_channel_unsigned(&this_arg_conv, &msg_conv);
15912         return (long)ret_conv;
15913 }
15914