Bindings updates
[ldk-java] / src / main / jni / bindings.c
1 #include "org_ldk_impl_bindings.h"
2 #include <rust_types.h>
3 #include <lightning.h>
4 #include <string.h>
5 #include <stdatomic.h>
6 #include <stdlib.h>
7 #include <assert.h>
8 // Always run a, then assert it is true:
9 #define DO_ASSERT(a) do { bool _assert_val = (a); assert(_assert_val); } while(0)
10 // Assert a is true or do nothing
11 #define CHECK(a) DO_ASSERT(a)
12
13 // Running a leak check across all the allocations and frees of the JDK is a mess,
14 // so instead we implement our own naive leak checker here, relying on the -wrap
15 // linker option to wrap malloc/calloc/realloc/free, tracking everyhing allocated
16 // and free'd in Rust or C across the generated bindings shared library.
17 #include <threads.h>
18 #include <execinfo.h>
19 #include <unistd.h>
20 static mtx_t allocation_mtx;
21
22 void __attribute__((constructor)) init_mtx() {
23         DO_ASSERT(mtx_init(&allocation_mtx, mtx_plain) == thrd_success);
24 }
25
26 #define BT_MAX 128
27 typedef struct allocation {
28         struct allocation* next;
29         void* ptr;
30         const char* struct_name;
31         void* bt[BT_MAX];
32         int bt_len;
33 } allocation;
34 static allocation* allocation_ll = NULL;
35
36 void* __real_malloc(size_t len);
37 void* __real_calloc(size_t nmemb, size_t len);
38 static void new_allocation(void* res, const char* struct_name) {
39         allocation* new_alloc = __real_malloc(sizeof(allocation));
40         new_alloc->ptr = res;
41         new_alloc->struct_name = struct_name;
42         new_alloc->bt_len = backtrace(new_alloc->bt, BT_MAX);
43         DO_ASSERT(mtx_lock(&allocation_mtx) == thrd_success);
44         new_alloc->next = allocation_ll;
45         allocation_ll = new_alloc;
46         DO_ASSERT(mtx_unlock(&allocation_mtx) == thrd_success);
47 }
48 static void* MALLOC(size_t len, const char* struct_name) {
49         void* res = __real_malloc(len);
50         new_allocation(res, struct_name);
51         return res;
52 }
53 void __real_free(void* ptr);
54 static void alloc_freed(void* ptr) {
55         allocation* p = NULL;
56         DO_ASSERT(mtx_lock(&allocation_mtx) == thrd_success);
57         allocation* it = allocation_ll;
58         while (it->ptr != ptr) {
59                 p = it; it = it->next;
60                 if (it == NULL) {
61                         fprintf(stderr, "Tried to free unknown pointer %p at:\n", ptr);
62                         void* bt[BT_MAX];
63                         int bt_len = backtrace(bt, BT_MAX);
64                         backtrace_symbols_fd(bt, bt_len, STDERR_FILENO);
65                         fprintf(stderr, "\n\n");
66                         DO_ASSERT(mtx_unlock(&allocation_mtx) == thrd_success);
67                         return; // addrsan should catch malloc-unknown and print more info than we have
68                 }
69         }
70         if (p) { p->next = it->next; } else { allocation_ll = it->next; }
71         DO_ASSERT(mtx_unlock(&allocation_mtx) == thrd_success);
72         DO_ASSERT(it->ptr == ptr);
73         __real_free(it);
74 }
75 static void FREE(void* ptr) {
76         if ((long)ptr < 1024) return; // Rust loves to create pointers to the NULL page for dummys
77         alloc_freed(ptr);
78         __real_free(ptr);
79 }
80
81 void* __wrap_malloc(size_t len) {
82         void* res = __real_malloc(len);
83         new_allocation(res, "malloc call");
84         return res;
85 }
86 void* __wrap_calloc(size_t nmemb, size_t len) {
87         void* res = __real_calloc(nmemb, len);
88         new_allocation(res, "calloc call");
89         return res;
90 }
91 void __wrap_free(void* ptr) {
92         if (ptr == NULL) return;
93         alloc_freed(ptr);
94         __real_free(ptr);
95 }
96
97 void* __real_realloc(void* ptr, size_t newlen);
98 void* __wrap_realloc(void* ptr, size_t len) {
99         if (ptr != NULL) alloc_freed(ptr);
100         void* res = __real_realloc(ptr, len);
101         new_allocation(res, "realloc call");
102         return res;
103 }
104 void __wrap_reallocarray(void* ptr, size_t new_sz) {
105         // Rust doesn't seem to use reallocarray currently
106         DO_ASSERT(false);
107 }
108
109 void __attribute__((destructor)) check_leaks() {
110         for (allocation* a = allocation_ll; a != NULL; a = a->next) {
111                 fprintf(stderr, "%s %p remains:\n", a->struct_name, a->ptr);
112                 backtrace_symbols_fd(a->bt, a->bt_len, STDERR_FILENO);
113                 fprintf(stderr, "\n\n");
114         }
115         DO_ASSERT(allocation_ll == NULL);
116 }
117
118 static jmethodID ordinal_meth = NULL;
119 static jmethodID slicedef_meth = NULL;
120 static jclass slicedef_cls = NULL;
121 JNIEXPORT void Java_org_ldk_impl_bindings_init(JNIEnv * env, jclass _b, jclass enum_class, jclass slicedef_class) {
122         ordinal_meth = (*env)->GetMethodID(env, enum_class, "ordinal", "()I");
123         CHECK(ordinal_meth != NULL);
124         slicedef_meth = (*env)->GetMethodID(env, slicedef_class, "<init>", "(JJJ)V");
125         CHECK(slicedef_meth != NULL);
126         slicedef_cls = (*env)->NewGlobalRef(env, slicedef_class);
127         CHECK(slicedef_cls != NULL);
128 }
129
130 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_deref_1bool (JNIEnv * env, jclass _a, jlong ptr) {
131         return *((bool*)ptr);
132 }
133 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_deref_1long (JNIEnv * env, jclass _a, jlong ptr) {
134         return *((long*)ptr);
135 }
136 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_free_1heap_1ptr (JNIEnv * env, jclass _a, jlong ptr) {
137         FREE((void*)ptr);
138 }
139 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_read_1bytes (JNIEnv * env, jclass _b, jlong ptr, jlong len) {
140         jbyteArray ret_arr = (*env)->NewByteArray(env, len);
141         (*env)->SetByteArrayRegion(env, ret_arr, 0, len, (unsigned char*)ptr);
142         return ret_arr;
143 }
144 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_get_1u8_1slice_1bytes (JNIEnv * env, jclass _b, jlong slice_ptr) {
145         LDKu8slice *slice = (LDKu8slice*)slice_ptr;
146         jbyteArray ret_arr = (*env)->NewByteArray(env, slice->datalen);
147         (*env)->SetByteArrayRegion(env, ret_arr, 0, slice->datalen, slice->data);
148         return ret_arr;
149 }
150 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_bytes_1to_1u8_1vec (JNIEnv * env, jclass _b, jbyteArray bytes) {
151         LDKCVec_u8Z *vec = (LDKCVec_u8Z*)MALLOC(sizeof(LDKCVec_u8Z), "LDKCVec_u8");
152         vec->datalen = (*env)->GetArrayLength(env, bytes);
153         vec->data = (uint8_t*)MALLOC(vec->datalen, "LDKCVec_u8Z Bytes");
154         (*env)->GetByteArrayRegion (env, bytes, 0, vec->datalen, vec->data);
155         return (long)vec;
156 }
157 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_txpointer_1get_1buffer (JNIEnv * env, jclass _b, jlong ptr) {
158         LDKTransaction *txdata = (LDKTransaction*)ptr;
159         LDKu8slice slice;
160         slice.data = txdata->data;
161         slice.datalen = txdata->datalen;
162         return Java_org_ldk_impl_bindings_get_1u8_1slice_1bytes(env, _b, (long)&slice);
163 }
164 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_new_1txpointer_1copy_1data (JNIEnv * env, jclass _b, jbyteArray bytes) {
165         LDKTransaction *txdata = (LDKTransaction*)MALLOC(sizeof(LDKTransaction), "LDKTransaction");
166         txdata->datalen = (*env)->GetArrayLength(env, bytes);
167         txdata->data = (uint8_t*)MALLOC(txdata->datalen, "Tx Data Bytes");
168         txdata->data_is_owned = false;
169         (*env)->GetByteArrayRegion (env, bytes, 0, txdata->datalen, txdata->data);
170         return (long)txdata;
171 }
172 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_txpointer_1free (JNIEnv * env, jclass _b, jlong ptr) {
173         LDKTransaction *tx = (LDKTransaction*)ptr;
174         tx->data_is_owned = true;
175         Transaction_free(*tx);
176         FREE((void*)ptr);
177 }
178 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_vec_1slice_1len (JNIEnv * env, jclass _a, jlong ptr) {
179         // Check offsets of a few Vec types are all consistent as we're meant to be generic across types
180         _Static_assert(offsetof(LDKCVec_u8Z, datalen) == offsetof(LDKCVec_SignatureZ, datalen), "Vec<*> needs to be mapped identically");
181         _Static_assert(offsetof(LDKCVec_u8Z, datalen) == offsetof(LDKCVec_MessageSendEventZ, datalen), "Vec<*> needs to be mapped identically");
182         _Static_assert(offsetof(LDKCVec_u8Z, datalen) == offsetof(LDKCVec_EventZ, datalen), "Vec<*> needs to be mapped identically");
183         _Static_assert(offsetof(LDKCVec_u8Z, datalen) == offsetof(LDKCVec_C2Tuple_usizeTransactionZZ, datalen), "Vec<*> needs to be mapped identically");
184         LDKCVec_u8Z *vec = (LDKCVec_u8Z*)ptr;
185         return (long)vec->datalen;
186 }
187 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_new_1empty_1slice_1vec (JNIEnv * env, jclass _b) {
188         // Check sizes of a few Vec types are all consistent as we're meant to be generic across types
189         _Static_assert(sizeof(LDKCVec_u8Z) == sizeof(LDKCVec_SignatureZ), "Vec<*> needs to be mapped identically");
190         _Static_assert(sizeof(LDKCVec_u8Z) == sizeof(LDKCVec_MessageSendEventZ), "Vec<*> needs to be mapped identically");
191         _Static_assert(sizeof(LDKCVec_u8Z) == sizeof(LDKCVec_EventZ), "Vec<*> needs to be mapped identically");
192         _Static_assert(sizeof(LDKCVec_u8Z) == sizeof(LDKCVec_C2Tuple_usizeTransactionZZ), "Vec<*> needs to be mapped identically");
193         LDKCVec_u8Z *vec = (LDKCVec_u8Z*)MALLOC(sizeof(LDKCVec_u8Z), "Empty LDKCVec");
194         vec->data = NULL;
195         vec->datalen = 0;
196         return (long)vec;
197 }
198
199 // We assume that CVec_u8Z and u8slice are the same size and layout (and thus pointers to the two can be mixed)
200 _Static_assert(sizeof(LDKCVec_u8Z) == sizeof(LDKu8slice), "Vec<u8> and [u8] need to have been mapped identically");
201 _Static_assert(offsetof(LDKCVec_u8Z, data) == offsetof(LDKu8slice, data), "Vec<u8> and [u8] need to have been mapped identically");
202 _Static_assert(offsetof(LDKCVec_u8Z, datalen) == offsetof(LDKu8slice, datalen), "Vec<u8> and [u8] need to have been mapped identically");
203
204 _Static_assert(sizeof(jlong) == sizeof(int64_t), "We assume that j-types are the same as C types");
205 _Static_assert(sizeof(jbyte) == sizeof(char), "We assume that j-types are the same as C types");
206 _Static_assert(sizeof(void*) <= 8, "Pointers must fit into 64 bits");
207
208 typedef jlongArray int64_tArray;
209 typedef jbyteArray int8_tArray;
210
211 static jclass arr_of_J_clz = NULL;
212 static jclass arr_of_B_clz = NULL;
213 JNIEXPORT void Java_org_ldk_impl_bindings_init_1class_1cache(JNIEnv * env, jclass clz) {
214         arr_of_J_clz = (*env)->FindClass(env, "[J");
215         CHECK(arr_of_J_clz != NULL);
216         arr_of_J_clz = (*env)->NewGlobalRef(env, arr_of_J_clz);
217         arr_of_B_clz = (*env)->FindClass(env, "[B");
218         CHECK(arr_of_B_clz != NULL);
219         arr_of_B_clz = (*env)->NewGlobalRef(env, arr_of_B_clz);
220 }
221 static inline struct LDKThirtyTwoBytes ThirtyTwoBytes_clone(const struct LDKThirtyTwoBytes *orig) { struct LDKThirtyTwoBytes ret; memcpy(ret.data, orig->data, 32); return ret; }
222 static inline LDKAccessError LDKAccessError_from_java(JNIEnv *env, jclass clz) {
223         switch ((*env)->CallIntMethod(env, clz, ordinal_meth)) {
224                 case 0: return LDKAccessError_UnknownChain;
225                 case 1: return LDKAccessError_UnknownTx;
226         }
227         abort();
228 }
229 static jclass LDKAccessError_class = NULL;
230 static jfieldID LDKAccessError_LDKAccessError_UnknownChain = NULL;
231 static jfieldID LDKAccessError_LDKAccessError_UnknownTx = NULL;
232 JNIEXPORT void JNICALL Java_org_ldk_enums_LDKAccessError_init (JNIEnv *env, jclass clz) {
233         LDKAccessError_class = (*env)->NewGlobalRef(env, clz);
234         CHECK(LDKAccessError_class != NULL);
235         LDKAccessError_LDKAccessError_UnknownChain = (*env)->GetStaticFieldID(env, LDKAccessError_class, "LDKAccessError_UnknownChain", "Lorg/ldk/enums/LDKAccessError;");
236         CHECK(LDKAccessError_LDKAccessError_UnknownChain != NULL);
237         LDKAccessError_LDKAccessError_UnknownTx = (*env)->GetStaticFieldID(env, LDKAccessError_class, "LDKAccessError_UnknownTx", "Lorg/ldk/enums/LDKAccessError;");
238         CHECK(LDKAccessError_LDKAccessError_UnknownTx != NULL);
239 }
240 static inline jclass LDKAccessError_to_java(JNIEnv *env, LDKAccessError val) {
241         switch (val) {
242                 case LDKAccessError_UnknownChain:
243                         return (*env)->GetStaticObjectField(env, LDKAccessError_class, LDKAccessError_LDKAccessError_UnknownChain);
244                 case LDKAccessError_UnknownTx:
245                         return (*env)->GetStaticObjectField(env, LDKAccessError_class, LDKAccessError_LDKAccessError_UnknownTx);
246                 default: abort();
247         }
248 }
249
250 static inline LDKChannelMonitorUpdateErr LDKChannelMonitorUpdateErr_from_java(JNIEnv *env, jclass clz) {
251         switch ((*env)->CallIntMethod(env, clz, ordinal_meth)) {
252                 case 0: return LDKChannelMonitorUpdateErr_TemporaryFailure;
253                 case 1: return LDKChannelMonitorUpdateErr_PermanentFailure;
254         }
255         abort();
256 }
257 static jclass LDKChannelMonitorUpdateErr_class = NULL;
258 static jfieldID LDKChannelMonitorUpdateErr_LDKChannelMonitorUpdateErr_TemporaryFailure = NULL;
259 static jfieldID LDKChannelMonitorUpdateErr_LDKChannelMonitorUpdateErr_PermanentFailure = NULL;
260 JNIEXPORT void JNICALL Java_org_ldk_enums_LDKChannelMonitorUpdateErr_init (JNIEnv *env, jclass clz) {
261         LDKChannelMonitorUpdateErr_class = (*env)->NewGlobalRef(env, clz);
262         CHECK(LDKChannelMonitorUpdateErr_class != NULL);
263         LDKChannelMonitorUpdateErr_LDKChannelMonitorUpdateErr_TemporaryFailure = (*env)->GetStaticFieldID(env, LDKChannelMonitorUpdateErr_class, "LDKChannelMonitorUpdateErr_TemporaryFailure", "Lorg/ldk/enums/LDKChannelMonitorUpdateErr;");
264         CHECK(LDKChannelMonitorUpdateErr_LDKChannelMonitorUpdateErr_TemporaryFailure != NULL);
265         LDKChannelMonitorUpdateErr_LDKChannelMonitorUpdateErr_PermanentFailure = (*env)->GetStaticFieldID(env, LDKChannelMonitorUpdateErr_class, "LDKChannelMonitorUpdateErr_PermanentFailure", "Lorg/ldk/enums/LDKChannelMonitorUpdateErr;");
266         CHECK(LDKChannelMonitorUpdateErr_LDKChannelMonitorUpdateErr_PermanentFailure != NULL);
267 }
268 static inline jclass LDKChannelMonitorUpdateErr_to_java(JNIEnv *env, LDKChannelMonitorUpdateErr val) {
269         switch (val) {
270                 case LDKChannelMonitorUpdateErr_TemporaryFailure:
271                         return (*env)->GetStaticObjectField(env, LDKChannelMonitorUpdateErr_class, LDKChannelMonitorUpdateErr_LDKChannelMonitorUpdateErr_TemporaryFailure);
272                 case LDKChannelMonitorUpdateErr_PermanentFailure:
273                         return (*env)->GetStaticObjectField(env, LDKChannelMonitorUpdateErr_class, LDKChannelMonitorUpdateErr_LDKChannelMonitorUpdateErr_PermanentFailure);
274                 default: abort();
275         }
276 }
277
278 static inline LDKConfirmationTarget LDKConfirmationTarget_from_java(JNIEnv *env, jclass clz) {
279         switch ((*env)->CallIntMethod(env, clz, ordinal_meth)) {
280                 case 0: return LDKConfirmationTarget_Background;
281                 case 1: return LDKConfirmationTarget_Normal;
282                 case 2: return LDKConfirmationTarget_HighPriority;
283         }
284         abort();
285 }
286 static jclass LDKConfirmationTarget_class = NULL;
287 static jfieldID LDKConfirmationTarget_LDKConfirmationTarget_Background = NULL;
288 static jfieldID LDKConfirmationTarget_LDKConfirmationTarget_Normal = NULL;
289 static jfieldID LDKConfirmationTarget_LDKConfirmationTarget_HighPriority = NULL;
290 JNIEXPORT void JNICALL Java_org_ldk_enums_LDKConfirmationTarget_init (JNIEnv *env, jclass clz) {
291         LDKConfirmationTarget_class = (*env)->NewGlobalRef(env, clz);
292         CHECK(LDKConfirmationTarget_class != NULL);
293         LDKConfirmationTarget_LDKConfirmationTarget_Background = (*env)->GetStaticFieldID(env, LDKConfirmationTarget_class, "LDKConfirmationTarget_Background", "Lorg/ldk/enums/LDKConfirmationTarget;");
294         CHECK(LDKConfirmationTarget_LDKConfirmationTarget_Background != NULL);
295         LDKConfirmationTarget_LDKConfirmationTarget_Normal = (*env)->GetStaticFieldID(env, LDKConfirmationTarget_class, "LDKConfirmationTarget_Normal", "Lorg/ldk/enums/LDKConfirmationTarget;");
296         CHECK(LDKConfirmationTarget_LDKConfirmationTarget_Normal != NULL);
297         LDKConfirmationTarget_LDKConfirmationTarget_HighPriority = (*env)->GetStaticFieldID(env, LDKConfirmationTarget_class, "LDKConfirmationTarget_HighPriority", "Lorg/ldk/enums/LDKConfirmationTarget;");
298         CHECK(LDKConfirmationTarget_LDKConfirmationTarget_HighPriority != NULL);
299 }
300 static inline jclass LDKConfirmationTarget_to_java(JNIEnv *env, LDKConfirmationTarget val) {
301         switch (val) {
302                 case LDKConfirmationTarget_Background:
303                         return (*env)->GetStaticObjectField(env, LDKConfirmationTarget_class, LDKConfirmationTarget_LDKConfirmationTarget_Background);
304                 case LDKConfirmationTarget_Normal:
305                         return (*env)->GetStaticObjectField(env, LDKConfirmationTarget_class, LDKConfirmationTarget_LDKConfirmationTarget_Normal);
306                 case LDKConfirmationTarget_HighPriority:
307                         return (*env)->GetStaticObjectField(env, LDKConfirmationTarget_class, LDKConfirmationTarget_LDKConfirmationTarget_HighPriority);
308                 default: abort();
309         }
310 }
311
312 static inline LDKLevel LDKLevel_from_java(JNIEnv *env, jclass clz) {
313         switch ((*env)->CallIntMethod(env, clz, ordinal_meth)) {
314                 case 0: return LDKLevel_Off;
315                 case 1: return LDKLevel_Error;
316                 case 2: return LDKLevel_Warn;
317                 case 3: return LDKLevel_Info;
318                 case 4: return LDKLevel_Debug;
319                 case 5: return LDKLevel_Trace;
320         }
321         abort();
322 }
323 static jclass LDKLevel_class = NULL;
324 static jfieldID LDKLevel_LDKLevel_Off = NULL;
325 static jfieldID LDKLevel_LDKLevel_Error = NULL;
326 static jfieldID LDKLevel_LDKLevel_Warn = NULL;
327 static jfieldID LDKLevel_LDKLevel_Info = NULL;
328 static jfieldID LDKLevel_LDKLevel_Debug = NULL;
329 static jfieldID LDKLevel_LDKLevel_Trace = NULL;
330 JNIEXPORT void JNICALL Java_org_ldk_enums_LDKLevel_init (JNIEnv *env, jclass clz) {
331         LDKLevel_class = (*env)->NewGlobalRef(env, clz);
332         CHECK(LDKLevel_class != NULL);
333         LDKLevel_LDKLevel_Off = (*env)->GetStaticFieldID(env, LDKLevel_class, "LDKLevel_Off", "Lorg/ldk/enums/LDKLevel;");
334         CHECK(LDKLevel_LDKLevel_Off != NULL);
335         LDKLevel_LDKLevel_Error = (*env)->GetStaticFieldID(env, LDKLevel_class, "LDKLevel_Error", "Lorg/ldk/enums/LDKLevel;");
336         CHECK(LDKLevel_LDKLevel_Error != NULL);
337         LDKLevel_LDKLevel_Warn = (*env)->GetStaticFieldID(env, LDKLevel_class, "LDKLevel_Warn", "Lorg/ldk/enums/LDKLevel;");
338         CHECK(LDKLevel_LDKLevel_Warn != NULL);
339         LDKLevel_LDKLevel_Info = (*env)->GetStaticFieldID(env, LDKLevel_class, "LDKLevel_Info", "Lorg/ldk/enums/LDKLevel;");
340         CHECK(LDKLevel_LDKLevel_Info != NULL);
341         LDKLevel_LDKLevel_Debug = (*env)->GetStaticFieldID(env, LDKLevel_class, "LDKLevel_Debug", "Lorg/ldk/enums/LDKLevel;");
342         CHECK(LDKLevel_LDKLevel_Debug != NULL);
343         LDKLevel_LDKLevel_Trace = (*env)->GetStaticFieldID(env, LDKLevel_class, "LDKLevel_Trace", "Lorg/ldk/enums/LDKLevel;");
344         CHECK(LDKLevel_LDKLevel_Trace != NULL);
345 }
346 static inline jclass LDKLevel_to_java(JNIEnv *env, LDKLevel val) {
347         switch (val) {
348                 case LDKLevel_Off:
349                         return (*env)->GetStaticObjectField(env, LDKLevel_class, LDKLevel_LDKLevel_Off);
350                 case LDKLevel_Error:
351                         return (*env)->GetStaticObjectField(env, LDKLevel_class, LDKLevel_LDKLevel_Error);
352                 case LDKLevel_Warn:
353                         return (*env)->GetStaticObjectField(env, LDKLevel_class, LDKLevel_LDKLevel_Warn);
354                 case LDKLevel_Info:
355                         return (*env)->GetStaticObjectField(env, LDKLevel_class, LDKLevel_LDKLevel_Info);
356                 case LDKLevel_Debug:
357                         return (*env)->GetStaticObjectField(env, LDKLevel_class, LDKLevel_LDKLevel_Debug);
358                 case LDKLevel_Trace:
359                         return (*env)->GetStaticObjectField(env, LDKLevel_class, LDKLevel_LDKLevel_Trace);
360                 default: abort();
361         }
362 }
363
364 static inline LDKNetwork LDKNetwork_from_java(JNIEnv *env, jclass clz) {
365         switch ((*env)->CallIntMethod(env, clz, ordinal_meth)) {
366                 case 0: return LDKNetwork_Bitcoin;
367                 case 1: return LDKNetwork_Testnet;
368                 case 2: return LDKNetwork_Regtest;
369         }
370         abort();
371 }
372 static jclass LDKNetwork_class = NULL;
373 static jfieldID LDKNetwork_LDKNetwork_Bitcoin = NULL;
374 static jfieldID LDKNetwork_LDKNetwork_Testnet = NULL;
375 static jfieldID LDKNetwork_LDKNetwork_Regtest = NULL;
376 JNIEXPORT void JNICALL Java_org_ldk_enums_LDKNetwork_init (JNIEnv *env, jclass clz) {
377         LDKNetwork_class = (*env)->NewGlobalRef(env, clz);
378         CHECK(LDKNetwork_class != NULL);
379         LDKNetwork_LDKNetwork_Bitcoin = (*env)->GetStaticFieldID(env, LDKNetwork_class, "LDKNetwork_Bitcoin", "Lorg/ldk/enums/LDKNetwork;");
380         CHECK(LDKNetwork_LDKNetwork_Bitcoin != NULL);
381         LDKNetwork_LDKNetwork_Testnet = (*env)->GetStaticFieldID(env, LDKNetwork_class, "LDKNetwork_Testnet", "Lorg/ldk/enums/LDKNetwork;");
382         CHECK(LDKNetwork_LDKNetwork_Testnet != NULL);
383         LDKNetwork_LDKNetwork_Regtest = (*env)->GetStaticFieldID(env, LDKNetwork_class, "LDKNetwork_Regtest", "Lorg/ldk/enums/LDKNetwork;");
384         CHECK(LDKNetwork_LDKNetwork_Regtest != NULL);
385 }
386 static inline jclass LDKNetwork_to_java(JNIEnv *env, LDKNetwork val) {
387         switch (val) {
388                 case LDKNetwork_Bitcoin:
389                         return (*env)->GetStaticObjectField(env, LDKNetwork_class, LDKNetwork_LDKNetwork_Bitcoin);
390                 case LDKNetwork_Testnet:
391                         return (*env)->GetStaticObjectField(env, LDKNetwork_class, LDKNetwork_LDKNetwork_Testnet);
392                 case LDKNetwork_Regtest:
393                         return (*env)->GetStaticObjectField(env, LDKNetwork_class, LDKNetwork_LDKNetwork_Regtest);
394                 default: abort();
395         }
396 }
397
398 static inline LDKSecp256k1Error LDKSecp256k1Error_from_java(JNIEnv *env, jclass clz) {
399         switch ((*env)->CallIntMethod(env, clz, ordinal_meth)) {
400                 case 0: return LDKSecp256k1Error_IncorrectSignature;
401                 case 1: return LDKSecp256k1Error_InvalidMessage;
402                 case 2: return LDKSecp256k1Error_InvalidPublicKey;
403                 case 3: return LDKSecp256k1Error_InvalidSignature;
404                 case 4: return LDKSecp256k1Error_InvalidSecretKey;
405                 case 5: return LDKSecp256k1Error_InvalidRecoveryId;
406                 case 6: return LDKSecp256k1Error_InvalidTweak;
407                 case 7: return LDKSecp256k1Error_NotEnoughMemory;
408                 case 8: return LDKSecp256k1Error_CallbackPanicked;
409         }
410         abort();
411 }
412 static jclass LDKSecp256k1Error_class = NULL;
413 static jfieldID LDKSecp256k1Error_LDKSecp256k1Error_IncorrectSignature = NULL;
414 static jfieldID LDKSecp256k1Error_LDKSecp256k1Error_InvalidMessage = NULL;
415 static jfieldID LDKSecp256k1Error_LDKSecp256k1Error_InvalidPublicKey = NULL;
416 static jfieldID LDKSecp256k1Error_LDKSecp256k1Error_InvalidSignature = NULL;
417 static jfieldID LDKSecp256k1Error_LDKSecp256k1Error_InvalidSecretKey = NULL;
418 static jfieldID LDKSecp256k1Error_LDKSecp256k1Error_InvalidRecoveryId = NULL;
419 static jfieldID LDKSecp256k1Error_LDKSecp256k1Error_InvalidTweak = NULL;
420 static jfieldID LDKSecp256k1Error_LDKSecp256k1Error_NotEnoughMemory = NULL;
421 static jfieldID LDKSecp256k1Error_LDKSecp256k1Error_CallbackPanicked = NULL;
422 JNIEXPORT void JNICALL Java_org_ldk_enums_LDKSecp256k1Error_init (JNIEnv *env, jclass clz) {
423         LDKSecp256k1Error_class = (*env)->NewGlobalRef(env, clz);
424         CHECK(LDKSecp256k1Error_class != NULL);
425         LDKSecp256k1Error_LDKSecp256k1Error_IncorrectSignature = (*env)->GetStaticFieldID(env, LDKSecp256k1Error_class, "LDKSecp256k1Error_IncorrectSignature", "Lorg/ldk/enums/LDKSecp256k1Error;");
426         CHECK(LDKSecp256k1Error_LDKSecp256k1Error_IncorrectSignature != NULL);
427         LDKSecp256k1Error_LDKSecp256k1Error_InvalidMessage = (*env)->GetStaticFieldID(env, LDKSecp256k1Error_class, "LDKSecp256k1Error_InvalidMessage", "Lorg/ldk/enums/LDKSecp256k1Error;");
428         CHECK(LDKSecp256k1Error_LDKSecp256k1Error_InvalidMessage != NULL);
429         LDKSecp256k1Error_LDKSecp256k1Error_InvalidPublicKey = (*env)->GetStaticFieldID(env, LDKSecp256k1Error_class, "LDKSecp256k1Error_InvalidPublicKey", "Lorg/ldk/enums/LDKSecp256k1Error;");
430         CHECK(LDKSecp256k1Error_LDKSecp256k1Error_InvalidPublicKey != NULL);
431         LDKSecp256k1Error_LDKSecp256k1Error_InvalidSignature = (*env)->GetStaticFieldID(env, LDKSecp256k1Error_class, "LDKSecp256k1Error_InvalidSignature", "Lorg/ldk/enums/LDKSecp256k1Error;");
432         CHECK(LDKSecp256k1Error_LDKSecp256k1Error_InvalidSignature != NULL);
433         LDKSecp256k1Error_LDKSecp256k1Error_InvalidSecretKey = (*env)->GetStaticFieldID(env, LDKSecp256k1Error_class, "LDKSecp256k1Error_InvalidSecretKey", "Lorg/ldk/enums/LDKSecp256k1Error;");
434         CHECK(LDKSecp256k1Error_LDKSecp256k1Error_InvalidSecretKey != NULL);
435         LDKSecp256k1Error_LDKSecp256k1Error_InvalidRecoveryId = (*env)->GetStaticFieldID(env, LDKSecp256k1Error_class, "LDKSecp256k1Error_InvalidRecoveryId", "Lorg/ldk/enums/LDKSecp256k1Error;");
436         CHECK(LDKSecp256k1Error_LDKSecp256k1Error_InvalidRecoveryId != NULL);
437         LDKSecp256k1Error_LDKSecp256k1Error_InvalidTweak = (*env)->GetStaticFieldID(env, LDKSecp256k1Error_class, "LDKSecp256k1Error_InvalidTweak", "Lorg/ldk/enums/LDKSecp256k1Error;");
438         CHECK(LDKSecp256k1Error_LDKSecp256k1Error_InvalidTweak != NULL);
439         LDKSecp256k1Error_LDKSecp256k1Error_NotEnoughMemory = (*env)->GetStaticFieldID(env, LDKSecp256k1Error_class, "LDKSecp256k1Error_NotEnoughMemory", "Lorg/ldk/enums/LDKSecp256k1Error;");
440         CHECK(LDKSecp256k1Error_LDKSecp256k1Error_NotEnoughMemory != NULL);
441         LDKSecp256k1Error_LDKSecp256k1Error_CallbackPanicked = (*env)->GetStaticFieldID(env, LDKSecp256k1Error_class, "LDKSecp256k1Error_CallbackPanicked", "Lorg/ldk/enums/LDKSecp256k1Error;");
442         CHECK(LDKSecp256k1Error_LDKSecp256k1Error_CallbackPanicked != NULL);
443 }
444 static inline jclass LDKSecp256k1Error_to_java(JNIEnv *env, LDKSecp256k1Error val) {
445         switch (val) {
446                 case LDKSecp256k1Error_IncorrectSignature:
447                         return (*env)->GetStaticObjectField(env, LDKSecp256k1Error_class, LDKSecp256k1Error_LDKSecp256k1Error_IncorrectSignature);
448                 case LDKSecp256k1Error_InvalidMessage:
449                         return (*env)->GetStaticObjectField(env, LDKSecp256k1Error_class, LDKSecp256k1Error_LDKSecp256k1Error_InvalidMessage);
450                 case LDKSecp256k1Error_InvalidPublicKey:
451                         return (*env)->GetStaticObjectField(env, LDKSecp256k1Error_class, LDKSecp256k1Error_LDKSecp256k1Error_InvalidPublicKey);
452                 case LDKSecp256k1Error_InvalidSignature:
453                         return (*env)->GetStaticObjectField(env, LDKSecp256k1Error_class, LDKSecp256k1Error_LDKSecp256k1Error_InvalidSignature);
454                 case LDKSecp256k1Error_InvalidSecretKey:
455                         return (*env)->GetStaticObjectField(env, LDKSecp256k1Error_class, LDKSecp256k1Error_LDKSecp256k1Error_InvalidSecretKey);
456                 case LDKSecp256k1Error_InvalidRecoveryId:
457                         return (*env)->GetStaticObjectField(env, LDKSecp256k1Error_class, LDKSecp256k1Error_LDKSecp256k1Error_InvalidRecoveryId);
458                 case LDKSecp256k1Error_InvalidTweak:
459                         return (*env)->GetStaticObjectField(env, LDKSecp256k1Error_class, LDKSecp256k1Error_LDKSecp256k1Error_InvalidTweak);
460                 case LDKSecp256k1Error_NotEnoughMemory:
461                         return (*env)->GetStaticObjectField(env, LDKSecp256k1Error_class, LDKSecp256k1Error_LDKSecp256k1Error_NotEnoughMemory);
462                 case LDKSecp256k1Error_CallbackPanicked:
463                         return (*env)->GetStaticObjectField(env, LDKSecp256k1Error_class, LDKSecp256k1Error_LDKSecp256k1Error_CallbackPanicked);
464                 default: abort();
465         }
466 }
467
468 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCVec_1u8Z_1new(JNIEnv *env, jclass clz, int8_tArray elems) {
469         LDKCVec_u8Z *ret = MALLOC(sizeof(LDKCVec_u8Z), "LDKCVec_u8Z");
470         ret->datalen = (*env)->GetArrayLength(env, elems);
471         if (ret->datalen == 0) {
472                 ret->data = NULL;
473         } else {
474                 ret->data = MALLOC(sizeof(uint8_t) * ret->datalen, "LDKCVec_u8Z Data");
475                 int8_t *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
476                 for (size_t i = 0; i < ret->datalen; i++) {
477                         ret->data[i] = java_elems[i];
478                 }
479                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
480         }
481         return (long)ret;
482 }
483 static inline LDKCVec_u8Z CVec_u8Z_clone(const LDKCVec_u8Z *orig) {
484         LDKCVec_u8Z ret = { .data = MALLOC(sizeof(int8_t) * orig->datalen, "LDKCVec_u8Z clone bytes"), .datalen = orig->datalen };
485         memcpy(ret.data, orig->data, sizeof(int8_t) * ret.datalen);
486         return ret;
487 }
488 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKC2Tuple_1u64u64Z_1new(JNIEnv *env, jclass clz, int64_t a, int64_t b) {
489         LDKC2Tuple_u64u64Z* ret = MALLOC(sizeof(LDKC2Tuple_u64u64Z), "LDKC2Tuple_u64u64Z");
490         ret->a = a;
491         ret->b = b;
492         return (long)ret;
493 }
494 static inline LDKC2Tuple_u64u64Z C2Tuple_u64u64Z_clone(const LDKC2Tuple_u64u64Z *orig) {
495         LDKC2Tuple_u64u64Z ret = {
496                 .a = orig->a,
497                 .b = orig->b,
498         };
499         return ret;
500 }
501 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKC2Tuple_1u64u64Z_1get_1a(JNIEnv *env, jclass clz, int64_t ptr) {
502         LDKC2Tuple_u64u64Z *tuple = (LDKC2Tuple_u64u64Z*)ptr;
503         return tuple->a;
504 }
505 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKC2Tuple_1u64u64Z_1get_1b(JNIEnv *env, jclass clz, int64_t ptr) {
506         LDKC2Tuple_u64u64Z *tuple = (LDKC2Tuple_u64u64Z*)ptr;
507         return tuple->b;
508 }
509 static jclass LDKSpendableOutputDescriptor_StaticOutput_class = NULL;
510 static jmethodID LDKSpendableOutputDescriptor_StaticOutput_meth = NULL;
511 static jclass LDKSpendableOutputDescriptor_DynamicOutputP2WSH_class = NULL;
512 static jmethodID LDKSpendableOutputDescriptor_DynamicOutputP2WSH_meth = NULL;
513 static jclass LDKSpendableOutputDescriptor_StaticOutputCounterpartyPayment_class = NULL;
514 static jmethodID LDKSpendableOutputDescriptor_StaticOutputCounterpartyPayment_meth = NULL;
515 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_00024LDKSpendableOutputDescriptor_init (JNIEnv *env, jclass clz) {
516         LDKSpendableOutputDescriptor_StaticOutput_class =
517                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKSpendableOutputDescriptor$StaticOutput;"));
518         CHECK(LDKSpendableOutputDescriptor_StaticOutput_class != NULL);
519         LDKSpendableOutputDescriptor_StaticOutput_meth = (*env)->GetMethodID(env, LDKSpendableOutputDescriptor_StaticOutput_class, "<init>", "(JJ)V");
520         CHECK(LDKSpendableOutputDescriptor_StaticOutput_meth != NULL);
521         LDKSpendableOutputDescriptor_DynamicOutputP2WSH_class =
522                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKSpendableOutputDescriptor$DynamicOutputP2WSH;"));
523         CHECK(LDKSpendableOutputDescriptor_DynamicOutputP2WSH_class != NULL);
524         LDKSpendableOutputDescriptor_DynamicOutputP2WSH_meth = (*env)->GetMethodID(env, LDKSpendableOutputDescriptor_DynamicOutputP2WSH_class, "<init>", "(J[BSJJ[B)V");
525         CHECK(LDKSpendableOutputDescriptor_DynamicOutputP2WSH_meth != NULL);
526         LDKSpendableOutputDescriptor_StaticOutputCounterpartyPayment_class =
527                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKSpendableOutputDescriptor$StaticOutputCounterpartyPayment;"));
528         CHECK(LDKSpendableOutputDescriptor_StaticOutputCounterpartyPayment_class != NULL);
529         LDKSpendableOutputDescriptor_StaticOutputCounterpartyPayment_meth = (*env)->GetMethodID(env, LDKSpendableOutputDescriptor_StaticOutputCounterpartyPayment_class, "<init>", "(JJJ)V");
530         CHECK(LDKSpendableOutputDescriptor_StaticOutputCounterpartyPayment_meth != NULL);
531 }
532 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKSpendableOutputDescriptor_1ref_1from_1ptr (JNIEnv *env, jclass clz, int64_t ptr) {
533         LDKSpendableOutputDescriptor *obj = (LDKSpendableOutputDescriptor*)ptr;
534         switch(obj->tag) {
535                 case LDKSpendableOutputDescriptor_StaticOutput: {
536                         LDKOutPoint outpoint_var = obj->static_output.outpoint;
537                         CHECK((((long)outpoint_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
538                         CHECK((((long)&outpoint_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
539                         long outpoint_ref = (long)outpoint_var.inner & ~1;
540                         long output_ref = (long)&obj->static_output.output;
541                         return (*env)->NewObject(env, LDKSpendableOutputDescriptor_StaticOutput_class, LDKSpendableOutputDescriptor_StaticOutput_meth, outpoint_ref, (long)output_ref);
542                 }
543                 case LDKSpendableOutputDescriptor_DynamicOutputP2WSH: {
544                         LDKOutPoint outpoint_var = obj->dynamic_output_p2wsh.outpoint;
545                         CHECK((((long)outpoint_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
546                         CHECK((((long)&outpoint_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
547                         long outpoint_ref = (long)outpoint_var.inner & ~1;
548                         int8_tArray per_commitment_point_arr = (*env)->NewByteArray(env, 33);
549                         (*env)->SetByteArrayRegion(env, per_commitment_point_arr, 0, 33, obj->dynamic_output_p2wsh.per_commitment_point.compressed_form);
550                         long output_ref = (long)&obj->dynamic_output_p2wsh.output;
551                         long key_derivation_params_ref = (long)&obj->dynamic_output_p2wsh.key_derivation_params;
552                         int8_tArray revocation_pubkey_arr = (*env)->NewByteArray(env, 33);
553                         (*env)->SetByteArrayRegion(env, revocation_pubkey_arr, 0, 33, obj->dynamic_output_p2wsh.revocation_pubkey.compressed_form);
554                         return (*env)->NewObject(env, LDKSpendableOutputDescriptor_DynamicOutputP2WSH_class, LDKSpendableOutputDescriptor_DynamicOutputP2WSH_meth, outpoint_ref, per_commitment_point_arr, obj->dynamic_output_p2wsh.to_self_delay, (long)output_ref, key_derivation_params_ref, revocation_pubkey_arr);
555                 }
556                 case LDKSpendableOutputDescriptor_StaticOutputCounterpartyPayment: {
557                         LDKOutPoint outpoint_var = obj->static_output_counterparty_payment.outpoint;
558                         CHECK((((long)outpoint_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
559                         CHECK((((long)&outpoint_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
560                         long outpoint_ref = (long)outpoint_var.inner & ~1;
561                         long output_ref = (long)&obj->static_output_counterparty_payment.output;
562                         long key_derivation_params_ref = (long)&obj->static_output_counterparty_payment.key_derivation_params;
563                         return (*env)->NewObject(env, LDKSpendableOutputDescriptor_StaticOutputCounterpartyPayment_class, LDKSpendableOutputDescriptor_StaticOutputCounterpartyPayment_meth, outpoint_ref, (long)output_ref, key_derivation_params_ref);
564                 }
565                 default: abort();
566         }
567 }
568 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCVec_1SpendableOutputDescriptorZ_1new(JNIEnv *env, jclass clz, int64_tArray elems) {
569         LDKCVec_SpendableOutputDescriptorZ *ret = MALLOC(sizeof(LDKCVec_SpendableOutputDescriptorZ), "LDKCVec_SpendableOutputDescriptorZ");
570         ret->datalen = (*env)->GetArrayLength(env, elems);
571         if (ret->datalen == 0) {
572                 ret->data = NULL;
573         } else {
574                 ret->data = MALLOC(sizeof(LDKSpendableOutputDescriptor) * ret->datalen, "LDKCVec_SpendableOutputDescriptorZ Data");
575                 int64_t *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
576                 for (size_t i = 0; i < ret->datalen; i++) {
577                         int64_t arr_elem = java_elems[i];
578                         LDKSpendableOutputDescriptor arr_elem_conv = *(LDKSpendableOutputDescriptor*)arr_elem;
579                         FREE((void*)arr_elem);
580                         ret->data[i] = arr_elem_conv;
581                 }
582                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
583         }
584         return (long)ret;
585 }
586 static inline LDKCVec_SpendableOutputDescriptorZ CVec_SpendableOutputDescriptorZ_clone(const LDKCVec_SpendableOutputDescriptorZ *orig) {
587         LDKCVec_SpendableOutputDescriptorZ ret = { .data = MALLOC(sizeof(LDKSpendableOutputDescriptor) * orig->datalen, "LDKCVec_SpendableOutputDescriptorZ clone bytes"), .datalen = orig->datalen };
588         for (size_t i = 0; i < ret.datalen; i++) {
589                 ret.data[i] = SpendableOutputDescriptor_clone(&orig->data[i]);
590         }
591         return ret;
592 }
593 static jclass LDKErrorAction_DisconnectPeer_class = NULL;
594 static jmethodID LDKErrorAction_DisconnectPeer_meth = NULL;
595 static jclass LDKErrorAction_IgnoreError_class = NULL;
596 static jmethodID LDKErrorAction_IgnoreError_meth = NULL;
597 static jclass LDKErrorAction_SendErrorMessage_class = NULL;
598 static jmethodID LDKErrorAction_SendErrorMessage_meth = NULL;
599 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_00024LDKErrorAction_init (JNIEnv *env, jclass clz) {
600         LDKErrorAction_DisconnectPeer_class =
601                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKErrorAction$DisconnectPeer;"));
602         CHECK(LDKErrorAction_DisconnectPeer_class != NULL);
603         LDKErrorAction_DisconnectPeer_meth = (*env)->GetMethodID(env, LDKErrorAction_DisconnectPeer_class, "<init>", "(J)V");
604         CHECK(LDKErrorAction_DisconnectPeer_meth != NULL);
605         LDKErrorAction_IgnoreError_class =
606                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKErrorAction$IgnoreError;"));
607         CHECK(LDKErrorAction_IgnoreError_class != NULL);
608         LDKErrorAction_IgnoreError_meth = (*env)->GetMethodID(env, LDKErrorAction_IgnoreError_class, "<init>", "()V");
609         CHECK(LDKErrorAction_IgnoreError_meth != NULL);
610         LDKErrorAction_SendErrorMessage_class =
611                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKErrorAction$SendErrorMessage;"));
612         CHECK(LDKErrorAction_SendErrorMessage_class != NULL);
613         LDKErrorAction_SendErrorMessage_meth = (*env)->GetMethodID(env, LDKErrorAction_SendErrorMessage_class, "<init>", "(J)V");
614         CHECK(LDKErrorAction_SendErrorMessage_meth != NULL);
615 }
616 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKErrorAction_1ref_1from_1ptr (JNIEnv *env, jclass clz, int64_t ptr) {
617         LDKErrorAction *obj = (LDKErrorAction*)ptr;
618         switch(obj->tag) {
619                 case LDKErrorAction_DisconnectPeer: {
620                         LDKErrorMessage msg_var = obj->disconnect_peer.msg;
621                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
622                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
623                         long msg_ref = (long)msg_var.inner & ~1;
624                         return (*env)->NewObject(env, LDKErrorAction_DisconnectPeer_class, LDKErrorAction_DisconnectPeer_meth, msg_ref);
625                 }
626                 case LDKErrorAction_IgnoreError: {
627                         return (*env)->NewObject(env, LDKErrorAction_IgnoreError_class, LDKErrorAction_IgnoreError_meth);
628                 }
629                 case LDKErrorAction_SendErrorMessage: {
630                         LDKErrorMessage msg_var = obj->send_error_message.msg;
631                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
632                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
633                         long msg_ref = (long)msg_var.inner & ~1;
634                         return (*env)->NewObject(env, LDKErrorAction_SendErrorMessage_class, LDKErrorAction_SendErrorMessage_meth, msg_ref);
635                 }
636                 default: abort();
637         }
638 }
639 static jclass LDKHTLCFailChannelUpdate_ChannelUpdateMessage_class = NULL;
640 static jmethodID LDKHTLCFailChannelUpdate_ChannelUpdateMessage_meth = NULL;
641 static jclass LDKHTLCFailChannelUpdate_ChannelClosed_class = NULL;
642 static jmethodID LDKHTLCFailChannelUpdate_ChannelClosed_meth = NULL;
643 static jclass LDKHTLCFailChannelUpdate_NodeFailure_class = NULL;
644 static jmethodID LDKHTLCFailChannelUpdate_NodeFailure_meth = NULL;
645 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_00024LDKHTLCFailChannelUpdate_init (JNIEnv *env, jclass clz) {
646         LDKHTLCFailChannelUpdate_ChannelUpdateMessage_class =
647                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKHTLCFailChannelUpdate$ChannelUpdateMessage;"));
648         CHECK(LDKHTLCFailChannelUpdate_ChannelUpdateMessage_class != NULL);
649         LDKHTLCFailChannelUpdate_ChannelUpdateMessage_meth = (*env)->GetMethodID(env, LDKHTLCFailChannelUpdate_ChannelUpdateMessage_class, "<init>", "(J)V");
650         CHECK(LDKHTLCFailChannelUpdate_ChannelUpdateMessage_meth != NULL);
651         LDKHTLCFailChannelUpdate_ChannelClosed_class =
652                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKHTLCFailChannelUpdate$ChannelClosed;"));
653         CHECK(LDKHTLCFailChannelUpdate_ChannelClosed_class != NULL);
654         LDKHTLCFailChannelUpdate_ChannelClosed_meth = (*env)->GetMethodID(env, LDKHTLCFailChannelUpdate_ChannelClosed_class, "<init>", "(JZ)V");
655         CHECK(LDKHTLCFailChannelUpdate_ChannelClosed_meth != NULL);
656         LDKHTLCFailChannelUpdate_NodeFailure_class =
657                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKHTLCFailChannelUpdate$NodeFailure;"));
658         CHECK(LDKHTLCFailChannelUpdate_NodeFailure_class != NULL);
659         LDKHTLCFailChannelUpdate_NodeFailure_meth = (*env)->GetMethodID(env, LDKHTLCFailChannelUpdate_NodeFailure_class, "<init>", "([BZ)V");
660         CHECK(LDKHTLCFailChannelUpdate_NodeFailure_meth != NULL);
661 }
662 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKHTLCFailChannelUpdate_1ref_1from_1ptr (JNIEnv *env, jclass clz, int64_t ptr) {
663         LDKHTLCFailChannelUpdate *obj = (LDKHTLCFailChannelUpdate*)ptr;
664         switch(obj->tag) {
665                 case LDKHTLCFailChannelUpdate_ChannelUpdateMessage: {
666                         LDKChannelUpdate msg_var = obj->channel_update_message.msg;
667                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
668                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
669                         long msg_ref = (long)msg_var.inner & ~1;
670                         return (*env)->NewObject(env, LDKHTLCFailChannelUpdate_ChannelUpdateMessage_class, LDKHTLCFailChannelUpdate_ChannelUpdateMessage_meth, msg_ref);
671                 }
672                 case LDKHTLCFailChannelUpdate_ChannelClosed: {
673                         return (*env)->NewObject(env, LDKHTLCFailChannelUpdate_ChannelClosed_class, LDKHTLCFailChannelUpdate_ChannelClosed_meth, obj->channel_closed.short_channel_id, obj->channel_closed.is_permanent);
674                 }
675                 case LDKHTLCFailChannelUpdate_NodeFailure: {
676                         int8_tArray node_id_arr = (*env)->NewByteArray(env, 33);
677                         (*env)->SetByteArrayRegion(env, node_id_arr, 0, 33, obj->node_failure.node_id.compressed_form);
678                         return (*env)->NewObject(env, LDKHTLCFailChannelUpdate_NodeFailure_class, LDKHTLCFailChannelUpdate_NodeFailure_meth, node_id_arr, obj->node_failure.is_permanent);
679                 }
680                 default: abort();
681         }
682 }
683 static jclass LDKMessageSendEvent_SendAcceptChannel_class = NULL;
684 static jmethodID LDKMessageSendEvent_SendAcceptChannel_meth = NULL;
685 static jclass LDKMessageSendEvent_SendOpenChannel_class = NULL;
686 static jmethodID LDKMessageSendEvent_SendOpenChannel_meth = NULL;
687 static jclass LDKMessageSendEvent_SendFundingCreated_class = NULL;
688 static jmethodID LDKMessageSendEvent_SendFundingCreated_meth = NULL;
689 static jclass LDKMessageSendEvent_SendFundingSigned_class = NULL;
690 static jmethodID LDKMessageSendEvent_SendFundingSigned_meth = NULL;
691 static jclass LDKMessageSendEvent_SendFundingLocked_class = NULL;
692 static jmethodID LDKMessageSendEvent_SendFundingLocked_meth = NULL;
693 static jclass LDKMessageSendEvent_SendAnnouncementSignatures_class = NULL;
694 static jmethodID LDKMessageSendEvent_SendAnnouncementSignatures_meth = NULL;
695 static jclass LDKMessageSendEvent_UpdateHTLCs_class = NULL;
696 static jmethodID LDKMessageSendEvent_UpdateHTLCs_meth = NULL;
697 static jclass LDKMessageSendEvent_SendRevokeAndACK_class = NULL;
698 static jmethodID LDKMessageSendEvent_SendRevokeAndACK_meth = NULL;
699 static jclass LDKMessageSendEvent_SendClosingSigned_class = NULL;
700 static jmethodID LDKMessageSendEvent_SendClosingSigned_meth = NULL;
701 static jclass LDKMessageSendEvent_SendShutdown_class = NULL;
702 static jmethodID LDKMessageSendEvent_SendShutdown_meth = NULL;
703 static jclass LDKMessageSendEvent_SendChannelReestablish_class = NULL;
704 static jmethodID LDKMessageSendEvent_SendChannelReestablish_meth = NULL;
705 static jclass LDKMessageSendEvent_BroadcastChannelAnnouncement_class = NULL;
706 static jmethodID LDKMessageSendEvent_BroadcastChannelAnnouncement_meth = NULL;
707 static jclass LDKMessageSendEvent_BroadcastNodeAnnouncement_class = NULL;
708 static jmethodID LDKMessageSendEvent_BroadcastNodeAnnouncement_meth = NULL;
709 static jclass LDKMessageSendEvent_BroadcastChannelUpdate_class = NULL;
710 static jmethodID LDKMessageSendEvent_BroadcastChannelUpdate_meth = NULL;
711 static jclass LDKMessageSendEvent_HandleError_class = NULL;
712 static jmethodID LDKMessageSendEvent_HandleError_meth = NULL;
713 static jclass LDKMessageSendEvent_PaymentFailureNetworkUpdate_class = NULL;
714 static jmethodID LDKMessageSendEvent_PaymentFailureNetworkUpdate_meth = NULL;
715 static jclass LDKMessageSendEvent_SendChannelRangeQuery_class = NULL;
716 static jmethodID LDKMessageSendEvent_SendChannelRangeQuery_meth = NULL;
717 static jclass LDKMessageSendEvent_SendShortIdsQuery_class = NULL;
718 static jmethodID LDKMessageSendEvent_SendShortIdsQuery_meth = NULL;
719 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_00024LDKMessageSendEvent_init (JNIEnv *env, jclass clz) {
720         LDKMessageSendEvent_SendAcceptChannel_class =
721                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKMessageSendEvent$SendAcceptChannel;"));
722         CHECK(LDKMessageSendEvent_SendAcceptChannel_class != NULL);
723         LDKMessageSendEvent_SendAcceptChannel_meth = (*env)->GetMethodID(env, LDKMessageSendEvent_SendAcceptChannel_class, "<init>", "([BJ)V");
724         CHECK(LDKMessageSendEvent_SendAcceptChannel_meth != NULL);
725         LDKMessageSendEvent_SendOpenChannel_class =
726                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKMessageSendEvent$SendOpenChannel;"));
727         CHECK(LDKMessageSendEvent_SendOpenChannel_class != NULL);
728         LDKMessageSendEvent_SendOpenChannel_meth = (*env)->GetMethodID(env, LDKMessageSendEvent_SendOpenChannel_class, "<init>", "([BJ)V");
729         CHECK(LDKMessageSendEvent_SendOpenChannel_meth != NULL);
730         LDKMessageSendEvent_SendFundingCreated_class =
731                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKMessageSendEvent$SendFundingCreated;"));
732         CHECK(LDKMessageSendEvent_SendFundingCreated_class != NULL);
733         LDKMessageSendEvent_SendFundingCreated_meth = (*env)->GetMethodID(env, LDKMessageSendEvent_SendFundingCreated_class, "<init>", "([BJ)V");
734         CHECK(LDKMessageSendEvent_SendFundingCreated_meth != NULL);
735         LDKMessageSendEvent_SendFundingSigned_class =
736                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKMessageSendEvent$SendFundingSigned;"));
737         CHECK(LDKMessageSendEvent_SendFundingSigned_class != NULL);
738         LDKMessageSendEvent_SendFundingSigned_meth = (*env)->GetMethodID(env, LDKMessageSendEvent_SendFundingSigned_class, "<init>", "([BJ)V");
739         CHECK(LDKMessageSendEvent_SendFundingSigned_meth != NULL);
740         LDKMessageSendEvent_SendFundingLocked_class =
741                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKMessageSendEvent$SendFundingLocked;"));
742         CHECK(LDKMessageSendEvent_SendFundingLocked_class != NULL);
743         LDKMessageSendEvent_SendFundingLocked_meth = (*env)->GetMethodID(env, LDKMessageSendEvent_SendFundingLocked_class, "<init>", "([BJ)V");
744         CHECK(LDKMessageSendEvent_SendFundingLocked_meth != NULL);
745         LDKMessageSendEvent_SendAnnouncementSignatures_class =
746                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKMessageSendEvent$SendAnnouncementSignatures;"));
747         CHECK(LDKMessageSendEvent_SendAnnouncementSignatures_class != NULL);
748         LDKMessageSendEvent_SendAnnouncementSignatures_meth = (*env)->GetMethodID(env, LDKMessageSendEvent_SendAnnouncementSignatures_class, "<init>", "([BJ)V");
749         CHECK(LDKMessageSendEvent_SendAnnouncementSignatures_meth != NULL);
750         LDKMessageSendEvent_UpdateHTLCs_class =
751                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKMessageSendEvent$UpdateHTLCs;"));
752         CHECK(LDKMessageSendEvent_UpdateHTLCs_class != NULL);
753         LDKMessageSendEvent_UpdateHTLCs_meth = (*env)->GetMethodID(env, LDKMessageSendEvent_UpdateHTLCs_class, "<init>", "([BJ)V");
754         CHECK(LDKMessageSendEvent_UpdateHTLCs_meth != NULL);
755         LDKMessageSendEvent_SendRevokeAndACK_class =
756                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKMessageSendEvent$SendRevokeAndACK;"));
757         CHECK(LDKMessageSendEvent_SendRevokeAndACK_class != NULL);
758         LDKMessageSendEvent_SendRevokeAndACK_meth = (*env)->GetMethodID(env, LDKMessageSendEvent_SendRevokeAndACK_class, "<init>", "([BJ)V");
759         CHECK(LDKMessageSendEvent_SendRevokeAndACK_meth != NULL);
760         LDKMessageSendEvent_SendClosingSigned_class =
761                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKMessageSendEvent$SendClosingSigned;"));
762         CHECK(LDKMessageSendEvent_SendClosingSigned_class != NULL);
763         LDKMessageSendEvent_SendClosingSigned_meth = (*env)->GetMethodID(env, LDKMessageSendEvent_SendClosingSigned_class, "<init>", "([BJ)V");
764         CHECK(LDKMessageSendEvent_SendClosingSigned_meth != NULL);
765         LDKMessageSendEvent_SendShutdown_class =
766                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKMessageSendEvent$SendShutdown;"));
767         CHECK(LDKMessageSendEvent_SendShutdown_class != NULL);
768         LDKMessageSendEvent_SendShutdown_meth = (*env)->GetMethodID(env, LDKMessageSendEvent_SendShutdown_class, "<init>", "([BJ)V");
769         CHECK(LDKMessageSendEvent_SendShutdown_meth != NULL);
770         LDKMessageSendEvent_SendChannelReestablish_class =
771                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKMessageSendEvent$SendChannelReestablish;"));
772         CHECK(LDKMessageSendEvent_SendChannelReestablish_class != NULL);
773         LDKMessageSendEvent_SendChannelReestablish_meth = (*env)->GetMethodID(env, LDKMessageSendEvent_SendChannelReestablish_class, "<init>", "([BJ)V");
774         CHECK(LDKMessageSendEvent_SendChannelReestablish_meth != NULL);
775         LDKMessageSendEvent_BroadcastChannelAnnouncement_class =
776                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKMessageSendEvent$BroadcastChannelAnnouncement;"));
777         CHECK(LDKMessageSendEvent_BroadcastChannelAnnouncement_class != NULL);
778         LDKMessageSendEvent_BroadcastChannelAnnouncement_meth = (*env)->GetMethodID(env, LDKMessageSendEvent_BroadcastChannelAnnouncement_class, "<init>", "(JJ)V");
779         CHECK(LDKMessageSendEvent_BroadcastChannelAnnouncement_meth != NULL);
780         LDKMessageSendEvent_BroadcastNodeAnnouncement_class =
781                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKMessageSendEvent$BroadcastNodeAnnouncement;"));
782         CHECK(LDKMessageSendEvent_BroadcastNodeAnnouncement_class != NULL);
783         LDKMessageSendEvent_BroadcastNodeAnnouncement_meth = (*env)->GetMethodID(env, LDKMessageSendEvent_BroadcastNodeAnnouncement_class, "<init>", "(J)V");
784         CHECK(LDKMessageSendEvent_BroadcastNodeAnnouncement_meth != NULL);
785         LDKMessageSendEvent_BroadcastChannelUpdate_class =
786                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKMessageSendEvent$BroadcastChannelUpdate;"));
787         CHECK(LDKMessageSendEvent_BroadcastChannelUpdate_class != NULL);
788         LDKMessageSendEvent_BroadcastChannelUpdate_meth = (*env)->GetMethodID(env, LDKMessageSendEvent_BroadcastChannelUpdate_class, "<init>", "(J)V");
789         CHECK(LDKMessageSendEvent_BroadcastChannelUpdate_meth != NULL);
790         LDKMessageSendEvent_HandleError_class =
791                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKMessageSendEvent$HandleError;"));
792         CHECK(LDKMessageSendEvent_HandleError_class != NULL);
793         LDKMessageSendEvent_HandleError_meth = (*env)->GetMethodID(env, LDKMessageSendEvent_HandleError_class, "<init>", "([BJ)V");
794         CHECK(LDKMessageSendEvent_HandleError_meth != NULL);
795         LDKMessageSendEvent_PaymentFailureNetworkUpdate_class =
796                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKMessageSendEvent$PaymentFailureNetworkUpdate;"));
797         CHECK(LDKMessageSendEvent_PaymentFailureNetworkUpdate_class != NULL);
798         LDKMessageSendEvent_PaymentFailureNetworkUpdate_meth = (*env)->GetMethodID(env, LDKMessageSendEvent_PaymentFailureNetworkUpdate_class, "<init>", "(J)V");
799         CHECK(LDKMessageSendEvent_PaymentFailureNetworkUpdate_meth != NULL);
800         LDKMessageSendEvent_SendChannelRangeQuery_class =
801                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKMessageSendEvent$SendChannelRangeQuery;"));
802         CHECK(LDKMessageSendEvent_SendChannelRangeQuery_class != NULL);
803         LDKMessageSendEvent_SendChannelRangeQuery_meth = (*env)->GetMethodID(env, LDKMessageSendEvent_SendChannelRangeQuery_class, "<init>", "([BJ)V");
804         CHECK(LDKMessageSendEvent_SendChannelRangeQuery_meth != NULL);
805         LDKMessageSendEvent_SendShortIdsQuery_class =
806                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKMessageSendEvent$SendShortIdsQuery;"));
807         CHECK(LDKMessageSendEvent_SendShortIdsQuery_class != NULL);
808         LDKMessageSendEvent_SendShortIdsQuery_meth = (*env)->GetMethodID(env, LDKMessageSendEvent_SendShortIdsQuery_class, "<init>", "([BJ)V");
809         CHECK(LDKMessageSendEvent_SendShortIdsQuery_meth != NULL);
810 }
811 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKMessageSendEvent_1ref_1from_1ptr (JNIEnv *env, jclass clz, int64_t ptr) {
812         LDKMessageSendEvent *obj = (LDKMessageSendEvent*)ptr;
813         switch(obj->tag) {
814                 case LDKMessageSendEvent_SendAcceptChannel: {
815                         int8_tArray node_id_arr = (*env)->NewByteArray(env, 33);
816                         (*env)->SetByteArrayRegion(env, node_id_arr, 0, 33, obj->send_accept_channel.node_id.compressed_form);
817                         LDKAcceptChannel msg_var = obj->send_accept_channel.msg;
818                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
819                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
820                         long msg_ref = (long)msg_var.inner & ~1;
821                         return (*env)->NewObject(env, LDKMessageSendEvent_SendAcceptChannel_class, LDKMessageSendEvent_SendAcceptChannel_meth, node_id_arr, msg_ref);
822                 }
823                 case LDKMessageSendEvent_SendOpenChannel: {
824                         int8_tArray node_id_arr = (*env)->NewByteArray(env, 33);
825                         (*env)->SetByteArrayRegion(env, node_id_arr, 0, 33, obj->send_open_channel.node_id.compressed_form);
826                         LDKOpenChannel msg_var = obj->send_open_channel.msg;
827                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
828                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
829                         long msg_ref = (long)msg_var.inner & ~1;
830                         return (*env)->NewObject(env, LDKMessageSendEvent_SendOpenChannel_class, LDKMessageSendEvent_SendOpenChannel_meth, node_id_arr, msg_ref);
831                 }
832                 case LDKMessageSendEvent_SendFundingCreated: {
833                         int8_tArray node_id_arr = (*env)->NewByteArray(env, 33);
834                         (*env)->SetByteArrayRegion(env, node_id_arr, 0, 33, obj->send_funding_created.node_id.compressed_form);
835                         LDKFundingCreated msg_var = obj->send_funding_created.msg;
836                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
837                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
838                         long msg_ref = (long)msg_var.inner & ~1;
839                         return (*env)->NewObject(env, LDKMessageSendEvent_SendFundingCreated_class, LDKMessageSendEvent_SendFundingCreated_meth, node_id_arr, msg_ref);
840                 }
841                 case LDKMessageSendEvent_SendFundingSigned: {
842                         int8_tArray node_id_arr = (*env)->NewByteArray(env, 33);
843                         (*env)->SetByteArrayRegion(env, node_id_arr, 0, 33, obj->send_funding_signed.node_id.compressed_form);
844                         LDKFundingSigned msg_var = obj->send_funding_signed.msg;
845                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
846                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
847                         long msg_ref = (long)msg_var.inner & ~1;
848                         return (*env)->NewObject(env, LDKMessageSendEvent_SendFundingSigned_class, LDKMessageSendEvent_SendFundingSigned_meth, node_id_arr, msg_ref);
849                 }
850                 case LDKMessageSendEvent_SendFundingLocked: {
851                         int8_tArray node_id_arr = (*env)->NewByteArray(env, 33);
852                         (*env)->SetByteArrayRegion(env, node_id_arr, 0, 33, obj->send_funding_locked.node_id.compressed_form);
853                         LDKFundingLocked msg_var = obj->send_funding_locked.msg;
854                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
855                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
856                         long msg_ref = (long)msg_var.inner & ~1;
857                         return (*env)->NewObject(env, LDKMessageSendEvent_SendFundingLocked_class, LDKMessageSendEvent_SendFundingLocked_meth, node_id_arr, msg_ref);
858                 }
859                 case LDKMessageSendEvent_SendAnnouncementSignatures: {
860                         int8_tArray node_id_arr = (*env)->NewByteArray(env, 33);
861                         (*env)->SetByteArrayRegion(env, node_id_arr, 0, 33, obj->send_announcement_signatures.node_id.compressed_form);
862                         LDKAnnouncementSignatures msg_var = obj->send_announcement_signatures.msg;
863                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
864                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
865                         long msg_ref = (long)msg_var.inner & ~1;
866                         return (*env)->NewObject(env, LDKMessageSendEvent_SendAnnouncementSignatures_class, LDKMessageSendEvent_SendAnnouncementSignatures_meth, node_id_arr, msg_ref);
867                 }
868                 case LDKMessageSendEvent_UpdateHTLCs: {
869                         int8_tArray node_id_arr = (*env)->NewByteArray(env, 33);
870                         (*env)->SetByteArrayRegion(env, node_id_arr, 0, 33, obj->update_htl_cs.node_id.compressed_form);
871                         LDKCommitmentUpdate updates_var = obj->update_htl_cs.updates;
872                         CHECK((((long)updates_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
873                         CHECK((((long)&updates_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
874                         long updates_ref = (long)updates_var.inner & ~1;
875                         return (*env)->NewObject(env, LDKMessageSendEvent_UpdateHTLCs_class, LDKMessageSendEvent_UpdateHTLCs_meth, node_id_arr, updates_ref);
876                 }
877                 case LDKMessageSendEvent_SendRevokeAndACK: {
878                         int8_tArray node_id_arr = (*env)->NewByteArray(env, 33);
879                         (*env)->SetByteArrayRegion(env, node_id_arr, 0, 33, obj->send_revoke_and_ack.node_id.compressed_form);
880                         LDKRevokeAndACK msg_var = obj->send_revoke_and_ack.msg;
881                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
882                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
883                         long msg_ref = (long)msg_var.inner & ~1;
884                         return (*env)->NewObject(env, LDKMessageSendEvent_SendRevokeAndACK_class, LDKMessageSendEvent_SendRevokeAndACK_meth, node_id_arr, msg_ref);
885                 }
886                 case LDKMessageSendEvent_SendClosingSigned: {
887                         int8_tArray node_id_arr = (*env)->NewByteArray(env, 33);
888                         (*env)->SetByteArrayRegion(env, node_id_arr, 0, 33, obj->send_closing_signed.node_id.compressed_form);
889                         LDKClosingSigned msg_var = obj->send_closing_signed.msg;
890                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
891                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
892                         long msg_ref = (long)msg_var.inner & ~1;
893                         return (*env)->NewObject(env, LDKMessageSendEvent_SendClosingSigned_class, LDKMessageSendEvent_SendClosingSigned_meth, node_id_arr, msg_ref);
894                 }
895                 case LDKMessageSendEvent_SendShutdown: {
896                         int8_tArray node_id_arr = (*env)->NewByteArray(env, 33);
897                         (*env)->SetByteArrayRegion(env, node_id_arr, 0, 33, obj->send_shutdown.node_id.compressed_form);
898                         LDKShutdown msg_var = obj->send_shutdown.msg;
899                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
900                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
901                         long msg_ref = (long)msg_var.inner & ~1;
902                         return (*env)->NewObject(env, LDKMessageSendEvent_SendShutdown_class, LDKMessageSendEvent_SendShutdown_meth, node_id_arr, msg_ref);
903                 }
904                 case LDKMessageSendEvent_SendChannelReestablish: {
905                         int8_tArray node_id_arr = (*env)->NewByteArray(env, 33);
906                         (*env)->SetByteArrayRegion(env, node_id_arr, 0, 33, obj->send_channel_reestablish.node_id.compressed_form);
907                         LDKChannelReestablish msg_var = obj->send_channel_reestablish.msg;
908                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
909                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
910                         long msg_ref = (long)msg_var.inner & ~1;
911                         return (*env)->NewObject(env, LDKMessageSendEvent_SendChannelReestablish_class, LDKMessageSendEvent_SendChannelReestablish_meth, node_id_arr, msg_ref);
912                 }
913                 case LDKMessageSendEvent_BroadcastChannelAnnouncement: {
914                         LDKChannelAnnouncement msg_var = obj->broadcast_channel_announcement.msg;
915                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
916                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
917                         long msg_ref = (long)msg_var.inner & ~1;
918                         LDKChannelUpdate update_msg_var = obj->broadcast_channel_announcement.update_msg;
919                         CHECK((((long)update_msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
920                         CHECK((((long)&update_msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
921                         long update_msg_ref = (long)update_msg_var.inner & ~1;
922                         return (*env)->NewObject(env, LDKMessageSendEvent_BroadcastChannelAnnouncement_class, LDKMessageSendEvent_BroadcastChannelAnnouncement_meth, msg_ref, update_msg_ref);
923                 }
924                 case LDKMessageSendEvent_BroadcastNodeAnnouncement: {
925                         LDKNodeAnnouncement msg_var = obj->broadcast_node_announcement.msg;
926                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
927                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
928                         long msg_ref = (long)msg_var.inner & ~1;
929                         return (*env)->NewObject(env, LDKMessageSendEvent_BroadcastNodeAnnouncement_class, LDKMessageSendEvent_BroadcastNodeAnnouncement_meth, msg_ref);
930                 }
931                 case LDKMessageSendEvent_BroadcastChannelUpdate: {
932                         LDKChannelUpdate msg_var = obj->broadcast_channel_update.msg;
933                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
934                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
935                         long msg_ref = (long)msg_var.inner & ~1;
936                         return (*env)->NewObject(env, LDKMessageSendEvent_BroadcastChannelUpdate_class, LDKMessageSendEvent_BroadcastChannelUpdate_meth, msg_ref);
937                 }
938                 case LDKMessageSendEvent_HandleError: {
939                         int8_tArray node_id_arr = (*env)->NewByteArray(env, 33);
940                         (*env)->SetByteArrayRegion(env, node_id_arr, 0, 33, obj->handle_error.node_id.compressed_form);
941                         long action_ref = (long)&obj->handle_error.action;
942                         return (*env)->NewObject(env, LDKMessageSendEvent_HandleError_class, LDKMessageSendEvent_HandleError_meth, node_id_arr, action_ref);
943                 }
944                 case LDKMessageSendEvent_PaymentFailureNetworkUpdate: {
945                         long update_ref = (long)&obj->payment_failure_network_update.update;
946                         return (*env)->NewObject(env, LDKMessageSendEvent_PaymentFailureNetworkUpdate_class, LDKMessageSendEvent_PaymentFailureNetworkUpdate_meth, update_ref);
947                 }
948                 case LDKMessageSendEvent_SendChannelRangeQuery: {
949                         int8_tArray node_id_arr = (*env)->NewByteArray(env, 33);
950                         (*env)->SetByteArrayRegion(env, node_id_arr, 0, 33, obj->send_channel_range_query.node_id.compressed_form);
951                         LDKQueryChannelRange msg_var = obj->send_channel_range_query.msg;
952                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
953                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
954                         long msg_ref = (long)msg_var.inner & ~1;
955                         return (*env)->NewObject(env, LDKMessageSendEvent_SendChannelRangeQuery_class, LDKMessageSendEvent_SendChannelRangeQuery_meth, node_id_arr, msg_ref);
956                 }
957                 case LDKMessageSendEvent_SendShortIdsQuery: {
958                         int8_tArray node_id_arr = (*env)->NewByteArray(env, 33);
959                         (*env)->SetByteArrayRegion(env, node_id_arr, 0, 33, obj->send_short_ids_query.node_id.compressed_form);
960                         LDKQueryShortChannelIds msg_var = obj->send_short_ids_query.msg;
961                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
962                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
963                         long msg_ref = (long)msg_var.inner & ~1;
964                         return (*env)->NewObject(env, LDKMessageSendEvent_SendShortIdsQuery_class, LDKMessageSendEvent_SendShortIdsQuery_meth, node_id_arr, msg_ref);
965                 }
966                 default: abort();
967         }
968 }
969 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCVec_1MessageSendEventZ_1new(JNIEnv *env, jclass clz, int64_tArray elems) {
970         LDKCVec_MessageSendEventZ *ret = MALLOC(sizeof(LDKCVec_MessageSendEventZ), "LDKCVec_MessageSendEventZ");
971         ret->datalen = (*env)->GetArrayLength(env, elems);
972         if (ret->datalen == 0) {
973                 ret->data = NULL;
974         } else {
975                 ret->data = MALLOC(sizeof(LDKMessageSendEvent) * ret->datalen, "LDKCVec_MessageSendEventZ Data");
976                 int64_t *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
977                 for (size_t i = 0; i < ret->datalen; i++) {
978                         int64_t arr_elem = java_elems[i];
979                         LDKMessageSendEvent arr_elem_conv = *(LDKMessageSendEvent*)arr_elem;
980                         FREE((void*)arr_elem);
981                         ret->data[i] = arr_elem_conv;
982                 }
983                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
984         }
985         return (long)ret;
986 }
987 static inline LDKCVec_MessageSendEventZ CVec_MessageSendEventZ_clone(const LDKCVec_MessageSendEventZ *orig) {
988         LDKCVec_MessageSendEventZ ret = { .data = MALLOC(sizeof(LDKMessageSendEvent) * orig->datalen, "LDKCVec_MessageSendEventZ clone bytes"), .datalen = orig->datalen };
989         for (size_t i = 0; i < ret.datalen; i++) {
990                 ret.data[i] = MessageSendEvent_clone(&orig->data[i]);
991         }
992         return ret;
993 }
994 static jclass LDKEvent_FundingGenerationReady_class = NULL;
995 static jmethodID LDKEvent_FundingGenerationReady_meth = NULL;
996 static jclass LDKEvent_FundingBroadcastSafe_class = NULL;
997 static jmethodID LDKEvent_FundingBroadcastSafe_meth = NULL;
998 static jclass LDKEvent_PaymentReceived_class = NULL;
999 static jmethodID LDKEvent_PaymentReceived_meth = NULL;
1000 static jclass LDKEvent_PaymentSent_class = NULL;
1001 static jmethodID LDKEvent_PaymentSent_meth = NULL;
1002 static jclass LDKEvent_PaymentFailed_class = NULL;
1003 static jmethodID LDKEvent_PaymentFailed_meth = NULL;
1004 static jclass LDKEvent_PendingHTLCsForwardable_class = NULL;
1005 static jmethodID LDKEvent_PendingHTLCsForwardable_meth = NULL;
1006 static jclass LDKEvent_SpendableOutputs_class = NULL;
1007 static jmethodID LDKEvent_SpendableOutputs_meth = NULL;
1008 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_00024LDKEvent_init (JNIEnv *env, jclass clz) {
1009         LDKEvent_FundingGenerationReady_class =
1010                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKEvent$FundingGenerationReady;"));
1011         CHECK(LDKEvent_FundingGenerationReady_class != NULL);
1012         LDKEvent_FundingGenerationReady_meth = (*env)->GetMethodID(env, LDKEvent_FundingGenerationReady_class, "<init>", "([BJ[BJ)V");
1013         CHECK(LDKEvent_FundingGenerationReady_meth != NULL);
1014         LDKEvent_FundingBroadcastSafe_class =
1015                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKEvent$FundingBroadcastSafe;"));
1016         CHECK(LDKEvent_FundingBroadcastSafe_class != NULL);
1017         LDKEvent_FundingBroadcastSafe_meth = (*env)->GetMethodID(env, LDKEvent_FundingBroadcastSafe_class, "<init>", "(JJ)V");
1018         CHECK(LDKEvent_FundingBroadcastSafe_meth != NULL);
1019         LDKEvent_PaymentReceived_class =
1020                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKEvent$PaymentReceived;"));
1021         CHECK(LDKEvent_PaymentReceived_class != NULL);
1022         LDKEvent_PaymentReceived_meth = (*env)->GetMethodID(env, LDKEvent_PaymentReceived_class, "<init>", "([B[BJ)V");
1023         CHECK(LDKEvent_PaymentReceived_meth != NULL);
1024         LDKEvent_PaymentSent_class =
1025                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKEvent$PaymentSent;"));
1026         CHECK(LDKEvent_PaymentSent_class != NULL);
1027         LDKEvent_PaymentSent_meth = (*env)->GetMethodID(env, LDKEvent_PaymentSent_class, "<init>", "([B)V");
1028         CHECK(LDKEvent_PaymentSent_meth != NULL);
1029         LDKEvent_PaymentFailed_class =
1030                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKEvent$PaymentFailed;"));
1031         CHECK(LDKEvent_PaymentFailed_class != NULL);
1032         LDKEvent_PaymentFailed_meth = (*env)->GetMethodID(env, LDKEvent_PaymentFailed_class, "<init>", "([BZ)V");
1033         CHECK(LDKEvent_PaymentFailed_meth != NULL);
1034         LDKEvent_PendingHTLCsForwardable_class =
1035                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKEvent$PendingHTLCsForwardable;"));
1036         CHECK(LDKEvent_PendingHTLCsForwardable_class != NULL);
1037         LDKEvent_PendingHTLCsForwardable_meth = (*env)->GetMethodID(env, LDKEvent_PendingHTLCsForwardable_class, "<init>", "(J)V");
1038         CHECK(LDKEvent_PendingHTLCsForwardable_meth != NULL);
1039         LDKEvent_SpendableOutputs_class =
1040                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKEvent$SpendableOutputs;"));
1041         CHECK(LDKEvent_SpendableOutputs_class != NULL);
1042         LDKEvent_SpendableOutputs_meth = (*env)->GetMethodID(env, LDKEvent_SpendableOutputs_class, "<init>", "([J)V");
1043         CHECK(LDKEvent_SpendableOutputs_meth != NULL);
1044 }
1045 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKEvent_1ref_1from_1ptr (JNIEnv *env, jclass clz, int64_t ptr) {
1046         LDKEvent *obj = (LDKEvent*)ptr;
1047         switch(obj->tag) {
1048                 case LDKEvent_FundingGenerationReady: {
1049                         int8_tArray temporary_channel_id_arr = (*env)->NewByteArray(env, 32);
1050                         (*env)->SetByteArrayRegion(env, temporary_channel_id_arr, 0, 32, obj->funding_generation_ready.temporary_channel_id.data);
1051                         LDKCVec_u8Z output_script_var = obj->funding_generation_ready.output_script;
1052                         int8_tArray output_script_arr = (*env)->NewByteArray(env, output_script_var.datalen);
1053                         (*env)->SetByteArrayRegion(env, output_script_arr, 0, output_script_var.datalen, output_script_var.data);
1054                         return (*env)->NewObject(env, LDKEvent_FundingGenerationReady_class, LDKEvent_FundingGenerationReady_meth, temporary_channel_id_arr, obj->funding_generation_ready.channel_value_satoshis, output_script_arr, obj->funding_generation_ready.user_channel_id);
1055                 }
1056                 case LDKEvent_FundingBroadcastSafe: {
1057                         LDKOutPoint funding_txo_var = obj->funding_broadcast_safe.funding_txo;
1058                         CHECK((((long)funding_txo_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1059                         CHECK((((long)&funding_txo_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1060                         long funding_txo_ref = (long)funding_txo_var.inner & ~1;
1061                         return (*env)->NewObject(env, LDKEvent_FundingBroadcastSafe_class, LDKEvent_FundingBroadcastSafe_meth, funding_txo_ref, obj->funding_broadcast_safe.user_channel_id);
1062                 }
1063                 case LDKEvent_PaymentReceived: {
1064                         int8_tArray payment_hash_arr = (*env)->NewByteArray(env, 32);
1065                         (*env)->SetByteArrayRegion(env, payment_hash_arr, 0, 32, obj->payment_received.payment_hash.data);
1066                         int8_tArray payment_secret_arr = (*env)->NewByteArray(env, 32);
1067                         (*env)->SetByteArrayRegion(env, payment_secret_arr, 0, 32, obj->payment_received.payment_secret.data);
1068                         return (*env)->NewObject(env, LDKEvent_PaymentReceived_class, LDKEvent_PaymentReceived_meth, payment_hash_arr, payment_secret_arr, obj->payment_received.amt);
1069                 }
1070                 case LDKEvent_PaymentSent: {
1071                         int8_tArray payment_preimage_arr = (*env)->NewByteArray(env, 32);
1072                         (*env)->SetByteArrayRegion(env, payment_preimage_arr, 0, 32, obj->payment_sent.payment_preimage.data);
1073                         return (*env)->NewObject(env, LDKEvent_PaymentSent_class, LDKEvent_PaymentSent_meth, payment_preimage_arr);
1074                 }
1075                 case LDKEvent_PaymentFailed: {
1076                         int8_tArray payment_hash_arr = (*env)->NewByteArray(env, 32);
1077                         (*env)->SetByteArrayRegion(env, payment_hash_arr, 0, 32, obj->payment_failed.payment_hash.data);
1078                         return (*env)->NewObject(env, LDKEvent_PaymentFailed_class, LDKEvent_PaymentFailed_meth, payment_hash_arr, obj->payment_failed.rejected_by_dest);
1079                 }
1080                 case LDKEvent_PendingHTLCsForwardable: {
1081                         return (*env)->NewObject(env, LDKEvent_PendingHTLCsForwardable_class, LDKEvent_PendingHTLCsForwardable_meth, obj->pending_htl_cs_forwardable.time_forwardable);
1082                 }
1083                 case LDKEvent_SpendableOutputs: {
1084                         LDKCVec_SpendableOutputDescriptorZ outputs_var = obj->spendable_outputs.outputs;
1085                         int64_tArray outputs_arr = (*env)->NewLongArray(env, outputs_var.datalen);
1086                         int64_t *outputs_arr_ptr = (*env)->GetPrimitiveArrayCritical(env, outputs_arr, NULL);
1087                         for (size_t b = 0; b < outputs_var.datalen; b++) {
1088                                 long arr_conv_27_ref = (long)&outputs_var.data[b];
1089                                 outputs_arr_ptr[b] = arr_conv_27_ref;
1090                         }
1091                         (*env)->ReleasePrimitiveArrayCritical(env, outputs_arr, outputs_arr_ptr, 0);
1092                         return (*env)->NewObject(env, LDKEvent_SpendableOutputs_class, LDKEvent_SpendableOutputs_meth, outputs_arr);
1093                 }
1094                 default: abort();
1095         }
1096 }
1097 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCVec_1EventZ_1new(JNIEnv *env, jclass clz, int64_tArray elems) {
1098         LDKCVec_EventZ *ret = MALLOC(sizeof(LDKCVec_EventZ), "LDKCVec_EventZ");
1099         ret->datalen = (*env)->GetArrayLength(env, elems);
1100         if (ret->datalen == 0) {
1101                 ret->data = NULL;
1102         } else {
1103                 ret->data = MALLOC(sizeof(LDKEvent) * ret->datalen, "LDKCVec_EventZ Data");
1104                 int64_t *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
1105                 for (size_t i = 0; i < ret->datalen; i++) {
1106                         int64_t arr_elem = java_elems[i];
1107                         LDKEvent arr_elem_conv = *(LDKEvent*)arr_elem;
1108                         FREE((void*)arr_elem);
1109                         ret->data[i] = arr_elem_conv;
1110                 }
1111                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
1112         }
1113         return (long)ret;
1114 }
1115 static inline LDKCVec_EventZ CVec_EventZ_clone(const LDKCVec_EventZ *orig) {
1116         LDKCVec_EventZ ret = { .data = MALLOC(sizeof(LDKEvent) * orig->datalen, "LDKCVec_EventZ clone bytes"), .datalen = orig->datalen };
1117         for (size_t i = 0; i < ret.datalen; i++) {
1118                 ret.data[i] = Event_clone(&orig->data[i]);
1119         }
1120         return ret;
1121 }
1122 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKC2Tuple_1usizeTransactionZ_1new(JNIEnv *env, jclass clz, intptr_t a, int8_tArray b) {
1123         LDKC2Tuple_usizeTransactionZ* ret = MALLOC(sizeof(LDKC2Tuple_usizeTransactionZ), "LDKC2Tuple_usizeTransactionZ");
1124         ret->a = a;
1125         LDKTransaction b_ref;
1126         b_ref.datalen = (*env)->GetArrayLength(env, b);
1127         b_ref.data = MALLOC(b_ref.datalen, "LDKTransaction Bytes");
1128         (*env)->GetByteArrayRegion(env, b, 0, b_ref.datalen, b_ref.data);
1129         b_ref.data_is_owned = false;
1130         ret->b = b_ref;
1131         return (long)ret;
1132 }
1133 JNIEXPORT intptr_t JNICALL Java_org_ldk_impl_bindings_LDKC2Tuple_1usizeTransactionZ_1get_1a(JNIEnv *env, jclass clz, int64_t ptr) {
1134         LDKC2Tuple_usizeTransactionZ *tuple = (LDKC2Tuple_usizeTransactionZ*)ptr;
1135         return tuple->a;
1136 }
1137 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_LDKC2Tuple_1usizeTransactionZ_1get_1b(JNIEnv *env, jclass clz, int64_t ptr) {
1138         LDKC2Tuple_usizeTransactionZ *tuple = (LDKC2Tuple_usizeTransactionZ*)ptr;
1139         LDKTransaction b_var = tuple->b;
1140         int8_tArray b_arr = (*env)->NewByteArray(env, b_var.datalen);
1141         (*env)->SetByteArrayRegion(env, b_arr, 0, b_var.datalen, b_var.data);
1142         return b_arr;
1143 }
1144 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCVec_1C2Tuple_1usizeTransactionZZ_1new(JNIEnv *env, jclass clz, int64_tArray elems) {
1145         LDKCVec_C2Tuple_usizeTransactionZZ *ret = MALLOC(sizeof(LDKCVec_C2Tuple_usizeTransactionZZ), "LDKCVec_C2Tuple_usizeTransactionZZ");
1146         ret->datalen = (*env)->GetArrayLength(env, elems);
1147         if (ret->datalen == 0) {
1148                 ret->data = NULL;
1149         } else {
1150                 ret->data = MALLOC(sizeof(LDKC2Tuple_usizeTransactionZ) * ret->datalen, "LDKCVec_C2Tuple_usizeTransactionZZ Data");
1151                 int64_t *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
1152                 for (size_t i = 0; i < ret->datalen; i++) {
1153                         int64_t arr_elem = java_elems[i];
1154                         LDKC2Tuple_usizeTransactionZ arr_elem_conv = *(LDKC2Tuple_usizeTransactionZ*)arr_elem;
1155                         FREE((void*)arr_elem);
1156                         ret->data[i] = arr_elem_conv;
1157                 }
1158                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
1159         }
1160         return (long)ret;
1161 }
1162 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NoneChannelMonitorUpdateErrZ_1result_1ok (JNIEnv *env, jclass clz, int64_t arg) {
1163         return ((LDKCResult_NoneChannelMonitorUpdateErrZ*)arg)->result_ok;
1164 }
1165 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NoneChannelMonitorUpdateErrZ_1get_1ok (JNIEnv *env, jclass clz, int64_t arg) {
1166         LDKCResult_NoneChannelMonitorUpdateErrZ *val = (LDKCResult_NoneChannelMonitorUpdateErrZ*)arg;
1167         CHECK(val->result_ok);
1168         return *val->contents.result;
1169 }
1170 JNIEXPORT jclass JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NoneChannelMonitorUpdateErrZ_1get_1err (JNIEnv *env, jclass clz, int64_t arg) {
1171         LDKCResult_NoneChannelMonitorUpdateErrZ *val = (LDKCResult_NoneChannelMonitorUpdateErrZ*)arg;
1172         CHECK(!val->result_ok);
1173         jclass err_conv = LDKChannelMonitorUpdateErr_to_java(env, (*val->contents.err));
1174         return err_conv;
1175 }
1176 static inline LDKCResult_NoneChannelMonitorUpdateErrZ CResult_NoneChannelMonitorUpdateErrZ_clone(const LDKCResult_NoneChannelMonitorUpdateErrZ *orig) {
1177         LDKCResult_NoneChannelMonitorUpdateErrZ res = { .result_ok = orig->result_ok };
1178         if (orig->result_ok) {
1179                 res.contents.result = NULL;
1180         } else {
1181                 LDKChannelMonitorUpdateErr* contents = MALLOC(sizeof(LDKChannelMonitorUpdateErr), "LDKChannelMonitorUpdateErr result Err clone");
1182                 *contents = ChannelMonitorUpdateErr_clone(orig->contents.err);
1183                 res.contents.err = contents;
1184         }
1185         return res;
1186 }
1187 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCVec_1MonitorEventZ_1new(JNIEnv *env, jclass clz, int64_tArray elems) {
1188         LDKCVec_MonitorEventZ *ret = MALLOC(sizeof(LDKCVec_MonitorEventZ), "LDKCVec_MonitorEventZ");
1189         ret->datalen = (*env)->GetArrayLength(env, elems);
1190         if (ret->datalen == 0) {
1191                 ret->data = NULL;
1192         } else {
1193                 ret->data = MALLOC(sizeof(LDKMonitorEvent) * ret->datalen, "LDKCVec_MonitorEventZ Data");
1194                 int64_t *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
1195                 for (size_t i = 0; i < ret->datalen; i++) {
1196                         int64_t arr_elem = java_elems[i];
1197                         LDKMonitorEvent arr_elem_conv;
1198                         arr_elem_conv.inner = (void*)(arr_elem & (~1));
1199                         arr_elem_conv.is_owned = (arr_elem & 1) || (arr_elem == 0);
1200                         if (arr_elem_conv.inner != NULL)
1201                                 arr_elem_conv = MonitorEvent_clone(&arr_elem_conv);
1202                         ret->data[i] = arr_elem_conv;
1203                 }
1204                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
1205         }
1206         return (long)ret;
1207 }
1208 static inline LDKCVec_MonitorEventZ CVec_MonitorEventZ_clone(const LDKCVec_MonitorEventZ *orig) {
1209         LDKCVec_MonitorEventZ ret = { .data = MALLOC(sizeof(LDKMonitorEvent) * orig->datalen, "LDKCVec_MonitorEventZ clone bytes"), .datalen = orig->datalen };
1210         for (size_t i = 0; i < ret.datalen; i++) {
1211                 ret.data[i] = MonitorEvent_clone(&orig->data[i]);
1212         }
1213         return ret;
1214 }
1215 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1ChannelMonitorUpdateDecodeErrorZ_1result_1ok (JNIEnv *env, jclass clz, int64_t arg) {
1216         return ((LDKCResult_ChannelMonitorUpdateDecodeErrorZ*)arg)->result_ok;
1217 }
1218 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1ChannelMonitorUpdateDecodeErrorZ_1get_1ok (JNIEnv *env, jclass clz, int64_t arg) {
1219         LDKCResult_ChannelMonitorUpdateDecodeErrorZ *val = (LDKCResult_ChannelMonitorUpdateDecodeErrorZ*)arg;
1220         CHECK(val->result_ok);
1221         LDKChannelMonitorUpdate res_var = (*val->contents.result);
1222         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1223         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1224         long res_ref = (long)res_var.inner & ~1;
1225         return res_ref;
1226 }
1227 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1ChannelMonitorUpdateDecodeErrorZ_1get_1err (JNIEnv *env, jclass clz, int64_t arg) {
1228         LDKCResult_ChannelMonitorUpdateDecodeErrorZ *val = (LDKCResult_ChannelMonitorUpdateDecodeErrorZ*)arg;
1229         CHECK(!val->result_ok);
1230         LDKDecodeError err_var = (*val->contents.err);
1231         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1232         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1233         long err_ref = (long)err_var.inner & ~1;
1234         return err_ref;
1235 }
1236 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NoneMonitorUpdateErrorZ_1result_1ok (JNIEnv *env, jclass clz, int64_t arg) {
1237         return ((LDKCResult_NoneMonitorUpdateErrorZ*)arg)->result_ok;
1238 }
1239 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NoneMonitorUpdateErrorZ_1get_1ok (JNIEnv *env, jclass clz, int64_t arg) {
1240         LDKCResult_NoneMonitorUpdateErrorZ *val = (LDKCResult_NoneMonitorUpdateErrorZ*)arg;
1241         CHECK(val->result_ok);
1242         return *val->contents.result;
1243 }
1244 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NoneMonitorUpdateErrorZ_1get_1err (JNIEnv *env, jclass clz, int64_t arg) {
1245         LDKCResult_NoneMonitorUpdateErrorZ *val = (LDKCResult_NoneMonitorUpdateErrorZ*)arg;
1246         CHECK(!val->result_ok);
1247         LDKMonitorUpdateError err_var = (*val->contents.err);
1248         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1249         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1250         long err_ref = (long)err_var.inner & ~1;
1251         return err_ref;
1252 }
1253 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKC2Tuple_1OutPointScriptZ_1new(JNIEnv *env, jclass clz, int64_t a, int8_tArray b) {
1254         LDKC2Tuple_OutPointScriptZ* ret = MALLOC(sizeof(LDKC2Tuple_OutPointScriptZ), "LDKC2Tuple_OutPointScriptZ");
1255         LDKOutPoint a_conv;
1256         a_conv.inner = (void*)(a & (~1));
1257         a_conv.is_owned = (a & 1) || (a == 0);
1258         if (a_conv.inner != NULL)
1259                 a_conv = OutPoint_clone(&a_conv);
1260         ret->a = a_conv;
1261         LDKCVec_u8Z b_ref;
1262         b_ref.datalen = (*env)->GetArrayLength(env, b);
1263         b_ref.data = MALLOC(b_ref.datalen, "LDKCVec_u8Z Bytes");
1264         (*env)->GetByteArrayRegion(env, b, 0, b_ref.datalen, b_ref.data);
1265         ret->b = b_ref;
1266         return (long)ret;
1267 }
1268 static inline LDKC2Tuple_OutPointScriptZ C2Tuple_OutPointScriptZ_clone(const LDKC2Tuple_OutPointScriptZ *orig) {
1269         LDKC2Tuple_OutPointScriptZ ret = {
1270                 .a = OutPoint_clone(&orig->a),
1271                 .b = CVec_u8Z_clone(&orig->b),
1272         };
1273         return ret;
1274 }
1275 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKC2Tuple_1OutPointScriptZ_1get_1a(JNIEnv *env, jclass clz, int64_t ptr) {
1276         LDKC2Tuple_OutPointScriptZ *tuple = (LDKC2Tuple_OutPointScriptZ*)ptr;
1277         LDKOutPoint a_var = tuple->a;
1278         CHECK((((long)a_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1279         CHECK((((long)&a_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1280         long a_ref = (long)a_var.inner & ~1;
1281         return a_ref;
1282 }
1283 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_LDKC2Tuple_1OutPointScriptZ_1get_1b(JNIEnv *env, jclass clz, int64_t ptr) {
1284         LDKC2Tuple_OutPointScriptZ *tuple = (LDKC2Tuple_OutPointScriptZ*)ptr;
1285         LDKCVec_u8Z b_var = tuple->b;
1286         int8_tArray b_arr = (*env)->NewByteArray(env, b_var.datalen);
1287         (*env)->SetByteArrayRegion(env, b_arr, 0, b_var.datalen, b_var.data);
1288         return b_arr;
1289 }
1290 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKC2Tuple_1u32TxOutZ_1new(JNIEnv *env, jclass clz, int32_t a, int64_t b) {
1291         LDKC2Tuple_u32TxOutZ* ret = MALLOC(sizeof(LDKC2Tuple_u32TxOutZ), "LDKC2Tuple_u32TxOutZ");
1292         ret->a = a;
1293         LDKTxOut b_conv = *(LDKTxOut*)b;
1294         FREE((void*)b);
1295         ret->b = b_conv;
1296         return (long)ret;
1297 }
1298 JNIEXPORT int32_t JNICALL Java_org_ldk_impl_bindings_LDKC2Tuple_1u32TxOutZ_1get_1a(JNIEnv *env, jclass clz, int64_t ptr) {
1299         LDKC2Tuple_u32TxOutZ *tuple = (LDKC2Tuple_u32TxOutZ*)ptr;
1300         return tuple->a;
1301 }
1302 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKC2Tuple_1u32TxOutZ_1get_1b(JNIEnv *env, jclass clz, int64_t ptr) {
1303         LDKC2Tuple_u32TxOutZ *tuple = (LDKC2Tuple_u32TxOutZ*)ptr;
1304         long b_ref = (long)&tuple->b;
1305         return (long)b_ref;
1306 }
1307 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCVec_1C2Tuple_1u32TxOutZZ_1new(JNIEnv *env, jclass clz, int64_tArray elems) {
1308         LDKCVec_C2Tuple_u32TxOutZZ *ret = MALLOC(sizeof(LDKCVec_C2Tuple_u32TxOutZZ), "LDKCVec_C2Tuple_u32TxOutZZ");
1309         ret->datalen = (*env)->GetArrayLength(env, elems);
1310         if (ret->datalen == 0) {
1311                 ret->data = NULL;
1312         } else {
1313                 ret->data = MALLOC(sizeof(LDKC2Tuple_u32TxOutZ) * ret->datalen, "LDKCVec_C2Tuple_u32TxOutZZ Data");
1314                 int64_t *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
1315                 for (size_t i = 0; i < ret->datalen; i++) {
1316                         int64_t arr_elem = java_elems[i];
1317                         LDKC2Tuple_u32TxOutZ arr_elem_conv = *(LDKC2Tuple_u32TxOutZ*)arr_elem;
1318                         FREE((void*)arr_elem);
1319                         ret->data[i] = arr_elem_conv;
1320                 }
1321                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
1322         }
1323         return (long)ret;
1324 }
1325 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKC2Tuple_1TxidCVec_1C2Tuple_1u32TxOutZZZ_1new(JNIEnv *env, jclass clz, int8_tArray a, int64_tArray b) {
1326         LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ* ret = MALLOC(sizeof(LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ), "LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ");
1327         LDKThirtyTwoBytes a_ref;
1328         CHECK((*env)->GetArrayLength(env, a) == 32);
1329         (*env)->GetByteArrayRegion(env, a, 0, 32, a_ref.data);
1330         ret->a = a_ref;
1331         LDKCVec_C2Tuple_u32TxOutZZ b_constr;
1332         b_constr.datalen = (*env)->GetArrayLength(env, b);
1333         if (b_constr.datalen > 0)
1334                 b_constr.data = MALLOC(b_constr.datalen * sizeof(LDKC2Tuple_u32TxOutZ), "LDKCVec_C2Tuple_u32TxOutZZ Elements");
1335         else
1336                 b_constr.data = NULL;
1337         int64_t* b_vals = (*env)->GetLongArrayElements (env, b, NULL);
1338         for (size_t a = 0; a < b_constr.datalen; a++) {
1339                 int64_t arr_conv_26 = b_vals[a];
1340                 LDKC2Tuple_u32TxOutZ arr_conv_26_conv = *(LDKC2Tuple_u32TxOutZ*)arr_conv_26;
1341                 FREE((void*)arr_conv_26);
1342                 b_constr.data[a] = arr_conv_26_conv;
1343         }
1344         (*env)->ReleaseLongArrayElements(env, b, b_vals, 0);
1345         ret->b = b_constr;
1346         return (long)ret;
1347 }
1348 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_LDKC2Tuple_1TxidCVec_1C2Tuple_1u32TxOutZZZ_1get_1a(JNIEnv *env, jclass clz, int64_t ptr) {
1349         LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ *tuple = (LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ*)ptr;
1350         int8_tArray a_arr = (*env)->NewByteArray(env, 32);
1351         (*env)->SetByteArrayRegion(env, a_arr, 0, 32, tuple->a.data);
1352         return a_arr;
1353 }
1354 JNIEXPORT int64_tArray JNICALL Java_org_ldk_impl_bindings_LDKC2Tuple_1TxidCVec_1C2Tuple_1u32TxOutZZZ_1get_1b(JNIEnv *env, jclass clz, int64_t ptr) {
1355         LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ *tuple = (LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ*)ptr;
1356         LDKCVec_C2Tuple_u32TxOutZZ b_var = tuple->b;
1357         int64_tArray b_arr = (*env)->NewLongArray(env, b_var.datalen);
1358         int64_t *b_arr_ptr = (*env)->GetPrimitiveArrayCritical(env, b_arr, NULL);
1359         for (size_t a = 0; a < b_var.datalen; a++) {
1360                 long arr_conv_26_ref = (long)&b_var.data[a];
1361                 b_arr_ptr[a] = arr_conv_26_ref;
1362         }
1363         (*env)->ReleasePrimitiveArrayCritical(env, b_arr, b_arr_ptr, 0);
1364         return b_arr;
1365 }
1366 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCVec_1C2Tuple_1TxidCVec_1C2Tuple_1u32TxOutZZZZ_1new(JNIEnv *env, jclass clz, int64_tArray elems) {
1367         LDKCVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ *ret = MALLOC(sizeof(LDKCVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ), "LDKCVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ");
1368         ret->datalen = (*env)->GetArrayLength(env, elems);
1369         if (ret->datalen == 0) {
1370                 ret->data = NULL;
1371         } else {
1372                 ret->data = MALLOC(sizeof(LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ) * ret->datalen, "LDKCVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ Data");
1373                 int64_t *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
1374                 for (size_t i = 0; i < ret->datalen; i++) {
1375                         int64_t arr_elem = java_elems[i];
1376                         LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ arr_elem_conv = *(LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ*)arr_elem;
1377                         FREE((void*)arr_elem);
1378                         ret->data[i] = arr_elem_conv;
1379                 }
1380                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
1381         }
1382         return (long)ret;
1383 }
1384 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKC2Tuple_1SignatureCVec_1SignatureZZ_1new(JNIEnv *env, jclass clz, int8_tArray a, jobjectArray b) {
1385         LDKC2Tuple_SignatureCVec_SignatureZZ* ret = MALLOC(sizeof(LDKC2Tuple_SignatureCVec_SignatureZZ), "LDKC2Tuple_SignatureCVec_SignatureZZ");
1386         LDKSignature a_ref;
1387         CHECK((*env)->GetArrayLength(env, a) == 64);
1388         (*env)->GetByteArrayRegion(env, a, 0, 64, a_ref.compact_form);
1389         ret->a = a_ref;
1390         LDKCVec_SignatureZ b_constr;
1391         b_constr.datalen = (*env)->GetArrayLength(env, b);
1392         if (b_constr.datalen > 0)
1393                 b_constr.data = MALLOC(b_constr.datalen * sizeof(LDKSignature), "LDKCVec_SignatureZ Elements");
1394         else
1395                 b_constr.data = NULL;
1396         for (size_t i = 0; i < b_constr.datalen; i++) {
1397                 int8_tArray arr_conv_8 = (*env)->GetObjectArrayElement(env, b, i);
1398                 LDKSignature arr_conv_8_ref;
1399                 CHECK((*env)->GetArrayLength(env, arr_conv_8) == 64);
1400                 (*env)->GetByteArrayRegion(env, arr_conv_8, 0, 64, arr_conv_8_ref.compact_form);
1401                 b_constr.data[i] = arr_conv_8_ref;
1402         }
1403         ret->b = b_constr;
1404         return (long)ret;
1405 }
1406 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_LDKC2Tuple_1SignatureCVec_1SignatureZZ_1get_1a(JNIEnv *env, jclass clz, int64_t ptr) {
1407         LDKC2Tuple_SignatureCVec_SignatureZZ *tuple = (LDKC2Tuple_SignatureCVec_SignatureZZ*)ptr;
1408         int8_tArray a_arr = (*env)->NewByteArray(env, 64);
1409         (*env)->SetByteArrayRegion(env, a_arr, 0, 64, tuple->a.compact_form);
1410         return a_arr;
1411 }
1412 JNIEXPORT jobjectArray JNICALL Java_org_ldk_impl_bindings_LDKC2Tuple_1SignatureCVec_1SignatureZZ_1get_1b(JNIEnv *env, jclass clz, int64_t ptr) {
1413         LDKC2Tuple_SignatureCVec_SignatureZZ *tuple = (LDKC2Tuple_SignatureCVec_SignatureZZ*)ptr;
1414         LDKCVec_SignatureZ b_var = tuple->b;
1415         jobjectArray b_arr = (*env)->NewObjectArray(env, b_var.datalen, arr_of_B_clz, NULL);
1416         ;
1417         for (size_t i = 0; i < b_var.datalen; i++) {
1418                 int8_tArray arr_conv_8_arr = (*env)->NewByteArray(env, 64);
1419                 (*env)->SetByteArrayRegion(env, arr_conv_8_arr, 0, 64, b_var.data[i].compact_form);
1420                 (*env)->SetObjectArrayElement(env, b_arr, i, arr_conv_8_arr);
1421         }
1422         return b_arr;
1423 }
1424 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1C2Tuple_1SignatureCVec_1SignatureZZNoneZ_1result_1ok (JNIEnv *env, jclass clz, int64_t arg) {
1425         return ((LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ*)arg)->result_ok;
1426 }
1427 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1C2Tuple_1SignatureCVec_1SignatureZZNoneZ_1get_1ok (JNIEnv *env, jclass clz, int64_t arg) {
1428         LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ *val = (LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ*)arg;
1429         CHECK(val->result_ok);
1430         long res_ref = (long)&(*val->contents.result);
1431         return res_ref;
1432 }
1433 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_LDKCResult_1C2Tuple_1SignatureCVec_1SignatureZZNoneZ_1get_1err (JNIEnv *env, jclass clz, int64_t arg) {
1434         LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ *val = (LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ*)arg;
1435         CHECK(!val->result_ok);
1436         return *val->contents.err;
1437 }
1438 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1SignatureNoneZ_1result_1ok (JNIEnv *env, jclass clz, int64_t arg) {
1439         return ((LDKCResult_SignatureNoneZ*)arg)->result_ok;
1440 }
1441 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_LDKCResult_1SignatureNoneZ_1get_1ok (JNIEnv *env, jclass clz, int64_t arg) {
1442         LDKCResult_SignatureNoneZ *val = (LDKCResult_SignatureNoneZ*)arg;
1443         CHECK(val->result_ok);
1444         int8_tArray res_arr = (*env)->NewByteArray(env, 64);
1445         (*env)->SetByteArrayRegion(env, res_arr, 0, 64, (*val->contents.result).compact_form);
1446         return res_arr;
1447 }
1448 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_LDKCResult_1SignatureNoneZ_1get_1err (JNIEnv *env, jclass clz, int64_t arg) {
1449         LDKCResult_SignatureNoneZ *val = (LDKCResult_SignatureNoneZ*)arg;
1450         CHECK(!val->result_ok);
1451         return *val->contents.err;
1452 }
1453 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1CVec_1SignatureZNoneZ_1result_1ok (JNIEnv *env, jclass clz, int64_t arg) {
1454         return ((LDKCResult_CVec_SignatureZNoneZ*)arg)->result_ok;
1455 }
1456 JNIEXPORT jobjectArray JNICALL Java_org_ldk_impl_bindings_LDKCResult_1CVec_1SignatureZNoneZ_1get_1ok (JNIEnv *env, jclass clz, int64_t arg) {
1457         LDKCResult_CVec_SignatureZNoneZ *val = (LDKCResult_CVec_SignatureZNoneZ*)arg;
1458         CHECK(val->result_ok);
1459         LDKCVec_SignatureZ res_var = (*val->contents.result);
1460         jobjectArray res_arr = (*env)->NewObjectArray(env, res_var.datalen, arr_of_B_clz, NULL);
1461         ;
1462         for (size_t i = 0; i < res_var.datalen; i++) {
1463                 int8_tArray arr_conv_8_arr = (*env)->NewByteArray(env, 64);
1464                 (*env)->SetByteArrayRegion(env, arr_conv_8_arr, 0, 64, res_var.data[i].compact_form);
1465                 (*env)->SetObjectArrayElement(env, res_arr, i, arr_conv_8_arr);
1466         }
1467         return res_arr;
1468 }
1469 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_LDKCResult_1CVec_1SignatureZNoneZ_1get_1err (JNIEnv *env, jclass clz, int64_t arg) {
1470         LDKCResult_CVec_SignatureZNoneZ *val = (LDKCResult_CVec_SignatureZNoneZ*)arg;
1471         CHECK(!val->result_ok);
1472         return *val->contents.err;
1473 }
1474 typedef struct LDKChannelKeys_JCalls {
1475         atomic_size_t refcnt;
1476         JavaVM *vm;
1477         jweak o;
1478         jmethodID get_per_commitment_point_meth;
1479         jmethodID release_commitment_secret_meth;
1480         jmethodID key_derivation_params_meth;
1481         jmethodID sign_counterparty_commitment_meth;
1482         jmethodID sign_holder_commitment_meth;
1483         jmethodID sign_holder_commitment_htlc_transactions_meth;
1484         jmethodID sign_justice_transaction_meth;
1485         jmethodID sign_counterparty_htlc_transaction_meth;
1486         jmethodID sign_closing_transaction_meth;
1487         jmethodID sign_channel_announcement_meth;
1488         jmethodID ready_channel_meth;
1489         jmethodID write_meth;
1490 } LDKChannelKeys_JCalls;
1491 static void LDKChannelKeys_JCalls_free(void* this_arg) {
1492         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1493         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
1494                 JNIEnv *env;
1495                 DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
1496                 (*env)->DeleteWeakGlobalRef(env, j_calls->o);
1497                 FREE(j_calls);
1498         }
1499 }
1500 LDKPublicKey get_per_commitment_point_jcall(const void* this_arg, uint64_t idx) {
1501         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1502         JNIEnv *env;
1503         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
1504         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
1505         CHECK(obj != NULL);
1506         int8_tArray arg = (*env)->CallObjectMethod(env, obj, j_calls->get_per_commitment_point_meth, idx);
1507         LDKPublicKey arg_ref;
1508         CHECK((*env)->GetArrayLength(env, arg) == 33);
1509         (*env)->GetByteArrayRegion(env, arg, 0, 33, arg_ref.compressed_form);
1510         return arg_ref;
1511 }
1512 LDKThirtyTwoBytes release_commitment_secret_jcall(const void* this_arg, uint64_t idx) {
1513         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1514         JNIEnv *env;
1515         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
1516         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
1517         CHECK(obj != NULL);
1518         int8_tArray arg = (*env)->CallObjectMethod(env, obj, j_calls->release_commitment_secret_meth, idx);
1519         LDKThirtyTwoBytes arg_ref;
1520         CHECK((*env)->GetArrayLength(env, arg) == 32);
1521         (*env)->GetByteArrayRegion(env, arg, 0, 32, arg_ref.data);
1522         return arg_ref;
1523 }
1524 LDKC2Tuple_u64u64Z key_derivation_params_jcall(const void* this_arg) {
1525         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1526         JNIEnv *env;
1527         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
1528         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
1529         CHECK(obj != NULL);
1530         LDKC2Tuple_u64u64Z* ret = (LDKC2Tuple_u64u64Z*)(*env)->CallLongMethod(env, obj, j_calls->key_derivation_params_meth);
1531         LDKC2Tuple_u64u64Z ret_conv = *(LDKC2Tuple_u64u64Z*)ret;
1532         FREE((void*)ret);
1533         return ret_conv;
1534 }
1535 LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ sign_counterparty_commitment_jcall(const void* this_arg, const LDKCommitmentTransaction * commitment_tx) {
1536         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1537         JNIEnv *env;
1538         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
1539         LDKCommitmentTransaction commitment_tx_var = *commitment_tx;
1540         if (commitment_tx->inner != NULL)
1541                 commitment_tx_var = CommitmentTransaction_clone(commitment_tx);
1542         CHECK((((long)commitment_tx_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1543         CHECK((((long)&commitment_tx_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1544         long commitment_tx_ref = (long)commitment_tx_var.inner;
1545         if (commitment_tx_var.is_owned) {
1546                 commitment_tx_ref |= 1;
1547         }
1548         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
1549         CHECK(obj != NULL);
1550         LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ* ret = (LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ*)(*env)->CallLongMethod(env, obj, j_calls->sign_counterparty_commitment_meth, commitment_tx_ref);
1551         LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ ret_conv = *(LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ*)ret;
1552         FREE((void*)ret);
1553         return ret_conv;
1554 }
1555 LDKCResult_SignatureNoneZ sign_holder_commitment_jcall(const void* this_arg, const LDKHolderCommitmentTransaction * commitment_tx) {
1556         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1557         JNIEnv *env;
1558         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
1559         LDKHolderCommitmentTransaction commitment_tx_var = *commitment_tx;
1560         if (commitment_tx->inner != NULL)
1561                 commitment_tx_var = HolderCommitmentTransaction_clone(commitment_tx);
1562         CHECK((((long)commitment_tx_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1563         CHECK((((long)&commitment_tx_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1564         long commitment_tx_ref = (long)commitment_tx_var.inner;
1565         if (commitment_tx_var.is_owned) {
1566                 commitment_tx_ref |= 1;
1567         }
1568         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
1569         CHECK(obj != NULL);
1570         LDKCResult_SignatureNoneZ* ret = (LDKCResult_SignatureNoneZ*)(*env)->CallLongMethod(env, obj, j_calls->sign_holder_commitment_meth, commitment_tx_ref);
1571         LDKCResult_SignatureNoneZ ret_conv = *(LDKCResult_SignatureNoneZ*)ret;
1572         FREE((void*)ret);
1573         return ret_conv;
1574 }
1575 LDKCResult_CVec_SignatureZNoneZ sign_holder_commitment_htlc_transactions_jcall(const void* this_arg, const LDKHolderCommitmentTransaction * commitment_tx) {
1576         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1577         JNIEnv *env;
1578         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
1579         LDKHolderCommitmentTransaction commitment_tx_var = *commitment_tx;
1580         if (commitment_tx->inner != NULL)
1581                 commitment_tx_var = HolderCommitmentTransaction_clone(commitment_tx);
1582         CHECK((((long)commitment_tx_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1583         CHECK((((long)&commitment_tx_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1584         long commitment_tx_ref = (long)commitment_tx_var.inner;
1585         if (commitment_tx_var.is_owned) {
1586                 commitment_tx_ref |= 1;
1587         }
1588         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
1589         CHECK(obj != NULL);
1590         LDKCResult_CVec_SignatureZNoneZ* ret = (LDKCResult_CVec_SignatureZNoneZ*)(*env)->CallLongMethod(env, obj, j_calls->sign_holder_commitment_htlc_transactions_meth, commitment_tx_ref);
1591         LDKCResult_CVec_SignatureZNoneZ ret_conv = *(LDKCResult_CVec_SignatureZNoneZ*)ret;
1592         FREE((void*)ret);
1593         return ret_conv;
1594 }
1595 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) {
1596         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1597         JNIEnv *env;
1598         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
1599         LDKTransaction justice_tx_var = justice_tx;
1600         int8_tArray justice_tx_arr = (*env)->NewByteArray(env, justice_tx_var.datalen);
1601         (*env)->SetByteArrayRegion(env, justice_tx_arr, 0, justice_tx_var.datalen, justice_tx_var.data);
1602         Transaction_free(justice_tx_var);
1603         int8_tArray per_commitment_key_arr = (*env)->NewByteArray(env, 32);
1604         (*env)->SetByteArrayRegion(env, per_commitment_key_arr, 0, 32, *per_commitment_key);
1605         LDKHTLCOutputInCommitment htlc_var = *htlc;
1606         if (htlc->inner != NULL)
1607                 htlc_var = HTLCOutputInCommitment_clone(htlc);
1608         CHECK((((long)htlc_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1609         CHECK((((long)&htlc_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1610         long htlc_ref = (long)htlc_var.inner;
1611         if (htlc_var.is_owned) {
1612                 htlc_ref |= 1;
1613         }
1614         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
1615         CHECK(obj != NULL);
1616         LDKCResult_SignatureNoneZ* ret = (LDKCResult_SignatureNoneZ*)(*env)->CallLongMethod(env, obj, j_calls->sign_justice_transaction_meth, justice_tx_arr, input, amount, per_commitment_key_arr, htlc_ref);
1617         LDKCResult_SignatureNoneZ ret_conv = *(LDKCResult_SignatureNoneZ*)ret;
1618         FREE((void*)ret);
1619         return ret_conv;
1620 }
1621 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) {
1622         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1623         JNIEnv *env;
1624         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
1625         LDKTransaction htlc_tx_var = htlc_tx;
1626         int8_tArray htlc_tx_arr = (*env)->NewByteArray(env, htlc_tx_var.datalen);
1627         (*env)->SetByteArrayRegion(env, htlc_tx_arr, 0, htlc_tx_var.datalen, htlc_tx_var.data);
1628         Transaction_free(htlc_tx_var);
1629         int8_tArray per_commitment_point_arr = (*env)->NewByteArray(env, 33);
1630         (*env)->SetByteArrayRegion(env, per_commitment_point_arr, 0, 33, per_commitment_point.compressed_form);
1631         LDKHTLCOutputInCommitment htlc_var = *htlc;
1632         if (htlc->inner != NULL)
1633                 htlc_var = HTLCOutputInCommitment_clone(htlc);
1634         CHECK((((long)htlc_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1635         CHECK((((long)&htlc_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1636         long htlc_ref = (long)htlc_var.inner;
1637         if (htlc_var.is_owned) {
1638                 htlc_ref |= 1;
1639         }
1640         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
1641         CHECK(obj != NULL);
1642         LDKCResult_SignatureNoneZ* ret = (LDKCResult_SignatureNoneZ*)(*env)->CallLongMethod(env, obj, j_calls->sign_counterparty_htlc_transaction_meth, htlc_tx_arr, input, amount, per_commitment_point_arr, htlc_ref);
1643         LDKCResult_SignatureNoneZ ret_conv = *(LDKCResult_SignatureNoneZ*)ret;
1644         FREE((void*)ret);
1645         return ret_conv;
1646 }
1647 LDKCResult_SignatureNoneZ sign_closing_transaction_jcall(const void* this_arg, LDKTransaction closing_tx) {
1648         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1649         JNIEnv *env;
1650         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
1651         LDKTransaction closing_tx_var = closing_tx;
1652         int8_tArray closing_tx_arr = (*env)->NewByteArray(env, closing_tx_var.datalen);
1653         (*env)->SetByteArrayRegion(env, closing_tx_arr, 0, closing_tx_var.datalen, closing_tx_var.data);
1654         Transaction_free(closing_tx_var);
1655         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
1656         CHECK(obj != NULL);
1657         LDKCResult_SignatureNoneZ* ret = (LDKCResult_SignatureNoneZ*)(*env)->CallLongMethod(env, obj, j_calls->sign_closing_transaction_meth, closing_tx_arr);
1658         LDKCResult_SignatureNoneZ ret_conv = *(LDKCResult_SignatureNoneZ*)ret;
1659         FREE((void*)ret);
1660         return ret_conv;
1661 }
1662 LDKCResult_SignatureNoneZ sign_channel_announcement_jcall(const void* this_arg, const LDKUnsignedChannelAnnouncement * msg) {
1663         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1664         JNIEnv *env;
1665         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
1666         LDKUnsignedChannelAnnouncement msg_var = *msg;
1667         if (msg->inner != NULL)
1668                 msg_var = UnsignedChannelAnnouncement_clone(msg);
1669         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1670         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1671         long msg_ref = (long)msg_var.inner;
1672         if (msg_var.is_owned) {
1673                 msg_ref |= 1;
1674         }
1675         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
1676         CHECK(obj != NULL);
1677         LDKCResult_SignatureNoneZ* ret = (LDKCResult_SignatureNoneZ*)(*env)->CallLongMethod(env, obj, j_calls->sign_channel_announcement_meth, msg_ref);
1678         LDKCResult_SignatureNoneZ ret_conv = *(LDKCResult_SignatureNoneZ*)ret;
1679         FREE((void*)ret);
1680         return ret_conv;
1681 }
1682 void ready_channel_jcall(void* this_arg, const LDKChannelTransactionParameters * channel_parameters) {
1683         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1684         JNIEnv *env;
1685         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
1686         LDKChannelTransactionParameters channel_parameters_var = *channel_parameters;
1687         if (channel_parameters->inner != NULL)
1688                 channel_parameters_var = ChannelTransactionParameters_clone(channel_parameters);
1689         CHECK((((long)channel_parameters_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1690         CHECK((((long)&channel_parameters_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1691         long channel_parameters_ref = (long)channel_parameters_var.inner;
1692         if (channel_parameters_var.is_owned) {
1693                 channel_parameters_ref |= 1;
1694         }
1695         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
1696         CHECK(obj != NULL);
1697         return (*env)->CallVoidMethod(env, obj, j_calls->ready_channel_meth, channel_parameters_ref);
1698 }
1699 LDKCVec_u8Z write_jcall(const void* this_arg) {
1700         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1701         JNIEnv *env;
1702         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
1703         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
1704         CHECK(obj != NULL);
1705         int8_tArray arg = (*env)->CallObjectMethod(env, obj, j_calls->write_meth);
1706         LDKCVec_u8Z arg_ref;
1707         arg_ref.datalen = (*env)->GetArrayLength(env, arg);
1708         arg_ref.data = MALLOC(arg_ref.datalen, "LDKCVec_u8Z Bytes");
1709         (*env)->GetByteArrayRegion(env, arg, 0, arg_ref.datalen, arg_ref.data);
1710         return arg_ref;
1711 }
1712 static void* LDKChannelKeys_JCalls_clone(const void* this_arg) {
1713         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1714         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
1715         return (void*) this_arg;
1716 }
1717 static inline LDKChannelKeys LDKChannelKeys_init (JNIEnv *env, jclass clz, jobject o, int64_t pubkeys) {
1718         jclass c = (*env)->GetObjectClass(env, o);
1719         CHECK(c != NULL);
1720         LDKChannelKeys_JCalls *calls = MALLOC(sizeof(LDKChannelKeys_JCalls), "LDKChannelKeys_JCalls");
1721         atomic_init(&calls->refcnt, 1);
1722         DO_ASSERT((*env)->GetJavaVM(env, &calls->vm) == 0);
1723         calls->o = (*env)->NewWeakGlobalRef(env, o);
1724         calls->get_per_commitment_point_meth = (*env)->GetMethodID(env, c, "get_per_commitment_point", "(J)[B");
1725         CHECK(calls->get_per_commitment_point_meth != NULL);
1726         calls->release_commitment_secret_meth = (*env)->GetMethodID(env, c, "release_commitment_secret", "(J)[B");
1727         CHECK(calls->release_commitment_secret_meth != NULL);
1728         calls->key_derivation_params_meth = (*env)->GetMethodID(env, c, "key_derivation_params", "()J");
1729         CHECK(calls->key_derivation_params_meth != NULL);
1730         calls->sign_counterparty_commitment_meth = (*env)->GetMethodID(env, c, "sign_counterparty_commitment", "(J)J");
1731         CHECK(calls->sign_counterparty_commitment_meth != NULL);
1732         calls->sign_holder_commitment_meth = (*env)->GetMethodID(env, c, "sign_holder_commitment", "(J)J");
1733         CHECK(calls->sign_holder_commitment_meth != NULL);
1734         calls->sign_holder_commitment_htlc_transactions_meth = (*env)->GetMethodID(env, c, "sign_holder_commitment_htlc_transactions", "(J)J");
1735         CHECK(calls->sign_holder_commitment_htlc_transactions_meth != NULL);
1736         calls->sign_justice_transaction_meth = (*env)->GetMethodID(env, c, "sign_justice_transaction", "([BJJ[BJ)J");
1737         CHECK(calls->sign_justice_transaction_meth != NULL);
1738         calls->sign_counterparty_htlc_transaction_meth = (*env)->GetMethodID(env, c, "sign_counterparty_htlc_transaction", "([BJJ[BJ)J");
1739         CHECK(calls->sign_counterparty_htlc_transaction_meth != NULL);
1740         calls->sign_closing_transaction_meth = (*env)->GetMethodID(env, c, "sign_closing_transaction", "([B)J");
1741         CHECK(calls->sign_closing_transaction_meth != NULL);
1742         calls->sign_channel_announcement_meth = (*env)->GetMethodID(env, c, "sign_channel_announcement", "(J)J");
1743         CHECK(calls->sign_channel_announcement_meth != NULL);
1744         calls->ready_channel_meth = (*env)->GetMethodID(env, c, "ready_channel", "(J)V");
1745         CHECK(calls->ready_channel_meth != NULL);
1746         calls->write_meth = (*env)->GetMethodID(env, c, "write", "()[B");
1747         CHECK(calls->write_meth != NULL);
1748
1749         LDKChannelPublicKeys pubkeys_conv;
1750         pubkeys_conv.inner = (void*)(pubkeys & (~1));
1751         pubkeys_conv.is_owned = (pubkeys & 1) || (pubkeys == 0);
1752         if (pubkeys_conv.inner != NULL)
1753                 pubkeys_conv = ChannelPublicKeys_clone(&pubkeys_conv);
1754
1755         LDKChannelKeys ret = {
1756                 .this_arg = (void*) calls,
1757                 .get_per_commitment_point = get_per_commitment_point_jcall,
1758                 .release_commitment_secret = release_commitment_secret_jcall,
1759                 .key_derivation_params = key_derivation_params_jcall,
1760                 .sign_counterparty_commitment = sign_counterparty_commitment_jcall,
1761                 .sign_holder_commitment = sign_holder_commitment_jcall,
1762                 .sign_holder_commitment_htlc_transactions = sign_holder_commitment_htlc_transactions_jcall,
1763                 .sign_justice_transaction = sign_justice_transaction_jcall,
1764                 .sign_counterparty_htlc_transaction = sign_counterparty_htlc_transaction_jcall,
1765                 .sign_closing_transaction = sign_closing_transaction_jcall,
1766                 .sign_channel_announcement = sign_channel_announcement_jcall,
1767                 .ready_channel = ready_channel_jcall,
1768                 .clone = LDKChannelKeys_JCalls_clone,
1769                 .write = write_jcall,
1770                 .free = LDKChannelKeys_JCalls_free,
1771                 .pubkeys = pubkeys_conv,
1772                 .set_pubkeys = NULL,
1773         };
1774         return ret;
1775 }
1776 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_LDKChannelKeys_1new (JNIEnv *env, jclass clz, jobject o, int64_t pubkeys) {
1777         LDKChannelKeys *res_ptr = MALLOC(sizeof(LDKChannelKeys), "LDKChannelKeys");
1778         *res_ptr = LDKChannelKeys_init(env, clz, o, pubkeys);
1779         return (long)res_ptr;
1780 }
1781 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1get_1per_1commitment_1point(JNIEnv *env, jclass clz, int64_t this_arg, int64_t idx) {
1782         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
1783         int8_tArray arg_arr = (*env)->NewByteArray(env, 33);
1784         (*env)->SetByteArrayRegion(env, arg_arr, 0, 33, (this_arg_conv->get_per_commitment_point)(this_arg_conv->this_arg, idx).compressed_form);
1785         return arg_arr;
1786 }
1787
1788 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1release_1commitment_1secret(JNIEnv *env, jclass clz, int64_t this_arg, int64_t idx) {
1789         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
1790         int8_tArray arg_arr = (*env)->NewByteArray(env, 32);
1791         (*env)->SetByteArrayRegion(env, arg_arr, 0, 32, (this_arg_conv->release_commitment_secret)(this_arg_conv->this_arg, idx).data);
1792         return arg_arr;
1793 }
1794
1795 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1key_1derivation_1params(JNIEnv *env, jclass clz, int64_t this_arg) {
1796         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
1797         LDKC2Tuple_u64u64Z* ret_ref = MALLOC(sizeof(LDKC2Tuple_u64u64Z), "LDKC2Tuple_u64u64Z");
1798         *ret_ref = (this_arg_conv->key_derivation_params)(this_arg_conv->this_arg);
1799         return (long)ret_ref;
1800 }
1801
1802 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1sign_1counterparty_1commitment(JNIEnv *env, jclass clz, int64_t this_arg, int64_t commitment_tx) {
1803         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
1804         LDKCommitmentTransaction commitment_tx_conv;
1805         commitment_tx_conv.inner = (void*)(commitment_tx & (~1));
1806         commitment_tx_conv.is_owned = false;
1807         LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ), "LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ");
1808         *ret_conv = (this_arg_conv->sign_counterparty_commitment)(this_arg_conv->this_arg, &commitment_tx_conv);
1809         return (long)ret_conv;
1810 }
1811
1812 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1sign_1holder_1commitment(JNIEnv *env, jclass clz, int64_t this_arg, int64_t commitment_tx) {
1813         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
1814         LDKHolderCommitmentTransaction commitment_tx_conv;
1815         commitment_tx_conv.inner = (void*)(commitment_tx & (~1));
1816         commitment_tx_conv.is_owned = false;
1817         LDKCResult_SignatureNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_SignatureNoneZ), "LDKCResult_SignatureNoneZ");
1818         *ret_conv = (this_arg_conv->sign_holder_commitment)(this_arg_conv->this_arg, &commitment_tx_conv);
1819         return (long)ret_conv;
1820 }
1821
1822 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1sign_1holder_1commitment_1htlc_1transactions(JNIEnv *env, jclass clz, int64_t this_arg, int64_t commitment_tx) {
1823         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
1824         LDKHolderCommitmentTransaction commitment_tx_conv;
1825         commitment_tx_conv.inner = (void*)(commitment_tx & (~1));
1826         commitment_tx_conv.is_owned = false;
1827         LDKCResult_CVec_SignatureZNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_CVec_SignatureZNoneZ), "LDKCResult_CVec_SignatureZNoneZ");
1828         *ret_conv = (this_arg_conv->sign_holder_commitment_htlc_transactions)(this_arg_conv->this_arg, &commitment_tx_conv);
1829         return (long)ret_conv;
1830 }
1831
1832 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1sign_1justice_1transaction(JNIEnv *env, jclass clz, int64_t this_arg, int8_tArray justice_tx, intptr_t input, int64_t amount, int8_tArray per_commitment_key, int64_t htlc) {
1833         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
1834         LDKTransaction justice_tx_ref;
1835         justice_tx_ref.datalen = (*env)->GetArrayLength(env, justice_tx);
1836         justice_tx_ref.data = MALLOC(justice_tx_ref.datalen, "LDKTransaction Bytes");
1837         (*env)->GetByteArrayRegion(env, justice_tx, 0, justice_tx_ref.datalen, justice_tx_ref.data);
1838         justice_tx_ref.data_is_owned = true;
1839         unsigned char per_commitment_key_arr[32];
1840         CHECK((*env)->GetArrayLength(env, per_commitment_key) == 32);
1841         (*env)->GetByteArrayRegion(env, per_commitment_key, 0, 32, per_commitment_key_arr);
1842         unsigned char (*per_commitment_key_ref)[32] = &per_commitment_key_arr;
1843         LDKHTLCOutputInCommitment htlc_conv;
1844         htlc_conv.inner = (void*)(htlc & (~1));
1845         htlc_conv.is_owned = false;
1846         LDKCResult_SignatureNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_SignatureNoneZ), "LDKCResult_SignatureNoneZ");
1847         *ret_conv = (this_arg_conv->sign_justice_transaction)(this_arg_conv->this_arg, justice_tx_ref, input, amount, per_commitment_key_ref, &htlc_conv);
1848         return (long)ret_conv;
1849 }
1850
1851 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1sign_1counterparty_1htlc_1transaction(JNIEnv *env, jclass clz, int64_t this_arg, int8_tArray htlc_tx, intptr_t input, int64_t amount, int8_tArray per_commitment_point, int64_t htlc) {
1852         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
1853         LDKTransaction htlc_tx_ref;
1854         htlc_tx_ref.datalen = (*env)->GetArrayLength(env, htlc_tx);
1855         htlc_tx_ref.data = MALLOC(htlc_tx_ref.datalen, "LDKTransaction Bytes");
1856         (*env)->GetByteArrayRegion(env, htlc_tx, 0, htlc_tx_ref.datalen, htlc_tx_ref.data);
1857         htlc_tx_ref.data_is_owned = true;
1858         LDKPublicKey per_commitment_point_ref;
1859         CHECK((*env)->GetArrayLength(env, per_commitment_point) == 33);
1860         (*env)->GetByteArrayRegion(env, per_commitment_point, 0, 33, per_commitment_point_ref.compressed_form);
1861         LDKHTLCOutputInCommitment htlc_conv;
1862         htlc_conv.inner = (void*)(htlc & (~1));
1863         htlc_conv.is_owned = false;
1864         LDKCResult_SignatureNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_SignatureNoneZ), "LDKCResult_SignatureNoneZ");
1865         *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);
1866         return (long)ret_conv;
1867 }
1868
1869 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1sign_1closing_1transaction(JNIEnv *env, jclass clz, int64_t this_arg, int8_tArray closing_tx) {
1870         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
1871         LDKTransaction closing_tx_ref;
1872         closing_tx_ref.datalen = (*env)->GetArrayLength(env, closing_tx);
1873         closing_tx_ref.data = MALLOC(closing_tx_ref.datalen, "LDKTransaction Bytes");
1874         (*env)->GetByteArrayRegion(env, closing_tx, 0, closing_tx_ref.datalen, closing_tx_ref.data);
1875         closing_tx_ref.data_is_owned = true;
1876         LDKCResult_SignatureNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_SignatureNoneZ), "LDKCResult_SignatureNoneZ");
1877         *ret_conv = (this_arg_conv->sign_closing_transaction)(this_arg_conv->this_arg, closing_tx_ref);
1878         return (long)ret_conv;
1879 }
1880
1881 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1sign_1channel_1announcement(JNIEnv *env, jclass clz, int64_t this_arg, int64_t msg) {
1882         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
1883         LDKUnsignedChannelAnnouncement msg_conv;
1884         msg_conv.inner = (void*)(msg & (~1));
1885         msg_conv.is_owned = false;
1886         LDKCResult_SignatureNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_SignatureNoneZ), "LDKCResult_SignatureNoneZ");
1887         *ret_conv = (this_arg_conv->sign_channel_announcement)(this_arg_conv->this_arg, &msg_conv);
1888         return (long)ret_conv;
1889 }
1890
1891 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1ready_1channel(JNIEnv *env, jclass clz, int64_t this_arg, int64_t channel_parameters) {
1892         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
1893         LDKChannelTransactionParameters channel_parameters_conv;
1894         channel_parameters_conv.inner = (void*)(channel_parameters & (~1));
1895         channel_parameters_conv.is_owned = false;
1896         (this_arg_conv->ready_channel)(this_arg_conv->this_arg, &channel_parameters_conv);
1897 }
1898
1899 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1write(JNIEnv *env, jclass clz, int64_t this_arg) {
1900         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
1901         LDKCVec_u8Z arg_var = (this_arg_conv->write)(this_arg_conv->this_arg);
1902         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
1903         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
1904         CVec_u8Z_free(arg_var);
1905         return arg_arr;
1906 }
1907
1908 LDKChannelPublicKeys LDKChannelKeys_set_get_pubkeys(LDKChannelKeys* this_arg) {
1909         if (this_arg->set_pubkeys != NULL)
1910                 this_arg->set_pubkeys(this_arg);
1911         return this_arg->pubkeys;
1912 }
1913 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1get_1pubkeys(JNIEnv *env, jclass clz, int64_t this_arg) {
1914         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
1915         LDKChannelPublicKeys ret_var = LDKChannelKeys_set_get_pubkeys(this_arg_conv);
1916         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1917         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1918         long ret_ref = (long)ret_var.inner;
1919         if (ret_var.is_owned) {
1920                 ret_ref |= 1;
1921         }
1922         return ret_ref;
1923 }
1924
1925 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKC2Tuple_1BlockHashChannelMonitorZ_1new(JNIEnv *env, jclass clz, int8_tArray a, int64_t b) {
1926         LDKC2Tuple_BlockHashChannelMonitorZ* ret = MALLOC(sizeof(LDKC2Tuple_BlockHashChannelMonitorZ), "LDKC2Tuple_BlockHashChannelMonitorZ");
1927         LDKThirtyTwoBytes a_ref;
1928         CHECK((*env)->GetArrayLength(env, a) == 32);
1929         (*env)->GetByteArrayRegion(env, a, 0, 32, a_ref.data);
1930         ret->a = a_ref;
1931         LDKChannelMonitor b_conv;
1932         b_conv.inner = (void*)(b & (~1));
1933         b_conv.is_owned = (b & 1) || (b == 0);
1934         // Warning: we may need a move here but can't clone!
1935         ret->b = b_conv;
1936         return (long)ret;
1937 }
1938 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_LDKC2Tuple_1BlockHashChannelMonitorZ_1get_1a(JNIEnv *env, jclass clz, int64_t ptr) {
1939         LDKC2Tuple_BlockHashChannelMonitorZ *tuple = (LDKC2Tuple_BlockHashChannelMonitorZ*)ptr;
1940         int8_tArray a_arr = (*env)->NewByteArray(env, 32);
1941         (*env)->SetByteArrayRegion(env, a_arr, 0, 32, tuple->a.data);
1942         return a_arr;
1943 }
1944 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKC2Tuple_1BlockHashChannelMonitorZ_1get_1b(JNIEnv *env, jclass clz, int64_t ptr) {
1945         LDKC2Tuple_BlockHashChannelMonitorZ *tuple = (LDKC2Tuple_BlockHashChannelMonitorZ*)ptr;
1946         LDKChannelMonitor b_var = tuple->b;
1947         CHECK((((long)b_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1948         CHECK((((long)&b_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1949         long b_ref = (long)b_var.inner & ~1;
1950         return b_ref;
1951 }
1952 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1C2Tuple_1BlockHashChannelMonitorZDecodeErrorZ_1result_1ok (JNIEnv *env, jclass clz, int64_t arg) {
1953         return ((LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ*)arg)->result_ok;
1954 }
1955 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1C2Tuple_1BlockHashChannelMonitorZDecodeErrorZ_1get_1ok (JNIEnv *env, jclass clz, int64_t arg) {
1956         LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ *val = (LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ*)arg;
1957         CHECK(val->result_ok);
1958         long res_ref = (long)&(*val->contents.result);
1959         return res_ref;
1960 }
1961 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1C2Tuple_1BlockHashChannelMonitorZDecodeErrorZ_1get_1err (JNIEnv *env, jclass clz, int64_t arg) {
1962         LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ *val = (LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ*)arg;
1963         CHECK(!val->result_ok);
1964         LDKDecodeError err_var = (*val->contents.err);
1965         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1966         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1967         long err_ref = (long)err_var.inner & ~1;
1968         return err_ref;
1969 }
1970 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1SpendableOutputDescriptorDecodeErrorZ_1result_1ok (JNIEnv *env, jclass clz, int64_t arg) {
1971         return ((LDKCResult_SpendableOutputDescriptorDecodeErrorZ*)arg)->result_ok;
1972 }
1973 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1SpendableOutputDescriptorDecodeErrorZ_1get_1ok (JNIEnv *env, jclass clz, int64_t arg) {
1974         LDKCResult_SpendableOutputDescriptorDecodeErrorZ *val = (LDKCResult_SpendableOutputDescriptorDecodeErrorZ*)arg;
1975         CHECK(val->result_ok);
1976         long res_ref = (long)&(*val->contents.result);
1977         return res_ref;
1978 }
1979 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1SpendableOutputDescriptorDecodeErrorZ_1get_1err (JNIEnv *env, jclass clz, int64_t arg) {
1980         LDKCResult_SpendableOutputDescriptorDecodeErrorZ *val = (LDKCResult_SpendableOutputDescriptorDecodeErrorZ*)arg;
1981         CHECK(!val->result_ok);
1982         LDKDecodeError err_var = (*val->contents.err);
1983         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1984         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1985         long err_ref = (long)err_var.inner & ~1;
1986         return err_ref;
1987 }
1988 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1ChanKeySignerDecodeErrorZ_1result_1ok (JNIEnv *env, jclass clz, int64_t arg) {
1989         return ((LDKCResult_ChanKeySignerDecodeErrorZ*)arg)->result_ok;
1990 }
1991 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1ChanKeySignerDecodeErrorZ_1get_1ok (JNIEnv *env, jclass clz, int64_t arg) {
1992         LDKCResult_ChanKeySignerDecodeErrorZ *val = (LDKCResult_ChanKeySignerDecodeErrorZ*)arg;
1993         CHECK(val->result_ok);
1994         LDKChannelKeys* ret = MALLOC(sizeof(LDKChannelKeys), "LDKChannelKeys");
1995         *ret = (*val->contents.result);
1996         return (long)ret;
1997 }
1998 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1ChanKeySignerDecodeErrorZ_1get_1err (JNIEnv *env, jclass clz, int64_t arg) {
1999         LDKCResult_ChanKeySignerDecodeErrorZ *val = (LDKCResult_ChanKeySignerDecodeErrorZ*)arg;
2000         CHECK(!val->result_ok);
2001         LDKDecodeError err_var = (*val->contents.err);
2002         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2003         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2004         long err_ref = (long)err_var.inner & ~1;
2005         return err_ref;
2006 }
2007 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1InMemoryChannelKeysDecodeErrorZ_1result_1ok (JNIEnv *env, jclass clz, int64_t arg) {
2008         return ((LDKCResult_InMemoryChannelKeysDecodeErrorZ*)arg)->result_ok;
2009 }
2010 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1InMemoryChannelKeysDecodeErrorZ_1get_1ok (JNIEnv *env, jclass clz, int64_t arg) {
2011         LDKCResult_InMemoryChannelKeysDecodeErrorZ *val = (LDKCResult_InMemoryChannelKeysDecodeErrorZ*)arg;
2012         CHECK(val->result_ok);
2013         LDKInMemoryChannelKeys res_var = (*val->contents.result);
2014         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2015         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2016         long res_ref = (long)res_var.inner & ~1;
2017         return res_ref;
2018 }
2019 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1InMemoryChannelKeysDecodeErrorZ_1get_1err (JNIEnv *env, jclass clz, int64_t arg) {
2020         LDKCResult_InMemoryChannelKeysDecodeErrorZ *val = (LDKCResult_InMemoryChannelKeysDecodeErrorZ*)arg;
2021         CHECK(!val->result_ok);
2022         LDKDecodeError err_var = (*val->contents.err);
2023         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2024         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2025         long err_ref = (long)err_var.inner & ~1;
2026         return err_ref;
2027 }
2028 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1TxOutAccessErrorZ_1result_1ok (JNIEnv *env, jclass clz, int64_t arg) {
2029         return ((LDKCResult_TxOutAccessErrorZ*)arg)->result_ok;
2030 }
2031 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1TxOutAccessErrorZ_1get_1ok (JNIEnv *env, jclass clz, int64_t arg) {
2032         LDKCResult_TxOutAccessErrorZ *val = (LDKCResult_TxOutAccessErrorZ*)arg;
2033         CHECK(val->result_ok);
2034         long res_ref = (long)&(*val->contents.result);
2035         return (long)res_ref;
2036 }
2037 JNIEXPORT jclass JNICALL Java_org_ldk_impl_bindings_LDKCResult_1TxOutAccessErrorZ_1get_1err (JNIEnv *env, jclass clz, int64_t arg) {
2038         LDKCResult_TxOutAccessErrorZ *val = (LDKCResult_TxOutAccessErrorZ*)arg;
2039         CHECK(!val->result_ok);
2040         jclass err_conv = LDKAccessError_to_java(env, (*val->contents.err));
2041         return err_conv;
2042 }
2043 static jclass LDKAPIError_APIMisuseError_class = NULL;
2044 static jmethodID LDKAPIError_APIMisuseError_meth = NULL;
2045 static jclass LDKAPIError_FeeRateTooHigh_class = NULL;
2046 static jmethodID LDKAPIError_FeeRateTooHigh_meth = NULL;
2047 static jclass LDKAPIError_RouteError_class = NULL;
2048 static jmethodID LDKAPIError_RouteError_meth = NULL;
2049 static jclass LDKAPIError_ChannelUnavailable_class = NULL;
2050 static jmethodID LDKAPIError_ChannelUnavailable_meth = NULL;
2051 static jclass LDKAPIError_MonitorUpdateFailed_class = NULL;
2052 static jmethodID LDKAPIError_MonitorUpdateFailed_meth = NULL;
2053 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_00024LDKAPIError_init (JNIEnv *env, jclass clz) {
2054         LDKAPIError_APIMisuseError_class =
2055                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKAPIError$APIMisuseError;"));
2056         CHECK(LDKAPIError_APIMisuseError_class != NULL);
2057         LDKAPIError_APIMisuseError_meth = (*env)->GetMethodID(env, LDKAPIError_APIMisuseError_class, "<init>", "([B)V");
2058         CHECK(LDKAPIError_APIMisuseError_meth != NULL);
2059         LDKAPIError_FeeRateTooHigh_class =
2060                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKAPIError$FeeRateTooHigh;"));
2061         CHECK(LDKAPIError_FeeRateTooHigh_class != NULL);
2062         LDKAPIError_FeeRateTooHigh_meth = (*env)->GetMethodID(env, LDKAPIError_FeeRateTooHigh_class, "<init>", "([BI)V");
2063         CHECK(LDKAPIError_FeeRateTooHigh_meth != NULL);
2064         LDKAPIError_RouteError_class =
2065                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKAPIError$RouteError;"));
2066         CHECK(LDKAPIError_RouteError_class != NULL);
2067         LDKAPIError_RouteError_meth = (*env)->GetMethodID(env, LDKAPIError_RouteError_class, "<init>", "(Ljava/lang/String;)V");
2068         CHECK(LDKAPIError_RouteError_meth != NULL);
2069         LDKAPIError_ChannelUnavailable_class =
2070                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKAPIError$ChannelUnavailable;"));
2071         CHECK(LDKAPIError_ChannelUnavailable_class != NULL);
2072         LDKAPIError_ChannelUnavailable_meth = (*env)->GetMethodID(env, LDKAPIError_ChannelUnavailable_class, "<init>", "([B)V");
2073         CHECK(LDKAPIError_ChannelUnavailable_meth != NULL);
2074         LDKAPIError_MonitorUpdateFailed_class =
2075                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKAPIError$MonitorUpdateFailed;"));
2076         CHECK(LDKAPIError_MonitorUpdateFailed_class != NULL);
2077         LDKAPIError_MonitorUpdateFailed_meth = (*env)->GetMethodID(env, LDKAPIError_MonitorUpdateFailed_class, "<init>", "()V");
2078         CHECK(LDKAPIError_MonitorUpdateFailed_meth != NULL);
2079 }
2080 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKAPIError_1ref_1from_1ptr (JNIEnv *env, jclass clz, int64_t ptr) {
2081         LDKAPIError *obj = (LDKAPIError*)ptr;
2082         switch(obj->tag) {
2083                 case LDKAPIError_APIMisuseError: {
2084                         LDKCVec_u8Z err_var = obj->api_misuse_error.err;
2085                         int8_tArray err_arr = (*env)->NewByteArray(env, err_var.datalen);
2086                         (*env)->SetByteArrayRegion(env, err_arr, 0, err_var.datalen, err_var.data);
2087                         return (*env)->NewObject(env, LDKAPIError_APIMisuseError_class, LDKAPIError_APIMisuseError_meth, err_arr);
2088                 }
2089                 case LDKAPIError_FeeRateTooHigh: {
2090                         LDKCVec_u8Z err_var = obj->fee_rate_too_high.err;
2091                         int8_tArray err_arr = (*env)->NewByteArray(env, err_var.datalen);
2092                         (*env)->SetByteArrayRegion(env, err_arr, 0, err_var.datalen, err_var.data);
2093                         return (*env)->NewObject(env, LDKAPIError_FeeRateTooHigh_class, LDKAPIError_FeeRateTooHigh_meth, err_arr, obj->fee_rate_too_high.feerate);
2094                 }
2095                 case LDKAPIError_RouteError: {
2096                         LDKStr err_str = obj->route_error.err;
2097                         char* err_buf = MALLOC(err_str.len + 1, "str conv buf");
2098                         memcpy(err_buf, err_str.chars, err_str.len);
2099                         err_buf[err_str.len] = 0;
2100                         jstring err_conv = (*env)->NewStringUTF(env, err_str.chars);
2101                         FREE(err_buf);
2102                         return (*env)->NewObject(env, LDKAPIError_RouteError_class, LDKAPIError_RouteError_meth, err_conv);
2103                 }
2104                 case LDKAPIError_ChannelUnavailable: {
2105                         LDKCVec_u8Z err_var = obj->channel_unavailable.err;
2106                         int8_tArray err_arr = (*env)->NewByteArray(env, err_var.datalen);
2107                         (*env)->SetByteArrayRegion(env, err_arr, 0, err_var.datalen, err_var.data);
2108                         return (*env)->NewObject(env, LDKAPIError_ChannelUnavailable_class, LDKAPIError_ChannelUnavailable_meth, err_arr);
2109                 }
2110                 case LDKAPIError_MonitorUpdateFailed: {
2111                         return (*env)->NewObject(env, LDKAPIError_MonitorUpdateFailed_class, LDKAPIError_MonitorUpdateFailed_meth);
2112                 }
2113                 default: abort();
2114         }
2115 }
2116 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NoneAPIErrorZ_1result_1ok (JNIEnv *env, jclass clz, int64_t arg) {
2117         return ((LDKCResult_NoneAPIErrorZ*)arg)->result_ok;
2118 }
2119 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NoneAPIErrorZ_1get_1ok (JNIEnv *env, jclass clz, int64_t arg) {
2120         LDKCResult_NoneAPIErrorZ *val = (LDKCResult_NoneAPIErrorZ*)arg;
2121         CHECK(val->result_ok);
2122         return *val->contents.result;
2123 }
2124 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NoneAPIErrorZ_1get_1err (JNIEnv *env, jclass clz, int64_t arg) {
2125         LDKCResult_NoneAPIErrorZ *val = (LDKCResult_NoneAPIErrorZ*)arg;
2126         CHECK(!val->result_ok);
2127         long err_ref = (long)&(*val->contents.err);
2128         return err_ref;
2129 }
2130 static inline LDKCResult_NoneAPIErrorZ CResult_NoneAPIErrorZ_clone(const LDKCResult_NoneAPIErrorZ *orig) {
2131         LDKCResult_NoneAPIErrorZ res = { .result_ok = orig->result_ok };
2132         if (orig->result_ok) {
2133                 res.contents.result = NULL;
2134         } else {
2135                 LDKAPIError* contents = MALLOC(sizeof(LDKAPIError), "LDKAPIError result Err clone");
2136                 *contents = APIError_clone(orig->contents.err);
2137                 res.contents.err = contents;
2138         }
2139         return res;
2140 }
2141 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCVec_1ChannelDetailsZ_1new(JNIEnv *env, jclass clz, int64_tArray elems) {
2142         LDKCVec_ChannelDetailsZ *ret = MALLOC(sizeof(LDKCVec_ChannelDetailsZ), "LDKCVec_ChannelDetailsZ");
2143         ret->datalen = (*env)->GetArrayLength(env, elems);
2144         if (ret->datalen == 0) {
2145                 ret->data = NULL;
2146         } else {
2147                 ret->data = MALLOC(sizeof(LDKChannelDetails) * ret->datalen, "LDKCVec_ChannelDetailsZ Data");
2148                 int64_t *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
2149                 for (size_t i = 0; i < ret->datalen; i++) {
2150                         int64_t arr_elem = java_elems[i];
2151                         LDKChannelDetails arr_elem_conv;
2152                         arr_elem_conv.inner = (void*)(arr_elem & (~1));
2153                         arr_elem_conv.is_owned = (arr_elem & 1) || (arr_elem == 0);
2154                         if (arr_elem_conv.inner != NULL)
2155                                 arr_elem_conv = ChannelDetails_clone(&arr_elem_conv);
2156                         ret->data[i] = arr_elem_conv;
2157                 }
2158                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
2159         }
2160         return (long)ret;
2161 }
2162 static inline LDKCVec_ChannelDetailsZ CVec_ChannelDetailsZ_clone(const LDKCVec_ChannelDetailsZ *orig) {
2163         LDKCVec_ChannelDetailsZ ret = { .data = MALLOC(sizeof(LDKChannelDetails) * orig->datalen, "LDKCVec_ChannelDetailsZ clone bytes"), .datalen = orig->datalen };
2164         for (size_t i = 0; i < ret.datalen; i++) {
2165                 ret.data[i] = ChannelDetails_clone(&orig->data[i]);
2166         }
2167         return ret;
2168 }
2169 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NonePaymentSendFailureZ_1result_1ok (JNIEnv *env, jclass clz, int64_t arg) {
2170         return ((LDKCResult_NonePaymentSendFailureZ*)arg)->result_ok;
2171 }
2172 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NonePaymentSendFailureZ_1get_1ok (JNIEnv *env, jclass clz, int64_t arg) {
2173         LDKCResult_NonePaymentSendFailureZ *val = (LDKCResult_NonePaymentSendFailureZ*)arg;
2174         CHECK(val->result_ok);
2175         return *val->contents.result;
2176 }
2177 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NonePaymentSendFailureZ_1get_1err (JNIEnv *env, jclass clz, int64_t arg) {
2178         LDKCResult_NonePaymentSendFailureZ *val = (LDKCResult_NonePaymentSendFailureZ*)arg;
2179         CHECK(!val->result_ok);
2180         LDKPaymentSendFailure err_var = (*val->contents.err);
2181         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2182         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2183         long err_ref = (long)err_var.inner & ~1;
2184         return err_ref;
2185 }
2186 static jclass LDKNetAddress_IPv4_class = NULL;
2187 static jmethodID LDKNetAddress_IPv4_meth = NULL;
2188 static jclass LDKNetAddress_IPv6_class = NULL;
2189 static jmethodID LDKNetAddress_IPv6_meth = NULL;
2190 static jclass LDKNetAddress_OnionV2_class = NULL;
2191 static jmethodID LDKNetAddress_OnionV2_meth = NULL;
2192 static jclass LDKNetAddress_OnionV3_class = NULL;
2193 static jmethodID LDKNetAddress_OnionV3_meth = NULL;
2194 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_00024LDKNetAddress_init (JNIEnv *env, jclass clz) {
2195         LDKNetAddress_IPv4_class =
2196                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKNetAddress$IPv4;"));
2197         CHECK(LDKNetAddress_IPv4_class != NULL);
2198         LDKNetAddress_IPv4_meth = (*env)->GetMethodID(env, LDKNetAddress_IPv4_class, "<init>", "([BS)V");
2199         CHECK(LDKNetAddress_IPv4_meth != NULL);
2200         LDKNetAddress_IPv6_class =
2201                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKNetAddress$IPv6;"));
2202         CHECK(LDKNetAddress_IPv6_class != NULL);
2203         LDKNetAddress_IPv6_meth = (*env)->GetMethodID(env, LDKNetAddress_IPv6_class, "<init>", "([BS)V");
2204         CHECK(LDKNetAddress_IPv6_meth != NULL);
2205         LDKNetAddress_OnionV2_class =
2206                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKNetAddress$OnionV2;"));
2207         CHECK(LDKNetAddress_OnionV2_class != NULL);
2208         LDKNetAddress_OnionV2_meth = (*env)->GetMethodID(env, LDKNetAddress_OnionV2_class, "<init>", "([BS)V");
2209         CHECK(LDKNetAddress_OnionV2_meth != NULL);
2210         LDKNetAddress_OnionV3_class =
2211                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKNetAddress$OnionV3;"));
2212         CHECK(LDKNetAddress_OnionV3_class != NULL);
2213         LDKNetAddress_OnionV3_meth = (*env)->GetMethodID(env, LDKNetAddress_OnionV3_class, "<init>", "([BSBS)V");
2214         CHECK(LDKNetAddress_OnionV3_meth != NULL);
2215 }
2216 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKNetAddress_1ref_1from_1ptr (JNIEnv *env, jclass clz, int64_t ptr) {
2217         LDKNetAddress *obj = (LDKNetAddress*)ptr;
2218         switch(obj->tag) {
2219                 case LDKNetAddress_IPv4: {
2220                         int8_tArray addr_arr = (*env)->NewByteArray(env, 4);
2221                         (*env)->SetByteArrayRegion(env, addr_arr, 0, 4, obj->i_pv4.addr.data);
2222                         return (*env)->NewObject(env, LDKNetAddress_IPv4_class, LDKNetAddress_IPv4_meth, addr_arr, obj->i_pv4.port);
2223                 }
2224                 case LDKNetAddress_IPv6: {
2225                         int8_tArray addr_arr = (*env)->NewByteArray(env, 16);
2226                         (*env)->SetByteArrayRegion(env, addr_arr, 0, 16, obj->i_pv6.addr.data);
2227                         return (*env)->NewObject(env, LDKNetAddress_IPv6_class, LDKNetAddress_IPv6_meth, addr_arr, obj->i_pv6.port);
2228                 }
2229                 case LDKNetAddress_OnionV2: {
2230                         int8_tArray addr_arr = (*env)->NewByteArray(env, 10);
2231                         (*env)->SetByteArrayRegion(env, addr_arr, 0, 10, obj->onion_v2.addr.data);
2232                         return (*env)->NewObject(env, LDKNetAddress_OnionV2_class, LDKNetAddress_OnionV2_meth, addr_arr, obj->onion_v2.port);
2233                 }
2234                 case LDKNetAddress_OnionV3: {
2235                         int8_tArray ed25519_pubkey_arr = (*env)->NewByteArray(env, 32);
2236                         (*env)->SetByteArrayRegion(env, ed25519_pubkey_arr, 0, 32, obj->onion_v3.ed25519_pubkey.data);
2237                         return (*env)->NewObject(env, LDKNetAddress_OnionV3_class, LDKNetAddress_OnionV3_meth, ed25519_pubkey_arr, obj->onion_v3.checksum, obj->onion_v3.version, obj->onion_v3.port);
2238                 }
2239                 default: abort();
2240         }
2241 }
2242 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCVec_1NetAddressZ_1new(JNIEnv *env, jclass clz, int64_tArray elems) {
2243         LDKCVec_NetAddressZ *ret = MALLOC(sizeof(LDKCVec_NetAddressZ), "LDKCVec_NetAddressZ");
2244         ret->datalen = (*env)->GetArrayLength(env, elems);
2245         if (ret->datalen == 0) {
2246                 ret->data = NULL;
2247         } else {
2248                 ret->data = MALLOC(sizeof(LDKNetAddress) * ret->datalen, "LDKCVec_NetAddressZ Data");
2249                 int64_t *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
2250                 for (size_t i = 0; i < ret->datalen; i++) {
2251                         int64_t arr_elem = java_elems[i];
2252                         LDKNetAddress arr_elem_conv = *(LDKNetAddress*)arr_elem;
2253                         FREE((void*)arr_elem);
2254                         ret->data[i] = arr_elem_conv;
2255                 }
2256                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
2257         }
2258         return (long)ret;
2259 }
2260 static inline LDKCVec_NetAddressZ CVec_NetAddressZ_clone(const LDKCVec_NetAddressZ *orig) {
2261         LDKCVec_NetAddressZ ret = { .data = MALLOC(sizeof(LDKNetAddress) * orig->datalen, "LDKCVec_NetAddressZ clone bytes"), .datalen = orig->datalen };
2262         for (size_t i = 0; i < ret.datalen; i++) {
2263                 ret.data[i] = NetAddress_clone(&orig->data[i]);
2264         }
2265         return ret;
2266 }
2267 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCVec_1ChannelMonitorZ_1new(JNIEnv *env, jclass clz, int64_tArray elems) {
2268         LDKCVec_ChannelMonitorZ *ret = MALLOC(sizeof(LDKCVec_ChannelMonitorZ), "LDKCVec_ChannelMonitorZ");
2269         ret->datalen = (*env)->GetArrayLength(env, elems);
2270         if (ret->datalen == 0) {
2271                 ret->data = NULL;
2272         } else {
2273                 ret->data = MALLOC(sizeof(LDKChannelMonitor) * ret->datalen, "LDKCVec_ChannelMonitorZ Data");
2274                 int64_t *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
2275                 for (size_t i = 0; i < ret->datalen; i++) {
2276                         int64_t arr_elem = java_elems[i];
2277                         LDKChannelMonitor arr_elem_conv;
2278                         arr_elem_conv.inner = (void*)(arr_elem & (~1));
2279                         arr_elem_conv.is_owned = (arr_elem & 1) || (arr_elem == 0);
2280                         // Warning: we may need a move here but can't clone!
2281                         ret->data[i] = arr_elem_conv;
2282                 }
2283                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
2284         }
2285         return (long)ret;
2286 }
2287 typedef struct LDKWatch_JCalls {
2288         atomic_size_t refcnt;
2289         JavaVM *vm;
2290         jweak o;
2291         jmethodID watch_channel_meth;
2292         jmethodID update_channel_meth;
2293         jmethodID release_pending_monitor_events_meth;
2294 } LDKWatch_JCalls;
2295 static void LDKWatch_JCalls_free(void* this_arg) {
2296         LDKWatch_JCalls *j_calls = (LDKWatch_JCalls*) this_arg;
2297         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
2298                 JNIEnv *env;
2299                 DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
2300                 (*env)->DeleteWeakGlobalRef(env, j_calls->o);
2301                 FREE(j_calls);
2302         }
2303 }
2304 LDKCResult_NoneChannelMonitorUpdateErrZ watch_channel_jcall(const void* this_arg, LDKOutPoint funding_txo, LDKChannelMonitor monitor) {
2305         LDKWatch_JCalls *j_calls = (LDKWatch_JCalls*) this_arg;
2306         JNIEnv *env;
2307         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
2308         LDKOutPoint funding_txo_var = funding_txo;
2309         CHECK((((long)funding_txo_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2310         CHECK((((long)&funding_txo_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2311         long funding_txo_ref = (long)funding_txo_var.inner;
2312         if (funding_txo_var.is_owned) {
2313                 funding_txo_ref |= 1;
2314         }
2315         LDKChannelMonitor monitor_var = monitor;
2316         CHECK((((long)monitor_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2317         CHECK((((long)&monitor_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2318         long monitor_ref = (long)monitor_var.inner;
2319         if (monitor_var.is_owned) {
2320                 monitor_ref |= 1;
2321         }
2322         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
2323         CHECK(obj != NULL);
2324         LDKCResult_NoneChannelMonitorUpdateErrZ* ret = (LDKCResult_NoneChannelMonitorUpdateErrZ*)(*env)->CallLongMethod(env, obj, j_calls->watch_channel_meth, funding_txo_ref, monitor_ref);
2325         LDKCResult_NoneChannelMonitorUpdateErrZ ret_conv = *(LDKCResult_NoneChannelMonitorUpdateErrZ*)ret;
2326         FREE((void*)ret);
2327         return ret_conv;
2328 }
2329 LDKCResult_NoneChannelMonitorUpdateErrZ update_channel_jcall(const void* this_arg, LDKOutPoint funding_txo, LDKChannelMonitorUpdate update) {
2330         LDKWatch_JCalls *j_calls = (LDKWatch_JCalls*) this_arg;
2331         JNIEnv *env;
2332         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
2333         LDKOutPoint funding_txo_var = funding_txo;
2334         CHECK((((long)funding_txo_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2335         CHECK((((long)&funding_txo_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2336         long funding_txo_ref = (long)funding_txo_var.inner;
2337         if (funding_txo_var.is_owned) {
2338                 funding_txo_ref |= 1;
2339         }
2340         LDKChannelMonitorUpdate update_var = update;
2341         CHECK((((long)update_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2342         CHECK((((long)&update_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2343         long update_ref = (long)update_var.inner;
2344         if (update_var.is_owned) {
2345                 update_ref |= 1;
2346         }
2347         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
2348         CHECK(obj != NULL);
2349         LDKCResult_NoneChannelMonitorUpdateErrZ* ret = (LDKCResult_NoneChannelMonitorUpdateErrZ*)(*env)->CallLongMethod(env, obj, j_calls->update_channel_meth, funding_txo_ref, update_ref);
2350         LDKCResult_NoneChannelMonitorUpdateErrZ ret_conv = *(LDKCResult_NoneChannelMonitorUpdateErrZ*)ret;
2351         FREE((void*)ret);
2352         return ret_conv;
2353 }
2354 LDKCVec_MonitorEventZ release_pending_monitor_events_jcall(const void* this_arg) {
2355         LDKWatch_JCalls *j_calls = (LDKWatch_JCalls*) this_arg;
2356         JNIEnv *env;
2357         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
2358         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
2359         CHECK(obj != NULL);
2360         int64_tArray arg = (*env)->CallObjectMethod(env, obj, j_calls->release_pending_monitor_events_meth);
2361         LDKCVec_MonitorEventZ arg_constr;
2362         arg_constr.datalen = (*env)->GetArrayLength(env, arg);
2363         if (arg_constr.datalen > 0)
2364                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKMonitorEvent), "LDKCVec_MonitorEventZ Elements");
2365         else
2366                 arg_constr.data = NULL;
2367         int64_t* arg_vals = (*env)->GetLongArrayElements (env, arg, NULL);
2368         for (size_t o = 0; o < arg_constr.datalen; o++) {
2369                 int64_t arr_conv_14 = arg_vals[o];
2370                 LDKMonitorEvent arr_conv_14_conv;
2371                 arr_conv_14_conv.inner = (void*)(arr_conv_14 & (~1));
2372                 arr_conv_14_conv.is_owned = (arr_conv_14 & 1) || (arr_conv_14 == 0);
2373                 if (arr_conv_14_conv.inner != NULL)
2374                         arr_conv_14_conv = MonitorEvent_clone(&arr_conv_14_conv);
2375                 arg_constr.data[o] = arr_conv_14_conv;
2376         }
2377         (*env)->ReleaseLongArrayElements(env, arg, arg_vals, 0);
2378         return arg_constr;
2379 }
2380 static void* LDKWatch_JCalls_clone(const void* this_arg) {
2381         LDKWatch_JCalls *j_calls = (LDKWatch_JCalls*) this_arg;
2382         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
2383         return (void*) this_arg;
2384 }
2385 static inline LDKWatch LDKWatch_init (JNIEnv *env, jclass clz, jobject o) {
2386         jclass c = (*env)->GetObjectClass(env, o);
2387         CHECK(c != NULL);
2388         LDKWatch_JCalls *calls = MALLOC(sizeof(LDKWatch_JCalls), "LDKWatch_JCalls");
2389         atomic_init(&calls->refcnt, 1);
2390         DO_ASSERT((*env)->GetJavaVM(env, &calls->vm) == 0);
2391         calls->o = (*env)->NewWeakGlobalRef(env, o);
2392         calls->watch_channel_meth = (*env)->GetMethodID(env, c, "watch_channel", "(JJ)J");
2393         CHECK(calls->watch_channel_meth != NULL);
2394         calls->update_channel_meth = (*env)->GetMethodID(env, c, "update_channel", "(JJ)J");
2395         CHECK(calls->update_channel_meth != NULL);
2396         calls->release_pending_monitor_events_meth = (*env)->GetMethodID(env, c, "release_pending_monitor_events", "()[J");
2397         CHECK(calls->release_pending_monitor_events_meth != NULL);
2398
2399         LDKWatch ret = {
2400                 .this_arg = (void*) calls,
2401                 .watch_channel = watch_channel_jcall,
2402                 .update_channel = update_channel_jcall,
2403                 .release_pending_monitor_events = release_pending_monitor_events_jcall,
2404                 .free = LDKWatch_JCalls_free,
2405         };
2406         return ret;
2407 }
2408 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_LDKWatch_1new (JNIEnv *env, jclass clz, jobject o) {
2409         LDKWatch *res_ptr = MALLOC(sizeof(LDKWatch), "LDKWatch");
2410         *res_ptr = LDKWatch_init(env, clz, o);
2411         return (long)res_ptr;
2412 }
2413 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_Watch_1watch_1channel(JNIEnv *env, jclass clz, int64_t this_arg, int64_t funding_txo, int64_t monitor) {
2414         LDKWatch* this_arg_conv = (LDKWatch*)this_arg;
2415         LDKOutPoint funding_txo_conv;
2416         funding_txo_conv.inner = (void*)(funding_txo & (~1));
2417         funding_txo_conv.is_owned = (funding_txo & 1) || (funding_txo == 0);
2418         if (funding_txo_conv.inner != NULL)
2419                 funding_txo_conv = OutPoint_clone(&funding_txo_conv);
2420         LDKChannelMonitor monitor_conv;
2421         monitor_conv.inner = (void*)(monitor & (~1));
2422         monitor_conv.is_owned = (monitor & 1) || (monitor == 0);
2423         // Warning: we may need a move here but can't clone!
2424         LDKCResult_NoneChannelMonitorUpdateErrZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneChannelMonitorUpdateErrZ), "LDKCResult_NoneChannelMonitorUpdateErrZ");
2425         *ret_conv = (this_arg_conv->watch_channel)(this_arg_conv->this_arg, funding_txo_conv, monitor_conv);
2426         return (long)ret_conv;
2427 }
2428
2429 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_Watch_1update_1channel(JNIEnv *env, jclass clz, int64_t this_arg, int64_t funding_txo, int64_t update) {
2430         LDKWatch* this_arg_conv = (LDKWatch*)this_arg;
2431         LDKOutPoint funding_txo_conv;
2432         funding_txo_conv.inner = (void*)(funding_txo & (~1));
2433         funding_txo_conv.is_owned = (funding_txo & 1) || (funding_txo == 0);
2434         if (funding_txo_conv.inner != NULL)
2435                 funding_txo_conv = OutPoint_clone(&funding_txo_conv);
2436         LDKChannelMonitorUpdate update_conv;
2437         update_conv.inner = (void*)(update & (~1));
2438         update_conv.is_owned = (update & 1) || (update == 0);
2439         if (update_conv.inner != NULL)
2440                 update_conv = ChannelMonitorUpdate_clone(&update_conv);
2441         LDKCResult_NoneChannelMonitorUpdateErrZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneChannelMonitorUpdateErrZ), "LDKCResult_NoneChannelMonitorUpdateErrZ");
2442         *ret_conv = (this_arg_conv->update_channel)(this_arg_conv->this_arg, funding_txo_conv, update_conv);
2443         return (long)ret_conv;
2444 }
2445
2446 JNIEXPORT int64_tArray JNICALL Java_org_ldk_impl_bindings_Watch_1release_1pending_1monitor_1events(JNIEnv *env, jclass clz, int64_t this_arg) {
2447         LDKWatch* this_arg_conv = (LDKWatch*)this_arg;
2448         LDKCVec_MonitorEventZ ret_var = (this_arg_conv->release_pending_monitor_events)(this_arg_conv->this_arg);
2449         int64_tArray ret_arr = (*env)->NewLongArray(env, ret_var.datalen);
2450         int64_t *ret_arr_ptr = (*env)->GetPrimitiveArrayCritical(env, ret_arr, NULL);
2451         for (size_t o = 0; o < ret_var.datalen; o++) {
2452                 LDKMonitorEvent arr_conv_14_var = ret_var.data[o];
2453                 CHECK((((long)arr_conv_14_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2454                 CHECK((((long)&arr_conv_14_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2455                 long arr_conv_14_ref = (long)arr_conv_14_var.inner;
2456                 if (arr_conv_14_var.is_owned) {
2457                         arr_conv_14_ref |= 1;
2458                 }
2459                 ret_arr_ptr[o] = arr_conv_14_ref;
2460         }
2461         (*env)->ReleasePrimitiveArrayCritical(env, ret_arr, ret_arr_ptr, 0);
2462         FREE(ret_var.data);
2463         return ret_arr;
2464 }
2465
2466 typedef struct LDKBroadcasterInterface_JCalls {
2467         atomic_size_t refcnt;
2468         JavaVM *vm;
2469         jweak o;
2470         jmethodID broadcast_transaction_meth;
2471 } LDKBroadcasterInterface_JCalls;
2472 static void LDKBroadcasterInterface_JCalls_free(void* this_arg) {
2473         LDKBroadcasterInterface_JCalls *j_calls = (LDKBroadcasterInterface_JCalls*) this_arg;
2474         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
2475                 JNIEnv *env;
2476                 DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
2477                 (*env)->DeleteWeakGlobalRef(env, j_calls->o);
2478                 FREE(j_calls);
2479         }
2480 }
2481 void broadcast_transaction_jcall(const void* this_arg, LDKTransaction tx) {
2482         LDKBroadcasterInterface_JCalls *j_calls = (LDKBroadcasterInterface_JCalls*) this_arg;
2483         JNIEnv *env;
2484         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
2485         LDKTransaction tx_var = tx;
2486         int8_tArray tx_arr = (*env)->NewByteArray(env, tx_var.datalen);
2487         (*env)->SetByteArrayRegion(env, tx_arr, 0, tx_var.datalen, tx_var.data);
2488         Transaction_free(tx_var);
2489         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
2490         CHECK(obj != NULL);
2491         return (*env)->CallVoidMethod(env, obj, j_calls->broadcast_transaction_meth, tx_arr);
2492 }
2493 static void* LDKBroadcasterInterface_JCalls_clone(const void* this_arg) {
2494         LDKBroadcasterInterface_JCalls *j_calls = (LDKBroadcasterInterface_JCalls*) this_arg;
2495         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
2496         return (void*) this_arg;
2497 }
2498 static inline LDKBroadcasterInterface LDKBroadcasterInterface_init (JNIEnv *env, jclass clz, jobject o) {
2499         jclass c = (*env)->GetObjectClass(env, o);
2500         CHECK(c != NULL);
2501         LDKBroadcasterInterface_JCalls *calls = MALLOC(sizeof(LDKBroadcasterInterface_JCalls), "LDKBroadcasterInterface_JCalls");
2502         atomic_init(&calls->refcnt, 1);
2503         DO_ASSERT((*env)->GetJavaVM(env, &calls->vm) == 0);
2504         calls->o = (*env)->NewWeakGlobalRef(env, o);
2505         calls->broadcast_transaction_meth = (*env)->GetMethodID(env, c, "broadcast_transaction", "([B)V");
2506         CHECK(calls->broadcast_transaction_meth != NULL);
2507
2508         LDKBroadcasterInterface ret = {
2509                 .this_arg = (void*) calls,
2510                 .broadcast_transaction = broadcast_transaction_jcall,
2511                 .free = LDKBroadcasterInterface_JCalls_free,
2512         };
2513         return ret;
2514 }
2515 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_LDKBroadcasterInterface_1new (JNIEnv *env, jclass clz, jobject o) {
2516         LDKBroadcasterInterface *res_ptr = MALLOC(sizeof(LDKBroadcasterInterface), "LDKBroadcasterInterface");
2517         *res_ptr = LDKBroadcasterInterface_init(env, clz, o);
2518         return (long)res_ptr;
2519 }
2520 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_BroadcasterInterface_1broadcast_1transaction(JNIEnv *env, jclass clz, int64_t this_arg, int8_tArray tx) {
2521         LDKBroadcasterInterface* this_arg_conv = (LDKBroadcasterInterface*)this_arg;
2522         LDKTransaction tx_ref;
2523         tx_ref.datalen = (*env)->GetArrayLength(env, tx);
2524         tx_ref.data = MALLOC(tx_ref.datalen, "LDKTransaction Bytes");
2525         (*env)->GetByteArrayRegion(env, tx, 0, tx_ref.datalen, tx_ref.data);
2526         tx_ref.data_is_owned = true;
2527         (this_arg_conv->broadcast_transaction)(this_arg_conv->this_arg, tx_ref);
2528 }
2529
2530 typedef struct LDKKeysInterface_JCalls {
2531         atomic_size_t refcnt;
2532         JavaVM *vm;
2533         jweak o;
2534         jmethodID get_node_secret_meth;
2535         jmethodID get_destination_script_meth;
2536         jmethodID get_shutdown_pubkey_meth;
2537         jmethodID get_channel_keys_meth;
2538         jmethodID get_secure_random_bytes_meth;
2539         jmethodID read_chan_signer_meth;
2540 } LDKKeysInterface_JCalls;
2541 static void LDKKeysInterface_JCalls_free(void* this_arg) {
2542         LDKKeysInterface_JCalls *j_calls = (LDKKeysInterface_JCalls*) this_arg;
2543         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
2544                 JNIEnv *env;
2545                 DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
2546                 (*env)->DeleteWeakGlobalRef(env, j_calls->o);
2547                 FREE(j_calls);
2548         }
2549 }
2550 LDKSecretKey get_node_secret_jcall(const void* this_arg) {
2551         LDKKeysInterface_JCalls *j_calls = (LDKKeysInterface_JCalls*) this_arg;
2552         JNIEnv *env;
2553         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
2554         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
2555         CHECK(obj != NULL);
2556         int8_tArray arg = (*env)->CallObjectMethod(env, obj, j_calls->get_node_secret_meth);
2557         LDKSecretKey arg_ref;
2558         CHECK((*env)->GetArrayLength(env, arg) == 32);
2559         (*env)->GetByteArrayRegion(env, arg, 0, 32, arg_ref.bytes);
2560         return arg_ref;
2561 }
2562 LDKCVec_u8Z get_destination_script_jcall(const void* this_arg) {
2563         LDKKeysInterface_JCalls *j_calls = (LDKKeysInterface_JCalls*) this_arg;
2564         JNIEnv *env;
2565         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
2566         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
2567         CHECK(obj != NULL);
2568         int8_tArray arg = (*env)->CallObjectMethod(env, obj, j_calls->get_destination_script_meth);
2569         LDKCVec_u8Z arg_ref;
2570         arg_ref.datalen = (*env)->GetArrayLength(env, arg);
2571         arg_ref.data = MALLOC(arg_ref.datalen, "LDKCVec_u8Z Bytes");
2572         (*env)->GetByteArrayRegion(env, arg, 0, arg_ref.datalen, arg_ref.data);
2573         return arg_ref;
2574 }
2575 LDKPublicKey get_shutdown_pubkey_jcall(const void* this_arg) {
2576         LDKKeysInterface_JCalls *j_calls = (LDKKeysInterface_JCalls*) this_arg;
2577         JNIEnv *env;
2578         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
2579         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
2580         CHECK(obj != NULL);
2581         int8_tArray arg = (*env)->CallObjectMethod(env, obj, j_calls->get_shutdown_pubkey_meth);
2582         LDKPublicKey arg_ref;
2583         CHECK((*env)->GetArrayLength(env, arg) == 33);
2584         (*env)->GetByteArrayRegion(env, arg, 0, 33, arg_ref.compressed_form);
2585         return arg_ref;
2586 }
2587 LDKChannelKeys get_channel_keys_jcall(const void* this_arg, bool inbound, uint64_t channel_value_satoshis) {
2588         LDKKeysInterface_JCalls *j_calls = (LDKKeysInterface_JCalls*) this_arg;
2589         JNIEnv *env;
2590         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
2591         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
2592         CHECK(obj != NULL);
2593         LDKChannelKeys* ret = (LDKChannelKeys*)(*env)->CallLongMethod(env, obj, j_calls->get_channel_keys_meth, inbound, channel_value_satoshis);
2594         LDKChannelKeys ret_conv = *(LDKChannelKeys*)ret;
2595         ret_conv = ChannelKeys_clone(ret);
2596         return ret_conv;
2597 }
2598 LDKThirtyTwoBytes get_secure_random_bytes_jcall(const void* this_arg) {
2599         LDKKeysInterface_JCalls *j_calls = (LDKKeysInterface_JCalls*) this_arg;
2600         JNIEnv *env;
2601         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
2602         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
2603         CHECK(obj != NULL);
2604         int8_tArray arg = (*env)->CallObjectMethod(env, obj, j_calls->get_secure_random_bytes_meth);
2605         LDKThirtyTwoBytes arg_ref;
2606         CHECK((*env)->GetArrayLength(env, arg) == 32);
2607         (*env)->GetByteArrayRegion(env, arg, 0, 32, arg_ref.data);
2608         return arg_ref;
2609 }
2610 LDKCResult_ChanKeySignerDecodeErrorZ read_chan_signer_jcall(const void* this_arg, LDKu8slice reader) {
2611         LDKKeysInterface_JCalls *j_calls = (LDKKeysInterface_JCalls*) this_arg;
2612         JNIEnv *env;
2613         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
2614         LDKu8slice reader_var = reader;
2615         int8_tArray reader_arr = (*env)->NewByteArray(env, reader_var.datalen);
2616         (*env)->SetByteArrayRegion(env, reader_arr, 0, reader_var.datalen, reader_var.data);
2617         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
2618         CHECK(obj != NULL);
2619         LDKCResult_ChanKeySignerDecodeErrorZ* ret = (LDKCResult_ChanKeySignerDecodeErrorZ*)(*env)->CallLongMethod(env, obj, j_calls->read_chan_signer_meth, reader_arr);
2620         LDKCResult_ChanKeySignerDecodeErrorZ ret_conv = *(LDKCResult_ChanKeySignerDecodeErrorZ*)ret;
2621         FREE((void*)ret);
2622         return ret_conv;
2623 }
2624 static void* LDKKeysInterface_JCalls_clone(const void* this_arg) {
2625         LDKKeysInterface_JCalls *j_calls = (LDKKeysInterface_JCalls*) this_arg;
2626         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
2627         return (void*) this_arg;
2628 }
2629 static inline LDKKeysInterface LDKKeysInterface_init (JNIEnv *env, jclass clz, jobject o) {
2630         jclass c = (*env)->GetObjectClass(env, o);
2631         CHECK(c != NULL);
2632         LDKKeysInterface_JCalls *calls = MALLOC(sizeof(LDKKeysInterface_JCalls), "LDKKeysInterface_JCalls");
2633         atomic_init(&calls->refcnt, 1);
2634         DO_ASSERT((*env)->GetJavaVM(env, &calls->vm) == 0);
2635         calls->o = (*env)->NewWeakGlobalRef(env, o);
2636         calls->get_node_secret_meth = (*env)->GetMethodID(env, c, "get_node_secret", "()[B");
2637         CHECK(calls->get_node_secret_meth != NULL);
2638         calls->get_destination_script_meth = (*env)->GetMethodID(env, c, "get_destination_script", "()[B");
2639         CHECK(calls->get_destination_script_meth != NULL);
2640         calls->get_shutdown_pubkey_meth = (*env)->GetMethodID(env, c, "get_shutdown_pubkey", "()[B");
2641         CHECK(calls->get_shutdown_pubkey_meth != NULL);
2642         calls->get_channel_keys_meth = (*env)->GetMethodID(env, c, "get_channel_keys", "(ZJ)J");
2643         CHECK(calls->get_channel_keys_meth != NULL);
2644         calls->get_secure_random_bytes_meth = (*env)->GetMethodID(env, c, "get_secure_random_bytes", "()[B");
2645         CHECK(calls->get_secure_random_bytes_meth != NULL);
2646         calls->read_chan_signer_meth = (*env)->GetMethodID(env, c, "read_chan_signer", "([B)J");
2647         CHECK(calls->read_chan_signer_meth != NULL);
2648
2649         LDKKeysInterface ret = {
2650                 .this_arg = (void*) calls,
2651                 .get_node_secret = get_node_secret_jcall,
2652                 .get_destination_script = get_destination_script_jcall,
2653                 .get_shutdown_pubkey = get_shutdown_pubkey_jcall,
2654                 .get_channel_keys = get_channel_keys_jcall,
2655                 .get_secure_random_bytes = get_secure_random_bytes_jcall,
2656                 .read_chan_signer = read_chan_signer_jcall,
2657                 .free = LDKKeysInterface_JCalls_free,
2658         };
2659         return ret;
2660 }
2661 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_LDKKeysInterface_1new (JNIEnv *env, jclass clz, jobject o) {
2662         LDKKeysInterface *res_ptr = MALLOC(sizeof(LDKKeysInterface), "LDKKeysInterface");
2663         *res_ptr = LDKKeysInterface_init(env, clz, o);
2664         return (long)res_ptr;
2665 }
2666 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_KeysInterface_1get_1node_1secret(JNIEnv *env, jclass clz, int64_t this_arg) {
2667         LDKKeysInterface* this_arg_conv = (LDKKeysInterface*)this_arg;
2668         int8_tArray arg_arr = (*env)->NewByteArray(env, 32);
2669         (*env)->SetByteArrayRegion(env, arg_arr, 0, 32, (this_arg_conv->get_node_secret)(this_arg_conv->this_arg).bytes);
2670         return arg_arr;
2671 }
2672
2673 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_KeysInterface_1get_1destination_1script(JNIEnv *env, jclass clz, int64_t this_arg) {
2674         LDKKeysInterface* this_arg_conv = (LDKKeysInterface*)this_arg;
2675         LDKCVec_u8Z arg_var = (this_arg_conv->get_destination_script)(this_arg_conv->this_arg);
2676         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
2677         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
2678         CVec_u8Z_free(arg_var);
2679         return arg_arr;
2680 }
2681
2682 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_KeysInterface_1get_1shutdown_1pubkey(JNIEnv *env, jclass clz, int64_t this_arg) {
2683         LDKKeysInterface* this_arg_conv = (LDKKeysInterface*)this_arg;
2684         int8_tArray arg_arr = (*env)->NewByteArray(env, 33);
2685         (*env)->SetByteArrayRegion(env, arg_arr, 0, 33, (this_arg_conv->get_shutdown_pubkey)(this_arg_conv->this_arg).compressed_form);
2686         return arg_arr;
2687 }
2688
2689 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_KeysInterface_1get_1channel_1keys(JNIEnv *env, jclass clz, int64_t this_arg, jboolean inbound, int64_t channel_value_satoshis) {
2690         LDKKeysInterface* this_arg_conv = (LDKKeysInterface*)this_arg;
2691         LDKChannelKeys* ret = MALLOC(sizeof(LDKChannelKeys), "LDKChannelKeys");
2692         *ret = (this_arg_conv->get_channel_keys)(this_arg_conv->this_arg, inbound, channel_value_satoshis);
2693         return (long)ret;
2694 }
2695
2696 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_KeysInterface_1get_1secure_1random_1bytes(JNIEnv *env, jclass clz, int64_t this_arg) {
2697         LDKKeysInterface* this_arg_conv = (LDKKeysInterface*)this_arg;
2698         int8_tArray arg_arr = (*env)->NewByteArray(env, 32);
2699         (*env)->SetByteArrayRegion(env, arg_arr, 0, 32, (this_arg_conv->get_secure_random_bytes)(this_arg_conv->this_arg).data);
2700         return arg_arr;
2701 }
2702
2703 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_KeysInterface_1read_1chan_1signer(JNIEnv *env, jclass clz, int64_t this_arg, int8_tArray reader) {
2704         LDKKeysInterface* this_arg_conv = (LDKKeysInterface*)this_arg;
2705         LDKu8slice reader_ref;
2706         reader_ref.datalen = (*env)->GetArrayLength(env, reader);
2707         reader_ref.data = (*env)->GetByteArrayElements (env, reader, NULL);
2708         LDKCResult_ChanKeySignerDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ChanKeySignerDecodeErrorZ), "LDKCResult_ChanKeySignerDecodeErrorZ");
2709         *ret_conv = (this_arg_conv->read_chan_signer)(this_arg_conv->this_arg, reader_ref);
2710         (*env)->ReleaseByteArrayElements(env, reader, (int8_t*)reader_ref.data, 0);
2711         return (long)ret_conv;
2712 }
2713
2714 typedef struct LDKFeeEstimator_JCalls {
2715         atomic_size_t refcnt;
2716         JavaVM *vm;
2717         jweak o;
2718         jmethodID get_est_sat_per_1000_weight_meth;
2719 } LDKFeeEstimator_JCalls;
2720 static void LDKFeeEstimator_JCalls_free(void* this_arg) {
2721         LDKFeeEstimator_JCalls *j_calls = (LDKFeeEstimator_JCalls*) this_arg;
2722         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
2723                 JNIEnv *env;
2724                 DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
2725                 (*env)->DeleteWeakGlobalRef(env, j_calls->o);
2726                 FREE(j_calls);
2727         }
2728 }
2729 uint32_t get_est_sat_per_1000_weight_jcall(const void* this_arg, LDKConfirmationTarget confirmation_target) {
2730         LDKFeeEstimator_JCalls *j_calls = (LDKFeeEstimator_JCalls*) this_arg;
2731         JNIEnv *env;
2732         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
2733         jclass confirmation_target_conv = LDKConfirmationTarget_to_java(env, confirmation_target);
2734         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
2735         CHECK(obj != NULL);
2736         return (*env)->CallIntMethod(env, obj, j_calls->get_est_sat_per_1000_weight_meth, confirmation_target_conv);
2737 }
2738 static void* LDKFeeEstimator_JCalls_clone(const void* this_arg) {
2739         LDKFeeEstimator_JCalls *j_calls = (LDKFeeEstimator_JCalls*) this_arg;
2740         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
2741         return (void*) this_arg;
2742 }
2743 static inline LDKFeeEstimator LDKFeeEstimator_init (JNIEnv *env, jclass clz, jobject o) {
2744         jclass c = (*env)->GetObjectClass(env, o);
2745         CHECK(c != NULL);
2746         LDKFeeEstimator_JCalls *calls = MALLOC(sizeof(LDKFeeEstimator_JCalls), "LDKFeeEstimator_JCalls");
2747         atomic_init(&calls->refcnt, 1);
2748         DO_ASSERT((*env)->GetJavaVM(env, &calls->vm) == 0);
2749         calls->o = (*env)->NewWeakGlobalRef(env, o);
2750         calls->get_est_sat_per_1000_weight_meth = (*env)->GetMethodID(env, c, "get_est_sat_per_1000_weight", "(Lorg/ldk/enums/LDKConfirmationTarget;)I");
2751         CHECK(calls->get_est_sat_per_1000_weight_meth != NULL);
2752
2753         LDKFeeEstimator ret = {
2754                 .this_arg = (void*) calls,
2755                 .get_est_sat_per_1000_weight = get_est_sat_per_1000_weight_jcall,
2756                 .free = LDKFeeEstimator_JCalls_free,
2757         };
2758         return ret;
2759 }
2760 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_LDKFeeEstimator_1new (JNIEnv *env, jclass clz, jobject o) {
2761         LDKFeeEstimator *res_ptr = MALLOC(sizeof(LDKFeeEstimator), "LDKFeeEstimator");
2762         *res_ptr = LDKFeeEstimator_init(env, clz, o);
2763         return (long)res_ptr;
2764 }
2765 JNIEXPORT int32_t JNICALL Java_org_ldk_impl_bindings_FeeEstimator_1get_1est_1sat_1per_11000_1weight(JNIEnv *env, jclass clz, int64_t this_arg, jclass confirmation_target) {
2766         LDKFeeEstimator* this_arg_conv = (LDKFeeEstimator*)this_arg;
2767         LDKConfirmationTarget confirmation_target_conv = LDKConfirmationTarget_from_java(env, confirmation_target);
2768         int32_t ret_val = (this_arg_conv->get_est_sat_per_1000_weight)(this_arg_conv->this_arg, confirmation_target_conv);
2769         return ret_val;
2770 }
2771
2772 typedef struct LDKLogger_JCalls {
2773         atomic_size_t refcnt;
2774         JavaVM *vm;
2775         jweak o;
2776         jmethodID log_meth;
2777 } LDKLogger_JCalls;
2778 static void LDKLogger_JCalls_free(void* this_arg) {
2779         LDKLogger_JCalls *j_calls = (LDKLogger_JCalls*) this_arg;
2780         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
2781                 JNIEnv *env;
2782                 DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
2783                 (*env)->DeleteWeakGlobalRef(env, j_calls->o);
2784                 FREE(j_calls);
2785         }
2786 }
2787 void log_jcall(const void* this_arg, const char* record) {
2788         LDKLogger_JCalls *j_calls = (LDKLogger_JCalls*) this_arg;
2789         JNIEnv *env;
2790         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
2791         jstring record_conv = (*env)->NewStringUTF(env, record);
2792         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
2793         CHECK(obj != NULL);
2794         return (*env)->CallVoidMethod(env, obj, j_calls->log_meth, record_conv);
2795 }
2796 static void* LDKLogger_JCalls_clone(const void* this_arg) {
2797         LDKLogger_JCalls *j_calls = (LDKLogger_JCalls*) this_arg;
2798         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
2799         return (void*) this_arg;
2800 }
2801 static inline LDKLogger LDKLogger_init (JNIEnv *env, jclass clz, jobject o) {
2802         jclass c = (*env)->GetObjectClass(env, o);
2803         CHECK(c != NULL);
2804         LDKLogger_JCalls *calls = MALLOC(sizeof(LDKLogger_JCalls), "LDKLogger_JCalls");
2805         atomic_init(&calls->refcnt, 1);
2806         DO_ASSERT((*env)->GetJavaVM(env, &calls->vm) == 0);
2807         calls->o = (*env)->NewWeakGlobalRef(env, o);
2808         calls->log_meth = (*env)->GetMethodID(env, c, "log", "(Ljava/lang/String;)V");
2809         CHECK(calls->log_meth != NULL);
2810
2811         LDKLogger ret = {
2812                 .this_arg = (void*) calls,
2813                 .log = log_jcall,
2814                 .free = LDKLogger_JCalls_free,
2815         };
2816         return ret;
2817 }
2818 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_LDKLogger_1new (JNIEnv *env, jclass clz, jobject o) {
2819         LDKLogger *res_ptr = MALLOC(sizeof(LDKLogger), "LDKLogger");
2820         *res_ptr = LDKLogger_init(env, clz, o);
2821         return (long)res_ptr;
2822 }
2823 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKC2Tuple_1BlockHashChannelManagerZ_1new(JNIEnv *env, jclass clz, int8_tArray a, int64_t b) {
2824         LDKC2Tuple_BlockHashChannelManagerZ* ret = MALLOC(sizeof(LDKC2Tuple_BlockHashChannelManagerZ), "LDKC2Tuple_BlockHashChannelManagerZ");
2825         LDKThirtyTwoBytes a_ref;
2826         CHECK((*env)->GetArrayLength(env, a) == 32);
2827         (*env)->GetByteArrayRegion(env, a, 0, 32, a_ref.data);
2828         ret->a = a_ref;
2829         LDKChannelManager b_conv;
2830         b_conv.inner = (void*)(b & (~1));
2831         b_conv.is_owned = (b & 1) || (b == 0);
2832         // Warning: we may need a move here but can't clone!
2833         ret->b = b_conv;
2834         return (long)ret;
2835 }
2836 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_LDKC2Tuple_1BlockHashChannelManagerZ_1get_1a(JNIEnv *env, jclass clz, int64_t ptr) {
2837         LDKC2Tuple_BlockHashChannelManagerZ *tuple = (LDKC2Tuple_BlockHashChannelManagerZ*)ptr;
2838         int8_tArray a_arr = (*env)->NewByteArray(env, 32);
2839         (*env)->SetByteArrayRegion(env, a_arr, 0, 32, tuple->a.data);
2840         return a_arr;
2841 }
2842 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKC2Tuple_1BlockHashChannelManagerZ_1get_1b(JNIEnv *env, jclass clz, int64_t ptr) {
2843         LDKC2Tuple_BlockHashChannelManagerZ *tuple = (LDKC2Tuple_BlockHashChannelManagerZ*)ptr;
2844         LDKChannelManager b_var = tuple->b;
2845         CHECK((((long)b_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2846         CHECK((((long)&b_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2847         long b_ref = (long)b_var.inner & ~1;
2848         return b_ref;
2849 }
2850 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1C2Tuple_1BlockHashChannelManagerZDecodeErrorZ_1result_1ok (JNIEnv *env, jclass clz, int64_t arg) {
2851         return ((LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ*)arg)->result_ok;
2852 }
2853 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1C2Tuple_1BlockHashChannelManagerZDecodeErrorZ_1get_1ok (JNIEnv *env, jclass clz, int64_t arg) {
2854         LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ *val = (LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ*)arg;
2855         CHECK(val->result_ok);
2856         long res_ref = (long)&(*val->contents.result);
2857         return res_ref;
2858 }
2859 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1C2Tuple_1BlockHashChannelManagerZDecodeErrorZ_1get_1err (JNIEnv *env, jclass clz, int64_t arg) {
2860         LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ *val = (LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ*)arg;
2861         CHECK(!val->result_ok);
2862         LDKDecodeError err_var = (*val->contents.err);
2863         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2864         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2865         long err_ref = (long)err_var.inner & ~1;
2866         return err_ref;
2867 }
2868 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NetAddressu8Z_1result_1ok (JNIEnv *env, jclass clz, int64_t arg) {
2869         return ((LDKCResult_NetAddressu8Z*)arg)->result_ok;
2870 }
2871 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NetAddressu8Z_1get_1ok (JNIEnv *env, jclass clz, int64_t arg) {
2872         LDKCResult_NetAddressu8Z *val = (LDKCResult_NetAddressu8Z*)arg;
2873         CHECK(val->result_ok);
2874         long res_ref = (long)&(*val->contents.result);
2875         return res_ref;
2876 }
2877 JNIEXPORT int8_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NetAddressu8Z_1get_1err (JNIEnv *env, jclass clz, int64_t arg) {
2878         LDKCResult_NetAddressu8Z *val = (LDKCResult_NetAddressu8Z*)arg;
2879         CHECK(!val->result_ok);
2880         return *val->contents.err;
2881 }
2882 static inline LDKCResult_NetAddressu8Z CResult_NetAddressu8Z_clone(const LDKCResult_NetAddressu8Z *orig) {
2883         LDKCResult_NetAddressu8Z res = { .result_ok = orig->result_ok };
2884         if (orig->result_ok) {
2885                 LDKNetAddress* contents = MALLOC(sizeof(LDKNetAddress), "LDKNetAddress result OK clone");
2886                 *contents = NetAddress_clone(orig->contents.result);
2887                 res.contents.result = contents;
2888         } else {
2889                 int8_t* contents = MALLOC(sizeof(int8_t), "int8_t result Err clone");
2890                 *contents = *orig->contents.err;
2891                 res.contents.err = contents;
2892         }
2893         return res;
2894 }
2895 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1CResult_1NetAddressu8ZDecodeErrorZ_1result_1ok (JNIEnv *env, jclass clz, int64_t arg) {
2896         return ((LDKCResult_CResult_NetAddressu8ZDecodeErrorZ*)arg)->result_ok;
2897 }
2898 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1CResult_1NetAddressu8ZDecodeErrorZ_1get_1ok (JNIEnv *env, jclass clz, int64_t arg) {
2899         LDKCResult_CResult_NetAddressu8ZDecodeErrorZ *val = (LDKCResult_CResult_NetAddressu8ZDecodeErrorZ*)arg;
2900         CHECK(val->result_ok);
2901         LDKCResult_NetAddressu8Z* res_conv = MALLOC(sizeof(LDKCResult_NetAddressu8Z), "LDKCResult_NetAddressu8Z");
2902         *res_conv = (*val->contents.result);
2903         *res_conv = CResult_NetAddressu8Z_clone(res_conv);
2904         return (long)res_conv;
2905 }
2906 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1CResult_1NetAddressu8ZDecodeErrorZ_1get_1err (JNIEnv *env, jclass clz, int64_t arg) {
2907         LDKCResult_CResult_NetAddressu8ZDecodeErrorZ *val = (LDKCResult_CResult_NetAddressu8ZDecodeErrorZ*)arg;
2908         CHECK(!val->result_ok);
2909         LDKDecodeError err_var = (*val->contents.err);
2910         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2911         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2912         long err_ref = (long)err_var.inner & ~1;
2913         return err_ref;
2914 }
2915 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCVec_1u64Z_1new(JNIEnv *env, jclass clz, int64_tArray elems) {
2916         LDKCVec_u64Z *ret = MALLOC(sizeof(LDKCVec_u64Z), "LDKCVec_u64Z");
2917         ret->datalen = (*env)->GetArrayLength(env, elems);
2918         if (ret->datalen == 0) {
2919                 ret->data = NULL;
2920         } else {
2921                 ret->data = MALLOC(sizeof(uint64_t) * ret->datalen, "LDKCVec_u64Z Data");
2922                 int64_t *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
2923                 for (size_t i = 0; i < ret->datalen; i++) {
2924                         ret->data[i] = java_elems[i];
2925                 }
2926                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
2927         }
2928         return (long)ret;
2929 }
2930 static inline LDKCVec_u64Z CVec_u64Z_clone(const LDKCVec_u64Z *orig) {
2931         LDKCVec_u64Z ret = { .data = MALLOC(sizeof(int64_t) * orig->datalen, "LDKCVec_u64Z clone bytes"), .datalen = orig->datalen };
2932         memcpy(ret.data, orig->data, sizeof(int64_t) * ret.datalen);
2933         return ret;
2934 }
2935 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCVec_1UpdateAddHTLCZ_1new(JNIEnv *env, jclass clz, int64_tArray elems) {
2936         LDKCVec_UpdateAddHTLCZ *ret = MALLOC(sizeof(LDKCVec_UpdateAddHTLCZ), "LDKCVec_UpdateAddHTLCZ");
2937         ret->datalen = (*env)->GetArrayLength(env, elems);
2938         if (ret->datalen == 0) {
2939                 ret->data = NULL;
2940         } else {
2941                 ret->data = MALLOC(sizeof(LDKUpdateAddHTLC) * ret->datalen, "LDKCVec_UpdateAddHTLCZ Data");
2942                 int64_t *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
2943                 for (size_t i = 0; i < ret->datalen; i++) {
2944                         int64_t arr_elem = java_elems[i];
2945                         LDKUpdateAddHTLC arr_elem_conv;
2946                         arr_elem_conv.inner = (void*)(arr_elem & (~1));
2947                         arr_elem_conv.is_owned = (arr_elem & 1) || (arr_elem == 0);
2948                         if (arr_elem_conv.inner != NULL)
2949                                 arr_elem_conv = UpdateAddHTLC_clone(&arr_elem_conv);
2950                         ret->data[i] = arr_elem_conv;
2951                 }
2952                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
2953         }
2954         return (long)ret;
2955 }
2956 static inline LDKCVec_UpdateAddHTLCZ CVec_UpdateAddHTLCZ_clone(const LDKCVec_UpdateAddHTLCZ *orig) {
2957         LDKCVec_UpdateAddHTLCZ ret = { .data = MALLOC(sizeof(LDKUpdateAddHTLC) * orig->datalen, "LDKCVec_UpdateAddHTLCZ clone bytes"), .datalen = orig->datalen };
2958         for (size_t i = 0; i < ret.datalen; i++) {
2959                 ret.data[i] = UpdateAddHTLC_clone(&orig->data[i]);
2960         }
2961         return ret;
2962 }
2963 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCVec_1UpdateFulfillHTLCZ_1new(JNIEnv *env, jclass clz, int64_tArray elems) {
2964         LDKCVec_UpdateFulfillHTLCZ *ret = MALLOC(sizeof(LDKCVec_UpdateFulfillHTLCZ), "LDKCVec_UpdateFulfillHTLCZ");
2965         ret->datalen = (*env)->GetArrayLength(env, elems);
2966         if (ret->datalen == 0) {
2967                 ret->data = NULL;
2968         } else {
2969                 ret->data = MALLOC(sizeof(LDKUpdateFulfillHTLC) * ret->datalen, "LDKCVec_UpdateFulfillHTLCZ Data");
2970                 int64_t *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
2971                 for (size_t i = 0; i < ret->datalen; i++) {
2972                         int64_t arr_elem = java_elems[i];
2973                         LDKUpdateFulfillHTLC arr_elem_conv;
2974                         arr_elem_conv.inner = (void*)(arr_elem & (~1));
2975                         arr_elem_conv.is_owned = (arr_elem & 1) || (arr_elem == 0);
2976                         if (arr_elem_conv.inner != NULL)
2977                                 arr_elem_conv = UpdateFulfillHTLC_clone(&arr_elem_conv);
2978                         ret->data[i] = arr_elem_conv;
2979                 }
2980                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
2981         }
2982         return (long)ret;
2983 }
2984 static inline LDKCVec_UpdateFulfillHTLCZ CVec_UpdateFulfillHTLCZ_clone(const LDKCVec_UpdateFulfillHTLCZ *orig) {
2985         LDKCVec_UpdateFulfillHTLCZ ret = { .data = MALLOC(sizeof(LDKUpdateFulfillHTLC) * orig->datalen, "LDKCVec_UpdateFulfillHTLCZ clone bytes"), .datalen = orig->datalen };
2986         for (size_t i = 0; i < ret.datalen; i++) {
2987                 ret.data[i] = UpdateFulfillHTLC_clone(&orig->data[i]);
2988         }
2989         return ret;
2990 }
2991 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCVec_1UpdateFailHTLCZ_1new(JNIEnv *env, jclass clz, int64_tArray elems) {
2992         LDKCVec_UpdateFailHTLCZ *ret = MALLOC(sizeof(LDKCVec_UpdateFailHTLCZ), "LDKCVec_UpdateFailHTLCZ");
2993         ret->datalen = (*env)->GetArrayLength(env, elems);
2994         if (ret->datalen == 0) {
2995                 ret->data = NULL;
2996         } else {
2997                 ret->data = MALLOC(sizeof(LDKUpdateFailHTLC) * ret->datalen, "LDKCVec_UpdateFailHTLCZ Data");
2998                 int64_t *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
2999                 for (size_t i = 0; i < ret->datalen; i++) {
3000                         int64_t arr_elem = java_elems[i];
3001                         LDKUpdateFailHTLC arr_elem_conv;
3002                         arr_elem_conv.inner = (void*)(arr_elem & (~1));
3003                         arr_elem_conv.is_owned = (arr_elem & 1) || (arr_elem == 0);
3004                         if (arr_elem_conv.inner != NULL)
3005                                 arr_elem_conv = UpdateFailHTLC_clone(&arr_elem_conv);
3006                         ret->data[i] = arr_elem_conv;
3007                 }
3008                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
3009         }
3010         return (long)ret;
3011 }
3012 static inline LDKCVec_UpdateFailHTLCZ CVec_UpdateFailHTLCZ_clone(const LDKCVec_UpdateFailHTLCZ *orig) {
3013         LDKCVec_UpdateFailHTLCZ ret = { .data = MALLOC(sizeof(LDKUpdateFailHTLC) * orig->datalen, "LDKCVec_UpdateFailHTLCZ clone bytes"), .datalen = orig->datalen };
3014         for (size_t i = 0; i < ret.datalen; i++) {
3015                 ret.data[i] = UpdateFailHTLC_clone(&orig->data[i]);
3016         }
3017         return ret;
3018 }
3019 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCVec_1UpdateFailMalformedHTLCZ_1new(JNIEnv *env, jclass clz, int64_tArray elems) {
3020         LDKCVec_UpdateFailMalformedHTLCZ *ret = MALLOC(sizeof(LDKCVec_UpdateFailMalformedHTLCZ), "LDKCVec_UpdateFailMalformedHTLCZ");
3021         ret->datalen = (*env)->GetArrayLength(env, elems);
3022         if (ret->datalen == 0) {
3023                 ret->data = NULL;
3024         } else {
3025                 ret->data = MALLOC(sizeof(LDKUpdateFailMalformedHTLC) * ret->datalen, "LDKCVec_UpdateFailMalformedHTLCZ Data");
3026                 int64_t *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
3027                 for (size_t i = 0; i < ret->datalen; i++) {
3028                         int64_t arr_elem = java_elems[i];
3029                         LDKUpdateFailMalformedHTLC arr_elem_conv;
3030                         arr_elem_conv.inner = (void*)(arr_elem & (~1));
3031                         arr_elem_conv.is_owned = (arr_elem & 1) || (arr_elem == 0);
3032                         if (arr_elem_conv.inner != NULL)
3033                                 arr_elem_conv = UpdateFailMalformedHTLC_clone(&arr_elem_conv);
3034                         ret->data[i] = arr_elem_conv;
3035                 }
3036                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
3037         }
3038         return (long)ret;
3039 }
3040 static inline LDKCVec_UpdateFailMalformedHTLCZ CVec_UpdateFailMalformedHTLCZ_clone(const LDKCVec_UpdateFailMalformedHTLCZ *orig) {
3041         LDKCVec_UpdateFailMalformedHTLCZ ret = { .data = MALLOC(sizeof(LDKUpdateFailMalformedHTLC) * orig->datalen, "LDKCVec_UpdateFailMalformedHTLCZ clone bytes"), .datalen = orig->datalen };
3042         for (size_t i = 0; i < ret.datalen; i++) {
3043                 ret.data[i] = UpdateFailMalformedHTLC_clone(&orig->data[i]);
3044         }
3045         return ret;
3046 }
3047 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1boolLightningErrorZ_1result_1ok (JNIEnv *env, jclass clz, int64_t arg) {
3048         return ((LDKCResult_boolLightningErrorZ*)arg)->result_ok;
3049 }
3050 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1boolLightningErrorZ_1get_1ok (JNIEnv *env, jclass clz, int64_t arg) {
3051         LDKCResult_boolLightningErrorZ *val = (LDKCResult_boolLightningErrorZ*)arg;
3052         CHECK(val->result_ok);
3053         return *val->contents.result;
3054 }
3055 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1boolLightningErrorZ_1get_1err (JNIEnv *env, jclass clz, int64_t arg) {
3056         LDKCResult_boolLightningErrorZ *val = (LDKCResult_boolLightningErrorZ*)arg;
3057         CHECK(!val->result_ok);
3058         LDKLightningError err_var = (*val->contents.err);
3059         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3060         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3061         long err_ref = (long)err_var.inner & ~1;
3062         return err_ref;
3063 }
3064 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKC3Tuple_1ChannelAnnouncementChannelUpdateChannelUpdateZ_1new(JNIEnv *env, jclass clz, int64_t a, int64_t b, int64_t c) {
3065         LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ* ret = MALLOC(sizeof(LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ), "LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ");
3066         LDKChannelAnnouncement a_conv;
3067         a_conv.inner = (void*)(a & (~1));
3068         a_conv.is_owned = (a & 1) || (a == 0);
3069         if (a_conv.inner != NULL)
3070                 a_conv = ChannelAnnouncement_clone(&a_conv);
3071         ret->a = a_conv;
3072         LDKChannelUpdate b_conv;
3073         b_conv.inner = (void*)(b & (~1));
3074         b_conv.is_owned = (b & 1) || (b == 0);
3075         if (b_conv.inner != NULL)
3076                 b_conv = ChannelUpdate_clone(&b_conv);
3077         ret->b = b_conv;
3078         LDKChannelUpdate c_conv;
3079         c_conv.inner = (void*)(c & (~1));
3080         c_conv.is_owned = (c & 1) || (c == 0);
3081         if (c_conv.inner != NULL)
3082                 c_conv = ChannelUpdate_clone(&c_conv);
3083         ret->c = c_conv;
3084         return (long)ret;
3085 }
3086 static inline LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ_clone(const LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ *orig) {
3087         LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ ret = {
3088                 .a = ChannelAnnouncement_clone(&orig->a),
3089                 .b = ChannelUpdate_clone(&orig->b),
3090                 .c = ChannelUpdate_clone(&orig->c),
3091         };
3092         return ret;
3093 }
3094 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKC3Tuple_1ChannelAnnouncementChannelUpdateChannelUpdateZ_1get_1a(JNIEnv *env, jclass clz, int64_t ptr) {
3095         LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ *tuple = (LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ*)ptr;
3096         LDKChannelAnnouncement a_var = tuple->a;
3097         CHECK((((long)a_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3098         CHECK((((long)&a_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3099         long a_ref = (long)a_var.inner & ~1;
3100         return a_ref;
3101 }
3102 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKC3Tuple_1ChannelAnnouncementChannelUpdateChannelUpdateZ_1get_1b(JNIEnv *env, jclass clz, int64_t ptr) {
3103         LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ *tuple = (LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ*)ptr;
3104         LDKChannelUpdate b_var = tuple->b;
3105         CHECK((((long)b_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3106         CHECK((((long)&b_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3107         long b_ref = (long)b_var.inner & ~1;
3108         return b_ref;
3109 }
3110 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKC3Tuple_1ChannelAnnouncementChannelUpdateChannelUpdateZ_1get_1c(JNIEnv *env, jclass clz, int64_t ptr) {
3111         LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ *tuple = (LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ*)ptr;
3112         LDKChannelUpdate c_var = tuple->c;
3113         CHECK((((long)c_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3114         CHECK((((long)&c_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3115         long c_ref = (long)c_var.inner & ~1;
3116         return c_ref;
3117 }
3118 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCVec_1C3Tuple_1ChannelAnnouncementChannelUpdateChannelUpdateZZ_1new(JNIEnv *env, jclass clz, int64_tArray elems) {
3119         LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ *ret = MALLOC(sizeof(LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ), "LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ");
3120         ret->datalen = (*env)->GetArrayLength(env, elems);
3121         if (ret->datalen == 0) {
3122                 ret->data = NULL;
3123         } else {
3124                 ret->data = MALLOC(sizeof(LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ) * ret->datalen, "LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ Data");
3125                 int64_t *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
3126                 for (size_t i = 0; i < ret->datalen; i++) {
3127                         int64_t arr_elem = java_elems[i];
3128                         LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ arr_elem_conv = *(LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ*)arr_elem;
3129                         FREE((void*)arr_elem);
3130                         ret->data[i] = arr_elem_conv;
3131                 }
3132                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
3133         }
3134         return (long)ret;
3135 }
3136 static inline LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ CVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ_clone(const LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ *orig) {
3137         LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ ret = { .data = MALLOC(sizeof(LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ) * orig->datalen, "LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ clone bytes"), .datalen = orig->datalen };
3138         for (size_t i = 0; i < ret.datalen; i++) {
3139                 ret.data[i] = C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ_clone(&orig->data[i]);
3140         }
3141         return ret;
3142 }
3143 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCVec_1NodeAnnouncementZ_1new(JNIEnv *env, jclass clz, int64_tArray elems) {
3144         LDKCVec_NodeAnnouncementZ *ret = MALLOC(sizeof(LDKCVec_NodeAnnouncementZ), "LDKCVec_NodeAnnouncementZ");
3145         ret->datalen = (*env)->GetArrayLength(env, elems);
3146         if (ret->datalen == 0) {
3147                 ret->data = NULL;
3148         } else {
3149                 ret->data = MALLOC(sizeof(LDKNodeAnnouncement) * ret->datalen, "LDKCVec_NodeAnnouncementZ Data");
3150                 int64_t *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
3151                 for (size_t i = 0; i < ret->datalen; i++) {
3152                         int64_t arr_elem = java_elems[i];
3153                         LDKNodeAnnouncement arr_elem_conv;
3154                         arr_elem_conv.inner = (void*)(arr_elem & (~1));
3155                         arr_elem_conv.is_owned = (arr_elem & 1) || (arr_elem == 0);
3156                         if (arr_elem_conv.inner != NULL)
3157                                 arr_elem_conv = NodeAnnouncement_clone(&arr_elem_conv);
3158                         ret->data[i] = arr_elem_conv;
3159                 }
3160                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
3161         }
3162         return (long)ret;
3163 }
3164 static inline LDKCVec_NodeAnnouncementZ CVec_NodeAnnouncementZ_clone(const LDKCVec_NodeAnnouncementZ *orig) {
3165         LDKCVec_NodeAnnouncementZ ret = { .data = MALLOC(sizeof(LDKNodeAnnouncement) * orig->datalen, "LDKCVec_NodeAnnouncementZ clone bytes"), .datalen = orig->datalen };
3166         for (size_t i = 0; i < ret.datalen; i++) {
3167                 ret.data[i] = NodeAnnouncement_clone(&orig->data[i]);
3168         }
3169         return ret;
3170 }
3171 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NoneLightningErrorZ_1result_1ok (JNIEnv *env, jclass clz, int64_t arg) {
3172         return ((LDKCResult_NoneLightningErrorZ*)arg)->result_ok;
3173 }
3174 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NoneLightningErrorZ_1get_1ok (JNIEnv *env, jclass clz, int64_t arg) {
3175         LDKCResult_NoneLightningErrorZ *val = (LDKCResult_NoneLightningErrorZ*)arg;
3176         CHECK(val->result_ok);
3177         return *val->contents.result;
3178 }
3179 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NoneLightningErrorZ_1get_1err (JNIEnv *env, jclass clz, int64_t arg) {
3180         LDKCResult_NoneLightningErrorZ *val = (LDKCResult_NoneLightningErrorZ*)arg;
3181         CHECK(!val->result_ok);
3182         LDKLightningError err_var = (*val->contents.err);
3183         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3184         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3185         long err_ref = (long)err_var.inner & ~1;
3186         return err_ref;
3187 }
3188 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1ChannelReestablishDecodeErrorZ_1result_1ok (JNIEnv *env, jclass clz, int64_t arg) {
3189         return ((LDKCResult_ChannelReestablishDecodeErrorZ*)arg)->result_ok;
3190 }
3191 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1ChannelReestablishDecodeErrorZ_1get_1ok (JNIEnv *env, jclass clz, int64_t arg) {
3192         LDKCResult_ChannelReestablishDecodeErrorZ *val = (LDKCResult_ChannelReestablishDecodeErrorZ*)arg;
3193         CHECK(val->result_ok);
3194         LDKChannelReestablish res_var = (*val->contents.result);
3195         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3196         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3197         long res_ref = (long)res_var.inner & ~1;
3198         return res_ref;
3199 }
3200 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1ChannelReestablishDecodeErrorZ_1get_1err (JNIEnv *env, jclass clz, int64_t arg) {
3201         LDKCResult_ChannelReestablishDecodeErrorZ *val = (LDKCResult_ChannelReestablishDecodeErrorZ*)arg;
3202         CHECK(!val->result_ok);
3203         LDKDecodeError err_var = (*val->contents.err);
3204         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3205         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3206         long err_ref = (long)err_var.inner & ~1;
3207         return err_ref;
3208 }
3209 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1InitDecodeErrorZ_1result_1ok (JNIEnv *env, jclass clz, int64_t arg) {
3210         return ((LDKCResult_InitDecodeErrorZ*)arg)->result_ok;
3211 }
3212 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1InitDecodeErrorZ_1get_1ok (JNIEnv *env, jclass clz, int64_t arg) {
3213         LDKCResult_InitDecodeErrorZ *val = (LDKCResult_InitDecodeErrorZ*)arg;
3214         CHECK(val->result_ok);
3215         LDKInit res_var = (*val->contents.result);
3216         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3217         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3218         long res_ref = (long)res_var.inner & ~1;
3219         return res_ref;
3220 }
3221 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1InitDecodeErrorZ_1get_1err (JNIEnv *env, jclass clz, int64_t arg) {
3222         LDKCResult_InitDecodeErrorZ *val = (LDKCResult_InitDecodeErrorZ*)arg;
3223         CHECK(!val->result_ok);
3224         LDKDecodeError err_var = (*val->contents.err);
3225         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3226         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3227         long err_ref = (long)err_var.inner & ~1;
3228         return err_ref;
3229 }
3230 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1PingDecodeErrorZ_1result_1ok (JNIEnv *env, jclass clz, int64_t arg) {
3231         return ((LDKCResult_PingDecodeErrorZ*)arg)->result_ok;
3232 }
3233 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1PingDecodeErrorZ_1get_1ok (JNIEnv *env, jclass clz, int64_t arg) {
3234         LDKCResult_PingDecodeErrorZ *val = (LDKCResult_PingDecodeErrorZ*)arg;
3235         CHECK(val->result_ok);
3236         LDKPing res_var = (*val->contents.result);
3237         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3238         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3239         long res_ref = (long)res_var.inner & ~1;
3240         return res_ref;
3241 }
3242 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1PingDecodeErrorZ_1get_1err (JNIEnv *env, jclass clz, int64_t arg) {
3243         LDKCResult_PingDecodeErrorZ *val = (LDKCResult_PingDecodeErrorZ*)arg;
3244         CHECK(!val->result_ok);
3245         LDKDecodeError err_var = (*val->contents.err);
3246         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3247         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3248         long err_ref = (long)err_var.inner & ~1;
3249         return err_ref;
3250 }
3251 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1PongDecodeErrorZ_1result_1ok (JNIEnv *env, jclass clz, int64_t arg) {
3252         return ((LDKCResult_PongDecodeErrorZ*)arg)->result_ok;
3253 }
3254 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1PongDecodeErrorZ_1get_1ok (JNIEnv *env, jclass clz, int64_t arg) {
3255         LDKCResult_PongDecodeErrorZ *val = (LDKCResult_PongDecodeErrorZ*)arg;
3256         CHECK(val->result_ok);
3257         LDKPong res_var = (*val->contents.result);
3258         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3259         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3260         long res_ref = (long)res_var.inner & ~1;
3261         return res_ref;
3262 }
3263 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1PongDecodeErrorZ_1get_1err (JNIEnv *env, jclass clz, int64_t arg) {
3264         LDKCResult_PongDecodeErrorZ *val = (LDKCResult_PongDecodeErrorZ*)arg;
3265         CHECK(!val->result_ok);
3266         LDKDecodeError err_var = (*val->contents.err);
3267         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3268         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3269         long err_ref = (long)err_var.inner & ~1;
3270         return err_ref;
3271 }
3272 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1UnsignedChannelAnnouncementDecodeErrorZ_1result_1ok (JNIEnv *env, jclass clz, int64_t arg) {
3273         return ((LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ*)arg)->result_ok;
3274 }
3275 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1UnsignedChannelAnnouncementDecodeErrorZ_1get_1ok (JNIEnv *env, jclass clz, int64_t arg) {
3276         LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ *val = (LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ*)arg;
3277         CHECK(val->result_ok);
3278         LDKUnsignedChannelAnnouncement res_var = (*val->contents.result);
3279         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3280         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3281         long res_ref = (long)res_var.inner & ~1;
3282         return res_ref;
3283 }
3284 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1UnsignedChannelAnnouncementDecodeErrorZ_1get_1err (JNIEnv *env, jclass clz, int64_t arg) {
3285         LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ *val = (LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ*)arg;
3286         CHECK(!val->result_ok);
3287         LDKDecodeError err_var = (*val->contents.err);
3288         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3289         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3290         long err_ref = (long)err_var.inner & ~1;
3291         return err_ref;
3292 }
3293 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1UnsignedChannelUpdateDecodeErrorZ_1result_1ok (JNIEnv *env, jclass clz, int64_t arg) {
3294         return ((LDKCResult_UnsignedChannelUpdateDecodeErrorZ*)arg)->result_ok;
3295 }
3296 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1UnsignedChannelUpdateDecodeErrorZ_1get_1ok (JNIEnv *env, jclass clz, int64_t arg) {
3297         LDKCResult_UnsignedChannelUpdateDecodeErrorZ *val = (LDKCResult_UnsignedChannelUpdateDecodeErrorZ*)arg;
3298         CHECK(val->result_ok);
3299         LDKUnsignedChannelUpdate res_var = (*val->contents.result);
3300         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3301         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3302         long res_ref = (long)res_var.inner & ~1;
3303         return res_ref;
3304 }
3305 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1UnsignedChannelUpdateDecodeErrorZ_1get_1err (JNIEnv *env, jclass clz, int64_t arg) {
3306         LDKCResult_UnsignedChannelUpdateDecodeErrorZ *val = (LDKCResult_UnsignedChannelUpdateDecodeErrorZ*)arg;
3307         CHECK(!val->result_ok);
3308         LDKDecodeError err_var = (*val->contents.err);
3309         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3310         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3311         long err_ref = (long)err_var.inner & ~1;
3312         return err_ref;
3313 }
3314 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1ErrorMessageDecodeErrorZ_1result_1ok (JNIEnv *env, jclass clz, int64_t arg) {
3315         return ((LDKCResult_ErrorMessageDecodeErrorZ*)arg)->result_ok;
3316 }
3317 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1ErrorMessageDecodeErrorZ_1get_1ok (JNIEnv *env, jclass clz, int64_t arg) {
3318         LDKCResult_ErrorMessageDecodeErrorZ *val = (LDKCResult_ErrorMessageDecodeErrorZ*)arg;
3319         CHECK(val->result_ok);
3320         LDKErrorMessage res_var = (*val->contents.result);
3321         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3322         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3323         long res_ref = (long)res_var.inner & ~1;
3324         return res_ref;
3325 }
3326 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1ErrorMessageDecodeErrorZ_1get_1err (JNIEnv *env, jclass clz, int64_t arg) {
3327         LDKCResult_ErrorMessageDecodeErrorZ *val = (LDKCResult_ErrorMessageDecodeErrorZ*)arg;
3328         CHECK(!val->result_ok);
3329         LDKDecodeError err_var = (*val->contents.err);
3330         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3331         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3332         long err_ref = (long)err_var.inner & ~1;
3333         return err_ref;
3334 }
3335 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1UnsignedNodeAnnouncementDecodeErrorZ_1result_1ok (JNIEnv *env, jclass clz, int64_t arg) {
3336         return ((LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ*)arg)->result_ok;
3337 }
3338 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1UnsignedNodeAnnouncementDecodeErrorZ_1get_1ok (JNIEnv *env, jclass clz, int64_t arg) {
3339         LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ *val = (LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ*)arg;
3340         CHECK(val->result_ok);
3341         LDKUnsignedNodeAnnouncement res_var = (*val->contents.result);
3342         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3343         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3344         long res_ref = (long)res_var.inner & ~1;
3345         return res_ref;
3346 }
3347 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1UnsignedNodeAnnouncementDecodeErrorZ_1get_1err (JNIEnv *env, jclass clz, int64_t arg) {
3348         LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ *val = (LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ*)arg;
3349         CHECK(!val->result_ok);
3350         LDKDecodeError err_var = (*val->contents.err);
3351         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3352         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3353         long err_ref = (long)err_var.inner & ~1;
3354         return err_ref;
3355 }
3356 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1QueryShortChannelIdsDecodeErrorZ_1result_1ok (JNIEnv *env, jclass clz, int64_t arg) {
3357         return ((LDKCResult_QueryShortChannelIdsDecodeErrorZ*)arg)->result_ok;
3358 }
3359 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1QueryShortChannelIdsDecodeErrorZ_1get_1ok (JNIEnv *env, jclass clz, int64_t arg) {
3360         LDKCResult_QueryShortChannelIdsDecodeErrorZ *val = (LDKCResult_QueryShortChannelIdsDecodeErrorZ*)arg;
3361         CHECK(val->result_ok);
3362         LDKQueryShortChannelIds res_var = (*val->contents.result);
3363         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3364         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3365         long res_ref = (long)res_var.inner & ~1;
3366         return res_ref;
3367 }
3368 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1QueryShortChannelIdsDecodeErrorZ_1get_1err (JNIEnv *env, jclass clz, int64_t arg) {
3369         LDKCResult_QueryShortChannelIdsDecodeErrorZ *val = (LDKCResult_QueryShortChannelIdsDecodeErrorZ*)arg;
3370         CHECK(!val->result_ok);
3371         LDKDecodeError err_var = (*val->contents.err);
3372         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3373         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3374         long err_ref = (long)err_var.inner & ~1;
3375         return err_ref;
3376 }
3377 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1ReplyShortChannelIdsEndDecodeErrorZ_1result_1ok (JNIEnv *env, jclass clz, int64_t arg) {
3378         return ((LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ*)arg)->result_ok;
3379 }
3380 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1ReplyShortChannelIdsEndDecodeErrorZ_1get_1ok (JNIEnv *env, jclass clz, int64_t arg) {
3381         LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ *val = (LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ*)arg;
3382         CHECK(val->result_ok);
3383         LDKReplyShortChannelIdsEnd res_var = (*val->contents.result);
3384         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3385         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3386         long res_ref = (long)res_var.inner & ~1;
3387         return res_ref;
3388 }
3389 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1ReplyShortChannelIdsEndDecodeErrorZ_1get_1err (JNIEnv *env, jclass clz, int64_t arg) {
3390         LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ *val = (LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ*)arg;
3391         CHECK(!val->result_ok);
3392         LDKDecodeError err_var = (*val->contents.err);
3393         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3394         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3395         long err_ref = (long)err_var.inner & ~1;
3396         return err_ref;
3397 }
3398 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1QueryChannelRangeDecodeErrorZ_1result_1ok (JNIEnv *env, jclass clz, int64_t arg) {
3399         return ((LDKCResult_QueryChannelRangeDecodeErrorZ*)arg)->result_ok;
3400 }
3401 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1QueryChannelRangeDecodeErrorZ_1get_1ok (JNIEnv *env, jclass clz, int64_t arg) {
3402         LDKCResult_QueryChannelRangeDecodeErrorZ *val = (LDKCResult_QueryChannelRangeDecodeErrorZ*)arg;
3403         CHECK(val->result_ok);
3404         LDKQueryChannelRange res_var = (*val->contents.result);
3405         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3406         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3407         long res_ref = (long)res_var.inner & ~1;
3408         return res_ref;
3409 }
3410 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1QueryChannelRangeDecodeErrorZ_1get_1err (JNIEnv *env, jclass clz, int64_t arg) {
3411         LDKCResult_QueryChannelRangeDecodeErrorZ *val = (LDKCResult_QueryChannelRangeDecodeErrorZ*)arg;
3412         CHECK(!val->result_ok);
3413         LDKDecodeError err_var = (*val->contents.err);
3414         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3415         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3416         long err_ref = (long)err_var.inner & ~1;
3417         return err_ref;
3418 }
3419 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1ReplyChannelRangeDecodeErrorZ_1result_1ok (JNIEnv *env, jclass clz, int64_t arg) {
3420         return ((LDKCResult_ReplyChannelRangeDecodeErrorZ*)arg)->result_ok;
3421 }
3422 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1ReplyChannelRangeDecodeErrorZ_1get_1ok (JNIEnv *env, jclass clz, int64_t arg) {
3423         LDKCResult_ReplyChannelRangeDecodeErrorZ *val = (LDKCResult_ReplyChannelRangeDecodeErrorZ*)arg;
3424         CHECK(val->result_ok);
3425         LDKReplyChannelRange res_var = (*val->contents.result);
3426         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3427         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3428         long res_ref = (long)res_var.inner & ~1;
3429         return res_ref;
3430 }
3431 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1ReplyChannelRangeDecodeErrorZ_1get_1err (JNIEnv *env, jclass clz, int64_t arg) {
3432         LDKCResult_ReplyChannelRangeDecodeErrorZ *val = (LDKCResult_ReplyChannelRangeDecodeErrorZ*)arg;
3433         CHECK(!val->result_ok);
3434         LDKDecodeError err_var = (*val->contents.err);
3435         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3436         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3437         long err_ref = (long)err_var.inner & ~1;
3438         return err_ref;
3439 }
3440 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1GossipTimestampFilterDecodeErrorZ_1result_1ok (JNIEnv *env, jclass clz, int64_t arg) {
3441         return ((LDKCResult_GossipTimestampFilterDecodeErrorZ*)arg)->result_ok;
3442 }
3443 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1GossipTimestampFilterDecodeErrorZ_1get_1ok (JNIEnv *env, jclass clz, int64_t arg) {
3444         LDKCResult_GossipTimestampFilterDecodeErrorZ *val = (LDKCResult_GossipTimestampFilterDecodeErrorZ*)arg;
3445         CHECK(val->result_ok);
3446         LDKGossipTimestampFilter res_var = (*val->contents.result);
3447         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3448         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3449         long res_ref = (long)res_var.inner & ~1;
3450         return res_ref;
3451 }
3452 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1GossipTimestampFilterDecodeErrorZ_1get_1err (JNIEnv *env, jclass clz, int64_t arg) {
3453         LDKCResult_GossipTimestampFilterDecodeErrorZ *val = (LDKCResult_GossipTimestampFilterDecodeErrorZ*)arg;
3454         CHECK(!val->result_ok);
3455         LDKDecodeError err_var = (*val->contents.err);
3456         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3457         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3458         long err_ref = (long)err_var.inner & ~1;
3459         return err_ref;
3460 }
3461 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1CVec_1u8ZPeerHandleErrorZ_1result_1ok (JNIEnv *env, jclass clz, int64_t arg) {
3462         return ((LDKCResult_CVec_u8ZPeerHandleErrorZ*)arg)->result_ok;
3463 }
3464 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_LDKCResult_1CVec_1u8ZPeerHandleErrorZ_1get_1ok (JNIEnv *env, jclass clz, int64_t arg) {
3465         LDKCResult_CVec_u8ZPeerHandleErrorZ *val = (LDKCResult_CVec_u8ZPeerHandleErrorZ*)arg;
3466         CHECK(val->result_ok);
3467         LDKCVec_u8Z res_var = (*val->contents.result);
3468         int8_tArray res_arr = (*env)->NewByteArray(env, res_var.datalen);
3469         (*env)->SetByteArrayRegion(env, res_arr, 0, res_var.datalen, res_var.data);
3470         return res_arr;
3471 }
3472 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1CVec_1u8ZPeerHandleErrorZ_1get_1err (JNIEnv *env, jclass clz, int64_t arg) {
3473         LDKCResult_CVec_u8ZPeerHandleErrorZ *val = (LDKCResult_CVec_u8ZPeerHandleErrorZ*)arg;
3474         CHECK(!val->result_ok);
3475         LDKPeerHandleError err_var = (*val->contents.err);
3476         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3477         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3478         long err_ref = (long)err_var.inner & ~1;
3479         return err_ref;
3480 }
3481 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NonePeerHandleErrorZ_1result_1ok (JNIEnv *env, jclass clz, int64_t arg) {
3482         return ((LDKCResult_NonePeerHandleErrorZ*)arg)->result_ok;
3483 }
3484 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NonePeerHandleErrorZ_1get_1ok (JNIEnv *env, jclass clz, int64_t arg) {
3485         LDKCResult_NonePeerHandleErrorZ *val = (LDKCResult_NonePeerHandleErrorZ*)arg;
3486         CHECK(val->result_ok);
3487         return *val->contents.result;
3488 }
3489 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NonePeerHandleErrorZ_1get_1err (JNIEnv *env, jclass clz, int64_t arg) {
3490         LDKCResult_NonePeerHandleErrorZ *val = (LDKCResult_NonePeerHandleErrorZ*)arg;
3491         CHECK(!val->result_ok);
3492         LDKPeerHandleError err_var = (*val->contents.err);
3493         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3494         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3495         long err_ref = (long)err_var.inner & ~1;
3496         return err_ref;
3497 }
3498 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1boolPeerHandleErrorZ_1result_1ok (JNIEnv *env, jclass clz, int64_t arg) {
3499         return ((LDKCResult_boolPeerHandleErrorZ*)arg)->result_ok;
3500 }
3501 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1boolPeerHandleErrorZ_1get_1ok (JNIEnv *env, jclass clz, int64_t arg) {
3502         LDKCResult_boolPeerHandleErrorZ *val = (LDKCResult_boolPeerHandleErrorZ*)arg;
3503         CHECK(val->result_ok);
3504         return *val->contents.result;
3505 }
3506 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1boolPeerHandleErrorZ_1get_1err (JNIEnv *env, jclass clz, int64_t arg) {
3507         LDKCResult_boolPeerHandleErrorZ *val = (LDKCResult_boolPeerHandleErrorZ*)arg;
3508         CHECK(!val->result_ok);
3509         LDKPeerHandleError err_var = (*val->contents.err);
3510         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3511         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3512         long err_ref = (long)err_var.inner & ~1;
3513         return err_ref;
3514 }
3515 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1SecretKeySecpErrorZ_1result_1ok (JNIEnv *env, jclass clz, int64_t arg) {
3516         return ((LDKCResult_SecretKeySecpErrorZ*)arg)->result_ok;
3517 }
3518 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_LDKCResult_1SecretKeySecpErrorZ_1get_1ok (JNIEnv *env, jclass clz, int64_t arg) {
3519         LDKCResult_SecretKeySecpErrorZ *val = (LDKCResult_SecretKeySecpErrorZ*)arg;
3520         CHECK(val->result_ok);
3521         int8_tArray res_arr = (*env)->NewByteArray(env, 32);
3522         (*env)->SetByteArrayRegion(env, res_arr, 0, 32, (*val->contents.result).bytes);
3523         return res_arr;
3524 }
3525 JNIEXPORT jclass JNICALL Java_org_ldk_impl_bindings_LDKCResult_1SecretKeySecpErrorZ_1get_1err (JNIEnv *env, jclass clz, int64_t arg) {
3526         LDKCResult_SecretKeySecpErrorZ *val = (LDKCResult_SecretKeySecpErrorZ*)arg;
3527         CHECK(!val->result_ok);
3528         jclass err_conv = LDKSecp256k1Error_to_java(env, (*val->contents.err));
3529         return err_conv;
3530 }
3531 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1PublicKeySecpErrorZ_1result_1ok (JNIEnv *env, jclass clz, int64_t arg) {
3532         return ((LDKCResult_PublicKeySecpErrorZ*)arg)->result_ok;
3533 }
3534 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_LDKCResult_1PublicKeySecpErrorZ_1get_1ok (JNIEnv *env, jclass clz, int64_t arg) {
3535         LDKCResult_PublicKeySecpErrorZ *val = (LDKCResult_PublicKeySecpErrorZ*)arg;
3536         CHECK(val->result_ok);
3537         int8_tArray res_arr = (*env)->NewByteArray(env, 33);
3538         (*env)->SetByteArrayRegion(env, res_arr, 0, 33, (*val->contents.result).compressed_form);
3539         return res_arr;
3540 }
3541 JNIEXPORT jclass JNICALL Java_org_ldk_impl_bindings_LDKCResult_1PublicKeySecpErrorZ_1get_1err (JNIEnv *env, jclass clz, int64_t arg) {
3542         LDKCResult_PublicKeySecpErrorZ *val = (LDKCResult_PublicKeySecpErrorZ*)arg;
3543         CHECK(!val->result_ok);
3544         jclass err_conv = LDKSecp256k1Error_to_java(env, (*val->contents.err));
3545         return err_conv;
3546 }
3547 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1TxCreationKeysSecpErrorZ_1result_1ok (JNIEnv *env, jclass clz, int64_t arg) {
3548         return ((LDKCResult_TxCreationKeysSecpErrorZ*)arg)->result_ok;
3549 }
3550 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1TxCreationKeysSecpErrorZ_1get_1ok (JNIEnv *env, jclass clz, int64_t arg) {
3551         LDKCResult_TxCreationKeysSecpErrorZ *val = (LDKCResult_TxCreationKeysSecpErrorZ*)arg;
3552         CHECK(val->result_ok);
3553         LDKTxCreationKeys res_var = (*val->contents.result);
3554         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3555         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3556         long res_ref = (long)res_var.inner & ~1;
3557         return res_ref;
3558 }
3559 JNIEXPORT jclass JNICALL Java_org_ldk_impl_bindings_LDKCResult_1TxCreationKeysSecpErrorZ_1get_1err (JNIEnv *env, jclass clz, int64_t arg) {
3560         LDKCResult_TxCreationKeysSecpErrorZ *val = (LDKCResult_TxCreationKeysSecpErrorZ*)arg;
3561         CHECK(!val->result_ok);
3562         jclass err_conv = LDKSecp256k1Error_to_java(env, (*val->contents.err));
3563         return err_conv;
3564 }
3565 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1TrustedCommitmentTransactionNoneZ_1result_1ok (JNIEnv *env, jclass clz, int64_t arg) {
3566         return ((LDKCResult_TrustedCommitmentTransactionNoneZ*)arg)->result_ok;
3567 }
3568 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1TrustedCommitmentTransactionNoneZ_1get_1ok (JNIEnv *env, jclass clz, int64_t arg) {
3569         LDKCResult_TrustedCommitmentTransactionNoneZ *val = (LDKCResult_TrustedCommitmentTransactionNoneZ*)arg;
3570         CHECK(val->result_ok);
3571         LDKTrustedCommitmentTransaction res_var = (*val->contents.result);
3572         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3573         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3574         long res_ref = (long)res_var.inner & ~1;
3575         return res_ref;
3576 }
3577 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_LDKCResult_1TrustedCommitmentTransactionNoneZ_1get_1err (JNIEnv *env, jclass clz, int64_t arg) {
3578         LDKCResult_TrustedCommitmentTransactionNoneZ *val = (LDKCResult_TrustedCommitmentTransactionNoneZ*)arg;
3579         CHECK(!val->result_ok);
3580         return *val->contents.err;
3581 }
3582 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCVec_1RouteHopZ_1new(JNIEnv *env, jclass clz, int64_tArray elems) {
3583         LDKCVec_RouteHopZ *ret = MALLOC(sizeof(LDKCVec_RouteHopZ), "LDKCVec_RouteHopZ");
3584         ret->datalen = (*env)->GetArrayLength(env, elems);
3585         if (ret->datalen == 0) {
3586                 ret->data = NULL;
3587         } else {
3588                 ret->data = MALLOC(sizeof(LDKRouteHop) * ret->datalen, "LDKCVec_RouteHopZ Data");
3589                 int64_t *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
3590                 for (size_t i = 0; i < ret->datalen; i++) {
3591                         int64_t arr_elem = java_elems[i];
3592                         LDKRouteHop arr_elem_conv;
3593                         arr_elem_conv.inner = (void*)(arr_elem & (~1));
3594                         arr_elem_conv.is_owned = (arr_elem & 1) || (arr_elem == 0);
3595                         if (arr_elem_conv.inner != NULL)
3596                                 arr_elem_conv = RouteHop_clone(&arr_elem_conv);
3597                         ret->data[i] = arr_elem_conv;
3598                 }
3599                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
3600         }
3601         return (long)ret;
3602 }
3603 static inline LDKCVec_RouteHopZ CVec_RouteHopZ_clone(const LDKCVec_RouteHopZ *orig) {
3604         LDKCVec_RouteHopZ ret = { .data = MALLOC(sizeof(LDKRouteHop) * orig->datalen, "LDKCVec_RouteHopZ clone bytes"), .datalen = orig->datalen };
3605         for (size_t i = 0; i < ret.datalen; i++) {
3606                 ret.data[i] = RouteHop_clone(&orig->data[i]);
3607         }
3608         return ret;
3609 }
3610 static inline LDKCVec_CVec_RouteHopZZ CVec_CVec_RouteHopZZ_clone(const LDKCVec_CVec_RouteHopZZ *orig) {
3611         LDKCVec_CVec_RouteHopZZ ret = { .data = MALLOC(sizeof(LDKCVec_RouteHopZ) * orig->datalen, "LDKCVec_CVec_RouteHopZZ clone bytes"), .datalen = orig->datalen };
3612         for (size_t i = 0; i < ret.datalen; i++) {
3613                 ret.data[i] = CVec_RouteHopZ_clone(&orig->data[i]);
3614         }
3615         return ret;
3616 }
3617 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1RouteDecodeErrorZ_1result_1ok (JNIEnv *env, jclass clz, int64_t arg) {
3618         return ((LDKCResult_RouteDecodeErrorZ*)arg)->result_ok;
3619 }
3620 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1RouteDecodeErrorZ_1get_1ok (JNIEnv *env, jclass clz, int64_t arg) {
3621         LDKCResult_RouteDecodeErrorZ *val = (LDKCResult_RouteDecodeErrorZ*)arg;
3622         CHECK(val->result_ok);
3623         LDKRoute res_var = (*val->contents.result);
3624         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3625         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3626         long res_ref = (long)res_var.inner & ~1;
3627         return res_ref;
3628 }
3629 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1RouteDecodeErrorZ_1get_1err (JNIEnv *env, jclass clz, int64_t arg) {
3630         LDKCResult_RouteDecodeErrorZ *val = (LDKCResult_RouteDecodeErrorZ*)arg;
3631         CHECK(!val->result_ok);
3632         LDKDecodeError err_var = (*val->contents.err);
3633         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3634         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3635         long err_ref = (long)err_var.inner & ~1;
3636         return err_ref;
3637 }
3638 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCVec_1RouteHintZ_1new(JNIEnv *env, jclass clz, int64_tArray elems) {
3639         LDKCVec_RouteHintZ *ret = MALLOC(sizeof(LDKCVec_RouteHintZ), "LDKCVec_RouteHintZ");
3640         ret->datalen = (*env)->GetArrayLength(env, elems);
3641         if (ret->datalen == 0) {
3642                 ret->data = NULL;
3643         } else {
3644                 ret->data = MALLOC(sizeof(LDKRouteHint) * ret->datalen, "LDKCVec_RouteHintZ Data");
3645                 int64_t *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
3646                 for (size_t i = 0; i < ret->datalen; i++) {
3647                         int64_t arr_elem = java_elems[i];
3648                         LDKRouteHint arr_elem_conv;
3649                         arr_elem_conv.inner = (void*)(arr_elem & (~1));
3650                         arr_elem_conv.is_owned = (arr_elem & 1) || (arr_elem == 0);
3651                         if (arr_elem_conv.inner != NULL)
3652                                 arr_elem_conv = RouteHint_clone(&arr_elem_conv);
3653                         ret->data[i] = arr_elem_conv;
3654                 }
3655                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
3656         }
3657         return (long)ret;
3658 }
3659 static inline LDKCVec_RouteHintZ CVec_RouteHintZ_clone(const LDKCVec_RouteHintZ *orig) {
3660         LDKCVec_RouteHintZ ret = { .data = MALLOC(sizeof(LDKRouteHint) * orig->datalen, "LDKCVec_RouteHintZ clone bytes"), .datalen = orig->datalen };
3661         for (size_t i = 0; i < ret.datalen; i++) {
3662                 ret.data[i] = RouteHint_clone(&orig->data[i]);
3663         }
3664         return ret;
3665 }
3666 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1RouteLightningErrorZ_1result_1ok (JNIEnv *env, jclass clz, int64_t arg) {
3667         return ((LDKCResult_RouteLightningErrorZ*)arg)->result_ok;
3668 }
3669 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1RouteLightningErrorZ_1get_1ok (JNIEnv *env, jclass clz, int64_t arg) {
3670         LDKCResult_RouteLightningErrorZ *val = (LDKCResult_RouteLightningErrorZ*)arg;
3671         CHECK(val->result_ok);
3672         LDKRoute res_var = (*val->contents.result);
3673         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3674         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3675         long res_ref = (long)res_var.inner & ~1;
3676         return res_ref;
3677 }
3678 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1RouteLightningErrorZ_1get_1err (JNIEnv *env, jclass clz, int64_t arg) {
3679         LDKCResult_RouteLightningErrorZ *val = (LDKCResult_RouteLightningErrorZ*)arg;
3680         CHECK(!val->result_ok);
3681         LDKLightningError err_var = (*val->contents.err);
3682         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3683         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3684         long err_ref = (long)err_var.inner & ~1;
3685         return err_ref;
3686 }
3687 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1RoutingFeesDecodeErrorZ_1result_1ok (JNIEnv *env, jclass clz, int64_t arg) {
3688         return ((LDKCResult_RoutingFeesDecodeErrorZ*)arg)->result_ok;
3689 }
3690 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1RoutingFeesDecodeErrorZ_1get_1ok (JNIEnv *env, jclass clz, int64_t arg) {
3691         LDKCResult_RoutingFeesDecodeErrorZ *val = (LDKCResult_RoutingFeesDecodeErrorZ*)arg;
3692         CHECK(val->result_ok);
3693         LDKRoutingFees res_var = (*val->contents.result);
3694         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3695         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3696         long res_ref = (long)res_var.inner & ~1;
3697         return res_ref;
3698 }
3699 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1RoutingFeesDecodeErrorZ_1get_1err (JNIEnv *env, jclass clz, int64_t arg) {
3700         LDKCResult_RoutingFeesDecodeErrorZ *val = (LDKCResult_RoutingFeesDecodeErrorZ*)arg;
3701         CHECK(!val->result_ok);
3702         LDKDecodeError err_var = (*val->contents.err);
3703         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3704         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3705         long err_ref = (long)err_var.inner & ~1;
3706         return err_ref;
3707 }
3708 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NodeAnnouncementInfoDecodeErrorZ_1result_1ok (JNIEnv *env, jclass clz, int64_t arg) {
3709         return ((LDKCResult_NodeAnnouncementInfoDecodeErrorZ*)arg)->result_ok;
3710 }
3711 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NodeAnnouncementInfoDecodeErrorZ_1get_1ok (JNIEnv *env, jclass clz, int64_t arg) {
3712         LDKCResult_NodeAnnouncementInfoDecodeErrorZ *val = (LDKCResult_NodeAnnouncementInfoDecodeErrorZ*)arg;
3713         CHECK(val->result_ok);
3714         LDKNodeAnnouncementInfo res_var = (*val->contents.result);
3715         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3716         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3717         long res_ref = (long)res_var.inner & ~1;
3718         return res_ref;
3719 }
3720 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NodeAnnouncementInfoDecodeErrorZ_1get_1err (JNIEnv *env, jclass clz, int64_t arg) {
3721         LDKCResult_NodeAnnouncementInfoDecodeErrorZ *val = (LDKCResult_NodeAnnouncementInfoDecodeErrorZ*)arg;
3722         CHECK(!val->result_ok);
3723         LDKDecodeError err_var = (*val->contents.err);
3724         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3725         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3726         long err_ref = (long)err_var.inner & ~1;
3727         return err_ref;
3728 }
3729 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NodeInfoDecodeErrorZ_1result_1ok (JNIEnv *env, jclass clz, int64_t arg) {
3730         return ((LDKCResult_NodeInfoDecodeErrorZ*)arg)->result_ok;
3731 }
3732 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NodeInfoDecodeErrorZ_1get_1ok (JNIEnv *env, jclass clz, int64_t arg) {
3733         LDKCResult_NodeInfoDecodeErrorZ *val = (LDKCResult_NodeInfoDecodeErrorZ*)arg;
3734         CHECK(val->result_ok);
3735         LDKNodeInfo res_var = (*val->contents.result);
3736         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3737         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3738         long res_ref = (long)res_var.inner & ~1;
3739         return res_ref;
3740 }
3741 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NodeInfoDecodeErrorZ_1get_1err (JNIEnv *env, jclass clz, int64_t arg) {
3742         LDKCResult_NodeInfoDecodeErrorZ *val = (LDKCResult_NodeInfoDecodeErrorZ*)arg;
3743         CHECK(!val->result_ok);
3744         LDKDecodeError err_var = (*val->contents.err);
3745         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3746         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3747         long err_ref = (long)err_var.inner & ~1;
3748         return err_ref;
3749 }
3750 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NetworkGraphDecodeErrorZ_1result_1ok (JNIEnv *env, jclass clz, int64_t arg) {
3751         return ((LDKCResult_NetworkGraphDecodeErrorZ*)arg)->result_ok;
3752 }
3753 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NetworkGraphDecodeErrorZ_1get_1ok (JNIEnv *env, jclass clz, int64_t arg) {
3754         LDKCResult_NetworkGraphDecodeErrorZ *val = (LDKCResult_NetworkGraphDecodeErrorZ*)arg;
3755         CHECK(val->result_ok);
3756         LDKNetworkGraph res_var = (*val->contents.result);
3757         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3758         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3759         long res_ref = (long)res_var.inner & ~1;
3760         return res_ref;
3761 }
3762 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NetworkGraphDecodeErrorZ_1get_1err (JNIEnv *env, jclass clz, int64_t arg) {
3763         LDKCResult_NetworkGraphDecodeErrorZ *val = (LDKCResult_NetworkGraphDecodeErrorZ*)arg;
3764         CHECK(!val->result_ok);
3765         LDKDecodeError err_var = (*val->contents.err);
3766         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3767         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3768         long err_ref = (long)err_var.inner & ~1;
3769         return err_ref;
3770 }
3771 typedef struct LDKMessageSendEventsProvider_JCalls {
3772         atomic_size_t refcnt;
3773         JavaVM *vm;
3774         jweak o;
3775         jmethodID get_and_clear_pending_msg_events_meth;
3776 } LDKMessageSendEventsProvider_JCalls;
3777 static void LDKMessageSendEventsProvider_JCalls_free(void* this_arg) {
3778         LDKMessageSendEventsProvider_JCalls *j_calls = (LDKMessageSendEventsProvider_JCalls*) this_arg;
3779         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
3780                 JNIEnv *env;
3781                 DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
3782                 (*env)->DeleteWeakGlobalRef(env, j_calls->o);
3783                 FREE(j_calls);
3784         }
3785 }
3786 LDKCVec_MessageSendEventZ get_and_clear_pending_msg_events_jcall(const void* this_arg) {
3787         LDKMessageSendEventsProvider_JCalls *j_calls = (LDKMessageSendEventsProvider_JCalls*) this_arg;
3788         JNIEnv *env;
3789         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
3790         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
3791         CHECK(obj != NULL);
3792         int64_tArray arg = (*env)->CallObjectMethod(env, obj, j_calls->get_and_clear_pending_msg_events_meth);
3793         LDKCVec_MessageSendEventZ arg_constr;
3794         arg_constr.datalen = (*env)->GetArrayLength(env, arg);
3795         if (arg_constr.datalen > 0)
3796                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKMessageSendEvent), "LDKCVec_MessageSendEventZ Elements");
3797         else
3798                 arg_constr.data = NULL;
3799         int64_t* arg_vals = (*env)->GetLongArrayElements (env, arg, NULL);
3800         for (size_t s = 0; s < arg_constr.datalen; s++) {
3801                 int64_t arr_conv_18 = arg_vals[s];
3802                 LDKMessageSendEvent arr_conv_18_conv = *(LDKMessageSendEvent*)arr_conv_18;
3803                 FREE((void*)arr_conv_18);
3804                 arg_constr.data[s] = arr_conv_18_conv;
3805         }
3806         (*env)->ReleaseLongArrayElements(env, arg, arg_vals, 0);
3807         return arg_constr;
3808 }
3809 static void* LDKMessageSendEventsProvider_JCalls_clone(const void* this_arg) {
3810         LDKMessageSendEventsProvider_JCalls *j_calls = (LDKMessageSendEventsProvider_JCalls*) this_arg;
3811         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
3812         return (void*) this_arg;
3813 }
3814 static inline LDKMessageSendEventsProvider LDKMessageSendEventsProvider_init (JNIEnv *env, jclass clz, jobject o) {
3815         jclass c = (*env)->GetObjectClass(env, o);
3816         CHECK(c != NULL);
3817         LDKMessageSendEventsProvider_JCalls *calls = MALLOC(sizeof(LDKMessageSendEventsProvider_JCalls), "LDKMessageSendEventsProvider_JCalls");
3818         atomic_init(&calls->refcnt, 1);
3819         DO_ASSERT((*env)->GetJavaVM(env, &calls->vm) == 0);
3820         calls->o = (*env)->NewWeakGlobalRef(env, o);
3821         calls->get_and_clear_pending_msg_events_meth = (*env)->GetMethodID(env, c, "get_and_clear_pending_msg_events", "()[J");
3822         CHECK(calls->get_and_clear_pending_msg_events_meth != NULL);
3823
3824         LDKMessageSendEventsProvider ret = {
3825                 .this_arg = (void*) calls,
3826                 .get_and_clear_pending_msg_events = get_and_clear_pending_msg_events_jcall,
3827                 .free = LDKMessageSendEventsProvider_JCalls_free,
3828         };
3829         return ret;
3830 }
3831 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_LDKMessageSendEventsProvider_1new (JNIEnv *env, jclass clz, jobject o) {
3832         LDKMessageSendEventsProvider *res_ptr = MALLOC(sizeof(LDKMessageSendEventsProvider), "LDKMessageSendEventsProvider");
3833         *res_ptr = LDKMessageSendEventsProvider_init(env, clz, o);
3834         return (long)res_ptr;
3835 }
3836 JNIEXPORT int64_tArray JNICALL Java_org_ldk_impl_bindings_MessageSendEventsProvider_1get_1and_1clear_1pending_1msg_1events(JNIEnv *env, jclass clz, int64_t this_arg) {
3837         LDKMessageSendEventsProvider* this_arg_conv = (LDKMessageSendEventsProvider*)this_arg;
3838         LDKCVec_MessageSendEventZ ret_var = (this_arg_conv->get_and_clear_pending_msg_events)(this_arg_conv->this_arg);
3839         int64_tArray ret_arr = (*env)->NewLongArray(env, ret_var.datalen);
3840         int64_t *ret_arr_ptr = (*env)->GetPrimitiveArrayCritical(env, ret_arr, NULL);
3841         for (size_t s = 0; s < ret_var.datalen; s++) {
3842                 LDKMessageSendEvent *arr_conv_18_copy = MALLOC(sizeof(LDKMessageSendEvent), "LDKMessageSendEvent");
3843                 *arr_conv_18_copy = MessageSendEvent_clone(&ret_var.data[s]);
3844                 long arr_conv_18_ref = (long)arr_conv_18_copy;
3845                 ret_arr_ptr[s] = arr_conv_18_ref;
3846         }
3847         (*env)->ReleasePrimitiveArrayCritical(env, ret_arr, ret_arr_ptr, 0);
3848         FREE(ret_var.data);
3849         return ret_arr;
3850 }
3851
3852 typedef struct LDKEventsProvider_JCalls {
3853         atomic_size_t refcnt;
3854         JavaVM *vm;
3855         jweak o;
3856         jmethodID get_and_clear_pending_events_meth;
3857 } LDKEventsProvider_JCalls;
3858 static void LDKEventsProvider_JCalls_free(void* this_arg) {
3859         LDKEventsProvider_JCalls *j_calls = (LDKEventsProvider_JCalls*) this_arg;
3860         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
3861                 JNIEnv *env;
3862                 DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
3863                 (*env)->DeleteWeakGlobalRef(env, j_calls->o);
3864                 FREE(j_calls);
3865         }
3866 }
3867 LDKCVec_EventZ get_and_clear_pending_events_jcall(const void* this_arg) {
3868         LDKEventsProvider_JCalls *j_calls = (LDKEventsProvider_JCalls*) this_arg;
3869         JNIEnv *env;
3870         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
3871         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
3872         CHECK(obj != NULL);
3873         int64_tArray arg = (*env)->CallObjectMethod(env, obj, j_calls->get_and_clear_pending_events_meth);
3874         LDKCVec_EventZ arg_constr;
3875         arg_constr.datalen = (*env)->GetArrayLength(env, arg);
3876         if (arg_constr.datalen > 0)
3877                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKEvent), "LDKCVec_EventZ Elements");
3878         else
3879                 arg_constr.data = NULL;
3880         int64_t* arg_vals = (*env)->GetLongArrayElements (env, arg, NULL);
3881         for (size_t h = 0; h < arg_constr.datalen; h++) {
3882                 int64_t arr_conv_7 = arg_vals[h];
3883                 LDKEvent arr_conv_7_conv = *(LDKEvent*)arr_conv_7;
3884                 FREE((void*)arr_conv_7);
3885                 arg_constr.data[h] = arr_conv_7_conv;
3886         }
3887         (*env)->ReleaseLongArrayElements(env, arg, arg_vals, 0);
3888         return arg_constr;
3889 }
3890 static void* LDKEventsProvider_JCalls_clone(const void* this_arg) {
3891         LDKEventsProvider_JCalls *j_calls = (LDKEventsProvider_JCalls*) this_arg;
3892         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
3893         return (void*) this_arg;
3894 }
3895 static inline LDKEventsProvider LDKEventsProvider_init (JNIEnv *env, jclass clz, jobject o) {
3896         jclass c = (*env)->GetObjectClass(env, o);
3897         CHECK(c != NULL);
3898         LDKEventsProvider_JCalls *calls = MALLOC(sizeof(LDKEventsProvider_JCalls), "LDKEventsProvider_JCalls");
3899         atomic_init(&calls->refcnt, 1);
3900         DO_ASSERT((*env)->GetJavaVM(env, &calls->vm) == 0);
3901         calls->o = (*env)->NewWeakGlobalRef(env, o);
3902         calls->get_and_clear_pending_events_meth = (*env)->GetMethodID(env, c, "get_and_clear_pending_events", "()[J");
3903         CHECK(calls->get_and_clear_pending_events_meth != NULL);
3904
3905         LDKEventsProvider ret = {
3906                 .this_arg = (void*) calls,
3907                 .get_and_clear_pending_events = get_and_clear_pending_events_jcall,
3908                 .free = LDKEventsProvider_JCalls_free,
3909         };
3910         return ret;
3911 }
3912 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_LDKEventsProvider_1new (JNIEnv *env, jclass clz, jobject o) {
3913         LDKEventsProvider *res_ptr = MALLOC(sizeof(LDKEventsProvider), "LDKEventsProvider");
3914         *res_ptr = LDKEventsProvider_init(env, clz, o);
3915         return (long)res_ptr;
3916 }
3917 JNIEXPORT int64_tArray JNICALL Java_org_ldk_impl_bindings_EventsProvider_1get_1and_1clear_1pending_1events(JNIEnv *env, jclass clz, int64_t this_arg) {
3918         LDKEventsProvider* this_arg_conv = (LDKEventsProvider*)this_arg;
3919         LDKCVec_EventZ ret_var = (this_arg_conv->get_and_clear_pending_events)(this_arg_conv->this_arg);
3920         int64_tArray ret_arr = (*env)->NewLongArray(env, ret_var.datalen);
3921         int64_t *ret_arr_ptr = (*env)->GetPrimitiveArrayCritical(env, ret_arr, NULL);
3922         for (size_t h = 0; h < ret_var.datalen; h++) {
3923                 LDKEvent *arr_conv_7_copy = MALLOC(sizeof(LDKEvent), "LDKEvent");
3924                 *arr_conv_7_copy = Event_clone(&ret_var.data[h]);
3925                 long arr_conv_7_ref = (long)arr_conv_7_copy;
3926                 ret_arr_ptr[h] = arr_conv_7_ref;
3927         }
3928         (*env)->ReleasePrimitiveArrayCritical(env, ret_arr, ret_arr_ptr, 0);
3929         FREE(ret_var.data);
3930         return ret_arr;
3931 }
3932
3933 typedef struct LDKAccess_JCalls {
3934         atomic_size_t refcnt;
3935         JavaVM *vm;
3936         jweak o;
3937         jmethodID get_utxo_meth;
3938 } LDKAccess_JCalls;
3939 static void LDKAccess_JCalls_free(void* this_arg) {
3940         LDKAccess_JCalls *j_calls = (LDKAccess_JCalls*) this_arg;
3941         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
3942                 JNIEnv *env;
3943                 DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
3944                 (*env)->DeleteWeakGlobalRef(env, j_calls->o);
3945                 FREE(j_calls);
3946         }
3947 }
3948 LDKCResult_TxOutAccessErrorZ get_utxo_jcall(const void* this_arg, const uint8_t (* genesis_hash)[32], uint64_t short_channel_id) {
3949         LDKAccess_JCalls *j_calls = (LDKAccess_JCalls*) this_arg;
3950         JNIEnv *env;
3951         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
3952         int8_tArray genesis_hash_arr = (*env)->NewByteArray(env, 32);
3953         (*env)->SetByteArrayRegion(env, genesis_hash_arr, 0, 32, *genesis_hash);
3954         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
3955         CHECK(obj != NULL);
3956         LDKCResult_TxOutAccessErrorZ* ret = (LDKCResult_TxOutAccessErrorZ*)(*env)->CallLongMethod(env, obj, j_calls->get_utxo_meth, genesis_hash_arr, short_channel_id);
3957         LDKCResult_TxOutAccessErrorZ ret_conv = *(LDKCResult_TxOutAccessErrorZ*)ret;
3958         FREE((void*)ret);
3959         return ret_conv;
3960 }
3961 static void* LDKAccess_JCalls_clone(const void* this_arg) {
3962         LDKAccess_JCalls *j_calls = (LDKAccess_JCalls*) this_arg;
3963         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
3964         return (void*) this_arg;
3965 }
3966 static inline LDKAccess LDKAccess_init (JNIEnv *env, jclass clz, jobject o) {
3967         jclass c = (*env)->GetObjectClass(env, o);
3968         CHECK(c != NULL);
3969         LDKAccess_JCalls *calls = MALLOC(sizeof(LDKAccess_JCalls), "LDKAccess_JCalls");
3970         atomic_init(&calls->refcnt, 1);
3971         DO_ASSERT((*env)->GetJavaVM(env, &calls->vm) == 0);
3972         calls->o = (*env)->NewWeakGlobalRef(env, o);
3973         calls->get_utxo_meth = (*env)->GetMethodID(env, c, "get_utxo", "([BJ)J");
3974         CHECK(calls->get_utxo_meth != NULL);
3975
3976         LDKAccess ret = {
3977                 .this_arg = (void*) calls,
3978                 .get_utxo = get_utxo_jcall,
3979                 .free = LDKAccess_JCalls_free,
3980         };
3981         return ret;
3982 }
3983 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_LDKAccess_1new (JNIEnv *env, jclass clz, jobject o) {
3984         LDKAccess *res_ptr = MALLOC(sizeof(LDKAccess), "LDKAccess");
3985         *res_ptr = LDKAccess_init(env, clz, o);
3986         return (long)res_ptr;
3987 }
3988 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_Access_1get_1utxo(JNIEnv *env, jclass clz, int64_t this_arg, int8_tArray genesis_hash, int64_t short_channel_id) {
3989         LDKAccess* this_arg_conv = (LDKAccess*)this_arg;
3990         unsigned char genesis_hash_arr[32];
3991         CHECK((*env)->GetArrayLength(env, genesis_hash) == 32);
3992         (*env)->GetByteArrayRegion(env, genesis_hash, 0, 32, genesis_hash_arr);
3993         unsigned char (*genesis_hash_ref)[32] = &genesis_hash_arr;
3994         LDKCResult_TxOutAccessErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_TxOutAccessErrorZ), "LDKCResult_TxOutAccessErrorZ");
3995         *ret_conv = (this_arg_conv->get_utxo)(this_arg_conv->this_arg, genesis_hash_ref, short_channel_id);
3996         return (long)ret_conv;
3997 }
3998
3999 typedef struct LDKFilter_JCalls {
4000         atomic_size_t refcnt;
4001         JavaVM *vm;
4002         jweak o;
4003         jmethodID register_tx_meth;
4004         jmethodID register_output_meth;
4005 } LDKFilter_JCalls;
4006 static void LDKFilter_JCalls_free(void* this_arg) {
4007         LDKFilter_JCalls *j_calls = (LDKFilter_JCalls*) this_arg;
4008         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
4009                 JNIEnv *env;
4010                 DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
4011                 (*env)->DeleteWeakGlobalRef(env, j_calls->o);
4012                 FREE(j_calls);
4013         }
4014 }
4015 void register_tx_jcall(const void* this_arg, const uint8_t (* txid)[32], LDKu8slice script_pubkey) {
4016         LDKFilter_JCalls *j_calls = (LDKFilter_JCalls*) this_arg;
4017         JNIEnv *env;
4018         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
4019         int8_tArray txid_arr = (*env)->NewByteArray(env, 32);
4020         (*env)->SetByteArrayRegion(env, txid_arr, 0, 32, *txid);
4021         LDKu8slice script_pubkey_var = script_pubkey;
4022         int8_tArray script_pubkey_arr = (*env)->NewByteArray(env, script_pubkey_var.datalen);
4023         (*env)->SetByteArrayRegion(env, script_pubkey_arr, 0, script_pubkey_var.datalen, script_pubkey_var.data);
4024         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
4025         CHECK(obj != NULL);
4026         return (*env)->CallVoidMethod(env, obj, j_calls->register_tx_meth, txid_arr, script_pubkey_arr);
4027 }
4028 void register_output_jcall(const void* this_arg, const LDKOutPoint * outpoint, LDKu8slice script_pubkey) {
4029         LDKFilter_JCalls *j_calls = (LDKFilter_JCalls*) this_arg;
4030         JNIEnv *env;
4031         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
4032         LDKOutPoint outpoint_var = *outpoint;
4033         if (outpoint->inner != NULL)
4034                 outpoint_var = OutPoint_clone(outpoint);
4035         CHECK((((long)outpoint_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4036         CHECK((((long)&outpoint_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4037         long outpoint_ref = (long)outpoint_var.inner;
4038         if (outpoint_var.is_owned) {
4039                 outpoint_ref |= 1;
4040         }
4041         LDKu8slice script_pubkey_var = script_pubkey;
4042         int8_tArray script_pubkey_arr = (*env)->NewByteArray(env, script_pubkey_var.datalen);
4043         (*env)->SetByteArrayRegion(env, script_pubkey_arr, 0, script_pubkey_var.datalen, script_pubkey_var.data);
4044         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
4045         CHECK(obj != NULL);
4046         return (*env)->CallVoidMethod(env, obj, j_calls->register_output_meth, outpoint_ref, script_pubkey_arr);
4047 }
4048 static void* LDKFilter_JCalls_clone(const void* this_arg) {
4049         LDKFilter_JCalls *j_calls = (LDKFilter_JCalls*) this_arg;
4050         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
4051         return (void*) this_arg;
4052 }
4053 static inline LDKFilter LDKFilter_init (JNIEnv *env, jclass clz, jobject o) {
4054         jclass c = (*env)->GetObjectClass(env, o);
4055         CHECK(c != NULL);
4056         LDKFilter_JCalls *calls = MALLOC(sizeof(LDKFilter_JCalls), "LDKFilter_JCalls");
4057         atomic_init(&calls->refcnt, 1);
4058         DO_ASSERT((*env)->GetJavaVM(env, &calls->vm) == 0);
4059         calls->o = (*env)->NewWeakGlobalRef(env, o);
4060         calls->register_tx_meth = (*env)->GetMethodID(env, c, "register_tx", "([B[B)V");
4061         CHECK(calls->register_tx_meth != NULL);
4062         calls->register_output_meth = (*env)->GetMethodID(env, c, "register_output", "(J[B)V");
4063         CHECK(calls->register_output_meth != NULL);
4064
4065         LDKFilter ret = {
4066                 .this_arg = (void*) calls,
4067                 .register_tx = register_tx_jcall,
4068                 .register_output = register_output_jcall,
4069                 .free = LDKFilter_JCalls_free,
4070         };
4071         return ret;
4072 }
4073 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_LDKFilter_1new (JNIEnv *env, jclass clz, jobject o) {
4074         LDKFilter *res_ptr = MALLOC(sizeof(LDKFilter), "LDKFilter");
4075         *res_ptr = LDKFilter_init(env, clz, o);
4076         return (long)res_ptr;
4077 }
4078 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Filter_1register_1tx(JNIEnv *env, jclass clz, int64_t this_arg, int8_tArray txid, int8_tArray script_pubkey) {
4079         LDKFilter* this_arg_conv = (LDKFilter*)this_arg;
4080         unsigned char txid_arr[32];
4081         CHECK((*env)->GetArrayLength(env, txid) == 32);
4082         (*env)->GetByteArrayRegion(env, txid, 0, 32, txid_arr);
4083         unsigned char (*txid_ref)[32] = &txid_arr;
4084         LDKu8slice script_pubkey_ref;
4085         script_pubkey_ref.datalen = (*env)->GetArrayLength(env, script_pubkey);
4086         script_pubkey_ref.data = (*env)->GetByteArrayElements (env, script_pubkey, NULL);
4087         (this_arg_conv->register_tx)(this_arg_conv->this_arg, txid_ref, script_pubkey_ref);
4088         (*env)->ReleaseByteArrayElements(env, script_pubkey, (int8_t*)script_pubkey_ref.data, 0);
4089 }
4090
4091 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Filter_1register_1output(JNIEnv *env, jclass clz, int64_t this_arg, int64_t outpoint, int8_tArray script_pubkey) {
4092         LDKFilter* this_arg_conv = (LDKFilter*)this_arg;
4093         LDKOutPoint outpoint_conv;
4094         outpoint_conv.inner = (void*)(outpoint & (~1));
4095         outpoint_conv.is_owned = false;
4096         LDKu8slice script_pubkey_ref;
4097         script_pubkey_ref.datalen = (*env)->GetArrayLength(env, script_pubkey);
4098         script_pubkey_ref.data = (*env)->GetByteArrayElements (env, script_pubkey, NULL);
4099         (this_arg_conv->register_output)(this_arg_conv->this_arg, &outpoint_conv, script_pubkey_ref);
4100         (*env)->ReleaseByteArrayElements(env, script_pubkey, (int8_t*)script_pubkey_ref.data, 0);
4101 }
4102
4103 typedef struct LDKPersist_JCalls {
4104         atomic_size_t refcnt;
4105         JavaVM *vm;
4106         jweak o;
4107         jmethodID persist_new_channel_meth;
4108         jmethodID update_persisted_channel_meth;
4109 } LDKPersist_JCalls;
4110 static void LDKPersist_JCalls_free(void* this_arg) {
4111         LDKPersist_JCalls *j_calls = (LDKPersist_JCalls*) this_arg;
4112         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
4113                 JNIEnv *env;
4114                 DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
4115                 (*env)->DeleteWeakGlobalRef(env, j_calls->o);
4116                 FREE(j_calls);
4117         }
4118 }
4119 LDKCResult_NoneChannelMonitorUpdateErrZ persist_new_channel_jcall(const void* this_arg, LDKOutPoint id, const LDKChannelMonitor * data) {
4120         LDKPersist_JCalls *j_calls = (LDKPersist_JCalls*) this_arg;
4121         JNIEnv *env;
4122         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
4123         LDKOutPoint id_var = id;
4124         CHECK((((long)id_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4125         CHECK((((long)&id_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4126         long id_ref = (long)id_var.inner;
4127         if (id_var.is_owned) {
4128                 id_ref |= 1;
4129         }
4130         LDKChannelMonitor data_var = *data;
4131         // Warning: we may need a move here but can't clone!
4132         CHECK((((long)data_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4133         CHECK((((long)&data_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4134         long data_ref = (long)data_var.inner;
4135         if (data_var.is_owned) {
4136                 data_ref |= 1;
4137         }
4138         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
4139         CHECK(obj != NULL);
4140         LDKCResult_NoneChannelMonitorUpdateErrZ* ret = (LDKCResult_NoneChannelMonitorUpdateErrZ*)(*env)->CallLongMethod(env, obj, j_calls->persist_new_channel_meth, id_ref, data_ref);
4141         LDKCResult_NoneChannelMonitorUpdateErrZ ret_conv = *(LDKCResult_NoneChannelMonitorUpdateErrZ*)ret;
4142         FREE((void*)ret);
4143         return ret_conv;
4144 }
4145 LDKCResult_NoneChannelMonitorUpdateErrZ update_persisted_channel_jcall(const void* this_arg, LDKOutPoint id, const LDKChannelMonitorUpdate * update, const LDKChannelMonitor * data) {
4146         LDKPersist_JCalls *j_calls = (LDKPersist_JCalls*) this_arg;
4147         JNIEnv *env;
4148         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
4149         LDKOutPoint id_var = id;
4150         CHECK((((long)id_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4151         CHECK((((long)&id_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4152         long id_ref = (long)id_var.inner;
4153         if (id_var.is_owned) {
4154                 id_ref |= 1;
4155         }
4156         LDKChannelMonitorUpdate update_var = *update;
4157         if (update->inner != NULL)
4158                 update_var = ChannelMonitorUpdate_clone(update);
4159         CHECK((((long)update_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4160         CHECK((((long)&update_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4161         long update_ref = (long)update_var.inner;
4162         if (update_var.is_owned) {
4163                 update_ref |= 1;
4164         }
4165         LDKChannelMonitor data_var = *data;
4166         // Warning: we may need a move here but can't clone!
4167         CHECK((((long)data_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4168         CHECK((((long)&data_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4169         long data_ref = (long)data_var.inner;
4170         if (data_var.is_owned) {
4171                 data_ref |= 1;
4172         }
4173         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
4174         CHECK(obj != NULL);
4175         LDKCResult_NoneChannelMonitorUpdateErrZ* ret = (LDKCResult_NoneChannelMonitorUpdateErrZ*)(*env)->CallLongMethod(env, obj, j_calls->update_persisted_channel_meth, id_ref, update_ref, data_ref);
4176         LDKCResult_NoneChannelMonitorUpdateErrZ ret_conv = *(LDKCResult_NoneChannelMonitorUpdateErrZ*)ret;
4177         FREE((void*)ret);
4178         return ret_conv;
4179 }
4180 static void* LDKPersist_JCalls_clone(const void* this_arg) {
4181         LDKPersist_JCalls *j_calls = (LDKPersist_JCalls*) this_arg;
4182         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
4183         return (void*) this_arg;
4184 }
4185 static inline LDKPersist LDKPersist_init (JNIEnv *env, jclass clz, jobject o) {
4186         jclass c = (*env)->GetObjectClass(env, o);
4187         CHECK(c != NULL);
4188         LDKPersist_JCalls *calls = MALLOC(sizeof(LDKPersist_JCalls), "LDKPersist_JCalls");
4189         atomic_init(&calls->refcnt, 1);
4190         DO_ASSERT((*env)->GetJavaVM(env, &calls->vm) == 0);
4191         calls->o = (*env)->NewWeakGlobalRef(env, o);
4192         calls->persist_new_channel_meth = (*env)->GetMethodID(env, c, "persist_new_channel", "(JJ)J");
4193         CHECK(calls->persist_new_channel_meth != NULL);
4194         calls->update_persisted_channel_meth = (*env)->GetMethodID(env, c, "update_persisted_channel", "(JJJ)J");
4195         CHECK(calls->update_persisted_channel_meth != NULL);
4196
4197         LDKPersist ret = {
4198                 .this_arg = (void*) calls,
4199                 .persist_new_channel = persist_new_channel_jcall,
4200                 .update_persisted_channel = update_persisted_channel_jcall,
4201                 .free = LDKPersist_JCalls_free,
4202         };
4203         return ret;
4204 }
4205 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_LDKPersist_1new (JNIEnv *env, jclass clz, jobject o) {
4206         LDKPersist *res_ptr = MALLOC(sizeof(LDKPersist), "LDKPersist");
4207         *res_ptr = LDKPersist_init(env, clz, o);
4208         return (long)res_ptr;
4209 }
4210 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_Persist_1persist_1new_1channel(JNIEnv *env, jclass clz, int64_t this_arg, int64_t id, int64_t data) {
4211         LDKPersist* this_arg_conv = (LDKPersist*)this_arg;
4212         LDKOutPoint id_conv;
4213         id_conv.inner = (void*)(id & (~1));
4214         id_conv.is_owned = (id & 1) || (id == 0);
4215         if (id_conv.inner != NULL)
4216                 id_conv = OutPoint_clone(&id_conv);
4217         LDKChannelMonitor data_conv;
4218         data_conv.inner = (void*)(data & (~1));
4219         data_conv.is_owned = false;
4220         LDKCResult_NoneChannelMonitorUpdateErrZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneChannelMonitorUpdateErrZ), "LDKCResult_NoneChannelMonitorUpdateErrZ");
4221         *ret_conv = (this_arg_conv->persist_new_channel)(this_arg_conv->this_arg, id_conv, &data_conv);
4222         return (long)ret_conv;
4223 }
4224
4225 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_Persist_1update_1persisted_1channel(JNIEnv *env, jclass clz, int64_t this_arg, int64_t id, int64_t update, int64_t data) {
4226         LDKPersist* this_arg_conv = (LDKPersist*)this_arg;
4227         LDKOutPoint id_conv;
4228         id_conv.inner = (void*)(id & (~1));
4229         id_conv.is_owned = (id & 1) || (id == 0);
4230         if (id_conv.inner != NULL)
4231                 id_conv = OutPoint_clone(&id_conv);
4232         LDKChannelMonitorUpdate update_conv;
4233         update_conv.inner = (void*)(update & (~1));
4234         update_conv.is_owned = false;
4235         LDKChannelMonitor data_conv;
4236         data_conv.inner = (void*)(data & (~1));
4237         data_conv.is_owned = false;
4238         LDKCResult_NoneChannelMonitorUpdateErrZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneChannelMonitorUpdateErrZ), "LDKCResult_NoneChannelMonitorUpdateErrZ");
4239         *ret_conv = (this_arg_conv->update_persisted_channel)(this_arg_conv->this_arg, id_conv, &update_conv, &data_conv);
4240         return (long)ret_conv;
4241 }
4242
4243 typedef struct LDKChannelMessageHandler_JCalls {
4244         atomic_size_t refcnt;
4245         JavaVM *vm;
4246         jweak o;
4247         LDKMessageSendEventsProvider_JCalls* MessageSendEventsProvider;
4248         jmethodID handle_open_channel_meth;
4249         jmethodID handle_accept_channel_meth;
4250         jmethodID handle_funding_created_meth;
4251         jmethodID handle_funding_signed_meth;
4252         jmethodID handle_funding_locked_meth;
4253         jmethodID handle_shutdown_meth;
4254         jmethodID handle_closing_signed_meth;
4255         jmethodID handle_update_add_htlc_meth;
4256         jmethodID handle_update_fulfill_htlc_meth;
4257         jmethodID handle_update_fail_htlc_meth;
4258         jmethodID handle_update_fail_malformed_htlc_meth;
4259         jmethodID handle_commitment_signed_meth;
4260         jmethodID handle_revoke_and_ack_meth;
4261         jmethodID handle_update_fee_meth;
4262         jmethodID handle_announcement_signatures_meth;
4263         jmethodID peer_disconnected_meth;
4264         jmethodID peer_connected_meth;
4265         jmethodID handle_channel_reestablish_meth;
4266         jmethodID handle_error_meth;
4267 } LDKChannelMessageHandler_JCalls;
4268 static void LDKChannelMessageHandler_JCalls_free(void* this_arg) {
4269         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
4270         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
4271                 JNIEnv *env;
4272                 DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
4273                 (*env)->DeleteWeakGlobalRef(env, j_calls->o);
4274                 FREE(j_calls);
4275         }
4276 }
4277 void handle_open_channel_jcall(const void* this_arg, LDKPublicKey their_node_id, LDKInitFeatures their_features, const LDKOpenChannel * msg) {
4278         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
4279         JNIEnv *env;
4280         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
4281         int8_tArray their_node_id_arr = (*env)->NewByteArray(env, 33);
4282         (*env)->SetByteArrayRegion(env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
4283         LDKInitFeatures their_features_var = their_features;
4284         CHECK((((long)their_features_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4285         CHECK((((long)&their_features_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4286         long their_features_ref = (long)their_features_var.inner;
4287         if (their_features_var.is_owned) {
4288                 their_features_ref |= 1;
4289         }
4290         LDKOpenChannel msg_var = *msg;
4291         if (msg->inner != NULL)
4292                 msg_var = OpenChannel_clone(msg);
4293         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4294         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4295         long msg_ref = (long)msg_var.inner;
4296         if (msg_var.is_owned) {
4297                 msg_ref |= 1;
4298         }
4299         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
4300         CHECK(obj != NULL);
4301         return (*env)->CallVoidMethod(env, obj, j_calls->handle_open_channel_meth, their_node_id_arr, their_features_ref, msg_ref);
4302 }
4303 void handle_accept_channel_jcall(const void* this_arg, LDKPublicKey their_node_id, LDKInitFeatures their_features, const LDKAcceptChannel * msg) {
4304         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
4305         JNIEnv *env;
4306         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
4307         int8_tArray their_node_id_arr = (*env)->NewByteArray(env, 33);
4308         (*env)->SetByteArrayRegion(env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
4309         LDKInitFeatures their_features_var = their_features;
4310         CHECK((((long)their_features_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4311         CHECK((((long)&their_features_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4312         long their_features_ref = (long)their_features_var.inner;
4313         if (their_features_var.is_owned) {
4314                 their_features_ref |= 1;
4315         }
4316         LDKAcceptChannel msg_var = *msg;
4317         if (msg->inner != NULL)
4318                 msg_var = AcceptChannel_clone(msg);
4319         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4320         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4321         long msg_ref = (long)msg_var.inner;
4322         if (msg_var.is_owned) {
4323                 msg_ref |= 1;
4324         }
4325         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
4326         CHECK(obj != NULL);
4327         return (*env)->CallVoidMethod(env, obj, j_calls->handle_accept_channel_meth, their_node_id_arr, their_features_ref, msg_ref);
4328 }
4329 void handle_funding_created_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKFundingCreated * msg) {
4330         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
4331         JNIEnv *env;
4332         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
4333         int8_tArray their_node_id_arr = (*env)->NewByteArray(env, 33);
4334         (*env)->SetByteArrayRegion(env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
4335         LDKFundingCreated msg_var = *msg;
4336         if (msg->inner != NULL)
4337                 msg_var = FundingCreated_clone(msg);
4338         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4339         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4340         long msg_ref = (long)msg_var.inner;
4341         if (msg_var.is_owned) {
4342                 msg_ref |= 1;
4343         }
4344         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
4345         CHECK(obj != NULL);
4346         return (*env)->CallVoidMethod(env, obj, j_calls->handle_funding_created_meth, their_node_id_arr, msg_ref);
4347 }
4348 void handle_funding_signed_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKFundingSigned * msg) {
4349         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
4350         JNIEnv *env;
4351         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
4352         int8_tArray their_node_id_arr = (*env)->NewByteArray(env, 33);
4353         (*env)->SetByteArrayRegion(env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
4354         LDKFundingSigned msg_var = *msg;
4355         if (msg->inner != NULL)
4356                 msg_var = FundingSigned_clone(msg);
4357         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4358         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4359         long msg_ref = (long)msg_var.inner;
4360         if (msg_var.is_owned) {
4361                 msg_ref |= 1;
4362         }
4363         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
4364         CHECK(obj != NULL);
4365         return (*env)->CallVoidMethod(env, obj, j_calls->handle_funding_signed_meth, their_node_id_arr, msg_ref);
4366 }
4367 void handle_funding_locked_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKFundingLocked * msg) {
4368         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
4369         JNIEnv *env;
4370         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
4371         int8_tArray their_node_id_arr = (*env)->NewByteArray(env, 33);
4372         (*env)->SetByteArrayRegion(env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
4373         LDKFundingLocked msg_var = *msg;
4374         if (msg->inner != NULL)
4375                 msg_var = FundingLocked_clone(msg);
4376         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4377         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4378         long msg_ref = (long)msg_var.inner;
4379         if (msg_var.is_owned) {
4380                 msg_ref |= 1;
4381         }
4382         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
4383         CHECK(obj != NULL);
4384         return (*env)->CallVoidMethod(env, obj, j_calls->handle_funding_locked_meth, their_node_id_arr, msg_ref);
4385 }
4386 void handle_shutdown_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKShutdown * msg) {
4387         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
4388         JNIEnv *env;
4389         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
4390         int8_tArray their_node_id_arr = (*env)->NewByteArray(env, 33);
4391         (*env)->SetByteArrayRegion(env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
4392         LDKShutdown msg_var = *msg;
4393         if (msg->inner != NULL)
4394                 msg_var = Shutdown_clone(msg);
4395         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4396         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4397         long msg_ref = (long)msg_var.inner;
4398         if (msg_var.is_owned) {
4399                 msg_ref |= 1;
4400         }
4401         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
4402         CHECK(obj != NULL);
4403         return (*env)->CallVoidMethod(env, obj, j_calls->handle_shutdown_meth, their_node_id_arr, msg_ref);
4404 }
4405 void handle_closing_signed_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKClosingSigned * msg) {
4406         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
4407         JNIEnv *env;
4408         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
4409         int8_tArray their_node_id_arr = (*env)->NewByteArray(env, 33);
4410         (*env)->SetByteArrayRegion(env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
4411         LDKClosingSigned msg_var = *msg;
4412         if (msg->inner != NULL)
4413                 msg_var = ClosingSigned_clone(msg);
4414         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4415         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4416         long msg_ref = (long)msg_var.inner;
4417         if (msg_var.is_owned) {
4418                 msg_ref |= 1;
4419         }
4420         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
4421         CHECK(obj != NULL);
4422         return (*env)->CallVoidMethod(env, obj, j_calls->handle_closing_signed_meth, their_node_id_arr, msg_ref);
4423 }
4424 void handle_update_add_htlc_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKUpdateAddHTLC * msg) {
4425         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
4426         JNIEnv *env;
4427         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
4428         int8_tArray their_node_id_arr = (*env)->NewByteArray(env, 33);
4429         (*env)->SetByteArrayRegion(env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
4430         LDKUpdateAddHTLC msg_var = *msg;
4431         if (msg->inner != NULL)
4432                 msg_var = UpdateAddHTLC_clone(msg);
4433         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4434         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4435         long msg_ref = (long)msg_var.inner;
4436         if (msg_var.is_owned) {
4437                 msg_ref |= 1;
4438         }
4439         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
4440         CHECK(obj != NULL);
4441         return (*env)->CallVoidMethod(env, obj, j_calls->handle_update_add_htlc_meth, their_node_id_arr, msg_ref);
4442 }
4443 void handle_update_fulfill_htlc_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKUpdateFulfillHTLC * msg) {
4444         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
4445         JNIEnv *env;
4446         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
4447         int8_tArray their_node_id_arr = (*env)->NewByteArray(env, 33);
4448         (*env)->SetByteArrayRegion(env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
4449         LDKUpdateFulfillHTLC msg_var = *msg;
4450         if (msg->inner != NULL)
4451                 msg_var = UpdateFulfillHTLC_clone(msg);
4452         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4453         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4454         long msg_ref = (long)msg_var.inner;
4455         if (msg_var.is_owned) {
4456                 msg_ref |= 1;
4457         }
4458         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
4459         CHECK(obj != NULL);
4460         return (*env)->CallVoidMethod(env, obj, j_calls->handle_update_fulfill_htlc_meth, their_node_id_arr, msg_ref);
4461 }
4462 void handle_update_fail_htlc_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKUpdateFailHTLC * msg) {
4463         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
4464         JNIEnv *env;
4465         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
4466         int8_tArray their_node_id_arr = (*env)->NewByteArray(env, 33);
4467         (*env)->SetByteArrayRegion(env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
4468         LDKUpdateFailHTLC msg_var = *msg;
4469         if (msg->inner != NULL)
4470                 msg_var = UpdateFailHTLC_clone(msg);
4471         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4472         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4473         long msg_ref = (long)msg_var.inner;
4474         if (msg_var.is_owned) {
4475                 msg_ref |= 1;
4476         }
4477         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
4478         CHECK(obj != NULL);
4479         return (*env)->CallVoidMethod(env, obj, j_calls->handle_update_fail_htlc_meth, their_node_id_arr, msg_ref);
4480 }
4481 void handle_update_fail_malformed_htlc_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKUpdateFailMalformedHTLC * msg) {
4482         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
4483         JNIEnv *env;
4484         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
4485         int8_tArray their_node_id_arr = (*env)->NewByteArray(env, 33);
4486         (*env)->SetByteArrayRegion(env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
4487         LDKUpdateFailMalformedHTLC msg_var = *msg;
4488         if (msg->inner != NULL)
4489                 msg_var = UpdateFailMalformedHTLC_clone(msg);
4490         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4491         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4492         long msg_ref = (long)msg_var.inner;
4493         if (msg_var.is_owned) {
4494                 msg_ref |= 1;
4495         }
4496         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
4497         CHECK(obj != NULL);
4498         return (*env)->CallVoidMethod(env, obj, j_calls->handle_update_fail_malformed_htlc_meth, their_node_id_arr, msg_ref);
4499 }
4500 void handle_commitment_signed_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKCommitmentSigned * msg) {
4501         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
4502         JNIEnv *env;
4503         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
4504         int8_tArray their_node_id_arr = (*env)->NewByteArray(env, 33);
4505         (*env)->SetByteArrayRegion(env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
4506         LDKCommitmentSigned msg_var = *msg;
4507         if (msg->inner != NULL)
4508                 msg_var = CommitmentSigned_clone(msg);
4509         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4510         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4511         long msg_ref = (long)msg_var.inner;
4512         if (msg_var.is_owned) {
4513                 msg_ref |= 1;
4514         }
4515         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
4516         CHECK(obj != NULL);
4517         return (*env)->CallVoidMethod(env, obj, j_calls->handle_commitment_signed_meth, their_node_id_arr, msg_ref);
4518 }
4519 void handle_revoke_and_ack_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKRevokeAndACK * msg) {
4520         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
4521         JNIEnv *env;
4522         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
4523         int8_tArray their_node_id_arr = (*env)->NewByteArray(env, 33);
4524         (*env)->SetByteArrayRegion(env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
4525         LDKRevokeAndACK msg_var = *msg;
4526         if (msg->inner != NULL)
4527                 msg_var = RevokeAndACK_clone(msg);
4528         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4529         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4530         long msg_ref = (long)msg_var.inner;
4531         if (msg_var.is_owned) {
4532                 msg_ref |= 1;
4533         }
4534         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
4535         CHECK(obj != NULL);
4536         return (*env)->CallVoidMethod(env, obj, j_calls->handle_revoke_and_ack_meth, their_node_id_arr, msg_ref);
4537 }
4538 void handle_update_fee_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKUpdateFee * msg) {
4539         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
4540         JNIEnv *env;
4541         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
4542         int8_tArray their_node_id_arr = (*env)->NewByteArray(env, 33);
4543         (*env)->SetByteArrayRegion(env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
4544         LDKUpdateFee msg_var = *msg;
4545         if (msg->inner != NULL)
4546                 msg_var = UpdateFee_clone(msg);
4547         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4548         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4549         long msg_ref = (long)msg_var.inner;
4550         if (msg_var.is_owned) {
4551                 msg_ref |= 1;
4552         }
4553         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
4554         CHECK(obj != NULL);
4555         return (*env)->CallVoidMethod(env, obj, j_calls->handle_update_fee_meth, their_node_id_arr, msg_ref);
4556 }
4557 void handle_announcement_signatures_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKAnnouncementSignatures * msg) {
4558         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
4559         JNIEnv *env;
4560         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
4561         int8_tArray their_node_id_arr = (*env)->NewByteArray(env, 33);
4562         (*env)->SetByteArrayRegion(env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
4563         LDKAnnouncementSignatures msg_var = *msg;
4564         if (msg->inner != NULL)
4565                 msg_var = AnnouncementSignatures_clone(msg);
4566         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4567         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4568         long msg_ref = (long)msg_var.inner;
4569         if (msg_var.is_owned) {
4570                 msg_ref |= 1;
4571         }
4572         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
4573         CHECK(obj != NULL);
4574         return (*env)->CallVoidMethod(env, obj, j_calls->handle_announcement_signatures_meth, their_node_id_arr, msg_ref);
4575 }
4576 void peer_disconnected_jcall(const void* this_arg, LDKPublicKey their_node_id, bool no_connection_possible) {
4577         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
4578         JNIEnv *env;
4579         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
4580         int8_tArray their_node_id_arr = (*env)->NewByteArray(env, 33);
4581         (*env)->SetByteArrayRegion(env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
4582         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
4583         CHECK(obj != NULL);
4584         return (*env)->CallVoidMethod(env, obj, j_calls->peer_disconnected_meth, their_node_id_arr, no_connection_possible);
4585 }
4586 void peer_connected_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKInit * msg) {
4587         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
4588         JNIEnv *env;
4589         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
4590         int8_tArray their_node_id_arr = (*env)->NewByteArray(env, 33);
4591         (*env)->SetByteArrayRegion(env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
4592         LDKInit msg_var = *msg;
4593         if (msg->inner != NULL)
4594                 msg_var = Init_clone(msg);
4595         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4596         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4597         long msg_ref = (long)msg_var.inner;
4598         if (msg_var.is_owned) {
4599                 msg_ref |= 1;
4600         }
4601         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
4602         CHECK(obj != NULL);
4603         return (*env)->CallVoidMethod(env, obj, j_calls->peer_connected_meth, their_node_id_arr, msg_ref);
4604 }
4605 void handle_channel_reestablish_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKChannelReestablish * msg) {
4606         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
4607         JNIEnv *env;
4608         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
4609         int8_tArray their_node_id_arr = (*env)->NewByteArray(env, 33);
4610         (*env)->SetByteArrayRegion(env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
4611         LDKChannelReestablish msg_var = *msg;
4612         if (msg->inner != NULL)
4613                 msg_var = ChannelReestablish_clone(msg);
4614         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4615         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4616         long msg_ref = (long)msg_var.inner;
4617         if (msg_var.is_owned) {
4618                 msg_ref |= 1;
4619         }
4620         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
4621         CHECK(obj != NULL);
4622         return (*env)->CallVoidMethod(env, obj, j_calls->handle_channel_reestablish_meth, their_node_id_arr, msg_ref);
4623 }
4624 void handle_error_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKErrorMessage * msg) {
4625         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
4626         JNIEnv *env;
4627         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
4628         int8_tArray their_node_id_arr = (*env)->NewByteArray(env, 33);
4629         (*env)->SetByteArrayRegion(env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
4630         LDKErrorMessage msg_var = *msg;
4631         if (msg->inner != NULL)
4632                 msg_var = ErrorMessage_clone(msg);
4633         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4634         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4635         long msg_ref = (long)msg_var.inner;
4636         if (msg_var.is_owned) {
4637                 msg_ref |= 1;
4638         }
4639         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
4640         CHECK(obj != NULL);
4641         return (*env)->CallVoidMethod(env, obj, j_calls->handle_error_meth, their_node_id_arr, msg_ref);
4642 }
4643 static void* LDKChannelMessageHandler_JCalls_clone(const void* this_arg) {
4644         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
4645         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
4646         atomic_fetch_add_explicit(&j_calls->MessageSendEventsProvider->refcnt, 1, memory_order_release);
4647         return (void*) this_arg;
4648 }
4649 static inline LDKChannelMessageHandler LDKChannelMessageHandler_init (JNIEnv *env, jclass clz, jobject o, jobject MessageSendEventsProvider) {
4650         jclass c = (*env)->GetObjectClass(env, o);
4651         CHECK(c != NULL);
4652         LDKChannelMessageHandler_JCalls *calls = MALLOC(sizeof(LDKChannelMessageHandler_JCalls), "LDKChannelMessageHandler_JCalls");
4653         atomic_init(&calls->refcnt, 1);
4654         DO_ASSERT((*env)->GetJavaVM(env, &calls->vm) == 0);
4655         calls->o = (*env)->NewWeakGlobalRef(env, o);
4656         calls->handle_open_channel_meth = (*env)->GetMethodID(env, c, "handle_open_channel", "([BJJ)V");
4657         CHECK(calls->handle_open_channel_meth != NULL);
4658         calls->handle_accept_channel_meth = (*env)->GetMethodID(env, c, "handle_accept_channel", "([BJJ)V");
4659         CHECK(calls->handle_accept_channel_meth != NULL);
4660         calls->handle_funding_created_meth = (*env)->GetMethodID(env, c, "handle_funding_created", "([BJ)V");
4661         CHECK(calls->handle_funding_created_meth != NULL);
4662         calls->handle_funding_signed_meth = (*env)->GetMethodID(env, c, "handle_funding_signed", "([BJ)V");
4663         CHECK(calls->handle_funding_signed_meth != NULL);
4664         calls->handle_funding_locked_meth = (*env)->GetMethodID(env, c, "handle_funding_locked", "([BJ)V");
4665         CHECK(calls->handle_funding_locked_meth != NULL);
4666         calls->handle_shutdown_meth = (*env)->GetMethodID(env, c, "handle_shutdown", "([BJ)V");
4667         CHECK(calls->handle_shutdown_meth != NULL);
4668         calls->handle_closing_signed_meth = (*env)->GetMethodID(env, c, "handle_closing_signed", "([BJ)V");
4669         CHECK(calls->handle_closing_signed_meth != NULL);
4670         calls->handle_update_add_htlc_meth = (*env)->GetMethodID(env, c, "handle_update_add_htlc", "([BJ)V");
4671         CHECK(calls->handle_update_add_htlc_meth != NULL);
4672         calls->handle_update_fulfill_htlc_meth = (*env)->GetMethodID(env, c, "handle_update_fulfill_htlc", "([BJ)V");
4673         CHECK(calls->handle_update_fulfill_htlc_meth != NULL);
4674         calls->handle_update_fail_htlc_meth = (*env)->GetMethodID(env, c, "handle_update_fail_htlc", "([BJ)V");
4675         CHECK(calls->handle_update_fail_htlc_meth != NULL);
4676         calls->handle_update_fail_malformed_htlc_meth = (*env)->GetMethodID(env, c, "handle_update_fail_malformed_htlc", "([BJ)V");
4677         CHECK(calls->handle_update_fail_malformed_htlc_meth != NULL);
4678         calls->handle_commitment_signed_meth = (*env)->GetMethodID(env, c, "handle_commitment_signed", "([BJ)V");
4679         CHECK(calls->handle_commitment_signed_meth != NULL);
4680         calls->handle_revoke_and_ack_meth = (*env)->GetMethodID(env, c, "handle_revoke_and_ack", "([BJ)V");
4681         CHECK(calls->handle_revoke_and_ack_meth != NULL);
4682         calls->handle_update_fee_meth = (*env)->GetMethodID(env, c, "handle_update_fee", "([BJ)V");
4683         CHECK(calls->handle_update_fee_meth != NULL);
4684         calls->handle_announcement_signatures_meth = (*env)->GetMethodID(env, c, "handle_announcement_signatures", "([BJ)V");
4685         CHECK(calls->handle_announcement_signatures_meth != NULL);
4686         calls->peer_disconnected_meth = (*env)->GetMethodID(env, c, "peer_disconnected", "([BZ)V");
4687         CHECK(calls->peer_disconnected_meth != NULL);
4688         calls->peer_connected_meth = (*env)->GetMethodID(env, c, "peer_connected", "([BJ)V");
4689         CHECK(calls->peer_connected_meth != NULL);
4690         calls->handle_channel_reestablish_meth = (*env)->GetMethodID(env, c, "handle_channel_reestablish", "([BJ)V");
4691         CHECK(calls->handle_channel_reestablish_meth != NULL);
4692         calls->handle_error_meth = (*env)->GetMethodID(env, c, "handle_error", "([BJ)V");
4693         CHECK(calls->handle_error_meth != NULL);
4694
4695         LDKChannelMessageHandler ret = {
4696                 .this_arg = (void*) calls,
4697                 .handle_open_channel = handle_open_channel_jcall,
4698                 .handle_accept_channel = handle_accept_channel_jcall,
4699                 .handle_funding_created = handle_funding_created_jcall,
4700                 .handle_funding_signed = handle_funding_signed_jcall,
4701                 .handle_funding_locked = handle_funding_locked_jcall,
4702                 .handle_shutdown = handle_shutdown_jcall,
4703                 .handle_closing_signed = handle_closing_signed_jcall,
4704                 .handle_update_add_htlc = handle_update_add_htlc_jcall,
4705                 .handle_update_fulfill_htlc = handle_update_fulfill_htlc_jcall,
4706                 .handle_update_fail_htlc = handle_update_fail_htlc_jcall,
4707                 .handle_update_fail_malformed_htlc = handle_update_fail_malformed_htlc_jcall,
4708                 .handle_commitment_signed = handle_commitment_signed_jcall,
4709                 .handle_revoke_and_ack = handle_revoke_and_ack_jcall,
4710                 .handle_update_fee = handle_update_fee_jcall,
4711                 .handle_announcement_signatures = handle_announcement_signatures_jcall,
4712                 .peer_disconnected = peer_disconnected_jcall,
4713                 .peer_connected = peer_connected_jcall,
4714                 .handle_channel_reestablish = handle_channel_reestablish_jcall,
4715                 .handle_error = handle_error_jcall,
4716                 .free = LDKChannelMessageHandler_JCalls_free,
4717                 .MessageSendEventsProvider = LDKMessageSendEventsProvider_init(env, clz, MessageSendEventsProvider),
4718         };
4719         calls->MessageSendEventsProvider = ret.MessageSendEventsProvider.this_arg;
4720         return ret;
4721 }
4722 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_LDKChannelMessageHandler_1new (JNIEnv *env, jclass clz, jobject o, jobject MessageSendEventsProvider) {
4723         LDKChannelMessageHandler *res_ptr = MALLOC(sizeof(LDKChannelMessageHandler), "LDKChannelMessageHandler");
4724         *res_ptr = LDKChannelMessageHandler_init(env, clz, o, MessageSendEventsProvider);
4725         return (long)res_ptr;
4726 }
4727 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelMessageHandler_1handle_1open_1channel(JNIEnv *env, jclass clz, int64_t this_arg, int8_tArray their_node_id, int64_t their_features, int64_t msg) {
4728         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
4729         LDKPublicKey their_node_id_ref;
4730         CHECK((*env)->GetArrayLength(env, their_node_id) == 33);
4731         (*env)->GetByteArrayRegion(env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
4732         LDKInitFeatures their_features_conv;
4733         their_features_conv.inner = (void*)(their_features & (~1));
4734         their_features_conv.is_owned = (their_features & 1) || (their_features == 0);
4735         // Warning: we may need a move here but can't clone!
4736         LDKOpenChannel msg_conv;
4737         msg_conv.inner = (void*)(msg & (~1));
4738         msg_conv.is_owned = false;
4739         (this_arg_conv->handle_open_channel)(this_arg_conv->this_arg, their_node_id_ref, their_features_conv, &msg_conv);
4740 }
4741
4742 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelMessageHandler_1handle_1accept_1channel(JNIEnv *env, jclass clz, int64_t this_arg, int8_tArray their_node_id, int64_t their_features, int64_t msg) {
4743         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
4744         LDKPublicKey their_node_id_ref;
4745         CHECK((*env)->GetArrayLength(env, their_node_id) == 33);
4746         (*env)->GetByteArrayRegion(env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
4747         LDKInitFeatures their_features_conv;
4748         their_features_conv.inner = (void*)(their_features & (~1));
4749         their_features_conv.is_owned = (their_features & 1) || (their_features == 0);
4750         // Warning: we may need a move here but can't clone!
4751         LDKAcceptChannel msg_conv;
4752         msg_conv.inner = (void*)(msg & (~1));
4753         msg_conv.is_owned = false;
4754         (this_arg_conv->handle_accept_channel)(this_arg_conv->this_arg, their_node_id_ref, their_features_conv, &msg_conv);
4755 }
4756
4757 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelMessageHandler_1handle_1funding_1created(JNIEnv *env, jclass clz, int64_t this_arg, int8_tArray their_node_id, int64_t msg) {
4758         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
4759         LDKPublicKey their_node_id_ref;
4760         CHECK((*env)->GetArrayLength(env, their_node_id) == 33);
4761         (*env)->GetByteArrayRegion(env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
4762         LDKFundingCreated msg_conv;
4763         msg_conv.inner = (void*)(msg & (~1));
4764         msg_conv.is_owned = false;
4765         (this_arg_conv->handle_funding_created)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
4766 }
4767
4768 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelMessageHandler_1handle_1funding_1signed(JNIEnv *env, jclass clz, int64_t this_arg, int8_tArray their_node_id, int64_t msg) {
4769         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
4770         LDKPublicKey their_node_id_ref;
4771         CHECK((*env)->GetArrayLength(env, their_node_id) == 33);
4772         (*env)->GetByteArrayRegion(env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
4773         LDKFundingSigned msg_conv;
4774         msg_conv.inner = (void*)(msg & (~1));
4775         msg_conv.is_owned = false;
4776         (this_arg_conv->handle_funding_signed)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
4777 }
4778
4779 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelMessageHandler_1handle_1funding_1locked(JNIEnv *env, jclass clz, int64_t this_arg, int8_tArray their_node_id, int64_t msg) {
4780         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
4781         LDKPublicKey their_node_id_ref;
4782         CHECK((*env)->GetArrayLength(env, their_node_id) == 33);
4783         (*env)->GetByteArrayRegion(env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
4784         LDKFundingLocked msg_conv;
4785         msg_conv.inner = (void*)(msg & (~1));
4786         msg_conv.is_owned = false;
4787         (this_arg_conv->handle_funding_locked)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
4788 }
4789
4790 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelMessageHandler_1handle_1shutdown(JNIEnv *env, jclass clz, int64_t this_arg, int8_tArray their_node_id, int64_t msg) {
4791         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
4792         LDKPublicKey their_node_id_ref;
4793         CHECK((*env)->GetArrayLength(env, their_node_id) == 33);
4794         (*env)->GetByteArrayRegion(env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
4795         LDKShutdown msg_conv;
4796         msg_conv.inner = (void*)(msg & (~1));
4797         msg_conv.is_owned = false;
4798         (this_arg_conv->handle_shutdown)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
4799 }
4800
4801 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelMessageHandler_1handle_1closing_1signed(JNIEnv *env, jclass clz, int64_t this_arg, int8_tArray their_node_id, int64_t msg) {
4802         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
4803         LDKPublicKey their_node_id_ref;
4804         CHECK((*env)->GetArrayLength(env, their_node_id) == 33);
4805         (*env)->GetByteArrayRegion(env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
4806         LDKClosingSigned msg_conv;
4807         msg_conv.inner = (void*)(msg & (~1));
4808         msg_conv.is_owned = false;
4809         (this_arg_conv->handle_closing_signed)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
4810 }
4811
4812 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelMessageHandler_1handle_1update_1add_1htlc(JNIEnv *env, jclass clz, int64_t this_arg, int8_tArray their_node_id, int64_t msg) {
4813         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
4814         LDKPublicKey their_node_id_ref;
4815         CHECK((*env)->GetArrayLength(env, their_node_id) == 33);
4816         (*env)->GetByteArrayRegion(env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
4817         LDKUpdateAddHTLC msg_conv;
4818         msg_conv.inner = (void*)(msg & (~1));
4819         msg_conv.is_owned = false;
4820         (this_arg_conv->handle_update_add_htlc)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
4821 }
4822
4823 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelMessageHandler_1handle_1update_1fulfill_1htlc(JNIEnv *env, jclass clz, int64_t this_arg, int8_tArray their_node_id, int64_t msg) {
4824         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
4825         LDKPublicKey their_node_id_ref;
4826         CHECK((*env)->GetArrayLength(env, their_node_id) == 33);
4827         (*env)->GetByteArrayRegion(env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
4828         LDKUpdateFulfillHTLC msg_conv;
4829         msg_conv.inner = (void*)(msg & (~1));
4830         msg_conv.is_owned = false;
4831         (this_arg_conv->handle_update_fulfill_htlc)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
4832 }
4833
4834 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelMessageHandler_1handle_1update_1fail_1htlc(JNIEnv *env, jclass clz, int64_t this_arg, int8_tArray their_node_id, int64_t msg) {
4835         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
4836         LDKPublicKey their_node_id_ref;
4837         CHECK((*env)->GetArrayLength(env, their_node_id) == 33);
4838         (*env)->GetByteArrayRegion(env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
4839         LDKUpdateFailHTLC msg_conv;
4840         msg_conv.inner = (void*)(msg & (~1));
4841         msg_conv.is_owned = false;
4842         (this_arg_conv->handle_update_fail_htlc)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
4843 }
4844
4845 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelMessageHandler_1handle_1update_1fail_1malformed_1htlc(JNIEnv *env, jclass clz, int64_t this_arg, int8_tArray their_node_id, int64_t msg) {
4846         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
4847         LDKPublicKey their_node_id_ref;
4848         CHECK((*env)->GetArrayLength(env, their_node_id) == 33);
4849         (*env)->GetByteArrayRegion(env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
4850         LDKUpdateFailMalformedHTLC msg_conv;
4851         msg_conv.inner = (void*)(msg & (~1));
4852         msg_conv.is_owned = false;
4853         (this_arg_conv->handle_update_fail_malformed_htlc)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
4854 }
4855
4856 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelMessageHandler_1handle_1commitment_1signed(JNIEnv *env, jclass clz, int64_t this_arg, int8_tArray their_node_id, int64_t msg) {
4857         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
4858         LDKPublicKey their_node_id_ref;
4859         CHECK((*env)->GetArrayLength(env, their_node_id) == 33);
4860         (*env)->GetByteArrayRegion(env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
4861         LDKCommitmentSigned msg_conv;
4862         msg_conv.inner = (void*)(msg & (~1));
4863         msg_conv.is_owned = false;
4864         (this_arg_conv->handle_commitment_signed)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
4865 }
4866
4867 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelMessageHandler_1handle_1revoke_1and_1ack(JNIEnv *env, jclass clz, int64_t this_arg, int8_tArray their_node_id, int64_t msg) {
4868         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
4869         LDKPublicKey their_node_id_ref;
4870         CHECK((*env)->GetArrayLength(env, their_node_id) == 33);
4871         (*env)->GetByteArrayRegion(env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
4872         LDKRevokeAndACK msg_conv;
4873         msg_conv.inner = (void*)(msg & (~1));
4874         msg_conv.is_owned = false;
4875         (this_arg_conv->handle_revoke_and_ack)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
4876 }
4877
4878 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelMessageHandler_1handle_1update_1fee(JNIEnv *env, jclass clz, int64_t this_arg, int8_tArray their_node_id, int64_t msg) {
4879         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
4880         LDKPublicKey their_node_id_ref;
4881         CHECK((*env)->GetArrayLength(env, their_node_id) == 33);
4882         (*env)->GetByteArrayRegion(env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
4883         LDKUpdateFee msg_conv;
4884         msg_conv.inner = (void*)(msg & (~1));
4885         msg_conv.is_owned = false;
4886         (this_arg_conv->handle_update_fee)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
4887 }
4888
4889 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelMessageHandler_1handle_1announcement_1signatures(JNIEnv *env, jclass clz, int64_t this_arg, int8_tArray their_node_id, int64_t msg) {
4890         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
4891         LDKPublicKey their_node_id_ref;
4892         CHECK((*env)->GetArrayLength(env, their_node_id) == 33);
4893         (*env)->GetByteArrayRegion(env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
4894         LDKAnnouncementSignatures msg_conv;
4895         msg_conv.inner = (void*)(msg & (~1));
4896         msg_conv.is_owned = false;
4897         (this_arg_conv->handle_announcement_signatures)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
4898 }
4899
4900 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelMessageHandler_1peer_1disconnected(JNIEnv *env, jclass clz, int64_t this_arg, int8_tArray their_node_id, jboolean no_connection_possible) {
4901         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
4902         LDKPublicKey their_node_id_ref;
4903         CHECK((*env)->GetArrayLength(env, their_node_id) == 33);
4904         (*env)->GetByteArrayRegion(env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
4905         (this_arg_conv->peer_disconnected)(this_arg_conv->this_arg, their_node_id_ref, no_connection_possible);
4906 }
4907
4908 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelMessageHandler_1peer_1connected(JNIEnv *env, jclass clz, int64_t this_arg, int8_tArray their_node_id, int64_t msg) {
4909         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
4910         LDKPublicKey their_node_id_ref;
4911         CHECK((*env)->GetArrayLength(env, their_node_id) == 33);
4912         (*env)->GetByteArrayRegion(env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
4913         LDKInit msg_conv;
4914         msg_conv.inner = (void*)(msg & (~1));
4915         msg_conv.is_owned = false;
4916         (this_arg_conv->peer_connected)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
4917 }
4918
4919 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelMessageHandler_1handle_1channel_1reestablish(JNIEnv *env, jclass clz, int64_t this_arg, int8_tArray their_node_id, int64_t msg) {
4920         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
4921         LDKPublicKey their_node_id_ref;
4922         CHECK((*env)->GetArrayLength(env, their_node_id) == 33);
4923         (*env)->GetByteArrayRegion(env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
4924         LDKChannelReestablish msg_conv;
4925         msg_conv.inner = (void*)(msg & (~1));
4926         msg_conv.is_owned = false;
4927         (this_arg_conv->handle_channel_reestablish)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
4928 }
4929
4930 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelMessageHandler_1handle_1error(JNIEnv *env, jclass clz, int64_t this_arg, int8_tArray their_node_id, int64_t msg) {
4931         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
4932         LDKPublicKey their_node_id_ref;
4933         CHECK((*env)->GetArrayLength(env, their_node_id) == 33);
4934         (*env)->GetByteArrayRegion(env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
4935         LDKErrorMessage msg_conv;
4936         msg_conv.inner = (void*)(msg & (~1));
4937         msg_conv.is_owned = false;
4938         (this_arg_conv->handle_error)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
4939 }
4940
4941 typedef struct LDKRoutingMessageHandler_JCalls {
4942         atomic_size_t refcnt;
4943         JavaVM *vm;
4944         jweak o;
4945         LDKMessageSendEventsProvider_JCalls* MessageSendEventsProvider;
4946         jmethodID handle_node_announcement_meth;
4947         jmethodID handle_channel_announcement_meth;
4948         jmethodID handle_channel_update_meth;
4949         jmethodID handle_htlc_fail_channel_update_meth;
4950         jmethodID get_next_channel_announcements_meth;
4951         jmethodID get_next_node_announcements_meth;
4952         jmethodID sync_routing_table_meth;
4953         jmethodID handle_reply_channel_range_meth;
4954         jmethodID handle_reply_short_channel_ids_end_meth;
4955         jmethodID handle_query_channel_range_meth;
4956         jmethodID handle_query_short_channel_ids_meth;
4957 } LDKRoutingMessageHandler_JCalls;
4958 static void LDKRoutingMessageHandler_JCalls_free(void* this_arg) {
4959         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
4960         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
4961                 JNIEnv *env;
4962                 DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
4963                 (*env)->DeleteWeakGlobalRef(env, j_calls->o);
4964                 FREE(j_calls);
4965         }
4966 }
4967 LDKCResult_boolLightningErrorZ handle_node_announcement_jcall(const void* this_arg, const LDKNodeAnnouncement * msg) {
4968         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
4969         JNIEnv *env;
4970         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
4971         LDKNodeAnnouncement msg_var = *msg;
4972         if (msg->inner != NULL)
4973                 msg_var = NodeAnnouncement_clone(msg);
4974         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4975         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4976         long msg_ref = (long)msg_var.inner;
4977         if (msg_var.is_owned) {
4978                 msg_ref |= 1;
4979         }
4980         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
4981         CHECK(obj != NULL);
4982         LDKCResult_boolLightningErrorZ* ret = (LDKCResult_boolLightningErrorZ*)(*env)->CallLongMethod(env, obj, j_calls->handle_node_announcement_meth, msg_ref);
4983         LDKCResult_boolLightningErrorZ ret_conv = *(LDKCResult_boolLightningErrorZ*)ret;
4984         FREE((void*)ret);
4985         return ret_conv;
4986 }
4987 LDKCResult_boolLightningErrorZ handle_channel_announcement_jcall(const void* this_arg, const LDKChannelAnnouncement * msg) {
4988         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
4989         JNIEnv *env;
4990         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
4991         LDKChannelAnnouncement msg_var = *msg;
4992         if (msg->inner != NULL)
4993                 msg_var = ChannelAnnouncement_clone(msg);
4994         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4995         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4996         long msg_ref = (long)msg_var.inner;
4997         if (msg_var.is_owned) {
4998                 msg_ref |= 1;
4999         }
5000         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
5001         CHECK(obj != NULL);
5002         LDKCResult_boolLightningErrorZ* ret = (LDKCResult_boolLightningErrorZ*)(*env)->CallLongMethod(env, obj, j_calls->handle_channel_announcement_meth, msg_ref);
5003         LDKCResult_boolLightningErrorZ ret_conv = *(LDKCResult_boolLightningErrorZ*)ret;
5004         FREE((void*)ret);
5005         return ret_conv;
5006 }
5007 LDKCResult_boolLightningErrorZ handle_channel_update_jcall(const void* this_arg, const LDKChannelUpdate * msg) {
5008         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
5009         JNIEnv *env;
5010         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
5011         LDKChannelUpdate msg_var = *msg;
5012         if (msg->inner != NULL)
5013                 msg_var = ChannelUpdate_clone(msg);
5014         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
5015         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
5016         long msg_ref = (long)msg_var.inner;
5017         if (msg_var.is_owned) {
5018                 msg_ref |= 1;
5019         }
5020         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
5021         CHECK(obj != NULL);
5022         LDKCResult_boolLightningErrorZ* ret = (LDKCResult_boolLightningErrorZ*)(*env)->CallLongMethod(env, obj, j_calls->handle_channel_update_meth, msg_ref);
5023         LDKCResult_boolLightningErrorZ ret_conv = *(LDKCResult_boolLightningErrorZ*)ret;
5024         FREE((void*)ret);
5025         return ret_conv;
5026 }
5027 void handle_htlc_fail_channel_update_jcall(const void* this_arg, const LDKHTLCFailChannelUpdate * update) {
5028         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
5029         JNIEnv *env;
5030         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
5031         long ret_update = (long)update;
5032         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
5033         CHECK(obj != NULL);
5034         return (*env)->CallVoidMethod(env, obj, j_calls->handle_htlc_fail_channel_update_meth, ret_update);
5035 }
5036 LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ get_next_channel_announcements_jcall(const void* this_arg, uint64_t starting_point, uint8_t batch_amount) {
5037         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
5038         JNIEnv *env;
5039         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
5040         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
5041         CHECK(obj != NULL);
5042         int64_tArray arg = (*env)->CallObjectMethod(env, obj, j_calls->get_next_channel_announcements_meth, starting_point, batch_amount);
5043         LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ arg_constr;
5044         arg_constr.datalen = (*env)->GetArrayLength(env, arg);
5045         if (arg_constr.datalen > 0)
5046                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ), "LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ Elements");
5047         else
5048                 arg_constr.data = NULL;
5049         int64_t* arg_vals = (*env)->GetLongArrayElements (env, arg, NULL);
5050         for (size_t l = 0; l < arg_constr.datalen; l++) {
5051                 int64_t arr_conv_63 = arg_vals[l];
5052                 LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ arr_conv_63_conv = *(LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ*)arr_conv_63;
5053                 FREE((void*)arr_conv_63);
5054                 arg_constr.data[l] = arr_conv_63_conv;
5055         }
5056         (*env)->ReleaseLongArrayElements(env, arg, arg_vals, 0);
5057         return arg_constr;
5058 }
5059 LDKCVec_NodeAnnouncementZ get_next_node_announcements_jcall(const void* this_arg, LDKPublicKey starting_point, uint8_t batch_amount) {
5060         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
5061         JNIEnv *env;
5062         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
5063         int8_tArray starting_point_arr = (*env)->NewByteArray(env, 33);
5064         (*env)->SetByteArrayRegion(env, starting_point_arr, 0, 33, starting_point.compressed_form);
5065         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
5066         CHECK(obj != NULL);
5067         int64_tArray arg = (*env)->CallObjectMethod(env, obj, j_calls->get_next_node_announcements_meth, starting_point_arr, batch_amount);
5068         LDKCVec_NodeAnnouncementZ arg_constr;
5069         arg_constr.datalen = (*env)->GetArrayLength(env, arg);
5070         if (arg_constr.datalen > 0)
5071                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKNodeAnnouncement), "LDKCVec_NodeAnnouncementZ Elements");
5072         else
5073                 arg_constr.data = NULL;
5074         int64_t* arg_vals = (*env)->GetLongArrayElements (env, arg, NULL);
5075         for (size_t s = 0; s < arg_constr.datalen; s++) {
5076                 int64_t arr_conv_18 = arg_vals[s];
5077                 LDKNodeAnnouncement arr_conv_18_conv;
5078                 arr_conv_18_conv.inner = (void*)(arr_conv_18 & (~1));
5079                 arr_conv_18_conv.is_owned = (arr_conv_18 & 1) || (arr_conv_18 == 0);
5080                 if (arr_conv_18_conv.inner != NULL)
5081                         arr_conv_18_conv = NodeAnnouncement_clone(&arr_conv_18_conv);
5082                 arg_constr.data[s] = arr_conv_18_conv;
5083         }
5084         (*env)->ReleaseLongArrayElements(env, arg, arg_vals, 0);
5085         return arg_constr;
5086 }
5087 void sync_routing_table_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKInit * init) {
5088         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
5089         JNIEnv *env;
5090         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
5091         int8_tArray their_node_id_arr = (*env)->NewByteArray(env, 33);
5092         (*env)->SetByteArrayRegion(env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
5093         LDKInit init_var = *init;
5094         if (init->inner != NULL)
5095                 init_var = Init_clone(init);
5096         CHECK((((long)init_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
5097         CHECK((((long)&init_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
5098         long init_ref = (long)init_var.inner;
5099         if (init_var.is_owned) {
5100                 init_ref |= 1;
5101         }
5102         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
5103         CHECK(obj != NULL);
5104         return (*env)->CallVoidMethod(env, obj, j_calls->sync_routing_table_meth, their_node_id_arr, init_ref);
5105 }
5106 LDKCResult_NoneLightningErrorZ handle_reply_channel_range_jcall(const void* this_arg, LDKPublicKey their_node_id, LDKReplyChannelRange msg) {
5107         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
5108         JNIEnv *env;
5109         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
5110         int8_tArray their_node_id_arr = (*env)->NewByteArray(env, 33);
5111         (*env)->SetByteArrayRegion(env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
5112         LDKReplyChannelRange msg_var = msg;
5113         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
5114         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
5115         long msg_ref = (long)msg_var.inner;
5116         if (msg_var.is_owned) {
5117                 msg_ref |= 1;
5118         }
5119         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
5120         CHECK(obj != NULL);
5121         LDKCResult_NoneLightningErrorZ* ret = (LDKCResult_NoneLightningErrorZ*)(*env)->CallLongMethod(env, obj, j_calls->handle_reply_channel_range_meth, their_node_id_arr, msg_ref);
5122         LDKCResult_NoneLightningErrorZ ret_conv = *(LDKCResult_NoneLightningErrorZ*)ret;
5123         FREE((void*)ret);
5124         return ret_conv;
5125 }
5126 LDKCResult_NoneLightningErrorZ handle_reply_short_channel_ids_end_jcall(const void* this_arg, LDKPublicKey their_node_id, LDKReplyShortChannelIdsEnd msg) {
5127         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
5128         JNIEnv *env;
5129         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
5130         int8_tArray their_node_id_arr = (*env)->NewByteArray(env, 33);
5131         (*env)->SetByteArrayRegion(env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
5132         LDKReplyShortChannelIdsEnd msg_var = msg;
5133         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
5134         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
5135         long msg_ref = (long)msg_var.inner;
5136         if (msg_var.is_owned) {
5137                 msg_ref |= 1;
5138         }
5139         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
5140         CHECK(obj != NULL);
5141         LDKCResult_NoneLightningErrorZ* ret = (LDKCResult_NoneLightningErrorZ*)(*env)->CallLongMethod(env, obj, j_calls->handle_reply_short_channel_ids_end_meth, their_node_id_arr, msg_ref);
5142         LDKCResult_NoneLightningErrorZ ret_conv = *(LDKCResult_NoneLightningErrorZ*)ret;
5143         FREE((void*)ret);
5144         return ret_conv;
5145 }
5146 LDKCResult_NoneLightningErrorZ handle_query_channel_range_jcall(const void* this_arg, LDKPublicKey their_node_id, LDKQueryChannelRange msg) {
5147         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
5148         JNIEnv *env;
5149         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
5150         int8_tArray their_node_id_arr = (*env)->NewByteArray(env, 33);
5151         (*env)->SetByteArrayRegion(env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
5152         LDKQueryChannelRange msg_var = msg;
5153         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
5154         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
5155         long msg_ref = (long)msg_var.inner;
5156         if (msg_var.is_owned) {
5157                 msg_ref |= 1;
5158         }
5159         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
5160         CHECK(obj != NULL);
5161         LDKCResult_NoneLightningErrorZ* ret = (LDKCResult_NoneLightningErrorZ*)(*env)->CallLongMethod(env, obj, j_calls->handle_query_channel_range_meth, their_node_id_arr, msg_ref);
5162         LDKCResult_NoneLightningErrorZ ret_conv = *(LDKCResult_NoneLightningErrorZ*)ret;
5163         FREE((void*)ret);
5164         return ret_conv;
5165 }
5166 LDKCResult_NoneLightningErrorZ handle_query_short_channel_ids_jcall(const void* this_arg, LDKPublicKey their_node_id, LDKQueryShortChannelIds msg) {
5167         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
5168         JNIEnv *env;
5169         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
5170         int8_tArray their_node_id_arr = (*env)->NewByteArray(env, 33);
5171         (*env)->SetByteArrayRegion(env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
5172         LDKQueryShortChannelIds msg_var = msg;
5173         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
5174         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
5175         long msg_ref = (long)msg_var.inner;
5176         if (msg_var.is_owned) {
5177                 msg_ref |= 1;
5178         }
5179         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
5180         CHECK(obj != NULL);
5181         LDKCResult_NoneLightningErrorZ* ret = (LDKCResult_NoneLightningErrorZ*)(*env)->CallLongMethod(env, obj, j_calls->handle_query_short_channel_ids_meth, their_node_id_arr, msg_ref);
5182         LDKCResult_NoneLightningErrorZ ret_conv = *(LDKCResult_NoneLightningErrorZ*)ret;
5183         FREE((void*)ret);
5184         return ret_conv;
5185 }
5186 static void* LDKRoutingMessageHandler_JCalls_clone(const void* this_arg) {
5187         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
5188         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
5189         atomic_fetch_add_explicit(&j_calls->MessageSendEventsProvider->refcnt, 1, memory_order_release);
5190         return (void*) this_arg;
5191 }
5192 static inline LDKRoutingMessageHandler LDKRoutingMessageHandler_init (JNIEnv *env, jclass clz, jobject o, jobject MessageSendEventsProvider) {
5193         jclass c = (*env)->GetObjectClass(env, o);
5194         CHECK(c != NULL);
5195         LDKRoutingMessageHandler_JCalls *calls = MALLOC(sizeof(LDKRoutingMessageHandler_JCalls), "LDKRoutingMessageHandler_JCalls");
5196         atomic_init(&calls->refcnt, 1);
5197         DO_ASSERT((*env)->GetJavaVM(env, &calls->vm) == 0);
5198         calls->o = (*env)->NewWeakGlobalRef(env, o);
5199         calls->handle_node_announcement_meth = (*env)->GetMethodID(env, c, "handle_node_announcement", "(J)J");
5200         CHECK(calls->handle_node_announcement_meth != NULL);
5201         calls->handle_channel_announcement_meth = (*env)->GetMethodID(env, c, "handle_channel_announcement", "(J)J");
5202         CHECK(calls->handle_channel_announcement_meth != NULL);
5203         calls->handle_channel_update_meth = (*env)->GetMethodID(env, c, "handle_channel_update", "(J)J");
5204         CHECK(calls->handle_channel_update_meth != NULL);
5205         calls->handle_htlc_fail_channel_update_meth = (*env)->GetMethodID(env, c, "handle_htlc_fail_channel_update", "(J)V");
5206         CHECK(calls->handle_htlc_fail_channel_update_meth != NULL);
5207         calls->get_next_channel_announcements_meth = (*env)->GetMethodID(env, c, "get_next_channel_announcements", "(JB)[J");
5208         CHECK(calls->get_next_channel_announcements_meth != NULL);
5209         calls->get_next_node_announcements_meth = (*env)->GetMethodID(env, c, "get_next_node_announcements", "([BB)[J");
5210         CHECK(calls->get_next_node_announcements_meth != NULL);
5211         calls->sync_routing_table_meth = (*env)->GetMethodID(env, c, "sync_routing_table", "([BJ)V");
5212         CHECK(calls->sync_routing_table_meth != NULL);
5213         calls->handle_reply_channel_range_meth = (*env)->GetMethodID(env, c, "handle_reply_channel_range", "([BJ)J");
5214         CHECK(calls->handle_reply_channel_range_meth != NULL);
5215         calls->handle_reply_short_channel_ids_end_meth = (*env)->GetMethodID(env, c, "handle_reply_short_channel_ids_end", "([BJ)J");
5216         CHECK(calls->handle_reply_short_channel_ids_end_meth != NULL);
5217         calls->handle_query_channel_range_meth = (*env)->GetMethodID(env, c, "handle_query_channel_range", "([BJ)J");
5218         CHECK(calls->handle_query_channel_range_meth != NULL);
5219         calls->handle_query_short_channel_ids_meth = (*env)->GetMethodID(env, c, "handle_query_short_channel_ids", "([BJ)J");
5220         CHECK(calls->handle_query_short_channel_ids_meth != NULL);
5221
5222         LDKRoutingMessageHandler ret = {
5223                 .this_arg = (void*) calls,
5224                 .handle_node_announcement = handle_node_announcement_jcall,
5225                 .handle_channel_announcement = handle_channel_announcement_jcall,
5226                 .handle_channel_update = handle_channel_update_jcall,
5227                 .handle_htlc_fail_channel_update = handle_htlc_fail_channel_update_jcall,
5228                 .get_next_channel_announcements = get_next_channel_announcements_jcall,
5229                 .get_next_node_announcements = get_next_node_announcements_jcall,
5230                 .sync_routing_table = sync_routing_table_jcall,
5231                 .handle_reply_channel_range = handle_reply_channel_range_jcall,
5232                 .handle_reply_short_channel_ids_end = handle_reply_short_channel_ids_end_jcall,
5233                 .handle_query_channel_range = handle_query_channel_range_jcall,
5234                 .handle_query_short_channel_ids = handle_query_short_channel_ids_jcall,
5235                 .free = LDKRoutingMessageHandler_JCalls_free,
5236                 .MessageSendEventsProvider = LDKMessageSendEventsProvider_init(env, clz, MessageSendEventsProvider),
5237         };
5238         calls->MessageSendEventsProvider = ret.MessageSendEventsProvider.this_arg;
5239         return ret;
5240 }
5241 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_LDKRoutingMessageHandler_1new (JNIEnv *env, jclass clz, jobject o, jobject MessageSendEventsProvider) {
5242         LDKRoutingMessageHandler *res_ptr = MALLOC(sizeof(LDKRoutingMessageHandler), "LDKRoutingMessageHandler");
5243         *res_ptr = LDKRoutingMessageHandler_init(env, clz, o, MessageSendEventsProvider);
5244         return (long)res_ptr;
5245 }
5246 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_RoutingMessageHandler_1handle_1node_1announcement(JNIEnv *env, jclass clz, int64_t this_arg, int64_t msg) {
5247         LDKRoutingMessageHandler* this_arg_conv = (LDKRoutingMessageHandler*)this_arg;
5248         LDKNodeAnnouncement msg_conv;
5249         msg_conv.inner = (void*)(msg & (~1));
5250         msg_conv.is_owned = false;
5251         LDKCResult_boolLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_boolLightningErrorZ), "LDKCResult_boolLightningErrorZ");
5252         *ret_conv = (this_arg_conv->handle_node_announcement)(this_arg_conv->this_arg, &msg_conv);
5253         return (long)ret_conv;
5254 }
5255
5256 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_RoutingMessageHandler_1handle_1channel_1announcement(JNIEnv *env, jclass clz, int64_t this_arg, int64_t msg) {
5257         LDKRoutingMessageHandler* this_arg_conv = (LDKRoutingMessageHandler*)this_arg;
5258         LDKChannelAnnouncement msg_conv;
5259         msg_conv.inner = (void*)(msg & (~1));
5260         msg_conv.is_owned = false;
5261         LDKCResult_boolLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_boolLightningErrorZ), "LDKCResult_boolLightningErrorZ");
5262         *ret_conv = (this_arg_conv->handle_channel_announcement)(this_arg_conv->this_arg, &msg_conv);
5263         return (long)ret_conv;
5264 }
5265
5266 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_RoutingMessageHandler_1handle_1channel_1update(JNIEnv *env, jclass clz, int64_t this_arg, int64_t msg) {
5267         LDKRoutingMessageHandler* this_arg_conv = (LDKRoutingMessageHandler*)this_arg;
5268         LDKChannelUpdate msg_conv;
5269         msg_conv.inner = (void*)(msg & (~1));
5270         msg_conv.is_owned = false;
5271         LDKCResult_boolLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_boolLightningErrorZ), "LDKCResult_boolLightningErrorZ");
5272         *ret_conv = (this_arg_conv->handle_channel_update)(this_arg_conv->this_arg, &msg_conv);
5273         return (long)ret_conv;
5274 }
5275
5276 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RoutingMessageHandler_1handle_1htlc_1fail_1channel_1update(JNIEnv *env, jclass clz, int64_t this_arg, int64_t update) {
5277         LDKRoutingMessageHandler* this_arg_conv = (LDKRoutingMessageHandler*)this_arg;
5278         LDKHTLCFailChannelUpdate* update_conv = (LDKHTLCFailChannelUpdate*)update;
5279         (this_arg_conv->handle_htlc_fail_channel_update)(this_arg_conv->this_arg, update_conv);
5280 }
5281
5282 JNIEXPORT int64_tArray JNICALL Java_org_ldk_impl_bindings_RoutingMessageHandler_1get_1next_1channel_1announcements(JNIEnv *env, jclass clz, int64_t this_arg, int64_t starting_point, int8_t batch_amount) {
5283         LDKRoutingMessageHandler* this_arg_conv = (LDKRoutingMessageHandler*)this_arg;
5284         LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ ret_var = (this_arg_conv->get_next_channel_announcements)(this_arg_conv->this_arg, starting_point, batch_amount);
5285         int64_tArray ret_arr = (*env)->NewLongArray(env, ret_var.datalen);
5286         int64_t *ret_arr_ptr = (*env)->GetPrimitiveArrayCritical(env, ret_arr, NULL);
5287         for (size_t l = 0; l < ret_var.datalen; l++) {
5288                 LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ* arr_conv_63_ref = MALLOC(sizeof(LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ), "LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ");
5289                 *arr_conv_63_ref = ret_var.data[l];
5290                 arr_conv_63_ref->a = ChannelAnnouncement_clone(&arr_conv_63_ref->a);
5291                 arr_conv_63_ref->b = ChannelUpdate_clone(&arr_conv_63_ref->b);
5292                 arr_conv_63_ref->c = ChannelUpdate_clone(&arr_conv_63_ref->c);
5293                 ret_arr_ptr[l] = (long)arr_conv_63_ref;
5294         }
5295         (*env)->ReleasePrimitiveArrayCritical(env, ret_arr, ret_arr_ptr, 0);
5296         FREE(ret_var.data);
5297         return ret_arr;
5298 }
5299
5300 JNIEXPORT int64_tArray JNICALL Java_org_ldk_impl_bindings_RoutingMessageHandler_1get_1next_1node_1announcements(JNIEnv *env, jclass clz, int64_t this_arg, int8_tArray starting_point, int8_t batch_amount) {
5301         LDKRoutingMessageHandler* this_arg_conv = (LDKRoutingMessageHandler*)this_arg;
5302         LDKPublicKey starting_point_ref;
5303         CHECK((*env)->GetArrayLength(env, starting_point) == 33);
5304         (*env)->GetByteArrayRegion(env, starting_point, 0, 33, starting_point_ref.compressed_form);
5305         LDKCVec_NodeAnnouncementZ ret_var = (this_arg_conv->get_next_node_announcements)(this_arg_conv->this_arg, starting_point_ref, batch_amount);
5306         int64_tArray ret_arr = (*env)->NewLongArray(env, ret_var.datalen);
5307         int64_t *ret_arr_ptr = (*env)->GetPrimitiveArrayCritical(env, ret_arr, NULL);
5308         for (size_t s = 0; s < ret_var.datalen; s++) {
5309                 LDKNodeAnnouncement arr_conv_18_var = ret_var.data[s];
5310                 CHECK((((long)arr_conv_18_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
5311                 CHECK((((long)&arr_conv_18_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
5312                 long arr_conv_18_ref = (long)arr_conv_18_var.inner;
5313                 if (arr_conv_18_var.is_owned) {
5314                         arr_conv_18_ref |= 1;
5315                 }
5316                 ret_arr_ptr[s] = arr_conv_18_ref;
5317         }
5318         (*env)->ReleasePrimitiveArrayCritical(env, ret_arr, ret_arr_ptr, 0);
5319         FREE(ret_var.data);
5320         return ret_arr;
5321 }
5322
5323 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RoutingMessageHandler_1sync_1routing_1table(JNIEnv *env, jclass clz, int64_t this_arg, int8_tArray their_node_id, int64_t init) {
5324         LDKRoutingMessageHandler* this_arg_conv = (LDKRoutingMessageHandler*)this_arg;
5325         LDKPublicKey their_node_id_ref;
5326         CHECK((*env)->GetArrayLength(env, their_node_id) == 33);
5327         (*env)->GetByteArrayRegion(env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
5328         LDKInit init_conv;
5329         init_conv.inner = (void*)(init & (~1));
5330         init_conv.is_owned = false;
5331         (this_arg_conv->sync_routing_table)(this_arg_conv->this_arg, their_node_id_ref, &init_conv);
5332 }
5333
5334 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_RoutingMessageHandler_1handle_1reply_1channel_1range(JNIEnv *env, jclass clz, int64_t this_arg, int8_tArray their_node_id, int64_t msg) {
5335         LDKRoutingMessageHandler* this_arg_conv = (LDKRoutingMessageHandler*)this_arg;
5336         LDKPublicKey their_node_id_ref;
5337         CHECK((*env)->GetArrayLength(env, their_node_id) == 33);
5338         (*env)->GetByteArrayRegion(env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
5339         LDKReplyChannelRange msg_conv;
5340         msg_conv.inner = (void*)(msg & (~1));
5341         msg_conv.is_owned = (msg & 1) || (msg == 0);
5342         if (msg_conv.inner != NULL)
5343                 msg_conv = ReplyChannelRange_clone(&msg_conv);
5344         LDKCResult_NoneLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneLightningErrorZ), "LDKCResult_NoneLightningErrorZ");
5345         *ret_conv = (this_arg_conv->handle_reply_channel_range)(this_arg_conv->this_arg, their_node_id_ref, msg_conv);
5346         return (long)ret_conv;
5347 }
5348
5349 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_RoutingMessageHandler_1handle_1reply_1short_1channel_1ids_1end(JNIEnv *env, jclass clz, int64_t this_arg, int8_tArray their_node_id, int64_t msg) {
5350         LDKRoutingMessageHandler* this_arg_conv = (LDKRoutingMessageHandler*)this_arg;
5351         LDKPublicKey their_node_id_ref;
5352         CHECK((*env)->GetArrayLength(env, their_node_id) == 33);
5353         (*env)->GetByteArrayRegion(env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
5354         LDKReplyShortChannelIdsEnd msg_conv;
5355         msg_conv.inner = (void*)(msg & (~1));
5356         msg_conv.is_owned = (msg & 1) || (msg == 0);
5357         if (msg_conv.inner != NULL)
5358                 msg_conv = ReplyShortChannelIdsEnd_clone(&msg_conv);
5359         LDKCResult_NoneLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneLightningErrorZ), "LDKCResult_NoneLightningErrorZ");
5360         *ret_conv = (this_arg_conv->handle_reply_short_channel_ids_end)(this_arg_conv->this_arg, their_node_id_ref, msg_conv);
5361         return (long)ret_conv;
5362 }
5363
5364 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_RoutingMessageHandler_1handle_1query_1channel_1range(JNIEnv *env, jclass clz, int64_t this_arg, int8_tArray their_node_id, int64_t msg) {
5365         LDKRoutingMessageHandler* this_arg_conv = (LDKRoutingMessageHandler*)this_arg;
5366         LDKPublicKey their_node_id_ref;
5367         CHECK((*env)->GetArrayLength(env, their_node_id) == 33);
5368         (*env)->GetByteArrayRegion(env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
5369         LDKQueryChannelRange msg_conv;
5370         msg_conv.inner = (void*)(msg & (~1));
5371         msg_conv.is_owned = (msg & 1) || (msg == 0);
5372         if (msg_conv.inner != NULL)
5373                 msg_conv = QueryChannelRange_clone(&msg_conv);
5374         LDKCResult_NoneLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneLightningErrorZ), "LDKCResult_NoneLightningErrorZ");
5375         *ret_conv = (this_arg_conv->handle_query_channel_range)(this_arg_conv->this_arg, their_node_id_ref, msg_conv);
5376         return (long)ret_conv;
5377 }
5378
5379 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_RoutingMessageHandler_1handle_1query_1short_1channel_1ids(JNIEnv *env, jclass clz, int64_t this_arg, int8_tArray their_node_id, int64_t msg) {
5380         LDKRoutingMessageHandler* this_arg_conv = (LDKRoutingMessageHandler*)this_arg;
5381         LDKPublicKey their_node_id_ref;
5382         CHECK((*env)->GetArrayLength(env, their_node_id) == 33);
5383         (*env)->GetByteArrayRegion(env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
5384         LDKQueryShortChannelIds msg_conv;
5385         msg_conv.inner = (void*)(msg & (~1));
5386         msg_conv.is_owned = (msg & 1) || (msg == 0);
5387         if (msg_conv.inner != NULL)
5388                 msg_conv = QueryShortChannelIds_clone(&msg_conv);
5389         LDKCResult_NoneLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneLightningErrorZ), "LDKCResult_NoneLightningErrorZ");
5390         *ret_conv = (this_arg_conv->handle_query_short_channel_ids)(this_arg_conv->this_arg, their_node_id_ref, msg_conv);
5391         return (long)ret_conv;
5392 }
5393
5394 typedef struct LDKSocketDescriptor_JCalls {
5395         atomic_size_t refcnt;
5396         JavaVM *vm;
5397         jweak o;
5398         jmethodID send_data_meth;
5399         jmethodID disconnect_socket_meth;
5400         jmethodID eq_meth;
5401         jmethodID hash_meth;
5402 } LDKSocketDescriptor_JCalls;
5403 static void LDKSocketDescriptor_JCalls_free(void* this_arg) {
5404         LDKSocketDescriptor_JCalls *j_calls = (LDKSocketDescriptor_JCalls*) this_arg;
5405         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
5406                 JNIEnv *env;
5407                 DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
5408                 (*env)->DeleteWeakGlobalRef(env, j_calls->o);
5409                 FREE(j_calls);
5410         }
5411 }
5412 uintptr_t send_data_jcall(void* this_arg, LDKu8slice data, bool resume_read) {
5413         LDKSocketDescriptor_JCalls *j_calls = (LDKSocketDescriptor_JCalls*) this_arg;
5414         JNIEnv *env;
5415         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
5416         LDKu8slice data_var = data;
5417         int8_tArray data_arr = (*env)->NewByteArray(env, data_var.datalen);
5418         (*env)->SetByteArrayRegion(env, data_arr, 0, data_var.datalen, data_var.data);
5419         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
5420         CHECK(obj != NULL);
5421         return (*env)->CallLongMethod(env, obj, j_calls->send_data_meth, data_arr, resume_read);
5422 }
5423 void disconnect_socket_jcall(void* this_arg) {
5424         LDKSocketDescriptor_JCalls *j_calls = (LDKSocketDescriptor_JCalls*) this_arg;
5425         JNIEnv *env;
5426         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
5427         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
5428         CHECK(obj != NULL);
5429         return (*env)->CallVoidMethod(env, obj, j_calls->disconnect_socket_meth);
5430 }
5431 bool eq_jcall(const void* this_arg, const LDKSocketDescriptor * other_arg) {
5432         LDKSocketDescriptor_JCalls *j_calls = (LDKSocketDescriptor_JCalls*) this_arg;
5433         JNIEnv *env;
5434         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
5435         LDKSocketDescriptor *other_arg_clone = MALLOC(sizeof(LDKSocketDescriptor), "LDKSocketDescriptor");
5436         *other_arg_clone = SocketDescriptor_clone(other_arg);
5437         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
5438         CHECK(obj != NULL);
5439         return (*env)->CallBooleanMethod(env, obj, j_calls->eq_meth, (long)other_arg_clone);
5440 }
5441 uint64_t hash_jcall(const void* this_arg) {
5442         LDKSocketDescriptor_JCalls *j_calls = (LDKSocketDescriptor_JCalls*) this_arg;
5443         JNIEnv *env;
5444         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
5445         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
5446         CHECK(obj != NULL);
5447         return (*env)->CallLongMethod(env, obj, j_calls->hash_meth);
5448 }
5449 static void* LDKSocketDescriptor_JCalls_clone(const void* this_arg) {
5450         LDKSocketDescriptor_JCalls *j_calls = (LDKSocketDescriptor_JCalls*) this_arg;
5451         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
5452         return (void*) this_arg;
5453 }
5454 static inline LDKSocketDescriptor LDKSocketDescriptor_init (JNIEnv *env, jclass clz, jobject o) {
5455         jclass c = (*env)->GetObjectClass(env, o);
5456         CHECK(c != NULL);
5457         LDKSocketDescriptor_JCalls *calls = MALLOC(sizeof(LDKSocketDescriptor_JCalls), "LDKSocketDescriptor_JCalls");
5458         atomic_init(&calls->refcnt, 1);
5459         DO_ASSERT((*env)->GetJavaVM(env, &calls->vm) == 0);
5460         calls->o = (*env)->NewWeakGlobalRef(env, o);
5461         calls->send_data_meth = (*env)->GetMethodID(env, c, "send_data", "([BZ)J");
5462         CHECK(calls->send_data_meth != NULL);
5463         calls->disconnect_socket_meth = (*env)->GetMethodID(env, c, "disconnect_socket", "()V");
5464         CHECK(calls->disconnect_socket_meth != NULL);
5465         calls->eq_meth = (*env)->GetMethodID(env, c, "eq", "(J)Z");
5466         CHECK(calls->eq_meth != NULL);
5467         calls->hash_meth = (*env)->GetMethodID(env, c, "hash", "()J");
5468         CHECK(calls->hash_meth != NULL);
5469
5470         LDKSocketDescriptor ret = {
5471                 .this_arg = (void*) calls,
5472                 .send_data = send_data_jcall,
5473                 .disconnect_socket = disconnect_socket_jcall,
5474                 .eq = eq_jcall,
5475                 .hash = hash_jcall,
5476                 .clone = LDKSocketDescriptor_JCalls_clone,
5477                 .free = LDKSocketDescriptor_JCalls_free,
5478         };
5479         return ret;
5480 }
5481 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_LDKSocketDescriptor_1new (JNIEnv *env, jclass clz, jobject o) {
5482         LDKSocketDescriptor *res_ptr = MALLOC(sizeof(LDKSocketDescriptor), "LDKSocketDescriptor");
5483         *res_ptr = LDKSocketDescriptor_init(env, clz, o);
5484         return (long)res_ptr;
5485 }
5486 JNIEXPORT intptr_t JNICALL Java_org_ldk_impl_bindings_SocketDescriptor_1send_1data(JNIEnv *env, jclass clz, int64_t this_arg, int8_tArray data, jboolean resume_read) {
5487         LDKSocketDescriptor* this_arg_conv = (LDKSocketDescriptor*)this_arg;
5488         LDKu8slice data_ref;
5489         data_ref.datalen = (*env)->GetArrayLength(env, data);
5490         data_ref.data = (*env)->GetByteArrayElements (env, data, NULL);
5491         intptr_t ret_val = (this_arg_conv->send_data)(this_arg_conv->this_arg, data_ref, resume_read);
5492         (*env)->ReleaseByteArrayElements(env, data, (int8_t*)data_ref.data, 0);
5493         return ret_val;
5494 }
5495
5496 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_SocketDescriptor_1disconnect_1socket(JNIEnv *env, jclass clz, int64_t this_arg) {
5497         LDKSocketDescriptor* this_arg_conv = (LDKSocketDescriptor*)this_arg;
5498         (this_arg_conv->disconnect_socket)(this_arg_conv->this_arg);
5499 }
5500
5501 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_SocketDescriptor_1hash(JNIEnv *env, jclass clz, int64_t this_arg) {
5502         LDKSocketDescriptor* this_arg_conv = (LDKSocketDescriptor*)this_arg;
5503         int64_t ret_val = (this_arg_conv->hash)(this_arg_conv->this_arg);
5504         return ret_val;
5505 }
5506
5507 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Transaction_1free(JNIEnv *env, jclass clz, int8_tArray _res) {
5508         LDKTransaction _res_ref;
5509         _res_ref.datalen = (*env)->GetArrayLength(env, _res);
5510         _res_ref.data = MALLOC(_res_ref.datalen, "LDKTransaction Bytes");
5511         (*env)->GetByteArrayRegion(env, _res, 0, _res_ref.datalen, _res_ref.data);
5512         _res_ref.data_is_owned = true;
5513         Transaction_free(_res_ref);
5514 }
5515
5516 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_TxOut_1free(JNIEnv *env, jclass clz, int64_t _res) {
5517         LDKTxOut _res_conv = *(LDKTxOut*)_res;
5518         FREE((void*)_res);
5519         TxOut_free(_res_conv);
5520 }
5521
5522 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1SpendableOutputDescriptorZ_1free(JNIEnv *env, jclass clz, int64_tArray _res) {
5523         LDKCVec_SpendableOutputDescriptorZ _res_constr;
5524         _res_constr.datalen = (*env)->GetArrayLength(env, _res);
5525         if (_res_constr.datalen > 0)
5526                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKSpendableOutputDescriptor), "LDKCVec_SpendableOutputDescriptorZ Elements");
5527         else
5528                 _res_constr.data = NULL;
5529         int64_t* _res_vals = (*env)->GetLongArrayElements (env, _res, NULL);
5530         for (size_t b = 0; b < _res_constr.datalen; b++) {
5531                 int64_t arr_conv_27 = _res_vals[b];
5532                 LDKSpendableOutputDescriptor arr_conv_27_conv = *(LDKSpendableOutputDescriptor*)arr_conv_27;
5533                 FREE((void*)arr_conv_27);
5534                 _res_constr.data[b] = arr_conv_27_conv;
5535         }
5536         (*env)->ReleaseLongArrayElements(env, _res, _res_vals, 0);
5537         CVec_SpendableOutputDescriptorZ_free(_res_constr);
5538 }
5539
5540 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1MessageSendEventZ_1free(JNIEnv *env, jclass clz, int64_tArray _res) {
5541         LDKCVec_MessageSendEventZ _res_constr;
5542         _res_constr.datalen = (*env)->GetArrayLength(env, _res);
5543         if (_res_constr.datalen > 0)
5544                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKMessageSendEvent), "LDKCVec_MessageSendEventZ Elements");
5545         else
5546                 _res_constr.data = NULL;
5547         int64_t* _res_vals = (*env)->GetLongArrayElements (env, _res, NULL);
5548         for (size_t s = 0; s < _res_constr.datalen; s++) {
5549                 int64_t arr_conv_18 = _res_vals[s];
5550                 LDKMessageSendEvent arr_conv_18_conv = *(LDKMessageSendEvent*)arr_conv_18;
5551                 FREE((void*)arr_conv_18);
5552                 _res_constr.data[s] = arr_conv_18_conv;
5553         }
5554         (*env)->ReleaseLongArrayElements(env, _res, _res_vals, 0);
5555         CVec_MessageSendEventZ_free(_res_constr);
5556 }
5557
5558 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1EventZ_1free(JNIEnv *env, jclass clz, int64_tArray _res) {
5559         LDKCVec_EventZ _res_constr;
5560         _res_constr.datalen = (*env)->GetArrayLength(env, _res);
5561         if (_res_constr.datalen > 0)
5562                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKEvent), "LDKCVec_EventZ Elements");
5563         else
5564                 _res_constr.data = NULL;
5565         int64_t* _res_vals = (*env)->GetLongArrayElements (env, _res, NULL);
5566         for (size_t h = 0; h < _res_constr.datalen; h++) {
5567                 int64_t arr_conv_7 = _res_vals[h];
5568                 LDKEvent arr_conv_7_conv = *(LDKEvent*)arr_conv_7;
5569                 FREE((void*)arr_conv_7);
5570                 _res_constr.data[h] = arr_conv_7_conv;
5571         }
5572         (*env)->ReleaseLongArrayElements(env, _res, _res_vals, 0);
5573         CVec_EventZ_free(_res_constr);
5574 }
5575
5576 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_C2Tuple_1usizeTransactionZ_1free(JNIEnv *env, jclass clz, int64_t _res) {
5577         LDKC2Tuple_usizeTransactionZ _res_conv = *(LDKC2Tuple_usizeTransactionZ*)_res;
5578         FREE((void*)_res);
5579         C2Tuple_usizeTransactionZ_free(_res_conv);
5580 }
5581
5582 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_C2Tuple_1usizeTransactionZ_1new(JNIEnv *env, jclass clz, intptr_t a, int8_tArray b) {
5583         LDKTransaction b_ref;
5584         b_ref.datalen = (*env)->GetArrayLength(env, b);
5585         b_ref.data = MALLOC(b_ref.datalen, "LDKTransaction Bytes");
5586         (*env)->GetByteArrayRegion(env, b, 0, b_ref.datalen, b_ref.data);
5587         b_ref.data_is_owned = true;
5588         LDKC2Tuple_usizeTransactionZ* ret_ref = MALLOC(sizeof(LDKC2Tuple_usizeTransactionZ), "LDKC2Tuple_usizeTransactionZ");
5589         *ret_ref = C2Tuple_usizeTransactionZ_new(a, b_ref);
5590         // XXX: We likely need to clone here, but no _clone fn is available for byte[]
5591         return (long)ret_ref;
5592 }
5593
5594 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1C2Tuple_1usizeTransactionZZ_1free(JNIEnv *env, jclass clz, int64_tArray _res) {
5595         LDKCVec_C2Tuple_usizeTransactionZZ _res_constr;
5596         _res_constr.datalen = (*env)->GetArrayLength(env, _res);
5597         if (_res_constr.datalen > 0)
5598                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKC2Tuple_usizeTransactionZ), "LDKCVec_C2Tuple_usizeTransactionZZ Elements");
5599         else
5600                 _res_constr.data = NULL;
5601         int64_t* _res_vals = (*env)->GetLongArrayElements (env, _res, NULL);
5602         for (size_t y = 0; y < _res_constr.datalen; y++) {
5603                 int64_t arr_conv_24 = _res_vals[y];
5604                 LDKC2Tuple_usizeTransactionZ arr_conv_24_conv = *(LDKC2Tuple_usizeTransactionZ*)arr_conv_24;
5605                 FREE((void*)arr_conv_24);
5606                 _res_constr.data[y] = arr_conv_24_conv;
5607         }
5608         (*env)->ReleaseLongArrayElements(env, _res, _res_vals, 0);
5609         CVec_C2Tuple_usizeTransactionZZ_free(_res_constr);
5610 }
5611
5612 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1NoneChannelMonitorUpdateErrZ_1ok(JNIEnv *env, jclass clz) {
5613         LDKCResult_NoneChannelMonitorUpdateErrZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneChannelMonitorUpdateErrZ), "LDKCResult_NoneChannelMonitorUpdateErrZ");
5614         *ret_conv = CResult_NoneChannelMonitorUpdateErrZ_ok();
5615         return (long)ret_conv;
5616 }
5617
5618 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1NoneChannelMonitorUpdateErrZ_1err(JNIEnv *env, jclass clz, jclass e) {
5619         LDKChannelMonitorUpdateErr e_conv = LDKChannelMonitorUpdateErr_from_java(env, e);
5620         LDKCResult_NoneChannelMonitorUpdateErrZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneChannelMonitorUpdateErrZ), "LDKCResult_NoneChannelMonitorUpdateErrZ");
5621         *ret_conv = CResult_NoneChannelMonitorUpdateErrZ_err(e_conv);
5622         return (long)ret_conv;
5623 }
5624
5625 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1NoneChannelMonitorUpdateErrZ_1free(JNIEnv *env, jclass clz, int64_t _res) {
5626         LDKCResult_NoneChannelMonitorUpdateErrZ _res_conv = *(LDKCResult_NoneChannelMonitorUpdateErrZ*)_res;
5627         FREE((void*)_res);
5628         CResult_NoneChannelMonitorUpdateErrZ_free(_res_conv);
5629 }
5630
5631 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1MonitorEventZ_1free(JNIEnv *env, jclass clz, int64_tArray _res) {
5632         LDKCVec_MonitorEventZ _res_constr;
5633         _res_constr.datalen = (*env)->GetArrayLength(env, _res);
5634         if (_res_constr.datalen > 0)
5635                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKMonitorEvent), "LDKCVec_MonitorEventZ Elements");
5636         else
5637                 _res_constr.data = NULL;
5638         int64_t* _res_vals = (*env)->GetLongArrayElements (env, _res, NULL);
5639         for (size_t o = 0; o < _res_constr.datalen; o++) {
5640                 int64_t arr_conv_14 = _res_vals[o];
5641                 LDKMonitorEvent arr_conv_14_conv;
5642                 arr_conv_14_conv.inner = (void*)(arr_conv_14 & (~1));
5643                 arr_conv_14_conv.is_owned = (arr_conv_14 & 1) || (arr_conv_14 == 0);
5644                 _res_constr.data[o] = arr_conv_14_conv;
5645         }
5646         (*env)->ReleaseLongArrayElements(env, _res, _res_vals, 0);
5647         CVec_MonitorEventZ_free(_res_constr);
5648 }
5649
5650 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1ChannelMonitorUpdateDecodeErrorZ_1ok(JNIEnv *env, jclass clz, int64_t o) {
5651         LDKChannelMonitorUpdate o_conv;
5652         o_conv.inner = (void*)(o & (~1));
5653         o_conv.is_owned = (o & 1) || (o == 0);
5654         if (o_conv.inner != NULL)
5655                 o_conv = ChannelMonitorUpdate_clone(&o_conv);
5656         LDKCResult_ChannelMonitorUpdateDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ChannelMonitorUpdateDecodeErrorZ), "LDKCResult_ChannelMonitorUpdateDecodeErrorZ");
5657         *ret_conv = CResult_ChannelMonitorUpdateDecodeErrorZ_ok(o_conv);
5658         return (long)ret_conv;
5659 }
5660
5661 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1ChannelMonitorUpdateDecodeErrorZ_1err(JNIEnv *env, jclass clz, int64_t e) {
5662         LDKDecodeError e_conv;
5663         e_conv.inner = (void*)(e & (~1));
5664         e_conv.is_owned = (e & 1) || (e == 0);
5665         // Warning: we may need a move here but can't clone!
5666         LDKCResult_ChannelMonitorUpdateDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ChannelMonitorUpdateDecodeErrorZ), "LDKCResult_ChannelMonitorUpdateDecodeErrorZ");
5667         *ret_conv = CResult_ChannelMonitorUpdateDecodeErrorZ_err(e_conv);
5668         return (long)ret_conv;
5669 }
5670
5671 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1ChannelMonitorUpdateDecodeErrorZ_1free(JNIEnv *env, jclass clz, int64_t _res) {
5672         LDKCResult_ChannelMonitorUpdateDecodeErrorZ _res_conv = *(LDKCResult_ChannelMonitorUpdateDecodeErrorZ*)_res;
5673         FREE((void*)_res);
5674         CResult_ChannelMonitorUpdateDecodeErrorZ_free(_res_conv);
5675 }
5676
5677 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1NoneMonitorUpdateErrorZ_1ok(JNIEnv *env, jclass clz) {
5678         LDKCResult_NoneMonitorUpdateErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneMonitorUpdateErrorZ), "LDKCResult_NoneMonitorUpdateErrorZ");
5679         *ret_conv = CResult_NoneMonitorUpdateErrorZ_ok();
5680         return (long)ret_conv;
5681 }
5682
5683 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1NoneMonitorUpdateErrorZ_1err(JNIEnv *env, jclass clz, int64_t e) {
5684         LDKMonitorUpdateError e_conv;
5685         e_conv.inner = (void*)(e & (~1));
5686         e_conv.is_owned = (e & 1) || (e == 0);
5687         // Warning: we may need a move here but can't clone!
5688         LDKCResult_NoneMonitorUpdateErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneMonitorUpdateErrorZ), "LDKCResult_NoneMonitorUpdateErrorZ");
5689         *ret_conv = CResult_NoneMonitorUpdateErrorZ_err(e_conv);
5690         return (long)ret_conv;
5691 }
5692
5693 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1NoneMonitorUpdateErrorZ_1free(JNIEnv *env, jclass clz, int64_t _res) {
5694         LDKCResult_NoneMonitorUpdateErrorZ _res_conv = *(LDKCResult_NoneMonitorUpdateErrorZ*)_res;
5695         FREE((void*)_res);
5696         CResult_NoneMonitorUpdateErrorZ_free(_res_conv);
5697 }
5698
5699 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_C2Tuple_1OutPointScriptZ_1free(JNIEnv *env, jclass clz, int64_t _res) {
5700         LDKC2Tuple_OutPointScriptZ _res_conv = *(LDKC2Tuple_OutPointScriptZ*)_res;
5701         FREE((void*)_res);
5702         C2Tuple_OutPointScriptZ_free(_res_conv);
5703 }
5704
5705 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_C2Tuple_1OutPointScriptZ_1new(JNIEnv *env, jclass clz, int64_t a, int8_tArray b) {
5706         LDKOutPoint a_conv;
5707         a_conv.inner = (void*)(a & (~1));
5708         a_conv.is_owned = (a & 1) || (a == 0);
5709         if (a_conv.inner != NULL)
5710                 a_conv = OutPoint_clone(&a_conv);
5711         LDKCVec_u8Z b_ref;
5712         b_ref.datalen = (*env)->GetArrayLength(env, b);
5713         b_ref.data = MALLOC(b_ref.datalen, "LDKCVec_u8Z Bytes");
5714         (*env)->GetByteArrayRegion(env, b, 0, b_ref.datalen, b_ref.data);
5715         LDKC2Tuple_OutPointScriptZ* ret_ref = MALLOC(sizeof(LDKC2Tuple_OutPointScriptZ), "LDKC2Tuple_OutPointScriptZ");
5716         *ret_ref = C2Tuple_OutPointScriptZ_new(a_conv, b_ref);
5717         ret_ref->a = OutPoint_clone(&ret_ref->a);
5718         ret_ref->b = CVec_u8Z_clone(&ret_ref->b);
5719         return (long)ret_ref;
5720 }
5721
5722 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1TransactionZ_1free(JNIEnv *env, jclass clz, jobjectArray _res) {
5723         LDKCVec_TransactionZ _res_constr;
5724         _res_constr.datalen = (*env)->GetArrayLength(env, _res);
5725         if (_res_constr.datalen > 0)
5726                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKTransaction), "LDKCVec_TransactionZ Elements");
5727         else
5728                 _res_constr.data = NULL;
5729         for (size_t i = 0; i < _res_constr.datalen; i++) {
5730                 int8_tArray arr_conv_8 = (*env)->GetObjectArrayElement(env, _res, i);
5731                 LDKTransaction arr_conv_8_ref;
5732                 arr_conv_8_ref.datalen = (*env)->GetArrayLength(env, arr_conv_8);
5733                 arr_conv_8_ref.data = MALLOC(arr_conv_8_ref.datalen, "LDKTransaction Bytes");
5734                 (*env)->GetByteArrayRegion(env, arr_conv_8, 0, arr_conv_8_ref.datalen, arr_conv_8_ref.data);
5735                 arr_conv_8_ref.data_is_owned = true;
5736                 _res_constr.data[i] = arr_conv_8_ref;
5737         }
5738         CVec_TransactionZ_free(_res_constr);
5739 }
5740
5741 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_C2Tuple_1u32TxOutZ_1free(JNIEnv *env, jclass clz, int64_t _res) {
5742         LDKC2Tuple_u32TxOutZ _res_conv = *(LDKC2Tuple_u32TxOutZ*)_res;
5743         FREE((void*)_res);
5744         C2Tuple_u32TxOutZ_free(_res_conv);
5745 }
5746
5747 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_C2Tuple_1u32TxOutZ_1new(JNIEnv *env, jclass clz, int32_t a, int64_t b) {
5748         LDKTxOut b_conv = *(LDKTxOut*)b;
5749         FREE((void*)b);
5750         LDKC2Tuple_u32TxOutZ* ret_ref = MALLOC(sizeof(LDKC2Tuple_u32TxOutZ), "LDKC2Tuple_u32TxOutZ");
5751         *ret_ref = C2Tuple_u32TxOutZ_new(a, b_conv);
5752         // XXX: We likely need to clone here, but no _clone fn is available for TxOut
5753         return (long)ret_ref;
5754 }
5755
5756 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1C2Tuple_1u32TxOutZZ_1free(JNIEnv *env, jclass clz, int64_tArray _res) {
5757         LDKCVec_C2Tuple_u32TxOutZZ _res_constr;
5758         _res_constr.datalen = (*env)->GetArrayLength(env, _res);
5759         if (_res_constr.datalen > 0)
5760                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKC2Tuple_u32TxOutZ), "LDKCVec_C2Tuple_u32TxOutZZ Elements");
5761         else
5762                 _res_constr.data = NULL;
5763         int64_t* _res_vals = (*env)->GetLongArrayElements (env, _res, NULL);
5764         for (size_t a = 0; a < _res_constr.datalen; a++) {
5765                 int64_t arr_conv_26 = _res_vals[a];
5766                 LDKC2Tuple_u32TxOutZ arr_conv_26_conv = *(LDKC2Tuple_u32TxOutZ*)arr_conv_26;
5767                 FREE((void*)arr_conv_26);
5768                 _res_constr.data[a] = arr_conv_26_conv;
5769         }
5770         (*env)->ReleaseLongArrayElements(env, _res, _res_vals, 0);
5771         CVec_C2Tuple_u32TxOutZZ_free(_res_constr);
5772 }
5773
5774 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_C2Tuple_1TxidCVec_1C2Tuple_1u32TxOutZZZ_1free(JNIEnv *env, jclass clz, int64_t _res) {
5775         LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ _res_conv = *(LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ*)_res;
5776         FREE((void*)_res);
5777         C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ_free(_res_conv);
5778 }
5779
5780 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_C2Tuple_1TxidCVec_1C2Tuple_1u32TxOutZZZ_1new(JNIEnv *env, jclass clz, int8_tArray a, int64_tArray b) {
5781         LDKThirtyTwoBytes a_ref;
5782         CHECK((*env)->GetArrayLength(env, a) == 32);
5783         (*env)->GetByteArrayRegion(env, a, 0, 32, a_ref.data);
5784         LDKCVec_C2Tuple_u32TxOutZZ b_constr;
5785         b_constr.datalen = (*env)->GetArrayLength(env, b);
5786         if (b_constr.datalen > 0)
5787                 b_constr.data = MALLOC(b_constr.datalen * sizeof(LDKC2Tuple_u32TxOutZ), "LDKCVec_C2Tuple_u32TxOutZZ Elements");
5788         else
5789                 b_constr.data = NULL;
5790         int64_t* b_vals = (*env)->GetLongArrayElements (env, b, NULL);
5791         for (size_t a = 0; a < b_constr.datalen; a++) {
5792                 int64_t arr_conv_26 = b_vals[a];
5793                 LDKC2Tuple_u32TxOutZ arr_conv_26_conv = *(LDKC2Tuple_u32TxOutZ*)arr_conv_26;
5794                 FREE((void*)arr_conv_26);
5795                 b_constr.data[a] = arr_conv_26_conv;
5796         }
5797         (*env)->ReleaseLongArrayElements(env, b, b_vals, 0);
5798         LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ* ret_ref = MALLOC(sizeof(LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ), "LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ");
5799         *ret_ref = C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ_new(a_ref, b_constr);
5800         ret_ref->a = ThirtyTwoBytes_clone(&ret_ref->a);
5801         // XXX: We likely need to clone here, but no _clone fn is available for TwoTuple<Integer, TxOut>[]
5802         return (long)ret_ref;
5803 }
5804
5805 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1C2Tuple_1TxidCVec_1C2Tuple_1u32TxOutZZZZ_1free(JNIEnv *env, jclass clz, int64_tArray _res) {
5806         LDKCVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ _res_constr;
5807         _res_constr.datalen = (*env)->GetArrayLength(env, _res);
5808         if (_res_constr.datalen > 0)
5809                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ), "LDKCVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ Elements");
5810         else
5811                 _res_constr.data = NULL;
5812         int64_t* _res_vals = (*env)->GetLongArrayElements (env, _res, NULL);
5813         for (size_t u = 0; u < _res_constr.datalen; u++) {
5814                 int64_t arr_conv_46 = _res_vals[u];
5815                 LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ arr_conv_46_conv = *(LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ*)arr_conv_46;
5816                 FREE((void*)arr_conv_46);
5817                 _res_constr.data[u] = arr_conv_46_conv;
5818         }
5819         (*env)->ReleaseLongArrayElements(env, _res, _res_vals, 0);
5820         CVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ_free(_res_constr);
5821 }
5822
5823 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_C2Tuple_1BlockHashChannelMonitorZ_1free(JNIEnv *env, jclass clz, int64_t _res) {
5824         LDKC2Tuple_BlockHashChannelMonitorZ _res_conv = *(LDKC2Tuple_BlockHashChannelMonitorZ*)_res;
5825         FREE((void*)_res);
5826         C2Tuple_BlockHashChannelMonitorZ_free(_res_conv);
5827 }
5828
5829 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_C2Tuple_1BlockHashChannelMonitorZ_1new(JNIEnv *env, jclass clz, int8_tArray a, int64_t b) {
5830         LDKThirtyTwoBytes a_ref;
5831         CHECK((*env)->GetArrayLength(env, a) == 32);
5832         (*env)->GetByteArrayRegion(env, a, 0, 32, a_ref.data);
5833         LDKChannelMonitor b_conv;
5834         b_conv.inner = (void*)(b & (~1));
5835         b_conv.is_owned = (b & 1) || (b == 0);
5836         // Warning: we may need a move here but can't clone!
5837         LDKC2Tuple_BlockHashChannelMonitorZ* ret_ref = MALLOC(sizeof(LDKC2Tuple_BlockHashChannelMonitorZ), "LDKC2Tuple_BlockHashChannelMonitorZ");
5838         *ret_ref = C2Tuple_BlockHashChannelMonitorZ_new(a_ref, b_conv);
5839         ret_ref->a = ThirtyTwoBytes_clone(&ret_ref->a);
5840         // XXX: We likely need to clone here, but no _clone fn is available for ChannelMonitor
5841         return (long)ret_ref;
5842 }
5843
5844 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1C2Tuple_1BlockHashChannelMonitorZDecodeErrorZ_1ok(JNIEnv *env, jclass clz, int64_t o) {
5845         LDKC2Tuple_BlockHashChannelMonitorZ o_conv = *(LDKC2Tuple_BlockHashChannelMonitorZ*)o;
5846         FREE((void*)o);
5847         LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ), "LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ");
5848         *ret_conv = CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ_ok(o_conv);
5849         return (long)ret_conv;
5850 }
5851
5852 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1C2Tuple_1BlockHashChannelMonitorZDecodeErrorZ_1err(JNIEnv *env, jclass clz, int64_t e) {
5853         LDKDecodeError e_conv;
5854         e_conv.inner = (void*)(e & (~1));
5855         e_conv.is_owned = (e & 1) || (e == 0);
5856         // Warning: we may need a move here but can't clone!
5857         LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ), "LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ");
5858         *ret_conv = CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ_err(e_conv);
5859         return (long)ret_conv;
5860 }
5861
5862 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1C2Tuple_1BlockHashChannelMonitorZDecodeErrorZ_1free(JNIEnv *env, jclass clz, int64_t _res) {
5863         LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ _res_conv = *(LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ*)_res;
5864         FREE((void*)_res);
5865         CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ_free(_res_conv);
5866 }
5867
5868 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_C2Tuple_1u64u64Z_1free(JNIEnv *env, jclass clz, int64_t _res) {
5869         LDKC2Tuple_u64u64Z _res_conv = *(LDKC2Tuple_u64u64Z*)_res;
5870         FREE((void*)_res);
5871         C2Tuple_u64u64Z_free(_res_conv);
5872 }
5873
5874 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_C2Tuple_1u64u64Z_1new(JNIEnv *env, jclass clz, int64_t a, int64_t b) {
5875         LDKC2Tuple_u64u64Z* ret_ref = MALLOC(sizeof(LDKC2Tuple_u64u64Z), "LDKC2Tuple_u64u64Z");
5876         *ret_ref = C2Tuple_u64u64Z_new(a, b);
5877         return (long)ret_ref;
5878 }
5879
5880 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1SpendableOutputDescriptorDecodeErrorZ_1ok(JNIEnv *env, jclass clz, int64_t o) {
5881         LDKSpendableOutputDescriptor o_conv = *(LDKSpendableOutputDescriptor*)o;
5882         FREE((void*)o);
5883         LDKCResult_SpendableOutputDescriptorDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_SpendableOutputDescriptorDecodeErrorZ), "LDKCResult_SpendableOutputDescriptorDecodeErrorZ");
5884         *ret_conv = CResult_SpendableOutputDescriptorDecodeErrorZ_ok(o_conv);
5885         return (long)ret_conv;
5886 }
5887
5888 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1SpendableOutputDescriptorDecodeErrorZ_1err(JNIEnv *env, jclass clz, int64_t e) {
5889         LDKDecodeError e_conv;
5890         e_conv.inner = (void*)(e & (~1));
5891         e_conv.is_owned = (e & 1) || (e == 0);
5892         // Warning: we may need a move here but can't clone!
5893         LDKCResult_SpendableOutputDescriptorDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_SpendableOutputDescriptorDecodeErrorZ), "LDKCResult_SpendableOutputDescriptorDecodeErrorZ");
5894         *ret_conv = CResult_SpendableOutputDescriptorDecodeErrorZ_err(e_conv);
5895         return (long)ret_conv;
5896 }
5897
5898 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1SpendableOutputDescriptorDecodeErrorZ_1free(JNIEnv *env, jclass clz, int64_t _res) {
5899         LDKCResult_SpendableOutputDescriptorDecodeErrorZ _res_conv = *(LDKCResult_SpendableOutputDescriptorDecodeErrorZ*)_res;
5900         FREE((void*)_res);
5901         CResult_SpendableOutputDescriptorDecodeErrorZ_free(_res_conv);
5902 }
5903
5904 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1SignatureZ_1free(JNIEnv *env, jclass clz, jobjectArray _res) {
5905         LDKCVec_SignatureZ _res_constr;
5906         _res_constr.datalen = (*env)->GetArrayLength(env, _res);
5907         if (_res_constr.datalen > 0)
5908                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKSignature), "LDKCVec_SignatureZ Elements");
5909         else
5910                 _res_constr.data = NULL;
5911         for (size_t i = 0; i < _res_constr.datalen; i++) {
5912                 int8_tArray arr_conv_8 = (*env)->GetObjectArrayElement(env, _res, i);
5913                 LDKSignature arr_conv_8_ref;
5914                 CHECK((*env)->GetArrayLength(env, arr_conv_8) == 64);
5915                 (*env)->GetByteArrayRegion(env, arr_conv_8, 0, 64, arr_conv_8_ref.compact_form);
5916                 _res_constr.data[i] = arr_conv_8_ref;
5917         }
5918         CVec_SignatureZ_free(_res_constr);
5919 }
5920
5921 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_C2Tuple_1SignatureCVec_1SignatureZZ_1free(JNIEnv *env, jclass clz, int64_t _res) {
5922         LDKC2Tuple_SignatureCVec_SignatureZZ _res_conv = *(LDKC2Tuple_SignatureCVec_SignatureZZ*)_res;
5923         FREE((void*)_res);
5924         C2Tuple_SignatureCVec_SignatureZZ_free(_res_conv);
5925 }
5926
5927 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_C2Tuple_1SignatureCVec_1SignatureZZ_1new(JNIEnv *env, jclass clz, int8_tArray a, jobjectArray b) {
5928         LDKSignature a_ref;
5929         CHECK((*env)->GetArrayLength(env, a) == 64);
5930         (*env)->GetByteArrayRegion(env, a, 0, 64, a_ref.compact_form);
5931         LDKCVec_SignatureZ b_constr;
5932         b_constr.datalen = (*env)->GetArrayLength(env, b);
5933         if (b_constr.datalen > 0)
5934                 b_constr.data = MALLOC(b_constr.datalen * sizeof(LDKSignature), "LDKCVec_SignatureZ Elements");
5935         else
5936                 b_constr.data = NULL;
5937         for (size_t i = 0; i < b_constr.datalen; i++) {
5938                 int8_tArray arr_conv_8 = (*env)->GetObjectArrayElement(env, b, i);
5939                 LDKSignature arr_conv_8_ref;
5940                 CHECK((*env)->GetArrayLength(env, arr_conv_8) == 64);
5941                 (*env)->GetByteArrayRegion(env, arr_conv_8, 0, 64, arr_conv_8_ref.compact_form);
5942                 b_constr.data[i] = arr_conv_8_ref;
5943         }
5944         LDKC2Tuple_SignatureCVec_SignatureZZ* ret_ref = MALLOC(sizeof(LDKC2Tuple_SignatureCVec_SignatureZZ), "LDKC2Tuple_SignatureCVec_SignatureZZ");
5945         *ret_ref = C2Tuple_SignatureCVec_SignatureZZ_new(a_ref, b_constr);
5946         // XXX: We likely need to clone here, but no _clone fn is available for byte[]
5947         // XXX: We likely need to clone here, but no _clone fn is available for byte[][]
5948         return (long)ret_ref;
5949 }
5950
5951 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1C2Tuple_1SignatureCVec_1SignatureZZNoneZ_1ok(JNIEnv *env, jclass clz, int64_t o) {
5952         LDKC2Tuple_SignatureCVec_SignatureZZ o_conv = *(LDKC2Tuple_SignatureCVec_SignatureZZ*)o;
5953         FREE((void*)o);
5954         LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ), "LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ");
5955         *ret_conv = CResult_C2Tuple_SignatureCVec_SignatureZZNoneZ_ok(o_conv);
5956         return (long)ret_conv;
5957 }
5958
5959 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1C2Tuple_1SignatureCVec_1SignatureZZNoneZ_1err(JNIEnv *env, jclass clz) {
5960         LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ), "LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ");
5961         *ret_conv = CResult_C2Tuple_SignatureCVec_SignatureZZNoneZ_err();
5962         return (long)ret_conv;
5963 }
5964
5965 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1C2Tuple_1SignatureCVec_1SignatureZZNoneZ_1free(JNIEnv *env, jclass clz, int64_t _res) {
5966         LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ _res_conv = *(LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ*)_res;
5967         FREE((void*)_res);
5968         CResult_C2Tuple_SignatureCVec_SignatureZZNoneZ_free(_res_conv);
5969 }
5970
5971 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1SignatureNoneZ_1ok(JNIEnv *env, jclass clz, int8_tArray o) {
5972         LDKSignature o_ref;
5973         CHECK((*env)->GetArrayLength(env, o) == 64);
5974         (*env)->GetByteArrayRegion(env, o, 0, 64, o_ref.compact_form);
5975         LDKCResult_SignatureNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_SignatureNoneZ), "LDKCResult_SignatureNoneZ");
5976         *ret_conv = CResult_SignatureNoneZ_ok(o_ref);
5977         return (long)ret_conv;
5978 }
5979
5980 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1SignatureNoneZ_1err(JNIEnv *env, jclass clz) {
5981         LDKCResult_SignatureNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_SignatureNoneZ), "LDKCResult_SignatureNoneZ");
5982         *ret_conv = CResult_SignatureNoneZ_err();
5983         return (long)ret_conv;
5984 }
5985
5986 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1SignatureNoneZ_1free(JNIEnv *env, jclass clz, int64_t _res) {
5987         LDKCResult_SignatureNoneZ _res_conv = *(LDKCResult_SignatureNoneZ*)_res;
5988         FREE((void*)_res);
5989         CResult_SignatureNoneZ_free(_res_conv);
5990 }
5991
5992 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1CVec_1SignatureZNoneZ_1ok(JNIEnv *env, jclass clz, jobjectArray o) {
5993         LDKCVec_SignatureZ o_constr;
5994         o_constr.datalen = (*env)->GetArrayLength(env, o);
5995         if (o_constr.datalen > 0)
5996                 o_constr.data = MALLOC(o_constr.datalen * sizeof(LDKSignature), "LDKCVec_SignatureZ Elements");
5997         else
5998                 o_constr.data = NULL;
5999         for (size_t i = 0; i < o_constr.datalen; i++) {
6000                 int8_tArray arr_conv_8 = (*env)->GetObjectArrayElement(env, o, i);
6001                 LDKSignature arr_conv_8_ref;
6002                 CHECK((*env)->GetArrayLength(env, arr_conv_8) == 64);
6003                 (*env)->GetByteArrayRegion(env, arr_conv_8, 0, 64, arr_conv_8_ref.compact_form);
6004                 o_constr.data[i] = arr_conv_8_ref;
6005         }
6006         LDKCResult_CVec_SignatureZNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_CVec_SignatureZNoneZ), "LDKCResult_CVec_SignatureZNoneZ");
6007         *ret_conv = CResult_CVec_SignatureZNoneZ_ok(o_constr);
6008         return (long)ret_conv;
6009 }
6010
6011 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1CVec_1SignatureZNoneZ_1err(JNIEnv *env, jclass clz) {
6012         LDKCResult_CVec_SignatureZNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_CVec_SignatureZNoneZ), "LDKCResult_CVec_SignatureZNoneZ");
6013         *ret_conv = CResult_CVec_SignatureZNoneZ_err();
6014         return (long)ret_conv;
6015 }
6016
6017 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1CVec_1SignatureZNoneZ_1free(JNIEnv *env, jclass clz, int64_t _res) {
6018         LDKCResult_CVec_SignatureZNoneZ _res_conv = *(LDKCResult_CVec_SignatureZNoneZ*)_res;
6019         FREE((void*)_res);
6020         CResult_CVec_SignatureZNoneZ_free(_res_conv);
6021 }
6022
6023 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1ChanKeySignerDecodeErrorZ_1ok(JNIEnv *env, jclass clz, int64_t o) {
6024         LDKChannelKeys o_conv = *(LDKChannelKeys*)o;
6025         if (o_conv.free == LDKChannelKeys_JCalls_free) {
6026                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
6027                 LDKChannelKeys_JCalls_clone(o_conv.this_arg);
6028         }
6029         LDKCResult_ChanKeySignerDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ChanKeySignerDecodeErrorZ), "LDKCResult_ChanKeySignerDecodeErrorZ");
6030         *ret_conv = CResult_ChanKeySignerDecodeErrorZ_ok(o_conv);
6031         return (long)ret_conv;
6032 }
6033
6034 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1ChanKeySignerDecodeErrorZ_1err(JNIEnv *env, jclass clz, int64_t e) {
6035         LDKDecodeError e_conv;
6036         e_conv.inner = (void*)(e & (~1));
6037         e_conv.is_owned = (e & 1) || (e == 0);
6038         // Warning: we may need a move here but can't clone!
6039         LDKCResult_ChanKeySignerDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ChanKeySignerDecodeErrorZ), "LDKCResult_ChanKeySignerDecodeErrorZ");
6040         *ret_conv = CResult_ChanKeySignerDecodeErrorZ_err(e_conv);
6041         return (long)ret_conv;
6042 }
6043
6044 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1ChanKeySignerDecodeErrorZ_1free(JNIEnv *env, jclass clz, int64_t _res) {
6045         LDKCResult_ChanKeySignerDecodeErrorZ _res_conv = *(LDKCResult_ChanKeySignerDecodeErrorZ*)_res;
6046         FREE((void*)_res);
6047         CResult_ChanKeySignerDecodeErrorZ_free(_res_conv);
6048 }
6049
6050 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1InMemoryChannelKeysDecodeErrorZ_1ok(JNIEnv *env, jclass clz, int64_t o) {
6051         LDKInMemoryChannelKeys o_conv;
6052         o_conv.inner = (void*)(o & (~1));
6053         o_conv.is_owned = (o & 1) || (o == 0);
6054         if (o_conv.inner != NULL)
6055                 o_conv = InMemoryChannelKeys_clone(&o_conv);
6056         LDKCResult_InMemoryChannelKeysDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_InMemoryChannelKeysDecodeErrorZ), "LDKCResult_InMemoryChannelKeysDecodeErrorZ");
6057         *ret_conv = CResult_InMemoryChannelKeysDecodeErrorZ_ok(o_conv);
6058         return (long)ret_conv;
6059 }
6060
6061 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1InMemoryChannelKeysDecodeErrorZ_1err(JNIEnv *env, jclass clz, int64_t e) {
6062         LDKDecodeError e_conv;
6063         e_conv.inner = (void*)(e & (~1));
6064         e_conv.is_owned = (e & 1) || (e == 0);
6065         // Warning: we may need a move here but can't clone!
6066         LDKCResult_InMemoryChannelKeysDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_InMemoryChannelKeysDecodeErrorZ), "LDKCResult_InMemoryChannelKeysDecodeErrorZ");
6067         *ret_conv = CResult_InMemoryChannelKeysDecodeErrorZ_err(e_conv);
6068         return (long)ret_conv;
6069 }
6070
6071 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1InMemoryChannelKeysDecodeErrorZ_1free(JNIEnv *env, jclass clz, int64_t _res) {
6072         LDKCResult_InMemoryChannelKeysDecodeErrorZ _res_conv = *(LDKCResult_InMemoryChannelKeysDecodeErrorZ*)_res;
6073         FREE((void*)_res);
6074         CResult_InMemoryChannelKeysDecodeErrorZ_free(_res_conv);
6075 }
6076
6077 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1TxOutAccessErrorZ_1ok(JNIEnv *env, jclass clz, int64_t o) {
6078         LDKTxOut o_conv = *(LDKTxOut*)o;
6079         FREE((void*)o);
6080         LDKCResult_TxOutAccessErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_TxOutAccessErrorZ), "LDKCResult_TxOutAccessErrorZ");
6081         *ret_conv = CResult_TxOutAccessErrorZ_ok(o_conv);
6082         return (long)ret_conv;
6083 }
6084
6085 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1TxOutAccessErrorZ_1err(JNIEnv *env, jclass clz, jclass e) {
6086         LDKAccessError e_conv = LDKAccessError_from_java(env, e);
6087         LDKCResult_TxOutAccessErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_TxOutAccessErrorZ), "LDKCResult_TxOutAccessErrorZ");
6088         *ret_conv = CResult_TxOutAccessErrorZ_err(e_conv);
6089         return (long)ret_conv;
6090 }
6091
6092 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1TxOutAccessErrorZ_1free(JNIEnv *env, jclass clz, int64_t _res) {
6093         LDKCResult_TxOutAccessErrorZ _res_conv = *(LDKCResult_TxOutAccessErrorZ*)_res;
6094         FREE((void*)_res);
6095         CResult_TxOutAccessErrorZ_free(_res_conv);
6096 }
6097
6098 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1NoneAPIErrorZ_1ok(JNIEnv *env, jclass clz) {
6099         LDKCResult_NoneAPIErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneAPIErrorZ), "LDKCResult_NoneAPIErrorZ");
6100         *ret_conv = CResult_NoneAPIErrorZ_ok();
6101         return (long)ret_conv;
6102 }
6103
6104 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1NoneAPIErrorZ_1err(JNIEnv *env, jclass clz, int64_t e) {
6105         LDKAPIError e_conv = *(LDKAPIError*)e;
6106         FREE((void*)e);
6107         LDKCResult_NoneAPIErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneAPIErrorZ), "LDKCResult_NoneAPIErrorZ");
6108         *ret_conv = CResult_NoneAPIErrorZ_err(e_conv);
6109         return (long)ret_conv;
6110 }
6111
6112 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1NoneAPIErrorZ_1free(JNIEnv *env, jclass clz, int64_t _res) {
6113         LDKCResult_NoneAPIErrorZ _res_conv = *(LDKCResult_NoneAPIErrorZ*)_res;
6114         FREE((void*)_res);
6115         CResult_NoneAPIErrorZ_free(_res_conv);
6116 }
6117
6118 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1ChannelDetailsZ_1free(JNIEnv *env, jclass clz, int64_tArray _res) {
6119         LDKCVec_ChannelDetailsZ _res_constr;
6120         _res_constr.datalen = (*env)->GetArrayLength(env, _res);
6121         if (_res_constr.datalen > 0)
6122                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKChannelDetails), "LDKCVec_ChannelDetailsZ Elements");
6123         else
6124                 _res_constr.data = NULL;
6125         int64_t* _res_vals = (*env)->GetLongArrayElements (env, _res, NULL);
6126         for (size_t q = 0; q < _res_constr.datalen; q++) {
6127                 int64_t arr_conv_16 = _res_vals[q];
6128                 LDKChannelDetails arr_conv_16_conv;
6129                 arr_conv_16_conv.inner = (void*)(arr_conv_16 & (~1));
6130                 arr_conv_16_conv.is_owned = (arr_conv_16 & 1) || (arr_conv_16 == 0);
6131                 _res_constr.data[q] = arr_conv_16_conv;
6132         }
6133         (*env)->ReleaseLongArrayElements(env, _res, _res_vals, 0);
6134         CVec_ChannelDetailsZ_free(_res_constr);
6135 }
6136
6137 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1NonePaymentSendFailureZ_1ok(JNIEnv *env, jclass clz) {
6138         LDKCResult_NonePaymentSendFailureZ* ret_conv = MALLOC(sizeof(LDKCResult_NonePaymentSendFailureZ), "LDKCResult_NonePaymentSendFailureZ");
6139         *ret_conv = CResult_NonePaymentSendFailureZ_ok();
6140         return (long)ret_conv;
6141 }
6142
6143 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1NonePaymentSendFailureZ_1err(JNIEnv *env, jclass clz, int64_t e) {
6144         LDKPaymentSendFailure e_conv;
6145         e_conv.inner = (void*)(e & (~1));
6146         e_conv.is_owned = (e & 1) || (e == 0);
6147         // Warning: we may need a move here but can't clone!
6148         LDKCResult_NonePaymentSendFailureZ* ret_conv = MALLOC(sizeof(LDKCResult_NonePaymentSendFailureZ), "LDKCResult_NonePaymentSendFailureZ");
6149         *ret_conv = CResult_NonePaymentSendFailureZ_err(e_conv);
6150         return (long)ret_conv;
6151 }
6152
6153 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1NonePaymentSendFailureZ_1free(JNIEnv *env, jclass clz, int64_t _res) {
6154         LDKCResult_NonePaymentSendFailureZ _res_conv = *(LDKCResult_NonePaymentSendFailureZ*)_res;
6155         FREE((void*)_res);
6156         CResult_NonePaymentSendFailureZ_free(_res_conv);
6157 }
6158
6159 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1NetAddressZ_1free(JNIEnv *env, jclass clz, int64_tArray _res) {
6160         LDKCVec_NetAddressZ _res_constr;
6161         _res_constr.datalen = (*env)->GetArrayLength(env, _res);
6162         if (_res_constr.datalen > 0)
6163                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKNetAddress), "LDKCVec_NetAddressZ Elements");
6164         else
6165                 _res_constr.data = NULL;
6166         int64_t* _res_vals = (*env)->GetLongArrayElements (env, _res, NULL);
6167         for (size_t m = 0; m < _res_constr.datalen; m++) {
6168                 int64_t arr_conv_12 = _res_vals[m];
6169                 LDKNetAddress arr_conv_12_conv = *(LDKNetAddress*)arr_conv_12;
6170                 FREE((void*)arr_conv_12);
6171                 _res_constr.data[m] = arr_conv_12_conv;
6172         }
6173         (*env)->ReleaseLongArrayElements(env, _res, _res_vals, 0);
6174         CVec_NetAddressZ_free(_res_constr);
6175 }
6176
6177 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1ChannelMonitorZ_1free(JNIEnv *env, jclass clz, int64_tArray _res) {
6178         LDKCVec_ChannelMonitorZ _res_constr;
6179         _res_constr.datalen = (*env)->GetArrayLength(env, _res);
6180         if (_res_constr.datalen > 0)
6181                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKChannelMonitor), "LDKCVec_ChannelMonitorZ Elements");
6182         else
6183                 _res_constr.data = NULL;
6184         int64_t* _res_vals = (*env)->GetLongArrayElements (env, _res, NULL);
6185         for (size_t q = 0; q < _res_constr.datalen; q++) {
6186                 int64_t arr_conv_16 = _res_vals[q];
6187                 LDKChannelMonitor arr_conv_16_conv;
6188                 arr_conv_16_conv.inner = (void*)(arr_conv_16 & (~1));
6189                 arr_conv_16_conv.is_owned = (arr_conv_16 & 1) || (arr_conv_16 == 0);
6190                 _res_constr.data[q] = arr_conv_16_conv;
6191         }
6192         (*env)->ReleaseLongArrayElements(env, _res, _res_vals, 0);
6193         CVec_ChannelMonitorZ_free(_res_constr);
6194 }
6195
6196 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_C2Tuple_1BlockHashChannelManagerZ_1free(JNIEnv *env, jclass clz, int64_t _res) {
6197         LDKC2Tuple_BlockHashChannelManagerZ _res_conv = *(LDKC2Tuple_BlockHashChannelManagerZ*)_res;
6198         FREE((void*)_res);
6199         C2Tuple_BlockHashChannelManagerZ_free(_res_conv);
6200 }
6201
6202 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_C2Tuple_1BlockHashChannelManagerZ_1new(JNIEnv *env, jclass clz, int8_tArray a, int64_t b) {
6203         LDKThirtyTwoBytes a_ref;
6204         CHECK((*env)->GetArrayLength(env, a) == 32);
6205         (*env)->GetByteArrayRegion(env, a, 0, 32, a_ref.data);
6206         LDKChannelManager b_conv;
6207         b_conv.inner = (void*)(b & (~1));
6208         b_conv.is_owned = (b & 1) || (b == 0);
6209         // Warning: we may need a move here but can't clone!
6210         LDKC2Tuple_BlockHashChannelManagerZ* ret_ref = MALLOC(sizeof(LDKC2Tuple_BlockHashChannelManagerZ), "LDKC2Tuple_BlockHashChannelManagerZ");
6211         *ret_ref = C2Tuple_BlockHashChannelManagerZ_new(a_ref, b_conv);
6212         ret_ref->a = ThirtyTwoBytes_clone(&ret_ref->a);
6213         // XXX: We likely need to clone here, but no _clone fn is available for ChannelManager
6214         return (long)ret_ref;
6215 }
6216
6217 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1C2Tuple_1BlockHashChannelManagerZDecodeErrorZ_1ok(JNIEnv *env, jclass clz, int64_t o) {
6218         LDKC2Tuple_BlockHashChannelManagerZ o_conv = *(LDKC2Tuple_BlockHashChannelManagerZ*)o;
6219         FREE((void*)o);
6220         LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ), "LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ");
6221         *ret_conv = CResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ_ok(o_conv);
6222         return (long)ret_conv;
6223 }
6224
6225 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1C2Tuple_1BlockHashChannelManagerZDecodeErrorZ_1err(JNIEnv *env, jclass clz, int64_t e) {
6226         LDKDecodeError e_conv;
6227         e_conv.inner = (void*)(e & (~1));
6228         e_conv.is_owned = (e & 1) || (e == 0);
6229         // Warning: we may need a move here but can't clone!
6230         LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ), "LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ");
6231         *ret_conv = CResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ_err(e_conv);
6232         return (long)ret_conv;
6233 }
6234
6235 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1C2Tuple_1BlockHashChannelManagerZDecodeErrorZ_1free(JNIEnv *env, jclass clz, int64_t _res) {
6236         LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ _res_conv = *(LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ*)_res;
6237         FREE((void*)_res);
6238         CResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ_free(_res_conv);
6239 }
6240
6241 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1NetAddressu8Z_1ok(JNIEnv *env, jclass clz, int64_t o) {
6242         LDKNetAddress o_conv = *(LDKNetAddress*)o;
6243         FREE((void*)o);
6244         LDKCResult_NetAddressu8Z* ret_conv = MALLOC(sizeof(LDKCResult_NetAddressu8Z), "LDKCResult_NetAddressu8Z");
6245         *ret_conv = CResult_NetAddressu8Z_ok(o_conv);
6246         return (long)ret_conv;
6247 }
6248
6249 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1NetAddressu8Z_1err(JNIEnv *env, jclass clz, int8_t e) {
6250         LDKCResult_NetAddressu8Z* ret_conv = MALLOC(sizeof(LDKCResult_NetAddressu8Z), "LDKCResult_NetAddressu8Z");
6251         *ret_conv = CResult_NetAddressu8Z_err(e);
6252         return (long)ret_conv;
6253 }
6254
6255 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1NetAddressu8Z_1free(JNIEnv *env, jclass clz, int64_t _res) {
6256         LDKCResult_NetAddressu8Z _res_conv = *(LDKCResult_NetAddressu8Z*)_res;
6257         FREE((void*)_res);
6258         CResult_NetAddressu8Z_free(_res_conv);
6259 }
6260
6261 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1CResult_1NetAddressu8ZDecodeErrorZ_1ok(JNIEnv *env, jclass clz, int64_t o) {
6262         LDKCResult_NetAddressu8Z o_conv = *(LDKCResult_NetAddressu8Z*)o;
6263         FREE((void*)o);
6264         LDKCResult_CResult_NetAddressu8ZDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_CResult_NetAddressu8ZDecodeErrorZ), "LDKCResult_CResult_NetAddressu8ZDecodeErrorZ");
6265         *ret_conv = CResult_CResult_NetAddressu8ZDecodeErrorZ_ok(o_conv);
6266         return (long)ret_conv;
6267 }
6268
6269 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1CResult_1NetAddressu8ZDecodeErrorZ_1err(JNIEnv *env, jclass clz, int64_t e) {
6270         LDKDecodeError e_conv;
6271         e_conv.inner = (void*)(e & (~1));
6272         e_conv.is_owned = (e & 1) || (e == 0);
6273         // Warning: we may need a move here but can't clone!
6274         LDKCResult_CResult_NetAddressu8ZDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_CResult_NetAddressu8ZDecodeErrorZ), "LDKCResult_CResult_NetAddressu8ZDecodeErrorZ");
6275         *ret_conv = CResult_CResult_NetAddressu8ZDecodeErrorZ_err(e_conv);
6276         return (long)ret_conv;
6277 }
6278
6279 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1CResult_1NetAddressu8ZDecodeErrorZ_1free(JNIEnv *env, jclass clz, int64_t _res) {
6280         LDKCResult_CResult_NetAddressu8ZDecodeErrorZ _res_conv = *(LDKCResult_CResult_NetAddressu8ZDecodeErrorZ*)_res;
6281         FREE((void*)_res);
6282         CResult_CResult_NetAddressu8ZDecodeErrorZ_free(_res_conv);
6283 }
6284
6285 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1u64Z_1free(JNIEnv *env, jclass clz, int64_tArray _res) {
6286         LDKCVec_u64Z _res_constr;
6287         _res_constr.datalen = (*env)->GetArrayLength(env, _res);
6288         if (_res_constr.datalen > 0)
6289                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(int64_t), "LDKCVec_u64Z Elements");
6290         else
6291                 _res_constr.data = NULL;
6292         int64_t* _res_vals = (*env)->GetLongArrayElements (env, _res, NULL);
6293         for (size_t g = 0; g < _res_constr.datalen; g++) {
6294                 int64_t arr_conv_6 = _res_vals[g];
6295                 _res_constr.data[g] = arr_conv_6;
6296         }
6297         (*env)->ReleaseLongArrayElements(env, _res, _res_vals, 0);
6298         CVec_u64Z_free(_res_constr);
6299 }
6300
6301 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1UpdateAddHTLCZ_1free(JNIEnv *env, jclass clz, int64_tArray _res) {
6302         LDKCVec_UpdateAddHTLCZ _res_constr;
6303         _res_constr.datalen = (*env)->GetArrayLength(env, _res);
6304         if (_res_constr.datalen > 0)
6305                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKUpdateAddHTLC), "LDKCVec_UpdateAddHTLCZ Elements");
6306         else
6307                 _res_constr.data = NULL;
6308         int64_t* _res_vals = (*env)->GetLongArrayElements (env, _res, NULL);
6309         for (size_t p = 0; p < _res_constr.datalen; p++) {
6310                 int64_t arr_conv_15 = _res_vals[p];
6311                 LDKUpdateAddHTLC arr_conv_15_conv;
6312                 arr_conv_15_conv.inner = (void*)(arr_conv_15 & (~1));
6313                 arr_conv_15_conv.is_owned = (arr_conv_15 & 1) || (arr_conv_15 == 0);
6314                 _res_constr.data[p] = arr_conv_15_conv;
6315         }
6316         (*env)->ReleaseLongArrayElements(env, _res, _res_vals, 0);
6317         CVec_UpdateAddHTLCZ_free(_res_constr);
6318 }
6319
6320 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1UpdateFulfillHTLCZ_1free(JNIEnv *env, jclass clz, int64_tArray _res) {
6321         LDKCVec_UpdateFulfillHTLCZ _res_constr;
6322         _res_constr.datalen = (*env)->GetArrayLength(env, _res);
6323         if (_res_constr.datalen > 0)
6324                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKUpdateFulfillHTLC), "LDKCVec_UpdateFulfillHTLCZ Elements");
6325         else
6326                 _res_constr.data = NULL;
6327         int64_t* _res_vals = (*env)->GetLongArrayElements (env, _res, NULL);
6328         for (size_t t = 0; t < _res_constr.datalen; t++) {
6329                 int64_t arr_conv_19 = _res_vals[t];
6330                 LDKUpdateFulfillHTLC arr_conv_19_conv;
6331                 arr_conv_19_conv.inner = (void*)(arr_conv_19 & (~1));
6332                 arr_conv_19_conv.is_owned = (arr_conv_19 & 1) || (arr_conv_19 == 0);
6333                 _res_constr.data[t] = arr_conv_19_conv;
6334         }
6335         (*env)->ReleaseLongArrayElements(env, _res, _res_vals, 0);
6336         CVec_UpdateFulfillHTLCZ_free(_res_constr);
6337 }
6338
6339 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1UpdateFailHTLCZ_1free(JNIEnv *env, jclass clz, int64_tArray _res) {
6340         LDKCVec_UpdateFailHTLCZ _res_constr;
6341         _res_constr.datalen = (*env)->GetArrayLength(env, _res);
6342         if (_res_constr.datalen > 0)
6343                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKUpdateFailHTLC), "LDKCVec_UpdateFailHTLCZ Elements");
6344         else
6345                 _res_constr.data = NULL;
6346         int64_t* _res_vals = (*env)->GetLongArrayElements (env, _res, NULL);
6347         for (size_t q = 0; q < _res_constr.datalen; q++) {
6348                 int64_t arr_conv_16 = _res_vals[q];
6349                 LDKUpdateFailHTLC arr_conv_16_conv;
6350                 arr_conv_16_conv.inner = (void*)(arr_conv_16 & (~1));
6351                 arr_conv_16_conv.is_owned = (arr_conv_16 & 1) || (arr_conv_16 == 0);
6352                 _res_constr.data[q] = arr_conv_16_conv;
6353         }
6354         (*env)->ReleaseLongArrayElements(env, _res, _res_vals, 0);
6355         CVec_UpdateFailHTLCZ_free(_res_constr);
6356 }
6357
6358 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1UpdateFailMalformedHTLCZ_1free(JNIEnv *env, jclass clz, int64_tArray _res) {
6359         LDKCVec_UpdateFailMalformedHTLCZ _res_constr;
6360         _res_constr.datalen = (*env)->GetArrayLength(env, _res);
6361         if (_res_constr.datalen > 0)
6362                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKUpdateFailMalformedHTLC), "LDKCVec_UpdateFailMalformedHTLCZ Elements");
6363         else
6364                 _res_constr.data = NULL;
6365         int64_t* _res_vals = (*env)->GetLongArrayElements (env, _res, NULL);
6366         for (size_t z = 0; z < _res_constr.datalen; z++) {
6367                 int64_t arr_conv_25 = _res_vals[z];
6368                 LDKUpdateFailMalformedHTLC arr_conv_25_conv;
6369                 arr_conv_25_conv.inner = (void*)(arr_conv_25 & (~1));
6370                 arr_conv_25_conv.is_owned = (arr_conv_25 & 1) || (arr_conv_25 == 0);
6371                 _res_constr.data[z] = arr_conv_25_conv;
6372         }
6373         (*env)->ReleaseLongArrayElements(env, _res, _res_vals, 0);
6374         CVec_UpdateFailMalformedHTLCZ_free(_res_constr);
6375 }
6376
6377 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1boolLightningErrorZ_1ok(JNIEnv *env, jclass clz, jboolean o) {
6378         LDKCResult_boolLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_boolLightningErrorZ), "LDKCResult_boolLightningErrorZ");
6379         *ret_conv = CResult_boolLightningErrorZ_ok(o);
6380         return (long)ret_conv;
6381 }
6382
6383 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1boolLightningErrorZ_1err(JNIEnv *env, jclass clz, int64_t e) {
6384         LDKLightningError e_conv;
6385         e_conv.inner = (void*)(e & (~1));
6386         e_conv.is_owned = (e & 1) || (e == 0);
6387         // Warning: we may need a move here but can't clone!
6388         LDKCResult_boolLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_boolLightningErrorZ), "LDKCResult_boolLightningErrorZ");
6389         *ret_conv = CResult_boolLightningErrorZ_err(e_conv);
6390         return (long)ret_conv;
6391 }
6392
6393 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1boolLightningErrorZ_1free(JNIEnv *env, jclass clz, int64_t _res) {
6394         LDKCResult_boolLightningErrorZ _res_conv = *(LDKCResult_boolLightningErrorZ*)_res;
6395         FREE((void*)_res);
6396         CResult_boolLightningErrorZ_free(_res_conv);
6397 }
6398
6399 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_C3Tuple_1ChannelAnnouncementChannelUpdateChannelUpdateZ_1free(JNIEnv *env, jclass clz, int64_t _res) {
6400         LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ _res_conv = *(LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ*)_res;
6401         FREE((void*)_res);
6402         C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ_free(_res_conv);
6403 }
6404
6405 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_C3Tuple_1ChannelAnnouncementChannelUpdateChannelUpdateZ_1new(JNIEnv *env, jclass clz, int64_t a, int64_t b, int64_t c) {
6406         LDKChannelAnnouncement a_conv;
6407         a_conv.inner = (void*)(a & (~1));
6408         a_conv.is_owned = (a & 1) || (a == 0);
6409         if (a_conv.inner != NULL)
6410                 a_conv = ChannelAnnouncement_clone(&a_conv);
6411         LDKChannelUpdate b_conv;
6412         b_conv.inner = (void*)(b & (~1));
6413         b_conv.is_owned = (b & 1) || (b == 0);
6414         if (b_conv.inner != NULL)
6415                 b_conv = ChannelUpdate_clone(&b_conv);
6416         LDKChannelUpdate c_conv;
6417         c_conv.inner = (void*)(c & (~1));
6418         c_conv.is_owned = (c & 1) || (c == 0);
6419         if (c_conv.inner != NULL)
6420                 c_conv = ChannelUpdate_clone(&c_conv);
6421         LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ* ret_ref = MALLOC(sizeof(LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ), "LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ");
6422         *ret_ref = C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ_new(a_conv, b_conv, c_conv);
6423         ret_ref->a = ChannelAnnouncement_clone(&ret_ref->a);
6424         ret_ref->b = ChannelUpdate_clone(&ret_ref->b);
6425         ret_ref->c = ChannelUpdate_clone(&ret_ref->c);
6426         return (long)ret_ref;
6427 }
6428
6429 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1C3Tuple_1ChannelAnnouncementChannelUpdateChannelUpdateZZ_1free(JNIEnv *env, jclass clz, int64_tArray _res) {
6430         LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ _res_constr;
6431         _res_constr.datalen = (*env)->GetArrayLength(env, _res);
6432         if (_res_constr.datalen > 0)
6433                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ), "LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ Elements");
6434         else
6435                 _res_constr.data = NULL;
6436         int64_t* _res_vals = (*env)->GetLongArrayElements (env, _res, NULL);
6437         for (size_t l = 0; l < _res_constr.datalen; l++) {
6438                 int64_t arr_conv_63 = _res_vals[l];
6439                 LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ arr_conv_63_conv = *(LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ*)arr_conv_63;
6440                 FREE((void*)arr_conv_63);
6441                 _res_constr.data[l] = arr_conv_63_conv;
6442         }
6443         (*env)->ReleaseLongArrayElements(env, _res, _res_vals, 0);
6444         CVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ_free(_res_constr);
6445 }
6446
6447 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1NodeAnnouncementZ_1free(JNIEnv *env, jclass clz, int64_tArray _res) {
6448         LDKCVec_NodeAnnouncementZ _res_constr;
6449         _res_constr.datalen = (*env)->GetArrayLength(env, _res);
6450         if (_res_constr.datalen > 0)
6451                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKNodeAnnouncement), "LDKCVec_NodeAnnouncementZ Elements");
6452         else
6453                 _res_constr.data = NULL;
6454         int64_t* _res_vals = (*env)->GetLongArrayElements (env, _res, NULL);
6455         for (size_t s = 0; s < _res_constr.datalen; s++) {
6456                 int64_t arr_conv_18 = _res_vals[s];
6457                 LDKNodeAnnouncement arr_conv_18_conv;
6458                 arr_conv_18_conv.inner = (void*)(arr_conv_18 & (~1));
6459                 arr_conv_18_conv.is_owned = (arr_conv_18 & 1) || (arr_conv_18 == 0);
6460                 _res_constr.data[s] = arr_conv_18_conv;
6461         }
6462         (*env)->ReleaseLongArrayElements(env, _res, _res_vals, 0);
6463         CVec_NodeAnnouncementZ_free(_res_constr);
6464 }
6465
6466 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1NoneLightningErrorZ_1ok(JNIEnv *env, jclass clz) {
6467         LDKCResult_NoneLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneLightningErrorZ), "LDKCResult_NoneLightningErrorZ");
6468         *ret_conv = CResult_NoneLightningErrorZ_ok();
6469         return (long)ret_conv;
6470 }
6471
6472 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1NoneLightningErrorZ_1err(JNIEnv *env, jclass clz, int64_t e) {
6473         LDKLightningError e_conv;
6474         e_conv.inner = (void*)(e & (~1));
6475         e_conv.is_owned = (e & 1) || (e == 0);
6476         // Warning: we may need a move here but can't clone!
6477         LDKCResult_NoneLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneLightningErrorZ), "LDKCResult_NoneLightningErrorZ");
6478         *ret_conv = CResult_NoneLightningErrorZ_err(e_conv);
6479         return (long)ret_conv;
6480 }
6481
6482 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1NoneLightningErrorZ_1free(JNIEnv *env, jclass clz, int64_t _res) {
6483         LDKCResult_NoneLightningErrorZ _res_conv = *(LDKCResult_NoneLightningErrorZ*)_res;
6484         FREE((void*)_res);
6485         CResult_NoneLightningErrorZ_free(_res_conv);
6486 }
6487
6488 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1ChannelReestablishDecodeErrorZ_1ok(JNIEnv *env, jclass clz, int64_t o) {
6489         LDKChannelReestablish o_conv;
6490         o_conv.inner = (void*)(o & (~1));
6491         o_conv.is_owned = (o & 1) || (o == 0);
6492         if (o_conv.inner != NULL)
6493                 o_conv = ChannelReestablish_clone(&o_conv);
6494         LDKCResult_ChannelReestablishDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ChannelReestablishDecodeErrorZ), "LDKCResult_ChannelReestablishDecodeErrorZ");
6495         *ret_conv = CResult_ChannelReestablishDecodeErrorZ_ok(o_conv);
6496         return (long)ret_conv;
6497 }
6498
6499 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1ChannelReestablishDecodeErrorZ_1err(JNIEnv *env, jclass clz, int64_t e) {
6500         LDKDecodeError e_conv;
6501         e_conv.inner = (void*)(e & (~1));
6502         e_conv.is_owned = (e & 1) || (e == 0);
6503         // Warning: we may need a move here but can't clone!
6504         LDKCResult_ChannelReestablishDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ChannelReestablishDecodeErrorZ), "LDKCResult_ChannelReestablishDecodeErrorZ");
6505         *ret_conv = CResult_ChannelReestablishDecodeErrorZ_err(e_conv);
6506         return (long)ret_conv;
6507 }
6508
6509 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1ChannelReestablishDecodeErrorZ_1free(JNIEnv *env, jclass clz, int64_t _res) {
6510         LDKCResult_ChannelReestablishDecodeErrorZ _res_conv = *(LDKCResult_ChannelReestablishDecodeErrorZ*)_res;
6511         FREE((void*)_res);
6512         CResult_ChannelReestablishDecodeErrorZ_free(_res_conv);
6513 }
6514
6515 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1InitDecodeErrorZ_1ok(JNIEnv *env, jclass clz, int64_t o) {
6516         LDKInit o_conv;
6517         o_conv.inner = (void*)(o & (~1));
6518         o_conv.is_owned = (o & 1) || (o == 0);
6519         if (o_conv.inner != NULL)
6520                 o_conv = Init_clone(&o_conv);
6521         LDKCResult_InitDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_InitDecodeErrorZ), "LDKCResult_InitDecodeErrorZ");
6522         *ret_conv = CResult_InitDecodeErrorZ_ok(o_conv);
6523         return (long)ret_conv;
6524 }
6525
6526 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1InitDecodeErrorZ_1err(JNIEnv *env, jclass clz, int64_t e) {
6527         LDKDecodeError e_conv;
6528         e_conv.inner = (void*)(e & (~1));
6529         e_conv.is_owned = (e & 1) || (e == 0);
6530         // Warning: we may need a move here but can't clone!
6531         LDKCResult_InitDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_InitDecodeErrorZ), "LDKCResult_InitDecodeErrorZ");
6532         *ret_conv = CResult_InitDecodeErrorZ_err(e_conv);
6533         return (long)ret_conv;
6534 }
6535
6536 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1InitDecodeErrorZ_1free(JNIEnv *env, jclass clz, int64_t _res) {
6537         LDKCResult_InitDecodeErrorZ _res_conv = *(LDKCResult_InitDecodeErrorZ*)_res;
6538         FREE((void*)_res);
6539         CResult_InitDecodeErrorZ_free(_res_conv);
6540 }
6541
6542 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1PingDecodeErrorZ_1ok(JNIEnv *env, jclass clz, int64_t o) {
6543         LDKPing o_conv;
6544         o_conv.inner = (void*)(o & (~1));
6545         o_conv.is_owned = (o & 1) || (o == 0);
6546         if (o_conv.inner != NULL)
6547                 o_conv = Ping_clone(&o_conv);
6548         LDKCResult_PingDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_PingDecodeErrorZ), "LDKCResult_PingDecodeErrorZ");
6549         *ret_conv = CResult_PingDecodeErrorZ_ok(o_conv);
6550         return (long)ret_conv;
6551 }
6552
6553 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1PingDecodeErrorZ_1err(JNIEnv *env, jclass clz, int64_t e) {
6554         LDKDecodeError e_conv;
6555         e_conv.inner = (void*)(e & (~1));
6556         e_conv.is_owned = (e & 1) || (e == 0);
6557         // Warning: we may need a move here but can't clone!
6558         LDKCResult_PingDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_PingDecodeErrorZ), "LDKCResult_PingDecodeErrorZ");
6559         *ret_conv = CResult_PingDecodeErrorZ_err(e_conv);
6560         return (long)ret_conv;
6561 }
6562
6563 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1PingDecodeErrorZ_1free(JNIEnv *env, jclass clz, int64_t _res) {
6564         LDKCResult_PingDecodeErrorZ _res_conv = *(LDKCResult_PingDecodeErrorZ*)_res;
6565         FREE((void*)_res);
6566         CResult_PingDecodeErrorZ_free(_res_conv);
6567 }
6568
6569 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1PongDecodeErrorZ_1ok(JNIEnv *env, jclass clz, int64_t o) {
6570         LDKPong o_conv;
6571         o_conv.inner = (void*)(o & (~1));
6572         o_conv.is_owned = (o & 1) || (o == 0);
6573         if (o_conv.inner != NULL)
6574                 o_conv = Pong_clone(&o_conv);
6575         LDKCResult_PongDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_PongDecodeErrorZ), "LDKCResult_PongDecodeErrorZ");
6576         *ret_conv = CResult_PongDecodeErrorZ_ok(o_conv);
6577         return (long)ret_conv;
6578 }
6579
6580 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1PongDecodeErrorZ_1err(JNIEnv *env, jclass clz, int64_t e) {
6581         LDKDecodeError e_conv;
6582         e_conv.inner = (void*)(e & (~1));
6583         e_conv.is_owned = (e & 1) || (e == 0);
6584         // Warning: we may need a move here but can't clone!
6585         LDKCResult_PongDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_PongDecodeErrorZ), "LDKCResult_PongDecodeErrorZ");
6586         *ret_conv = CResult_PongDecodeErrorZ_err(e_conv);
6587         return (long)ret_conv;
6588 }
6589
6590 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1PongDecodeErrorZ_1free(JNIEnv *env, jclass clz, int64_t _res) {
6591         LDKCResult_PongDecodeErrorZ _res_conv = *(LDKCResult_PongDecodeErrorZ*)_res;
6592         FREE((void*)_res);
6593         CResult_PongDecodeErrorZ_free(_res_conv);
6594 }
6595
6596 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1UnsignedChannelAnnouncementDecodeErrorZ_1ok(JNIEnv *env, jclass clz, int64_t o) {
6597         LDKUnsignedChannelAnnouncement o_conv;
6598         o_conv.inner = (void*)(o & (~1));
6599         o_conv.is_owned = (o & 1) || (o == 0);
6600         if (o_conv.inner != NULL)
6601                 o_conv = UnsignedChannelAnnouncement_clone(&o_conv);
6602         LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ), "LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ");
6603         *ret_conv = CResult_UnsignedChannelAnnouncementDecodeErrorZ_ok(o_conv);
6604         return (long)ret_conv;
6605 }
6606
6607 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1UnsignedChannelAnnouncementDecodeErrorZ_1err(JNIEnv *env, jclass clz, int64_t e) {
6608         LDKDecodeError e_conv;
6609         e_conv.inner = (void*)(e & (~1));
6610         e_conv.is_owned = (e & 1) || (e == 0);
6611         // Warning: we may need a move here but can't clone!
6612         LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ), "LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ");
6613         *ret_conv = CResult_UnsignedChannelAnnouncementDecodeErrorZ_err(e_conv);
6614         return (long)ret_conv;
6615 }
6616
6617 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1UnsignedChannelAnnouncementDecodeErrorZ_1free(JNIEnv *env, jclass clz, int64_t _res) {
6618         LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ _res_conv = *(LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ*)_res;
6619         FREE((void*)_res);
6620         CResult_UnsignedChannelAnnouncementDecodeErrorZ_free(_res_conv);
6621 }
6622
6623 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1UnsignedChannelUpdateDecodeErrorZ_1ok(JNIEnv *env, jclass clz, int64_t o) {
6624         LDKUnsignedChannelUpdate o_conv;
6625         o_conv.inner = (void*)(o & (~1));
6626         o_conv.is_owned = (o & 1) || (o == 0);
6627         if (o_conv.inner != NULL)
6628                 o_conv = UnsignedChannelUpdate_clone(&o_conv);
6629         LDKCResult_UnsignedChannelUpdateDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_UnsignedChannelUpdateDecodeErrorZ), "LDKCResult_UnsignedChannelUpdateDecodeErrorZ");
6630         *ret_conv = CResult_UnsignedChannelUpdateDecodeErrorZ_ok(o_conv);
6631         return (long)ret_conv;
6632 }
6633
6634 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1UnsignedChannelUpdateDecodeErrorZ_1err(JNIEnv *env, jclass clz, int64_t e) {
6635         LDKDecodeError e_conv;
6636         e_conv.inner = (void*)(e & (~1));
6637         e_conv.is_owned = (e & 1) || (e == 0);
6638         // Warning: we may need a move here but can't clone!
6639         LDKCResult_UnsignedChannelUpdateDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_UnsignedChannelUpdateDecodeErrorZ), "LDKCResult_UnsignedChannelUpdateDecodeErrorZ");
6640         *ret_conv = CResult_UnsignedChannelUpdateDecodeErrorZ_err(e_conv);
6641         return (long)ret_conv;
6642 }
6643
6644 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1UnsignedChannelUpdateDecodeErrorZ_1free(JNIEnv *env, jclass clz, int64_t _res) {
6645         LDKCResult_UnsignedChannelUpdateDecodeErrorZ _res_conv = *(LDKCResult_UnsignedChannelUpdateDecodeErrorZ*)_res;
6646         FREE((void*)_res);
6647         CResult_UnsignedChannelUpdateDecodeErrorZ_free(_res_conv);
6648 }
6649
6650 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1ErrorMessageDecodeErrorZ_1ok(JNIEnv *env, jclass clz, int64_t o) {
6651         LDKErrorMessage o_conv;
6652         o_conv.inner = (void*)(o & (~1));
6653         o_conv.is_owned = (o & 1) || (o == 0);
6654         if (o_conv.inner != NULL)
6655                 o_conv = ErrorMessage_clone(&o_conv);
6656         LDKCResult_ErrorMessageDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ErrorMessageDecodeErrorZ), "LDKCResult_ErrorMessageDecodeErrorZ");
6657         *ret_conv = CResult_ErrorMessageDecodeErrorZ_ok(o_conv);
6658         return (long)ret_conv;
6659 }
6660
6661 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1ErrorMessageDecodeErrorZ_1err(JNIEnv *env, jclass clz, int64_t e) {
6662         LDKDecodeError e_conv;
6663         e_conv.inner = (void*)(e & (~1));
6664         e_conv.is_owned = (e & 1) || (e == 0);
6665         // Warning: we may need a move here but can't clone!
6666         LDKCResult_ErrorMessageDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ErrorMessageDecodeErrorZ), "LDKCResult_ErrorMessageDecodeErrorZ");
6667         *ret_conv = CResult_ErrorMessageDecodeErrorZ_err(e_conv);
6668         return (long)ret_conv;
6669 }
6670
6671 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1ErrorMessageDecodeErrorZ_1free(JNIEnv *env, jclass clz, int64_t _res) {
6672         LDKCResult_ErrorMessageDecodeErrorZ _res_conv = *(LDKCResult_ErrorMessageDecodeErrorZ*)_res;
6673         FREE((void*)_res);
6674         CResult_ErrorMessageDecodeErrorZ_free(_res_conv);
6675 }
6676
6677 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1UnsignedNodeAnnouncementDecodeErrorZ_1ok(JNIEnv *env, jclass clz, int64_t o) {
6678         LDKUnsignedNodeAnnouncement o_conv;
6679         o_conv.inner = (void*)(o & (~1));
6680         o_conv.is_owned = (o & 1) || (o == 0);
6681         if (o_conv.inner != NULL)
6682                 o_conv = UnsignedNodeAnnouncement_clone(&o_conv);
6683         LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ), "LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ");
6684         *ret_conv = CResult_UnsignedNodeAnnouncementDecodeErrorZ_ok(o_conv);
6685         return (long)ret_conv;
6686 }
6687
6688 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1UnsignedNodeAnnouncementDecodeErrorZ_1err(JNIEnv *env, jclass clz, int64_t e) {
6689         LDKDecodeError e_conv;
6690         e_conv.inner = (void*)(e & (~1));
6691         e_conv.is_owned = (e & 1) || (e == 0);
6692         // Warning: we may need a move here but can't clone!
6693         LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ), "LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ");
6694         *ret_conv = CResult_UnsignedNodeAnnouncementDecodeErrorZ_err(e_conv);
6695         return (long)ret_conv;
6696 }
6697
6698 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1UnsignedNodeAnnouncementDecodeErrorZ_1free(JNIEnv *env, jclass clz, int64_t _res) {
6699         LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ _res_conv = *(LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ*)_res;
6700         FREE((void*)_res);
6701         CResult_UnsignedNodeAnnouncementDecodeErrorZ_free(_res_conv);
6702 }
6703
6704 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1QueryShortChannelIdsDecodeErrorZ_1ok(JNIEnv *env, jclass clz, int64_t o) {
6705         LDKQueryShortChannelIds o_conv;
6706         o_conv.inner = (void*)(o & (~1));
6707         o_conv.is_owned = (o & 1) || (o == 0);
6708         if (o_conv.inner != NULL)
6709                 o_conv = QueryShortChannelIds_clone(&o_conv);
6710         LDKCResult_QueryShortChannelIdsDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_QueryShortChannelIdsDecodeErrorZ), "LDKCResult_QueryShortChannelIdsDecodeErrorZ");
6711         *ret_conv = CResult_QueryShortChannelIdsDecodeErrorZ_ok(o_conv);
6712         return (long)ret_conv;
6713 }
6714
6715 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1QueryShortChannelIdsDecodeErrorZ_1err(JNIEnv *env, jclass clz, int64_t e) {
6716         LDKDecodeError e_conv;
6717         e_conv.inner = (void*)(e & (~1));
6718         e_conv.is_owned = (e & 1) || (e == 0);
6719         // Warning: we may need a move here but can't clone!
6720         LDKCResult_QueryShortChannelIdsDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_QueryShortChannelIdsDecodeErrorZ), "LDKCResult_QueryShortChannelIdsDecodeErrorZ");
6721         *ret_conv = CResult_QueryShortChannelIdsDecodeErrorZ_err(e_conv);
6722         return (long)ret_conv;
6723 }
6724
6725 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1QueryShortChannelIdsDecodeErrorZ_1free(JNIEnv *env, jclass clz, int64_t _res) {
6726         LDKCResult_QueryShortChannelIdsDecodeErrorZ _res_conv = *(LDKCResult_QueryShortChannelIdsDecodeErrorZ*)_res;
6727         FREE((void*)_res);
6728         CResult_QueryShortChannelIdsDecodeErrorZ_free(_res_conv);
6729 }
6730
6731 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1ReplyShortChannelIdsEndDecodeErrorZ_1ok(JNIEnv *env, jclass clz, int64_t o) {
6732         LDKReplyShortChannelIdsEnd o_conv;
6733         o_conv.inner = (void*)(o & (~1));
6734         o_conv.is_owned = (o & 1) || (o == 0);
6735         if (o_conv.inner != NULL)
6736                 o_conv = ReplyShortChannelIdsEnd_clone(&o_conv);
6737         LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ), "LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ");
6738         *ret_conv = CResult_ReplyShortChannelIdsEndDecodeErrorZ_ok(o_conv);
6739         return (long)ret_conv;
6740 }
6741
6742 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1ReplyShortChannelIdsEndDecodeErrorZ_1err(JNIEnv *env, jclass clz, int64_t e) {
6743         LDKDecodeError e_conv;
6744         e_conv.inner = (void*)(e & (~1));
6745         e_conv.is_owned = (e & 1) || (e == 0);
6746         // Warning: we may need a move here but can't clone!
6747         LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ), "LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ");
6748         *ret_conv = CResult_ReplyShortChannelIdsEndDecodeErrorZ_err(e_conv);
6749         return (long)ret_conv;
6750 }
6751
6752 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1ReplyShortChannelIdsEndDecodeErrorZ_1free(JNIEnv *env, jclass clz, int64_t _res) {
6753         LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ _res_conv = *(LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ*)_res;
6754         FREE((void*)_res);
6755         CResult_ReplyShortChannelIdsEndDecodeErrorZ_free(_res_conv);
6756 }
6757
6758 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1QueryChannelRangeDecodeErrorZ_1ok(JNIEnv *env, jclass clz, int64_t o) {
6759         LDKQueryChannelRange o_conv;
6760         o_conv.inner = (void*)(o & (~1));
6761         o_conv.is_owned = (o & 1) || (o == 0);
6762         if (o_conv.inner != NULL)
6763                 o_conv = QueryChannelRange_clone(&o_conv);
6764         LDKCResult_QueryChannelRangeDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_QueryChannelRangeDecodeErrorZ), "LDKCResult_QueryChannelRangeDecodeErrorZ");
6765         *ret_conv = CResult_QueryChannelRangeDecodeErrorZ_ok(o_conv);
6766         return (long)ret_conv;
6767 }
6768
6769 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1QueryChannelRangeDecodeErrorZ_1err(JNIEnv *env, jclass clz, int64_t e) {
6770         LDKDecodeError e_conv;
6771         e_conv.inner = (void*)(e & (~1));
6772         e_conv.is_owned = (e & 1) || (e == 0);
6773         // Warning: we may need a move here but can't clone!
6774         LDKCResult_QueryChannelRangeDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_QueryChannelRangeDecodeErrorZ), "LDKCResult_QueryChannelRangeDecodeErrorZ");
6775         *ret_conv = CResult_QueryChannelRangeDecodeErrorZ_err(e_conv);
6776         return (long)ret_conv;
6777 }
6778
6779 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1QueryChannelRangeDecodeErrorZ_1free(JNIEnv *env, jclass clz, int64_t _res) {
6780         LDKCResult_QueryChannelRangeDecodeErrorZ _res_conv = *(LDKCResult_QueryChannelRangeDecodeErrorZ*)_res;
6781         FREE((void*)_res);
6782         CResult_QueryChannelRangeDecodeErrorZ_free(_res_conv);
6783 }
6784
6785 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1ReplyChannelRangeDecodeErrorZ_1ok(JNIEnv *env, jclass clz, int64_t o) {
6786         LDKReplyChannelRange o_conv;
6787         o_conv.inner = (void*)(o & (~1));
6788         o_conv.is_owned = (o & 1) || (o == 0);
6789         if (o_conv.inner != NULL)
6790                 o_conv = ReplyChannelRange_clone(&o_conv);
6791         LDKCResult_ReplyChannelRangeDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ReplyChannelRangeDecodeErrorZ), "LDKCResult_ReplyChannelRangeDecodeErrorZ");
6792         *ret_conv = CResult_ReplyChannelRangeDecodeErrorZ_ok(o_conv);
6793         return (long)ret_conv;
6794 }
6795
6796 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1ReplyChannelRangeDecodeErrorZ_1err(JNIEnv *env, jclass clz, int64_t e) {
6797         LDKDecodeError e_conv;
6798         e_conv.inner = (void*)(e & (~1));
6799         e_conv.is_owned = (e & 1) || (e == 0);
6800         // Warning: we may need a move here but can't clone!
6801         LDKCResult_ReplyChannelRangeDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ReplyChannelRangeDecodeErrorZ), "LDKCResult_ReplyChannelRangeDecodeErrorZ");
6802         *ret_conv = CResult_ReplyChannelRangeDecodeErrorZ_err(e_conv);
6803         return (long)ret_conv;
6804 }
6805
6806 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1ReplyChannelRangeDecodeErrorZ_1free(JNIEnv *env, jclass clz, int64_t _res) {
6807         LDKCResult_ReplyChannelRangeDecodeErrorZ _res_conv = *(LDKCResult_ReplyChannelRangeDecodeErrorZ*)_res;
6808         FREE((void*)_res);
6809         CResult_ReplyChannelRangeDecodeErrorZ_free(_res_conv);
6810 }
6811
6812 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1GossipTimestampFilterDecodeErrorZ_1ok(JNIEnv *env, jclass clz, int64_t o) {
6813         LDKGossipTimestampFilter o_conv;
6814         o_conv.inner = (void*)(o & (~1));
6815         o_conv.is_owned = (o & 1) || (o == 0);
6816         if (o_conv.inner != NULL)
6817                 o_conv = GossipTimestampFilter_clone(&o_conv);
6818         LDKCResult_GossipTimestampFilterDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_GossipTimestampFilterDecodeErrorZ), "LDKCResult_GossipTimestampFilterDecodeErrorZ");
6819         *ret_conv = CResult_GossipTimestampFilterDecodeErrorZ_ok(o_conv);
6820         return (long)ret_conv;
6821 }
6822
6823 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1GossipTimestampFilterDecodeErrorZ_1err(JNIEnv *env, jclass clz, int64_t e) {
6824         LDKDecodeError e_conv;
6825         e_conv.inner = (void*)(e & (~1));
6826         e_conv.is_owned = (e & 1) || (e == 0);
6827         // Warning: we may need a move here but can't clone!
6828         LDKCResult_GossipTimestampFilterDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_GossipTimestampFilterDecodeErrorZ), "LDKCResult_GossipTimestampFilterDecodeErrorZ");
6829         *ret_conv = CResult_GossipTimestampFilterDecodeErrorZ_err(e_conv);
6830         return (long)ret_conv;
6831 }
6832
6833 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1GossipTimestampFilterDecodeErrorZ_1free(JNIEnv *env, jclass clz, int64_t _res) {
6834         LDKCResult_GossipTimestampFilterDecodeErrorZ _res_conv = *(LDKCResult_GossipTimestampFilterDecodeErrorZ*)_res;
6835         FREE((void*)_res);
6836         CResult_GossipTimestampFilterDecodeErrorZ_free(_res_conv);
6837 }
6838
6839 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1PublicKeyZ_1free(JNIEnv *env, jclass clz, jobjectArray _res) {
6840         LDKCVec_PublicKeyZ _res_constr;
6841         _res_constr.datalen = (*env)->GetArrayLength(env, _res);
6842         if (_res_constr.datalen > 0)
6843                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKPublicKey), "LDKCVec_PublicKeyZ Elements");
6844         else
6845                 _res_constr.data = NULL;
6846         for (size_t i = 0; i < _res_constr.datalen; i++) {
6847                 int8_tArray arr_conv_8 = (*env)->GetObjectArrayElement(env, _res, i);
6848                 LDKPublicKey arr_conv_8_ref;
6849                 CHECK((*env)->GetArrayLength(env, arr_conv_8) == 33);
6850                 (*env)->GetByteArrayRegion(env, arr_conv_8, 0, 33, arr_conv_8_ref.compressed_form);
6851                 _res_constr.data[i] = arr_conv_8_ref;
6852         }
6853         CVec_PublicKeyZ_free(_res_constr);
6854 }
6855
6856 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1u8Z_1free(JNIEnv *env, jclass clz, int8_tArray _res) {
6857         LDKCVec_u8Z _res_ref;
6858         _res_ref.datalen = (*env)->GetArrayLength(env, _res);
6859         _res_ref.data = MALLOC(_res_ref.datalen, "LDKCVec_u8Z Bytes");
6860         (*env)->GetByteArrayRegion(env, _res, 0, _res_ref.datalen, _res_ref.data);
6861         CVec_u8Z_free(_res_ref);
6862 }
6863
6864 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1CVec_1u8ZPeerHandleErrorZ_1ok(JNIEnv *env, jclass clz, int8_tArray o) {
6865         LDKCVec_u8Z o_ref;
6866         o_ref.datalen = (*env)->GetArrayLength(env, o);
6867         o_ref.data = MALLOC(o_ref.datalen, "LDKCVec_u8Z Bytes");
6868         (*env)->GetByteArrayRegion(env, o, 0, o_ref.datalen, o_ref.data);
6869         LDKCResult_CVec_u8ZPeerHandleErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_CVec_u8ZPeerHandleErrorZ), "LDKCResult_CVec_u8ZPeerHandleErrorZ");
6870         *ret_conv = CResult_CVec_u8ZPeerHandleErrorZ_ok(o_ref);
6871         return (long)ret_conv;
6872 }
6873
6874 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1CVec_1u8ZPeerHandleErrorZ_1err(JNIEnv *env, jclass clz, int64_t e) {
6875         LDKPeerHandleError e_conv;
6876         e_conv.inner = (void*)(e & (~1));
6877         e_conv.is_owned = (e & 1) || (e == 0);
6878         // Warning: we may need a move here but can't clone!
6879         LDKCResult_CVec_u8ZPeerHandleErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_CVec_u8ZPeerHandleErrorZ), "LDKCResult_CVec_u8ZPeerHandleErrorZ");
6880         *ret_conv = CResult_CVec_u8ZPeerHandleErrorZ_err(e_conv);
6881         return (long)ret_conv;
6882 }
6883
6884 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1CVec_1u8ZPeerHandleErrorZ_1free(JNIEnv *env, jclass clz, int64_t _res) {
6885         LDKCResult_CVec_u8ZPeerHandleErrorZ _res_conv = *(LDKCResult_CVec_u8ZPeerHandleErrorZ*)_res;
6886         FREE((void*)_res);
6887         CResult_CVec_u8ZPeerHandleErrorZ_free(_res_conv);
6888 }
6889
6890 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1NonePeerHandleErrorZ_1ok(JNIEnv *env, jclass clz) {
6891         LDKCResult_NonePeerHandleErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NonePeerHandleErrorZ), "LDKCResult_NonePeerHandleErrorZ");
6892         *ret_conv = CResult_NonePeerHandleErrorZ_ok();
6893         return (long)ret_conv;
6894 }
6895
6896 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1NonePeerHandleErrorZ_1err(JNIEnv *env, jclass clz, int64_t e) {
6897         LDKPeerHandleError e_conv;
6898         e_conv.inner = (void*)(e & (~1));
6899         e_conv.is_owned = (e & 1) || (e == 0);
6900         // Warning: we may need a move here but can't clone!
6901         LDKCResult_NonePeerHandleErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NonePeerHandleErrorZ), "LDKCResult_NonePeerHandleErrorZ");
6902         *ret_conv = CResult_NonePeerHandleErrorZ_err(e_conv);
6903         return (long)ret_conv;
6904 }
6905
6906 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1NonePeerHandleErrorZ_1free(JNIEnv *env, jclass clz, int64_t _res) {
6907         LDKCResult_NonePeerHandleErrorZ _res_conv = *(LDKCResult_NonePeerHandleErrorZ*)_res;
6908         FREE((void*)_res);
6909         CResult_NonePeerHandleErrorZ_free(_res_conv);
6910 }
6911
6912 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1boolPeerHandleErrorZ_1ok(JNIEnv *env, jclass clz, jboolean o) {
6913         LDKCResult_boolPeerHandleErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_boolPeerHandleErrorZ), "LDKCResult_boolPeerHandleErrorZ");
6914         *ret_conv = CResult_boolPeerHandleErrorZ_ok(o);
6915         return (long)ret_conv;
6916 }
6917
6918 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1boolPeerHandleErrorZ_1err(JNIEnv *env, jclass clz, int64_t e) {
6919         LDKPeerHandleError e_conv;
6920         e_conv.inner = (void*)(e & (~1));
6921         e_conv.is_owned = (e & 1) || (e == 0);
6922         // Warning: we may need a move here but can't clone!
6923         LDKCResult_boolPeerHandleErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_boolPeerHandleErrorZ), "LDKCResult_boolPeerHandleErrorZ");
6924         *ret_conv = CResult_boolPeerHandleErrorZ_err(e_conv);
6925         return (long)ret_conv;
6926 }
6927
6928 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1boolPeerHandleErrorZ_1free(JNIEnv *env, jclass clz, int64_t _res) {
6929         LDKCResult_boolPeerHandleErrorZ _res_conv = *(LDKCResult_boolPeerHandleErrorZ*)_res;
6930         FREE((void*)_res);
6931         CResult_boolPeerHandleErrorZ_free(_res_conv);
6932 }
6933
6934 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1SecretKeySecpErrorZ_1ok(JNIEnv *env, jclass clz, int8_tArray o) {
6935         LDKSecretKey o_ref;
6936         CHECK((*env)->GetArrayLength(env, o) == 32);
6937         (*env)->GetByteArrayRegion(env, o, 0, 32, o_ref.bytes);
6938         LDKCResult_SecretKeySecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_SecretKeySecpErrorZ), "LDKCResult_SecretKeySecpErrorZ");
6939         *ret_conv = CResult_SecretKeySecpErrorZ_ok(o_ref);
6940         return (long)ret_conv;
6941 }
6942
6943 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1SecretKeySecpErrorZ_1err(JNIEnv *env, jclass clz, jclass e) {
6944         LDKSecp256k1Error e_conv = LDKSecp256k1Error_from_java(env, e);
6945         LDKCResult_SecretKeySecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_SecretKeySecpErrorZ), "LDKCResult_SecretKeySecpErrorZ");
6946         *ret_conv = CResult_SecretKeySecpErrorZ_err(e_conv);
6947         return (long)ret_conv;
6948 }
6949
6950 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1SecretKeySecpErrorZ_1free(JNIEnv *env, jclass clz, int64_t _res) {
6951         LDKCResult_SecretKeySecpErrorZ _res_conv = *(LDKCResult_SecretKeySecpErrorZ*)_res;
6952         FREE((void*)_res);
6953         CResult_SecretKeySecpErrorZ_free(_res_conv);
6954 }
6955
6956 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1PublicKeySecpErrorZ_1ok(JNIEnv *env, jclass clz, int8_tArray o) {
6957         LDKPublicKey o_ref;
6958         CHECK((*env)->GetArrayLength(env, o) == 33);
6959         (*env)->GetByteArrayRegion(env, o, 0, 33, o_ref.compressed_form);
6960         LDKCResult_PublicKeySecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_PublicKeySecpErrorZ), "LDKCResult_PublicKeySecpErrorZ");
6961         *ret_conv = CResult_PublicKeySecpErrorZ_ok(o_ref);
6962         return (long)ret_conv;
6963 }
6964
6965 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1PublicKeySecpErrorZ_1err(JNIEnv *env, jclass clz, jclass e) {
6966         LDKSecp256k1Error e_conv = LDKSecp256k1Error_from_java(env, e);
6967         LDKCResult_PublicKeySecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_PublicKeySecpErrorZ), "LDKCResult_PublicKeySecpErrorZ");
6968         *ret_conv = CResult_PublicKeySecpErrorZ_err(e_conv);
6969         return (long)ret_conv;
6970 }
6971
6972 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1PublicKeySecpErrorZ_1free(JNIEnv *env, jclass clz, int64_t _res) {
6973         LDKCResult_PublicKeySecpErrorZ _res_conv = *(LDKCResult_PublicKeySecpErrorZ*)_res;
6974         FREE((void*)_res);
6975         CResult_PublicKeySecpErrorZ_free(_res_conv);
6976 }
6977
6978 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1TxCreationKeysSecpErrorZ_1ok(JNIEnv *env, jclass clz, int64_t o) {
6979         LDKTxCreationKeys o_conv;
6980         o_conv.inner = (void*)(o & (~1));
6981         o_conv.is_owned = (o & 1) || (o == 0);
6982         if (o_conv.inner != NULL)
6983                 o_conv = TxCreationKeys_clone(&o_conv);
6984         LDKCResult_TxCreationKeysSecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_TxCreationKeysSecpErrorZ), "LDKCResult_TxCreationKeysSecpErrorZ");
6985         *ret_conv = CResult_TxCreationKeysSecpErrorZ_ok(o_conv);
6986         return (long)ret_conv;
6987 }
6988
6989 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1TxCreationKeysSecpErrorZ_1err(JNIEnv *env, jclass clz, jclass e) {
6990         LDKSecp256k1Error e_conv = LDKSecp256k1Error_from_java(env, e);
6991         LDKCResult_TxCreationKeysSecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_TxCreationKeysSecpErrorZ), "LDKCResult_TxCreationKeysSecpErrorZ");
6992         *ret_conv = CResult_TxCreationKeysSecpErrorZ_err(e_conv);
6993         return (long)ret_conv;
6994 }
6995
6996 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1TxCreationKeysSecpErrorZ_1free(JNIEnv *env, jclass clz, int64_t _res) {
6997         LDKCResult_TxCreationKeysSecpErrorZ _res_conv = *(LDKCResult_TxCreationKeysSecpErrorZ*)_res;
6998         FREE((void*)_res);
6999         CResult_TxCreationKeysSecpErrorZ_free(_res_conv);
7000 }
7001
7002 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1TrustedCommitmentTransactionNoneZ_1ok(JNIEnv *env, jclass clz, int64_t o) {
7003         LDKTrustedCommitmentTransaction o_conv;
7004         o_conv.inner = (void*)(o & (~1));
7005         o_conv.is_owned = (o & 1) || (o == 0);
7006         // Warning: we may need a move here but can't clone!
7007         LDKCResult_TrustedCommitmentTransactionNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_TrustedCommitmentTransactionNoneZ), "LDKCResult_TrustedCommitmentTransactionNoneZ");
7008         *ret_conv = CResult_TrustedCommitmentTransactionNoneZ_ok(o_conv);
7009         return (long)ret_conv;
7010 }
7011
7012 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1TrustedCommitmentTransactionNoneZ_1err(JNIEnv *env, jclass clz) {
7013         LDKCResult_TrustedCommitmentTransactionNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_TrustedCommitmentTransactionNoneZ), "LDKCResult_TrustedCommitmentTransactionNoneZ");
7014         *ret_conv = CResult_TrustedCommitmentTransactionNoneZ_err();
7015         return (long)ret_conv;
7016 }
7017
7018 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1TrustedCommitmentTransactionNoneZ_1free(JNIEnv *env, jclass clz, int64_t _res) {
7019         LDKCResult_TrustedCommitmentTransactionNoneZ _res_conv = *(LDKCResult_TrustedCommitmentTransactionNoneZ*)_res;
7020         FREE((void*)_res);
7021         CResult_TrustedCommitmentTransactionNoneZ_free(_res_conv);
7022 }
7023
7024 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1RouteHopZ_1free(JNIEnv *env, jclass clz, int64_tArray _res) {
7025         LDKCVec_RouteHopZ _res_constr;
7026         _res_constr.datalen = (*env)->GetArrayLength(env, _res);
7027         if (_res_constr.datalen > 0)
7028                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKRouteHop), "LDKCVec_RouteHopZ Elements");
7029         else
7030                 _res_constr.data = NULL;
7031         int64_t* _res_vals = (*env)->GetLongArrayElements (env, _res, NULL);
7032         for (size_t k = 0; k < _res_constr.datalen; k++) {
7033                 int64_t arr_conv_10 = _res_vals[k];
7034                 LDKRouteHop arr_conv_10_conv;
7035                 arr_conv_10_conv.inner = (void*)(arr_conv_10 & (~1));
7036                 arr_conv_10_conv.is_owned = (arr_conv_10 & 1) || (arr_conv_10 == 0);
7037                 _res_constr.data[k] = arr_conv_10_conv;
7038         }
7039         (*env)->ReleaseLongArrayElements(env, _res, _res_vals, 0);
7040         CVec_RouteHopZ_free(_res_constr);
7041 }
7042
7043 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1CVec_1RouteHopZZ_1free(JNIEnv *env, jclass clz, jobjectArray _res) {
7044         LDKCVec_CVec_RouteHopZZ _res_constr;
7045         _res_constr.datalen = (*env)->GetArrayLength(env, _res);
7046         if (_res_constr.datalen > 0)
7047                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKCVec_RouteHopZ), "LDKCVec_CVec_RouteHopZZ Elements");
7048         else
7049                 _res_constr.data = NULL;
7050         for (size_t m = 0; m < _res_constr.datalen; m++) {
7051                 int64_tArray arr_conv_12 = (*env)->GetObjectArrayElement(env, _res, m);
7052                 LDKCVec_RouteHopZ arr_conv_12_constr;
7053                 arr_conv_12_constr.datalen = (*env)->GetArrayLength(env, arr_conv_12);
7054                 if (arr_conv_12_constr.datalen > 0)
7055                         arr_conv_12_constr.data = MALLOC(arr_conv_12_constr.datalen * sizeof(LDKRouteHop), "LDKCVec_RouteHopZ Elements");
7056                 else
7057                         arr_conv_12_constr.data = NULL;
7058                 int64_t* arr_conv_12_vals = (*env)->GetLongArrayElements (env, arr_conv_12, NULL);
7059                 for (size_t k = 0; k < arr_conv_12_constr.datalen; k++) {
7060                         int64_t arr_conv_10 = arr_conv_12_vals[k];
7061                         LDKRouteHop arr_conv_10_conv;
7062                         arr_conv_10_conv.inner = (void*)(arr_conv_10 & (~1));
7063                         arr_conv_10_conv.is_owned = (arr_conv_10 & 1) || (arr_conv_10 == 0);
7064                         arr_conv_12_constr.data[k] = arr_conv_10_conv;
7065                 }
7066                 (*env)->ReleaseLongArrayElements(env, arr_conv_12, arr_conv_12_vals, 0);
7067                 _res_constr.data[m] = arr_conv_12_constr;
7068         }
7069         CVec_CVec_RouteHopZZ_free(_res_constr);
7070 }
7071
7072 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1RouteDecodeErrorZ_1ok(JNIEnv *env, jclass clz, int64_t o) {
7073         LDKRoute o_conv;
7074         o_conv.inner = (void*)(o & (~1));
7075         o_conv.is_owned = (o & 1) || (o == 0);
7076         if (o_conv.inner != NULL)
7077                 o_conv = Route_clone(&o_conv);
7078         LDKCResult_RouteDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_RouteDecodeErrorZ), "LDKCResult_RouteDecodeErrorZ");
7079         *ret_conv = CResult_RouteDecodeErrorZ_ok(o_conv);
7080         return (long)ret_conv;
7081 }
7082
7083 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1RouteDecodeErrorZ_1err(JNIEnv *env, jclass clz, int64_t e) {
7084         LDKDecodeError e_conv;
7085         e_conv.inner = (void*)(e & (~1));
7086         e_conv.is_owned = (e & 1) || (e == 0);
7087         // Warning: we may need a move here but can't clone!
7088         LDKCResult_RouteDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_RouteDecodeErrorZ), "LDKCResult_RouteDecodeErrorZ");
7089         *ret_conv = CResult_RouteDecodeErrorZ_err(e_conv);
7090         return (long)ret_conv;
7091 }
7092
7093 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1RouteDecodeErrorZ_1free(JNIEnv *env, jclass clz, int64_t _res) {
7094         LDKCResult_RouteDecodeErrorZ _res_conv = *(LDKCResult_RouteDecodeErrorZ*)_res;
7095         FREE((void*)_res);
7096         CResult_RouteDecodeErrorZ_free(_res_conv);
7097 }
7098
7099 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1RouteHintZ_1free(JNIEnv *env, jclass clz, int64_tArray _res) {
7100         LDKCVec_RouteHintZ _res_constr;
7101         _res_constr.datalen = (*env)->GetArrayLength(env, _res);
7102         if (_res_constr.datalen > 0)
7103                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKRouteHint), "LDKCVec_RouteHintZ Elements");
7104         else
7105                 _res_constr.data = NULL;
7106         int64_t* _res_vals = (*env)->GetLongArrayElements (env, _res, NULL);
7107         for (size_t l = 0; l < _res_constr.datalen; l++) {
7108                 int64_t arr_conv_11 = _res_vals[l];
7109                 LDKRouteHint arr_conv_11_conv;
7110                 arr_conv_11_conv.inner = (void*)(arr_conv_11 & (~1));
7111                 arr_conv_11_conv.is_owned = (arr_conv_11 & 1) || (arr_conv_11 == 0);
7112                 _res_constr.data[l] = arr_conv_11_conv;
7113         }
7114         (*env)->ReleaseLongArrayElements(env, _res, _res_vals, 0);
7115         CVec_RouteHintZ_free(_res_constr);
7116 }
7117
7118 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1RouteLightningErrorZ_1ok(JNIEnv *env, jclass clz, int64_t o) {
7119         LDKRoute o_conv;
7120         o_conv.inner = (void*)(o & (~1));
7121         o_conv.is_owned = (o & 1) || (o == 0);
7122         if (o_conv.inner != NULL)
7123                 o_conv = Route_clone(&o_conv);
7124         LDKCResult_RouteLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_RouteLightningErrorZ), "LDKCResult_RouteLightningErrorZ");
7125         *ret_conv = CResult_RouteLightningErrorZ_ok(o_conv);
7126         return (long)ret_conv;
7127 }
7128
7129 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1RouteLightningErrorZ_1err(JNIEnv *env, jclass clz, int64_t e) {
7130         LDKLightningError e_conv;
7131         e_conv.inner = (void*)(e & (~1));
7132         e_conv.is_owned = (e & 1) || (e == 0);
7133         // Warning: we may need a move here but can't clone!
7134         LDKCResult_RouteLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_RouteLightningErrorZ), "LDKCResult_RouteLightningErrorZ");
7135         *ret_conv = CResult_RouteLightningErrorZ_err(e_conv);
7136         return (long)ret_conv;
7137 }
7138
7139 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1RouteLightningErrorZ_1free(JNIEnv *env, jclass clz, int64_t _res) {
7140         LDKCResult_RouteLightningErrorZ _res_conv = *(LDKCResult_RouteLightningErrorZ*)_res;
7141         FREE((void*)_res);
7142         CResult_RouteLightningErrorZ_free(_res_conv);
7143 }
7144
7145 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1RoutingFeesDecodeErrorZ_1ok(JNIEnv *env, jclass clz, int64_t o) {
7146         LDKRoutingFees o_conv;
7147         o_conv.inner = (void*)(o & (~1));
7148         o_conv.is_owned = (o & 1) || (o == 0);
7149         if (o_conv.inner != NULL)
7150                 o_conv = RoutingFees_clone(&o_conv);
7151         LDKCResult_RoutingFeesDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_RoutingFeesDecodeErrorZ), "LDKCResult_RoutingFeesDecodeErrorZ");
7152         *ret_conv = CResult_RoutingFeesDecodeErrorZ_ok(o_conv);
7153         return (long)ret_conv;
7154 }
7155
7156 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1RoutingFeesDecodeErrorZ_1err(JNIEnv *env, jclass clz, int64_t e) {
7157         LDKDecodeError e_conv;
7158         e_conv.inner = (void*)(e & (~1));
7159         e_conv.is_owned = (e & 1) || (e == 0);
7160         // Warning: we may need a move here but can't clone!
7161         LDKCResult_RoutingFeesDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_RoutingFeesDecodeErrorZ), "LDKCResult_RoutingFeesDecodeErrorZ");
7162         *ret_conv = CResult_RoutingFeesDecodeErrorZ_err(e_conv);
7163         return (long)ret_conv;
7164 }
7165
7166 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1RoutingFeesDecodeErrorZ_1free(JNIEnv *env, jclass clz, int64_t _res) {
7167         LDKCResult_RoutingFeesDecodeErrorZ _res_conv = *(LDKCResult_RoutingFeesDecodeErrorZ*)_res;
7168         FREE((void*)_res);
7169         CResult_RoutingFeesDecodeErrorZ_free(_res_conv);
7170 }
7171
7172 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1NodeAnnouncementInfoDecodeErrorZ_1ok(JNIEnv *env, jclass clz, int64_t o) {
7173         LDKNodeAnnouncementInfo o_conv;
7174         o_conv.inner = (void*)(o & (~1));
7175         o_conv.is_owned = (o & 1) || (o == 0);
7176         // Warning: we may need a move here but can't clone!
7177         LDKCResult_NodeAnnouncementInfoDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NodeAnnouncementInfoDecodeErrorZ), "LDKCResult_NodeAnnouncementInfoDecodeErrorZ");
7178         *ret_conv = CResult_NodeAnnouncementInfoDecodeErrorZ_ok(o_conv);
7179         return (long)ret_conv;
7180 }
7181
7182 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1NodeAnnouncementInfoDecodeErrorZ_1err(JNIEnv *env, jclass clz, int64_t e) {
7183         LDKDecodeError e_conv;
7184         e_conv.inner = (void*)(e & (~1));
7185         e_conv.is_owned = (e & 1) || (e == 0);
7186         // Warning: we may need a move here but can't clone!
7187         LDKCResult_NodeAnnouncementInfoDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NodeAnnouncementInfoDecodeErrorZ), "LDKCResult_NodeAnnouncementInfoDecodeErrorZ");
7188         *ret_conv = CResult_NodeAnnouncementInfoDecodeErrorZ_err(e_conv);
7189         return (long)ret_conv;
7190 }
7191
7192 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1NodeAnnouncementInfoDecodeErrorZ_1free(JNIEnv *env, jclass clz, int64_t _res) {
7193         LDKCResult_NodeAnnouncementInfoDecodeErrorZ _res_conv = *(LDKCResult_NodeAnnouncementInfoDecodeErrorZ*)_res;
7194         FREE((void*)_res);
7195         CResult_NodeAnnouncementInfoDecodeErrorZ_free(_res_conv);
7196 }
7197
7198 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1NodeInfoDecodeErrorZ_1ok(JNIEnv *env, jclass clz, int64_t o) {
7199         LDKNodeInfo o_conv;
7200         o_conv.inner = (void*)(o & (~1));
7201         o_conv.is_owned = (o & 1) || (o == 0);
7202         // Warning: we may need a move here but can't clone!
7203         LDKCResult_NodeInfoDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NodeInfoDecodeErrorZ), "LDKCResult_NodeInfoDecodeErrorZ");
7204         *ret_conv = CResult_NodeInfoDecodeErrorZ_ok(o_conv);
7205         return (long)ret_conv;
7206 }
7207
7208 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1NodeInfoDecodeErrorZ_1err(JNIEnv *env, jclass clz, int64_t e) {
7209         LDKDecodeError e_conv;
7210         e_conv.inner = (void*)(e & (~1));
7211         e_conv.is_owned = (e & 1) || (e == 0);
7212         // Warning: we may need a move here but can't clone!
7213         LDKCResult_NodeInfoDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NodeInfoDecodeErrorZ), "LDKCResult_NodeInfoDecodeErrorZ");
7214         *ret_conv = CResult_NodeInfoDecodeErrorZ_err(e_conv);
7215         return (long)ret_conv;
7216 }
7217
7218 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1NodeInfoDecodeErrorZ_1free(JNIEnv *env, jclass clz, int64_t _res) {
7219         LDKCResult_NodeInfoDecodeErrorZ _res_conv = *(LDKCResult_NodeInfoDecodeErrorZ*)_res;
7220         FREE((void*)_res);
7221         CResult_NodeInfoDecodeErrorZ_free(_res_conv);
7222 }
7223
7224 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1NetworkGraphDecodeErrorZ_1ok(JNIEnv *env, jclass clz, int64_t o) {
7225         LDKNetworkGraph o_conv;
7226         o_conv.inner = (void*)(o & (~1));
7227         o_conv.is_owned = (o & 1) || (o == 0);
7228         // Warning: we may need a move here but can't clone!
7229         LDKCResult_NetworkGraphDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NetworkGraphDecodeErrorZ), "LDKCResult_NetworkGraphDecodeErrorZ");
7230         *ret_conv = CResult_NetworkGraphDecodeErrorZ_ok(o_conv);
7231         return (long)ret_conv;
7232 }
7233
7234 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1NetworkGraphDecodeErrorZ_1err(JNIEnv *env, jclass clz, int64_t e) {
7235         LDKDecodeError e_conv;
7236         e_conv.inner = (void*)(e & (~1));
7237         e_conv.is_owned = (e & 1) || (e == 0);
7238         // Warning: we may need a move here but can't clone!
7239         LDKCResult_NetworkGraphDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NetworkGraphDecodeErrorZ), "LDKCResult_NetworkGraphDecodeErrorZ");
7240         *ret_conv = CResult_NetworkGraphDecodeErrorZ_err(e_conv);
7241         return (long)ret_conv;
7242 }
7243
7244 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1NetworkGraphDecodeErrorZ_1free(JNIEnv *env, jclass clz, int64_t _res) {
7245         LDKCResult_NetworkGraphDecodeErrorZ _res_conv = *(LDKCResult_NetworkGraphDecodeErrorZ*)_res;
7246         FREE((void*)_res);
7247         CResult_NetworkGraphDecodeErrorZ_free(_res_conv);
7248 }
7249
7250 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Event_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
7251         LDKEvent this_ptr_conv = *(LDKEvent*)this_ptr;
7252         FREE((void*)this_ptr);
7253         Event_free(this_ptr_conv);
7254 }
7255
7256 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_Event_1clone(JNIEnv *env, jclass clz, int64_t orig) {
7257         LDKEvent* orig_conv = (LDKEvent*)orig;
7258         LDKEvent *ret_copy = MALLOC(sizeof(LDKEvent), "LDKEvent");
7259         *ret_copy = Event_clone(orig_conv);
7260         long ret_ref = (long)ret_copy;
7261         return ret_ref;
7262 }
7263
7264 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_Event_1write(JNIEnv *env, jclass clz, int64_t obj) {
7265         LDKEvent* obj_conv = (LDKEvent*)obj;
7266         LDKCVec_u8Z arg_var = Event_write(obj_conv);
7267         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
7268         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
7269         CVec_u8Z_free(arg_var);
7270         return arg_arr;
7271 }
7272
7273 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_MessageSendEvent_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
7274         LDKMessageSendEvent this_ptr_conv = *(LDKMessageSendEvent*)this_ptr;
7275         FREE((void*)this_ptr);
7276         MessageSendEvent_free(this_ptr_conv);
7277 }
7278
7279 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_MessageSendEvent_1clone(JNIEnv *env, jclass clz, int64_t orig) {
7280         LDKMessageSendEvent* orig_conv = (LDKMessageSendEvent*)orig;
7281         LDKMessageSendEvent *ret_copy = MALLOC(sizeof(LDKMessageSendEvent), "LDKMessageSendEvent");
7282         *ret_copy = MessageSendEvent_clone(orig_conv);
7283         long ret_ref = (long)ret_copy;
7284         return ret_ref;
7285 }
7286
7287 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_MessageSendEventsProvider_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
7288         LDKMessageSendEventsProvider this_ptr_conv = *(LDKMessageSendEventsProvider*)this_ptr;
7289         FREE((void*)this_ptr);
7290         MessageSendEventsProvider_free(this_ptr_conv);
7291 }
7292
7293 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_EventsProvider_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
7294         LDKEventsProvider this_ptr_conv = *(LDKEventsProvider*)this_ptr;
7295         FREE((void*)this_ptr);
7296         EventsProvider_free(this_ptr_conv);
7297 }
7298
7299 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_APIError_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
7300         LDKAPIError this_ptr_conv = *(LDKAPIError*)this_ptr;
7301         FREE((void*)this_ptr);
7302         APIError_free(this_ptr_conv);
7303 }
7304
7305 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_APIError_1clone(JNIEnv *env, jclass clz, int64_t orig) {
7306         LDKAPIError* orig_conv = (LDKAPIError*)orig;
7307         LDKAPIError *ret_copy = MALLOC(sizeof(LDKAPIError), "LDKAPIError");
7308         *ret_copy = APIError_clone(orig_conv);
7309         long ret_ref = (long)ret_copy;
7310         return ret_ref;
7311 }
7312
7313 JNIEXPORT jclass JNICALL Java_org_ldk_impl_bindings_Level_1clone(JNIEnv *env, jclass clz, int64_t orig) {
7314         LDKLevel* orig_conv = (LDKLevel*)orig;
7315         jclass ret_conv = LDKLevel_to_java(env, Level_clone(orig_conv));
7316         return ret_conv;
7317 }
7318
7319 JNIEXPORT jclass JNICALL Java_org_ldk_impl_bindings_Level_1max(JNIEnv *env, jclass clz) {
7320         jclass ret_conv = LDKLevel_to_java(env, Level_max());
7321         return ret_conv;
7322 }
7323
7324 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Logger_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
7325         LDKLogger this_ptr_conv = *(LDKLogger*)this_ptr;
7326         FREE((void*)this_ptr);
7327         Logger_free(this_ptr_conv);
7328 }
7329
7330 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeConfig_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
7331         LDKChannelHandshakeConfig this_ptr_conv;
7332         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7333         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7334         ChannelHandshakeConfig_free(this_ptr_conv);
7335 }
7336
7337 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeConfig_1clone(JNIEnv *env, jclass clz, int64_t orig) {
7338         LDKChannelHandshakeConfig orig_conv;
7339         orig_conv.inner = (void*)(orig & (~1));
7340         orig_conv.is_owned = false;
7341         LDKChannelHandshakeConfig ret_var = ChannelHandshakeConfig_clone(&orig_conv);
7342         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7343         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7344         long ret_ref = (long)ret_var.inner;
7345         if (ret_var.is_owned) {
7346                 ret_ref |= 1;
7347         }
7348         return ret_ref;
7349 }
7350
7351 JNIEXPORT int32_t JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeConfig_1get_1minimum_1depth(JNIEnv *env, jclass clz, int64_t this_ptr) {
7352         LDKChannelHandshakeConfig this_ptr_conv;
7353         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7354         this_ptr_conv.is_owned = false;
7355         int32_t ret_val = ChannelHandshakeConfig_get_minimum_depth(&this_ptr_conv);
7356         return ret_val;
7357 }
7358
7359 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeConfig_1set_1minimum_1depth(JNIEnv *env, jclass clz, int64_t this_ptr, int32_t val) {
7360         LDKChannelHandshakeConfig this_ptr_conv;
7361         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7362         this_ptr_conv.is_owned = false;
7363         ChannelHandshakeConfig_set_minimum_depth(&this_ptr_conv, val);
7364 }
7365
7366 JNIEXPORT int16_t JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeConfig_1get_1our_1to_1self_1delay(JNIEnv *env, jclass clz, int64_t this_ptr) {
7367         LDKChannelHandshakeConfig this_ptr_conv;
7368         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7369         this_ptr_conv.is_owned = false;
7370         int16_t ret_val = ChannelHandshakeConfig_get_our_to_self_delay(&this_ptr_conv);
7371         return ret_val;
7372 }
7373
7374 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeConfig_1set_1our_1to_1self_1delay(JNIEnv *env, jclass clz, int64_t this_ptr, int16_t val) {
7375         LDKChannelHandshakeConfig this_ptr_conv;
7376         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7377         this_ptr_conv.is_owned = false;
7378         ChannelHandshakeConfig_set_our_to_self_delay(&this_ptr_conv, val);
7379 }
7380
7381 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeConfig_1get_1our_1htlc_1minimum_1msat(JNIEnv *env, jclass clz, int64_t this_ptr) {
7382         LDKChannelHandshakeConfig this_ptr_conv;
7383         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7384         this_ptr_conv.is_owned = false;
7385         int64_t ret_val = ChannelHandshakeConfig_get_our_htlc_minimum_msat(&this_ptr_conv);
7386         return ret_val;
7387 }
7388
7389 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeConfig_1set_1our_1htlc_1minimum_1msat(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
7390         LDKChannelHandshakeConfig this_ptr_conv;
7391         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7392         this_ptr_conv.is_owned = false;
7393         ChannelHandshakeConfig_set_our_htlc_minimum_msat(&this_ptr_conv, val);
7394 }
7395
7396 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeConfig_1new(JNIEnv *env, jclass clz, int32_t minimum_depth_arg, int16_t our_to_self_delay_arg, int64_t our_htlc_minimum_msat_arg) {
7397         LDKChannelHandshakeConfig ret_var = ChannelHandshakeConfig_new(minimum_depth_arg, our_to_self_delay_arg, our_htlc_minimum_msat_arg);
7398         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7399         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7400         long ret_ref = (long)ret_var.inner;
7401         if (ret_var.is_owned) {
7402                 ret_ref |= 1;
7403         }
7404         return ret_ref;
7405 }
7406
7407 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeConfig_1default(JNIEnv *env, jclass clz) {
7408         LDKChannelHandshakeConfig ret_var = ChannelHandshakeConfig_default();
7409         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7410         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7411         long ret_ref = (long)ret_var.inner;
7412         if (ret_var.is_owned) {
7413                 ret_ref |= 1;
7414         }
7415         return ret_ref;
7416 }
7417
7418 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
7419         LDKChannelHandshakeLimits this_ptr_conv;
7420         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7421         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7422         ChannelHandshakeLimits_free(this_ptr_conv);
7423 }
7424
7425 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1clone(JNIEnv *env, jclass clz, int64_t orig) {
7426         LDKChannelHandshakeLimits orig_conv;
7427         orig_conv.inner = (void*)(orig & (~1));
7428         orig_conv.is_owned = false;
7429         LDKChannelHandshakeLimits ret_var = ChannelHandshakeLimits_clone(&orig_conv);
7430         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7431         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7432         long ret_ref = (long)ret_var.inner;
7433         if (ret_var.is_owned) {
7434                 ret_ref |= 1;
7435         }
7436         return ret_ref;
7437 }
7438
7439 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1get_1min_1funding_1satoshis(JNIEnv *env, jclass clz, int64_t this_ptr) {
7440         LDKChannelHandshakeLimits this_ptr_conv;
7441         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7442         this_ptr_conv.is_owned = false;
7443         int64_t ret_val = ChannelHandshakeLimits_get_min_funding_satoshis(&this_ptr_conv);
7444         return ret_val;
7445 }
7446
7447 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1set_1min_1funding_1satoshis(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
7448         LDKChannelHandshakeLimits this_ptr_conv;
7449         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7450         this_ptr_conv.is_owned = false;
7451         ChannelHandshakeLimits_set_min_funding_satoshis(&this_ptr_conv, val);
7452 }
7453
7454 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1get_1max_1htlc_1minimum_1msat(JNIEnv *env, jclass clz, int64_t this_ptr) {
7455         LDKChannelHandshakeLimits this_ptr_conv;
7456         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7457         this_ptr_conv.is_owned = false;
7458         int64_t ret_val = ChannelHandshakeLimits_get_max_htlc_minimum_msat(&this_ptr_conv);
7459         return ret_val;
7460 }
7461
7462 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1set_1max_1htlc_1minimum_1msat(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
7463         LDKChannelHandshakeLimits this_ptr_conv;
7464         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7465         this_ptr_conv.is_owned = false;
7466         ChannelHandshakeLimits_set_max_htlc_minimum_msat(&this_ptr_conv, val);
7467 }
7468
7469 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1get_1min_1max_1htlc_1value_1in_1flight_1msat(JNIEnv *env, jclass clz, int64_t this_ptr) {
7470         LDKChannelHandshakeLimits this_ptr_conv;
7471         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7472         this_ptr_conv.is_owned = false;
7473         int64_t ret_val = ChannelHandshakeLimits_get_min_max_htlc_value_in_flight_msat(&this_ptr_conv);
7474         return ret_val;
7475 }
7476
7477 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1set_1min_1max_1htlc_1value_1in_1flight_1msat(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
7478         LDKChannelHandshakeLimits this_ptr_conv;
7479         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7480         this_ptr_conv.is_owned = false;
7481         ChannelHandshakeLimits_set_min_max_htlc_value_in_flight_msat(&this_ptr_conv, val);
7482 }
7483
7484 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1get_1max_1channel_1reserve_1satoshis(JNIEnv *env, jclass clz, int64_t this_ptr) {
7485         LDKChannelHandshakeLimits this_ptr_conv;
7486         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7487         this_ptr_conv.is_owned = false;
7488         int64_t ret_val = ChannelHandshakeLimits_get_max_channel_reserve_satoshis(&this_ptr_conv);
7489         return ret_val;
7490 }
7491
7492 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1set_1max_1channel_1reserve_1satoshis(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
7493         LDKChannelHandshakeLimits this_ptr_conv;
7494         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7495         this_ptr_conv.is_owned = false;
7496         ChannelHandshakeLimits_set_max_channel_reserve_satoshis(&this_ptr_conv, val);
7497 }
7498
7499 JNIEXPORT int16_t JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1get_1min_1max_1accepted_1htlcs(JNIEnv *env, jclass clz, int64_t this_ptr) {
7500         LDKChannelHandshakeLimits this_ptr_conv;
7501         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7502         this_ptr_conv.is_owned = false;
7503         int16_t ret_val = ChannelHandshakeLimits_get_min_max_accepted_htlcs(&this_ptr_conv);
7504         return ret_val;
7505 }
7506
7507 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1set_1min_1max_1accepted_1htlcs(JNIEnv *env, jclass clz, int64_t this_ptr, int16_t val) {
7508         LDKChannelHandshakeLimits this_ptr_conv;
7509         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7510         this_ptr_conv.is_owned = false;
7511         ChannelHandshakeLimits_set_min_max_accepted_htlcs(&this_ptr_conv, val);
7512 }
7513
7514 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1get_1min_1dust_1limit_1satoshis(JNIEnv *env, jclass clz, int64_t this_ptr) {
7515         LDKChannelHandshakeLimits this_ptr_conv;
7516         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7517         this_ptr_conv.is_owned = false;
7518         int64_t ret_val = ChannelHandshakeLimits_get_min_dust_limit_satoshis(&this_ptr_conv);
7519         return ret_val;
7520 }
7521
7522 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1set_1min_1dust_1limit_1satoshis(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
7523         LDKChannelHandshakeLimits this_ptr_conv;
7524         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7525         this_ptr_conv.is_owned = false;
7526         ChannelHandshakeLimits_set_min_dust_limit_satoshis(&this_ptr_conv, val);
7527 }
7528
7529 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1get_1max_1dust_1limit_1satoshis(JNIEnv *env, jclass clz, int64_t this_ptr) {
7530         LDKChannelHandshakeLimits this_ptr_conv;
7531         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7532         this_ptr_conv.is_owned = false;
7533         int64_t ret_val = ChannelHandshakeLimits_get_max_dust_limit_satoshis(&this_ptr_conv);
7534         return ret_val;
7535 }
7536
7537 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1set_1max_1dust_1limit_1satoshis(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
7538         LDKChannelHandshakeLimits this_ptr_conv;
7539         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7540         this_ptr_conv.is_owned = false;
7541         ChannelHandshakeLimits_set_max_dust_limit_satoshis(&this_ptr_conv, val);
7542 }
7543
7544 JNIEXPORT int32_t JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1get_1max_1minimum_1depth(JNIEnv *env, jclass clz, int64_t this_ptr) {
7545         LDKChannelHandshakeLimits this_ptr_conv;
7546         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7547         this_ptr_conv.is_owned = false;
7548         int32_t ret_val = ChannelHandshakeLimits_get_max_minimum_depth(&this_ptr_conv);
7549         return ret_val;
7550 }
7551
7552 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1set_1max_1minimum_1depth(JNIEnv *env, jclass clz, int64_t this_ptr, int32_t val) {
7553         LDKChannelHandshakeLimits this_ptr_conv;
7554         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7555         this_ptr_conv.is_owned = false;
7556         ChannelHandshakeLimits_set_max_minimum_depth(&this_ptr_conv, val);
7557 }
7558
7559 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1get_1force_1announced_1channel_1preference(JNIEnv *env, jclass clz, int64_t this_ptr) {
7560         LDKChannelHandshakeLimits this_ptr_conv;
7561         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7562         this_ptr_conv.is_owned = false;
7563         jboolean ret_val = ChannelHandshakeLimits_get_force_announced_channel_preference(&this_ptr_conv);
7564         return ret_val;
7565 }
7566
7567 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1set_1force_1announced_1channel_1preference(JNIEnv *env, jclass clz, int64_t this_ptr, jboolean val) {
7568         LDKChannelHandshakeLimits this_ptr_conv;
7569         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7570         this_ptr_conv.is_owned = false;
7571         ChannelHandshakeLimits_set_force_announced_channel_preference(&this_ptr_conv, val);
7572 }
7573
7574 JNIEXPORT int16_t JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1get_1their_1to_1self_1delay(JNIEnv *env, jclass clz, int64_t this_ptr) {
7575         LDKChannelHandshakeLimits this_ptr_conv;
7576         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7577         this_ptr_conv.is_owned = false;
7578         int16_t ret_val = ChannelHandshakeLimits_get_their_to_self_delay(&this_ptr_conv);
7579         return ret_val;
7580 }
7581
7582 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1set_1their_1to_1self_1delay(JNIEnv *env, jclass clz, int64_t this_ptr, int16_t val) {
7583         LDKChannelHandshakeLimits this_ptr_conv;
7584         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7585         this_ptr_conv.is_owned = false;
7586         ChannelHandshakeLimits_set_their_to_self_delay(&this_ptr_conv, val);
7587 }
7588
7589 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1new(JNIEnv *env, jclass clz, 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) {
7590         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);
7591         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7592         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7593         long ret_ref = (long)ret_var.inner;
7594         if (ret_var.is_owned) {
7595                 ret_ref |= 1;
7596         }
7597         return ret_ref;
7598 }
7599
7600 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1default(JNIEnv *env, jclass clz) {
7601         LDKChannelHandshakeLimits ret_var = ChannelHandshakeLimits_default();
7602         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7603         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7604         long ret_ref = (long)ret_var.inner;
7605         if (ret_var.is_owned) {
7606                 ret_ref |= 1;
7607         }
7608         return ret_ref;
7609 }
7610
7611 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelConfig_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
7612         LDKChannelConfig this_ptr_conv;
7613         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7614         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7615         ChannelConfig_free(this_ptr_conv);
7616 }
7617
7618 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelConfig_1clone(JNIEnv *env, jclass clz, int64_t orig) {
7619         LDKChannelConfig orig_conv;
7620         orig_conv.inner = (void*)(orig & (~1));
7621         orig_conv.is_owned = false;
7622         LDKChannelConfig ret_var = ChannelConfig_clone(&orig_conv);
7623         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7624         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7625         long ret_ref = (long)ret_var.inner;
7626         if (ret_var.is_owned) {
7627                 ret_ref |= 1;
7628         }
7629         return ret_ref;
7630 }
7631
7632 JNIEXPORT int32_t JNICALL Java_org_ldk_impl_bindings_ChannelConfig_1get_1fee_1proportional_1millionths(JNIEnv *env, jclass clz, int64_t this_ptr) {
7633         LDKChannelConfig this_ptr_conv;
7634         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7635         this_ptr_conv.is_owned = false;
7636         int32_t ret_val = ChannelConfig_get_fee_proportional_millionths(&this_ptr_conv);
7637         return ret_val;
7638 }
7639
7640 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelConfig_1set_1fee_1proportional_1millionths(JNIEnv *env, jclass clz, int64_t this_ptr, int32_t val) {
7641         LDKChannelConfig this_ptr_conv;
7642         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7643         this_ptr_conv.is_owned = false;
7644         ChannelConfig_set_fee_proportional_millionths(&this_ptr_conv, val);
7645 }
7646
7647 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_ChannelConfig_1get_1announced_1channel(JNIEnv *env, jclass clz, int64_t this_ptr) {
7648         LDKChannelConfig this_ptr_conv;
7649         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7650         this_ptr_conv.is_owned = false;
7651         jboolean ret_val = ChannelConfig_get_announced_channel(&this_ptr_conv);
7652         return ret_val;
7653 }
7654
7655 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelConfig_1set_1announced_1channel(JNIEnv *env, jclass clz, int64_t this_ptr, jboolean val) {
7656         LDKChannelConfig this_ptr_conv;
7657         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7658         this_ptr_conv.is_owned = false;
7659         ChannelConfig_set_announced_channel(&this_ptr_conv, val);
7660 }
7661
7662 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_ChannelConfig_1get_1commit_1upfront_1shutdown_1pubkey(JNIEnv *env, jclass clz, int64_t this_ptr) {
7663         LDKChannelConfig this_ptr_conv;
7664         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7665         this_ptr_conv.is_owned = false;
7666         jboolean ret_val = ChannelConfig_get_commit_upfront_shutdown_pubkey(&this_ptr_conv);
7667         return ret_val;
7668 }
7669
7670 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelConfig_1set_1commit_1upfront_1shutdown_1pubkey(JNIEnv *env, jclass clz, int64_t this_ptr, jboolean val) {
7671         LDKChannelConfig this_ptr_conv;
7672         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7673         this_ptr_conv.is_owned = false;
7674         ChannelConfig_set_commit_upfront_shutdown_pubkey(&this_ptr_conv, val);
7675 }
7676
7677 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelConfig_1new(JNIEnv *env, jclass clz, int32_t fee_proportional_millionths_arg, jboolean announced_channel_arg, jboolean commit_upfront_shutdown_pubkey_arg) {
7678         LDKChannelConfig ret_var = ChannelConfig_new(fee_proportional_millionths_arg, announced_channel_arg, commit_upfront_shutdown_pubkey_arg);
7679         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7680         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7681         long ret_ref = (long)ret_var.inner;
7682         if (ret_var.is_owned) {
7683                 ret_ref |= 1;
7684         }
7685         return ret_ref;
7686 }
7687
7688 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelConfig_1default(JNIEnv *env, jclass clz) {
7689         LDKChannelConfig ret_var = ChannelConfig_default();
7690         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7691         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7692         long ret_ref = (long)ret_var.inner;
7693         if (ret_var.is_owned) {
7694                 ret_ref |= 1;
7695         }
7696         return ret_ref;
7697 }
7698
7699 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_ChannelConfig_1write(JNIEnv *env, jclass clz, int64_t obj) {
7700         LDKChannelConfig obj_conv;
7701         obj_conv.inner = (void*)(obj & (~1));
7702         obj_conv.is_owned = false;
7703         LDKCVec_u8Z arg_var = ChannelConfig_write(&obj_conv);
7704         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
7705         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
7706         CVec_u8Z_free(arg_var);
7707         return arg_arr;
7708 }
7709
7710 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelConfig_1read(JNIEnv *env, jclass clz, int8_tArray ser) {
7711         LDKu8slice ser_ref;
7712         ser_ref.datalen = (*env)->GetArrayLength(env, ser);
7713         ser_ref.data = (*env)->GetByteArrayElements (env, ser, NULL);
7714         LDKChannelConfig ret_var = ChannelConfig_read(ser_ref);
7715         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7716         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7717         long ret_ref = (long)ret_var.inner;
7718         if (ret_var.is_owned) {
7719                 ret_ref |= 1;
7720         }
7721         (*env)->ReleaseByteArrayElements(env, ser, (int8_t*)ser_ref.data, 0);
7722         return ret_ref;
7723 }
7724
7725 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UserConfig_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
7726         LDKUserConfig this_ptr_conv;
7727         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7728         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7729         UserConfig_free(this_ptr_conv);
7730 }
7731
7732 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_UserConfig_1clone(JNIEnv *env, jclass clz, int64_t orig) {
7733         LDKUserConfig orig_conv;
7734         orig_conv.inner = (void*)(orig & (~1));
7735         orig_conv.is_owned = false;
7736         LDKUserConfig ret_var = UserConfig_clone(&orig_conv);
7737         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7738         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7739         long ret_ref = (long)ret_var.inner;
7740         if (ret_var.is_owned) {
7741                 ret_ref |= 1;
7742         }
7743         return ret_ref;
7744 }
7745
7746 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_UserConfig_1get_1own_1channel_1config(JNIEnv *env, jclass clz, int64_t this_ptr) {
7747         LDKUserConfig this_ptr_conv;
7748         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7749         this_ptr_conv.is_owned = false;
7750         LDKChannelHandshakeConfig ret_var = UserConfig_get_own_channel_config(&this_ptr_conv);
7751         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7752         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7753         long ret_ref = (long)ret_var.inner;
7754         if (ret_var.is_owned) {
7755                 ret_ref |= 1;
7756         }
7757         return ret_ref;
7758 }
7759
7760 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UserConfig_1set_1own_1channel_1config(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
7761         LDKUserConfig this_ptr_conv;
7762         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7763         this_ptr_conv.is_owned = false;
7764         LDKChannelHandshakeConfig val_conv;
7765         val_conv.inner = (void*)(val & (~1));
7766         val_conv.is_owned = (val & 1) || (val == 0);
7767         if (val_conv.inner != NULL)
7768                 val_conv = ChannelHandshakeConfig_clone(&val_conv);
7769         UserConfig_set_own_channel_config(&this_ptr_conv, val_conv);
7770 }
7771
7772 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_UserConfig_1get_1peer_1channel_1config_1limits(JNIEnv *env, jclass clz, int64_t this_ptr) {
7773         LDKUserConfig this_ptr_conv;
7774         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7775         this_ptr_conv.is_owned = false;
7776         LDKChannelHandshakeLimits ret_var = UserConfig_get_peer_channel_config_limits(&this_ptr_conv);
7777         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7778         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7779         long ret_ref = (long)ret_var.inner;
7780         if (ret_var.is_owned) {
7781                 ret_ref |= 1;
7782         }
7783         return ret_ref;
7784 }
7785
7786 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UserConfig_1set_1peer_1channel_1config_1limits(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
7787         LDKUserConfig this_ptr_conv;
7788         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7789         this_ptr_conv.is_owned = false;
7790         LDKChannelHandshakeLimits val_conv;
7791         val_conv.inner = (void*)(val & (~1));
7792         val_conv.is_owned = (val & 1) || (val == 0);
7793         if (val_conv.inner != NULL)
7794                 val_conv = ChannelHandshakeLimits_clone(&val_conv);
7795         UserConfig_set_peer_channel_config_limits(&this_ptr_conv, val_conv);
7796 }
7797
7798 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_UserConfig_1get_1channel_1options(JNIEnv *env, jclass clz, int64_t this_ptr) {
7799         LDKUserConfig this_ptr_conv;
7800         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7801         this_ptr_conv.is_owned = false;
7802         LDKChannelConfig ret_var = UserConfig_get_channel_options(&this_ptr_conv);
7803         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7804         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7805         long ret_ref = (long)ret_var.inner;
7806         if (ret_var.is_owned) {
7807                 ret_ref |= 1;
7808         }
7809         return ret_ref;
7810 }
7811
7812 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UserConfig_1set_1channel_1options(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
7813         LDKUserConfig this_ptr_conv;
7814         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7815         this_ptr_conv.is_owned = false;
7816         LDKChannelConfig val_conv;
7817         val_conv.inner = (void*)(val & (~1));
7818         val_conv.is_owned = (val & 1) || (val == 0);
7819         if (val_conv.inner != NULL)
7820                 val_conv = ChannelConfig_clone(&val_conv);
7821         UserConfig_set_channel_options(&this_ptr_conv, val_conv);
7822 }
7823
7824 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_UserConfig_1new(JNIEnv *env, jclass clz, int64_t own_channel_config_arg, int64_t peer_channel_config_limits_arg, int64_t channel_options_arg) {
7825         LDKChannelHandshakeConfig own_channel_config_arg_conv;
7826         own_channel_config_arg_conv.inner = (void*)(own_channel_config_arg & (~1));
7827         own_channel_config_arg_conv.is_owned = (own_channel_config_arg & 1) || (own_channel_config_arg == 0);
7828         if (own_channel_config_arg_conv.inner != NULL)
7829                 own_channel_config_arg_conv = ChannelHandshakeConfig_clone(&own_channel_config_arg_conv);
7830         LDKChannelHandshakeLimits peer_channel_config_limits_arg_conv;
7831         peer_channel_config_limits_arg_conv.inner = (void*)(peer_channel_config_limits_arg & (~1));
7832         peer_channel_config_limits_arg_conv.is_owned = (peer_channel_config_limits_arg & 1) || (peer_channel_config_limits_arg == 0);
7833         if (peer_channel_config_limits_arg_conv.inner != NULL)
7834                 peer_channel_config_limits_arg_conv = ChannelHandshakeLimits_clone(&peer_channel_config_limits_arg_conv);
7835         LDKChannelConfig channel_options_arg_conv;
7836         channel_options_arg_conv.inner = (void*)(channel_options_arg & (~1));
7837         channel_options_arg_conv.is_owned = (channel_options_arg & 1) || (channel_options_arg == 0);
7838         if (channel_options_arg_conv.inner != NULL)
7839                 channel_options_arg_conv = ChannelConfig_clone(&channel_options_arg_conv);
7840         LDKUserConfig ret_var = UserConfig_new(own_channel_config_arg_conv, peer_channel_config_limits_arg_conv, channel_options_arg_conv);
7841         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7842         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7843         long ret_ref = (long)ret_var.inner;
7844         if (ret_var.is_owned) {
7845                 ret_ref |= 1;
7846         }
7847         return ret_ref;
7848 }
7849
7850 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_UserConfig_1default(JNIEnv *env, jclass clz) {
7851         LDKUserConfig ret_var = UserConfig_default();
7852         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7853         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7854         long ret_ref = (long)ret_var.inner;
7855         if (ret_var.is_owned) {
7856                 ret_ref |= 1;
7857         }
7858         return ret_ref;
7859 }
7860
7861 JNIEXPORT jclass JNICALL Java_org_ldk_impl_bindings_AccessError_1clone(JNIEnv *env, jclass clz, int64_t orig) {
7862         LDKAccessError* orig_conv = (LDKAccessError*)orig;
7863         jclass ret_conv = LDKAccessError_to_java(env, AccessError_clone(orig_conv));
7864         return ret_conv;
7865 }
7866
7867 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Access_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
7868         LDKAccess this_ptr_conv = *(LDKAccess*)this_ptr;
7869         FREE((void*)this_ptr);
7870         Access_free(this_ptr_conv);
7871 }
7872
7873 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Watch_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
7874         LDKWatch this_ptr_conv = *(LDKWatch*)this_ptr;
7875         FREE((void*)this_ptr);
7876         Watch_free(this_ptr_conv);
7877 }
7878
7879 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Filter_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
7880         LDKFilter this_ptr_conv = *(LDKFilter*)this_ptr;
7881         FREE((void*)this_ptr);
7882         Filter_free(this_ptr_conv);
7883 }
7884
7885 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_BroadcasterInterface_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
7886         LDKBroadcasterInterface this_ptr_conv = *(LDKBroadcasterInterface*)this_ptr;
7887         FREE((void*)this_ptr);
7888         BroadcasterInterface_free(this_ptr_conv);
7889 }
7890
7891 JNIEXPORT jclass JNICALL Java_org_ldk_impl_bindings_ConfirmationTarget_1clone(JNIEnv *env, jclass clz, int64_t orig) {
7892         LDKConfirmationTarget* orig_conv = (LDKConfirmationTarget*)orig;
7893         jclass ret_conv = LDKConfirmationTarget_to_java(env, ConfirmationTarget_clone(orig_conv));
7894         return ret_conv;
7895 }
7896
7897 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_FeeEstimator_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
7898         LDKFeeEstimator this_ptr_conv = *(LDKFeeEstimator*)this_ptr;
7899         FREE((void*)this_ptr);
7900         FeeEstimator_free(this_ptr_conv);
7901 }
7902
7903 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChainMonitor_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
7904         LDKChainMonitor this_ptr_conv;
7905         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7906         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7907         ChainMonitor_free(this_ptr_conv);
7908 }
7909
7910 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChainMonitor_1block_1connected(JNIEnv *env, jclass clz, int64_t this_arg, int8_tArray header, int64_tArray txdata, int32_t height) {
7911         LDKChainMonitor this_arg_conv;
7912         this_arg_conv.inner = (void*)(this_arg & (~1));
7913         this_arg_conv.is_owned = false;
7914         unsigned char header_arr[80];
7915         CHECK((*env)->GetArrayLength(env, header) == 80);
7916         (*env)->GetByteArrayRegion(env, header, 0, 80, header_arr);
7917         unsigned char (*header_ref)[80] = &header_arr;
7918         LDKCVec_C2Tuple_usizeTransactionZZ txdata_constr;
7919         txdata_constr.datalen = (*env)->GetArrayLength(env, txdata);
7920         if (txdata_constr.datalen > 0)
7921                 txdata_constr.data = MALLOC(txdata_constr.datalen * sizeof(LDKC2Tuple_usizeTransactionZ), "LDKCVec_C2Tuple_usizeTransactionZZ Elements");
7922         else
7923                 txdata_constr.data = NULL;
7924         int64_t* txdata_vals = (*env)->GetLongArrayElements (env, txdata, NULL);
7925         for (size_t y = 0; y < txdata_constr.datalen; y++) {
7926                 int64_t arr_conv_24 = txdata_vals[y];
7927                 LDKC2Tuple_usizeTransactionZ arr_conv_24_conv = *(LDKC2Tuple_usizeTransactionZ*)arr_conv_24;
7928                 FREE((void*)arr_conv_24);
7929                 txdata_constr.data[y] = arr_conv_24_conv;
7930         }
7931         (*env)->ReleaseLongArrayElements(env, txdata, txdata_vals, 0);
7932         ChainMonitor_block_connected(&this_arg_conv, header_ref, txdata_constr, height);
7933 }
7934
7935 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChainMonitor_1block_1disconnected(JNIEnv *env, jclass clz, int64_t this_arg, int8_tArray header, int32_t disconnected_height) {
7936         LDKChainMonitor this_arg_conv;
7937         this_arg_conv.inner = (void*)(this_arg & (~1));
7938         this_arg_conv.is_owned = false;
7939         unsigned char header_arr[80];
7940         CHECK((*env)->GetArrayLength(env, header) == 80);
7941         (*env)->GetByteArrayRegion(env, header, 0, 80, header_arr);
7942         unsigned char (*header_ref)[80] = &header_arr;
7943         ChainMonitor_block_disconnected(&this_arg_conv, header_ref, disconnected_height);
7944 }
7945
7946 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChainMonitor_1new(JNIEnv *env, jclass clz, int64_t chain_source, int64_t broadcaster, int64_t logger, int64_t feeest, int64_t persister) {
7947         LDKFilter* chain_source_conv = (LDKFilter*)chain_source;
7948         LDKBroadcasterInterface broadcaster_conv = *(LDKBroadcasterInterface*)broadcaster;
7949         if (broadcaster_conv.free == LDKBroadcasterInterface_JCalls_free) {
7950                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
7951                 LDKBroadcasterInterface_JCalls_clone(broadcaster_conv.this_arg);
7952         }
7953         LDKLogger logger_conv = *(LDKLogger*)logger;
7954         if (logger_conv.free == LDKLogger_JCalls_free) {
7955                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
7956                 LDKLogger_JCalls_clone(logger_conv.this_arg);
7957         }
7958         LDKFeeEstimator feeest_conv = *(LDKFeeEstimator*)feeest;
7959         if (feeest_conv.free == LDKFeeEstimator_JCalls_free) {
7960                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
7961                 LDKFeeEstimator_JCalls_clone(feeest_conv.this_arg);
7962         }
7963         LDKPersist persister_conv = *(LDKPersist*)persister;
7964         if (persister_conv.free == LDKPersist_JCalls_free) {
7965                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
7966                 LDKPersist_JCalls_clone(persister_conv.this_arg);
7967         }
7968         LDKChainMonitor ret_var = ChainMonitor_new(chain_source_conv, broadcaster_conv, logger_conv, feeest_conv, persister_conv);
7969         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7970         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7971         long ret_ref = (long)ret_var.inner;
7972         if (ret_var.is_owned) {
7973                 ret_ref |= 1;
7974         }
7975         return ret_ref;
7976 }
7977
7978 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChainMonitor_1as_1Watch(JNIEnv *env, jclass clz, int64_t this_arg) {
7979         LDKChainMonitor this_arg_conv;
7980         this_arg_conv.inner = (void*)(this_arg & (~1));
7981         this_arg_conv.is_owned = false;
7982         LDKWatch* ret = MALLOC(sizeof(LDKWatch), "LDKWatch");
7983         *ret = ChainMonitor_as_Watch(&this_arg_conv);
7984         return (long)ret;
7985 }
7986
7987 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChainMonitor_1as_1EventsProvider(JNIEnv *env, jclass clz, int64_t this_arg) {
7988         LDKChainMonitor this_arg_conv;
7989         this_arg_conv.inner = (void*)(this_arg & (~1));
7990         this_arg_conv.is_owned = false;
7991         LDKEventsProvider* ret = MALLOC(sizeof(LDKEventsProvider), "LDKEventsProvider");
7992         *ret = ChainMonitor_as_EventsProvider(&this_arg_conv);
7993         return (long)ret;
7994 }
7995
7996 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelMonitorUpdate_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
7997         LDKChannelMonitorUpdate this_ptr_conv;
7998         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7999         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8000         ChannelMonitorUpdate_free(this_ptr_conv);
8001 }
8002
8003 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelMonitorUpdate_1clone(JNIEnv *env, jclass clz, int64_t orig) {
8004         LDKChannelMonitorUpdate orig_conv;
8005         orig_conv.inner = (void*)(orig & (~1));
8006         orig_conv.is_owned = false;
8007         LDKChannelMonitorUpdate ret_var = ChannelMonitorUpdate_clone(&orig_conv);
8008         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8009         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8010         long ret_ref = (long)ret_var.inner;
8011         if (ret_var.is_owned) {
8012                 ret_ref |= 1;
8013         }
8014         return ret_ref;
8015 }
8016
8017 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelMonitorUpdate_1get_1update_1id(JNIEnv *env, jclass clz, int64_t this_ptr) {
8018         LDKChannelMonitorUpdate this_ptr_conv;
8019         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8020         this_ptr_conv.is_owned = false;
8021         int64_t ret_val = ChannelMonitorUpdate_get_update_id(&this_ptr_conv);
8022         return ret_val;
8023 }
8024
8025 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelMonitorUpdate_1set_1update_1id(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
8026         LDKChannelMonitorUpdate this_ptr_conv;
8027         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8028         this_ptr_conv.is_owned = false;
8029         ChannelMonitorUpdate_set_update_id(&this_ptr_conv, val);
8030 }
8031
8032 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_ChannelMonitorUpdate_1write(JNIEnv *env, jclass clz, int64_t obj) {
8033         LDKChannelMonitorUpdate obj_conv;
8034         obj_conv.inner = (void*)(obj & (~1));
8035         obj_conv.is_owned = false;
8036         LDKCVec_u8Z arg_var = ChannelMonitorUpdate_write(&obj_conv);
8037         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
8038         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
8039         CVec_u8Z_free(arg_var);
8040         return arg_arr;
8041 }
8042
8043 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelMonitorUpdate_1read(JNIEnv *env, jclass clz, int8_tArray ser) {
8044         LDKu8slice ser_ref;
8045         ser_ref.datalen = (*env)->GetArrayLength(env, ser);
8046         ser_ref.data = (*env)->GetByteArrayElements (env, ser, NULL);
8047         LDKCResult_ChannelMonitorUpdateDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ChannelMonitorUpdateDecodeErrorZ), "LDKCResult_ChannelMonitorUpdateDecodeErrorZ");
8048         *ret_conv = ChannelMonitorUpdate_read(ser_ref);
8049         (*env)->ReleaseByteArrayElements(env, ser, (int8_t*)ser_ref.data, 0);
8050         return (long)ret_conv;
8051 }
8052
8053 JNIEXPORT jclass JNICALL Java_org_ldk_impl_bindings_ChannelMonitorUpdateErr_1clone(JNIEnv *env, jclass clz, int64_t orig) {
8054         LDKChannelMonitorUpdateErr* orig_conv = (LDKChannelMonitorUpdateErr*)orig;
8055         jclass ret_conv = LDKChannelMonitorUpdateErr_to_java(env, ChannelMonitorUpdateErr_clone(orig_conv));
8056         return ret_conv;
8057 }
8058
8059 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_MonitorUpdateError_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
8060         LDKMonitorUpdateError this_ptr_conv;
8061         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8062         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8063         MonitorUpdateError_free(this_ptr_conv);
8064 }
8065
8066 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_MonitorEvent_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
8067         LDKMonitorEvent this_ptr_conv;
8068         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8069         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8070         MonitorEvent_free(this_ptr_conv);
8071 }
8072
8073 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_MonitorEvent_1clone(JNIEnv *env, jclass clz, int64_t orig) {
8074         LDKMonitorEvent orig_conv;
8075         orig_conv.inner = (void*)(orig & (~1));
8076         orig_conv.is_owned = false;
8077         LDKMonitorEvent ret_var = MonitorEvent_clone(&orig_conv);
8078         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8079         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8080         long ret_ref = (long)ret_var.inner;
8081         if (ret_var.is_owned) {
8082                 ret_ref |= 1;
8083         }
8084         return ret_ref;
8085 }
8086
8087 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_HTLCUpdate_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
8088         LDKHTLCUpdate this_ptr_conv;
8089         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8090         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8091         HTLCUpdate_free(this_ptr_conv);
8092 }
8093
8094 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_HTLCUpdate_1clone(JNIEnv *env, jclass clz, int64_t orig) {
8095         LDKHTLCUpdate orig_conv;
8096         orig_conv.inner = (void*)(orig & (~1));
8097         orig_conv.is_owned = false;
8098         LDKHTLCUpdate ret_var = HTLCUpdate_clone(&orig_conv);
8099         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8100         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8101         long ret_ref = (long)ret_var.inner;
8102         if (ret_var.is_owned) {
8103                 ret_ref |= 1;
8104         }
8105         return ret_ref;
8106 }
8107
8108 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_HTLCUpdate_1write(JNIEnv *env, jclass clz, int64_t obj) {
8109         LDKHTLCUpdate obj_conv;
8110         obj_conv.inner = (void*)(obj & (~1));
8111         obj_conv.is_owned = false;
8112         LDKCVec_u8Z arg_var = HTLCUpdate_write(&obj_conv);
8113         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
8114         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
8115         CVec_u8Z_free(arg_var);
8116         return arg_arr;
8117 }
8118
8119 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_HTLCUpdate_1read(JNIEnv *env, jclass clz, int8_tArray ser) {
8120         LDKu8slice ser_ref;
8121         ser_ref.datalen = (*env)->GetArrayLength(env, ser);
8122         ser_ref.data = (*env)->GetByteArrayElements (env, ser, NULL);
8123         LDKHTLCUpdate ret_var = HTLCUpdate_read(ser_ref);
8124         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8125         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8126         long ret_ref = (long)ret_var.inner;
8127         if (ret_var.is_owned) {
8128                 ret_ref |= 1;
8129         }
8130         (*env)->ReleaseByteArrayElements(env, ser, (int8_t*)ser_ref.data, 0);
8131         return ret_ref;
8132 }
8133
8134 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelMonitor_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
8135         LDKChannelMonitor this_ptr_conv;
8136         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8137         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8138         ChannelMonitor_free(this_ptr_conv);
8139 }
8140
8141 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_ChannelMonitor_1write(JNIEnv *env, jclass clz, int64_t obj) {
8142         LDKChannelMonitor obj_conv;
8143         obj_conv.inner = (void*)(obj & (~1));
8144         obj_conv.is_owned = false;
8145         LDKCVec_u8Z arg_var = ChannelMonitor_write(&obj_conv);
8146         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
8147         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
8148         CVec_u8Z_free(arg_var);
8149         return arg_arr;
8150 }
8151
8152 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelMonitor_1update_1monitor(JNIEnv *env, jclass clz, int64_t this_arg, int64_t updates, int64_t broadcaster, int64_t fee_estimator, int64_t logger) {
8153         LDKChannelMonitor this_arg_conv;
8154         this_arg_conv.inner = (void*)(this_arg & (~1));
8155         this_arg_conv.is_owned = false;
8156         LDKChannelMonitorUpdate updates_conv;
8157         updates_conv.inner = (void*)(updates & (~1));
8158         updates_conv.is_owned = false;
8159         LDKBroadcasterInterface* broadcaster_conv = (LDKBroadcasterInterface*)broadcaster;
8160         LDKFeeEstimator* fee_estimator_conv = (LDKFeeEstimator*)fee_estimator;
8161         LDKLogger* logger_conv = (LDKLogger*)logger;
8162         LDKCResult_NoneMonitorUpdateErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneMonitorUpdateErrorZ), "LDKCResult_NoneMonitorUpdateErrorZ");
8163         *ret_conv = ChannelMonitor_update_monitor(&this_arg_conv, &updates_conv, broadcaster_conv, fee_estimator_conv, logger_conv);
8164         return (long)ret_conv;
8165 }
8166
8167 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelMonitor_1get_1latest_1update_1id(JNIEnv *env, jclass clz, int64_t this_arg) {
8168         LDKChannelMonitor this_arg_conv;
8169         this_arg_conv.inner = (void*)(this_arg & (~1));
8170         this_arg_conv.is_owned = false;
8171         int64_t ret_val = ChannelMonitor_get_latest_update_id(&this_arg_conv);
8172         return ret_val;
8173 }
8174
8175 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelMonitor_1get_1funding_1txo(JNIEnv *env, jclass clz, int64_t this_arg) {
8176         LDKChannelMonitor this_arg_conv;
8177         this_arg_conv.inner = (void*)(this_arg & (~1));
8178         this_arg_conv.is_owned = false;
8179         LDKC2Tuple_OutPointScriptZ* ret_ref = MALLOC(sizeof(LDKC2Tuple_OutPointScriptZ), "LDKC2Tuple_OutPointScriptZ");
8180         *ret_ref = ChannelMonitor_get_funding_txo(&this_arg_conv);
8181         ret_ref->a = OutPoint_clone(&ret_ref->a);
8182         ret_ref->b = CVec_u8Z_clone(&ret_ref->b);
8183         return (long)ret_ref;
8184 }
8185
8186 JNIEXPORT int64_tArray JNICALL Java_org_ldk_impl_bindings_ChannelMonitor_1get_1and_1clear_1pending_1monitor_1events(JNIEnv *env, jclass clz, int64_t this_arg) {
8187         LDKChannelMonitor this_arg_conv;
8188         this_arg_conv.inner = (void*)(this_arg & (~1));
8189         this_arg_conv.is_owned = false;
8190         LDKCVec_MonitorEventZ ret_var = ChannelMonitor_get_and_clear_pending_monitor_events(&this_arg_conv);
8191         int64_tArray ret_arr = (*env)->NewLongArray(env, ret_var.datalen);
8192         int64_t *ret_arr_ptr = (*env)->GetPrimitiveArrayCritical(env, ret_arr, NULL);
8193         for (size_t o = 0; o < ret_var.datalen; o++) {
8194                 LDKMonitorEvent arr_conv_14_var = ret_var.data[o];
8195                 CHECK((((long)arr_conv_14_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8196                 CHECK((((long)&arr_conv_14_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8197                 long arr_conv_14_ref = (long)arr_conv_14_var.inner;
8198                 if (arr_conv_14_var.is_owned) {
8199                         arr_conv_14_ref |= 1;
8200                 }
8201                 ret_arr_ptr[o] = arr_conv_14_ref;
8202         }
8203         (*env)->ReleasePrimitiveArrayCritical(env, ret_arr, ret_arr_ptr, 0);
8204         FREE(ret_var.data);
8205         return ret_arr;
8206 }
8207
8208 JNIEXPORT int64_tArray JNICALL Java_org_ldk_impl_bindings_ChannelMonitor_1get_1and_1clear_1pending_1events(JNIEnv *env, jclass clz, int64_t this_arg) {
8209         LDKChannelMonitor this_arg_conv;
8210         this_arg_conv.inner = (void*)(this_arg & (~1));
8211         this_arg_conv.is_owned = false;
8212         LDKCVec_EventZ ret_var = ChannelMonitor_get_and_clear_pending_events(&this_arg_conv);
8213         int64_tArray ret_arr = (*env)->NewLongArray(env, ret_var.datalen);
8214         int64_t *ret_arr_ptr = (*env)->GetPrimitiveArrayCritical(env, ret_arr, NULL);
8215         for (size_t h = 0; h < ret_var.datalen; h++) {
8216                 LDKEvent *arr_conv_7_copy = MALLOC(sizeof(LDKEvent), "LDKEvent");
8217                 *arr_conv_7_copy = Event_clone(&ret_var.data[h]);
8218                 long arr_conv_7_ref = (long)arr_conv_7_copy;
8219                 ret_arr_ptr[h] = arr_conv_7_ref;
8220         }
8221         (*env)->ReleasePrimitiveArrayCritical(env, ret_arr, ret_arr_ptr, 0);
8222         FREE(ret_var.data);
8223         return ret_arr;
8224 }
8225
8226 JNIEXPORT jobjectArray JNICALL Java_org_ldk_impl_bindings_ChannelMonitor_1get_1latest_1holder_1commitment_1txn(JNIEnv *env, jclass clz, int64_t this_arg, int64_t logger) {
8227         LDKChannelMonitor this_arg_conv;
8228         this_arg_conv.inner = (void*)(this_arg & (~1));
8229         this_arg_conv.is_owned = false;
8230         LDKLogger* logger_conv = (LDKLogger*)logger;
8231         LDKCVec_TransactionZ ret_var = ChannelMonitor_get_latest_holder_commitment_txn(&this_arg_conv, logger_conv);
8232         jobjectArray ret_arr = (*env)->NewObjectArray(env, ret_var.datalen, arr_of_B_clz, NULL);
8233         ;
8234         for (size_t i = 0; i < ret_var.datalen; i++) {
8235                 LDKTransaction arr_conv_8_var = ret_var.data[i];
8236                 int8_tArray arr_conv_8_arr = (*env)->NewByteArray(env, arr_conv_8_var.datalen);
8237                 (*env)->SetByteArrayRegion(env, arr_conv_8_arr, 0, arr_conv_8_var.datalen, arr_conv_8_var.data);
8238                 Transaction_free(arr_conv_8_var);
8239                 (*env)->SetObjectArrayElement(env, ret_arr, i, arr_conv_8_arr);
8240         }
8241         FREE(ret_var.data);
8242         return ret_arr;
8243 }
8244
8245 JNIEXPORT int64_tArray JNICALL Java_org_ldk_impl_bindings_ChannelMonitor_1block_1connected(JNIEnv *env, jclass clz, int64_t this_arg, int8_tArray header, int64_tArray txdata, int32_t height, int64_t broadcaster, int64_t fee_estimator, int64_t logger) {
8246         LDKChannelMonitor this_arg_conv;
8247         this_arg_conv.inner = (void*)(this_arg & (~1));
8248         this_arg_conv.is_owned = false;
8249         unsigned char header_arr[80];
8250         CHECK((*env)->GetArrayLength(env, header) == 80);
8251         (*env)->GetByteArrayRegion(env, header, 0, 80, header_arr);
8252         unsigned char (*header_ref)[80] = &header_arr;
8253         LDKCVec_C2Tuple_usizeTransactionZZ txdata_constr;
8254         txdata_constr.datalen = (*env)->GetArrayLength(env, txdata);
8255         if (txdata_constr.datalen > 0)
8256                 txdata_constr.data = MALLOC(txdata_constr.datalen * sizeof(LDKC2Tuple_usizeTransactionZ), "LDKCVec_C2Tuple_usizeTransactionZZ Elements");
8257         else
8258                 txdata_constr.data = NULL;
8259         int64_t* txdata_vals = (*env)->GetLongArrayElements (env, txdata, NULL);
8260         for (size_t y = 0; y < txdata_constr.datalen; y++) {
8261                 int64_t arr_conv_24 = txdata_vals[y];
8262                 LDKC2Tuple_usizeTransactionZ arr_conv_24_conv = *(LDKC2Tuple_usizeTransactionZ*)arr_conv_24;
8263                 FREE((void*)arr_conv_24);
8264                 txdata_constr.data[y] = arr_conv_24_conv;
8265         }
8266         (*env)->ReleaseLongArrayElements(env, txdata, txdata_vals, 0);
8267         LDKBroadcasterInterface broadcaster_conv = *(LDKBroadcasterInterface*)broadcaster;
8268         if (broadcaster_conv.free == LDKBroadcasterInterface_JCalls_free) {
8269                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
8270                 LDKBroadcasterInterface_JCalls_clone(broadcaster_conv.this_arg);
8271         }
8272         LDKFeeEstimator fee_estimator_conv = *(LDKFeeEstimator*)fee_estimator;
8273         if (fee_estimator_conv.free == LDKFeeEstimator_JCalls_free) {
8274                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
8275                 LDKFeeEstimator_JCalls_clone(fee_estimator_conv.this_arg);
8276         }
8277         LDKLogger logger_conv = *(LDKLogger*)logger;
8278         if (logger_conv.free == LDKLogger_JCalls_free) {
8279                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
8280                 LDKLogger_JCalls_clone(logger_conv.this_arg);
8281         }
8282         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);
8283         int64_tArray ret_arr = (*env)->NewLongArray(env, ret_var.datalen);
8284         int64_t *ret_arr_ptr = (*env)->GetPrimitiveArrayCritical(env, ret_arr, NULL);
8285         for (size_t u = 0; u < ret_var.datalen; u++) {
8286                 LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ* arr_conv_46_ref = MALLOC(sizeof(LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ), "LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ");
8287                 *arr_conv_46_ref = ret_var.data[u];
8288                 arr_conv_46_ref->a = ThirtyTwoBytes_clone(&arr_conv_46_ref->a);
8289                 // XXX: We likely need to clone here, but no _clone fn is available for TwoTuple<Integer, TxOut>[]
8290                 ret_arr_ptr[u] = (long)arr_conv_46_ref;
8291         }
8292         (*env)->ReleasePrimitiveArrayCritical(env, ret_arr, ret_arr_ptr, 0);
8293         FREE(ret_var.data);
8294         return ret_arr;
8295 }
8296
8297 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelMonitor_1block_1disconnected(JNIEnv *env, jclass clz, int64_t this_arg, int8_tArray header, int32_t height, int64_t broadcaster, int64_t fee_estimator, int64_t logger) {
8298         LDKChannelMonitor this_arg_conv;
8299         this_arg_conv.inner = (void*)(this_arg & (~1));
8300         this_arg_conv.is_owned = false;
8301         unsigned char header_arr[80];
8302         CHECK((*env)->GetArrayLength(env, header) == 80);
8303         (*env)->GetByteArrayRegion(env, header, 0, 80, header_arr);
8304         unsigned char (*header_ref)[80] = &header_arr;
8305         LDKBroadcasterInterface broadcaster_conv = *(LDKBroadcasterInterface*)broadcaster;
8306         if (broadcaster_conv.free == LDKBroadcasterInterface_JCalls_free) {
8307                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
8308                 LDKBroadcasterInterface_JCalls_clone(broadcaster_conv.this_arg);
8309         }
8310         LDKFeeEstimator fee_estimator_conv = *(LDKFeeEstimator*)fee_estimator;
8311         if (fee_estimator_conv.free == LDKFeeEstimator_JCalls_free) {
8312                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
8313                 LDKFeeEstimator_JCalls_clone(fee_estimator_conv.this_arg);
8314         }
8315         LDKLogger logger_conv = *(LDKLogger*)logger;
8316         if (logger_conv.free == LDKLogger_JCalls_free) {
8317                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
8318                 LDKLogger_JCalls_clone(logger_conv.this_arg);
8319         }
8320         ChannelMonitor_block_disconnected(&this_arg_conv, header_ref, height, broadcaster_conv, fee_estimator_conv, logger_conv);
8321 }
8322
8323 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Persist_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
8324         LDKPersist this_ptr_conv = *(LDKPersist*)this_ptr;
8325         FREE((void*)this_ptr);
8326         Persist_free(this_ptr_conv);
8327 }
8328
8329 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_C2Tuple_1BlockHashChannelMonitorZ_1read(JNIEnv *env, jclass clz, int8_tArray ser, int64_t arg) {
8330         LDKu8slice ser_ref;
8331         ser_ref.datalen = (*env)->GetArrayLength(env, ser);
8332         ser_ref.data = (*env)->GetByteArrayElements (env, ser, NULL);
8333         LDKKeysInterface* arg_conv = (LDKKeysInterface*)arg;
8334         LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ), "LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ");
8335         *ret_conv = C2Tuple_BlockHashChannelMonitorZ_read(ser_ref, arg_conv);
8336         (*env)->ReleaseByteArrayElements(env, ser, (int8_t*)ser_ref.data, 0);
8337         return (long)ret_conv;
8338 }
8339
8340 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OutPoint_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
8341         LDKOutPoint this_ptr_conv;
8342         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8343         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8344         OutPoint_free(this_ptr_conv);
8345 }
8346
8347 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_OutPoint_1clone(JNIEnv *env, jclass clz, int64_t orig) {
8348         LDKOutPoint orig_conv;
8349         orig_conv.inner = (void*)(orig & (~1));
8350         orig_conv.is_owned = false;
8351         LDKOutPoint ret_var = OutPoint_clone(&orig_conv);
8352         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8353         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8354         long ret_ref = (long)ret_var.inner;
8355         if (ret_var.is_owned) {
8356                 ret_ref |= 1;
8357         }
8358         return ret_ref;
8359 }
8360
8361 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_OutPoint_1get_1txid(JNIEnv *env, jclass clz, int64_t this_ptr) {
8362         LDKOutPoint this_ptr_conv;
8363         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8364         this_ptr_conv.is_owned = false;
8365         int8_tArray ret_arr = (*env)->NewByteArray(env, 32);
8366         (*env)->SetByteArrayRegion(env, ret_arr, 0, 32, *OutPoint_get_txid(&this_ptr_conv));
8367         return ret_arr;
8368 }
8369
8370 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OutPoint_1set_1txid(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
8371         LDKOutPoint this_ptr_conv;
8372         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8373         this_ptr_conv.is_owned = false;
8374         LDKThirtyTwoBytes val_ref;
8375         CHECK((*env)->GetArrayLength(env, val) == 32);
8376         (*env)->GetByteArrayRegion(env, val, 0, 32, val_ref.data);
8377         OutPoint_set_txid(&this_ptr_conv, val_ref);
8378 }
8379
8380 JNIEXPORT int16_t JNICALL Java_org_ldk_impl_bindings_OutPoint_1get_1index(JNIEnv *env, jclass clz, int64_t this_ptr) {
8381         LDKOutPoint this_ptr_conv;
8382         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8383         this_ptr_conv.is_owned = false;
8384         int16_t ret_val = OutPoint_get_index(&this_ptr_conv);
8385         return ret_val;
8386 }
8387
8388 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OutPoint_1set_1index(JNIEnv *env, jclass clz, int64_t this_ptr, int16_t val) {
8389         LDKOutPoint this_ptr_conv;
8390         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8391         this_ptr_conv.is_owned = false;
8392         OutPoint_set_index(&this_ptr_conv, val);
8393 }
8394
8395 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_OutPoint_1new(JNIEnv *env, jclass clz, int8_tArray txid_arg, int16_t index_arg) {
8396         LDKThirtyTwoBytes txid_arg_ref;
8397         CHECK((*env)->GetArrayLength(env, txid_arg) == 32);
8398         (*env)->GetByteArrayRegion(env, txid_arg, 0, 32, txid_arg_ref.data);
8399         LDKOutPoint ret_var = OutPoint_new(txid_arg_ref, index_arg);
8400         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8401         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8402         long ret_ref = (long)ret_var.inner;
8403         if (ret_var.is_owned) {
8404                 ret_ref |= 1;
8405         }
8406         return ret_ref;
8407 }
8408
8409 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_OutPoint_1to_1channel_1id(JNIEnv *env, jclass clz, int64_t this_arg) {
8410         LDKOutPoint this_arg_conv;
8411         this_arg_conv.inner = (void*)(this_arg & (~1));
8412         this_arg_conv.is_owned = false;
8413         int8_tArray arg_arr = (*env)->NewByteArray(env, 32);
8414         (*env)->SetByteArrayRegion(env, arg_arr, 0, 32, OutPoint_to_channel_id(&this_arg_conv).data);
8415         return arg_arr;
8416 }
8417
8418 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_OutPoint_1write(JNIEnv *env, jclass clz, int64_t obj) {
8419         LDKOutPoint obj_conv;
8420         obj_conv.inner = (void*)(obj & (~1));
8421         obj_conv.is_owned = false;
8422         LDKCVec_u8Z arg_var = OutPoint_write(&obj_conv);
8423         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
8424         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
8425         CVec_u8Z_free(arg_var);
8426         return arg_arr;
8427 }
8428
8429 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_OutPoint_1read(JNIEnv *env, jclass clz, int8_tArray ser) {
8430         LDKu8slice ser_ref;
8431         ser_ref.datalen = (*env)->GetArrayLength(env, ser);
8432         ser_ref.data = (*env)->GetByteArrayElements (env, ser, NULL);
8433         LDKOutPoint ret_var = OutPoint_read(ser_ref);
8434         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8435         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8436         long ret_ref = (long)ret_var.inner;
8437         if (ret_var.is_owned) {
8438                 ret_ref |= 1;
8439         }
8440         (*env)->ReleaseByteArrayElements(env, ser, (int8_t*)ser_ref.data, 0);
8441         return ret_ref;
8442 }
8443
8444 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_SpendableOutputDescriptor_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
8445         LDKSpendableOutputDescriptor this_ptr_conv = *(LDKSpendableOutputDescriptor*)this_ptr;
8446         FREE((void*)this_ptr);
8447         SpendableOutputDescriptor_free(this_ptr_conv);
8448 }
8449
8450 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_SpendableOutputDescriptor_1clone(JNIEnv *env, jclass clz, int64_t orig) {
8451         LDKSpendableOutputDescriptor* orig_conv = (LDKSpendableOutputDescriptor*)orig;
8452         LDKSpendableOutputDescriptor *ret_copy = MALLOC(sizeof(LDKSpendableOutputDescriptor), "LDKSpendableOutputDescriptor");
8453         *ret_copy = SpendableOutputDescriptor_clone(orig_conv);
8454         long ret_ref = (long)ret_copy;
8455         return ret_ref;
8456 }
8457
8458 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_SpendableOutputDescriptor_1write(JNIEnv *env, jclass clz, int64_t obj) {
8459         LDKSpendableOutputDescriptor* obj_conv = (LDKSpendableOutputDescriptor*)obj;
8460         LDKCVec_u8Z arg_var = SpendableOutputDescriptor_write(obj_conv);
8461         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
8462         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
8463         CVec_u8Z_free(arg_var);
8464         return arg_arr;
8465 }
8466
8467 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_SpendableOutputDescriptor_1read(JNIEnv *env, jclass clz, int8_tArray ser) {
8468         LDKu8slice ser_ref;
8469         ser_ref.datalen = (*env)->GetArrayLength(env, ser);
8470         ser_ref.data = (*env)->GetByteArrayElements (env, ser, NULL);
8471         LDKCResult_SpendableOutputDescriptorDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_SpendableOutputDescriptorDecodeErrorZ), "LDKCResult_SpendableOutputDescriptorDecodeErrorZ");
8472         *ret_conv = SpendableOutputDescriptor_read(ser_ref);
8473         (*env)->ReleaseByteArrayElements(env, ser, (int8_t*)ser_ref.data, 0);
8474         return (long)ret_conv;
8475 }
8476
8477 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1clone(JNIEnv *env, jclass clz, int64_t orig) {
8478         LDKChannelKeys* orig_conv = (LDKChannelKeys*)orig;
8479         LDKChannelKeys* ret = MALLOC(sizeof(LDKChannelKeys), "LDKChannelKeys");
8480         *ret = ChannelKeys_clone(orig_conv);
8481         return (long)ret;
8482 }
8483
8484 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
8485         LDKChannelKeys this_ptr_conv = *(LDKChannelKeys*)this_ptr;
8486         FREE((void*)this_ptr);
8487         ChannelKeys_free(this_ptr_conv);
8488 }
8489
8490 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_KeysInterface_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
8491         LDKKeysInterface this_ptr_conv = *(LDKKeysInterface*)this_ptr;
8492         FREE((void*)this_ptr);
8493         KeysInterface_free(this_ptr_conv);
8494 }
8495
8496 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
8497         LDKInMemoryChannelKeys this_ptr_conv;
8498         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8499         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8500         InMemoryChannelKeys_free(this_ptr_conv);
8501 }
8502
8503 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1clone(JNIEnv *env, jclass clz, int64_t orig) {
8504         LDKInMemoryChannelKeys orig_conv;
8505         orig_conv.inner = (void*)(orig & (~1));
8506         orig_conv.is_owned = false;
8507         LDKInMemoryChannelKeys ret_var = InMemoryChannelKeys_clone(&orig_conv);
8508         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8509         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8510         long ret_ref = (long)ret_var.inner;
8511         if (ret_var.is_owned) {
8512                 ret_ref |= 1;
8513         }
8514         return ret_ref;
8515 }
8516
8517 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1get_1funding_1key(JNIEnv *env, jclass clz, int64_t this_ptr) {
8518         LDKInMemoryChannelKeys this_ptr_conv;
8519         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8520         this_ptr_conv.is_owned = false;
8521         int8_tArray ret_arr = (*env)->NewByteArray(env, 32);
8522         (*env)->SetByteArrayRegion(env, ret_arr, 0, 32, *InMemoryChannelKeys_get_funding_key(&this_ptr_conv));
8523         return ret_arr;
8524 }
8525
8526 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1set_1funding_1key(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
8527         LDKInMemoryChannelKeys this_ptr_conv;
8528         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8529         this_ptr_conv.is_owned = false;
8530         LDKSecretKey val_ref;
8531         CHECK((*env)->GetArrayLength(env, val) == 32);
8532         (*env)->GetByteArrayRegion(env, val, 0, 32, val_ref.bytes);
8533         InMemoryChannelKeys_set_funding_key(&this_ptr_conv, val_ref);
8534 }
8535
8536 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1get_1revocation_1base_1key(JNIEnv *env, jclass clz, int64_t this_ptr) {
8537         LDKInMemoryChannelKeys this_ptr_conv;
8538         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8539         this_ptr_conv.is_owned = false;
8540         int8_tArray ret_arr = (*env)->NewByteArray(env, 32);
8541         (*env)->SetByteArrayRegion(env, ret_arr, 0, 32, *InMemoryChannelKeys_get_revocation_base_key(&this_ptr_conv));
8542         return ret_arr;
8543 }
8544
8545 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1set_1revocation_1base_1key(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
8546         LDKInMemoryChannelKeys this_ptr_conv;
8547         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8548         this_ptr_conv.is_owned = false;
8549         LDKSecretKey val_ref;
8550         CHECK((*env)->GetArrayLength(env, val) == 32);
8551         (*env)->GetByteArrayRegion(env, val, 0, 32, val_ref.bytes);
8552         InMemoryChannelKeys_set_revocation_base_key(&this_ptr_conv, val_ref);
8553 }
8554
8555 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1get_1payment_1key(JNIEnv *env, jclass clz, int64_t this_ptr) {
8556         LDKInMemoryChannelKeys this_ptr_conv;
8557         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8558         this_ptr_conv.is_owned = false;
8559         int8_tArray ret_arr = (*env)->NewByteArray(env, 32);
8560         (*env)->SetByteArrayRegion(env, ret_arr, 0, 32, *InMemoryChannelKeys_get_payment_key(&this_ptr_conv));
8561         return ret_arr;
8562 }
8563
8564 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1set_1payment_1key(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
8565         LDKInMemoryChannelKeys this_ptr_conv;
8566         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8567         this_ptr_conv.is_owned = false;
8568         LDKSecretKey val_ref;
8569         CHECK((*env)->GetArrayLength(env, val) == 32);
8570         (*env)->GetByteArrayRegion(env, val, 0, 32, val_ref.bytes);
8571         InMemoryChannelKeys_set_payment_key(&this_ptr_conv, val_ref);
8572 }
8573
8574 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1get_1delayed_1payment_1base_1key(JNIEnv *env, jclass clz, int64_t this_ptr) {
8575         LDKInMemoryChannelKeys this_ptr_conv;
8576         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8577         this_ptr_conv.is_owned = false;
8578         int8_tArray ret_arr = (*env)->NewByteArray(env, 32);
8579         (*env)->SetByteArrayRegion(env, ret_arr, 0, 32, *InMemoryChannelKeys_get_delayed_payment_base_key(&this_ptr_conv));
8580         return ret_arr;
8581 }
8582
8583 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1set_1delayed_1payment_1base_1key(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
8584         LDKInMemoryChannelKeys this_ptr_conv;
8585         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8586         this_ptr_conv.is_owned = false;
8587         LDKSecretKey val_ref;
8588         CHECK((*env)->GetArrayLength(env, val) == 32);
8589         (*env)->GetByteArrayRegion(env, val, 0, 32, val_ref.bytes);
8590         InMemoryChannelKeys_set_delayed_payment_base_key(&this_ptr_conv, val_ref);
8591 }
8592
8593 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1get_1htlc_1base_1key(JNIEnv *env, jclass clz, int64_t this_ptr) {
8594         LDKInMemoryChannelKeys this_ptr_conv;
8595         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8596         this_ptr_conv.is_owned = false;
8597         int8_tArray ret_arr = (*env)->NewByteArray(env, 32);
8598         (*env)->SetByteArrayRegion(env, ret_arr, 0, 32, *InMemoryChannelKeys_get_htlc_base_key(&this_ptr_conv));
8599         return ret_arr;
8600 }
8601
8602 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1set_1htlc_1base_1key(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
8603         LDKInMemoryChannelKeys this_ptr_conv;
8604         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8605         this_ptr_conv.is_owned = false;
8606         LDKSecretKey val_ref;
8607         CHECK((*env)->GetArrayLength(env, val) == 32);
8608         (*env)->GetByteArrayRegion(env, val, 0, 32, val_ref.bytes);
8609         InMemoryChannelKeys_set_htlc_base_key(&this_ptr_conv, val_ref);
8610 }
8611
8612 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1get_1commitment_1seed(JNIEnv *env, jclass clz, int64_t this_ptr) {
8613         LDKInMemoryChannelKeys this_ptr_conv;
8614         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8615         this_ptr_conv.is_owned = false;
8616         int8_tArray ret_arr = (*env)->NewByteArray(env, 32);
8617         (*env)->SetByteArrayRegion(env, ret_arr, 0, 32, *InMemoryChannelKeys_get_commitment_seed(&this_ptr_conv));
8618         return ret_arr;
8619 }
8620
8621 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1set_1commitment_1seed(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
8622         LDKInMemoryChannelKeys this_ptr_conv;
8623         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8624         this_ptr_conv.is_owned = false;
8625         LDKThirtyTwoBytes val_ref;
8626         CHECK((*env)->GetArrayLength(env, val) == 32);
8627         (*env)->GetByteArrayRegion(env, val, 0, 32, val_ref.data);
8628         InMemoryChannelKeys_set_commitment_seed(&this_ptr_conv, val_ref);
8629 }
8630
8631 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1new(JNIEnv *env, jclass clz, 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, int64_t key_derivation_params) {
8632         LDKSecretKey funding_key_ref;
8633         CHECK((*env)->GetArrayLength(env, funding_key) == 32);
8634         (*env)->GetByteArrayRegion(env, funding_key, 0, 32, funding_key_ref.bytes);
8635         LDKSecretKey revocation_base_key_ref;
8636         CHECK((*env)->GetArrayLength(env, revocation_base_key) == 32);
8637         (*env)->GetByteArrayRegion(env, revocation_base_key, 0, 32, revocation_base_key_ref.bytes);
8638         LDKSecretKey payment_key_ref;
8639         CHECK((*env)->GetArrayLength(env, payment_key) == 32);
8640         (*env)->GetByteArrayRegion(env, payment_key, 0, 32, payment_key_ref.bytes);
8641         LDKSecretKey delayed_payment_base_key_ref;
8642         CHECK((*env)->GetArrayLength(env, delayed_payment_base_key) == 32);
8643         (*env)->GetByteArrayRegion(env, delayed_payment_base_key, 0, 32, delayed_payment_base_key_ref.bytes);
8644         LDKSecretKey htlc_base_key_ref;
8645         CHECK((*env)->GetArrayLength(env, htlc_base_key) == 32);
8646         (*env)->GetByteArrayRegion(env, htlc_base_key, 0, 32, htlc_base_key_ref.bytes);
8647         LDKThirtyTwoBytes commitment_seed_ref;
8648         CHECK((*env)->GetArrayLength(env, commitment_seed) == 32);
8649         (*env)->GetByteArrayRegion(env, commitment_seed, 0, 32, commitment_seed_ref.data);
8650         LDKC2Tuple_u64u64Z key_derivation_params_conv = *(LDKC2Tuple_u64u64Z*)key_derivation_params;
8651         FREE((void*)key_derivation_params);
8652         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);
8653         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8654         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8655         long ret_ref = (long)ret_var.inner;
8656         if (ret_var.is_owned) {
8657                 ret_ref |= 1;
8658         }
8659         return ret_ref;
8660 }
8661
8662 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1counterparty_1pubkeys(JNIEnv *env, jclass clz, int64_t this_arg) {
8663         LDKInMemoryChannelKeys this_arg_conv;
8664         this_arg_conv.inner = (void*)(this_arg & (~1));
8665         this_arg_conv.is_owned = false;
8666         LDKChannelPublicKeys ret_var = InMemoryChannelKeys_counterparty_pubkeys(&this_arg_conv);
8667         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8668         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8669         long ret_ref = (long)ret_var.inner;
8670         if (ret_var.is_owned) {
8671                 ret_ref |= 1;
8672         }
8673         return ret_ref;
8674 }
8675
8676 JNIEXPORT int16_t JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1counterparty_1selected_1contest_1delay(JNIEnv *env, jclass clz, int64_t this_arg) {
8677         LDKInMemoryChannelKeys this_arg_conv;
8678         this_arg_conv.inner = (void*)(this_arg & (~1));
8679         this_arg_conv.is_owned = false;
8680         int16_t ret_val = InMemoryChannelKeys_counterparty_selected_contest_delay(&this_arg_conv);
8681         return ret_val;
8682 }
8683
8684 JNIEXPORT int16_t JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1holder_1selected_1contest_1delay(JNIEnv *env, jclass clz, int64_t this_arg) {
8685         LDKInMemoryChannelKeys this_arg_conv;
8686         this_arg_conv.inner = (void*)(this_arg & (~1));
8687         this_arg_conv.is_owned = false;
8688         int16_t ret_val = InMemoryChannelKeys_holder_selected_contest_delay(&this_arg_conv);
8689         return ret_val;
8690 }
8691
8692 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1is_1outbound(JNIEnv *env, jclass clz, int64_t this_arg) {
8693         LDKInMemoryChannelKeys this_arg_conv;
8694         this_arg_conv.inner = (void*)(this_arg & (~1));
8695         this_arg_conv.is_owned = false;
8696         jboolean ret_val = InMemoryChannelKeys_is_outbound(&this_arg_conv);
8697         return ret_val;
8698 }
8699
8700 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1funding_1outpoint(JNIEnv *env, jclass clz, int64_t this_arg) {
8701         LDKInMemoryChannelKeys this_arg_conv;
8702         this_arg_conv.inner = (void*)(this_arg & (~1));
8703         this_arg_conv.is_owned = false;
8704         LDKOutPoint ret_var = InMemoryChannelKeys_funding_outpoint(&this_arg_conv);
8705         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8706         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8707         long ret_ref = (long)ret_var.inner;
8708         if (ret_var.is_owned) {
8709                 ret_ref |= 1;
8710         }
8711         return ret_ref;
8712 }
8713
8714 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1get_1channel_1parameters(JNIEnv *env, jclass clz, int64_t this_arg) {
8715         LDKInMemoryChannelKeys this_arg_conv;
8716         this_arg_conv.inner = (void*)(this_arg & (~1));
8717         this_arg_conv.is_owned = false;
8718         LDKChannelTransactionParameters ret_var = InMemoryChannelKeys_get_channel_parameters(&this_arg_conv);
8719         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8720         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8721         long ret_ref = (long)ret_var.inner;
8722         if (ret_var.is_owned) {
8723                 ret_ref |= 1;
8724         }
8725         return ret_ref;
8726 }
8727
8728 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1as_1ChannelKeys(JNIEnv *env, jclass clz, int64_t this_arg) {
8729         LDKInMemoryChannelKeys this_arg_conv;
8730         this_arg_conv.inner = (void*)(this_arg & (~1));
8731         this_arg_conv.is_owned = false;
8732         LDKChannelKeys* ret = MALLOC(sizeof(LDKChannelKeys), "LDKChannelKeys");
8733         *ret = InMemoryChannelKeys_as_ChannelKeys(&this_arg_conv);
8734         return (long)ret;
8735 }
8736
8737 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1write(JNIEnv *env, jclass clz, int64_t obj) {
8738         LDKInMemoryChannelKeys obj_conv;
8739         obj_conv.inner = (void*)(obj & (~1));
8740         obj_conv.is_owned = false;
8741         LDKCVec_u8Z arg_var = InMemoryChannelKeys_write(&obj_conv);
8742         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
8743         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
8744         CVec_u8Z_free(arg_var);
8745         return arg_arr;
8746 }
8747
8748 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1read(JNIEnv *env, jclass clz, int8_tArray ser) {
8749         LDKu8slice ser_ref;
8750         ser_ref.datalen = (*env)->GetArrayLength(env, ser);
8751         ser_ref.data = (*env)->GetByteArrayElements (env, ser, NULL);
8752         LDKCResult_InMemoryChannelKeysDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_InMemoryChannelKeysDecodeErrorZ), "LDKCResult_InMemoryChannelKeysDecodeErrorZ");
8753         *ret_conv = InMemoryChannelKeys_read(ser_ref);
8754         (*env)->ReleaseByteArrayElements(env, ser, (int8_t*)ser_ref.data, 0);
8755         return (long)ret_conv;
8756 }
8757
8758 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_KeysManager_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
8759         LDKKeysManager this_ptr_conv;
8760         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8761         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8762         KeysManager_free(this_ptr_conv);
8763 }
8764
8765 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_KeysManager_1new(JNIEnv *env, jclass clz, int8_tArray seed, jclass network, int64_t starting_time_secs, int32_t starting_time_nanos) {
8766         unsigned char seed_arr[32];
8767         CHECK((*env)->GetArrayLength(env, seed) == 32);
8768         (*env)->GetByteArrayRegion(env, seed, 0, 32, seed_arr);
8769         unsigned char (*seed_ref)[32] = &seed_arr;
8770         LDKNetwork network_conv = LDKNetwork_from_java(env, network);
8771         LDKKeysManager ret_var = KeysManager_new(seed_ref, network_conv, starting_time_secs, starting_time_nanos);
8772         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8773         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8774         long ret_ref = (long)ret_var.inner;
8775         if (ret_var.is_owned) {
8776                 ret_ref |= 1;
8777         }
8778         return ret_ref;
8779 }
8780
8781 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_KeysManager_1derive_1channel_1keys(JNIEnv *env, jclass clz, int64_t this_arg, int64_t channel_value_satoshis, int64_t params_1, int64_t params_2) {
8782         LDKKeysManager this_arg_conv;
8783         this_arg_conv.inner = (void*)(this_arg & (~1));
8784         this_arg_conv.is_owned = false;
8785         LDKInMemoryChannelKeys ret_var = KeysManager_derive_channel_keys(&this_arg_conv, channel_value_satoshis, params_1, params_2);
8786         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8787         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8788         long ret_ref = (long)ret_var.inner;
8789         if (ret_var.is_owned) {
8790                 ret_ref |= 1;
8791         }
8792         return ret_ref;
8793 }
8794
8795 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_KeysManager_1as_1KeysInterface(JNIEnv *env, jclass clz, int64_t this_arg) {
8796         LDKKeysManager this_arg_conv;
8797         this_arg_conv.inner = (void*)(this_arg & (~1));
8798         this_arg_conv.is_owned = false;
8799         LDKKeysInterface* ret = MALLOC(sizeof(LDKKeysInterface), "LDKKeysInterface");
8800         *ret = KeysManager_as_KeysInterface(&this_arg_conv);
8801         return (long)ret;
8802 }
8803
8804 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelManager_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
8805         LDKChannelManager this_ptr_conv;
8806         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8807         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8808         ChannelManager_free(this_ptr_conv);
8809 }
8810
8811 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
8812         LDKChannelDetails this_ptr_conv;
8813         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8814         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8815         ChannelDetails_free(this_ptr_conv);
8816 }
8817
8818 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1clone(JNIEnv *env, jclass clz, int64_t orig) {
8819         LDKChannelDetails orig_conv;
8820         orig_conv.inner = (void*)(orig & (~1));
8821         orig_conv.is_owned = false;
8822         LDKChannelDetails ret_var = ChannelDetails_clone(&orig_conv);
8823         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8824         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8825         long ret_ref = (long)ret_var.inner;
8826         if (ret_var.is_owned) {
8827                 ret_ref |= 1;
8828         }
8829         return ret_ref;
8830 }
8831
8832 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1get_1channel_1id(JNIEnv *env, jclass clz, int64_t this_ptr) {
8833         LDKChannelDetails this_ptr_conv;
8834         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8835         this_ptr_conv.is_owned = false;
8836         int8_tArray ret_arr = (*env)->NewByteArray(env, 32);
8837         (*env)->SetByteArrayRegion(env, ret_arr, 0, 32, *ChannelDetails_get_channel_id(&this_ptr_conv));
8838         return ret_arr;
8839 }
8840
8841 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1set_1channel_1id(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
8842         LDKChannelDetails this_ptr_conv;
8843         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8844         this_ptr_conv.is_owned = false;
8845         LDKThirtyTwoBytes val_ref;
8846         CHECK((*env)->GetArrayLength(env, val) == 32);
8847         (*env)->GetByteArrayRegion(env, val, 0, 32, val_ref.data);
8848         ChannelDetails_set_channel_id(&this_ptr_conv, val_ref);
8849 }
8850
8851 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1get_1remote_1network_1id(JNIEnv *env, jclass clz, int64_t this_ptr) {
8852         LDKChannelDetails this_ptr_conv;
8853         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8854         this_ptr_conv.is_owned = false;
8855         int8_tArray arg_arr = (*env)->NewByteArray(env, 33);
8856         (*env)->SetByteArrayRegion(env, arg_arr, 0, 33, ChannelDetails_get_remote_network_id(&this_ptr_conv).compressed_form);
8857         return arg_arr;
8858 }
8859
8860 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1set_1remote_1network_1id(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
8861         LDKChannelDetails this_ptr_conv;
8862         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8863         this_ptr_conv.is_owned = false;
8864         LDKPublicKey val_ref;
8865         CHECK((*env)->GetArrayLength(env, val) == 33);
8866         (*env)->GetByteArrayRegion(env, val, 0, 33, val_ref.compressed_form);
8867         ChannelDetails_set_remote_network_id(&this_ptr_conv, val_ref);
8868 }
8869
8870 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1get_1counterparty_1features(JNIEnv *env, jclass clz, int64_t this_ptr) {
8871         LDKChannelDetails this_ptr_conv;
8872         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8873         this_ptr_conv.is_owned = false;
8874         LDKInitFeatures ret_var = ChannelDetails_get_counterparty_features(&this_ptr_conv);
8875         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8876         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8877         long ret_ref = (long)ret_var.inner;
8878         if (ret_var.is_owned) {
8879                 ret_ref |= 1;
8880         }
8881         return ret_ref;
8882 }
8883
8884 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1set_1counterparty_1features(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
8885         LDKChannelDetails this_ptr_conv;
8886         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8887         this_ptr_conv.is_owned = false;
8888         LDKInitFeatures val_conv;
8889         val_conv.inner = (void*)(val & (~1));
8890         val_conv.is_owned = (val & 1) || (val == 0);
8891         // Warning: we may need a move here but can't clone!
8892         ChannelDetails_set_counterparty_features(&this_ptr_conv, val_conv);
8893 }
8894
8895 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1get_1channel_1value_1satoshis(JNIEnv *env, jclass clz, int64_t this_ptr) {
8896         LDKChannelDetails this_ptr_conv;
8897         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8898         this_ptr_conv.is_owned = false;
8899         int64_t ret_val = ChannelDetails_get_channel_value_satoshis(&this_ptr_conv);
8900         return ret_val;
8901 }
8902
8903 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1set_1channel_1value_1satoshis(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
8904         LDKChannelDetails this_ptr_conv;
8905         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8906         this_ptr_conv.is_owned = false;
8907         ChannelDetails_set_channel_value_satoshis(&this_ptr_conv, val);
8908 }
8909
8910 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1get_1user_1id(JNIEnv *env, jclass clz, int64_t this_ptr) {
8911         LDKChannelDetails this_ptr_conv;
8912         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8913         this_ptr_conv.is_owned = false;
8914         int64_t ret_val = ChannelDetails_get_user_id(&this_ptr_conv);
8915         return ret_val;
8916 }
8917
8918 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1set_1user_1id(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
8919         LDKChannelDetails this_ptr_conv;
8920         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8921         this_ptr_conv.is_owned = false;
8922         ChannelDetails_set_user_id(&this_ptr_conv, val);
8923 }
8924
8925 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1get_1outbound_1capacity_1msat(JNIEnv *env, jclass clz, int64_t this_ptr) {
8926         LDKChannelDetails this_ptr_conv;
8927         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8928         this_ptr_conv.is_owned = false;
8929         int64_t ret_val = ChannelDetails_get_outbound_capacity_msat(&this_ptr_conv);
8930         return ret_val;
8931 }
8932
8933 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1set_1outbound_1capacity_1msat(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
8934         LDKChannelDetails this_ptr_conv;
8935         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8936         this_ptr_conv.is_owned = false;
8937         ChannelDetails_set_outbound_capacity_msat(&this_ptr_conv, val);
8938 }
8939
8940 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1get_1inbound_1capacity_1msat(JNIEnv *env, jclass clz, int64_t this_ptr) {
8941         LDKChannelDetails this_ptr_conv;
8942         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8943         this_ptr_conv.is_owned = false;
8944         int64_t ret_val = ChannelDetails_get_inbound_capacity_msat(&this_ptr_conv);
8945         return ret_val;
8946 }
8947
8948 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1set_1inbound_1capacity_1msat(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
8949         LDKChannelDetails this_ptr_conv;
8950         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8951         this_ptr_conv.is_owned = false;
8952         ChannelDetails_set_inbound_capacity_msat(&this_ptr_conv, val);
8953 }
8954
8955 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1get_1is_1live(JNIEnv *env, jclass clz, int64_t this_ptr) {
8956         LDKChannelDetails this_ptr_conv;
8957         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8958         this_ptr_conv.is_owned = false;
8959         jboolean ret_val = ChannelDetails_get_is_live(&this_ptr_conv);
8960         return ret_val;
8961 }
8962
8963 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1set_1is_1live(JNIEnv *env, jclass clz, int64_t this_ptr, jboolean val) {
8964         LDKChannelDetails this_ptr_conv;
8965         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8966         this_ptr_conv.is_owned = false;
8967         ChannelDetails_set_is_live(&this_ptr_conv, val);
8968 }
8969
8970 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_PaymentSendFailure_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
8971         LDKPaymentSendFailure this_ptr_conv;
8972         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8973         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8974         PaymentSendFailure_free(this_ptr_conv);
8975 }
8976
8977 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelManager_1new(JNIEnv *env, jclass clz, jclass network, int64_t fee_est, int64_t chain_monitor, int64_t tx_broadcaster, int64_t logger, int64_t keys_manager, int64_t config, intptr_t current_blockchain_height) {
8978         LDKNetwork network_conv = LDKNetwork_from_java(env, network);
8979         LDKFeeEstimator fee_est_conv = *(LDKFeeEstimator*)fee_est;
8980         if (fee_est_conv.free == LDKFeeEstimator_JCalls_free) {
8981                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
8982                 LDKFeeEstimator_JCalls_clone(fee_est_conv.this_arg);
8983         }
8984         LDKWatch chain_monitor_conv = *(LDKWatch*)chain_monitor;
8985         if (chain_monitor_conv.free == LDKWatch_JCalls_free) {
8986                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
8987                 LDKWatch_JCalls_clone(chain_monitor_conv.this_arg);
8988         }
8989         LDKBroadcasterInterface tx_broadcaster_conv = *(LDKBroadcasterInterface*)tx_broadcaster;
8990         if (tx_broadcaster_conv.free == LDKBroadcasterInterface_JCalls_free) {
8991                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
8992                 LDKBroadcasterInterface_JCalls_clone(tx_broadcaster_conv.this_arg);
8993         }
8994         LDKLogger logger_conv = *(LDKLogger*)logger;
8995         if (logger_conv.free == LDKLogger_JCalls_free) {
8996                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
8997                 LDKLogger_JCalls_clone(logger_conv.this_arg);
8998         }
8999         LDKKeysInterface keys_manager_conv = *(LDKKeysInterface*)keys_manager;
9000         if (keys_manager_conv.free == LDKKeysInterface_JCalls_free) {
9001                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
9002                 LDKKeysInterface_JCalls_clone(keys_manager_conv.this_arg);
9003         }
9004         LDKUserConfig config_conv;
9005         config_conv.inner = (void*)(config & (~1));
9006         config_conv.is_owned = (config & 1) || (config == 0);
9007         if (config_conv.inner != NULL)
9008                 config_conv = UserConfig_clone(&config_conv);
9009         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);
9010         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9011         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9012         long ret_ref = (long)ret_var.inner;
9013         if (ret_var.is_owned) {
9014                 ret_ref |= 1;
9015         }
9016         return ret_ref;
9017 }
9018
9019 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelManager_1create_1channel(JNIEnv *env, jclass clz, int64_t this_arg, int8_tArray their_network_key, int64_t channel_value_satoshis, int64_t push_msat, int64_t user_id, int64_t override_config) {
9020         LDKChannelManager this_arg_conv;
9021         this_arg_conv.inner = (void*)(this_arg & (~1));
9022         this_arg_conv.is_owned = false;
9023         LDKPublicKey their_network_key_ref;
9024         CHECK((*env)->GetArrayLength(env, their_network_key) == 33);
9025         (*env)->GetByteArrayRegion(env, their_network_key, 0, 33, their_network_key_ref.compressed_form);
9026         LDKUserConfig override_config_conv;
9027         override_config_conv.inner = (void*)(override_config & (~1));
9028         override_config_conv.is_owned = (override_config & 1) || (override_config == 0);
9029         if (override_config_conv.inner != NULL)
9030                 override_config_conv = UserConfig_clone(&override_config_conv);
9031         LDKCResult_NoneAPIErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneAPIErrorZ), "LDKCResult_NoneAPIErrorZ");
9032         *ret_conv = ChannelManager_create_channel(&this_arg_conv, their_network_key_ref, channel_value_satoshis, push_msat, user_id, override_config_conv);
9033         return (long)ret_conv;
9034 }
9035
9036 JNIEXPORT int64_tArray JNICALL Java_org_ldk_impl_bindings_ChannelManager_1list_1channels(JNIEnv *env, jclass clz, int64_t this_arg) {
9037         LDKChannelManager this_arg_conv;
9038         this_arg_conv.inner = (void*)(this_arg & (~1));
9039         this_arg_conv.is_owned = false;
9040         LDKCVec_ChannelDetailsZ ret_var = ChannelManager_list_channels(&this_arg_conv);
9041         int64_tArray ret_arr = (*env)->NewLongArray(env, ret_var.datalen);
9042         int64_t *ret_arr_ptr = (*env)->GetPrimitiveArrayCritical(env, ret_arr, NULL);
9043         for (size_t q = 0; q < ret_var.datalen; q++) {
9044                 LDKChannelDetails arr_conv_16_var = ret_var.data[q];
9045                 CHECK((((long)arr_conv_16_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9046                 CHECK((((long)&arr_conv_16_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9047                 long arr_conv_16_ref = (long)arr_conv_16_var.inner;
9048                 if (arr_conv_16_var.is_owned) {
9049                         arr_conv_16_ref |= 1;
9050                 }
9051                 ret_arr_ptr[q] = arr_conv_16_ref;
9052         }
9053         (*env)->ReleasePrimitiveArrayCritical(env, ret_arr, ret_arr_ptr, 0);
9054         FREE(ret_var.data);
9055         return ret_arr;
9056 }
9057
9058 JNIEXPORT int64_tArray JNICALL Java_org_ldk_impl_bindings_ChannelManager_1list_1usable_1channels(JNIEnv *env, jclass clz, int64_t this_arg) {
9059         LDKChannelManager this_arg_conv;
9060         this_arg_conv.inner = (void*)(this_arg & (~1));
9061         this_arg_conv.is_owned = false;
9062         LDKCVec_ChannelDetailsZ ret_var = ChannelManager_list_usable_channels(&this_arg_conv);
9063         int64_tArray ret_arr = (*env)->NewLongArray(env, ret_var.datalen);
9064         int64_t *ret_arr_ptr = (*env)->GetPrimitiveArrayCritical(env, ret_arr, NULL);
9065         for (size_t q = 0; q < ret_var.datalen; q++) {
9066                 LDKChannelDetails arr_conv_16_var = ret_var.data[q];
9067                 CHECK((((long)arr_conv_16_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9068                 CHECK((((long)&arr_conv_16_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9069                 long arr_conv_16_ref = (long)arr_conv_16_var.inner;
9070                 if (arr_conv_16_var.is_owned) {
9071                         arr_conv_16_ref |= 1;
9072                 }
9073                 ret_arr_ptr[q] = arr_conv_16_ref;
9074         }
9075         (*env)->ReleasePrimitiveArrayCritical(env, ret_arr, ret_arr_ptr, 0);
9076         FREE(ret_var.data);
9077         return ret_arr;
9078 }
9079
9080 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelManager_1close_1channel(JNIEnv *env, jclass clz, int64_t this_arg, int8_tArray channel_id) {
9081         LDKChannelManager this_arg_conv;
9082         this_arg_conv.inner = (void*)(this_arg & (~1));
9083         this_arg_conv.is_owned = false;
9084         unsigned char channel_id_arr[32];
9085         CHECK((*env)->GetArrayLength(env, channel_id) == 32);
9086         (*env)->GetByteArrayRegion(env, channel_id, 0, 32, channel_id_arr);
9087         unsigned char (*channel_id_ref)[32] = &channel_id_arr;
9088         LDKCResult_NoneAPIErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneAPIErrorZ), "LDKCResult_NoneAPIErrorZ");
9089         *ret_conv = ChannelManager_close_channel(&this_arg_conv, channel_id_ref);
9090         return (long)ret_conv;
9091 }
9092
9093 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelManager_1force_1close_1channel(JNIEnv *env, jclass clz, int64_t this_arg, int8_tArray channel_id) {
9094         LDKChannelManager this_arg_conv;
9095         this_arg_conv.inner = (void*)(this_arg & (~1));
9096         this_arg_conv.is_owned = false;
9097         unsigned char channel_id_arr[32];
9098         CHECK((*env)->GetArrayLength(env, channel_id) == 32);
9099         (*env)->GetByteArrayRegion(env, channel_id, 0, 32, channel_id_arr);
9100         unsigned char (*channel_id_ref)[32] = &channel_id_arr;
9101         ChannelManager_force_close_channel(&this_arg_conv, channel_id_ref);
9102 }
9103
9104 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelManager_1force_1close_1all_1channels(JNIEnv *env, jclass clz, int64_t this_arg) {
9105         LDKChannelManager this_arg_conv;
9106         this_arg_conv.inner = (void*)(this_arg & (~1));
9107         this_arg_conv.is_owned = false;
9108         ChannelManager_force_close_all_channels(&this_arg_conv);
9109 }
9110
9111 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelManager_1send_1payment(JNIEnv *env, jclass clz, int64_t this_arg, int64_t route, int8_tArray payment_hash, int8_tArray payment_secret) {
9112         LDKChannelManager this_arg_conv;
9113         this_arg_conv.inner = (void*)(this_arg & (~1));
9114         this_arg_conv.is_owned = false;
9115         LDKRoute route_conv;
9116         route_conv.inner = (void*)(route & (~1));
9117         route_conv.is_owned = false;
9118         LDKThirtyTwoBytes payment_hash_ref;
9119         CHECK((*env)->GetArrayLength(env, payment_hash) == 32);
9120         (*env)->GetByteArrayRegion(env, payment_hash, 0, 32, payment_hash_ref.data);
9121         LDKThirtyTwoBytes payment_secret_ref;
9122         CHECK((*env)->GetArrayLength(env, payment_secret) == 32);
9123         (*env)->GetByteArrayRegion(env, payment_secret, 0, 32, payment_secret_ref.data);
9124         LDKCResult_NonePaymentSendFailureZ* ret_conv = MALLOC(sizeof(LDKCResult_NonePaymentSendFailureZ), "LDKCResult_NonePaymentSendFailureZ");
9125         *ret_conv = ChannelManager_send_payment(&this_arg_conv, &route_conv, payment_hash_ref, payment_secret_ref);
9126         return (long)ret_conv;
9127 }
9128
9129 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelManager_1funding_1transaction_1generated(JNIEnv *env, jclass clz, int64_t this_arg, int8_tArray temporary_channel_id, int64_t funding_txo) {
9130         LDKChannelManager this_arg_conv;
9131         this_arg_conv.inner = (void*)(this_arg & (~1));
9132         this_arg_conv.is_owned = false;
9133         unsigned char temporary_channel_id_arr[32];
9134         CHECK((*env)->GetArrayLength(env, temporary_channel_id) == 32);
9135         (*env)->GetByteArrayRegion(env, temporary_channel_id, 0, 32, temporary_channel_id_arr);
9136         unsigned char (*temporary_channel_id_ref)[32] = &temporary_channel_id_arr;
9137         LDKOutPoint funding_txo_conv;
9138         funding_txo_conv.inner = (void*)(funding_txo & (~1));
9139         funding_txo_conv.is_owned = (funding_txo & 1) || (funding_txo == 0);
9140         if (funding_txo_conv.inner != NULL)
9141                 funding_txo_conv = OutPoint_clone(&funding_txo_conv);
9142         ChannelManager_funding_transaction_generated(&this_arg_conv, temporary_channel_id_ref, funding_txo_conv);
9143 }
9144
9145 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelManager_1broadcast_1node_1announcement(JNIEnv *env, jclass clz, int64_t this_arg, int8_tArray rgb, int8_tArray alias, int64_tArray addresses) {
9146         LDKChannelManager this_arg_conv;
9147         this_arg_conv.inner = (void*)(this_arg & (~1));
9148         this_arg_conv.is_owned = false;
9149         LDKThreeBytes rgb_ref;
9150         CHECK((*env)->GetArrayLength(env, rgb) == 3);
9151         (*env)->GetByteArrayRegion(env, rgb, 0, 3, rgb_ref.data);
9152         LDKThirtyTwoBytes alias_ref;
9153         CHECK((*env)->GetArrayLength(env, alias) == 32);
9154         (*env)->GetByteArrayRegion(env, alias, 0, 32, alias_ref.data);
9155         LDKCVec_NetAddressZ addresses_constr;
9156         addresses_constr.datalen = (*env)->GetArrayLength(env, addresses);
9157         if (addresses_constr.datalen > 0)
9158                 addresses_constr.data = MALLOC(addresses_constr.datalen * sizeof(LDKNetAddress), "LDKCVec_NetAddressZ Elements");
9159         else
9160                 addresses_constr.data = NULL;
9161         int64_t* addresses_vals = (*env)->GetLongArrayElements (env, addresses, NULL);
9162         for (size_t m = 0; m < addresses_constr.datalen; m++) {
9163                 int64_t arr_conv_12 = addresses_vals[m];
9164                 LDKNetAddress arr_conv_12_conv = *(LDKNetAddress*)arr_conv_12;
9165                 FREE((void*)arr_conv_12);
9166                 addresses_constr.data[m] = arr_conv_12_conv;
9167         }
9168         (*env)->ReleaseLongArrayElements(env, addresses, addresses_vals, 0);
9169         ChannelManager_broadcast_node_announcement(&this_arg_conv, rgb_ref, alias_ref, addresses_constr);
9170 }
9171
9172 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelManager_1process_1pending_1htlc_1forwards(JNIEnv *env, jclass clz, int64_t this_arg) {
9173         LDKChannelManager this_arg_conv;
9174         this_arg_conv.inner = (void*)(this_arg & (~1));
9175         this_arg_conv.is_owned = false;
9176         ChannelManager_process_pending_htlc_forwards(&this_arg_conv);
9177 }
9178
9179 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelManager_1timer_1chan_1freshness_1every_1min(JNIEnv *env, jclass clz, int64_t this_arg) {
9180         LDKChannelManager this_arg_conv;
9181         this_arg_conv.inner = (void*)(this_arg & (~1));
9182         this_arg_conv.is_owned = false;
9183         ChannelManager_timer_chan_freshness_every_min(&this_arg_conv);
9184 }
9185
9186 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_ChannelManager_1fail_1htlc_1backwards(JNIEnv *env, jclass clz, int64_t this_arg, int8_tArray payment_hash, int8_tArray payment_secret) {
9187         LDKChannelManager this_arg_conv;
9188         this_arg_conv.inner = (void*)(this_arg & (~1));
9189         this_arg_conv.is_owned = false;
9190         unsigned char payment_hash_arr[32];
9191         CHECK((*env)->GetArrayLength(env, payment_hash) == 32);
9192         (*env)->GetByteArrayRegion(env, payment_hash, 0, 32, payment_hash_arr);
9193         unsigned char (*payment_hash_ref)[32] = &payment_hash_arr;
9194         LDKThirtyTwoBytes payment_secret_ref;
9195         CHECK((*env)->GetArrayLength(env, payment_secret) == 32);
9196         (*env)->GetByteArrayRegion(env, payment_secret, 0, 32, payment_secret_ref.data);
9197         jboolean ret_val = ChannelManager_fail_htlc_backwards(&this_arg_conv, payment_hash_ref, payment_secret_ref);
9198         return ret_val;
9199 }
9200
9201 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_ChannelManager_1claim_1funds(JNIEnv *env, jclass clz, int64_t this_arg, int8_tArray payment_preimage, int8_tArray payment_secret, int64_t expected_amount) {
9202         LDKChannelManager this_arg_conv;
9203         this_arg_conv.inner = (void*)(this_arg & (~1));
9204         this_arg_conv.is_owned = false;
9205         LDKThirtyTwoBytes payment_preimage_ref;
9206         CHECK((*env)->GetArrayLength(env, payment_preimage) == 32);
9207         (*env)->GetByteArrayRegion(env, payment_preimage, 0, 32, payment_preimage_ref.data);
9208         LDKThirtyTwoBytes payment_secret_ref;
9209         CHECK((*env)->GetArrayLength(env, payment_secret) == 32);
9210         (*env)->GetByteArrayRegion(env, payment_secret, 0, 32, payment_secret_ref.data);
9211         jboolean ret_val = ChannelManager_claim_funds(&this_arg_conv, payment_preimage_ref, payment_secret_ref, expected_amount);
9212         return ret_val;
9213 }
9214
9215 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_ChannelManager_1get_1our_1node_1id(JNIEnv *env, jclass clz, int64_t this_arg) {
9216         LDKChannelManager this_arg_conv;
9217         this_arg_conv.inner = (void*)(this_arg & (~1));
9218         this_arg_conv.is_owned = false;
9219         int8_tArray arg_arr = (*env)->NewByteArray(env, 33);
9220         (*env)->SetByteArrayRegion(env, arg_arr, 0, 33, ChannelManager_get_our_node_id(&this_arg_conv).compressed_form);
9221         return arg_arr;
9222 }
9223
9224 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelManager_1channel_1monitor_1updated(JNIEnv *env, jclass clz, int64_t this_arg, int64_t funding_txo, int64_t highest_applied_update_id) {
9225         LDKChannelManager this_arg_conv;
9226         this_arg_conv.inner = (void*)(this_arg & (~1));
9227         this_arg_conv.is_owned = false;
9228         LDKOutPoint funding_txo_conv;
9229         funding_txo_conv.inner = (void*)(funding_txo & (~1));
9230         funding_txo_conv.is_owned = false;
9231         ChannelManager_channel_monitor_updated(&this_arg_conv, &funding_txo_conv, highest_applied_update_id);
9232 }
9233
9234 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelManager_1as_1MessageSendEventsProvider(JNIEnv *env, jclass clz, int64_t this_arg) {
9235         LDKChannelManager this_arg_conv;
9236         this_arg_conv.inner = (void*)(this_arg & (~1));
9237         this_arg_conv.is_owned = false;
9238         LDKMessageSendEventsProvider* ret = MALLOC(sizeof(LDKMessageSendEventsProvider), "LDKMessageSendEventsProvider");
9239         *ret = ChannelManager_as_MessageSendEventsProvider(&this_arg_conv);
9240         return (long)ret;
9241 }
9242
9243 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelManager_1as_1EventsProvider(JNIEnv *env, jclass clz, int64_t this_arg) {
9244         LDKChannelManager this_arg_conv;
9245         this_arg_conv.inner = (void*)(this_arg & (~1));
9246         this_arg_conv.is_owned = false;
9247         LDKEventsProvider* ret = MALLOC(sizeof(LDKEventsProvider), "LDKEventsProvider");
9248         *ret = ChannelManager_as_EventsProvider(&this_arg_conv);
9249         return (long)ret;
9250 }
9251
9252 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelManager_1block_1connected(JNIEnv *env, jclass clz, int64_t this_arg, int8_tArray header, int64_tArray txdata, int32_t height) {
9253         LDKChannelManager this_arg_conv;
9254         this_arg_conv.inner = (void*)(this_arg & (~1));
9255         this_arg_conv.is_owned = false;
9256         unsigned char header_arr[80];
9257         CHECK((*env)->GetArrayLength(env, header) == 80);
9258         (*env)->GetByteArrayRegion(env, header, 0, 80, header_arr);
9259         unsigned char (*header_ref)[80] = &header_arr;
9260         LDKCVec_C2Tuple_usizeTransactionZZ txdata_constr;
9261         txdata_constr.datalen = (*env)->GetArrayLength(env, txdata);
9262         if (txdata_constr.datalen > 0)
9263                 txdata_constr.data = MALLOC(txdata_constr.datalen * sizeof(LDKC2Tuple_usizeTransactionZ), "LDKCVec_C2Tuple_usizeTransactionZZ Elements");
9264         else
9265                 txdata_constr.data = NULL;
9266         int64_t* txdata_vals = (*env)->GetLongArrayElements (env, txdata, NULL);
9267         for (size_t y = 0; y < txdata_constr.datalen; y++) {
9268                 int64_t arr_conv_24 = txdata_vals[y];
9269                 LDKC2Tuple_usizeTransactionZ arr_conv_24_conv = *(LDKC2Tuple_usizeTransactionZ*)arr_conv_24;
9270                 FREE((void*)arr_conv_24);
9271                 txdata_constr.data[y] = arr_conv_24_conv;
9272         }
9273         (*env)->ReleaseLongArrayElements(env, txdata, txdata_vals, 0);
9274         ChannelManager_block_connected(&this_arg_conv, header_ref, txdata_constr, height);
9275 }
9276
9277 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelManager_1block_1disconnected(JNIEnv *env, jclass clz, int64_t this_arg, int8_tArray header) {
9278         LDKChannelManager this_arg_conv;
9279         this_arg_conv.inner = (void*)(this_arg & (~1));
9280         this_arg_conv.is_owned = false;
9281         unsigned char header_arr[80];
9282         CHECK((*env)->GetArrayLength(env, header) == 80);
9283         (*env)->GetByteArrayRegion(env, header, 0, 80, header_arr);
9284         unsigned char (*header_ref)[80] = &header_arr;
9285         ChannelManager_block_disconnected(&this_arg_conv, header_ref);
9286 }
9287
9288 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelManager_1as_1ChannelMessageHandler(JNIEnv *env, jclass clz, int64_t this_arg) {
9289         LDKChannelManager this_arg_conv;
9290         this_arg_conv.inner = (void*)(this_arg & (~1));
9291         this_arg_conv.is_owned = false;
9292         LDKChannelMessageHandler* ret = MALLOC(sizeof(LDKChannelMessageHandler), "LDKChannelMessageHandler");
9293         *ret = ChannelManager_as_ChannelMessageHandler(&this_arg_conv);
9294         return (long)ret;
9295 }
9296
9297 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_ChannelManager_1write(JNIEnv *env, jclass clz, int64_t obj) {
9298         LDKChannelManager obj_conv;
9299         obj_conv.inner = (void*)(obj & (~1));
9300         obj_conv.is_owned = false;
9301         LDKCVec_u8Z arg_var = ChannelManager_write(&obj_conv);
9302         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
9303         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
9304         CVec_u8Z_free(arg_var);
9305         return arg_arr;
9306 }
9307
9308 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelManagerReadArgs_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
9309         LDKChannelManagerReadArgs this_ptr_conv;
9310         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9311         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9312         ChannelManagerReadArgs_free(this_ptr_conv);
9313 }
9314
9315 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelManagerReadArgs_1get_1keys_1manager(JNIEnv *env, jclass clz, int64_t this_ptr) {
9316         LDKChannelManagerReadArgs this_ptr_conv;
9317         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9318         this_ptr_conv.is_owned = false;
9319         long ret_ret = (long)ChannelManagerReadArgs_get_keys_manager(&this_ptr_conv);
9320         return ret_ret;
9321 }
9322
9323 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelManagerReadArgs_1set_1keys_1manager(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
9324         LDKChannelManagerReadArgs this_ptr_conv;
9325         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9326         this_ptr_conv.is_owned = false;
9327         LDKKeysInterface val_conv = *(LDKKeysInterface*)val;
9328         if (val_conv.free == LDKKeysInterface_JCalls_free) {
9329                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
9330                 LDKKeysInterface_JCalls_clone(val_conv.this_arg);
9331         }
9332         ChannelManagerReadArgs_set_keys_manager(&this_ptr_conv, val_conv);
9333 }
9334
9335 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelManagerReadArgs_1get_1fee_1estimator(JNIEnv *env, jclass clz, int64_t this_ptr) {
9336         LDKChannelManagerReadArgs this_ptr_conv;
9337         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9338         this_ptr_conv.is_owned = false;
9339         long ret_ret = (long)ChannelManagerReadArgs_get_fee_estimator(&this_ptr_conv);
9340         return ret_ret;
9341 }
9342
9343 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelManagerReadArgs_1set_1fee_1estimator(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
9344         LDKChannelManagerReadArgs this_ptr_conv;
9345         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9346         this_ptr_conv.is_owned = false;
9347         LDKFeeEstimator val_conv = *(LDKFeeEstimator*)val;
9348         if (val_conv.free == LDKFeeEstimator_JCalls_free) {
9349                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
9350                 LDKFeeEstimator_JCalls_clone(val_conv.this_arg);
9351         }
9352         ChannelManagerReadArgs_set_fee_estimator(&this_ptr_conv, val_conv);
9353 }
9354
9355 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelManagerReadArgs_1get_1chain_1monitor(JNIEnv *env, jclass clz, int64_t this_ptr) {
9356         LDKChannelManagerReadArgs this_ptr_conv;
9357         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9358         this_ptr_conv.is_owned = false;
9359         long ret_ret = (long)ChannelManagerReadArgs_get_chain_monitor(&this_ptr_conv);
9360         return ret_ret;
9361 }
9362
9363 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelManagerReadArgs_1set_1chain_1monitor(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
9364         LDKChannelManagerReadArgs this_ptr_conv;
9365         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9366         this_ptr_conv.is_owned = false;
9367         LDKWatch val_conv = *(LDKWatch*)val;
9368         if (val_conv.free == LDKWatch_JCalls_free) {
9369                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
9370                 LDKWatch_JCalls_clone(val_conv.this_arg);
9371         }
9372         ChannelManagerReadArgs_set_chain_monitor(&this_ptr_conv, val_conv);
9373 }
9374
9375 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelManagerReadArgs_1get_1tx_1broadcaster(JNIEnv *env, jclass clz, int64_t this_ptr) {
9376         LDKChannelManagerReadArgs this_ptr_conv;
9377         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9378         this_ptr_conv.is_owned = false;
9379         long ret_ret = (long)ChannelManagerReadArgs_get_tx_broadcaster(&this_ptr_conv);
9380         return ret_ret;
9381 }
9382
9383 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelManagerReadArgs_1set_1tx_1broadcaster(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
9384         LDKChannelManagerReadArgs this_ptr_conv;
9385         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9386         this_ptr_conv.is_owned = false;
9387         LDKBroadcasterInterface val_conv = *(LDKBroadcasterInterface*)val;
9388         if (val_conv.free == LDKBroadcasterInterface_JCalls_free) {
9389                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
9390                 LDKBroadcasterInterface_JCalls_clone(val_conv.this_arg);
9391         }
9392         ChannelManagerReadArgs_set_tx_broadcaster(&this_ptr_conv, val_conv);
9393 }
9394
9395 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelManagerReadArgs_1get_1logger(JNIEnv *env, jclass clz, int64_t this_ptr) {
9396         LDKChannelManagerReadArgs this_ptr_conv;
9397         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9398         this_ptr_conv.is_owned = false;
9399         long ret_ret = (long)ChannelManagerReadArgs_get_logger(&this_ptr_conv);
9400         return ret_ret;
9401 }
9402
9403 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelManagerReadArgs_1set_1logger(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
9404         LDKChannelManagerReadArgs this_ptr_conv;
9405         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9406         this_ptr_conv.is_owned = false;
9407         LDKLogger val_conv = *(LDKLogger*)val;
9408         if (val_conv.free == LDKLogger_JCalls_free) {
9409                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
9410                 LDKLogger_JCalls_clone(val_conv.this_arg);
9411         }
9412         ChannelManagerReadArgs_set_logger(&this_ptr_conv, val_conv);
9413 }
9414
9415 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelManagerReadArgs_1get_1default_1config(JNIEnv *env, jclass clz, int64_t this_ptr) {
9416         LDKChannelManagerReadArgs this_ptr_conv;
9417         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9418         this_ptr_conv.is_owned = false;
9419         LDKUserConfig ret_var = ChannelManagerReadArgs_get_default_config(&this_ptr_conv);
9420         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9421         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9422         long ret_ref = (long)ret_var.inner;
9423         if (ret_var.is_owned) {
9424                 ret_ref |= 1;
9425         }
9426         return ret_ref;
9427 }
9428
9429 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelManagerReadArgs_1set_1default_1config(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
9430         LDKChannelManagerReadArgs this_ptr_conv;
9431         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9432         this_ptr_conv.is_owned = false;
9433         LDKUserConfig val_conv;
9434         val_conv.inner = (void*)(val & (~1));
9435         val_conv.is_owned = (val & 1) || (val == 0);
9436         if (val_conv.inner != NULL)
9437                 val_conv = UserConfig_clone(&val_conv);
9438         ChannelManagerReadArgs_set_default_config(&this_ptr_conv, val_conv);
9439 }
9440
9441 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelManagerReadArgs_1new(JNIEnv *env, jclass clz, int64_t keys_manager, int64_t fee_estimator, int64_t chain_monitor, int64_t tx_broadcaster, int64_t logger, int64_t default_config, int64_tArray channel_monitors) {
9442         LDKKeysInterface keys_manager_conv = *(LDKKeysInterface*)keys_manager;
9443         if (keys_manager_conv.free == LDKKeysInterface_JCalls_free) {
9444                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
9445                 LDKKeysInterface_JCalls_clone(keys_manager_conv.this_arg);
9446         }
9447         LDKFeeEstimator fee_estimator_conv = *(LDKFeeEstimator*)fee_estimator;
9448         if (fee_estimator_conv.free == LDKFeeEstimator_JCalls_free) {
9449                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
9450                 LDKFeeEstimator_JCalls_clone(fee_estimator_conv.this_arg);
9451         }
9452         LDKWatch chain_monitor_conv = *(LDKWatch*)chain_monitor;
9453         if (chain_monitor_conv.free == LDKWatch_JCalls_free) {
9454                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
9455                 LDKWatch_JCalls_clone(chain_monitor_conv.this_arg);
9456         }
9457         LDKBroadcasterInterface tx_broadcaster_conv = *(LDKBroadcasterInterface*)tx_broadcaster;
9458         if (tx_broadcaster_conv.free == LDKBroadcasterInterface_JCalls_free) {
9459                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
9460                 LDKBroadcasterInterface_JCalls_clone(tx_broadcaster_conv.this_arg);
9461         }
9462         LDKLogger logger_conv = *(LDKLogger*)logger;
9463         if (logger_conv.free == LDKLogger_JCalls_free) {
9464                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
9465                 LDKLogger_JCalls_clone(logger_conv.this_arg);
9466         }
9467         LDKUserConfig default_config_conv;
9468         default_config_conv.inner = (void*)(default_config & (~1));
9469         default_config_conv.is_owned = (default_config & 1) || (default_config == 0);
9470         if (default_config_conv.inner != NULL)
9471                 default_config_conv = UserConfig_clone(&default_config_conv);
9472         LDKCVec_ChannelMonitorZ channel_monitors_constr;
9473         channel_monitors_constr.datalen = (*env)->GetArrayLength(env, channel_monitors);
9474         if (channel_monitors_constr.datalen > 0)
9475                 channel_monitors_constr.data = MALLOC(channel_monitors_constr.datalen * sizeof(LDKChannelMonitor), "LDKCVec_ChannelMonitorZ Elements");
9476         else
9477                 channel_monitors_constr.data = NULL;
9478         int64_t* channel_monitors_vals = (*env)->GetLongArrayElements (env, channel_monitors, NULL);
9479         for (size_t q = 0; q < channel_monitors_constr.datalen; q++) {
9480                 int64_t arr_conv_16 = channel_monitors_vals[q];
9481                 LDKChannelMonitor arr_conv_16_conv;
9482                 arr_conv_16_conv.inner = (void*)(arr_conv_16 & (~1));
9483                 arr_conv_16_conv.is_owned = (arr_conv_16 & 1) || (arr_conv_16 == 0);
9484                 // Warning: we may need a move here but can't clone!
9485                 channel_monitors_constr.data[q] = arr_conv_16_conv;
9486         }
9487         (*env)->ReleaseLongArrayElements(env, channel_monitors, channel_monitors_vals, 0);
9488         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);
9489         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9490         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9491         long ret_ref = (long)ret_var.inner;
9492         if (ret_var.is_owned) {
9493                 ret_ref |= 1;
9494         }
9495         return ret_ref;
9496 }
9497
9498 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_C2Tuple_1BlockHashChannelManagerZ_1read(JNIEnv *env, jclass clz, int8_tArray ser, int64_t arg) {
9499         LDKu8slice ser_ref;
9500         ser_ref.datalen = (*env)->GetArrayLength(env, ser);
9501         ser_ref.data = (*env)->GetByteArrayElements (env, ser, NULL);
9502         LDKChannelManagerReadArgs arg_conv;
9503         arg_conv.inner = (void*)(arg & (~1));
9504         arg_conv.is_owned = (arg & 1) || (arg == 0);
9505         // Warning: we may need a move here but can't clone!
9506         LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ), "LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ");
9507         *ret_conv = C2Tuple_BlockHashChannelManagerZ_read(ser_ref, arg_conv);
9508         (*env)->ReleaseByteArrayElements(env, ser, (int8_t*)ser_ref.data, 0);
9509         return (long)ret_conv;
9510 }
9511
9512 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_DecodeError_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
9513         LDKDecodeError this_ptr_conv;
9514         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9515         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9516         DecodeError_free(this_ptr_conv);
9517 }
9518
9519 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Init_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
9520         LDKInit this_ptr_conv;
9521         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9522         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9523         Init_free(this_ptr_conv);
9524 }
9525
9526 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_Init_1clone(JNIEnv *env, jclass clz, int64_t orig) {
9527         LDKInit orig_conv;
9528         orig_conv.inner = (void*)(orig & (~1));
9529         orig_conv.is_owned = false;
9530         LDKInit ret_var = Init_clone(&orig_conv);
9531         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9532         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9533         long ret_ref = (long)ret_var.inner;
9534         if (ret_var.is_owned) {
9535                 ret_ref |= 1;
9536         }
9537         return ret_ref;
9538 }
9539
9540 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ErrorMessage_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
9541         LDKErrorMessage this_ptr_conv;
9542         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9543         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9544         ErrorMessage_free(this_ptr_conv);
9545 }
9546
9547 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ErrorMessage_1clone(JNIEnv *env, jclass clz, int64_t orig) {
9548         LDKErrorMessage orig_conv;
9549         orig_conv.inner = (void*)(orig & (~1));
9550         orig_conv.is_owned = false;
9551         LDKErrorMessage ret_var = ErrorMessage_clone(&orig_conv);
9552         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9553         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9554         long ret_ref = (long)ret_var.inner;
9555         if (ret_var.is_owned) {
9556                 ret_ref |= 1;
9557         }
9558         return ret_ref;
9559 }
9560
9561 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_ErrorMessage_1get_1channel_1id(JNIEnv *env, jclass clz, int64_t this_ptr) {
9562         LDKErrorMessage this_ptr_conv;
9563         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9564         this_ptr_conv.is_owned = false;
9565         int8_tArray ret_arr = (*env)->NewByteArray(env, 32);
9566         (*env)->SetByteArrayRegion(env, ret_arr, 0, 32, *ErrorMessage_get_channel_id(&this_ptr_conv));
9567         return ret_arr;
9568 }
9569
9570 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ErrorMessage_1set_1channel_1id(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
9571         LDKErrorMessage this_ptr_conv;
9572         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9573         this_ptr_conv.is_owned = false;
9574         LDKThirtyTwoBytes val_ref;
9575         CHECK((*env)->GetArrayLength(env, val) == 32);
9576         (*env)->GetByteArrayRegion(env, val, 0, 32, val_ref.data);
9577         ErrorMessage_set_channel_id(&this_ptr_conv, val_ref);
9578 }
9579
9580 JNIEXPORT jstring JNICALL Java_org_ldk_impl_bindings_ErrorMessage_1get_1data(JNIEnv *env, jclass clz, int64_t this_ptr) {
9581         LDKErrorMessage this_ptr_conv;
9582         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9583         this_ptr_conv.is_owned = false;
9584         LDKStr _str = ErrorMessage_get_data(&this_ptr_conv);
9585         char* _buf = MALLOC(_str.len + 1, "str conv buf");
9586         memcpy(_buf, _str.chars, _str.len);
9587         _buf[_str.len] = 0;
9588         jstring _conv = (*env)->NewStringUTF(env, _str.chars);
9589         FREE(_buf);
9590         return _conv;
9591 }
9592
9593 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ErrorMessage_1set_1data(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
9594         LDKErrorMessage this_ptr_conv;
9595         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9596         this_ptr_conv.is_owned = false;
9597         LDKCVec_u8Z val_ref;
9598         val_ref.datalen = (*env)->GetArrayLength(env, val);
9599         val_ref.data = MALLOC(val_ref.datalen, "LDKCVec_u8Z Bytes");
9600         (*env)->GetByteArrayRegion(env, val, 0, val_ref.datalen, val_ref.data);
9601         ErrorMessage_set_data(&this_ptr_conv, val_ref);
9602 }
9603
9604 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ErrorMessage_1new(JNIEnv *env, jclass clz, int8_tArray channel_id_arg, int8_tArray data_arg) {
9605         LDKThirtyTwoBytes channel_id_arg_ref;
9606         CHECK((*env)->GetArrayLength(env, channel_id_arg) == 32);
9607         (*env)->GetByteArrayRegion(env, channel_id_arg, 0, 32, channel_id_arg_ref.data);
9608         LDKCVec_u8Z data_arg_ref;
9609         data_arg_ref.datalen = (*env)->GetArrayLength(env, data_arg);
9610         data_arg_ref.data = MALLOC(data_arg_ref.datalen, "LDKCVec_u8Z Bytes");
9611         (*env)->GetByteArrayRegion(env, data_arg, 0, data_arg_ref.datalen, data_arg_ref.data);
9612         LDKErrorMessage ret_var = ErrorMessage_new(channel_id_arg_ref, data_arg_ref);
9613         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9614         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9615         long ret_ref = (long)ret_var.inner;
9616         if (ret_var.is_owned) {
9617                 ret_ref |= 1;
9618         }
9619         return ret_ref;
9620 }
9621
9622 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Ping_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
9623         LDKPing this_ptr_conv;
9624         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9625         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9626         Ping_free(this_ptr_conv);
9627 }
9628
9629 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_Ping_1clone(JNIEnv *env, jclass clz, int64_t orig) {
9630         LDKPing orig_conv;
9631         orig_conv.inner = (void*)(orig & (~1));
9632         orig_conv.is_owned = false;
9633         LDKPing ret_var = Ping_clone(&orig_conv);
9634         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9635         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9636         long ret_ref = (long)ret_var.inner;
9637         if (ret_var.is_owned) {
9638                 ret_ref |= 1;
9639         }
9640         return ret_ref;
9641 }
9642
9643 JNIEXPORT int16_t JNICALL Java_org_ldk_impl_bindings_Ping_1get_1ponglen(JNIEnv *env, jclass clz, int64_t this_ptr) {
9644         LDKPing this_ptr_conv;
9645         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9646         this_ptr_conv.is_owned = false;
9647         int16_t ret_val = Ping_get_ponglen(&this_ptr_conv);
9648         return ret_val;
9649 }
9650
9651 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Ping_1set_1ponglen(JNIEnv *env, jclass clz, int64_t this_ptr, int16_t val) {
9652         LDKPing this_ptr_conv;
9653         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9654         this_ptr_conv.is_owned = false;
9655         Ping_set_ponglen(&this_ptr_conv, val);
9656 }
9657
9658 JNIEXPORT int16_t JNICALL Java_org_ldk_impl_bindings_Ping_1get_1byteslen(JNIEnv *env, jclass clz, int64_t this_ptr) {
9659         LDKPing this_ptr_conv;
9660         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9661         this_ptr_conv.is_owned = false;
9662         int16_t ret_val = Ping_get_byteslen(&this_ptr_conv);
9663         return ret_val;
9664 }
9665
9666 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Ping_1set_1byteslen(JNIEnv *env, jclass clz, int64_t this_ptr, int16_t val) {
9667         LDKPing this_ptr_conv;
9668         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9669         this_ptr_conv.is_owned = false;
9670         Ping_set_byteslen(&this_ptr_conv, val);
9671 }
9672
9673 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_Ping_1new(JNIEnv *env, jclass clz, int16_t ponglen_arg, int16_t byteslen_arg) {
9674         LDKPing ret_var = Ping_new(ponglen_arg, byteslen_arg);
9675         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9676         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9677         long ret_ref = (long)ret_var.inner;
9678         if (ret_var.is_owned) {
9679                 ret_ref |= 1;
9680         }
9681         return ret_ref;
9682 }
9683
9684 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Pong_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
9685         LDKPong this_ptr_conv;
9686         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9687         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9688         Pong_free(this_ptr_conv);
9689 }
9690
9691 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_Pong_1clone(JNIEnv *env, jclass clz, int64_t orig) {
9692         LDKPong orig_conv;
9693         orig_conv.inner = (void*)(orig & (~1));
9694         orig_conv.is_owned = false;
9695         LDKPong ret_var = Pong_clone(&orig_conv);
9696         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9697         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9698         long ret_ref = (long)ret_var.inner;
9699         if (ret_var.is_owned) {
9700                 ret_ref |= 1;
9701         }
9702         return ret_ref;
9703 }
9704
9705 JNIEXPORT int16_t JNICALL Java_org_ldk_impl_bindings_Pong_1get_1byteslen(JNIEnv *env, jclass clz, int64_t this_ptr) {
9706         LDKPong this_ptr_conv;
9707         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9708         this_ptr_conv.is_owned = false;
9709         int16_t ret_val = Pong_get_byteslen(&this_ptr_conv);
9710         return ret_val;
9711 }
9712
9713 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Pong_1set_1byteslen(JNIEnv *env, jclass clz, int64_t this_ptr, int16_t val) {
9714         LDKPong this_ptr_conv;
9715         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9716         this_ptr_conv.is_owned = false;
9717         Pong_set_byteslen(&this_ptr_conv, val);
9718 }
9719
9720 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_Pong_1new(JNIEnv *env, jclass clz, int16_t byteslen_arg) {
9721         LDKPong ret_var = Pong_new(byteslen_arg);
9722         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9723         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9724         long ret_ref = (long)ret_var.inner;
9725         if (ret_var.is_owned) {
9726                 ret_ref |= 1;
9727         }
9728         return ret_ref;
9729 }
9730
9731 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
9732         LDKOpenChannel this_ptr_conv;
9733         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9734         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9735         OpenChannel_free(this_ptr_conv);
9736 }
9737
9738 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_OpenChannel_1clone(JNIEnv *env, jclass clz, int64_t orig) {
9739         LDKOpenChannel orig_conv;
9740         orig_conv.inner = (void*)(orig & (~1));
9741         orig_conv.is_owned = false;
9742         LDKOpenChannel ret_var = OpenChannel_clone(&orig_conv);
9743         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9744         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9745         long ret_ref = (long)ret_var.inner;
9746         if (ret_var.is_owned) {
9747                 ret_ref |= 1;
9748         }
9749         return ret_ref;
9750 }
9751
9752 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1chain_1hash(JNIEnv *env, jclass clz, int64_t this_ptr) {
9753         LDKOpenChannel this_ptr_conv;
9754         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9755         this_ptr_conv.is_owned = false;
9756         int8_tArray ret_arr = (*env)->NewByteArray(env, 32);
9757         (*env)->SetByteArrayRegion(env, ret_arr, 0, 32, *OpenChannel_get_chain_hash(&this_ptr_conv));
9758         return ret_arr;
9759 }
9760
9761 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1chain_1hash(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
9762         LDKOpenChannel this_ptr_conv;
9763         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9764         this_ptr_conv.is_owned = false;
9765         LDKThirtyTwoBytes val_ref;
9766         CHECK((*env)->GetArrayLength(env, val) == 32);
9767         (*env)->GetByteArrayRegion(env, val, 0, 32, val_ref.data);
9768         OpenChannel_set_chain_hash(&this_ptr_conv, val_ref);
9769 }
9770
9771 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1temporary_1channel_1id(JNIEnv *env, jclass clz, int64_t this_ptr) {
9772         LDKOpenChannel this_ptr_conv;
9773         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9774         this_ptr_conv.is_owned = false;
9775         int8_tArray ret_arr = (*env)->NewByteArray(env, 32);
9776         (*env)->SetByteArrayRegion(env, ret_arr, 0, 32, *OpenChannel_get_temporary_channel_id(&this_ptr_conv));
9777         return ret_arr;
9778 }
9779
9780 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1temporary_1channel_1id(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
9781         LDKOpenChannel this_ptr_conv;
9782         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9783         this_ptr_conv.is_owned = false;
9784         LDKThirtyTwoBytes val_ref;
9785         CHECK((*env)->GetArrayLength(env, val) == 32);
9786         (*env)->GetByteArrayRegion(env, val, 0, 32, val_ref.data);
9787         OpenChannel_set_temporary_channel_id(&this_ptr_conv, val_ref);
9788 }
9789
9790 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1funding_1satoshis(JNIEnv *env, jclass clz, int64_t this_ptr) {
9791         LDKOpenChannel this_ptr_conv;
9792         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9793         this_ptr_conv.is_owned = false;
9794         int64_t ret_val = OpenChannel_get_funding_satoshis(&this_ptr_conv);
9795         return ret_val;
9796 }
9797
9798 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1funding_1satoshis(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
9799         LDKOpenChannel this_ptr_conv;
9800         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9801         this_ptr_conv.is_owned = false;
9802         OpenChannel_set_funding_satoshis(&this_ptr_conv, val);
9803 }
9804
9805 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1push_1msat(JNIEnv *env, jclass clz, int64_t this_ptr) {
9806         LDKOpenChannel this_ptr_conv;
9807         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9808         this_ptr_conv.is_owned = false;
9809         int64_t ret_val = OpenChannel_get_push_msat(&this_ptr_conv);
9810         return ret_val;
9811 }
9812
9813 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1push_1msat(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
9814         LDKOpenChannel this_ptr_conv;
9815         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9816         this_ptr_conv.is_owned = false;
9817         OpenChannel_set_push_msat(&this_ptr_conv, val);
9818 }
9819
9820 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1dust_1limit_1satoshis(JNIEnv *env, jclass clz, int64_t this_ptr) {
9821         LDKOpenChannel this_ptr_conv;
9822         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9823         this_ptr_conv.is_owned = false;
9824         int64_t ret_val = OpenChannel_get_dust_limit_satoshis(&this_ptr_conv);
9825         return ret_val;
9826 }
9827
9828 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1dust_1limit_1satoshis(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
9829         LDKOpenChannel this_ptr_conv;
9830         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9831         this_ptr_conv.is_owned = false;
9832         OpenChannel_set_dust_limit_satoshis(&this_ptr_conv, val);
9833 }
9834
9835 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1max_1htlc_1value_1in_1flight_1msat(JNIEnv *env, jclass clz, int64_t this_ptr) {
9836         LDKOpenChannel this_ptr_conv;
9837         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9838         this_ptr_conv.is_owned = false;
9839         int64_t ret_val = OpenChannel_get_max_htlc_value_in_flight_msat(&this_ptr_conv);
9840         return ret_val;
9841 }
9842
9843 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1max_1htlc_1value_1in_1flight_1msat(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
9844         LDKOpenChannel this_ptr_conv;
9845         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9846         this_ptr_conv.is_owned = false;
9847         OpenChannel_set_max_htlc_value_in_flight_msat(&this_ptr_conv, val);
9848 }
9849
9850 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1channel_1reserve_1satoshis(JNIEnv *env, jclass clz, int64_t this_ptr) {
9851         LDKOpenChannel this_ptr_conv;
9852         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9853         this_ptr_conv.is_owned = false;
9854         int64_t ret_val = OpenChannel_get_channel_reserve_satoshis(&this_ptr_conv);
9855         return ret_val;
9856 }
9857
9858 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1channel_1reserve_1satoshis(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
9859         LDKOpenChannel this_ptr_conv;
9860         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9861         this_ptr_conv.is_owned = false;
9862         OpenChannel_set_channel_reserve_satoshis(&this_ptr_conv, val);
9863 }
9864
9865 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1htlc_1minimum_1msat(JNIEnv *env, jclass clz, int64_t this_ptr) {
9866         LDKOpenChannel this_ptr_conv;
9867         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9868         this_ptr_conv.is_owned = false;
9869         int64_t ret_val = OpenChannel_get_htlc_minimum_msat(&this_ptr_conv);
9870         return ret_val;
9871 }
9872
9873 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1htlc_1minimum_1msat(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
9874         LDKOpenChannel this_ptr_conv;
9875         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9876         this_ptr_conv.is_owned = false;
9877         OpenChannel_set_htlc_minimum_msat(&this_ptr_conv, val);
9878 }
9879
9880 JNIEXPORT int32_t JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1feerate_1per_1kw(JNIEnv *env, jclass clz, int64_t this_ptr) {
9881         LDKOpenChannel this_ptr_conv;
9882         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9883         this_ptr_conv.is_owned = false;
9884         int32_t ret_val = OpenChannel_get_feerate_per_kw(&this_ptr_conv);
9885         return ret_val;
9886 }
9887
9888 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1feerate_1per_1kw(JNIEnv *env, jclass clz, int64_t this_ptr, int32_t val) {
9889         LDKOpenChannel this_ptr_conv;
9890         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9891         this_ptr_conv.is_owned = false;
9892         OpenChannel_set_feerate_per_kw(&this_ptr_conv, val);
9893 }
9894
9895 JNIEXPORT int16_t JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1to_1self_1delay(JNIEnv *env, jclass clz, int64_t this_ptr) {
9896         LDKOpenChannel this_ptr_conv;
9897         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9898         this_ptr_conv.is_owned = false;
9899         int16_t ret_val = OpenChannel_get_to_self_delay(&this_ptr_conv);
9900         return ret_val;
9901 }
9902
9903 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1to_1self_1delay(JNIEnv *env, jclass clz, int64_t this_ptr, int16_t val) {
9904         LDKOpenChannel this_ptr_conv;
9905         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9906         this_ptr_conv.is_owned = false;
9907         OpenChannel_set_to_self_delay(&this_ptr_conv, val);
9908 }
9909
9910 JNIEXPORT int16_t JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1max_1accepted_1htlcs(JNIEnv *env, jclass clz, int64_t this_ptr) {
9911         LDKOpenChannel this_ptr_conv;
9912         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9913         this_ptr_conv.is_owned = false;
9914         int16_t ret_val = OpenChannel_get_max_accepted_htlcs(&this_ptr_conv);
9915         return ret_val;
9916 }
9917
9918 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1max_1accepted_1htlcs(JNIEnv *env, jclass clz, int64_t this_ptr, int16_t val) {
9919         LDKOpenChannel this_ptr_conv;
9920         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9921         this_ptr_conv.is_owned = false;
9922         OpenChannel_set_max_accepted_htlcs(&this_ptr_conv, val);
9923 }
9924
9925 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1funding_1pubkey(JNIEnv *env, jclass clz, int64_t this_ptr) {
9926         LDKOpenChannel this_ptr_conv;
9927         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9928         this_ptr_conv.is_owned = false;
9929         int8_tArray arg_arr = (*env)->NewByteArray(env, 33);
9930         (*env)->SetByteArrayRegion(env, arg_arr, 0, 33, OpenChannel_get_funding_pubkey(&this_ptr_conv).compressed_form);
9931         return arg_arr;
9932 }
9933
9934 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1funding_1pubkey(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
9935         LDKOpenChannel this_ptr_conv;
9936         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9937         this_ptr_conv.is_owned = false;
9938         LDKPublicKey val_ref;
9939         CHECK((*env)->GetArrayLength(env, val) == 33);
9940         (*env)->GetByteArrayRegion(env, val, 0, 33, val_ref.compressed_form);
9941         OpenChannel_set_funding_pubkey(&this_ptr_conv, val_ref);
9942 }
9943
9944 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1revocation_1basepoint(JNIEnv *env, jclass clz, int64_t this_ptr) {
9945         LDKOpenChannel this_ptr_conv;
9946         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9947         this_ptr_conv.is_owned = false;
9948         int8_tArray arg_arr = (*env)->NewByteArray(env, 33);
9949         (*env)->SetByteArrayRegion(env, arg_arr, 0, 33, OpenChannel_get_revocation_basepoint(&this_ptr_conv).compressed_form);
9950         return arg_arr;
9951 }
9952
9953 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1revocation_1basepoint(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
9954         LDKOpenChannel this_ptr_conv;
9955         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9956         this_ptr_conv.is_owned = false;
9957         LDKPublicKey val_ref;
9958         CHECK((*env)->GetArrayLength(env, val) == 33);
9959         (*env)->GetByteArrayRegion(env, val, 0, 33, val_ref.compressed_form);
9960         OpenChannel_set_revocation_basepoint(&this_ptr_conv, val_ref);
9961 }
9962
9963 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1payment_1point(JNIEnv *env, jclass clz, int64_t this_ptr) {
9964         LDKOpenChannel this_ptr_conv;
9965         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9966         this_ptr_conv.is_owned = false;
9967         int8_tArray arg_arr = (*env)->NewByteArray(env, 33);
9968         (*env)->SetByteArrayRegion(env, arg_arr, 0, 33, OpenChannel_get_payment_point(&this_ptr_conv).compressed_form);
9969         return arg_arr;
9970 }
9971
9972 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1payment_1point(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
9973         LDKOpenChannel this_ptr_conv;
9974         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9975         this_ptr_conv.is_owned = false;
9976         LDKPublicKey val_ref;
9977         CHECK((*env)->GetArrayLength(env, val) == 33);
9978         (*env)->GetByteArrayRegion(env, val, 0, 33, val_ref.compressed_form);
9979         OpenChannel_set_payment_point(&this_ptr_conv, val_ref);
9980 }
9981
9982 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1delayed_1payment_1basepoint(JNIEnv *env, jclass clz, int64_t this_ptr) {
9983         LDKOpenChannel this_ptr_conv;
9984         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9985         this_ptr_conv.is_owned = false;
9986         int8_tArray arg_arr = (*env)->NewByteArray(env, 33);
9987         (*env)->SetByteArrayRegion(env, arg_arr, 0, 33, OpenChannel_get_delayed_payment_basepoint(&this_ptr_conv).compressed_form);
9988         return arg_arr;
9989 }
9990
9991 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1delayed_1payment_1basepoint(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
9992         LDKOpenChannel this_ptr_conv;
9993         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9994         this_ptr_conv.is_owned = false;
9995         LDKPublicKey val_ref;
9996         CHECK((*env)->GetArrayLength(env, val) == 33);
9997         (*env)->GetByteArrayRegion(env, val, 0, 33, val_ref.compressed_form);
9998         OpenChannel_set_delayed_payment_basepoint(&this_ptr_conv, val_ref);
9999 }
10000
10001 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1htlc_1basepoint(JNIEnv *env, jclass clz, int64_t this_ptr) {
10002         LDKOpenChannel this_ptr_conv;
10003         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10004         this_ptr_conv.is_owned = false;
10005         int8_tArray arg_arr = (*env)->NewByteArray(env, 33);
10006         (*env)->SetByteArrayRegion(env, arg_arr, 0, 33, OpenChannel_get_htlc_basepoint(&this_ptr_conv).compressed_form);
10007         return arg_arr;
10008 }
10009
10010 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1htlc_1basepoint(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
10011         LDKOpenChannel this_ptr_conv;
10012         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10013         this_ptr_conv.is_owned = false;
10014         LDKPublicKey val_ref;
10015         CHECK((*env)->GetArrayLength(env, val) == 33);
10016         (*env)->GetByteArrayRegion(env, val, 0, 33, val_ref.compressed_form);
10017         OpenChannel_set_htlc_basepoint(&this_ptr_conv, val_ref);
10018 }
10019
10020 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1first_1per_1commitment_1point(JNIEnv *env, jclass clz, int64_t this_ptr) {
10021         LDKOpenChannel this_ptr_conv;
10022         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10023         this_ptr_conv.is_owned = false;
10024         int8_tArray arg_arr = (*env)->NewByteArray(env, 33);
10025         (*env)->SetByteArrayRegion(env, arg_arr, 0, 33, OpenChannel_get_first_per_commitment_point(&this_ptr_conv).compressed_form);
10026         return arg_arr;
10027 }
10028
10029 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1first_1per_1commitment_1point(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
10030         LDKOpenChannel this_ptr_conv;
10031         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10032         this_ptr_conv.is_owned = false;
10033         LDKPublicKey val_ref;
10034         CHECK((*env)->GetArrayLength(env, val) == 33);
10035         (*env)->GetByteArrayRegion(env, val, 0, 33, val_ref.compressed_form);
10036         OpenChannel_set_first_per_commitment_point(&this_ptr_conv, val_ref);
10037 }
10038
10039 JNIEXPORT int8_t JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1channel_1flags(JNIEnv *env, jclass clz, int64_t this_ptr) {
10040         LDKOpenChannel this_ptr_conv;
10041         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10042         this_ptr_conv.is_owned = false;
10043         int8_t ret_val = OpenChannel_get_channel_flags(&this_ptr_conv);
10044         return ret_val;
10045 }
10046
10047 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1channel_1flags(JNIEnv *env, jclass clz, int64_t this_ptr, int8_t val) {
10048         LDKOpenChannel this_ptr_conv;
10049         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10050         this_ptr_conv.is_owned = false;
10051         OpenChannel_set_channel_flags(&this_ptr_conv, val);
10052 }
10053
10054 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
10055         LDKAcceptChannel this_ptr_conv;
10056         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10057         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10058         AcceptChannel_free(this_ptr_conv);
10059 }
10060
10061 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1clone(JNIEnv *env, jclass clz, int64_t orig) {
10062         LDKAcceptChannel orig_conv;
10063         orig_conv.inner = (void*)(orig & (~1));
10064         orig_conv.is_owned = false;
10065         LDKAcceptChannel ret_var = AcceptChannel_clone(&orig_conv);
10066         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10067         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10068         long ret_ref = (long)ret_var.inner;
10069         if (ret_var.is_owned) {
10070                 ret_ref |= 1;
10071         }
10072         return ret_ref;
10073 }
10074
10075 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1get_1temporary_1channel_1id(JNIEnv *env, jclass clz, int64_t this_ptr) {
10076         LDKAcceptChannel this_ptr_conv;
10077         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10078         this_ptr_conv.is_owned = false;
10079         int8_tArray ret_arr = (*env)->NewByteArray(env, 32);
10080         (*env)->SetByteArrayRegion(env, ret_arr, 0, 32, *AcceptChannel_get_temporary_channel_id(&this_ptr_conv));
10081         return ret_arr;
10082 }
10083
10084 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1set_1temporary_1channel_1id(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
10085         LDKAcceptChannel this_ptr_conv;
10086         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10087         this_ptr_conv.is_owned = false;
10088         LDKThirtyTwoBytes val_ref;
10089         CHECK((*env)->GetArrayLength(env, val) == 32);
10090         (*env)->GetByteArrayRegion(env, val, 0, 32, val_ref.data);
10091         AcceptChannel_set_temporary_channel_id(&this_ptr_conv, val_ref);
10092 }
10093
10094 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1get_1dust_1limit_1satoshis(JNIEnv *env, jclass clz, int64_t this_ptr) {
10095         LDKAcceptChannel this_ptr_conv;
10096         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10097         this_ptr_conv.is_owned = false;
10098         int64_t ret_val = AcceptChannel_get_dust_limit_satoshis(&this_ptr_conv);
10099         return ret_val;
10100 }
10101
10102 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1set_1dust_1limit_1satoshis(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
10103         LDKAcceptChannel this_ptr_conv;
10104         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10105         this_ptr_conv.is_owned = false;
10106         AcceptChannel_set_dust_limit_satoshis(&this_ptr_conv, val);
10107 }
10108
10109 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1get_1max_1htlc_1value_1in_1flight_1msat(JNIEnv *env, jclass clz, int64_t this_ptr) {
10110         LDKAcceptChannel this_ptr_conv;
10111         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10112         this_ptr_conv.is_owned = false;
10113         int64_t ret_val = AcceptChannel_get_max_htlc_value_in_flight_msat(&this_ptr_conv);
10114         return ret_val;
10115 }
10116
10117 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1set_1max_1htlc_1value_1in_1flight_1msat(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
10118         LDKAcceptChannel this_ptr_conv;
10119         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10120         this_ptr_conv.is_owned = false;
10121         AcceptChannel_set_max_htlc_value_in_flight_msat(&this_ptr_conv, val);
10122 }
10123
10124 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1get_1channel_1reserve_1satoshis(JNIEnv *env, jclass clz, int64_t this_ptr) {
10125         LDKAcceptChannel this_ptr_conv;
10126         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10127         this_ptr_conv.is_owned = false;
10128         int64_t ret_val = AcceptChannel_get_channel_reserve_satoshis(&this_ptr_conv);
10129         return ret_val;
10130 }
10131
10132 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1set_1channel_1reserve_1satoshis(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
10133         LDKAcceptChannel this_ptr_conv;
10134         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10135         this_ptr_conv.is_owned = false;
10136         AcceptChannel_set_channel_reserve_satoshis(&this_ptr_conv, val);
10137 }
10138
10139 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1get_1htlc_1minimum_1msat(JNIEnv *env, jclass clz, int64_t this_ptr) {
10140         LDKAcceptChannel this_ptr_conv;
10141         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10142         this_ptr_conv.is_owned = false;
10143         int64_t ret_val = AcceptChannel_get_htlc_minimum_msat(&this_ptr_conv);
10144         return ret_val;
10145 }
10146
10147 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1set_1htlc_1minimum_1msat(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
10148         LDKAcceptChannel this_ptr_conv;
10149         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10150         this_ptr_conv.is_owned = false;
10151         AcceptChannel_set_htlc_minimum_msat(&this_ptr_conv, val);
10152 }
10153
10154 JNIEXPORT int32_t JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1get_1minimum_1depth(JNIEnv *env, jclass clz, int64_t this_ptr) {
10155         LDKAcceptChannel this_ptr_conv;
10156         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10157         this_ptr_conv.is_owned = false;
10158         int32_t ret_val = AcceptChannel_get_minimum_depth(&this_ptr_conv);
10159         return ret_val;
10160 }
10161
10162 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1set_1minimum_1depth(JNIEnv *env, jclass clz, int64_t this_ptr, int32_t val) {
10163         LDKAcceptChannel this_ptr_conv;
10164         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10165         this_ptr_conv.is_owned = false;
10166         AcceptChannel_set_minimum_depth(&this_ptr_conv, val);
10167 }
10168
10169 JNIEXPORT int16_t JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1get_1to_1self_1delay(JNIEnv *env, jclass clz, int64_t this_ptr) {
10170         LDKAcceptChannel this_ptr_conv;
10171         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10172         this_ptr_conv.is_owned = false;
10173         int16_t ret_val = AcceptChannel_get_to_self_delay(&this_ptr_conv);
10174         return ret_val;
10175 }
10176
10177 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1set_1to_1self_1delay(JNIEnv *env, jclass clz, int64_t this_ptr, int16_t val) {
10178         LDKAcceptChannel this_ptr_conv;
10179         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10180         this_ptr_conv.is_owned = false;
10181         AcceptChannel_set_to_self_delay(&this_ptr_conv, val);
10182 }
10183
10184 JNIEXPORT int16_t JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1get_1max_1accepted_1htlcs(JNIEnv *env, jclass clz, int64_t this_ptr) {
10185         LDKAcceptChannel this_ptr_conv;
10186         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10187         this_ptr_conv.is_owned = false;
10188         int16_t ret_val = AcceptChannel_get_max_accepted_htlcs(&this_ptr_conv);
10189         return ret_val;
10190 }
10191
10192 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1set_1max_1accepted_1htlcs(JNIEnv *env, jclass clz, int64_t this_ptr, int16_t val) {
10193         LDKAcceptChannel this_ptr_conv;
10194         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10195         this_ptr_conv.is_owned = false;
10196         AcceptChannel_set_max_accepted_htlcs(&this_ptr_conv, val);
10197 }
10198
10199 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1get_1funding_1pubkey(JNIEnv *env, jclass clz, int64_t this_ptr) {
10200         LDKAcceptChannel this_ptr_conv;
10201         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10202         this_ptr_conv.is_owned = false;
10203         int8_tArray arg_arr = (*env)->NewByteArray(env, 33);
10204         (*env)->SetByteArrayRegion(env, arg_arr, 0, 33, AcceptChannel_get_funding_pubkey(&this_ptr_conv).compressed_form);
10205         return arg_arr;
10206 }
10207
10208 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1set_1funding_1pubkey(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
10209         LDKAcceptChannel this_ptr_conv;
10210         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10211         this_ptr_conv.is_owned = false;
10212         LDKPublicKey val_ref;
10213         CHECK((*env)->GetArrayLength(env, val) == 33);
10214         (*env)->GetByteArrayRegion(env, val, 0, 33, val_ref.compressed_form);
10215         AcceptChannel_set_funding_pubkey(&this_ptr_conv, val_ref);
10216 }
10217
10218 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1get_1revocation_1basepoint(JNIEnv *env, jclass clz, int64_t this_ptr) {
10219         LDKAcceptChannel this_ptr_conv;
10220         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10221         this_ptr_conv.is_owned = false;
10222         int8_tArray arg_arr = (*env)->NewByteArray(env, 33);
10223         (*env)->SetByteArrayRegion(env, arg_arr, 0, 33, AcceptChannel_get_revocation_basepoint(&this_ptr_conv).compressed_form);
10224         return arg_arr;
10225 }
10226
10227 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1set_1revocation_1basepoint(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
10228         LDKAcceptChannel this_ptr_conv;
10229         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10230         this_ptr_conv.is_owned = false;
10231         LDKPublicKey val_ref;
10232         CHECK((*env)->GetArrayLength(env, val) == 33);
10233         (*env)->GetByteArrayRegion(env, val, 0, 33, val_ref.compressed_form);
10234         AcceptChannel_set_revocation_basepoint(&this_ptr_conv, val_ref);
10235 }
10236
10237 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1get_1payment_1point(JNIEnv *env, jclass clz, int64_t this_ptr) {
10238         LDKAcceptChannel this_ptr_conv;
10239         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10240         this_ptr_conv.is_owned = false;
10241         int8_tArray arg_arr = (*env)->NewByteArray(env, 33);
10242         (*env)->SetByteArrayRegion(env, arg_arr, 0, 33, AcceptChannel_get_payment_point(&this_ptr_conv).compressed_form);
10243         return arg_arr;
10244 }
10245
10246 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1set_1payment_1point(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
10247         LDKAcceptChannel this_ptr_conv;
10248         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10249         this_ptr_conv.is_owned = false;
10250         LDKPublicKey val_ref;
10251         CHECK((*env)->GetArrayLength(env, val) == 33);
10252         (*env)->GetByteArrayRegion(env, val, 0, 33, val_ref.compressed_form);
10253         AcceptChannel_set_payment_point(&this_ptr_conv, val_ref);
10254 }
10255
10256 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1get_1delayed_1payment_1basepoint(JNIEnv *env, jclass clz, int64_t this_ptr) {
10257         LDKAcceptChannel this_ptr_conv;
10258         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10259         this_ptr_conv.is_owned = false;
10260         int8_tArray arg_arr = (*env)->NewByteArray(env, 33);
10261         (*env)->SetByteArrayRegion(env, arg_arr, 0, 33, AcceptChannel_get_delayed_payment_basepoint(&this_ptr_conv).compressed_form);
10262         return arg_arr;
10263 }
10264
10265 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1set_1delayed_1payment_1basepoint(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
10266         LDKAcceptChannel this_ptr_conv;
10267         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10268         this_ptr_conv.is_owned = false;
10269         LDKPublicKey val_ref;
10270         CHECK((*env)->GetArrayLength(env, val) == 33);
10271         (*env)->GetByteArrayRegion(env, val, 0, 33, val_ref.compressed_form);
10272         AcceptChannel_set_delayed_payment_basepoint(&this_ptr_conv, val_ref);
10273 }
10274
10275 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1get_1htlc_1basepoint(JNIEnv *env, jclass clz, int64_t this_ptr) {
10276         LDKAcceptChannel this_ptr_conv;
10277         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10278         this_ptr_conv.is_owned = false;
10279         int8_tArray arg_arr = (*env)->NewByteArray(env, 33);
10280         (*env)->SetByteArrayRegion(env, arg_arr, 0, 33, AcceptChannel_get_htlc_basepoint(&this_ptr_conv).compressed_form);
10281         return arg_arr;
10282 }
10283
10284 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1set_1htlc_1basepoint(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
10285         LDKAcceptChannel this_ptr_conv;
10286         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10287         this_ptr_conv.is_owned = false;
10288         LDKPublicKey val_ref;
10289         CHECK((*env)->GetArrayLength(env, val) == 33);
10290         (*env)->GetByteArrayRegion(env, val, 0, 33, val_ref.compressed_form);
10291         AcceptChannel_set_htlc_basepoint(&this_ptr_conv, val_ref);
10292 }
10293
10294 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1get_1first_1per_1commitment_1point(JNIEnv *env, jclass clz, int64_t this_ptr) {
10295         LDKAcceptChannel this_ptr_conv;
10296         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10297         this_ptr_conv.is_owned = false;
10298         int8_tArray arg_arr = (*env)->NewByteArray(env, 33);
10299         (*env)->SetByteArrayRegion(env, arg_arr, 0, 33, AcceptChannel_get_first_per_commitment_point(&this_ptr_conv).compressed_form);
10300         return arg_arr;
10301 }
10302
10303 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1set_1first_1per_1commitment_1point(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
10304         LDKAcceptChannel this_ptr_conv;
10305         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10306         this_ptr_conv.is_owned = false;
10307         LDKPublicKey val_ref;
10308         CHECK((*env)->GetArrayLength(env, val) == 33);
10309         (*env)->GetByteArrayRegion(env, val, 0, 33, val_ref.compressed_form);
10310         AcceptChannel_set_first_per_commitment_point(&this_ptr_conv, val_ref);
10311 }
10312
10313 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_FundingCreated_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
10314         LDKFundingCreated this_ptr_conv;
10315         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10316         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10317         FundingCreated_free(this_ptr_conv);
10318 }
10319
10320 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_FundingCreated_1clone(JNIEnv *env, jclass clz, int64_t orig) {
10321         LDKFundingCreated orig_conv;
10322         orig_conv.inner = (void*)(orig & (~1));
10323         orig_conv.is_owned = false;
10324         LDKFundingCreated ret_var = FundingCreated_clone(&orig_conv);
10325         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10326         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10327         long ret_ref = (long)ret_var.inner;
10328         if (ret_var.is_owned) {
10329                 ret_ref |= 1;
10330         }
10331         return ret_ref;
10332 }
10333
10334 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_FundingCreated_1get_1temporary_1channel_1id(JNIEnv *env, jclass clz, int64_t this_ptr) {
10335         LDKFundingCreated this_ptr_conv;
10336         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10337         this_ptr_conv.is_owned = false;
10338         int8_tArray ret_arr = (*env)->NewByteArray(env, 32);
10339         (*env)->SetByteArrayRegion(env, ret_arr, 0, 32, *FundingCreated_get_temporary_channel_id(&this_ptr_conv));
10340         return ret_arr;
10341 }
10342
10343 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_FundingCreated_1set_1temporary_1channel_1id(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
10344         LDKFundingCreated this_ptr_conv;
10345         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10346         this_ptr_conv.is_owned = false;
10347         LDKThirtyTwoBytes val_ref;
10348         CHECK((*env)->GetArrayLength(env, val) == 32);
10349         (*env)->GetByteArrayRegion(env, val, 0, 32, val_ref.data);
10350         FundingCreated_set_temporary_channel_id(&this_ptr_conv, val_ref);
10351 }
10352
10353 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_FundingCreated_1get_1funding_1txid(JNIEnv *env, jclass clz, int64_t this_ptr) {
10354         LDKFundingCreated this_ptr_conv;
10355         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10356         this_ptr_conv.is_owned = false;
10357         int8_tArray ret_arr = (*env)->NewByteArray(env, 32);
10358         (*env)->SetByteArrayRegion(env, ret_arr, 0, 32, *FundingCreated_get_funding_txid(&this_ptr_conv));
10359         return ret_arr;
10360 }
10361
10362 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_FundingCreated_1set_1funding_1txid(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
10363         LDKFundingCreated this_ptr_conv;
10364         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10365         this_ptr_conv.is_owned = false;
10366         LDKThirtyTwoBytes val_ref;
10367         CHECK((*env)->GetArrayLength(env, val) == 32);
10368         (*env)->GetByteArrayRegion(env, val, 0, 32, val_ref.data);
10369         FundingCreated_set_funding_txid(&this_ptr_conv, val_ref);
10370 }
10371
10372 JNIEXPORT int16_t JNICALL Java_org_ldk_impl_bindings_FundingCreated_1get_1funding_1output_1index(JNIEnv *env, jclass clz, int64_t this_ptr) {
10373         LDKFundingCreated this_ptr_conv;
10374         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10375         this_ptr_conv.is_owned = false;
10376         int16_t ret_val = FundingCreated_get_funding_output_index(&this_ptr_conv);
10377         return ret_val;
10378 }
10379
10380 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_FundingCreated_1set_1funding_1output_1index(JNIEnv *env, jclass clz, int64_t this_ptr, int16_t val) {
10381         LDKFundingCreated this_ptr_conv;
10382         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10383         this_ptr_conv.is_owned = false;
10384         FundingCreated_set_funding_output_index(&this_ptr_conv, val);
10385 }
10386
10387 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_FundingCreated_1get_1signature(JNIEnv *env, jclass clz, int64_t this_ptr) {
10388         LDKFundingCreated this_ptr_conv;
10389         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10390         this_ptr_conv.is_owned = false;
10391         int8_tArray arg_arr = (*env)->NewByteArray(env, 64);
10392         (*env)->SetByteArrayRegion(env, arg_arr, 0, 64, FundingCreated_get_signature(&this_ptr_conv).compact_form);
10393         return arg_arr;
10394 }
10395
10396 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_FundingCreated_1set_1signature(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
10397         LDKFundingCreated this_ptr_conv;
10398         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10399         this_ptr_conv.is_owned = false;
10400         LDKSignature val_ref;
10401         CHECK((*env)->GetArrayLength(env, val) == 64);
10402         (*env)->GetByteArrayRegion(env, val, 0, 64, val_ref.compact_form);
10403         FundingCreated_set_signature(&this_ptr_conv, val_ref);
10404 }
10405
10406 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_FundingCreated_1new(JNIEnv *env, jclass clz, int8_tArray temporary_channel_id_arg, int8_tArray funding_txid_arg, int16_t funding_output_index_arg, int8_tArray signature_arg) {
10407         LDKThirtyTwoBytes temporary_channel_id_arg_ref;
10408         CHECK((*env)->GetArrayLength(env, temporary_channel_id_arg) == 32);
10409         (*env)->GetByteArrayRegion(env, temporary_channel_id_arg, 0, 32, temporary_channel_id_arg_ref.data);
10410         LDKThirtyTwoBytes funding_txid_arg_ref;
10411         CHECK((*env)->GetArrayLength(env, funding_txid_arg) == 32);
10412         (*env)->GetByteArrayRegion(env, funding_txid_arg, 0, 32, funding_txid_arg_ref.data);
10413         LDKSignature signature_arg_ref;
10414         CHECK((*env)->GetArrayLength(env, signature_arg) == 64);
10415         (*env)->GetByteArrayRegion(env, signature_arg, 0, 64, signature_arg_ref.compact_form);
10416         LDKFundingCreated ret_var = FundingCreated_new(temporary_channel_id_arg_ref, funding_txid_arg_ref, funding_output_index_arg, signature_arg_ref);
10417         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10418         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10419         long ret_ref = (long)ret_var.inner;
10420         if (ret_var.is_owned) {
10421                 ret_ref |= 1;
10422         }
10423         return ret_ref;
10424 }
10425
10426 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_FundingSigned_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
10427         LDKFundingSigned this_ptr_conv;
10428         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10429         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10430         FundingSigned_free(this_ptr_conv);
10431 }
10432
10433 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_FundingSigned_1clone(JNIEnv *env, jclass clz, int64_t orig) {
10434         LDKFundingSigned orig_conv;
10435         orig_conv.inner = (void*)(orig & (~1));
10436         orig_conv.is_owned = false;
10437         LDKFundingSigned ret_var = FundingSigned_clone(&orig_conv);
10438         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10439         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10440         long ret_ref = (long)ret_var.inner;
10441         if (ret_var.is_owned) {
10442                 ret_ref |= 1;
10443         }
10444         return ret_ref;
10445 }
10446
10447 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_FundingSigned_1get_1channel_1id(JNIEnv *env, jclass clz, int64_t this_ptr) {
10448         LDKFundingSigned this_ptr_conv;
10449         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10450         this_ptr_conv.is_owned = false;
10451         int8_tArray ret_arr = (*env)->NewByteArray(env, 32);
10452         (*env)->SetByteArrayRegion(env, ret_arr, 0, 32, *FundingSigned_get_channel_id(&this_ptr_conv));
10453         return ret_arr;
10454 }
10455
10456 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_FundingSigned_1set_1channel_1id(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
10457         LDKFundingSigned this_ptr_conv;
10458         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10459         this_ptr_conv.is_owned = false;
10460         LDKThirtyTwoBytes val_ref;
10461         CHECK((*env)->GetArrayLength(env, val) == 32);
10462         (*env)->GetByteArrayRegion(env, val, 0, 32, val_ref.data);
10463         FundingSigned_set_channel_id(&this_ptr_conv, val_ref);
10464 }
10465
10466 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_FundingSigned_1get_1signature(JNIEnv *env, jclass clz, int64_t this_ptr) {
10467         LDKFundingSigned this_ptr_conv;
10468         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10469         this_ptr_conv.is_owned = false;
10470         int8_tArray arg_arr = (*env)->NewByteArray(env, 64);
10471         (*env)->SetByteArrayRegion(env, arg_arr, 0, 64, FundingSigned_get_signature(&this_ptr_conv).compact_form);
10472         return arg_arr;
10473 }
10474
10475 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_FundingSigned_1set_1signature(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
10476         LDKFundingSigned this_ptr_conv;
10477         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10478         this_ptr_conv.is_owned = false;
10479         LDKSignature val_ref;
10480         CHECK((*env)->GetArrayLength(env, val) == 64);
10481         (*env)->GetByteArrayRegion(env, val, 0, 64, val_ref.compact_form);
10482         FundingSigned_set_signature(&this_ptr_conv, val_ref);
10483 }
10484
10485 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_FundingSigned_1new(JNIEnv *env, jclass clz, int8_tArray channel_id_arg, int8_tArray signature_arg) {
10486         LDKThirtyTwoBytes channel_id_arg_ref;
10487         CHECK((*env)->GetArrayLength(env, channel_id_arg) == 32);
10488         (*env)->GetByteArrayRegion(env, channel_id_arg, 0, 32, channel_id_arg_ref.data);
10489         LDKSignature signature_arg_ref;
10490         CHECK((*env)->GetArrayLength(env, signature_arg) == 64);
10491         (*env)->GetByteArrayRegion(env, signature_arg, 0, 64, signature_arg_ref.compact_form);
10492         LDKFundingSigned ret_var = FundingSigned_new(channel_id_arg_ref, signature_arg_ref);
10493         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10494         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10495         long ret_ref = (long)ret_var.inner;
10496         if (ret_var.is_owned) {
10497                 ret_ref |= 1;
10498         }
10499         return ret_ref;
10500 }
10501
10502 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_FundingLocked_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
10503         LDKFundingLocked this_ptr_conv;
10504         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10505         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10506         FundingLocked_free(this_ptr_conv);
10507 }
10508
10509 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_FundingLocked_1clone(JNIEnv *env, jclass clz, int64_t orig) {
10510         LDKFundingLocked orig_conv;
10511         orig_conv.inner = (void*)(orig & (~1));
10512         orig_conv.is_owned = false;
10513         LDKFundingLocked ret_var = FundingLocked_clone(&orig_conv);
10514         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10515         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10516         long ret_ref = (long)ret_var.inner;
10517         if (ret_var.is_owned) {
10518                 ret_ref |= 1;
10519         }
10520         return ret_ref;
10521 }
10522
10523 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_FundingLocked_1get_1channel_1id(JNIEnv *env, jclass clz, int64_t this_ptr) {
10524         LDKFundingLocked this_ptr_conv;
10525         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10526         this_ptr_conv.is_owned = false;
10527         int8_tArray ret_arr = (*env)->NewByteArray(env, 32);
10528         (*env)->SetByteArrayRegion(env, ret_arr, 0, 32, *FundingLocked_get_channel_id(&this_ptr_conv));
10529         return ret_arr;
10530 }
10531
10532 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_FundingLocked_1set_1channel_1id(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
10533         LDKFundingLocked this_ptr_conv;
10534         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10535         this_ptr_conv.is_owned = false;
10536         LDKThirtyTwoBytes val_ref;
10537         CHECK((*env)->GetArrayLength(env, val) == 32);
10538         (*env)->GetByteArrayRegion(env, val, 0, 32, val_ref.data);
10539         FundingLocked_set_channel_id(&this_ptr_conv, val_ref);
10540 }
10541
10542 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_FundingLocked_1get_1next_1per_1commitment_1point(JNIEnv *env, jclass clz, int64_t this_ptr) {
10543         LDKFundingLocked this_ptr_conv;
10544         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10545         this_ptr_conv.is_owned = false;
10546         int8_tArray arg_arr = (*env)->NewByteArray(env, 33);
10547         (*env)->SetByteArrayRegion(env, arg_arr, 0, 33, FundingLocked_get_next_per_commitment_point(&this_ptr_conv).compressed_form);
10548         return arg_arr;
10549 }
10550
10551 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_FundingLocked_1set_1next_1per_1commitment_1point(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
10552         LDKFundingLocked this_ptr_conv;
10553         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10554         this_ptr_conv.is_owned = false;
10555         LDKPublicKey val_ref;
10556         CHECK((*env)->GetArrayLength(env, val) == 33);
10557         (*env)->GetByteArrayRegion(env, val, 0, 33, val_ref.compressed_form);
10558         FundingLocked_set_next_per_commitment_point(&this_ptr_conv, val_ref);
10559 }
10560
10561 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_FundingLocked_1new(JNIEnv *env, jclass clz, int8_tArray channel_id_arg, int8_tArray next_per_commitment_point_arg) {
10562         LDKThirtyTwoBytes channel_id_arg_ref;
10563         CHECK((*env)->GetArrayLength(env, channel_id_arg) == 32);
10564         (*env)->GetByteArrayRegion(env, channel_id_arg, 0, 32, channel_id_arg_ref.data);
10565         LDKPublicKey next_per_commitment_point_arg_ref;
10566         CHECK((*env)->GetArrayLength(env, next_per_commitment_point_arg) == 33);
10567         (*env)->GetByteArrayRegion(env, next_per_commitment_point_arg, 0, 33, next_per_commitment_point_arg_ref.compressed_form);
10568         LDKFundingLocked ret_var = FundingLocked_new(channel_id_arg_ref, next_per_commitment_point_arg_ref);
10569         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10570         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10571         long ret_ref = (long)ret_var.inner;
10572         if (ret_var.is_owned) {
10573                 ret_ref |= 1;
10574         }
10575         return ret_ref;
10576 }
10577
10578 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Shutdown_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
10579         LDKShutdown this_ptr_conv;
10580         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10581         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10582         Shutdown_free(this_ptr_conv);
10583 }
10584
10585 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_Shutdown_1clone(JNIEnv *env, jclass clz, int64_t orig) {
10586         LDKShutdown orig_conv;
10587         orig_conv.inner = (void*)(orig & (~1));
10588         orig_conv.is_owned = false;
10589         LDKShutdown ret_var = Shutdown_clone(&orig_conv);
10590         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10591         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10592         long ret_ref = (long)ret_var.inner;
10593         if (ret_var.is_owned) {
10594                 ret_ref |= 1;
10595         }
10596         return ret_ref;
10597 }
10598
10599 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_Shutdown_1get_1channel_1id(JNIEnv *env, jclass clz, int64_t this_ptr) {
10600         LDKShutdown this_ptr_conv;
10601         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10602         this_ptr_conv.is_owned = false;
10603         int8_tArray ret_arr = (*env)->NewByteArray(env, 32);
10604         (*env)->SetByteArrayRegion(env, ret_arr, 0, 32, *Shutdown_get_channel_id(&this_ptr_conv));
10605         return ret_arr;
10606 }
10607
10608 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Shutdown_1set_1channel_1id(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
10609         LDKShutdown this_ptr_conv;
10610         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10611         this_ptr_conv.is_owned = false;
10612         LDKThirtyTwoBytes val_ref;
10613         CHECK((*env)->GetArrayLength(env, val) == 32);
10614         (*env)->GetByteArrayRegion(env, val, 0, 32, val_ref.data);
10615         Shutdown_set_channel_id(&this_ptr_conv, val_ref);
10616 }
10617
10618 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_Shutdown_1get_1scriptpubkey(JNIEnv *env, jclass clz, int64_t this_ptr) {
10619         LDKShutdown this_ptr_conv;
10620         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10621         this_ptr_conv.is_owned = false;
10622         LDKu8slice arg_var = Shutdown_get_scriptpubkey(&this_ptr_conv);
10623         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
10624         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
10625         return arg_arr;
10626 }
10627
10628 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Shutdown_1set_1scriptpubkey(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
10629         LDKShutdown this_ptr_conv;
10630         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10631         this_ptr_conv.is_owned = false;
10632         LDKCVec_u8Z val_ref;
10633         val_ref.datalen = (*env)->GetArrayLength(env, val);
10634         val_ref.data = MALLOC(val_ref.datalen, "LDKCVec_u8Z Bytes");
10635         (*env)->GetByteArrayRegion(env, val, 0, val_ref.datalen, val_ref.data);
10636         Shutdown_set_scriptpubkey(&this_ptr_conv, val_ref);
10637 }
10638
10639 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_Shutdown_1new(JNIEnv *env, jclass clz, int8_tArray channel_id_arg, int8_tArray scriptpubkey_arg) {
10640         LDKThirtyTwoBytes channel_id_arg_ref;
10641         CHECK((*env)->GetArrayLength(env, channel_id_arg) == 32);
10642         (*env)->GetByteArrayRegion(env, channel_id_arg, 0, 32, channel_id_arg_ref.data);
10643         LDKCVec_u8Z scriptpubkey_arg_ref;
10644         scriptpubkey_arg_ref.datalen = (*env)->GetArrayLength(env, scriptpubkey_arg);
10645         scriptpubkey_arg_ref.data = MALLOC(scriptpubkey_arg_ref.datalen, "LDKCVec_u8Z Bytes");
10646         (*env)->GetByteArrayRegion(env, scriptpubkey_arg, 0, scriptpubkey_arg_ref.datalen, scriptpubkey_arg_ref.data);
10647         LDKShutdown ret_var = Shutdown_new(channel_id_arg_ref, scriptpubkey_arg_ref);
10648         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10649         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10650         long ret_ref = (long)ret_var.inner;
10651         if (ret_var.is_owned) {
10652                 ret_ref |= 1;
10653         }
10654         return ret_ref;
10655 }
10656
10657 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ClosingSigned_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
10658         LDKClosingSigned this_ptr_conv;
10659         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10660         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10661         ClosingSigned_free(this_ptr_conv);
10662 }
10663
10664 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ClosingSigned_1clone(JNIEnv *env, jclass clz, int64_t orig) {
10665         LDKClosingSigned orig_conv;
10666         orig_conv.inner = (void*)(orig & (~1));
10667         orig_conv.is_owned = false;
10668         LDKClosingSigned ret_var = ClosingSigned_clone(&orig_conv);
10669         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10670         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10671         long ret_ref = (long)ret_var.inner;
10672         if (ret_var.is_owned) {
10673                 ret_ref |= 1;
10674         }
10675         return ret_ref;
10676 }
10677
10678 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_ClosingSigned_1get_1channel_1id(JNIEnv *env, jclass clz, int64_t this_ptr) {
10679         LDKClosingSigned this_ptr_conv;
10680         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10681         this_ptr_conv.is_owned = false;
10682         int8_tArray ret_arr = (*env)->NewByteArray(env, 32);
10683         (*env)->SetByteArrayRegion(env, ret_arr, 0, 32, *ClosingSigned_get_channel_id(&this_ptr_conv));
10684         return ret_arr;
10685 }
10686
10687 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ClosingSigned_1set_1channel_1id(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
10688         LDKClosingSigned this_ptr_conv;
10689         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10690         this_ptr_conv.is_owned = false;
10691         LDKThirtyTwoBytes val_ref;
10692         CHECK((*env)->GetArrayLength(env, val) == 32);
10693         (*env)->GetByteArrayRegion(env, val, 0, 32, val_ref.data);
10694         ClosingSigned_set_channel_id(&this_ptr_conv, val_ref);
10695 }
10696
10697 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ClosingSigned_1get_1fee_1satoshis(JNIEnv *env, jclass clz, int64_t this_ptr) {
10698         LDKClosingSigned this_ptr_conv;
10699         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10700         this_ptr_conv.is_owned = false;
10701         int64_t ret_val = ClosingSigned_get_fee_satoshis(&this_ptr_conv);
10702         return ret_val;
10703 }
10704
10705 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ClosingSigned_1set_1fee_1satoshis(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
10706         LDKClosingSigned this_ptr_conv;
10707         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10708         this_ptr_conv.is_owned = false;
10709         ClosingSigned_set_fee_satoshis(&this_ptr_conv, val);
10710 }
10711
10712 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_ClosingSigned_1get_1signature(JNIEnv *env, jclass clz, int64_t this_ptr) {
10713         LDKClosingSigned this_ptr_conv;
10714         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10715         this_ptr_conv.is_owned = false;
10716         int8_tArray arg_arr = (*env)->NewByteArray(env, 64);
10717         (*env)->SetByteArrayRegion(env, arg_arr, 0, 64, ClosingSigned_get_signature(&this_ptr_conv).compact_form);
10718         return arg_arr;
10719 }
10720
10721 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ClosingSigned_1set_1signature(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
10722         LDKClosingSigned this_ptr_conv;
10723         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10724         this_ptr_conv.is_owned = false;
10725         LDKSignature val_ref;
10726         CHECK((*env)->GetArrayLength(env, val) == 64);
10727         (*env)->GetByteArrayRegion(env, val, 0, 64, val_ref.compact_form);
10728         ClosingSigned_set_signature(&this_ptr_conv, val_ref);
10729 }
10730
10731 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ClosingSigned_1new(JNIEnv *env, jclass clz, int8_tArray channel_id_arg, int64_t fee_satoshis_arg, int8_tArray signature_arg) {
10732         LDKThirtyTwoBytes channel_id_arg_ref;
10733         CHECK((*env)->GetArrayLength(env, channel_id_arg) == 32);
10734         (*env)->GetByteArrayRegion(env, channel_id_arg, 0, 32, channel_id_arg_ref.data);
10735         LDKSignature signature_arg_ref;
10736         CHECK((*env)->GetArrayLength(env, signature_arg) == 64);
10737         (*env)->GetByteArrayRegion(env, signature_arg, 0, 64, signature_arg_ref.compact_form);
10738         LDKClosingSigned ret_var = ClosingSigned_new(channel_id_arg_ref, fee_satoshis_arg, signature_arg_ref);
10739         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10740         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10741         long ret_ref = (long)ret_var.inner;
10742         if (ret_var.is_owned) {
10743                 ret_ref |= 1;
10744         }
10745         return ret_ref;
10746 }
10747
10748 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateAddHTLC_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
10749         LDKUpdateAddHTLC this_ptr_conv;
10750         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10751         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10752         UpdateAddHTLC_free(this_ptr_conv);
10753 }
10754
10755 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_UpdateAddHTLC_1clone(JNIEnv *env, jclass clz, int64_t orig) {
10756         LDKUpdateAddHTLC orig_conv;
10757         orig_conv.inner = (void*)(orig & (~1));
10758         orig_conv.is_owned = false;
10759         LDKUpdateAddHTLC ret_var = UpdateAddHTLC_clone(&orig_conv);
10760         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10761         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10762         long ret_ref = (long)ret_var.inner;
10763         if (ret_var.is_owned) {
10764                 ret_ref |= 1;
10765         }
10766         return ret_ref;
10767 }
10768
10769 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_UpdateAddHTLC_1get_1channel_1id(JNIEnv *env, jclass clz, int64_t this_ptr) {
10770         LDKUpdateAddHTLC this_ptr_conv;
10771         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10772         this_ptr_conv.is_owned = false;
10773         int8_tArray ret_arr = (*env)->NewByteArray(env, 32);
10774         (*env)->SetByteArrayRegion(env, ret_arr, 0, 32, *UpdateAddHTLC_get_channel_id(&this_ptr_conv));
10775         return ret_arr;
10776 }
10777
10778 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateAddHTLC_1set_1channel_1id(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
10779         LDKUpdateAddHTLC this_ptr_conv;
10780         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10781         this_ptr_conv.is_owned = false;
10782         LDKThirtyTwoBytes val_ref;
10783         CHECK((*env)->GetArrayLength(env, val) == 32);
10784         (*env)->GetByteArrayRegion(env, val, 0, 32, val_ref.data);
10785         UpdateAddHTLC_set_channel_id(&this_ptr_conv, val_ref);
10786 }
10787
10788 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_UpdateAddHTLC_1get_1htlc_1id(JNIEnv *env, jclass clz, int64_t this_ptr) {
10789         LDKUpdateAddHTLC this_ptr_conv;
10790         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10791         this_ptr_conv.is_owned = false;
10792         int64_t ret_val = UpdateAddHTLC_get_htlc_id(&this_ptr_conv);
10793         return ret_val;
10794 }
10795
10796 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateAddHTLC_1set_1htlc_1id(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
10797         LDKUpdateAddHTLC this_ptr_conv;
10798         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10799         this_ptr_conv.is_owned = false;
10800         UpdateAddHTLC_set_htlc_id(&this_ptr_conv, val);
10801 }
10802
10803 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_UpdateAddHTLC_1get_1amount_1msat(JNIEnv *env, jclass clz, int64_t this_ptr) {
10804         LDKUpdateAddHTLC this_ptr_conv;
10805         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10806         this_ptr_conv.is_owned = false;
10807         int64_t ret_val = UpdateAddHTLC_get_amount_msat(&this_ptr_conv);
10808         return ret_val;
10809 }
10810
10811 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateAddHTLC_1set_1amount_1msat(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
10812         LDKUpdateAddHTLC this_ptr_conv;
10813         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10814         this_ptr_conv.is_owned = false;
10815         UpdateAddHTLC_set_amount_msat(&this_ptr_conv, val);
10816 }
10817
10818 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_UpdateAddHTLC_1get_1payment_1hash(JNIEnv *env, jclass clz, int64_t this_ptr) {
10819         LDKUpdateAddHTLC this_ptr_conv;
10820         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10821         this_ptr_conv.is_owned = false;
10822         int8_tArray ret_arr = (*env)->NewByteArray(env, 32);
10823         (*env)->SetByteArrayRegion(env, ret_arr, 0, 32, *UpdateAddHTLC_get_payment_hash(&this_ptr_conv));
10824         return ret_arr;
10825 }
10826
10827 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateAddHTLC_1set_1payment_1hash(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
10828         LDKUpdateAddHTLC this_ptr_conv;
10829         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10830         this_ptr_conv.is_owned = false;
10831         LDKThirtyTwoBytes val_ref;
10832         CHECK((*env)->GetArrayLength(env, val) == 32);
10833         (*env)->GetByteArrayRegion(env, val, 0, 32, val_ref.data);
10834         UpdateAddHTLC_set_payment_hash(&this_ptr_conv, val_ref);
10835 }
10836
10837 JNIEXPORT int32_t JNICALL Java_org_ldk_impl_bindings_UpdateAddHTLC_1get_1cltv_1expiry(JNIEnv *env, jclass clz, int64_t this_ptr) {
10838         LDKUpdateAddHTLC this_ptr_conv;
10839         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10840         this_ptr_conv.is_owned = false;
10841         int32_t ret_val = UpdateAddHTLC_get_cltv_expiry(&this_ptr_conv);
10842         return ret_val;
10843 }
10844
10845 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateAddHTLC_1set_1cltv_1expiry(JNIEnv *env, jclass clz, int64_t this_ptr, int32_t val) {
10846         LDKUpdateAddHTLC this_ptr_conv;
10847         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10848         this_ptr_conv.is_owned = false;
10849         UpdateAddHTLC_set_cltv_expiry(&this_ptr_conv, val);
10850 }
10851
10852 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateFulfillHTLC_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
10853         LDKUpdateFulfillHTLC this_ptr_conv;
10854         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10855         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10856         UpdateFulfillHTLC_free(this_ptr_conv);
10857 }
10858
10859 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_UpdateFulfillHTLC_1clone(JNIEnv *env, jclass clz, int64_t orig) {
10860         LDKUpdateFulfillHTLC orig_conv;
10861         orig_conv.inner = (void*)(orig & (~1));
10862         orig_conv.is_owned = false;
10863         LDKUpdateFulfillHTLC ret_var = UpdateFulfillHTLC_clone(&orig_conv);
10864         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10865         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10866         long ret_ref = (long)ret_var.inner;
10867         if (ret_var.is_owned) {
10868                 ret_ref |= 1;
10869         }
10870         return ret_ref;
10871 }
10872
10873 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_UpdateFulfillHTLC_1get_1channel_1id(JNIEnv *env, jclass clz, int64_t this_ptr) {
10874         LDKUpdateFulfillHTLC this_ptr_conv;
10875         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10876         this_ptr_conv.is_owned = false;
10877         int8_tArray ret_arr = (*env)->NewByteArray(env, 32);
10878         (*env)->SetByteArrayRegion(env, ret_arr, 0, 32, *UpdateFulfillHTLC_get_channel_id(&this_ptr_conv));
10879         return ret_arr;
10880 }
10881
10882 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateFulfillHTLC_1set_1channel_1id(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
10883         LDKUpdateFulfillHTLC this_ptr_conv;
10884         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10885         this_ptr_conv.is_owned = false;
10886         LDKThirtyTwoBytes val_ref;
10887         CHECK((*env)->GetArrayLength(env, val) == 32);
10888         (*env)->GetByteArrayRegion(env, val, 0, 32, val_ref.data);
10889         UpdateFulfillHTLC_set_channel_id(&this_ptr_conv, val_ref);
10890 }
10891
10892 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_UpdateFulfillHTLC_1get_1htlc_1id(JNIEnv *env, jclass clz, int64_t this_ptr) {
10893         LDKUpdateFulfillHTLC this_ptr_conv;
10894         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10895         this_ptr_conv.is_owned = false;
10896         int64_t ret_val = UpdateFulfillHTLC_get_htlc_id(&this_ptr_conv);
10897         return ret_val;
10898 }
10899
10900 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateFulfillHTLC_1set_1htlc_1id(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
10901         LDKUpdateFulfillHTLC this_ptr_conv;
10902         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10903         this_ptr_conv.is_owned = false;
10904         UpdateFulfillHTLC_set_htlc_id(&this_ptr_conv, val);
10905 }
10906
10907 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_UpdateFulfillHTLC_1get_1payment_1preimage(JNIEnv *env, jclass clz, int64_t this_ptr) {
10908         LDKUpdateFulfillHTLC this_ptr_conv;
10909         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10910         this_ptr_conv.is_owned = false;
10911         int8_tArray ret_arr = (*env)->NewByteArray(env, 32);
10912         (*env)->SetByteArrayRegion(env, ret_arr, 0, 32, *UpdateFulfillHTLC_get_payment_preimage(&this_ptr_conv));
10913         return ret_arr;
10914 }
10915
10916 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateFulfillHTLC_1set_1payment_1preimage(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
10917         LDKUpdateFulfillHTLC this_ptr_conv;
10918         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10919         this_ptr_conv.is_owned = false;
10920         LDKThirtyTwoBytes val_ref;
10921         CHECK((*env)->GetArrayLength(env, val) == 32);
10922         (*env)->GetByteArrayRegion(env, val, 0, 32, val_ref.data);
10923         UpdateFulfillHTLC_set_payment_preimage(&this_ptr_conv, val_ref);
10924 }
10925
10926 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_UpdateFulfillHTLC_1new(JNIEnv *env, jclass clz, int8_tArray channel_id_arg, int64_t htlc_id_arg, int8_tArray payment_preimage_arg) {
10927         LDKThirtyTwoBytes channel_id_arg_ref;
10928         CHECK((*env)->GetArrayLength(env, channel_id_arg) == 32);
10929         (*env)->GetByteArrayRegion(env, channel_id_arg, 0, 32, channel_id_arg_ref.data);
10930         LDKThirtyTwoBytes payment_preimage_arg_ref;
10931         CHECK((*env)->GetArrayLength(env, payment_preimage_arg) == 32);
10932         (*env)->GetByteArrayRegion(env, payment_preimage_arg, 0, 32, payment_preimage_arg_ref.data);
10933         LDKUpdateFulfillHTLC ret_var = UpdateFulfillHTLC_new(channel_id_arg_ref, htlc_id_arg, payment_preimage_arg_ref);
10934         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10935         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10936         long ret_ref = (long)ret_var.inner;
10937         if (ret_var.is_owned) {
10938                 ret_ref |= 1;
10939         }
10940         return ret_ref;
10941 }
10942
10943 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateFailHTLC_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
10944         LDKUpdateFailHTLC this_ptr_conv;
10945         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10946         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10947         UpdateFailHTLC_free(this_ptr_conv);
10948 }
10949
10950 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_UpdateFailHTLC_1clone(JNIEnv *env, jclass clz, int64_t orig) {
10951         LDKUpdateFailHTLC orig_conv;
10952         orig_conv.inner = (void*)(orig & (~1));
10953         orig_conv.is_owned = false;
10954         LDKUpdateFailHTLC ret_var = UpdateFailHTLC_clone(&orig_conv);
10955         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10956         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10957         long ret_ref = (long)ret_var.inner;
10958         if (ret_var.is_owned) {
10959                 ret_ref |= 1;
10960         }
10961         return ret_ref;
10962 }
10963
10964 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_UpdateFailHTLC_1get_1channel_1id(JNIEnv *env, jclass clz, int64_t this_ptr) {
10965         LDKUpdateFailHTLC this_ptr_conv;
10966         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10967         this_ptr_conv.is_owned = false;
10968         int8_tArray ret_arr = (*env)->NewByteArray(env, 32);
10969         (*env)->SetByteArrayRegion(env, ret_arr, 0, 32, *UpdateFailHTLC_get_channel_id(&this_ptr_conv));
10970         return ret_arr;
10971 }
10972
10973 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateFailHTLC_1set_1channel_1id(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
10974         LDKUpdateFailHTLC this_ptr_conv;
10975         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10976         this_ptr_conv.is_owned = false;
10977         LDKThirtyTwoBytes val_ref;
10978         CHECK((*env)->GetArrayLength(env, val) == 32);
10979         (*env)->GetByteArrayRegion(env, val, 0, 32, val_ref.data);
10980         UpdateFailHTLC_set_channel_id(&this_ptr_conv, val_ref);
10981 }
10982
10983 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_UpdateFailHTLC_1get_1htlc_1id(JNIEnv *env, jclass clz, int64_t this_ptr) {
10984         LDKUpdateFailHTLC this_ptr_conv;
10985         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10986         this_ptr_conv.is_owned = false;
10987         int64_t ret_val = UpdateFailHTLC_get_htlc_id(&this_ptr_conv);
10988         return ret_val;
10989 }
10990
10991 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateFailHTLC_1set_1htlc_1id(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
10992         LDKUpdateFailHTLC this_ptr_conv;
10993         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10994         this_ptr_conv.is_owned = false;
10995         UpdateFailHTLC_set_htlc_id(&this_ptr_conv, val);
10996 }
10997
10998 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateFailMalformedHTLC_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
10999         LDKUpdateFailMalformedHTLC this_ptr_conv;
11000         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11001         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
11002         UpdateFailMalformedHTLC_free(this_ptr_conv);
11003 }
11004
11005 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_UpdateFailMalformedHTLC_1clone(JNIEnv *env, jclass clz, int64_t orig) {
11006         LDKUpdateFailMalformedHTLC orig_conv;
11007         orig_conv.inner = (void*)(orig & (~1));
11008         orig_conv.is_owned = false;
11009         LDKUpdateFailMalformedHTLC ret_var = UpdateFailMalformedHTLC_clone(&orig_conv);
11010         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11011         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11012         long ret_ref = (long)ret_var.inner;
11013         if (ret_var.is_owned) {
11014                 ret_ref |= 1;
11015         }
11016         return ret_ref;
11017 }
11018
11019 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_UpdateFailMalformedHTLC_1get_1channel_1id(JNIEnv *env, jclass clz, int64_t this_ptr) {
11020         LDKUpdateFailMalformedHTLC this_ptr_conv;
11021         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11022         this_ptr_conv.is_owned = false;
11023         int8_tArray ret_arr = (*env)->NewByteArray(env, 32);
11024         (*env)->SetByteArrayRegion(env, ret_arr, 0, 32, *UpdateFailMalformedHTLC_get_channel_id(&this_ptr_conv));
11025         return ret_arr;
11026 }
11027
11028 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateFailMalformedHTLC_1set_1channel_1id(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
11029         LDKUpdateFailMalformedHTLC this_ptr_conv;
11030         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11031         this_ptr_conv.is_owned = false;
11032         LDKThirtyTwoBytes val_ref;
11033         CHECK((*env)->GetArrayLength(env, val) == 32);
11034         (*env)->GetByteArrayRegion(env, val, 0, 32, val_ref.data);
11035         UpdateFailMalformedHTLC_set_channel_id(&this_ptr_conv, val_ref);
11036 }
11037
11038 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_UpdateFailMalformedHTLC_1get_1htlc_1id(JNIEnv *env, jclass clz, int64_t this_ptr) {
11039         LDKUpdateFailMalformedHTLC this_ptr_conv;
11040         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11041         this_ptr_conv.is_owned = false;
11042         int64_t ret_val = UpdateFailMalformedHTLC_get_htlc_id(&this_ptr_conv);
11043         return ret_val;
11044 }
11045
11046 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateFailMalformedHTLC_1set_1htlc_1id(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
11047         LDKUpdateFailMalformedHTLC this_ptr_conv;
11048         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11049         this_ptr_conv.is_owned = false;
11050         UpdateFailMalformedHTLC_set_htlc_id(&this_ptr_conv, val);
11051 }
11052
11053 JNIEXPORT int16_t JNICALL Java_org_ldk_impl_bindings_UpdateFailMalformedHTLC_1get_1failure_1code(JNIEnv *env, jclass clz, int64_t this_ptr) {
11054         LDKUpdateFailMalformedHTLC this_ptr_conv;
11055         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11056         this_ptr_conv.is_owned = false;
11057         int16_t ret_val = UpdateFailMalformedHTLC_get_failure_code(&this_ptr_conv);
11058         return ret_val;
11059 }
11060
11061 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateFailMalformedHTLC_1set_1failure_1code(JNIEnv *env, jclass clz, int64_t this_ptr, int16_t val) {
11062         LDKUpdateFailMalformedHTLC this_ptr_conv;
11063         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11064         this_ptr_conv.is_owned = false;
11065         UpdateFailMalformedHTLC_set_failure_code(&this_ptr_conv, val);
11066 }
11067
11068 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CommitmentSigned_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
11069         LDKCommitmentSigned this_ptr_conv;
11070         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11071         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
11072         CommitmentSigned_free(this_ptr_conv);
11073 }
11074
11075 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CommitmentSigned_1clone(JNIEnv *env, jclass clz, int64_t orig) {
11076         LDKCommitmentSigned orig_conv;
11077         orig_conv.inner = (void*)(orig & (~1));
11078         orig_conv.is_owned = false;
11079         LDKCommitmentSigned ret_var = CommitmentSigned_clone(&orig_conv);
11080         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11081         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11082         long ret_ref = (long)ret_var.inner;
11083         if (ret_var.is_owned) {
11084                 ret_ref |= 1;
11085         }
11086         return ret_ref;
11087 }
11088
11089 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_CommitmentSigned_1get_1channel_1id(JNIEnv *env, jclass clz, int64_t this_ptr) {
11090         LDKCommitmentSigned this_ptr_conv;
11091         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11092         this_ptr_conv.is_owned = false;
11093         int8_tArray ret_arr = (*env)->NewByteArray(env, 32);
11094         (*env)->SetByteArrayRegion(env, ret_arr, 0, 32, *CommitmentSigned_get_channel_id(&this_ptr_conv));
11095         return ret_arr;
11096 }
11097
11098 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CommitmentSigned_1set_1channel_1id(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
11099         LDKCommitmentSigned this_ptr_conv;
11100         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11101         this_ptr_conv.is_owned = false;
11102         LDKThirtyTwoBytes val_ref;
11103         CHECK((*env)->GetArrayLength(env, val) == 32);
11104         (*env)->GetByteArrayRegion(env, val, 0, 32, val_ref.data);
11105         CommitmentSigned_set_channel_id(&this_ptr_conv, val_ref);
11106 }
11107
11108 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_CommitmentSigned_1get_1signature(JNIEnv *env, jclass clz, int64_t this_ptr) {
11109         LDKCommitmentSigned this_ptr_conv;
11110         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11111         this_ptr_conv.is_owned = false;
11112         int8_tArray arg_arr = (*env)->NewByteArray(env, 64);
11113         (*env)->SetByteArrayRegion(env, arg_arr, 0, 64, CommitmentSigned_get_signature(&this_ptr_conv).compact_form);
11114         return arg_arr;
11115 }
11116
11117 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CommitmentSigned_1set_1signature(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
11118         LDKCommitmentSigned this_ptr_conv;
11119         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11120         this_ptr_conv.is_owned = false;
11121         LDKSignature val_ref;
11122         CHECK((*env)->GetArrayLength(env, val) == 64);
11123         (*env)->GetByteArrayRegion(env, val, 0, 64, val_ref.compact_form);
11124         CommitmentSigned_set_signature(&this_ptr_conv, val_ref);
11125 }
11126
11127 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CommitmentSigned_1set_1htlc_1signatures(JNIEnv *env, jclass clz, int64_t this_ptr, jobjectArray val) {
11128         LDKCommitmentSigned this_ptr_conv;
11129         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11130         this_ptr_conv.is_owned = false;
11131         LDKCVec_SignatureZ val_constr;
11132         val_constr.datalen = (*env)->GetArrayLength(env, val);
11133         if (val_constr.datalen > 0)
11134                 val_constr.data = MALLOC(val_constr.datalen * sizeof(LDKSignature), "LDKCVec_SignatureZ Elements");
11135         else
11136                 val_constr.data = NULL;
11137         for (size_t i = 0; i < val_constr.datalen; i++) {
11138                 int8_tArray arr_conv_8 = (*env)->GetObjectArrayElement(env, val, i);
11139                 LDKSignature arr_conv_8_ref;
11140                 CHECK((*env)->GetArrayLength(env, arr_conv_8) == 64);
11141                 (*env)->GetByteArrayRegion(env, arr_conv_8, 0, 64, arr_conv_8_ref.compact_form);
11142                 val_constr.data[i] = arr_conv_8_ref;
11143         }
11144         CommitmentSigned_set_htlc_signatures(&this_ptr_conv, val_constr);
11145 }
11146
11147 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CommitmentSigned_1new(JNIEnv *env, jclass clz, int8_tArray channel_id_arg, int8_tArray signature_arg, jobjectArray htlc_signatures_arg) {
11148         LDKThirtyTwoBytes channel_id_arg_ref;
11149         CHECK((*env)->GetArrayLength(env, channel_id_arg) == 32);
11150         (*env)->GetByteArrayRegion(env, channel_id_arg, 0, 32, channel_id_arg_ref.data);
11151         LDKSignature signature_arg_ref;
11152         CHECK((*env)->GetArrayLength(env, signature_arg) == 64);
11153         (*env)->GetByteArrayRegion(env, signature_arg, 0, 64, signature_arg_ref.compact_form);
11154         LDKCVec_SignatureZ htlc_signatures_arg_constr;
11155         htlc_signatures_arg_constr.datalen = (*env)->GetArrayLength(env, htlc_signatures_arg);
11156         if (htlc_signatures_arg_constr.datalen > 0)
11157                 htlc_signatures_arg_constr.data = MALLOC(htlc_signatures_arg_constr.datalen * sizeof(LDKSignature), "LDKCVec_SignatureZ Elements");
11158         else
11159                 htlc_signatures_arg_constr.data = NULL;
11160         for (size_t i = 0; i < htlc_signatures_arg_constr.datalen; i++) {
11161                 int8_tArray arr_conv_8 = (*env)->GetObjectArrayElement(env, htlc_signatures_arg, i);
11162                 LDKSignature arr_conv_8_ref;
11163                 CHECK((*env)->GetArrayLength(env, arr_conv_8) == 64);
11164                 (*env)->GetByteArrayRegion(env, arr_conv_8, 0, 64, arr_conv_8_ref.compact_form);
11165                 htlc_signatures_arg_constr.data[i] = arr_conv_8_ref;
11166         }
11167         LDKCommitmentSigned ret_var = CommitmentSigned_new(channel_id_arg_ref, signature_arg_ref, htlc_signatures_arg_constr);
11168         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11169         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11170         long ret_ref = (long)ret_var.inner;
11171         if (ret_var.is_owned) {
11172                 ret_ref |= 1;
11173         }
11174         return ret_ref;
11175 }
11176
11177 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RevokeAndACK_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
11178         LDKRevokeAndACK this_ptr_conv;
11179         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11180         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
11181         RevokeAndACK_free(this_ptr_conv);
11182 }
11183
11184 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_RevokeAndACK_1clone(JNIEnv *env, jclass clz, int64_t orig) {
11185         LDKRevokeAndACK orig_conv;
11186         orig_conv.inner = (void*)(orig & (~1));
11187         orig_conv.is_owned = false;
11188         LDKRevokeAndACK ret_var = RevokeAndACK_clone(&orig_conv);
11189         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11190         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11191         long ret_ref = (long)ret_var.inner;
11192         if (ret_var.is_owned) {
11193                 ret_ref |= 1;
11194         }
11195         return ret_ref;
11196 }
11197
11198 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_RevokeAndACK_1get_1channel_1id(JNIEnv *env, jclass clz, int64_t this_ptr) {
11199         LDKRevokeAndACK this_ptr_conv;
11200         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11201         this_ptr_conv.is_owned = false;
11202         int8_tArray ret_arr = (*env)->NewByteArray(env, 32);
11203         (*env)->SetByteArrayRegion(env, ret_arr, 0, 32, *RevokeAndACK_get_channel_id(&this_ptr_conv));
11204         return ret_arr;
11205 }
11206
11207 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RevokeAndACK_1set_1channel_1id(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
11208         LDKRevokeAndACK this_ptr_conv;
11209         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11210         this_ptr_conv.is_owned = false;
11211         LDKThirtyTwoBytes val_ref;
11212         CHECK((*env)->GetArrayLength(env, val) == 32);
11213         (*env)->GetByteArrayRegion(env, val, 0, 32, val_ref.data);
11214         RevokeAndACK_set_channel_id(&this_ptr_conv, val_ref);
11215 }
11216
11217 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_RevokeAndACK_1get_1per_1commitment_1secret(JNIEnv *env, jclass clz, int64_t this_ptr) {
11218         LDKRevokeAndACK this_ptr_conv;
11219         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11220         this_ptr_conv.is_owned = false;
11221         int8_tArray ret_arr = (*env)->NewByteArray(env, 32);
11222         (*env)->SetByteArrayRegion(env, ret_arr, 0, 32, *RevokeAndACK_get_per_commitment_secret(&this_ptr_conv));
11223         return ret_arr;
11224 }
11225
11226 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RevokeAndACK_1set_1per_1commitment_1secret(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
11227         LDKRevokeAndACK this_ptr_conv;
11228         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11229         this_ptr_conv.is_owned = false;
11230         LDKThirtyTwoBytes val_ref;
11231         CHECK((*env)->GetArrayLength(env, val) == 32);
11232         (*env)->GetByteArrayRegion(env, val, 0, 32, val_ref.data);
11233         RevokeAndACK_set_per_commitment_secret(&this_ptr_conv, val_ref);
11234 }
11235
11236 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_RevokeAndACK_1get_1next_1per_1commitment_1point(JNIEnv *env, jclass clz, int64_t this_ptr) {
11237         LDKRevokeAndACK this_ptr_conv;
11238         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11239         this_ptr_conv.is_owned = false;
11240         int8_tArray arg_arr = (*env)->NewByteArray(env, 33);
11241         (*env)->SetByteArrayRegion(env, arg_arr, 0, 33, RevokeAndACK_get_next_per_commitment_point(&this_ptr_conv).compressed_form);
11242         return arg_arr;
11243 }
11244
11245 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RevokeAndACK_1set_1next_1per_1commitment_1point(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
11246         LDKRevokeAndACK this_ptr_conv;
11247         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11248         this_ptr_conv.is_owned = false;
11249         LDKPublicKey val_ref;
11250         CHECK((*env)->GetArrayLength(env, val) == 33);
11251         (*env)->GetByteArrayRegion(env, val, 0, 33, val_ref.compressed_form);
11252         RevokeAndACK_set_next_per_commitment_point(&this_ptr_conv, val_ref);
11253 }
11254
11255 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_RevokeAndACK_1new(JNIEnv *env, jclass clz, int8_tArray channel_id_arg, int8_tArray per_commitment_secret_arg, int8_tArray next_per_commitment_point_arg) {
11256         LDKThirtyTwoBytes channel_id_arg_ref;
11257         CHECK((*env)->GetArrayLength(env, channel_id_arg) == 32);
11258         (*env)->GetByteArrayRegion(env, channel_id_arg, 0, 32, channel_id_arg_ref.data);
11259         LDKThirtyTwoBytes per_commitment_secret_arg_ref;
11260         CHECK((*env)->GetArrayLength(env, per_commitment_secret_arg) == 32);
11261         (*env)->GetByteArrayRegion(env, per_commitment_secret_arg, 0, 32, per_commitment_secret_arg_ref.data);
11262         LDKPublicKey next_per_commitment_point_arg_ref;
11263         CHECK((*env)->GetArrayLength(env, next_per_commitment_point_arg) == 33);
11264         (*env)->GetByteArrayRegion(env, next_per_commitment_point_arg, 0, 33, next_per_commitment_point_arg_ref.compressed_form);
11265         LDKRevokeAndACK ret_var = RevokeAndACK_new(channel_id_arg_ref, per_commitment_secret_arg_ref, next_per_commitment_point_arg_ref);
11266         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11267         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11268         long ret_ref = (long)ret_var.inner;
11269         if (ret_var.is_owned) {
11270                 ret_ref |= 1;
11271         }
11272         return ret_ref;
11273 }
11274
11275 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateFee_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
11276         LDKUpdateFee this_ptr_conv;
11277         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11278         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
11279         UpdateFee_free(this_ptr_conv);
11280 }
11281
11282 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_UpdateFee_1clone(JNIEnv *env, jclass clz, int64_t orig) {
11283         LDKUpdateFee orig_conv;
11284         orig_conv.inner = (void*)(orig & (~1));
11285         orig_conv.is_owned = false;
11286         LDKUpdateFee ret_var = UpdateFee_clone(&orig_conv);
11287         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11288         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11289         long ret_ref = (long)ret_var.inner;
11290         if (ret_var.is_owned) {
11291                 ret_ref |= 1;
11292         }
11293         return ret_ref;
11294 }
11295
11296 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_UpdateFee_1get_1channel_1id(JNIEnv *env, jclass clz, int64_t this_ptr) {
11297         LDKUpdateFee this_ptr_conv;
11298         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11299         this_ptr_conv.is_owned = false;
11300         int8_tArray ret_arr = (*env)->NewByteArray(env, 32);
11301         (*env)->SetByteArrayRegion(env, ret_arr, 0, 32, *UpdateFee_get_channel_id(&this_ptr_conv));
11302         return ret_arr;
11303 }
11304
11305 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateFee_1set_1channel_1id(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
11306         LDKUpdateFee this_ptr_conv;
11307         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11308         this_ptr_conv.is_owned = false;
11309         LDKThirtyTwoBytes val_ref;
11310         CHECK((*env)->GetArrayLength(env, val) == 32);
11311         (*env)->GetByteArrayRegion(env, val, 0, 32, val_ref.data);
11312         UpdateFee_set_channel_id(&this_ptr_conv, val_ref);
11313 }
11314
11315 JNIEXPORT int32_t JNICALL Java_org_ldk_impl_bindings_UpdateFee_1get_1feerate_1per_1kw(JNIEnv *env, jclass clz, int64_t this_ptr) {
11316         LDKUpdateFee this_ptr_conv;
11317         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11318         this_ptr_conv.is_owned = false;
11319         int32_t ret_val = UpdateFee_get_feerate_per_kw(&this_ptr_conv);
11320         return ret_val;
11321 }
11322
11323 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateFee_1set_1feerate_1per_1kw(JNIEnv *env, jclass clz, int64_t this_ptr, int32_t val) {
11324         LDKUpdateFee this_ptr_conv;
11325         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11326         this_ptr_conv.is_owned = false;
11327         UpdateFee_set_feerate_per_kw(&this_ptr_conv, val);
11328 }
11329
11330 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_UpdateFee_1new(JNIEnv *env, jclass clz, int8_tArray channel_id_arg, int32_t feerate_per_kw_arg) {
11331         LDKThirtyTwoBytes channel_id_arg_ref;
11332         CHECK((*env)->GetArrayLength(env, channel_id_arg) == 32);
11333         (*env)->GetByteArrayRegion(env, channel_id_arg, 0, 32, channel_id_arg_ref.data);
11334         LDKUpdateFee ret_var = UpdateFee_new(channel_id_arg_ref, feerate_per_kw_arg);
11335         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11336         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11337         long ret_ref = (long)ret_var.inner;
11338         if (ret_var.is_owned) {
11339                 ret_ref |= 1;
11340         }
11341         return ret_ref;
11342 }
11343
11344 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_DataLossProtect_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
11345         LDKDataLossProtect this_ptr_conv;
11346         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11347         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
11348         DataLossProtect_free(this_ptr_conv);
11349 }
11350
11351 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_DataLossProtect_1clone(JNIEnv *env, jclass clz, int64_t orig) {
11352         LDKDataLossProtect orig_conv;
11353         orig_conv.inner = (void*)(orig & (~1));
11354         orig_conv.is_owned = false;
11355         LDKDataLossProtect ret_var = DataLossProtect_clone(&orig_conv);
11356         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11357         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11358         long ret_ref = (long)ret_var.inner;
11359         if (ret_var.is_owned) {
11360                 ret_ref |= 1;
11361         }
11362         return ret_ref;
11363 }
11364
11365 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_DataLossProtect_1get_1your_1last_1per_1commitment_1secret(JNIEnv *env, jclass clz, int64_t this_ptr) {
11366         LDKDataLossProtect this_ptr_conv;
11367         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11368         this_ptr_conv.is_owned = false;
11369         int8_tArray ret_arr = (*env)->NewByteArray(env, 32);
11370         (*env)->SetByteArrayRegion(env, ret_arr, 0, 32, *DataLossProtect_get_your_last_per_commitment_secret(&this_ptr_conv));
11371         return ret_arr;
11372 }
11373
11374 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_DataLossProtect_1set_1your_1last_1per_1commitment_1secret(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
11375         LDKDataLossProtect this_ptr_conv;
11376         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11377         this_ptr_conv.is_owned = false;
11378         LDKThirtyTwoBytes val_ref;
11379         CHECK((*env)->GetArrayLength(env, val) == 32);
11380         (*env)->GetByteArrayRegion(env, val, 0, 32, val_ref.data);
11381         DataLossProtect_set_your_last_per_commitment_secret(&this_ptr_conv, val_ref);
11382 }
11383
11384 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_DataLossProtect_1get_1my_1current_1per_1commitment_1point(JNIEnv *env, jclass clz, int64_t this_ptr) {
11385         LDKDataLossProtect this_ptr_conv;
11386         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11387         this_ptr_conv.is_owned = false;
11388         int8_tArray arg_arr = (*env)->NewByteArray(env, 33);
11389         (*env)->SetByteArrayRegion(env, arg_arr, 0, 33, DataLossProtect_get_my_current_per_commitment_point(&this_ptr_conv).compressed_form);
11390         return arg_arr;
11391 }
11392
11393 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_DataLossProtect_1set_1my_1current_1per_1commitment_1point(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
11394         LDKDataLossProtect this_ptr_conv;
11395         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11396         this_ptr_conv.is_owned = false;
11397         LDKPublicKey val_ref;
11398         CHECK((*env)->GetArrayLength(env, val) == 33);
11399         (*env)->GetByteArrayRegion(env, val, 0, 33, val_ref.compressed_form);
11400         DataLossProtect_set_my_current_per_commitment_point(&this_ptr_conv, val_ref);
11401 }
11402
11403 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_DataLossProtect_1new(JNIEnv *env, jclass clz, int8_tArray your_last_per_commitment_secret_arg, int8_tArray my_current_per_commitment_point_arg) {
11404         LDKThirtyTwoBytes your_last_per_commitment_secret_arg_ref;
11405         CHECK((*env)->GetArrayLength(env, your_last_per_commitment_secret_arg) == 32);
11406         (*env)->GetByteArrayRegion(env, your_last_per_commitment_secret_arg, 0, 32, your_last_per_commitment_secret_arg_ref.data);
11407         LDKPublicKey my_current_per_commitment_point_arg_ref;
11408         CHECK((*env)->GetArrayLength(env, my_current_per_commitment_point_arg) == 33);
11409         (*env)->GetByteArrayRegion(env, my_current_per_commitment_point_arg, 0, 33, my_current_per_commitment_point_arg_ref.compressed_form);
11410         LDKDataLossProtect ret_var = DataLossProtect_new(your_last_per_commitment_secret_arg_ref, my_current_per_commitment_point_arg_ref);
11411         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11412         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11413         long ret_ref = (long)ret_var.inner;
11414         if (ret_var.is_owned) {
11415                 ret_ref |= 1;
11416         }
11417         return ret_ref;
11418 }
11419
11420 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelReestablish_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
11421         LDKChannelReestablish this_ptr_conv;
11422         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11423         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
11424         ChannelReestablish_free(this_ptr_conv);
11425 }
11426
11427 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelReestablish_1clone(JNIEnv *env, jclass clz, int64_t orig) {
11428         LDKChannelReestablish orig_conv;
11429         orig_conv.inner = (void*)(orig & (~1));
11430         orig_conv.is_owned = false;
11431         LDKChannelReestablish ret_var = ChannelReestablish_clone(&orig_conv);
11432         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11433         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11434         long ret_ref = (long)ret_var.inner;
11435         if (ret_var.is_owned) {
11436                 ret_ref |= 1;
11437         }
11438         return ret_ref;
11439 }
11440
11441 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_ChannelReestablish_1get_1channel_1id(JNIEnv *env, jclass clz, int64_t this_ptr) {
11442         LDKChannelReestablish this_ptr_conv;
11443         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11444         this_ptr_conv.is_owned = false;
11445         int8_tArray ret_arr = (*env)->NewByteArray(env, 32);
11446         (*env)->SetByteArrayRegion(env, ret_arr, 0, 32, *ChannelReestablish_get_channel_id(&this_ptr_conv));
11447         return ret_arr;
11448 }
11449
11450 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelReestablish_1set_1channel_1id(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
11451         LDKChannelReestablish this_ptr_conv;
11452         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11453         this_ptr_conv.is_owned = false;
11454         LDKThirtyTwoBytes val_ref;
11455         CHECK((*env)->GetArrayLength(env, val) == 32);
11456         (*env)->GetByteArrayRegion(env, val, 0, 32, val_ref.data);
11457         ChannelReestablish_set_channel_id(&this_ptr_conv, val_ref);
11458 }
11459
11460 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelReestablish_1get_1next_1local_1commitment_1number(JNIEnv *env, jclass clz, int64_t this_ptr) {
11461         LDKChannelReestablish this_ptr_conv;
11462         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11463         this_ptr_conv.is_owned = false;
11464         int64_t ret_val = ChannelReestablish_get_next_local_commitment_number(&this_ptr_conv);
11465         return ret_val;
11466 }
11467
11468 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelReestablish_1set_1next_1local_1commitment_1number(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
11469         LDKChannelReestablish this_ptr_conv;
11470         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11471         this_ptr_conv.is_owned = false;
11472         ChannelReestablish_set_next_local_commitment_number(&this_ptr_conv, val);
11473 }
11474
11475 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelReestablish_1get_1next_1remote_1commitment_1number(JNIEnv *env, jclass clz, int64_t this_ptr) {
11476         LDKChannelReestablish this_ptr_conv;
11477         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11478         this_ptr_conv.is_owned = false;
11479         int64_t ret_val = ChannelReestablish_get_next_remote_commitment_number(&this_ptr_conv);
11480         return ret_val;
11481 }
11482
11483 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelReestablish_1set_1next_1remote_1commitment_1number(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
11484         LDKChannelReestablish this_ptr_conv;
11485         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11486         this_ptr_conv.is_owned = false;
11487         ChannelReestablish_set_next_remote_commitment_number(&this_ptr_conv, val);
11488 }
11489
11490 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AnnouncementSignatures_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
11491         LDKAnnouncementSignatures this_ptr_conv;
11492         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11493         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
11494         AnnouncementSignatures_free(this_ptr_conv);
11495 }
11496
11497 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_AnnouncementSignatures_1clone(JNIEnv *env, jclass clz, int64_t orig) {
11498         LDKAnnouncementSignatures orig_conv;
11499         orig_conv.inner = (void*)(orig & (~1));
11500         orig_conv.is_owned = false;
11501         LDKAnnouncementSignatures ret_var = AnnouncementSignatures_clone(&orig_conv);
11502         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11503         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11504         long ret_ref = (long)ret_var.inner;
11505         if (ret_var.is_owned) {
11506                 ret_ref |= 1;
11507         }
11508         return ret_ref;
11509 }
11510
11511 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_AnnouncementSignatures_1get_1channel_1id(JNIEnv *env, jclass clz, int64_t this_ptr) {
11512         LDKAnnouncementSignatures this_ptr_conv;
11513         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11514         this_ptr_conv.is_owned = false;
11515         int8_tArray ret_arr = (*env)->NewByteArray(env, 32);
11516         (*env)->SetByteArrayRegion(env, ret_arr, 0, 32, *AnnouncementSignatures_get_channel_id(&this_ptr_conv));
11517         return ret_arr;
11518 }
11519
11520 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AnnouncementSignatures_1set_1channel_1id(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
11521         LDKAnnouncementSignatures this_ptr_conv;
11522         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11523         this_ptr_conv.is_owned = false;
11524         LDKThirtyTwoBytes val_ref;
11525         CHECK((*env)->GetArrayLength(env, val) == 32);
11526         (*env)->GetByteArrayRegion(env, val, 0, 32, val_ref.data);
11527         AnnouncementSignatures_set_channel_id(&this_ptr_conv, val_ref);
11528 }
11529
11530 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_AnnouncementSignatures_1get_1short_1channel_1id(JNIEnv *env, jclass clz, int64_t this_ptr) {
11531         LDKAnnouncementSignatures this_ptr_conv;
11532         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11533         this_ptr_conv.is_owned = false;
11534         int64_t ret_val = AnnouncementSignatures_get_short_channel_id(&this_ptr_conv);
11535         return ret_val;
11536 }
11537
11538 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AnnouncementSignatures_1set_1short_1channel_1id(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
11539         LDKAnnouncementSignatures this_ptr_conv;
11540         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11541         this_ptr_conv.is_owned = false;
11542         AnnouncementSignatures_set_short_channel_id(&this_ptr_conv, val);
11543 }
11544
11545 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_AnnouncementSignatures_1get_1node_1signature(JNIEnv *env, jclass clz, int64_t this_ptr) {
11546         LDKAnnouncementSignatures this_ptr_conv;
11547         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11548         this_ptr_conv.is_owned = false;
11549         int8_tArray arg_arr = (*env)->NewByteArray(env, 64);
11550         (*env)->SetByteArrayRegion(env, arg_arr, 0, 64, AnnouncementSignatures_get_node_signature(&this_ptr_conv).compact_form);
11551         return arg_arr;
11552 }
11553
11554 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AnnouncementSignatures_1set_1node_1signature(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
11555         LDKAnnouncementSignatures this_ptr_conv;
11556         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11557         this_ptr_conv.is_owned = false;
11558         LDKSignature val_ref;
11559         CHECK((*env)->GetArrayLength(env, val) == 64);
11560         (*env)->GetByteArrayRegion(env, val, 0, 64, val_ref.compact_form);
11561         AnnouncementSignatures_set_node_signature(&this_ptr_conv, val_ref);
11562 }
11563
11564 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_AnnouncementSignatures_1get_1bitcoin_1signature(JNIEnv *env, jclass clz, int64_t this_ptr) {
11565         LDKAnnouncementSignatures this_ptr_conv;
11566         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11567         this_ptr_conv.is_owned = false;
11568         int8_tArray arg_arr = (*env)->NewByteArray(env, 64);
11569         (*env)->SetByteArrayRegion(env, arg_arr, 0, 64, AnnouncementSignatures_get_bitcoin_signature(&this_ptr_conv).compact_form);
11570         return arg_arr;
11571 }
11572
11573 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AnnouncementSignatures_1set_1bitcoin_1signature(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
11574         LDKAnnouncementSignatures this_ptr_conv;
11575         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11576         this_ptr_conv.is_owned = false;
11577         LDKSignature val_ref;
11578         CHECK((*env)->GetArrayLength(env, val) == 64);
11579         (*env)->GetByteArrayRegion(env, val, 0, 64, val_ref.compact_form);
11580         AnnouncementSignatures_set_bitcoin_signature(&this_ptr_conv, val_ref);
11581 }
11582
11583 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_AnnouncementSignatures_1new(JNIEnv *env, jclass clz, int8_tArray channel_id_arg, int64_t short_channel_id_arg, int8_tArray node_signature_arg, int8_tArray bitcoin_signature_arg) {
11584         LDKThirtyTwoBytes channel_id_arg_ref;
11585         CHECK((*env)->GetArrayLength(env, channel_id_arg) == 32);
11586         (*env)->GetByteArrayRegion(env, channel_id_arg, 0, 32, channel_id_arg_ref.data);
11587         LDKSignature node_signature_arg_ref;
11588         CHECK((*env)->GetArrayLength(env, node_signature_arg) == 64);
11589         (*env)->GetByteArrayRegion(env, node_signature_arg, 0, 64, node_signature_arg_ref.compact_form);
11590         LDKSignature bitcoin_signature_arg_ref;
11591         CHECK((*env)->GetArrayLength(env, bitcoin_signature_arg) == 64);
11592         (*env)->GetByteArrayRegion(env, bitcoin_signature_arg, 0, 64, bitcoin_signature_arg_ref.compact_form);
11593         LDKAnnouncementSignatures ret_var = AnnouncementSignatures_new(channel_id_arg_ref, short_channel_id_arg, node_signature_arg_ref, bitcoin_signature_arg_ref);
11594         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11595         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11596         long ret_ref = (long)ret_var.inner;
11597         if (ret_var.is_owned) {
11598                 ret_ref |= 1;
11599         }
11600         return ret_ref;
11601 }
11602
11603 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NetAddress_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
11604         LDKNetAddress this_ptr_conv = *(LDKNetAddress*)this_ptr;
11605         FREE((void*)this_ptr);
11606         NetAddress_free(this_ptr_conv);
11607 }
11608
11609 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_NetAddress_1clone(JNIEnv *env, jclass clz, int64_t orig) {
11610         LDKNetAddress* orig_conv = (LDKNetAddress*)orig;
11611         LDKNetAddress *ret_copy = MALLOC(sizeof(LDKNetAddress), "LDKNetAddress");
11612         *ret_copy = NetAddress_clone(orig_conv);
11613         long ret_ref = (long)ret_copy;
11614         return ret_ref;
11615 }
11616
11617 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_NetAddress_1write(JNIEnv *env, jclass clz, int64_t obj) {
11618         LDKNetAddress* obj_conv = (LDKNetAddress*)obj;
11619         LDKCVec_u8Z arg_var = NetAddress_write(obj_conv);
11620         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
11621         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
11622         CVec_u8Z_free(arg_var);
11623         return arg_arr;
11624 }
11625
11626 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_Result_1read(JNIEnv *env, jclass clz, int8_tArray ser) {
11627         LDKu8slice ser_ref;
11628         ser_ref.datalen = (*env)->GetArrayLength(env, ser);
11629         ser_ref.data = (*env)->GetByteArrayElements (env, ser, NULL);
11630         LDKCResult_CResult_NetAddressu8ZDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_CResult_NetAddressu8ZDecodeErrorZ), "LDKCResult_CResult_NetAddressu8ZDecodeErrorZ");
11631         *ret_conv = Result_read(ser_ref);
11632         (*env)->ReleaseByteArrayElements(env, ser, (int8_t*)ser_ref.data, 0);
11633         return (long)ret_conv;
11634 }
11635
11636 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedNodeAnnouncement_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
11637         LDKUnsignedNodeAnnouncement this_ptr_conv;
11638         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11639         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
11640         UnsignedNodeAnnouncement_free(this_ptr_conv);
11641 }
11642
11643 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_UnsignedNodeAnnouncement_1clone(JNIEnv *env, jclass clz, int64_t orig) {
11644         LDKUnsignedNodeAnnouncement orig_conv;
11645         orig_conv.inner = (void*)(orig & (~1));
11646         orig_conv.is_owned = false;
11647         LDKUnsignedNodeAnnouncement ret_var = UnsignedNodeAnnouncement_clone(&orig_conv);
11648         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11649         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11650         long ret_ref = (long)ret_var.inner;
11651         if (ret_var.is_owned) {
11652                 ret_ref |= 1;
11653         }
11654         return ret_ref;
11655 }
11656
11657 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_UnsignedNodeAnnouncement_1get_1features(JNIEnv *env, jclass clz, int64_t this_ptr) {
11658         LDKUnsignedNodeAnnouncement this_ptr_conv;
11659         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11660         this_ptr_conv.is_owned = false;
11661         LDKNodeFeatures ret_var = UnsignedNodeAnnouncement_get_features(&this_ptr_conv);
11662         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11663         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11664         long ret_ref = (long)ret_var.inner;
11665         if (ret_var.is_owned) {
11666                 ret_ref |= 1;
11667         }
11668         return ret_ref;
11669 }
11670
11671 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedNodeAnnouncement_1set_1features(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
11672         LDKUnsignedNodeAnnouncement this_ptr_conv;
11673         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11674         this_ptr_conv.is_owned = false;
11675         LDKNodeFeatures val_conv;
11676         val_conv.inner = (void*)(val & (~1));
11677         val_conv.is_owned = (val & 1) || (val == 0);
11678         // Warning: we may need a move here but can't clone!
11679         UnsignedNodeAnnouncement_set_features(&this_ptr_conv, val_conv);
11680 }
11681
11682 JNIEXPORT int32_t JNICALL Java_org_ldk_impl_bindings_UnsignedNodeAnnouncement_1get_1timestamp(JNIEnv *env, jclass clz, int64_t this_ptr) {
11683         LDKUnsignedNodeAnnouncement this_ptr_conv;
11684         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11685         this_ptr_conv.is_owned = false;
11686         int32_t ret_val = UnsignedNodeAnnouncement_get_timestamp(&this_ptr_conv);
11687         return ret_val;
11688 }
11689
11690 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedNodeAnnouncement_1set_1timestamp(JNIEnv *env, jclass clz, int64_t this_ptr, int32_t val) {
11691         LDKUnsignedNodeAnnouncement this_ptr_conv;
11692         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11693         this_ptr_conv.is_owned = false;
11694         UnsignedNodeAnnouncement_set_timestamp(&this_ptr_conv, val);
11695 }
11696
11697 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_UnsignedNodeAnnouncement_1get_1node_1id(JNIEnv *env, jclass clz, int64_t this_ptr) {
11698         LDKUnsignedNodeAnnouncement this_ptr_conv;
11699         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11700         this_ptr_conv.is_owned = false;
11701         int8_tArray arg_arr = (*env)->NewByteArray(env, 33);
11702         (*env)->SetByteArrayRegion(env, arg_arr, 0, 33, UnsignedNodeAnnouncement_get_node_id(&this_ptr_conv).compressed_form);
11703         return arg_arr;
11704 }
11705
11706 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedNodeAnnouncement_1set_1node_1id(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
11707         LDKUnsignedNodeAnnouncement this_ptr_conv;
11708         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11709         this_ptr_conv.is_owned = false;
11710         LDKPublicKey val_ref;
11711         CHECK((*env)->GetArrayLength(env, val) == 33);
11712         (*env)->GetByteArrayRegion(env, val, 0, 33, val_ref.compressed_form);
11713         UnsignedNodeAnnouncement_set_node_id(&this_ptr_conv, val_ref);
11714 }
11715
11716 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_UnsignedNodeAnnouncement_1get_1rgb(JNIEnv *env, jclass clz, int64_t this_ptr) {
11717         LDKUnsignedNodeAnnouncement this_ptr_conv;
11718         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11719         this_ptr_conv.is_owned = false;
11720         int8_tArray ret_arr = (*env)->NewByteArray(env, 3);
11721         (*env)->SetByteArrayRegion(env, ret_arr, 0, 3, *UnsignedNodeAnnouncement_get_rgb(&this_ptr_conv));
11722         return ret_arr;
11723 }
11724
11725 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedNodeAnnouncement_1set_1rgb(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
11726         LDKUnsignedNodeAnnouncement this_ptr_conv;
11727         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11728         this_ptr_conv.is_owned = false;
11729         LDKThreeBytes val_ref;
11730         CHECK((*env)->GetArrayLength(env, val) == 3);
11731         (*env)->GetByteArrayRegion(env, val, 0, 3, val_ref.data);
11732         UnsignedNodeAnnouncement_set_rgb(&this_ptr_conv, val_ref);
11733 }
11734
11735 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_UnsignedNodeAnnouncement_1get_1alias(JNIEnv *env, jclass clz, int64_t this_ptr) {
11736         LDKUnsignedNodeAnnouncement this_ptr_conv;
11737         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11738         this_ptr_conv.is_owned = false;
11739         int8_tArray ret_arr = (*env)->NewByteArray(env, 32);
11740         (*env)->SetByteArrayRegion(env, ret_arr, 0, 32, *UnsignedNodeAnnouncement_get_alias(&this_ptr_conv));
11741         return ret_arr;
11742 }
11743
11744 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedNodeAnnouncement_1set_1alias(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
11745         LDKUnsignedNodeAnnouncement this_ptr_conv;
11746         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11747         this_ptr_conv.is_owned = false;
11748         LDKThirtyTwoBytes val_ref;
11749         CHECK((*env)->GetArrayLength(env, val) == 32);
11750         (*env)->GetByteArrayRegion(env, val, 0, 32, val_ref.data);
11751         UnsignedNodeAnnouncement_set_alias(&this_ptr_conv, val_ref);
11752 }
11753
11754 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedNodeAnnouncement_1set_1addresses(JNIEnv *env, jclass clz, int64_t this_ptr, int64_tArray val) {
11755         LDKUnsignedNodeAnnouncement this_ptr_conv;
11756         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11757         this_ptr_conv.is_owned = false;
11758         LDKCVec_NetAddressZ val_constr;
11759         val_constr.datalen = (*env)->GetArrayLength(env, val);
11760         if (val_constr.datalen > 0)
11761                 val_constr.data = MALLOC(val_constr.datalen * sizeof(LDKNetAddress), "LDKCVec_NetAddressZ Elements");
11762         else
11763                 val_constr.data = NULL;
11764         int64_t* val_vals = (*env)->GetLongArrayElements (env, val, NULL);
11765         for (size_t m = 0; m < val_constr.datalen; m++) {
11766                 int64_t arr_conv_12 = val_vals[m];
11767                 LDKNetAddress arr_conv_12_conv = *(LDKNetAddress*)arr_conv_12;
11768                 FREE((void*)arr_conv_12);
11769                 val_constr.data[m] = arr_conv_12_conv;
11770         }
11771         (*env)->ReleaseLongArrayElements(env, val, val_vals, 0);
11772         UnsignedNodeAnnouncement_set_addresses(&this_ptr_conv, val_constr);
11773 }
11774
11775 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NodeAnnouncement_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
11776         LDKNodeAnnouncement this_ptr_conv;
11777         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11778         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
11779         NodeAnnouncement_free(this_ptr_conv);
11780 }
11781
11782 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_NodeAnnouncement_1clone(JNIEnv *env, jclass clz, int64_t orig) {
11783         LDKNodeAnnouncement orig_conv;
11784         orig_conv.inner = (void*)(orig & (~1));
11785         orig_conv.is_owned = false;
11786         LDKNodeAnnouncement ret_var = NodeAnnouncement_clone(&orig_conv);
11787         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11788         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11789         long ret_ref = (long)ret_var.inner;
11790         if (ret_var.is_owned) {
11791                 ret_ref |= 1;
11792         }
11793         return ret_ref;
11794 }
11795
11796 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_NodeAnnouncement_1get_1signature(JNIEnv *env, jclass clz, int64_t this_ptr) {
11797         LDKNodeAnnouncement this_ptr_conv;
11798         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11799         this_ptr_conv.is_owned = false;
11800         int8_tArray arg_arr = (*env)->NewByteArray(env, 64);
11801         (*env)->SetByteArrayRegion(env, arg_arr, 0, 64, NodeAnnouncement_get_signature(&this_ptr_conv).compact_form);
11802         return arg_arr;
11803 }
11804
11805 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NodeAnnouncement_1set_1signature(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
11806         LDKNodeAnnouncement this_ptr_conv;
11807         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11808         this_ptr_conv.is_owned = false;
11809         LDKSignature val_ref;
11810         CHECK((*env)->GetArrayLength(env, val) == 64);
11811         (*env)->GetByteArrayRegion(env, val, 0, 64, val_ref.compact_form);
11812         NodeAnnouncement_set_signature(&this_ptr_conv, val_ref);
11813 }
11814
11815 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_NodeAnnouncement_1get_1contents(JNIEnv *env, jclass clz, int64_t this_ptr) {
11816         LDKNodeAnnouncement this_ptr_conv;
11817         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11818         this_ptr_conv.is_owned = false;
11819         LDKUnsignedNodeAnnouncement ret_var = NodeAnnouncement_get_contents(&this_ptr_conv);
11820         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11821         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11822         long ret_ref = (long)ret_var.inner;
11823         if (ret_var.is_owned) {
11824                 ret_ref |= 1;
11825         }
11826         return ret_ref;
11827 }
11828
11829 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NodeAnnouncement_1set_1contents(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
11830         LDKNodeAnnouncement this_ptr_conv;
11831         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11832         this_ptr_conv.is_owned = false;
11833         LDKUnsignedNodeAnnouncement val_conv;
11834         val_conv.inner = (void*)(val & (~1));
11835         val_conv.is_owned = (val & 1) || (val == 0);
11836         if (val_conv.inner != NULL)
11837                 val_conv = UnsignedNodeAnnouncement_clone(&val_conv);
11838         NodeAnnouncement_set_contents(&this_ptr_conv, val_conv);
11839 }
11840
11841 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_NodeAnnouncement_1new(JNIEnv *env, jclass clz, int8_tArray signature_arg, int64_t contents_arg) {
11842         LDKSignature signature_arg_ref;
11843         CHECK((*env)->GetArrayLength(env, signature_arg) == 64);
11844         (*env)->GetByteArrayRegion(env, signature_arg, 0, 64, signature_arg_ref.compact_form);
11845         LDKUnsignedNodeAnnouncement contents_arg_conv;
11846         contents_arg_conv.inner = (void*)(contents_arg & (~1));
11847         contents_arg_conv.is_owned = (contents_arg & 1) || (contents_arg == 0);
11848         if (contents_arg_conv.inner != NULL)
11849                 contents_arg_conv = UnsignedNodeAnnouncement_clone(&contents_arg_conv);
11850         LDKNodeAnnouncement ret_var = NodeAnnouncement_new(signature_arg_ref, contents_arg_conv);
11851         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11852         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11853         long ret_ref = (long)ret_var.inner;
11854         if (ret_var.is_owned) {
11855                 ret_ref |= 1;
11856         }
11857         return ret_ref;
11858 }
11859
11860 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
11861         LDKUnsignedChannelAnnouncement this_ptr_conv;
11862         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11863         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
11864         UnsignedChannelAnnouncement_free(this_ptr_conv);
11865 }
11866
11867 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1clone(JNIEnv *env, jclass clz, int64_t orig) {
11868         LDKUnsignedChannelAnnouncement orig_conv;
11869         orig_conv.inner = (void*)(orig & (~1));
11870         orig_conv.is_owned = false;
11871         LDKUnsignedChannelAnnouncement ret_var = UnsignedChannelAnnouncement_clone(&orig_conv);
11872         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11873         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11874         long ret_ref = (long)ret_var.inner;
11875         if (ret_var.is_owned) {
11876                 ret_ref |= 1;
11877         }
11878         return ret_ref;
11879 }
11880
11881 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1get_1features(JNIEnv *env, jclass clz, int64_t this_ptr) {
11882         LDKUnsignedChannelAnnouncement this_ptr_conv;
11883         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11884         this_ptr_conv.is_owned = false;
11885         LDKChannelFeatures ret_var = UnsignedChannelAnnouncement_get_features(&this_ptr_conv);
11886         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11887         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11888         long ret_ref = (long)ret_var.inner;
11889         if (ret_var.is_owned) {
11890                 ret_ref |= 1;
11891         }
11892         return ret_ref;
11893 }
11894
11895 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1set_1features(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
11896         LDKUnsignedChannelAnnouncement this_ptr_conv;
11897         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11898         this_ptr_conv.is_owned = false;
11899         LDKChannelFeatures val_conv;
11900         val_conv.inner = (void*)(val & (~1));
11901         val_conv.is_owned = (val & 1) || (val == 0);
11902         // Warning: we may need a move here but can't clone!
11903         UnsignedChannelAnnouncement_set_features(&this_ptr_conv, val_conv);
11904 }
11905
11906 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1get_1chain_1hash(JNIEnv *env, jclass clz, int64_t this_ptr) {
11907         LDKUnsignedChannelAnnouncement this_ptr_conv;
11908         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11909         this_ptr_conv.is_owned = false;
11910         int8_tArray ret_arr = (*env)->NewByteArray(env, 32);
11911         (*env)->SetByteArrayRegion(env, ret_arr, 0, 32, *UnsignedChannelAnnouncement_get_chain_hash(&this_ptr_conv));
11912         return ret_arr;
11913 }
11914
11915 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1set_1chain_1hash(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
11916         LDKUnsignedChannelAnnouncement this_ptr_conv;
11917         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11918         this_ptr_conv.is_owned = false;
11919         LDKThirtyTwoBytes val_ref;
11920         CHECK((*env)->GetArrayLength(env, val) == 32);
11921         (*env)->GetByteArrayRegion(env, val, 0, 32, val_ref.data);
11922         UnsignedChannelAnnouncement_set_chain_hash(&this_ptr_conv, val_ref);
11923 }
11924
11925 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1get_1short_1channel_1id(JNIEnv *env, jclass clz, int64_t this_ptr) {
11926         LDKUnsignedChannelAnnouncement this_ptr_conv;
11927         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11928         this_ptr_conv.is_owned = false;
11929         int64_t ret_val = UnsignedChannelAnnouncement_get_short_channel_id(&this_ptr_conv);
11930         return ret_val;
11931 }
11932
11933 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1set_1short_1channel_1id(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
11934         LDKUnsignedChannelAnnouncement this_ptr_conv;
11935         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11936         this_ptr_conv.is_owned = false;
11937         UnsignedChannelAnnouncement_set_short_channel_id(&this_ptr_conv, val);
11938 }
11939
11940 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1get_1node_1id_11(JNIEnv *env, jclass clz, int64_t this_ptr) {
11941         LDKUnsignedChannelAnnouncement this_ptr_conv;
11942         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11943         this_ptr_conv.is_owned = false;
11944         int8_tArray arg_arr = (*env)->NewByteArray(env, 33);
11945         (*env)->SetByteArrayRegion(env, arg_arr, 0, 33, UnsignedChannelAnnouncement_get_node_id_1(&this_ptr_conv).compressed_form);
11946         return arg_arr;
11947 }
11948
11949 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1set_1node_1id_11(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
11950         LDKUnsignedChannelAnnouncement this_ptr_conv;
11951         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11952         this_ptr_conv.is_owned = false;
11953         LDKPublicKey val_ref;
11954         CHECK((*env)->GetArrayLength(env, val) == 33);
11955         (*env)->GetByteArrayRegion(env, val, 0, 33, val_ref.compressed_form);
11956         UnsignedChannelAnnouncement_set_node_id_1(&this_ptr_conv, val_ref);
11957 }
11958
11959 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1get_1node_1id_12(JNIEnv *env, jclass clz, int64_t this_ptr) {
11960         LDKUnsignedChannelAnnouncement this_ptr_conv;
11961         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11962         this_ptr_conv.is_owned = false;
11963         int8_tArray arg_arr = (*env)->NewByteArray(env, 33);
11964         (*env)->SetByteArrayRegion(env, arg_arr, 0, 33, UnsignedChannelAnnouncement_get_node_id_2(&this_ptr_conv).compressed_form);
11965         return arg_arr;
11966 }
11967
11968 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1set_1node_1id_12(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
11969         LDKUnsignedChannelAnnouncement this_ptr_conv;
11970         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11971         this_ptr_conv.is_owned = false;
11972         LDKPublicKey val_ref;
11973         CHECK((*env)->GetArrayLength(env, val) == 33);
11974         (*env)->GetByteArrayRegion(env, val, 0, 33, val_ref.compressed_form);
11975         UnsignedChannelAnnouncement_set_node_id_2(&this_ptr_conv, val_ref);
11976 }
11977
11978 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1get_1bitcoin_1key_11(JNIEnv *env, jclass clz, int64_t this_ptr) {
11979         LDKUnsignedChannelAnnouncement this_ptr_conv;
11980         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11981         this_ptr_conv.is_owned = false;
11982         int8_tArray arg_arr = (*env)->NewByteArray(env, 33);
11983         (*env)->SetByteArrayRegion(env, arg_arr, 0, 33, UnsignedChannelAnnouncement_get_bitcoin_key_1(&this_ptr_conv).compressed_form);
11984         return arg_arr;
11985 }
11986
11987 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1set_1bitcoin_1key_11(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
11988         LDKUnsignedChannelAnnouncement this_ptr_conv;
11989         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11990         this_ptr_conv.is_owned = false;
11991         LDKPublicKey val_ref;
11992         CHECK((*env)->GetArrayLength(env, val) == 33);
11993         (*env)->GetByteArrayRegion(env, val, 0, 33, val_ref.compressed_form);
11994         UnsignedChannelAnnouncement_set_bitcoin_key_1(&this_ptr_conv, val_ref);
11995 }
11996
11997 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1get_1bitcoin_1key_12(JNIEnv *env, jclass clz, int64_t this_ptr) {
11998         LDKUnsignedChannelAnnouncement this_ptr_conv;
11999         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12000         this_ptr_conv.is_owned = false;
12001         int8_tArray arg_arr = (*env)->NewByteArray(env, 33);
12002         (*env)->SetByteArrayRegion(env, arg_arr, 0, 33, UnsignedChannelAnnouncement_get_bitcoin_key_2(&this_ptr_conv).compressed_form);
12003         return arg_arr;
12004 }
12005
12006 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1set_1bitcoin_1key_12(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
12007         LDKUnsignedChannelAnnouncement this_ptr_conv;
12008         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12009         this_ptr_conv.is_owned = false;
12010         LDKPublicKey val_ref;
12011         CHECK((*env)->GetArrayLength(env, val) == 33);
12012         (*env)->GetByteArrayRegion(env, val, 0, 33, val_ref.compressed_form);
12013         UnsignedChannelAnnouncement_set_bitcoin_key_2(&this_ptr_conv, val_ref);
12014 }
12015
12016 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelAnnouncement_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
12017         LDKChannelAnnouncement this_ptr_conv;
12018         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12019         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12020         ChannelAnnouncement_free(this_ptr_conv);
12021 }
12022
12023 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelAnnouncement_1clone(JNIEnv *env, jclass clz, int64_t orig) {
12024         LDKChannelAnnouncement orig_conv;
12025         orig_conv.inner = (void*)(orig & (~1));
12026         orig_conv.is_owned = false;
12027         LDKChannelAnnouncement ret_var = ChannelAnnouncement_clone(&orig_conv);
12028         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12029         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12030         long ret_ref = (long)ret_var.inner;
12031         if (ret_var.is_owned) {
12032                 ret_ref |= 1;
12033         }
12034         return ret_ref;
12035 }
12036
12037 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_ChannelAnnouncement_1get_1node_1signature_11(JNIEnv *env, jclass clz, int64_t this_ptr) {
12038         LDKChannelAnnouncement this_ptr_conv;
12039         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12040         this_ptr_conv.is_owned = false;
12041         int8_tArray arg_arr = (*env)->NewByteArray(env, 64);
12042         (*env)->SetByteArrayRegion(env, arg_arr, 0, 64, ChannelAnnouncement_get_node_signature_1(&this_ptr_conv).compact_form);
12043         return arg_arr;
12044 }
12045
12046 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelAnnouncement_1set_1node_1signature_11(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
12047         LDKChannelAnnouncement this_ptr_conv;
12048         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12049         this_ptr_conv.is_owned = false;
12050         LDKSignature val_ref;
12051         CHECK((*env)->GetArrayLength(env, val) == 64);
12052         (*env)->GetByteArrayRegion(env, val, 0, 64, val_ref.compact_form);
12053         ChannelAnnouncement_set_node_signature_1(&this_ptr_conv, val_ref);
12054 }
12055
12056 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_ChannelAnnouncement_1get_1node_1signature_12(JNIEnv *env, jclass clz, int64_t this_ptr) {
12057         LDKChannelAnnouncement this_ptr_conv;
12058         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12059         this_ptr_conv.is_owned = false;
12060         int8_tArray arg_arr = (*env)->NewByteArray(env, 64);
12061         (*env)->SetByteArrayRegion(env, arg_arr, 0, 64, ChannelAnnouncement_get_node_signature_2(&this_ptr_conv).compact_form);
12062         return arg_arr;
12063 }
12064
12065 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelAnnouncement_1set_1node_1signature_12(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
12066         LDKChannelAnnouncement this_ptr_conv;
12067         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12068         this_ptr_conv.is_owned = false;
12069         LDKSignature val_ref;
12070         CHECK((*env)->GetArrayLength(env, val) == 64);
12071         (*env)->GetByteArrayRegion(env, val, 0, 64, val_ref.compact_form);
12072         ChannelAnnouncement_set_node_signature_2(&this_ptr_conv, val_ref);
12073 }
12074
12075 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_ChannelAnnouncement_1get_1bitcoin_1signature_11(JNIEnv *env, jclass clz, int64_t this_ptr) {
12076         LDKChannelAnnouncement this_ptr_conv;
12077         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12078         this_ptr_conv.is_owned = false;
12079         int8_tArray arg_arr = (*env)->NewByteArray(env, 64);
12080         (*env)->SetByteArrayRegion(env, arg_arr, 0, 64, ChannelAnnouncement_get_bitcoin_signature_1(&this_ptr_conv).compact_form);
12081         return arg_arr;
12082 }
12083
12084 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelAnnouncement_1set_1bitcoin_1signature_11(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
12085         LDKChannelAnnouncement this_ptr_conv;
12086         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12087         this_ptr_conv.is_owned = false;
12088         LDKSignature val_ref;
12089         CHECK((*env)->GetArrayLength(env, val) == 64);
12090         (*env)->GetByteArrayRegion(env, val, 0, 64, val_ref.compact_form);
12091         ChannelAnnouncement_set_bitcoin_signature_1(&this_ptr_conv, val_ref);
12092 }
12093
12094 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_ChannelAnnouncement_1get_1bitcoin_1signature_12(JNIEnv *env, jclass clz, int64_t this_ptr) {
12095         LDKChannelAnnouncement this_ptr_conv;
12096         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12097         this_ptr_conv.is_owned = false;
12098         int8_tArray arg_arr = (*env)->NewByteArray(env, 64);
12099         (*env)->SetByteArrayRegion(env, arg_arr, 0, 64, ChannelAnnouncement_get_bitcoin_signature_2(&this_ptr_conv).compact_form);
12100         return arg_arr;
12101 }
12102
12103 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelAnnouncement_1set_1bitcoin_1signature_12(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
12104         LDKChannelAnnouncement this_ptr_conv;
12105         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12106         this_ptr_conv.is_owned = false;
12107         LDKSignature val_ref;
12108         CHECK((*env)->GetArrayLength(env, val) == 64);
12109         (*env)->GetByteArrayRegion(env, val, 0, 64, val_ref.compact_form);
12110         ChannelAnnouncement_set_bitcoin_signature_2(&this_ptr_conv, val_ref);
12111 }
12112
12113 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelAnnouncement_1get_1contents(JNIEnv *env, jclass clz, int64_t this_ptr) {
12114         LDKChannelAnnouncement this_ptr_conv;
12115         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12116         this_ptr_conv.is_owned = false;
12117         LDKUnsignedChannelAnnouncement ret_var = ChannelAnnouncement_get_contents(&this_ptr_conv);
12118         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12119         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12120         long ret_ref = (long)ret_var.inner;
12121         if (ret_var.is_owned) {
12122                 ret_ref |= 1;
12123         }
12124         return ret_ref;
12125 }
12126
12127 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelAnnouncement_1set_1contents(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
12128         LDKChannelAnnouncement this_ptr_conv;
12129         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12130         this_ptr_conv.is_owned = false;
12131         LDKUnsignedChannelAnnouncement val_conv;
12132         val_conv.inner = (void*)(val & (~1));
12133         val_conv.is_owned = (val & 1) || (val == 0);
12134         if (val_conv.inner != NULL)
12135                 val_conv = UnsignedChannelAnnouncement_clone(&val_conv);
12136         ChannelAnnouncement_set_contents(&this_ptr_conv, val_conv);
12137 }
12138
12139 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelAnnouncement_1new(JNIEnv *env, jclass clz, int8_tArray node_signature_1_arg, int8_tArray node_signature_2_arg, int8_tArray bitcoin_signature_1_arg, int8_tArray bitcoin_signature_2_arg, int64_t contents_arg) {
12140         LDKSignature node_signature_1_arg_ref;
12141         CHECK((*env)->GetArrayLength(env, node_signature_1_arg) == 64);
12142         (*env)->GetByteArrayRegion(env, node_signature_1_arg, 0, 64, node_signature_1_arg_ref.compact_form);
12143         LDKSignature node_signature_2_arg_ref;
12144         CHECK((*env)->GetArrayLength(env, node_signature_2_arg) == 64);
12145         (*env)->GetByteArrayRegion(env, node_signature_2_arg, 0, 64, node_signature_2_arg_ref.compact_form);
12146         LDKSignature bitcoin_signature_1_arg_ref;
12147         CHECK((*env)->GetArrayLength(env, bitcoin_signature_1_arg) == 64);
12148         (*env)->GetByteArrayRegion(env, bitcoin_signature_1_arg, 0, 64, bitcoin_signature_1_arg_ref.compact_form);
12149         LDKSignature bitcoin_signature_2_arg_ref;
12150         CHECK((*env)->GetArrayLength(env, bitcoin_signature_2_arg) == 64);
12151         (*env)->GetByteArrayRegion(env, bitcoin_signature_2_arg, 0, 64, bitcoin_signature_2_arg_ref.compact_form);
12152         LDKUnsignedChannelAnnouncement contents_arg_conv;
12153         contents_arg_conv.inner = (void*)(contents_arg & (~1));
12154         contents_arg_conv.is_owned = (contents_arg & 1) || (contents_arg == 0);
12155         if (contents_arg_conv.inner != NULL)
12156                 contents_arg_conv = UnsignedChannelAnnouncement_clone(&contents_arg_conv);
12157         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);
12158         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12159         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12160         long ret_ref = (long)ret_var.inner;
12161         if (ret_var.is_owned) {
12162                 ret_ref |= 1;
12163         }
12164         return ret_ref;
12165 }
12166
12167 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
12168         LDKUnsignedChannelUpdate this_ptr_conv;
12169         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12170         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12171         UnsignedChannelUpdate_free(this_ptr_conv);
12172 }
12173
12174 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1clone(JNIEnv *env, jclass clz, int64_t orig) {
12175         LDKUnsignedChannelUpdate orig_conv;
12176         orig_conv.inner = (void*)(orig & (~1));
12177         orig_conv.is_owned = false;
12178         LDKUnsignedChannelUpdate ret_var = UnsignedChannelUpdate_clone(&orig_conv);
12179         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12180         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12181         long ret_ref = (long)ret_var.inner;
12182         if (ret_var.is_owned) {
12183                 ret_ref |= 1;
12184         }
12185         return ret_ref;
12186 }
12187
12188 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1get_1chain_1hash(JNIEnv *env, jclass clz, int64_t this_ptr) {
12189         LDKUnsignedChannelUpdate this_ptr_conv;
12190         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12191         this_ptr_conv.is_owned = false;
12192         int8_tArray ret_arr = (*env)->NewByteArray(env, 32);
12193         (*env)->SetByteArrayRegion(env, ret_arr, 0, 32, *UnsignedChannelUpdate_get_chain_hash(&this_ptr_conv));
12194         return ret_arr;
12195 }
12196
12197 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1set_1chain_1hash(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
12198         LDKUnsignedChannelUpdate this_ptr_conv;
12199         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12200         this_ptr_conv.is_owned = false;
12201         LDKThirtyTwoBytes val_ref;
12202         CHECK((*env)->GetArrayLength(env, val) == 32);
12203         (*env)->GetByteArrayRegion(env, val, 0, 32, val_ref.data);
12204         UnsignedChannelUpdate_set_chain_hash(&this_ptr_conv, val_ref);
12205 }
12206
12207 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1get_1short_1channel_1id(JNIEnv *env, jclass clz, int64_t this_ptr) {
12208         LDKUnsignedChannelUpdate this_ptr_conv;
12209         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12210         this_ptr_conv.is_owned = false;
12211         int64_t ret_val = UnsignedChannelUpdate_get_short_channel_id(&this_ptr_conv);
12212         return ret_val;
12213 }
12214
12215 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1set_1short_1channel_1id(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
12216         LDKUnsignedChannelUpdate this_ptr_conv;
12217         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12218         this_ptr_conv.is_owned = false;
12219         UnsignedChannelUpdate_set_short_channel_id(&this_ptr_conv, val);
12220 }
12221
12222 JNIEXPORT int32_t JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1get_1timestamp(JNIEnv *env, jclass clz, int64_t this_ptr) {
12223         LDKUnsignedChannelUpdate this_ptr_conv;
12224         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12225         this_ptr_conv.is_owned = false;
12226         int32_t ret_val = UnsignedChannelUpdate_get_timestamp(&this_ptr_conv);
12227         return ret_val;
12228 }
12229
12230 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1set_1timestamp(JNIEnv *env, jclass clz, int64_t this_ptr, int32_t val) {
12231         LDKUnsignedChannelUpdate this_ptr_conv;
12232         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12233         this_ptr_conv.is_owned = false;
12234         UnsignedChannelUpdate_set_timestamp(&this_ptr_conv, val);
12235 }
12236
12237 JNIEXPORT int8_t JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1get_1flags(JNIEnv *env, jclass clz, int64_t this_ptr) {
12238         LDKUnsignedChannelUpdate this_ptr_conv;
12239         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12240         this_ptr_conv.is_owned = false;
12241         int8_t ret_val = UnsignedChannelUpdate_get_flags(&this_ptr_conv);
12242         return ret_val;
12243 }
12244
12245 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1set_1flags(JNIEnv *env, jclass clz, int64_t this_ptr, int8_t val) {
12246         LDKUnsignedChannelUpdate this_ptr_conv;
12247         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12248         this_ptr_conv.is_owned = false;
12249         UnsignedChannelUpdate_set_flags(&this_ptr_conv, val);
12250 }
12251
12252 JNIEXPORT int16_t JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1get_1cltv_1expiry_1delta(JNIEnv *env, jclass clz, int64_t this_ptr) {
12253         LDKUnsignedChannelUpdate this_ptr_conv;
12254         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12255         this_ptr_conv.is_owned = false;
12256         int16_t ret_val = UnsignedChannelUpdate_get_cltv_expiry_delta(&this_ptr_conv);
12257         return ret_val;
12258 }
12259
12260 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1set_1cltv_1expiry_1delta(JNIEnv *env, jclass clz, int64_t this_ptr, int16_t val) {
12261         LDKUnsignedChannelUpdate this_ptr_conv;
12262         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12263         this_ptr_conv.is_owned = false;
12264         UnsignedChannelUpdate_set_cltv_expiry_delta(&this_ptr_conv, val);
12265 }
12266
12267 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1get_1htlc_1minimum_1msat(JNIEnv *env, jclass clz, int64_t this_ptr) {
12268         LDKUnsignedChannelUpdate this_ptr_conv;
12269         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12270         this_ptr_conv.is_owned = false;
12271         int64_t ret_val = UnsignedChannelUpdate_get_htlc_minimum_msat(&this_ptr_conv);
12272         return ret_val;
12273 }
12274
12275 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1set_1htlc_1minimum_1msat(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
12276         LDKUnsignedChannelUpdate this_ptr_conv;
12277         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12278         this_ptr_conv.is_owned = false;
12279         UnsignedChannelUpdate_set_htlc_minimum_msat(&this_ptr_conv, val);
12280 }
12281
12282 JNIEXPORT int32_t JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1get_1fee_1base_1msat(JNIEnv *env, jclass clz, int64_t this_ptr) {
12283         LDKUnsignedChannelUpdate this_ptr_conv;
12284         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12285         this_ptr_conv.is_owned = false;
12286         int32_t ret_val = UnsignedChannelUpdate_get_fee_base_msat(&this_ptr_conv);
12287         return ret_val;
12288 }
12289
12290 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1set_1fee_1base_1msat(JNIEnv *env, jclass clz, int64_t this_ptr, int32_t val) {
12291         LDKUnsignedChannelUpdate this_ptr_conv;
12292         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12293         this_ptr_conv.is_owned = false;
12294         UnsignedChannelUpdate_set_fee_base_msat(&this_ptr_conv, val);
12295 }
12296
12297 JNIEXPORT int32_t JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1get_1fee_1proportional_1millionths(JNIEnv *env, jclass clz, int64_t this_ptr) {
12298         LDKUnsignedChannelUpdate this_ptr_conv;
12299         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12300         this_ptr_conv.is_owned = false;
12301         int32_t ret_val = UnsignedChannelUpdate_get_fee_proportional_millionths(&this_ptr_conv);
12302         return ret_val;
12303 }
12304
12305 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1set_1fee_1proportional_1millionths(JNIEnv *env, jclass clz, int64_t this_ptr, int32_t val) {
12306         LDKUnsignedChannelUpdate this_ptr_conv;
12307         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12308         this_ptr_conv.is_owned = false;
12309         UnsignedChannelUpdate_set_fee_proportional_millionths(&this_ptr_conv, val);
12310 }
12311
12312 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelUpdate_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
12313         LDKChannelUpdate this_ptr_conv;
12314         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12315         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12316         ChannelUpdate_free(this_ptr_conv);
12317 }
12318
12319 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelUpdate_1clone(JNIEnv *env, jclass clz, int64_t orig) {
12320         LDKChannelUpdate orig_conv;
12321         orig_conv.inner = (void*)(orig & (~1));
12322         orig_conv.is_owned = false;
12323         LDKChannelUpdate ret_var = ChannelUpdate_clone(&orig_conv);
12324         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12325         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12326         long ret_ref = (long)ret_var.inner;
12327         if (ret_var.is_owned) {
12328                 ret_ref |= 1;
12329         }
12330         return ret_ref;
12331 }
12332
12333 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_ChannelUpdate_1get_1signature(JNIEnv *env, jclass clz, int64_t this_ptr) {
12334         LDKChannelUpdate this_ptr_conv;
12335         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12336         this_ptr_conv.is_owned = false;
12337         int8_tArray arg_arr = (*env)->NewByteArray(env, 64);
12338         (*env)->SetByteArrayRegion(env, arg_arr, 0, 64, ChannelUpdate_get_signature(&this_ptr_conv).compact_form);
12339         return arg_arr;
12340 }
12341
12342 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelUpdate_1set_1signature(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
12343         LDKChannelUpdate this_ptr_conv;
12344         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12345         this_ptr_conv.is_owned = false;
12346         LDKSignature val_ref;
12347         CHECK((*env)->GetArrayLength(env, val) == 64);
12348         (*env)->GetByteArrayRegion(env, val, 0, 64, val_ref.compact_form);
12349         ChannelUpdate_set_signature(&this_ptr_conv, val_ref);
12350 }
12351
12352 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelUpdate_1get_1contents(JNIEnv *env, jclass clz, int64_t this_ptr) {
12353         LDKChannelUpdate this_ptr_conv;
12354         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12355         this_ptr_conv.is_owned = false;
12356         LDKUnsignedChannelUpdate ret_var = ChannelUpdate_get_contents(&this_ptr_conv);
12357         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12358         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12359         long ret_ref = (long)ret_var.inner;
12360         if (ret_var.is_owned) {
12361                 ret_ref |= 1;
12362         }
12363         return ret_ref;
12364 }
12365
12366 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelUpdate_1set_1contents(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
12367         LDKChannelUpdate this_ptr_conv;
12368         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12369         this_ptr_conv.is_owned = false;
12370         LDKUnsignedChannelUpdate val_conv;
12371         val_conv.inner = (void*)(val & (~1));
12372         val_conv.is_owned = (val & 1) || (val == 0);
12373         if (val_conv.inner != NULL)
12374                 val_conv = UnsignedChannelUpdate_clone(&val_conv);
12375         ChannelUpdate_set_contents(&this_ptr_conv, val_conv);
12376 }
12377
12378 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelUpdate_1new(JNIEnv *env, jclass clz, int8_tArray signature_arg, int64_t contents_arg) {
12379         LDKSignature signature_arg_ref;
12380         CHECK((*env)->GetArrayLength(env, signature_arg) == 64);
12381         (*env)->GetByteArrayRegion(env, signature_arg, 0, 64, signature_arg_ref.compact_form);
12382         LDKUnsignedChannelUpdate contents_arg_conv;
12383         contents_arg_conv.inner = (void*)(contents_arg & (~1));
12384         contents_arg_conv.is_owned = (contents_arg & 1) || (contents_arg == 0);
12385         if (contents_arg_conv.inner != NULL)
12386                 contents_arg_conv = UnsignedChannelUpdate_clone(&contents_arg_conv);
12387         LDKChannelUpdate ret_var = ChannelUpdate_new(signature_arg_ref, contents_arg_conv);
12388         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12389         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12390         long ret_ref = (long)ret_var.inner;
12391         if (ret_var.is_owned) {
12392                 ret_ref |= 1;
12393         }
12394         return ret_ref;
12395 }
12396
12397 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_QueryChannelRange_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
12398         LDKQueryChannelRange this_ptr_conv;
12399         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12400         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12401         QueryChannelRange_free(this_ptr_conv);
12402 }
12403
12404 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_QueryChannelRange_1clone(JNIEnv *env, jclass clz, int64_t orig) {
12405         LDKQueryChannelRange orig_conv;
12406         orig_conv.inner = (void*)(orig & (~1));
12407         orig_conv.is_owned = false;
12408         LDKQueryChannelRange ret_var = QueryChannelRange_clone(&orig_conv);
12409         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12410         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12411         long ret_ref = (long)ret_var.inner;
12412         if (ret_var.is_owned) {
12413                 ret_ref |= 1;
12414         }
12415         return ret_ref;
12416 }
12417
12418 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_QueryChannelRange_1get_1chain_1hash(JNIEnv *env, jclass clz, int64_t this_ptr) {
12419         LDKQueryChannelRange this_ptr_conv;
12420         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12421         this_ptr_conv.is_owned = false;
12422         int8_tArray ret_arr = (*env)->NewByteArray(env, 32);
12423         (*env)->SetByteArrayRegion(env, ret_arr, 0, 32, *QueryChannelRange_get_chain_hash(&this_ptr_conv));
12424         return ret_arr;
12425 }
12426
12427 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_QueryChannelRange_1set_1chain_1hash(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
12428         LDKQueryChannelRange this_ptr_conv;
12429         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12430         this_ptr_conv.is_owned = false;
12431         LDKThirtyTwoBytes val_ref;
12432         CHECK((*env)->GetArrayLength(env, val) == 32);
12433         (*env)->GetByteArrayRegion(env, val, 0, 32, val_ref.data);
12434         QueryChannelRange_set_chain_hash(&this_ptr_conv, val_ref);
12435 }
12436
12437 JNIEXPORT int32_t JNICALL Java_org_ldk_impl_bindings_QueryChannelRange_1get_1first_1blocknum(JNIEnv *env, jclass clz, int64_t this_ptr) {
12438         LDKQueryChannelRange this_ptr_conv;
12439         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12440         this_ptr_conv.is_owned = false;
12441         int32_t ret_val = QueryChannelRange_get_first_blocknum(&this_ptr_conv);
12442         return ret_val;
12443 }
12444
12445 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_QueryChannelRange_1set_1first_1blocknum(JNIEnv *env, jclass clz, int64_t this_ptr, int32_t val) {
12446         LDKQueryChannelRange this_ptr_conv;
12447         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12448         this_ptr_conv.is_owned = false;
12449         QueryChannelRange_set_first_blocknum(&this_ptr_conv, val);
12450 }
12451
12452 JNIEXPORT int32_t JNICALL Java_org_ldk_impl_bindings_QueryChannelRange_1get_1number_1of_1blocks(JNIEnv *env, jclass clz, int64_t this_ptr) {
12453         LDKQueryChannelRange this_ptr_conv;
12454         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12455         this_ptr_conv.is_owned = false;
12456         int32_t ret_val = QueryChannelRange_get_number_of_blocks(&this_ptr_conv);
12457         return ret_val;
12458 }
12459
12460 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_QueryChannelRange_1set_1number_1of_1blocks(JNIEnv *env, jclass clz, int64_t this_ptr, int32_t val) {
12461         LDKQueryChannelRange this_ptr_conv;
12462         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12463         this_ptr_conv.is_owned = false;
12464         QueryChannelRange_set_number_of_blocks(&this_ptr_conv, val);
12465 }
12466
12467 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_QueryChannelRange_1new(JNIEnv *env, jclass clz, int8_tArray chain_hash_arg, int32_t first_blocknum_arg, int32_t number_of_blocks_arg) {
12468         LDKThirtyTwoBytes chain_hash_arg_ref;
12469         CHECK((*env)->GetArrayLength(env, chain_hash_arg) == 32);
12470         (*env)->GetByteArrayRegion(env, chain_hash_arg, 0, 32, chain_hash_arg_ref.data);
12471         LDKQueryChannelRange ret_var = QueryChannelRange_new(chain_hash_arg_ref, first_blocknum_arg, number_of_blocks_arg);
12472         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12473         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12474         long ret_ref = (long)ret_var.inner;
12475         if (ret_var.is_owned) {
12476                 ret_ref |= 1;
12477         }
12478         return ret_ref;
12479 }
12480
12481 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ReplyChannelRange_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
12482         LDKReplyChannelRange this_ptr_conv;
12483         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12484         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12485         ReplyChannelRange_free(this_ptr_conv);
12486 }
12487
12488 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ReplyChannelRange_1clone(JNIEnv *env, jclass clz, int64_t orig) {
12489         LDKReplyChannelRange orig_conv;
12490         orig_conv.inner = (void*)(orig & (~1));
12491         orig_conv.is_owned = false;
12492         LDKReplyChannelRange ret_var = ReplyChannelRange_clone(&orig_conv);
12493         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12494         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12495         long ret_ref = (long)ret_var.inner;
12496         if (ret_var.is_owned) {
12497                 ret_ref |= 1;
12498         }
12499         return ret_ref;
12500 }
12501
12502 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_ReplyChannelRange_1get_1chain_1hash(JNIEnv *env, jclass clz, int64_t this_ptr) {
12503         LDKReplyChannelRange this_ptr_conv;
12504         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12505         this_ptr_conv.is_owned = false;
12506         int8_tArray ret_arr = (*env)->NewByteArray(env, 32);
12507         (*env)->SetByteArrayRegion(env, ret_arr, 0, 32, *ReplyChannelRange_get_chain_hash(&this_ptr_conv));
12508         return ret_arr;
12509 }
12510
12511 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ReplyChannelRange_1set_1chain_1hash(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
12512         LDKReplyChannelRange this_ptr_conv;
12513         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12514         this_ptr_conv.is_owned = false;
12515         LDKThirtyTwoBytes val_ref;
12516         CHECK((*env)->GetArrayLength(env, val) == 32);
12517         (*env)->GetByteArrayRegion(env, val, 0, 32, val_ref.data);
12518         ReplyChannelRange_set_chain_hash(&this_ptr_conv, val_ref);
12519 }
12520
12521 JNIEXPORT int32_t JNICALL Java_org_ldk_impl_bindings_ReplyChannelRange_1get_1first_1blocknum(JNIEnv *env, jclass clz, int64_t this_ptr) {
12522         LDKReplyChannelRange this_ptr_conv;
12523         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12524         this_ptr_conv.is_owned = false;
12525         int32_t ret_val = ReplyChannelRange_get_first_blocknum(&this_ptr_conv);
12526         return ret_val;
12527 }
12528
12529 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ReplyChannelRange_1set_1first_1blocknum(JNIEnv *env, jclass clz, int64_t this_ptr, int32_t val) {
12530         LDKReplyChannelRange this_ptr_conv;
12531         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12532         this_ptr_conv.is_owned = false;
12533         ReplyChannelRange_set_first_blocknum(&this_ptr_conv, val);
12534 }
12535
12536 JNIEXPORT int32_t JNICALL Java_org_ldk_impl_bindings_ReplyChannelRange_1get_1number_1of_1blocks(JNIEnv *env, jclass clz, int64_t this_ptr) {
12537         LDKReplyChannelRange this_ptr_conv;
12538         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12539         this_ptr_conv.is_owned = false;
12540         int32_t ret_val = ReplyChannelRange_get_number_of_blocks(&this_ptr_conv);
12541         return ret_val;
12542 }
12543
12544 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ReplyChannelRange_1set_1number_1of_1blocks(JNIEnv *env, jclass clz, int64_t this_ptr, int32_t val) {
12545         LDKReplyChannelRange this_ptr_conv;
12546         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12547         this_ptr_conv.is_owned = false;
12548         ReplyChannelRange_set_number_of_blocks(&this_ptr_conv, val);
12549 }
12550
12551 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_ReplyChannelRange_1get_1full_1information(JNIEnv *env, jclass clz, int64_t this_ptr) {
12552         LDKReplyChannelRange this_ptr_conv;
12553         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12554         this_ptr_conv.is_owned = false;
12555         jboolean ret_val = ReplyChannelRange_get_full_information(&this_ptr_conv);
12556         return ret_val;
12557 }
12558
12559 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ReplyChannelRange_1set_1full_1information(JNIEnv *env, jclass clz, int64_t this_ptr, jboolean val) {
12560         LDKReplyChannelRange this_ptr_conv;
12561         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12562         this_ptr_conv.is_owned = false;
12563         ReplyChannelRange_set_full_information(&this_ptr_conv, val);
12564 }
12565
12566 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ReplyChannelRange_1set_1short_1channel_1ids(JNIEnv *env, jclass clz, int64_t this_ptr, int64_tArray val) {
12567         LDKReplyChannelRange this_ptr_conv;
12568         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12569         this_ptr_conv.is_owned = false;
12570         LDKCVec_u64Z val_constr;
12571         val_constr.datalen = (*env)->GetArrayLength(env, val);
12572         if (val_constr.datalen > 0)
12573                 val_constr.data = MALLOC(val_constr.datalen * sizeof(int64_t), "LDKCVec_u64Z Elements");
12574         else
12575                 val_constr.data = NULL;
12576         int64_t* val_vals = (*env)->GetLongArrayElements (env, val, NULL);
12577         for (size_t g = 0; g < val_constr.datalen; g++) {
12578                 int64_t arr_conv_6 = val_vals[g];
12579                 val_constr.data[g] = arr_conv_6;
12580         }
12581         (*env)->ReleaseLongArrayElements(env, val, val_vals, 0);
12582         ReplyChannelRange_set_short_channel_ids(&this_ptr_conv, val_constr);
12583 }
12584
12585 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ReplyChannelRange_1new(JNIEnv *env, jclass clz, 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) {
12586         LDKThirtyTwoBytes chain_hash_arg_ref;
12587         CHECK((*env)->GetArrayLength(env, chain_hash_arg) == 32);
12588         (*env)->GetByteArrayRegion(env, chain_hash_arg, 0, 32, chain_hash_arg_ref.data);
12589         LDKCVec_u64Z short_channel_ids_arg_constr;
12590         short_channel_ids_arg_constr.datalen = (*env)->GetArrayLength(env, short_channel_ids_arg);
12591         if (short_channel_ids_arg_constr.datalen > 0)
12592                 short_channel_ids_arg_constr.data = MALLOC(short_channel_ids_arg_constr.datalen * sizeof(int64_t), "LDKCVec_u64Z Elements");
12593         else
12594                 short_channel_ids_arg_constr.data = NULL;
12595         int64_t* short_channel_ids_arg_vals = (*env)->GetLongArrayElements (env, short_channel_ids_arg, NULL);
12596         for (size_t g = 0; g < short_channel_ids_arg_constr.datalen; g++) {
12597                 int64_t arr_conv_6 = short_channel_ids_arg_vals[g];
12598                 short_channel_ids_arg_constr.data[g] = arr_conv_6;
12599         }
12600         (*env)->ReleaseLongArrayElements(env, short_channel_ids_arg, short_channel_ids_arg_vals, 0);
12601         LDKReplyChannelRange ret_var = ReplyChannelRange_new(chain_hash_arg_ref, first_blocknum_arg, number_of_blocks_arg, full_information_arg, short_channel_ids_arg_constr);
12602         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12603         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12604         long ret_ref = (long)ret_var.inner;
12605         if (ret_var.is_owned) {
12606                 ret_ref |= 1;
12607         }
12608         return ret_ref;
12609 }
12610
12611 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_QueryShortChannelIds_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
12612         LDKQueryShortChannelIds this_ptr_conv;
12613         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12614         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12615         QueryShortChannelIds_free(this_ptr_conv);
12616 }
12617
12618 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_QueryShortChannelIds_1clone(JNIEnv *env, jclass clz, int64_t orig) {
12619         LDKQueryShortChannelIds orig_conv;
12620         orig_conv.inner = (void*)(orig & (~1));
12621         orig_conv.is_owned = false;
12622         LDKQueryShortChannelIds ret_var = QueryShortChannelIds_clone(&orig_conv);
12623         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12624         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12625         long ret_ref = (long)ret_var.inner;
12626         if (ret_var.is_owned) {
12627                 ret_ref |= 1;
12628         }
12629         return ret_ref;
12630 }
12631
12632 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_QueryShortChannelIds_1get_1chain_1hash(JNIEnv *env, jclass clz, int64_t this_ptr) {
12633         LDKQueryShortChannelIds this_ptr_conv;
12634         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12635         this_ptr_conv.is_owned = false;
12636         int8_tArray ret_arr = (*env)->NewByteArray(env, 32);
12637         (*env)->SetByteArrayRegion(env, ret_arr, 0, 32, *QueryShortChannelIds_get_chain_hash(&this_ptr_conv));
12638         return ret_arr;
12639 }
12640
12641 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_QueryShortChannelIds_1set_1chain_1hash(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
12642         LDKQueryShortChannelIds this_ptr_conv;
12643         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12644         this_ptr_conv.is_owned = false;
12645         LDKThirtyTwoBytes val_ref;
12646         CHECK((*env)->GetArrayLength(env, val) == 32);
12647         (*env)->GetByteArrayRegion(env, val, 0, 32, val_ref.data);
12648         QueryShortChannelIds_set_chain_hash(&this_ptr_conv, val_ref);
12649 }
12650
12651 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_QueryShortChannelIds_1set_1short_1channel_1ids(JNIEnv *env, jclass clz, int64_t this_ptr, int64_tArray val) {
12652         LDKQueryShortChannelIds this_ptr_conv;
12653         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12654         this_ptr_conv.is_owned = false;
12655         LDKCVec_u64Z val_constr;
12656         val_constr.datalen = (*env)->GetArrayLength(env, val);
12657         if (val_constr.datalen > 0)
12658                 val_constr.data = MALLOC(val_constr.datalen * sizeof(int64_t), "LDKCVec_u64Z Elements");
12659         else
12660                 val_constr.data = NULL;
12661         int64_t* val_vals = (*env)->GetLongArrayElements (env, val, NULL);
12662         for (size_t g = 0; g < val_constr.datalen; g++) {
12663                 int64_t arr_conv_6 = val_vals[g];
12664                 val_constr.data[g] = arr_conv_6;
12665         }
12666         (*env)->ReleaseLongArrayElements(env, val, val_vals, 0);
12667         QueryShortChannelIds_set_short_channel_ids(&this_ptr_conv, val_constr);
12668 }
12669
12670 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_QueryShortChannelIds_1new(JNIEnv *env, jclass clz, int8_tArray chain_hash_arg, int64_tArray short_channel_ids_arg) {
12671         LDKThirtyTwoBytes chain_hash_arg_ref;
12672         CHECK((*env)->GetArrayLength(env, chain_hash_arg) == 32);
12673         (*env)->GetByteArrayRegion(env, chain_hash_arg, 0, 32, chain_hash_arg_ref.data);
12674         LDKCVec_u64Z short_channel_ids_arg_constr;
12675         short_channel_ids_arg_constr.datalen = (*env)->GetArrayLength(env, short_channel_ids_arg);
12676         if (short_channel_ids_arg_constr.datalen > 0)
12677                 short_channel_ids_arg_constr.data = MALLOC(short_channel_ids_arg_constr.datalen * sizeof(int64_t), "LDKCVec_u64Z Elements");
12678         else
12679                 short_channel_ids_arg_constr.data = NULL;
12680         int64_t* short_channel_ids_arg_vals = (*env)->GetLongArrayElements (env, short_channel_ids_arg, NULL);
12681         for (size_t g = 0; g < short_channel_ids_arg_constr.datalen; g++) {
12682                 int64_t arr_conv_6 = short_channel_ids_arg_vals[g];
12683                 short_channel_ids_arg_constr.data[g] = arr_conv_6;
12684         }
12685         (*env)->ReleaseLongArrayElements(env, short_channel_ids_arg, short_channel_ids_arg_vals, 0);
12686         LDKQueryShortChannelIds ret_var = QueryShortChannelIds_new(chain_hash_arg_ref, short_channel_ids_arg_constr);
12687         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12688         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12689         long ret_ref = (long)ret_var.inner;
12690         if (ret_var.is_owned) {
12691                 ret_ref |= 1;
12692         }
12693         return ret_ref;
12694 }
12695
12696 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ReplyShortChannelIdsEnd_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
12697         LDKReplyShortChannelIdsEnd this_ptr_conv;
12698         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12699         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12700         ReplyShortChannelIdsEnd_free(this_ptr_conv);
12701 }
12702
12703 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ReplyShortChannelIdsEnd_1clone(JNIEnv *env, jclass clz, int64_t orig) {
12704         LDKReplyShortChannelIdsEnd orig_conv;
12705         orig_conv.inner = (void*)(orig & (~1));
12706         orig_conv.is_owned = false;
12707         LDKReplyShortChannelIdsEnd ret_var = ReplyShortChannelIdsEnd_clone(&orig_conv);
12708         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12709         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12710         long ret_ref = (long)ret_var.inner;
12711         if (ret_var.is_owned) {
12712                 ret_ref |= 1;
12713         }
12714         return ret_ref;
12715 }
12716
12717 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_ReplyShortChannelIdsEnd_1get_1chain_1hash(JNIEnv *env, jclass clz, int64_t this_ptr) {
12718         LDKReplyShortChannelIdsEnd this_ptr_conv;
12719         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12720         this_ptr_conv.is_owned = false;
12721         int8_tArray ret_arr = (*env)->NewByteArray(env, 32);
12722         (*env)->SetByteArrayRegion(env, ret_arr, 0, 32, *ReplyShortChannelIdsEnd_get_chain_hash(&this_ptr_conv));
12723         return ret_arr;
12724 }
12725
12726 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ReplyShortChannelIdsEnd_1set_1chain_1hash(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
12727         LDKReplyShortChannelIdsEnd this_ptr_conv;
12728         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12729         this_ptr_conv.is_owned = false;
12730         LDKThirtyTwoBytes val_ref;
12731         CHECK((*env)->GetArrayLength(env, val) == 32);
12732         (*env)->GetByteArrayRegion(env, val, 0, 32, val_ref.data);
12733         ReplyShortChannelIdsEnd_set_chain_hash(&this_ptr_conv, val_ref);
12734 }
12735
12736 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_ReplyShortChannelIdsEnd_1get_1full_1information(JNIEnv *env, jclass clz, int64_t this_ptr) {
12737         LDKReplyShortChannelIdsEnd this_ptr_conv;
12738         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12739         this_ptr_conv.is_owned = false;
12740         jboolean ret_val = ReplyShortChannelIdsEnd_get_full_information(&this_ptr_conv);
12741         return ret_val;
12742 }
12743
12744 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ReplyShortChannelIdsEnd_1set_1full_1information(JNIEnv *env, jclass clz, int64_t this_ptr, jboolean val) {
12745         LDKReplyShortChannelIdsEnd this_ptr_conv;
12746         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12747         this_ptr_conv.is_owned = false;
12748         ReplyShortChannelIdsEnd_set_full_information(&this_ptr_conv, val);
12749 }
12750
12751 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ReplyShortChannelIdsEnd_1new(JNIEnv *env, jclass clz, int8_tArray chain_hash_arg, jboolean full_information_arg) {
12752         LDKThirtyTwoBytes chain_hash_arg_ref;
12753         CHECK((*env)->GetArrayLength(env, chain_hash_arg) == 32);
12754         (*env)->GetByteArrayRegion(env, chain_hash_arg, 0, 32, chain_hash_arg_ref.data);
12755         LDKReplyShortChannelIdsEnd ret_var = ReplyShortChannelIdsEnd_new(chain_hash_arg_ref, full_information_arg);
12756         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12757         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12758         long ret_ref = (long)ret_var.inner;
12759         if (ret_var.is_owned) {
12760                 ret_ref |= 1;
12761         }
12762         return ret_ref;
12763 }
12764
12765 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_GossipTimestampFilter_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
12766         LDKGossipTimestampFilter this_ptr_conv;
12767         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12768         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12769         GossipTimestampFilter_free(this_ptr_conv);
12770 }
12771
12772 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_GossipTimestampFilter_1clone(JNIEnv *env, jclass clz, int64_t orig) {
12773         LDKGossipTimestampFilter orig_conv;
12774         orig_conv.inner = (void*)(orig & (~1));
12775         orig_conv.is_owned = false;
12776         LDKGossipTimestampFilter ret_var = GossipTimestampFilter_clone(&orig_conv);
12777         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12778         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12779         long ret_ref = (long)ret_var.inner;
12780         if (ret_var.is_owned) {
12781                 ret_ref |= 1;
12782         }
12783         return ret_ref;
12784 }
12785
12786 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_GossipTimestampFilter_1get_1chain_1hash(JNIEnv *env, jclass clz, int64_t this_ptr) {
12787         LDKGossipTimestampFilter this_ptr_conv;
12788         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12789         this_ptr_conv.is_owned = false;
12790         int8_tArray ret_arr = (*env)->NewByteArray(env, 32);
12791         (*env)->SetByteArrayRegion(env, ret_arr, 0, 32, *GossipTimestampFilter_get_chain_hash(&this_ptr_conv));
12792         return ret_arr;
12793 }
12794
12795 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_GossipTimestampFilter_1set_1chain_1hash(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
12796         LDKGossipTimestampFilter this_ptr_conv;
12797         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12798         this_ptr_conv.is_owned = false;
12799         LDKThirtyTwoBytes val_ref;
12800         CHECK((*env)->GetArrayLength(env, val) == 32);
12801         (*env)->GetByteArrayRegion(env, val, 0, 32, val_ref.data);
12802         GossipTimestampFilter_set_chain_hash(&this_ptr_conv, val_ref);
12803 }
12804
12805 JNIEXPORT int32_t JNICALL Java_org_ldk_impl_bindings_GossipTimestampFilter_1get_1first_1timestamp(JNIEnv *env, jclass clz, int64_t this_ptr) {
12806         LDKGossipTimestampFilter this_ptr_conv;
12807         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12808         this_ptr_conv.is_owned = false;
12809         int32_t ret_val = GossipTimestampFilter_get_first_timestamp(&this_ptr_conv);
12810         return ret_val;
12811 }
12812
12813 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_GossipTimestampFilter_1set_1first_1timestamp(JNIEnv *env, jclass clz, int64_t this_ptr, int32_t val) {
12814         LDKGossipTimestampFilter this_ptr_conv;
12815         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12816         this_ptr_conv.is_owned = false;
12817         GossipTimestampFilter_set_first_timestamp(&this_ptr_conv, val);
12818 }
12819
12820 JNIEXPORT int32_t JNICALL Java_org_ldk_impl_bindings_GossipTimestampFilter_1get_1timestamp_1range(JNIEnv *env, jclass clz, int64_t this_ptr) {
12821         LDKGossipTimestampFilter this_ptr_conv;
12822         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12823         this_ptr_conv.is_owned = false;
12824         int32_t ret_val = GossipTimestampFilter_get_timestamp_range(&this_ptr_conv);
12825         return ret_val;
12826 }
12827
12828 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_GossipTimestampFilter_1set_1timestamp_1range(JNIEnv *env, jclass clz, int64_t this_ptr, int32_t val) {
12829         LDKGossipTimestampFilter this_ptr_conv;
12830         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12831         this_ptr_conv.is_owned = false;
12832         GossipTimestampFilter_set_timestamp_range(&this_ptr_conv, val);
12833 }
12834
12835 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_GossipTimestampFilter_1new(JNIEnv *env, jclass clz, int8_tArray chain_hash_arg, int32_t first_timestamp_arg, int32_t timestamp_range_arg) {
12836         LDKThirtyTwoBytes chain_hash_arg_ref;
12837         CHECK((*env)->GetArrayLength(env, chain_hash_arg) == 32);
12838         (*env)->GetByteArrayRegion(env, chain_hash_arg, 0, 32, chain_hash_arg_ref.data);
12839         LDKGossipTimestampFilter ret_var = GossipTimestampFilter_new(chain_hash_arg_ref, first_timestamp_arg, timestamp_range_arg);
12840         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12841         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12842         long ret_ref = (long)ret_var.inner;
12843         if (ret_var.is_owned) {
12844                 ret_ref |= 1;
12845         }
12846         return ret_ref;
12847 }
12848
12849 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ErrorAction_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
12850         LDKErrorAction this_ptr_conv = *(LDKErrorAction*)this_ptr;
12851         FREE((void*)this_ptr);
12852         ErrorAction_free(this_ptr_conv);
12853 }
12854
12855 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ErrorAction_1clone(JNIEnv *env, jclass clz, int64_t orig) {
12856         LDKErrorAction* orig_conv = (LDKErrorAction*)orig;
12857         LDKErrorAction *ret_copy = MALLOC(sizeof(LDKErrorAction), "LDKErrorAction");
12858         *ret_copy = ErrorAction_clone(orig_conv);
12859         long ret_ref = (long)ret_copy;
12860         return ret_ref;
12861 }
12862
12863 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_LightningError_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
12864         LDKLightningError this_ptr_conv;
12865         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12866         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12867         LightningError_free(this_ptr_conv);
12868 }
12869
12870 JNIEXPORT jstring JNICALL Java_org_ldk_impl_bindings_LightningError_1get_1err(JNIEnv *env, jclass clz, int64_t this_ptr) {
12871         LDKLightningError this_ptr_conv;
12872         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12873         this_ptr_conv.is_owned = false;
12874         LDKStr _str = LightningError_get_err(&this_ptr_conv);
12875         char* _buf = MALLOC(_str.len + 1, "str conv buf");
12876         memcpy(_buf, _str.chars, _str.len);
12877         _buf[_str.len] = 0;
12878         jstring _conv = (*env)->NewStringUTF(env, _str.chars);
12879         FREE(_buf);
12880         return _conv;
12881 }
12882
12883 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_LightningError_1set_1err(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
12884         LDKLightningError this_ptr_conv;
12885         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12886         this_ptr_conv.is_owned = false;
12887         LDKCVec_u8Z val_ref;
12888         val_ref.datalen = (*env)->GetArrayLength(env, val);
12889         val_ref.data = MALLOC(val_ref.datalen, "LDKCVec_u8Z Bytes");
12890         (*env)->GetByteArrayRegion(env, val, 0, val_ref.datalen, val_ref.data);
12891         LightningError_set_err(&this_ptr_conv, val_ref);
12892 }
12893
12894 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LightningError_1get_1action(JNIEnv *env, jclass clz, int64_t this_ptr) {
12895         LDKLightningError this_ptr_conv;
12896         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12897         this_ptr_conv.is_owned = false;
12898         LDKErrorAction *ret_copy = MALLOC(sizeof(LDKErrorAction), "LDKErrorAction");
12899         *ret_copy = LightningError_get_action(&this_ptr_conv);
12900         long ret_ref = (long)ret_copy;
12901         return ret_ref;
12902 }
12903
12904 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_LightningError_1set_1action(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
12905         LDKLightningError this_ptr_conv;
12906         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12907         this_ptr_conv.is_owned = false;
12908         LDKErrorAction val_conv = *(LDKErrorAction*)val;
12909         FREE((void*)val);
12910         LightningError_set_action(&this_ptr_conv, val_conv);
12911 }
12912
12913 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LightningError_1new(JNIEnv *env, jclass clz, int8_tArray err_arg, int64_t action_arg) {
12914         LDKCVec_u8Z err_arg_ref;
12915         err_arg_ref.datalen = (*env)->GetArrayLength(env, err_arg);
12916         err_arg_ref.data = MALLOC(err_arg_ref.datalen, "LDKCVec_u8Z Bytes");
12917         (*env)->GetByteArrayRegion(env, err_arg, 0, err_arg_ref.datalen, err_arg_ref.data);
12918         LDKErrorAction action_arg_conv = *(LDKErrorAction*)action_arg;
12919         FREE((void*)action_arg);
12920         LDKLightningError ret_var = LightningError_new(err_arg_ref, action_arg_conv);
12921         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12922         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12923         long ret_ref = (long)ret_var.inner;
12924         if (ret_var.is_owned) {
12925                 ret_ref |= 1;
12926         }
12927         return ret_ref;
12928 }
12929
12930 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CommitmentUpdate_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
12931         LDKCommitmentUpdate this_ptr_conv;
12932         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12933         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12934         CommitmentUpdate_free(this_ptr_conv);
12935 }
12936
12937 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CommitmentUpdate_1clone(JNIEnv *env, jclass clz, int64_t orig) {
12938         LDKCommitmentUpdate orig_conv;
12939         orig_conv.inner = (void*)(orig & (~1));
12940         orig_conv.is_owned = false;
12941         LDKCommitmentUpdate ret_var = CommitmentUpdate_clone(&orig_conv);
12942         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12943         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12944         long ret_ref = (long)ret_var.inner;
12945         if (ret_var.is_owned) {
12946                 ret_ref |= 1;
12947         }
12948         return ret_ref;
12949 }
12950
12951 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CommitmentUpdate_1set_1update_1add_1htlcs(JNIEnv *env, jclass clz, int64_t this_ptr, int64_tArray val) {
12952         LDKCommitmentUpdate this_ptr_conv;
12953         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12954         this_ptr_conv.is_owned = false;
12955         LDKCVec_UpdateAddHTLCZ val_constr;
12956         val_constr.datalen = (*env)->GetArrayLength(env, val);
12957         if (val_constr.datalen > 0)
12958                 val_constr.data = MALLOC(val_constr.datalen * sizeof(LDKUpdateAddHTLC), "LDKCVec_UpdateAddHTLCZ Elements");
12959         else
12960                 val_constr.data = NULL;
12961         int64_t* val_vals = (*env)->GetLongArrayElements (env, val, NULL);
12962         for (size_t p = 0; p < val_constr.datalen; p++) {
12963                 int64_t arr_conv_15 = val_vals[p];
12964                 LDKUpdateAddHTLC arr_conv_15_conv;
12965                 arr_conv_15_conv.inner = (void*)(arr_conv_15 & (~1));
12966                 arr_conv_15_conv.is_owned = (arr_conv_15 & 1) || (arr_conv_15 == 0);
12967                 if (arr_conv_15_conv.inner != NULL)
12968                         arr_conv_15_conv = UpdateAddHTLC_clone(&arr_conv_15_conv);
12969                 val_constr.data[p] = arr_conv_15_conv;
12970         }
12971         (*env)->ReleaseLongArrayElements(env, val, val_vals, 0);
12972         CommitmentUpdate_set_update_add_htlcs(&this_ptr_conv, val_constr);
12973 }
12974
12975 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CommitmentUpdate_1set_1update_1fulfill_1htlcs(JNIEnv *env, jclass clz, int64_t this_ptr, int64_tArray val) {
12976         LDKCommitmentUpdate this_ptr_conv;
12977         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12978         this_ptr_conv.is_owned = false;
12979         LDKCVec_UpdateFulfillHTLCZ val_constr;
12980         val_constr.datalen = (*env)->GetArrayLength(env, val);
12981         if (val_constr.datalen > 0)
12982                 val_constr.data = MALLOC(val_constr.datalen * sizeof(LDKUpdateFulfillHTLC), "LDKCVec_UpdateFulfillHTLCZ Elements");
12983         else
12984                 val_constr.data = NULL;
12985         int64_t* val_vals = (*env)->GetLongArrayElements (env, val, NULL);
12986         for (size_t t = 0; t < val_constr.datalen; t++) {
12987                 int64_t arr_conv_19 = val_vals[t];
12988                 LDKUpdateFulfillHTLC arr_conv_19_conv;
12989                 arr_conv_19_conv.inner = (void*)(arr_conv_19 & (~1));
12990                 arr_conv_19_conv.is_owned = (arr_conv_19 & 1) || (arr_conv_19 == 0);
12991                 if (arr_conv_19_conv.inner != NULL)
12992                         arr_conv_19_conv = UpdateFulfillHTLC_clone(&arr_conv_19_conv);
12993                 val_constr.data[t] = arr_conv_19_conv;
12994         }
12995         (*env)->ReleaseLongArrayElements(env, val, val_vals, 0);
12996         CommitmentUpdate_set_update_fulfill_htlcs(&this_ptr_conv, val_constr);
12997 }
12998
12999 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CommitmentUpdate_1set_1update_1fail_1htlcs(JNIEnv *env, jclass clz, int64_t this_ptr, int64_tArray val) {
13000         LDKCommitmentUpdate this_ptr_conv;
13001         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13002         this_ptr_conv.is_owned = false;
13003         LDKCVec_UpdateFailHTLCZ val_constr;
13004         val_constr.datalen = (*env)->GetArrayLength(env, val);
13005         if (val_constr.datalen > 0)
13006                 val_constr.data = MALLOC(val_constr.datalen * sizeof(LDKUpdateFailHTLC), "LDKCVec_UpdateFailHTLCZ Elements");
13007         else
13008                 val_constr.data = NULL;
13009         int64_t* val_vals = (*env)->GetLongArrayElements (env, val, NULL);
13010         for (size_t q = 0; q < val_constr.datalen; q++) {
13011                 int64_t arr_conv_16 = val_vals[q];
13012                 LDKUpdateFailHTLC arr_conv_16_conv;
13013                 arr_conv_16_conv.inner = (void*)(arr_conv_16 & (~1));
13014                 arr_conv_16_conv.is_owned = (arr_conv_16 & 1) || (arr_conv_16 == 0);
13015                 if (arr_conv_16_conv.inner != NULL)
13016                         arr_conv_16_conv = UpdateFailHTLC_clone(&arr_conv_16_conv);
13017                 val_constr.data[q] = arr_conv_16_conv;
13018         }
13019         (*env)->ReleaseLongArrayElements(env, val, val_vals, 0);
13020         CommitmentUpdate_set_update_fail_htlcs(&this_ptr_conv, val_constr);
13021 }
13022
13023 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CommitmentUpdate_1set_1update_1fail_1malformed_1htlcs(JNIEnv *env, jclass clz, int64_t this_ptr, int64_tArray val) {
13024         LDKCommitmentUpdate this_ptr_conv;
13025         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13026         this_ptr_conv.is_owned = false;
13027         LDKCVec_UpdateFailMalformedHTLCZ val_constr;
13028         val_constr.datalen = (*env)->GetArrayLength(env, val);
13029         if (val_constr.datalen > 0)
13030                 val_constr.data = MALLOC(val_constr.datalen * sizeof(LDKUpdateFailMalformedHTLC), "LDKCVec_UpdateFailMalformedHTLCZ Elements");
13031         else
13032                 val_constr.data = NULL;
13033         int64_t* val_vals = (*env)->GetLongArrayElements (env, val, NULL);
13034         for (size_t z = 0; z < val_constr.datalen; z++) {
13035                 int64_t arr_conv_25 = val_vals[z];
13036                 LDKUpdateFailMalformedHTLC arr_conv_25_conv;
13037                 arr_conv_25_conv.inner = (void*)(arr_conv_25 & (~1));
13038                 arr_conv_25_conv.is_owned = (arr_conv_25 & 1) || (arr_conv_25 == 0);
13039                 if (arr_conv_25_conv.inner != NULL)
13040                         arr_conv_25_conv = UpdateFailMalformedHTLC_clone(&arr_conv_25_conv);
13041                 val_constr.data[z] = arr_conv_25_conv;
13042         }
13043         (*env)->ReleaseLongArrayElements(env, val, val_vals, 0);
13044         CommitmentUpdate_set_update_fail_malformed_htlcs(&this_ptr_conv, val_constr);
13045 }
13046
13047 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CommitmentUpdate_1get_1update_1fee(JNIEnv *env, jclass clz, int64_t this_ptr) {
13048         LDKCommitmentUpdate this_ptr_conv;
13049         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13050         this_ptr_conv.is_owned = false;
13051         LDKUpdateFee ret_var = CommitmentUpdate_get_update_fee(&this_ptr_conv);
13052         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13053         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13054         long ret_ref = (long)ret_var.inner;
13055         if (ret_var.is_owned) {
13056                 ret_ref |= 1;
13057         }
13058         return ret_ref;
13059 }
13060
13061 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CommitmentUpdate_1set_1update_1fee(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
13062         LDKCommitmentUpdate this_ptr_conv;
13063         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13064         this_ptr_conv.is_owned = false;
13065         LDKUpdateFee val_conv;
13066         val_conv.inner = (void*)(val & (~1));
13067         val_conv.is_owned = (val & 1) || (val == 0);
13068         if (val_conv.inner != NULL)
13069                 val_conv = UpdateFee_clone(&val_conv);
13070         CommitmentUpdate_set_update_fee(&this_ptr_conv, val_conv);
13071 }
13072
13073 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CommitmentUpdate_1get_1commitment_1signed(JNIEnv *env, jclass clz, int64_t this_ptr) {
13074         LDKCommitmentUpdate this_ptr_conv;
13075         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13076         this_ptr_conv.is_owned = false;
13077         LDKCommitmentSigned ret_var = CommitmentUpdate_get_commitment_signed(&this_ptr_conv);
13078         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13079         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13080         long ret_ref = (long)ret_var.inner;
13081         if (ret_var.is_owned) {
13082                 ret_ref |= 1;
13083         }
13084         return ret_ref;
13085 }
13086
13087 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CommitmentUpdate_1set_1commitment_1signed(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
13088         LDKCommitmentUpdate this_ptr_conv;
13089         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13090         this_ptr_conv.is_owned = false;
13091         LDKCommitmentSigned val_conv;
13092         val_conv.inner = (void*)(val & (~1));
13093         val_conv.is_owned = (val & 1) || (val == 0);
13094         if (val_conv.inner != NULL)
13095                 val_conv = CommitmentSigned_clone(&val_conv);
13096         CommitmentUpdate_set_commitment_signed(&this_ptr_conv, val_conv);
13097 }
13098
13099 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CommitmentUpdate_1new(JNIEnv *env, jclass clz, int64_tArray update_add_htlcs_arg, int64_tArray update_fulfill_htlcs_arg, int64_tArray update_fail_htlcs_arg, int64_tArray update_fail_malformed_htlcs_arg, int64_t update_fee_arg, int64_t commitment_signed_arg) {
13100         LDKCVec_UpdateAddHTLCZ update_add_htlcs_arg_constr;
13101         update_add_htlcs_arg_constr.datalen = (*env)->GetArrayLength(env, update_add_htlcs_arg);
13102         if (update_add_htlcs_arg_constr.datalen > 0)
13103                 update_add_htlcs_arg_constr.data = MALLOC(update_add_htlcs_arg_constr.datalen * sizeof(LDKUpdateAddHTLC), "LDKCVec_UpdateAddHTLCZ Elements");
13104         else
13105                 update_add_htlcs_arg_constr.data = NULL;
13106         int64_t* update_add_htlcs_arg_vals = (*env)->GetLongArrayElements (env, update_add_htlcs_arg, NULL);
13107         for (size_t p = 0; p < update_add_htlcs_arg_constr.datalen; p++) {
13108                 int64_t arr_conv_15 = update_add_htlcs_arg_vals[p];
13109                 LDKUpdateAddHTLC arr_conv_15_conv;
13110                 arr_conv_15_conv.inner = (void*)(arr_conv_15 & (~1));
13111                 arr_conv_15_conv.is_owned = (arr_conv_15 & 1) || (arr_conv_15 == 0);
13112                 if (arr_conv_15_conv.inner != NULL)
13113                         arr_conv_15_conv = UpdateAddHTLC_clone(&arr_conv_15_conv);
13114                 update_add_htlcs_arg_constr.data[p] = arr_conv_15_conv;
13115         }
13116         (*env)->ReleaseLongArrayElements(env, update_add_htlcs_arg, update_add_htlcs_arg_vals, 0);
13117         LDKCVec_UpdateFulfillHTLCZ update_fulfill_htlcs_arg_constr;
13118         update_fulfill_htlcs_arg_constr.datalen = (*env)->GetArrayLength(env, update_fulfill_htlcs_arg);
13119         if (update_fulfill_htlcs_arg_constr.datalen > 0)
13120                 update_fulfill_htlcs_arg_constr.data = MALLOC(update_fulfill_htlcs_arg_constr.datalen * sizeof(LDKUpdateFulfillHTLC), "LDKCVec_UpdateFulfillHTLCZ Elements");
13121         else
13122                 update_fulfill_htlcs_arg_constr.data = NULL;
13123         int64_t* update_fulfill_htlcs_arg_vals = (*env)->GetLongArrayElements (env, update_fulfill_htlcs_arg, NULL);
13124         for (size_t t = 0; t < update_fulfill_htlcs_arg_constr.datalen; t++) {
13125                 int64_t arr_conv_19 = update_fulfill_htlcs_arg_vals[t];
13126                 LDKUpdateFulfillHTLC arr_conv_19_conv;
13127                 arr_conv_19_conv.inner = (void*)(arr_conv_19 & (~1));
13128                 arr_conv_19_conv.is_owned = (arr_conv_19 & 1) || (arr_conv_19 == 0);
13129                 if (arr_conv_19_conv.inner != NULL)
13130                         arr_conv_19_conv = UpdateFulfillHTLC_clone(&arr_conv_19_conv);
13131                 update_fulfill_htlcs_arg_constr.data[t] = arr_conv_19_conv;
13132         }
13133         (*env)->ReleaseLongArrayElements(env, update_fulfill_htlcs_arg, update_fulfill_htlcs_arg_vals, 0);
13134         LDKCVec_UpdateFailHTLCZ update_fail_htlcs_arg_constr;
13135         update_fail_htlcs_arg_constr.datalen = (*env)->GetArrayLength(env, update_fail_htlcs_arg);
13136         if (update_fail_htlcs_arg_constr.datalen > 0)
13137                 update_fail_htlcs_arg_constr.data = MALLOC(update_fail_htlcs_arg_constr.datalen * sizeof(LDKUpdateFailHTLC), "LDKCVec_UpdateFailHTLCZ Elements");
13138         else
13139                 update_fail_htlcs_arg_constr.data = NULL;
13140         int64_t* update_fail_htlcs_arg_vals = (*env)->GetLongArrayElements (env, update_fail_htlcs_arg, NULL);
13141         for (size_t q = 0; q < update_fail_htlcs_arg_constr.datalen; q++) {
13142                 int64_t arr_conv_16 = update_fail_htlcs_arg_vals[q];
13143                 LDKUpdateFailHTLC arr_conv_16_conv;
13144                 arr_conv_16_conv.inner = (void*)(arr_conv_16 & (~1));
13145                 arr_conv_16_conv.is_owned = (arr_conv_16 & 1) || (arr_conv_16 == 0);
13146                 if (arr_conv_16_conv.inner != NULL)
13147                         arr_conv_16_conv = UpdateFailHTLC_clone(&arr_conv_16_conv);
13148                 update_fail_htlcs_arg_constr.data[q] = arr_conv_16_conv;
13149         }
13150         (*env)->ReleaseLongArrayElements(env, update_fail_htlcs_arg, update_fail_htlcs_arg_vals, 0);
13151         LDKCVec_UpdateFailMalformedHTLCZ update_fail_malformed_htlcs_arg_constr;
13152         update_fail_malformed_htlcs_arg_constr.datalen = (*env)->GetArrayLength(env, update_fail_malformed_htlcs_arg);
13153         if (update_fail_malformed_htlcs_arg_constr.datalen > 0)
13154                 update_fail_malformed_htlcs_arg_constr.data = MALLOC(update_fail_malformed_htlcs_arg_constr.datalen * sizeof(LDKUpdateFailMalformedHTLC), "LDKCVec_UpdateFailMalformedHTLCZ Elements");
13155         else
13156                 update_fail_malformed_htlcs_arg_constr.data = NULL;
13157         int64_t* update_fail_malformed_htlcs_arg_vals = (*env)->GetLongArrayElements (env, update_fail_malformed_htlcs_arg, NULL);
13158         for (size_t z = 0; z < update_fail_malformed_htlcs_arg_constr.datalen; z++) {
13159                 int64_t arr_conv_25 = update_fail_malformed_htlcs_arg_vals[z];
13160                 LDKUpdateFailMalformedHTLC arr_conv_25_conv;
13161                 arr_conv_25_conv.inner = (void*)(arr_conv_25 & (~1));
13162                 arr_conv_25_conv.is_owned = (arr_conv_25 & 1) || (arr_conv_25 == 0);
13163                 if (arr_conv_25_conv.inner != NULL)
13164                         arr_conv_25_conv = UpdateFailMalformedHTLC_clone(&arr_conv_25_conv);
13165                 update_fail_malformed_htlcs_arg_constr.data[z] = arr_conv_25_conv;
13166         }
13167         (*env)->ReleaseLongArrayElements(env, update_fail_malformed_htlcs_arg, update_fail_malformed_htlcs_arg_vals, 0);
13168         LDKUpdateFee update_fee_arg_conv;
13169         update_fee_arg_conv.inner = (void*)(update_fee_arg & (~1));
13170         update_fee_arg_conv.is_owned = (update_fee_arg & 1) || (update_fee_arg == 0);
13171         if (update_fee_arg_conv.inner != NULL)
13172                 update_fee_arg_conv = UpdateFee_clone(&update_fee_arg_conv);
13173         LDKCommitmentSigned commitment_signed_arg_conv;
13174         commitment_signed_arg_conv.inner = (void*)(commitment_signed_arg & (~1));
13175         commitment_signed_arg_conv.is_owned = (commitment_signed_arg & 1) || (commitment_signed_arg == 0);
13176         if (commitment_signed_arg_conv.inner != NULL)
13177                 commitment_signed_arg_conv = CommitmentSigned_clone(&commitment_signed_arg_conv);
13178         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);
13179         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13180         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13181         long ret_ref = (long)ret_var.inner;
13182         if (ret_var.is_owned) {
13183                 ret_ref |= 1;
13184         }
13185         return ret_ref;
13186 }
13187
13188 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_HTLCFailChannelUpdate_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
13189         LDKHTLCFailChannelUpdate this_ptr_conv = *(LDKHTLCFailChannelUpdate*)this_ptr;
13190         FREE((void*)this_ptr);
13191         HTLCFailChannelUpdate_free(this_ptr_conv);
13192 }
13193
13194 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_HTLCFailChannelUpdate_1clone(JNIEnv *env, jclass clz, int64_t orig) {
13195         LDKHTLCFailChannelUpdate* orig_conv = (LDKHTLCFailChannelUpdate*)orig;
13196         LDKHTLCFailChannelUpdate *ret_copy = MALLOC(sizeof(LDKHTLCFailChannelUpdate), "LDKHTLCFailChannelUpdate");
13197         *ret_copy = HTLCFailChannelUpdate_clone(orig_conv);
13198         long ret_ref = (long)ret_copy;
13199         return ret_ref;
13200 }
13201
13202 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelMessageHandler_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
13203         LDKChannelMessageHandler this_ptr_conv = *(LDKChannelMessageHandler*)this_ptr;
13204         FREE((void*)this_ptr);
13205         ChannelMessageHandler_free(this_ptr_conv);
13206 }
13207
13208 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RoutingMessageHandler_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
13209         LDKRoutingMessageHandler this_ptr_conv = *(LDKRoutingMessageHandler*)this_ptr;
13210         FREE((void*)this_ptr);
13211         RoutingMessageHandler_free(this_ptr_conv);
13212 }
13213
13214 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1write(JNIEnv *env, jclass clz, int64_t obj) {
13215         LDKAcceptChannel obj_conv;
13216         obj_conv.inner = (void*)(obj & (~1));
13217         obj_conv.is_owned = false;
13218         LDKCVec_u8Z arg_var = AcceptChannel_write(&obj_conv);
13219         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
13220         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
13221         CVec_u8Z_free(arg_var);
13222         return arg_arr;
13223 }
13224
13225 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1read(JNIEnv *env, jclass clz, int8_tArray ser) {
13226         LDKu8slice ser_ref;
13227         ser_ref.datalen = (*env)->GetArrayLength(env, ser);
13228         ser_ref.data = (*env)->GetByteArrayElements (env, ser, NULL);
13229         LDKAcceptChannel ret_var = AcceptChannel_read(ser_ref);
13230         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13231         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13232         long ret_ref = (long)ret_var.inner;
13233         if (ret_var.is_owned) {
13234                 ret_ref |= 1;
13235         }
13236         (*env)->ReleaseByteArrayElements(env, ser, (int8_t*)ser_ref.data, 0);
13237         return ret_ref;
13238 }
13239
13240 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_AnnouncementSignatures_1write(JNIEnv *env, jclass clz, int64_t obj) {
13241         LDKAnnouncementSignatures obj_conv;
13242         obj_conv.inner = (void*)(obj & (~1));
13243         obj_conv.is_owned = false;
13244         LDKCVec_u8Z arg_var = AnnouncementSignatures_write(&obj_conv);
13245         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
13246         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
13247         CVec_u8Z_free(arg_var);
13248         return arg_arr;
13249 }
13250
13251 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_AnnouncementSignatures_1read(JNIEnv *env, jclass clz, int8_tArray ser) {
13252         LDKu8slice ser_ref;
13253         ser_ref.datalen = (*env)->GetArrayLength(env, ser);
13254         ser_ref.data = (*env)->GetByteArrayElements (env, ser, NULL);
13255         LDKAnnouncementSignatures ret_var = AnnouncementSignatures_read(ser_ref);
13256         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13257         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13258         long ret_ref = (long)ret_var.inner;
13259         if (ret_var.is_owned) {
13260                 ret_ref |= 1;
13261         }
13262         (*env)->ReleaseByteArrayElements(env, ser, (int8_t*)ser_ref.data, 0);
13263         return ret_ref;
13264 }
13265
13266 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_ChannelReestablish_1write(JNIEnv *env, jclass clz, int64_t obj) {
13267         LDKChannelReestablish obj_conv;
13268         obj_conv.inner = (void*)(obj & (~1));
13269         obj_conv.is_owned = false;
13270         LDKCVec_u8Z arg_var = ChannelReestablish_write(&obj_conv);
13271         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
13272         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
13273         CVec_u8Z_free(arg_var);
13274         return arg_arr;
13275 }
13276
13277 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelReestablish_1read(JNIEnv *env, jclass clz, int8_tArray ser) {
13278         LDKu8slice ser_ref;
13279         ser_ref.datalen = (*env)->GetArrayLength(env, ser);
13280         ser_ref.data = (*env)->GetByteArrayElements (env, ser, NULL);
13281         LDKCResult_ChannelReestablishDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ChannelReestablishDecodeErrorZ), "LDKCResult_ChannelReestablishDecodeErrorZ");
13282         *ret_conv = ChannelReestablish_read(ser_ref);
13283         (*env)->ReleaseByteArrayElements(env, ser, (int8_t*)ser_ref.data, 0);
13284         return (long)ret_conv;
13285 }
13286
13287 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_ClosingSigned_1write(JNIEnv *env, jclass clz, int64_t obj) {
13288         LDKClosingSigned obj_conv;
13289         obj_conv.inner = (void*)(obj & (~1));
13290         obj_conv.is_owned = false;
13291         LDKCVec_u8Z arg_var = ClosingSigned_write(&obj_conv);
13292         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
13293         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
13294         CVec_u8Z_free(arg_var);
13295         return arg_arr;
13296 }
13297
13298 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ClosingSigned_1read(JNIEnv *env, jclass clz, int8_tArray ser) {
13299         LDKu8slice ser_ref;
13300         ser_ref.datalen = (*env)->GetArrayLength(env, ser);
13301         ser_ref.data = (*env)->GetByteArrayElements (env, ser, NULL);
13302         LDKClosingSigned ret_var = ClosingSigned_read(ser_ref);
13303         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13304         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13305         long ret_ref = (long)ret_var.inner;
13306         if (ret_var.is_owned) {
13307                 ret_ref |= 1;
13308         }
13309         (*env)->ReleaseByteArrayElements(env, ser, (int8_t*)ser_ref.data, 0);
13310         return ret_ref;
13311 }
13312
13313 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_CommitmentSigned_1write(JNIEnv *env, jclass clz, int64_t obj) {
13314         LDKCommitmentSigned obj_conv;
13315         obj_conv.inner = (void*)(obj & (~1));
13316         obj_conv.is_owned = false;
13317         LDKCVec_u8Z arg_var = CommitmentSigned_write(&obj_conv);
13318         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
13319         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
13320         CVec_u8Z_free(arg_var);
13321         return arg_arr;
13322 }
13323
13324 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CommitmentSigned_1read(JNIEnv *env, jclass clz, int8_tArray ser) {
13325         LDKu8slice ser_ref;
13326         ser_ref.datalen = (*env)->GetArrayLength(env, ser);
13327         ser_ref.data = (*env)->GetByteArrayElements (env, ser, NULL);
13328         LDKCommitmentSigned ret_var = CommitmentSigned_read(ser_ref);
13329         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13330         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13331         long ret_ref = (long)ret_var.inner;
13332         if (ret_var.is_owned) {
13333                 ret_ref |= 1;
13334         }
13335         (*env)->ReleaseByteArrayElements(env, ser, (int8_t*)ser_ref.data, 0);
13336         return ret_ref;
13337 }
13338
13339 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_FundingCreated_1write(JNIEnv *env, jclass clz, int64_t obj) {
13340         LDKFundingCreated obj_conv;
13341         obj_conv.inner = (void*)(obj & (~1));
13342         obj_conv.is_owned = false;
13343         LDKCVec_u8Z arg_var = FundingCreated_write(&obj_conv);
13344         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
13345         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
13346         CVec_u8Z_free(arg_var);
13347         return arg_arr;
13348 }
13349
13350 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_FundingCreated_1read(JNIEnv *env, jclass clz, int8_tArray ser) {
13351         LDKu8slice ser_ref;
13352         ser_ref.datalen = (*env)->GetArrayLength(env, ser);
13353         ser_ref.data = (*env)->GetByteArrayElements (env, ser, NULL);
13354         LDKFundingCreated ret_var = FundingCreated_read(ser_ref);
13355         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13356         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13357         long ret_ref = (long)ret_var.inner;
13358         if (ret_var.is_owned) {
13359                 ret_ref |= 1;
13360         }
13361         (*env)->ReleaseByteArrayElements(env, ser, (int8_t*)ser_ref.data, 0);
13362         return ret_ref;
13363 }
13364
13365 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_FundingSigned_1write(JNIEnv *env, jclass clz, int64_t obj) {
13366         LDKFundingSigned obj_conv;
13367         obj_conv.inner = (void*)(obj & (~1));
13368         obj_conv.is_owned = false;
13369         LDKCVec_u8Z arg_var = FundingSigned_write(&obj_conv);
13370         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
13371         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
13372         CVec_u8Z_free(arg_var);
13373         return arg_arr;
13374 }
13375
13376 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_FundingSigned_1read(JNIEnv *env, jclass clz, int8_tArray ser) {
13377         LDKu8slice ser_ref;
13378         ser_ref.datalen = (*env)->GetArrayLength(env, ser);
13379         ser_ref.data = (*env)->GetByteArrayElements (env, ser, NULL);
13380         LDKFundingSigned ret_var = FundingSigned_read(ser_ref);
13381         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13382         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13383         long ret_ref = (long)ret_var.inner;
13384         if (ret_var.is_owned) {
13385                 ret_ref |= 1;
13386         }
13387         (*env)->ReleaseByteArrayElements(env, ser, (int8_t*)ser_ref.data, 0);
13388         return ret_ref;
13389 }
13390
13391 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_FundingLocked_1write(JNIEnv *env, jclass clz, int64_t obj) {
13392         LDKFundingLocked obj_conv;
13393         obj_conv.inner = (void*)(obj & (~1));
13394         obj_conv.is_owned = false;
13395         LDKCVec_u8Z arg_var = FundingLocked_write(&obj_conv);
13396         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
13397         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
13398         CVec_u8Z_free(arg_var);
13399         return arg_arr;
13400 }
13401
13402 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_FundingLocked_1read(JNIEnv *env, jclass clz, int8_tArray ser) {
13403         LDKu8slice ser_ref;
13404         ser_ref.datalen = (*env)->GetArrayLength(env, ser);
13405         ser_ref.data = (*env)->GetByteArrayElements (env, ser, NULL);
13406         LDKFundingLocked ret_var = FundingLocked_read(ser_ref);
13407         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13408         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13409         long ret_ref = (long)ret_var.inner;
13410         if (ret_var.is_owned) {
13411                 ret_ref |= 1;
13412         }
13413         (*env)->ReleaseByteArrayElements(env, ser, (int8_t*)ser_ref.data, 0);
13414         return ret_ref;
13415 }
13416
13417 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_Init_1write(JNIEnv *env, jclass clz, int64_t obj) {
13418         LDKInit obj_conv;
13419         obj_conv.inner = (void*)(obj & (~1));
13420         obj_conv.is_owned = false;
13421         LDKCVec_u8Z arg_var = Init_write(&obj_conv);
13422         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
13423         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
13424         CVec_u8Z_free(arg_var);
13425         return arg_arr;
13426 }
13427
13428 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_Init_1read(JNIEnv *env, jclass clz, int8_tArray ser) {
13429         LDKu8slice ser_ref;
13430         ser_ref.datalen = (*env)->GetArrayLength(env, ser);
13431         ser_ref.data = (*env)->GetByteArrayElements (env, ser, NULL);
13432         LDKCResult_InitDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_InitDecodeErrorZ), "LDKCResult_InitDecodeErrorZ");
13433         *ret_conv = Init_read(ser_ref);
13434         (*env)->ReleaseByteArrayElements(env, ser, (int8_t*)ser_ref.data, 0);
13435         return (long)ret_conv;
13436 }
13437
13438 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_OpenChannel_1write(JNIEnv *env, jclass clz, int64_t obj) {
13439         LDKOpenChannel obj_conv;
13440         obj_conv.inner = (void*)(obj & (~1));
13441         obj_conv.is_owned = false;
13442         LDKCVec_u8Z arg_var = OpenChannel_write(&obj_conv);
13443         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
13444         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
13445         CVec_u8Z_free(arg_var);
13446         return arg_arr;
13447 }
13448
13449 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_OpenChannel_1read(JNIEnv *env, jclass clz, int8_tArray ser) {
13450         LDKu8slice ser_ref;
13451         ser_ref.datalen = (*env)->GetArrayLength(env, ser);
13452         ser_ref.data = (*env)->GetByteArrayElements (env, ser, NULL);
13453         LDKOpenChannel ret_var = OpenChannel_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         (*env)->ReleaseByteArrayElements(env, ser, (int8_t*)ser_ref.data, 0);
13461         return ret_ref;
13462 }
13463
13464 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_RevokeAndACK_1write(JNIEnv *env, jclass clz, int64_t obj) {
13465         LDKRevokeAndACK obj_conv;
13466         obj_conv.inner = (void*)(obj & (~1));
13467         obj_conv.is_owned = false;
13468         LDKCVec_u8Z arg_var = RevokeAndACK_write(&obj_conv);
13469         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
13470         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
13471         CVec_u8Z_free(arg_var);
13472         return arg_arr;
13473 }
13474
13475 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_RevokeAndACK_1read(JNIEnv *env, jclass clz, int8_tArray ser) {
13476         LDKu8slice ser_ref;
13477         ser_ref.datalen = (*env)->GetArrayLength(env, ser);
13478         ser_ref.data = (*env)->GetByteArrayElements (env, ser, NULL);
13479         LDKRevokeAndACK ret_var = RevokeAndACK_read(ser_ref);
13480         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13481         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13482         long ret_ref = (long)ret_var.inner;
13483         if (ret_var.is_owned) {
13484                 ret_ref |= 1;
13485         }
13486         (*env)->ReleaseByteArrayElements(env, ser, (int8_t*)ser_ref.data, 0);
13487         return ret_ref;
13488 }
13489
13490 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_Shutdown_1write(JNIEnv *env, jclass clz, int64_t obj) {
13491         LDKShutdown obj_conv;
13492         obj_conv.inner = (void*)(obj & (~1));
13493         obj_conv.is_owned = false;
13494         LDKCVec_u8Z arg_var = Shutdown_write(&obj_conv);
13495         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
13496         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
13497         CVec_u8Z_free(arg_var);
13498         return arg_arr;
13499 }
13500
13501 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_Shutdown_1read(JNIEnv *env, jclass clz, int8_tArray ser) {
13502         LDKu8slice ser_ref;
13503         ser_ref.datalen = (*env)->GetArrayLength(env, ser);
13504         ser_ref.data = (*env)->GetByteArrayElements (env, ser, NULL);
13505         LDKShutdown ret_var = Shutdown_read(ser_ref);
13506         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13507         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13508         long ret_ref = (long)ret_var.inner;
13509         if (ret_var.is_owned) {
13510                 ret_ref |= 1;
13511         }
13512         (*env)->ReleaseByteArrayElements(env, ser, (int8_t*)ser_ref.data, 0);
13513         return ret_ref;
13514 }
13515
13516 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_UpdateFailHTLC_1write(JNIEnv *env, jclass clz, int64_t obj) {
13517         LDKUpdateFailHTLC obj_conv;
13518         obj_conv.inner = (void*)(obj & (~1));
13519         obj_conv.is_owned = false;
13520         LDKCVec_u8Z arg_var = UpdateFailHTLC_write(&obj_conv);
13521         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
13522         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
13523         CVec_u8Z_free(arg_var);
13524         return arg_arr;
13525 }
13526
13527 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_UpdateFailHTLC_1read(JNIEnv *env, jclass clz, int8_tArray ser) {
13528         LDKu8slice ser_ref;
13529         ser_ref.datalen = (*env)->GetArrayLength(env, ser);
13530         ser_ref.data = (*env)->GetByteArrayElements (env, ser, NULL);
13531         LDKUpdateFailHTLC ret_var = UpdateFailHTLC_read(ser_ref);
13532         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13533         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13534         long ret_ref = (long)ret_var.inner;
13535         if (ret_var.is_owned) {
13536                 ret_ref |= 1;
13537         }
13538         (*env)->ReleaseByteArrayElements(env, ser, (int8_t*)ser_ref.data, 0);
13539         return ret_ref;
13540 }
13541
13542 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_UpdateFailMalformedHTLC_1write(JNIEnv *env, jclass clz, int64_t obj) {
13543         LDKUpdateFailMalformedHTLC obj_conv;
13544         obj_conv.inner = (void*)(obj & (~1));
13545         obj_conv.is_owned = false;
13546         LDKCVec_u8Z arg_var = UpdateFailMalformedHTLC_write(&obj_conv);
13547         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
13548         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
13549         CVec_u8Z_free(arg_var);
13550         return arg_arr;
13551 }
13552
13553 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_UpdateFailMalformedHTLC_1read(JNIEnv *env, jclass clz, int8_tArray ser) {
13554         LDKu8slice ser_ref;
13555         ser_ref.datalen = (*env)->GetArrayLength(env, ser);
13556         ser_ref.data = (*env)->GetByteArrayElements (env, ser, NULL);
13557         LDKUpdateFailMalformedHTLC ret_var = UpdateFailMalformedHTLC_read(ser_ref);
13558         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13559         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13560         long ret_ref = (long)ret_var.inner;
13561         if (ret_var.is_owned) {
13562                 ret_ref |= 1;
13563         }
13564         (*env)->ReleaseByteArrayElements(env, ser, (int8_t*)ser_ref.data, 0);
13565         return ret_ref;
13566 }
13567
13568 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_UpdateFee_1write(JNIEnv *env, jclass clz, int64_t obj) {
13569         LDKUpdateFee obj_conv;
13570         obj_conv.inner = (void*)(obj & (~1));
13571         obj_conv.is_owned = false;
13572         LDKCVec_u8Z arg_var = UpdateFee_write(&obj_conv);
13573         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
13574         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
13575         CVec_u8Z_free(arg_var);
13576         return arg_arr;
13577 }
13578
13579 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_UpdateFee_1read(JNIEnv *env, jclass clz, int8_tArray ser) {
13580         LDKu8slice ser_ref;
13581         ser_ref.datalen = (*env)->GetArrayLength(env, ser);
13582         ser_ref.data = (*env)->GetByteArrayElements (env, ser, NULL);
13583         LDKUpdateFee ret_var = UpdateFee_read(ser_ref);
13584         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13585         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13586         long ret_ref = (long)ret_var.inner;
13587         if (ret_var.is_owned) {
13588                 ret_ref |= 1;
13589         }
13590         (*env)->ReleaseByteArrayElements(env, ser, (int8_t*)ser_ref.data, 0);
13591         return ret_ref;
13592 }
13593
13594 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_UpdateFulfillHTLC_1write(JNIEnv *env, jclass clz, int64_t obj) {
13595         LDKUpdateFulfillHTLC obj_conv;
13596         obj_conv.inner = (void*)(obj & (~1));
13597         obj_conv.is_owned = false;
13598         LDKCVec_u8Z arg_var = UpdateFulfillHTLC_write(&obj_conv);
13599         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
13600         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
13601         CVec_u8Z_free(arg_var);
13602         return arg_arr;
13603 }
13604
13605 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_UpdateFulfillHTLC_1read(JNIEnv *env, jclass clz, int8_tArray ser) {
13606         LDKu8slice ser_ref;
13607         ser_ref.datalen = (*env)->GetArrayLength(env, ser);
13608         ser_ref.data = (*env)->GetByteArrayElements (env, ser, NULL);
13609         LDKUpdateFulfillHTLC ret_var = UpdateFulfillHTLC_read(ser_ref);
13610         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13611         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13612         long ret_ref = (long)ret_var.inner;
13613         if (ret_var.is_owned) {
13614                 ret_ref |= 1;
13615         }
13616         (*env)->ReleaseByteArrayElements(env, ser, (int8_t*)ser_ref.data, 0);
13617         return ret_ref;
13618 }
13619
13620 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_UpdateAddHTLC_1write(JNIEnv *env, jclass clz, int64_t obj) {
13621         LDKUpdateAddHTLC obj_conv;
13622         obj_conv.inner = (void*)(obj & (~1));
13623         obj_conv.is_owned = false;
13624         LDKCVec_u8Z arg_var = UpdateAddHTLC_write(&obj_conv);
13625         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
13626         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
13627         CVec_u8Z_free(arg_var);
13628         return arg_arr;
13629 }
13630
13631 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_UpdateAddHTLC_1read(JNIEnv *env, jclass clz, int8_tArray ser) {
13632         LDKu8slice ser_ref;
13633         ser_ref.datalen = (*env)->GetArrayLength(env, ser);
13634         ser_ref.data = (*env)->GetByteArrayElements (env, ser, NULL);
13635         LDKUpdateAddHTLC ret_var = UpdateAddHTLC_read(ser_ref);
13636         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13637         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13638         long ret_ref = (long)ret_var.inner;
13639         if (ret_var.is_owned) {
13640                 ret_ref |= 1;
13641         }
13642         (*env)->ReleaseByteArrayElements(env, ser, (int8_t*)ser_ref.data, 0);
13643         return ret_ref;
13644 }
13645
13646 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_Ping_1write(JNIEnv *env, jclass clz, int64_t obj) {
13647         LDKPing obj_conv;
13648         obj_conv.inner = (void*)(obj & (~1));
13649         obj_conv.is_owned = false;
13650         LDKCVec_u8Z arg_var = Ping_write(&obj_conv);
13651         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
13652         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
13653         CVec_u8Z_free(arg_var);
13654         return arg_arr;
13655 }
13656
13657 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_Ping_1read(JNIEnv *env, jclass clz, int8_tArray ser) {
13658         LDKu8slice ser_ref;
13659         ser_ref.datalen = (*env)->GetArrayLength(env, ser);
13660         ser_ref.data = (*env)->GetByteArrayElements (env, ser, NULL);
13661         LDKCResult_PingDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_PingDecodeErrorZ), "LDKCResult_PingDecodeErrorZ");
13662         *ret_conv = Ping_read(ser_ref);
13663         (*env)->ReleaseByteArrayElements(env, ser, (int8_t*)ser_ref.data, 0);
13664         return (long)ret_conv;
13665 }
13666
13667 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_Pong_1write(JNIEnv *env, jclass clz, int64_t obj) {
13668         LDKPong obj_conv;
13669         obj_conv.inner = (void*)(obj & (~1));
13670         obj_conv.is_owned = false;
13671         LDKCVec_u8Z arg_var = Pong_write(&obj_conv);
13672         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
13673         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
13674         CVec_u8Z_free(arg_var);
13675         return arg_arr;
13676 }
13677
13678 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_Pong_1read(JNIEnv *env, jclass clz, int8_tArray ser) {
13679         LDKu8slice ser_ref;
13680         ser_ref.datalen = (*env)->GetArrayLength(env, ser);
13681         ser_ref.data = (*env)->GetByteArrayElements (env, ser, NULL);
13682         LDKCResult_PongDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_PongDecodeErrorZ), "LDKCResult_PongDecodeErrorZ");
13683         *ret_conv = Pong_read(ser_ref);
13684         (*env)->ReleaseByteArrayElements(env, ser, (int8_t*)ser_ref.data, 0);
13685         return (long)ret_conv;
13686 }
13687
13688 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1write(JNIEnv *env, jclass clz, int64_t obj) {
13689         LDKUnsignedChannelAnnouncement obj_conv;
13690         obj_conv.inner = (void*)(obj & (~1));
13691         obj_conv.is_owned = false;
13692         LDKCVec_u8Z arg_var = UnsignedChannelAnnouncement_write(&obj_conv);
13693         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
13694         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
13695         CVec_u8Z_free(arg_var);
13696         return arg_arr;
13697 }
13698
13699 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1read(JNIEnv *env, jclass clz, int8_tArray ser) {
13700         LDKu8slice ser_ref;
13701         ser_ref.datalen = (*env)->GetArrayLength(env, ser);
13702         ser_ref.data = (*env)->GetByteArrayElements (env, ser, NULL);
13703         LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ), "LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ");
13704         *ret_conv = UnsignedChannelAnnouncement_read(ser_ref);
13705         (*env)->ReleaseByteArrayElements(env, ser, (int8_t*)ser_ref.data, 0);
13706         return (long)ret_conv;
13707 }
13708
13709 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_ChannelAnnouncement_1write(JNIEnv *env, jclass clz, int64_t obj) {
13710         LDKChannelAnnouncement obj_conv;
13711         obj_conv.inner = (void*)(obj & (~1));
13712         obj_conv.is_owned = false;
13713         LDKCVec_u8Z arg_var = ChannelAnnouncement_write(&obj_conv);
13714         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
13715         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
13716         CVec_u8Z_free(arg_var);
13717         return arg_arr;
13718 }
13719
13720 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelAnnouncement_1read(JNIEnv *env, jclass clz, int8_tArray ser) {
13721         LDKu8slice ser_ref;
13722         ser_ref.datalen = (*env)->GetArrayLength(env, ser);
13723         ser_ref.data = (*env)->GetByteArrayElements (env, ser, NULL);
13724         LDKChannelAnnouncement ret_var = ChannelAnnouncement_read(ser_ref);
13725         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13726         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13727         long ret_ref = (long)ret_var.inner;
13728         if (ret_var.is_owned) {
13729                 ret_ref |= 1;
13730         }
13731         (*env)->ReleaseByteArrayElements(env, ser, (int8_t*)ser_ref.data, 0);
13732         return ret_ref;
13733 }
13734
13735 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1write(JNIEnv *env, jclass clz, int64_t obj) {
13736         LDKUnsignedChannelUpdate obj_conv;
13737         obj_conv.inner = (void*)(obj & (~1));
13738         obj_conv.is_owned = false;
13739         LDKCVec_u8Z arg_var = UnsignedChannelUpdate_write(&obj_conv);
13740         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
13741         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
13742         CVec_u8Z_free(arg_var);
13743         return arg_arr;
13744 }
13745
13746 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1read(JNIEnv *env, jclass clz, int8_tArray ser) {
13747         LDKu8slice ser_ref;
13748         ser_ref.datalen = (*env)->GetArrayLength(env, ser);
13749         ser_ref.data = (*env)->GetByteArrayElements (env, ser, NULL);
13750         LDKCResult_UnsignedChannelUpdateDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_UnsignedChannelUpdateDecodeErrorZ), "LDKCResult_UnsignedChannelUpdateDecodeErrorZ");
13751         *ret_conv = UnsignedChannelUpdate_read(ser_ref);
13752         (*env)->ReleaseByteArrayElements(env, ser, (int8_t*)ser_ref.data, 0);
13753         return (long)ret_conv;
13754 }
13755
13756 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_ChannelUpdate_1write(JNIEnv *env, jclass clz, int64_t obj) {
13757         LDKChannelUpdate obj_conv;
13758         obj_conv.inner = (void*)(obj & (~1));
13759         obj_conv.is_owned = false;
13760         LDKCVec_u8Z arg_var = ChannelUpdate_write(&obj_conv);
13761         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
13762         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
13763         CVec_u8Z_free(arg_var);
13764         return arg_arr;
13765 }
13766
13767 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelUpdate_1read(JNIEnv *env, jclass clz, int8_tArray ser) {
13768         LDKu8slice ser_ref;
13769         ser_ref.datalen = (*env)->GetArrayLength(env, ser);
13770         ser_ref.data = (*env)->GetByteArrayElements (env, ser, NULL);
13771         LDKChannelUpdate ret_var = ChannelUpdate_read(ser_ref);
13772         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13773         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13774         long ret_ref = (long)ret_var.inner;
13775         if (ret_var.is_owned) {
13776                 ret_ref |= 1;
13777         }
13778         (*env)->ReleaseByteArrayElements(env, ser, (int8_t*)ser_ref.data, 0);
13779         return ret_ref;
13780 }
13781
13782 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_ErrorMessage_1write(JNIEnv *env, jclass clz, int64_t obj) {
13783         LDKErrorMessage obj_conv;
13784         obj_conv.inner = (void*)(obj & (~1));
13785         obj_conv.is_owned = false;
13786         LDKCVec_u8Z arg_var = ErrorMessage_write(&obj_conv);
13787         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
13788         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
13789         CVec_u8Z_free(arg_var);
13790         return arg_arr;
13791 }
13792
13793 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ErrorMessage_1read(JNIEnv *env, jclass clz, int8_tArray ser) {
13794         LDKu8slice ser_ref;
13795         ser_ref.datalen = (*env)->GetArrayLength(env, ser);
13796         ser_ref.data = (*env)->GetByteArrayElements (env, ser, NULL);
13797         LDKCResult_ErrorMessageDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ErrorMessageDecodeErrorZ), "LDKCResult_ErrorMessageDecodeErrorZ");
13798         *ret_conv = ErrorMessage_read(ser_ref);
13799         (*env)->ReleaseByteArrayElements(env, ser, (int8_t*)ser_ref.data, 0);
13800         return (long)ret_conv;
13801 }
13802
13803 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_UnsignedNodeAnnouncement_1write(JNIEnv *env, jclass clz, int64_t obj) {
13804         LDKUnsignedNodeAnnouncement obj_conv;
13805         obj_conv.inner = (void*)(obj & (~1));
13806         obj_conv.is_owned = false;
13807         LDKCVec_u8Z arg_var = UnsignedNodeAnnouncement_write(&obj_conv);
13808         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
13809         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
13810         CVec_u8Z_free(arg_var);
13811         return arg_arr;
13812 }
13813
13814 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_UnsignedNodeAnnouncement_1read(JNIEnv *env, jclass clz, int8_tArray ser) {
13815         LDKu8slice ser_ref;
13816         ser_ref.datalen = (*env)->GetArrayLength(env, ser);
13817         ser_ref.data = (*env)->GetByteArrayElements (env, ser, NULL);
13818         LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ), "LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ");
13819         *ret_conv = UnsignedNodeAnnouncement_read(ser_ref);
13820         (*env)->ReleaseByteArrayElements(env, ser, (int8_t*)ser_ref.data, 0);
13821         return (long)ret_conv;
13822 }
13823
13824 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_NodeAnnouncement_1write(JNIEnv *env, jclass clz, int64_t obj) {
13825         LDKNodeAnnouncement obj_conv;
13826         obj_conv.inner = (void*)(obj & (~1));
13827         obj_conv.is_owned = false;
13828         LDKCVec_u8Z arg_var = NodeAnnouncement_write(&obj_conv);
13829         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
13830         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
13831         CVec_u8Z_free(arg_var);
13832         return arg_arr;
13833 }
13834
13835 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_NodeAnnouncement_1read(JNIEnv *env, jclass clz, int8_tArray ser) {
13836         LDKu8slice ser_ref;
13837         ser_ref.datalen = (*env)->GetArrayLength(env, ser);
13838         ser_ref.data = (*env)->GetByteArrayElements (env, ser, NULL);
13839         LDKNodeAnnouncement ret_var = NodeAnnouncement_read(ser_ref);
13840         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13841         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13842         long ret_ref = (long)ret_var.inner;
13843         if (ret_var.is_owned) {
13844                 ret_ref |= 1;
13845         }
13846         (*env)->ReleaseByteArrayElements(env, ser, (int8_t*)ser_ref.data, 0);
13847         return ret_ref;
13848 }
13849
13850 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_QueryShortChannelIds_1read(JNIEnv *env, jclass clz, int8_tArray ser) {
13851         LDKu8slice ser_ref;
13852         ser_ref.datalen = (*env)->GetArrayLength(env, ser);
13853         ser_ref.data = (*env)->GetByteArrayElements (env, ser, NULL);
13854         LDKCResult_QueryShortChannelIdsDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_QueryShortChannelIdsDecodeErrorZ), "LDKCResult_QueryShortChannelIdsDecodeErrorZ");
13855         *ret_conv = QueryShortChannelIds_read(ser_ref);
13856         (*env)->ReleaseByteArrayElements(env, ser, (int8_t*)ser_ref.data, 0);
13857         return (long)ret_conv;
13858 }
13859
13860 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_QueryShortChannelIds_1write(JNIEnv *env, jclass clz, int64_t obj) {
13861         LDKQueryShortChannelIds obj_conv;
13862         obj_conv.inner = (void*)(obj & (~1));
13863         obj_conv.is_owned = false;
13864         LDKCVec_u8Z arg_var = QueryShortChannelIds_write(&obj_conv);
13865         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
13866         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
13867         CVec_u8Z_free(arg_var);
13868         return arg_arr;
13869 }
13870
13871 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ReplyShortChannelIdsEnd_1read(JNIEnv *env, jclass clz, int8_tArray ser) {
13872         LDKu8slice ser_ref;
13873         ser_ref.datalen = (*env)->GetArrayLength(env, ser);
13874         ser_ref.data = (*env)->GetByteArrayElements (env, ser, NULL);
13875         LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ), "LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ");
13876         *ret_conv = ReplyShortChannelIdsEnd_read(ser_ref);
13877         (*env)->ReleaseByteArrayElements(env, ser, (int8_t*)ser_ref.data, 0);
13878         return (long)ret_conv;
13879 }
13880
13881 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_ReplyShortChannelIdsEnd_1write(JNIEnv *env, jclass clz, int64_t obj) {
13882         LDKReplyShortChannelIdsEnd obj_conv;
13883         obj_conv.inner = (void*)(obj & (~1));
13884         obj_conv.is_owned = false;
13885         LDKCVec_u8Z arg_var = ReplyShortChannelIdsEnd_write(&obj_conv);
13886         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
13887         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
13888         CVec_u8Z_free(arg_var);
13889         return arg_arr;
13890 }
13891
13892 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_QueryChannelRange_1read(JNIEnv *env, jclass clz, int8_tArray ser) {
13893         LDKu8slice ser_ref;
13894         ser_ref.datalen = (*env)->GetArrayLength(env, ser);
13895         ser_ref.data = (*env)->GetByteArrayElements (env, ser, NULL);
13896         LDKCResult_QueryChannelRangeDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_QueryChannelRangeDecodeErrorZ), "LDKCResult_QueryChannelRangeDecodeErrorZ");
13897         *ret_conv = QueryChannelRange_read(ser_ref);
13898         (*env)->ReleaseByteArrayElements(env, ser, (int8_t*)ser_ref.data, 0);
13899         return (long)ret_conv;
13900 }
13901
13902 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_QueryChannelRange_1write(JNIEnv *env, jclass clz, int64_t obj) {
13903         LDKQueryChannelRange obj_conv;
13904         obj_conv.inner = (void*)(obj & (~1));
13905         obj_conv.is_owned = false;
13906         LDKCVec_u8Z arg_var = QueryChannelRange_write(&obj_conv);
13907         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
13908         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
13909         CVec_u8Z_free(arg_var);
13910         return arg_arr;
13911 }
13912
13913 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ReplyChannelRange_1read(JNIEnv *env, jclass clz, int8_tArray ser) {
13914         LDKu8slice ser_ref;
13915         ser_ref.datalen = (*env)->GetArrayLength(env, ser);
13916         ser_ref.data = (*env)->GetByteArrayElements (env, ser, NULL);
13917         LDKCResult_ReplyChannelRangeDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ReplyChannelRangeDecodeErrorZ), "LDKCResult_ReplyChannelRangeDecodeErrorZ");
13918         *ret_conv = ReplyChannelRange_read(ser_ref);
13919         (*env)->ReleaseByteArrayElements(env, ser, (int8_t*)ser_ref.data, 0);
13920         return (long)ret_conv;
13921 }
13922
13923 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_ReplyChannelRange_1write(JNIEnv *env, jclass clz, int64_t obj) {
13924         LDKReplyChannelRange obj_conv;
13925         obj_conv.inner = (void*)(obj & (~1));
13926         obj_conv.is_owned = false;
13927         LDKCVec_u8Z arg_var = ReplyChannelRange_write(&obj_conv);
13928         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
13929         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
13930         CVec_u8Z_free(arg_var);
13931         return arg_arr;
13932 }
13933
13934 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_GossipTimestampFilter_1read(JNIEnv *env, jclass clz, int8_tArray ser) {
13935         LDKu8slice ser_ref;
13936         ser_ref.datalen = (*env)->GetArrayLength(env, ser);
13937         ser_ref.data = (*env)->GetByteArrayElements (env, ser, NULL);
13938         LDKCResult_GossipTimestampFilterDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_GossipTimestampFilterDecodeErrorZ), "LDKCResult_GossipTimestampFilterDecodeErrorZ");
13939         *ret_conv = GossipTimestampFilter_read(ser_ref);
13940         (*env)->ReleaseByteArrayElements(env, ser, (int8_t*)ser_ref.data, 0);
13941         return (long)ret_conv;
13942 }
13943
13944 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_GossipTimestampFilter_1write(JNIEnv *env, jclass clz, int64_t obj) {
13945         LDKGossipTimestampFilter obj_conv;
13946         obj_conv.inner = (void*)(obj & (~1));
13947         obj_conv.is_owned = false;
13948         LDKCVec_u8Z arg_var = GossipTimestampFilter_write(&obj_conv);
13949         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
13950         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
13951         CVec_u8Z_free(arg_var);
13952         return arg_arr;
13953 }
13954
13955 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_MessageHandler_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
13956         LDKMessageHandler this_ptr_conv;
13957         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13958         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13959         MessageHandler_free(this_ptr_conv);
13960 }
13961
13962 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_MessageHandler_1get_1chan_1handler(JNIEnv *env, jclass clz, int64_t this_ptr) {
13963         LDKMessageHandler this_ptr_conv;
13964         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13965         this_ptr_conv.is_owned = false;
13966         long ret_ret = (long)MessageHandler_get_chan_handler(&this_ptr_conv);
13967         return ret_ret;
13968 }
13969
13970 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_MessageHandler_1set_1chan_1handler(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
13971         LDKMessageHandler this_ptr_conv;
13972         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13973         this_ptr_conv.is_owned = false;
13974         LDKChannelMessageHandler val_conv = *(LDKChannelMessageHandler*)val;
13975         if (val_conv.free == LDKChannelMessageHandler_JCalls_free) {
13976                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
13977                 LDKChannelMessageHandler_JCalls_clone(val_conv.this_arg);
13978         }
13979         MessageHandler_set_chan_handler(&this_ptr_conv, val_conv);
13980 }
13981
13982 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_MessageHandler_1get_1route_1handler(JNIEnv *env, jclass clz, int64_t this_ptr) {
13983         LDKMessageHandler this_ptr_conv;
13984         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13985         this_ptr_conv.is_owned = false;
13986         long ret_ret = (long)MessageHandler_get_route_handler(&this_ptr_conv);
13987         return ret_ret;
13988 }
13989
13990 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_MessageHandler_1set_1route_1handler(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
13991         LDKMessageHandler this_ptr_conv;
13992         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13993         this_ptr_conv.is_owned = false;
13994         LDKRoutingMessageHandler val_conv = *(LDKRoutingMessageHandler*)val;
13995         if (val_conv.free == LDKRoutingMessageHandler_JCalls_free) {
13996                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
13997                 LDKRoutingMessageHandler_JCalls_clone(val_conv.this_arg);
13998         }
13999         MessageHandler_set_route_handler(&this_ptr_conv, val_conv);
14000 }
14001
14002 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_MessageHandler_1new(JNIEnv *env, jclass clz, int64_t chan_handler_arg, int64_t route_handler_arg) {
14003         LDKChannelMessageHandler chan_handler_arg_conv = *(LDKChannelMessageHandler*)chan_handler_arg;
14004         if (chan_handler_arg_conv.free == LDKChannelMessageHandler_JCalls_free) {
14005                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
14006                 LDKChannelMessageHandler_JCalls_clone(chan_handler_arg_conv.this_arg);
14007         }
14008         LDKRoutingMessageHandler route_handler_arg_conv = *(LDKRoutingMessageHandler*)route_handler_arg;
14009         if (route_handler_arg_conv.free == LDKRoutingMessageHandler_JCalls_free) {
14010                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
14011                 LDKRoutingMessageHandler_JCalls_clone(route_handler_arg_conv.this_arg);
14012         }
14013         LDKMessageHandler ret_var = MessageHandler_new(chan_handler_arg_conv, route_handler_arg_conv);
14014         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14015         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14016         long ret_ref = (long)ret_var.inner;
14017         if (ret_var.is_owned) {
14018                 ret_ref |= 1;
14019         }
14020         return ret_ref;
14021 }
14022
14023 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_SocketDescriptor_1clone(JNIEnv *env, jclass clz, int64_t orig) {
14024         LDKSocketDescriptor* orig_conv = (LDKSocketDescriptor*)orig;
14025         LDKSocketDescriptor* ret = MALLOC(sizeof(LDKSocketDescriptor), "LDKSocketDescriptor");
14026         *ret = SocketDescriptor_clone(orig_conv);
14027         return (long)ret;
14028 }
14029
14030 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_SocketDescriptor_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
14031         LDKSocketDescriptor this_ptr_conv = *(LDKSocketDescriptor*)this_ptr;
14032         FREE((void*)this_ptr);
14033         SocketDescriptor_free(this_ptr_conv);
14034 }
14035
14036 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_PeerHandleError_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
14037         LDKPeerHandleError this_ptr_conv;
14038         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14039         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
14040         PeerHandleError_free(this_ptr_conv);
14041 }
14042
14043 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_PeerHandleError_1get_1no_1connection_1possible(JNIEnv *env, jclass clz, int64_t this_ptr) {
14044         LDKPeerHandleError this_ptr_conv;
14045         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14046         this_ptr_conv.is_owned = false;
14047         jboolean ret_val = PeerHandleError_get_no_connection_possible(&this_ptr_conv);
14048         return ret_val;
14049 }
14050
14051 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_PeerHandleError_1set_1no_1connection_1possible(JNIEnv *env, jclass clz, int64_t this_ptr, jboolean val) {
14052         LDKPeerHandleError this_ptr_conv;
14053         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14054         this_ptr_conv.is_owned = false;
14055         PeerHandleError_set_no_connection_possible(&this_ptr_conv, val);
14056 }
14057
14058 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_PeerHandleError_1new(JNIEnv *env, jclass clz, jboolean no_connection_possible_arg) {
14059         LDKPeerHandleError ret_var = PeerHandleError_new(no_connection_possible_arg);
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 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_PeerManager_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
14070         LDKPeerManager this_ptr_conv;
14071         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14072         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
14073         PeerManager_free(this_ptr_conv);
14074 }
14075
14076 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_PeerManager_1new(JNIEnv *env, jclass clz, int64_t message_handler, int8_tArray our_node_secret, int8_tArray ephemeral_random_data, int64_t logger) {
14077         LDKMessageHandler message_handler_conv;
14078         message_handler_conv.inner = (void*)(message_handler & (~1));
14079         message_handler_conv.is_owned = (message_handler & 1) || (message_handler == 0);
14080         // Warning: we may need a move here but can't clone!
14081         LDKSecretKey our_node_secret_ref;
14082         CHECK((*env)->GetArrayLength(env, our_node_secret) == 32);
14083         (*env)->GetByteArrayRegion(env, our_node_secret, 0, 32, our_node_secret_ref.bytes);
14084         unsigned char ephemeral_random_data_arr[32];
14085         CHECK((*env)->GetArrayLength(env, ephemeral_random_data) == 32);
14086         (*env)->GetByteArrayRegion(env, ephemeral_random_data, 0, 32, ephemeral_random_data_arr);
14087         unsigned char (*ephemeral_random_data_ref)[32] = &ephemeral_random_data_arr;
14088         LDKLogger logger_conv = *(LDKLogger*)logger;
14089         if (logger_conv.free == LDKLogger_JCalls_free) {
14090                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
14091                 LDKLogger_JCalls_clone(logger_conv.this_arg);
14092         }
14093         LDKPeerManager ret_var = PeerManager_new(message_handler_conv, our_node_secret_ref, ephemeral_random_data_ref, logger_conv);
14094         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14095         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14096         long ret_ref = (long)ret_var.inner;
14097         if (ret_var.is_owned) {
14098                 ret_ref |= 1;
14099         }
14100         return ret_ref;
14101 }
14102
14103 JNIEXPORT jobjectArray JNICALL Java_org_ldk_impl_bindings_PeerManager_1get_1peer_1node_1ids(JNIEnv *env, jclass clz, int64_t this_arg) {
14104         LDKPeerManager this_arg_conv;
14105         this_arg_conv.inner = (void*)(this_arg & (~1));
14106         this_arg_conv.is_owned = false;
14107         LDKCVec_PublicKeyZ ret_var = PeerManager_get_peer_node_ids(&this_arg_conv);
14108         jobjectArray ret_arr = (*env)->NewObjectArray(env, ret_var.datalen, arr_of_B_clz, NULL);
14109         ;
14110         for (size_t i = 0; i < ret_var.datalen; i++) {
14111                 int8_tArray arr_conv_8_arr = (*env)->NewByteArray(env, 33);
14112                 (*env)->SetByteArrayRegion(env, arr_conv_8_arr, 0, 33, ret_var.data[i].compressed_form);
14113                 (*env)->SetObjectArrayElement(env, ret_arr, i, arr_conv_8_arr);
14114         }
14115         FREE(ret_var.data);
14116         return ret_arr;
14117 }
14118
14119 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_PeerManager_1new_1outbound_1connection(JNIEnv *env, jclass clz, int64_t this_arg, int8_tArray their_node_id, int64_t descriptor) {
14120         LDKPeerManager this_arg_conv;
14121         this_arg_conv.inner = (void*)(this_arg & (~1));
14122         this_arg_conv.is_owned = false;
14123         LDKPublicKey their_node_id_ref;
14124         CHECK((*env)->GetArrayLength(env, their_node_id) == 33);
14125         (*env)->GetByteArrayRegion(env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
14126         LDKSocketDescriptor descriptor_conv = *(LDKSocketDescriptor*)descriptor;
14127         if (descriptor_conv.free == LDKSocketDescriptor_JCalls_free) {
14128                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
14129                 LDKSocketDescriptor_JCalls_clone(descriptor_conv.this_arg);
14130         }
14131         LDKCResult_CVec_u8ZPeerHandleErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_CVec_u8ZPeerHandleErrorZ), "LDKCResult_CVec_u8ZPeerHandleErrorZ");
14132         *ret_conv = PeerManager_new_outbound_connection(&this_arg_conv, their_node_id_ref, descriptor_conv);
14133         return (long)ret_conv;
14134 }
14135
14136 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_PeerManager_1new_1inbound_1connection(JNIEnv *env, jclass clz, int64_t this_arg, int64_t descriptor) {
14137         LDKPeerManager this_arg_conv;
14138         this_arg_conv.inner = (void*)(this_arg & (~1));
14139         this_arg_conv.is_owned = false;
14140         LDKSocketDescriptor descriptor_conv = *(LDKSocketDescriptor*)descriptor;
14141         if (descriptor_conv.free == LDKSocketDescriptor_JCalls_free) {
14142                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
14143                 LDKSocketDescriptor_JCalls_clone(descriptor_conv.this_arg);
14144         }
14145         LDKCResult_NonePeerHandleErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NonePeerHandleErrorZ), "LDKCResult_NonePeerHandleErrorZ");
14146         *ret_conv = PeerManager_new_inbound_connection(&this_arg_conv, descriptor_conv);
14147         return (long)ret_conv;
14148 }
14149
14150 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_PeerManager_1write_1buffer_1space_1avail(JNIEnv *env, jclass clz, int64_t this_arg, int64_t descriptor) {
14151         LDKPeerManager this_arg_conv;
14152         this_arg_conv.inner = (void*)(this_arg & (~1));
14153         this_arg_conv.is_owned = false;
14154         LDKSocketDescriptor* descriptor_conv = (LDKSocketDescriptor*)descriptor;
14155         LDKCResult_NonePeerHandleErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NonePeerHandleErrorZ), "LDKCResult_NonePeerHandleErrorZ");
14156         *ret_conv = PeerManager_write_buffer_space_avail(&this_arg_conv, descriptor_conv);
14157         return (long)ret_conv;
14158 }
14159
14160 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_PeerManager_1read_1event(JNIEnv *env, jclass clz, int64_t this_arg, int64_t peer_descriptor, int8_tArray data) {
14161         LDKPeerManager this_arg_conv;
14162         this_arg_conv.inner = (void*)(this_arg & (~1));
14163         this_arg_conv.is_owned = false;
14164         LDKSocketDescriptor* peer_descriptor_conv = (LDKSocketDescriptor*)peer_descriptor;
14165         LDKu8slice data_ref;
14166         data_ref.datalen = (*env)->GetArrayLength(env, data);
14167         data_ref.data = (*env)->GetByteArrayElements (env, data, NULL);
14168         LDKCResult_boolPeerHandleErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_boolPeerHandleErrorZ), "LDKCResult_boolPeerHandleErrorZ");
14169         *ret_conv = PeerManager_read_event(&this_arg_conv, peer_descriptor_conv, data_ref);
14170         (*env)->ReleaseByteArrayElements(env, data, (int8_t*)data_ref.data, 0);
14171         return (long)ret_conv;
14172 }
14173
14174 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_PeerManager_1process_1events(JNIEnv *env, jclass clz, int64_t this_arg) {
14175         LDKPeerManager this_arg_conv;
14176         this_arg_conv.inner = (void*)(this_arg & (~1));
14177         this_arg_conv.is_owned = false;
14178         PeerManager_process_events(&this_arg_conv);
14179 }
14180
14181 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_PeerManager_1socket_1disconnected(JNIEnv *env, jclass clz, int64_t this_arg, int64_t descriptor) {
14182         LDKPeerManager this_arg_conv;
14183         this_arg_conv.inner = (void*)(this_arg & (~1));
14184         this_arg_conv.is_owned = false;
14185         LDKSocketDescriptor* descriptor_conv = (LDKSocketDescriptor*)descriptor;
14186         PeerManager_socket_disconnected(&this_arg_conv, descriptor_conv);
14187 }
14188
14189 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_PeerManager_1timer_1tick_1occured(JNIEnv *env, jclass clz, int64_t this_arg) {
14190         LDKPeerManager this_arg_conv;
14191         this_arg_conv.inner = (void*)(this_arg & (~1));
14192         this_arg_conv.is_owned = false;
14193         PeerManager_timer_tick_occured(&this_arg_conv);
14194 }
14195
14196 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_build_1commitment_1secret(JNIEnv *env, jclass clz, int8_tArray commitment_seed, int64_t idx) {
14197         unsigned char commitment_seed_arr[32];
14198         CHECK((*env)->GetArrayLength(env, commitment_seed) == 32);
14199         (*env)->GetByteArrayRegion(env, commitment_seed, 0, 32, commitment_seed_arr);
14200         unsigned char (*commitment_seed_ref)[32] = &commitment_seed_arr;
14201         int8_tArray arg_arr = (*env)->NewByteArray(env, 32);
14202         (*env)->SetByteArrayRegion(env, arg_arr, 0, 32, build_commitment_secret(commitment_seed_ref, idx).data);
14203         return arg_arr;
14204 }
14205
14206 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_derive_1private_1key(JNIEnv *env, jclass clz, int8_tArray per_commitment_point, int8_tArray base_secret) {
14207         LDKPublicKey per_commitment_point_ref;
14208         CHECK((*env)->GetArrayLength(env, per_commitment_point) == 33);
14209         (*env)->GetByteArrayRegion(env, per_commitment_point, 0, 33, per_commitment_point_ref.compressed_form);
14210         unsigned char base_secret_arr[32];
14211         CHECK((*env)->GetArrayLength(env, base_secret) == 32);
14212         (*env)->GetByteArrayRegion(env, base_secret, 0, 32, base_secret_arr);
14213         unsigned char (*base_secret_ref)[32] = &base_secret_arr;
14214         LDKCResult_SecretKeySecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_SecretKeySecpErrorZ), "LDKCResult_SecretKeySecpErrorZ");
14215         *ret_conv = derive_private_key(per_commitment_point_ref, base_secret_ref);
14216         return (long)ret_conv;
14217 }
14218
14219 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_derive_1public_1key(JNIEnv *env, jclass clz, int8_tArray per_commitment_point, int8_tArray base_point) {
14220         LDKPublicKey per_commitment_point_ref;
14221         CHECK((*env)->GetArrayLength(env, per_commitment_point) == 33);
14222         (*env)->GetByteArrayRegion(env, per_commitment_point, 0, 33, per_commitment_point_ref.compressed_form);
14223         LDKPublicKey base_point_ref;
14224         CHECK((*env)->GetArrayLength(env, base_point) == 33);
14225         (*env)->GetByteArrayRegion(env, base_point, 0, 33, base_point_ref.compressed_form);
14226         LDKCResult_PublicKeySecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_PublicKeySecpErrorZ), "LDKCResult_PublicKeySecpErrorZ");
14227         *ret_conv = derive_public_key(per_commitment_point_ref, base_point_ref);
14228         return (long)ret_conv;
14229 }
14230
14231 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_derive_1private_1revocation_1key(JNIEnv *env, jclass clz, int8_tArray per_commitment_secret, int8_tArray countersignatory_revocation_base_secret) {
14232         unsigned char per_commitment_secret_arr[32];
14233         CHECK((*env)->GetArrayLength(env, per_commitment_secret) == 32);
14234         (*env)->GetByteArrayRegion(env, per_commitment_secret, 0, 32, per_commitment_secret_arr);
14235         unsigned char (*per_commitment_secret_ref)[32] = &per_commitment_secret_arr;
14236         unsigned char countersignatory_revocation_base_secret_arr[32];
14237         CHECK((*env)->GetArrayLength(env, countersignatory_revocation_base_secret) == 32);
14238         (*env)->GetByteArrayRegion(env, countersignatory_revocation_base_secret, 0, 32, countersignatory_revocation_base_secret_arr);
14239         unsigned char (*countersignatory_revocation_base_secret_ref)[32] = &countersignatory_revocation_base_secret_arr;
14240         LDKCResult_SecretKeySecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_SecretKeySecpErrorZ), "LDKCResult_SecretKeySecpErrorZ");
14241         *ret_conv = derive_private_revocation_key(per_commitment_secret_ref, countersignatory_revocation_base_secret_ref);
14242         return (long)ret_conv;
14243 }
14244
14245 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_derive_1public_1revocation_1key(JNIEnv *env, jclass clz, int8_tArray per_commitment_point, int8_tArray countersignatory_revocation_base_point) {
14246         LDKPublicKey per_commitment_point_ref;
14247         CHECK((*env)->GetArrayLength(env, per_commitment_point) == 33);
14248         (*env)->GetByteArrayRegion(env, per_commitment_point, 0, 33, per_commitment_point_ref.compressed_form);
14249         LDKPublicKey countersignatory_revocation_base_point_ref;
14250         CHECK((*env)->GetArrayLength(env, countersignatory_revocation_base_point) == 33);
14251         (*env)->GetByteArrayRegion(env, countersignatory_revocation_base_point, 0, 33, countersignatory_revocation_base_point_ref.compressed_form);
14252         LDKCResult_PublicKeySecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_PublicKeySecpErrorZ), "LDKCResult_PublicKeySecpErrorZ");
14253         *ret_conv = derive_public_revocation_key(per_commitment_point_ref, countersignatory_revocation_base_point_ref);
14254         return (long)ret_conv;
14255 }
14256
14257 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_TxCreationKeys_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
14258         LDKTxCreationKeys this_ptr_conv;
14259         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14260         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
14261         TxCreationKeys_free(this_ptr_conv);
14262 }
14263
14264 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_TxCreationKeys_1clone(JNIEnv *env, jclass clz, int64_t orig) {
14265         LDKTxCreationKeys orig_conv;
14266         orig_conv.inner = (void*)(orig & (~1));
14267         orig_conv.is_owned = false;
14268         LDKTxCreationKeys ret_var = TxCreationKeys_clone(&orig_conv);
14269         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14270         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14271         long ret_ref = (long)ret_var.inner;
14272         if (ret_var.is_owned) {
14273                 ret_ref |= 1;
14274         }
14275         return ret_ref;
14276 }
14277
14278 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_TxCreationKeys_1get_1per_1commitment_1point(JNIEnv *env, jclass clz, int64_t this_ptr) {
14279         LDKTxCreationKeys this_ptr_conv;
14280         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14281         this_ptr_conv.is_owned = false;
14282         int8_tArray arg_arr = (*env)->NewByteArray(env, 33);
14283         (*env)->SetByteArrayRegion(env, arg_arr, 0, 33, TxCreationKeys_get_per_commitment_point(&this_ptr_conv).compressed_form);
14284         return arg_arr;
14285 }
14286
14287 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_TxCreationKeys_1set_1per_1commitment_1point(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
14288         LDKTxCreationKeys this_ptr_conv;
14289         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14290         this_ptr_conv.is_owned = false;
14291         LDKPublicKey val_ref;
14292         CHECK((*env)->GetArrayLength(env, val) == 33);
14293         (*env)->GetByteArrayRegion(env, val, 0, 33, val_ref.compressed_form);
14294         TxCreationKeys_set_per_commitment_point(&this_ptr_conv, val_ref);
14295 }
14296
14297 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_TxCreationKeys_1get_1revocation_1key(JNIEnv *env, jclass clz, int64_t this_ptr) {
14298         LDKTxCreationKeys this_ptr_conv;
14299         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14300         this_ptr_conv.is_owned = false;
14301         int8_tArray arg_arr = (*env)->NewByteArray(env, 33);
14302         (*env)->SetByteArrayRegion(env, arg_arr, 0, 33, TxCreationKeys_get_revocation_key(&this_ptr_conv).compressed_form);
14303         return arg_arr;
14304 }
14305
14306 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_TxCreationKeys_1set_1revocation_1key(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
14307         LDKTxCreationKeys this_ptr_conv;
14308         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14309         this_ptr_conv.is_owned = false;
14310         LDKPublicKey val_ref;
14311         CHECK((*env)->GetArrayLength(env, val) == 33);
14312         (*env)->GetByteArrayRegion(env, val, 0, 33, val_ref.compressed_form);
14313         TxCreationKeys_set_revocation_key(&this_ptr_conv, val_ref);
14314 }
14315
14316 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_TxCreationKeys_1get_1broadcaster_1htlc_1key(JNIEnv *env, jclass clz, int64_t this_ptr) {
14317         LDKTxCreationKeys this_ptr_conv;
14318         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14319         this_ptr_conv.is_owned = false;
14320         int8_tArray arg_arr = (*env)->NewByteArray(env, 33);
14321         (*env)->SetByteArrayRegion(env, arg_arr, 0, 33, TxCreationKeys_get_broadcaster_htlc_key(&this_ptr_conv).compressed_form);
14322         return arg_arr;
14323 }
14324
14325 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_TxCreationKeys_1set_1broadcaster_1htlc_1key(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
14326         LDKTxCreationKeys this_ptr_conv;
14327         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14328         this_ptr_conv.is_owned = false;
14329         LDKPublicKey val_ref;
14330         CHECK((*env)->GetArrayLength(env, val) == 33);
14331         (*env)->GetByteArrayRegion(env, val, 0, 33, val_ref.compressed_form);
14332         TxCreationKeys_set_broadcaster_htlc_key(&this_ptr_conv, val_ref);
14333 }
14334
14335 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_TxCreationKeys_1get_1countersignatory_1htlc_1key(JNIEnv *env, jclass clz, int64_t this_ptr) {
14336         LDKTxCreationKeys this_ptr_conv;
14337         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14338         this_ptr_conv.is_owned = false;
14339         int8_tArray arg_arr = (*env)->NewByteArray(env, 33);
14340         (*env)->SetByteArrayRegion(env, arg_arr, 0, 33, TxCreationKeys_get_countersignatory_htlc_key(&this_ptr_conv).compressed_form);
14341         return arg_arr;
14342 }
14343
14344 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_TxCreationKeys_1set_1countersignatory_1htlc_1key(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
14345         LDKTxCreationKeys this_ptr_conv;
14346         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14347         this_ptr_conv.is_owned = false;
14348         LDKPublicKey val_ref;
14349         CHECK((*env)->GetArrayLength(env, val) == 33);
14350         (*env)->GetByteArrayRegion(env, val, 0, 33, val_ref.compressed_form);
14351         TxCreationKeys_set_countersignatory_htlc_key(&this_ptr_conv, val_ref);
14352 }
14353
14354 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_TxCreationKeys_1get_1broadcaster_1delayed_1payment_1key(JNIEnv *env, jclass clz, int64_t this_ptr) {
14355         LDKTxCreationKeys this_ptr_conv;
14356         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14357         this_ptr_conv.is_owned = false;
14358         int8_tArray arg_arr = (*env)->NewByteArray(env, 33);
14359         (*env)->SetByteArrayRegion(env, arg_arr, 0, 33, TxCreationKeys_get_broadcaster_delayed_payment_key(&this_ptr_conv).compressed_form);
14360         return arg_arr;
14361 }
14362
14363 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_TxCreationKeys_1set_1broadcaster_1delayed_1payment_1key(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
14364         LDKTxCreationKeys this_ptr_conv;
14365         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14366         this_ptr_conv.is_owned = false;
14367         LDKPublicKey val_ref;
14368         CHECK((*env)->GetArrayLength(env, val) == 33);
14369         (*env)->GetByteArrayRegion(env, val, 0, 33, val_ref.compressed_form);
14370         TxCreationKeys_set_broadcaster_delayed_payment_key(&this_ptr_conv, val_ref);
14371 }
14372
14373 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_TxCreationKeys_1new(JNIEnv *env, jclass clz, 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) {
14374         LDKPublicKey per_commitment_point_arg_ref;
14375         CHECK((*env)->GetArrayLength(env, per_commitment_point_arg) == 33);
14376         (*env)->GetByteArrayRegion(env, per_commitment_point_arg, 0, 33, per_commitment_point_arg_ref.compressed_form);
14377         LDKPublicKey revocation_key_arg_ref;
14378         CHECK((*env)->GetArrayLength(env, revocation_key_arg) == 33);
14379         (*env)->GetByteArrayRegion(env, revocation_key_arg, 0, 33, revocation_key_arg_ref.compressed_form);
14380         LDKPublicKey broadcaster_htlc_key_arg_ref;
14381         CHECK((*env)->GetArrayLength(env, broadcaster_htlc_key_arg) == 33);
14382         (*env)->GetByteArrayRegion(env, broadcaster_htlc_key_arg, 0, 33, broadcaster_htlc_key_arg_ref.compressed_form);
14383         LDKPublicKey countersignatory_htlc_key_arg_ref;
14384         CHECK((*env)->GetArrayLength(env, countersignatory_htlc_key_arg) == 33);
14385         (*env)->GetByteArrayRegion(env, countersignatory_htlc_key_arg, 0, 33, countersignatory_htlc_key_arg_ref.compressed_form);
14386         LDKPublicKey broadcaster_delayed_payment_key_arg_ref;
14387         CHECK((*env)->GetArrayLength(env, broadcaster_delayed_payment_key_arg) == 33);
14388         (*env)->GetByteArrayRegion(env, broadcaster_delayed_payment_key_arg, 0, 33, broadcaster_delayed_payment_key_arg_ref.compressed_form);
14389         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);
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 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_TxCreationKeys_1write(JNIEnv *env, jclass clz, int64_t obj) {
14400         LDKTxCreationKeys obj_conv;
14401         obj_conv.inner = (void*)(obj & (~1));
14402         obj_conv.is_owned = false;
14403         LDKCVec_u8Z arg_var = TxCreationKeys_write(&obj_conv);
14404         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
14405         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
14406         CVec_u8Z_free(arg_var);
14407         return arg_arr;
14408 }
14409
14410 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_TxCreationKeys_1read(JNIEnv *env, jclass clz, int8_tArray ser) {
14411         LDKu8slice ser_ref;
14412         ser_ref.datalen = (*env)->GetArrayLength(env, ser);
14413         ser_ref.data = (*env)->GetByteArrayElements (env, ser, NULL);
14414         LDKTxCreationKeys ret_var = TxCreationKeys_read(ser_ref);
14415         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14416         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14417         long ret_ref = (long)ret_var.inner;
14418         if (ret_var.is_owned) {
14419                 ret_ref |= 1;
14420         }
14421         (*env)->ReleaseByteArrayElements(env, ser, (int8_t*)ser_ref.data, 0);
14422         return ret_ref;
14423 }
14424
14425 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelPublicKeys_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
14426         LDKChannelPublicKeys this_ptr_conv;
14427         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14428         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
14429         ChannelPublicKeys_free(this_ptr_conv);
14430 }
14431
14432 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelPublicKeys_1clone(JNIEnv *env, jclass clz, int64_t orig) {
14433         LDKChannelPublicKeys orig_conv;
14434         orig_conv.inner = (void*)(orig & (~1));
14435         orig_conv.is_owned = false;
14436         LDKChannelPublicKeys ret_var = ChannelPublicKeys_clone(&orig_conv);
14437         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14438         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14439         long ret_ref = (long)ret_var.inner;
14440         if (ret_var.is_owned) {
14441                 ret_ref |= 1;
14442         }
14443         return ret_ref;
14444 }
14445
14446 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_ChannelPublicKeys_1get_1funding_1pubkey(JNIEnv *env, jclass clz, int64_t this_ptr) {
14447         LDKChannelPublicKeys this_ptr_conv;
14448         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14449         this_ptr_conv.is_owned = false;
14450         int8_tArray arg_arr = (*env)->NewByteArray(env, 33);
14451         (*env)->SetByteArrayRegion(env, arg_arr, 0, 33, ChannelPublicKeys_get_funding_pubkey(&this_ptr_conv).compressed_form);
14452         return arg_arr;
14453 }
14454
14455 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelPublicKeys_1set_1funding_1pubkey(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
14456         LDKChannelPublicKeys this_ptr_conv;
14457         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14458         this_ptr_conv.is_owned = false;
14459         LDKPublicKey val_ref;
14460         CHECK((*env)->GetArrayLength(env, val) == 33);
14461         (*env)->GetByteArrayRegion(env, val, 0, 33, val_ref.compressed_form);
14462         ChannelPublicKeys_set_funding_pubkey(&this_ptr_conv, val_ref);
14463 }
14464
14465 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_ChannelPublicKeys_1get_1revocation_1basepoint(JNIEnv *env, jclass clz, int64_t this_ptr) {
14466         LDKChannelPublicKeys this_ptr_conv;
14467         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14468         this_ptr_conv.is_owned = false;
14469         int8_tArray arg_arr = (*env)->NewByteArray(env, 33);
14470         (*env)->SetByteArrayRegion(env, arg_arr, 0, 33, ChannelPublicKeys_get_revocation_basepoint(&this_ptr_conv).compressed_form);
14471         return arg_arr;
14472 }
14473
14474 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelPublicKeys_1set_1revocation_1basepoint(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
14475         LDKChannelPublicKeys this_ptr_conv;
14476         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14477         this_ptr_conv.is_owned = false;
14478         LDKPublicKey val_ref;
14479         CHECK((*env)->GetArrayLength(env, val) == 33);
14480         (*env)->GetByteArrayRegion(env, val, 0, 33, val_ref.compressed_form);
14481         ChannelPublicKeys_set_revocation_basepoint(&this_ptr_conv, val_ref);
14482 }
14483
14484 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_ChannelPublicKeys_1get_1payment_1point(JNIEnv *env, jclass clz, int64_t this_ptr) {
14485         LDKChannelPublicKeys this_ptr_conv;
14486         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14487         this_ptr_conv.is_owned = false;
14488         int8_tArray arg_arr = (*env)->NewByteArray(env, 33);
14489         (*env)->SetByteArrayRegion(env, arg_arr, 0, 33, ChannelPublicKeys_get_payment_point(&this_ptr_conv).compressed_form);
14490         return arg_arr;
14491 }
14492
14493 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelPublicKeys_1set_1payment_1point(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
14494         LDKChannelPublicKeys this_ptr_conv;
14495         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14496         this_ptr_conv.is_owned = false;
14497         LDKPublicKey val_ref;
14498         CHECK((*env)->GetArrayLength(env, val) == 33);
14499         (*env)->GetByteArrayRegion(env, val, 0, 33, val_ref.compressed_form);
14500         ChannelPublicKeys_set_payment_point(&this_ptr_conv, val_ref);
14501 }
14502
14503 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_ChannelPublicKeys_1get_1delayed_1payment_1basepoint(JNIEnv *env, jclass clz, int64_t this_ptr) {
14504         LDKChannelPublicKeys this_ptr_conv;
14505         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14506         this_ptr_conv.is_owned = false;
14507         int8_tArray arg_arr = (*env)->NewByteArray(env, 33);
14508         (*env)->SetByteArrayRegion(env, arg_arr, 0, 33, ChannelPublicKeys_get_delayed_payment_basepoint(&this_ptr_conv).compressed_form);
14509         return arg_arr;
14510 }
14511
14512 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelPublicKeys_1set_1delayed_1payment_1basepoint(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
14513         LDKChannelPublicKeys this_ptr_conv;
14514         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14515         this_ptr_conv.is_owned = false;
14516         LDKPublicKey val_ref;
14517         CHECK((*env)->GetArrayLength(env, val) == 33);
14518         (*env)->GetByteArrayRegion(env, val, 0, 33, val_ref.compressed_form);
14519         ChannelPublicKeys_set_delayed_payment_basepoint(&this_ptr_conv, val_ref);
14520 }
14521
14522 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_ChannelPublicKeys_1get_1htlc_1basepoint(JNIEnv *env, jclass clz, int64_t this_ptr) {
14523         LDKChannelPublicKeys this_ptr_conv;
14524         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14525         this_ptr_conv.is_owned = false;
14526         int8_tArray arg_arr = (*env)->NewByteArray(env, 33);
14527         (*env)->SetByteArrayRegion(env, arg_arr, 0, 33, ChannelPublicKeys_get_htlc_basepoint(&this_ptr_conv).compressed_form);
14528         return arg_arr;
14529 }
14530
14531 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelPublicKeys_1set_1htlc_1basepoint(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
14532         LDKChannelPublicKeys this_ptr_conv;
14533         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14534         this_ptr_conv.is_owned = false;
14535         LDKPublicKey val_ref;
14536         CHECK((*env)->GetArrayLength(env, val) == 33);
14537         (*env)->GetByteArrayRegion(env, val, 0, 33, val_ref.compressed_form);
14538         ChannelPublicKeys_set_htlc_basepoint(&this_ptr_conv, val_ref);
14539 }
14540
14541 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelPublicKeys_1new(JNIEnv *env, jclass clz, 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) {
14542         LDKPublicKey funding_pubkey_arg_ref;
14543         CHECK((*env)->GetArrayLength(env, funding_pubkey_arg) == 33);
14544         (*env)->GetByteArrayRegion(env, funding_pubkey_arg, 0, 33, funding_pubkey_arg_ref.compressed_form);
14545         LDKPublicKey revocation_basepoint_arg_ref;
14546         CHECK((*env)->GetArrayLength(env, revocation_basepoint_arg) == 33);
14547         (*env)->GetByteArrayRegion(env, revocation_basepoint_arg, 0, 33, revocation_basepoint_arg_ref.compressed_form);
14548         LDKPublicKey payment_point_arg_ref;
14549         CHECK((*env)->GetArrayLength(env, payment_point_arg) == 33);
14550         (*env)->GetByteArrayRegion(env, payment_point_arg, 0, 33, payment_point_arg_ref.compressed_form);
14551         LDKPublicKey delayed_payment_basepoint_arg_ref;
14552         CHECK((*env)->GetArrayLength(env, delayed_payment_basepoint_arg) == 33);
14553         (*env)->GetByteArrayRegion(env, delayed_payment_basepoint_arg, 0, 33, delayed_payment_basepoint_arg_ref.compressed_form);
14554         LDKPublicKey htlc_basepoint_arg_ref;
14555         CHECK((*env)->GetArrayLength(env, htlc_basepoint_arg) == 33);
14556         (*env)->GetByteArrayRegion(env, htlc_basepoint_arg, 0, 33, htlc_basepoint_arg_ref.compressed_form);
14557         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);
14558         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14559         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14560         long ret_ref = (long)ret_var.inner;
14561         if (ret_var.is_owned) {
14562                 ret_ref |= 1;
14563         }
14564         return ret_ref;
14565 }
14566
14567 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_ChannelPublicKeys_1write(JNIEnv *env, jclass clz, int64_t obj) {
14568         LDKChannelPublicKeys obj_conv;
14569         obj_conv.inner = (void*)(obj & (~1));
14570         obj_conv.is_owned = false;
14571         LDKCVec_u8Z arg_var = ChannelPublicKeys_write(&obj_conv);
14572         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
14573         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
14574         CVec_u8Z_free(arg_var);
14575         return arg_arr;
14576 }
14577
14578 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelPublicKeys_1read(JNIEnv *env, jclass clz, int8_tArray ser) {
14579         LDKu8slice ser_ref;
14580         ser_ref.datalen = (*env)->GetArrayLength(env, ser);
14581         ser_ref.data = (*env)->GetByteArrayElements (env, ser, NULL);
14582         LDKChannelPublicKeys ret_var = ChannelPublicKeys_read(ser_ref);
14583         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14584         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14585         long ret_ref = (long)ret_var.inner;
14586         if (ret_var.is_owned) {
14587                 ret_ref |= 1;
14588         }
14589         (*env)->ReleaseByteArrayElements(env, ser, (int8_t*)ser_ref.data, 0);
14590         return ret_ref;
14591 }
14592
14593 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_TxCreationKeys_1derive_1new(JNIEnv *env, jclass clz, 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) {
14594         LDKPublicKey per_commitment_point_ref;
14595         CHECK((*env)->GetArrayLength(env, per_commitment_point) == 33);
14596         (*env)->GetByteArrayRegion(env, per_commitment_point, 0, 33, per_commitment_point_ref.compressed_form);
14597         LDKPublicKey broadcaster_delayed_payment_base_ref;
14598         CHECK((*env)->GetArrayLength(env, broadcaster_delayed_payment_base) == 33);
14599         (*env)->GetByteArrayRegion(env, broadcaster_delayed_payment_base, 0, 33, broadcaster_delayed_payment_base_ref.compressed_form);
14600         LDKPublicKey broadcaster_htlc_base_ref;
14601         CHECK((*env)->GetArrayLength(env, broadcaster_htlc_base) == 33);
14602         (*env)->GetByteArrayRegion(env, broadcaster_htlc_base, 0, 33, broadcaster_htlc_base_ref.compressed_form);
14603         LDKPublicKey countersignatory_revocation_base_ref;
14604         CHECK((*env)->GetArrayLength(env, countersignatory_revocation_base) == 33);
14605         (*env)->GetByteArrayRegion(env, countersignatory_revocation_base, 0, 33, countersignatory_revocation_base_ref.compressed_form);
14606         LDKPublicKey countersignatory_htlc_base_ref;
14607         CHECK((*env)->GetArrayLength(env, countersignatory_htlc_base) == 33);
14608         (*env)->GetByteArrayRegion(env, countersignatory_htlc_base, 0, 33, countersignatory_htlc_base_ref.compressed_form);
14609         LDKCResult_TxCreationKeysSecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_TxCreationKeysSecpErrorZ), "LDKCResult_TxCreationKeysSecpErrorZ");
14610         *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);
14611         return (long)ret_conv;
14612 }
14613
14614 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_TxCreationKeys_1from_1channel_1static_1keys(JNIEnv *env, jclass clz, int8_tArray per_commitment_point, int64_t broadcaster_keys, int64_t countersignatory_keys) {
14615         LDKPublicKey per_commitment_point_ref;
14616         CHECK((*env)->GetArrayLength(env, per_commitment_point) == 33);
14617         (*env)->GetByteArrayRegion(env, per_commitment_point, 0, 33, per_commitment_point_ref.compressed_form);
14618         LDKChannelPublicKeys broadcaster_keys_conv;
14619         broadcaster_keys_conv.inner = (void*)(broadcaster_keys & (~1));
14620         broadcaster_keys_conv.is_owned = false;
14621         LDKChannelPublicKeys countersignatory_keys_conv;
14622         countersignatory_keys_conv.inner = (void*)(countersignatory_keys & (~1));
14623         countersignatory_keys_conv.is_owned = false;
14624         LDKCResult_TxCreationKeysSecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_TxCreationKeysSecpErrorZ), "LDKCResult_TxCreationKeysSecpErrorZ");
14625         *ret_conv = TxCreationKeys_from_channel_static_keys(per_commitment_point_ref, &broadcaster_keys_conv, &countersignatory_keys_conv);
14626         return (long)ret_conv;
14627 }
14628
14629 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_get_1revokeable_1redeemscript(JNIEnv *env, jclass clz, int8_tArray revocation_key, int16_t contest_delay, int8_tArray broadcaster_delayed_payment_key) {
14630         LDKPublicKey revocation_key_ref;
14631         CHECK((*env)->GetArrayLength(env, revocation_key) == 33);
14632         (*env)->GetByteArrayRegion(env, revocation_key, 0, 33, revocation_key_ref.compressed_form);
14633         LDKPublicKey broadcaster_delayed_payment_key_ref;
14634         CHECK((*env)->GetArrayLength(env, broadcaster_delayed_payment_key) == 33);
14635         (*env)->GetByteArrayRegion(env, broadcaster_delayed_payment_key, 0, 33, broadcaster_delayed_payment_key_ref.compressed_form);
14636         LDKCVec_u8Z arg_var = get_revokeable_redeemscript(revocation_key_ref, contest_delay, broadcaster_delayed_payment_key_ref);
14637         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
14638         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
14639         CVec_u8Z_free(arg_var);
14640         return arg_arr;
14641 }
14642
14643 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_HTLCOutputInCommitment_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
14644         LDKHTLCOutputInCommitment this_ptr_conv;
14645         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14646         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
14647         HTLCOutputInCommitment_free(this_ptr_conv);
14648 }
14649
14650 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_HTLCOutputInCommitment_1clone(JNIEnv *env, jclass clz, int64_t orig) {
14651         LDKHTLCOutputInCommitment orig_conv;
14652         orig_conv.inner = (void*)(orig & (~1));
14653         orig_conv.is_owned = false;
14654         LDKHTLCOutputInCommitment ret_var = HTLCOutputInCommitment_clone(&orig_conv);
14655         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14656         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14657         long ret_ref = (long)ret_var.inner;
14658         if (ret_var.is_owned) {
14659                 ret_ref |= 1;
14660         }
14661         return ret_ref;
14662 }
14663
14664 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_HTLCOutputInCommitment_1get_1offered(JNIEnv *env, jclass clz, int64_t this_ptr) {
14665         LDKHTLCOutputInCommitment this_ptr_conv;
14666         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14667         this_ptr_conv.is_owned = false;
14668         jboolean ret_val = HTLCOutputInCommitment_get_offered(&this_ptr_conv);
14669         return ret_val;
14670 }
14671
14672 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_HTLCOutputInCommitment_1set_1offered(JNIEnv *env, jclass clz, int64_t this_ptr, jboolean val) {
14673         LDKHTLCOutputInCommitment this_ptr_conv;
14674         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14675         this_ptr_conv.is_owned = false;
14676         HTLCOutputInCommitment_set_offered(&this_ptr_conv, val);
14677 }
14678
14679 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_HTLCOutputInCommitment_1get_1amount_1msat(JNIEnv *env, jclass clz, int64_t this_ptr) {
14680         LDKHTLCOutputInCommitment this_ptr_conv;
14681         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14682         this_ptr_conv.is_owned = false;
14683         int64_t ret_val = HTLCOutputInCommitment_get_amount_msat(&this_ptr_conv);
14684         return ret_val;
14685 }
14686
14687 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_HTLCOutputInCommitment_1set_1amount_1msat(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
14688         LDKHTLCOutputInCommitment this_ptr_conv;
14689         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14690         this_ptr_conv.is_owned = false;
14691         HTLCOutputInCommitment_set_amount_msat(&this_ptr_conv, val);
14692 }
14693
14694 JNIEXPORT int32_t JNICALL Java_org_ldk_impl_bindings_HTLCOutputInCommitment_1get_1cltv_1expiry(JNIEnv *env, jclass clz, int64_t this_ptr) {
14695         LDKHTLCOutputInCommitment this_ptr_conv;
14696         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14697         this_ptr_conv.is_owned = false;
14698         int32_t ret_val = HTLCOutputInCommitment_get_cltv_expiry(&this_ptr_conv);
14699         return ret_val;
14700 }
14701
14702 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_HTLCOutputInCommitment_1set_1cltv_1expiry(JNIEnv *env, jclass clz, int64_t this_ptr, int32_t val) {
14703         LDKHTLCOutputInCommitment this_ptr_conv;
14704         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14705         this_ptr_conv.is_owned = false;
14706         HTLCOutputInCommitment_set_cltv_expiry(&this_ptr_conv, val);
14707 }
14708
14709 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_HTLCOutputInCommitment_1get_1payment_1hash(JNIEnv *env, jclass clz, int64_t this_ptr) {
14710         LDKHTLCOutputInCommitment this_ptr_conv;
14711         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14712         this_ptr_conv.is_owned = false;
14713         int8_tArray ret_arr = (*env)->NewByteArray(env, 32);
14714         (*env)->SetByteArrayRegion(env, ret_arr, 0, 32, *HTLCOutputInCommitment_get_payment_hash(&this_ptr_conv));
14715         return ret_arr;
14716 }
14717
14718 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_HTLCOutputInCommitment_1set_1payment_1hash(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
14719         LDKHTLCOutputInCommitment this_ptr_conv;
14720         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14721         this_ptr_conv.is_owned = false;
14722         LDKThirtyTwoBytes val_ref;
14723         CHECK((*env)->GetArrayLength(env, val) == 32);
14724         (*env)->GetByteArrayRegion(env, val, 0, 32, val_ref.data);
14725         HTLCOutputInCommitment_set_payment_hash(&this_ptr_conv, val_ref);
14726 }
14727
14728 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_HTLCOutputInCommitment_1write(JNIEnv *env, jclass clz, int64_t obj) {
14729         LDKHTLCOutputInCommitment obj_conv;
14730         obj_conv.inner = (void*)(obj & (~1));
14731         obj_conv.is_owned = false;
14732         LDKCVec_u8Z arg_var = HTLCOutputInCommitment_write(&obj_conv);
14733         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
14734         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
14735         CVec_u8Z_free(arg_var);
14736         return arg_arr;
14737 }
14738
14739 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_HTLCOutputInCommitment_1read(JNIEnv *env, jclass clz, int8_tArray ser) {
14740         LDKu8slice ser_ref;
14741         ser_ref.datalen = (*env)->GetArrayLength(env, ser);
14742         ser_ref.data = (*env)->GetByteArrayElements (env, ser, NULL);
14743         LDKHTLCOutputInCommitment ret_var = HTLCOutputInCommitment_read(ser_ref);
14744         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14745         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14746         long ret_ref = (long)ret_var.inner;
14747         if (ret_var.is_owned) {
14748                 ret_ref |= 1;
14749         }
14750         (*env)->ReleaseByteArrayElements(env, ser, (int8_t*)ser_ref.data, 0);
14751         return ret_ref;
14752 }
14753
14754 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_get_1htlc_1redeemscript(JNIEnv *env, jclass clz, int64_t htlc, int64_t keys) {
14755         LDKHTLCOutputInCommitment htlc_conv;
14756         htlc_conv.inner = (void*)(htlc & (~1));
14757         htlc_conv.is_owned = false;
14758         LDKTxCreationKeys keys_conv;
14759         keys_conv.inner = (void*)(keys & (~1));
14760         keys_conv.is_owned = false;
14761         LDKCVec_u8Z arg_var = get_htlc_redeemscript(&htlc_conv, &keys_conv);
14762         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
14763         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
14764         CVec_u8Z_free(arg_var);
14765         return arg_arr;
14766 }
14767
14768 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_make_1funding_1redeemscript(JNIEnv *env, jclass clz, int8_tArray broadcaster, int8_tArray countersignatory) {
14769         LDKPublicKey broadcaster_ref;
14770         CHECK((*env)->GetArrayLength(env, broadcaster) == 33);
14771         (*env)->GetByteArrayRegion(env, broadcaster, 0, 33, broadcaster_ref.compressed_form);
14772         LDKPublicKey countersignatory_ref;
14773         CHECK((*env)->GetArrayLength(env, countersignatory) == 33);
14774         (*env)->GetByteArrayRegion(env, countersignatory, 0, 33, countersignatory_ref.compressed_form);
14775         LDKCVec_u8Z arg_var = make_funding_redeemscript(broadcaster_ref, countersignatory_ref);
14776         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
14777         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
14778         CVec_u8Z_free(arg_var);
14779         return arg_arr;
14780 }
14781
14782 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_build_1htlc_1transaction(JNIEnv *env, jclass clz, int8_tArray prev_hash, int32_t feerate_per_kw, int16_t contest_delay, int64_t htlc, int8_tArray broadcaster_delayed_payment_key, int8_tArray revocation_key) {
14783         unsigned char prev_hash_arr[32];
14784         CHECK((*env)->GetArrayLength(env, prev_hash) == 32);
14785         (*env)->GetByteArrayRegion(env, prev_hash, 0, 32, prev_hash_arr);
14786         unsigned char (*prev_hash_ref)[32] = &prev_hash_arr;
14787         LDKHTLCOutputInCommitment htlc_conv;
14788         htlc_conv.inner = (void*)(htlc & (~1));
14789         htlc_conv.is_owned = false;
14790         LDKPublicKey broadcaster_delayed_payment_key_ref;
14791         CHECK((*env)->GetArrayLength(env, broadcaster_delayed_payment_key) == 33);
14792         (*env)->GetByteArrayRegion(env, broadcaster_delayed_payment_key, 0, 33, broadcaster_delayed_payment_key_ref.compressed_form);
14793         LDKPublicKey revocation_key_ref;
14794         CHECK((*env)->GetArrayLength(env, revocation_key) == 33);
14795         (*env)->GetByteArrayRegion(env, revocation_key, 0, 33, revocation_key_ref.compressed_form);
14796         LDKTransaction arg_var = build_htlc_transaction(prev_hash_ref, feerate_per_kw, contest_delay, &htlc_conv, broadcaster_delayed_payment_key_ref, revocation_key_ref);
14797         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
14798         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
14799         Transaction_free(arg_var);
14800         return arg_arr;
14801 }
14802
14803 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelTransactionParameters_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
14804         LDKChannelTransactionParameters this_ptr_conv;
14805         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14806         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
14807         ChannelTransactionParameters_free(this_ptr_conv);
14808 }
14809
14810 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelTransactionParameters_1clone(JNIEnv *env, jclass clz, int64_t orig) {
14811         LDKChannelTransactionParameters orig_conv;
14812         orig_conv.inner = (void*)(orig & (~1));
14813         orig_conv.is_owned = false;
14814         LDKChannelTransactionParameters ret_var = ChannelTransactionParameters_clone(&orig_conv);
14815         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14816         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14817         long ret_ref = (long)ret_var.inner;
14818         if (ret_var.is_owned) {
14819                 ret_ref |= 1;
14820         }
14821         return ret_ref;
14822 }
14823
14824 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelTransactionParameters_1get_1holder_1pubkeys(JNIEnv *env, jclass clz, int64_t this_ptr) {
14825         LDKChannelTransactionParameters this_ptr_conv;
14826         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14827         this_ptr_conv.is_owned = false;
14828         LDKChannelPublicKeys ret_var = ChannelTransactionParameters_get_holder_pubkeys(&this_ptr_conv);
14829         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14830         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14831         long ret_ref = (long)ret_var.inner;
14832         if (ret_var.is_owned) {
14833                 ret_ref |= 1;
14834         }
14835         return ret_ref;
14836 }
14837
14838 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelTransactionParameters_1set_1holder_1pubkeys(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
14839         LDKChannelTransactionParameters this_ptr_conv;
14840         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14841         this_ptr_conv.is_owned = false;
14842         LDKChannelPublicKeys val_conv;
14843         val_conv.inner = (void*)(val & (~1));
14844         val_conv.is_owned = (val & 1) || (val == 0);
14845         if (val_conv.inner != NULL)
14846                 val_conv = ChannelPublicKeys_clone(&val_conv);
14847         ChannelTransactionParameters_set_holder_pubkeys(&this_ptr_conv, val_conv);
14848 }
14849
14850 JNIEXPORT int16_t JNICALL Java_org_ldk_impl_bindings_ChannelTransactionParameters_1get_1holder_1selected_1contest_1delay(JNIEnv *env, jclass clz, int64_t this_ptr) {
14851         LDKChannelTransactionParameters this_ptr_conv;
14852         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14853         this_ptr_conv.is_owned = false;
14854         int16_t ret_val = ChannelTransactionParameters_get_holder_selected_contest_delay(&this_ptr_conv);
14855         return ret_val;
14856 }
14857
14858 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelTransactionParameters_1set_1holder_1selected_1contest_1delay(JNIEnv *env, jclass clz, int64_t this_ptr, int16_t val) {
14859         LDKChannelTransactionParameters this_ptr_conv;
14860         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14861         this_ptr_conv.is_owned = false;
14862         ChannelTransactionParameters_set_holder_selected_contest_delay(&this_ptr_conv, val);
14863 }
14864
14865 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_ChannelTransactionParameters_1get_1is_1outbound_1from_1holder(JNIEnv *env, jclass clz, int64_t this_ptr) {
14866         LDKChannelTransactionParameters this_ptr_conv;
14867         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14868         this_ptr_conv.is_owned = false;
14869         jboolean ret_val = ChannelTransactionParameters_get_is_outbound_from_holder(&this_ptr_conv);
14870         return ret_val;
14871 }
14872
14873 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelTransactionParameters_1set_1is_1outbound_1from_1holder(JNIEnv *env, jclass clz, int64_t this_ptr, jboolean val) {
14874         LDKChannelTransactionParameters this_ptr_conv;
14875         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14876         this_ptr_conv.is_owned = false;
14877         ChannelTransactionParameters_set_is_outbound_from_holder(&this_ptr_conv, val);
14878 }
14879
14880 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelTransactionParameters_1get_1counterparty_1parameters(JNIEnv *env, jclass clz, int64_t this_ptr) {
14881         LDKChannelTransactionParameters this_ptr_conv;
14882         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14883         this_ptr_conv.is_owned = false;
14884         LDKCounterpartyChannelTransactionParameters ret_var = ChannelTransactionParameters_get_counterparty_parameters(&this_ptr_conv);
14885         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14886         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14887         long ret_ref = (long)ret_var.inner;
14888         if (ret_var.is_owned) {
14889                 ret_ref |= 1;
14890         }
14891         return ret_ref;
14892 }
14893
14894 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelTransactionParameters_1set_1counterparty_1parameters(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
14895         LDKChannelTransactionParameters this_ptr_conv;
14896         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14897         this_ptr_conv.is_owned = false;
14898         LDKCounterpartyChannelTransactionParameters val_conv;
14899         val_conv.inner = (void*)(val & (~1));
14900         val_conv.is_owned = (val & 1) || (val == 0);
14901         if (val_conv.inner != NULL)
14902                 val_conv = CounterpartyChannelTransactionParameters_clone(&val_conv);
14903         ChannelTransactionParameters_set_counterparty_parameters(&this_ptr_conv, val_conv);
14904 }
14905
14906 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelTransactionParameters_1get_1funding_1outpoint(JNIEnv *env, jclass clz, int64_t this_ptr) {
14907         LDKChannelTransactionParameters this_ptr_conv;
14908         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14909         this_ptr_conv.is_owned = false;
14910         LDKOutPoint ret_var = ChannelTransactionParameters_get_funding_outpoint(&this_ptr_conv);
14911         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14912         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14913         long ret_ref = (long)ret_var.inner;
14914         if (ret_var.is_owned) {
14915                 ret_ref |= 1;
14916         }
14917         return ret_ref;
14918 }
14919
14920 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelTransactionParameters_1set_1funding_1outpoint(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
14921         LDKChannelTransactionParameters this_ptr_conv;
14922         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14923         this_ptr_conv.is_owned = false;
14924         LDKOutPoint val_conv;
14925         val_conv.inner = (void*)(val & (~1));
14926         val_conv.is_owned = (val & 1) || (val == 0);
14927         if (val_conv.inner != NULL)
14928                 val_conv = OutPoint_clone(&val_conv);
14929         ChannelTransactionParameters_set_funding_outpoint(&this_ptr_conv, val_conv);
14930 }
14931
14932 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelTransactionParameters_1new(JNIEnv *env, jclass clz, int64_t holder_pubkeys_arg, int16_t holder_selected_contest_delay_arg, jboolean is_outbound_from_holder_arg, int64_t counterparty_parameters_arg, int64_t funding_outpoint_arg) {
14933         LDKChannelPublicKeys holder_pubkeys_arg_conv;
14934         holder_pubkeys_arg_conv.inner = (void*)(holder_pubkeys_arg & (~1));
14935         holder_pubkeys_arg_conv.is_owned = (holder_pubkeys_arg & 1) || (holder_pubkeys_arg == 0);
14936         if (holder_pubkeys_arg_conv.inner != NULL)
14937                 holder_pubkeys_arg_conv = ChannelPublicKeys_clone(&holder_pubkeys_arg_conv);
14938         LDKCounterpartyChannelTransactionParameters counterparty_parameters_arg_conv;
14939         counterparty_parameters_arg_conv.inner = (void*)(counterparty_parameters_arg & (~1));
14940         counterparty_parameters_arg_conv.is_owned = (counterparty_parameters_arg & 1) || (counterparty_parameters_arg == 0);
14941         if (counterparty_parameters_arg_conv.inner != NULL)
14942                 counterparty_parameters_arg_conv = CounterpartyChannelTransactionParameters_clone(&counterparty_parameters_arg_conv);
14943         LDKOutPoint funding_outpoint_arg_conv;
14944         funding_outpoint_arg_conv.inner = (void*)(funding_outpoint_arg & (~1));
14945         funding_outpoint_arg_conv.is_owned = (funding_outpoint_arg & 1) || (funding_outpoint_arg == 0);
14946         if (funding_outpoint_arg_conv.inner != NULL)
14947                 funding_outpoint_arg_conv = OutPoint_clone(&funding_outpoint_arg_conv);
14948         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);
14949         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14950         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14951         long ret_ref = (long)ret_var.inner;
14952         if (ret_var.is_owned) {
14953                 ret_ref |= 1;
14954         }
14955         return ret_ref;
14956 }
14957
14958 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CounterpartyChannelTransactionParameters_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
14959         LDKCounterpartyChannelTransactionParameters 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         CounterpartyChannelTransactionParameters_free(this_ptr_conv);
14963 }
14964
14965 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CounterpartyChannelTransactionParameters_1clone(JNIEnv *env, jclass clz, int64_t orig) {
14966         LDKCounterpartyChannelTransactionParameters orig_conv;
14967         orig_conv.inner = (void*)(orig & (~1));
14968         orig_conv.is_owned = false;
14969         LDKCounterpartyChannelTransactionParameters ret_var = CounterpartyChannelTransactionParameters_clone(&orig_conv);
14970         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14971         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14972         long ret_ref = (long)ret_var.inner;
14973         if (ret_var.is_owned) {
14974                 ret_ref |= 1;
14975         }
14976         return ret_ref;
14977 }
14978
14979 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CounterpartyChannelTransactionParameters_1get_1pubkeys(JNIEnv *env, jclass clz, int64_t this_ptr) {
14980         LDKCounterpartyChannelTransactionParameters this_ptr_conv;
14981         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14982         this_ptr_conv.is_owned = false;
14983         LDKChannelPublicKeys ret_var = CounterpartyChannelTransactionParameters_get_pubkeys(&this_ptr_conv);
14984         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14985         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14986         long ret_ref = (long)ret_var.inner;
14987         if (ret_var.is_owned) {
14988                 ret_ref |= 1;
14989         }
14990         return ret_ref;
14991 }
14992
14993 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CounterpartyChannelTransactionParameters_1set_1pubkeys(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
14994         LDKCounterpartyChannelTransactionParameters this_ptr_conv;
14995         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14996         this_ptr_conv.is_owned = false;
14997         LDKChannelPublicKeys val_conv;
14998         val_conv.inner = (void*)(val & (~1));
14999         val_conv.is_owned = (val & 1) || (val == 0);
15000         if (val_conv.inner != NULL)
15001                 val_conv = ChannelPublicKeys_clone(&val_conv);
15002         CounterpartyChannelTransactionParameters_set_pubkeys(&this_ptr_conv, val_conv);
15003 }
15004
15005 JNIEXPORT int16_t JNICALL Java_org_ldk_impl_bindings_CounterpartyChannelTransactionParameters_1get_1selected_1contest_1delay(JNIEnv *env, jclass clz, int64_t this_ptr) {
15006         LDKCounterpartyChannelTransactionParameters this_ptr_conv;
15007         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15008         this_ptr_conv.is_owned = false;
15009         int16_t ret_val = CounterpartyChannelTransactionParameters_get_selected_contest_delay(&this_ptr_conv);
15010         return ret_val;
15011 }
15012
15013 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CounterpartyChannelTransactionParameters_1set_1selected_1contest_1delay(JNIEnv *env, jclass clz, int64_t this_ptr, int16_t val) {
15014         LDKCounterpartyChannelTransactionParameters this_ptr_conv;
15015         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15016         this_ptr_conv.is_owned = false;
15017         CounterpartyChannelTransactionParameters_set_selected_contest_delay(&this_ptr_conv, val);
15018 }
15019
15020 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CounterpartyChannelTransactionParameters_1new(JNIEnv *env, jclass clz, int64_t pubkeys_arg, int16_t selected_contest_delay_arg) {
15021         LDKChannelPublicKeys pubkeys_arg_conv;
15022         pubkeys_arg_conv.inner = (void*)(pubkeys_arg & (~1));
15023         pubkeys_arg_conv.is_owned = (pubkeys_arg & 1) || (pubkeys_arg == 0);
15024         if (pubkeys_arg_conv.inner != NULL)
15025                 pubkeys_arg_conv = ChannelPublicKeys_clone(&pubkeys_arg_conv);
15026         LDKCounterpartyChannelTransactionParameters ret_var = CounterpartyChannelTransactionParameters_new(pubkeys_arg_conv, selected_contest_delay_arg);
15027         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15028         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15029         long ret_ref = (long)ret_var.inner;
15030         if (ret_var.is_owned) {
15031                 ret_ref |= 1;
15032         }
15033         return ret_ref;
15034 }
15035
15036 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_ChannelTransactionParameters_1is_1populated(JNIEnv *env, jclass clz, int64_t this_arg) {
15037         LDKChannelTransactionParameters this_arg_conv;
15038         this_arg_conv.inner = (void*)(this_arg & (~1));
15039         this_arg_conv.is_owned = false;
15040         jboolean ret_val = ChannelTransactionParameters_is_populated(&this_arg_conv);
15041         return ret_val;
15042 }
15043
15044 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelTransactionParameters_1as_1holder_1broadcastable(JNIEnv *env, jclass clz, int64_t this_arg) {
15045         LDKChannelTransactionParameters this_arg_conv;
15046         this_arg_conv.inner = (void*)(this_arg & (~1));
15047         this_arg_conv.is_owned = false;
15048         LDKDirectedChannelTransactionParameters ret_var = ChannelTransactionParameters_as_holder_broadcastable(&this_arg_conv);
15049         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15050         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15051         long ret_ref = (long)ret_var.inner;
15052         if (ret_var.is_owned) {
15053                 ret_ref |= 1;
15054         }
15055         return ret_ref;
15056 }
15057
15058 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelTransactionParameters_1as_1counterparty_1broadcastable(JNIEnv *env, jclass clz, int64_t this_arg) {
15059         LDKChannelTransactionParameters this_arg_conv;
15060         this_arg_conv.inner = (void*)(this_arg & (~1));
15061         this_arg_conv.is_owned = false;
15062         LDKDirectedChannelTransactionParameters ret_var = ChannelTransactionParameters_as_counterparty_broadcastable(&this_arg_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 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_CounterpartyChannelTransactionParameters_1write(JNIEnv *env, jclass clz, int64_t obj) {
15073         LDKCounterpartyChannelTransactionParameters obj_conv;
15074         obj_conv.inner = (void*)(obj & (~1));
15075         obj_conv.is_owned = false;
15076         LDKCVec_u8Z arg_var = CounterpartyChannelTransactionParameters_write(&obj_conv);
15077         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
15078         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
15079         CVec_u8Z_free(arg_var);
15080         return arg_arr;
15081 }
15082
15083 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CounterpartyChannelTransactionParameters_1read(JNIEnv *env, jclass clz, int8_tArray ser) {
15084         LDKu8slice ser_ref;
15085         ser_ref.datalen = (*env)->GetArrayLength(env, ser);
15086         ser_ref.data = (*env)->GetByteArrayElements (env, ser, NULL);
15087         LDKCounterpartyChannelTransactionParameters ret_var = CounterpartyChannelTransactionParameters_read(ser_ref);
15088         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15089         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15090         long ret_ref = (long)ret_var.inner;
15091         if (ret_var.is_owned) {
15092                 ret_ref |= 1;
15093         }
15094         (*env)->ReleaseByteArrayElements(env, ser, (int8_t*)ser_ref.data, 0);
15095         return ret_ref;
15096 }
15097
15098 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_ChannelTransactionParameters_1write(JNIEnv *env, jclass clz, int64_t obj) {
15099         LDKChannelTransactionParameters obj_conv;
15100         obj_conv.inner = (void*)(obj & (~1));
15101         obj_conv.is_owned = false;
15102         LDKCVec_u8Z arg_var = ChannelTransactionParameters_write(&obj_conv);
15103         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
15104         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
15105         CVec_u8Z_free(arg_var);
15106         return arg_arr;
15107 }
15108
15109 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelTransactionParameters_1read(JNIEnv *env, jclass clz, int8_tArray ser) {
15110         LDKu8slice ser_ref;
15111         ser_ref.datalen = (*env)->GetArrayLength(env, ser);
15112         ser_ref.data = (*env)->GetByteArrayElements (env, ser, NULL);
15113         LDKChannelTransactionParameters ret_var = ChannelTransactionParameters_read(ser_ref);
15114         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15115         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15116         long ret_ref = (long)ret_var.inner;
15117         if (ret_var.is_owned) {
15118                 ret_ref |= 1;
15119         }
15120         (*env)->ReleaseByteArrayElements(env, ser, (int8_t*)ser_ref.data, 0);
15121         return ret_ref;
15122 }
15123
15124 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_DirectedChannelTransactionParameters_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
15125         LDKDirectedChannelTransactionParameters this_ptr_conv;
15126         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15127         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
15128         DirectedChannelTransactionParameters_free(this_ptr_conv);
15129 }
15130
15131 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_DirectedChannelTransactionParameters_1broadcaster_1pubkeys(JNIEnv *env, jclass clz, int64_t this_arg) {
15132         LDKDirectedChannelTransactionParameters this_arg_conv;
15133         this_arg_conv.inner = (void*)(this_arg & (~1));
15134         this_arg_conv.is_owned = false;
15135         LDKChannelPublicKeys ret_var = DirectedChannelTransactionParameters_broadcaster_pubkeys(&this_arg_conv);
15136         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15137         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15138         long ret_ref = (long)ret_var.inner;
15139         if (ret_var.is_owned) {
15140                 ret_ref |= 1;
15141         }
15142         return ret_ref;
15143 }
15144
15145 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_DirectedChannelTransactionParameters_1countersignatory_1pubkeys(JNIEnv *env, jclass clz, int64_t this_arg) {
15146         LDKDirectedChannelTransactionParameters this_arg_conv;
15147         this_arg_conv.inner = (void*)(this_arg & (~1));
15148         this_arg_conv.is_owned = false;
15149         LDKChannelPublicKeys ret_var = DirectedChannelTransactionParameters_countersignatory_pubkeys(&this_arg_conv);
15150         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15151         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15152         long ret_ref = (long)ret_var.inner;
15153         if (ret_var.is_owned) {
15154                 ret_ref |= 1;
15155         }
15156         return ret_ref;
15157 }
15158
15159 JNIEXPORT int16_t JNICALL Java_org_ldk_impl_bindings_DirectedChannelTransactionParameters_1contest_1delay(JNIEnv *env, jclass clz, int64_t this_arg) {
15160         LDKDirectedChannelTransactionParameters this_arg_conv;
15161         this_arg_conv.inner = (void*)(this_arg & (~1));
15162         this_arg_conv.is_owned = false;
15163         int16_t ret_val = DirectedChannelTransactionParameters_contest_delay(&this_arg_conv);
15164         return ret_val;
15165 }
15166
15167 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_DirectedChannelTransactionParameters_1is_1outbound(JNIEnv *env, jclass clz, int64_t this_arg) {
15168         LDKDirectedChannelTransactionParameters this_arg_conv;
15169         this_arg_conv.inner = (void*)(this_arg & (~1));
15170         this_arg_conv.is_owned = false;
15171         jboolean ret_val = DirectedChannelTransactionParameters_is_outbound(&this_arg_conv);
15172         return ret_val;
15173 }
15174
15175 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_DirectedChannelTransactionParameters_1funding_1outpoint(JNIEnv *env, jclass clz, int64_t this_arg) {
15176         LDKDirectedChannelTransactionParameters this_arg_conv;
15177         this_arg_conv.inner = (void*)(this_arg & (~1));
15178         this_arg_conv.is_owned = false;
15179         LDKOutPoint ret_var = DirectedChannelTransactionParameters_funding_outpoint(&this_arg_conv);
15180         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15181         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15182         long ret_ref = (long)ret_var.inner;
15183         if (ret_var.is_owned) {
15184                 ret_ref |= 1;
15185         }
15186         return ret_ref;
15187 }
15188
15189 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_HolderCommitmentTransaction_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
15190         LDKHolderCommitmentTransaction this_ptr_conv;
15191         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15192         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
15193         HolderCommitmentTransaction_free(this_ptr_conv);
15194 }
15195
15196 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_HolderCommitmentTransaction_1clone(JNIEnv *env, jclass clz, int64_t orig) {
15197         LDKHolderCommitmentTransaction orig_conv;
15198         orig_conv.inner = (void*)(orig & (~1));
15199         orig_conv.is_owned = false;
15200         LDKHolderCommitmentTransaction ret_var = HolderCommitmentTransaction_clone(&orig_conv);
15201         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15202         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15203         long ret_ref = (long)ret_var.inner;
15204         if (ret_var.is_owned) {
15205                 ret_ref |= 1;
15206         }
15207         return ret_ref;
15208 }
15209
15210 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_HolderCommitmentTransaction_1get_1counterparty_1sig(JNIEnv *env, jclass clz, int64_t this_ptr) {
15211         LDKHolderCommitmentTransaction this_ptr_conv;
15212         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15213         this_ptr_conv.is_owned = false;
15214         int8_tArray arg_arr = (*env)->NewByteArray(env, 64);
15215         (*env)->SetByteArrayRegion(env, arg_arr, 0, 64, HolderCommitmentTransaction_get_counterparty_sig(&this_ptr_conv).compact_form);
15216         return arg_arr;
15217 }
15218
15219 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_HolderCommitmentTransaction_1set_1counterparty_1sig(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
15220         LDKHolderCommitmentTransaction this_ptr_conv;
15221         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15222         this_ptr_conv.is_owned = false;
15223         LDKSignature val_ref;
15224         CHECK((*env)->GetArrayLength(env, val) == 64);
15225         (*env)->GetByteArrayRegion(env, val, 0, 64, val_ref.compact_form);
15226         HolderCommitmentTransaction_set_counterparty_sig(&this_ptr_conv, val_ref);
15227 }
15228
15229 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_HolderCommitmentTransaction_1set_1counterparty_1htlc_1sigs(JNIEnv *env, jclass clz, int64_t this_ptr, jobjectArray val) {
15230         LDKHolderCommitmentTransaction this_ptr_conv;
15231         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15232         this_ptr_conv.is_owned = false;
15233         LDKCVec_SignatureZ val_constr;
15234         val_constr.datalen = (*env)->GetArrayLength(env, val);
15235         if (val_constr.datalen > 0)
15236                 val_constr.data = MALLOC(val_constr.datalen * sizeof(LDKSignature), "LDKCVec_SignatureZ Elements");
15237         else
15238                 val_constr.data = NULL;
15239         for (size_t i = 0; i < val_constr.datalen; i++) {
15240                 int8_tArray arr_conv_8 = (*env)->GetObjectArrayElement(env, val, i);
15241                 LDKSignature arr_conv_8_ref;
15242                 CHECK((*env)->GetArrayLength(env, arr_conv_8) == 64);
15243                 (*env)->GetByteArrayRegion(env, arr_conv_8, 0, 64, arr_conv_8_ref.compact_form);
15244                 val_constr.data[i] = arr_conv_8_ref;
15245         }
15246         HolderCommitmentTransaction_set_counterparty_htlc_sigs(&this_ptr_conv, val_constr);
15247 }
15248
15249 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_HolderCommitmentTransaction_1write(JNIEnv *env, jclass clz, int64_t obj) {
15250         LDKHolderCommitmentTransaction obj_conv;
15251         obj_conv.inner = (void*)(obj & (~1));
15252         obj_conv.is_owned = false;
15253         LDKCVec_u8Z arg_var = HolderCommitmentTransaction_write(&obj_conv);
15254         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
15255         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
15256         CVec_u8Z_free(arg_var);
15257         return arg_arr;
15258 }
15259
15260 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_HolderCommitmentTransaction_1read(JNIEnv *env, jclass clz, int8_tArray ser) {
15261         LDKu8slice ser_ref;
15262         ser_ref.datalen = (*env)->GetArrayLength(env, ser);
15263         ser_ref.data = (*env)->GetByteArrayElements (env, ser, NULL);
15264         LDKHolderCommitmentTransaction ret_var = HolderCommitmentTransaction_read(ser_ref);
15265         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15266         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15267         long ret_ref = (long)ret_var.inner;
15268         if (ret_var.is_owned) {
15269                 ret_ref |= 1;
15270         }
15271         (*env)->ReleaseByteArrayElements(env, ser, (int8_t*)ser_ref.data, 0);
15272         return ret_ref;
15273 }
15274
15275 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_HolderCommitmentTransaction_1new(JNIEnv *env, jclass clz, int64_t commitment_tx, int8_tArray counterparty_sig, jobjectArray counterparty_htlc_sigs, int8_tArray holder_funding_key, int8_tArray counterparty_funding_key) {
15276         LDKCommitmentTransaction commitment_tx_conv;
15277         commitment_tx_conv.inner = (void*)(commitment_tx & (~1));
15278         commitment_tx_conv.is_owned = (commitment_tx & 1) || (commitment_tx == 0);
15279         if (commitment_tx_conv.inner != NULL)
15280                 commitment_tx_conv = CommitmentTransaction_clone(&commitment_tx_conv);
15281         LDKSignature counterparty_sig_ref;
15282         CHECK((*env)->GetArrayLength(env, counterparty_sig) == 64);
15283         (*env)->GetByteArrayRegion(env, counterparty_sig, 0, 64, counterparty_sig_ref.compact_form);
15284         LDKCVec_SignatureZ counterparty_htlc_sigs_constr;
15285         counterparty_htlc_sigs_constr.datalen = (*env)->GetArrayLength(env, counterparty_htlc_sigs);
15286         if (counterparty_htlc_sigs_constr.datalen > 0)
15287                 counterparty_htlc_sigs_constr.data = MALLOC(counterparty_htlc_sigs_constr.datalen * sizeof(LDKSignature), "LDKCVec_SignatureZ Elements");
15288         else
15289                 counterparty_htlc_sigs_constr.data = NULL;
15290         for (size_t i = 0; i < counterparty_htlc_sigs_constr.datalen; i++) {
15291                 int8_tArray arr_conv_8 = (*env)->GetObjectArrayElement(env, counterparty_htlc_sigs, i);
15292                 LDKSignature arr_conv_8_ref;
15293                 CHECK((*env)->GetArrayLength(env, arr_conv_8) == 64);
15294                 (*env)->GetByteArrayRegion(env, arr_conv_8, 0, 64, arr_conv_8_ref.compact_form);
15295                 counterparty_htlc_sigs_constr.data[i] = arr_conv_8_ref;
15296         }
15297         LDKPublicKey holder_funding_key_ref;
15298         CHECK((*env)->GetArrayLength(env, holder_funding_key) == 33);
15299         (*env)->GetByteArrayRegion(env, holder_funding_key, 0, 33, holder_funding_key_ref.compressed_form);
15300         LDKPublicKey counterparty_funding_key_ref;
15301         CHECK((*env)->GetArrayLength(env, counterparty_funding_key) == 33);
15302         (*env)->GetByteArrayRegion(env, counterparty_funding_key, 0, 33, counterparty_funding_key_ref.compressed_form);
15303         LDKHolderCommitmentTransaction ret_var = HolderCommitmentTransaction_new(commitment_tx_conv, counterparty_sig_ref, counterparty_htlc_sigs_constr, holder_funding_key_ref, counterparty_funding_key_ref);
15304         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15305         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15306         long ret_ref = (long)ret_var.inner;
15307         if (ret_var.is_owned) {
15308                 ret_ref |= 1;
15309         }
15310         return ret_ref;
15311 }
15312
15313 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_BuiltCommitmentTransaction_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
15314         LDKBuiltCommitmentTransaction this_ptr_conv;
15315         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15316         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
15317         BuiltCommitmentTransaction_free(this_ptr_conv);
15318 }
15319
15320 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_BuiltCommitmentTransaction_1clone(JNIEnv *env, jclass clz, int64_t orig) {
15321         LDKBuiltCommitmentTransaction orig_conv;
15322         orig_conv.inner = (void*)(orig & (~1));
15323         orig_conv.is_owned = false;
15324         LDKBuiltCommitmentTransaction ret_var = BuiltCommitmentTransaction_clone(&orig_conv);
15325         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15326         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15327         long ret_ref = (long)ret_var.inner;
15328         if (ret_var.is_owned) {
15329                 ret_ref |= 1;
15330         }
15331         return ret_ref;
15332 }
15333
15334 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_BuiltCommitmentTransaction_1get_1transaction(JNIEnv *env, jclass clz, int64_t this_ptr) {
15335         LDKBuiltCommitmentTransaction this_ptr_conv;
15336         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15337         this_ptr_conv.is_owned = false;
15338         LDKTransaction arg_var = BuiltCommitmentTransaction_get_transaction(&this_ptr_conv);
15339         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
15340         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
15341         Transaction_free(arg_var);
15342         return arg_arr;
15343 }
15344
15345 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_BuiltCommitmentTransaction_1set_1transaction(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
15346         LDKBuiltCommitmentTransaction this_ptr_conv;
15347         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15348         this_ptr_conv.is_owned = false;
15349         LDKTransaction val_ref;
15350         val_ref.datalen = (*env)->GetArrayLength(env, val);
15351         val_ref.data = MALLOC(val_ref.datalen, "LDKTransaction Bytes");
15352         (*env)->GetByteArrayRegion(env, val, 0, val_ref.datalen, val_ref.data);
15353         val_ref.data_is_owned = true;
15354         BuiltCommitmentTransaction_set_transaction(&this_ptr_conv, val_ref);
15355 }
15356
15357 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_BuiltCommitmentTransaction_1get_1txid(JNIEnv *env, jclass clz, int64_t this_ptr) {
15358         LDKBuiltCommitmentTransaction this_ptr_conv;
15359         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15360         this_ptr_conv.is_owned = false;
15361         int8_tArray ret_arr = (*env)->NewByteArray(env, 32);
15362         (*env)->SetByteArrayRegion(env, ret_arr, 0, 32, *BuiltCommitmentTransaction_get_txid(&this_ptr_conv));
15363         return ret_arr;
15364 }
15365
15366 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_BuiltCommitmentTransaction_1set_1txid(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
15367         LDKBuiltCommitmentTransaction this_ptr_conv;
15368         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15369         this_ptr_conv.is_owned = false;
15370         LDKThirtyTwoBytes val_ref;
15371         CHECK((*env)->GetArrayLength(env, val) == 32);
15372         (*env)->GetByteArrayRegion(env, val, 0, 32, val_ref.data);
15373         BuiltCommitmentTransaction_set_txid(&this_ptr_conv, val_ref);
15374 }
15375
15376 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_BuiltCommitmentTransaction_1new(JNIEnv *env, jclass clz, int8_tArray transaction_arg, int8_tArray txid_arg) {
15377         LDKTransaction transaction_arg_ref;
15378         transaction_arg_ref.datalen = (*env)->GetArrayLength(env, transaction_arg);
15379         transaction_arg_ref.data = MALLOC(transaction_arg_ref.datalen, "LDKTransaction Bytes");
15380         (*env)->GetByteArrayRegion(env, transaction_arg, 0, transaction_arg_ref.datalen, transaction_arg_ref.data);
15381         transaction_arg_ref.data_is_owned = true;
15382         LDKThirtyTwoBytes txid_arg_ref;
15383         CHECK((*env)->GetArrayLength(env, txid_arg) == 32);
15384         (*env)->GetByteArrayRegion(env, txid_arg, 0, 32, txid_arg_ref.data);
15385         LDKBuiltCommitmentTransaction ret_var = BuiltCommitmentTransaction_new(transaction_arg_ref, txid_arg_ref);
15386         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15387         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15388         long ret_ref = (long)ret_var.inner;
15389         if (ret_var.is_owned) {
15390                 ret_ref |= 1;
15391         }
15392         return ret_ref;
15393 }
15394
15395 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_BuiltCommitmentTransaction_1write(JNIEnv *env, jclass clz, int64_t obj) {
15396         LDKBuiltCommitmentTransaction obj_conv;
15397         obj_conv.inner = (void*)(obj & (~1));
15398         obj_conv.is_owned = false;
15399         LDKCVec_u8Z arg_var = BuiltCommitmentTransaction_write(&obj_conv);
15400         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
15401         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
15402         CVec_u8Z_free(arg_var);
15403         return arg_arr;
15404 }
15405
15406 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_BuiltCommitmentTransaction_1read(JNIEnv *env, jclass clz, int8_tArray ser) {
15407         LDKu8slice ser_ref;
15408         ser_ref.datalen = (*env)->GetArrayLength(env, ser);
15409         ser_ref.data = (*env)->GetByteArrayElements (env, ser, NULL);
15410         LDKBuiltCommitmentTransaction ret_var = BuiltCommitmentTransaction_read(ser_ref);
15411         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15412         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15413         long ret_ref = (long)ret_var.inner;
15414         if (ret_var.is_owned) {
15415                 ret_ref |= 1;
15416         }
15417         (*env)->ReleaseByteArrayElements(env, ser, (int8_t*)ser_ref.data, 0);
15418         return ret_ref;
15419 }
15420
15421 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_BuiltCommitmentTransaction_1get_1sighash_1all(JNIEnv *env, jclass clz, int64_t this_arg, int8_tArray funding_redeemscript, int64_t channel_value_satoshis) {
15422         LDKBuiltCommitmentTransaction this_arg_conv;
15423         this_arg_conv.inner = (void*)(this_arg & (~1));
15424         this_arg_conv.is_owned = false;
15425         LDKu8slice funding_redeemscript_ref;
15426         funding_redeemscript_ref.datalen = (*env)->GetArrayLength(env, funding_redeemscript);
15427         funding_redeemscript_ref.data = (*env)->GetByteArrayElements (env, funding_redeemscript, NULL);
15428         int8_tArray arg_arr = (*env)->NewByteArray(env, 32);
15429         (*env)->SetByteArrayRegion(env, arg_arr, 0, 32, BuiltCommitmentTransaction_get_sighash_all(&this_arg_conv, funding_redeemscript_ref, channel_value_satoshis).data);
15430         (*env)->ReleaseByteArrayElements(env, funding_redeemscript, (int8_t*)funding_redeemscript_ref.data, 0);
15431         return arg_arr;
15432 }
15433
15434 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_BuiltCommitmentTransaction_1sign(JNIEnv *env, jclass clz, int64_t this_arg, int8_tArray funding_key, int8_tArray funding_redeemscript, int64_t channel_value_satoshis) {
15435         LDKBuiltCommitmentTransaction this_arg_conv;
15436         this_arg_conv.inner = (void*)(this_arg & (~1));
15437         this_arg_conv.is_owned = false;
15438         unsigned char funding_key_arr[32];
15439         CHECK((*env)->GetArrayLength(env, funding_key) == 32);
15440         (*env)->GetByteArrayRegion(env, funding_key, 0, 32, funding_key_arr);
15441         unsigned char (*funding_key_ref)[32] = &funding_key_arr;
15442         LDKu8slice funding_redeemscript_ref;
15443         funding_redeemscript_ref.datalen = (*env)->GetArrayLength(env, funding_redeemscript);
15444         funding_redeemscript_ref.data = (*env)->GetByteArrayElements (env, funding_redeemscript, NULL);
15445         int8_tArray arg_arr = (*env)->NewByteArray(env, 64);
15446         (*env)->SetByteArrayRegion(env, arg_arr, 0, 64, BuiltCommitmentTransaction_sign(&this_arg_conv, funding_key_ref, funding_redeemscript_ref, channel_value_satoshis).compact_form);
15447         (*env)->ReleaseByteArrayElements(env, funding_redeemscript, (int8_t*)funding_redeemscript_ref.data, 0);
15448         return arg_arr;
15449 }
15450
15451 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CommitmentTransaction_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
15452         LDKCommitmentTransaction this_ptr_conv;
15453         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15454         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
15455         CommitmentTransaction_free(this_ptr_conv);
15456 }
15457
15458 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CommitmentTransaction_1clone(JNIEnv *env, jclass clz, int64_t orig) {
15459         LDKCommitmentTransaction orig_conv;
15460         orig_conv.inner = (void*)(orig & (~1));
15461         orig_conv.is_owned = false;
15462         LDKCommitmentTransaction ret_var = CommitmentTransaction_clone(&orig_conv);
15463         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15464         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15465         long ret_ref = (long)ret_var.inner;
15466         if (ret_var.is_owned) {
15467                 ret_ref |= 1;
15468         }
15469         return ret_ref;
15470 }
15471
15472 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_CommitmentTransaction_1write(JNIEnv *env, jclass clz, int64_t obj) {
15473         LDKCommitmentTransaction obj_conv;
15474         obj_conv.inner = (void*)(obj & (~1));
15475         obj_conv.is_owned = false;
15476         LDKCVec_u8Z arg_var = CommitmentTransaction_write(&obj_conv);
15477         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
15478         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
15479         CVec_u8Z_free(arg_var);
15480         return arg_arr;
15481 }
15482
15483 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CommitmentTransaction_1read(JNIEnv *env, jclass clz, int8_tArray ser) {
15484         LDKu8slice ser_ref;
15485         ser_ref.datalen = (*env)->GetArrayLength(env, ser);
15486         ser_ref.data = (*env)->GetByteArrayElements (env, ser, NULL);
15487         LDKCommitmentTransaction ret_var = CommitmentTransaction_read(ser_ref);
15488         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15489         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15490         long ret_ref = (long)ret_var.inner;
15491         if (ret_var.is_owned) {
15492                 ret_ref |= 1;
15493         }
15494         (*env)->ReleaseByteArrayElements(env, ser, (int8_t*)ser_ref.data, 0);
15495         return ret_ref;
15496 }
15497
15498 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CommitmentTransaction_1commitment_1number(JNIEnv *env, jclass clz, int64_t this_arg) {
15499         LDKCommitmentTransaction this_arg_conv;
15500         this_arg_conv.inner = (void*)(this_arg & (~1));
15501         this_arg_conv.is_owned = false;
15502         int64_t ret_val = CommitmentTransaction_commitment_number(&this_arg_conv);
15503         return ret_val;
15504 }
15505
15506 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CommitmentTransaction_1to_1broadcaster_1value_1sat(JNIEnv *env, jclass clz, int64_t this_arg) {
15507         LDKCommitmentTransaction this_arg_conv;
15508         this_arg_conv.inner = (void*)(this_arg & (~1));
15509         this_arg_conv.is_owned = false;
15510         int64_t ret_val = CommitmentTransaction_to_broadcaster_value_sat(&this_arg_conv);
15511         return ret_val;
15512 }
15513
15514 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CommitmentTransaction_1to_1countersignatory_1value_1sat(JNIEnv *env, jclass clz, int64_t this_arg) {
15515         LDKCommitmentTransaction this_arg_conv;
15516         this_arg_conv.inner = (void*)(this_arg & (~1));
15517         this_arg_conv.is_owned = false;
15518         int64_t ret_val = CommitmentTransaction_to_countersignatory_value_sat(&this_arg_conv);
15519         return ret_val;
15520 }
15521
15522 JNIEXPORT int32_t JNICALL Java_org_ldk_impl_bindings_CommitmentTransaction_1feerate_1per_1kw(JNIEnv *env, jclass clz, int64_t this_arg) {
15523         LDKCommitmentTransaction this_arg_conv;
15524         this_arg_conv.inner = (void*)(this_arg & (~1));
15525         this_arg_conv.is_owned = false;
15526         int32_t ret_val = CommitmentTransaction_feerate_per_kw(&this_arg_conv);
15527         return ret_val;
15528 }
15529
15530 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CommitmentTransaction_1trust(JNIEnv *env, jclass clz, int64_t this_arg) {
15531         LDKCommitmentTransaction this_arg_conv;
15532         this_arg_conv.inner = (void*)(this_arg & (~1));
15533         this_arg_conv.is_owned = false;
15534         LDKTrustedCommitmentTransaction ret_var = CommitmentTransaction_trust(&this_arg_conv);
15535         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15536         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15537         long ret_ref = (long)ret_var.inner;
15538         if (ret_var.is_owned) {
15539                 ret_ref |= 1;
15540         }
15541         return ret_ref;
15542 }
15543
15544 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CommitmentTransaction_1verify(JNIEnv *env, jclass clz, int64_t this_arg, int64_t channel_parameters, int64_t broadcaster_keys, int64_t countersignatory_keys) {
15545         LDKCommitmentTransaction this_arg_conv;
15546         this_arg_conv.inner = (void*)(this_arg & (~1));
15547         this_arg_conv.is_owned = false;
15548         LDKDirectedChannelTransactionParameters channel_parameters_conv;
15549         channel_parameters_conv.inner = (void*)(channel_parameters & (~1));
15550         channel_parameters_conv.is_owned = false;
15551         LDKChannelPublicKeys broadcaster_keys_conv;
15552         broadcaster_keys_conv.inner = (void*)(broadcaster_keys & (~1));
15553         broadcaster_keys_conv.is_owned = false;
15554         LDKChannelPublicKeys countersignatory_keys_conv;
15555         countersignatory_keys_conv.inner = (void*)(countersignatory_keys & (~1));
15556         countersignatory_keys_conv.is_owned = false;
15557         LDKCResult_TrustedCommitmentTransactionNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_TrustedCommitmentTransactionNoneZ), "LDKCResult_TrustedCommitmentTransactionNoneZ");
15558         *ret_conv = CommitmentTransaction_verify(&this_arg_conv, &channel_parameters_conv, &broadcaster_keys_conv, &countersignatory_keys_conv);
15559         return (long)ret_conv;
15560 }
15561
15562 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_TrustedCommitmentTransaction_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
15563         LDKTrustedCommitmentTransaction this_ptr_conv;
15564         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15565         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
15566         TrustedCommitmentTransaction_free(this_ptr_conv);
15567 }
15568
15569 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_TrustedCommitmentTransaction_1txid(JNIEnv *env, jclass clz, int64_t this_arg) {
15570         LDKTrustedCommitmentTransaction this_arg_conv;
15571         this_arg_conv.inner = (void*)(this_arg & (~1));
15572         this_arg_conv.is_owned = false;
15573         int8_tArray arg_arr = (*env)->NewByteArray(env, 32);
15574         (*env)->SetByteArrayRegion(env, arg_arr, 0, 32, TrustedCommitmentTransaction_txid(&this_arg_conv).data);
15575         return arg_arr;
15576 }
15577
15578 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_TrustedCommitmentTransaction_1built_1transaction(JNIEnv *env, jclass clz, int64_t this_arg) {
15579         LDKTrustedCommitmentTransaction this_arg_conv;
15580         this_arg_conv.inner = (void*)(this_arg & (~1));
15581         this_arg_conv.is_owned = false;
15582         LDKBuiltCommitmentTransaction ret_var = TrustedCommitmentTransaction_built_transaction(&this_arg_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 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_TrustedCommitmentTransaction_1keys(JNIEnv *env, jclass clz, int64_t this_arg) {
15593         LDKTrustedCommitmentTransaction this_arg_conv;
15594         this_arg_conv.inner = (void*)(this_arg & (~1));
15595         this_arg_conv.is_owned = false;
15596         LDKTxCreationKeys ret_var = TrustedCommitmentTransaction_keys(&this_arg_conv);
15597         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15598         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15599         long ret_ref = (long)ret_var.inner;
15600         if (ret_var.is_owned) {
15601                 ret_ref |= 1;
15602         }
15603         return ret_ref;
15604 }
15605
15606 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_TrustedCommitmentTransaction_1get_1htlc_1sigs(JNIEnv *env, jclass clz, int64_t this_arg, int8_tArray htlc_base_key, int64_t channel_parameters) {
15607         LDKTrustedCommitmentTransaction this_arg_conv;
15608         this_arg_conv.inner = (void*)(this_arg & (~1));
15609         this_arg_conv.is_owned = false;
15610         unsigned char htlc_base_key_arr[32];
15611         CHECK((*env)->GetArrayLength(env, htlc_base_key) == 32);
15612         (*env)->GetByteArrayRegion(env, htlc_base_key, 0, 32, htlc_base_key_arr);
15613         unsigned char (*htlc_base_key_ref)[32] = &htlc_base_key_arr;
15614         LDKDirectedChannelTransactionParameters channel_parameters_conv;
15615         channel_parameters_conv.inner = (void*)(channel_parameters & (~1));
15616         channel_parameters_conv.is_owned = false;
15617         LDKCResult_CVec_SignatureZNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_CVec_SignatureZNoneZ), "LDKCResult_CVec_SignatureZNoneZ");
15618         *ret_conv = TrustedCommitmentTransaction_get_htlc_sigs(&this_arg_conv, htlc_base_key_ref, &channel_parameters_conv);
15619         return (long)ret_conv;
15620 }
15621
15622 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_get_1commitment_1transaction_1number_1obscure_1factor(JNIEnv *env, jclass clz, int8_tArray broadcaster_payment_basepoint, int8_tArray countersignatory_payment_basepoint, jboolean outbound_from_broadcaster) {
15623         LDKPublicKey broadcaster_payment_basepoint_ref;
15624         CHECK((*env)->GetArrayLength(env, broadcaster_payment_basepoint) == 33);
15625         (*env)->GetByteArrayRegion(env, broadcaster_payment_basepoint, 0, 33, broadcaster_payment_basepoint_ref.compressed_form);
15626         LDKPublicKey countersignatory_payment_basepoint_ref;
15627         CHECK((*env)->GetArrayLength(env, countersignatory_payment_basepoint) == 33);
15628         (*env)->GetByteArrayRegion(env, countersignatory_payment_basepoint, 0, 33, countersignatory_payment_basepoint_ref.compressed_form);
15629         int64_t ret_val = get_commitment_transaction_number_obscure_factor(broadcaster_payment_basepoint_ref, countersignatory_payment_basepoint_ref, outbound_from_broadcaster);
15630         return ret_val;
15631 }
15632
15633 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_InitFeatures_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
15634         LDKInitFeatures this_ptr_conv;
15635         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15636         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
15637         InitFeatures_free(this_ptr_conv);
15638 }
15639
15640 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NodeFeatures_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
15641         LDKNodeFeatures this_ptr_conv;
15642         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15643         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
15644         NodeFeatures_free(this_ptr_conv);
15645 }
15646
15647 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelFeatures_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
15648         LDKChannelFeatures this_ptr_conv;
15649         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15650         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
15651         ChannelFeatures_free(this_ptr_conv);
15652 }
15653
15654 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RouteHop_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
15655         LDKRouteHop this_ptr_conv;
15656         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15657         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
15658         RouteHop_free(this_ptr_conv);
15659 }
15660
15661 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_RouteHop_1clone(JNIEnv *env, jclass clz, int64_t orig) {
15662         LDKRouteHop orig_conv;
15663         orig_conv.inner = (void*)(orig & (~1));
15664         orig_conv.is_owned = false;
15665         LDKRouteHop ret_var = RouteHop_clone(&orig_conv);
15666         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15667         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15668         long ret_ref = (long)ret_var.inner;
15669         if (ret_var.is_owned) {
15670                 ret_ref |= 1;
15671         }
15672         return ret_ref;
15673 }
15674
15675 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_RouteHop_1get_1pubkey(JNIEnv *env, jclass clz, int64_t this_ptr) {
15676         LDKRouteHop this_ptr_conv;
15677         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15678         this_ptr_conv.is_owned = false;
15679         int8_tArray arg_arr = (*env)->NewByteArray(env, 33);
15680         (*env)->SetByteArrayRegion(env, arg_arr, 0, 33, RouteHop_get_pubkey(&this_ptr_conv).compressed_form);
15681         return arg_arr;
15682 }
15683
15684 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RouteHop_1set_1pubkey(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
15685         LDKRouteHop this_ptr_conv;
15686         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15687         this_ptr_conv.is_owned = false;
15688         LDKPublicKey val_ref;
15689         CHECK((*env)->GetArrayLength(env, val) == 33);
15690         (*env)->GetByteArrayRegion(env, val, 0, 33, val_ref.compressed_form);
15691         RouteHop_set_pubkey(&this_ptr_conv, val_ref);
15692 }
15693
15694 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_RouteHop_1get_1node_1features(JNIEnv *env, jclass clz, int64_t this_ptr) {
15695         LDKRouteHop this_ptr_conv;
15696         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15697         this_ptr_conv.is_owned = false;
15698         LDKNodeFeatures ret_var = RouteHop_get_node_features(&this_ptr_conv);
15699         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15700         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15701         long ret_ref = (long)ret_var.inner;
15702         if (ret_var.is_owned) {
15703                 ret_ref |= 1;
15704         }
15705         return ret_ref;
15706 }
15707
15708 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RouteHop_1set_1node_1features(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
15709         LDKRouteHop this_ptr_conv;
15710         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15711         this_ptr_conv.is_owned = false;
15712         LDKNodeFeatures val_conv;
15713         val_conv.inner = (void*)(val & (~1));
15714         val_conv.is_owned = (val & 1) || (val == 0);
15715         // Warning: we may need a move here but can't clone!
15716         RouteHop_set_node_features(&this_ptr_conv, val_conv);
15717 }
15718
15719 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_RouteHop_1get_1short_1channel_1id(JNIEnv *env, jclass clz, int64_t this_ptr) {
15720         LDKRouteHop this_ptr_conv;
15721         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15722         this_ptr_conv.is_owned = false;
15723         int64_t ret_val = RouteHop_get_short_channel_id(&this_ptr_conv);
15724         return ret_val;
15725 }
15726
15727 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RouteHop_1set_1short_1channel_1id(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
15728         LDKRouteHop this_ptr_conv;
15729         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15730         this_ptr_conv.is_owned = false;
15731         RouteHop_set_short_channel_id(&this_ptr_conv, val);
15732 }
15733
15734 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_RouteHop_1get_1channel_1features(JNIEnv *env, jclass clz, int64_t this_ptr) {
15735         LDKRouteHop this_ptr_conv;
15736         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15737         this_ptr_conv.is_owned = false;
15738         LDKChannelFeatures ret_var = RouteHop_get_channel_features(&this_ptr_conv);
15739         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15740         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15741         long ret_ref = (long)ret_var.inner;
15742         if (ret_var.is_owned) {
15743                 ret_ref |= 1;
15744         }
15745         return ret_ref;
15746 }
15747
15748 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RouteHop_1set_1channel_1features(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
15749         LDKRouteHop this_ptr_conv;
15750         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15751         this_ptr_conv.is_owned = false;
15752         LDKChannelFeatures val_conv;
15753         val_conv.inner = (void*)(val & (~1));
15754         val_conv.is_owned = (val & 1) || (val == 0);
15755         // Warning: we may need a move here but can't clone!
15756         RouteHop_set_channel_features(&this_ptr_conv, val_conv);
15757 }
15758
15759 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_RouteHop_1get_1fee_1msat(JNIEnv *env, jclass clz, int64_t this_ptr) {
15760         LDKRouteHop this_ptr_conv;
15761         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15762         this_ptr_conv.is_owned = false;
15763         int64_t ret_val = RouteHop_get_fee_msat(&this_ptr_conv);
15764         return ret_val;
15765 }
15766
15767 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RouteHop_1set_1fee_1msat(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
15768         LDKRouteHop this_ptr_conv;
15769         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15770         this_ptr_conv.is_owned = false;
15771         RouteHop_set_fee_msat(&this_ptr_conv, val);
15772 }
15773
15774 JNIEXPORT int32_t JNICALL Java_org_ldk_impl_bindings_RouteHop_1get_1cltv_1expiry_1delta(JNIEnv *env, jclass clz, int64_t this_ptr) {
15775         LDKRouteHop this_ptr_conv;
15776         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15777         this_ptr_conv.is_owned = false;
15778         int32_t ret_val = RouteHop_get_cltv_expiry_delta(&this_ptr_conv);
15779         return ret_val;
15780 }
15781
15782 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RouteHop_1set_1cltv_1expiry_1delta(JNIEnv *env, jclass clz, int64_t this_ptr, int32_t val) {
15783         LDKRouteHop this_ptr_conv;
15784         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15785         this_ptr_conv.is_owned = false;
15786         RouteHop_set_cltv_expiry_delta(&this_ptr_conv, val);
15787 }
15788
15789 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_RouteHop_1new(JNIEnv *env, jclass clz, int8_tArray pubkey_arg, int64_t node_features_arg, int64_t short_channel_id_arg, int64_t channel_features_arg, int64_t fee_msat_arg, int32_t cltv_expiry_delta_arg) {
15790         LDKPublicKey pubkey_arg_ref;
15791         CHECK((*env)->GetArrayLength(env, pubkey_arg) == 33);
15792         (*env)->GetByteArrayRegion(env, pubkey_arg, 0, 33, pubkey_arg_ref.compressed_form);
15793         LDKNodeFeatures node_features_arg_conv;
15794         node_features_arg_conv.inner = (void*)(node_features_arg & (~1));
15795         node_features_arg_conv.is_owned = (node_features_arg & 1) || (node_features_arg == 0);
15796         // Warning: we may need a move here but can't clone!
15797         LDKChannelFeatures channel_features_arg_conv;
15798         channel_features_arg_conv.inner = (void*)(channel_features_arg & (~1));
15799         channel_features_arg_conv.is_owned = (channel_features_arg & 1) || (channel_features_arg == 0);
15800         // Warning: we may need a move here but can't clone!
15801         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);
15802         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15803         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15804         long ret_ref = (long)ret_var.inner;
15805         if (ret_var.is_owned) {
15806                 ret_ref |= 1;
15807         }
15808         return ret_ref;
15809 }
15810
15811 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Route_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
15812         LDKRoute this_ptr_conv;
15813         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15814         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
15815         Route_free(this_ptr_conv);
15816 }
15817
15818 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_Route_1clone(JNIEnv *env, jclass clz, int64_t orig) {
15819         LDKRoute orig_conv;
15820         orig_conv.inner = (void*)(orig & (~1));
15821         orig_conv.is_owned = false;
15822         LDKRoute ret_var = Route_clone(&orig_conv);
15823         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15824         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15825         long ret_ref = (long)ret_var.inner;
15826         if (ret_var.is_owned) {
15827                 ret_ref |= 1;
15828         }
15829         return ret_ref;
15830 }
15831
15832 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Route_1set_1paths(JNIEnv *env, jclass clz, int64_t this_ptr, jobjectArray val) {
15833         LDKRoute this_ptr_conv;
15834         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15835         this_ptr_conv.is_owned = false;
15836         LDKCVec_CVec_RouteHopZZ val_constr;
15837         val_constr.datalen = (*env)->GetArrayLength(env, val);
15838         if (val_constr.datalen > 0)
15839                 val_constr.data = MALLOC(val_constr.datalen * sizeof(LDKCVec_RouteHopZ), "LDKCVec_CVec_RouteHopZZ Elements");
15840         else
15841                 val_constr.data = NULL;
15842         for (size_t m = 0; m < val_constr.datalen; m++) {
15843                 int64_tArray arr_conv_12 = (*env)->GetObjectArrayElement(env, val, m);
15844                 LDKCVec_RouteHopZ arr_conv_12_constr;
15845                 arr_conv_12_constr.datalen = (*env)->GetArrayLength(env, arr_conv_12);
15846                 if (arr_conv_12_constr.datalen > 0)
15847                         arr_conv_12_constr.data = MALLOC(arr_conv_12_constr.datalen * sizeof(LDKRouteHop), "LDKCVec_RouteHopZ Elements");
15848                 else
15849                         arr_conv_12_constr.data = NULL;
15850                 int64_t* arr_conv_12_vals = (*env)->GetLongArrayElements (env, arr_conv_12, NULL);
15851                 for (size_t k = 0; k < arr_conv_12_constr.datalen; k++) {
15852                         int64_t arr_conv_10 = arr_conv_12_vals[k];
15853                         LDKRouteHop arr_conv_10_conv;
15854                         arr_conv_10_conv.inner = (void*)(arr_conv_10 & (~1));
15855                         arr_conv_10_conv.is_owned = (arr_conv_10 & 1) || (arr_conv_10 == 0);
15856                         if (arr_conv_10_conv.inner != NULL)
15857                                 arr_conv_10_conv = RouteHop_clone(&arr_conv_10_conv);
15858                         arr_conv_12_constr.data[k] = arr_conv_10_conv;
15859                 }
15860                 (*env)->ReleaseLongArrayElements(env, arr_conv_12, arr_conv_12_vals, 0);
15861                 val_constr.data[m] = arr_conv_12_constr;
15862         }
15863         Route_set_paths(&this_ptr_conv, val_constr);
15864 }
15865
15866 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_Route_1new(JNIEnv *env, jclass clz, jobjectArray paths_arg) {
15867         LDKCVec_CVec_RouteHopZZ paths_arg_constr;
15868         paths_arg_constr.datalen = (*env)->GetArrayLength(env, paths_arg);
15869         if (paths_arg_constr.datalen > 0)
15870                 paths_arg_constr.data = MALLOC(paths_arg_constr.datalen * sizeof(LDKCVec_RouteHopZ), "LDKCVec_CVec_RouteHopZZ Elements");
15871         else
15872                 paths_arg_constr.data = NULL;
15873         for (size_t m = 0; m < paths_arg_constr.datalen; m++) {
15874                 int64_tArray arr_conv_12 = (*env)->GetObjectArrayElement(env, paths_arg, m);
15875                 LDKCVec_RouteHopZ arr_conv_12_constr;
15876                 arr_conv_12_constr.datalen = (*env)->GetArrayLength(env, arr_conv_12);
15877                 if (arr_conv_12_constr.datalen > 0)
15878                         arr_conv_12_constr.data = MALLOC(arr_conv_12_constr.datalen * sizeof(LDKRouteHop), "LDKCVec_RouteHopZ Elements");
15879                 else
15880                         arr_conv_12_constr.data = NULL;
15881                 int64_t* arr_conv_12_vals = (*env)->GetLongArrayElements (env, arr_conv_12, NULL);
15882                 for (size_t k = 0; k < arr_conv_12_constr.datalen; k++) {
15883                         int64_t arr_conv_10 = arr_conv_12_vals[k];
15884                         LDKRouteHop arr_conv_10_conv;
15885                         arr_conv_10_conv.inner = (void*)(arr_conv_10 & (~1));
15886                         arr_conv_10_conv.is_owned = (arr_conv_10 & 1) || (arr_conv_10 == 0);
15887                         if (arr_conv_10_conv.inner != NULL)
15888                                 arr_conv_10_conv = RouteHop_clone(&arr_conv_10_conv);
15889                         arr_conv_12_constr.data[k] = arr_conv_10_conv;
15890                 }
15891                 (*env)->ReleaseLongArrayElements(env, arr_conv_12, arr_conv_12_vals, 0);
15892                 paths_arg_constr.data[m] = arr_conv_12_constr;
15893         }
15894         LDKRoute ret_var = Route_new(paths_arg_constr);
15895         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15896         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15897         long ret_ref = (long)ret_var.inner;
15898         if (ret_var.is_owned) {
15899                 ret_ref |= 1;
15900         }
15901         return ret_ref;
15902 }
15903
15904 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_Route_1write(JNIEnv *env, jclass clz, int64_t obj) {
15905         LDKRoute obj_conv;
15906         obj_conv.inner = (void*)(obj & (~1));
15907         obj_conv.is_owned = false;
15908         LDKCVec_u8Z arg_var = Route_write(&obj_conv);
15909         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
15910         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
15911         CVec_u8Z_free(arg_var);
15912         return arg_arr;
15913 }
15914
15915 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_Route_1read(JNIEnv *env, jclass clz, int8_tArray ser) {
15916         LDKu8slice ser_ref;
15917         ser_ref.datalen = (*env)->GetArrayLength(env, ser);
15918         ser_ref.data = (*env)->GetByteArrayElements (env, ser, NULL);
15919         LDKCResult_RouteDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_RouteDecodeErrorZ), "LDKCResult_RouteDecodeErrorZ");
15920         *ret_conv = Route_read(ser_ref);
15921         (*env)->ReleaseByteArrayElements(env, ser, (int8_t*)ser_ref.data, 0);
15922         return (long)ret_conv;
15923 }
15924
15925 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RouteHint_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
15926         LDKRouteHint this_ptr_conv;
15927         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15928         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
15929         RouteHint_free(this_ptr_conv);
15930 }
15931
15932 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_RouteHint_1clone(JNIEnv *env, jclass clz, int64_t orig) {
15933         LDKRouteHint orig_conv;
15934         orig_conv.inner = (void*)(orig & (~1));
15935         orig_conv.is_owned = false;
15936         LDKRouteHint ret_var = RouteHint_clone(&orig_conv);
15937         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15938         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15939         long ret_ref = (long)ret_var.inner;
15940         if (ret_var.is_owned) {
15941                 ret_ref |= 1;
15942         }
15943         return ret_ref;
15944 }
15945
15946 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_RouteHint_1get_1src_1node_1id(JNIEnv *env, jclass clz, int64_t this_ptr) {
15947         LDKRouteHint this_ptr_conv;
15948         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15949         this_ptr_conv.is_owned = false;
15950         int8_tArray arg_arr = (*env)->NewByteArray(env, 33);
15951         (*env)->SetByteArrayRegion(env, arg_arr, 0, 33, RouteHint_get_src_node_id(&this_ptr_conv).compressed_form);
15952         return arg_arr;
15953 }
15954
15955 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RouteHint_1set_1src_1node_1id(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
15956         LDKRouteHint this_ptr_conv;
15957         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15958         this_ptr_conv.is_owned = false;
15959         LDKPublicKey val_ref;
15960         CHECK((*env)->GetArrayLength(env, val) == 33);
15961         (*env)->GetByteArrayRegion(env, val, 0, 33, val_ref.compressed_form);
15962         RouteHint_set_src_node_id(&this_ptr_conv, val_ref);
15963 }
15964
15965 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_RouteHint_1get_1short_1channel_1id(JNIEnv *env, jclass clz, int64_t this_ptr) {
15966         LDKRouteHint this_ptr_conv;
15967         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15968         this_ptr_conv.is_owned = false;
15969         int64_t ret_val = RouteHint_get_short_channel_id(&this_ptr_conv);
15970         return ret_val;
15971 }
15972
15973 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RouteHint_1set_1short_1channel_1id(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
15974         LDKRouteHint this_ptr_conv;
15975         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15976         this_ptr_conv.is_owned = false;
15977         RouteHint_set_short_channel_id(&this_ptr_conv, val);
15978 }
15979
15980 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_RouteHint_1get_1fees(JNIEnv *env, jclass clz, int64_t this_ptr) {
15981         LDKRouteHint this_ptr_conv;
15982         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15983         this_ptr_conv.is_owned = false;
15984         LDKRoutingFees ret_var = RouteHint_get_fees(&this_ptr_conv);
15985         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15986         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15987         long ret_ref = (long)ret_var.inner;
15988         if (ret_var.is_owned) {
15989                 ret_ref |= 1;
15990         }
15991         return ret_ref;
15992 }
15993
15994 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RouteHint_1set_1fees(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
15995         LDKRouteHint this_ptr_conv;
15996         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15997         this_ptr_conv.is_owned = false;
15998         LDKRoutingFees val_conv;
15999         val_conv.inner = (void*)(val & (~1));
16000         val_conv.is_owned = (val & 1) || (val == 0);
16001         if (val_conv.inner != NULL)
16002                 val_conv = RoutingFees_clone(&val_conv);
16003         RouteHint_set_fees(&this_ptr_conv, val_conv);
16004 }
16005
16006 JNIEXPORT int16_t JNICALL Java_org_ldk_impl_bindings_RouteHint_1get_1cltv_1expiry_1delta(JNIEnv *env, jclass clz, int64_t this_ptr) {
16007         LDKRouteHint this_ptr_conv;
16008         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16009         this_ptr_conv.is_owned = false;
16010         int16_t ret_val = RouteHint_get_cltv_expiry_delta(&this_ptr_conv);
16011         return ret_val;
16012 }
16013
16014 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RouteHint_1set_1cltv_1expiry_1delta(JNIEnv *env, jclass clz, int64_t this_ptr, int16_t val) {
16015         LDKRouteHint this_ptr_conv;
16016         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16017         this_ptr_conv.is_owned = false;
16018         RouteHint_set_cltv_expiry_delta(&this_ptr_conv, val);
16019 }
16020
16021 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_RouteHint_1get_1htlc_1minimum_1msat(JNIEnv *env, jclass clz, int64_t this_ptr) {
16022         LDKRouteHint this_ptr_conv;
16023         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16024         this_ptr_conv.is_owned = false;
16025         int64_t ret_val = RouteHint_get_htlc_minimum_msat(&this_ptr_conv);
16026         return ret_val;
16027 }
16028
16029 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RouteHint_1set_1htlc_1minimum_1msat(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
16030         LDKRouteHint this_ptr_conv;
16031         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16032         this_ptr_conv.is_owned = false;
16033         RouteHint_set_htlc_minimum_msat(&this_ptr_conv, val);
16034 }
16035
16036 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_RouteHint_1new(JNIEnv *env, jclass clz, int8_tArray src_node_id_arg, int64_t short_channel_id_arg, int64_t fees_arg, int16_t cltv_expiry_delta_arg, int64_t htlc_minimum_msat_arg) {
16037         LDKPublicKey src_node_id_arg_ref;
16038         CHECK((*env)->GetArrayLength(env, src_node_id_arg) == 33);
16039         (*env)->GetByteArrayRegion(env, src_node_id_arg, 0, 33, src_node_id_arg_ref.compressed_form);
16040         LDKRoutingFees fees_arg_conv;
16041         fees_arg_conv.inner = (void*)(fees_arg & (~1));
16042         fees_arg_conv.is_owned = (fees_arg & 1) || (fees_arg == 0);
16043         if (fees_arg_conv.inner != NULL)
16044                 fees_arg_conv = RoutingFees_clone(&fees_arg_conv);
16045         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);
16046         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
16047         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
16048         long ret_ref = (long)ret_var.inner;
16049         if (ret_var.is_owned) {
16050                 ret_ref |= 1;
16051         }
16052         return ret_ref;
16053 }
16054
16055 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_get_1route(JNIEnv *env, jclass clz, int8_tArray our_node_id, int64_t network, int8_tArray target, int64_tArray first_hops, int64_tArray last_hops, int64_t final_value_msat, int32_t final_cltv, int64_t logger) {
16056         LDKPublicKey our_node_id_ref;
16057         CHECK((*env)->GetArrayLength(env, our_node_id) == 33);
16058         (*env)->GetByteArrayRegion(env, our_node_id, 0, 33, our_node_id_ref.compressed_form);
16059         LDKNetworkGraph network_conv;
16060         network_conv.inner = (void*)(network & (~1));
16061         network_conv.is_owned = false;
16062         LDKPublicKey target_ref;
16063         CHECK((*env)->GetArrayLength(env, target) == 33);
16064         (*env)->GetByteArrayRegion(env, target, 0, 33, target_ref.compressed_form);
16065         LDKCVec_ChannelDetailsZ first_hops_constr;
16066         first_hops_constr.datalen = (*env)->GetArrayLength(env, first_hops);
16067         if (first_hops_constr.datalen > 0)
16068                 first_hops_constr.data = MALLOC(first_hops_constr.datalen * sizeof(LDKChannelDetails), "LDKCVec_ChannelDetailsZ Elements");
16069         else
16070                 first_hops_constr.data = NULL;
16071         int64_t* first_hops_vals = (*env)->GetLongArrayElements (env, first_hops, NULL);
16072         for (size_t q = 0; q < first_hops_constr.datalen; q++) {
16073                 int64_t arr_conv_16 = first_hops_vals[q];
16074                 LDKChannelDetails arr_conv_16_conv;
16075                 arr_conv_16_conv.inner = (void*)(arr_conv_16 & (~1));
16076                 arr_conv_16_conv.is_owned = (arr_conv_16 & 1) || (arr_conv_16 == 0);
16077                 first_hops_constr.data[q] = arr_conv_16_conv;
16078         }
16079         (*env)->ReleaseLongArrayElements(env, first_hops, first_hops_vals, 0);
16080         LDKCVec_RouteHintZ last_hops_constr;
16081         last_hops_constr.datalen = (*env)->GetArrayLength(env, last_hops);
16082         if (last_hops_constr.datalen > 0)
16083                 last_hops_constr.data = MALLOC(last_hops_constr.datalen * sizeof(LDKRouteHint), "LDKCVec_RouteHintZ Elements");
16084         else
16085                 last_hops_constr.data = NULL;
16086         int64_t* last_hops_vals = (*env)->GetLongArrayElements (env, last_hops, NULL);
16087         for (size_t l = 0; l < last_hops_constr.datalen; l++) {
16088                 int64_t arr_conv_11 = last_hops_vals[l];
16089                 LDKRouteHint arr_conv_11_conv;
16090                 arr_conv_11_conv.inner = (void*)(arr_conv_11 & (~1));
16091                 arr_conv_11_conv.is_owned = (arr_conv_11 & 1) || (arr_conv_11 == 0);
16092                 if (arr_conv_11_conv.inner != NULL)
16093                         arr_conv_11_conv = RouteHint_clone(&arr_conv_11_conv);
16094                 last_hops_constr.data[l] = arr_conv_11_conv;
16095         }
16096         (*env)->ReleaseLongArrayElements(env, last_hops, last_hops_vals, 0);
16097         LDKLogger logger_conv = *(LDKLogger*)logger;
16098         if (logger_conv.free == LDKLogger_JCalls_free) {
16099                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
16100                 LDKLogger_JCalls_clone(logger_conv.this_arg);
16101         }
16102         LDKCResult_RouteLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_RouteLightningErrorZ), "LDKCResult_RouteLightningErrorZ");
16103         *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);
16104         FREE(first_hops_constr.data);
16105         return (long)ret_conv;
16106 }
16107
16108 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NetworkGraph_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
16109         LDKNetworkGraph this_ptr_conv;
16110         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16111         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
16112         NetworkGraph_free(this_ptr_conv);
16113 }
16114
16115 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_LockedNetworkGraph_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
16116         LDKLockedNetworkGraph this_ptr_conv;
16117         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16118         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
16119         LockedNetworkGraph_free(this_ptr_conv);
16120 }
16121
16122 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NetGraphMsgHandler_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
16123         LDKNetGraphMsgHandler this_ptr_conv;
16124         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16125         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
16126         NetGraphMsgHandler_free(this_ptr_conv);
16127 }
16128
16129 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_NetGraphMsgHandler_1new(JNIEnv *env, jclass clz, int8_tArray genesis_hash, int64_t chain_access, int64_t logger) {
16130         LDKThirtyTwoBytes genesis_hash_ref;
16131         CHECK((*env)->GetArrayLength(env, genesis_hash) == 32);
16132         (*env)->GetByteArrayRegion(env, genesis_hash, 0, 32, genesis_hash_ref.data);
16133         LDKAccess* chain_access_conv = (LDKAccess*)chain_access;
16134         LDKLogger logger_conv = *(LDKLogger*)logger;
16135         if (logger_conv.free == LDKLogger_JCalls_free) {
16136                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
16137                 LDKLogger_JCalls_clone(logger_conv.this_arg);
16138         }
16139         LDKNetGraphMsgHandler ret_var = NetGraphMsgHandler_new(genesis_hash_ref, chain_access_conv, logger_conv);
16140         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
16141         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
16142         long ret_ref = (long)ret_var.inner;
16143         if (ret_var.is_owned) {
16144                 ret_ref |= 1;
16145         }
16146         return ret_ref;
16147 }
16148
16149 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_NetGraphMsgHandler_1from_1net_1graph(JNIEnv *env, jclass clz, int64_t chain_access, int64_t logger, int64_t network_graph) {
16150         LDKAccess* chain_access_conv = (LDKAccess*)chain_access;
16151         LDKLogger logger_conv = *(LDKLogger*)logger;
16152         if (logger_conv.free == LDKLogger_JCalls_free) {
16153                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
16154                 LDKLogger_JCalls_clone(logger_conv.this_arg);
16155         }
16156         LDKNetworkGraph network_graph_conv;
16157         network_graph_conv.inner = (void*)(network_graph & (~1));
16158         network_graph_conv.is_owned = (network_graph & 1) || (network_graph == 0);
16159         // Warning: we may need a move here but can't clone!
16160         LDKNetGraphMsgHandler ret_var = NetGraphMsgHandler_from_net_graph(chain_access_conv, logger_conv, network_graph_conv);
16161         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
16162         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
16163         long ret_ref = (long)ret_var.inner;
16164         if (ret_var.is_owned) {
16165                 ret_ref |= 1;
16166         }
16167         return ret_ref;
16168 }
16169
16170 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_NetGraphMsgHandler_1read_1locked_1graph(JNIEnv *env, jclass clz, int64_t this_arg) {
16171         LDKNetGraphMsgHandler this_arg_conv;
16172         this_arg_conv.inner = (void*)(this_arg & (~1));
16173         this_arg_conv.is_owned = false;
16174         LDKLockedNetworkGraph ret_var = NetGraphMsgHandler_read_locked_graph(&this_arg_conv);
16175         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
16176         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
16177         long ret_ref = (long)ret_var.inner;
16178         if (ret_var.is_owned) {
16179                 ret_ref |= 1;
16180         }
16181         return ret_ref;
16182 }
16183
16184 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LockedNetworkGraph_1graph(JNIEnv *env, jclass clz, int64_t this_arg) {
16185         LDKLockedNetworkGraph this_arg_conv;
16186         this_arg_conv.inner = (void*)(this_arg & (~1));
16187         this_arg_conv.is_owned = false;
16188         LDKNetworkGraph ret_var = LockedNetworkGraph_graph(&this_arg_conv);
16189         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
16190         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
16191         long ret_ref = (long)ret_var.inner;
16192         if (ret_var.is_owned) {
16193                 ret_ref |= 1;
16194         }
16195         return ret_ref;
16196 }
16197
16198 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_NetGraphMsgHandler_1as_1RoutingMessageHandler(JNIEnv *env, jclass clz, int64_t this_arg) {
16199         LDKNetGraphMsgHandler this_arg_conv;
16200         this_arg_conv.inner = (void*)(this_arg & (~1));
16201         this_arg_conv.is_owned = false;
16202         LDKRoutingMessageHandler* ret = MALLOC(sizeof(LDKRoutingMessageHandler), "LDKRoutingMessageHandler");
16203         *ret = NetGraphMsgHandler_as_RoutingMessageHandler(&this_arg_conv);
16204         return (long)ret;
16205 }
16206
16207 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_NetGraphMsgHandler_1as_1MessageSendEventsProvider(JNIEnv *env, jclass clz, int64_t this_arg) {
16208         LDKNetGraphMsgHandler this_arg_conv;
16209         this_arg_conv.inner = (void*)(this_arg & (~1));
16210         this_arg_conv.is_owned = false;
16211         LDKMessageSendEventsProvider* ret = MALLOC(sizeof(LDKMessageSendEventsProvider), "LDKMessageSendEventsProvider");
16212         *ret = NetGraphMsgHandler_as_MessageSendEventsProvider(&this_arg_conv);
16213         return (long)ret;
16214 }
16215
16216 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_DirectionalChannelInfo_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
16217         LDKDirectionalChannelInfo this_ptr_conv;
16218         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16219         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
16220         DirectionalChannelInfo_free(this_ptr_conv);
16221 }
16222
16223 JNIEXPORT int32_t JNICALL Java_org_ldk_impl_bindings_DirectionalChannelInfo_1get_1last_1update(JNIEnv *env, jclass clz, int64_t this_ptr) {
16224         LDKDirectionalChannelInfo this_ptr_conv;
16225         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16226         this_ptr_conv.is_owned = false;
16227         int32_t ret_val = DirectionalChannelInfo_get_last_update(&this_ptr_conv);
16228         return ret_val;
16229 }
16230
16231 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_DirectionalChannelInfo_1set_1last_1update(JNIEnv *env, jclass clz, int64_t this_ptr, int32_t val) {
16232         LDKDirectionalChannelInfo this_ptr_conv;
16233         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16234         this_ptr_conv.is_owned = false;
16235         DirectionalChannelInfo_set_last_update(&this_ptr_conv, val);
16236 }
16237
16238 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_DirectionalChannelInfo_1get_1enabled(JNIEnv *env, jclass clz, int64_t this_ptr) {
16239         LDKDirectionalChannelInfo this_ptr_conv;
16240         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16241         this_ptr_conv.is_owned = false;
16242         jboolean ret_val = DirectionalChannelInfo_get_enabled(&this_ptr_conv);
16243         return ret_val;
16244 }
16245
16246 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_DirectionalChannelInfo_1set_1enabled(JNIEnv *env, jclass clz, int64_t this_ptr, jboolean val) {
16247         LDKDirectionalChannelInfo this_ptr_conv;
16248         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16249         this_ptr_conv.is_owned = false;
16250         DirectionalChannelInfo_set_enabled(&this_ptr_conv, val);
16251 }
16252
16253 JNIEXPORT int16_t JNICALL Java_org_ldk_impl_bindings_DirectionalChannelInfo_1get_1cltv_1expiry_1delta(JNIEnv *env, jclass clz, int64_t this_ptr) {
16254         LDKDirectionalChannelInfo this_ptr_conv;
16255         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16256         this_ptr_conv.is_owned = false;
16257         int16_t ret_val = DirectionalChannelInfo_get_cltv_expiry_delta(&this_ptr_conv);
16258         return ret_val;
16259 }
16260
16261 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_DirectionalChannelInfo_1set_1cltv_1expiry_1delta(JNIEnv *env, jclass clz, int64_t this_ptr, int16_t val) {
16262         LDKDirectionalChannelInfo this_ptr_conv;
16263         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16264         this_ptr_conv.is_owned = false;
16265         DirectionalChannelInfo_set_cltv_expiry_delta(&this_ptr_conv, val);
16266 }
16267
16268 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_DirectionalChannelInfo_1get_1htlc_1minimum_1msat(JNIEnv *env, jclass clz, int64_t this_ptr) {
16269         LDKDirectionalChannelInfo this_ptr_conv;
16270         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16271         this_ptr_conv.is_owned = false;
16272         int64_t ret_val = DirectionalChannelInfo_get_htlc_minimum_msat(&this_ptr_conv);
16273         return ret_val;
16274 }
16275
16276 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_DirectionalChannelInfo_1set_1htlc_1minimum_1msat(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
16277         LDKDirectionalChannelInfo this_ptr_conv;
16278         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16279         this_ptr_conv.is_owned = false;
16280         DirectionalChannelInfo_set_htlc_minimum_msat(&this_ptr_conv, val);
16281 }
16282
16283 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_DirectionalChannelInfo_1get_1fees(JNIEnv *env, jclass clz, int64_t this_ptr) {
16284         LDKDirectionalChannelInfo this_ptr_conv;
16285         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16286         this_ptr_conv.is_owned = false;
16287         LDKRoutingFees ret_var = DirectionalChannelInfo_get_fees(&this_ptr_conv);
16288         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
16289         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
16290         long ret_ref = (long)ret_var.inner;
16291         if (ret_var.is_owned) {
16292                 ret_ref |= 1;
16293         }
16294         return ret_ref;
16295 }
16296
16297 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_DirectionalChannelInfo_1set_1fees(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
16298         LDKDirectionalChannelInfo this_ptr_conv;
16299         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16300         this_ptr_conv.is_owned = false;
16301         LDKRoutingFees val_conv;
16302         val_conv.inner = (void*)(val & (~1));
16303         val_conv.is_owned = (val & 1) || (val == 0);
16304         if (val_conv.inner != NULL)
16305                 val_conv = RoutingFees_clone(&val_conv);
16306         DirectionalChannelInfo_set_fees(&this_ptr_conv, val_conv);
16307 }
16308
16309 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_DirectionalChannelInfo_1get_1last_1update_1message(JNIEnv *env, jclass clz, int64_t this_ptr) {
16310         LDKDirectionalChannelInfo this_ptr_conv;
16311         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16312         this_ptr_conv.is_owned = false;
16313         LDKChannelUpdate ret_var = DirectionalChannelInfo_get_last_update_message(&this_ptr_conv);
16314         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
16315         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
16316         long ret_ref = (long)ret_var.inner;
16317         if (ret_var.is_owned) {
16318                 ret_ref |= 1;
16319         }
16320         return ret_ref;
16321 }
16322
16323 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_DirectionalChannelInfo_1set_1last_1update_1message(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
16324         LDKDirectionalChannelInfo this_ptr_conv;
16325         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16326         this_ptr_conv.is_owned = false;
16327         LDKChannelUpdate val_conv;
16328         val_conv.inner = (void*)(val & (~1));
16329         val_conv.is_owned = (val & 1) || (val == 0);
16330         if (val_conv.inner != NULL)
16331                 val_conv = ChannelUpdate_clone(&val_conv);
16332         DirectionalChannelInfo_set_last_update_message(&this_ptr_conv, val_conv);
16333 }
16334
16335 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_DirectionalChannelInfo_1write(JNIEnv *env, jclass clz, int64_t obj) {
16336         LDKDirectionalChannelInfo obj_conv;
16337         obj_conv.inner = (void*)(obj & (~1));
16338         obj_conv.is_owned = false;
16339         LDKCVec_u8Z arg_var = DirectionalChannelInfo_write(&obj_conv);
16340         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
16341         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
16342         CVec_u8Z_free(arg_var);
16343         return arg_arr;
16344 }
16345
16346 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_DirectionalChannelInfo_1read(JNIEnv *env, jclass clz, int8_tArray ser) {
16347         LDKu8slice ser_ref;
16348         ser_ref.datalen = (*env)->GetArrayLength(env, ser);
16349         ser_ref.data = (*env)->GetByteArrayElements (env, ser, NULL);
16350         LDKDirectionalChannelInfo ret_var = DirectionalChannelInfo_read(ser_ref);
16351         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
16352         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
16353         long ret_ref = (long)ret_var.inner;
16354         if (ret_var.is_owned) {
16355                 ret_ref |= 1;
16356         }
16357         (*env)->ReleaseByteArrayElements(env, ser, (int8_t*)ser_ref.data, 0);
16358         return ret_ref;
16359 }
16360
16361 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelInfo_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
16362         LDKChannelInfo this_ptr_conv;
16363         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16364         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
16365         ChannelInfo_free(this_ptr_conv);
16366 }
16367
16368 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelInfo_1get_1features(JNIEnv *env, jclass clz, int64_t this_ptr) {
16369         LDKChannelInfo this_ptr_conv;
16370         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16371         this_ptr_conv.is_owned = false;
16372         LDKChannelFeatures ret_var = ChannelInfo_get_features(&this_ptr_conv);
16373         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
16374         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
16375         long ret_ref = (long)ret_var.inner;
16376         if (ret_var.is_owned) {
16377                 ret_ref |= 1;
16378         }
16379         return ret_ref;
16380 }
16381
16382 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelInfo_1set_1features(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
16383         LDKChannelInfo this_ptr_conv;
16384         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16385         this_ptr_conv.is_owned = false;
16386         LDKChannelFeatures val_conv;
16387         val_conv.inner = (void*)(val & (~1));
16388         val_conv.is_owned = (val & 1) || (val == 0);
16389         // Warning: we may need a move here but can't clone!
16390         ChannelInfo_set_features(&this_ptr_conv, val_conv);
16391 }
16392
16393 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_ChannelInfo_1get_1node_1one(JNIEnv *env, jclass clz, int64_t this_ptr) {
16394         LDKChannelInfo this_ptr_conv;
16395         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16396         this_ptr_conv.is_owned = false;
16397         int8_tArray arg_arr = (*env)->NewByteArray(env, 33);
16398         (*env)->SetByteArrayRegion(env, arg_arr, 0, 33, ChannelInfo_get_node_one(&this_ptr_conv).compressed_form);
16399         return arg_arr;
16400 }
16401
16402 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelInfo_1set_1node_1one(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
16403         LDKChannelInfo this_ptr_conv;
16404         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16405         this_ptr_conv.is_owned = false;
16406         LDKPublicKey val_ref;
16407         CHECK((*env)->GetArrayLength(env, val) == 33);
16408         (*env)->GetByteArrayRegion(env, val, 0, 33, val_ref.compressed_form);
16409         ChannelInfo_set_node_one(&this_ptr_conv, val_ref);
16410 }
16411
16412 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelInfo_1get_1one_1to_1two(JNIEnv *env, jclass clz, int64_t this_ptr) {
16413         LDKChannelInfo this_ptr_conv;
16414         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16415         this_ptr_conv.is_owned = false;
16416         LDKDirectionalChannelInfo ret_var = ChannelInfo_get_one_to_two(&this_ptr_conv);
16417         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
16418         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
16419         long ret_ref = (long)ret_var.inner;
16420         if (ret_var.is_owned) {
16421                 ret_ref |= 1;
16422         }
16423         return ret_ref;
16424 }
16425
16426 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelInfo_1set_1one_1to_1two(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
16427         LDKChannelInfo this_ptr_conv;
16428         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16429         this_ptr_conv.is_owned = false;
16430         LDKDirectionalChannelInfo val_conv;
16431         val_conv.inner = (void*)(val & (~1));
16432         val_conv.is_owned = (val & 1) || (val == 0);
16433         // Warning: we may need a move here but can't clone!
16434         ChannelInfo_set_one_to_two(&this_ptr_conv, val_conv);
16435 }
16436
16437 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_ChannelInfo_1get_1node_1two(JNIEnv *env, jclass clz, int64_t this_ptr) {
16438         LDKChannelInfo this_ptr_conv;
16439         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16440         this_ptr_conv.is_owned = false;
16441         int8_tArray arg_arr = (*env)->NewByteArray(env, 33);
16442         (*env)->SetByteArrayRegion(env, arg_arr, 0, 33, ChannelInfo_get_node_two(&this_ptr_conv).compressed_form);
16443         return arg_arr;
16444 }
16445
16446 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelInfo_1set_1node_1two(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
16447         LDKChannelInfo this_ptr_conv;
16448         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16449         this_ptr_conv.is_owned = false;
16450         LDKPublicKey val_ref;
16451         CHECK((*env)->GetArrayLength(env, val) == 33);
16452         (*env)->GetByteArrayRegion(env, val, 0, 33, val_ref.compressed_form);
16453         ChannelInfo_set_node_two(&this_ptr_conv, val_ref);
16454 }
16455
16456 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelInfo_1get_1two_1to_1one(JNIEnv *env, jclass clz, int64_t this_ptr) {
16457         LDKChannelInfo this_ptr_conv;
16458         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16459         this_ptr_conv.is_owned = false;
16460         LDKDirectionalChannelInfo ret_var = ChannelInfo_get_two_to_one(&this_ptr_conv);
16461         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
16462         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
16463         long ret_ref = (long)ret_var.inner;
16464         if (ret_var.is_owned) {
16465                 ret_ref |= 1;
16466         }
16467         return ret_ref;
16468 }
16469
16470 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelInfo_1set_1two_1to_1one(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
16471         LDKChannelInfo this_ptr_conv;
16472         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16473         this_ptr_conv.is_owned = false;
16474         LDKDirectionalChannelInfo val_conv;
16475         val_conv.inner = (void*)(val & (~1));
16476         val_conv.is_owned = (val & 1) || (val == 0);
16477         // Warning: we may need a move here but can't clone!
16478         ChannelInfo_set_two_to_one(&this_ptr_conv, val_conv);
16479 }
16480
16481 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelInfo_1get_1announcement_1message(JNIEnv *env, jclass clz, int64_t this_ptr) {
16482         LDKChannelInfo this_ptr_conv;
16483         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16484         this_ptr_conv.is_owned = false;
16485         LDKChannelAnnouncement ret_var = ChannelInfo_get_announcement_message(&this_ptr_conv);
16486         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
16487         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
16488         long ret_ref = (long)ret_var.inner;
16489         if (ret_var.is_owned) {
16490                 ret_ref |= 1;
16491         }
16492         return ret_ref;
16493 }
16494
16495 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelInfo_1set_1announcement_1message(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
16496         LDKChannelInfo this_ptr_conv;
16497         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16498         this_ptr_conv.is_owned = false;
16499         LDKChannelAnnouncement val_conv;
16500         val_conv.inner = (void*)(val & (~1));
16501         val_conv.is_owned = (val & 1) || (val == 0);
16502         if (val_conv.inner != NULL)
16503                 val_conv = ChannelAnnouncement_clone(&val_conv);
16504         ChannelInfo_set_announcement_message(&this_ptr_conv, val_conv);
16505 }
16506
16507 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_ChannelInfo_1write(JNIEnv *env, jclass clz, int64_t obj) {
16508         LDKChannelInfo obj_conv;
16509         obj_conv.inner = (void*)(obj & (~1));
16510         obj_conv.is_owned = false;
16511         LDKCVec_u8Z arg_var = ChannelInfo_write(&obj_conv);
16512         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
16513         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
16514         CVec_u8Z_free(arg_var);
16515         return arg_arr;
16516 }
16517
16518 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelInfo_1read(JNIEnv *env, jclass clz, int8_tArray ser) {
16519         LDKu8slice ser_ref;
16520         ser_ref.datalen = (*env)->GetArrayLength(env, ser);
16521         ser_ref.data = (*env)->GetByteArrayElements (env, ser, NULL);
16522         LDKChannelInfo ret_var = ChannelInfo_read(ser_ref);
16523         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
16524         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
16525         long ret_ref = (long)ret_var.inner;
16526         if (ret_var.is_owned) {
16527                 ret_ref |= 1;
16528         }
16529         (*env)->ReleaseByteArrayElements(env, ser, (int8_t*)ser_ref.data, 0);
16530         return ret_ref;
16531 }
16532
16533 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RoutingFees_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
16534         LDKRoutingFees this_ptr_conv;
16535         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16536         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
16537         RoutingFees_free(this_ptr_conv);
16538 }
16539
16540 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_RoutingFees_1clone(JNIEnv *env, jclass clz, int64_t orig) {
16541         LDKRoutingFees orig_conv;
16542         orig_conv.inner = (void*)(orig & (~1));
16543         orig_conv.is_owned = false;
16544         LDKRoutingFees ret_var = RoutingFees_clone(&orig_conv);
16545         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
16546         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
16547         long ret_ref = (long)ret_var.inner;
16548         if (ret_var.is_owned) {
16549                 ret_ref |= 1;
16550         }
16551         return ret_ref;
16552 }
16553
16554 JNIEXPORT int32_t JNICALL Java_org_ldk_impl_bindings_RoutingFees_1get_1base_1msat(JNIEnv *env, jclass clz, int64_t this_ptr) {
16555         LDKRoutingFees this_ptr_conv;
16556         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16557         this_ptr_conv.is_owned = false;
16558         int32_t ret_val = RoutingFees_get_base_msat(&this_ptr_conv);
16559         return ret_val;
16560 }
16561
16562 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RoutingFees_1set_1base_1msat(JNIEnv *env, jclass clz, int64_t this_ptr, int32_t val) {
16563         LDKRoutingFees this_ptr_conv;
16564         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16565         this_ptr_conv.is_owned = false;
16566         RoutingFees_set_base_msat(&this_ptr_conv, val);
16567 }
16568
16569 JNIEXPORT int32_t JNICALL Java_org_ldk_impl_bindings_RoutingFees_1get_1proportional_1millionths(JNIEnv *env, jclass clz, int64_t this_ptr) {
16570         LDKRoutingFees this_ptr_conv;
16571         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16572         this_ptr_conv.is_owned = false;
16573         int32_t ret_val = RoutingFees_get_proportional_millionths(&this_ptr_conv);
16574         return ret_val;
16575 }
16576
16577 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RoutingFees_1set_1proportional_1millionths(JNIEnv *env, jclass clz, int64_t this_ptr, int32_t val) {
16578         LDKRoutingFees this_ptr_conv;
16579         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16580         this_ptr_conv.is_owned = false;
16581         RoutingFees_set_proportional_millionths(&this_ptr_conv, val);
16582 }
16583
16584 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_RoutingFees_1new(JNIEnv *env, jclass clz, int32_t base_msat_arg, int32_t proportional_millionths_arg) {
16585         LDKRoutingFees ret_var = RoutingFees_new(base_msat_arg, proportional_millionths_arg);
16586         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
16587         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
16588         long ret_ref = (long)ret_var.inner;
16589         if (ret_var.is_owned) {
16590                 ret_ref |= 1;
16591         }
16592         return ret_ref;
16593 }
16594
16595 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_RoutingFees_1read(JNIEnv *env, jclass clz, int8_tArray ser) {
16596         LDKu8slice ser_ref;
16597         ser_ref.datalen = (*env)->GetArrayLength(env, ser);
16598         ser_ref.data = (*env)->GetByteArrayElements (env, ser, NULL);
16599         LDKCResult_RoutingFeesDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_RoutingFeesDecodeErrorZ), "LDKCResult_RoutingFeesDecodeErrorZ");
16600         *ret_conv = RoutingFees_read(ser_ref);
16601         (*env)->ReleaseByteArrayElements(env, ser, (int8_t*)ser_ref.data, 0);
16602         return (long)ret_conv;
16603 }
16604
16605 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_RoutingFees_1write(JNIEnv *env, jclass clz, int64_t obj) {
16606         LDKRoutingFees obj_conv;
16607         obj_conv.inner = (void*)(obj & (~1));
16608         obj_conv.is_owned = false;
16609         LDKCVec_u8Z arg_var = RoutingFees_write(&obj_conv);
16610         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
16611         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
16612         CVec_u8Z_free(arg_var);
16613         return arg_arr;
16614 }
16615
16616 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NodeAnnouncementInfo_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
16617         LDKNodeAnnouncementInfo this_ptr_conv;
16618         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16619         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
16620         NodeAnnouncementInfo_free(this_ptr_conv);
16621 }
16622
16623 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_NodeAnnouncementInfo_1get_1features(JNIEnv *env, jclass clz, int64_t this_ptr) {
16624         LDKNodeAnnouncementInfo this_ptr_conv;
16625         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16626         this_ptr_conv.is_owned = false;
16627         LDKNodeFeatures ret_var = NodeAnnouncementInfo_get_features(&this_ptr_conv);
16628         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
16629         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
16630         long ret_ref = (long)ret_var.inner;
16631         if (ret_var.is_owned) {
16632                 ret_ref |= 1;
16633         }
16634         return ret_ref;
16635 }
16636
16637 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NodeAnnouncementInfo_1set_1features(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
16638         LDKNodeAnnouncementInfo this_ptr_conv;
16639         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16640         this_ptr_conv.is_owned = false;
16641         LDKNodeFeatures val_conv;
16642         val_conv.inner = (void*)(val & (~1));
16643         val_conv.is_owned = (val & 1) || (val == 0);
16644         // Warning: we may need a move here but can't clone!
16645         NodeAnnouncementInfo_set_features(&this_ptr_conv, val_conv);
16646 }
16647
16648 JNIEXPORT int32_t JNICALL Java_org_ldk_impl_bindings_NodeAnnouncementInfo_1get_1last_1update(JNIEnv *env, jclass clz, int64_t this_ptr) {
16649         LDKNodeAnnouncementInfo this_ptr_conv;
16650         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16651         this_ptr_conv.is_owned = false;
16652         int32_t ret_val = NodeAnnouncementInfo_get_last_update(&this_ptr_conv);
16653         return ret_val;
16654 }
16655
16656 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NodeAnnouncementInfo_1set_1last_1update(JNIEnv *env, jclass clz, int64_t this_ptr, int32_t val) {
16657         LDKNodeAnnouncementInfo this_ptr_conv;
16658         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16659         this_ptr_conv.is_owned = false;
16660         NodeAnnouncementInfo_set_last_update(&this_ptr_conv, val);
16661 }
16662
16663 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_NodeAnnouncementInfo_1get_1rgb(JNIEnv *env, jclass clz, int64_t this_ptr) {
16664         LDKNodeAnnouncementInfo this_ptr_conv;
16665         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16666         this_ptr_conv.is_owned = false;
16667         int8_tArray ret_arr = (*env)->NewByteArray(env, 3);
16668         (*env)->SetByteArrayRegion(env, ret_arr, 0, 3, *NodeAnnouncementInfo_get_rgb(&this_ptr_conv));
16669         return ret_arr;
16670 }
16671
16672 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NodeAnnouncementInfo_1set_1rgb(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
16673         LDKNodeAnnouncementInfo this_ptr_conv;
16674         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16675         this_ptr_conv.is_owned = false;
16676         LDKThreeBytes val_ref;
16677         CHECK((*env)->GetArrayLength(env, val) == 3);
16678         (*env)->GetByteArrayRegion(env, val, 0, 3, val_ref.data);
16679         NodeAnnouncementInfo_set_rgb(&this_ptr_conv, val_ref);
16680 }
16681
16682 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_NodeAnnouncementInfo_1get_1alias(JNIEnv *env, jclass clz, int64_t this_ptr) {
16683         LDKNodeAnnouncementInfo this_ptr_conv;
16684         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16685         this_ptr_conv.is_owned = false;
16686         int8_tArray ret_arr = (*env)->NewByteArray(env, 32);
16687         (*env)->SetByteArrayRegion(env, ret_arr, 0, 32, *NodeAnnouncementInfo_get_alias(&this_ptr_conv));
16688         return ret_arr;
16689 }
16690
16691 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NodeAnnouncementInfo_1set_1alias(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
16692         LDKNodeAnnouncementInfo this_ptr_conv;
16693         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16694         this_ptr_conv.is_owned = false;
16695         LDKThirtyTwoBytes val_ref;
16696         CHECK((*env)->GetArrayLength(env, val) == 32);
16697         (*env)->GetByteArrayRegion(env, val, 0, 32, val_ref.data);
16698         NodeAnnouncementInfo_set_alias(&this_ptr_conv, val_ref);
16699 }
16700
16701 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NodeAnnouncementInfo_1set_1addresses(JNIEnv *env, jclass clz, int64_t this_ptr, int64_tArray val) {
16702         LDKNodeAnnouncementInfo this_ptr_conv;
16703         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16704         this_ptr_conv.is_owned = false;
16705         LDKCVec_NetAddressZ val_constr;
16706         val_constr.datalen = (*env)->GetArrayLength(env, val);
16707         if (val_constr.datalen > 0)
16708                 val_constr.data = MALLOC(val_constr.datalen * sizeof(LDKNetAddress), "LDKCVec_NetAddressZ Elements");
16709         else
16710                 val_constr.data = NULL;
16711         int64_t* val_vals = (*env)->GetLongArrayElements (env, val, NULL);
16712         for (size_t m = 0; m < val_constr.datalen; m++) {
16713                 int64_t arr_conv_12 = val_vals[m];
16714                 LDKNetAddress arr_conv_12_conv = *(LDKNetAddress*)arr_conv_12;
16715                 FREE((void*)arr_conv_12);
16716                 val_constr.data[m] = arr_conv_12_conv;
16717         }
16718         (*env)->ReleaseLongArrayElements(env, val, val_vals, 0);
16719         NodeAnnouncementInfo_set_addresses(&this_ptr_conv, val_constr);
16720 }
16721
16722 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_NodeAnnouncementInfo_1get_1announcement_1message(JNIEnv *env, jclass clz, int64_t this_ptr) {
16723         LDKNodeAnnouncementInfo this_ptr_conv;
16724         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16725         this_ptr_conv.is_owned = false;
16726         LDKNodeAnnouncement ret_var = NodeAnnouncementInfo_get_announcement_message(&this_ptr_conv);
16727         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
16728         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
16729         long ret_ref = (long)ret_var.inner;
16730         if (ret_var.is_owned) {
16731                 ret_ref |= 1;
16732         }
16733         return ret_ref;
16734 }
16735
16736 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NodeAnnouncementInfo_1set_1announcement_1message(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
16737         LDKNodeAnnouncementInfo this_ptr_conv;
16738         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16739         this_ptr_conv.is_owned = false;
16740         LDKNodeAnnouncement val_conv;
16741         val_conv.inner = (void*)(val & (~1));
16742         val_conv.is_owned = (val & 1) || (val == 0);
16743         if (val_conv.inner != NULL)
16744                 val_conv = NodeAnnouncement_clone(&val_conv);
16745         NodeAnnouncementInfo_set_announcement_message(&this_ptr_conv, val_conv);
16746 }
16747
16748 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_NodeAnnouncementInfo_1new(JNIEnv *env, jclass clz, int64_t features_arg, int32_t last_update_arg, int8_tArray rgb_arg, int8_tArray alias_arg, int64_tArray addresses_arg, int64_t announcement_message_arg) {
16749         LDKNodeFeatures features_arg_conv;
16750         features_arg_conv.inner = (void*)(features_arg & (~1));
16751         features_arg_conv.is_owned = (features_arg & 1) || (features_arg == 0);
16752         // Warning: we may need a move here but can't clone!
16753         LDKThreeBytes rgb_arg_ref;
16754         CHECK((*env)->GetArrayLength(env, rgb_arg) == 3);
16755         (*env)->GetByteArrayRegion(env, rgb_arg, 0, 3, rgb_arg_ref.data);
16756         LDKThirtyTwoBytes alias_arg_ref;
16757         CHECK((*env)->GetArrayLength(env, alias_arg) == 32);
16758         (*env)->GetByteArrayRegion(env, alias_arg, 0, 32, alias_arg_ref.data);
16759         LDKCVec_NetAddressZ addresses_arg_constr;
16760         addresses_arg_constr.datalen = (*env)->GetArrayLength(env, addresses_arg);
16761         if (addresses_arg_constr.datalen > 0)
16762                 addresses_arg_constr.data = MALLOC(addresses_arg_constr.datalen * sizeof(LDKNetAddress), "LDKCVec_NetAddressZ Elements");
16763         else
16764                 addresses_arg_constr.data = NULL;
16765         int64_t* addresses_arg_vals = (*env)->GetLongArrayElements (env, addresses_arg, NULL);
16766         for (size_t m = 0; m < addresses_arg_constr.datalen; m++) {
16767                 int64_t arr_conv_12 = addresses_arg_vals[m];
16768                 LDKNetAddress arr_conv_12_conv = *(LDKNetAddress*)arr_conv_12;
16769                 FREE((void*)arr_conv_12);
16770                 addresses_arg_constr.data[m] = arr_conv_12_conv;
16771         }
16772         (*env)->ReleaseLongArrayElements(env, addresses_arg, addresses_arg_vals, 0);
16773         LDKNodeAnnouncement announcement_message_arg_conv;
16774         announcement_message_arg_conv.inner = (void*)(announcement_message_arg & (~1));
16775         announcement_message_arg_conv.is_owned = (announcement_message_arg & 1) || (announcement_message_arg == 0);
16776         if (announcement_message_arg_conv.inner != NULL)
16777                 announcement_message_arg_conv = NodeAnnouncement_clone(&announcement_message_arg_conv);
16778         LDKNodeAnnouncementInfo ret_var = NodeAnnouncementInfo_new(features_arg_conv, last_update_arg, rgb_arg_ref, alias_arg_ref, addresses_arg_constr, announcement_message_arg_conv);
16779         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
16780         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
16781         long ret_ref = (long)ret_var.inner;
16782         if (ret_var.is_owned) {
16783                 ret_ref |= 1;
16784         }
16785         return ret_ref;
16786 }
16787
16788 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_NodeAnnouncementInfo_1write(JNIEnv *env, jclass clz, int64_t obj) {
16789         LDKNodeAnnouncementInfo obj_conv;
16790         obj_conv.inner = (void*)(obj & (~1));
16791         obj_conv.is_owned = false;
16792         LDKCVec_u8Z arg_var = NodeAnnouncementInfo_write(&obj_conv);
16793         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
16794         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
16795         CVec_u8Z_free(arg_var);
16796         return arg_arr;
16797 }
16798
16799 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_NodeAnnouncementInfo_1read(JNIEnv *env, jclass clz, int8_tArray ser) {
16800         LDKu8slice ser_ref;
16801         ser_ref.datalen = (*env)->GetArrayLength(env, ser);
16802         ser_ref.data = (*env)->GetByteArrayElements (env, ser, NULL);
16803         LDKCResult_NodeAnnouncementInfoDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NodeAnnouncementInfoDecodeErrorZ), "LDKCResult_NodeAnnouncementInfoDecodeErrorZ");
16804         *ret_conv = NodeAnnouncementInfo_read(ser_ref);
16805         (*env)->ReleaseByteArrayElements(env, ser, (int8_t*)ser_ref.data, 0);
16806         return (long)ret_conv;
16807 }
16808
16809 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NodeInfo_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
16810         LDKNodeInfo this_ptr_conv;
16811         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16812         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
16813         NodeInfo_free(this_ptr_conv);
16814 }
16815
16816 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NodeInfo_1set_1channels(JNIEnv *env, jclass clz, int64_t this_ptr, int64_tArray val) {
16817         LDKNodeInfo this_ptr_conv;
16818         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16819         this_ptr_conv.is_owned = false;
16820         LDKCVec_u64Z val_constr;
16821         val_constr.datalen = (*env)->GetArrayLength(env, val);
16822         if (val_constr.datalen > 0)
16823                 val_constr.data = MALLOC(val_constr.datalen * sizeof(int64_t), "LDKCVec_u64Z Elements");
16824         else
16825                 val_constr.data = NULL;
16826         int64_t* val_vals = (*env)->GetLongArrayElements (env, val, NULL);
16827         for (size_t g = 0; g < val_constr.datalen; g++) {
16828                 int64_t arr_conv_6 = val_vals[g];
16829                 val_constr.data[g] = arr_conv_6;
16830         }
16831         (*env)->ReleaseLongArrayElements(env, val, val_vals, 0);
16832         NodeInfo_set_channels(&this_ptr_conv, val_constr);
16833 }
16834
16835 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_NodeInfo_1get_1lowest_1inbound_1channel_1fees(JNIEnv *env, jclass clz, int64_t this_ptr) {
16836         LDKNodeInfo this_ptr_conv;
16837         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16838         this_ptr_conv.is_owned = false;
16839         LDKRoutingFees ret_var = NodeInfo_get_lowest_inbound_channel_fees(&this_ptr_conv);
16840         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
16841         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
16842         long ret_ref = (long)ret_var.inner;
16843         if (ret_var.is_owned) {
16844                 ret_ref |= 1;
16845         }
16846         return ret_ref;
16847 }
16848
16849 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NodeInfo_1set_1lowest_1inbound_1channel_1fees(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
16850         LDKNodeInfo this_ptr_conv;
16851         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16852         this_ptr_conv.is_owned = false;
16853         LDKRoutingFees val_conv;
16854         val_conv.inner = (void*)(val & (~1));
16855         val_conv.is_owned = (val & 1) || (val == 0);
16856         if (val_conv.inner != NULL)
16857                 val_conv = RoutingFees_clone(&val_conv);
16858         NodeInfo_set_lowest_inbound_channel_fees(&this_ptr_conv, val_conv);
16859 }
16860
16861 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_NodeInfo_1get_1announcement_1info(JNIEnv *env, jclass clz, int64_t this_ptr) {
16862         LDKNodeInfo this_ptr_conv;
16863         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16864         this_ptr_conv.is_owned = false;
16865         LDKNodeAnnouncementInfo ret_var = NodeInfo_get_announcement_info(&this_ptr_conv);
16866         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
16867         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
16868         long ret_ref = (long)ret_var.inner;
16869         if (ret_var.is_owned) {
16870                 ret_ref |= 1;
16871         }
16872         return ret_ref;
16873 }
16874
16875 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NodeInfo_1set_1announcement_1info(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
16876         LDKNodeInfo this_ptr_conv;
16877         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16878         this_ptr_conv.is_owned = false;
16879         LDKNodeAnnouncementInfo val_conv;
16880         val_conv.inner = (void*)(val & (~1));
16881         val_conv.is_owned = (val & 1) || (val == 0);
16882         // Warning: we may need a move here but can't clone!
16883         NodeInfo_set_announcement_info(&this_ptr_conv, val_conv);
16884 }
16885
16886 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_NodeInfo_1new(JNIEnv *env, jclass clz, int64_tArray channels_arg, int64_t lowest_inbound_channel_fees_arg, int64_t announcement_info_arg) {
16887         LDKCVec_u64Z channels_arg_constr;
16888         channels_arg_constr.datalen = (*env)->GetArrayLength(env, channels_arg);
16889         if (channels_arg_constr.datalen > 0)
16890                 channels_arg_constr.data = MALLOC(channels_arg_constr.datalen * sizeof(int64_t), "LDKCVec_u64Z Elements");
16891         else
16892                 channels_arg_constr.data = NULL;
16893         int64_t* channels_arg_vals = (*env)->GetLongArrayElements (env, channels_arg, NULL);
16894         for (size_t g = 0; g < channels_arg_constr.datalen; g++) {
16895                 int64_t arr_conv_6 = channels_arg_vals[g];
16896                 channels_arg_constr.data[g] = arr_conv_6;
16897         }
16898         (*env)->ReleaseLongArrayElements(env, channels_arg, channels_arg_vals, 0);
16899         LDKRoutingFees lowest_inbound_channel_fees_arg_conv;
16900         lowest_inbound_channel_fees_arg_conv.inner = (void*)(lowest_inbound_channel_fees_arg & (~1));
16901         lowest_inbound_channel_fees_arg_conv.is_owned = (lowest_inbound_channel_fees_arg & 1) || (lowest_inbound_channel_fees_arg == 0);
16902         if (lowest_inbound_channel_fees_arg_conv.inner != NULL)
16903                 lowest_inbound_channel_fees_arg_conv = RoutingFees_clone(&lowest_inbound_channel_fees_arg_conv);
16904         LDKNodeAnnouncementInfo announcement_info_arg_conv;
16905         announcement_info_arg_conv.inner = (void*)(announcement_info_arg & (~1));
16906         announcement_info_arg_conv.is_owned = (announcement_info_arg & 1) || (announcement_info_arg == 0);
16907         // Warning: we may need a move here but can't clone!
16908         LDKNodeInfo ret_var = NodeInfo_new(channels_arg_constr, lowest_inbound_channel_fees_arg_conv, announcement_info_arg_conv);
16909         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
16910         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
16911         long ret_ref = (long)ret_var.inner;
16912         if (ret_var.is_owned) {
16913                 ret_ref |= 1;
16914         }
16915         return ret_ref;
16916 }
16917
16918 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_NodeInfo_1write(JNIEnv *env, jclass clz, int64_t obj) {
16919         LDKNodeInfo obj_conv;
16920         obj_conv.inner = (void*)(obj & (~1));
16921         obj_conv.is_owned = false;
16922         LDKCVec_u8Z arg_var = NodeInfo_write(&obj_conv);
16923         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
16924         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
16925         CVec_u8Z_free(arg_var);
16926         return arg_arr;
16927 }
16928
16929 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_NodeInfo_1read(JNIEnv *env, jclass clz, int8_tArray ser) {
16930         LDKu8slice ser_ref;
16931         ser_ref.datalen = (*env)->GetArrayLength(env, ser);
16932         ser_ref.data = (*env)->GetByteArrayElements (env, ser, NULL);
16933         LDKCResult_NodeInfoDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NodeInfoDecodeErrorZ), "LDKCResult_NodeInfoDecodeErrorZ");
16934         *ret_conv = NodeInfo_read(ser_ref);
16935         (*env)->ReleaseByteArrayElements(env, ser, (int8_t*)ser_ref.data, 0);
16936         return (long)ret_conv;
16937 }
16938
16939 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_NetworkGraph_1write(JNIEnv *env, jclass clz, int64_t obj) {
16940         LDKNetworkGraph obj_conv;
16941         obj_conv.inner = (void*)(obj & (~1));
16942         obj_conv.is_owned = false;
16943         LDKCVec_u8Z arg_var = NetworkGraph_write(&obj_conv);
16944         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
16945         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
16946         CVec_u8Z_free(arg_var);
16947         return arg_arr;
16948 }
16949
16950 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_NetworkGraph_1read(JNIEnv *env, jclass clz, int8_tArray ser) {
16951         LDKu8slice ser_ref;
16952         ser_ref.datalen = (*env)->GetArrayLength(env, ser);
16953         ser_ref.data = (*env)->GetByteArrayElements (env, ser, NULL);
16954         LDKCResult_NetworkGraphDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NetworkGraphDecodeErrorZ), "LDKCResult_NetworkGraphDecodeErrorZ");
16955         *ret_conv = NetworkGraph_read(ser_ref);
16956         (*env)->ReleaseByteArrayElements(env, ser, (int8_t*)ser_ref.data, 0);
16957         return (long)ret_conv;
16958 }
16959
16960 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_NetworkGraph_1new(JNIEnv *env, jclass clz, int8_tArray genesis_hash) {
16961         LDKThirtyTwoBytes genesis_hash_ref;
16962         CHECK((*env)->GetArrayLength(env, genesis_hash) == 32);
16963         (*env)->GetByteArrayRegion(env, genesis_hash, 0, 32, genesis_hash_ref.data);
16964         LDKNetworkGraph ret_var = NetworkGraph_new(genesis_hash_ref);
16965         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
16966         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
16967         long ret_ref = (long)ret_var.inner;
16968         if (ret_var.is_owned) {
16969                 ret_ref |= 1;
16970         }
16971         return ret_ref;
16972 }
16973
16974 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_NetworkGraph_1update_1node_1from_1announcement(JNIEnv *env, jclass clz, int64_t this_arg, int64_t msg) {
16975         LDKNetworkGraph this_arg_conv;
16976         this_arg_conv.inner = (void*)(this_arg & (~1));
16977         this_arg_conv.is_owned = false;
16978         LDKNodeAnnouncement msg_conv;
16979         msg_conv.inner = (void*)(msg & (~1));
16980         msg_conv.is_owned = false;
16981         LDKCResult_NoneLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneLightningErrorZ), "LDKCResult_NoneLightningErrorZ");
16982         *ret_conv = NetworkGraph_update_node_from_announcement(&this_arg_conv, &msg_conv);
16983         return (long)ret_conv;
16984 }
16985
16986 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_NetworkGraph_1update_1node_1from_1unsigned_1announcement(JNIEnv *env, jclass clz, int64_t this_arg, int64_t msg) {
16987         LDKNetworkGraph this_arg_conv;
16988         this_arg_conv.inner = (void*)(this_arg & (~1));
16989         this_arg_conv.is_owned = false;
16990         LDKUnsignedNodeAnnouncement msg_conv;
16991         msg_conv.inner = (void*)(msg & (~1));
16992         msg_conv.is_owned = false;
16993         LDKCResult_NoneLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneLightningErrorZ), "LDKCResult_NoneLightningErrorZ");
16994         *ret_conv = NetworkGraph_update_node_from_unsigned_announcement(&this_arg_conv, &msg_conv);
16995         return (long)ret_conv;
16996 }
16997
16998 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_NetworkGraph_1update_1channel_1from_1announcement(JNIEnv *env, jclass clz, int64_t this_arg, int64_t msg, int64_t chain_access) {
16999         LDKNetworkGraph this_arg_conv;
17000         this_arg_conv.inner = (void*)(this_arg & (~1));
17001         this_arg_conv.is_owned = false;
17002         LDKChannelAnnouncement msg_conv;
17003         msg_conv.inner = (void*)(msg & (~1));
17004         msg_conv.is_owned = false;
17005         LDKAccess* chain_access_conv = (LDKAccess*)chain_access;
17006         LDKCResult_NoneLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneLightningErrorZ), "LDKCResult_NoneLightningErrorZ");
17007         *ret_conv = NetworkGraph_update_channel_from_announcement(&this_arg_conv, &msg_conv, chain_access_conv);
17008         return (long)ret_conv;
17009 }
17010
17011 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_NetworkGraph_1update_1channel_1from_1unsigned_1announcement(JNIEnv *env, jclass clz, int64_t this_arg, int64_t msg, int64_t chain_access) {
17012         LDKNetworkGraph this_arg_conv;
17013         this_arg_conv.inner = (void*)(this_arg & (~1));
17014         this_arg_conv.is_owned = false;
17015         LDKUnsignedChannelAnnouncement msg_conv;
17016         msg_conv.inner = (void*)(msg & (~1));
17017         msg_conv.is_owned = false;
17018         LDKAccess* chain_access_conv = (LDKAccess*)chain_access;
17019         LDKCResult_NoneLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneLightningErrorZ), "LDKCResult_NoneLightningErrorZ");
17020         *ret_conv = NetworkGraph_update_channel_from_unsigned_announcement(&this_arg_conv, &msg_conv, chain_access_conv);
17021         return (long)ret_conv;
17022 }
17023
17024 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NetworkGraph_1close_1channel_1from_1update(JNIEnv *env, jclass clz, int64_t this_arg, int64_t short_channel_id, jboolean is_permanent) {
17025         LDKNetworkGraph this_arg_conv;
17026         this_arg_conv.inner = (void*)(this_arg & (~1));
17027         this_arg_conv.is_owned = false;
17028         NetworkGraph_close_channel_from_update(&this_arg_conv, short_channel_id, is_permanent);
17029 }
17030
17031 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_NetworkGraph_1update_1channel(JNIEnv *env, jclass clz, int64_t this_arg, int64_t msg) {
17032         LDKNetworkGraph this_arg_conv;
17033         this_arg_conv.inner = (void*)(this_arg & (~1));
17034         this_arg_conv.is_owned = false;
17035         LDKChannelUpdate msg_conv;
17036         msg_conv.inner = (void*)(msg & (~1));
17037         msg_conv.is_owned = false;
17038         LDKCResult_NoneLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneLightningErrorZ), "LDKCResult_NoneLightningErrorZ");
17039         *ret_conv = NetworkGraph_update_channel(&this_arg_conv, &msg_conv);
17040         return (long)ret_conv;
17041 }
17042
17043 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_NetworkGraph_1update_1channel_1unsigned(JNIEnv *env, jclass clz, int64_t this_arg, int64_t msg) {
17044         LDKNetworkGraph this_arg_conv;
17045         this_arg_conv.inner = (void*)(this_arg & (~1));
17046         this_arg_conv.is_owned = false;
17047         LDKUnsignedChannelUpdate msg_conv;
17048         msg_conv.inner = (void*)(msg & (~1));
17049         msg_conv.is_owned = false;
17050         LDKCResult_NoneLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneLightningErrorZ), "LDKCResult_NoneLightningErrorZ");
17051         *ret_conv = NetworkGraph_update_channel_unsigned(&this_arg_conv, &msg_conv);
17052         return (long)ret_conv;
17053 }
17054