Java bindings updates with new generator, with no functional changes
[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_B_clz = NULL;
212 static jclass arr_of_J_clz = NULL;
213 JNIEXPORT void Java_org_ldk_impl_bindings_init_1class_1cache(JNIEnv * env, jclass clz) {
214         arr_of_B_clz = (*env)->FindClass(env, "[B");
215         CHECK(arr_of_B_clz != NULL);
216         arr_of_B_clz = (*env)->NewGlobalRef(env, arr_of_B_clz);
217         arr_of_J_clz = (*env)->FindClass(env, "[J");
218         CHECK(arr_of_J_clz != NULL);
219         arr_of_J_clz = (*env)->NewGlobalRef(env, arr_of_J_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, int64_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 int64_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         for (size_t i = 0; i < b_var.datalen; i++) {
1417                 int8_tArray arr_conv_8_arr = (*env)->NewByteArray(env, 64);
1418                 (*env)->SetByteArrayRegion(env, arr_conv_8_arr, 0, 64, b_var.data[i].compact_form);
1419                 (*env)->SetObjectArrayElement(env, b_arr, i, arr_conv_8_arr);
1420         }
1421         return b_arr;
1422 }
1423 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1C2Tuple_1SignatureCVec_1SignatureZZNoneZ_1result_1ok (JNIEnv *env, jclass clz, int64_t arg) {
1424         return ((LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ*)arg)->result_ok;
1425 }
1426 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1C2Tuple_1SignatureCVec_1SignatureZZNoneZ_1get_1ok (JNIEnv *env, jclass clz, int64_t arg) {
1427         LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ *val = (LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ*)arg;
1428         CHECK(val->result_ok);
1429         long res_ref = (long)&(*val->contents.result);
1430         return res_ref;
1431 }
1432 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_LDKCResult_1C2Tuple_1SignatureCVec_1SignatureZZNoneZ_1get_1err (JNIEnv *env, jclass clz, int64_t arg) {
1433         LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ *val = (LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ*)arg;
1434         CHECK(!val->result_ok);
1435         return *val->contents.err;
1436 }
1437 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1SignatureNoneZ_1result_1ok (JNIEnv *env, jclass clz, int64_t arg) {
1438         return ((LDKCResult_SignatureNoneZ*)arg)->result_ok;
1439 }
1440 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_LDKCResult_1SignatureNoneZ_1get_1ok (JNIEnv *env, jclass clz, int64_t arg) {
1441         LDKCResult_SignatureNoneZ *val = (LDKCResult_SignatureNoneZ*)arg;
1442         CHECK(val->result_ok);
1443         int8_tArray res_arr = (*env)->NewByteArray(env, 64);
1444         (*env)->SetByteArrayRegion(env, res_arr, 0, 64, (*val->contents.result).compact_form);
1445         return res_arr;
1446 }
1447 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_LDKCResult_1SignatureNoneZ_1get_1err (JNIEnv *env, jclass clz, int64_t arg) {
1448         LDKCResult_SignatureNoneZ *val = (LDKCResult_SignatureNoneZ*)arg;
1449         CHECK(!val->result_ok);
1450         return *val->contents.err;
1451 }
1452 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1CVec_1SignatureZNoneZ_1result_1ok (JNIEnv *env, jclass clz, int64_t arg) {
1453         return ((LDKCResult_CVec_SignatureZNoneZ*)arg)->result_ok;
1454 }
1455 JNIEXPORT jobjectArray JNICALL Java_org_ldk_impl_bindings_LDKCResult_1CVec_1SignatureZNoneZ_1get_1ok (JNIEnv *env, jclass clz, int64_t arg) {
1456         LDKCResult_CVec_SignatureZNoneZ *val = (LDKCResult_CVec_SignatureZNoneZ*)arg;
1457         CHECK(val->result_ok);
1458         LDKCVec_SignatureZ res_var = (*val->contents.result);
1459         jobjectArray res_arr = (*env)->NewObjectArray(env, res_var.datalen, arr_of_B_clz, NULL);
1460         for (size_t i = 0; i < res_var.datalen; i++) {
1461                 int8_tArray arr_conv_8_arr = (*env)->NewByteArray(env, 64);
1462                 (*env)->SetByteArrayRegion(env, arr_conv_8_arr, 0, 64, res_var.data[i].compact_form);
1463                 (*env)->SetObjectArrayElement(env, res_arr, i, arr_conv_8_arr);
1464         }
1465         return res_arr;
1466 }
1467 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_LDKCResult_1CVec_1SignatureZNoneZ_1get_1err (JNIEnv *env, jclass clz, int64_t arg) {
1468         LDKCResult_CVec_SignatureZNoneZ *val = (LDKCResult_CVec_SignatureZNoneZ*)arg;
1469         CHECK(!val->result_ok);
1470         return *val->contents.err;
1471 }
1472 typedef struct LDKChannelKeys_JCalls {
1473         atomic_size_t refcnt;
1474         JavaVM *vm;
1475         jweak o;
1476         jmethodID get_per_commitment_point_meth;
1477         jmethodID release_commitment_secret_meth;
1478         jmethodID key_derivation_params_meth;
1479         jmethodID sign_counterparty_commitment_meth;
1480         jmethodID sign_holder_commitment_meth;
1481         jmethodID sign_holder_commitment_htlc_transactions_meth;
1482         jmethodID sign_justice_transaction_meth;
1483         jmethodID sign_counterparty_htlc_transaction_meth;
1484         jmethodID sign_closing_transaction_meth;
1485         jmethodID sign_channel_announcement_meth;
1486         jmethodID ready_channel_meth;
1487         jmethodID write_meth;
1488 } LDKChannelKeys_JCalls;
1489 static void LDKChannelKeys_JCalls_free(void* this_arg) {
1490         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1491         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
1492                 JNIEnv *env;
1493                 DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
1494                 (*env)->DeleteWeakGlobalRef(env, j_calls->o);
1495                 FREE(j_calls);
1496         }
1497 }
1498 LDKPublicKey get_per_commitment_point_jcall(const void* this_arg, uint64_t idx) {
1499         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1500         JNIEnv *env;
1501         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
1502         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
1503         CHECK(obj != NULL);
1504         int8_tArray arg = (*env)->CallObjectMethod(env, obj, j_calls->get_per_commitment_point_meth, idx);
1505         LDKPublicKey arg_ref;
1506         CHECK((*env)->GetArrayLength(env, arg) == 33);
1507         (*env)->GetByteArrayRegion(env, arg, 0, 33, arg_ref.compressed_form);
1508         return arg_ref;
1509 }
1510 LDKThirtyTwoBytes release_commitment_secret_jcall(const void* this_arg, uint64_t idx) {
1511         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1512         JNIEnv *env;
1513         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
1514         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
1515         CHECK(obj != NULL);
1516         int8_tArray arg = (*env)->CallObjectMethod(env, obj, j_calls->release_commitment_secret_meth, idx);
1517         LDKThirtyTwoBytes arg_ref;
1518         CHECK((*env)->GetArrayLength(env, arg) == 32);
1519         (*env)->GetByteArrayRegion(env, arg, 0, 32, arg_ref.data);
1520         return arg_ref;
1521 }
1522 LDKC2Tuple_u64u64Z key_derivation_params_jcall(const void* this_arg) {
1523         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1524         JNIEnv *env;
1525         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
1526         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
1527         CHECK(obj != NULL);
1528         LDKC2Tuple_u64u64Z* ret = (LDKC2Tuple_u64u64Z*)(*env)->CallLongMethod(env, obj, j_calls->key_derivation_params_meth);
1529         LDKC2Tuple_u64u64Z ret_conv = *(LDKC2Tuple_u64u64Z*)ret;
1530         FREE((void*)ret);
1531         return ret_conv;
1532 }
1533 LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ sign_counterparty_commitment_jcall(const void* this_arg, const LDKCommitmentTransaction * commitment_tx) {
1534         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1535         JNIEnv *env;
1536         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
1537         LDKCommitmentTransaction commitment_tx_var = *commitment_tx;
1538         if (commitment_tx->inner != NULL)
1539                 commitment_tx_var = CommitmentTransaction_clone(commitment_tx);
1540         CHECK((((long)commitment_tx_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1541         CHECK((((long)&commitment_tx_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1542         long commitment_tx_ref = (long)commitment_tx_var.inner;
1543         if (commitment_tx_var.is_owned) {
1544                 commitment_tx_ref |= 1;
1545         }
1546         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
1547         CHECK(obj != NULL);
1548         LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ* ret = (LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ*)(*env)->CallLongMethod(env, obj, j_calls->sign_counterparty_commitment_meth, commitment_tx_ref);
1549         LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ ret_conv = *(LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ*)ret;
1550         FREE((void*)ret);
1551         return ret_conv;
1552 }
1553 LDKCResult_SignatureNoneZ sign_holder_commitment_jcall(const void* this_arg, const LDKHolderCommitmentTransaction * commitment_tx) {
1554         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1555         JNIEnv *env;
1556         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
1557         LDKHolderCommitmentTransaction commitment_tx_var = *commitment_tx;
1558         if (commitment_tx->inner != NULL)
1559                 commitment_tx_var = HolderCommitmentTransaction_clone(commitment_tx);
1560         CHECK((((long)commitment_tx_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1561         CHECK((((long)&commitment_tx_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1562         long commitment_tx_ref = (long)commitment_tx_var.inner;
1563         if (commitment_tx_var.is_owned) {
1564                 commitment_tx_ref |= 1;
1565         }
1566         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
1567         CHECK(obj != NULL);
1568         LDKCResult_SignatureNoneZ* ret = (LDKCResult_SignatureNoneZ*)(*env)->CallLongMethod(env, obj, j_calls->sign_holder_commitment_meth, commitment_tx_ref);
1569         LDKCResult_SignatureNoneZ ret_conv = *(LDKCResult_SignatureNoneZ*)ret;
1570         FREE((void*)ret);
1571         return ret_conv;
1572 }
1573 LDKCResult_CVec_SignatureZNoneZ sign_holder_commitment_htlc_transactions_jcall(const void* this_arg, const LDKHolderCommitmentTransaction * commitment_tx) {
1574         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1575         JNIEnv *env;
1576         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
1577         LDKHolderCommitmentTransaction commitment_tx_var = *commitment_tx;
1578         if (commitment_tx->inner != NULL)
1579                 commitment_tx_var = HolderCommitmentTransaction_clone(commitment_tx);
1580         CHECK((((long)commitment_tx_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1581         CHECK((((long)&commitment_tx_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1582         long commitment_tx_ref = (long)commitment_tx_var.inner;
1583         if (commitment_tx_var.is_owned) {
1584                 commitment_tx_ref |= 1;
1585         }
1586         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
1587         CHECK(obj != NULL);
1588         LDKCResult_CVec_SignatureZNoneZ* ret = (LDKCResult_CVec_SignatureZNoneZ*)(*env)->CallLongMethod(env, obj, j_calls->sign_holder_commitment_htlc_transactions_meth, commitment_tx_ref);
1589         LDKCResult_CVec_SignatureZNoneZ ret_conv = *(LDKCResult_CVec_SignatureZNoneZ*)ret;
1590         FREE((void*)ret);
1591         return ret_conv;
1592 }
1593 LDKCResult_SignatureNoneZ sign_justice_transaction_jcall(const void* this_arg, LDKTransaction justice_tx, uint64_t input, uint64_t amount, const uint8_t (* per_commitment_key)[32], const LDKHTLCOutputInCommitment * htlc) {
1594         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1595         JNIEnv *env;
1596         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
1597         LDKTransaction justice_tx_var = justice_tx;
1598         int8_tArray justice_tx_arr = (*env)->NewByteArray(env, justice_tx_var.datalen);
1599         (*env)->SetByteArrayRegion(env, justice_tx_arr, 0, justice_tx_var.datalen, justice_tx_var.data);
1600         Transaction_free(justice_tx_var);
1601         int8_tArray per_commitment_key_arr = (*env)->NewByteArray(env, 32);
1602         (*env)->SetByteArrayRegion(env, per_commitment_key_arr, 0, 32, *per_commitment_key);
1603         LDKHTLCOutputInCommitment htlc_var = *htlc;
1604         if (htlc->inner != NULL)
1605                 htlc_var = HTLCOutputInCommitment_clone(htlc);
1606         CHECK((((long)htlc_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1607         CHECK((((long)&htlc_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1608         long htlc_ref = (long)htlc_var.inner;
1609         if (htlc_var.is_owned) {
1610                 htlc_ref |= 1;
1611         }
1612         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
1613         CHECK(obj != NULL);
1614         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);
1615         LDKCResult_SignatureNoneZ ret_conv = *(LDKCResult_SignatureNoneZ*)ret;
1616         FREE((void*)ret);
1617         return ret_conv;
1618 }
1619 LDKCResult_SignatureNoneZ sign_counterparty_htlc_transaction_jcall(const void* this_arg, LDKTransaction htlc_tx, uint64_t input, uint64_t amount, LDKPublicKey per_commitment_point, const LDKHTLCOutputInCommitment * htlc) {
1620         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1621         JNIEnv *env;
1622         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
1623         LDKTransaction htlc_tx_var = htlc_tx;
1624         int8_tArray htlc_tx_arr = (*env)->NewByteArray(env, htlc_tx_var.datalen);
1625         (*env)->SetByteArrayRegion(env, htlc_tx_arr, 0, htlc_tx_var.datalen, htlc_tx_var.data);
1626         Transaction_free(htlc_tx_var);
1627         int8_tArray per_commitment_point_arr = (*env)->NewByteArray(env, 33);
1628         (*env)->SetByteArrayRegion(env, per_commitment_point_arr, 0, 33, per_commitment_point.compressed_form);
1629         LDKHTLCOutputInCommitment htlc_var = *htlc;
1630         if (htlc->inner != NULL)
1631                 htlc_var = HTLCOutputInCommitment_clone(htlc);
1632         CHECK((((long)htlc_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1633         CHECK((((long)&htlc_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1634         long htlc_ref = (long)htlc_var.inner;
1635         if (htlc_var.is_owned) {
1636                 htlc_ref |= 1;
1637         }
1638         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
1639         CHECK(obj != NULL);
1640         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);
1641         LDKCResult_SignatureNoneZ ret_conv = *(LDKCResult_SignatureNoneZ*)ret;
1642         FREE((void*)ret);
1643         return ret_conv;
1644 }
1645 LDKCResult_SignatureNoneZ sign_closing_transaction_jcall(const void* this_arg, LDKTransaction closing_tx) {
1646         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1647         JNIEnv *env;
1648         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
1649         LDKTransaction closing_tx_var = closing_tx;
1650         int8_tArray closing_tx_arr = (*env)->NewByteArray(env, closing_tx_var.datalen);
1651         (*env)->SetByteArrayRegion(env, closing_tx_arr, 0, closing_tx_var.datalen, closing_tx_var.data);
1652         Transaction_free(closing_tx_var);
1653         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
1654         CHECK(obj != NULL);
1655         LDKCResult_SignatureNoneZ* ret = (LDKCResult_SignatureNoneZ*)(*env)->CallLongMethod(env, obj, j_calls->sign_closing_transaction_meth, closing_tx_arr);
1656         LDKCResult_SignatureNoneZ ret_conv = *(LDKCResult_SignatureNoneZ*)ret;
1657         FREE((void*)ret);
1658         return ret_conv;
1659 }
1660 LDKCResult_SignatureNoneZ sign_channel_announcement_jcall(const void* this_arg, const LDKUnsignedChannelAnnouncement * msg) {
1661         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1662         JNIEnv *env;
1663         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
1664         LDKUnsignedChannelAnnouncement msg_var = *msg;
1665         if (msg->inner != NULL)
1666                 msg_var = UnsignedChannelAnnouncement_clone(msg);
1667         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1668         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1669         long msg_ref = (long)msg_var.inner;
1670         if (msg_var.is_owned) {
1671                 msg_ref |= 1;
1672         }
1673         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
1674         CHECK(obj != NULL);
1675         LDKCResult_SignatureNoneZ* ret = (LDKCResult_SignatureNoneZ*)(*env)->CallLongMethod(env, obj, j_calls->sign_channel_announcement_meth, msg_ref);
1676         LDKCResult_SignatureNoneZ ret_conv = *(LDKCResult_SignatureNoneZ*)ret;
1677         FREE((void*)ret);
1678         return ret_conv;
1679 }
1680 void ready_channel_jcall(void* this_arg, const LDKChannelTransactionParameters * channel_parameters) {
1681         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1682         JNIEnv *env;
1683         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
1684         LDKChannelTransactionParameters channel_parameters_var = *channel_parameters;
1685         if (channel_parameters->inner != NULL)
1686                 channel_parameters_var = ChannelTransactionParameters_clone(channel_parameters);
1687         CHECK((((long)channel_parameters_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1688         CHECK((((long)&channel_parameters_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1689         long channel_parameters_ref = (long)channel_parameters_var.inner;
1690         if (channel_parameters_var.is_owned) {
1691                 channel_parameters_ref |= 1;
1692         }
1693         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
1694         CHECK(obj != NULL);
1695         return (*env)->CallVoidMethod(env, obj, j_calls->ready_channel_meth, channel_parameters_ref);
1696 }
1697 LDKCVec_u8Z write_jcall(const void* this_arg) {
1698         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1699         JNIEnv *env;
1700         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
1701         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
1702         CHECK(obj != NULL);
1703         int8_tArray arg = (*env)->CallObjectMethod(env, obj, j_calls->write_meth);
1704         LDKCVec_u8Z arg_ref;
1705         arg_ref.datalen = (*env)->GetArrayLength(env, arg);
1706         arg_ref.data = MALLOC(arg_ref.datalen, "LDKCVec_u8Z Bytes");
1707         (*env)->GetByteArrayRegion(env, arg, 0, arg_ref.datalen, arg_ref.data);
1708         return arg_ref;
1709 }
1710 static void* LDKChannelKeys_JCalls_clone(const void* this_arg) {
1711         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1712         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
1713         return (void*) this_arg;
1714 }
1715 static inline LDKChannelKeys LDKChannelKeys_init (JNIEnv *env, jclass clz, jobject o, int64_t pubkeys) {
1716         jclass c = (*env)->GetObjectClass(env, o);
1717         CHECK(c != NULL);
1718         LDKChannelKeys_JCalls *calls = MALLOC(sizeof(LDKChannelKeys_JCalls), "LDKChannelKeys_JCalls");
1719         atomic_init(&calls->refcnt, 1);
1720         DO_ASSERT((*env)->GetJavaVM(env, &calls->vm) == 0);
1721         calls->o = (*env)->NewWeakGlobalRef(env, o);
1722         calls->get_per_commitment_point_meth = (*env)->GetMethodID(env, c, "get_per_commitment_point", "(J)[B");
1723         CHECK(calls->get_per_commitment_point_meth != NULL);
1724         calls->release_commitment_secret_meth = (*env)->GetMethodID(env, c, "release_commitment_secret", "(J)[B");
1725         CHECK(calls->release_commitment_secret_meth != NULL);
1726         calls->key_derivation_params_meth = (*env)->GetMethodID(env, c, "key_derivation_params", "()J");
1727         CHECK(calls->key_derivation_params_meth != NULL);
1728         calls->sign_counterparty_commitment_meth = (*env)->GetMethodID(env, c, "sign_counterparty_commitment", "(J)J");
1729         CHECK(calls->sign_counterparty_commitment_meth != NULL);
1730         calls->sign_holder_commitment_meth = (*env)->GetMethodID(env, c, "sign_holder_commitment", "(J)J");
1731         CHECK(calls->sign_holder_commitment_meth != NULL);
1732         calls->sign_holder_commitment_htlc_transactions_meth = (*env)->GetMethodID(env, c, "sign_holder_commitment_htlc_transactions", "(J)J");
1733         CHECK(calls->sign_holder_commitment_htlc_transactions_meth != NULL);
1734         calls->sign_justice_transaction_meth = (*env)->GetMethodID(env, c, "sign_justice_transaction", "([BJJ[BJ)J");
1735         CHECK(calls->sign_justice_transaction_meth != NULL);
1736         calls->sign_counterparty_htlc_transaction_meth = (*env)->GetMethodID(env, c, "sign_counterparty_htlc_transaction", "([BJJ[BJ)J");
1737         CHECK(calls->sign_counterparty_htlc_transaction_meth != NULL);
1738         calls->sign_closing_transaction_meth = (*env)->GetMethodID(env, c, "sign_closing_transaction", "([B)J");
1739         CHECK(calls->sign_closing_transaction_meth != NULL);
1740         calls->sign_channel_announcement_meth = (*env)->GetMethodID(env, c, "sign_channel_announcement", "(J)J");
1741         CHECK(calls->sign_channel_announcement_meth != NULL);
1742         calls->ready_channel_meth = (*env)->GetMethodID(env, c, "ready_channel", "(J)V");
1743         CHECK(calls->ready_channel_meth != NULL);
1744         calls->write_meth = (*env)->GetMethodID(env, c, "write", "()[B");
1745         CHECK(calls->write_meth != NULL);
1746
1747         LDKChannelPublicKeys pubkeys_conv;
1748         pubkeys_conv.inner = (void*)(pubkeys & (~1));
1749         pubkeys_conv.is_owned = (pubkeys & 1) || (pubkeys == 0);
1750         if (pubkeys_conv.inner != NULL)
1751                 pubkeys_conv = ChannelPublicKeys_clone(&pubkeys_conv);
1752
1753         LDKChannelKeys ret = {
1754                 .this_arg = (void*) calls,
1755                 .get_per_commitment_point = get_per_commitment_point_jcall,
1756                 .release_commitment_secret = release_commitment_secret_jcall,
1757                 .key_derivation_params = key_derivation_params_jcall,
1758                 .sign_counterparty_commitment = sign_counterparty_commitment_jcall,
1759                 .sign_holder_commitment = sign_holder_commitment_jcall,
1760                 .sign_holder_commitment_htlc_transactions = sign_holder_commitment_htlc_transactions_jcall,
1761                 .sign_justice_transaction = sign_justice_transaction_jcall,
1762                 .sign_counterparty_htlc_transaction = sign_counterparty_htlc_transaction_jcall,
1763                 .sign_closing_transaction = sign_closing_transaction_jcall,
1764                 .sign_channel_announcement = sign_channel_announcement_jcall,
1765                 .ready_channel = ready_channel_jcall,
1766                 .clone = LDKChannelKeys_JCalls_clone,
1767                 .write = write_jcall,
1768                 .free = LDKChannelKeys_JCalls_free,
1769                 .pubkeys = pubkeys_conv,
1770                 .set_pubkeys = NULL,
1771         };
1772         return ret;
1773 }
1774 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_LDKChannelKeys_1new (JNIEnv *env, jclass clz, jobject o, int64_t pubkeys) {
1775         LDKChannelKeys *res_ptr = MALLOC(sizeof(LDKChannelKeys), "LDKChannelKeys");
1776         *res_ptr = LDKChannelKeys_init(env, clz, o, pubkeys);
1777         return (long)res_ptr;
1778 }
1779 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKChannelKeys_1get_1obj_1from_1jcalls (JNIEnv *env, jclass clz, int64_t val) {
1780         jobject ret = (*env)->NewLocalRef(env, ((LDKChannelKeys_JCalls*)val)->o);
1781         CHECK(ret != NULL);
1782         return ret;
1783 }
1784 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) {
1785         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
1786         int8_tArray arg_arr = (*env)->NewByteArray(env, 33);
1787         (*env)->SetByteArrayRegion(env, arg_arr, 0, 33, (this_arg_conv->get_per_commitment_point)(this_arg_conv->this_arg, idx).compressed_form);
1788         return arg_arr;
1789 }
1790
1791 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1release_1commitment_1secret(JNIEnv *env, jclass clz, int64_t this_arg, int64_t idx) {
1792         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
1793         int8_tArray arg_arr = (*env)->NewByteArray(env, 32);
1794         (*env)->SetByteArrayRegion(env, arg_arr, 0, 32, (this_arg_conv->release_commitment_secret)(this_arg_conv->this_arg, idx).data);
1795         return arg_arr;
1796 }
1797
1798 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1key_1derivation_1params(JNIEnv *env, jclass clz, int64_t this_arg) {
1799         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
1800         LDKC2Tuple_u64u64Z* ret_ref = MALLOC(sizeof(LDKC2Tuple_u64u64Z), "LDKC2Tuple_u64u64Z");
1801         *ret_ref = (this_arg_conv->key_derivation_params)(this_arg_conv->this_arg);
1802         return (long)ret_ref;
1803 }
1804
1805 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) {
1806         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
1807         LDKCommitmentTransaction commitment_tx_conv;
1808         commitment_tx_conv.inner = (void*)(commitment_tx & (~1));
1809         commitment_tx_conv.is_owned = false;
1810         LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ), "LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ");
1811         *ret_conv = (this_arg_conv->sign_counterparty_commitment)(this_arg_conv->this_arg, &commitment_tx_conv);
1812         return (long)ret_conv;
1813 }
1814
1815 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) {
1816         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
1817         LDKHolderCommitmentTransaction commitment_tx_conv;
1818         commitment_tx_conv.inner = (void*)(commitment_tx & (~1));
1819         commitment_tx_conv.is_owned = false;
1820         LDKCResult_SignatureNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_SignatureNoneZ), "LDKCResult_SignatureNoneZ");
1821         *ret_conv = (this_arg_conv->sign_holder_commitment)(this_arg_conv->this_arg, &commitment_tx_conv);
1822         return (long)ret_conv;
1823 }
1824
1825 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) {
1826         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
1827         LDKHolderCommitmentTransaction commitment_tx_conv;
1828         commitment_tx_conv.inner = (void*)(commitment_tx & (~1));
1829         commitment_tx_conv.is_owned = false;
1830         LDKCResult_CVec_SignatureZNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_CVec_SignatureZNoneZ), "LDKCResult_CVec_SignatureZNoneZ");
1831         *ret_conv = (this_arg_conv->sign_holder_commitment_htlc_transactions)(this_arg_conv->this_arg, &commitment_tx_conv);
1832         return (long)ret_conv;
1833 }
1834
1835 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, int64_t input, int64_t amount, int8_tArray per_commitment_key, int64_t htlc) {
1836         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
1837         LDKTransaction justice_tx_ref;
1838         justice_tx_ref.datalen = (*env)->GetArrayLength(env, justice_tx);
1839         justice_tx_ref.data = MALLOC(justice_tx_ref.datalen, "LDKTransaction Bytes");
1840         (*env)->GetByteArrayRegion(env, justice_tx, 0, justice_tx_ref.datalen, justice_tx_ref.data);
1841         justice_tx_ref.data_is_owned = true;
1842         unsigned char per_commitment_key_arr[32];
1843         CHECK((*env)->GetArrayLength(env, per_commitment_key) == 32);
1844         (*env)->GetByteArrayRegion(env, per_commitment_key, 0, 32, per_commitment_key_arr);
1845         unsigned char (*per_commitment_key_ref)[32] = &per_commitment_key_arr;
1846         LDKHTLCOutputInCommitment htlc_conv;
1847         htlc_conv.inner = (void*)(htlc & (~1));
1848         htlc_conv.is_owned = false;
1849         LDKCResult_SignatureNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_SignatureNoneZ), "LDKCResult_SignatureNoneZ");
1850         *ret_conv = (this_arg_conv->sign_justice_transaction)(this_arg_conv->this_arg, justice_tx_ref, input, amount, per_commitment_key_ref, &htlc_conv);
1851         return (long)ret_conv;
1852 }
1853
1854 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, int64_t input, int64_t amount, int8_tArray per_commitment_point, int64_t htlc) {
1855         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
1856         LDKTransaction htlc_tx_ref;
1857         htlc_tx_ref.datalen = (*env)->GetArrayLength(env, htlc_tx);
1858         htlc_tx_ref.data = MALLOC(htlc_tx_ref.datalen, "LDKTransaction Bytes");
1859         (*env)->GetByteArrayRegion(env, htlc_tx, 0, htlc_tx_ref.datalen, htlc_tx_ref.data);
1860         htlc_tx_ref.data_is_owned = true;
1861         LDKPublicKey per_commitment_point_ref;
1862         CHECK((*env)->GetArrayLength(env, per_commitment_point) == 33);
1863         (*env)->GetByteArrayRegion(env, per_commitment_point, 0, 33, per_commitment_point_ref.compressed_form);
1864         LDKHTLCOutputInCommitment htlc_conv;
1865         htlc_conv.inner = (void*)(htlc & (~1));
1866         htlc_conv.is_owned = false;
1867         LDKCResult_SignatureNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_SignatureNoneZ), "LDKCResult_SignatureNoneZ");
1868         *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);
1869         return (long)ret_conv;
1870 }
1871
1872 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) {
1873         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
1874         LDKTransaction closing_tx_ref;
1875         closing_tx_ref.datalen = (*env)->GetArrayLength(env, closing_tx);
1876         closing_tx_ref.data = MALLOC(closing_tx_ref.datalen, "LDKTransaction Bytes");
1877         (*env)->GetByteArrayRegion(env, closing_tx, 0, closing_tx_ref.datalen, closing_tx_ref.data);
1878         closing_tx_ref.data_is_owned = true;
1879         LDKCResult_SignatureNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_SignatureNoneZ), "LDKCResult_SignatureNoneZ");
1880         *ret_conv = (this_arg_conv->sign_closing_transaction)(this_arg_conv->this_arg, closing_tx_ref);
1881         return (long)ret_conv;
1882 }
1883
1884 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1sign_1channel_1announcement(JNIEnv *env, jclass clz, int64_t this_arg, int64_t msg) {
1885         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
1886         LDKUnsignedChannelAnnouncement msg_conv;
1887         msg_conv.inner = (void*)(msg & (~1));
1888         msg_conv.is_owned = false;
1889         LDKCResult_SignatureNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_SignatureNoneZ), "LDKCResult_SignatureNoneZ");
1890         *ret_conv = (this_arg_conv->sign_channel_announcement)(this_arg_conv->this_arg, &msg_conv);
1891         return (long)ret_conv;
1892 }
1893
1894 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1ready_1channel(JNIEnv *env, jclass clz, int64_t this_arg, int64_t channel_parameters) {
1895         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
1896         LDKChannelTransactionParameters channel_parameters_conv;
1897         channel_parameters_conv.inner = (void*)(channel_parameters & (~1));
1898         channel_parameters_conv.is_owned = false;
1899         (this_arg_conv->ready_channel)(this_arg_conv->this_arg, &channel_parameters_conv);
1900 }
1901
1902 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1write(JNIEnv *env, jclass clz, int64_t this_arg) {
1903         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
1904         LDKCVec_u8Z arg_var = (this_arg_conv->write)(this_arg_conv->this_arg);
1905         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
1906         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
1907         CVec_u8Z_free(arg_var);
1908         return arg_arr;
1909 }
1910
1911 LDKChannelPublicKeys LDKChannelKeys_set_get_pubkeys(LDKChannelKeys* this_arg) {
1912         if (this_arg->set_pubkeys != NULL)
1913                 this_arg->set_pubkeys(this_arg);
1914         return this_arg->pubkeys;
1915 }
1916 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1get_1pubkeys(JNIEnv *env, jclass clz, int64_t this_arg) {
1917         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
1918         LDKChannelPublicKeys ret_var = LDKChannelKeys_set_get_pubkeys(this_arg_conv);
1919         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1920         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1921         long ret_ref = (long)ret_var.inner;
1922         if (ret_var.is_owned) {
1923                 ret_ref |= 1;
1924         }
1925         return ret_ref;
1926 }
1927
1928 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKC2Tuple_1BlockHashChannelMonitorZ_1new(JNIEnv *env, jclass clz, int8_tArray a, int64_t b) {
1929         LDKC2Tuple_BlockHashChannelMonitorZ* ret = MALLOC(sizeof(LDKC2Tuple_BlockHashChannelMonitorZ), "LDKC2Tuple_BlockHashChannelMonitorZ");
1930         LDKThirtyTwoBytes a_ref;
1931         CHECK((*env)->GetArrayLength(env, a) == 32);
1932         (*env)->GetByteArrayRegion(env, a, 0, 32, a_ref.data);
1933         ret->a = a_ref;
1934         LDKChannelMonitor b_conv;
1935         b_conv.inner = (void*)(b & (~1));
1936         b_conv.is_owned = (b & 1) || (b == 0);
1937         // Warning: we may need a move here but can't clone!
1938         ret->b = b_conv;
1939         return (long)ret;
1940 }
1941 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_LDKC2Tuple_1BlockHashChannelMonitorZ_1get_1a(JNIEnv *env, jclass clz, int64_t ptr) {
1942         LDKC2Tuple_BlockHashChannelMonitorZ *tuple = (LDKC2Tuple_BlockHashChannelMonitorZ*)ptr;
1943         int8_tArray a_arr = (*env)->NewByteArray(env, 32);
1944         (*env)->SetByteArrayRegion(env, a_arr, 0, 32, tuple->a.data);
1945         return a_arr;
1946 }
1947 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKC2Tuple_1BlockHashChannelMonitorZ_1get_1b(JNIEnv *env, jclass clz, int64_t ptr) {
1948         LDKC2Tuple_BlockHashChannelMonitorZ *tuple = (LDKC2Tuple_BlockHashChannelMonitorZ*)ptr;
1949         LDKChannelMonitor b_var = tuple->b;
1950         CHECK((((long)b_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1951         CHECK((((long)&b_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1952         long b_ref = (long)b_var.inner & ~1;
1953         return b_ref;
1954 }
1955 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1C2Tuple_1BlockHashChannelMonitorZDecodeErrorZ_1result_1ok (JNIEnv *env, jclass clz, int64_t arg) {
1956         return ((LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ*)arg)->result_ok;
1957 }
1958 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1C2Tuple_1BlockHashChannelMonitorZDecodeErrorZ_1get_1ok (JNIEnv *env, jclass clz, int64_t arg) {
1959         LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ *val = (LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ*)arg;
1960         CHECK(val->result_ok);
1961         long res_ref = (long)&(*val->contents.result);
1962         return res_ref;
1963 }
1964 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1C2Tuple_1BlockHashChannelMonitorZDecodeErrorZ_1get_1err (JNIEnv *env, jclass clz, int64_t arg) {
1965         LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ *val = (LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ*)arg;
1966         CHECK(!val->result_ok);
1967         LDKDecodeError err_var = (*val->contents.err);
1968         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1969         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1970         long err_ref = (long)err_var.inner & ~1;
1971         return err_ref;
1972 }
1973 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1SpendableOutputDescriptorDecodeErrorZ_1result_1ok (JNIEnv *env, jclass clz, int64_t arg) {
1974         return ((LDKCResult_SpendableOutputDescriptorDecodeErrorZ*)arg)->result_ok;
1975 }
1976 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1SpendableOutputDescriptorDecodeErrorZ_1get_1ok (JNIEnv *env, jclass clz, int64_t arg) {
1977         LDKCResult_SpendableOutputDescriptorDecodeErrorZ *val = (LDKCResult_SpendableOutputDescriptorDecodeErrorZ*)arg;
1978         CHECK(val->result_ok);
1979         long res_ref = (long)&(*val->contents.result);
1980         return res_ref;
1981 }
1982 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1SpendableOutputDescriptorDecodeErrorZ_1get_1err (JNIEnv *env, jclass clz, int64_t arg) {
1983         LDKCResult_SpendableOutputDescriptorDecodeErrorZ *val = (LDKCResult_SpendableOutputDescriptorDecodeErrorZ*)arg;
1984         CHECK(!val->result_ok);
1985         LDKDecodeError err_var = (*val->contents.err);
1986         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1987         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1988         long err_ref = (long)err_var.inner & ~1;
1989         return err_ref;
1990 }
1991 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1ChanKeySignerDecodeErrorZ_1result_1ok (JNIEnv *env, jclass clz, int64_t arg) {
1992         return ((LDKCResult_ChanKeySignerDecodeErrorZ*)arg)->result_ok;
1993 }
1994 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1ChanKeySignerDecodeErrorZ_1get_1ok (JNIEnv *env, jclass clz, int64_t arg) {
1995         LDKCResult_ChanKeySignerDecodeErrorZ *val = (LDKCResult_ChanKeySignerDecodeErrorZ*)arg;
1996         CHECK(val->result_ok);
1997         LDKChannelKeys* ret = MALLOC(sizeof(LDKChannelKeys), "LDKChannelKeys");
1998         *ret = (*val->contents.result);
1999         return (long)ret;
2000 }
2001 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1ChanKeySignerDecodeErrorZ_1get_1err (JNIEnv *env, jclass clz, int64_t arg) {
2002         LDKCResult_ChanKeySignerDecodeErrorZ *val = (LDKCResult_ChanKeySignerDecodeErrorZ*)arg;
2003         CHECK(!val->result_ok);
2004         LDKDecodeError err_var = (*val->contents.err);
2005         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2006         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2007         long err_ref = (long)err_var.inner & ~1;
2008         return err_ref;
2009 }
2010 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1InMemoryChannelKeysDecodeErrorZ_1result_1ok (JNIEnv *env, jclass clz, int64_t arg) {
2011         return ((LDKCResult_InMemoryChannelKeysDecodeErrorZ*)arg)->result_ok;
2012 }
2013 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1InMemoryChannelKeysDecodeErrorZ_1get_1ok (JNIEnv *env, jclass clz, int64_t arg) {
2014         LDKCResult_InMemoryChannelKeysDecodeErrorZ *val = (LDKCResult_InMemoryChannelKeysDecodeErrorZ*)arg;
2015         CHECK(val->result_ok);
2016         LDKInMemoryChannelKeys res_var = (*val->contents.result);
2017         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2018         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2019         long res_ref = (long)res_var.inner & ~1;
2020         return res_ref;
2021 }
2022 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1InMemoryChannelKeysDecodeErrorZ_1get_1err (JNIEnv *env, jclass clz, int64_t arg) {
2023         LDKCResult_InMemoryChannelKeysDecodeErrorZ *val = (LDKCResult_InMemoryChannelKeysDecodeErrorZ*)arg;
2024         CHECK(!val->result_ok);
2025         LDKDecodeError err_var = (*val->contents.err);
2026         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2027         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2028         long err_ref = (long)err_var.inner & ~1;
2029         return err_ref;
2030 }
2031 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1TxOutAccessErrorZ_1result_1ok (JNIEnv *env, jclass clz, int64_t arg) {
2032         return ((LDKCResult_TxOutAccessErrorZ*)arg)->result_ok;
2033 }
2034 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1TxOutAccessErrorZ_1get_1ok (JNIEnv *env, jclass clz, int64_t arg) {
2035         LDKCResult_TxOutAccessErrorZ *val = (LDKCResult_TxOutAccessErrorZ*)arg;
2036         CHECK(val->result_ok);
2037         long res_ref = (long)&(*val->contents.result);
2038         return (long)res_ref;
2039 }
2040 JNIEXPORT jclass JNICALL Java_org_ldk_impl_bindings_LDKCResult_1TxOutAccessErrorZ_1get_1err (JNIEnv *env, jclass clz, int64_t arg) {
2041         LDKCResult_TxOutAccessErrorZ *val = (LDKCResult_TxOutAccessErrorZ*)arg;
2042         CHECK(!val->result_ok);
2043         jclass err_conv = LDKAccessError_to_java(env, (*val->contents.err));
2044         return err_conv;
2045 }
2046 static jclass LDKAPIError_APIMisuseError_class = NULL;
2047 static jmethodID LDKAPIError_APIMisuseError_meth = NULL;
2048 static jclass LDKAPIError_FeeRateTooHigh_class = NULL;
2049 static jmethodID LDKAPIError_FeeRateTooHigh_meth = NULL;
2050 static jclass LDKAPIError_RouteError_class = NULL;
2051 static jmethodID LDKAPIError_RouteError_meth = NULL;
2052 static jclass LDKAPIError_ChannelUnavailable_class = NULL;
2053 static jmethodID LDKAPIError_ChannelUnavailable_meth = NULL;
2054 static jclass LDKAPIError_MonitorUpdateFailed_class = NULL;
2055 static jmethodID LDKAPIError_MonitorUpdateFailed_meth = NULL;
2056 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_00024LDKAPIError_init (JNIEnv *env, jclass clz) {
2057         LDKAPIError_APIMisuseError_class =
2058                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKAPIError$APIMisuseError;"));
2059         CHECK(LDKAPIError_APIMisuseError_class != NULL);
2060         LDKAPIError_APIMisuseError_meth = (*env)->GetMethodID(env, LDKAPIError_APIMisuseError_class, "<init>", "([B)V");
2061         CHECK(LDKAPIError_APIMisuseError_meth != NULL);
2062         LDKAPIError_FeeRateTooHigh_class =
2063                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKAPIError$FeeRateTooHigh;"));
2064         CHECK(LDKAPIError_FeeRateTooHigh_class != NULL);
2065         LDKAPIError_FeeRateTooHigh_meth = (*env)->GetMethodID(env, LDKAPIError_FeeRateTooHigh_class, "<init>", "([BI)V");
2066         CHECK(LDKAPIError_FeeRateTooHigh_meth != NULL);
2067         LDKAPIError_RouteError_class =
2068                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKAPIError$RouteError;"));
2069         CHECK(LDKAPIError_RouteError_class != NULL);
2070         LDKAPIError_RouteError_meth = (*env)->GetMethodID(env, LDKAPIError_RouteError_class, "<init>", "(Ljava/lang/String;)V");
2071         CHECK(LDKAPIError_RouteError_meth != NULL);
2072         LDKAPIError_ChannelUnavailable_class =
2073                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKAPIError$ChannelUnavailable;"));
2074         CHECK(LDKAPIError_ChannelUnavailable_class != NULL);
2075         LDKAPIError_ChannelUnavailable_meth = (*env)->GetMethodID(env, LDKAPIError_ChannelUnavailable_class, "<init>", "([B)V");
2076         CHECK(LDKAPIError_ChannelUnavailable_meth != NULL);
2077         LDKAPIError_MonitorUpdateFailed_class =
2078                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKAPIError$MonitorUpdateFailed;"));
2079         CHECK(LDKAPIError_MonitorUpdateFailed_class != NULL);
2080         LDKAPIError_MonitorUpdateFailed_meth = (*env)->GetMethodID(env, LDKAPIError_MonitorUpdateFailed_class, "<init>", "()V");
2081         CHECK(LDKAPIError_MonitorUpdateFailed_meth != NULL);
2082 }
2083 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKAPIError_1ref_1from_1ptr (JNIEnv *env, jclass clz, int64_t ptr) {
2084         LDKAPIError *obj = (LDKAPIError*)ptr;
2085         switch(obj->tag) {
2086                 case LDKAPIError_APIMisuseError: {
2087                         LDKCVec_u8Z err_var = obj->api_misuse_error.err;
2088                         int8_tArray err_arr = (*env)->NewByteArray(env, err_var.datalen);
2089                         (*env)->SetByteArrayRegion(env, err_arr, 0, err_var.datalen, err_var.data);
2090                         return (*env)->NewObject(env, LDKAPIError_APIMisuseError_class, LDKAPIError_APIMisuseError_meth, err_arr);
2091                 }
2092                 case LDKAPIError_FeeRateTooHigh: {
2093                         LDKCVec_u8Z err_var = obj->fee_rate_too_high.err;
2094                         int8_tArray err_arr = (*env)->NewByteArray(env, err_var.datalen);
2095                         (*env)->SetByteArrayRegion(env, err_arr, 0, err_var.datalen, err_var.data);
2096                         return (*env)->NewObject(env, LDKAPIError_FeeRateTooHigh_class, LDKAPIError_FeeRateTooHigh_meth, err_arr, obj->fee_rate_too_high.feerate);
2097                 }
2098                 case LDKAPIError_RouteError: {
2099                         LDKStr err_str = obj->route_error.err;
2100                         char* err_buf = MALLOC(err_str.len + 1, "str conv buf");
2101                         memcpy(err_buf, err_str.chars, err_str.len);
2102                         err_buf[err_str.len] = 0;
2103                         jstring err_conv = (*env)->NewStringUTF(env, err_str.chars);
2104                         FREE(err_buf);
2105                         return (*env)->NewObject(env, LDKAPIError_RouteError_class, LDKAPIError_RouteError_meth, err_conv);
2106                 }
2107                 case LDKAPIError_ChannelUnavailable: {
2108                         LDKCVec_u8Z err_var = obj->channel_unavailable.err;
2109                         int8_tArray err_arr = (*env)->NewByteArray(env, err_var.datalen);
2110                         (*env)->SetByteArrayRegion(env, err_arr, 0, err_var.datalen, err_var.data);
2111                         return (*env)->NewObject(env, LDKAPIError_ChannelUnavailable_class, LDKAPIError_ChannelUnavailable_meth, err_arr);
2112                 }
2113                 case LDKAPIError_MonitorUpdateFailed: {
2114                         return (*env)->NewObject(env, LDKAPIError_MonitorUpdateFailed_class, LDKAPIError_MonitorUpdateFailed_meth);
2115                 }
2116                 default: abort();
2117         }
2118 }
2119 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NoneAPIErrorZ_1result_1ok (JNIEnv *env, jclass clz, int64_t arg) {
2120         return ((LDKCResult_NoneAPIErrorZ*)arg)->result_ok;
2121 }
2122 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NoneAPIErrorZ_1get_1ok (JNIEnv *env, jclass clz, int64_t arg) {
2123         LDKCResult_NoneAPIErrorZ *val = (LDKCResult_NoneAPIErrorZ*)arg;
2124         CHECK(val->result_ok);
2125         return *val->contents.result;
2126 }
2127 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NoneAPIErrorZ_1get_1err (JNIEnv *env, jclass clz, int64_t arg) {
2128         LDKCResult_NoneAPIErrorZ *val = (LDKCResult_NoneAPIErrorZ*)arg;
2129         CHECK(!val->result_ok);
2130         long err_ref = (long)&(*val->contents.err);
2131         return err_ref;
2132 }
2133 static inline LDKCResult_NoneAPIErrorZ CResult_NoneAPIErrorZ_clone(const LDKCResult_NoneAPIErrorZ *orig) {
2134         LDKCResult_NoneAPIErrorZ res = { .result_ok = orig->result_ok };
2135         if (orig->result_ok) {
2136                 res.contents.result = NULL;
2137         } else {
2138                 LDKAPIError* contents = MALLOC(sizeof(LDKAPIError), "LDKAPIError result Err clone");
2139                 *contents = APIError_clone(orig->contents.err);
2140                 res.contents.err = contents;
2141         }
2142         return res;
2143 }
2144 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCVec_1ChannelDetailsZ_1new(JNIEnv *env, jclass clz, int64_tArray elems) {
2145         LDKCVec_ChannelDetailsZ *ret = MALLOC(sizeof(LDKCVec_ChannelDetailsZ), "LDKCVec_ChannelDetailsZ");
2146         ret->datalen = (*env)->GetArrayLength(env, elems);
2147         if (ret->datalen == 0) {
2148                 ret->data = NULL;
2149         } else {
2150                 ret->data = MALLOC(sizeof(LDKChannelDetails) * ret->datalen, "LDKCVec_ChannelDetailsZ Data");
2151                 int64_t *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
2152                 for (size_t i = 0; i < ret->datalen; i++) {
2153                         int64_t arr_elem = java_elems[i];
2154                         LDKChannelDetails arr_elem_conv;
2155                         arr_elem_conv.inner = (void*)(arr_elem & (~1));
2156                         arr_elem_conv.is_owned = (arr_elem & 1) || (arr_elem == 0);
2157                         if (arr_elem_conv.inner != NULL)
2158                                 arr_elem_conv = ChannelDetails_clone(&arr_elem_conv);
2159                         ret->data[i] = arr_elem_conv;
2160                 }
2161                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
2162         }
2163         return (long)ret;
2164 }
2165 static inline LDKCVec_ChannelDetailsZ CVec_ChannelDetailsZ_clone(const LDKCVec_ChannelDetailsZ *orig) {
2166         LDKCVec_ChannelDetailsZ ret = { .data = MALLOC(sizeof(LDKChannelDetails) * orig->datalen, "LDKCVec_ChannelDetailsZ clone bytes"), .datalen = orig->datalen };
2167         for (size_t i = 0; i < ret.datalen; i++) {
2168                 ret.data[i] = ChannelDetails_clone(&orig->data[i]);
2169         }
2170         return ret;
2171 }
2172 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NonePaymentSendFailureZ_1result_1ok (JNIEnv *env, jclass clz, int64_t arg) {
2173         return ((LDKCResult_NonePaymentSendFailureZ*)arg)->result_ok;
2174 }
2175 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NonePaymentSendFailureZ_1get_1ok (JNIEnv *env, jclass clz, int64_t arg) {
2176         LDKCResult_NonePaymentSendFailureZ *val = (LDKCResult_NonePaymentSendFailureZ*)arg;
2177         CHECK(val->result_ok);
2178         return *val->contents.result;
2179 }
2180 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NonePaymentSendFailureZ_1get_1err (JNIEnv *env, jclass clz, int64_t arg) {
2181         LDKCResult_NonePaymentSendFailureZ *val = (LDKCResult_NonePaymentSendFailureZ*)arg;
2182         CHECK(!val->result_ok);
2183         LDKPaymentSendFailure err_var = (*val->contents.err);
2184         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2185         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2186         long err_ref = (long)err_var.inner & ~1;
2187         return err_ref;
2188 }
2189 static jclass LDKNetAddress_IPv4_class = NULL;
2190 static jmethodID LDKNetAddress_IPv4_meth = NULL;
2191 static jclass LDKNetAddress_IPv6_class = NULL;
2192 static jmethodID LDKNetAddress_IPv6_meth = NULL;
2193 static jclass LDKNetAddress_OnionV2_class = NULL;
2194 static jmethodID LDKNetAddress_OnionV2_meth = NULL;
2195 static jclass LDKNetAddress_OnionV3_class = NULL;
2196 static jmethodID LDKNetAddress_OnionV3_meth = NULL;
2197 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_00024LDKNetAddress_init (JNIEnv *env, jclass clz) {
2198         LDKNetAddress_IPv4_class =
2199                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKNetAddress$IPv4;"));
2200         CHECK(LDKNetAddress_IPv4_class != NULL);
2201         LDKNetAddress_IPv4_meth = (*env)->GetMethodID(env, LDKNetAddress_IPv4_class, "<init>", "([BS)V");
2202         CHECK(LDKNetAddress_IPv4_meth != NULL);
2203         LDKNetAddress_IPv6_class =
2204                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKNetAddress$IPv6;"));
2205         CHECK(LDKNetAddress_IPv6_class != NULL);
2206         LDKNetAddress_IPv6_meth = (*env)->GetMethodID(env, LDKNetAddress_IPv6_class, "<init>", "([BS)V");
2207         CHECK(LDKNetAddress_IPv6_meth != NULL);
2208         LDKNetAddress_OnionV2_class =
2209                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKNetAddress$OnionV2;"));
2210         CHECK(LDKNetAddress_OnionV2_class != NULL);
2211         LDKNetAddress_OnionV2_meth = (*env)->GetMethodID(env, LDKNetAddress_OnionV2_class, "<init>", "([BS)V");
2212         CHECK(LDKNetAddress_OnionV2_meth != NULL);
2213         LDKNetAddress_OnionV3_class =
2214                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKNetAddress$OnionV3;"));
2215         CHECK(LDKNetAddress_OnionV3_class != NULL);
2216         LDKNetAddress_OnionV3_meth = (*env)->GetMethodID(env, LDKNetAddress_OnionV3_class, "<init>", "([BSBS)V");
2217         CHECK(LDKNetAddress_OnionV3_meth != NULL);
2218 }
2219 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKNetAddress_1ref_1from_1ptr (JNIEnv *env, jclass clz, int64_t ptr) {
2220         LDKNetAddress *obj = (LDKNetAddress*)ptr;
2221         switch(obj->tag) {
2222                 case LDKNetAddress_IPv4: {
2223                         int8_tArray addr_arr = (*env)->NewByteArray(env, 4);
2224                         (*env)->SetByteArrayRegion(env, addr_arr, 0, 4, obj->i_pv4.addr.data);
2225                         return (*env)->NewObject(env, LDKNetAddress_IPv4_class, LDKNetAddress_IPv4_meth, addr_arr, obj->i_pv4.port);
2226                 }
2227                 case LDKNetAddress_IPv6: {
2228                         int8_tArray addr_arr = (*env)->NewByteArray(env, 16);
2229                         (*env)->SetByteArrayRegion(env, addr_arr, 0, 16, obj->i_pv6.addr.data);
2230                         return (*env)->NewObject(env, LDKNetAddress_IPv6_class, LDKNetAddress_IPv6_meth, addr_arr, obj->i_pv6.port);
2231                 }
2232                 case LDKNetAddress_OnionV2: {
2233                         int8_tArray addr_arr = (*env)->NewByteArray(env, 10);
2234                         (*env)->SetByteArrayRegion(env, addr_arr, 0, 10, obj->onion_v2.addr.data);
2235                         return (*env)->NewObject(env, LDKNetAddress_OnionV2_class, LDKNetAddress_OnionV2_meth, addr_arr, obj->onion_v2.port);
2236                 }
2237                 case LDKNetAddress_OnionV3: {
2238                         int8_tArray ed25519_pubkey_arr = (*env)->NewByteArray(env, 32);
2239                         (*env)->SetByteArrayRegion(env, ed25519_pubkey_arr, 0, 32, obj->onion_v3.ed25519_pubkey.data);
2240                         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);
2241                 }
2242                 default: abort();
2243         }
2244 }
2245 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCVec_1NetAddressZ_1new(JNIEnv *env, jclass clz, int64_tArray elems) {
2246         LDKCVec_NetAddressZ *ret = MALLOC(sizeof(LDKCVec_NetAddressZ), "LDKCVec_NetAddressZ");
2247         ret->datalen = (*env)->GetArrayLength(env, elems);
2248         if (ret->datalen == 0) {
2249                 ret->data = NULL;
2250         } else {
2251                 ret->data = MALLOC(sizeof(LDKNetAddress) * ret->datalen, "LDKCVec_NetAddressZ Data");
2252                 int64_t *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
2253                 for (size_t i = 0; i < ret->datalen; i++) {
2254                         int64_t arr_elem = java_elems[i];
2255                         LDKNetAddress arr_elem_conv = *(LDKNetAddress*)arr_elem;
2256                         FREE((void*)arr_elem);
2257                         ret->data[i] = arr_elem_conv;
2258                 }
2259                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
2260         }
2261         return (long)ret;
2262 }
2263 static inline LDKCVec_NetAddressZ CVec_NetAddressZ_clone(const LDKCVec_NetAddressZ *orig) {
2264         LDKCVec_NetAddressZ ret = { .data = MALLOC(sizeof(LDKNetAddress) * orig->datalen, "LDKCVec_NetAddressZ clone bytes"), .datalen = orig->datalen };
2265         for (size_t i = 0; i < ret.datalen; i++) {
2266                 ret.data[i] = NetAddress_clone(&orig->data[i]);
2267         }
2268         return ret;
2269 }
2270 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCVec_1ChannelMonitorZ_1new(JNIEnv *env, jclass clz, int64_tArray elems) {
2271         LDKCVec_ChannelMonitorZ *ret = MALLOC(sizeof(LDKCVec_ChannelMonitorZ), "LDKCVec_ChannelMonitorZ");
2272         ret->datalen = (*env)->GetArrayLength(env, elems);
2273         if (ret->datalen == 0) {
2274                 ret->data = NULL;
2275         } else {
2276                 ret->data = MALLOC(sizeof(LDKChannelMonitor) * ret->datalen, "LDKCVec_ChannelMonitorZ Data");
2277                 int64_t *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
2278                 for (size_t i = 0; i < ret->datalen; i++) {
2279                         int64_t arr_elem = java_elems[i];
2280                         LDKChannelMonitor arr_elem_conv;
2281                         arr_elem_conv.inner = (void*)(arr_elem & (~1));
2282                         arr_elem_conv.is_owned = (arr_elem & 1) || (arr_elem == 0);
2283                         // Warning: we may need a move here but can't clone!
2284                         ret->data[i] = arr_elem_conv;
2285                 }
2286                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
2287         }
2288         return (long)ret;
2289 }
2290 typedef struct LDKWatch_JCalls {
2291         atomic_size_t refcnt;
2292         JavaVM *vm;
2293         jweak o;
2294         jmethodID watch_channel_meth;
2295         jmethodID update_channel_meth;
2296         jmethodID release_pending_monitor_events_meth;
2297 } LDKWatch_JCalls;
2298 static void LDKWatch_JCalls_free(void* this_arg) {
2299         LDKWatch_JCalls *j_calls = (LDKWatch_JCalls*) this_arg;
2300         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
2301                 JNIEnv *env;
2302                 DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
2303                 (*env)->DeleteWeakGlobalRef(env, j_calls->o);
2304                 FREE(j_calls);
2305         }
2306 }
2307 LDKCResult_NoneChannelMonitorUpdateErrZ watch_channel_jcall(const void* this_arg, LDKOutPoint funding_txo, LDKChannelMonitor monitor) {
2308         LDKWatch_JCalls *j_calls = (LDKWatch_JCalls*) this_arg;
2309         JNIEnv *env;
2310         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
2311         LDKOutPoint funding_txo_var = funding_txo;
2312         CHECK((((long)funding_txo_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2313         CHECK((((long)&funding_txo_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2314         long funding_txo_ref = (long)funding_txo_var.inner;
2315         if (funding_txo_var.is_owned) {
2316                 funding_txo_ref |= 1;
2317         }
2318         LDKChannelMonitor monitor_var = monitor;
2319         CHECK((((long)monitor_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2320         CHECK((((long)&monitor_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2321         long monitor_ref = (long)monitor_var.inner;
2322         if (monitor_var.is_owned) {
2323                 monitor_ref |= 1;
2324         }
2325         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
2326         CHECK(obj != NULL);
2327         LDKCResult_NoneChannelMonitorUpdateErrZ* ret = (LDKCResult_NoneChannelMonitorUpdateErrZ*)(*env)->CallLongMethod(env, obj, j_calls->watch_channel_meth, funding_txo_ref, monitor_ref);
2328         LDKCResult_NoneChannelMonitorUpdateErrZ ret_conv = *(LDKCResult_NoneChannelMonitorUpdateErrZ*)ret;
2329         FREE((void*)ret);
2330         return ret_conv;
2331 }
2332 LDKCResult_NoneChannelMonitorUpdateErrZ update_channel_jcall(const void* this_arg, LDKOutPoint funding_txo, LDKChannelMonitorUpdate update) {
2333         LDKWatch_JCalls *j_calls = (LDKWatch_JCalls*) this_arg;
2334         JNIEnv *env;
2335         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
2336         LDKOutPoint funding_txo_var = funding_txo;
2337         CHECK((((long)funding_txo_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2338         CHECK((((long)&funding_txo_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2339         long funding_txo_ref = (long)funding_txo_var.inner;
2340         if (funding_txo_var.is_owned) {
2341                 funding_txo_ref |= 1;
2342         }
2343         LDKChannelMonitorUpdate update_var = update;
2344         CHECK((((long)update_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2345         CHECK((((long)&update_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2346         long update_ref = (long)update_var.inner;
2347         if (update_var.is_owned) {
2348                 update_ref |= 1;
2349         }
2350         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
2351         CHECK(obj != NULL);
2352         LDKCResult_NoneChannelMonitorUpdateErrZ* ret = (LDKCResult_NoneChannelMonitorUpdateErrZ*)(*env)->CallLongMethod(env, obj, j_calls->update_channel_meth, funding_txo_ref, update_ref);
2353         LDKCResult_NoneChannelMonitorUpdateErrZ ret_conv = *(LDKCResult_NoneChannelMonitorUpdateErrZ*)ret;
2354         FREE((void*)ret);
2355         return ret_conv;
2356 }
2357 LDKCVec_MonitorEventZ release_pending_monitor_events_jcall(const void* this_arg) {
2358         LDKWatch_JCalls *j_calls = (LDKWatch_JCalls*) this_arg;
2359         JNIEnv *env;
2360         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
2361         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
2362         CHECK(obj != NULL);
2363         int64_tArray arg = (*env)->CallObjectMethod(env, obj, j_calls->release_pending_monitor_events_meth);
2364         LDKCVec_MonitorEventZ arg_constr;
2365         arg_constr.datalen = (*env)->GetArrayLength(env, arg);
2366         if (arg_constr.datalen > 0)
2367                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKMonitorEvent), "LDKCVec_MonitorEventZ Elements");
2368         else
2369                 arg_constr.data = NULL;
2370         int64_t* arg_vals = (*env)->GetLongArrayElements (env, arg, NULL);
2371         for (size_t o = 0; o < arg_constr.datalen; o++) {
2372                 int64_t arr_conv_14 = arg_vals[o];
2373                 LDKMonitorEvent arr_conv_14_conv;
2374                 arr_conv_14_conv.inner = (void*)(arr_conv_14 & (~1));
2375                 arr_conv_14_conv.is_owned = (arr_conv_14 & 1) || (arr_conv_14 == 0);
2376                 if (arr_conv_14_conv.inner != NULL)
2377                         arr_conv_14_conv = MonitorEvent_clone(&arr_conv_14_conv);
2378                 arg_constr.data[o] = arr_conv_14_conv;
2379         }
2380         (*env)->ReleaseLongArrayElements(env, arg, arg_vals, 0);
2381         return arg_constr;
2382 }
2383 static void* LDKWatch_JCalls_clone(const void* this_arg) {
2384         LDKWatch_JCalls *j_calls = (LDKWatch_JCalls*) this_arg;
2385         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
2386         return (void*) this_arg;
2387 }
2388 static inline LDKWatch LDKWatch_init (JNIEnv *env, jclass clz, jobject o) {
2389         jclass c = (*env)->GetObjectClass(env, o);
2390         CHECK(c != NULL);
2391         LDKWatch_JCalls *calls = MALLOC(sizeof(LDKWatch_JCalls), "LDKWatch_JCalls");
2392         atomic_init(&calls->refcnt, 1);
2393         DO_ASSERT((*env)->GetJavaVM(env, &calls->vm) == 0);
2394         calls->o = (*env)->NewWeakGlobalRef(env, o);
2395         calls->watch_channel_meth = (*env)->GetMethodID(env, c, "watch_channel", "(JJ)J");
2396         CHECK(calls->watch_channel_meth != NULL);
2397         calls->update_channel_meth = (*env)->GetMethodID(env, c, "update_channel", "(JJ)J");
2398         CHECK(calls->update_channel_meth != NULL);
2399         calls->release_pending_monitor_events_meth = (*env)->GetMethodID(env, c, "release_pending_monitor_events", "()[J");
2400         CHECK(calls->release_pending_monitor_events_meth != NULL);
2401
2402         LDKWatch ret = {
2403                 .this_arg = (void*) calls,
2404                 .watch_channel = watch_channel_jcall,
2405                 .update_channel = update_channel_jcall,
2406                 .release_pending_monitor_events = release_pending_monitor_events_jcall,
2407                 .free = LDKWatch_JCalls_free,
2408         };
2409         return ret;
2410 }
2411 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_LDKWatch_1new (JNIEnv *env, jclass clz, jobject o) {
2412         LDKWatch *res_ptr = MALLOC(sizeof(LDKWatch), "LDKWatch");
2413         *res_ptr = LDKWatch_init(env, clz, o);
2414         return (long)res_ptr;
2415 }
2416 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKWatch_1get_1obj_1from_1jcalls (JNIEnv *env, jclass clz, int64_t val) {
2417         jobject ret = (*env)->NewLocalRef(env, ((LDKWatch_JCalls*)val)->o);
2418         CHECK(ret != NULL);
2419         return ret;
2420 }
2421 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) {
2422         LDKWatch* this_arg_conv = (LDKWatch*)this_arg;
2423         LDKOutPoint funding_txo_conv;
2424         funding_txo_conv.inner = (void*)(funding_txo & (~1));
2425         funding_txo_conv.is_owned = (funding_txo & 1) || (funding_txo == 0);
2426         if (funding_txo_conv.inner != NULL)
2427                 funding_txo_conv = OutPoint_clone(&funding_txo_conv);
2428         LDKChannelMonitor monitor_conv;
2429         monitor_conv.inner = (void*)(monitor & (~1));
2430         monitor_conv.is_owned = (monitor & 1) || (monitor == 0);
2431         // Warning: we may need a move here but can't clone!
2432         LDKCResult_NoneChannelMonitorUpdateErrZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneChannelMonitorUpdateErrZ), "LDKCResult_NoneChannelMonitorUpdateErrZ");
2433         *ret_conv = (this_arg_conv->watch_channel)(this_arg_conv->this_arg, funding_txo_conv, monitor_conv);
2434         return (long)ret_conv;
2435 }
2436
2437 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) {
2438         LDKWatch* this_arg_conv = (LDKWatch*)this_arg;
2439         LDKOutPoint funding_txo_conv;
2440         funding_txo_conv.inner = (void*)(funding_txo & (~1));
2441         funding_txo_conv.is_owned = (funding_txo & 1) || (funding_txo == 0);
2442         if (funding_txo_conv.inner != NULL)
2443                 funding_txo_conv = OutPoint_clone(&funding_txo_conv);
2444         LDKChannelMonitorUpdate update_conv;
2445         update_conv.inner = (void*)(update & (~1));
2446         update_conv.is_owned = (update & 1) || (update == 0);
2447         if (update_conv.inner != NULL)
2448                 update_conv = ChannelMonitorUpdate_clone(&update_conv);
2449         LDKCResult_NoneChannelMonitorUpdateErrZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneChannelMonitorUpdateErrZ), "LDKCResult_NoneChannelMonitorUpdateErrZ");
2450         *ret_conv = (this_arg_conv->update_channel)(this_arg_conv->this_arg, funding_txo_conv, update_conv);
2451         return (long)ret_conv;
2452 }
2453
2454 JNIEXPORT int64_tArray JNICALL Java_org_ldk_impl_bindings_Watch_1release_1pending_1monitor_1events(JNIEnv *env, jclass clz, int64_t this_arg) {
2455         LDKWatch* this_arg_conv = (LDKWatch*)this_arg;
2456         LDKCVec_MonitorEventZ ret_var = (this_arg_conv->release_pending_monitor_events)(this_arg_conv->this_arg);
2457         int64_tArray ret_arr = (*env)->NewLongArray(env, ret_var.datalen);
2458         int64_t *ret_arr_ptr = (*env)->GetPrimitiveArrayCritical(env, ret_arr, NULL);
2459         for (size_t o = 0; o < ret_var.datalen; o++) {
2460                 LDKMonitorEvent arr_conv_14_var = ret_var.data[o];
2461                 CHECK((((long)arr_conv_14_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2462                 CHECK((((long)&arr_conv_14_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2463                 long arr_conv_14_ref = (long)arr_conv_14_var.inner;
2464                 if (arr_conv_14_var.is_owned) {
2465                         arr_conv_14_ref |= 1;
2466                 }
2467                 ret_arr_ptr[o] = arr_conv_14_ref;
2468         }
2469         (*env)->ReleasePrimitiveArrayCritical(env, ret_arr, ret_arr_ptr, 0);
2470         FREE(ret_var.data);
2471         return ret_arr;
2472 }
2473
2474 typedef struct LDKBroadcasterInterface_JCalls {
2475         atomic_size_t refcnt;
2476         JavaVM *vm;
2477         jweak o;
2478         jmethodID broadcast_transaction_meth;
2479 } LDKBroadcasterInterface_JCalls;
2480 static void LDKBroadcasterInterface_JCalls_free(void* this_arg) {
2481         LDKBroadcasterInterface_JCalls *j_calls = (LDKBroadcasterInterface_JCalls*) this_arg;
2482         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
2483                 JNIEnv *env;
2484                 DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
2485                 (*env)->DeleteWeakGlobalRef(env, j_calls->o);
2486                 FREE(j_calls);
2487         }
2488 }
2489 void broadcast_transaction_jcall(const void* this_arg, LDKTransaction tx) {
2490         LDKBroadcasterInterface_JCalls *j_calls = (LDKBroadcasterInterface_JCalls*) this_arg;
2491         JNIEnv *env;
2492         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
2493         LDKTransaction tx_var = tx;
2494         int8_tArray tx_arr = (*env)->NewByteArray(env, tx_var.datalen);
2495         (*env)->SetByteArrayRegion(env, tx_arr, 0, tx_var.datalen, tx_var.data);
2496         Transaction_free(tx_var);
2497         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
2498         CHECK(obj != NULL);
2499         return (*env)->CallVoidMethod(env, obj, j_calls->broadcast_transaction_meth, tx_arr);
2500 }
2501 static void* LDKBroadcasterInterface_JCalls_clone(const void* this_arg) {
2502         LDKBroadcasterInterface_JCalls *j_calls = (LDKBroadcasterInterface_JCalls*) this_arg;
2503         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
2504         return (void*) this_arg;
2505 }
2506 static inline LDKBroadcasterInterface LDKBroadcasterInterface_init (JNIEnv *env, jclass clz, jobject o) {
2507         jclass c = (*env)->GetObjectClass(env, o);
2508         CHECK(c != NULL);
2509         LDKBroadcasterInterface_JCalls *calls = MALLOC(sizeof(LDKBroadcasterInterface_JCalls), "LDKBroadcasterInterface_JCalls");
2510         atomic_init(&calls->refcnt, 1);
2511         DO_ASSERT((*env)->GetJavaVM(env, &calls->vm) == 0);
2512         calls->o = (*env)->NewWeakGlobalRef(env, o);
2513         calls->broadcast_transaction_meth = (*env)->GetMethodID(env, c, "broadcast_transaction", "([B)V");
2514         CHECK(calls->broadcast_transaction_meth != NULL);
2515
2516         LDKBroadcasterInterface ret = {
2517                 .this_arg = (void*) calls,
2518                 .broadcast_transaction = broadcast_transaction_jcall,
2519                 .free = LDKBroadcasterInterface_JCalls_free,
2520         };
2521         return ret;
2522 }
2523 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_LDKBroadcasterInterface_1new (JNIEnv *env, jclass clz, jobject o) {
2524         LDKBroadcasterInterface *res_ptr = MALLOC(sizeof(LDKBroadcasterInterface), "LDKBroadcasterInterface");
2525         *res_ptr = LDKBroadcasterInterface_init(env, clz, o);
2526         return (long)res_ptr;
2527 }
2528 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKBroadcasterInterface_1get_1obj_1from_1jcalls (JNIEnv *env, jclass clz, int64_t val) {
2529         jobject ret = (*env)->NewLocalRef(env, ((LDKBroadcasterInterface_JCalls*)val)->o);
2530         CHECK(ret != NULL);
2531         return ret;
2532 }
2533 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_BroadcasterInterface_1broadcast_1transaction(JNIEnv *env, jclass clz, int64_t this_arg, int8_tArray tx) {
2534         LDKBroadcasterInterface* this_arg_conv = (LDKBroadcasterInterface*)this_arg;
2535         LDKTransaction tx_ref;
2536         tx_ref.datalen = (*env)->GetArrayLength(env, tx);
2537         tx_ref.data = MALLOC(tx_ref.datalen, "LDKTransaction Bytes");
2538         (*env)->GetByteArrayRegion(env, tx, 0, tx_ref.datalen, tx_ref.data);
2539         tx_ref.data_is_owned = true;
2540         (this_arg_conv->broadcast_transaction)(this_arg_conv->this_arg, tx_ref);
2541 }
2542
2543 typedef struct LDKKeysInterface_JCalls {
2544         atomic_size_t refcnt;
2545         JavaVM *vm;
2546         jweak o;
2547         jmethodID get_node_secret_meth;
2548         jmethodID get_destination_script_meth;
2549         jmethodID get_shutdown_pubkey_meth;
2550         jmethodID get_channel_keys_meth;
2551         jmethodID get_secure_random_bytes_meth;
2552         jmethodID read_chan_signer_meth;
2553 } LDKKeysInterface_JCalls;
2554 static void LDKKeysInterface_JCalls_free(void* this_arg) {
2555         LDKKeysInterface_JCalls *j_calls = (LDKKeysInterface_JCalls*) this_arg;
2556         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
2557                 JNIEnv *env;
2558                 DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
2559                 (*env)->DeleteWeakGlobalRef(env, j_calls->o);
2560                 FREE(j_calls);
2561         }
2562 }
2563 LDKSecretKey get_node_secret_jcall(const void* this_arg) {
2564         LDKKeysInterface_JCalls *j_calls = (LDKKeysInterface_JCalls*) this_arg;
2565         JNIEnv *env;
2566         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
2567         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
2568         CHECK(obj != NULL);
2569         int8_tArray arg = (*env)->CallObjectMethod(env, obj, j_calls->get_node_secret_meth);
2570         LDKSecretKey arg_ref;
2571         CHECK((*env)->GetArrayLength(env, arg) == 32);
2572         (*env)->GetByteArrayRegion(env, arg, 0, 32, arg_ref.bytes);
2573         return arg_ref;
2574 }
2575 LDKCVec_u8Z get_destination_script_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_destination_script_meth);
2582         LDKCVec_u8Z arg_ref;
2583         arg_ref.datalen = (*env)->GetArrayLength(env, arg);
2584         arg_ref.data = MALLOC(arg_ref.datalen, "LDKCVec_u8Z Bytes");
2585         (*env)->GetByteArrayRegion(env, arg, 0, arg_ref.datalen, arg_ref.data);
2586         return arg_ref;
2587 }
2588 LDKPublicKey get_shutdown_pubkey_jcall(const void* this_arg) {
2589         LDKKeysInterface_JCalls *j_calls = (LDKKeysInterface_JCalls*) this_arg;
2590         JNIEnv *env;
2591         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
2592         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
2593         CHECK(obj != NULL);
2594         int8_tArray arg = (*env)->CallObjectMethod(env, obj, j_calls->get_shutdown_pubkey_meth);
2595         LDKPublicKey arg_ref;
2596         CHECK((*env)->GetArrayLength(env, arg) == 33);
2597         (*env)->GetByteArrayRegion(env, arg, 0, 33, arg_ref.compressed_form);
2598         return arg_ref;
2599 }
2600 LDKChannelKeys get_channel_keys_jcall(const void* this_arg, bool inbound, uint64_t channel_value_satoshis) {
2601         LDKKeysInterface_JCalls *j_calls = (LDKKeysInterface_JCalls*) this_arg;
2602         JNIEnv *env;
2603         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
2604         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
2605         CHECK(obj != NULL);
2606         LDKChannelKeys* ret = (LDKChannelKeys*)(*env)->CallLongMethod(env, obj, j_calls->get_channel_keys_meth, inbound, channel_value_satoshis);
2607         LDKChannelKeys ret_conv = *(LDKChannelKeys*)ret;
2608         ret_conv = ChannelKeys_clone(ret);
2609         return ret_conv;
2610 }
2611 LDKThirtyTwoBytes get_secure_random_bytes_jcall(const void* this_arg) {
2612         LDKKeysInterface_JCalls *j_calls = (LDKKeysInterface_JCalls*) this_arg;
2613         JNIEnv *env;
2614         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
2615         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
2616         CHECK(obj != NULL);
2617         int8_tArray arg = (*env)->CallObjectMethod(env, obj, j_calls->get_secure_random_bytes_meth);
2618         LDKThirtyTwoBytes arg_ref;
2619         CHECK((*env)->GetArrayLength(env, arg) == 32);
2620         (*env)->GetByteArrayRegion(env, arg, 0, 32, arg_ref.data);
2621         return arg_ref;
2622 }
2623 LDKCResult_ChanKeySignerDecodeErrorZ read_chan_signer_jcall(const void* this_arg, LDKu8slice reader) {
2624         LDKKeysInterface_JCalls *j_calls = (LDKKeysInterface_JCalls*) this_arg;
2625         JNIEnv *env;
2626         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
2627         LDKu8slice reader_var = reader;
2628         int8_tArray reader_arr = (*env)->NewByteArray(env, reader_var.datalen);
2629         (*env)->SetByteArrayRegion(env, reader_arr, 0, reader_var.datalen, reader_var.data);
2630         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
2631         CHECK(obj != NULL);
2632         LDKCResult_ChanKeySignerDecodeErrorZ* ret = (LDKCResult_ChanKeySignerDecodeErrorZ*)(*env)->CallLongMethod(env, obj, j_calls->read_chan_signer_meth, reader_arr);
2633         LDKCResult_ChanKeySignerDecodeErrorZ ret_conv = *(LDKCResult_ChanKeySignerDecodeErrorZ*)ret;
2634         FREE((void*)ret);
2635         return ret_conv;
2636 }
2637 static void* LDKKeysInterface_JCalls_clone(const void* this_arg) {
2638         LDKKeysInterface_JCalls *j_calls = (LDKKeysInterface_JCalls*) this_arg;
2639         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
2640         return (void*) this_arg;
2641 }
2642 static inline LDKKeysInterface LDKKeysInterface_init (JNIEnv *env, jclass clz, jobject o) {
2643         jclass c = (*env)->GetObjectClass(env, o);
2644         CHECK(c != NULL);
2645         LDKKeysInterface_JCalls *calls = MALLOC(sizeof(LDKKeysInterface_JCalls), "LDKKeysInterface_JCalls");
2646         atomic_init(&calls->refcnt, 1);
2647         DO_ASSERT((*env)->GetJavaVM(env, &calls->vm) == 0);
2648         calls->o = (*env)->NewWeakGlobalRef(env, o);
2649         calls->get_node_secret_meth = (*env)->GetMethodID(env, c, "get_node_secret", "()[B");
2650         CHECK(calls->get_node_secret_meth != NULL);
2651         calls->get_destination_script_meth = (*env)->GetMethodID(env, c, "get_destination_script", "()[B");
2652         CHECK(calls->get_destination_script_meth != NULL);
2653         calls->get_shutdown_pubkey_meth = (*env)->GetMethodID(env, c, "get_shutdown_pubkey", "()[B");
2654         CHECK(calls->get_shutdown_pubkey_meth != NULL);
2655         calls->get_channel_keys_meth = (*env)->GetMethodID(env, c, "get_channel_keys", "(ZJ)J");
2656         CHECK(calls->get_channel_keys_meth != NULL);
2657         calls->get_secure_random_bytes_meth = (*env)->GetMethodID(env, c, "get_secure_random_bytes", "()[B");
2658         CHECK(calls->get_secure_random_bytes_meth != NULL);
2659         calls->read_chan_signer_meth = (*env)->GetMethodID(env, c, "read_chan_signer", "([B)J");
2660         CHECK(calls->read_chan_signer_meth != NULL);
2661
2662         LDKKeysInterface ret = {
2663                 .this_arg = (void*) calls,
2664                 .get_node_secret = get_node_secret_jcall,
2665                 .get_destination_script = get_destination_script_jcall,
2666                 .get_shutdown_pubkey = get_shutdown_pubkey_jcall,
2667                 .get_channel_keys = get_channel_keys_jcall,
2668                 .get_secure_random_bytes = get_secure_random_bytes_jcall,
2669                 .read_chan_signer = read_chan_signer_jcall,
2670                 .free = LDKKeysInterface_JCalls_free,
2671         };
2672         return ret;
2673 }
2674 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_LDKKeysInterface_1new (JNIEnv *env, jclass clz, jobject o) {
2675         LDKKeysInterface *res_ptr = MALLOC(sizeof(LDKKeysInterface), "LDKKeysInterface");
2676         *res_ptr = LDKKeysInterface_init(env, clz, o);
2677         return (long)res_ptr;
2678 }
2679 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKKeysInterface_1get_1obj_1from_1jcalls (JNIEnv *env, jclass clz, int64_t val) {
2680         jobject ret = (*env)->NewLocalRef(env, ((LDKKeysInterface_JCalls*)val)->o);
2681         CHECK(ret != NULL);
2682         return ret;
2683 }
2684 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_KeysInterface_1get_1node_1secret(JNIEnv *env, jclass clz, int64_t this_arg) {
2685         LDKKeysInterface* this_arg_conv = (LDKKeysInterface*)this_arg;
2686         int8_tArray arg_arr = (*env)->NewByteArray(env, 32);
2687         (*env)->SetByteArrayRegion(env, arg_arr, 0, 32, (this_arg_conv->get_node_secret)(this_arg_conv->this_arg).bytes);
2688         return arg_arr;
2689 }
2690
2691 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_KeysInterface_1get_1destination_1script(JNIEnv *env, jclass clz, int64_t this_arg) {
2692         LDKKeysInterface* this_arg_conv = (LDKKeysInterface*)this_arg;
2693         LDKCVec_u8Z arg_var = (this_arg_conv->get_destination_script)(this_arg_conv->this_arg);
2694         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
2695         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
2696         CVec_u8Z_free(arg_var);
2697         return arg_arr;
2698 }
2699
2700 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_KeysInterface_1get_1shutdown_1pubkey(JNIEnv *env, jclass clz, int64_t this_arg) {
2701         LDKKeysInterface* this_arg_conv = (LDKKeysInterface*)this_arg;
2702         int8_tArray arg_arr = (*env)->NewByteArray(env, 33);
2703         (*env)->SetByteArrayRegion(env, arg_arr, 0, 33, (this_arg_conv->get_shutdown_pubkey)(this_arg_conv->this_arg).compressed_form);
2704         return arg_arr;
2705 }
2706
2707 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) {
2708         LDKKeysInterface* this_arg_conv = (LDKKeysInterface*)this_arg;
2709         LDKChannelKeys* ret = MALLOC(sizeof(LDKChannelKeys), "LDKChannelKeys");
2710         *ret = (this_arg_conv->get_channel_keys)(this_arg_conv->this_arg, inbound, channel_value_satoshis);
2711         return (long)ret;
2712 }
2713
2714 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_KeysInterface_1get_1secure_1random_1bytes(JNIEnv *env, jclass clz, int64_t this_arg) {
2715         LDKKeysInterface* this_arg_conv = (LDKKeysInterface*)this_arg;
2716         int8_tArray arg_arr = (*env)->NewByteArray(env, 32);
2717         (*env)->SetByteArrayRegion(env, arg_arr, 0, 32, (this_arg_conv->get_secure_random_bytes)(this_arg_conv->this_arg).data);
2718         return arg_arr;
2719 }
2720
2721 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_KeysInterface_1read_1chan_1signer(JNIEnv *env, jclass clz, int64_t this_arg, int8_tArray reader) {
2722         LDKKeysInterface* this_arg_conv = (LDKKeysInterface*)this_arg;
2723         LDKu8slice reader_ref;
2724         reader_ref.datalen = (*env)->GetArrayLength(env, reader);
2725         reader_ref.data = (*env)->GetByteArrayElements (env, reader, NULL);
2726         LDKCResult_ChanKeySignerDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ChanKeySignerDecodeErrorZ), "LDKCResult_ChanKeySignerDecodeErrorZ");
2727         *ret_conv = (this_arg_conv->read_chan_signer)(this_arg_conv->this_arg, reader_ref);
2728         (*env)->ReleaseByteArrayElements(env, reader, (int8_t*)reader_ref.data, 0);
2729         return (long)ret_conv;
2730 }
2731
2732 typedef struct LDKFeeEstimator_JCalls {
2733         atomic_size_t refcnt;
2734         JavaVM *vm;
2735         jweak o;
2736         jmethodID get_est_sat_per_1000_weight_meth;
2737 } LDKFeeEstimator_JCalls;
2738 static void LDKFeeEstimator_JCalls_free(void* this_arg) {
2739         LDKFeeEstimator_JCalls *j_calls = (LDKFeeEstimator_JCalls*) this_arg;
2740         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
2741                 JNIEnv *env;
2742                 DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
2743                 (*env)->DeleteWeakGlobalRef(env, j_calls->o);
2744                 FREE(j_calls);
2745         }
2746 }
2747 uint32_t get_est_sat_per_1000_weight_jcall(const void* this_arg, LDKConfirmationTarget confirmation_target) {
2748         LDKFeeEstimator_JCalls *j_calls = (LDKFeeEstimator_JCalls*) this_arg;
2749         JNIEnv *env;
2750         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
2751         jclass confirmation_target_conv = LDKConfirmationTarget_to_java(env, confirmation_target);
2752         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
2753         CHECK(obj != NULL);
2754         return (*env)->CallIntMethod(env, obj, j_calls->get_est_sat_per_1000_weight_meth, confirmation_target_conv);
2755 }
2756 static void* LDKFeeEstimator_JCalls_clone(const void* this_arg) {
2757         LDKFeeEstimator_JCalls *j_calls = (LDKFeeEstimator_JCalls*) this_arg;
2758         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
2759         return (void*) this_arg;
2760 }
2761 static inline LDKFeeEstimator LDKFeeEstimator_init (JNIEnv *env, jclass clz, jobject o) {
2762         jclass c = (*env)->GetObjectClass(env, o);
2763         CHECK(c != NULL);
2764         LDKFeeEstimator_JCalls *calls = MALLOC(sizeof(LDKFeeEstimator_JCalls), "LDKFeeEstimator_JCalls");
2765         atomic_init(&calls->refcnt, 1);
2766         DO_ASSERT((*env)->GetJavaVM(env, &calls->vm) == 0);
2767         calls->o = (*env)->NewWeakGlobalRef(env, o);
2768         calls->get_est_sat_per_1000_weight_meth = (*env)->GetMethodID(env, c, "get_est_sat_per_1000_weight", "(Lorg/ldk/enums/LDKConfirmationTarget;)I");
2769         CHECK(calls->get_est_sat_per_1000_weight_meth != NULL);
2770
2771         LDKFeeEstimator ret = {
2772                 .this_arg = (void*) calls,
2773                 .get_est_sat_per_1000_weight = get_est_sat_per_1000_weight_jcall,
2774                 .free = LDKFeeEstimator_JCalls_free,
2775         };
2776         return ret;
2777 }
2778 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_LDKFeeEstimator_1new (JNIEnv *env, jclass clz, jobject o) {
2779         LDKFeeEstimator *res_ptr = MALLOC(sizeof(LDKFeeEstimator), "LDKFeeEstimator");
2780         *res_ptr = LDKFeeEstimator_init(env, clz, o);
2781         return (long)res_ptr;
2782 }
2783 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKFeeEstimator_1get_1obj_1from_1jcalls (JNIEnv *env, jclass clz, int64_t val) {
2784         jobject ret = (*env)->NewLocalRef(env, ((LDKFeeEstimator_JCalls*)val)->o);
2785         CHECK(ret != NULL);
2786         return ret;
2787 }
2788 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) {
2789         LDKFeeEstimator* this_arg_conv = (LDKFeeEstimator*)this_arg;
2790         LDKConfirmationTarget confirmation_target_conv = LDKConfirmationTarget_from_java(env, confirmation_target);
2791         int32_t ret_val = (this_arg_conv->get_est_sat_per_1000_weight)(this_arg_conv->this_arg, confirmation_target_conv);
2792         return ret_val;
2793 }
2794
2795 typedef struct LDKLogger_JCalls {
2796         atomic_size_t refcnt;
2797         JavaVM *vm;
2798         jweak o;
2799         jmethodID log_meth;
2800 } LDKLogger_JCalls;
2801 static void LDKLogger_JCalls_free(void* this_arg) {
2802         LDKLogger_JCalls *j_calls = (LDKLogger_JCalls*) this_arg;
2803         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
2804                 JNIEnv *env;
2805                 DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
2806                 (*env)->DeleteWeakGlobalRef(env, j_calls->o);
2807                 FREE(j_calls);
2808         }
2809 }
2810 void log_jcall(const void* this_arg, const char* record) {
2811         LDKLogger_JCalls *j_calls = (LDKLogger_JCalls*) this_arg;
2812         JNIEnv *env;
2813         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
2814         jstring record_conv = (*env)->NewStringUTF(env, record);
2815         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
2816         CHECK(obj != NULL);
2817         return (*env)->CallVoidMethod(env, obj, j_calls->log_meth, record_conv);
2818 }
2819 static void* LDKLogger_JCalls_clone(const void* this_arg) {
2820         LDKLogger_JCalls *j_calls = (LDKLogger_JCalls*) this_arg;
2821         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
2822         return (void*) this_arg;
2823 }
2824 static inline LDKLogger LDKLogger_init (JNIEnv *env, jclass clz, jobject o) {
2825         jclass c = (*env)->GetObjectClass(env, o);
2826         CHECK(c != NULL);
2827         LDKLogger_JCalls *calls = MALLOC(sizeof(LDKLogger_JCalls), "LDKLogger_JCalls");
2828         atomic_init(&calls->refcnt, 1);
2829         DO_ASSERT((*env)->GetJavaVM(env, &calls->vm) == 0);
2830         calls->o = (*env)->NewWeakGlobalRef(env, o);
2831         calls->log_meth = (*env)->GetMethodID(env, c, "log", "(Ljava/lang/String;)V");
2832         CHECK(calls->log_meth != NULL);
2833
2834         LDKLogger ret = {
2835                 .this_arg = (void*) calls,
2836                 .log = log_jcall,
2837                 .free = LDKLogger_JCalls_free,
2838         };
2839         return ret;
2840 }
2841 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_LDKLogger_1new (JNIEnv *env, jclass clz, jobject o) {
2842         LDKLogger *res_ptr = MALLOC(sizeof(LDKLogger), "LDKLogger");
2843         *res_ptr = LDKLogger_init(env, clz, o);
2844         return (long)res_ptr;
2845 }
2846 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKLogger_1get_1obj_1from_1jcalls (JNIEnv *env, jclass clz, int64_t val) {
2847         jobject ret = (*env)->NewLocalRef(env, ((LDKLogger_JCalls*)val)->o);
2848         CHECK(ret != NULL);
2849         return ret;
2850 }
2851 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKC2Tuple_1BlockHashChannelManagerZ_1new(JNIEnv *env, jclass clz, int8_tArray a, int64_t b) {
2852         LDKC2Tuple_BlockHashChannelManagerZ* ret = MALLOC(sizeof(LDKC2Tuple_BlockHashChannelManagerZ), "LDKC2Tuple_BlockHashChannelManagerZ");
2853         LDKThirtyTwoBytes a_ref;
2854         CHECK((*env)->GetArrayLength(env, a) == 32);
2855         (*env)->GetByteArrayRegion(env, a, 0, 32, a_ref.data);
2856         ret->a = a_ref;
2857         LDKChannelManager b_conv;
2858         b_conv.inner = (void*)(b & (~1));
2859         b_conv.is_owned = (b & 1) || (b == 0);
2860         // Warning: we may need a move here but can't clone!
2861         ret->b = b_conv;
2862         return (long)ret;
2863 }
2864 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_LDKC2Tuple_1BlockHashChannelManagerZ_1get_1a(JNIEnv *env, jclass clz, int64_t ptr) {
2865         LDKC2Tuple_BlockHashChannelManagerZ *tuple = (LDKC2Tuple_BlockHashChannelManagerZ*)ptr;
2866         int8_tArray a_arr = (*env)->NewByteArray(env, 32);
2867         (*env)->SetByteArrayRegion(env, a_arr, 0, 32, tuple->a.data);
2868         return a_arr;
2869 }
2870 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKC2Tuple_1BlockHashChannelManagerZ_1get_1b(JNIEnv *env, jclass clz, int64_t ptr) {
2871         LDKC2Tuple_BlockHashChannelManagerZ *tuple = (LDKC2Tuple_BlockHashChannelManagerZ*)ptr;
2872         LDKChannelManager b_var = tuple->b;
2873         CHECK((((long)b_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2874         CHECK((((long)&b_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2875         long b_ref = (long)b_var.inner & ~1;
2876         return b_ref;
2877 }
2878 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1C2Tuple_1BlockHashChannelManagerZDecodeErrorZ_1result_1ok (JNIEnv *env, jclass clz, int64_t arg) {
2879         return ((LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ*)arg)->result_ok;
2880 }
2881 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1C2Tuple_1BlockHashChannelManagerZDecodeErrorZ_1get_1ok (JNIEnv *env, jclass clz, int64_t arg) {
2882         LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ *val = (LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ*)arg;
2883         CHECK(val->result_ok);
2884         long res_ref = (long)&(*val->contents.result);
2885         return res_ref;
2886 }
2887 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1C2Tuple_1BlockHashChannelManagerZDecodeErrorZ_1get_1err (JNIEnv *env, jclass clz, int64_t arg) {
2888         LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ *val = (LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ*)arg;
2889         CHECK(!val->result_ok);
2890         LDKDecodeError err_var = (*val->contents.err);
2891         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2892         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2893         long err_ref = (long)err_var.inner & ~1;
2894         return err_ref;
2895 }
2896 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NetAddressu8Z_1result_1ok (JNIEnv *env, jclass clz, int64_t arg) {
2897         return ((LDKCResult_NetAddressu8Z*)arg)->result_ok;
2898 }
2899 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NetAddressu8Z_1get_1ok (JNIEnv *env, jclass clz, int64_t arg) {
2900         LDKCResult_NetAddressu8Z *val = (LDKCResult_NetAddressu8Z*)arg;
2901         CHECK(val->result_ok);
2902         long res_ref = (long)&(*val->contents.result);
2903         return res_ref;
2904 }
2905 JNIEXPORT int8_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NetAddressu8Z_1get_1err (JNIEnv *env, jclass clz, int64_t arg) {
2906         LDKCResult_NetAddressu8Z *val = (LDKCResult_NetAddressu8Z*)arg;
2907         CHECK(!val->result_ok);
2908         return *val->contents.err;
2909 }
2910 static inline LDKCResult_NetAddressu8Z CResult_NetAddressu8Z_clone(const LDKCResult_NetAddressu8Z *orig) {
2911         LDKCResult_NetAddressu8Z res = { .result_ok = orig->result_ok };
2912         if (orig->result_ok) {
2913                 LDKNetAddress* contents = MALLOC(sizeof(LDKNetAddress), "LDKNetAddress result OK clone");
2914                 *contents = NetAddress_clone(orig->contents.result);
2915                 res.contents.result = contents;
2916         } else {
2917                 int8_t* contents = MALLOC(sizeof(int8_t), "int8_t result Err clone");
2918                 *contents = *orig->contents.err;
2919                 res.contents.err = contents;
2920         }
2921         return res;
2922 }
2923 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1CResult_1NetAddressu8ZDecodeErrorZ_1result_1ok (JNIEnv *env, jclass clz, int64_t arg) {
2924         return ((LDKCResult_CResult_NetAddressu8ZDecodeErrorZ*)arg)->result_ok;
2925 }
2926 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1CResult_1NetAddressu8ZDecodeErrorZ_1get_1ok (JNIEnv *env, jclass clz, int64_t arg) {
2927         LDKCResult_CResult_NetAddressu8ZDecodeErrorZ *val = (LDKCResult_CResult_NetAddressu8ZDecodeErrorZ*)arg;
2928         CHECK(val->result_ok);
2929         LDKCResult_NetAddressu8Z* res_conv = MALLOC(sizeof(LDKCResult_NetAddressu8Z), "LDKCResult_NetAddressu8Z");
2930         *res_conv = (*val->contents.result);
2931         *res_conv = CResult_NetAddressu8Z_clone(res_conv);
2932         return (long)res_conv;
2933 }
2934 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1CResult_1NetAddressu8ZDecodeErrorZ_1get_1err (JNIEnv *env, jclass clz, int64_t arg) {
2935         LDKCResult_CResult_NetAddressu8ZDecodeErrorZ *val = (LDKCResult_CResult_NetAddressu8ZDecodeErrorZ*)arg;
2936         CHECK(!val->result_ok);
2937         LDKDecodeError err_var = (*val->contents.err);
2938         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2939         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2940         long err_ref = (long)err_var.inner & ~1;
2941         return err_ref;
2942 }
2943 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCVec_1u64Z_1new(JNIEnv *env, jclass clz, int64_tArray elems) {
2944         LDKCVec_u64Z *ret = MALLOC(sizeof(LDKCVec_u64Z), "LDKCVec_u64Z");
2945         ret->datalen = (*env)->GetArrayLength(env, elems);
2946         if (ret->datalen == 0) {
2947                 ret->data = NULL;
2948         } else {
2949                 ret->data = MALLOC(sizeof(uint64_t) * ret->datalen, "LDKCVec_u64Z Data");
2950                 int64_t *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
2951                 for (size_t i = 0; i < ret->datalen; i++) {
2952                         ret->data[i] = java_elems[i];
2953                 }
2954                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
2955         }
2956         return (long)ret;
2957 }
2958 static inline LDKCVec_u64Z CVec_u64Z_clone(const LDKCVec_u64Z *orig) {
2959         LDKCVec_u64Z ret = { .data = MALLOC(sizeof(int64_t) * orig->datalen, "LDKCVec_u64Z clone bytes"), .datalen = orig->datalen };
2960         memcpy(ret.data, orig->data, sizeof(int64_t) * ret.datalen);
2961         return ret;
2962 }
2963 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCVec_1UpdateAddHTLCZ_1new(JNIEnv *env, jclass clz, int64_tArray elems) {
2964         LDKCVec_UpdateAddHTLCZ *ret = MALLOC(sizeof(LDKCVec_UpdateAddHTLCZ), "LDKCVec_UpdateAddHTLCZ");
2965         ret->datalen = (*env)->GetArrayLength(env, elems);
2966         if (ret->datalen == 0) {
2967                 ret->data = NULL;
2968         } else {
2969                 ret->data = MALLOC(sizeof(LDKUpdateAddHTLC) * ret->datalen, "LDKCVec_UpdateAddHTLCZ 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                         LDKUpdateAddHTLC 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 = UpdateAddHTLC_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_UpdateAddHTLCZ CVec_UpdateAddHTLCZ_clone(const LDKCVec_UpdateAddHTLCZ *orig) {
2985         LDKCVec_UpdateAddHTLCZ ret = { .data = MALLOC(sizeof(LDKUpdateAddHTLC) * orig->datalen, "LDKCVec_UpdateAddHTLCZ clone bytes"), .datalen = orig->datalen };
2986         for (size_t i = 0; i < ret.datalen; i++) {
2987                 ret.data[i] = UpdateAddHTLC_clone(&orig->data[i]);
2988         }
2989         return ret;
2990 }
2991 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCVec_1UpdateFulfillHTLCZ_1new(JNIEnv *env, jclass clz, int64_tArray elems) {
2992         LDKCVec_UpdateFulfillHTLCZ *ret = MALLOC(sizeof(LDKCVec_UpdateFulfillHTLCZ), "LDKCVec_UpdateFulfillHTLCZ");
2993         ret->datalen = (*env)->GetArrayLength(env, elems);
2994         if (ret->datalen == 0) {
2995                 ret->data = NULL;
2996         } else {
2997                 ret->data = MALLOC(sizeof(LDKUpdateFulfillHTLC) * ret->datalen, "LDKCVec_UpdateFulfillHTLCZ 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                         LDKUpdateFulfillHTLC 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 = UpdateFulfillHTLC_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_UpdateFulfillHTLCZ CVec_UpdateFulfillHTLCZ_clone(const LDKCVec_UpdateFulfillHTLCZ *orig) {
3013         LDKCVec_UpdateFulfillHTLCZ ret = { .data = MALLOC(sizeof(LDKUpdateFulfillHTLC) * orig->datalen, "LDKCVec_UpdateFulfillHTLCZ clone bytes"), .datalen = orig->datalen };
3014         for (size_t i = 0; i < ret.datalen; i++) {
3015                 ret.data[i] = UpdateFulfillHTLC_clone(&orig->data[i]);
3016         }
3017         return ret;
3018 }
3019 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCVec_1UpdateFailHTLCZ_1new(JNIEnv *env, jclass clz, int64_tArray elems) {
3020         LDKCVec_UpdateFailHTLCZ *ret = MALLOC(sizeof(LDKCVec_UpdateFailHTLCZ), "LDKCVec_UpdateFailHTLCZ");
3021         ret->datalen = (*env)->GetArrayLength(env, elems);
3022         if (ret->datalen == 0) {
3023                 ret->data = NULL;
3024         } else {
3025                 ret->data = MALLOC(sizeof(LDKUpdateFailHTLC) * ret->datalen, "LDKCVec_UpdateFailHTLCZ 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                         LDKUpdateFailHTLC 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 = UpdateFailHTLC_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_UpdateFailHTLCZ CVec_UpdateFailHTLCZ_clone(const LDKCVec_UpdateFailHTLCZ *orig) {
3041         LDKCVec_UpdateFailHTLCZ ret = { .data = MALLOC(sizeof(LDKUpdateFailHTLC) * orig->datalen, "LDKCVec_UpdateFailHTLCZ clone bytes"), .datalen = orig->datalen };
3042         for (size_t i = 0; i < ret.datalen; i++) {
3043                 ret.data[i] = UpdateFailHTLC_clone(&orig->data[i]);
3044         }
3045         return ret;
3046 }
3047 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCVec_1UpdateFailMalformedHTLCZ_1new(JNIEnv *env, jclass clz, int64_tArray elems) {
3048         LDKCVec_UpdateFailMalformedHTLCZ *ret = MALLOC(sizeof(LDKCVec_UpdateFailMalformedHTLCZ), "LDKCVec_UpdateFailMalformedHTLCZ");
3049         ret->datalen = (*env)->GetArrayLength(env, elems);
3050         if (ret->datalen == 0) {
3051                 ret->data = NULL;
3052         } else {
3053                 ret->data = MALLOC(sizeof(LDKUpdateFailMalformedHTLC) * ret->datalen, "LDKCVec_UpdateFailMalformedHTLCZ Data");
3054                 int64_t *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
3055                 for (size_t i = 0; i < ret->datalen; i++) {
3056                         int64_t arr_elem = java_elems[i];
3057                         LDKUpdateFailMalformedHTLC arr_elem_conv;
3058                         arr_elem_conv.inner = (void*)(arr_elem & (~1));
3059                         arr_elem_conv.is_owned = (arr_elem & 1) || (arr_elem == 0);
3060                         if (arr_elem_conv.inner != NULL)
3061                                 arr_elem_conv = UpdateFailMalformedHTLC_clone(&arr_elem_conv);
3062                         ret->data[i] = arr_elem_conv;
3063                 }
3064                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
3065         }
3066         return (long)ret;
3067 }
3068 static inline LDKCVec_UpdateFailMalformedHTLCZ CVec_UpdateFailMalformedHTLCZ_clone(const LDKCVec_UpdateFailMalformedHTLCZ *orig) {
3069         LDKCVec_UpdateFailMalformedHTLCZ ret = { .data = MALLOC(sizeof(LDKUpdateFailMalformedHTLC) * orig->datalen, "LDKCVec_UpdateFailMalformedHTLCZ clone bytes"), .datalen = orig->datalen };
3070         for (size_t i = 0; i < ret.datalen; i++) {
3071                 ret.data[i] = UpdateFailMalformedHTLC_clone(&orig->data[i]);
3072         }
3073         return ret;
3074 }
3075 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1boolLightningErrorZ_1result_1ok (JNIEnv *env, jclass clz, int64_t arg) {
3076         return ((LDKCResult_boolLightningErrorZ*)arg)->result_ok;
3077 }
3078 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1boolLightningErrorZ_1get_1ok (JNIEnv *env, jclass clz, int64_t arg) {
3079         LDKCResult_boolLightningErrorZ *val = (LDKCResult_boolLightningErrorZ*)arg;
3080         CHECK(val->result_ok);
3081         return *val->contents.result;
3082 }
3083 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1boolLightningErrorZ_1get_1err (JNIEnv *env, jclass clz, int64_t arg) {
3084         LDKCResult_boolLightningErrorZ *val = (LDKCResult_boolLightningErrorZ*)arg;
3085         CHECK(!val->result_ok);
3086         LDKLightningError err_var = (*val->contents.err);
3087         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3088         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3089         long err_ref = (long)err_var.inner & ~1;
3090         return err_ref;
3091 }
3092 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) {
3093         LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ* ret = MALLOC(sizeof(LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ), "LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ");
3094         LDKChannelAnnouncement a_conv;
3095         a_conv.inner = (void*)(a & (~1));
3096         a_conv.is_owned = (a & 1) || (a == 0);
3097         if (a_conv.inner != NULL)
3098                 a_conv = ChannelAnnouncement_clone(&a_conv);
3099         ret->a = a_conv;
3100         LDKChannelUpdate b_conv;
3101         b_conv.inner = (void*)(b & (~1));
3102         b_conv.is_owned = (b & 1) || (b == 0);
3103         if (b_conv.inner != NULL)
3104                 b_conv = ChannelUpdate_clone(&b_conv);
3105         ret->b = b_conv;
3106         LDKChannelUpdate c_conv;
3107         c_conv.inner = (void*)(c & (~1));
3108         c_conv.is_owned = (c & 1) || (c == 0);
3109         if (c_conv.inner != NULL)
3110                 c_conv = ChannelUpdate_clone(&c_conv);
3111         ret->c = c_conv;
3112         return (long)ret;
3113 }
3114 static inline LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ_clone(const LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ *orig) {
3115         LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ ret = {
3116                 .a = ChannelAnnouncement_clone(&orig->a),
3117                 .b = ChannelUpdate_clone(&orig->b),
3118                 .c = ChannelUpdate_clone(&orig->c),
3119         };
3120         return ret;
3121 }
3122 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKC3Tuple_1ChannelAnnouncementChannelUpdateChannelUpdateZ_1get_1a(JNIEnv *env, jclass clz, int64_t ptr) {
3123         LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ *tuple = (LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ*)ptr;
3124         LDKChannelAnnouncement a_var = tuple->a;
3125         CHECK((((long)a_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3126         CHECK((((long)&a_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3127         long a_ref = (long)a_var.inner & ~1;
3128         return a_ref;
3129 }
3130 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKC3Tuple_1ChannelAnnouncementChannelUpdateChannelUpdateZ_1get_1b(JNIEnv *env, jclass clz, int64_t ptr) {
3131         LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ *tuple = (LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ*)ptr;
3132         LDKChannelUpdate b_var = tuple->b;
3133         CHECK((((long)b_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3134         CHECK((((long)&b_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3135         long b_ref = (long)b_var.inner & ~1;
3136         return b_ref;
3137 }
3138 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKC3Tuple_1ChannelAnnouncementChannelUpdateChannelUpdateZ_1get_1c(JNIEnv *env, jclass clz, int64_t ptr) {
3139         LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ *tuple = (LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ*)ptr;
3140         LDKChannelUpdate c_var = tuple->c;
3141         CHECK((((long)c_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3142         CHECK((((long)&c_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3143         long c_ref = (long)c_var.inner & ~1;
3144         return c_ref;
3145 }
3146 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCVec_1C3Tuple_1ChannelAnnouncementChannelUpdateChannelUpdateZZ_1new(JNIEnv *env, jclass clz, int64_tArray elems) {
3147         LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ *ret = MALLOC(sizeof(LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ), "LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ");
3148         ret->datalen = (*env)->GetArrayLength(env, elems);
3149         if (ret->datalen == 0) {
3150                 ret->data = NULL;
3151         } else {
3152                 ret->data = MALLOC(sizeof(LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ) * ret->datalen, "LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ Data");
3153                 int64_t *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
3154                 for (size_t i = 0; i < ret->datalen; i++) {
3155                         int64_t arr_elem = java_elems[i];
3156                         LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ arr_elem_conv = *(LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ*)arr_elem;
3157                         FREE((void*)arr_elem);
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_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ CVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ_clone(const LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ *orig) {
3165         LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ ret = { .data = MALLOC(sizeof(LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ) * orig->datalen, "LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ clone bytes"), .datalen = orig->datalen };
3166         for (size_t i = 0; i < ret.datalen; i++) {
3167                 ret.data[i] = C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ_clone(&orig->data[i]);
3168         }
3169         return ret;
3170 }
3171 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCVec_1NodeAnnouncementZ_1new(JNIEnv *env, jclass clz, int64_tArray elems) {
3172         LDKCVec_NodeAnnouncementZ *ret = MALLOC(sizeof(LDKCVec_NodeAnnouncementZ), "LDKCVec_NodeAnnouncementZ");
3173         ret->datalen = (*env)->GetArrayLength(env, elems);
3174         if (ret->datalen == 0) {
3175                 ret->data = NULL;
3176         } else {
3177                 ret->data = MALLOC(sizeof(LDKNodeAnnouncement) * ret->datalen, "LDKCVec_NodeAnnouncementZ Data");
3178                 int64_t *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
3179                 for (size_t i = 0; i < ret->datalen; i++) {
3180                         int64_t arr_elem = java_elems[i];
3181                         LDKNodeAnnouncement arr_elem_conv;
3182                         arr_elem_conv.inner = (void*)(arr_elem & (~1));
3183                         arr_elem_conv.is_owned = (arr_elem & 1) || (arr_elem == 0);
3184                         if (arr_elem_conv.inner != NULL)
3185                                 arr_elem_conv = NodeAnnouncement_clone(&arr_elem_conv);
3186                         ret->data[i] = arr_elem_conv;
3187                 }
3188                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
3189         }
3190         return (long)ret;
3191 }
3192 static inline LDKCVec_NodeAnnouncementZ CVec_NodeAnnouncementZ_clone(const LDKCVec_NodeAnnouncementZ *orig) {
3193         LDKCVec_NodeAnnouncementZ ret = { .data = MALLOC(sizeof(LDKNodeAnnouncement) * orig->datalen, "LDKCVec_NodeAnnouncementZ clone bytes"), .datalen = orig->datalen };
3194         for (size_t i = 0; i < ret.datalen; i++) {
3195                 ret.data[i] = NodeAnnouncement_clone(&orig->data[i]);
3196         }
3197         return ret;
3198 }
3199 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NoneLightningErrorZ_1result_1ok (JNIEnv *env, jclass clz, int64_t arg) {
3200         return ((LDKCResult_NoneLightningErrorZ*)arg)->result_ok;
3201 }
3202 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NoneLightningErrorZ_1get_1ok (JNIEnv *env, jclass clz, int64_t arg) {
3203         LDKCResult_NoneLightningErrorZ *val = (LDKCResult_NoneLightningErrorZ*)arg;
3204         CHECK(val->result_ok);
3205         return *val->contents.result;
3206 }
3207 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NoneLightningErrorZ_1get_1err (JNIEnv *env, jclass clz, int64_t arg) {
3208         LDKCResult_NoneLightningErrorZ *val = (LDKCResult_NoneLightningErrorZ*)arg;
3209         CHECK(!val->result_ok);
3210         LDKLightningError err_var = (*val->contents.err);
3211         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3212         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3213         long err_ref = (long)err_var.inner & ~1;
3214         return err_ref;
3215 }
3216 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1ChannelReestablishDecodeErrorZ_1result_1ok (JNIEnv *env, jclass clz, int64_t arg) {
3217         return ((LDKCResult_ChannelReestablishDecodeErrorZ*)arg)->result_ok;
3218 }
3219 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1ChannelReestablishDecodeErrorZ_1get_1ok (JNIEnv *env, jclass clz, int64_t arg) {
3220         LDKCResult_ChannelReestablishDecodeErrorZ *val = (LDKCResult_ChannelReestablishDecodeErrorZ*)arg;
3221         CHECK(val->result_ok);
3222         LDKChannelReestablish res_var = (*val->contents.result);
3223         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3224         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3225         long res_ref = (long)res_var.inner & ~1;
3226         return res_ref;
3227 }
3228 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1ChannelReestablishDecodeErrorZ_1get_1err (JNIEnv *env, jclass clz, int64_t arg) {
3229         LDKCResult_ChannelReestablishDecodeErrorZ *val = (LDKCResult_ChannelReestablishDecodeErrorZ*)arg;
3230         CHECK(!val->result_ok);
3231         LDKDecodeError err_var = (*val->contents.err);
3232         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3233         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3234         long err_ref = (long)err_var.inner & ~1;
3235         return err_ref;
3236 }
3237 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1InitDecodeErrorZ_1result_1ok (JNIEnv *env, jclass clz, int64_t arg) {
3238         return ((LDKCResult_InitDecodeErrorZ*)arg)->result_ok;
3239 }
3240 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1InitDecodeErrorZ_1get_1ok (JNIEnv *env, jclass clz, int64_t arg) {
3241         LDKCResult_InitDecodeErrorZ *val = (LDKCResult_InitDecodeErrorZ*)arg;
3242         CHECK(val->result_ok);
3243         LDKInit res_var = (*val->contents.result);
3244         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3245         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3246         long res_ref = (long)res_var.inner & ~1;
3247         return res_ref;
3248 }
3249 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1InitDecodeErrorZ_1get_1err (JNIEnv *env, jclass clz, int64_t arg) {
3250         LDKCResult_InitDecodeErrorZ *val = (LDKCResult_InitDecodeErrorZ*)arg;
3251         CHECK(!val->result_ok);
3252         LDKDecodeError err_var = (*val->contents.err);
3253         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3254         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3255         long err_ref = (long)err_var.inner & ~1;
3256         return err_ref;
3257 }
3258 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1PingDecodeErrorZ_1result_1ok (JNIEnv *env, jclass clz, int64_t arg) {
3259         return ((LDKCResult_PingDecodeErrorZ*)arg)->result_ok;
3260 }
3261 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1PingDecodeErrorZ_1get_1ok (JNIEnv *env, jclass clz, int64_t arg) {
3262         LDKCResult_PingDecodeErrorZ *val = (LDKCResult_PingDecodeErrorZ*)arg;
3263         CHECK(val->result_ok);
3264         LDKPing res_var = (*val->contents.result);
3265         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3266         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3267         long res_ref = (long)res_var.inner & ~1;
3268         return res_ref;
3269 }
3270 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1PingDecodeErrorZ_1get_1err (JNIEnv *env, jclass clz, int64_t arg) {
3271         LDKCResult_PingDecodeErrorZ *val = (LDKCResult_PingDecodeErrorZ*)arg;
3272         CHECK(!val->result_ok);
3273         LDKDecodeError err_var = (*val->contents.err);
3274         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3275         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3276         long err_ref = (long)err_var.inner & ~1;
3277         return err_ref;
3278 }
3279 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1PongDecodeErrorZ_1result_1ok (JNIEnv *env, jclass clz, int64_t arg) {
3280         return ((LDKCResult_PongDecodeErrorZ*)arg)->result_ok;
3281 }
3282 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1PongDecodeErrorZ_1get_1ok (JNIEnv *env, jclass clz, int64_t arg) {
3283         LDKCResult_PongDecodeErrorZ *val = (LDKCResult_PongDecodeErrorZ*)arg;
3284         CHECK(val->result_ok);
3285         LDKPong res_var = (*val->contents.result);
3286         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3287         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3288         long res_ref = (long)res_var.inner & ~1;
3289         return res_ref;
3290 }
3291 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1PongDecodeErrorZ_1get_1err (JNIEnv *env, jclass clz, int64_t arg) {
3292         LDKCResult_PongDecodeErrorZ *val = (LDKCResult_PongDecodeErrorZ*)arg;
3293         CHECK(!val->result_ok);
3294         LDKDecodeError err_var = (*val->contents.err);
3295         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3296         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3297         long err_ref = (long)err_var.inner & ~1;
3298         return err_ref;
3299 }
3300 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1UnsignedChannelAnnouncementDecodeErrorZ_1result_1ok (JNIEnv *env, jclass clz, int64_t arg) {
3301         return ((LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ*)arg)->result_ok;
3302 }
3303 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1UnsignedChannelAnnouncementDecodeErrorZ_1get_1ok (JNIEnv *env, jclass clz, int64_t arg) {
3304         LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ *val = (LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ*)arg;
3305         CHECK(val->result_ok);
3306         LDKUnsignedChannelAnnouncement res_var = (*val->contents.result);
3307         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3308         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3309         long res_ref = (long)res_var.inner & ~1;
3310         return res_ref;
3311 }
3312 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1UnsignedChannelAnnouncementDecodeErrorZ_1get_1err (JNIEnv *env, jclass clz, int64_t arg) {
3313         LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ *val = (LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ*)arg;
3314         CHECK(!val->result_ok);
3315         LDKDecodeError err_var = (*val->contents.err);
3316         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3317         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3318         long err_ref = (long)err_var.inner & ~1;
3319         return err_ref;
3320 }
3321 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1UnsignedChannelUpdateDecodeErrorZ_1result_1ok (JNIEnv *env, jclass clz, int64_t arg) {
3322         return ((LDKCResult_UnsignedChannelUpdateDecodeErrorZ*)arg)->result_ok;
3323 }
3324 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1UnsignedChannelUpdateDecodeErrorZ_1get_1ok (JNIEnv *env, jclass clz, int64_t arg) {
3325         LDKCResult_UnsignedChannelUpdateDecodeErrorZ *val = (LDKCResult_UnsignedChannelUpdateDecodeErrorZ*)arg;
3326         CHECK(val->result_ok);
3327         LDKUnsignedChannelUpdate res_var = (*val->contents.result);
3328         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3329         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3330         long res_ref = (long)res_var.inner & ~1;
3331         return res_ref;
3332 }
3333 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1UnsignedChannelUpdateDecodeErrorZ_1get_1err (JNIEnv *env, jclass clz, int64_t arg) {
3334         LDKCResult_UnsignedChannelUpdateDecodeErrorZ *val = (LDKCResult_UnsignedChannelUpdateDecodeErrorZ*)arg;
3335         CHECK(!val->result_ok);
3336         LDKDecodeError err_var = (*val->contents.err);
3337         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3338         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3339         long err_ref = (long)err_var.inner & ~1;
3340         return err_ref;
3341 }
3342 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1ErrorMessageDecodeErrorZ_1result_1ok (JNIEnv *env, jclass clz, int64_t arg) {
3343         return ((LDKCResult_ErrorMessageDecodeErrorZ*)arg)->result_ok;
3344 }
3345 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1ErrorMessageDecodeErrorZ_1get_1ok (JNIEnv *env, jclass clz, int64_t arg) {
3346         LDKCResult_ErrorMessageDecodeErrorZ *val = (LDKCResult_ErrorMessageDecodeErrorZ*)arg;
3347         CHECK(val->result_ok);
3348         LDKErrorMessage res_var = (*val->contents.result);
3349         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3350         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3351         long res_ref = (long)res_var.inner & ~1;
3352         return res_ref;
3353 }
3354 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1ErrorMessageDecodeErrorZ_1get_1err (JNIEnv *env, jclass clz, int64_t arg) {
3355         LDKCResult_ErrorMessageDecodeErrorZ *val = (LDKCResult_ErrorMessageDecodeErrorZ*)arg;
3356         CHECK(!val->result_ok);
3357         LDKDecodeError err_var = (*val->contents.err);
3358         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3359         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3360         long err_ref = (long)err_var.inner & ~1;
3361         return err_ref;
3362 }
3363 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1UnsignedNodeAnnouncementDecodeErrorZ_1result_1ok (JNIEnv *env, jclass clz, int64_t arg) {
3364         return ((LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ*)arg)->result_ok;
3365 }
3366 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1UnsignedNodeAnnouncementDecodeErrorZ_1get_1ok (JNIEnv *env, jclass clz, int64_t arg) {
3367         LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ *val = (LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ*)arg;
3368         CHECK(val->result_ok);
3369         LDKUnsignedNodeAnnouncement res_var = (*val->contents.result);
3370         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3371         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3372         long res_ref = (long)res_var.inner & ~1;
3373         return res_ref;
3374 }
3375 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1UnsignedNodeAnnouncementDecodeErrorZ_1get_1err (JNIEnv *env, jclass clz, int64_t arg) {
3376         LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ *val = (LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ*)arg;
3377         CHECK(!val->result_ok);
3378         LDKDecodeError err_var = (*val->contents.err);
3379         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3380         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3381         long err_ref = (long)err_var.inner & ~1;
3382         return err_ref;
3383 }
3384 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1QueryShortChannelIdsDecodeErrorZ_1result_1ok (JNIEnv *env, jclass clz, int64_t arg) {
3385         return ((LDKCResult_QueryShortChannelIdsDecodeErrorZ*)arg)->result_ok;
3386 }
3387 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1QueryShortChannelIdsDecodeErrorZ_1get_1ok (JNIEnv *env, jclass clz, int64_t arg) {
3388         LDKCResult_QueryShortChannelIdsDecodeErrorZ *val = (LDKCResult_QueryShortChannelIdsDecodeErrorZ*)arg;
3389         CHECK(val->result_ok);
3390         LDKQueryShortChannelIds res_var = (*val->contents.result);
3391         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3392         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3393         long res_ref = (long)res_var.inner & ~1;
3394         return res_ref;
3395 }
3396 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1QueryShortChannelIdsDecodeErrorZ_1get_1err (JNIEnv *env, jclass clz, int64_t arg) {
3397         LDKCResult_QueryShortChannelIdsDecodeErrorZ *val = (LDKCResult_QueryShortChannelIdsDecodeErrorZ*)arg;
3398         CHECK(!val->result_ok);
3399         LDKDecodeError err_var = (*val->contents.err);
3400         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3401         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3402         long err_ref = (long)err_var.inner & ~1;
3403         return err_ref;
3404 }
3405 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1ReplyShortChannelIdsEndDecodeErrorZ_1result_1ok (JNIEnv *env, jclass clz, int64_t arg) {
3406         return ((LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ*)arg)->result_ok;
3407 }
3408 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1ReplyShortChannelIdsEndDecodeErrorZ_1get_1ok (JNIEnv *env, jclass clz, int64_t arg) {
3409         LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ *val = (LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ*)arg;
3410         CHECK(val->result_ok);
3411         LDKReplyShortChannelIdsEnd res_var = (*val->contents.result);
3412         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3413         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3414         long res_ref = (long)res_var.inner & ~1;
3415         return res_ref;
3416 }
3417 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1ReplyShortChannelIdsEndDecodeErrorZ_1get_1err (JNIEnv *env, jclass clz, int64_t arg) {
3418         LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ *val = (LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ*)arg;
3419         CHECK(!val->result_ok);
3420         LDKDecodeError err_var = (*val->contents.err);
3421         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3422         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3423         long err_ref = (long)err_var.inner & ~1;
3424         return err_ref;
3425 }
3426 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1QueryChannelRangeDecodeErrorZ_1result_1ok (JNIEnv *env, jclass clz, int64_t arg) {
3427         return ((LDKCResult_QueryChannelRangeDecodeErrorZ*)arg)->result_ok;
3428 }
3429 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1QueryChannelRangeDecodeErrorZ_1get_1ok (JNIEnv *env, jclass clz, int64_t arg) {
3430         LDKCResult_QueryChannelRangeDecodeErrorZ *val = (LDKCResult_QueryChannelRangeDecodeErrorZ*)arg;
3431         CHECK(val->result_ok);
3432         LDKQueryChannelRange res_var = (*val->contents.result);
3433         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3434         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3435         long res_ref = (long)res_var.inner & ~1;
3436         return res_ref;
3437 }
3438 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1QueryChannelRangeDecodeErrorZ_1get_1err (JNIEnv *env, jclass clz, int64_t arg) {
3439         LDKCResult_QueryChannelRangeDecodeErrorZ *val = (LDKCResult_QueryChannelRangeDecodeErrorZ*)arg;
3440         CHECK(!val->result_ok);
3441         LDKDecodeError err_var = (*val->contents.err);
3442         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3443         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3444         long err_ref = (long)err_var.inner & ~1;
3445         return err_ref;
3446 }
3447 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1ReplyChannelRangeDecodeErrorZ_1result_1ok (JNIEnv *env, jclass clz, int64_t arg) {
3448         return ((LDKCResult_ReplyChannelRangeDecodeErrorZ*)arg)->result_ok;
3449 }
3450 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1ReplyChannelRangeDecodeErrorZ_1get_1ok (JNIEnv *env, jclass clz, int64_t arg) {
3451         LDKCResult_ReplyChannelRangeDecodeErrorZ *val = (LDKCResult_ReplyChannelRangeDecodeErrorZ*)arg;
3452         CHECK(val->result_ok);
3453         LDKReplyChannelRange res_var = (*val->contents.result);
3454         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3455         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3456         long res_ref = (long)res_var.inner & ~1;
3457         return res_ref;
3458 }
3459 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1ReplyChannelRangeDecodeErrorZ_1get_1err (JNIEnv *env, jclass clz, int64_t arg) {
3460         LDKCResult_ReplyChannelRangeDecodeErrorZ *val = (LDKCResult_ReplyChannelRangeDecodeErrorZ*)arg;
3461         CHECK(!val->result_ok);
3462         LDKDecodeError err_var = (*val->contents.err);
3463         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3464         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3465         long err_ref = (long)err_var.inner & ~1;
3466         return err_ref;
3467 }
3468 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1GossipTimestampFilterDecodeErrorZ_1result_1ok (JNIEnv *env, jclass clz, int64_t arg) {
3469         return ((LDKCResult_GossipTimestampFilterDecodeErrorZ*)arg)->result_ok;
3470 }
3471 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1GossipTimestampFilterDecodeErrorZ_1get_1ok (JNIEnv *env, jclass clz, int64_t arg) {
3472         LDKCResult_GossipTimestampFilterDecodeErrorZ *val = (LDKCResult_GossipTimestampFilterDecodeErrorZ*)arg;
3473         CHECK(val->result_ok);
3474         LDKGossipTimestampFilter res_var = (*val->contents.result);
3475         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3476         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3477         long res_ref = (long)res_var.inner & ~1;
3478         return res_ref;
3479 }
3480 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1GossipTimestampFilterDecodeErrorZ_1get_1err (JNIEnv *env, jclass clz, int64_t arg) {
3481         LDKCResult_GossipTimestampFilterDecodeErrorZ *val = (LDKCResult_GossipTimestampFilterDecodeErrorZ*)arg;
3482         CHECK(!val->result_ok);
3483         LDKDecodeError err_var = (*val->contents.err);
3484         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3485         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3486         long err_ref = (long)err_var.inner & ~1;
3487         return err_ref;
3488 }
3489 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1CVec_1u8ZPeerHandleErrorZ_1result_1ok (JNIEnv *env, jclass clz, int64_t arg) {
3490         return ((LDKCResult_CVec_u8ZPeerHandleErrorZ*)arg)->result_ok;
3491 }
3492 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_LDKCResult_1CVec_1u8ZPeerHandleErrorZ_1get_1ok (JNIEnv *env, jclass clz, int64_t arg) {
3493         LDKCResult_CVec_u8ZPeerHandleErrorZ *val = (LDKCResult_CVec_u8ZPeerHandleErrorZ*)arg;
3494         CHECK(val->result_ok);
3495         LDKCVec_u8Z res_var = (*val->contents.result);
3496         int8_tArray res_arr = (*env)->NewByteArray(env, res_var.datalen);
3497         (*env)->SetByteArrayRegion(env, res_arr, 0, res_var.datalen, res_var.data);
3498         return res_arr;
3499 }
3500 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1CVec_1u8ZPeerHandleErrorZ_1get_1err (JNIEnv *env, jclass clz, int64_t arg) {
3501         LDKCResult_CVec_u8ZPeerHandleErrorZ *val = (LDKCResult_CVec_u8ZPeerHandleErrorZ*)arg;
3502         CHECK(!val->result_ok);
3503         LDKPeerHandleError err_var = (*val->contents.err);
3504         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3505         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3506         long err_ref = (long)err_var.inner & ~1;
3507         return err_ref;
3508 }
3509 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NonePeerHandleErrorZ_1result_1ok (JNIEnv *env, jclass clz, int64_t arg) {
3510         return ((LDKCResult_NonePeerHandleErrorZ*)arg)->result_ok;
3511 }
3512 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NonePeerHandleErrorZ_1get_1ok (JNIEnv *env, jclass clz, int64_t arg) {
3513         LDKCResult_NonePeerHandleErrorZ *val = (LDKCResult_NonePeerHandleErrorZ*)arg;
3514         CHECK(val->result_ok);
3515         return *val->contents.result;
3516 }
3517 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NonePeerHandleErrorZ_1get_1err (JNIEnv *env, jclass clz, int64_t arg) {
3518         LDKCResult_NonePeerHandleErrorZ *val = (LDKCResult_NonePeerHandleErrorZ*)arg;
3519         CHECK(!val->result_ok);
3520         LDKPeerHandleError err_var = (*val->contents.err);
3521         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3522         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3523         long err_ref = (long)err_var.inner & ~1;
3524         return err_ref;
3525 }
3526 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1boolPeerHandleErrorZ_1result_1ok (JNIEnv *env, jclass clz, int64_t arg) {
3527         return ((LDKCResult_boolPeerHandleErrorZ*)arg)->result_ok;
3528 }
3529 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1boolPeerHandleErrorZ_1get_1ok (JNIEnv *env, jclass clz, int64_t arg) {
3530         LDKCResult_boolPeerHandleErrorZ *val = (LDKCResult_boolPeerHandleErrorZ*)arg;
3531         CHECK(val->result_ok);
3532         return *val->contents.result;
3533 }
3534 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1boolPeerHandleErrorZ_1get_1err (JNIEnv *env, jclass clz, int64_t arg) {
3535         LDKCResult_boolPeerHandleErrorZ *val = (LDKCResult_boolPeerHandleErrorZ*)arg;
3536         CHECK(!val->result_ok);
3537         LDKPeerHandleError err_var = (*val->contents.err);
3538         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3539         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3540         long err_ref = (long)err_var.inner & ~1;
3541         return err_ref;
3542 }
3543 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1SecretKeySecpErrorZ_1result_1ok (JNIEnv *env, jclass clz, int64_t arg) {
3544         return ((LDKCResult_SecretKeySecpErrorZ*)arg)->result_ok;
3545 }
3546 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_LDKCResult_1SecretKeySecpErrorZ_1get_1ok (JNIEnv *env, jclass clz, int64_t arg) {
3547         LDKCResult_SecretKeySecpErrorZ *val = (LDKCResult_SecretKeySecpErrorZ*)arg;
3548         CHECK(val->result_ok);
3549         int8_tArray res_arr = (*env)->NewByteArray(env, 32);
3550         (*env)->SetByteArrayRegion(env, res_arr, 0, 32, (*val->contents.result).bytes);
3551         return res_arr;
3552 }
3553 JNIEXPORT jclass JNICALL Java_org_ldk_impl_bindings_LDKCResult_1SecretKeySecpErrorZ_1get_1err (JNIEnv *env, jclass clz, int64_t arg) {
3554         LDKCResult_SecretKeySecpErrorZ *val = (LDKCResult_SecretKeySecpErrorZ*)arg;
3555         CHECK(!val->result_ok);
3556         jclass err_conv = LDKSecp256k1Error_to_java(env, (*val->contents.err));
3557         return err_conv;
3558 }
3559 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1PublicKeySecpErrorZ_1result_1ok (JNIEnv *env, jclass clz, int64_t arg) {
3560         return ((LDKCResult_PublicKeySecpErrorZ*)arg)->result_ok;
3561 }
3562 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_LDKCResult_1PublicKeySecpErrorZ_1get_1ok (JNIEnv *env, jclass clz, int64_t arg) {
3563         LDKCResult_PublicKeySecpErrorZ *val = (LDKCResult_PublicKeySecpErrorZ*)arg;
3564         CHECK(val->result_ok);
3565         int8_tArray res_arr = (*env)->NewByteArray(env, 33);
3566         (*env)->SetByteArrayRegion(env, res_arr, 0, 33, (*val->contents.result).compressed_form);
3567         return res_arr;
3568 }
3569 JNIEXPORT jclass JNICALL Java_org_ldk_impl_bindings_LDKCResult_1PublicKeySecpErrorZ_1get_1err (JNIEnv *env, jclass clz, int64_t arg) {
3570         LDKCResult_PublicKeySecpErrorZ *val = (LDKCResult_PublicKeySecpErrorZ*)arg;
3571         CHECK(!val->result_ok);
3572         jclass err_conv = LDKSecp256k1Error_to_java(env, (*val->contents.err));
3573         return err_conv;
3574 }
3575 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1TxCreationKeysSecpErrorZ_1result_1ok (JNIEnv *env, jclass clz, int64_t arg) {
3576         return ((LDKCResult_TxCreationKeysSecpErrorZ*)arg)->result_ok;
3577 }
3578 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1TxCreationKeysSecpErrorZ_1get_1ok (JNIEnv *env, jclass clz, int64_t arg) {
3579         LDKCResult_TxCreationKeysSecpErrorZ *val = (LDKCResult_TxCreationKeysSecpErrorZ*)arg;
3580         CHECK(val->result_ok);
3581         LDKTxCreationKeys res_var = (*val->contents.result);
3582         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3583         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3584         long res_ref = (long)res_var.inner & ~1;
3585         return res_ref;
3586 }
3587 JNIEXPORT jclass JNICALL Java_org_ldk_impl_bindings_LDKCResult_1TxCreationKeysSecpErrorZ_1get_1err (JNIEnv *env, jclass clz, int64_t arg) {
3588         LDKCResult_TxCreationKeysSecpErrorZ *val = (LDKCResult_TxCreationKeysSecpErrorZ*)arg;
3589         CHECK(!val->result_ok);
3590         jclass err_conv = LDKSecp256k1Error_to_java(env, (*val->contents.err));
3591         return err_conv;
3592 }
3593 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1TrustedCommitmentTransactionNoneZ_1result_1ok (JNIEnv *env, jclass clz, int64_t arg) {
3594         return ((LDKCResult_TrustedCommitmentTransactionNoneZ*)arg)->result_ok;
3595 }
3596 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1TrustedCommitmentTransactionNoneZ_1get_1ok (JNIEnv *env, jclass clz, int64_t arg) {
3597         LDKCResult_TrustedCommitmentTransactionNoneZ *val = (LDKCResult_TrustedCommitmentTransactionNoneZ*)arg;
3598         CHECK(val->result_ok);
3599         LDKTrustedCommitmentTransaction res_var = (*val->contents.result);
3600         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3601         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3602         long res_ref = (long)res_var.inner & ~1;
3603         return res_ref;
3604 }
3605 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_LDKCResult_1TrustedCommitmentTransactionNoneZ_1get_1err (JNIEnv *env, jclass clz, int64_t arg) {
3606         LDKCResult_TrustedCommitmentTransactionNoneZ *val = (LDKCResult_TrustedCommitmentTransactionNoneZ*)arg;
3607         CHECK(!val->result_ok);
3608         return *val->contents.err;
3609 }
3610 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCVec_1RouteHopZ_1new(JNIEnv *env, jclass clz, int64_tArray elems) {
3611         LDKCVec_RouteHopZ *ret = MALLOC(sizeof(LDKCVec_RouteHopZ), "LDKCVec_RouteHopZ");
3612         ret->datalen = (*env)->GetArrayLength(env, elems);
3613         if (ret->datalen == 0) {
3614                 ret->data = NULL;
3615         } else {
3616                 ret->data = MALLOC(sizeof(LDKRouteHop) * ret->datalen, "LDKCVec_RouteHopZ Data");
3617                 int64_t *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
3618                 for (size_t i = 0; i < ret->datalen; i++) {
3619                         int64_t arr_elem = java_elems[i];
3620                         LDKRouteHop arr_elem_conv;
3621                         arr_elem_conv.inner = (void*)(arr_elem & (~1));
3622                         arr_elem_conv.is_owned = (arr_elem & 1) || (arr_elem == 0);
3623                         if (arr_elem_conv.inner != NULL)
3624                                 arr_elem_conv = RouteHop_clone(&arr_elem_conv);
3625                         ret->data[i] = arr_elem_conv;
3626                 }
3627                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
3628         }
3629         return (long)ret;
3630 }
3631 static inline LDKCVec_RouteHopZ CVec_RouteHopZ_clone(const LDKCVec_RouteHopZ *orig) {
3632         LDKCVec_RouteHopZ ret = { .data = MALLOC(sizeof(LDKRouteHop) * orig->datalen, "LDKCVec_RouteHopZ clone bytes"), .datalen = orig->datalen };
3633         for (size_t i = 0; i < ret.datalen; i++) {
3634                 ret.data[i] = RouteHop_clone(&orig->data[i]);
3635         }
3636         return ret;
3637 }
3638 static inline LDKCVec_CVec_RouteHopZZ CVec_CVec_RouteHopZZ_clone(const LDKCVec_CVec_RouteHopZZ *orig) {
3639         LDKCVec_CVec_RouteHopZZ ret = { .data = MALLOC(sizeof(LDKCVec_RouteHopZ) * orig->datalen, "LDKCVec_CVec_RouteHopZZ clone bytes"), .datalen = orig->datalen };
3640         for (size_t i = 0; i < ret.datalen; i++) {
3641                 ret.data[i] = CVec_RouteHopZ_clone(&orig->data[i]);
3642         }
3643         return ret;
3644 }
3645 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1RouteDecodeErrorZ_1result_1ok (JNIEnv *env, jclass clz, int64_t arg) {
3646         return ((LDKCResult_RouteDecodeErrorZ*)arg)->result_ok;
3647 }
3648 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1RouteDecodeErrorZ_1get_1ok (JNIEnv *env, jclass clz, int64_t arg) {
3649         LDKCResult_RouteDecodeErrorZ *val = (LDKCResult_RouteDecodeErrorZ*)arg;
3650         CHECK(val->result_ok);
3651         LDKRoute res_var = (*val->contents.result);
3652         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3653         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3654         long res_ref = (long)res_var.inner & ~1;
3655         return res_ref;
3656 }
3657 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1RouteDecodeErrorZ_1get_1err (JNIEnv *env, jclass clz, int64_t arg) {
3658         LDKCResult_RouteDecodeErrorZ *val = (LDKCResult_RouteDecodeErrorZ*)arg;
3659         CHECK(!val->result_ok);
3660         LDKDecodeError err_var = (*val->contents.err);
3661         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3662         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3663         long err_ref = (long)err_var.inner & ~1;
3664         return err_ref;
3665 }
3666 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCVec_1RouteHintZ_1new(JNIEnv *env, jclass clz, int64_tArray elems) {
3667         LDKCVec_RouteHintZ *ret = MALLOC(sizeof(LDKCVec_RouteHintZ), "LDKCVec_RouteHintZ");
3668         ret->datalen = (*env)->GetArrayLength(env, elems);
3669         if (ret->datalen == 0) {
3670                 ret->data = NULL;
3671         } else {
3672                 ret->data = MALLOC(sizeof(LDKRouteHint) * ret->datalen, "LDKCVec_RouteHintZ Data");
3673                 int64_t *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
3674                 for (size_t i = 0; i < ret->datalen; i++) {
3675                         int64_t arr_elem = java_elems[i];
3676                         LDKRouteHint arr_elem_conv;
3677                         arr_elem_conv.inner = (void*)(arr_elem & (~1));
3678                         arr_elem_conv.is_owned = (arr_elem & 1) || (arr_elem == 0);
3679                         if (arr_elem_conv.inner != NULL)
3680                                 arr_elem_conv = RouteHint_clone(&arr_elem_conv);
3681                         ret->data[i] = arr_elem_conv;
3682                 }
3683                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
3684         }
3685         return (long)ret;
3686 }
3687 static inline LDKCVec_RouteHintZ CVec_RouteHintZ_clone(const LDKCVec_RouteHintZ *orig) {
3688         LDKCVec_RouteHintZ ret = { .data = MALLOC(sizeof(LDKRouteHint) * orig->datalen, "LDKCVec_RouteHintZ clone bytes"), .datalen = orig->datalen };
3689         for (size_t i = 0; i < ret.datalen; i++) {
3690                 ret.data[i] = RouteHint_clone(&orig->data[i]);
3691         }
3692         return ret;
3693 }
3694 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1RouteLightningErrorZ_1result_1ok (JNIEnv *env, jclass clz, int64_t arg) {
3695         return ((LDKCResult_RouteLightningErrorZ*)arg)->result_ok;
3696 }
3697 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1RouteLightningErrorZ_1get_1ok (JNIEnv *env, jclass clz, int64_t arg) {
3698         LDKCResult_RouteLightningErrorZ *val = (LDKCResult_RouteLightningErrorZ*)arg;
3699         CHECK(val->result_ok);
3700         LDKRoute res_var = (*val->contents.result);
3701         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3702         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3703         long res_ref = (long)res_var.inner & ~1;
3704         return res_ref;
3705 }
3706 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1RouteLightningErrorZ_1get_1err (JNIEnv *env, jclass clz, int64_t arg) {
3707         LDKCResult_RouteLightningErrorZ *val = (LDKCResult_RouteLightningErrorZ*)arg;
3708         CHECK(!val->result_ok);
3709         LDKLightningError err_var = (*val->contents.err);
3710         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3711         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3712         long err_ref = (long)err_var.inner & ~1;
3713         return err_ref;
3714 }
3715 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1RoutingFeesDecodeErrorZ_1result_1ok (JNIEnv *env, jclass clz, int64_t arg) {
3716         return ((LDKCResult_RoutingFeesDecodeErrorZ*)arg)->result_ok;
3717 }
3718 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1RoutingFeesDecodeErrorZ_1get_1ok (JNIEnv *env, jclass clz, int64_t arg) {
3719         LDKCResult_RoutingFeesDecodeErrorZ *val = (LDKCResult_RoutingFeesDecodeErrorZ*)arg;
3720         CHECK(val->result_ok);
3721         LDKRoutingFees res_var = (*val->contents.result);
3722         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3723         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3724         long res_ref = (long)res_var.inner & ~1;
3725         return res_ref;
3726 }
3727 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1RoutingFeesDecodeErrorZ_1get_1err (JNIEnv *env, jclass clz, int64_t arg) {
3728         LDKCResult_RoutingFeesDecodeErrorZ *val = (LDKCResult_RoutingFeesDecodeErrorZ*)arg;
3729         CHECK(!val->result_ok);
3730         LDKDecodeError err_var = (*val->contents.err);
3731         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3732         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3733         long err_ref = (long)err_var.inner & ~1;
3734         return err_ref;
3735 }
3736 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NodeAnnouncementInfoDecodeErrorZ_1result_1ok (JNIEnv *env, jclass clz, int64_t arg) {
3737         return ((LDKCResult_NodeAnnouncementInfoDecodeErrorZ*)arg)->result_ok;
3738 }
3739 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NodeAnnouncementInfoDecodeErrorZ_1get_1ok (JNIEnv *env, jclass clz, int64_t arg) {
3740         LDKCResult_NodeAnnouncementInfoDecodeErrorZ *val = (LDKCResult_NodeAnnouncementInfoDecodeErrorZ*)arg;
3741         CHECK(val->result_ok);
3742         LDKNodeAnnouncementInfo res_var = (*val->contents.result);
3743         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3744         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3745         long res_ref = (long)res_var.inner & ~1;
3746         return res_ref;
3747 }
3748 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NodeAnnouncementInfoDecodeErrorZ_1get_1err (JNIEnv *env, jclass clz, int64_t arg) {
3749         LDKCResult_NodeAnnouncementInfoDecodeErrorZ *val = (LDKCResult_NodeAnnouncementInfoDecodeErrorZ*)arg;
3750         CHECK(!val->result_ok);
3751         LDKDecodeError err_var = (*val->contents.err);
3752         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3753         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3754         long err_ref = (long)err_var.inner & ~1;
3755         return err_ref;
3756 }
3757 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NodeInfoDecodeErrorZ_1result_1ok (JNIEnv *env, jclass clz, int64_t arg) {
3758         return ((LDKCResult_NodeInfoDecodeErrorZ*)arg)->result_ok;
3759 }
3760 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NodeInfoDecodeErrorZ_1get_1ok (JNIEnv *env, jclass clz, int64_t arg) {
3761         LDKCResult_NodeInfoDecodeErrorZ *val = (LDKCResult_NodeInfoDecodeErrorZ*)arg;
3762         CHECK(val->result_ok);
3763         LDKNodeInfo res_var = (*val->contents.result);
3764         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3765         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3766         long res_ref = (long)res_var.inner & ~1;
3767         return res_ref;
3768 }
3769 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NodeInfoDecodeErrorZ_1get_1err (JNIEnv *env, jclass clz, int64_t arg) {
3770         LDKCResult_NodeInfoDecodeErrorZ *val = (LDKCResult_NodeInfoDecodeErrorZ*)arg;
3771         CHECK(!val->result_ok);
3772         LDKDecodeError err_var = (*val->contents.err);
3773         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3774         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3775         long err_ref = (long)err_var.inner & ~1;
3776         return err_ref;
3777 }
3778 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NetworkGraphDecodeErrorZ_1result_1ok (JNIEnv *env, jclass clz, int64_t arg) {
3779         return ((LDKCResult_NetworkGraphDecodeErrorZ*)arg)->result_ok;
3780 }
3781 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NetworkGraphDecodeErrorZ_1get_1ok (JNIEnv *env, jclass clz, int64_t arg) {
3782         LDKCResult_NetworkGraphDecodeErrorZ *val = (LDKCResult_NetworkGraphDecodeErrorZ*)arg;
3783         CHECK(val->result_ok);
3784         LDKNetworkGraph res_var = (*val->contents.result);
3785         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3786         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3787         long res_ref = (long)res_var.inner & ~1;
3788         return res_ref;
3789 }
3790 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NetworkGraphDecodeErrorZ_1get_1err (JNIEnv *env, jclass clz, int64_t arg) {
3791         LDKCResult_NetworkGraphDecodeErrorZ *val = (LDKCResult_NetworkGraphDecodeErrorZ*)arg;
3792         CHECK(!val->result_ok);
3793         LDKDecodeError err_var = (*val->contents.err);
3794         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3795         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3796         long err_ref = (long)err_var.inner & ~1;
3797         return err_ref;
3798 }
3799 typedef struct LDKMessageSendEventsProvider_JCalls {
3800         atomic_size_t refcnt;
3801         JavaVM *vm;
3802         jweak o;
3803         jmethodID get_and_clear_pending_msg_events_meth;
3804 } LDKMessageSendEventsProvider_JCalls;
3805 static void LDKMessageSendEventsProvider_JCalls_free(void* this_arg) {
3806         LDKMessageSendEventsProvider_JCalls *j_calls = (LDKMessageSendEventsProvider_JCalls*) this_arg;
3807         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
3808                 JNIEnv *env;
3809                 DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
3810                 (*env)->DeleteWeakGlobalRef(env, j_calls->o);
3811                 FREE(j_calls);
3812         }
3813 }
3814 LDKCVec_MessageSendEventZ get_and_clear_pending_msg_events_jcall(const void* this_arg) {
3815         LDKMessageSendEventsProvider_JCalls *j_calls = (LDKMessageSendEventsProvider_JCalls*) this_arg;
3816         JNIEnv *env;
3817         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
3818         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
3819         CHECK(obj != NULL);
3820         int64_tArray arg = (*env)->CallObjectMethod(env, obj, j_calls->get_and_clear_pending_msg_events_meth);
3821         LDKCVec_MessageSendEventZ arg_constr;
3822         arg_constr.datalen = (*env)->GetArrayLength(env, arg);
3823         if (arg_constr.datalen > 0)
3824                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKMessageSendEvent), "LDKCVec_MessageSendEventZ Elements");
3825         else
3826                 arg_constr.data = NULL;
3827         int64_t* arg_vals = (*env)->GetLongArrayElements (env, arg, NULL);
3828         for (size_t s = 0; s < arg_constr.datalen; s++) {
3829                 int64_t arr_conv_18 = arg_vals[s];
3830                 LDKMessageSendEvent arr_conv_18_conv = *(LDKMessageSendEvent*)arr_conv_18;
3831                 FREE((void*)arr_conv_18);
3832                 arg_constr.data[s] = arr_conv_18_conv;
3833         }
3834         (*env)->ReleaseLongArrayElements(env, arg, arg_vals, 0);
3835         return arg_constr;
3836 }
3837 static void* LDKMessageSendEventsProvider_JCalls_clone(const void* this_arg) {
3838         LDKMessageSendEventsProvider_JCalls *j_calls = (LDKMessageSendEventsProvider_JCalls*) this_arg;
3839         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
3840         return (void*) this_arg;
3841 }
3842 static inline LDKMessageSendEventsProvider LDKMessageSendEventsProvider_init (JNIEnv *env, jclass clz, jobject o) {
3843         jclass c = (*env)->GetObjectClass(env, o);
3844         CHECK(c != NULL);
3845         LDKMessageSendEventsProvider_JCalls *calls = MALLOC(sizeof(LDKMessageSendEventsProvider_JCalls), "LDKMessageSendEventsProvider_JCalls");
3846         atomic_init(&calls->refcnt, 1);
3847         DO_ASSERT((*env)->GetJavaVM(env, &calls->vm) == 0);
3848         calls->o = (*env)->NewWeakGlobalRef(env, o);
3849         calls->get_and_clear_pending_msg_events_meth = (*env)->GetMethodID(env, c, "get_and_clear_pending_msg_events", "()[J");
3850         CHECK(calls->get_and_clear_pending_msg_events_meth != NULL);
3851
3852         LDKMessageSendEventsProvider ret = {
3853                 .this_arg = (void*) calls,
3854                 .get_and_clear_pending_msg_events = get_and_clear_pending_msg_events_jcall,
3855                 .free = LDKMessageSendEventsProvider_JCalls_free,
3856         };
3857         return ret;
3858 }
3859 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_LDKMessageSendEventsProvider_1new (JNIEnv *env, jclass clz, jobject o) {
3860         LDKMessageSendEventsProvider *res_ptr = MALLOC(sizeof(LDKMessageSendEventsProvider), "LDKMessageSendEventsProvider");
3861         *res_ptr = LDKMessageSendEventsProvider_init(env, clz, o);
3862         return (long)res_ptr;
3863 }
3864 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKMessageSendEventsProvider_1get_1obj_1from_1jcalls (JNIEnv *env, jclass clz, int64_t val) {
3865         jobject ret = (*env)->NewLocalRef(env, ((LDKMessageSendEventsProvider_JCalls*)val)->o);
3866         CHECK(ret != NULL);
3867         return ret;
3868 }
3869 JNIEXPORT int64_tArray JNICALL Java_org_ldk_impl_bindings_MessageSendEventsProvider_1get_1and_1clear_1pending_1msg_1events(JNIEnv *env, jclass clz, int64_t this_arg) {
3870         LDKMessageSendEventsProvider* this_arg_conv = (LDKMessageSendEventsProvider*)this_arg;
3871         LDKCVec_MessageSendEventZ ret_var = (this_arg_conv->get_and_clear_pending_msg_events)(this_arg_conv->this_arg);
3872         int64_tArray ret_arr = (*env)->NewLongArray(env, ret_var.datalen);
3873         int64_t *ret_arr_ptr = (*env)->GetPrimitiveArrayCritical(env, ret_arr, NULL);
3874         for (size_t s = 0; s < ret_var.datalen; s++) {
3875                 LDKMessageSendEvent *arr_conv_18_copy = MALLOC(sizeof(LDKMessageSendEvent), "LDKMessageSendEvent");
3876                 *arr_conv_18_copy = MessageSendEvent_clone(&ret_var.data[s]);
3877                 long arr_conv_18_ref = (long)arr_conv_18_copy;
3878                 ret_arr_ptr[s] = arr_conv_18_ref;
3879         }
3880         (*env)->ReleasePrimitiveArrayCritical(env, ret_arr, ret_arr_ptr, 0);
3881         FREE(ret_var.data);
3882         return ret_arr;
3883 }
3884
3885 typedef struct LDKEventsProvider_JCalls {
3886         atomic_size_t refcnt;
3887         JavaVM *vm;
3888         jweak o;
3889         jmethodID get_and_clear_pending_events_meth;
3890 } LDKEventsProvider_JCalls;
3891 static void LDKEventsProvider_JCalls_free(void* this_arg) {
3892         LDKEventsProvider_JCalls *j_calls = (LDKEventsProvider_JCalls*) this_arg;
3893         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
3894                 JNIEnv *env;
3895                 DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
3896                 (*env)->DeleteWeakGlobalRef(env, j_calls->o);
3897                 FREE(j_calls);
3898         }
3899 }
3900 LDKCVec_EventZ get_and_clear_pending_events_jcall(const void* this_arg) {
3901         LDKEventsProvider_JCalls *j_calls = (LDKEventsProvider_JCalls*) this_arg;
3902         JNIEnv *env;
3903         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
3904         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
3905         CHECK(obj != NULL);
3906         int64_tArray arg = (*env)->CallObjectMethod(env, obj, j_calls->get_and_clear_pending_events_meth);
3907         LDKCVec_EventZ arg_constr;
3908         arg_constr.datalen = (*env)->GetArrayLength(env, arg);
3909         if (arg_constr.datalen > 0)
3910                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKEvent), "LDKCVec_EventZ Elements");
3911         else
3912                 arg_constr.data = NULL;
3913         int64_t* arg_vals = (*env)->GetLongArrayElements (env, arg, NULL);
3914         for (size_t h = 0; h < arg_constr.datalen; h++) {
3915                 int64_t arr_conv_7 = arg_vals[h];
3916                 LDKEvent arr_conv_7_conv = *(LDKEvent*)arr_conv_7;
3917                 FREE((void*)arr_conv_7);
3918                 arg_constr.data[h] = arr_conv_7_conv;
3919         }
3920         (*env)->ReleaseLongArrayElements(env, arg, arg_vals, 0);
3921         return arg_constr;
3922 }
3923 static void* LDKEventsProvider_JCalls_clone(const void* this_arg) {
3924         LDKEventsProvider_JCalls *j_calls = (LDKEventsProvider_JCalls*) this_arg;
3925         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
3926         return (void*) this_arg;
3927 }
3928 static inline LDKEventsProvider LDKEventsProvider_init (JNIEnv *env, jclass clz, jobject o) {
3929         jclass c = (*env)->GetObjectClass(env, o);
3930         CHECK(c != NULL);
3931         LDKEventsProvider_JCalls *calls = MALLOC(sizeof(LDKEventsProvider_JCalls), "LDKEventsProvider_JCalls");
3932         atomic_init(&calls->refcnt, 1);
3933         DO_ASSERT((*env)->GetJavaVM(env, &calls->vm) == 0);
3934         calls->o = (*env)->NewWeakGlobalRef(env, o);
3935         calls->get_and_clear_pending_events_meth = (*env)->GetMethodID(env, c, "get_and_clear_pending_events", "()[J");
3936         CHECK(calls->get_and_clear_pending_events_meth != NULL);
3937
3938         LDKEventsProvider ret = {
3939                 .this_arg = (void*) calls,
3940                 .get_and_clear_pending_events = get_and_clear_pending_events_jcall,
3941                 .free = LDKEventsProvider_JCalls_free,
3942         };
3943         return ret;
3944 }
3945 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_LDKEventsProvider_1new (JNIEnv *env, jclass clz, jobject o) {
3946         LDKEventsProvider *res_ptr = MALLOC(sizeof(LDKEventsProvider), "LDKEventsProvider");
3947         *res_ptr = LDKEventsProvider_init(env, clz, o);
3948         return (long)res_ptr;
3949 }
3950 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKEventsProvider_1get_1obj_1from_1jcalls (JNIEnv *env, jclass clz, int64_t val) {
3951         jobject ret = (*env)->NewLocalRef(env, ((LDKEventsProvider_JCalls*)val)->o);
3952         CHECK(ret != NULL);
3953         return ret;
3954 }
3955 JNIEXPORT int64_tArray JNICALL Java_org_ldk_impl_bindings_EventsProvider_1get_1and_1clear_1pending_1events(JNIEnv *env, jclass clz, int64_t this_arg) {
3956         LDKEventsProvider* this_arg_conv = (LDKEventsProvider*)this_arg;
3957         LDKCVec_EventZ ret_var = (this_arg_conv->get_and_clear_pending_events)(this_arg_conv->this_arg);
3958         int64_tArray ret_arr = (*env)->NewLongArray(env, ret_var.datalen);
3959         int64_t *ret_arr_ptr = (*env)->GetPrimitiveArrayCritical(env, ret_arr, NULL);
3960         for (size_t h = 0; h < ret_var.datalen; h++) {
3961                 LDKEvent *arr_conv_7_copy = MALLOC(sizeof(LDKEvent), "LDKEvent");
3962                 *arr_conv_7_copy = Event_clone(&ret_var.data[h]);
3963                 long arr_conv_7_ref = (long)arr_conv_7_copy;
3964                 ret_arr_ptr[h] = arr_conv_7_ref;
3965         }
3966         (*env)->ReleasePrimitiveArrayCritical(env, ret_arr, ret_arr_ptr, 0);
3967         FREE(ret_var.data);
3968         return ret_arr;
3969 }
3970
3971 typedef struct LDKAccess_JCalls {
3972         atomic_size_t refcnt;
3973         JavaVM *vm;
3974         jweak o;
3975         jmethodID get_utxo_meth;
3976 } LDKAccess_JCalls;
3977 static void LDKAccess_JCalls_free(void* this_arg) {
3978         LDKAccess_JCalls *j_calls = (LDKAccess_JCalls*) this_arg;
3979         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
3980                 JNIEnv *env;
3981                 DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
3982                 (*env)->DeleteWeakGlobalRef(env, j_calls->o);
3983                 FREE(j_calls);
3984         }
3985 }
3986 LDKCResult_TxOutAccessErrorZ get_utxo_jcall(const void* this_arg, const uint8_t (* genesis_hash)[32], uint64_t short_channel_id) {
3987         LDKAccess_JCalls *j_calls = (LDKAccess_JCalls*) this_arg;
3988         JNIEnv *env;
3989         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
3990         int8_tArray genesis_hash_arr = (*env)->NewByteArray(env, 32);
3991         (*env)->SetByteArrayRegion(env, genesis_hash_arr, 0, 32, *genesis_hash);
3992         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
3993         CHECK(obj != NULL);
3994         LDKCResult_TxOutAccessErrorZ* ret = (LDKCResult_TxOutAccessErrorZ*)(*env)->CallLongMethod(env, obj, j_calls->get_utxo_meth, genesis_hash_arr, short_channel_id);
3995         LDKCResult_TxOutAccessErrorZ ret_conv = *(LDKCResult_TxOutAccessErrorZ*)ret;
3996         FREE((void*)ret);
3997         return ret_conv;
3998 }
3999 static void* LDKAccess_JCalls_clone(const void* this_arg) {
4000         LDKAccess_JCalls *j_calls = (LDKAccess_JCalls*) this_arg;
4001         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
4002         return (void*) this_arg;
4003 }
4004 static inline LDKAccess LDKAccess_init (JNIEnv *env, jclass clz, jobject o) {
4005         jclass c = (*env)->GetObjectClass(env, o);
4006         CHECK(c != NULL);
4007         LDKAccess_JCalls *calls = MALLOC(sizeof(LDKAccess_JCalls), "LDKAccess_JCalls");
4008         atomic_init(&calls->refcnt, 1);
4009         DO_ASSERT((*env)->GetJavaVM(env, &calls->vm) == 0);
4010         calls->o = (*env)->NewWeakGlobalRef(env, o);
4011         calls->get_utxo_meth = (*env)->GetMethodID(env, c, "get_utxo", "([BJ)J");
4012         CHECK(calls->get_utxo_meth != NULL);
4013
4014         LDKAccess ret = {
4015                 .this_arg = (void*) calls,
4016                 .get_utxo = get_utxo_jcall,
4017                 .free = LDKAccess_JCalls_free,
4018         };
4019         return ret;
4020 }
4021 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_LDKAccess_1new (JNIEnv *env, jclass clz, jobject o) {
4022         LDKAccess *res_ptr = MALLOC(sizeof(LDKAccess), "LDKAccess");
4023         *res_ptr = LDKAccess_init(env, clz, o);
4024         return (long)res_ptr;
4025 }
4026 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKAccess_1get_1obj_1from_1jcalls (JNIEnv *env, jclass clz, int64_t val) {
4027         jobject ret = (*env)->NewLocalRef(env, ((LDKAccess_JCalls*)val)->o);
4028         CHECK(ret != NULL);
4029         return ret;
4030 }
4031 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) {
4032         LDKAccess* this_arg_conv = (LDKAccess*)this_arg;
4033         unsigned char genesis_hash_arr[32];
4034         CHECK((*env)->GetArrayLength(env, genesis_hash) == 32);
4035         (*env)->GetByteArrayRegion(env, genesis_hash, 0, 32, genesis_hash_arr);
4036         unsigned char (*genesis_hash_ref)[32] = &genesis_hash_arr;
4037         LDKCResult_TxOutAccessErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_TxOutAccessErrorZ), "LDKCResult_TxOutAccessErrorZ");
4038         *ret_conv = (this_arg_conv->get_utxo)(this_arg_conv->this_arg, genesis_hash_ref, short_channel_id);
4039         return (long)ret_conv;
4040 }
4041
4042 typedef struct LDKFilter_JCalls {
4043         atomic_size_t refcnt;
4044         JavaVM *vm;
4045         jweak o;
4046         jmethodID register_tx_meth;
4047         jmethodID register_output_meth;
4048 } LDKFilter_JCalls;
4049 static void LDKFilter_JCalls_free(void* this_arg) {
4050         LDKFilter_JCalls *j_calls = (LDKFilter_JCalls*) this_arg;
4051         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
4052                 JNIEnv *env;
4053                 DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
4054                 (*env)->DeleteWeakGlobalRef(env, j_calls->o);
4055                 FREE(j_calls);
4056         }
4057 }
4058 void register_tx_jcall(const void* this_arg, const uint8_t (* txid)[32], LDKu8slice script_pubkey) {
4059         LDKFilter_JCalls *j_calls = (LDKFilter_JCalls*) this_arg;
4060         JNIEnv *env;
4061         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
4062         int8_tArray txid_arr = (*env)->NewByteArray(env, 32);
4063         (*env)->SetByteArrayRegion(env, txid_arr, 0, 32, *txid);
4064         LDKu8slice script_pubkey_var = script_pubkey;
4065         int8_tArray script_pubkey_arr = (*env)->NewByteArray(env, script_pubkey_var.datalen);
4066         (*env)->SetByteArrayRegion(env, script_pubkey_arr, 0, script_pubkey_var.datalen, script_pubkey_var.data);
4067         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
4068         CHECK(obj != NULL);
4069         return (*env)->CallVoidMethod(env, obj, j_calls->register_tx_meth, txid_arr, script_pubkey_arr);
4070 }
4071 void register_output_jcall(const void* this_arg, const LDKOutPoint * outpoint, LDKu8slice script_pubkey) {
4072         LDKFilter_JCalls *j_calls = (LDKFilter_JCalls*) this_arg;
4073         JNIEnv *env;
4074         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
4075         LDKOutPoint outpoint_var = *outpoint;
4076         if (outpoint->inner != NULL)
4077                 outpoint_var = OutPoint_clone(outpoint);
4078         CHECK((((long)outpoint_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4079         CHECK((((long)&outpoint_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4080         long outpoint_ref = (long)outpoint_var.inner;
4081         if (outpoint_var.is_owned) {
4082                 outpoint_ref |= 1;
4083         }
4084         LDKu8slice script_pubkey_var = script_pubkey;
4085         int8_tArray script_pubkey_arr = (*env)->NewByteArray(env, script_pubkey_var.datalen);
4086         (*env)->SetByteArrayRegion(env, script_pubkey_arr, 0, script_pubkey_var.datalen, script_pubkey_var.data);
4087         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
4088         CHECK(obj != NULL);
4089         return (*env)->CallVoidMethod(env, obj, j_calls->register_output_meth, outpoint_ref, script_pubkey_arr);
4090 }
4091 static void* LDKFilter_JCalls_clone(const void* this_arg) {
4092         LDKFilter_JCalls *j_calls = (LDKFilter_JCalls*) this_arg;
4093         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
4094         return (void*) this_arg;
4095 }
4096 static inline LDKFilter LDKFilter_init (JNIEnv *env, jclass clz, jobject o) {
4097         jclass c = (*env)->GetObjectClass(env, o);
4098         CHECK(c != NULL);
4099         LDKFilter_JCalls *calls = MALLOC(sizeof(LDKFilter_JCalls), "LDKFilter_JCalls");
4100         atomic_init(&calls->refcnt, 1);
4101         DO_ASSERT((*env)->GetJavaVM(env, &calls->vm) == 0);
4102         calls->o = (*env)->NewWeakGlobalRef(env, o);
4103         calls->register_tx_meth = (*env)->GetMethodID(env, c, "register_tx", "([B[B)V");
4104         CHECK(calls->register_tx_meth != NULL);
4105         calls->register_output_meth = (*env)->GetMethodID(env, c, "register_output", "(J[B)V");
4106         CHECK(calls->register_output_meth != NULL);
4107
4108         LDKFilter ret = {
4109                 .this_arg = (void*) calls,
4110                 .register_tx = register_tx_jcall,
4111                 .register_output = register_output_jcall,
4112                 .free = LDKFilter_JCalls_free,
4113         };
4114         return ret;
4115 }
4116 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_LDKFilter_1new (JNIEnv *env, jclass clz, jobject o) {
4117         LDKFilter *res_ptr = MALLOC(sizeof(LDKFilter), "LDKFilter");
4118         *res_ptr = LDKFilter_init(env, clz, o);
4119         return (long)res_ptr;
4120 }
4121 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKFilter_1get_1obj_1from_1jcalls (JNIEnv *env, jclass clz, int64_t val) {
4122         jobject ret = (*env)->NewLocalRef(env, ((LDKFilter_JCalls*)val)->o);
4123         CHECK(ret != NULL);
4124         return ret;
4125 }
4126 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) {
4127         LDKFilter* this_arg_conv = (LDKFilter*)this_arg;
4128         unsigned char txid_arr[32];
4129         CHECK((*env)->GetArrayLength(env, txid) == 32);
4130         (*env)->GetByteArrayRegion(env, txid, 0, 32, txid_arr);
4131         unsigned char (*txid_ref)[32] = &txid_arr;
4132         LDKu8slice script_pubkey_ref;
4133         script_pubkey_ref.datalen = (*env)->GetArrayLength(env, script_pubkey);
4134         script_pubkey_ref.data = (*env)->GetByteArrayElements (env, script_pubkey, NULL);
4135         (this_arg_conv->register_tx)(this_arg_conv->this_arg, txid_ref, script_pubkey_ref);
4136         (*env)->ReleaseByteArrayElements(env, script_pubkey, (int8_t*)script_pubkey_ref.data, 0);
4137 }
4138
4139 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) {
4140         LDKFilter* this_arg_conv = (LDKFilter*)this_arg;
4141         LDKOutPoint outpoint_conv;
4142         outpoint_conv.inner = (void*)(outpoint & (~1));
4143         outpoint_conv.is_owned = false;
4144         LDKu8slice script_pubkey_ref;
4145         script_pubkey_ref.datalen = (*env)->GetArrayLength(env, script_pubkey);
4146         script_pubkey_ref.data = (*env)->GetByteArrayElements (env, script_pubkey, NULL);
4147         (this_arg_conv->register_output)(this_arg_conv->this_arg, &outpoint_conv, script_pubkey_ref);
4148         (*env)->ReleaseByteArrayElements(env, script_pubkey, (int8_t*)script_pubkey_ref.data, 0);
4149 }
4150
4151 typedef struct LDKPersist_JCalls {
4152         atomic_size_t refcnt;
4153         JavaVM *vm;
4154         jweak o;
4155         jmethodID persist_new_channel_meth;
4156         jmethodID update_persisted_channel_meth;
4157 } LDKPersist_JCalls;
4158 static void LDKPersist_JCalls_free(void* this_arg) {
4159         LDKPersist_JCalls *j_calls = (LDKPersist_JCalls*) this_arg;
4160         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
4161                 JNIEnv *env;
4162                 DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
4163                 (*env)->DeleteWeakGlobalRef(env, j_calls->o);
4164                 FREE(j_calls);
4165         }
4166 }
4167 LDKCResult_NoneChannelMonitorUpdateErrZ persist_new_channel_jcall(const void* this_arg, LDKOutPoint id, const LDKChannelMonitor * data) {
4168         LDKPersist_JCalls *j_calls = (LDKPersist_JCalls*) this_arg;
4169         JNIEnv *env;
4170         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
4171         LDKOutPoint id_var = id;
4172         CHECK((((long)id_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4173         CHECK((((long)&id_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4174         long id_ref = (long)id_var.inner;
4175         if (id_var.is_owned) {
4176                 id_ref |= 1;
4177         }
4178         LDKChannelMonitor data_var = *data;
4179         // Warning: we may need a move here but can't clone!
4180         CHECK((((long)data_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4181         CHECK((((long)&data_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4182         long data_ref = (long)data_var.inner;
4183         if (data_var.is_owned) {
4184                 data_ref |= 1;
4185         }
4186         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
4187         CHECK(obj != NULL);
4188         LDKCResult_NoneChannelMonitorUpdateErrZ* ret = (LDKCResult_NoneChannelMonitorUpdateErrZ*)(*env)->CallLongMethod(env, obj, j_calls->persist_new_channel_meth, id_ref, data_ref);
4189         LDKCResult_NoneChannelMonitorUpdateErrZ ret_conv = *(LDKCResult_NoneChannelMonitorUpdateErrZ*)ret;
4190         FREE((void*)ret);
4191         return ret_conv;
4192 }
4193 LDKCResult_NoneChannelMonitorUpdateErrZ update_persisted_channel_jcall(const void* this_arg, LDKOutPoint id, const LDKChannelMonitorUpdate * update, const LDKChannelMonitor * data) {
4194         LDKPersist_JCalls *j_calls = (LDKPersist_JCalls*) this_arg;
4195         JNIEnv *env;
4196         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
4197         LDKOutPoint id_var = id;
4198         CHECK((((long)id_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4199         CHECK((((long)&id_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4200         long id_ref = (long)id_var.inner;
4201         if (id_var.is_owned) {
4202                 id_ref |= 1;
4203         }
4204         LDKChannelMonitorUpdate update_var = *update;
4205         if (update->inner != NULL)
4206                 update_var = ChannelMonitorUpdate_clone(update);
4207         CHECK((((long)update_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4208         CHECK((((long)&update_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4209         long update_ref = (long)update_var.inner;
4210         if (update_var.is_owned) {
4211                 update_ref |= 1;
4212         }
4213         LDKChannelMonitor data_var = *data;
4214         // Warning: we may need a move here but can't clone!
4215         CHECK((((long)data_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4216         CHECK((((long)&data_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4217         long data_ref = (long)data_var.inner;
4218         if (data_var.is_owned) {
4219                 data_ref |= 1;
4220         }
4221         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
4222         CHECK(obj != NULL);
4223         LDKCResult_NoneChannelMonitorUpdateErrZ* ret = (LDKCResult_NoneChannelMonitorUpdateErrZ*)(*env)->CallLongMethod(env, obj, j_calls->update_persisted_channel_meth, id_ref, update_ref, data_ref);
4224         LDKCResult_NoneChannelMonitorUpdateErrZ ret_conv = *(LDKCResult_NoneChannelMonitorUpdateErrZ*)ret;
4225         FREE((void*)ret);
4226         return ret_conv;
4227 }
4228 static void* LDKPersist_JCalls_clone(const void* this_arg) {
4229         LDKPersist_JCalls *j_calls = (LDKPersist_JCalls*) this_arg;
4230         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
4231         return (void*) this_arg;
4232 }
4233 static inline LDKPersist LDKPersist_init (JNIEnv *env, jclass clz, jobject o) {
4234         jclass c = (*env)->GetObjectClass(env, o);
4235         CHECK(c != NULL);
4236         LDKPersist_JCalls *calls = MALLOC(sizeof(LDKPersist_JCalls), "LDKPersist_JCalls");
4237         atomic_init(&calls->refcnt, 1);
4238         DO_ASSERT((*env)->GetJavaVM(env, &calls->vm) == 0);
4239         calls->o = (*env)->NewWeakGlobalRef(env, o);
4240         calls->persist_new_channel_meth = (*env)->GetMethodID(env, c, "persist_new_channel", "(JJ)J");
4241         CHECK(calls->persist_new_channel_meth != NULL);
4242         calls->update_persisted_channel_meth = (*env)->GetMethodID(env, c, "update_persisted_channel", "(JJJ)J");
4243         CHECK(calls->update_persisted_channel_meth != NULL);
4244
4245         LDKPersist ret = {
4246                 .this_arg = (void*) calls,
4247                 .persist_new_channel = persist_new_channel_jcall,
4248                 .update_persisted_channel = update_persisted_channel_jcall,
4249                 .free = LDKPersist_JCalls_free,
4250         };
4251         return ret;
4252 }
4253 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_LDKPersist_1new (JNIEnv *env, jclass clz, jobject o) {
4254         LDKPersist *res_ptr = MALLOC(sizeof(LDKPersist), "LDKPersist");
4255         *res_ptr = LDKPersist_init(env, clz, o);
4256         return (long)res_ptr;
4257 }
4258 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKPersist_1get_1obj_1from_1jcalls (JNIEnv *env, jclass clz, int64_t val) {
4259         jobject ret = (*env)->NewLocalRef(env, ((LDKPersist_JCalls*)val)->o);
4260         CHECK(ret != NULL);
4261         return ret;
4262 }
4263 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) {
4264         LDKPersist* this_arg_conv = (LDKPersist*)this_arg;
4265         LDKOutPoint id_conv;
4266         id_conv.inner = (void*)(id & (~1));
4267         id_conv.is_owned = (id & 1) || (id == 0);
4268         if (id_conv.inner != NULL)
4269                 id_conv = OutPoint_clone(&id_conv);
4270         LDKChannelMonitor data_conv;
4271         data_conv.inner = (void*)(data & (~1));
4272         data_conv.is_owned = false;
4273         LDKCResult_NoneChannelMonitorUpdateErrZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneChannelMonitorUpdateErrZ), "LDKCResult_NoneChannelMonitorUpdateErrZ");
4274         *ret_conv = (this_arg_conv->persist_new_channel)(this_arg_conv->this_arg, id_conv, &data_conv);
4275         return (long)ret_conv;
4276 }
4277
4278 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) {
4279         LDKPersist* this_arg_conv = (LDKPersist*)this_arg;
4280         LDKOutPoint id_conv;
4281         id_conv.inner = (void*)(id & (~1));
4282         id_conv.is_owned = (id & 1) || (id == 0);
4283         if (id_conv.inner != NULL)
4284                 id_conv = OutPoint_clone(&id_conv);
4285         LDKChannelMonitorUpdate update_conv;
4286         update_conv.inner = (void*)(update & (~1));
4287         update_conv.is_owned = false;
4288         LDKChannelMonitor data_conv;
4289         data_conv.inner = (void*)(data & (~1));
4290         data_conv.is_owned = false;
4291         LDKCResult_NoneChannelMonitorUpdateErrZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneChannelMonitorUpdateErrZ), "LDKCResult_NoneChannelMonitorUpdateErrZ");
4292         *ret_conv = (this_arg_conv->update_persisted_channel)(this_arg_conv->this_arg, id_conv, &update_conv, &data_conv);
4293         return (long)ret_conv;
4294 }
4295
4296 typedef struct LDKChannelMessageHandler_JCalls {
4297         atomic_size_t refcnt;
4298         JavaVM *vm;
4299         jweak o;
4300         LDKMessageSendEventsProvider_JCalls* MessageSendEventsProvider;
4301         jmethodID handle_open_channel_meth;
4302         jmethodID handle_accept_channel_meth;
4303         jmethodID handle_funding_created_meth;
4304         jmethodID handle_funding_signed_meth;
4305         jmethodID handle_funding_locked_meth;
4306         jmethodID handle_shutdown_meth;
4307         jmethodID handle_closing_signed_meth;
4308         jmethodID handle_update_add_htlc_meth;
4309         jmethodID handle_update_fulfill_htlc_meth;
4310         jmethodID handle_update_fail_htlc_meth;
4311         jmethodID handle_update_fail_malformed_htlc_meth;
4312         jmethodID handle_commitment_signed_meth;
4313         jmethodID handle_revoke_and_ack_meth;
4314         jmethodID handle_update_fee_meth;
4315         jmethodID handle_announcement_signatures_meth;
4316         jmethodID peer_disconnected_meth;
4317         jmethodID peer_connected_meth;
4318         jmethodID handle_channel_reestablish_meth;
4319         jmethodID handle_error_meth;
4320 } LDKChannelMessageHandler_JCalls;
4321 static void LDKChannelMessageHandler_JCalls_free(void* this_arg) {
4322         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
4323         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
4324                 JNIEnv *env;
4325                 DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
4326                 (*env)->DeleteWeakGlobalRef(env, j_calls->o);
4327                 FREE(j_calls);
4328         }
4329 }
4330 void handle_open_channel_jcall(const void* this_arg, LDKPublicKey their_node_id, LDKInitFeatures their_features, const LDKOpenChannel * msg) {
4331         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
4332         JNIEnv *env;
4333         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
4334         int8_tArray their_node_id_arr = (*env)->NewByteArray(env, 33);
4335         (*env)->SetByteArrayRegion(env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
4336         LDKInitFeatures their_features_var = their_features;
4337         CHECK((((long)their_features_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4338         CHECK((((long)&their_features_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4339         long their_features_ref = (long)their_features_var.inner;
4340         if (their_features_var.is_owned) {
4341                 their_features_ref |= 1;
4342         }
4343         LDKOpenChannel msg_var = *msg;
4344         if (msg->inner != NULL)
4345                 msg_var = OpenChannel_clone(msg);
4346         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4347         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4348         long msg_ref = (long)msg_var.inner;
4349         if (msg_var.is_owned) {
4350                 msg_ref |= 1;
4351         }
4352         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
4353         CHECK(obj != NULL);
4354         return (*env)->CallVoidMethod(env, obj, j_calls->handle_open_channel_meth, their_node_id_arr, their_features_ref, msg_ref);
4355 }
4356 void handle_accept_channel_jcall(const void* this_arg, LDKPublicKey their_node_id, LDKInitFeatures their_features, const LDKAcceptChannel * msg) {
4357         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
4358         JNIEnv *env;
4359         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
4360         int8_tArray their_node_id_arr = (*env)->NewByteArray(env, 33);
4361         (*env)->SetByteArrayRegion(env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
4362         LDKInitFeatures their_features_var = their_features;
4363         CHECK((((long)their_features_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4364         CHECK((((long)&their_features_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4365         long their_features_ref = (long)their_features_var.inner;
4366         if (their_features_var.is_owned) {
4367                 their_features_ref |= 1;
4368         }
4369         LDKAcceptChannel msg_var = *msg;
4370         if (msg->inner != NULL)
4371                 msg_var = AcceptChannel_clone(msg);
4372         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4373         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4374         long msg_ref = (long)msg_var.inner;
4375         if (msg_var.is_owned) {
4376                 msg_ref |= 1;
4377         }
4378         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
4379         CHECK(obj != NULL);
4380         return (*env)->CallVoidMethod(env, obj, j_calls->handle_accept_channel_meth, their_node_id_arr, their_features_ref, msg_ref);
4381 }
4382 void handle_funding_created_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKFundingCreated * msg) {
4383         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
4384         JNIEnv *env;
4385         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
4386         int8_tArray their_node_id_arr = (*env)->NewByteArray(env, 33);
4387         (*env)->SetByteArrayRegion(env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
4388         LDKFundingCreated msg_var = *msg;
4389         if (msg->inner != NULL)
4390                 msg_var = FundingCreated_clone(msg);
4391         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4392         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4393         long msg_ref = (long)msg_var.inner;
4394         if (msg_var.is_owned) {
4395                 msg_ref |= 1;
4396         }
4397         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
4398         CHECK(obj != NULL);
4399         return (*env)->CallVoidMethod(env, obj, j_calls->handle_funding_created_meth, their_node_id_arr, msg_ref);
4400 }
4401 void handle_funding_signed_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKFundingSigned * msg) {
4402         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
4403         JNIEnv *env;
4404         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
4405         int8_tArray their_node_id_arr = (*env)->NewByteArray(env, 33);
4406         (*env)->SetByteArrayRegion(env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
4407         LDKFundingSigned msg_var = *msg;
4408         if (msg->inner != NULL)
4409                 msg_var = FundingSigned_clone(msg);
4410         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4411         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4412         long msg_ref = (long)msg_var.inner;
4413         if (msg_var.is_owned) {
4414                 msg_ref |= 1;
4415         }
4416         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
4417         CHECK(obj != NULL);
4418         return (*env)->CallVoidMethod(env, obj, j_calls->handle_funding_signed_meth, their_node_id_arr, msg_ref);
4419 }
4420 void handle_funding_locked_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKFundingLocked * msg) {
4421         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
4422         JNIEnv *env;
4423         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
4424         int8_tArray their_node_id_arr = (*env)->NewByteArray(env, 33);
4425         (*env)->SetByteArrayRegion(env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
4426         LDKFundingLocked msg_var = *msg;
4427         if (msg->inner != NULL)
4428                 msg_var = FundingLocked_clone(msg);
4429         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4430         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4431         long msg_ref = (long)msg_var.inner;
4432         if (msg_var.is_owned) {
4433                 msg_ref |= 1;
4434         }
4435         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
4436         CHECK(obj != NULL);
4437         return (*env)->CallVoidMethod(env, obj, j_calls->handle_funding_locked_meth, their_node_id_arr, msg_ref);
4438 }
4439 void handle_shutdown_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKShutdown * msg) {
4440         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
4441         JNIEnv *env;
4442         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
4443         int8_tArray their_node_id_arr = (*env)->NewByteArray(env, 33);
4444         (*env)->SetByteArrayRegion(env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
4445         LDKShutdown msg_var = *msg;
4446         if (msg->inner != NULL)
4447                 msg_var = Shutdown_clone(msg);
4448         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4449         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4450         long msg_ref = (long)msg_var.inner;
4451         if (msg_var.is_owned) {
4452                 msg_ref |= 1;
4453         }
4454         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
4455         CHECK(obj != NULL);
4456         return (*env)->CallVoidMethod(env, obj, j_calls->handle_shutdown_meth, their_node_id_arr, msg_ref);
4457 }
4458 void handle_closing_signed_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKClosingSigned * msg) {
4459         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
4460         JNIEnv *env;
4461         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
4462         int8_tArray their_node_id_arr = (*env)->NewByteArray(env, 33);
4463         (*env)->SetByteArrayRegion(env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
4464         LDKClosingSigned msg_var = *msg;
4465         if (msg->inner != NULL)
4466                 msg_var = ClosingSigned_clone(msg);
4467         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4468         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4469         long msg_ref = (long)msg_var.inner;
4470         if (msg_var.is_owned) {
4471                 msg_ref |= 1;
4472         }
4473         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
4474         CHECK(obj != NULL);
4475         return (*env)->CallVoidMethod(env, obj, j_calls->handle_closing_signed_meth, their_node_id_arr, msg_ref);
4476 }
4477 void handle_update_add_htlc_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKUpdateAddHTLC * msg) {
4478         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
4479         JNIEnv *env;
4480         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
4481         int8_tArray their_node_id_arr = (*env)->NewByteArray(env, 33);
4482         (*env)->SetByteArrayRegion(env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
4483         LDKUpdateAddHTLC msg_var = *msg;
4484         if (msg->inner != NULL)
4485                 msg_var = UpdateAddHTLC_clone(msg);
4486         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4487         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4488         long msg_ref = (long)msg_var.inner;
4489         if (msg_var.is_owned) {
4490                 msg_ref |= 1;
4491         }
4492         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
4493         CHECK(obj != NULL);
4494         return (*env)->CallVoidMethod(env, obj, j_calls->handle_update_add_htlc_meth, their_node_id_arr, msg_ref);
4495 }
4496 void handle_update_fulfill_htlc_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKUpdateFulfillHTLC * msg) {
4497         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
4498         JNIEnv *env;
4499         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
4500         int8_tArray their_node_id_arr = (*env)->NewByteArray(env, 33);
4501         (*env)->SetByteArrayRegion(env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
4502         LDKUpdateFulfillHTLC msg_var = *msg;
4503         if (msg->inner != NULL)
4504                 msg_var = UpdateFulfillHTLC_clone(msg);
4505         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4506         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4507         long msg_ref = (long)msg_var.inner;
4508         if (msg_var.is_owned) {
4509                 msg_ref |= 1;
4510         }
4511         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
4512         CHECK(obj != NULL);
4513         return (*env)->CallVoidMethod(env, obj, j_calls->handle_update_fulfill_htlc_meth, their_node_id_arr, msg_ref);
4514 }
4515 void handle_update_fail_htlc_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKUpdateFailHTLC * msg) {
4516         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
4517         JNIEnv *env;
4518         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
4519         int8_tArray their_node_id_arr = (*env)->NewByteArray(env, 33);
4520         (*env)->SetByteArrayRegion(env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
4521         LDKUpdateFailHTLC msg_var = *msg;
4522         if (msg->inner != NULL)
4523                 msg_var = UpdateFailHTLC_clone(msg);
4524         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4525         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4526         long msg_ref = (long)msg_var.inner;
4527         if (msg_var.is_owned) {
4528                 msg_ref |= 1;
4529         }
4530         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
4531         CHECK(obj != NULL);
4532         return (*env)->CallVoidMethod(env, obj, j_calls->handle_update_fail_htlc_meth, their_node_id_arr, msg_ref);
4533 }
4534 void handle_update_fail_malformed_htlc_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKUpdateFailMalformedHTLC * msg) {
4535         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
4536         JNIEnv *env;
4537         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
4538         int8_tArray their_node_id_arr = (*env)->NewByteArray(env, 33);
4539         (*env)->SetByteArrayRegion(env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
4540         LDKUpdateFailMalformedHTLC msg_var = *msg;
4541         if (msg->inner != NULL)
4542                 msg_var = UpdateFailMalformedHTLC_clone(msg);
4543         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4544         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4545         long msg_ref = (long)msg_var.inner;
4546         if (msg_var.is_owned) {
4547                 msg_ref |= 1;
4548         }
4549         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
4550         CHECK(obj != NULL);
4551         return (*env)->CallVoidMethod(env, obj, j_calls->handle_update_fail_malformed_htlc_meth, their_node_id_arr, msg_ref);
4552 }
4553 void handle_commitment_signed_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKCommitmentSigned * msg) {
4554         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
4555         JNIEnv *env;
4556         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
4557         int8_tArray their_node_id_arr = (*env)->NewByteArray(env, 33);
4558         (*env)->SetByteArrayRegion(env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
4559         LDKCommitmentSigned msg_var = *msg;
4560         if (msg->inner != NULL)
4561                 msg_var = CommitmentSigned_clone(msg);
4562         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4563         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4564         long msg_ref = (long)msg_var.inner;
4565         if (msg_var.is_owned) {
4566                 msg_ref |= 1;
4567         }
4568         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
4569         CHECK(obj != NULL);
4570         return (*env)->CallVoidMethod(env, obj, j_calls->handle_commitment_signed_meth, their_node_id_arr, msg_ref);
4571 }
4572 void handle_revoke_and_ack_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKRevokeAndACK * msg) {
4573         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
4574         JNIEnv *env;
4575         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
4576         int8_tArray their_node_id_arr = (*env)->NewByteArray(env, 33);
4577         (*env)->SetByteArrayRegion(env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
4578         LDKRevokeAndACK msg_var = *msg;
4579         if (msg->inner != NULL)
4580                 msg_var = RevokeAndACK_clone(msg);
4581         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4582         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4583         long msg_ref = (long)msg_var.inner;
4584         if (msg_var.is_owned) {
4585                 msg_ref |= 1;
4586         }
4587         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
4588         CHECK(obj != NULL);
4589         return (*env)->CallVoidMethod(env, obj, j_calls->handle_revoke_and_ack_meth, their_node_id_arr, msg_ref);
4590 }
4591 void handle_update_fee_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKUpdateFee * msg) {
4592         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
4593         JNIEnv *env;
4594         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
4595         int8_tArray their_node_id_arr = (*env)->NewByteArray(env, 33);
4596         (*env)->SetByteArrayRegion(env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
4597         LDKUpdateFee msg_var = *msg;
4598         if (msg->inner != NULL)
4599                 msg_var = UpdateFee_clone(msg);
4600         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4601         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4602         long msg_ref = (long)msg_var.inner;
4603         if (msg_var.is_owned) {
4604                 msg_ref |= 1;
4605         }
4606         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
4607         CHECK(obj != NULL);
4608         return (*env)->CallVoidMethod(env, obj, j_calls->handle_update_fee_meth, their_node_id_arr, msg_ref);
4609 }
4610 void handle_announcement_signatures_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKAnnouncementSignatures * msg) {
4611         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
4612         JNIEnv *env;
4613         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
4614         int8_tArray their_node_id_arr = (*env)->NewByteArray(env, 33);
4615         (*env)->SetByteArrayRegion(env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
4616         LDKAnnouncementSignatures msg_var = *msg;
4617         if (msg->inner != NULL)
4618                 msg_var = AnnouncementSignatures_clone(msg);
4619         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4620         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4621         long msg_ref = (long)msg_var.inner;
4622         if (msg_var.is_owned) {
4623                 msg_ref |= 1;
4624         }
4625         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
4626         CHECK(obj != NULL);
4627         return (*env)->CallVoidMethod(env, obj, j_calls->handle_announcement_signatures_meth, their_node_id_arr, msg_ref);
4628 }
4629 void peer_disconnected_jcall(const void* this_arg, LDKPublicKey their_node_id, bool no_connection_possible) {
4630         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
4631         JNIEnv *env;
4632         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
4633         int8_tArray their_node_id_arr = (*env)->NewByteArray(env, 33);
4634         (*env)->SetByteArrayRegion(env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
4635         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
4636         CHECK(obj != NULL);
4637         return (*env)->CallVoidMethod(env, obj, j_calls->peer_disconnected_meth, their_node_id_arr, no_connection_possible);
4638 }
4639 void peer_connected_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKInit * msg) {
4640         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
4641         JNIEnv *env;
4642         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
4643         int8_tArray their_node_id_arr = (*env)->NewByteArray(env, 33);
4644         (*env)->SetByteArrayRegion(env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
4645         LDKInit msg_var = *msg;
4646         if (msg->inner != NULL)
4647                 msg_var = Init_clone(msg);
4648         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4649         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4650         long msg_ref = (long)msg_var.inner;
4651         if (msg_var.is_owned) {
4652                 msg_ref |= 1;
4653         }
4654         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
4655         CHECK(obj != NULL);
4656         return (*env)->CallVoidMethod(env, obj, j_calls->peer_connected_meth, their_node_id_arr, msg_ref);
4657 }
4658 void handle_channel_reestablish_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKChannelReestablish * msg) {
4659         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
4660         JNIEnv *env;
4661         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
4662         int8_tArray their_node_id_arr = (*env)->NewByteArray(env, 33);
4663         (*env)->SetByteArrayRegion(env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
4664         LDKChannelReestablish msg_var = *msg;
4665         if (msg->inner != NULL)
4666                 msg_var = ChannelReestablish_clone(msg);
4667         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4668         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4669         long msg_ref = (long)msg_var.inner;
4670         if (msg_var.is_owned) {
4671                 msg_ref |= 1;
4672         }
4673         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
4674         CHECK(obj != NULL);
4675         return (*env)->CallVoidMethod(env, obj, j_calls->handle_channel_reestablish_meth, their_node_id_arr, msg_ref);
4676 }
4677 void handle_error_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKErrorMessage * msg) {
4678         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
4679         JNIEnv *env;
4680         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
4681         int8_tArray their_node_id_arr = (*env)->NewByteArray(env, 33);
4682         (*env)->SetByteArrayRegion(env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
4683         LDKErrorMessage msg_var = *msg;
4684         if (msg->inner != NULL)
4685                 msg_var = ErrorMessage_clone(msg);
4686         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4687         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4688         long msg_ref = (long)msg_var.inner;
4689         if (msg_var.is_owned) {
4690                 msg_ref |= 1;
4691         }
4692         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
4693         CHECK(obj != NULL);
4694         return (*env)->CallVoidMethod(env, obj, j_calls->handle_error_meth, their_node_id_arr, msg_ref);
4695 }
4696 static void* LDKChannelMessageHandler_JCalls_clone(const void* this_arg) {
4697         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
4698         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
4699         atomic_fetch_add_explicit(&j_calls->MessageSendEventsProvider->refcnt, 1, memory_order_release);
4700         return (void*) this_arg;
4701 }
4702 static inline LDKChannelMessageHandler LDKChannelMessageHandler_init (JNIEnv *env, jclass clz, jobject o, jobject MessageSendEventsProvider) {
4703         jclass c = (*env)->GetObjectClass(env, o);
4704         CHECK(c != NULL);
4705         LDKChannelMessageHandler_JCalls *calls = MALLOC(sizeof(LDKChannelMessageHandler_JCalls), "LDKChannelMessageHandler_JCalls");
4706         atomic_init(&calls->refcnt, 1);
4707         DO_ASSERT((*env)->GetJavaVM(env, &calls->vm) == 0);
4708         calls->o = (*env)->NewWeakGlobalRef(env, o);
4709         calls->handle_open_channel_meth = (*env)->GetMethodID(env, c, "handle_open_channel", "([BJJ)V");
4710         CHECK(calls->handle_open_channel_meth != NULL);
4711         calls->handle_accept_channel_meth = (*env)->GetMethodID(env, c, "handle_accept_channel", "([BJJ)V");
4712         CHECK(calls->handle_accept_channel_meth != NULL);
4713         calls->handle_funding_created_meth = (*env)->GetMethodID(env, c, "handle_funding_created", "([BJ)V");
4714         CHECK(calls->handle_funding_created_meth != NULL);
4715         calls->handle_funding_signed_meth = (*env)->GetMethodID(env, c, "handle_funding_signed", "([BJ)V");
4716         CHECK(calls->handle_funding_signed_meth != NULL);
4717         calls->handle_funding_locked_meth = (*env)->GetMethodID(env, c, "handle_funding_locked", "([BJ)V");
4718         CHECK(calls->handle_funding_locked_meth != NULL);
4719         calls->handle_shutdown_meth = (*env)->GetMethodID(env, c, "handle_shutdown", "([BJ)V");
4720         CHECK(calls->handle_shutdown_meth != NULL);
4721         calls->handle_closing_signed_meth = (*env)->GetMethodID(env, c, "handle_closing_signed", "([BJ)V");
4722         CHECK(calls->handle_closing_signed_meth != NULL);
4723         calls->handle_update_add_htlc_meth = (*env)->GetMethodID(env, c, "handle_update_add_htlc", "([BJ)V");
4724         CHECK(calls->handle_update_add_htlc_meth != NULL);
4725         calls->handle_update_fulfill_htlc_meth = (*env)->GetMethodID(env, c, "handle_update_fulfill_htlc", "([BJ)V");
4726         CHECK(calls->handle_update_fulfill_htlc_meth != NULL);
4727         calls->handle_update_fail_htlc_meth = (*env)->GetMethodID(env, c, "handle_update_fail_htlc", "([BJ)V");
4728         CHECK(calls->handle_update_fail_htlc_meth != NULL);
4729         calls->handle_update_fail_malformed_htlc_meth = (*env)->GetMethodID(env, c, "handle_update_fail_malformed_htlc", "([BJ)V");
4730         CHECK(calls->handle_update_fail_malformed_htlc_meth != NULL);
4731         calls->handle_commitment_signed_meth = (*env)->GetMethodID(env, c, "handle_commitment_signed", "([BJ)V");
4732         CHECK(calls->handle_commitment_signed_meth != NULL);
4733         calls->handle_revoke_and_ack_meth = (*env)->GetMethodID(env, c, "handle_revoke_and_ack", "([BJ)V");
4734         CHECK(calls->handle_revoke_and_ack_meth != NULL);
4735         calls->handle_update_fee_meth = (*env)->GetMethodID(env, c, "handle_update_fee", "([BJ)V");
4736         CHECK(calls->handle_update_fee_meth != NULL);
4737         calls->handle_announcement_signatures_meth = (*env)->GetMethodID(env, c, "handle_announcement_signatures", "([BJ)V");
4738         CHECK(calls->handle_announcement_signatures_meth != NULL);
4739         calls->peer_disconnected_meth = (*env)->GetMethodID(env, c, "peer_disconnected", "([BZ)V");
4740         CHECK(calls->peer_disconnected_meth != NULL);
4741         calls->peer_connected_meth = (*env)->GetMethodID(env, c, "peer_connected", "([BJ)V");
4742         CHECK(calls->peer_connected_meth != NULL);
4743         calls->handle_channel_reestablish_meth = (*env)->GetMethodID(env, c, "handle_channel_reestablish", "([BJ)V");
4744         CHECK(calls->handle_channel_reestablish_meth != NULL);
4745         calls->handle_error_meth = (*env)->GetMethodID(env, c, "handle_error", "([BJ)V");
4746         CHECK(calls->handle_error_meth != NULL);
4747
4748         LDKChannelMessageHandler ret = {
4749                 .this_arg = (void*) calls,
4750                 .handle_open_channel = handle_open_channel_jcall,
4751                 .handle_accept_channel = handle_accept_channel_jcall,
4752                 .handle_funding_created = handle_funding_created_jcall,
4753                 .handle_funding_signed = handle_funding_signed_jcall,
4754                 .handle_funding_locked = handle_funding_locked_jcall,
4755                 .handle_shutdown = handle_shutdown_jcall,
4756                 .handle_closing_signed = handle_closing_signed_jcall,
4757                 .handle_update_add_htlc = handle_update_add_htlc_jcall,
4758                 .handle_update_fulfill_htlc = handle_update_fulfill_htlc_jcall,
4759                 .handle_update_fail_htlc = handle_update_fail_htlc_jcall,
4760                 .handle_update_fail_malformed_htlc = handle_update_fail_malformed_htlc_jcall,
4761                 .handle_commitment_signed = handle_commitment_signed_jcall,
4762                 .handle_revoke_and_ack = handle_revoke_and_ack_jcall,
4763                 .handle_update_fee = handle_update_fee_jcall,
4764                 .handle_announcement_signatures = handle_announcement_signatures_jcall,
4765                 .peer_disconnected = peer_disconnected_jcall,
4766                 .peer_connected = peer_connected_jcall,
4767                 .handle_channel_reestablish = handle_channel_reestablish_jcall,
4768                 .handle_error = handle_error_jcall,
4769                 .free = LDKChannelMessageHandler_JCalls_free,
4770                 .MessageSendEventsProvider = LDKMessageSendEventsProvider_init(env, clz, MessageSendEventsProvider),
4771         };
4772         calls->MessageSendEventsProvider = ret.MessageSendEventsProvider.this_arg;
4773         return ret;
4774 }
4775 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_LDKChannelMessageHandler_1new (JNIEnv *env, jclass clz, jobject o, jobject MessageSendEventsProvider) {
4776         LDKChannelMessageHandler *res_ptr = MALLOC(sizeof(LDKChannelMessageHandler), "LDKChannelMessageHandler");
4777         *res_ptr = LDKChannelMessageHandler_init(env, clz, o, MessageSendEventsProvider);
4778         return (long)res_ptr;
4779 }
4780 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKChannelMessageHandler_1get_1obj_1from_1jcalls (JNIEnv *env, jclass clz, int64_t val) {
4781         jobject ret = (*env)->NewLocalRef(env, ((LDKChannelMessageHandler_JCalls*)val)->o);
4782         CHECK(ret != NULL);
4783         return ret;
4784 }
4785 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) {
4786         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
4787         LDKPublicKey their_node_id_ref;
4788         CHECK((*env)->GetArrayLength(env, their_node_id) == 33);
4789         (*env)->GetByteArrayRegion(env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
4790         LDKInitFeatures their_features_conv;
4791         their_features_conv.inner = (void*)(their_features & (~1));
4792         their_features_conv.is_owned = (their_features & 1) || (their_features == 0);
4793         // Warning: we may need a move here but can't clone!
4794         LDKOpenChannel msg_conv;
4795         msg_conv.inner = (void*)(msg & (~1));
4796         msg_conv.is_owned = false;
4797         (this_arg_conv->handle_open_channel)(this_arg_conv->this_arg, their_node_id_ref, their_features_conv, &msg_conv);
4798 }
4799
4800 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) {
4801         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
4802         LDKPublicKey their_node_id_ref;
4803         CHECK((*env)->GetArrayLength(env, their_node_id) == 33);
4804         (*env)->GetByteArrayRegion(env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
4805         LDKInitFeatures their_features_conv;
4806         their_features_conv.inner = (void*)(their_features & (~1));
4807         their_features_conv.is_owned = (their_features & 1) || (their_features == 0);
4808         // Warning: we may need a move here but can't clone!
4809         LDKAcceptChannel msg_conv;
4810         msg_conv.inner = (void*)(msg & (~1));
4811         msg_conv.is_owned = false;
4812         (this_arg_conv->handle_accept_channel)(this_arg_conv->this_arg, their_node_id_ref, their_features_conv, &msg_conv);
4813 }
4814
4815 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) {
4816         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
4817         LDKPublicKey their_node_id_ref;
4818         CHECK((*env)->GetArrayLength(env, their_node_id) == 33);
4819         (*env)->GetByteArrayRegion(env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
4820         LDKFundingCreated msg_conv;
4821         msg_conv.inner = (void*)(msg & (~1));
4822         msg_conv.is_owned = false;
4823         (this_arg_conv->handle_funding_created)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
4824 }
4825
4826 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) {
4827         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
4828         LDKPublicKey their_node_id_ref;
4829         CHECK((*env)->GetArrayLength(env, their_node_id) == 33);
4830         (*env)->GetByteArrayRegion(env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
4831         LDKFundingSigned msg_conv;
4832         msg_conv.inner = (void*)(msg & (~1));
4833         msg_conv.is_owned = false;
4834         (this_arg_conv->handle_funding_signed)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
4835 }
4836
4837 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) {
4838         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
4839         LDKPublicKey their_node_id_ref;
4840         CHECK((*env)->GetArrayLength(env, their_node_id) == 33);
4841         (*env)->GetByteArrayRegion(env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
4842         LDKFundingLocked msg_conv;
4843         msg_conv.inner = (void*)(msg & (~1));
4844         msg_conv.is_owned = false;
4845         (this_arg_conv->handle_funding_locked)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
4846 }
4847
4848 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) {
4849         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
4850         LDKPublicKey their_node_id_ref;
4851         CHECK((*env)->GetArrayLength(env, their_node_id) == 33);
4852         (*env)->GetByteArrayRegion(env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
4853         LDKShutdown msg_conv;
4854         msg_conv.inner = (void*)(msg & (~1));
4855         msg_conv.is_owned = false;
4856         (this_arg_conv->handle_shutdown)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
4857 }
4858
4859 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) {
4860         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
4861         LDKPublicKey their_node_id_ref;
4862         CHECK((*env)->GetArrayLength(env, their_node_id) == 33);
4863         (*env)->GetByteArrayRegion(env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
4864         LDKClosingSigned msg_conv;
4865         msg_conv.inner = (void*)(msg & (~1));
4866         msg_conv.is_owned = false;
4867         (this_arg_conv->handle_closing_signed)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
4868 }
4869
4870 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) {
4871         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
4872         LDKPublicKey their_node_id_ref;
4873         CHECK((*env)->GetArrayLength(env, their_node_id) == 33);
4874         (*env)->GetByteArrayRegion(env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
4875         LDKUpdateAddHTLC msg_conv;
4876         msg_conv.inner = (void*)(msg & (~1));
4877         msg_conv.is_owned = false;
4878         (this_arg_conv->handle_update_add_htlc)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
4879 }
4880
4881 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) {
4882         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
4883         LDKPublicKey their_node_id_ref;
4884         CHECK((*env)->GetArrayLength(env, their_node_id) == 33);
4885         (*env)->GetByteArrayRegion(env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
4886         LDKUpdateFulfillHTLC msg_conv;
4887         msg_conv.inner = (void*)(msg & (~1));
4888         msg_conv.is_owned = false;
4889         (this_arg_conv->handle_update_fulfill_htlc)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
4890 }
4891
4892 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) {
4893         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
4894         LDKPublicKey their_node_id_ref;
4895         CHECK((*env)->GetArrayLength(env, their_node_id) == 33);
4896         (*env)->GetByteArrayRegion(env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
4897         LDKUpdateFailHTLC msg_conv;
4898         msg_conv.inner = (void*)(msg & (~1));
4899         msg_conv.is_owned = false;
4900         (this_arg_conv->handle_update_fail_htlc)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
4901 }
4902
4903 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) {
4904         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
4905         LDKPublicKey their_node_id_ref;
4906         CHECK((*env)->GetArrayLength(env, their_node_id) == 33);
4907         (*env)->GetByteArrayRegion(env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
4908         LDKUpdateFailMalformedHTLC msg_conv;
4909         msg_conv.inner = (void*)(msg & (~1));
4910         msg_conv.is_owned = false;
4911         (this_arg_conv->handle_update_fail_malformed_htlc)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
4912 }
4913
4914 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) {
4915         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
4916         LDKPublicKey their_node_id_ref;
4917         CHECK((*env)->GetArrayLength(env, their_node_id) == 33);
4918         (*env)->GetByteArrayRegion(env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
4919         LDKCommitmentSigned msg_conv;
4920         msg_conv.inner = (void*)(msg & (~1));
4921         msg_conv.is_owned = false;
4922         (this_arg_conv->handle_commitment_signed)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
4923 }
4924
4925 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) {
4926         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
4927         LDKPublicKey their_node_id_ref;
4928         CHECK((*env)->GetArrayLength(env, their_node_id) == 33);
4929         (*env)->GetByteArrayRegion(env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
4930         LDKRevokeAndACK msg_conv;
4931         msg_conv.inner = (void*)(msg & (~1));
4932         msg_conv.is_owned = false;
4933         (this_arg_conv->handle_revoke_and_ack)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
4934 }
4935
4936 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) {
4937         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
4938         LDKPublicKey their_node_id_ref;
4939         CHECK((*env)->GetArrayLength(env, their_node_id) == 33);
4940         (*env)->GetByteArrayRegion(env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
4941         LDKUpdateFee msg_conv;
4942         msg_conv.inner = (void*)(msg & (~1));
4943         msg_conv.is_owned = false;
4944         (this_arg_conv->handle_update_fee)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
4945 }
4946
4947 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) {
4948         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
4949         LDKPublicKey their_node_id_ref;
4950         CHECK((*env)->GetArrayLength(env, their_node_id) == 33);
4951         (*env)->GetByteArrayRegion(env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
4952         LDKAnnouncementSignatures msg_conv;
4953         msg_conv.inner = (void*)(msg & (~1));
4954         msg_conv.is_owned = false;
4955         (this_arg_conv->handle_announcement_signatures)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
4956 }
4957
4958 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) {
4959         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
4960         LDKPublicKey their_node_id_ref;
4961         CHECK((*env)->GetArrayLength(env, their_node_id) == 33);
4962         (*env)->GetByteArrayRegion(env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
4963         (this_arg_conv->peer_disconnected)(this_arg_conv->this_arg, their_node_id_ref, no_connection_possible);
4964 }
4965
4966 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) {
4967         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
4968         LDKPublicKey their_node_id_ref;
4969         CHECK((*env)->GetArrayLength(env, their_node_id) == 33);
4970         (*env)->GetByteArrayRegion(env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
4971         LDKInit msg_conv;
4972         msg_conv.inner = (void*)(msg & (~1));
4973         msg_conv.is_owned = false;
4974         (this_arg_conv->peer_connected)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
4975 }
4976
4977 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) {
4978         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
4979         LDKPublicKey their_node_id_ref;
4980         CHECK((*env)->GetArrayLength(env, their_node_id) == 33);
4981         (*env)->GetByteArrayRegion(env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
4982         LDKChannelReestablish msg_conv;
4983         msg_conv.inner = (void*)(msg & (~1));
4984         msg_conv.is_owned = false;
4985         (this_arg_conv->handle_channel_reestablish)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
4986 }
4987
4988 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) {
4989         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
4990         LDKPublicKey their_node_id_ref;
4991         CHECK((*env)->GetArrayLength(env, their_node_id) == 33);
4992         (*env)->GetByteArrayRegion(env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
4993         LDKErrorMessage msg_conv;
4994         msg_conv.inner = (void*)(msg & (~1));
4995         msg_conv.is_owned = false;
4996         (this_arg_conv->handle_error)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
4997 }
4998
4999 typedef struct LDKRoutingMessageHandler_JCalls {
5000         atomic_size_t refcnt;
5001         JavaVM *vm;
5002         jweak o;
5003         LDKMessageSendEventsProvider_JCalls* MessageSendEventsProvider;
5004         jmethodID handle_node_announcement_meth;
5005         jmethodID handle_channel_announcement_meth;
5006         jmethodID handle_channel_update_meth;
5007         jmethodID handle_htlc_fail_channel_update_meth;
5008         jmethodID get_next_channel_announcements_meth;
5009         jmethodID get_next_node_announcements_meth;
5010         jmethodID sync_routing_table_meth;
5011         jmethodID handle_reply_channel_range_meth;
5012         jmethodID handle_reply_short_channel_ids_end_meth;
5013         jmethodID handle_query_channel_range_meth;
5014         jmethodID handle_query_short_channel_ids_meth;
5015 } LDKRoutingMessageHandler_JCalls;
5016 static void LDKRoutingMessageHandler_JCalls_free(void* this_arg) {
5017         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
5018         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
5019                 JNIEnv *env;
5020                 DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
5021                 (*env)->DeleteWeakGlobalRef(env, j_calls->o);
5022                 FREE(j_calls);
5023         }
5024 }
5025 LDKCResult_boolLightningErrorZ handle_node_announcement_jcall(const void* this_arg, const LDKNodeAnnouncement * msg) {
5026         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
5027         JNIEnv *env;
5028         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
5029         LDKNodeAnnouncement msg_var = *msg;
5030         if (msg->inner != NULL)
5031                 msg_var = NodeAnnouncement_clone(msg);
5032         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
5033         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
5034         long msg_ref = (long)msg_var.inner;
5035         if (msg_var.is_owned) {
5036                 msg_ref |= 1;
5037         }
5038         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
5039         CHECK(obj != NULL);
5040         LDKCResult_boolLightningErrorZ* ret = (LDKCResult_boolLightningErrorZ*)(*env)->CallLongMethod(env, obj, j_calls->handle_node_announcement_meth, msg_ref);
5041         LDKCResult_boolLightningErrorZ ret_conv = *(LDKCResult_boolLightningErrorZ*)ret;
5042         FREE((void*)ret);
5043         return ret_conv;
5044 }
5045 LDKCResult_boolLightningErrorZ handle_channel_announcement_jcall(const void* this_arg, const LDKChannelAnnouncement * msg) {
5046         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
5047         JNIEnv *env;
5048         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
5049         LDKChannelAnnouncement msg_var = *msg;
5050         if (msg->inner != NULL)
5051                 msg_var = ChannelAnnouncement_clone(msg);
5052         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
5053         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
5054         long msg_ref = (long)msg_var.inner;
5055         if (msg_var.is_owned) {
5056                 msg_ref |= 1;
5057         }
5058         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
5059         CHECK(obj != NULL);
5060         LDKCResult_boolLightningErrorZ* ret = (LDKCResult_boolLightningErrorZ*)(*env)->CallLongMethod(env, obj, j_calls->handle_channel_announcement_meth, msg_ref);
5061         LDKCResult_boolLightningErrorZ ret_conv = *(LDKCResult_boolLightningErrorZ*)ret;
5062         FREE((void*)ret);
5063         return ret_conv;
5064 }
5065 LDKCResult_boolLightningErrorZ handle_channel_update_jcall(const void* this_arg, const LDKChannelUpdate * msg) {
5066         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
5067         JNIEnv *env;
5068         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
5069         LDKChannelUpdate msg_var = *msg;
5070         if (msg->inner != NULL)
5071                 msg_var = ChannelUpdate_clone(msg);
5072         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
5073         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
5074         long msg_ref = (long)msg_var.inner;
5075         if (msg_var.is_owned) {
5076                 msg_ref |= 1;
5077         }
5078         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
5079         CHECK(obj != NULL);
5080         LDKCResult_boolLightningErrorZ* ret = (LDKCResult_boolLightningErrorZ*)(*env)->CallLongMethod(env, obj, j_calls->handle_channel_update_meth, msg_ref);
5081         LDKCResult_boolLightningErrorZ ret_conv = *(LDKCResult_boolLightningErrorZ*)ret;
5082         FREE((void*)ret);
5083         return ret_conv;
5084 }
5085 void handle_htlc_fail_channel_update_jcall(const void* this_arg, const LDKHTLCFailChannelUpdate * update) {
5086         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
5087         JNIEnv *env;
5088         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
5089         long ret_update = (long)update;
5090         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
5091         CHECK(obj != NULL);
5092         return (*env)->CallVoidMethod(env, obj, j_calls->handle_htlc_fail_channel_update_meth, ret_update);
5093 }
5094 LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ get_next_channel_announcements_jcall(const void* this_arg, uint64_t starting_point, uint8_t batch_amount) {
5095         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
5096         JNIEnv *env;
5097         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
5098         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
5099         CHECK(obj != NULL);
5100         int64_tArray arg = (*env)->CallObjectMethod(env, obj, j_calls->get_next_channel_announcements_meth, starting_point, batch_amount);
5101         LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ arg_constr;
5102         arg_constr.datalen = (*env)->GetArrayLength(env, arg);
5103         if (arg_constr.datalen > 0)
5104                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ), "LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ Elements");
5105         else
5106                 arg_constr.data = NULL;
5107         int64_t* arg_vals = (*env)->GetLongArrayElements (env, arg, NULL);
5108         for (size_t l = 0; l < arg_constr.datalen; l++) {
5109                 int64_t arr_conv_63 = arg_vals[l];
5110                 LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ arr_conv_63_conv = *(LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ*)arr_conv_63;
5111                 FREE((void*)arr_conv_63);
5112                 arg_constr.data[l] = arr_conv_63_conv;
5113         }
5114         (*env)->ReleaseLongArrayElements(env, arg, arg_vals, 0);
5115         return arg_constr;
5116 }
5117 LDKCVec_NodeAnnouncementZ get_next_node_announcements_jcall(const void* this_arg, LDKPublicKey starting_point, uint8_t batch_amount) {
5118         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
5119         JNIEnv *env;
5120         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
5121         int8_tArray starting_point_arr = (*env)->NewByteArray(env, 33);
5122         (*env)->SetByteArrayRegion(env, starting_point_arr, 0, 33, starting_point.compressed_form);
5123         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
5124         CHECK(obj != NULL);
5125         int64_tArray arg = (*env)->CallObjectMethod(env, obj, j_calls->get_next_node_announcements_meth, starting_point_arr, batch_amount);
5126         LDKCVec_NodeAnnouncementZ arg_constr;
5127         arg_constr.datalen = (*env)->GetArrayLength(env, arg);
5128         if (arg_constr.datalen > 0)
5129                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKNodeAnnouncement), "LDKCVec_NodeAnnouncementZ Elements");
5130         else
5131                 arg_constr.data = NULL;
5132         int64_t* arg_vals = (*env)->GetLongArrayElements (env, arg, NULL);
5133         for (size_t s = 0; s < arg_constr.datalen; s++) {
5134                 int64_t arr_conv_18 = arg_vals[s];
5135                 LDKNodeAnnouncement arr_conv_18_conv;
5136                 arr_conv_18_conv.inner = (void*)(arr_conv_18 & (~1));
5137                 arr_conv_18_conv.is_owned = (arr_conv_18 & 1) || (arr_conv_18 == 0);
5138                 if (arr_conv_18_conv.inner != NULL)
5139                         arr_conv_18_conv = NodeAnnouncement_clone(&arr_conv_18_conv);
5140                 arg_constr.data[s] = arr_conv_18_conv;
5141         }
5142         (*env)->ReleaseLongArrayElements(env, arg, arg_vals, 0);
5143         return arg_constr;
5144 }
5145 void sync_routing_table_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKInit * init) {
5146         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
5147         JNIEnv *env;
5148         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
5149         int8_tArray their_node_id_arr = (*env)->NewByteArray(env, 33);
5150         (*env)->SetByteArrayRegion(env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
5151         LDKInit init_var = *init;
5152         if (init->inner != NULL)
5153                 init_var = Init_clone(init);
5154         CHECK((((long)init_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
5155         CHECK((((long)&init_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
5156         long init_ref = (long)init_var.inner;
5157         if (init_var.is_owned) {
5158                 init_ref |= 1;
5159         }
5160         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
5161         CHECK(obj != NULL);
5162         return (*env)->CallVoidMethod(env, obj, j_calls->sync_routing_table_meth, their_node_id_arr, init_ref);
5163 }
5164 LDKCResult_NoneLightningErrorZ handle_reply_channel_range_jcall(const void* this_arg, LDKPublicKey their_node_id, LDKReplyChannelRange msg) {
5165         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
5166         JNIEnv *env;
5167         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
5168         int8_tArray their_node_id_arr = (*env)->NewByteArray(env, 33);
5169         (*env)->SetByteArrayRegion(env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
5170         LDKReplyChannelRange msg_var = msg;
5171         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
5172         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
5173         long msg_ref = (long)msg_var.inner;
5174         if (msg_var.is_owned) {
5175                 msg_ref |= 1;
5176         }
5177         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
5178         CHECK(obj != NULL);
5179         LDKCResult_NoneLightningErrorZ* ret = (LDKCResult_NoneLightningErrorZ*)(*env)->CallLongMethod(env, obj, j_calls->handle_reply_channel_range_meth, their_node_id_arr, msg_ref);
5180         LDKCResult_NoneLightningErrorZ ret_conv = *(LDKCResult_NoneLightningErrorZ*)ret;
5181         FREE((void*)ret);
5182         return ret_conv;
5183 }
5184 LDKCResult_NoneLightningErrorZ handle_reply_short_channel_ids_end_jcall(const void* this_arg, LDKPublicKey their_node_id, LDKReplyShortChannelIdsEnd msg) {
5185         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
5186         JNIEnv *env;
5187         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
5188         int8_tArray their_node_id_arr = (*env)->NewByteArray(env, 33);
5189         (*env)->SetByteArrayRegion(env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
5190         LDKReplyShortChannelIdsEnd msg_var = msg;
5191         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
5192         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
5193         long msg_ref = (long)msg_var.inner;
5194         if (msg_var.is_owned) {
5195                 msg_ref |= 1;
5196         }
5197         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
5198         CHECK(obj != NULL);
5199         LDKCResult_NoneLightningErrorZ* ret = (LDKCResult_NoneLightningErrorZ*)(*env)->CallLongMethod(env, obj, j_calls->handle_reply_short_channel_ids_end_meth, their_node_id_arr, msg_ref);
5200         LDKCResult_NoneLightningErrorZ ret_conv = *(LDKCResult_NoneLightningErrorZ*)ret;
5201         FREE((void*)ret);
5202         return ret_conv;
5203 }
5204 LDKCResult_NoneLightningErrorZ handle_query_channel_range_jcall(const void* this_arg, LDKPublicKey their_node_id, LDKQueryChannelRange msg) {
5205         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
5206         JNIEnv *env;
5207         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
5208         int8_tArray their_node_id_arr = (*env)->NewByteArray(env, 33);
5209         (*env)->SetByteArrayRegion(env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
5210         LDKQueryChannelRange msg_var = msg;
5211         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
5212         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
5213         long msg_ref = (long)msg_var.inner;
5214         if (msg_var.is_owned) {
5215                 msg_ref |= 1;
5216         }
5217         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
5218         CHECK(obj != NULL);
5219         LDKCResult_NoneLightningErrorZ* ret = (LDKCResult_NoneLightningErrorZ*)(*env)->CallLongMethod(env, obj, j_calls->handle_query_channel_range_meth, their_node_id_arr, msg_ref);
5220         LDKCResult_NoneLightningErrorZ ret_conv = *(LDKCResult_NoneLightningErrorZ*)ret;
5221         FREE((void*)ret);
5222         return ret_conv;
5223 }
5224 LDKCResult_NoneLightningErrorZ handle_query_short_channel_ids_jcall(const void* this_arg, LDKPublicKey their_node_id, LDKQueryShortChannelIds msg) {
5225         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
5226         JNIEnv *env;
5227         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
5228         int8_tArray their_node_id_arr = (*env)->NewByteArray(env, 33);
5229         (*env)->SetByteArrayRegion(env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
5230         LDKQueryShortChannelIds msg_var = msg;
5231         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
5232         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
5233         long msg_ref = (long)msg_var.inner;
5234         if (msg_var.is_owned) {
5235                 msg_ref |= 1;
5236         }
5237         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
5238         CHECK(obj != NULL);
5239         LDKCResult_NoneLightningErrorZ* ret = (LDKCResult_NoneLightningErrorZ*)(*env)->CallLongMethod(env, obj, j_calls->handle_query_short_channel_ids_meth, their_node_id_arr, msg_ref);
5240         LDKCResult_NoneLightningErrorZ ret_conv = *(LDKCResult_NoneLightningErrorZ*)ret;
5241         FREE((void*)ret);
5242         return ret_conv;
5243 }
5244 static void* LDKRoutingMessageHandler_JCalls_clone(const void* this_arg) {
5245         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
5246         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
5247         atomic_fetch_add_explicit(&j_calls->MessageSendEventsProvider->refcnt, 1, memory_order_release);
5248         return (void*) this_arg;
5249 }
5250 static inline LDKRoutingMessageHandler LDKRoutingMessageHandler_init (JNIEnv *env, jclass clz, jobject o, jobject MessageSendEventsProvider) {
5251         jclass c = (*env)->GetObjectClass(env, o);
5252         CHECK(c != NULL);
5253         LDKRoutingMessageHandler_JCalls *calls = MALLOC(sizeof(LDKRoutingMessageHandler_JCalls), "LDKRoutingMessageHandler_JCalls");
5254         atomic_init(&calls->refcnt, 1);
5255         DO_ASSERT((*env)->GetJavaVM(env, &calls->vm) == 0);
5256         calls->o = (*env)->NewWeakGlobalRef(env, o);
5257         calls->handle_node_announcement_meth = (*env)->GetMethodID(env, c, "handle_node_announcement", "(J)J");
5258         CHECK(calls->handle_node_announcement_meth != NULL);
5259         calls->handle_channel_announcement_meth = (*env)->GetMethodID(env, c, "handle_channel_announcement", "(J)J");
5260         CHECK(calls->handle_channel_announcement_meth != NULL);
5261         calls->handle_channel_update_meth = (*env)->GetMethodID(env, c, "handle_channel_update", "(J)J");
5262         CHECK(calls->handle_channel_update_meth != NULL);
5263         calls->handle_htlc_fail_channel_update_meth = (*env)->GetMethodID(env, c, "handle_htlc_fail_channel_update", "(J)V");
5264         CHECK(calls->handle_htlc_fail_channel_update_meth != NULL);
5265         calls->get_next_channel_announcements_meth = (*env)->GetMethodID(env, c, "get_next_channel_announcements", "(JB)[J");
5266         CHECK(calls->get_next_channel_announcements_meth != NULL);
5267         calls->get_next_node_announcements_meth = (*env)->GetMethodID(env, c, "get_next_node_announcements", "([BB)[J");
5268         CHECK(calls->get_next_node_announcements_meth != NULL);
5269         calls->sync_routing_table_meth = (*env)->GetMethodID(env, c, "sync_routing_table", "([BJ)V");
5270         CHECK(calls->sync_routing_table_meth != NULL);
5271         calls->handle_reply_channel_range_meth = (*env)->GetMethodID(env, c, "handle_reply_channel_range", "([BJ)J");
5272         CHECK(calls->handle_reply_channel_range_meth != NULL);
5273         calls->handle_reply_short_channel_ids_end_meth = (*env)->GetMethodID(env, c, "handle_reply_short_channel_ids_end", "([BJ)J");
5274         CHECK(calls->handle_reply_short_channel_ids_end_meth != NULL);
5275         calls->handle_query_channel_range_meth = (*env)->GetMethodID(env, c, "handle_query_channel_range", "([BJ)J");
5276         CHECK(calls->handle_query_channel_range_meth != NULL);
5277         calls->handle_query_short_channel_ids_meth = (*env)->GetMethodID(env, c, "handle_query_short_channel_ids", "([BJ)J");
5278         CHECK(calls->handle_query_short_channel_ids_meth != NULL);
5279
5280         LDKRoutingMessageHandler ret = {
5281                 .this_arg = (void*) calls,
5282                 .handle_node_announcement = handle_node_announcement_jcall,
5283                 .handle_channel_announcement = handle_channel_announcement_jcall,
5284                 .handle_channel_update = handle_channel_update_jcall,
5285                 .handle_htlc_fail_channel_update = handle_htlc_fail_channel_update_jcall,
5286                 .get_next_channel_announcements = get_next_channel_announcements_jcall,
5287                 .get_next_node_announcements = get_next_node_announcements_jcall,
5288                 .sync_routing_table = sync_routing_table_jcall,
5289                 .handle_reply_channel_range = handle_reply_channel_range_jcall,
5290                 .handle_reply_short_channel_ids_end = handle_reply_short_channel_ids_end_jcall,
5291                 .handle_query_channel_range = handle_query_channel_range_jcall,
5292                 .handle_query_short_channel_ids = handle_query_short_channel_ids_jcall,
5293                 .free = LDKRoutingMessageHandler_JCalls_free,
5294                 .MessageSendEventsProvider = LDKMessageSendEventsProvider_init(env, clz, MessageSendEventsProvider),
5295         };
5296         calls->MessageSendEventsProvider = ret.MessageSendEventsProvider.this_arg;
5297         return ret;
5298 }
5299 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_LDKRoutingMessageHandler_1new (JNIEnv *env, jclass clz, jobject o, jobject MessageSendEventsProvider) {
5300         LDKRoutingMessageHandler *res_ptr = MALLOC(sizeof(LDKRoutingMessageHandler), "LDKRoutingMessageHandler");
5301         *res_ptr = LDKRoutingMessageHandler_init(env, clz, o, MessageSendEventsProvider);
5302         return (long)res_ptr;
5303 }
5304 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKRoutingMessageHandler_1get_1obj_1from_1jcalls (JNIEnv *env, jclass clz, int64_t val) {
5305         jobject ret = (*env)->NewLocalRef(env, ((LDKRoutingMessageHandler_JCalls*)val)->o);
5306         CHECK(ret != NULL);
5307         return ret;
5308 }
5309 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_RoutingMessageHandler_1handle_1node_1announcement(JNIEnv *env, jclass clz, int64_t this_arg, int64_t msg) {
5310         LDKRoutingMessageHandler* this_arg_conv = (LDKRoutingMessageHandler*)this_arg;
5311         LDKNodeAnnouncement msg_conv;
5312         msg_conv.inner = (void*)(msg & (~1));
5313         msg_conv.is_owned = false;
5314         LDKCResult_boolLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_boolLightningErrorZ), "LDKCResult_boolLightningErrorZ");
5315         *ret_conv = (this_arg_conv->handle_node_announcement)(this_arg_conv->this_arg, &msg_conv);
5316         return (long)ret_conv;
5317 }
5318
5319 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_RoutingMessageHandler_1handle_1channel_1announcement(JNIEnv *env, jclass clz, int64_t this_arg, int64_t msg) {
5320         LDKRoutingMessageHandler* this_arg_conv = (LDKRoutingMessageHandler*)this_arg;
5321         LDKChannelAnnouncement msg_conv;
5322         msg_conv.inner = (void*)(msg & (~1));
5323         msg_conv.is_owned = false;
5324         LDKCResult_boolLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_boolLightningErrorZ), "LDKCResult_boolLightningErrorZ");
5325         *ret_conv = (this_arg_conv->handle_channel_announcement)(this_arg_conv->this_arg, &msg_conv);
5326         return (long)ret_conv;
5327 }
5328
5329 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_RoutingMessageHandler_1handle_1channel_1update(JNIEnv *env, jclass clz, int64_t this_arg, int64_t msg) {
5330         LDKRoutingMessageHandler* this_arg_conv = (LDKRoutingMessageHandler*)this_arg;
5331         LDKChannelUpdate msg_conv;
5332         msg_conv.inner = (void*)(msg & (~1));
5333         msg_conv.is_owned = false;
5334         LDKCResult_boolLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_boolLightningErrorZ), "LDKCResult_boolLightningErrorZ");
5335         *ret_conv = (this_arg_conv->handle_channel_update)(this_arg_conv->this_arg, &msg_conv);
5336         return (long)ret_conv;
5337 }
5338
5339 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) {
5340         LDKRoutingMessageHandler* this_arg_conv = (LDKRoutingMessageHandler*)this_arg;
5341         LDKHTLCFailChannelUpdate* update_conv = (LDKHTLCFailChannelUpdate*)update;
5342         (this_arg_conv->handle_htlc_fail_channel_update)(this_arg_conv->this_arg, update_conv);
5343 }
5344
5345 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) {
5346         LDKRoutingMessageHandler* this_arg_conv = (LDKRoutingMessageHandler*)this_arg;
5347         LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ ret_var = (this_arg_conv->get_next_channel_announcements)(this_arg_conv->this_arg, starting_point, batch_amount);
5348         int64_tArray ret_arr = (*env)->NewLongArray(env, ret_var.datalen);
5349         int64_t *ret_arr_ptr = (*env)->GetPrimitiveArrayCritical(env, ret_arr, NULL);
5350         for (size_t l = 0; l < ret_var.datalen; l++) {
5351                 LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ* arr_conv_63_ref = MALLOC(sizeof(LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ), "LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ");
5352                 *arr_conv_63_ref = ret_var.data[l];
5353                 arr_conv_63_ref->a = ChannelAnnouncement_clone(&arr_conv_63_ref->a);
5354                 arr_conv_63_ref->b = ChannelUpdate_clone(&arr_conv_63_ref->b);
5355                 arr_conv_63_ref->c = ChannelUpdate_clone(&arr_conv_63_ref->c);
5356                 ret_arr_ptr[l] = (long)arr_conv_63_ref;
5357         }
5358         (*env)->ReleasePrimitiveArrayCritical(env, ret_arr, ret_arr_ptr, 0);
5359         FREE(ret_var.data);
5360         return ret_arr;
5361 }
5362
5363 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) {
5364         LDKRoutingMessageHandler* this_arg_conv = (LDKRoutingMessageHandler*)this_arg;
5365         LDKPublicKey starting_point_ref;
5366         CHECK((*env)->GetArrayLength(env, starting_point) == 33);
5367         (*env)->GetByteArrayRegion(env, starting_point, 0, 33, starting_point_ref.compressed_form);
5368         LDKCVec_NodeAnnouncementZ ret_var = (this_arg_conv->get_next_node_announcements)(this_arg_conv->this_arg, starting_point_ref, batch_amount);
5369         int64_tArray ret_arr = (*env)->NewLongArray(env, ret_var.datalen);
5370         int64_t *ret_arr_ptr = (*env)->GetPrimitiveArrayCritical(env, ret_arr, NULL);
5371         for (size_t s = 0; s < ret_var.datalen; s++) {
5372                 LDKNodeAnnouncement arr_conv_18_var = ret_var.data[s];
5373                 CHECK((((long)arr_conv_18_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
5374                 CHECK((((long)&arr_conv_18_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
5375                 long arr_conv_18_ref = (long)arr_conv_18_var.inner;
5376                 if (arr_conv_18_var.is_owned) {
5377                         arr_conv_18_ref |= 1;
5378                 }
5379                 ret_arr_ptr[s] = arr_conv_18_ref;
5380         }
5381         (*env)->ReleasePrimitiveArrayCritical(env, ret_arr, ret_arr_ptr, 0);
5382         FREE(ret_var.data);
5383         return ret_arr;
5384 }
5385
5386 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) {
5387         LDKRoutingMessageHandler* this_arg_conv = (LDKRoutingMessageHandler*)this_arg;
5388         LDKPublicKey their_node_id_ref;
5389         CHECK((*env)->GetArrayLength(env, their_node_id) == 33);
5390         (*env)->GetByteArrayRegion(env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
5391         LDKInit init_conv;
5392         init_conv.inner = (void*)(init & (~1));
5393         init_conv.is_owned = false;
5394         (this_arg_conv->sync_routing_table)(this_arg_conv->this_arg, their_node_id_ref, &init_conv);
5395 }
5396
5397 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) {
5398         LDKRoutingMessageHandler* this_arg_conv = (LDKRoutingMessageHandler*)this_arg;
5399         LDKPublicKey their_node_id_ref;
5400         CHECK((*env)->GetArrayLength(env, their_node_id) == 33);
5401         (*env)->GetByteArrayRegion(env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
5402         LDKReplyChannelRange msg_conv;
5403         msg_conv.inner = (void*)(msg & (~1));
5404         msg_conv.is_owned = (msg & 1) || (msg == 0);
5405         if (msg_conv.inner != NULL)
5406                 msg_conv = ReplyChannelRange_clone(&msg_conv);
5407         LDKCResult_NoneLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneLightningErrorZ), "LDKCResult_NoneLightningErrorZ");
5408         *ret_conv = (this_arg_conv->handle_reply_channel_range)(this_arg_conv->this_arg, their_node_id_ref, msg_conv);
5409         return (long)ret_conv;
5410 }
5411
5412 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) {
5413         LDKRoutingMessageHandler* this_arg_conv = (LDKRoutingMessageHandler*)this_arg;
5414         LDKPublicKey their_node_id_ref;
5415         CHECK((*env)->GetArrayLength(env, their_node_id) == 33);
5416         (*env)->GetByteArrayRegion(env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
5417         LDKReplyShortChannelIdsEnd msg_conv;
5418         msg_conv.inner = (void*)(msg & (~1));
5419         msg_conv.is_owned = (msg & 1) || (msg == 0);
5420         if (msg_conv.inner != NULL)
5421                 msg_conv = ReplyShortChannelIdsEnd_clone(&msg_conv);
5422         LDKCResult_NoneLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneLightningErrorZ), "LDKCResult_NoneLightningErrorZ");
5423         *ret_conv = (this_arg_conv->handle_reply_short_channel_ids_end)(this_arg_conv->this_arg, their_node_id_ref, msg_conv);
5424         return (long)ret_conv;
5425 }
5426
5427 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) {
5428         LDKRoutingMessageHandler* this_arg_conv = (LDKRoutingMessageHandler*)this_arg;
5429         LDKPublicKey their_node_id_ref;
5430         CHECK((*env)->GetArrayLength(env, their_node_id) == 33);
5431         (*env)->GetByteArrayRegion(env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
5432         LDKQueryChannelRange msg_conv;
5433         msg_conv.inner = (void*)(msg & (~1));
5434         msg_conv.is_owned = (msg & 1) || (msg == 0);
5435         if (msg_conv.inner != NULL)
5436                 msg_conv = QueryChannelRange_clone(&msg_conv);
5437         LDKCResult_NoneLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneLightningErrorZ), "LDKCResult_NoneLightningErrorZ");
5438         *ret_conv = (this_arg_conv->handle_query_channel_range)(this_arg_conv->this_arg, their_node_id_ref, msg_conv);
5439         return (long)ret_conv;
5440 }
5441
5442 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) {
5443         LDKRoutingMessageHandler* this_arg_conv = (LDKRoutingMessageHandler*)this_arg;
5444         LDKPublicKey their_node_id_ref;
5445         CHECK((*env)->GetArrayLength(env, their_node_id) == 33);
5446         (*env)->GetByteArrayRegion(env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
5447         LDKQueryShortChannelIds msg_conv;
5448         msg_conv.inner = (void*)(msg & (~1));
5449         msg_conv.is_owned = (msg & 1) || (msg == 0);
5450         if (msg_conv.inner != NULL)
5451                 msg_conv = QueryShortChannelIds_clone(&msg_conv);
5452         LDKCResult_NoneLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneLightningErrorZ), "LDKCResult_NoneLightningErrorZ");
5453         *ret_conv = (this_arg_conv->handle_query_short_channel_ids)(this_arg_conv->this_arg, their_node_id_ref, msg_conv);
5454         return (long)ret_conv;
5455 }
5456
5457 typedef struct LDKSocketDescriptor_JCalls {
5458         atomic_size_t refcnt;
5459         JavaVM *vm;
5460         jweak o;
5461         jmethodID send_data_meth;
5462         jmethodID disconnect_socket_meth;
5463         jmethodID eq_meth;
5464         jmethodID hash_meth;
5465 } LDKSocketDescriptor_JCalls;
5466 static void LDKSocketDescriptor_JCalls_free(void* this_arg) {
5467         LDKSocketDescriptor_JCalls *j_calls = (LDKSocketDescriptor_JCalls*) this_arg;
5468         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
5469                 JNIEnv *env;
5470                 DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
5471                 (*env)->DeleteWeakGlobalRef(env, j_calls->o);
5472                 FREE(j_calls);
5473         }
5474 }
5475 uint64_t send_data_jcall(void* this_arg, LDKu8slice data, bool resume_read) {
5476         LDKSocketDescriptor_JCalls *j_calls = (LDKSocketDescriptor_JCalls*) this_arg;
5477         JNIEnv *env;
5478         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
5479         LDKu8slice data_var = data;
5480         int8_tArray data_arr = (*env)->NewByteArray(env, data_var.datalen);
5481         (*env)->SetByteArrayRegion(env, data_arr, 0, data_var.datalen, data_var.data);
5482         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
5483         CHECK(obj != NULL);
5484         return (*env)->CallLongMethod(env, obj, j_calls->send_data_meth, data_arr, resume_read);
5485 }
5486 void disconnect_socket_jcall(void* this_arg) {
5487         LDKSocketDescriptor_JCalls *j_calls = (LDKSocketDescriptor_JCalls*) this_arg;
5488         JNIEnv *env;
5489         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
5490         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
5491         CHECK(obj != NULL);
5492         return (*env)->CallVoidMethod(env, obj, j_calls->disconnect_socket_meth);
5493 }
5494 bool eq_jcall(const void* this_arg, const LDKSocketDescriptor * other_arg) {
5495         LDKSocketDescriptor_JCalls *j_calls = (LDKSocketDescriptor_JCalls*) this_arg;
5496         JNIEnv *env;
5497         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
5498         LDKSocketDescriptor *other_arg_clone = MALLOC(sizeof(LDKSocketDescriptor), "LDKSocketDescriptor");
5499         *other_arg_clone = SocketDescriptor_clone(other_arg);
5500         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
5501         CHECK(obj != NULL);
5502         return (*env)->CallBooleanMethod(env, obj, j_calls->eq_meth, (long)other_arg_clone);
5503 }
5504 uint64_t hash_jcall(const void* this_arg) {
5505         LDKSocketDescriptor_JCalls *j_calls = (LDKSocketDescriptor_JCalls*) this_arg;
5506         JNIEnv *env;
5507         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
5508         jobject obj = (*env)->NewLocalRef(env, j_calls->o);
5509         CHECK(obj != NULL);
5510         return (*env)->CallLongMethod(env, obj, j_calls->hash_meth);
5511 }
5512 static void* LDKSocketDescriptor_JCalls_clone(const void* this_arg) {
5513         LDKSocketDescriptor_JCalls *j_calls = (LDKSocketDescriptor_JCalls*) this_arg;
5514         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
5515         return (void*) this_arg;
5516 }
5517 static inline LDKSocketDescriptor LDKSocketDescriptor_init (JNIEnv *env, jclass clz, jobject o) {
5518         jclass c = (*env)->GetObjectClass(env, o);
5519         CHECK(c != NULL);
5520         LDKSocketDescriptor_JCalls *calls = MALLOC(sizeof(LDKSocketDescriptor_JCalls), "LDKSocketDescriptor_JCalls");
5521         atomic_init(&calls->refcnt, 1);
5522         DO_ASSERT((*env)->GetJavaVM(env, &calls->vm) == 0);
5523         calls->o = (*env)->NewWeakGlobalRef(env, o);
5524         calls->send_data_meth = (*env)->GetMethodID(env, c, "send_data", "([BZ)J");
5525         CHECK(calls->send_data_meth != NULL);
5526         calls->disconnect_socket_meth = (*env)->GetMethodID(env, c, "disconnect_socket", "()V");
5527         CHECK(calls->disconnect_socket_meth != NULL);
5528         calls->eq_meth = (*env)->GetMethodID(env, c, "eq", "(J)Z");
5529         CHECK(calls->eq_meth != NULL);
5530         calls->hash_meth = (*env)->GetMethodID(env, c, "hash", "()J");
5531         CHECK(calls->hash_meth != NULL);
5532
5533         LDKSocketDescriptor ret = {
5534                 .this_arg = (void*) calls,
5535                 .send_data = send_data_jcall,
5536                 .disconnect_socket = disconnect_socket_jcall,
5537                 .eq = eq_jcall,
5538                 .hash = hash_jcall,
5539                 .clone = LDKSocketDescriptor_JCalls_clone,
5540                 .free = LDKSocketDescriptor_JCalls_free,
5541         };
5542         return ret;
5543 }
5544 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_LDKSocketDescriptor_1new (JNIEnv *env, jclass clz, jobject o) {
5545         LDKSocketDescriptor *res_ptr = MALLOC(sizeof(LDKSocketDescriptor), "LDKSocketDescriptor");
5546         *res_ptr = LDKSocketDescriptor_init(env, clz, o);
5547         return (long)res_ptr;
5548 }
5549 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKSocketDescriptor_1get_1obj_1from_1jcalls (JNIEnv *env, jclass clz, int64_t val) {
5550         jobject ret = (*env)->NewLocalRef(env, ((LDKSocketDescriptor_JCalls*)val)->o);
5551         CHECK(ret != NULL);
5552         return ret;
5553 }
5554 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_SocketDescriptor_1send_1data(JNIEnv *env, jclass clz, int64_t this_arg, int8_tArray data, jboolean resume_read) {
5555         LDKSocketDescriptor* this_arg_conv = (LDKSocketDescriptor*)this_arg;
5556         LDKu8slice data_ref;
5557         data_ref.datalen = (*env)->GetArrayLength(env, data);
5558         data_ref.data = (*env)->GetByteArrayElements (env, data, NULL);
5559         int64_t ret_val = (this_arg_conv->send_data)(this_arg_conv->this_arg, data_ref, resume_read);
5560         (*env)->ReleaseByteArrayElements(env, data, (int8_t*)data_ref.data, 0);
5561         return ret_val;
5562 }
5563
5564 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_SocketDescriptor_1disconnect_1socket(JNIEnv *env, jclass clz, int64_t this_arg) {
5565         LDKSocketDescriptor* this_arg_conv = (LDKSocketDescriptor*)this_arg;
5566         (this_arg_conv->disconnect_socket)(this_arg_conv->this_arg);
5567 }
5568
5569 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_SocketDescriptor_1hash(JNIEnv *env, jclass clz, int64_t this_arg) {
5570         LDKSocketDescriptor* this_arg_conv = (LDKSocketDescriptor*)this_arg;
5571         int64_t ret_val = (this_arg_conv->hash)(this_arg_conv->this_arg);
5572         return ret_val;
5573 }
5574
5575 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Transaction_1free(JNIEnv *env, jclass clz, int8_tArray _res) {
5576         LDKTransaction _res_ref;
5577         _res_ref.datalen = (*env)->GetArrayLength(env, _res);
5578         _res_ref.data = MALLOC(_res_ref.datalen, "LDKTransaction Bytes");
5579         (*env)->GetByteArrayRegion(env, _res, 0, _res_ref.datalen, _res_ref.data);
5580         _res_ref.data_is_owned = true;
5581         Transaction_free(_res_ref);
5582 }
5583
5584 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_TxOut_1free(JNIEnv *env, jclass clz, int64_t _res) {
5585         LDKTxOut _res_conv = *(LDKTxOut*)_res;
5586         FREE((void*)_res);
5587         TxOut_free(_res_conv);
5588 }
5589
5590 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1SpendableOutputDescriptorZ_1free(JNIEnv *env, jclass clz, int64_tArray _res) {
5591         LDKCVec_SpendableOutputDescriptorZ _res_constr;
5592         _res_constr.datalen = (*env)->GetArrayLength(env, _res);
5593         if (_res_constr.datalen > 0)
5594                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKSpendableOutputDescriptor), "LDKCVec_SpendableOutputDescriptorZ Elements");
5595         else
5596                 _res_constr.data = NULL;
5597         int64_t* _res_vals = (*env)->GetLongArrayElements (env, _res, NULL);
5598         for (size_t b = 0; b < _res_constr.datalen; b++) {
5599                 int64_t arr_conv_27 = _res_vals[b];
5600                 LDKSpendableOutputDescriptor arr_conv_27_conv = *(LDKSpendableOutputDescriptor*)arr_conv_27;
5601                 FREE((void*)arr_conv_27);
5602                 _res_constr.data[b] = arr_conv_27_conv;
5603         }
5604         (*env)->ReleaseLongArrayElements(env, _res, _res_vals, 0);
5605         CVec_SpendableOutputDescriptorZ_free(_res_constr);
5606 }
5607
5608 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1MessageSendEventZ_1free(JNIEnv *env, jclass clz, int64_tArray _res) {
5609         LDKCVec_MessageSendEventZ _res_constr;
5610         _res_constr.datalen = (*env)->GetArrayLength(env, _res);
5611         if (_res_constr.datalen > 0)
5612                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKMessageSendEvent), "LDKCVec_MessageSendEventZ Elements");
5613         else
5614                 _res_constr.data = NULL;
5615         int64_t* _res_vals = (*env)->GetLongArrayElements (env, _res, NULL);
5616         for (size_t s = 0; s < _res_constr.datalen; s++) {
5617                 int64_t arr_conv_18 = _res_vals[s];
5618                 LDKMessageSendEvent arr_conv_18_conv = *(LDKMessageSendEvent*)arr_conv_18;
5619                 FREE((void*)arr_conv_18);
5620                 _res_constr.data[s] = arr_conv_18_conv;
5621         }
5622         (*env)->ReleaseLongArrayElements(env, _res, _res_vals, 0);
5623         CVec_MessageSendEventZ_free(_res_constr);
5624 }
5625
5626 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1EventZ_1free(JNIEnv *env, jclass clz, int64_tArray _res) {
5627         LDKCVec_EventZ _res_constr;
5628         _res_constr.datalen = (*env)->GetArrayLength(env, _res);
5629         if (_res_constr.datalen > 0)
5630                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKEvent), "LDKCVec_EventZ Elements");
5631         else
5632                 _res_constr.data = NULL;
5633         int64_t* _res_vals = (*env)->GetLongArrayElements (env, _res, NULL);
5634         for (size_t h = 0; h < _res_constr.datalen; h++) {
5635                 int64_t arr_conv_7 = _res_vals[h];
5636                 LDKEvent arr_conv_7_conv = *(LDKEvent*)arr_conv_7;
5637                 FREE((void*)arr_conv_7);
5638                 _res_constr.data[h] = arr_conv_7_conv;
5639         }
5640         (*env)->ReleaseLongArrayElements(env, _res, _res_vals, 0);
5641         CVec_EventZ_free(_res_constr);
5642 }
5643
5644 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_C2Tuple_1usizeTransactionZ_1free(JNIEnv *env, jclass clz, int64_t _res) {
5645         LDKC2Tuple_usizeTransactionZ _res_conv = *(LDKC2Tuple_usizeTransactionZ*)_res;
5646         FREE((void*)_res);
5647         C2Tuple_usizeTransactionZ_free(_res_conv);
5648 }
5649
5650 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_C2Tuple_1usizeTransactionZ_1new(JNIEnv *env, jclass clz, int64_t a, int8_tArray b) {
5651         LDKTransaction b_ref;
5652         b_ref.datalen = (*env)->GetArrayLength(env, b);
5653         b_ref.data = MALLOC(b_ref.datalen, "LDKTransaction Bytes");
5654         (*env)->GetByteArrayRegion(env, b, 0, b_ref.datalen, b_ref.data);
5655         b_ref.data_is_owned = true;
5656         LDKC2Tuple_usizeTransactionZ* ret_ref = MALLOC(sizeof(LDKC2Tuple_usizeTransactionZ), "LDKC2Tuple_usizeTransactionZ");
5657         *ret_ref = C2Tuple_usizeTransactionZ_new(a, b_ref);
5658         // XXX: We likely need to clone here, but no _clone fn is available for byte[]
5659         return (long)ret_ref;
5660 }
5661
5662 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1C2Tuple_1usizeTransactionZZ_1free(JNIEnv *env, jclass clz, int64_tArray _res) {
5663         LDKCVec_C2Tuple_usizeTransactionZZ _res_constr;
5664         _res_constr.datalen = (*env)->GetArrayLength(env, _res);
5665         if (_res_constr.datalen > 0)
5666                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKC2Tuple_usizeTransactionZ), "LDKCVec_C2Tuple_usizeTransactionZZ Elements");
5667         else
5668                 _res_constr.data = NULL;
5669         int64_t* _res_vals = (*env)->GetLongArrayElements (env, _res, NULL);
5670         for (size_t y = 0; y < _res_constr.datalen; y++) {
5671                 int64_t arr_conv_24 = _res_vals[y];
5672                 LDKC2Tuple_usizeTransactionZ arr_conv_24_conv = *(LDKC2Tuple_usizeTransactionZ*)arr_conv_24;
5673                 FREE((void*)arr_conv_24);
5674                 _res_constr.data[y] = arr_conv_24_conv;
5675         }
5676         (*env)->ReleaseLongArrayElements(env, _res, _res_vals, 0);
5677         CVec_C2Tuple_usizeTransactionZZ_free(_res_constr);
5678 }
5679
5680 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1NoneChannelMonitorUpdateErrZ_1ok(JNIEnv *env, jclass clz) {
5681         LDKCResult_NoneChannelMonitorUpdateErrZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneChannelMonitorUpdateErrZ), "LDKCResult_NoneChannelMonitorUpdateErrZ");
5682         *ret_conv = CResult_NoneChannelMonitorUpdateErrZ_ok();
5683         return (long)ret_conv;
5684 }
5685
5686 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1NoneChannelMonitorUpdateErrZ_1err(JNIEnv *env, jclass clz, jclass e) {
5687         LDKChannelMonitorUpdateErr e_conv = LDKChannelMonitorUpdateErr_from_java(env, e);
5688         LDKCResult_NoneChannelMonitorUpdateErrZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneChannelMonitorUpdateErrZ), "LDKCResult_NoneChannelMonitorUpdateErrZ");
5689         *ret_conv = CResult_NoneChannelMonitorUpdateErrZ_err(e_conv);
5690         return (long)ret_conv;
5691 }
5692
5693 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1NoneChannelMonitorUpdateErrZ_1free(JNIEnv *env, jclass clz, int64_t _res) {
5694         LDKCResult_NoneChannelMonitorUpdateErrZ _res_conv = *(LDKCResult_NoneChannelMonitorUpdateErrZ*)_res;
5695         FREE((void*)_res);
5696         CResult_NoneChannelMonitorUpdateErrZ_free(_res_conv);
5697 }
5698
5699 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1MonitorEventZ_1free(JNIEnv *env, jclass clz, int64_tArray _res) {
5700         LDKCVec_MonitorEventZ _res_constr;
5701         _res_constr.datalen = (*env)->GetArrayLength(env, _res);
5702         if (_res_constr.datalen > 0)
5703                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKMonitorEvent), "LDKCVec_MonitorEventZ Elements");
5704         else
5705                 _res_constr.data = NULL;
5706         int64_t* _res_vals = (*env)->GetLongArrayElements (env, _res, NULL);
5707         for (size_t o = 0; o < _res_constr.datalen; o++) {
5708                 int64_t arr_conv_14 = _res_vals[o];
5709                 LDKMonitorEvent arr_conv_14_conv;
5710                 arr_conv_14_conv.inner = (void*)(arr_conv_14 & (~1));
5711                 arr_conv_14_conv.is_owned = (arr_conv_14 & 1) || (arr_conv_14 == 0);
5712                 _res_constr.data[o] = arr_conv_14_conv;
5713         }
5714         (*env)->ReleaseLongArrayElements(env, _res, _res_vals, 0);
5715         CVec_MonitorEventZ_free(_res_constr);
5716 }
5717
5718 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1ChannelMonitorUpdateDecodeErrorZ_1ok(JNIEnv *env, jclass clz, int64_t o) {
5719         LDKChannelMonitorUpdate o_conv;
5720         o_conv.inner = (void*)(o & (~1));
5721         o_conv.is_owned = (o & 1) || (o == 0);
5722         if (o_conv.inner != NULL)
5723                 o_conv = ChannelMonitorUpdate_clone(&o_conv);
5724         LDKCResult_ChannelMonitorUpdateDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ChannelMonitorUpdateDecodeErrorZ), "LDKCResult_ChannelMonitorUpdateDecodeErrorZ");
5725         *ret_conv = CResult_ChannelMonitorUpdateDecodeErrorZ_ok(o_conv);
5726         return (long)ret_conv;
5727 }
5728
5729 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1ChannelMonitorUpdateDecodeErrorZ_1err(JNIEnv *env, jclass clz, int64_t e) {
5730         LDKDecodeError e_conv;
5731         e_conv.inner = (void*)(e & (~1));
5732         e_conv.is_owned = (e & 1) || (e == 0);
5733         // Warning: we may need a move here but can't clone!
5734         LDKCResult_ChannelMonitorUpdateDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ChannelMonitorUpdateDecodeErrorZ), "LDKCResult_ChannelMonitorUpdateDecodeErrorZ");
5735         *ret_conv = CResult_ChannelMonitorUpdateDecodeErrorZ_err(e_conv);
5736         return (long)ret_conv;
5737 }
5738
5739 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1ChannelMonitorUpdateDecodeErrorZ_1free(JNIEnv *env, jclass clz, int64_t _res) {
5740         LDKCResult_ChannelMonitorUpdateDecodeErrorZ _res_conv = *(LDKCResult_ChannelMonitorUpdateDecodeErrorZ*)_res;
5741         FREE((void*)_res);
5742         CResult_ChannelMonitorUpdateDecodeErrorZ_free(_res_conv);
5743 }
5744
5745 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1NoneMonitorUpdateErrorZ_1ok(JNIEnv *env, jclass clz) {
5746         LDKCResult_NoneMonitorUpdateErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneMonitorUpdateErrorZ), "LDKCResult_NoneMonitorUpdateErrorZ");
5747         *ret_conv = CResult_NoneMonitorUpdateErrorZ_ok();
5748         return (long)ret_conv;
5749 }
5750
5751 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1NoneMonitorUpdateErrorZ_1err(JNIEnv *env, jclass clz, int64_t e) {
5752         LDKMonitorUpdateError e_conv;
5753         e_conv.inner = (void*)(e & (~1));
5754         e_conv.is_owned = (e & 1) || (e == 0);
5755         // Warning: we may need a move here but can't clone!
5756         LDKCResult_NoneMonitorUpdateErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneMonitorUpdateErrorZ), "LDKCResult_NoneMonitorUpdateErrorZ");
5757         *ret_conv = CResult_NoneMonitorUpdateErrorZ_err(e_conv);
5758         return (long)ret_conv;
5759 }
5760
5761 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1NoneMonitorUpdateErrorZ_1free(JNIEnv *env, jclass clz, int64_t _res) {
5762         LDKCResult_NoneMonitorUpdateErrorZ _res_conv = *(LDKCResult_NoneMonitorUpdateErrorZ*)_res;
5763         FREE((void*)_res);
5764         CResult_NoneMonitorUpdateErrorZ_free(_res_conv);
5765 }
5766
5767 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_C2Tuple_1OutPointScriptZ_1free(JNIEnv *env, jclass clz, int64_t _res) {
5768         LDKC2Tuple_OutPointScriptZ _res_conv = *(LDKC2Tuple_OutPointScriptZ*)_res;
5769         FREE((void*)_res);
5770         C2Tuple_OutPointScriptZ_free(_res_conv);
5771 }
5772
5773 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_C2Tuple_1OutPointScriptZ_1new(JNIEnv *env, jclass clz, int64_t a, int8_tArray b) {
5774         LDKOutPoint a_conv;
5775         a_conv.inner = (void*)(a & (~1));
5776         a_conv.is_owned = (a & 1) || (a == 0);
5777         if (a_conv.inner != NULL)
5778                 a_conv = OutPoint_clone(&a_conv);
5779         LDKCVec_u8Z b_ref;
5780         b_ref.datalen = (*env)->GetArrayLength(env, b);
5781         b_ref.data = MALLOC(b_ref.datalen, "LDKCVec_u8Z Bytes");
5782         (*env)->GetByteArrayRegion(env, b, 0, b_ref.datalen, b_ref.data);
5783         LDKC2Tuple_OutPointScriptZ* ret_ref = MALLOC(sizeof(LDKC2Tuple_OutPointScriptZ), "LDKC2Tuple_OutPointScriptZ");
5784         *ret_ref = C2Tuple_OutPointScriptZ_new(a_conv, b_ref);
5785         ret_ref->a = OutPoint_clone(&ret_ref->a);
5786         ret_ref->b = CVec_u8Z_clone(&ret_ref->b);
5787         return (long)ret_ref;
5788 }
5789
5790 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1TransactionZ_1free(JNIEnv *env, jclass clz, jobjectArray _res) {
5791         LDKCVec_TransactionZ _res_constr;
5792         _res_constr.datalen = (*env)->GetArrayLength(env, _res);
5793         if (_res_constr.datalen > 0)
5794                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKTransaction), "LDKCVec_TransactionZ Elements");
5795         else
5796                 _res_constr.data = NULL;
5797         for (size_t i = 0; i < _res_constr.datalen; i++) {
5798                 int8_tArray arr_conv_8 = (*env)->GetObjectArrayElement(env, _res, i);
5799                 LDKTransaction arr_conv_8_ref;
5800                 arr_conv_8_ref.datalen = (*env)->GetArrayLength(env, arr_conv_8);
5801                 arr_conv_8_ref.data = MALLOC(arr_conv_8_ref.datalen, "LDKTransaction Bytes");
5802                 (*env)->GetByteArrayRegion(env, arr_conv_8, 0, arr_conv_8_ref.datalen, arr_conv_8_ref.data);
5803                 arr_conv_8_ref.data_is_owned = true;
5804                 _res_constr.data[i] = arr_conv_8_ref;
5805         }
5806         CVec_TransactionZ_free(_res_constr);
5807 }
5808
5809 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_C2Tuple_1u32TxOutZ_1free(JNIEnv *env, jclass clz, int64_t _res) {
5810         LDKC2Tuple_u32TxOutZ _res_conv = *(LDKC2Tuple_u32TxOutZ*)_res;
5811         FREE((void*)_res);
5812         C2Tuple_u32TxOutZ_free(_res_conv);
5813 }
5814
5815 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_C2Tuple_1u32TxOutZ_1new(JNIEnv *env, jclass clz, int32_t a, int64_t b) {
5816         LDKTxOut b_conv = *(LDKTxOut*)b;
5817         FREE((void*)b);
5818         LDKC2Tuple_u32TxOutZ* ret_ref = MALLOC(sizeof(LDKC2Tuple_u32TxOutZ), "LDKC2Tuple_u32TxOutZ");
5819         *ret_ref = C2Tuple_u32TxOutZ_new(a, b_conv);
5820         // XXX: We likely need to clone here, but no _clone fn is available for TxOut
5821         return (long)ret_ref;
5822 }
5823
5824 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1C2Tuple_1u32TxOutZZ_1free(JNIEnv *env, jclass clz, int64_tArray _res) {
5825         LDKCVec_C2Tuple_u32TxOutZZ _res_constr;
5826         _res_constr.datalen = (*env)->GetArrayLength(env, _res);
5827         if (_res_constr.datalen > 0)
5828                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKC2Tuple_u32TxOutZ), "LDKCVec_C2Tuple_u32TxOutZZ Elements");
5829         else
5830                 _res_constr.data = NULL;
5831         int64_t* _res_vals = (*env)->GetLongArrayElements (env, _res, NULL);
5832         for (size_t a = 0; a < _res_constr.datalen; a++) {
5833                 int64_t arr_conv_26 = _res_vals[a];
5834                 LDKC2Tuple_u32TxOutZ arr_conv_26_conv = *(LDKC2Tuple_u32TxOutZ*)arr_conv_26;
5835                 FREE((void*)arr_conv_26);
5836                 _res_constr.data[a] = arr_conv_26_conv;
5837         }
5838         (*env)->ReleaseLongArrayElements(env, _res, _res_vals, 0);
5839         CVec_C2Tuple_u32TxOutZZ_free(_res_constr);
5840 }
5841
5842 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_C2Tuple_1TxidCVec_1C2Tuple_1u32TxOutZZZ_1free(JNIEnv *env, jclass clz, int64_t _res) {
5843         LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ _res_conv = *(LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ*)_res;
5844         FREE((void*)_res);
5845         C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ_free(_res_conv);
5846 }
5847
5848 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_C2Tuple_1TxidCVec_1C2Tuple_1u32TxOutZZZ_1new(JNIEnv *env, jclass clz, int8_tArray a, int64_tArray b) {
5849         LDKThirtyTwoBytes a_ref;
5850         CHECK((*env)->GetArrayLength(env, a) == 32);
5851         (*env)->GetByteArrayRegion(env, a, 0, 32, a_ref.data);
5852         LDKCVec_C2Tuple_u32TxOutZZ b_constr;
5853         b_constr.datalen = (*env)->GetArrayLength(env, b);
5854         if (b_constr.datalen > 0)
5855                 b_constr.data = MALLOC(b_constr.datalen * sizeof(LDKC2Tuple_u32TxOutZ), "LDKCVec_C2Tuple_u32TxOutZZ Elements");
5856         else
5857                 b_constr.data = NULL;
5858         int64_t* b_vals = (*env)->GetLongArrayElements (env, b, NULL);
5859         for (size_t a = 0; a < b_constr.datalen; a++) {
5860                 int64_t arr_conv_26 = b_vals[a];
5861                 LDKC2Tuple_u32TxOutZ arr_conv_26_conv = *(LDKC2Tuple_u32TxOutZ*)arr_conv_26;
5862                 FREE((void*)arr_conv_26);
5863                 b_constr.data[a] = arr_conv_26_conv;
5864         }
5865         (*env)->ReleaseLongArrayElements(env, b, b_vals, 0);
5866         LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ* ret_ref = MALLOC(sizeof(LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ), "LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ");
5867         *ret_ref = C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ_new(a_ref, b_constr);
5868         ret_ref->a = ThirtyTwoBytes_clone(&ret_ref->a);
5869         // XXX: We likely need to clone here, but no _clone fn is available for TwoTuple<Integer, TxOut>[]
5870         return (long)ret_ref;
5871 }
5872
5873 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1C2Tuple_1TxidCVec_1C2Tuple_1u32TxOutZZZZ_1free(JNIEnv *env, jclass clz, int64_tArray _res) {
5874         LDKCVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ _res_constr;
5875         _res_constr.datalen = (*env)->GetArrayLength(env, _res);
5876         if (_res_constr.datalen > 0)
5877                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ), "LDKCVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ Elements");
5878         else
5879                 _res_constr.data = NULL;
5880         int64_t* _res_vals = (*env)->GetLongArrayElements (env, _res, NULL);
5881         for (size_t u = 0; u < _res_constr.datalen; u++) {
5882                 int64_t arr_conv_46 = _res_vals[u];
5883                 LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ arr_conv_46_conv = *(LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ*)arr_conv_46;
5884                 FREE((void*)arr_conv_46);
5885                 _res_constr.data[u] = arr_conv_46_conv;
5886         }
5887         (*env)->ReleaseLongArrayElements(env, _res, _res_vals, 0);
5888         CVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ_free(_res_constr);
5889 }
5890
5891 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_C2Tuple_1BlockHashChannelMonitorZ_1free(JNIEnv *env, jclass clz, int64_t _res) {
5892         LDKC2Tuple_BlockHashChannelMonitorZ _res_conv = *(LDKC2Tuple_BlockHashChannelMonitorZ*)_res;
5893         FREE((void*)_res);
5894         C2Tuple_BlockHashChannelMonitorZ_free(_res_conv);
5895 }
5896
5897 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_C2Tuple_1BlockHashChannelMonitorZ_1new(JNIEnv *env, jclass clz, int8_tArray a, int64_t b) {
5898         LDKThirtyTwoBytes a_ref;
5899         CHECK((*env)->GetArrayLength(env, a) == 32);
5900         (*env)->GetByteArrayRegion(env, a, 0, 32, a_ref.data);
5901         LDKChannelMonitor b_conv;
5902         b_conv.inner = (void*)(b & (~1));
5903         b_conv.is_owned = (b & 1) || (b == 0);
5904         // Warning: we may need a move here but can't clone!
5905         LDKC2Tuple_BlockHashChannelMonitorZ* ret_ref = MALLOC(sizeof(LDKC2Tuple_BlockHashChannelMonitorZ), "LDKC2Tuple_BlockHashChannelMonitorZ");
5906         *ret_ref = C2Tuple_BlockHashChannelMonitorZ_new(a_ref, b_conv);
5907         ret_ref->a = ThirtyTwoBytes_clone(&ret_ref->a);
5908         // XXX: We likely need to clone here, but no _clone fn is available for ChannelMonitor
5909         return (long)ret_ref;
5910 }
5911
5912 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1C2Tuple_1BlockHashChannelMonitorZDecodeErrorZ_1ok(JNIEnv *env, jclass clz, int64_t o) {
5913         LDKC2Tuple_BlockHashChannelMonitorZ o_conv = *(LDKC2Tuple_BlockHashChannelMonitorZ*)o;
5914         FREE((void*)o);
5915         LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ), "LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ");
5916         *ret_conv = CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ_ok(o_conv);
5917         return (long)ret_conv;
5918 }
5919
5920 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1C2Tuple_1BlockHashChannelMonitorZDecodeErrorZ_1err(JNIEnv *env, jclass clz, int64_t e) {
5921         LDKDecodeError e_conv;
5922         e_conv.inner = (void*)(e & (~1));
5923         e_conv.is_owned = (e & 1) || (e == 0);
5924         // Warning: we may need a move here but can't clone!
5925         LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ), "LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ");
5926         *ret_conv = CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ_err(e_conv);
5927         return (long)ret_conv;
5928 }
5929
5930 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1C2Tuple_1BlockHashChannelMonitorZDecodeErrorZ_1free(JNIEnv *env, jclass clz, int64_t _res) {
5931         LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ _res_conv = *(LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ*)_res;
5932         FREE((void*)_res);
5933         CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ_free(_res_conv);
5934 }
5935
5936 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_C2Tuple_1u64u64Z_1free(JNIEnv *env, jclass clz, int64_t _res) {
5937         LDKC2Tuple_u64u64Z _res_conv = *(LDKC2Tuple_u64u64Z*)_res;
5938         FREE((void*)_res);
5939         C2Tuple_u64u64Z_free(_res_conv);
5940 }
5941
5942 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_C2Tuple_1u64u64Z_1new(JNIEnv *env, jclass clz, int64_t a, int64_t b) {
5943         LDKC2Tuple_u64u64Z* ret_ref = MALLOC(sizeof(LDKC2Tuple_u64u64Z), "LDKC2Tuple_u64u64Z");
5944         *ret_ref = C2Tuple_u64u64Z_new(a, b);
5945         return (long)ret_ref;
5946 }
5947
5948 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1SpendableOutputDescriptorDecodeErrorZ_1ok(JNIEnv *env, jclass clz, int64_t o) {
5949         LDKSpendableOutputDescriptor o_conv = *(LDKSpendableOutputDescriptor*)o;
5950         FREE((void*)o);
5951         LDKCResult_SpendableOutputDescriptorDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_SpendableOutputDescriptorDecodeErrorZ), "LDKCResult_SpendableOutputDescriptorDecodeErrorZ");
5952         *ret_conv = CResult_SpendableOutputDescriptorDecodeErrorZ_ok(o_conv);
5953         return (long)ret_conv;
5954 }
5955
5956 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1SpendableOutputDescriptorDecodeErrorZ_1err(JNIEnv *env, jclass clz, int64_t e) {
5957         LDKDecodeError e_conv;
5958         e_conv.inner = (void*)(e & (~1));
5959         e_conv.is_owned = (e & 1) || (e == 0);
5960         // Warning: we may need a move here but can't clone!
5961         LDKCResult_SpendableOutputDescriptorDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_SpendableOutputDescriptorDecodeErrorZ), "LDKCResult_SpendableOutputDescriptorDecodeErrorZ");
5962         *ret_conv = CResult_SpendableOutputDescriptorDecodeErrorZ_err(e_conv);
5963         return (long)ret_conv;
5964 }
5965
5966 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1SpendableOutputDescriptorDecodeErrorZ_1free(JNIEnv *env, jclass clz, int64_t _res) {
5967         LDKCResult_SpendableOutputDescriptorDecodeErrorZ _res_conv = *(LDKCResult_SpendableOutputDescriptorDecodeErrorZ*)_res;
5968         FREE((void*)_res);
5969         CResult_SpendableOutputDescriptorDecodeErrorZ_free(_res_conv);
5970 }
5971
5972 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1SignatureZ_1free(JNIEnv *env, jclass clz, jobjectArray _res) {
5973         LDKCVec_SignatureZ _res_constr;
5974         _res_constr.datalen = (*env)->GetArrayLength(env, _res);
5975         if (_res_constr.datalen > 0)
5976                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKSignature), "LDKCVec_SignatureZ Elements");
5977         else
5978                 _res_constr.data = NULL;
5979         for (size_t i = 0; i < _res_constr.datalen; i++) {
5980                 int8_tArray arr_conv_8 = (*env)->GetObjectArrayElement(env, _res, i);
5981                 LDKSignature arr_conv_8_ref;
5982                 CHECK((*env)->GetArrayLength(env, arr_conv_8) == 64);
5983                 (*env)->GetByteArrayRegion(env, arr_conv_8, 0, 64, arr_conv_8_ref.compact_form);
5984                 _res_constr.data[i] = arr_conv_8_ref;
5985         }
5986         CVec_SignatureZ_free(_res_constr);
5987 }
5988
5989 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_C2Tuple_1SignatureCVec_1SignatureZZ_1free(JNIEnv *env, jclass clz, int64_t _res) {
5990         LDKC2Tuple_SignatureCVec_SignatureZZ _res_conv = *(LDKC2Tuple_SignatureCVec_SignatureZZ*)_res;
5991         FREE((void*)_res);
5992         C2Tuple_SignatureCVec_SignatureZZ_free(_res_conv);
5993 }
5994
5995 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_C2Tuple_1SignatureCVec_1SignatureZZ_1new(JNIEnv *env, jclass clz, int8_tArray a, jobjectArray b) {
5996         LDKSignature a_ref;
5997         CHECK((*env)->GetArrayLength(env, a) == 64);
5998         (*env)->GetByteArrayRegion(env, a, 0, 64, a_ref.compact_form);
5999         LDKCVec_SignatureZ b_constr;
6000         b_constr.datalen = (*env)->GetArrayLength(env, b);
6001         if (b_constr.datalen > 0)
6002                 b_constr.data = MALLOC(b_constr.datalen * sizeof(LDKSignature), "LDKCVec_SignatureZ Elements");
6003         else
6004                 b_constr.data = NULL;
6005         for (size_t i = 0; i < b_constr.datalen; i++) {
6006                 int8_tArray arr_conv_8 = (*env)->GetObjectArrayElement(env, b, i);
6007                 LDKSignature arr_conv_8_ref;
6008                 CHECK((*env)->GetArrayLength(env, arr_conv_8) == 64);
6009                 (*env)->GetByteArrayRegion(env, arr_conv_8, 0, 64, arr_conv_8_ref.compact_form);
6010                 b_constr.data[i] = arr_conv_8_ref;
6011         }
6012         LDKC2Tuple_SignatureCVec_SignatureZZ* ret_ref = MALLOC(sizeof(LDKC2Tuple_SignatureCVec_SignatureZZ), "LDKC2Tuple_SignatureCVec_SignatureZZ");
6013         *ret_ref = C2Tuple_SignatureCVec_SignatureZZ_new(a_ref, b_constr);
6014         // XXX: We likely need to clone here, but no _clone fn is available for byte[]
6015         // XXX: We likely need to clone here, but no _clone fn is available for byte[][]
6016         return (long)ret_ref;
6017 }
6018
6019 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1C2Tuple_1SignatureCVec_1SignatureZZNoneZ_1ok(JNIEnv *env, jclass clz, int64_t o) {
6020         LDKC2Tuple_SignatureCVec_SignatureZZ o_conv = *(LDKC2Tuple_SignatureCVec_SignatureZZ*)o;
6021         FREE((void*)o);
6022         LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ), "LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ");
6023         *ret_conv = CResult_C2Tuple_SignatureCVec_SignatureZZNoneZ_ok(o_conv);
6024         return (long)ret_conv;
6025 }
6026
6027 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1C2Tuple_1SignatureCVec_1SignatureZZNoneZ_1err(JNIEnv *env, jclass clz) {
6028         LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ), "LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ");
6029         *ret_conv = CResult_C2Tuple_SignatureCVec_SignatureZZNoneZ_err();
6030         return (long)ret_conv;
6031 }
6032
6033 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1C2Tuple_1SignatureCVec_1SignatureZZNoneZ_1free(JNIEnv *env, jclass clz, int64_t _res) {
6034         LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ _res_conv = *(LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ*)_res;
6035         FREE((void*)_res);
6036         CResult_C2Tuple_SignatureCVec_SignatureZZNoneZ_free(_res_conv);
6037 }
6038
6039 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1SignatureNoneZ_1ok(JNIEnv *env, jclass clz, int8_tArray o) {
6040         LDKSignature o_ref;
6041         CHECK((*env)->GetArrayLength(env, o) == 64);
6042         (*env)->GetByteArrayRegion(env, o, 0, 64, o_ref.compact_form);
6043         LDKCResult_SignatureNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_SignatureNoneZ), "LDKCResult_SignatureNoneZ");
6044         *ret_conv = CResult_SignatureNoneZ_ok(o_ref);
6045         return (long)ret_conv;
6046 }
6047
6048 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1SignatureNoneZ_1err(JNIEnv *env, jclass clz) {
6049         LDKCResult_SignatureNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_SignatureNoneZ), "LDKCResult_SignatureNoneZ");
6050         *ret_conv = CResult_SignatureNoneZ_err();
6051         return (long)ret_conv;
6052 }
6053
6054 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1SignatureNoneZ_1free(JNIEnv *env, jclass clz, int64_t _res) {
6055         LDKCResult_SignatureNoneZ _res_conv = *(LDKCResult_SignatureNoneZ*)_res;
6056         FREE((void*)_res);
6057         CResult_SignatureNoneZ_free(_res_conv);
6058 }
6059
6060 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1CVec_1SignatureZNoneZ_1ok(JNIEnv *env, jclass clz, jobjectArray o) {
6061         LDKCVec_SignatureZ o_constr;
6062         o_constr.datalen = (*env)->GetArrayLength(env, o);
6063         if (o_constr.datalen > 0)
6064                 o_constr.data = MALLOC(o_constr.datalen * sizeof(LDKSignature), "LDKCVec_SignatureZ Elements");
6065         else
6066                 o_constr.data = NULL;
6067         for (size_t i = 0; i < o_constr.datalen; i++) {
6068                 int8_tArray arr_conv_8 = (*env)->GetObjectArrayElement(env, o, i);
6069                 LDKSignature arr_conv_8_ref;
6070                 CHECK((*env)->GetArrayLength(env, arr_conv_8) == 64);
6071                 (*env)->GetByteArrayRegion(env, arr_conv_8, 0, 64, arr_conv_8_ref.compact_form);
6072                 o_constr.data[i] = arr_conv_8_ref;
6073         }
6074         LDKCResult_CVec_SignatureZNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_CVec_SignatureZNoneZ), "LDKCResult_CVec_SignatureZNoneZ");
6075         *ret_conv = CResult_CVec_SignatureZNoneZ_ok(o_constr);
6076         return (long)ret_conv;
6077 }
6078
6079 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1CVec_1SignatureZNoneZ_1err(JNIEnv *env, jclass clz) {
6080         LDKCResult_CVec_SignatureZNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_CVec_SignatureZNoneZ), "LDKCResult_CVec_SignatureZNoneZ");
6081         *ret_conv = CResult_CVec_SignatureZNoneZ_err();
6082         return (long)ret_conv;
6083 }
6084
6085 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1CVec_1SignatureZNoneZ_1free(JNIEnv *env, jclass clz, int64_t _res) {
6086         LDKCResult_CVec_SignatureZNoneZ _res_conv = *(LDKCResult_CVec_SignatureZNoneZ*)_res;
6087         FREE((void*)_res);
6088         CResult_CVec_SignatureZNoneZ_free(_res_conv);
6089 }
6090
6091 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1ChanKeySignerDecodeErrorZ_1ok(JNIEnv *env, jclass clz, int64_t o) {
6092         LDKChannelKeys o_conv = *(LDKChannelKeys*)o;
6093         if (o_conv.free == LDKChannelKeys_JCalls_free) {
6094                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
6095                 LDKChannelKeys_JCalls_clone(o_conv.this_arg);
6096         }
6097         LDKCResult_ChanKeySignerDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ChanKeySignerDecodeErrorZ), "LDKCResult_ChanKeySignerDecodeErrorZ");
6098         *ret_conv = CResult_ChanKeySignerDecodeErrorZ_ok(o_conv);
6099         return (long)ret_conv;
6100 }
6101
6102 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1ChanKeySignerDecodeErrorZ_1err(JNIEnv *env, jclass clz, int64_t e) {
6103         LDKDecodeError e_conv;
6104         e_conv.inner = (void*)(e & (~1));
6105         e_conv.is_owned = (e & 1) || (e == 0);
6106         // Warning: we may need a move here but can't clone!
6107         LDKCResult_ChanKeySignerDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ChanKeySignerDecodeErrorZ), "LDKCResult_ChanKeySignerDecodeErrorZ");
6108         *ret_conv = CResult_ChanKeySignerDecodeErrorZ_err(e_conv);
6109         return (long)ret_conv;
6110 }
6111
6112 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1ChanKeySignerDecodeErrorZ_1free(JNIEnv *env, jclass clz, int64_t _res) {
6113         LDKCResult_ChanKeySignerDecodeErrorZ _res_conv = *(LDKCResult_ChanKeySignerDecodeErrorZ*)_res;
6114         FREE((void*)_res);
6115         CResult_ChanKeySignerDecodeErrorZ_free(_res_conv);
6116 }
6117
6118 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1InMemoryChannelKeysDecodeErrorZ_1ok(JNIEnv *env, jclass clz, int64_t o) {
6119         LDKInMemoryChannelKeys o_conv;
6120         o_conv.inner = (void*)(o & (~1));
6121         o_conv.is_owned = (o & 1) || (o == 0);
6122         if (o_conv.inner != NULL)
6123                 o_conv = InMemoryChannelKeys_clone(&o_conv);
6124         LDKCResult_InMemoryChannelKeysDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_InMemoryChannelKeysDecodeErrorZ), "LDKCResult_InMemoryChannelKeysDecodeErrorZ");
6125         *ret_conv = CResult_InMemoryChannelKeysDecodeErrorZ_ok(o_conv);
6126         return (long)ret_conv;
6127 }
6128
6129 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1InMemoryChannelKeysDecodeErrorZ_1err(JNIEnv *env, jclass clz, int64_t e) {
6130         LDKDecodeError e_conv;
6131         e_conv.inner = (void*)(e & (~1));
6132         e_conv.is_owned = (e & 1) || (e == 0);
6133         // Warning: we may need a move here but can't clone!
6134         LDKCResult_InMemoryChannelKeysDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_InMemoryChannelKeysDecodeErrorZ), "LDKCResult_InMemoryChannelKeysDecodeErrorZ");
6135         *ret_conv = CResult_InMemoryChannelKeysDecodeErrorZ_err(e_conv);
6136         return (long)ret_conv;
6137 }
6138
6139 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1InMemoryChannelKeysDecodeErrorZ_1free(JNIEnv *env, jclass clz, int64_t _res) {
6140         LDKCResult_InMemoryChannelKeysDecodeErrorZ _res_conv = *(LDKCResult_InMemoryChannelKeysDecodeErrorZ*)_res;
6141         FREE((void*)_res);
6142         CResult_InMemoryChannelKeysDecodeErrorZ_free(_res_conv);
6143 }
6144
6145 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1TxOutAccessErrorZ_1ok(JNIEnv *env, jclass clz, int64_t o) {
6146         LDKTxOut o_conv = *(LDKTxOut*)o;
6147         FREE((void*)o);
6148         LDKCResult_TxOutAccessErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_TxOutAccessErrorZ), "LDKCResult_TxOutAccessErrorZ");
6149         *ret_conv = CResult_TxOutAccessErrorZ_ok(o_conv);
6150         return (long)ret_conv;
6151 }
6152
6153 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1TxOutAccessErrorZ_1err(JNIEnv *env, jclass clz, jclass e) {
6154         LDKAccessError e_conv = LDKAccessError_from_java(env, e);
6155         LDKCResult_TxOutAccessErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_TxOutAccessErrorZ), "LDKCResult_TxOutAccessErrorZ");
6156         *ret_conv = CResult_TxOutAccessErrorZ_err(e_conv);
6157         return (long)ret_conv;
6158 }
6159
6160 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1TxOutAccessErrorZ_1free(JNIEnv *env, jclass clz, int64_t _res) {
6161         LDKCResult_TxOutAccessErrorZ _res_conv = *(LDKCResult_TxOutAccessErrorZ*)_res;
6162         FREE((void*)_res);
6163         CResult_TxOutAccessErrorZ_free(_res_conv);
6164 }
6165
6166 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1NoneAPIErrorZ_1ok(JNIEnv *env, jclass clz) {
6167         LDKCResult_NoneAPIErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneAPIErrorZ), "LDKCResult_NoneAPIErrorZ");
6168         *ret_conv = CResult_NoneAPIErrorZ_ok();
6169         return (long)ret_conv;
6170 }
6171
6172 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1NoneAPIErrorZ_1err(JNIEnv *env, jclass clz, int64_t e) {
6173         LDKAPIError e_conv = *(LDKAPIError*)e;
6174         FREE((void*)e);
6175         LDKCResult_NoneAPIErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneAPIErrorZ), "LDKCResult_NoneAPIErrorZ");
6176         *ret_conv = CResult_NoneAPIErrorZ_err(e_conv);
6177         return (long)ret_conv;
6178 }
6179
6180 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1NoneAPIErrorZ_1free(JNIEnv *env, jclass clz, int64_t _res) {
6181         LDKCResult_NoneAPIErrorZ _res_conv = *(LDKCResult_NoneAPIErrorZ*)_res;
6182         FREE((void*)_res);
6183         CResult_NoneAPIErrorZ_free(_res_conv);
6184 }
6185
6186 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1ChannelDetailsZ_1free(JNIEnv *env, jclass clz, int64_tArray _res) {
6187         LDKCVec_ChannelDetailsZ _res_constr;
6188         _res_constr.datalen = (*env)->GetArrayLength(env, _res);
6189         if (_res_constr.datalen > 0)
6190                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKChannelDetails), "LDKCVec_ChannelDetailsZ Elements");
6191         else
6192                 _res_constr.data = NULL;
6193         int64_t* _res_vals = (*env)->GetLongArrayElements (env, _res, NULL);
6194         for (size_t q = 0; q < _res_constr.datalen; q++) {
6195                 int64_t arr_conv_16 = _res_vals[q];
6196                 LDKChannelDetails arr_conv_16_conv;
6197                 arr_conv_16_conv.inner = (void*)(arr_conv_16 & (~1));
6198                 arr_conv_16_conv.is_owned = (arr_conv_16 & 1) || (arr_conv_16 == 0);
6199                 _res_constr.data[q] = arr_conv_16_conv;
6200         }
6201         (*env)->ReleaseLongArrayElements(env, _res, _res_vals, 0);
6202         CVec_ChannelDetailsZ_free(_res_constr);
6203 }
6204
6205 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1NonePaymentSendFailureZ_1ok(JNIEnv *env, jclass clz) {
6206         LDKCResult_NonePaymentSendFailureZ* ret_conv = MALLOC(sizeof(LDKCResult_NonePaymentSendFailureZ), "LDKCResult_NonePaymentSendFailureZ");
6207         *ret_conv = CResult_NonePaymentSendFailureZ_ok();
6208         return (long)ret_conv;
6209 }
6210
6211 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1NonePaymentSendFailureZ_1err(JNIEnv *env, jclass clz, int64_t e) {
6212         LDKPaymentSendFailure e_conv;
6213         e_conv.inner = (void*)(e & (~1));
6214         e_conv.is_owned = (e & 1) || (e == 0);
6215         // Warning: we may need a move here but can't clone!
6216         LDKCResult_NonePaymentSendFailureZ* ret_conv = MALLOC(sizeof(LDKCResult_NonePaymentSendFailureZ), "LDKCResult_NonePaymentSendFailureZ");
6217         *ret_conv = CResult_NonePaymentSendFailureZ_err(e_conv);
6218         return (long)ret_conv;
6219 }
6220
6221 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1NonePaymentSendFailureZ_1free(JNIEnv *env, jclass clz, int64_t _res) {
6222         LDKCResult_NonePaymentSendFailureZ _res_conv = *(LDKCResult_NonePaymentSendFailureZ*)_res;
6223         FREE((void*)_res);
6224         CResult_NonePaymentSendFailureZ_free(_res_conv);
6225 }
6226
6227 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1NetAddressZ_1free(JNIEnv *env, jclass clz, int64_tArray _res) {
6228         LDKCVec_NetAddressZ _res_constr;
6229         _res_constr.datalen = (*env)->GetArrayLength(env, _res);
6230         if (_res_constr.datalen > 0)
6231                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKNetAddress), "LDKCVec_NetAddressZ Elements");
6232         else
6233                 _res_constr.data = NULL;
6234         int64_t* _res_vals = (*env)->GetLongArrayElements (env, _res, NULL);
6235         for (size_t m = 0; m < _res_constr.datalen; m++) {
6236                 int64_t arr_conv_12 = _res_vals[m];
6237                 LDKNetAddress arr_conv_12_conv = *(LDKNetAddress*)arr_conv_12;
6238                 FREE((void*)arr_conv_12);
6239                 _res_constr.data[m] = arr_conv_12_conv;
6240         }
6241         (*env)->ReleaseLongArrayElements(env, _res, _res_vals, 0);
6242         CVec_NetAddressZ_free(_res_constr);
6243 }
6244
6245 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1ChannelMonitorZ_1free(JNIEnv *env, jclass clz, int64_tArray _res) {
6246         LDKCVec_ChannelMonitorZ _res_constr;
6247         _res_constr.datalen = (*env)->GetArrayLength(env, _res);
6248         if (_res_constr.datalen > 0)
6249                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKChannelMonitor), "LDKCVec_ChannelMonitorZ Elements");
6250         else
6251                 _res_constr.data = NULL;
6252         int64_t* _res_vals = (*env)->GetLongArrayElements (env, _res, NULL);
6253         for (size_t q = 0; q < _res_constr.datalen; q++) {
6254                 int64_t arr_conv_16 = _res_vals[q];
6255                 LDKChannelMonitor arr_conv_16_conv;
6256                 arr_conv_16_conv.inner = (void*)(arr_conv_16 & (~1));
6257                 arr_conv_16_conv.is_owned = (arr_conv_16 & 1) || (arr_conv_16 == 0);
6258                 _res_constr.data[q] = arr_conv_16_conv;
6259         }
6260         (*env)->ReleaseLongArrayElements(env, _res, _res_vals, 0);
6261         CVec_ChannelMonitorZ_free(_res_constr);
6262 }
6263
6264 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_C2Tuple_1BlockHashChannelManagerZ_1free(JNIEnv *env, jclass clz, int64_t _res) {
6265         LDKC2Tuple_BlockHashChannelManagerZ _res_conv = *(LDKC2Tuple_BlockHashChannelManagerZ*)_res;
6266         FREE((void*)_res);
6267         C2Tuple_BlockHashChannelManagerZ_free(_res_conv);
6268 }
6269
6270 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_C2Tuple_1BlockHashChannelManagerZ_1new(JNIEnv *env, jclass clz, int8_tArray a, int64_t b) {
6271         LDKThirtyTwoBytes a_ref;
6272         CHECK((*env)->GetArrayLength(env, a) == 32);
6273         (*env)->GetByteArrayRegion(env, a, 0, 32, a_ref.data);
6274         LDKChannelManager b_conv;
6275         b_conv.inner = (void*)(b & (~1));
6276         b_conv.is_owned = (b & 1) || (b == 0);
6277         // Warning: we may need a move here but can't clone!
6278         LDKC2Tuple_BlockHashChannelManagerZ* ret_ref = MALLOC(sizeof(LDKC2Tuple_BlockHashChannelManagerZ), "LDKC2Tuple_BlockHashChannelManagerZ");
6279         *ret_ref = C2Tuple_BlockHashChannelManagerZ_new(a_ref, b_conv);
6280         ret_ref->a = ThirtyTwoBytes_clone(&ret_ref->a);
6281         // XXX: We likely need to clone here, but no _clone fn is available for ChannelManager
6282         return (long)ret_ref;
6283 }
6284
6285 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1C2Tuple_1BlockHashChannelManagerZDecodeErrorZ_1ok(JNIEnv *env, jclass clz, int64_t o) {
6286         LDKC2Tuple_BlockHashChannelManagerZ o_conv = *(LDKC2Tuple_BlockHashChannelManagerZ*)o;
6287         FREE((void*)o);
6288         LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ), "LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ");
6289         *ret_conv = CResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ_ok(o_conv);
6290         return (long)ret_conv;
6291 }
6292
6293 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1C2Tuple_1BlockHashChannelManagerZDecodeErrorZ_1err(JNIEnv *env, jclass clz, int64_t e) {
6294         LDKDecodeError e_conv;
6295         e_conv.inner = (void*)(e & (~1));
6296         e_conv.is_owned = (e & 1) || (e == 0);
6297         // Warning: we may need a move here but can't clone!
6298         LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ), "LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ");
6299         *ret_conv = CResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ_err(e_conv);
6300         return (long)ret_conv;
6301 }
6302
6303 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1C2Tuple_1BlockHashChannelManagerZDecodeErrorZ_1free(JNIEnv *env, jclass clz, int64_t _res) {
6304         LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ _res_conv = *(LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ*)_res;
6305         FREE((void*)_res);
6306         CResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ_free(_res_conv);
6307 }
6308
6309 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1NetAddressu8Z_1ok(JNIEnv *env, jclass clz, int64_t o) {
6310         LDKNetAddress o_conv = *(LDKNetAddress*)o;
6311         FREE((void*)o);
6312         LDKCResult_NetAddressu8Z* ret_conv = MALLOC(sizeof(LDKCResult_NetAddressu8Z), "LDKCResult_NetAddressu8Z");
6313         *ret_conv = CResult_NetAddressu8Z_ok(o_conv);
6314         return (long)ret_conv;
6315 }
6316
6317 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1NetAddressu8Z_1err(JNIEnv *env, jclass clz, int8_t e) {
6318         LDKCResult_NetAddressu8Z* ret_conv = MALLOC(sizeof(LDKCResult_NetAddressu8Z), "LDKCResult_NetAddressu8Z");
6319         *ret_conv = CResult_NetAddressu8Z_err(e);
6320         return (long)ret_conv;
6321 }
6322
6323 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1NetAddressu8Z_1free(JNIEnv *env, jclass clz, int64_t _res) {
6324         LDKCResult_NetAddressu8Z _res_conv = *(LDKCResult_NetAddressu8Z*)_res;
6325         FREE((void*)_res);
6326         CResult_NetAddressu8Z_free(_res_conv);
6327 }
6328
6329 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1CResult_1NetAddressu8ZDecodeErrorZ_1ok(JNIEnv *env, jclass clz, int64_t o) {
6330         LDKCResult_NetAddressu8Z o_conv = *(LDKCResult_NetAddressu8Z*)o;
6331         FREE((void*)o);
6332         LDKCResult_CResult_NetAddressu8ZDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_CResult_NetAddressu8ZDecodeErrorZ), "LDKCResult_CResult_NetAddressu8ZDecodeErrorZ");
6333         *ret_conv = CResult_CResult_NetAddressu8ZDecodeErrorZ_ok(o_conv);
6334         return (long)ret_conv;
6335 }
6336
6337 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1CResult_1NetAddressu8ZDecodeErrorZ_1err(JNIEnv *env, jclass clz, int64_t e) {
6338         LDKDecodeError e_conv;
6339         e_conv.inner = (void*)(e & (~1));
6340         e_conv.is_owned = (e & 1) || (e == 0);
6341         // Warning: we may need a move here but can't clone!
6342         LDKCResult_CResult_NetAddressu8ZDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_CResult_NetAddressu8ZDecodeErrorZ), "LDKCResult_CResult_NetAddressu8ZDecodeErrorZ");
6343         *ret_conv = CResult_CResult_NetAddressu8ZDecodeErrorZ_err(e_conv);
6344         return (long)ret_conv;
6345 }
6346
6347 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1CResult_1NetAddressu8ZDecodeErrorZ_1free(JNIEnv *env, jclass clz, int64_t _res) {
6348         LDKCResult_CResult_NetAddressu8ZDecodeErrorZ _res_conv = *(LDKCResult_CResult_NetAddressu8ZDecodeErrorZ*)_res;
6349         FREE((void*)_res);
6350         CResult_CResult_NetAddressu8ZDecodeErrorZ_free(_res_conv);
6351 }
6352
6353 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1u64Z_1free(JNIEnv *env, jclass clz, int64_tArray _res) {
6354         LDKCVec_u64Z _res_constr;
6355         _res_constr.datalen = (*env)->GetArrayLength(env, _res);
6356         if (_res_constr.datalen > 0)
6357                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(int64_t), "LDKCVec_u64Z Elements");
6358         else
6359                 _res_constr.data = NULL;
6360         int64_t* _res_vals = (*env)->GetLongArrayElements (env, _res, NULL);
6361         for (size_t g = 0; g < _res_constr.datalen; g++) {
6362                 int64_t arr_conv_6 = _res_vals[g];
6363                 _res_constr.data[g] = arr_conv_6;
6364         }
6365         (*env)->ReleaseLongArrayElements(env, _res, _res_vals, 0);
6366         CVec_u64Z_free(_res_constr);
6367 }
6368
6369 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1UpdateAddHTLCZ_1free(JNIEnv *env, jclass clz, int64_tArray _res) {
6370         LDKCVec_UpdateAddHTLCZ _res_constr;
6371         _res_constr.datalen = (*env)->GetArrayLength(env, _res);
6372         if (_res_constr.datalen > 0)
6373                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKUpdateAddHTLC), "LDKCVec_UpdateAddHTLCZ Elements");
6374         else
6375                 _res_constr.data = NULL;
6376         int64_t* _res_vals = (*env)->GetLongArrayElements (env, _res, NULL);
6377         for (size_t p = 0; p < _res_constr.datalen; p++) {
6378                 int64_t arr_conv_15 = _res_vals[p];
6379                 LDKUpdateAddHTLC arr_conv_15_conv;
6380                 arr_conv_15_conv.inner = (void*)(arr_conv_15 & (~1));
6381                 arr_conv_15_conv.is_owned = (arr_conv_15 & 1) || (arr_conv_15 == 0);
6382                 _res_constr.data[p] = arr_conv_15_conv;
6383         }
6384         (*env)->ReleaseLongArrayElements(env, _res, _res_vals, 0);
6385         CVec_UpdateAddHTLCZ_free(_res_constr);
6386 }
6387
6388 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1UpdateFulfillHTLCZ_1free(JNIEnv *env, jclass clz, int64_tArray _res) {
6389         LDKCVec_UpdateFulfillHTLCZ _res_constr;
6390         _res_constr.datalen = (*env)->GetArrayLength(env, _res);
6391         if (_res_constr.datalen > 0)
6392                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKUpdateFulfillHTLC), "LDKCVec_UpdateFulfillHTLCZ Elements");
6393         else
6394                 _res_constr.data = NULL;
6395         int64_t* _res_vals = (*env)->GetLongArrayElements (env, _res, NULL);
6396         for (size_t t = 0; t < _res_constr.datalen; t++) {
6397                 int64_t arr_conv_19 = _res_vals[t];
6398                 LDKUpdateFulfillHTLC arr_conv_19_conv;
6399                 arr_conv_19_conv.inner = (void*)(arr_conv_19 & (~1));
6400                 arr_conv_19_conv.is_owned = (arr_conv_19 & 1) || (arr_conv_19 == 0);
6401                 _res_constr.data[t] = arr_conv_19_conv;
6402         }
6403         (*env)->ReleaseLongArrayElements(env, _res, _res_vals, 0);
6404         CVec_UpdateFulfillHTLCZ_free(_res_constr);
6405 }
6406
6407 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1UpdateFailHTLCZ_1free(JNIEnv *env, jclass clz, int64_tArray _res) {
6408         LDKCVec_UpdateFailHTLCZ _res_constr;
6409         _res_constr.datalen = (*env)->GetArrayLength(env, _res);
6410         if (_res_constr.datalen > 0)
6411                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKUpdateFailHTLC), "LDKCVec_UpdateFailHTLCZ Elements");
6412         else
6413                 _res_constr.data = NULL;
6414         int64_t* _res_vals = (*env)->GetLongArrayElements (env, _res, NULL);
6415         for (size_t q = 0; q < _res_constr.datalen; q++) {
6416                 int64_t arr_conv_16 = _res_vals[q];
6417                 LDKUpdateFailHTLC arr_conv_16_conv;
6418                 arr_conv_16_conv.inner = (void*)(arr_conv_16 & (~1));
6419                 arr_conv_16_conv.is_owned = (arr_conv_16 & 1) || (arr_conv_16 == 0);
6420                 _res_constr.data[q] = arr_conv_16_conv;
6421         }
6422         (*env)->ReleaseLongArrayElements(env, _res, _res_vals, 0);
6423         CVec_UpdateFailHTLCZ_free(_res_constr);
6424 }
6425
6426 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1UpdateFailMalformedHTLCZ_1free(JNIEnv *env, jclass clz, int64_tArray _res) {
6427         LDKCVec_UpdateFailMalformedHTLCZ _res_constr;
6428         _res_constr.datalen = (*env)->GetArrayLength(env, _res);
6429         if (_res_constr.datalen > 0)
6430                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKUpdateFailMalformedHTLC), "LDKCVec_UpdateFailMalformedHTLCZ Elements");
6431         else
6432                 _res_constr.data = NULL;
6433         int64_t* _res_vals = (*env)->GetLongArrayElements (env, _res, NULL);
6434         for (size_t z = 0; z < _res_constr.datalen; z++) {
6435                 int64_t arr_conv_25 = _res_vals[z];
6436                 LDKUpdateFailMalformedHTLC arr_conv_25_conv;
6437                 arr_conv_25_conv.inner = (void*)(arr_conv_25 & (~1));
6438                 arr_conv_25_conv.is_owned = (arr_conv_25 & 1) || (arr_conv_25 == 0);
6439                 _res_constr.data[z] = arr_conv_25_conv;
6440         }
6441         (*env)->ReleaseLongArrayElements(env, _res, _res_vals, 0);
6442         CVec_UpdateFailMalformedHTLCZ_free(_res_constr);
6443 }
6444
6445 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1boolLightningErrorZ_1ok(JNIEnv *env, jclass clz, jboolean o) {
6446         LDKCResult_boolLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_boolLightningErrorZ), "LDKCResult_boolLightningErrorZ");
6447         *ret_conv = CResult_boolLightningErrorZ_ok(o);
6448         return (long)ret_conv;
6449 }
6450
6451 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1boolLightningErrorZ_1err(JNIEnv *env, jclass clz, int64_t e) {
6452         LDKLightningError e_conv;
6453         e_conv.inner = (void*)(e & (~1));
6454         e_conv.is_owned = (e & 1) || (e == 0);
6455         // Warning: we may need a move here but can't clone!
6456         LDKCResult_boolLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_boolLightningErrorZ), "LDKCResult_boolLightningErrorZ");
6457         *ret_conv = CResult_boolLightningErrorZ_err(e_conv);
6458         return (long)ret_conv;
6459 }
6460
6461 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1boolLightningErrorZ_1free(JNIEnv *env, jclass clz, int64_t _res) {
6462         LDKCResult_boolLightningErrorZ _res_conv = *(LDKCResult_boolLightningErrorZ*)_res;
6463         FREE((void*)_res);
6464         CResult_boolLightningErrorZ_free(_res_conv);
6465 }
6466
6467 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_C3Tuple_1ChannelAnnouncementChannelUpdateChannelUpdateZ_1free(JNIEnv *env, jclass clz, int64_t _res) {
6468         LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ _res_conv = *(LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ*)_res;
6469         FREE((void*)_res);
6470         C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ_free(_res_conv);
6471 }
6472
6473 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) {
6474         LDKChannelAnnouncement a_conv;
6475         a_conv.inner = (void*)(a & (~1));
6476         a_conv.is_owned = (a & 1) || (a == 0);
6477         if (a_conv.inner != NULL)
6478                 a_conv = ChannelAnnouncement_clone(&a_conv);
6479         LDKChannelUpdate b_conv;
6480         b_conv.inner = (void*)(b & (~1));
6481         b_conv.is_owned = (b & 1) || (b == 0);
6482         if (b_conv.inner != NULL)
6483                 b_conv = ChannelUpdate_clone(&b_conv);
6484         LDKChannelUpdate c_conv;
6485         c_conv.inner = (void*)(c & (~1));
6486         c_conv.is_owned = (c & 1) || (c == 0);
6487         if (c_conv.inner != NULL)
6488                 c_conv = ChannelUpdate_clone(&c_conv);
6489         LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ* ret_ref = MALLOC(sizeof(LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ), "LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ");
6490         *ret_ref = C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ_new(a_conv, b_conv, c_conv);
6491         ret_ref->a = ChannelAnnouncement_clone(&ret_ref->a);
6492         ret_ref->b = ChannelUpdate_clone(&ret_ref->b);
6493         ret_ref->c = ChannelUpdate_clone(&ret_ref->c);
6494         return (long)ret_ref;
6495 }
6496
6497 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1C3Tuple_1ChannelAnnouncementChannelUpdateChannelUpdateZZ_1free(JNIEnv *env, jclass clz, int64_tArray _res) {
6498         LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ _res_constr;
6499         _res_constr.datalen = (*env)->GetArrayLength(env, _res);
6500         if (_res_constr.datalen > 0)
6501                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ), "LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ Elements");
6502         else
6503                 _res_constr.data = NULL;
6504         int64_t* _res_vals = (*env)->GetLongArrayElements (env, _res, NULL);
6505         for (size_t l = 0; l < _res_constr.datalen; l++) {
6506                 int64_t arr_conv_63 = _res_vals[l];
6507                 LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ arr_conv_63_conv = *(LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ*)arr_conv_63;
6508                 FREE((void*)arr_conv_63);
6509                 _res_constr.data[l] = arr_conv_63_conv;
6510         }
6511         (*env)->ReleaseLongArrayElements(env, _res, _res_vals, 0);
6512         CVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ_free(_res_constr);
6513 }
6514
6515 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1NodeAnnouncementZ_1free(JNIEnv *env, jclass clz, int64_tArray _res) {
6516         LDKCVec_NodeAnnouncementZ _res_constr;
6517         _res_constr.datalen = (*env)->GetArrayLength(env, _res);
6518         if (_res_constr.datalen > 0)
6519                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKNodeAnnouncement), "LDKCVec_NodeAnnouncementZ Elements");
6520         else
6521                 _res_constr.data = NULL;
6522         int64_t* _res_vals = (*env)->GetLongArrayElements (env, _res, NULL);
6523         for (size_t s = 0; s < _res_constr.datalen; s++) {
6524                 int64_t arr_conv_18 = _res_vals[s];
6525                 LDKNodeAnnouncement arr_conv_18_conv;
6526                 arr_conv_18_conv.inner = (void*)(arr_conv_18 & (~1));
6527                 arr_conv_18_conv.is_owned = (arr_conv_18 & 1) || (arr_conv_18 == 0);
6528                 _res_constr.data[s] = arr_conv_18_conv;
6529         }
6530         (*env)->ReleaseLongArrayElements(env, _res, _res_vals, 0);
6531         CVec_NodeAnnouncementZ_free(_res_constr);
6532 }
6533
6534 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1NoneLightningErrorZ_1ok(JNIEnv *env, jclass clz) {
6535         LDKCResult_NoneLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneLightningErrorZ), "LDKCResult_NoneLightningErrorZ");
6536         *ret_conv = CResult_NoneLightningErrorZ_ok();
6537         return (long)ret_conv;
6538 }
6539
6540 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1NoneLightningErrorZ_1err(JNIEnv *env, jclass clz, int64_t e) {
6541         LDKLightningError e_conv;
6542         e_conv.inner = (void*)(e & (~1));
6543         e_conv.is_owned = (e & 1) || (e == 0);
6544         // Warning: we may need a move here but can't clone!
6545         LDKCResult_NoneLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneLightningErrorZ), "LDKCResult_NoneLightningErrorZ");
6546         *ret_conv = CResult_NoneLightningErrorZ_err(e_conv);
6547         return (long)ret_conv;
6548 }
6549
6550 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1NoneLightningErrorZ_1free(JNIEnv *env, jclass clz, int64_t _res) {
6551         LDKCResult_NoneLightningErrorZ _res_conv = *(LDKCResult_NoneLightningErrorZ*)_res;
6552         FREE((void*)_res);
6553         CResult_NoneLightningErrorZ_free(_res_conv);
6554 }
6555
6556 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1ChannelReestablishDecodeErrorZ_1ok(JNIEnv *env, jclass clz, int64_t o) {
6557         LDKChannelReestablish o_conv;
6558         o_conv.inner = (void*)(o & (~1));
6559         o_conv.is_owned = (o & 1) || (o == 0);
6560         if (o_conv.inner != NULL)
6561                 o_conv = ChannelReestablish_clone(&o_conv);
6562         LDKCResult_ChannelReestablishDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ChannelReestablishDecodeErrorZ), "LDKCResult_ChannelReestablishDecodeErrorZ");
6563         *ret_conv = CResult_ChannelReestablishDecodeErrorZ_ok(o_conv);
6564         return (long)ret_conv;
6565 }
6566
6567 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1ChannelReestablishDecodeErrorZ_1err(JNIEnv *env, jclass clz, int64_t e) {
6568         LDKDecodeError e_conv;
6569         e_conv.inner = (void*)(e & (~1));
6570         e_conv.is_owned = (e & 1) || (e == 0);
6571         // Warning: we may need a move here but can't clone!
6572         LDKCResult_ChannelReestablishDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ChannelReestablishDecodeErrorZ), "LDKCResult_ChannelReestablishDecodeErrorZ");
6573         *ret_conv = CResult_ChannelReestablishDecodeErrorZ_err(e_conv);
6574         return (long)ret_conv;
6575 }
6576
6577 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1ChannelReestablishDecodeErrorZ_1free(JNIEnv *env, jclass clz, int64_t _res) {
6578         LDKCResult_ChannelReestablishDecodeErrorZ _res_conv = *(LDKCResult_ChannelReestablishDecodeErrorZ*)_res;
6579         FREE((void*)_res);
6580         CResult_ChannelReestablishDecodeErrorZ_free(_res_conv);
6581 }
6582
6583 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1InitDecodeErrorZ_1ok(JNIEnv *env, jclass clz, int64_t o) {
6584         LDKInit o_conv;
6585         o_conv.inner = (void*)(o & (~1));
6586         o_conv.is_owned = (o & 1) || (o == 0);
6587         if (o_conv.inner != NULL)
6588                 o_conv = Init_clone(&o_conv);
6589         LDKCResult_InitDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_InitDecodeErrorZ), "LDKCResult_InitDecodeErrorZ");
6590         *ret_conv = CResult_InitDecodeErrorZ_ok(o_conv);
6591         return (long)ret_conv;
6592 }
6593
6594 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1InitDecodeErrorZ_1err(JNIEnv *env, jclass clz, int64_t e) {
6595         LDKDecodeError e_conv;
6596         e_conv.inner = (void*)(e & (~1));
6597         e_conv.is_owned = (e & 1) || (e == 0);
6598         // Warning: we may need a move here but can't clone!
6599         LDKCResult_InitDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_InitDecodeErrorZ), "LDKCResult_InitDecodeErrorZ");
6600         *ret_conv = CResult_InitDecodeErrorZ_err(e_conv);
6601         return (long)ret_conv;
6602 }
6603
6604 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1InitDecodeErrorZ_1free(JNIEnv *env, jclass clz, int64_t _res) {
6605         LDKCResult_InitDecodeErrorZ _res_conv = *(LDKCResult_InitDecodeErrorZ*)_res;
6606         FREE((void*)_res);
6607         CResult_InitDecodeErrorZ_free(_res_conv);
6608 }
6609
6610 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1PingDecodeErrorZ_1ok(JNIEnv *env, jclass clz, int64_t o) {
6611         LDKPing o_conv;
6612         o_conv.inner = (void*)(o & (~1));
6613         o_conv.is_owned = (o & 1) || (o == 0);
6614         if (o_conv.inner != NULL)
6615                 o_conv = Ping_clone(&o_conv);
6616         LDKCResult_PingDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_PingDecodeErrorZ), "LDKCResult_PingDecodeErrorZ");
6617         *ret_conv = CResult_PingDecodeErrorZ_ok(o_conv);
6618         return (long)ret_conv;
6619 }
6620
6621 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1PingDecodeErrorZ_1err(JNIEnv *env, jclass clz, int64_t e) {
6622         LDKDecodeError e_conv;
6623         e_conv.inner = (void*)(e & (~1));
6624         e_conv.is_owned = (e & 1) || (e == 0);
6625         // Warning: we may need a move here but can't clone!
6626         LDKCResult_PingDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_PingDecodeErrorZ), "LDKCResult_PingDecodeErrorZ");
6627         *ret_conv = CResult_PingDecodeErrorZ_err(e_conv);
6628         return (long)ret_conv;
6629 }
6630
6631 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1PingDecodeErrorZ_1free(JNIEnv *env, jclass clz, int64_t _res) {
6632         LDKCResult_PingDecodeErrorZ _res_conv = *(LDKCResult_PingDecodeErrorZ*)_res;
6633         FREE((void*)_res);
6634         CResult_PingDecodeErrorZ_free(_res_conv);
6635 }
6636
6637 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1PongDecodeErrorZ_1ok(JNIEnv *env, jclass clz, int64_t o) {
6638         LDKPong o_conv;
6639         o_conv.inner = (void*)(o & (~1));
6640         o_conv.is_owned = (o & 1) || (o == 0);
6641         if (o_conv.inner != NULL)
6642                 o_conv = Pong_clone(&o_conv);
6643         LDKCResult_PongDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_PongDecodeErrorZ), "LDKCResult_PongDecodeErrorZ");
6644         *ret_conv = CResult_PongDecodeErrorZ_ok(o_conv);
6645         return (long)ret_conv;
6646 }
6647
6648 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1PongDecodeErrorZ_1err(JNIEnv *env, jclass clz, int64_t e) {
6649         LDKDecodeError e_conv;
6650         e_conv.inner = (void*)(e & (~1));
6651         e_conv.is_owned = (e & 1) || (e == 0);
6652         // Warning: we may need a move here but can't clone!
6653         LDKCResult_PongDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_PongDecodeErrorZ), "LDKCResult_PongDecodeErrorZ");
6654         *ret_conv = CResult_PongDecodeErrorZ_err(e_conv);
6655         return (long)ret_conv;
6656 }
6657
6658 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1PongDecodeErrorZ_1free(JNIEnv *env, jclass clz, int64_t _res) {
6659         LDKCResult_PongDecodeErrorZ _res_conv = *(LDKCResult_PongDecodeErrorZ*)_res;
6660         FREE((void*)_res);
6661         CResult_PongDecodeErrorZ_free(_res_conv);
6662 }
6663
6664 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1UnsignedChannelAnnouncementDecodeErrorZ_1ok(JNIEnv *env, jclass clz, int64_t o) {
6665         LDKUnsignedChannelAnnouncement o_conv;
6666         o_conv.inner = (void*)(o & (~1));
6667         o_conv.is_owned = (o & 1) || (o == 0);
6668         if (o_conv.inner != NULL)
6669                 o_conv = UnsignedChannelAnnouncement_clone(&o_conv);
6670         LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ), "LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ");
6671         *ret_conv = CResult_UnsignedChannelAnnouncementDecodeErrorZ_ok(o_conv);
6672         return (long)ret_conv;
6673 }
6674
6675 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1UnsignedChannelAnnouncementDecodeErrorZ_1err(JNIEnv *env, jclass clz, int64_t e) {
6676         LDKDecodeError e_conv;
6677         e_conv.inner = (void*)(e & (~1));
6678         e_conv.is_owned = (e & 1) || (e == 0);
6679         // Warning: we may need a move here but can't clone!
6680         LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ), "LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ");
6681         *ret_conv = CResult_UnsignedChannelAnnouncementDecodeErrorZ_err(e_conv);
6682         return (long)ret_conv;
6683 }
6684
6685 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1UnsignedChannelAnnouncementDecodeErrorZ_1free(JNIEnv *env, jclass clz, int64_t _res) {
6686         LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ _res_conv = *(LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ*)_res;
6687         FREE((void*)_res);
6688         CResult_UnsignedChannelAnnouncementDecodeErrorZ_free(_res_conv);
6689 }
6690
6691 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1UnsignedChannelUpdateDecodeErrorZ_1ok(JNIEnv *env, jclass clz, int64_t o) {
6692         LDKUnsignedChannelUpdate o_conv;
6693         o_conv.inner = (void*)(o & (~1));
6694         o_conv.is_owned = (o & 1) || (o == 0);
6695         if (o_conv.inner != NULL)
6696                 o_conv = UnsignedChannelUpdate_clone(&o_conv);
6697         LDKCResult_UnsignedChannelUpdateDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_UnsignedChannelUpdateDecodeErrorZ), "LDKCResult_UnsignedChannelUpdateDecodeErrorZ");
6698         *ret_conv = CResult_UnsignedChannelUpdateDecodeErrorZ_ok(o_conv);
6699         return (long)ret_conv;
6700 }
6701
6702 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1UnsignedChannelUpdateDecodeErrorZ_1err(JNIEnv *env, jclass clz, int64_t e) {
6703         LDKDecodeError e_conv;
6704         e_conv.inner = (void*)(e & (~1));
6705         e_conv.is_owned = (e & 1) || (e == 0);
6706         // Warning: we may need a move here but can't clone!
6707         LDKCResult_UnsignedChannelUpdateDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_UnsignedChannelUpdateDecodeErrorZ), "LDKCResult_UnsignedChannelUpdateDecodeErrorZ");
6708         *ret_conv = CResult_UnsignedChannelUpdateDecodeErrorZ_err(e_conv);
6709         return (long)ret_conv;
6710 }
6711
6712 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1UnsignedChannelUpdateDecodeErrorZ_1free(JNIEnv *env, jclass clz, int64_t _res) {
6713         LDKCResult_UnsignedChannelUpdateDecodeErrorZ _res_conv = *(LDKCResult_UnsignedChannelUpdateDecodeErrorZ*)_res;
6714         FREE((void*)_res);
6715         CResult_UnsignedChannelUpdateDecodeErrorZ_free(_res_conv);
6716 }
6717
6718 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1ErrorMessageDecodeErrorZ_1ok(JNIEnv *env, jclass clz, int64_t o) {
6719         LDKErrorMessage o_conv;
6720         o_conv.inner = (void*)(o & (~1));
6721         o_conv.is_owned = (o & 1) || (o == 0);
6722         if (o_conv.inner != NULL)
6723                 o_conv = ErrorMessage_clone(&o_conv);
6724         LDKCResult_ErrorMessageDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ErrorMessageDecodeErrorZ), "LDKCResult_ErrorMessageDecodeErrorZ");
6725         *ret_conv = CResult_ErrorMessageDecodeErrorZ_ok(o_conv);
6726         return (long)ret_conv;
6727 }
6728
6729 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1ErrorMessageDecodeErrorZ_1err(JNIEnv *env, jclass clz, int64_t e) {
6730         LDKDecodeError e_conv;
6731         e_conv.inner = (void*)(e & (~1));
6732         e_conv.is_owned = (e & 1) || (e == 0);
6733         // Warning: we may need a move here but can't clone!
6734         LDKCResult_ErrorMessageDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ErrorMessageDecodeErrorZ), "LDKCResult_ErrorMessageDecodeErrorZ");
6735         *ret_conv = CResult_ErrorMessageDecodeErrorZ_err(e_conv);
6736         return (long)ret_conv;
6737 }
6738
6739 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1ErrorMessageDecodeErrorZ_1free(JNIEnv *env, jclass clz, int64_t _res) {
6740         LDKCResult_ErrorMessageDecodeErrorZ _res_conv = *(LDKCResult_ErrorMessageDecodeErrorZ*)_res;
6741         FREE((void*)_res);
6742         CResult_ErrorMessageDecodeErrorZ_free(_res_conv);
6743 }
6744
6745 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1UnsignedNodeAnnouncementDecodeErrorZ_1ok(JNIEnv *env, jclass clz, int64_t o) {
6746         LDKUnsignedNodeAnnouncement o_conv;
6747         o_conv.inner = (void*)(o & (~1));
6748         o_conv.is_owned = (o & 1) || (o == 0);
6749         if (o_conv.inner != NULL)
6750                 o_conv = UnsignedNodeAnnouncement_clone(&o_conv);
6751         LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ), "LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ");
6752         *ret_conv = CResult_UnsignedNodeAnnouncementDecodeErrorZ_ok(o_conv);
6753         return (long)ret_conv;
6754 }
6755
6756 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1UnsignedNodeAnnouncementDecodeErrorZ_1err(JNIEnv *env, jclass clz, int64_t e) {
6757         LDKDecodeError e_conv;
6758         e_conv.inner = (void*)(e & (~1));
6759         e_conv.is_owned = (e & 1) || (e == 0);
6760         // Warning: we may need a move here but can't clone!
6761         LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ), "LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ");
6762         *ret_conv = CResult_UnsignedNodeAnnouncementDecodeErrorZ_err(e_conv);
6763         return (long)ret_conv;
6764 }
6765
6766 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1UnsignedNodeAnnouncementDecodeErrorZ_1free(JNIEnv *env, jclass clz, int64_t _res) {
6767         LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ _res_conv = *(LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ*)_res;
6768         FREE((void*)_res);
6769         CResult_UnsignedNodeAnnouncementDecodeErrorZ_free(_res_conv);
6770 }
6771
6772 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1QueryShortChannelIdsDecodeErrorZ_1ok(JNIEnv *env, jclass clz, int64_t o) {
6773         LDKQueryShortChannelIds o_conv;
6774         o_conv.inner = (void*)(o & (~1));
6775         o_conv.is_owned = (o & 1) || (o == 0);
6776         if (o_conv.inner != NULL)
6777                 o_conv = QueryShortChannelIds_clone(&o_conv);
6778         LDKCResult_QueryShortChannelIdsDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_QueryShortChannelIdsDecodeErrorZ), "LDKCResult_QueryShortChannelIdsDecodeErrorZ");
6779         *ret_conv = CResult_QueryShortChannelIdsDecodeErrorZ_ok(o_conv);
6780         return (long)ret_conv;
6781 }
6782
6783 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1QueryShortChannelIdsDecodeErrorZ_1err(JNIEnv *env, jclass clz, int64_t e) {
6784         LDKDecodeError e_conv;
6785         e_conv.inner = (void*)(e & (~1));
6786         e_conv.is_owned = (e & 1) || (e == 0);
6787         // Warning: we may need a move here but can't clone!
6788         LDKCResult_QueryShortChannelIdsDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_QueryShortChannelIdsDecodeErrorZ), "LDKCResult_QueryShortChannelIdsDecodeErrorZ");
6789         *ret_conv = CResult_QueryShortChannelIdsDecodeErrorZ_err(e_conv);
6790         return (long)ret_conv;
6791 }
6792
6793 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1QueryShortChannelIdsDecodeErrorZ_1free(JNIEnv *env, jclass clz, int64_t _res) {
6794         LDKCResult_QueryShortChannelIdsDecodeErrorZ _res_conv = *(LDKCResult_QueryShortChannelIdsDecodeErrorZ*)_res;
6795         FREE((void*)_res);
6796         CResult_QueryShortChannelIdsDecodeErrorZ_free(_res_conv);
6797 }
6798
6799 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1ReplyShortChannelIdsEndDecodeErrorZ_1ok(JNIEnv *env, jclass clz, int64_t o) {
6800         LDKReplyShortChannelIdsEnd o_conv;
6801         o_conv.inner = (void*)(o & (~1));
6802         o_conv.is_owned = (o & 1) || (o == 0);
6803         if (o_conv.inner != NULL)
6804                 o_conv = ReplyShortChannelIdsEnd_clone(&o_conv);
6805         LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ), "LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ");
6806         *ret_conv = CResult_ReplyShortChannelIdsEndDecodeErrorZ_ok(o_conv);
6807         return (long)ret_conv;
6808 }
6809
6810 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1ReplyShortChannelIdsEndDecodeErrorZ_1err(JNIEnv *env, jclass clz, int64_t e) {
6811         LDKDecodeError e_conv;
6812         e_conv.inner = (void*)(e & (~1));
6813         e_conv.is_owned = (e & 1) || (e == 0);
6814         // Warning: we may need a move here but can't clone!
6815         LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ), "LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ");
6816         *ret_conv = CResult_ReplyShortChannelIdsEndDecodeErrorZ_err(e_conv);
6817         return (long)ret_conv;
6818 }
6819
6820 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1ReplyShortChannelIdsEndDecodeErrorZ_1free(JNIEnv *env, jclass clz, int64_t _res) {
6821         LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ _res_conv = *(LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ*)_res;
6822         FREE((void*)_res);
6823         CResult_ReplyShortChannelIdsEndDecodeErrorZ_free(_res_conv);
6824 }
6825
6826 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1QueryChannelRangeDecodeErrorZ_1ok(JNIEnv *env, jclass clz, int64_t o) {
6827         LDKQueryChannelRange o_conv;
6828         o_conv.inner = (void*)(o & (~1));
6829         o_conv.is_owned = (o & 1) || (o == 0);
6830         if (o_conv.inner != NULL)
6831                 o_conv = QueryChannelRange_clone(&o_conv);
6832         LDKCResult_QueryChannelRangeDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_QueryChannelRangeDecodeErrorZ), "LDKCResult_QueryChannelRangeDecodeErrorZ");
6833         *ret_conv = CResult_QueryChannelRangeDecodeErrorZ_ok(o_conv);
6834         return (long)ret_conv;
6835 }
6836
6837 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1QueryChannelRangeDecodeErrorZ_1err(JNIEnv *env, jclass clz, int64_t e) {
6838         LDKDecodeError e_conv;
6839         e_conv.inner = (void*)(e & (~1));
6840         e_conv.is_owned = (e & 1) || (e == 0);
6841         // Warning: we may need a move here but can't clone!
6842         LDKCResult_QueryChannelRangeDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_QueryChannelRangeDecodeErrorZ), "LDKCResult_QueryChannelRangeDecodeErrorZ");
6843         *ret_conv = CResult_QueryChannelRangeDecodeErrorZ_err(e_conv);
6844         return (long)ret_conv;
6845 }
6846
6847 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1QueryChannelRangeDecodeErrorZ_1free(JNIEnv *env, jclass clz, int64_t _res) {
6848         LDKCResult_QueryChannelRangeDecodeErrorZ _res_conv = *(LDKCResult_QueryChannelRangeDecodeErrorZ*)_res;
6849         FREE((void*)_res);
6850         CResult_QueryChannelRangeDecodeErrorZ_free(_res_conv);
6851 }
6852
6853 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1ReplyChannelRangeDecodeErrorZ_1ok(JNIEnv *env, jclass clz, int64_t o) {
6854         LDKReplyChannelRange o_conv;
6855         o_conv.inner = (void*)(o & (~1));
6856         o_conv.is_owned = (o & 1) || (o == 0);
6857         if (o_conv.inner != NULL)
6858                 o_conv = ReplyChannelRange_clone(&o_conv);
6859         LDKCResult_ReplyChannelRangeDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ReplyChannelRangeDecodeErrorZ), "LDKCResult_ReplyChannelRangeDecodeErrorZ");
6860         *ret_conv = CResult_ReplyChannelRangeDecodeErrorZ_ok(o_conv);
6861         return (long)ret_conv;
6862 }
6863
6864 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1ReplyChannelRangeDecodeErrorZ_1err(JNIEnv *env, jclass clz, int64_t e) {
6865         LDKDecodeError e_conv;
6866         e_conv.inner = (void*)(e & (~1));
6867         e_conv.is_owned = (e & 1) || (e == 0);
6868         // Warning: we may need a move here but can't clone!
6869         LDKCResult_ReplyChannelRangeDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ReplyChannelRangeDecodeErrorZ), "LDKCResult_ReplyChannelRangeDecodeErrorZ");
6870         *ret_conv = CResult_ReplyChannelRangeDecodeErrorZ_err(e_conv);
6871         return (long)ret_conv;
6872 }
6873
6874 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1ReplyChannelRangeDecodeErrorZ_1free(JNIEnv *env, jclass clz, int64_t _res) {
6875         LDKCResult_ReplyChannelRangeDecodeErrorZ _res_conv = *(LDKCResult_ReplyChannelRangeDecodeErrorZ*)_res;
6876         FREE((void*)_res);
6877         CResult_ReplyChannelRangeDecodeErrorZ_free(_res_conv);
6878 }
6879
6880 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1GossipTimestampFilterDecodeErrorZ_1ok(JNIEnv *env, jclass clz, int64_t o) {
6881         LDKGossipTimestampFilter o_conv;
6882         o_conv.inner = (void*)(o & (~1));
6883         o_conv.is_owned = (o & 1) || (o == 0);
6884         if (o_conv.inner != NULL)
6885                 o_conv = GossipTimestampFilter_clone(&o_conv);
6886         LDKCResult_GossipTimestampFilterDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_GossipTimestampFilterDecodeErrorZ), "LDKCResult_GossipTimestampFilterDecodeErrorZ");
6887         *ret_conv = CResult_GossipTimestampFilterDecodeErrorZ_ok(o_conv);
6888         return (long)ret_conv;
6889 }
6890
6891 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1GossipTimestampFilterDecodeErrorZ_1err(JNIEnv *env, jclass clz, int64_t e) {
6892         LDKDecodeError e_conv;
6893         e_conv.inner = (void*)(e & (~1));
6894         e_conv.is_owned = (e & 1) || (e == 0);
6895         // Warning: we may need a move here but can't clone!
6896         LDKCResult_GossipTimestampFilterDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_GossipTimestampFilterDecodeErrorZ), "LDKCResult_GossipTimestampFilterDecodeErrorZ");
6897         *ret_conv = CResult_GossipTimestampFilterDecodeErrorZ_err(e_conv);
6898         return (long)ret_conv;
6899 }
6900
6901 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1GossipTimestampFilterDecodeErrorZ_1free(JNIEnv *env, jclass clz, int64_t _res) {
6902         LDKCResult_GossipTimestampFilterDecodeErrorZ _res_conv = *(LDKCResult_GossipTimestampFilterDecodeErrorZ*)_res;
6903         FREE((void*)_res);
6904         CResult_GossipTimestampFilterDecodeErrorZ_free(_res_conv);
6905 }
6906
6907 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1PublicKeyZ_1free(JNIEnv *env, jclass clz, jobjectArray _res) {
6908         LDKCVec_PublicKeyZ _res_constr;
6909         _res_constr.datalen = (*env)->GetArrayLength(env, _res);
6910         if (_res_constr.datalen > 0)
6911                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKPublicKey), "LDKCVec_PublicKeyZ Elements");
6912         else
6913                 _res_constr.data = NULL;
6914         for (size_t i = 0; i < _res_constr.datalen; i++) {
6915                 int8_tArray arr_conv_8 = (*env)->GetObjectArrayElement(env, _res, i);
6916                 LDKPublicKey arr_conv_8_ref;
6917                 CHECK((*env)->GetArrayLength(env, arr_conv_8) == 33);
6918                 (*env)->GetByteArrayRegion(env, arr_conv_8, 0, 33, arr_conv_8_ref.compressed_form);
6919                 _res_constr.data[i] = arr_conv_8_ref;
6920         }
6921         CVec_PublicKeyZ_free(_res_constr);
6922 }
6923
6924 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1u8Z_1free(JNIEnv *env, jclass clz, int8_tArray _res) {
6925         LDKCVec_u8Z _res_ref;
6926         _res_ref.datalen = (*env)->GetArrayLength(env, _res);
6927         _res_ref.data = MALLOC(_res_ref.datalen, "LDKCVec_u8Z Bytes");
6928         (*env)->GetByteArrayRegion(env, _res, 0, _res_ref.datalen, _res_ref.data);
6929         CVec_u8Z_free(_res_ref);
6930 }
6931
6932 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1CVec_1u8ZPeerHandleErrorZ_1ok(JNIEnv *env, jclass clz, int8_tArray o) {
6933         LDKCVec_u8Z o_ref;
6934         o_ref.datalen = (*env)->GetArrayLength(env, o);
6935         o_ref.data = MALLOC(o_ref.datalen, "LDKCVec_u8Z Bytes");
6936         (*env)->GetByteArrayRegion(env, o, 0, o_ref.datalen, o_ref.data);
6937         LDKCResult_CVec_u8ZPeerHandleErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_CVec_u8ZPeerHandleErrorZ), "LDKCResult_CVec_u8ZPeerHandleErrorZ");
6938         *ret_conv = CResult_CVec_u8ZPeerHandleErrorZ_ok(o_ref);
6939         return (long)ret_conv;
6940 }
6941
6942 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1CVec_1u8ZPeerHandleErrorZ_1err(JNIEnv *env, jclass clz, int64_t e) {
6943         LDKPeerHandleError e_conv;
6944         e_conv.inner = (void*)(e & (~1));
6945         e_conv.is_owned = (e & 1) || (e == 0);
6946         // Warning: we may need a move here but can't clone!
6947         LDKCResult_CVec_u8ZPeerHandleErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_CVec_u8ZPeerHandleErrorZ), "LDKCResult_CVec_u8ZPeerHandleErrorZ");
6948         *ret_conv = CResult_CVec_u8ZPeerHandleErrorZ_err(e_conv);
6949         return (long)ret_conv;
6950 }
6951
6952 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1CVec_1u8ZPeerHandleErrorZ_1free(JNIEnv *env, jclass clz, int64_t _res) {
6953         LDKCResult_CVec_u8ZPeerHandleErrorZ _res_conv = *(LDKCResult_CVec_u8ZPeerHandleErrorZ*)_res;
6954         FREE((void*)_res);
6955         CResult_CVec_u8ZPeerHandleErrorZ_free(_res_conv);
6956 }
6957
6958 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1NonePeerHandleErrorZ_1ok(JNIEnv *env, jclass clz) {
6959         LDKCResult_NonePeerHandleErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NonePeerHandleErrorZ), "LDKCResult_NonePeerHandleErrorZ");
6960         *ret_conv = CResult_NonePeerHandleErrorZ_ok();
6961         return (long)ret_conv;
6962 }
6963
6964 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1NonePeerHandleErrorZ_1err(JNIEnv *env, jclass clz, int64_t e) {
6965         LDKPeerHandleError e_conv;
6966         e_conv.inner = (void*)(e & (~1));
6967         e_conv.is_owned = (e & 1) || (e == 0);
6968         // Warning: we may need a move here but can't clone!
6969         LDKCResult_NonePeerHandleErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NonePeerHandleErrorZ), "LDKCResult_NonePeerHandleErrorZ");
6970         *ret_conv = CResult_NonePeerHandleErrorZ_err(e_conv);
6971         return (long)ret_conv;
6972 }
6973
6974 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1NonePeerHandleErrorZ_1free(JNIEnv *env, jclass clz, int64_t _res) {
6975         LDKCResult_NonePeerHandleErrorZ _res_conv = *(LDKCResult_NonePeerHandleErrorZ*)_res;
6976         FREE((void*)_res);
6977         CResult_NonePeerHandleErrorZ_free(_res_conv);
6978 }
6979
6980 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1boolPeerHandleErrorZ_1ok(JNIEnv *env, jclass clz, jboolean o) {
6981         LDKCResult_boolPeerHandleErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_boolPeerHandleErrorZ), "LDKCResult_boolPeerHandleErrorZ");
6982         *ret_conv = CResult_boolPeerHandleErrorZ_ok(o);
6983         return (long)ret_conv;
6984 }
6985
6986 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1boolPeerHandleErrorZ_1err(JNIEnv *env, jclass clz, int64_t e) {
6987         LDKPeerHandleError e_conv;
6988         e_conv.inner = (void*)(e & (~1));
6989         e_conv.is_owned = (e & 1) || (e == 0);
6990         // Warning: we may need a move here but can't clone!
6991         LDKCResult_boolPeerHandleErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_boolPeerHandleErrorZ), "LDKCResult_boolPeerHandleErrorZ");
6992         *ret_conv = CResult_boolPeerHandleErrorZ_err(e_conv);
6993         return (long)ret_conv;
6994 }
6995
6996 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1boolPeerHandleErrorZ_1free(JNIEnv *env, jclass clz, int64_t _res) {
6997         LDKCResult_boolPeerHandleErrorZ _res_conv = *(LDKCResult_boolPeerHandleErrorZ*)_res;
6998         FREE((void*)_res);
6999         CResult_boolPeerHandleErrorZ_free(_res_conv);
7000 }
7001
7002 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1SecretKeySecpErrorZ_1ok(JNIEnv *env, jclass clz, int8_tArray o) {
7003         LDKSecretKey o_ref;
7004         CHECK((*env)->GetArrayLength(env, o) == 32);
7005         (*env)->GetByteArrayRegion(env, o, 0, 32, o_ref.bytes);
7006         LDKCResult_SecretKeySecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_SecretKeySecpErrorZ), "LDKCResult_SecretKeySecpErrorZ");
7007         *ret_conv = CResult_SecretKeySecpErrorZ_ok(o_ref);
7008         return (long)ret_conv;
7009 }
7010
7011 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1SecretKeySecpErrorZ_1err(JNIEnv *env, jclass clz, jclass e) {
7012         LDKSecp256k1Error e_conv = LDKSecp256k1Error_from_java(env, e);
7013         LDKCResult_SecretKeySecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_SecretKeySecpErrorZ), "LDKCResult_SecretKeySecpErrorZ");
7014         *ret_conv = CResult_SecretKeySecpErrorZ_err(e_conv);
7015         return (long)ret_conv;
7016 }
7017
7018 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1SecretKeySecpErrorZ_1free(JNIEnv *env, jclass clz, int64_t _res) {
7019         LDKCResult_SecretKeySecpErrorZ _res_conv = *(LDKCResult_SecretKeySecpErrorZ*)_res;
7020         FREE((void*)_res);
7021         CResult_SecretKeySecpErrorZ_free(_res_conv);
7022 }
7023
7024 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1PublicKeySecpErrorZ_1ok(JNIEnv *env, jclass clz, int8_tArray o) {
7025         LDKPublicKey o_ref;
7026         CHECK((*env)->GetArrayLength(env, o) == 33);
7027         (*env)->GetByteArrayRegion(env, o, 0, 33, o_ref.compressed_form);
7028         LDKCResult_PublicKeySecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_PublicKeySecpErrorZ), "LDKCResult_PublicKeySecpErrorZ");
7029         *ret_conv = CResult_PublicKeySecpErrorZ_ok(o_ref);
7030         return (long)ret_conv;
7031 }
7032
7033 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1PublicKeySecpErrorZ_1err(JNIEnv *env, jclass clz, jclass e) {
7034         LDKSecp256k1Error e_conv = LDKSecp256k1Error_from_java(env, e);
7035         LDKCResult_PublicKeySecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_PublicKeySecpErrorZ), "LDKCResult_PublicKeySecpErrorZ");
7036         *ret_conv = CResult_PublicKeySecpErrorZ_err(e_conv);
7037         return (long)ret_conv;
7038 }
7039
7040 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1PublicKeySecpErrorZ_1free(JNIEnv *env, jclass clz, int64_t _res) {
7041         LDKCResult_PublicKeySecpErrorZ _res_conv = *(LDKCResult_PublicKeySecpErrorZ*)_res;
7042         FREE((void*)_res);
7043         CResult_PublicKeySecpErrorZ_free(_res_conv);
7044 }
7045
7046 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1TxCreationKeysSecpErrorZ_1ok(JNIEnv *env, jclass clz, int64_t o) {
7047         LDKTxCreationKeys o_conv;
7048         o_conv.inner = (void*)(o & (~1));
7049         o_conv.is_owned = (o & 1) || (o == 0);
7050         if (o_conv.inner != NULL)
7051                 o_conv = TxCreationKeys_clone(&o_conv);
7052         LDKCResult_TxCreationKeysSecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_TxCreationKeysSecpErrorZ), "LDKCResult_TxCreationKeysSecpErrorZ");
7053         *ret_conv = CResult_TxCreationKeysSecpErrorZ_ok(o_conv);
7054         return (long)ret_conv;
7055 }
7056
7057 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1TxCreationKeysSecpErrorZ_1err(JNIEnv *env, jclass clz, jclass e) {
7058         LDKSecp256k1Error e_conv = LDKSecp256k1Error_from_java(env, e);
7059         LDKCResult_TxCreationKeysSecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_TxCreationKeysSecpErrorZ), "LDKCResult_TxCreationKeysSecpErrorZ");
7060         *ret_conv = CResult_TxCreationKeysSecpErrorZ_err(e_conv);
7061         return (long)ret_conv;
7062 }
7063
7064 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1TxCreationKeysSecpErrorZ_1free(JNIEnv *env, jclass clz, int64_t _res) {
7065         LDKCResult_TxCreationKeysSecpErrorZ _res_conv = *(LDKCResult_TxCreationKeysSecpErrorZ*)_res;
7066         FREE((void*)_res);
7067         CResult_TxCreationKeysSecpErrorZ_free(_res_conv);
7068 }
7069
7070 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1TrustedCommitmentTransactionNoneZ_1ok(JNIEnv *env, jclass clz, int64_t o) {
7071         LDKTrustedCommitmentTransaction o_conv;
7072         o_conv.inner = (void*)(o & (~1));
7073         o_conv.is_owned = (o & 1) || (o == 0);
7074         // Warning: we may need a move here but can't clone!
7075         LDKCResult_TrustedCommitmentTransactionNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_TrustedCommitmentTransactionNoneZ), "LDKCResult_TrustedCommitmentTransactionNoneZ");
7076         *ret_conv = CResult_TrustedCommitmentTransactionNoneZ_ok(o_conv);
7077         return (long)ret_conv;
7078 }
7079
7080 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1TrustedCommitmentTransactionNoneZ_1err(JNIEnv *env, jclass clz) {
7081         LDKCResult_TrustedCommitmentTransactionNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_TrustedCommitmentTransactionNoneZ), "LDKCResult_TrustedCommitmentTransactionNoneZ");
7082         *ret_conv = CResult_TrustedCommitmentTransactionNoneZ_err();
7083         return (long)ret_conv;
7084 }
7085
7086 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1TrustedCommitmentTransactionNoneZ_1free(JNIEnv *env, jclass clz, int64_t _res) {
7087         LDKCResult_TrustedCommitmentTransactionNoneZ _res_conv = *(LDKCResult_TrustedCommitmentTransactionNoneZ*)_res;
7088         FREE((void*)_res);
7089         CResult_TrustedCommitmentTransactionNoneZ_free(_res_conv);
7090 }
7091
7092 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1RouteHopZ_1free(JNIEnv *env, jclass clz, int64_tArray _res) {
7093         LDKCVec_RouteHopZ _res_constr;
7094         _res_constr.datalen = (*env)->GetArrayLength(env, _res);
7095         if (_res_constr.datalen > 0)
7096                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKRouteHop), "LDKCVec_RouteHopZ Elements");
7097         else
7098                 _res_constr.data = NULL;
7099         int64_t* _res_vals = (*env)->GetLongArrayElements (env, _res, NULL);
7100         for (size_t k = 0; k < _res_constr.datalen; k++) {
7101                 int64_t arr_conv_10 = _res_vals[k];
7102                 LDKRouteHop arr_conv_10_conv;
7103                 arr_conv_10_conv.inner = (void*)(arr_conv_10 & (~1));
7104                 arr_conv_10_conv.is_owned = (arr_conv_10 & 1) || (arr_conv_10 == 0);
7105                 _res_constr.data[k] = arr_conv_10_conv;
7106         }
7107         (*env)->ReleaseLongArrayElements(env, _res, _res_vals, 0);
7108         CVec_RouteHopZ_free(_res_constr);
7109 }
7110
7111 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1CVec_1RouteHopZZ_1free(JNIEnv *env, jclass clz, jobjectArray _res) {
7112         LDKCVec_CVec_RouteHopZZ _res_constr;
7113         _res_constr.datalen = (*env)->GetArrayLength(env, _res);
7114         if (_res_constr.datalen > 0)
7115                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKCVec_RouteHopZ), "LDKCVec_CVec_RouteHopZZ Elements");
7116         else
7117                 _res_constr.data = NULL;
7118         for (size_t m = 0; m < _res_constr.datalen; m++) {
7119                 int64_tArray arr_conv_12 = (*env)->GetObjectArrayElement(env, _res, m);
7120                 LDKCVec_RouteHopZ arr_conv_12_constr;
7121                 arr_conv_12_constr.datalen = (*env)->GetArrayLength(env, arr_conv_12);
7122                 if (arr_conv_12_constr.datalen > 0)
7123                         arr_conv_12_constr.data = MALLOC(arr_conv_12_constr.datalen * sizeof(LDKRouteHop), "LDKCVec_RouteHopZ Elements");
7124                 else
7125                         arr_conv_12_constr.data = NULL;
7126                 int64_t* arr_conv_12_vals = (*env)->GetLongArrayElements (env, arr_conv_12, NULL);
7127                 for (size_t k = 0; k < arr_conv_12_constr.datalen; k++) {
7128                         int64_t arr_conv_10 = arr_conv_12_vals[k];
7129                         LDKRouteHop arr_conv_10_conv;
7130                         arr_conv_10_conv.inner = (void*)(arr_conv_10 & (~1));
7131                         arr_conv_10_conv.is_owned = (arr_conv_10 & 1) || (arr_conv_10 == 0);
7132                         arr_conv_12_constr.data[k] = arr_conv_10_conv;
7133                 }
7134                 (*env)->ReleaseLongArrayElements(env, arr_conv_12, arr_conv_12_vals, 0);
7135                 _res_constr.data[m] = arr_conv_12_constr;
7136         }
7137         CVec_CVec_RouteHopZZ_free(_res_constr);
7138 }
7139
7140 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1RouteDecodeErrorZ_1ok(JNIEnv *env, jclass clz, int64_t o) {
7141         LDKRoute o_conv;
7142         o_conv.inner = (void*)(o & (~1));
7143         o_conv.is_owned = (o & 1) || (o == 0);
7144         if (o_conv.inner != NULL)
7145                 o_conv = Route_clone(&o_conv);
7146         LDKCResult_RouteDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_RouteDecodeErrorZ), "LDKCResult_RouteDecodeErrorZ");
7147         *ret_conv = CResult_RouteDecodeErrorZ_ok(o_conv);
7148         return (long)ret_conv;
7149 }
7150
7151 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1RouteDecodeErrorZ_1err(JNIEnv *env, jclass clz, int64_t e) {
7152         LDKDecodeError e_conv;
7153         e_conv.inner = (void*)(e & (~1));
7154         e_conv.is_owned = (e & 1) || (e == 0);
7155         // Warning: we may need a move here but can't clone!
7156         LDKCResult_RouteDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_RouteDecodeErrorZ), "LDKCResult_RouteDecodeErrorZ");
7157         *ret_conv = CResult_RouteDecodeErrorZ_err(e_conv);
7158         return (long)ret_conv;
7159 }
7160
7161 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1RouteDecodeErrorZ_1free(JNIEnv *env, jclass clz, int64_t _res) {
7162         LDKCResult_RouteDecodeErrorZ _res_conv = *(LDKCResult_RouteDecodeErrorZ*)_res;
7163         FREE((void*)_res);
7164         CResult_RouteDecodeErrorZ_free(_res_conv);
7165 }
7166
7167 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1RouteHintZ_1free(JNIEnv *env, jclass clz, int64_tArray _res) {
7168         LDKCVec_RouteHintZ _res_constr;
7169         _res_constr.datalen = (*env)->GetArrayLength(env, _res);
7170         if (_res_constr.datalen > 0)
7171                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKRouteHint), "LDKCVec_RouteHintZ Elements");
7172         else
7173                 _res_constr.data = NULL;
7174         int64_t* _res_vals = (*env)->GetLongArrayElements (env, _res, NULL);
7175         for (size_t l = 0; l < _res_constr.datalen; l++) {
7176                 int64_t arr_conv_11 = _res_vals[l];
7177                 LDKRouteHint arr_conv_11_conv;
7178                 arr_conv_11_conv.inner = (void*)(arr_conv_11 & (~1));
7179                 arr_conv_11_conv.is_owned = (arr_conv_11 & 1) || (arr_conv_11 == 0);
7180                 _res_constr.data[l] = arr_conv_11_conv;
7181         }
7182         (*env)->ReleaseLongArrayElements(env, _res, _res_vals, 0);
7183         CVec_RouteHintZ_free(_res_constr);
7184 }
7185
7186 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1RouteLightningErrorZ_1ok(JNIEnv *env, jclass clz, int64_t o) {
7187         LDKRoute o_conv;
7188         o_conv.inner = (void*)(o & (~1));
7189         o_conv.is_owned = (o & 1) || (o == 0);
7190         if (o_conv.inner != NULL)
7191                 o_conv = Route_clone(&o_conv);
7192         LDKCResult_RouteLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_RouteLightningErrorZ), "LDKCResult_RouteLightningErrorZ");
7193         *ret_conv = CResult_RouteLightningErrorZ_ok(o_conv);
7194         return (long)ret_conv;
7195 }
7196
7197 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1RouteLightningErrorZ_1err(JNIEnv *env, jclass clz, int64_t e) {
7198         LDKLightningError e_conv;
7199         e_conv.inner = (void*)(e & (~1));
7200         e_conv.is_owned = (e & 1) || (e == 0);
7201         // Warning: we may need a move here but can't clone!
7202         LDKCResult_RouteLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_RouteLightningErrorZ), "LDKCResult_RouteLightningErrorZ");
7203         *ret_conv = CResult_RouteLightningErrorZ_err(e_conv);
7204         return (long)ret_conv;
7205 }
7206
7207 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1RouteLightningErrorZ_1free(JNIEnv *env, jclass clz, int64_t _res) {
7208         LDKCResult_RouteLightningErrorZ _res_conv = *(LDKCResult_RouteLightningErrorZ*)_res;
7209         FREE((void*)_res);
7210         CResult_RouteLightningErrorZ_free(_res_conv);
7211 }
7212
7213 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1RoutingFeesDecodeErrorZ_1ok(JNIEnv *env, jclass clz, int64_t o) {
7214         LDKRoutingFees o_conv;
7215         o_conv.inner = (void*)(o & (~1));
7216         o_conv.is_owned = (o & 1) || (o == 0);
7217         if (o_conv.inner != NULL)
7218                 o_conv = RoutingFees_clone(&o_conv);
7219         LDKCResult_RoutingFeesDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_RoutingFeesDecodeErrorZ), "LDKCResult_RoutingFeesDecodeErrorZ");
7220         *ret_conv = CResult_RoutingFeesDecodeErrorZ_ok(o_conv);
7221         return (long)ret_conv;
7222 }
7223
7224 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1RoutingFeesDecodeErrorZ_1err(JNIEnv *env, jclass clz, int64_t e) {
7225         LDKDecodeError e_conv;
7226         e_conv.inner = (void*)(e & (~1));
7227         e_conv.is_owned = (e & 1) || (e == 0);
7228         // Warning: we may need a move here but can't clone!
7229         LDKCResult_RoutingFeesDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_RoutingFeesDecodeErrorZ), "LDKCResult_RoutingFeesDecodeErrorZ");
7230         *ret_conv = CResult_RoutingFeesDecodeErrorZ_err(e_conv);
7231         return (long)ret_conv;
7232 }
7233
7234 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1RoutingFeesDecodeErrorZ_1free(JNIEnv *env, jclass clz, int64_t _res) {
7235         LDKCResult_RoutingFeesDecodeErrorZ _res_conv = *(LDKCResult_RoutingFeesDecodeErrorZ*)_res;
7236         FREE((void*)_res);
7237         CResult_RoutingFeesDecodeErrorZ_free(_res_conv);
7238 }
7239
7240 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1NodeAnnouncementInfoDecodeErrorZ_1ok(JNIEnv *env, jclass clz, int64_t o) {
7241         LDKNodeAnnouncementInfo o_conv;
7242         o_conv.inner = (void*)(o & (~1));
7243         o_conv.is_owned = (o & 1) || (o == 0);
7244         // Warning: we may need a move here but can't clone!
7245         LDKCResult_NodeAnnouncementInfoDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NodeAnnouncementInfoDecodeErrorZ), "LDKCResult_NodeAnnouncementInfoDecodeErrorZ");
7246         *ret_conv = CResult_NodeAnnouncementInfoDecodeErrorZ_ok(o_conv);
7247         return (long)ret_conv;
7248 }
7249
7250 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1NodeAnnouncementInfoDecodeErrorZ_1err(JNIEnv *env, jclass clz, int64_t e) {
7251         LDKDecodeError e_conv;
7252         e_conv.inner = (void*)(e & (~1));
7253         e_conv.is_owned = (e & 1) || (e == 0);
7254         // Warning: we may need a move here but can't clone!
7255         LDKCResult_NodeAnnouncementInfoDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NodeAnnouncementInfoDecodeErrorZ), "LDKCResult_NodeAnnouncementInfoDecodeErrorZ");
7256         *ret_conv = CResult_NodeAnnouncementInfoDecodeErrorZ_err(e_conv);
7257         return (long)ret_conv;
7258 }
7259
7260 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1NodeAnnouncementInfoDecodeErrorZ_1free(JNIEnv *env, jclass clz, int64_t _res) {
7261         LDKCResult_NodeAnnouncementInfoDecodeErrorZ _res_conv = *(LDKCResult_NodeAnnouncementInfoDecodeErrorZ*)_res;
7262         FREE((void*)_res);
7263         CResult_NodeAnnouncementInfoDecodeErrorZ_free(_res_conv);
7264 }
7265
7266 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1NodeInfoDecodeErrorZ_1ok(JNIEnv *env, jclass clz, int64_t o) {
7267         LDKNodeInfo o_conv;
7268         o_conv.inner = (void*)(o & (~1));
7269         o_conv.is_owned = (o & 1) || (o == 0);
7270         // Warning: we may need a move here but can't clone!
7271         LDKCResult_NodeInfoDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NodeInfoDecodeErrorZ), "LDKCResult_NodeInfoDecodeErrorZ");
7272         *ret_conv = CResult_NodeInfoDecodeErrorZ_ok(o_conv);
7273         return (long)ret_conv;
7274 }
7275
7276 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1NodeInfoDecodeErrorZ_1err(JNIEnv *env, jclass clz, int64_t e) {
7277         LDKDecodeError e_conv;
7278         e_conv.inner = (void*)(e & (~1));
7279         e_conv.is_owned = (e & 1) || (e == 0);
7280         // Warning: we may need a move here but can't clone!
7281         LDKCResult_NodeInfoDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NodeInfoDecodeErrorZ), "LDKCResult_NodeInfoDecodeErrorZ");
7282         *ret_conv = CResult_NodeInfoDecodeErrorZ_err(e_conv);
7283         return (long)ret_conv;
7284 }
7285
7286 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1NodeInfoDecodeErrorZ_1free(JNIEnv *env, jclass clz, int64_t _res) {
7287         LDKCResult_NodeInfoDecodeErrorZ _res_conv = *(LDKCResult_NodeInfoDecodeErrorZ*)_res;
7288         FREE((void*)_res);
7289         CResult_NodeInfoDecodeErrorZ_free(_res_conv);
7290 }
7291
7292 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1NetworkGraphDecodeErrorZ_1ok(JNIEnv *env, jclass clz, int64_t o) {
7293         LDKNetworkGraph o_conv;
7294         o_conv.inner = (void*)(o & (~1));
7295         o_conv.is_owned = (o & 1) || (o == 0);
7296         // Warning: we may need a move here but can't clone!
7297         LDKCResult_NetworkGraphDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NetworkGraphDecodeErrorZ), "LDKCResult_NetworkGraphDecodeErrorZ");
7298         *ret_conv = CResult_NetworkGraphDecodeErrorZ_ok(o_conv);
7299         return (long)ret_conv;
7300 }
7301
7302 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CResult_1NetworkGraphDecodeErrorZ_1err(JNIEnv *env, jclass clz, int64_t e) {
7303         LDKDecodeError e_conv;
7304         e_conv.inner = (void*)(e & (~1));
7305         e_conv.is_owned = (e & 1) || (e == 0);
7306         // Warning: we may need a move here but can't clone!
7307         LDKCResult_NetworkGraphDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NetworkGraphDecodeErrorZ), "LDKCResult_NetworkGraphDecodeErrorZ");
7308         *ret_conv = CResult_NetworkGraphDecodeErrorZ_err(e_conv);
7309         return (long)ret_conv;
7310 }
7311
7312 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1NetworkGraphDecodeErrorZ_1free(JNIEnv *env, jclass clz, int64_t _res) {
7313         LDKCResult_NetworkGraphDecodeErrorZ _res_conv = *(LDKCResult_NetworkGraphDecodeErrorZ*)_res;
7314         FREE((void*)_res);
7315         CResult_NetworkGraphDecodeErrorZ_free(_res_conv);
7316 }
7317
7318 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Event_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
7319         LDKEvent this_ptr_conv = *(LDKEvent*)this_ptr;
7320         FREE((void*)this_ptr);
7321         Event_free(this_ptr_conv);
7322 }
7323
7324 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_Event_1clone(JNIEnv *env, jclass clz, int64_t orig) {
7325         LDKEvent* orig_conv = (LDKEvent*)orig;
7326         LDKEvent *ret_copy = MALLOC(sizeof(LDKEvent), "LDKEvent");
7327         *ret_copy = Event_clone(orig_conv);
7328         long ret_ref = (long)ret_copy;
7329         return ret_ref;
7330 }
7331
7332 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_Event_1write(JNIEnv *env, jclass clz, int64_t obj) {
7333         LDKEvent* obj_conv = (LDKEvent*)obj;
7334         LDKCVec_u8Z arg_var = Event_write(obj_conv);
7335         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
7336         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
7337         CVec_u8Z_free(arg_var);
7338         return arg_arr;
7339 }
7340
7341 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_MessageSendEvent_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
7342         LDKMessageSendEvent this_ptr_conv = *(LDKMessageSendEvent*)this_ptr;
7343         FREE((void*)this_ptr);
7344         MessageSendEvent_free(this_ptr_conv);
7345 }
7346
7347 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_MessageSendEvent_1clone(JNIEnv *env, jclass clz, int64_t orig) {
7348         LDKMessageSendEvent* orig_conv = (LDKMessageSendEvent*)orig;
7349         LDKMessageSendEvent *ret_copy = MALLOC(sizeof(LDKMessageSendEvent), "LDKMessageSendEvent");
7350         *ret_copy = MessageSendEvent_clone(orig_conv);
7351         long ret_ref = (long)ret_copy;
7352         return ret_ref;
7353 }
7354
7355 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_MessageSendEventsProvider_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
7356         LDKMessageSendEventsProvider this_ptr_conv = *(LDKMessageSendEventsProvider*)this_ptr;
7357         FREE((void*)this_ptr);
7358         MessageSendEventsProvider_free(this_ptr_conv);
7359 }
7360
7361 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_EventsProvider_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
7362         LDKEventsProvider this_ptr_conv = *(LDKEventsProvider*)this_ptr;
7363         FREE((void*)this_ptr);
7364         EventsProvider_free(this_ptr_conv);
7365 }
7366
7367 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_APIError_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
7368         LDKAPIError this_ptr_conv = *(LDKAPIError*)this_ptr;
7369         FREE((void*)this_ptr);
7370         APIError_free(this_ptr_conv);
7371 }
7372
7373 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_APIError_1clone(JNIEnv *env, jclass clz, int64_t orig) {
7374         LDKAPIError* orig_conv = (LDKAPIError*)orig;
7375         LDKAPIError *ret_copy = MALLOC(sizeof(LDKAPIError), "LDKAPIError");
7376         *ret_copy = APIError_clone(orig_conv);
7377         long ret_ref = (long)ret_copy;
7378         return ret_ref;
7379 }
7380
7381 JNIEXPORT jclass JNICALL Java_org_ldk_impl_bindings_Level_1clone(JNIEnv *env, jclass clz, int64_t orig) {
7382         LDKLevel* orig_conv = (LDKLevel*)orig;
7383         jclass ret_conv = LDKLevel_to_java(env, Level_clone(orig_conv));
7384         return ret_conv;
7385 }
7386
7387 JNIEXPORT jclass JNICALL Java_org_ldk_impl_bindings_Level_1max(JNIEnv *env, jclass clz) {
7388         jclass ret_conv = LDKLevel_to_java(env, Level_max());
7389         return ret_conv;
7390 }
7391
7392 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Logger_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
7393         LDKLogger this_ptr_conv = *(LDKLogger*)this_ptr;
7394         FREE((void*)this_ptr);
7395         Logger_free(this_ptr_conv);
7396 }
7397
7398 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeConfig_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
7399         LDKChannelHandshakeConfig this_ptr_conv;
7400         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7401         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7402         ChannelHandshakeConfig_free(this_ptr_conv);
7403 }
7404
7405 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeConfig_1clone(JNIEnv *env, jclass clz, int64_t orig) {
7406         LDKChannelHandshakeConfig orig_conv;
7407         orig_conv.inner = (void*)(orig & (~1));
7408         orig_conv.is_owned = false;
7409         LDKChannelHandshakeConfig ret_var = ChannelHandshakeConfig_clone(&orig_conv);
7410         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7411         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7412         long ret_ref = (long)ret_var.inner;
7413         if (ret_var.is_owned) {
7414                 ret_ref |= 1;
7415         }
7416         return ret_ref;
7417 }
7418
7419 JNIEXPORT int32_t JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeConfig_1get_1minimum_1depth(JNIEnv *env, jclass clz, int64_t this_ptr) {
7420         LDKChannelHandshakeConfig this_ptr_conv;
7421         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7422         this_ptr_conv.is_owned = false;
7423         int32_t ret_val = ChannelHandshakeConfig_get_minimum_depth(&this_ptr_conv);
7424         return ret_val;
7425 }
7426
7427 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeConfig_1set_1minimum_1depth(JNIEnv *env, jclass clz, int64_t this_ptr, int32_t val) {
7428         LDKChannelHandshakeConfig this_ptr_conv;
7429         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7430         this_ptr_conv.is_owned = false;
7431         ChannelHandshakeConfig_set_minimum_depth(&this_ptr_conv, val);
7432 }
7433
7434 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeConfig_1get_1our_1to_1self_1delay(JNIEnv *env, jclass clz, int64_t this_ptr) {
7435         LDKChannelHandshakeConfig this_ptr_conv;
7436         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7437         this_ptr_conv.is_owned = false;
7438         jshort ret_val = ChannelHandshakeConfig_get_our_to_self_delay(&this_ptr_conv);
7439         return ret_val;
7440 }
7441
7442 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeConfig_1set_1our_1to_1self_1delay(JNIEnv *env, jclass clz, int64_t this_ptr, jshort val) {
7443         LDKChannelHandshakeConfig this_ptr_conv;
7444         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7445         this_ptr_conv.is_owned = false;
7446         ChannelHandshakeConfig_set_our_to_self_delay(&this_ptr_conv, val);
7447 }
7448
7449 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeConfig_1get_1our_1htlc_1minimum_1msat(JNIEnv *env, jclass clz, int64_t this_ptr) {
7450         LDKChannelHandshakeConfig this_ptr_conv;
7451         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7452         this_ptr_conv.is_owned = false;
7453         int64_t ret_val = ChannelHandshakeConfig_get_our_htlc_minimum_msat(&this_ptr_conv);
7454         return ret_val;
7455 }
7456
7457 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) {
7458         LDKChannelHandshakeConfig this_ptr_conv;
7459         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7460         this_ptr_conv.is_owned = false;
7461         ChannelHandshakeConfig_set_our_htlc_minimum_msat(&this_ptr_conv, val);
7462 }
7463
7464 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeConfig_1new(JNIEnv *env, jclass clz, int32_t minimum_depth_arg, jshort our_to_self_delay_arg, int64_t our_htlc_minimum_msat_arg) {
7465         LDKChannelHandshakeConfig ret_var = ChannelHandshakeConfig_new(minimum_depth_arg, our_to_self_delay_arg, our_htlc_minimum_msat_arg);
7466         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7467         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7468         long ret_ref = (long)ret_var.inner;
7469         if (ret_var.is_owned) {
7470                 ret_ref |= 1;
7471         }
7472         return ret_ref;
7473 }
7474
7475 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeConfig_1default(JNIEnv *env, jclass clz) {
7476         LDKChannelHandshakeConfig ret_var = ChannelHandshakeConfig_default();
7477         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7478         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7479         long ret_ref = (long)ret_var.inner;
7480         if (ret_var.is_owned) {
7481                 ret_ref |= 1;
7482         }
7483         return ret_ref;
7484 }
7485
7486 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
7487         LDKChannelHandshakeLimits this_ptr_conv;
7488         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7489         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7490         ChannelHandshakeLimits_free(this_ptr_conv);
7491 }
7492
7493 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1clone(JNIEnv *env, jclass clz, int64_t orig) {
7494         LDKChannelHandshakeLimits orig_conv;
7495         orig_conv.inner = (void*)(orig & (~1));
7496         orig_conv.is_owned = false;
7497         LDKChannelHandshakeLimits ret_var = ChannelHandshakeLimits_clone(&orig_conv);
7498         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7499         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7500         long ret_ref = (long)ret_var.inner;
7501         if (ret_var.is_owned) {
7502                 ret_ref |= 1;
7503         }
7504         return ret_ref;
7505 }
7506
7507 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1get_1min_1funding_1satoshis(JNIEnv *env, jclass clz, int64_t this_ptr) {
7508         LDKChannelHandshakeLimits this_ptr_conv;
7509         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7510         this_ptr_conv.is_owned = false;
7511         int64_t ret_val = ChannelHandshakeLimits_get_min_funding_satoshis(&this_ptr_conv);
7512         return ret_val;
7513 }
7514
7515 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1set_1min_1funding_1satoshis(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
7516         LDKChannelHandshakeLimits this_ptr_conv;
7517         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7518         this_ptr_conv.is_owned = false;
7519         ChannelHandshakeLimits_set_min_funding_satoshis(&this_ptr_conv, val);
7520 }
7521
7522 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1get_1max_1htlc_1minimum_1msat(JNIEnv *env, jclass clz, int64_t this_ptr) {
7523         LDKChannelHandshakeLimits this_ptr_conv;
7524         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7525         this_ptr_conv.is_owned = false;
7526         int64_t ret_val = ChannelHandshakeLimits_get_max_htlc_minimum_msat(&this_ptr_conv);
7527         return ret_val;
7528 }
7529
7530 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) {
7531         LDKChannelHandshakeLimits this_ptr_conv;
7532         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7533         this_ptr_conv.is_owned = false;
7534         ChannelHandshakeLimits_set_max_htlc_minimum_msat(&this_ptr_conv, val);
7535 }
7536
7537 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) {
7538         LDKChannelHandshakeLimits this_ptr_conv;
7539         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7540         this_ptr_conv.is_owned = false;
7541         int64_t ret_val = ChannelHandshakeLimits_get_min_max_htlc_value_in_flight_msat(&this_ptr_conv);
7542         return ret_val;
7543 }
7544
7545 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) {
7546         LDKChannelHandshakeLimits this_ptr_conv;
7547         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7548         this_ptr_conv.is_owned = false;
7549         ChannelHandshakeLimits_set_min_max_htlc_value_in_flight_msat(&this_ptr_conv, val);
7550 }
7551
7552 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1get_1max_1channel_1reserve_1satoshis(JNIEnv *env, jclass clz, int64_t this_ptr) {
7553         LDKChannelHandshakeLimits this_ptr_conv;
7554         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7555         this_ptr_conv.is_owned = false;
7556         int64_t ret_val = ChannelHandshakeLimits_get_max_channel_reserve_satoshis(&this_ptr_conv);
7557         return ret_val;
7558 }
7559
7560 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) {
7561         LDKChannelHandshakeLimits this_ptr_conv;
7562         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7563         this_ptr_conv.is_owned = false;
7564         ChannelHandshakeLimits_set_max_channel_reserve_satoshis(&this_ptr_conv, val);
7565 }
7566
7567 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1get_1min_1max_1accepted_1htlcs(JNIEnv *env, jclass clz, int64_t this_ptr) {
7568         LDKChannelHandshakeLimits this_ptr_conv;
7569         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7570         this_ptr_conv.is_owned = false;
7571         jshort ret_val = ChannelHandshakeLimits_get_min_max_accepted_htlcs(&this_ptr_conv);
7572         return ret_val;
7573 }
7574
7575 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1set_1min_1max_1accepted_1htlcs(JNIEnv *env, jclass clz, int64_t this_ptr, jshort val) {
7576         LDKChannelHandshakeLimits this_ptr_conv;
7577         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7578         this_ptr_conv.is_owned = false;
7579         ChannelHandshakeLimits_set_min_max_accepted_htlcs(&this_ptr_conv, val);
7580 }
7581
7582 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1get_1min_1dust_1limit_1satoshis(JNIEnv *env, jclass clz, int64_t this_ptr) {
7583         LDKChannelHandshakeLimits this_ptr_conv;
7584         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7585         this_ptr_conv.is_owned = false;
7586         int64_t ret_val = ChannelHandshakeLimits_get_min_dust_limit_satoshis(&this_ptr_conv);
7587         return ret_val;
7588 }
7589
7590 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) {
7591         LDKChannelHandshakeLimits this_ptr_conv;
7592         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7593         this_ptr_conv.is_owned = false;
7594         ChannelHandshakeLimits_set_min_dust_limit_satoshis(&this_ptr_conv, val);
7595 }
7596
7597 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1get_1max_1dust_1limit_1satoshis(JNIEnv *env, jclass clz, int64_t this_ptr) {
7598         LDKChannelHandshakeLimits this_ptr_conv;
7599         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7600         this_ptr_conv.is_owned = false;
7601         int64_t ret_val = ChannelHandshakeLimits_get_max_dust_limit_satoshis(&this_ptr_conv);
7602         return ret_val;
7603 }
7604
7605 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) {
7606         LDKChannelHandshakeLimits this_ptr_conv;
7607         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7608         this_ptr_conv.is_owned = false;
7609         ChannelHandshakeLimits_set_max_dust_limit_satoshis(&this_ptr_conv, val);
7610 }
7611
7612 JNIEXPORT int32_t JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1get_1max_1minimum_1depth(JNIEnv *env, jclass clz, int64_t this_ptr) {
7613         LDKChannelHandshakeLimits this_ptr_conv;
7614         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7615         this_ptr_conv.is_owned = false;
7616         int32_t ret_val = ChannelHandshakeLimits_get_max_minimum_depth(&this_ptr_conv);
7617         return ret_val;
7618 }
7619
7620 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1set_1max_1minimum_1depth(JNIEnv *env, jclass clz, int64_t this_ptr, int32_t val) {
7621         LDKChannelHandshakeLimits this_ptr_conv;
7622         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7623         this_ptr_conv.is_owned = false;
7624         ChannelHandshakeLimits_set_max_minimum_depth(&this_ptr_conv, val);
7625 }
7626
7627 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1get_1force_1announced_1channel_1preference(JNIEnv *env, jclass clz, int64_t this_ptr) {
7628         LDKChannelHandshakeLimits this_ptr_conv;
7629         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7630         this_ptr_conv.is_owned = false;
7631         jboolean ret_val = ChannelHandshakeLimits_get_force_announced_channel_preference(&this_ptr_conv);
7632         return ret_val;
7633 }
7634
7635 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1set_1force_1announced_1channel_1preference(JNIEnv *env, jclass clz, int64_t this_ptr, jboolean val) {
7636         LDKChannelHandshakeLimits this_ptr_conv;
7637         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7638         this_ptr_conv.is_owned = false;
7639         ChannelHandshakeLimits_set_force_announced_channel_preference(&this_ptr_conv, val);
7640 }
7641
7642 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1get_1their_1to_1self_1delay(JNIEnv *env, jclass clz, int64_t this_ptr) {
7643         LDKChannelHandshakeLimits this_ptr_conv;
7644         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7645         this_ptr_conv.is_owned = false;
7646         jshort ret_val = ChannelHandshakeLimits_get_their_to_self_delay(&this_ptr_conv);
7647         return ret_val;
7648 }
7649
7650 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1set_1their_1to_1self_1delay(JNIEnv *env, jclass clz, int64_t this_ptr, jshort val) {
7651         LDKChannelHandshakeLimits this_ptr_conv;
7652         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7653         this_ptr_conv.is_owned = false;
7654         ChannelHandshakeLimits_set_their_to_self_delay(&this_ptr_conv, val);
7655 }
7656
7657 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, jshort 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, jshort their_to_self_delay_arg) {
7658         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);
7659         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7660         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7661         long ret_ref = (long)ret_var.inner;
7662         if (ret_var.is_owned) {
7663                 ret_ref |= 1;
7664         }
7665         return ret_ref;
7666 }
7667
7668 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1default(JNIEnv *env, jclass clz) {
7669         LDKChannelHandshakeLimits ret_var = ChannelHandshakeLimits_default();
7670         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7671         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7672         long ret_ref = (long)ret_var.inner;
7673         if (ret_var.is_owned) {
7674                 ret_ref |= 1;
7675         }
7676         return ret_ref;
7677 }
7678
7679 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelConfig_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
7680         LDKChannelConfig this_ptr_conv;
7681         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7682         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7683         ChannelConfig_free(this_ptr_conv);
7684 }
7685
7686 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelConfig_1clone(JNIEnv *env, jclass clz, int64_t orig) {
7687         LDKChannelConfig orig_conv;
7688         orig_conv.inner = (void*)(orig & (~1));
7689         orig_conv.is_owned = false;
7690         LDKChannelConfig ret_var = ChannelConfig_clone(&orig_conv);
7691         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7692         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7693         long ret_ref = (long)ret_var.inner;
7694         if (ret_var.is_owned) {
7695                 ret_ref |= 1;
7696         }
7697         return ret_ref;
7698 }
7699
7700 JNIEXPORT int32_t JNICALL Java_org_ldk_impl_bindings_ChannelConfig_1get_1fee_1proportional_1millionths(JNIEnv *env, jclass clz, int64_t this_ptr) {
7701         LDKChannelConfig this_ptr_conv;
7702         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7703         this_ptr_conv.is_owned = false;
7704         int32_t ret_val = ChannelConfig_get_fee_proportional_millionths(&this_ptr_conv);
7705         return ret_val;
7706 }
7707
7708 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelConfig_1set_1fee_1proportional_1millionths(JNIEnv *env, jclass clz, int64_t this_ptr, int32_t val) {
7709         LDKChannelConfig this_ptr_conv;
7710         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7711         this_ptr_conv.is_owned = false;
7712         ChannelConfig_set_fee_proportional_millionths(&this_ptr_conv, val);
7713 }
7714
7715 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_ChannelConfig_1get_1announced_1channel(JNIEnv *env, jclass clz, int64_t this_ptr) {
7716         LDKChannelConfig this_ptr_conv;
7717         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7718         this_ptr_conv.is_owned = false;
7719         jboolean ret_val = ChannelConfig_get_announced_channel(&this_ptr_conv);
7720         return ret_val;
7721 }
7722
7723 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelConfig_1set_1announced_1channel(JNIEnv *env, jclass clz, int64_t this_ptr, jboolean val) {
7724         LDKChannelConfig this_ptr_conv;
7725         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7726         this_ptr_conv.is_owned = false;
7727         ChannelConfig_set_announced_channel(&this_ptr_conv, val);
7728 }
7729
7730 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_ChannelConfig_1get_1commit_1upfront_1shutdown_1pubkey(JNIEnv *env, jclass clz, int64_t this_ptr) {
7731         LDKChannelConfig this_ptr_conv;
7732         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7733         this_ptr_conv.is_owned = false;
7734         jboolean ret_val = ChannelConfig_get_commit_upfront_shutdown_pubkey(&this_ptr_conv);
7735         return ret_val;
7736 }
7737
7738 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelConfig_1set_1commit_1upfront_1shutdown_1pubkey(JNIEnv *env, jclass clz, int64_t this_ptr, jboolean val) {
7739         LDKChannelConfig this_ptr_conv;
7740         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7741         this_ptr_conv.is_owned = false;
7742         ChannelConfig_set_commit_upfront_shutdown_pubkey(&this_ptr_conv, val);
7743 }
7744
7745 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) {
7746         LDKChannelConfig ret_var = ChannelConfig_new(fee_proportional_millionths_arg, announced_channel_arg, commit_upfront_shutdown_pubkey_arg);
7747         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7748         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7749         long ret_ref = (long)ret_var.inner;
7750         if (ret_var.is_owned) {
7751                 ret_ref |= 1;
7752         }
7753         return ret_ref;
7754 }
7755
7756 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelConfig_1default(JNIEnv *env, jclass clz) {
7757         LDKChannelConfig ret_var = ChannelConfig_default();
7758         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7759         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7760         long ret_ref = (long)ret_var.inner;
7761         if (ret_var.is_owned) {
7762                 ret_ref |= 1;
7763         }
7764         return ret_ref;
7765 }
7766
7767 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_ChannelConfig_1write(JNIEnv *env, jclass clz, int64_t obj) {
7768         LDKChannelConfig obj_conv;
7769         obj_conv.inner = (void*)(obj & (~1));
7770         obj_conv.is_owned = false;
7771         LDKCVec_u8Z arg_var = ChannelConfig_write(&obj_conv);
7772         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
7773         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
7774         CVec_u8Z_free(arg_var);
7775         return arg_arr;
7776 }
7777
7778 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelConfig_1read(JNIEnv *env, jclass clz, int8_tArray ser) {
7779         LDKu8slice ser_ref;
7780         ser_ref.datalen = (*env)->GetArrayLength(env, ser);
7781         ser_ref.data = (*env)->GetByteArrayElements (env, ser, NULL);
7782         LDKChannelConfig ret_var = ChannelConfig_read(ser_ref);
7783         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7784         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7785         long ret_ref = (long)ret_var.inner;
7786         if (ret_var.is_owned) {
7787                 ret_ref |= 1;
7788         }
7789         (*env)->ReleaseByteArrayElements(env, ser, (int8_t*)ser_ref.data, 0);
7790         return ret_ref;
7791 }
7792
7793 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UserConfig_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
7794         LDKUserConfig this_ptr_conv;
7795         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7796         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7797         UserConfig_free(this_ptr_conv);
7798 }
7799
7800 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_UserConfig_1clone(JNIEnv *env, jclass clz, int64_t orig) {
7801         LDKUserConfig orig_conv;
7802         orig_conv.inner = (void*)(orig & (~1));
7803         orig_conv.is_owned = false;
7804         LDKUserConfig ret_var = UserConfig_clone(&orig_conv);
7805         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7806         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7807         long ret_ref = (long)ret_var.inner;
7808         if (ret_var.is_owned) {
7809                 ret_ref |= 1;
7810         }
7811         return ret_ref;
7812 }
7813
7814 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_UserConfig_1get_1own_1channel_1config(JNIEnv *env, jclass clz, int64_t this_ptr) {
7815         LDKUserConfig this_ptr_conv;
7816         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7817         this_ptr_conv.is_owned = false;
7818         LDKChannelHandshakeConfig ret_var = UserConfig_get_own_channel_config(&this_ptr_conv);
7819         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7820         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7821         long ret_ref = (long)ret_var.inner;
7822         if (ret_var.is_owned) {
7823                 ret_ref |= 1;
7824         }
7825         return ret_ref;
7826 }
7827
7828 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UserConfig_1set_1own_1channel_1config(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
7829         LDKUserConfig this_ptr_conv;
7830         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7831         this_ptr_conv.is_owned = false;
7832         LDKChannelHandshakeConfig val_conv;
7833         val_conv.inner = (void*)(val & (~1));
7834         val_conv.is_owned = (val & 1) || (val == 0);
7835         if (val_conv.inner != NULL)
7836                 val_conv = ChannelHandshakeConfig_clone(&val_conv);
7837         UserConfig_set_own_channel_config(&this_ptr_conv, val_conv);
7838 }
7839
7840 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_UserConfig_1get_1peer_1channel_1config_1limits(JNIEnv *env, jclass clz, int64_t this_ptr) {
7841         LDKUserConfig this_ptr_conv;
7842         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7843         this_ptr_conv.is_owned = false;
7844         LDKChannelHandshakeLimits ret_var = UserConfig_get_peer_channel_config_limits(&this_ptr_conv);
7845         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7846         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7847         long ret_ref = (long)ret_var.inner;
7848         if (ret_var.is_owned) {
7849                 ret_ref |= 1;
7850         }
7851         return ret_ref;
7852 }
7853
7854 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) {
7855         LDKUserConfig this_ptr_conv;
7856         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7857         this_ptr_conv.is_owned = false;
7858         LDKChannelHandshakeLimits val_conv;
7859         val_conv.inner = (void*)(val & (~1));
7860         val_conv.is_owned = (val & 1) || (val == 0);
7861         if (val_conv.inner != NULL)
7862                 val_conv = ChannelHandshakeLimits_clone(&val_conv);
7863         UserConfig_set_peer_channel_config_limits(&this_ptr_conv, val_conv);
7864 }
7865
7866 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_UserConfig_1get_1channel_1options(JNIEnv *env, jclass clz, int64_t this_ptr) {
7867         LDKUserConfig this_ptr_conv;
7868         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7869         this_ptr_conv.is_owned = false;
7870         LDKChannelConfig ret_var = UserConfig_get_channel_options(&this_ptr_conv);
7871         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7872         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7873         long ret_ref = (long)ret_var.inner;
7874         if (ret_var.is_owned) {
7875                 ret_ref |= 1;
7876         }
7877         return ret_ref;
7878 }
7879
7880 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UserConfig_1set_1channel_1options(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
7881         LDKUserConfig this_ptr_conv;
7882         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7883         this_ptr_conv.is_owned = false;
7884         LDKChannelConfig val_conv;
7885         val_conv.inner = (void*)(val & (~1));
7886         val_conv.is_owned = (val & 1) || (val == 0);
7887         if (val_conv.inner != NULL)
7888                 val_conv = ChannelConfig_clone(&val_conv);
7889         UserConfig_set_channel_options(&this_ptr_conv, val_conv);
7890 }
7891
7892 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) {
7893         LDKChannelHandshakeConfig own_channel_config_arg_conv;
7894         own_channel_config_arg_conv.inner = (void*)(own_channel_config_arg & (~1));
7895         own_channel_config_arg_conv.is_owned = (own_channel_config_arg & 1) || (own_channel_config_arg == 0);
7896         if (own_channel_config_arg_conv.inner != NULL)
7897                 own_channel_config_arg_conv = ChannelHandshakeConfig_clone(&own_channel_config_arg_conv);
7898         LDKChannelHandshakeLimits peer_channel_config_limits_arg_conv;
7899         peer_channel_config_limits_arg_conv.inner = (void*)(peer_channel_config_limits_arg & (~1));
7900         peer_channel_config_limits_arg_conv.is_owned = (peer_channel_config_limits_arg & 1) || (peer_channel_config_limits_arg == 0);
7901         if (peer_channel_config_limits_arg_conv.inner != NULL)
7902                 peer_channel_config_limits_arg_conv = ChannelHandshakeLimits_clone(&peer_channel_config_limits_arg_conv);
7903         LDKChannelConfig channel_options_arg_conv;
7904         channel_options_arg_conv.inner = (void*)(channel_options_arg & (~1));
7905         channel_options_arg_conv.is_owned = (channel_options_arg & 1) || (channel_options_arg == 0);
7906         if (channel_options_arg_conv.inner != NULL)
7907                 channel_options_arg_conv = ChannelConfig_clone(&channel_options_arg_conv);
7908         LDKUserConfig ret_var = UserConfig_new(own_channel_config_arg_conv, peer_channel_config_limits_arg_conv, channel_options_arg_conv);
7909         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7910         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7911         long ret_ref = (long)ret_var.inner;
7912         if (ret_var.is_owned) {
7913                 ret_ref |= 1;
7914         }
7915         return ret_ref;
7916 }
7917
7918 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_UserConfig_1default(JNIEnv *env, jclass clz) {
7919         LDKUserConfig ret_var = UserConfig_default();
7920         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7921         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7922         long ret_ref = (long)ret_var.inner;
7923         if (ret_var.is_owned) {
7924                 ret_ref |= 1;
7925         }
7926         return ret_ref;
7927 }
7928
7929 JNIEXPORT jclass JNICALL Java_org_ldk_impl_bindings_AccessError_1clone(JNIEnv *env, jclass clz, int64_t orig) {
7930         LDKAccessError* orig_conv = (LDKAccessError*)orig;
7931         jclass ret_conv = LDKAccessError_to_java(env, AccessError_clone(orig_conv));
7932         return ret_conv;
7933 }
7934
7935 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Access_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
7936         LDKAccess this_ptr_conv = *(LDKAccess*)this_ptr;
7937         FREE((void*)this_ptr);
7938         Access_free(this_ptr_conv);
7939 }
7940
7941 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Watch_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
7942         LDKWatch this_ptr_conv = *(LDKWatch*)this_ptr;
7943         FREE((void*)this_ptr);
7944         Watch_free(this_ptr_conv);
7945 }
7946
7947 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Filter_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
7948         LDKFilter this_ptr_conv = *(LDKFilter*)this_ptr;
7949         FREE((void*)this_ptr);
7950         Filter_free(this_ptr_conv);
7951 }
7952
7953 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_BroadcasterInterface_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
7954         LDKBroadcasterInterface this_ptr_conv = *(LDKBroadcasterInterface*)this_ptr;
7955         FREE((void*)this_ptr);
7956         BroadcasterInterface_free(this_ptr_conv);
7957 }
7958
7959 JNIEXPORT jclass JNICALL Java_org_ldk_impl_bindings_ConfirmationTarget_1clone(JNIEnv *env, jclass clz, int64_t orig) {
7960         LDKConfirmationTarget* orig_conv = (LDKConfirmationTarget*)orig;
7961         jclass ret_conv = LDKConfirmationTarget_to_java(env, ConfirmationTarget_clone(orig_conv));
7962         return ret_conv;
7963 }
7964
7965 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_FeeEstimator_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
7966         LDKFeeEstimator this_ptr_conv = *(LDKFeeEstimator*)this_ptr;
7967         FREE((void*)this_ptr);
7968         FeeEstimator_free(this_ptr_conv);
7969 }
7970
7971 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChainMonitor_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
7972         LDKChainMonitor this_ptr_conv;
7973         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7974         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7975         ChainMonitor_free(this_ptr_conv);
7976 }
7977
7978 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) {
7979         LDKChainMonitor this_arg_conv;
7980         this_arg_conv.inner = (void*)(this_arg & (~1));
7981         this_arg_conv.is_owned = false;
7982         unsigned char header_arr[80];
7983         CHECK((*env)->GetArrayLength(env, header) == 80);
7984         (*env)->GetByteArrayRegion(env, header, 0, 80, header_arr);
7985         unsigned char (*header_ref)[80] = &header_arr;
7986         LDKCVec_C2Tuple_usizeTransactionZZ txdata_constr;
7987         txdata_constr.datalen = (*env)->GetArrayLength(env, txdata);
7988         if (txdata_constr.datalen > 0)
7989                 txdata_constr.data = MALLOC(txdata_constr.datalen * sizeof(LDKC2Tuple_usizeTransactionZ), "LDKCVec_C2Tuple_usizeTransactionZZ Elements");
7990         else
7991                 txdata_constr.data = NULL;
7992         int64_t* txdata_vals = (*env)->GetLongArrayElements (env, txdata, NULL);
7993         for (size_t y = 0; y < txdata_constr.datalen; y++) {
7994                 int64_t arr_conv_24 = txdata_vals[y];
7995                 LDKC2Tuple_usizeTransactionZ arr_conv_24_conv = *(LDKC2Tuple_usizeTransactionZ*)arr_conv_24;
7996                 FREE((void*)arr_conv_24);
7997                 txdata_constr.data[y] = arr_conv_24_conv;
7998         }
7999         (*env)->ReleaseLongArrayElements(env, txdata, txdata_vals, 0);
8000         ChainMonitor_block_connected(&this_arg_conv, header_ref, txdata_constr, height);
8001 }
8002
8003 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) {
8004         LDKChainMonitor this_arg_conv;
8005         this_arg_conv.inner = (void*)(this_arg & (~1));
8006         this_arg_conv.is_owned = false;
8007         unsigned char header_arr[80];
8008         CHECK((*env)->GetArrayLength(env, header) == 80);
8009         (*env)->GetByteArrayRegion(env, header, 0, 80, header_arr);
8010         unsigned char (*header_ref)[80] = &header_arr;
8011         ChainMonitor_block_disconnected(&this_arg_conv, header_ref, disconnected_height);
8012 }
8013
8014 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) {
8015         LDKFilter* chain_source_conv = (LDKFilter*)chain_source;
8016         LDKBroadcasterInterface broadcaster_conv = *(LDKBroadcasterInterface*)broadcaster;
8017         if (broadcaster_conv.free == LDKBroadcasterInterface_JCalls_free) {
8018                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
8019                 LDKBroadcasterInterface_JCalls_clone(broadcaster_conv.this_arg);
8020         }
8021         LDKLogger logger_conv = *(LDKLogger*)logger;
8022         if (logger_conv.free == LDKLogger_JCalls_free) {
8023                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
8024                 LDKLogger_JCalls_clone(logger_conv.this_arg);
8025         }
8026         LDKFeeEstimator feeest_conv = *(LDKFeeEstimator*)feeest;
8027         if (feeest_conv.free == LDKFeeEstimator_JCalls_free) {
8028                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
8029                 LDKFeeEstimator_JCalls_clone(feeest_conv.this_arg);
8030         }
8031         LDKPersist persister_conv = *(LDKPersist*)persister;
8032         if (persister_conv.free == LDKPersist_JCalls_free) {
8033                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
8034                 LDKPersist_JCalls_clone(persister_conv.this_arg);
8035         }
8036         LDKChainMonitor ret_var = ChainMonitor_new(chain_source_conv, broadcaster_conv, logger_conv, feeest_conv, persister_conv);
8037         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8038         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8039         long ret_ref = (long)ret_var.inner;
8040         if (ret_var.is_owned) {
8041                 ret_ref |= 1;
8042         }
8043         return ret_ref;
8044 }
8045
8046 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChainMonitor_1as_1Watch(JNIEnv *env, jclass clz, int64_t this_arg) {
8047         LDKChainMonitor this_arg_conv;
8048         this_arg_conv.inner = (void*)(this_arg & (~1));
8049         this_arg_conv.is_owned = false;
8050         LDKWatch* ret = MALLOC(sizeof(LDKWatch), "LDKWatch");
8051         *ret = ChainMonitor_as_Watch(&this_arg_conv);
8052         return (long)ret;
8053 }
8054
8055 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChainMonitor_1as_1EventsProvider(JNIEnv *env, jclass clz, int64_t this_arg) {
8056         LDKChainMonitor this_arg_conv;
8057         this_arg_conv.inner = (void*)(this_arg & (~1));
8058         this_arg_conv.is_owned = false;
8059         LDKEventsProvider* ret = MALLOC(sizeof(LDKEventsProvider), "LDKEventsProvider");
8060         *ret = ChainMonitor_as_EventsProvider(&this_arg_conv);
8061         return (long)ret;
8062 }
8063
8064 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelMonitorUpdate_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
8065         LDKChannelMonitorUpdate this_ptr_conv;
8066         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8067         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8068         ChannelMonitorUpdate_free(this_ptr_conv);
8069 }
8070
8071 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelMonitorUpdate_1clone(JNIEnv *env, jclass clz, int64_t orig) {
8072         LDKChannelMonitorUpdate orig_conv;
8073         orig_conv.inner = (void*)(orig & (~1));
8074         orig_conv.is_owned = false;
8075         LDKChannelMonitorUpdate ret_var = ChannelMonitorUpdate_clone(&orig_conv);
8076         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8077         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8078         long ret_ref = (long)ret_var.inner;
8079         if (ret_var.is_owned) {
8080                 ret_ref |= 1;
8081         }
8082         return ret_ref;
8083 }
8084
8085 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelMonitorUpdate_1get_1update_1id(JNIEnv *env, jclass clz, int64_t this_ptr) {
8086         LDKChannelMonitorUpdate this_ptr_conv;
8087         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8088         this_ptr_conv.is_owned = false;
8089         int64_t ret_val = ChannelMonitorUpdate_get_update_id(&this_ptr_conv);
8090         return ret_val;
8091 }
8092
8093 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelMonitorUpdate_1set_1update_1id(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
8094         LDKChannelMonitorUpdate this_ptr_conv;
8095         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8096         this_ptr_conv.is_owned = false;
8097         ChannelMonitorUpdate_set_update_id(&this_ptr_conv, val);
8098 }
8099
8100 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_ChannelMonitorUpdate_1write(JNIEnv *env, jclass clz, int64_t obj) {
8101         LDKChannelMonitorUpdate obj_conv;
8102         obj_conv.inner = (void*)(obj & (~1));
8103         obj_conv.is_owned = false;
8104         LDKCVec_u8Z arg_var = ChannelMonitorUpdate_write(&obj_conv);
8105         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
8106         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
8107         CVec_u8Z_free(arg_var);
8108         return arg_arr;
8109 }
8110
8111 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelMonitorUpdate_1read(JNIEnv *env, jclass clz, int8_tArray ser) {
8112         LDKu8slice ser_ref;
8113         ser_ref.datalen = (*env)->GetArrayLength(env, ser);
8114         ser_ref.data = (*env)->GetByteArrayElements (env, ser, NULL);
8115         LDKCResult_ChannelMonitorUpdateDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ChannelMonitorUpdateDecodeErrorZ), "LDKCResult_ChannelMonitorUpdateDecodeErrorZ");
8116         *ret_conv = ChannelMonitorUpdate_read(ser_ref);
8117         (*env)->ReleaseByteArrayElements(env, ser, (int8_t*)ser_ref.data, 0);
8118         return (long)ret_conv;
8119 }
8120
8121 JNIEXPORT jclass JNICALL Java_org_ldk_impl_bindings_ChannelMonitorUpdateErr_1clone(JNIEnv *env, jclass clz, int64_t orig) {
8122         LDKChannelMonitorUpdateErr* orig_conv = (LDKChannelMonitorUpdateErr*)orig;
8123         jclass ret_conv = LDKChannelMonitorUpdateErr_to_java(env, ChannelMonitorUpdateErr_clone(orig_conv));
8124         return ret_conv;
8125 }
8126
8127 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_MonitorUpdateError_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
8128         LDKMonitorUpdateError this_ptr_conv;
8129         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8130         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8131         MonitorUpdateError_free(this_ptr_conv);
8132 }
8133
8134 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_MonitorEvent_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
8135         LDKMonitorEvent 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         MonitorEvent_free(this_ptr_conv);
8139 }
8140
8141 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_MonitorEvent_1clone(JNIEnv *env, jclass clz, int64_t orig) {
8142         LDKMonitorEvent orig_conv;
8143         orig_conv.inner = (void*)(orig & (~1));
8144         orig_conv.is_owned = false;
8145         LDKMonitorEvent ret_var = MonitorEvent_clone(&orig_conv);
8146         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8147         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8148         long ret_ref = (long)ret_var.inner;
8149         if (ret_var.is_owned) {
8150                 ret_ref |= 1;
8151         }
8152         return ret_ref;
8153 }
8154
8155 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_HTLCUpdate_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
8156         LDKHTLCUpdate this_ptr_conv;
8157         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8158         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8159         HTLCUpdate_free(this_ptr_conv);
8160 }
8161
8162 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_HTLCUpdate_1clone(JNIEnv *env, jclass clz, int64_t orig) {
8163         LDKHTLCUpdate orig_conv;
8164         orig_conv.inner = (void*)(orig & (~1));
8165         orig_conv.is_owned = false;
8166         LDKHTLCUpdate ret_var = HTLCUpdate_clone(&orig_conv);
8167         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8168         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8169         long ret_ref = (long)ret_var.inner;
8170         if (ret_var.is_owned) {
8171                 ret_ref |= 1;
8172         }
8173         return ret_ref;
8174 }
8175
8176 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_HTLCUpdate_1write(JNIEnv *env, jclass clz, int64_t obj) {
8177         LDKHTLCUpdate obj_conv;
8178         obj_conv.inner = (void*)(obj & (~1));
8179         obj_conv.is_owned = false;
8180         LDKCVec_u8Z arg_var = HTLCUpdate_write(&obj_conv);
8181         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
8182         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
8183         CVec_u8Z_free(arg_var);
8184         return arg_arr;
8185 }
8186
8187 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_HTLCUpdate_1read(JNIEnv *env, jclass clz, int8_tArray ser) {
8188         LDKu8slice ser_ref;
8189         ser_ref.datalen = (*env)->GetArrayLength(env, ser);
8190         ser_ref.data = (*env)->GetByteArrayElements (env, ser, NULL);
8191         LDKHTLCUpdate ret_var = HTLCUpdate_read(ser_ref);
8192         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8193         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8194         long ret_ref = (long)ret_var.inner;
8195         if (ret_var.is_owned) {
8196                 ret_ref |= 1;
8197         }
8198         (*env)->ReleaseByteArrayElements(env, ser, (int8_t*)ser_ref.data, 0);
8199         return ret_ref;
8200 }
8201
8202 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelMonitor_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
8203         LDKChannelMonitor this_ptr_conv;
8204         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8205         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8206         ChannelMonitor_free(this_ptr_conv);
8207 }
8208
8209 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_ChannelMonitor_1write(JNIEnv *env, jclass clz, int64_t obj) {
8210         LDKChannelMonitor obj_conv;
8211         obj_conv.inner = (void*)(obj & (~1));
8212         obj_conv.is_owned = false;
8213         LDKCVec_u8Z arg_var = ChannelMonitor_write(&obj_conv);
8214         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
8215         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
8216         CVec_u8Z_free(arg_var);
8217         return arg_arr;
8218 }
8219
8220 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) {
8221         LDKChannelMonitor this_arg_conv;
8222         this_arg_conv.inner = (void*)(this_arg & (~1));
8223         this_arg_conv.is_owned = false;
8224         LDKChannelMonitorUpdate updates_conv;
8225         updates_conv.inner = (void*)(updates & (~1));
8226         updates_conv.is_owned = false;
8227         LDKBroadcasterInterface* broadcaster_conv = (LDKBroadcasterInterface*)broadcaster;
8228         LDKFeeEstimator* fee_estimator_conv = (LDKFeeEstimator*)fee_estimator;
8229         LDKLogger* logger_conv = (LDKLogger*)logger;
8230         LDKCResult_NoneMonitorUpdateErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneMonitorUpdateErrorZ), "LDKCResult_NoneMonitorUpdateErrorZ");
8231         *ret_conv = ChannelMonitor_update_monitor(&this_arg_conv, &updates_conv, broadcaster_conv, fee_estimator_conv, logger_conv);
8232         return (long)ret_conv;
8233 }
8234
8235 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelMonitor_1get_1latest_1update_1id(JNIEnv *env, jclass clz, int64_t this_arg) {
8236         LDKChannelMonitor this_arg_conv;
8237         this_arg_conv.inner = (void*)(this_arg & (~1));
8238         this_arg_conv.is_owned = false;
8239         int64_t ret_val = ChannelMonitor_get_latest_update_id(&this_arg_conv);
8240         return ret_val;
8241 }
8242
8243 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelMonitor_1get_1funding_1txo(JNIEnv *env, jclass clz, int64_t this_arg) {
8244         LDKChannelMonitor this_arg_conv;
8245         this_arg_conv.inner = (void*)(this_arg & (~1));
8246         this_arg_conv.is_owned = false;
8247         LDKC2Tuple_OutPointScriptZ* ret_ref = MALLOC(sizeof(LDKC2Tuple_OutPointScriptZ), "LDKC2Tuple_OutPointScriptZ");
8248         *ret_ref = ChannelMonitor_get_funding_txo(&this_arg_conv);
8249         ret_ref->a = OutPoint_clone(&ret_ref->a);
8250         ret_ref->b = CVec_u8Z_clone(&ret_ref->b);
8251         return (long)ret_ref;
8252 }
8253
8254 JNIEXPORT int64_tArray JNICALL Java_org_ldk_impl_bindings_ChannelMonitor_1get_1and_1clear_1pending_1monitor_1events(JNIEnv *env, jclass clz, int64_t this_arg) {
8255         LDKChannelMonitor this_arg_conv;
8256         this_arg_conv.inner = (void*)(this_arg & (~1));
8257         this_arg_conv.is_owned = false;
8258         LDKCVec_MonitorEventZ ret_var = ChannelMonitor_get_and_clear_pending_monitor_events(&this_arg_conv);
8259         int64_tArray ret_arr = (*env)->NewLongArray(env, ret_var.datalen);
8260         int64_t *ret_arr_ptr = (*env)->GetPrimitiveArrayCritical(env, ret_arr, NULL);
8261         for (size_t o = 0; o < ret_var.datalen; o++) {
8262                 LDKMonitorEvent arr_conv_14_var = ret_var.data[o];
8263                 CHECK((((long)arr_conv_14_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8264                 CHECK((((long)&arr_conv_14_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8265                 long arr_conv_14_ref = (long)arr_conv_14_var.inner;
8266                 if (arr_conv_14_var.is_owned) {
8267                         arr_conv_14_ref |= 1;
8268                 }
8269                 ret_arr_ptr[o] = arr_conv_14_ref;
8270         }
8271         (*env)->ReleasePrimitiveArrayCritical(env, ret_arr, ret_arr_ptr, 0);
8272         FREE(ret_var.data);
8273         return ret_arr;
8274 }
8275
8276 JNIEXPORT int64_tArray JNICALL Java_org_ldk_impl_bindings_ChannelMonitor_1get_1and_1clear_1pending_1events(JNIEnv *env, jclass clz, int64_t this_arg) {
8277         LDKChannelMonitor this_arg_conv;
8278         this_arg_conv.inner = (void*)(this_arg & (~1));
8279         this_arg_conv.is_owned = false;
8280         LDKCVec_EventZ ret_var = ChannelMonitor_get_and_clear_pending_events(&this_arg_conv);
8281         int64_tArray ret_arr = (*env)->NewLongArray(env, ret_var.datalen);
8282         int64_t *ret_arr_ptr = (*env)->GetPrimitiveArrayCritical(env, ret_arr, NULL);
8283         for (size_t h = 0; h < ret_var.datalen; h++) {
8284                 LDKEvent *arr_conv_7_copy = MALLOC(sizeof(LDKEvent), "LDKEvent");
8285                 *arr_conv_7_copy = Event_clone(&ret_var.data[h]);
8286                 long arr_conv_7_ref = (long)arr_conv_7_copy;
8287                 ret_arr_ptr[h] = arr_conv_7_ref;
8288         }
8289         (*env)->ReleasePrimitiveArrayCritical(env, ret_arr, ret_arr_ptr, 0);
8290         FREE(ret_var.data);
8291         return ret_arr;
8292 }
8293
8294 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) {
8295         LDKChannelMonitor this_arg_conv;
8296         this_arg_conv.inner = (void*)(this_arg & (~1));
8297         this_arg_conv.is_owned = false;
8298         LDKLogger* logger_conv = (LDKLogger*)logger;
8299         LDKCVec_TransactionZ ret_var = ChannelMonitor_get_latest_holder_commitment_txn(&this_arg_conv, logger_conv);
8300         jobjectArray ret_arr = (*env)->NewObjectArray(env, ret_var.datalen, arr_of_B_clz, NULL);
8301         for (size_t i = 0; i < ret_var.datalen; i++) {
8302                 LDKTransaction arr_conv_8_var = ret_var.data[i];
8303                 int8_tArray arr_conv_8_arr = (*env)->NewByteArray(env, arr_conv_8_var.datalen);
8304                 (*env)->SetByteArrayRegion(env, arr_conv_8_arr, 0, arr_conv_8_var.datalen, arr_conv_8_var.data);
8305                 Transaction_free(arr_conv_8_var);
8306                 (*env)->SetObjectArrayElement(env, ret_arr, i, arr_conv_8_arr);
8307         }
8308         FREE(ret_var.data);
8309         return ret_arr;
8310 }
8311
8312 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) {
8313         LDKChannelMonitor this_arg_conv;
8314         this_arg_conv.inner = (void*)(this_arg & (~1));
8315         this_arg_conv.is_owned = false;
8316         unsigned char header_arr[80];
8317         CHECK((*env)->GetArrayLength(env, header) == 80);
8318         (*env)->GetByteArrayRegion(env, header, 0, 80, header_arr);
8319         unsigned char (*header_ref)[80] = &header_arr;
8320         LDKCVec_C2Tuple_usizeTransactionZZ txdata_constr;
8321         txdata_constr.datalen = (*env)->GetArrayLength(env, txdata);
8322         if (txdata_constr.datalen > 0)
8323                 txdata_constr.data = MALLOC(txdata_constr.datalen * sizeof(LDKC2Tuple_usizeTransactionZ), "LDKCVec_C2Tuple_usizeTransactionZZ Elements");
8324         else
8325                 txdata_constr.data = NULL;
8326         int64_t* txdata_vals = (*env)->GetLongArrayElements (env, txdata, NULL);
8327         for (size_t y = 0; y < txdata_constr.datalen; y++) {
8328                 int64_t arr_conv_24 = txdata_vals[y];
8329                 LDKC2Tuple_usizeTransactionZ arr_conv_24_conv = *(LDKC2Tuple_usizeTransactionZ*)arr_conv_24;
8330                 FREE((void*)arr_conv_24);
8331                 txdata_constr.data[y] = arr_conv_24_conv;
8332         }
8333         (*env)->ReleaseLongArrayElements(env, txdata, txdata_vals, 0);
8334         LDKBroadcasterInterface broadcaster_conv = *(LDKBroadcasterInterface*)broadcaster;
8335         if (broadcaster_conv.free == LDKBroadcasterInterface_JCalls_free) {
8336                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
8337                 LDKBroadcasterInterface_JCalls_clone(broadcaster_conv.this_arg);
8338         }
8339         LDKFeeEstimator fee_estimator_conv = *(LDKFeeEstimator*)fee_estimator;
8340         if (fee_estimator_conv.free == LDKFeeEstimator_JCalls_free) {
8341                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
8342                 LDKFeeEstimator_JCalls_clone(fee_estimator_conv.this_arg);
8343         }
8344         LDKLogger logger_conv = *(LDKLogger*)logger;
8345         if (logger_conv.free == LDKLogger_JCalls_free) {
8346                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
8347                 LDKLogger_JCalls_clone(logger_conv.this_arg);
8348         }
8349         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);
8350         int64_tArray ret_arr = (*env)->NewLongArray(env, ret_var.datalen);
8351         int64_t *ret_arr_ptr = (*env)->GetPrimitiveArrayCritical(env, ret_arr, NULL);
8352         for (size_t u = 0; u < ret_var.datalen; u++) {
8353                 LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ* arr_conv_46_ref = MALLOC(sizeof(LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ), "LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ");
8354                 *arr_conv_46_ref = ret_var.data[u];
8355                 arr_conv_46_ref->a = ThirtyTwoBytes_clone(&arr_conv_46_ref->a);
8356                 // XXX: We likely need to clone here, but no _clone fn is available for TwoTuple<Integer, TxOut>[]
8357                 ret_arr_ptr[u] = (long)arr_conv_46_ref;
8358         }
8359         (*env)->ReleasePrimitiveArrayCritical(env, ret_arr, ret_arr_ptr, 0);
8360         FREE(ret_var.data);
8361         return ret_arr;
8362 }
8363
8364 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) {
8365         LDKChannelMonitor this_arg_conv;
8366         this_arg_conv.inner = (void*)(this_arg & (~1));
8367         this_arg_conv.is_owned = false;
8368         unsigned char header_arr[80];
8369         CHECK((*env)->GetArrayLength(env, header) == 80);
8370         (*env)->GetByteArrayRegion(env, header, 0, 80, header_arr);
8371         unsigned char (*header_ref)[80] = &header_arr;
8372         LDKBroadcasterInterface broadcaster_conv = *(LDKBroadcasterInterface*)broadcaster;
8373         if (broadcaster_conv.free == LDKBroadcasterInterface_JCalls_free) {
8374                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
8375                 LDKBroadcasterInterface_JCalls_clone(broadcaster_conv.this_arg);
8376         }
8377         LDKFeeEstimator fee_estimator_conv = *(LDKFeeEstimator*)fee_estimator;
8378         if (fee_estimator_conv.free == LDKFeeEstimator_JCalls_free) {
8379                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
8380                 LDKFeeEstimator_JCalls_clone(fee_estimator_conv.this_arg);
8381         }
8382         LDKLogger logger_conv = *(LDKLogger*)logger;
8383         if (logger_conv.free == LDKLogger_JCalls_free) {
8384                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
8385                 LDKLogger_JCalls_clone(logger_conv.this_arg);
8386         }
8387         ChannelMonitor_block_disconnected(&this_arg_conv, header_ref, height, broadcaster_conv, fee_estimator_conv, logger_conv);
8388 }
8389
8390 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Persist_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
8391         LDKPersist this_ptr_conv = *(LDKPersist*)this_ptr;
8392         FREE((void*)this_ptr);
8393         Persist_free(this_ptr_conv);
8394 }
8395
8396 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_C2Tuple_1BlockHashChannelMonitorZ_1read(JNIEnv *env, jclass clz, int8_tArray ser, int64_t arg) {
8397         LDKu8slice ser_ref;
8398         ser_ref.datalen = (*env)->GetArrayLength(env, ser);
8399         ser_ref.data = (*env)->GetByteArrayElements (env, ser, NULL);
8400         LDKKeysInterface* arg_conv = (LDKKeysInterface*)arg;
8401         LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ), "LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ");
8402         *ret_conv = C2Tuple_BlockHashChannelMonitorZ_read(ser_ref, arg_conv);
8403         (*env)->ReleaseByteArrayElements(env, ser, (int8_t*)ser_ref.data, 0);
8404         return (long)ret_conv;
8405 }
8406
8407 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OutPoint_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
8408         LDKOutPoint this_ptr_conv;
8409         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8410         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8411         OutPoint_free(this_ptr_conv);
8412 }
8413
8414 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_OutPoint_1clone(JNIEnv *env, jclass clz, int64_t orig) {
8415         LDKOutPoint orig_conv;
8416         orig_conv.inner = (void*)(orig & (~1));
8417         orig_conv.is_owned = false;
8418         LDKOutPoint ret_var = OutPoint_clone(&orig_conv);
8419         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8420         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8421         long ret_ref = (long)ret_var.inner;
8422         if (ret_var.is_owned) {
8423                 ret_ref |= 1;
8424         }
8425         return ret_ref;
8426 }
8427
8428 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_OutPoint_1get_1txid(JNIEnv *env, jclass clz, int64_t this_ptr) {
8429         LDKOutPoint this_ptr_conv;
8430         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8431         this_ptr_conv.is_owned = false;
8432         int8_tArray ret_arr = (*env)->NewByteArray(env, 32);
8433         (*env)->SetByteArrayRegion(env, ret_arr, 0, 32, *OutPoint_get_txid(&this_ptr_conv));
8434         return ret_arr;
8435 }
8436
8437 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OutPoint_1set_1txid(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
8438         LDKOutPoint this_ptr_conv;
8439         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8440         this_ptr_conv.is_owned = false;
8441         LDKThirtyTwoBytes val_ref;
8442         CHECK((*env)->GetArrayLength(env, val) == 32);
8443         (*env)->GetByteArrayRegion(env, val, 0, 32, val_ref.data);
8444         OutPoint_set_txid(&this_ptr_conv, val_ref);
8445 }
8446
8447 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_OutPoint_1get_1index(JNIEnv *env, jclass clz, int64_t this_ptr) {
8448         LDKOutPoint this_ptr_conv;
8449         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8450         this_ptr_conv.is_owned = false;
8451         jshort ret_val = OutPoint_get_index(&this_ptr_conv);
8452         return ret_val;
8453 }
8454
8455 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OutPoint_1set_1index(JNIEnv *env, jclass clz, int64_t this_ptr, jshort val) {
8456         LDKOutPoint this_ptr_conv;
8457         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8458         this_ptr_conv.is_owned = false;
8459         OutPoint_set_index(&this_ptr_conv, val);
8460 }
8461
8462 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_OutPoint_1new(JNIEnv *env, jclass clz, int8_tArray txid_arg, jshort index_arg) {
8463         LDKThirtyTwoBytes txid_arg_ref;
8464         CHECK((*env)->GetArrayLength(env, txid_arg) == 32);
8465         (*env)->GetByteArrayRegion(env, txid_arg, 0, 32, txid_arg_ref.data);
8466         LDKOutPoint ret_var = OutPoint_new(txid_arg_ref, index_arg);
8467         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8468         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8469         long ret_ref = (long)ret_var.inner;
8470         if (ret_var.is_owned) {
8471                 ret_ref |= 1;
8472         }
8473         return ret_ref;
8474 }
8475
8476 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_OutPoint_1to_1channel_1id(JNIEnv *env, jclass clz, int64_t this_arg) {
8477         LDKOutPoint this_arg_conv;
8478         this_arg_conv.inner = (void*)(this_arg & (~1));
8479         this_arg_conv.is_owned = false;
8480         int8_tArray arg_arr = (*env)->NewByteArray(env, 32);
8481         (*env)->SetByteArrayRegion(env, arg_arr, 0, 32, OutPoint_to_channel_id(&this_arg_conv).data);
8482         return arg_arr;
8483 }
8484
8485 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_OutPoint_1write(JNIEnv *env, jclass clz, int64_t obj) {
8486         LDKOutPoint obj_conv;
8487         obj_conv.inner = (void*)(obj & (~1));
8488         obj_conv.is_owned = false;
8489         LDKCVec_u8Z arg_var = OutPoint_write(&obj_conv);
8490         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
8491         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
8492         CVec_u8Z_free(arg_var);
8493         return arg_arr;
8494 }
8495
8496 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_OutPoint_1read(JNIEnv *env, jclass clz, int8_tArray ser) {
8497         LDKu8slice ser_ref;
8498         ser_ref.datalen = (*env)->GetArrayLength(env, ser);
8499         ser_ref.data = (*env)->GetByteArrayElements (env, ser, NULL);
8500         LDKOutPoint ret_var = OutPoint_read(ser_ref);
8501         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8502         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8503         long ret_ref = (long)ret_var.inner;
8504         if (ret_var.is_owned) {
8505                 ret_ref |= 1;
8506         }
8507         (*env)->ReleaseByteArrayElements(env, ser, (int8_t*)ser_ref.data, 0);
8508         return ret_ref;
8509 }
8510
8511 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_SpendableOutputDescriptor_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
8512         LDKSpendableOutputDescriptor this_ptr_conv = *(LDKSpendableOutputDescriptor*)this_ptr;
8513         FREE((void*)this_ptr);
8514         SpendableOutputDescriptor_free(this_ptr_conv);
8515 }
8516
8517 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_SpendableOutputDescriptor_1clone(JNIEnv *env, jclass clz, int64_t orig) {
8518         LDKSpendableOutputDescriptor* orig_conv = (LDKSpendableOutputDescriptor*)orig;
8519         LDKSpendableOutputDescriptor *ret_copy = MALLOC(sizeof(LDKSpendableOutputDescriptor), "LDKSpendableOutputDescriptor");
8520         *ret_copy = SpendableOutputDescriptor_clone(orig_conv);
8521         long ret_ref = (long)ret_copy;
8522         return ret_ref;
8523 }
8524
8525 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_SpendableOutputDescriptor_1write(JNIEnv *env, jclass clz, int64_t obj) {
8526         LDKSpendableOutputDescriptor* obj_conv = (LDKSpendableOutputDescriptor*)obj;
8527         LDKCVec_u8Z arg_var = SpendableOutputDescriptor_write(obj_conv);
8528         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
8529         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
8530         CVec_u8Z_free(arg_var);
8531         return arg_arr;
8532 }
8533
8534 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_SpendableOutputDescriptor_1read(JNIEnv *env, jclass clz, int8_tArray ser) {
8535         LDKu8slice ser_ref;
8536         ser_ref.datalen = (*env)->GetArrayLength(env, ser);
8537         ser_ref.data = (*env)->GetByteArrayElements (env, ser, NULL);
8538         LDKCResult_SpendableOutputDescriptorDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_SpendableOutputDescriptorDecodeErrorZ), "LDKCResult_SpendableOutputDescriptorDecodeErrorZ");
8539         *ret_conv = SpendableOutputDescriptor_read(ser_ref);
8540         (*env)->ReleaseByteArrayElements(env, ser, (int8_t*)ser_ref.data, 0);
8541         return (long)ret_conv;
8542 }
8543
8544 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1clone(JNIEnv *env, jclass clz, int64_t orig) {
8545         LDKChannelKeys* orig_conv = (LDKChannelKeys*)orig;
8546         LDKChannelKeys* ret = MALLOC(sizeof(LDKChannelKeys), "LDKChannelKeys");
8547         *ret = ChannelKeys_clone(orig_conv);
8548         return (long)ret;
8549 }
8550
8551 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
8552         LDKChannelKeys this_ptr_conv = *(LDKChannelKeys*)this_ptr;
8553         FREE((void*)this_ptr);
8554         ChannelKeys_free(this_ptr_conv);
8555 }
8556
8557 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_KeysInterface_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
8558         LDKKeysInterface this_ptr_conv = *(LDKKeysInterface*)this_ptr;
8559         FREE((void*)this_ptr);
8560         KeysInterface_free(this_ptr_conv);
8561 }
8562
8563 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
8564         LDKInMemoryChannelKeys this_ptr_conv;
8565         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8566         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8567         InMemoryChannelKeys_free(this_ptr_conv);
8568 }
8569
8570 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1clone(JNIEnv *env, jclass clz, int64_t orig) {
8571         LDKInMemoryChannelKeys orig_conv;
8572         orig_conv.inner = (void*)(orig & (~1));
8573         orig_conv.is_owned = false;
8574         LDKInMemoryChannelKeys ret_var = InMemoryChannelKeys_clone(&orig_conv);
8575         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8576         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8577         long ret_ref = (long)ret_var.inner;
8578         if (ret_var.is_owned) {
8579                 ret_ref |= 1;
8580         }
8581         return ret_ref;
8582 }
8583
8584 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1get_1funding_1key(JNIEnv *env, jclass clz, int64_t this_ptr) {
8585         LDKInMemoryChannelKeys this_ptr_conv;
8586         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8587         this_ptr_conv.is_owned = false;
8588         int8_tArray ret_arr = (*env)->NewByteArray(env, 32);
8589         (*env)->SetByteArrayRegion(env, ret_arr, 0, 32, *InMemoryChannelKeys_get_funding_key(&this_ptr_conv));
8590         return ret_arr;
8591 }
8592
8593 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1set_1funding_1key(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
8594         LDKInMemoryChannelKeys this_ptr_conv;
8595         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8596         this_ptr_conv.is_owned = false;
8597         LDKSecretKey val_ref;
8598         CHECK((*env)->GetArrayLength(env, val) == 32);
8599         (*env)->GetByteArrayRegion(env, val, 0, 32, val_ref.bytes);
8600         InMemoryChannelKeys_set_funding_key(&this_ptr_conv, val_ref);
8601 }
8602
8603 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1get_1revocation_1base_1key(JNIEnv *env, jclass clz, int64_t this_ptr) {
8604         LDKInMemoryChannelKeys this_ptr_conv;
8605         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8606         this_ptr_conv.is_owned = false;
8607         int8_tArray ret_arr = (*env)->NewByteArray(env, 32);
8608         (*env)->SetByteArrayRegion(env, ret_arr, 0, 32, *InMemoryChannelKeys_get_revocation_base_key(&this_ptr_conv));
8609         return ret_arr;
8610 }
8611
8612 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1set_1revocation_1base_1key(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
8613         LDKInMemoryChannelKeys this_ptr_conv;
8614         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8615         this_ptr_conv.is_owned = false;
8616         LDKSecretKey val_ref;
8617         CHECK((*env)->GetArrayLength(env, val) == 32);
8618         (*env)->GetByteArrayRegion(env, val, 0, 32, val_ref.bytes);
8619         InMemoryChannelKeys_set_revocation_base_key(&this_ptr_conv, val_ref);
8620 }
8621
8622 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1get_1payment_1key(JNIEnv *env, jclass clz, int64_t this_ptr) {
8623         LDKInMemoryChannelKeys this_ptr_conv;
8624         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8625         this_ptr_conv.is_owned = false;
8626         int8_tArray ret_arr = (*env)->NewByteArray(env, 32);
8627         (*env)->SetByteArrayRegion(env, ret_arr, 0, 32, *InMemoryChannelKeys_get_payment_key(&this_ptr_conv));
8628         return ret_arr;
8629 }
8630
8631 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1set_1payment_1key(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
8632         LDKInMemoryChannelKeys this_ptr_conv;
8633         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8634         this_ptr_conv.is_owned = false;
8635         LDKSecretKey val_ref;
8636         CHECK((*env)->GetArrayLength(env, val) == 32);
8637         (*env)->GetByteArrayRegion(env, val, 0, 32, val_ref.bytes);
8638         InMemoryChannelKeys_set_payment_key(&this_ptr_conv, val_ref);
8639 }
8640
8641 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1get_1delayed_1payment_1base_1key(JNIEnv *env, jclass clz, int64_t this_ptr) {
8642         LDKInMemoryChannelKeys this_ptr_conv;
8643         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8644         this_ptr_conv.is_owned = false;
8645         int8_tArray ret_arr = (*env)->NewByteArray(env, 32);
8646         (*env)->SetByteArrayRegion(env, ret_arr, 0, 32, *InMemoryChannelKeys_get_delayed_payment_base_key(&this_ptr_conv));
8647         return ret_arr;
8648 }
8649
8650 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) {
8651         LDKInMemoryChannelKeys this_ptr_conv;
8652         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8653         this_ptr_conv.is_owned = false;
8654         LDKSecretKey val_ref;
8655         CHECK((*env)->GetArrayLength(env, val) == 32);
8656         (*env)->GetByteArrayRegion(env, val, 0, 32, val_ref.bytes);
8657         InMemoryChannelKeys_set_delayed_payment_base_key(&this_ptr_conv, val_ref);
8658 }
8659
8660 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1get_1htlc_1base_1key(JNIEnv *env, jclass clz, int64_t this_ptr) {
8661         LDKInMemoryChannelKeys this_ptr_conv;
8662         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8663         this_ptr_conv.is_owned = false;
8664         int8_tArray ret_arr = (*env)->NewByteArray(env, 32);
8665         (*env)->SetByteArrayRegion(env, ret_arr, 0, 32, *InMemoryChannelKeys_get_htlc_base_key(&this_ptr_conv));
8666         return ret_arr;
8667 }
8668
8669 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1set_1htlc_1base_1key(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
8670         LDKInMemoryChannelKeys this_ptr_conv;
8671         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8672         this_ptr_conv.is_owned = false;
8673         LDKSecretKey val_ref;
8674         CHECK((*env)->GetArrayLength(env, val) == 32);
8675         (*env)->GetByteArrayRegion(env, val, 0, 32, val_ref.bytes);
8676         InMemoryChannelKeys_set_htlc_base_key(&this_ptr_conv, val_ref);
8677 }
8678
8679 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1get_1commitment_1seed(JNIEnv *env, jclass clz, int64_t this_ptr) {
8680         LDKInMemoryChannelKeys this_ptr_conv;
8681         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8682         this_ptr_conv.is_owned = false;
8683         int8_tArray ret_arr = (*env)->NewByteArray(env, 32);
8684         (*env)->SetByteArrayRegion(env, ret_arr, 0, 32, *InMemoryChannelKeys_get_commitment_seed(&this_ptr_conv));
8685         return ret_arr;
8686 }
8687
8688 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1set_1commitment_1seed(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
8689         LDKInMemoryChannelKeys this_ptr_conv;
8690         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8691         this_ptr_conv.is_owned = false;
8692         LDKThirtyTwoBytes val_ref;
8693         CHECK((*env)->GetArrayLength(env, val) == 32);
8694         (*env)->GetByteArrayRegion(env, val, 0, 32, val_ref.data);
8695         InMemoryChannelKeys_set_commitment_seed(&this_ptr_conv, val_ref);
8696 }
8697
8698 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) {
8699         LDKSecretKey funding_key_ref;
8700         CHECK((*env)->GetArrayLength(env, funding_key) == 32);
8701         (*env)->GetByteArrayRegion(env, funding_key, 0, 32, funding_key_ref.bytes);
8702         LDKSecretKey revocation_base_key_ref;
8703         CHECK((*env)->GetArrayLength(env, revocation_base_key) == 32);
8704         (*env)->GetByteArrayRegion(env, revocation_base_key, 0, 32, revocation_base_key_ref.bytes);
8705         LDKSecretKey payment_key_ref;
8706         CHECK((*env)->GetArrayLength(env, payment_key) == 32);
8707         (*env)->GetByteArrayRegion(env, payment_key, 0, 32, payment_key_ref.bytes);
8708         LDKSecretKey delayed_payment_base_key_ref;
8709         CHECK((*env)->GetArrayLength(env, delayed_payment_base_key) == 32);
8710         (*env)->GetByteArrayRegion(env, delayed_payment_base_key, 0, 32, delayed_payment_base_key_ref.bytes);
8711         LDKSecretKey htlc_base_key_ref;
8712         CHECK((*env)->GetArrayLength(env, htlc_base_key) == 32);
8713         (*env)->GetByteArrayRegion(env, htlc_base_key, 0, 32, htlc_base_key_ref.bytes);
8714         LDKThirtyTwoBytes commitment_seed_ref;
8715         CHECK((*env)->GetArrayLength(env, commitment_seed) == 32);
8716         (*env)->GetByteArrayRegion(env, commitment_seed, 0, 32, commitment_seed_ref.data);
8717         LDKC2Tuple_u64u64Z key_derivation_params_conv = *(LDKC2Tuple_u64u64Z*)key_derivation_params;
8718         FREE((void*)key_derivation_params);
8719         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);
8720         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8721         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8722         long ret_ref = (long)ret_var.inner;
8723         if (ret_var.is_owned) {
8724                 ret_ref |= 1;
8725         }
8726         return ret_ref;
8727 }
8728
8729 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1counterparty_1pubkeys(JNIEnv *env, jclass clz, int64_t this_arg) {
8730         LDKInMemoryChannelKeys this_arg_conv;
8731         this_arg_conv.inner = (void*)(this_arg & (~1));
8732         this_arg_conv.is_owned = false;
8733         LDKChannelPublicKeys ret_var = InMemoryChannelKeys_counterparty_pubkeys(&this_arg_conv);
8734         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8735         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8736         long ret_ref = (long)ret_var.inner;
8737         if (ret_var.is_owned) {
8738                 ret_ref |= 1;
8739         }
8740         return ret_ref;
8741 }
8742
8743 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1counterparty_1selected_1contest_1delay(JNIEnv *env, jclass clz, int64_t this_arg) {
8744         LDKInMemoryChannelKeys this_arg_conv;
8745         this_arg_conv.inner = (void*)(this_arg & (~1));
8746         this_arg_conv.is_owned = false;
8747         jshort ret_val = InMemoryChannelKeys_counterparty_selected_contest_delay(&this_arg_conv);
8748         return ret_val;
8749 }
8750
8751 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1holder_1selected_1contest_1delay(JNIEnv *env, jclass clz, int64_t this_arg) {
8752         LDKInMemoryChannelKeys this_arg_conv;
8753         this_arg_conv.inner = (void*)(this_arg & (~1));
8754         this_arg_conv.is_owned = false;
8755         jshort ret_val = InMemoryChannelKeys_holder_selected_contest_delay(&this_arg_conv);
8756         return ret_val;
8757 }
8758
8759 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1is_1outbound(JNIEnv *env, jclass clz, int64_t this_arg) {
8760         LDKInMemoryChannelKeys this_arg_conv;
8761         this_arg_conv.inner = (void*)(this_arg & (~1));
8762         this_arg_conv.is_owned = false;
8763         jboolean ret_val = InMemoryChannelKeys_is_outbound(&this_arg_conv);
8764         return ret_val;
8765 }
8766
8767 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1funding_1outpoint(JNIEnv *env, jclass clz, int64_t this_arg) {
8768         LDKInMemoryChannelKeys this_arg_conv;
8769         this_arg_conv.inner = (void*)(this_arg & (~1));
8770         this_arg_conv.is_owned = false;
8771         LDKOutPoint ret_var = InMemoryChannelKeys_funding_outpoint(&this_arg_conv);
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_InMemoryChannelKeys_1get_1channel_1parameters(JNIEnv *env, jclass clz, int64_t this_arg) {
8782         LDKInMemoryChannelKeys this_arg_conv;
8783         this_arg_conv.inner = (void*)(this_arg & (~1));
8784         this_arg_conv.is_owned = false;
8785         LDKChannelTransactionParameters ret_var = InMemoryChannelKeys_get_channel_parameters(&this_arg_conv);
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_InMemoryChannelKeys_1as_1ChannelKeys(JNIEnv *env, jclass clz, int64_t this_arg) {
8796         LDKInMemoryChannelKeys this_arg_conv;
8797         this_arg_conv.inner = (void*)(this_arg & (~1));
8798         this_arg_conv.is_owned = false;
8799         LDKChannelKeys* ret = MALLOC(sizeof(LDKChannelKeys), "LDKChannelKeys");
8800         *ret = InMemoryChannelKeys_as_ChannelKeys(&this_arg_conv);
8801         return (long)ret;
8802 }
8803
8804 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1write(JNIEnv *env, jclass clz, int64_t obj) {
8805         LDKInMemoryChannelKeys obj_conv;
8806         obj_conv.inner = (void*)(obj & (~1));
8807         obj_conv.is_owned = false;
8808         LDKCVec_u8Z arg_var = InMemoryChannelKeys_write(&obj_conv);
8809         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
8810         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
8811         CVec_u8Z_free(arg_var);
8812         return arg_arr;
8813 }
8814
8815 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1read(JNIEnv *env, jclass clz, int8_tArray ser) {
8816         LDKu8slice ser_ref;
8817         ser_ref.datalen = (*env)->GetArrayLength(env, ser);
8818         ser_ref.data = (*env)->GetByteArrayElements (env, ser, NULL);
8819         LDKCResult_InMemoryChannelKeysDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_InMemoryChannelKeysDecodeErrorZ), "LDKCResult_InMemoryChannelKeysDecodeErrorZ");
8820         *ret_conv = InMemoryChannelKeys_read(ser_ref);
8821         (*env)->ReleaseByteArrayElements(env, ser, (int8_t*)ser_ref.data, 0);
8822         return (long)ret_conv;
8823 }
8824
8825 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_KeysManager_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
8826         LDKKeysManager this_ptr_conv;
8827         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8828         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8829         KeysManager_free(this_ptr_conv);
8830 }
8831
8832 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) {
8833         unsigned char seed_arr[32];
8834         CHECK((*env)->GetArrayLength(env, seed) == 32);
8835         (*env)->GetByteArrayRegion(env, seed, 0, 32, seed_arr);
8836         unsigned char (*seed_ref)[32] = &seed_arr;
8837         LDKNetwork network_conv = LDKNetwork_from_java(env, network);
8838         LDKKeysManager ret_var = KeysManager_new(seed_ref, network_conv, starting_time_secs, starting_time_nanos);
8839         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8840         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8841         long ret_ref = (long)ret_var.inner;
8842         if (ret_var.is_owned) {
8843                 ret_ref |= 1;
8844         }
8845         return ret_ref;
8846 }
8847
8848 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) {
8849         LDKKeysManager this_arg_conv;
8850         this_arg_conv.inner = (void*)(this_arg & (~1));
8851         this_arg_conv.is_owned = false;
8852         LDKInMemoryChannelKeys ret_var = KeysManager_derive_channel_keys(&this_arg_conv, channel_value_satoshis, params_1, params_2);
8853         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8854         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8855         long ret_ref = (long)ret_var.inner;
8856         if (ret_var.is_owned) {
8857                 ret_ref |= 1;
8858         }
8859         return ret_ref;
8860 }
8861
8862 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_KeysManager_1as_1KeysInterface(JNIEnv *env, jclass clz, int64_t this_arg) {
8863         LDKKeysManager this_arg_conv;
8864         this_arg_conv.inner = (void*)(this_arg & (~1));
8865         this_arg_conv.is_owned = false;
8866         LDKKeysInterface* ret = MALLOC(sizeof(LDKKeysInterface), "LDKKeysInterface");
8867         *ret = KeysManager_as_KeysInterface(&this_arg_conv);
8868         return (long)ret;
8869 }
8870
8871 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelManager_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
8872         LDKChannelManager this_ptr_conv;
8873         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8874         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8875         ChannelManager_free(this_ptr_conv);
8876 }
8877
8878 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
8879         LDKChannelDetails this_ptr_conv;
8880         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8881         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8882         ChannelDetails_free(this_ptr_conv);
8883 }
8884
8885 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1clone(JNIEnv *env, jclass clz, int64_t orig) {
8886         LDKChannelDetails orig_conv;
8887         orig_conv.inner = (void*)(orig & (~1));
8888         orig_conv.is_owned = false;
8889         LDKChannelDetails ret_var = ChannelDetails_clone(&orig_conv);
8890         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8891         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8892         long ret_ref = (long)ret_var.inner;
8893         if (ret_var.is_owned) {
8894                 ret_ref |= 1;
8895         }
8896         return ret_ref;
8897 }
8898
8899 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1get_1channel_1id(JNIEnv *env, jclass clz, int64_t this_ptr) {
8900         LDKChannelDetails this_ptr_conv;
8901         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8902         this_ptr_conv.is_owned = false;
8903         int8_tArray ret_arr = (*env)->NewByteArray(env, 32);
8904         (*env)->SetByteArrayRegion(env, ret_arr, 0, 32, *ChannelDetails_get_channel_id(&this_ptr_conv));
8905         return ret_arr;
8906 }
8907
8908 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1set_1channel_1id(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
8909         LDKChannelDetails this_ptr_conv;
8910         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8911         this_ptr_conv.is_owned = false;
8912         LDKThirtyTwoBytes val_ref;
8913         CHECK((*env)->GetArrayLength(env, val) == 32);
8914         (*env)->GetByteArrayRegion(env, val, 0, 32, val_ref.data);
8915         ChannelDetails_set_channel_id(&this_ptr_conv, val_ref);
8916 }
8917
8918 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1get_1remote_1network_1id(JNIEnv *env, jclass clz, int64_t this_ptr) {
8919         LDKChannelDetails this_ptr_conv;
8920         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8921         this_ptr_conv.is_owned = false;
8922         int8_tArray arg_arr = (*env)->NewByteArray(env, 33);
8923         (*env)->SetByteArrayRegion(env, arg_arr, 0, 33, ChannelDetails_get_remote_network_id(&this_ptr_conv).compressed_form);
8924         return arg_arr;
8925 }
8926
8927 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1set_1remote_1network_1id(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
8928         LDKChannelDetails this_ptr_conv;
8929         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8930         this_ptr_conv.is_owned = false;
8931         LDKPublicKey val_ref;
8932         CHECK((*env)->GetArrayLength(env, val) == 33);
8933         (*env)->GetByteArrayRegion(env, val, 0, 33, val_ref.compressed_form);
8934         ChannelDetails_set_remote_network_id(&this_ptr_conv, val_ref);
8935 }
8936
8937 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1get_1counterparty_1features(JNIEnv *env, jclass clz, int64_t this_ptr) {
8938         LDKChannelDetails this_ptr_conv;
8939         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8940         this_ptr_conv.is_owned = false;
8941         LDKInitFeatures ret_var = ChannelDetails_get_counterparty_features(&this_ptr_conv);
8942         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8943         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8944         long ret_ref = (long)ret_var.inner;
8945         if (ret_var.is_owned) {
8946                 ret_ref |= 1;
8947         }
8948         return ret_ref;
8949 }
8950
8951 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1set_1counterparty_1features(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
8952         LDKChannelDetails this_ptr_conv;
8953         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8954         this_ptr_conv.is_owned = false;
8955         LDKInitFeatures val_conv;
8956         val_conv.inner = (void*)(val & (~1));
8957         val_conv.is_owned = (val & 1) || (val == 0);
8958         // Warning: we may need a move here but can't clone!
8959         ChannelDetails_set_counterparty_features(&this_ptr_conv, val_conv);
8960 }
8961
8962 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1get_1channel_1value_1satoshis(JNIEnv *env, jclass clz, int64_t this_ptr) {
8963         LDKChannelDetails this_ptr_conv;
8964         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8965         this_ptr_conv.is_owned = false;
8966         int64_t ret_val = ChannelDetails_get_channel_value_satoshis(&this_ptr_conv);
8967         return ret_val;
8968 }
8969
8970 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1set_1channel_1value_1satoshis(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
8971         LDKChannelDetails this_ptr_conv;
8972         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8973         this_ptr_conv.is_owned = false;
8974         ChannelDetails_set_channel_value_satoshis(&this_ptr_conv, val);
8975 }
8976
8977 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1get_1user_1id(JNIEnv *env, jclass clz, int64_t this_ptr) {
8978         LDKChannelDetails this_ptr_conv;
8979         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8980         this_ptr_conv.is_owned = false;
8981         int64_t ret_val = ChannelDetails_get_user_id(&this_ptr_conv);
8982         return ret_val;
8983 }
8984
8985 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1set_1user_1id(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
8986         LDKChannelDetails this_ptr_conv;
8987         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8988         this_ptr_conv.is_owned = false;
8989         ChannelDetails_set_user_id(&this_ptr_conv, val);
8990 }
8991
8992 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1get_1outbound_1capacity_1msat(JNIEnv *env, jclass clz, int64_t this_ptr) {
8993         LDKChannelDetails this_ptr_conv;
8994         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8995         this_ptr_conv.is_owned = false;
8996         int64_t ret_val = ChannelDetails_get_outbound_capacity_msat(&this_ptr_conv);
8997         return ret_val;
8998 }
8999
9000 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1set_1outbound_1capacity_1msat(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
9001         LDKChannelDetails this_ptr_conv;
9002         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9003         this_ptr_conv.is_owned = false;
9004         ChannelDetails_set_outbound_capacity_msat(&this_ptr_conv, val);
9005 }
9006
9007 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1get_1inbound_1capacity_1msat(JNIEnv *env, jclass clz, int64_t this_ptr) {
9008         LDKChannelDetails this_ptr_conv;
9009         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9010         this_ptr_conv.is_owned = false;
9011         int64_t ret_val = ChannelDetails_get_inbound_capacity_msat(&this_ptr_conv);
9012         return ret_val;
9013 }
9014
9015 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1set_1inbound_1capacity_1msat(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
9016         LDKChannelDetails this_ptr_conv;
9017         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9018         this_ptr_conv.is_owned = false;
9019         ChannelDetails_set_inbound_capacity_msat(&this_ptr_conv, val);
9020 }
9021
9022 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1get_1is_1live(JNIEnv *env, jclass clz, int64_t this_ptr) {
9023         LDKChannelDetails this_ptr_conv;
9024         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9025         this_ptr_conv.is_owned = false;
9026         jboolean ret_val = ChannelDetails_get_is_live(&this_ptr_conv);
9027         return ret_val;
9028 }
9029
9030 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1set_1is_1live(JNIEnv *env, jclass clz, int64_t this_ptr, jboolean val) {
9031         LDKChannelDetails this_ptr_conv;
9032         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9033         this_ptr_conv.is_owned = false;
9034         ChannelDetails_set_is_live(&this_ptr_conv, val);
9035 }
9036
9037 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_PaymentSendFailure_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
9038         LDKPaymentSendFailure this_ptr_conv;
9039         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9040         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9041         PaymentSendFailure_free(this_ptr_conv);
9042 }
9043
9044 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, int64_t current_blockchain_height) {
9045         LDKNetwork network_conv = LDKNetwork_from_java(env, network);
9046         LDKFeeEstimator fee_est_conv = *(LDKFeeEstimator*)fee_est;
9047         if (fee_est_conv.free == LDKFeeEstimator_JCalls_free) {
9048                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
9049                 LDKFeeEstimator_JCalls_clone(fee_est_conv.this_arg);
9050         }
9051         LDKWatch chain_monitor_conv = *(LDKWatch*)chain_monitor;
9052         if (chain_monitor_conv.free == LDKWatch_JCalls_free) {
9053                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
9054                 LDKWatch_JCalls_clone(chain_monitor_conv.this_arg);
9055         }
9056         LDKBroadcasterInterface tx_broadcaster_conv = *(LDKBroadcasterInterface*)tx_broadcaster;
9057         if (tx_broadcaster_conv.free == LDKBroadcasterInterface_JCalls_free) {
9058                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
9059                 LDKBroadcasterInterface_JCalls_clone(tx_broadcaster_conv.this_arg);
9060         }
9061         LDKLogger logger_conv = *(LDKLogger*)logger;
9062         if (logger_conv.free == LDKLogger_JCalls_free) {
9063                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
9064                 LDKLogger_JCalls_clone(logger_conv.this_arg);
9065         }
9066         LDKKeysInterface keys_manager_conv = *(LDKKeysInterface*)keys_manager;
9067         if (keys_manager_conv.free == LDKKeysInterface_JCalls_free) {
9068                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
9069                 LDKKeysInterface_JCalls_clone(keys_manager_conv.this_arg);
9070         }
9071         LDKUserConfig config_conv;
9072         config_conv.inner = (void*)(config & (~1));
9073         config_conv.is_owned = (config & 1) || (config == 0);
9074         if (config_conv.inner != NULL)
9075                 config_conv = UserConfig_clone(&config_conv);
9076         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);
9077         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9078         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9079         long ret_ref = (long)ret_var.inner;
9080         if (ret_var.is_owned) {
9081                 ret_ref |= 1;
9082         }
9083         return ret_ref;
9084 }
9085
9086 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) {
9087         LDKChannelManager this_arg_conv;
9088         this_arg_conv.inner = (void*)(this_arg & (~1));
9089         this_arg_conv.is_owned = false;
9090         LDKPublicKey their_network_key_ref;
9091         CHECK((*env)->GetArrayLength(env, their_network_key) == 33);
9092         (*env)->GetByteArrayRegion(env, their_network_key, 0, 33, their_network_key_ref.compressed_form);
9093         LDKUserConfig override_config_conv;
9094         override_config_conv.inner = (void*)(override_config & (~1));
9095         override_config_conv.is_owned = (override_config & 1) || (override_config == 0);
9096         if (override_config_conv.inner != NULL)
9097                 override_config_conv = UserConfig_clone(&override_config_conv);
9098         LDKCResult_NoneAPIErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneAPIErrorZ), "LDKCResult_NoneAPIErrorZ");
9099         *ret_conv = ChannelManager_create_channel(&this_arg_conv, their_network_key_ref, channel_value_satoshis, push_msat, user_id, override_config_conv);
9100         return (long)ret_conv;
9101 }
9102
9103 JNIEXPORT int64_tArray JNICALL Java_org_ldk_impl_bindings_ChannelManager_1list_1channels(JNIEnv *env, jclass clz, int64_t this_arg) {
9104         LDKChannelManager this_arg_conv;
9105         this_arg_conv.inner = (void*)(this_arg & (~1));
9106         this_arg_conv.is_owned = false;
9107         LDKCVec_ChannelDetailsZ ret_var = ChannelManager_list_channels(&this_arg_conv);
9108         int64_tArray ret_arr = (*env)->NewLongArray(env, ret_var.datalen);
9109         int64_t *ret_arr_ptr = (*env)->GetPrimitiveArrayCritical(env, ret_arr, NULL);
9110         for (size_t q = 0; q < ret_var.datalen; q++) {
9111                 LDKChannelDetails arr_conv_16_var = ret_var.data[q];
9112                 CHECK((((long)arr_conv_16_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9113                 CHECK((((long)&arr_conv_16_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9114                 long arr_conv_16_ref = (long)arr_conv_16_var.inner;
9115                 if (arr_conv_16_var.is_owned) {
9116                         arr_conv_16_ref |= 1;
9117                 }
9118                 ret_arr_ptr[q] = arr_conv_16_ref;
9119         }
9120         (*env)->ReleasePrimitiveArrayCritical(env, ret_arr, ret_arr_ptr, 0);
9121         FREE(ret_var.data);
9122         return ret_arr;
9123 }
9124
9125 JNIEXPORT int64_tArray JNICALL Java_org_ldk_impl_bindings_ChannelManager_1list_1usable_1channels(JNIEnv *env, jclass clz, int64_t this_arg) {
9126         LDKChannelManager this_arg_conv;
9127         this_arg_conv.inner = (void*)(this_arg & (~1));
9128         this_arg_conv.is_owned = false;
9129         LDKCVec_ChannelDetailsZ ret_var = ChannelManager_list_usable_channels(&this_arg_conv);
9130         int64_tArray ret_arr = (*env)->NewLongArray(env, ret_var.datalen);
9131         int64_t *ret_arr_ptr = (*env)->GetPrimitiveArrayCritical(env, ret_arr, NULL);
9132         for (size_t q = 0; q < ret_var.datalen; q++) {
9133                 LDKChannelDetails arr_conv_16_var = ret_var.data[q];
9134                 CHECK((((long)arr_conv_16_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9135                 CHECK((((long)&arr_conv_16_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9136                 long arr_conv_16_ref = (long)arr_conv_16_var.inner;
9137                 if (arr_conv_16_var.is_owned) {
9138                         arr_conv_16_ref |= 1;
9139                 }
9140                 ret_arr_ptr[q] = arr_conv_16_ref;
9141         }
9142         (*env)->ReleasePrimitiveArrayCritical(env, ret_arr, ret_arr_ptr, 0);
9143         FREE(ret_var.data);
9144         return ret_arr;
9145 }
9146
9147 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelManager_1close_1channel(JNIEnv *env, jclass clz, int64_t this_arg, int8_tArray channel_id) {
9148         LDKChannelManager this_arg_conv;
9149         this_arg_conv.inner = (void*)(this_arg & (~1));
9150         this_arg_conv.is_owned = false;
9151         unsigned char channel_id_arr[32];
9152         CHECK((*env)->GetArrayLength(env, channel_id) == 32);
9153         (*env)->GetByteArrayRegion(env, channel_id, 0, 32, channel_id_arr);
9154         unsigned char (*channel_id_ref)[32] = &channel_id_arr;
9155         LDKCResult_NoneAPIErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneAPIErrorZ), "LDKCResult_NoneAPIErrorZ");
9156         *ret_conv = ChannelManager_close_channel(&this_arg_conv, channel_id_ref);
9157         return (long)ret_conv;
9158 }
9159
9160 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelManager_1force_1close_1channel(JNIEnv *env, jclass clz, int64_t this_arg, int8_tArray channel_id) {
9161         LDKChannelManager this_arg_conv;
9162         this_arg_conv.inner = (void*)(this_arg & (~1));
9163         this_arg_conv.is_owned = false;
9164         unsigned char channel_id_arr[32];
9165         CHECK((*env)->GetArrayLength(env, channel_id) == 32);
9166         (*env)->GetByteArrayRegion(env, channel_id, 0, 32, channel_id_arr);
9167         unsigned char (*channel_id_ref)[32] = &channel_id_arr;
9168         ChannelManager_force_close_channel(&this_arg_conv, channel_id_ref);
9169 }
9170
9171 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelManager_1force_1close_1all_1channels(JNIEnv *env, jclass clz, int64_t this_arg) {
9172         LDKChannelManager this_arg_conv;
9173         this_arg_conv.inner = (void*)(this_arg & (~1));
9174         this_arg_conv.is_owned = false;
9175         ChannelManager_force_close_all_channels(&this_arg_conv);
9176 }
9177
9178 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) {
9179         LDKChannelManager this_arg_conv;
9180         this_arg_conv.inner = (void*)(this_arg & (~1));
9181         this_arg_conv.is_owned = false;
9182         LDKRoute route_conv;
9183         route_conv.inner = (void*)(route & (~1));
9184         route_conv.is_owned = false;
9185         LDKThirtyTwoBytes payment_hash_ref;
9186         CHECK((*env)->GetArrayLength(env, payment_hash) == 32);
9187         (*env)->GetByteArrayRegion(env, payment_hash, 0, 32, payment_hash_ref.data);
9188         LDKThirtyTwoBytes payment_secret_ref;
9189         CHECK((*env)->GetArrayLength(env, payment_secret) == 32);
9190         (*env)->GetByteArrayRegion(env, payment_secret, 0, 32, payment_secret_ref.data);
9191         LDKCResult_NonePaymentSendFailureZ* ret_conv = MALLOC(sizeof(LDKCResult_NonePaymentSendFailureZ), "LDKCResult_NonePaymentSendFailureZ");
9192         *ret_conv = ChannelManager_send_payment(&this_arg_conv, &route_conv, payment_hash_ref, payment_secret_ref);
9193         return (long)ret_conv;
9194 }
9195
9196 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) {
9197         LDKChannelManager this_arg_conv;
9198         this_arg_conv.inner = (void*)(this_arg & (~1));
9199         this_arg_conv.is_owned = false;
9200         unsigned char temporary_channel_id_arr[32];
9201         CHECK((*env)->GetArrayLength(env, temporary_channel_id) == 32);
9202         (*env)->GetByteArrayRegion(env, temporary_channel_id, 0, 32, temporary_channel_id_arr);
9203         unsigned char (*temporary_channel_id_ref)[32] = &temporary_channel_id_arr;
9204         LDKOutPoint funding_txo_conv;
9205         funding_txo_conv.inner = (void*)(funding_txo & (~1));
9206         funding_txo_conv.is_owned = (funding_txo & 1) || (funding_txo == 0);
9207         if (funding_txo_conv.inner != NULL)
9208                 funding_txo_conv = OutPoint_clone(&funding_txo_conv);
9209         ChannelManager_funding_transaction_generated(&this_arg_conv, temporary_channel_id_ref, funding_txo_conv);
9210 }
9211
9212 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) {
9213         LDKChannelManager this_arg_conv;
9214         this_arg_conv.inner = (void*)(this_arg & (~1));
9215         this_arg_conv.is_owned = false;
9216         LDKThreeBytes rgb_ref;
9217         CHECK((*env)->GetArrayLength(env, rgb) == 3);
9218         (*env)->GetByteArrayRegion(env, rgb, 0, 3, rgb_ref.data);
9219         LDKThirtyTwoBytes alias_ref;
9220         CHECK((*env)->GetArrayLength(env, alias) == 32);
9221         (*env)->GetByteArrayRegion(env, alias, 0, 32, alias_ref.data);
9222         LDKCVec_NetAddressZ addresses_constr;
9223         addresses_constr.datalen = (*env)->GetArrayLength(env, addresses);
9224         if (addresses_constr.datalen > 0)
9225                 addresses_constr.data = MALLOC(addresses_constr.datalen * sizeof(LDKNetAddress), "LDKCVec_NetAddressZ Elements");
9226         else
9227                 addresses_constr.data = NULL;
9228         int64_t* addresses_vals = (*env)->GetLongArrayElements (env, addresses, NULL);
9229         for (size_t m = 0; m < addresses_constr.datalen; m++) {
9230                 int64_t arr_conv_12 = addresses_vals[m];
9231                 LDKNetAddress arr_conv_12_conv = *(LDKNetAddress*)arr_conv_12;
9232                 FREE((void*)arr_conv_12);
9233                 addresses_constr.data[m] = arr_conv_12_conv;
9234         }
9235         (*env)->ReleaseLongArrayElements(env, addresses, addresses_vals, 0);
9236         ChannelManager_broadcast_node_announcement(&this_arg_conv, rgb_ref, alias_ref, addresses_constr);
9237 }
9238
9239 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelManager_1process_1pending_1htlc_1forwards(JNIEnv *env, jclass clz, int64_t this_arg) {
9240         LDKChannelManager this_arg_conv;
9241         this_arg_conv.inner = (void*)(this_arg & (~1));
9242         this_arg_conv.is_owned = false;
9243         ChannelManager_process_pending_htlc_forwards(&this_arg_conv);
9244 }
9245
9246 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelManager_1timer_1chan_1freshness_1every_1min(JNIEnv *env, jclass clz, int64_t this_arg) {
9247         LDKChannelManager this_arg_conv;
9248         this_arg_conv.inner = (void*)(this_arg & (~1));
9249         this_arg_conv.is_owned = false;
9250         ChannelManager_timer_chan_freshness_every_min(&this_arg_conv);
9251 }
9252
9253 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) {
9254         LDKChannelManager this_arg_conv;
9255         this_arg_conv.inner = (void*)(this_arg & (~1));
9256         this_arg_conv.is_owned = false;
9257         unsigned char payment_hash_arr[32];
9258         CHECK((*env)->GetArrayLength(env, payment_hash) == 32);
9259         (*env)->GetByteArrayRegion(env, payment_hash, 0, 32, payment_hash_arr);
9260         unsigned char (*payment_hash_ref)[32] = &payment_hash_arr;
9261         LDKThirtyTwoBytes payment_secret_ref;
9262         CHECK((*env)->GetArrayLength(env, payment_secret) == 32);
9263         (*env)->GetByteArrayRegion(env, payment_secret, 0, 32, payment_secret_ref.data);
9264         jboolean ret_val = ChannelManager_fail_htlc_backwards(&this_arg_conv, payment_hash_ref, payment_secret_ref);
9265         return ret_val;
9266 }
9267
9268 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) {
9269         LDKChannelManager this_arg_conv;
9270         this_arg_conv.inner = (void*)(this_arg & (~1));
9271         this_arg_conv.is_owned = false;
9272         LDKThirtyTwoBytes payment_preimage_ref;
9273         CHECK((*env)->GetArrayLength(env, payment_preimage) == 32);
9274         (*env)->GetByteArrayRegion(env, payment_preimage, 0, 32, payment_preimage_ref.data);
9275         LDKThirtyTwoBytes payment_secret_ref;
9276         CHECK((*env)->GetArrayLength(env, payment_secret) == 32);
9277         (*env)->GetByteArrayRegion(env, payment_secret, 0, 32, payment_secret_ref.data);
9278         jboolean ret_val = ChannelManager_claim_funds(&this_arg_conv, payment_preimage_ref, payment_secret_ref, expected_amount);
9279         return ret_val;
9280 }
9281
9282 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_ChannelManager_1get_1our_1node_1id(JNIEnv *env, jclass clz, int64_t this_arg) {
9283         LDKChannelManager this_arg_conv;
9284         this_arg_conv.inner = (void*)(this_arg & (~1));
9285         this_arg_conv.is_owned = false;
9286         int8_tArray arg_arr = (*env)->NewByteArray(env, 33);
9287         (*env)->SetByteArrayRegion(env, arg_arr, 0, 33, ChannelManager_get_our_node_id(&this_arg_conv).compressed_form);
9288         return arg_arr;
9289 }
9290
9291 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) {
9292         LDKChannelManager this_arg_conv;
9293         this_arg_conv.inner = (void*)(this_arg & (~1));
9294         this_arg_conv.is_owned = false;
9295         LDKOutPoint funding_txo_conv;
9296         funding_txo_conv.inner = (void*)(funding_txo & (~1));
9297         funding_txo_conv.is_owned = false;
9298         ChannelManager_channel_monitor_updated(&this_arg_conv, &funding_txo_conv, highest_applied_update_id);
9299 }
9300
9301 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelManager_1as_1MessageSendEventsProvider(JNIEnv *env, jclass clz, int64_t this_arg) {
9302         LDKChannelManager this_arg_conv;
9303         this_arg_conv.inner = (void*)(this_arg & (~1));
9304         this_arg_conv.is_owned = false;
9305         LDKMessageSendEventsProvider* ret = MALLOC(sizeof(LDKMessageSendEventsProvider), "LDKMessageSendEventsProvider");
9306         *ret = ChannelManager_as_MessageSendEventsProvider(&this_arg_conv);
9307         return (long)ret;
9308 }
9309
9310 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelManager_1as_1EventsProvider(JNIEnv *env, jclass clz, int64_t this_arg) {
9311         LDKChannelManager this_arg_conv;
9312         this_arg_conv.inner = (void*)(this_arg & (~1));
9313         this_arg_conv.is_owned = false;
9314         LDKEventsProvider* ret = MALLOC(sizeof(LDKEventsProvider), "LDKEventsProvider");
9315         *ret = ChannelManager_as_EventsProvider(&this_arg_conv);
9316         return (long)ret;
9317 }
9318
9319 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) {
9320         LDKChannelManager this_arg_conv;
9321         this_arg_conv.inner = (void*)(this_arg & (~1));
9322         this_arg_conv.is_owned = false;
9323         unsigned char header_arr[80];
9324         CHECK((*env)->GetArrayLength(env, header) == 80);
9325         (*env)->GetByteArrayRegion(env, header, 0, 80, header_arr);
9326         unsigned char (*header_ref)[80] = &header_arr;
9327         LDKCVec_C2Tuple_usizeTransactionZZ txdata_constr;
9328         txdata_constr.datalen = (*env)->GetArrayLength(env, txdata);
9329         if (txdata_constr.datalen > 0)
9330                 txdata_constr.data = MALLOC(txdata_constr.datalen * sizeof(LDKC2Tuple_usizeTransactionZ), "LDKCVec_C2Tuple_usizeTransactionZZ Elements");
9331         else
9332                 txdata_constr.data = NULL;
9333         int64_t* txdata_vals = (*env)->GetLongArrayElements (env, txdata, NULL);
9334         for (size_t y = 0; y < txdata_constr.datalen; y++) {
9335                 int64_t arr_conv_24 = txdata_vals[y];
9336                 LDKC2Tuple_usizeTransactionZ arr_conv_24_conv = *(LDKC2Tuple_usizeTransactionZ*)arr_conv_24;
9337                 FREE((void*)arr_conv_24);
9338                 txdata_constr.data[y] = arr_conv_24_conv;
9339         }
9340         (*env)->ReleaseLongArrayElements(env, txdata, txdata_vals, 0);
9341         ChannelManager_block_connected(&this_arg_conv, header_ref, txdata_constr, height);
9342 }
9343
9344 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelManager_1block_1disconnected(JNIEnv *env, jclass clz, int64_t this_arg, int8_tArray header) {
9345         LDKChannelManager this_arg_conv;
9346         this_arg_conv.inner = (void*)(this_arg & (~1));
9347         this_arg_conv.is_owned = false;
9348         unsigned char header_arr[80];
9349         CHECK((*env)->GetArrayLength(env, header) == 80);
9350         (*env)->GetByteArrayRegion(env, header, 0, 80, header_arr);
9351         unsigned char (*header_ref)[80] = &header_arr;
9352         ChannelManager_block_disconnected(&this_arg_conv, header_ref);
9353 }
9354
9355 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelManager_1as_1ChannelMessageHandler(JNIEnv *env, jclass clz, int64_t this_arg) {
9356         LDKChannelManager this_arg_conv;
9357         this_arg_conv.inner = (void*)(this_arg & (~1));
9358         this_arg_conv.is_owned = false;
9359         LDKChannelMessageHandler* ret = MALLOC(sizeof(LDKChannelMessageHandler), "LDKChannelMessageHandler");
9360         *ret = ChannelManager_as_ChannelMessageHandler(&this_arg_conv);
9361         return (long)ret;
9362 }
9363
9364 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_ChannelManager_1write(JNIEnv *env, jclass clz, int64_t obj) {
9365         LDKChannelManager obj_conv;
9366         obj_conv.inner = (void*)(obj & (~1));
9367         obj_conv.is_owned = false;
9368         LDKCVec_u8Z arg_var = ChannelManager_write(&obj_conv);
9369         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
9370         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
9371         CVec_u8Z_free(arg_var);
9372         return arg_arr;
9373 }
9374
9375 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelManagerReadArgs_1free(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 = (this_ptr & 1) || (this_ptr == 0);
9379         ChannelManagerReadArgs_free(this_ptr_conv);
9380 }
9381
9382 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelManagerReadArgs_1get_1keys_1manager(JNIEnv *env, jclass clz, int64_t this_ptr) {
9383         LDKChannelManagerReadArgs this_ptr_conv;
9384         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9385         this_ptr_conv.is_owned = false;
9386         long ret_ret = (long)ChannelManagerReadArgs_get_keys_manager(&this_ptr_conv);
9387         return ret_ret;
9388 }
9389
9390 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelManagerReadArgs_1set_1keys_1manager(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
9391         LDKChannelManagerReadArgs this_ptr_conv;
9392         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9393         this_ptr_conv.is_owned = false;
9394         LDKKeysInterface val_conv = *(LDKKeysInterface*)val;
9395         if (val_conv.free == LDKKeysInterface_JCalls_free) {
9396                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
9397                 LDKKeysInterface_JCalls_clone(val_conv.this_arg);
9398         }
9399         ChannelManagerReadArgs_set_keys_manager(&this_ptr_conv, val_conv);
9400 }
9401
9402 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelManagerReadArgs_1get_1fee_1estimator(JNIEnv *env, jclass clz, int64_t this_ptr) {
9403         LDKChannelManagerReadArgs this_ptr_conv;
9404         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9405         this_ptr_conv.is_owned = false;
9406         long ret_ret = (long)ChannelManagerReadArgs_get_fee_estimator(&this_ptr_conv);
9407         return ret_ret;
9408 }
9409
9410 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelManagerReadArgs_1set_1fee_1estimator(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
9411         LDKChannelManagerReadArgs this_ptr_conv;
9412         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9413         this_ptr_conv.is_owned = false;
9414         LDKFeeEstimator val_conv = *(LDKFeeEstimator*)val;
9415         if (val_conv.free == LDKFeeEstimator_JCalls_free) {
9416                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
9417                 LDKFeeEstimator_JCalls_clone(val_conv.this_arg);
9418         }
9419         ChannelManagerReadArgs_set_fee_estimator(&this_ptr_conv, val_conv);
9420 }
9421
9422 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelManagerReadArgs_1get_1chain_1monitor(JNIEnv *env, jclass clz, int64_t this_ptr) {
9423         LDKChannelManagerReadArgs this_ptr_conv;
9424         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9425         this_ptr_conv.is_owned = false;
9426         long ret_ret = (long)ChannelManagerReadArgs_get_chain_monitor(&this_ptr_conv);
9427         return ret_ret;
9428 }
9429
9430 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelManagerReadArgs_1set_1chain_1monitor(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
9431         LDKChannelManagerReadArgs this_ptr_conv;
9432         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9433         this_ptr_conv.is_owned = false;
9434         LDKWatch val_conv = *(LDKWatch*)val;
9435         if (val_conv.free == LDKWatch_JCalls_free) {
9436                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
9437                 LDKWatch_JCalls_clone(val_conv.this_arg);
9438         }
9439         ChannelManagerReadArgs_set_chain_monitor(&this_ptr_conv, val_conv);
9440 }
9441
9442 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelManagerReadArgs_1get_1tx_1broadcaster(JNIEnv *env, jclass clz, int64_t this_ptr) {
9443         LDKChannelManagerReadArgs this_ptr_conv;
9444         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9445         this_ptr_conv.is_owned = false;
9446         long ret_ret = (long)ChannelManagerReadArgs_get_tx_broadcaster(&this_ptr_conv);
9447         return ret_ret;
9448 }
9449
9450 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelManagerReadArgs_1set_1tx_1broadcaster(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
9451         LDKChannelManagerReadArgs this_ptr_conv;
9452         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9453         this_ptr_conv.is_owned = false;
9454         LDKBroadcasterInterface val_conv = *(LDKBroadcasterInterface*)val;
9455         if (val_conv.free == LDKBroadcasterInterface_JCalls_free) {
9456                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
9457                 LDKBroadcasterInterface_JCalls_clone(val_conv.this_arg);
9458         }
9459         ChannelManagerReadArgs_set_tx_broadcaster(&this_ptr_conv, val_conv);
9460 }
9461
9462 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelManagerReadArgs_1get_1logger(JNIEnv *env, jclass clz, int64_t this_ptr) {
9463         LDKChannelManagerReadArgs this_ptr_conv;
9464         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9465         this_ptr_conv.is_owned = false;
9466         long ret_ret = (long)ChannelManagerReadArgs_get_logger(&this_ptr_conv);
9467         return ret_ret;
9468 }
9469
9470 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelManagerReadArgs_1set_1logger(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
9471         LDKChannelManagerReadArgs this_ptr_conv;
9472         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9473         this_ptr_conv.is_owned = false;
9474         LDKLogger val_conv = *(LDKLogger*)val;
9475         if (val_conv.free == LDKLogger_JCalls_free) {
9476                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
9477                 LDKLogger_JCalls_clone(val_conv.this_arg);
9478         }
9479         ChannelManagerReadArgs_set_logger(&this_ptr_conv, val_conv);
9480 }
9481
9482 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelManagerReadArgs_1get_1default_1config(JNIEnv *env, jclass clz, int64_t this_ptr) {
9483         LDKChannelManagerReadArgs this_ptr_conv;
9484         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9485         this_ptr_conv.is_owned = false;
9486         LDKUserConfig ret_var = ChannelManagerReadArgs_get_default_config(&this_ptr_conv);
9487         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9488         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9489         long ret_ref = (long)ret_var.inner;
9490         if (ret_var.is_owned) {
9491                 ret_ref |= 1;
9492         }
9493         return ret_ref;
9494 }
9495
9496 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelManagerReadArgs_1set_1default_1config(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
9497         LDKChannelManagerReadArgs this_ptr_conv;
9498         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9499         this_ptr_conv.is_owned = false;
9500         LDKUserConfig val_conv;
9501         val_conv.inner = (void*)(val & (~1));
9502         val_conv.is_owned = (val & 1) || (val == 0);
9503         if (val_conv.inner != NULL)
9504                 val_conv = UserConfig_clone(&val_conv);
9505         ChannelManagerReadArgs_set_default_config(&this_ptr_conv, val_conv);
9506 }
9507
9508 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) {
9509         LDKKeysInterface keys_manager_conv = *(LDKKeysInterface*)keys_manager;
9510         if (keys_manager_conv.free == LDKKeysInterface_JCalls_free) {
9511                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
9512                 LDKKeysInterface_JCalls_clone(keys_manager_conv.this_arg);
9513         }
9514         LDKFeeEstimator fee_estimator_conv = *(LDKFeeEstimator*)fee_estimator;
9515         if (fee_estimator_conv.free == LDKFeeEstimator_JCalls_free) {
9516                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
9517                 LDKFeeEstimator_JCalls_clone(fee_estimator_conv.this_arg);
9518         }
9519         LDKWatch chain_monitor_conv = *(LDKWatch*)chain_monitor;
9520         if (chain_monitor_conv.free == LDKWatch_JCalls_free) {
9521                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
9522                 LDKWatch_JCalls_clone(chain_monitor_conv.this_arg);
9523         }
9524         LDKBroadcasterInterface tx_broadcaster_conv = *(LDKBroadcasterInterface*)tx_broadcaster;
9525         if (tx_broadcaster_conv.free == LDKBroadcasterInterface_JCalls_free) {
9526                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
9527                 LDKBroadcasterInterface_JCalls_clone(tx_broadcaster_conv.this_arg);
9528         }
9529         LDKLogger logger_conv = *(LDKLogger*)logger;
9530         if (logger_conv.free == LDKLogger_JCalls_free) {
9531                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
9532                 LDKLogger_JCalls_clone(logger_conv.this_arg);
9533         }
9534         LDKUserConfig default_config_conv;
9535         default_config_conv.inner = (void*)(default_config & (~1));
9536         default_config_conv.is_owned = (default_config & 1) || (default_config == 0);
9537         if (default_config_conv.inner != NULL)
9538                 default_config_conv = UserConfig_clone(&default_config_conv);
9539         LDKCVec_ChannelMonitorZ channel_monitors_constr;
9540         channel_monitors_constr.datalen = (*env)->GetArrayLength(env, channel_monitors);
9541         if (channel_monitors_constr.datalen > 0)
9542                 channel_monitors_constr.data = MALLOC(channel_monitors_constr.datalen * sizeof(LDKChannelMonitor), "LDKCVec_ChannelMonitorZ Elements");
9543         else
9544                 channel_monitors_constr.data = NULL;
9545         int64_t* channel_monitors_vals = (*env)->GetLongArrayElements (env, channel_monitors, NULL);
9546         for (size_t q = 0; q < channel_monitors_constr.datalen; q++) {
9547                 int64_t arr_conv_16 = channel_monitors_vals[q];
9548                 LDKChannelMonitor arr_conv_16_conv;
9549                 arr_conv_16_conv.inner = (void*)(arr_conv_16 & (~1));
9550                 arr_conv_16_conv.is_owned = (arr_conv_16 & 1) || (arr_conv_16 == 0);
9551                 // Warning: we may need a move here but can't clone!
9552                 channel_monitors_constr.data[q] = arr_conv_16_conv;
9553         }
9554         (*env)->ReleaseLongArrayElements(env, channel_monitors, channel_monitors_vals, 0);
9555         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);
9556         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9557         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9558         long ret_ref = (long)ret_var.inner;
9559         if (ret_var.is_owned) {
9560                 ret_ref |= 1;
9561         }
9562         return ret_ref;
9563 }
9564
9565 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_C2Tuple_1BlockHashChannelManagerZ_1read(JNIEnv *env, jclass clz, int8_tArray ser, int64_t arg) {
9566         LDKu8slice ser_ref;
9567         ser_ref.datalen = (*env)->GetArrayLength(env, ser);
9568         ser_ref.data = (*env)->GetByteArrayElements (env, ser, NULL);
9569         LDKChannelManagerReadArgs arg_conv;
9570         arg_conv.inner = (void*)(arg & (~1));
9571         arg_conv.is_owned = (arg & 1) || (arg == 0);
9572         // Warning: we may need a move here but can't clone!
9573         LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ), "LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ");
9574         *ret_conv = C2Tuple_BlockHashChannelManagerZ_read(ser_ref, arg_conv);
9575         (*env)->ReleaseByteArrayElements(env, ser, (int8_t*)ser_ref.data, 0);
9576         return (long)ret_conv;
9577 }
9578
9579 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_DecodeError_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
9580         LDKDecodeError this_ptr_conv;
9581         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9582         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9583         DecodeError_free(this_ptr_conv);
9584 }
9585
9586 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Init_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
9587         LDKInit this_ptr_conv;
9588         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9589         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9590         Init_free(this_ptr_conv);
9591 }
9592
9593 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_Init_1clone(JNIEnv *env, jclass clz, int64_t orig) {
9594         LDKInit orig_conv;
9595         orig_conv.inner = (void*)(orig & (~1));
9596         orig_conv.is_owned = false;
9597         LDKInit ret_var = Init_clone(&orig_conv);
9598         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9599         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9600         long ret_ref = (long)ret_var.inner;
9601         if (ret_var.is_owned) {
9602                 ret_ref |= 1;
9603         }
9604         return ret_ref;
9605 }
9606
9607 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ErrorMessage_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
9608         LDKErrorMessage this_ptr_conv;
9609         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9610         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9611         ErrorMessage_free(this_ptr_conv);
9612 }
9613
9614 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ErrorMessage_1clone(JNIEnv *env, jclass clz, int64_t orig) {
9615         LDKErrorMessage orig_conv;
9616         orig_conv.inner = (void*)(orig & (~1));
9617         orig_conv.is_owned = false;
9618         LDKErrorMessage ret_var = ErrorMessage_clone(&orig_conv);
9619         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9620         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9621         long ret_ref = (long)ret_var.inner;
9622         if (ret_var.is_owned) {
9623                 ret_ref |= 1;
9624         }
9625         return ret_ref;
9626 }
9627
9628 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_ErrorMessage_1get_1channel_1id(JNIEnv *env, jclass clz, int64_t this_ptr) {
9629         LDKErrorMessage this_ptr_conv;
9630         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9631         this_ptr_conv.is_owned = false;
9632         int8_tArray ret_arr = (*env)->NewByteArray(env, 32);
9633         (*env)->SetByteArrayRegion(env, ret_arr, 0, 32, *ErrorMessage_get_channel_id(&this_ptr_conv));
9634         return ret_arr;
9635 }
9636
9637 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ErrorMessage_1set_1channel_1id(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
9638         LDKErrorMessage this_ptr_conv;
9639         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9640         this_ptr_conv.is_owned = false;
9641         LDKThirtyTwoBytes val_ref;
9642         CHECK((*env)->GetArrayLength(env, val) == 32);
9643         (*env)->GetByteArrayRegion(env, val, 0, 32, val_ref.data);
9644         ErrorMessage_set_channel_id(&this_ptr_conv, val_ref);
9645 }
9646
9647 JNIEXPORT jstring JNICALL Java_org_ldk_impl_bindings_ErrorMessage_1get_1data(JNIEnv *env, jclass clz, int64_t this_ptr) {
9648         LDKErrorMessage this_ptr_conv;
9649         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9650         this_ptr_conv.is_owned = false;
9651         LDKStr _str = ErrorMessage_get_data(&this_ptr_conv);
9652         char* _buf = MALLOC(_str.len + 1, "str conv buf");
9653         memcpy(_buf, _str.chars, _str.len);
9654         _buf[_str.len] = 0;
9655         jstring _conv = (*env)->NewStringUTF(env, _str.chars);
9656         FREE(_buf);
9657         return _conv;
9658 }
9659
9660 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ErrorMessage_1set_1data(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
9661         LDKErrorMessage this_ptr_conv;
9662         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9663         this_ptr_conv.is_owned = false;
9664         LDKCVec_u8Z val_ref;
9665         val_ref.datalen = (*env)->GetArrayLength(env, val);
9666         val_ref.data = MALLOC(val_ref.datalen, "LDKCVec_u8Z Bytes");
9667         (*env)->GetByteArrayRegion(env, val, 0, val_ref.datalen, val_ref.data);
9668         ErrorMessage_set_data(&this_ptr_conv, val_ref);
9669 }
9670
9671 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ErrorMessage_1new(JNIEnv *env, jclass clz, int8_tArray channel_id_arg, int8_tArray data_arg) {
9672         LDKThirtyTwoBytes channel_id_arg_ref;
9673         CHECK((*env)->GetArrayLength(env, channel_id_arg) == 32);
9674         (*env)->GetByteArrayRegion(env, channel_id_arg, 0, 32, channel_id_arg_ref.data);
9675         LDKCVec_u8Z data_arg_ref;
9676         data_arg_ref.datalen = (*env)->GetArrayLength(env, data_arg);
9677         data_arg_ref.data = MALLOC(data_arg_ref.datalen, "LDKCVec_u8Z Bytes");
9678         (*env)->GetByteArrayRegion(env, data_arg, 0, data_arg_ref.datalen, data_arg_ref.data);
9679         LDKErrorMessage ret_var = ErrorMessage_new(channel_id_arg_ref, data_arg_ref);
9680         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9681         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9682         long ret_ref = (long)ret_var.inner;
9683         if (ret_var.is_owned) {
9684                 ret_ref |= 1;
9685         }
9686         return ret_ref;
9687 }
9688
9689 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Ping_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
9690         LDKPing this_ptr_conv;
9691         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9692         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9693         Ping_free(this_ptr_conv);
9694 }
9695
9696 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_Ping_1clone(JNIEnv *env, jclass clz, int64_t orig) {
9697         LDKPing orig_conv;
9698         orig_conv.inner = (void*)(orig & (~1));
9699         orig_conv.is_owned = false;
9700         LDKPing ret_var = Ping_clone(&orig_conv);
9701         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9702         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9703         long ret_ref = (long)ret_var.inner;
9704         if (ret_var.is_owned) {
9705                 ret_ref |= 1;
9706         }
9707         return ret_ref;
9708 }
9709
9710 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_Ping_1get_1ponglen(JNIEnv *env, jclass clz, int64_t this_ptr) {
9711         LDKPing this_ptr_conv;
9712         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9713         this_ptr_conv.is_owned = false;
9714         jshort ret_val = Ping_get_ponglen(&this_ptr_conv);
9715         return ret_val;
9716 }
9717
9718 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Ping_1set_1ponglen(JNIEnv *env, jclass clz, int64_t this_ptr, jshort val) {
9719         LDKPing this_ptr_conv;
9720         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9721         this_ptr_conv.is_owned = false;
9722         Ping_set_ponglen(&this_ptr_conv, val);
9723 }
9724
9725 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_Ping_1get_1byteslen(JNIEnv *env, jclass clz, int64_t this_ptr) {
9726         LDKPing this_ptr_conv;
9727         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9728         this_ptr_conv.is_owned = false;
9729         jshort ret_val = Ping_get_byteslen(&this_ptr_conv);
9730         return ret_val;
9731 }
9732
9733 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Ping_1set_1byteslen(JNIEnv *env, jclass clz, int64_t this_ptr, jshort val) {
9734         LDKPing this_ptr_conv;
9735         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9736         this_ptr_conv.is_owned = false;
9737         Ping_set_byteslen(&this_ptr_conv, val);
9738 }
9739
9740 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_Ping_1new(JNIEnv *env, jclass clz, jshort ponglen_arg, jshort byteslen_arg) {
9741         LDKPing ret_var = Ping_new(ponglen_arg, byteslen_arg);
9742         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9743         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9744         long ret_ref = (long)ret_var.inner;
9745         if (ret_var.is_owned) {
9746                 ret_ref |= 1;
9747         }
9748         return ret_ref;
9749 }
9750
9751 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Pong_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
9752         LDKPong this_ptr_conv;
9753         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9754         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9755         Pong_free(this_ptr_conv);
9756 }
9757
9758 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_Pong_1clone(JNIEnv *env, jclass clz, int64_t orig) {
9759         LDKPong orig_conv;
9760         orig_conv.inner = (void*)(orig & (~1));
9761         orig_conv.is_owned = false;
9762         LDKPong ret_var = Pong_clone(&orig_conv);
9763         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9764         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9765         long ret_ref = (long)ret_var.inner;
9766         if (ret_var.is_owned) {
9767                 ret_ref |= 1;
9768         }
9769         return ret_ref;
9770 }
9771
9772 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_Pong_1get_1byteslen(JNIEnv *env, jclass clz, int64_t this_ptr) {
9773         LDKPong this_ptr_conv;
9774         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9775         this_ptr_conv.is_owned = false;
9776         jshort ret_val = Pong_get_byteslen(&this_ptr_conv);
9777         return ret_val;
9778 }
9779
9780 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Pong_1set_1byteslen(JNIEnv *env, jclass clz, int64_t this_ptr, jshort val) {
9781         LDKPong this_ptr_conv;
9782         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9783         this_ptr_conv.is_owned = false;
9784         Pong_set_byteslen(&this_ptr_conv, val);
9785 }
9786
9787 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_Pong_1new(JNIEnv *env, jclass clz, jshort byteslen_arg) {
9788         LDKPong ret_var = Pong_new(byteslen_arg);
9789         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9790         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9791         long ret_ref = (long)ret_var.inner;
9792         if (ret_var.is_owned) {
9793                 ret_ref |= 1;
9794         }
9795         return ret_ref;
9796 }
9797
9798 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
9799         LDKOpenChannel this_ptr_conv;
9800         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9801         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9802         OpenChannel_free(this_ptr_conv);
9803 }
9804
9805 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_OpenChannel_1clone(JNIEnv *env, jclass clz, int64_t orig) {
9806         LDKOpenChannel orig_conv;
9807         orig_conv.inner = (void*)(orig & (~1));
9808         orig_conv.is_owned = false;
9809         LDKOpenChannel ret_var = OpenChannel_clone(&orig_conv);
9810         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9811         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9812         long ret_ref = (long)ret_var.inner;
9813         if (ret_var.is_owned) {
9814                 ret_ref |= 1;
9815         }
9816         return ret_ref;
9817 }
9818
9819 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1chain_1hash(JNIEnv *env, jclass clz, int64_t this_ptr) {
9820         LDKOpenChannel this_ptr_conv;
9821         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9822         this_ptr_conv.is_owned = false;
9823         int8_tArray ret_arr = (*env)->NewByteArray(env, 32);
9824         (*env)->SetByteArrayRegion(env, ret_arr, 0, 32, *OpenChannel_get_chain_hash(&this_ptr_conv));
9825         return ret_arr;
9826 }
9827
9828 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1chain_1hash(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
9829         LDKOpenChannel this_ptr_conv;
9830         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9831         this_ptr_conv.is_owned = false;
9832         LDKThirtyTwoBytes val_ref;
9833         CHECK((*env)->GetArrayLength(env, val) == 32);
9834         (*env)->GetByteArrayRegion(env, val, 0, 32, val_ref.data);
9835         OpenChannel_set_chain_hash(&this_ptr_conv, val_ref);
9836 }
9837
9838 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1temporary_1channel_1id(JNIEnv *env, jclass clz, int64_t this_ptr) {
9839         LDKOpenChannel this_ptr_conv;
9840         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9841         this_ptr_conv.is_owned = false;
9842         int8_tArray ret_arr = (*env)->NewByteArray(env, 32);
9843         (*env)->SetByteArrayRegion(env, ret_arr, 0, 32, *OpenChannel_get_temporary_channel_id(&this_ptr_conv));
9844         return ret_arr;
9845 }
9846
9847 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1temporary_1channel_1id(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
9848         LDKOpenChannel this_ptr_conv;
9849         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9850         this_ptr_conv.is_owned = false;
9851         LDKThirtyTwoBytes val_ref;
9852         CHECK((*env)->GetArrayLength(env, val) == 32);
9853         (*env)->GetByteArrayRegion(env, val, 0, 32, val_ref.data);
9854         OpenChannel_set_temporary_channel_id(&this_ptr_conv, val_ref);
9855 }
9856
9857 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1funding_1satoshis(JNIEnv *env, jclass clz, int64_t this_ptr) {
9858         LDKOpenChannel this_ptr_conv;
9859         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9860         this_ptr_conv.is_owned = false;
9861         int64_t ret_val = OpenChannel_get_funding_satoshis(&this_ptr_conv);
9862         return ret_val;
9863 }
9864
9865 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1funding_1satoshis(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
9866         LDKOpenChannel this_ptr_conv;
9867         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9868         this_ptr_conv.is_owned = false;
9869         OpenChannel_set_funding_satoshis(&this_ptr_conv, val);
9870 }
9871
9872 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1push_1msat(JNIEnv *env, jclass clz, int64_t this_ptr) {
9873         LDKOpenChannel this_ptr_conv;
9874         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9875         this_ptr_conv.is_owned = false;
9876         int64_t ret_val = OpenChannel_get_push_msat(&this_ptr_conv);
9877         return ret_val;
9878 }
9879
9880 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1push_1msat(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
9881         LDKOpenChannel this_ptr_conv;
9882         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9883         this_ptr_conv.is_owned = false;
9884         OpenChannel_set_push_msat(&this_ptr_conv, val);
9885 }
9886
9887 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1dust_1limit_1satoshis(JNIEnv *env, jclass clz, int64_t this_ptr) {
9888         LDKOpenChannel this_ptr_conv;
9889         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9890         this_ptr_conv.is_owned = false;
9891         int64_t ret_val = OpenChannel_get_dust_limit_satoshis(&this_ptr_conv);
9892         return ret_val;
9893 }
9894
9895 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1dust_1limit_1satoshis(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
9896         LDKOpenChannel this_ptr_conv;
9897         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9898         this_ptr_conv.is_owned = false;
9899         OpenChannel_set_dust_limit_satoshis(&this_ptr_conv, val);
9900 }
9901
9902 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) {
9903         LDKOpenChannel this_ptr_conv;
9904         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9905         this_ptr_conv.is_owned = false;
9906         int64_t ret_val = OpenChannel_get_max_htlc_value_in_flight_msat(&this_ptr_conv);
9907         return ret_val;
9908 }
9909
9910 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) {
9911         LDKOpenChannel this_ptr_conv;
9912         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9913         this_ptr_conv.is_owned = false;
9914         OpenChannel_set_max_htlc_value_in_flight_msat(&this_ptr_conv, val);
9915 }
9916
9917 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1channel_1reserve_1satoshis(JNIEnv *env, jclass clz, int64_t this_ptr) {
9918         LDKOpenChannel this_ptr_conv;
9919         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9920         this_ptr_conv.is_owned = false;
9921         int64_t ret_val = OpenChannel_get_channel_reserve_satoshis(&this_ptr_conv);
9922         return ret_val;
9923 }
9924
9925 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1channel_1reserve_1satoshis(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
9926         LDKOpenChannel this_ptr_conv;
9927         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9928         this_ptr_conv.is_owned = false;
9929         OpenChannel_set_channel_reserve_satoshis(&this_ptr_conv, val);
9930 }
9931
9932 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1htlc_1minimum_1msat(JNIEnv *env, jclass clz, int64_t this_ptr) {
9933         LDKOpenChannel this_ptr_conv;
9934         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9935         this_ptr_conv.is_owned = false;
9936         int64_t ret_val = OpenChannel_get_htlc_minimum_msat(&this_ptr_conv);
9937         return ret_val;
9938 }
9939
9940 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1htlc_1minimum_1msat(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
9941         LDKOpenChannel this_ptr_conv;
9942         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9943         this_ptr_conv.is_owned = false;
9944         OpenChannel_set_htlc_minimum_msat(&this_ptr_conv, val);
9945 }
9946
9947 JNIEXPORT int32_t JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1feerate_1per_1kw(JNIEnv *env, jclass clz, int64_t this_ptr) {
9948         LDKOpenChannel this_ptr_conv;
9949         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9950         this_ptr_conv.is_owned = false;
9951         int32_t ret_val = OpenChannel_get_feerate_per_kw(&this_ptr_conv);
9952         return ret_val;
9953 }
9954
9955 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1feerate_1per_1kw(JNIEnv *env, jclass clz, int64_t this_ptr, int32_t val) {
9956         LDKOpenChannel this_ptr_conv;
9957         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9958         this_ptr_conv.is_owned = false;
9959         OpenChannel_set_feerate_per_kw(&this_ptr_conv, val);
9960 }
9961
9962 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1to_1self_1delay(JNIEnv *env, jclass clz, int64_t this_ptr) {
9963         LDKOpenChannel this_ptr_conv;
9964         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9965         this_ptr_conv.is_owned = false;
9966         jshort ret_val = OpenChannel_get_to_self_delay(&this_ptr_conv);
9967         return ret_val;
9968 }
9969
9970 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1to_1self_1delay(JNIEnv *env, jclass clz, int64_t this_ptr, jshort val) {
9971         LDKOpenChannel this_ptr_conv;
9972         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9973         this_ptr_conv.is_owned = false;
9974         OpenChannel_set_to_self_delay(&this_ptr_conv, val);
9975 }
9976
9977 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1max_1accepted_1htlcs(JNIEnv *env, jclass clz, int64_t this_ptr) {
9978         LDKOpenChannel this_ptr_conv;
9979         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9980         this_ptr_conv.is_owned = false;
9981         jshort ret_val = OpenChannel_get_max_accepted_htlcs(&this_ptr_conv);
9982         return ret_val;
9983 }
9984
9985 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1max_1accepted_1htlcs(JNIEnv *env, jclass clz, int64_t this_ptr, jshort val) {
9986         LDKOpenChannel this_ptr_conv;
9987         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9988         this_ptr_conv.is_owned = false;
9989         OpenChannel_set_max_accepted_htlcs(&this_ptr_conv, val);
9990 }
9991
9992 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1funding_1pubkey(JNIEnv *env, jclass clz, int64_t this_ptr) {
9993         LDKOpenChannel this_ptr_conv;
9994         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9995         this_ptr_conv.is_owned = false;
9996         int8_tArray arg_arr = (*env)->NewByteArray(env, 33);
9997         (*env)->SetByteArrayRegion(env, arg_arr, 0, 33, OpenChannel_get_funding_pubkey(&this_ptr_conv).compressed_form);
9998         return arg_arr;
9999 }
10000
10001 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1funding_1pubkey(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
10002         LDKOpenChannel this_ptr_conv;
10003         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10004         this_ptr_conv.is_owned = false;
10005         LDKPublicKey val_ref;
10006         CHECK((*env)->GetArrayLength(env, val) == 33);
10007         (*env)->GetByteArrayRegion(env, val, 0, 33, val_ref.compressed_form);
10008         OpenChannel_set_funding_pubkey(&this_ptr_conv, val_ref);
10009 }
10010
10011 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1revocation_1basepoint(JNIEnv *env, jclass clz, int64_t this_ptr) {
10012         LDKOpenChannel this_ptr_conv;
10013         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10014         this_ptr_conv.is_owned = false;
10015         int8_tArray arg_arr = (*env)->NewByteArray(env, 33);
10016         (*env)->SetByteArrayRegion(env, arg_arr, 0, 33, OpenChannel_get_revocation_basepoint(&this_ptr_conv).compressed_form);
10017         return arg_arr;
10018 }
10019
10020 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1revocation_1basepoint(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
10021         LDKOpenChannel this_ptr_conv;
10022         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10023         this_ptr_conv.is_owned = false;
10024         LDKPublicKey val_ref;
10025         CHECK((*env)->GetArrayLength(env, val) == 33);
10026         (*env)->GetByteArrayRegion(env, val, 0, 33, val_ref.compressed_form);
10027         OpenChannel_set_revocation_basepoint(&this_ptr_conv, val_ref);
10028 }
10029
10030 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1payment_1point(JNIEnv *env, jclass clz, int64_t this_ptr) {
10031         LDKOpenChannel this_ptr_conv;
10032         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10033         this_ptr_conv.is_owned = false;
10034         int8_tArray arg_arr = (*env)->NewByteArray(env, 33);
10035         (*env)->SetByteArrayRegion(env, arg_arr, 0, 33, OpenChannel_get_payment_point(&this_ptr_conv).compressed_form);
10036         return arg_arr;
10037 }
10038
10039 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1payment_1point(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
10040         LDKOpenChannel this_ptr_conv;
10041         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10042         this_ptr_conv.is_owned = false;
10043         LDKPublicKey val_ref;
10044         CHECK((*env)->GetArrayLength(env, val) == 33);
10045         (*env)->GetByteArrayRegion(env, val, 0, 33, val_ref.compressed_form);
10046         OpenChannel_set_payment_point(&this_ptr_conv, val_ref);
10047 }
10048
10049 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1delayed_1payment_1basepoint(JNIEnv *env, jclass clz, int64_t this_ptr) {
10050         LDKOpenChannel this_ptr_conv;
10051         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10052         this_ptr_conv.is_owned = false;
10053         int8_tArray arg_arr = (*env)->NewByteArray(env, 33);
10054         (*env)->SetByteArrayRegion(env, arg_arr, 0, 33, OpenChannel_get_delayed_payment_basepoint(&this_ptr_conv).compressed_form);
10055         return arg_arr;
10056 }
10057
10058 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1delayed_1payment_1basepoint(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
10059         LDKOpenChannel this_ptr_conv;
10060         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10061         this_ptr_conv.is_owned = false;
10062         LDKPublicKey val_ref;
10063         CHECK((*env)->GetArrayLength(env, val) == 33);
10064         (*env)->GetByteArrayRegion(env, val, 0, 33, val_ref.compressed_form);
10065         OpenChannel_set_delayed_payment_basepoint(&this_ptr_conv, val_ref);
10066 }
10067
10068 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1htlc_1basepoint(JNIEnv *env, jclass clz, int64_t this_ptr) {
10069         LDKOpenChannel this_ptr_conv;
10070         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10071         this_ptr_conv.is_owned = false;
10072         int8_tArray arg_arr = (*env)->NewByteArray(env, 33);
10073         (*env)->SetByteArrayRegion(env, arg_arr, 0, 33, OpenChannel_get_htlc_basepoint(&this_ptr_conv).compressed_form);
10074         return arg_arr;
10075 }
10076
10077 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1htlc_1basepoint(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
10078         LDKOpenChannel this_ptr_conv;
10079         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10080         this_ptr_conv.is_owned = false;
10081         LDKPublicKey val_ref;
10082         CHECK((*env)->GetArrayLength(env, val) == 33);
10083         (*env)->GetByteArrayRegion(env, val, 0, 33, val_ref.compressed_form);
10084         OpenChannel_set_htlc_basepoint(&this_ptr_conv, val_ref);
10085 }
10086
10087 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1first_1per_1commitment_1point(JNIEnv *env, jclass clz, int64_t this_ptr) {
10088         LDKOpenChannel this_ptr_conv;
10089         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10090         this_ptr_conv.is_owned = false;
10091         int8_tArray arg_arr = (*env)->NewByteArray(env, 33);
10092         (*env)->SetByteArrayRegion(env, arg_arr, 0, 33, OpenChannel_get_first_per_commitment_point(&this_ptr_conv).compressed_form);
10093         return arg_arr;
10094 }
10095
10096 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) {
10097         LDKOpenChannel this_ptr_conv;
10098         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10099         this_ptr_conv.is_owned = false;
10100         LDKPublicKey val_ref;
10101         CHECK((*env)->GetArrayLength(env, val) == 33);
10102         (*env)->GetByteArrayRegion(env, val, 0, 33, val_ref.compressed_form);
10103         OpenChannel_set_first_per_commitment_point(&this_ptr_conv, val_ref);
10104 }
10105
10106 JNIEXPORT int8_t JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1channel_1flags(JNIEnv *env, jclass clz, int64_t this_ptr) {
10107         LDKOpenChannel this_ptr_conv;
10108         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10109         this_ptr_conv.is_owned = false;
10110         int8_t ret_val = OpenChannel_get_channel_flags(&this_ptr_conv);
10111         return ret_val;
10112 }
10113
10114 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1channel_1flags(JNIEnv *env, jclass clz, int64_t this_ptr, int8_t val) {
10115         LDKOpenChannel this_ptr_conv;
10116         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10117         this_ptr_conv.is_owned = false;
10118         OpenChannel_set_channel_flags(&this_ptr_conv, val);
10119 }
10120
10121 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
10122         LDKAcceptChannel this_ptr_conv;
10123         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10124         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10125         AcceptChannel_free(this_ptr_conv);
10126 }
10127
10128 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1clone(JNIEnv *env, jclass clz, int64_t orig) {
10129         LDKAcceptChannel orig_conv;
10130         orig_conv.inner = (void*)(orig & (~1));
10131         orig_conv.is_owned = false;
10132         LDKAcceptChannel ret_var = AcceptChannel_clone(&orig_conv);
10133         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10134         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10135         long ret_ref = (long)ret_var.inner;
10136         if (ret_var.is_owned) {
10137                 ret_ref |= 1;
10138         }
10139         return ret_ref;
10140 }
10141
10142 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1get_1temporary_1channel_1id(JNIEnv *env, jclass clz, int64_t this_ptr) {
10143         LDKAcceptChannel this_ptr_conv;
10144         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10145         this_ptr_conv.is_owned = false;
10146         int8_tArray ret_arr = (*env)->NewByteArray(env, 32);
10147         (*env)->SetByteArrayRegion(env, ret_arr, 0, 32, *AcceptChannel_get_temporary_channel_id(&this_ptr_conv));
10148         return ret_arr;
10149 }
10150
10151 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1set_1temporary_1channel_1id(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
10152         LDKAcceptChannel this_ptr_conv;
10153         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10154         this_ptr_conv.is_owned = false;
10155         LDKThirtyTwoBytes val_ref;
10156         CHECK((*env)->GetArrayLength(env, val) == 32);
10157         (*env)->GetByteArrayRegion(env, val, 0, 32, val_ref.data);
10158         AcceptChannel_set_temporary_channel_id(&this_ptr_conv, val_ref);
10159 }
10160
10161 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1get_1dust_1limit_1satoshis(JNIEnv *env, jclass clz, int64_t this_ptr) {
10162         LDKAcceptChannel this_ptr_conv;
10163         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10164         this_ptr_conv.is_owned = false;
10165         int64_t ret_val = AcceptChannel_get_dust_limit_satoshis(&this_ptr_conv);
10166         return ret_val;
10167 }
10168
10169 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1set_1dust_1limit_1satoshis(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
10170         LDKAcceptChannel this_ptr_conv;
10171         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10172         this_ptr_conv.is_owned = false;
10173         AcceptChannel_set_dust_limit_satoshis(&this_ptr_conv, val);
10174 }
10175
10176 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) {
10177         LDKAcceptChannel this_ptr_conv;
10178         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10179         this_ptr_conv.is_owned = false;
10180         int64_t ret_val = AcceptChannel_get_max_htlc_value_in_flight_msat(&this_ptr_conv);
10181         return ret_val;
10182 }
10183
10184 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) {
10185         LDKAcceptChannel this_ptr_conv;
10186         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10187         this_ptr_conv.is_owned = false;
10188         AcceptChannel_set_max_htlc_value_in_flight_msat(&this_ptr_conv, val);
10189 }
10190
10191 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1get_1channel_1reserve_1satoshis(JNIEnv *env, jclass clz, int64_t this_ptr) {
10192         LDKAcceptChannel this_ptr_conv;
10193         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10194         this_ptr_conv.is_owned = false;
10195         int64_t ret_val = AcceptChannel_get_channel_reserve_satoshis(&this_ptr_conv);
10196         return ret_val;
10197 }
10198
10199 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1set_1channel_1reserve_1satoshis(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
10200         LDKAcceptChannel this_ptr_conv;
10201         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10202         this_ptr_conv.is_owned = false;
10203         AcceptChannel_set_channel_reserve_satoshis(&this_ptr_conv, val);
10204 }
10205
10206 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1get_1htlc_1minimum_1msat(JNIEnv *env, jclass clz, int64_t this_ptr) {
10207         LDKAcceptChannel this_ptr_conv;
10208         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10209         this_ptr_conv.is_owned = false;
10210         int64_t ret_val = AcceptChannel_get_htlc_minimum_msat(&this_ptr_conv);
10211         return ret_val;
10212 }
10213
10214 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1set_1htlc_1minimum_1msat(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
10215         LDKAcceptChannel this_ptr_conv;
10216         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10217         this_ptr_conv.is_owned = false;
10218         AcceptChannel_set_htlc_minimum_msat(&this_ptr_conv, val);
10219 }
10220
10221 JNIEXPORT int32_t JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1get_1minimum_1depth(JNIEnv *env, jclass clz, int64_t this_ptr) {
10222         LDKAcceptChannel this_ptr_conv;
10223         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10224         this_ptr_conv.is_owned = false;
10225         int32_t ret_val = AcceptChannel_get_minimum_depth(&this_ptr_conv);
10226         return ret_val;
10227 }
10228
10229 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1set_1minimum_1depth(JNIEnv *env, jclass clz, int64_t this_ptr, int32_t val) {
10230         LDKAcceptChannel this_ptr_conv;
10231         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10232         this_ptr_conv.is_owned = false;
10233         AcceptChannel_set_minimum_depth(&this_ptr_conv, val);
10234 }
10235
10236 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1get_1to_1self_1delay(JNIEnv *env, jclass clz, int64_t this_ptr) {
10237         LDKAcceptChannel this_ptr_conv;
10238         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10239         this_ptr_conv.is_owned = false;
10240         jshort ret_val = AcceptChannel_get_to_self_delay(&this_ptr_conv);
10241         return ret_val;
10242 }
10243
10244 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1set_1to_1self_1delay(JNIEnv *env, jclass clz, int64_t this_ptr, jshort val) {
10245         LDKAcceptChannel this_ptr_conv;
10246         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10247         this_ptr_conv.is_owned = false;
10248         AcceptChannel_set_to_self_delay(&this_ptr_conv, val);
10249 }
10250
10251 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1get_1max_1accepted_1htlcs(JNIEnv *env, jclass clz, int64_t this_ptr) {
10252         LDKAcceptChannel this_ptr_conv;
10253         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10254         this_ptr_conv.is_owned = false;
10255         jshort ret_val = AcceptChannel_get_max_accepted_htlcs(&this_ptr_conv);
10256         return ret_val;
10257 }
10258
10259 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1set_1max_1accepted_1htlcs(JNIEnv *env, jclass clz, int64_t this_ptr, jshort val) {
10260         LDKAcceptChannel this_ptr_conv;
10261         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10262         this_ptr_conv.is_owned = false;
10263         AcceptChannel_set_max_accepted_htlcs(&this_ptr_conv, val);
10264 }
10265
10266 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1get_1funding_1pubkey(JNIEnv *env, jclass clz, int64_t this_ptr) {
10267         LDKAcceptChannel this_ptr_conv;
10268         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10269         this_ptr_conv.is_owned = false;
10270         int8_tArray arg_arr = (*env)->NewByteArray(env, 33);
10271         (*env)->SetByteArrayRegion(env, arg_arr, 0, 33, AcceptChannel_get_funding_pubkey(&this_ptr_conv).compressed_form);
10272         return arg_arr;
10273 }
10274
10275 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1set_1funding_1pubkey(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
10276         LDKAcceptChannel this_ptr_conv;
10277         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10278         this_ptr_conv.is_owned = false;
10279         LDKPublicKey val_ref;
10280         CHECK((*env)->GetArrayLength(env, val) == 33);
10281         (*env)->GetByteArrayRegion(env, val, 0, 33, val_ref.compressed_form);
10282         AcceptChannel_set_funding_pubkey(&this_ptr_conv, val_ref);
10283 }
10284
10285 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1get_1revocation_1basepoint(JNIEnv *env, jclass clz, int64_t this_ptr) {
10286         LDKAcceptChannel this_ptr_conv;
10287         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10288         this_ptr_conv.is_owned = false;
10289         int8_tArray arg_arr = (*env)->NewByteArray(env, 33);
10290         (*env)->SetByteArrayRegion(env, arg_arr, 0, 33, AcceptChannel_get_revocation_basepoint(&this_ptr_conv).compressed_form);
10291         return arg_arr;
10292 }
10293
10294 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1set_1revocation_1basepoint(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
10295         LDKAcceptChannel this_ptr_conv;
10296         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10297         this_ptr_conv.is_owned = false;
10298         LDKPublicKey val_ref;
10299         CHECK((*env)->GetArrayLength(env, val) == 33);
10300         (*env)->GetByteArrayRegion(env, val, 0, 33, val_ref.compressed_form);
10301         AcceptChannel_set_revocation_basepoint(&this_ptr_conv, val_ref);
10302 }
10303
10304 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1get_1payment_1point(JNIEnv *env, jclass clz, int64_t this_ptr) {
10305         LDKAcceptChannel this_ptr_conv;
10306         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10307         this_ptr_conv.is_owned = false;
10308         int8_tArray arg_arr = (*env)->NewByteArray(env, 33);
10309         (*env)->SetByteArrayRegion(env, arg_arr, 0, 33, AcceptChannel_get_payment_point(&this_ptr_conv).compressed_form);
10310         return arg_arr;
10311 }
10312
10313 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1set_1payment_1point(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
10314         LDKAcceptChannel this_ptr_conv;
10315         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10316         this_ptr_conv.is_owned = false;
10317         LDKPublicKey val_ref;
10318         CHECK((*env)->GetArrayLength(env, val) == 33);
10319         (*env)->GetByteArrayRegion(env, val, 0, 33, val_ref.compressed_form);
10320         AcceptChannel_set_payment_point(&this_ptr_conv, val_ref);
10321 }
10322
10323 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1get_1delayed_1payment_1basepoint(JNIEnv *env, jclass clz, int64_t this_ptr) {
10324         LDKAcceptChannel this_ptr_conv;
10325         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10326         this_ptr_conv.is_owned = false;
10327         int8_tArray arg_arr = (*env)->NewByteArray(env, 33);
10328         (*env)->SetByteArrayRegion(env, arg_arr, 0, 33, AcceptChannel_get_delayed_payment_basepoint(&this_ptr_conv).compressed_form);
10329         return arg_arr;
10330 }
10331
10332 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1set_1delayed_1payment_1basepoint(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
10333         LDKAcceptChannel this_ptr_conv;
10334         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10335         this_ptr_conv.is_owned = false;
10336         LDKPublicKey val_ref;
10337         CHECK((*env)->GetArrayLength(env, val) == 33);
10338         (*env)->GetByteArrayRegion(env, val, 0, 33, val_ref.compressed_form);
10339         AcceptChannel_set_delayed_payment_basepoint(&this_ptr_conv, val_ref);
10340 }
10341
10342 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1get_1htlc_1basepoint(JNIEnv *env, jclass clz, int64_t this_ptr) {
10343         LDKAcceptChannel this_ptr_conv;
10344         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10345         this_ptr_conv.is_owned = false;
10346         int8_tArray arg_arr = (*env)->NewByteArray(env, 33);
10347         (*env)->SetByteArrayRegion(env, arg_arr, 0, 33, AcceptChannel_get_htlc_basepoint(&this_ptr_conv).compressed_form);
10348         return arg_arr;
10349 }
10350
10351 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1set_1htlc_1basepoint(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
10352         LDKAcceptChannel this_ptr_conv;
10353         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10354         this_ptr_conv.is_owned = false;
10355         LDKPublicKey val_ref;
10356         CHECK((*env)->GetArrayLength(env, val) == 33);
10357         (*env)->GetByteArrayRegion(env, val, 0, 33, val_ref.compressed_form);
10358         AcceptChannel_set_htlc_basepoint(&this_ptr_conv, val_ref);
10359 }
10360
10361 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1get_1first_1per_1commitment_1point(JNIEnv *env, jclass clz, int64_t this_ptr) {
10362         LDKAcceptChannel this_ptr_conv;
10363         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10364         this_ptr_conv.is_owned = false;
10365         int8_tArray arg_arr = (*env)->NewByteArray(env, 33);
10366         (*env)->SetByteArrayRegion(env, arg_arr, 0, 33, AcceptChannel_get_first_per_commitment_point(&this_ptr_conv).compressed_form);
10367         return arg_arr;
10368 }
10369
10370 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) {
10371         LDKAcceptChannel this_ptr_conv;
10372         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10373         this_ptr_conv.is_owned = false;
10374         LDKPublicKey val_ref;
10375         CHECK((*env)->GetArrayLength(env, val) == 33);
10376         (*env)->GetByteArrayRegion(env, val, 0, 33, val_ref.compressed_form);
10377         AcceptChannel_set_first_per_commitment_point(&this_ptr_conv, val_ref);
10378 }
10379
10380 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_FundingCreated_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
10381         LDKFundingCreated this_ptr_conv;
10382         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10383         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10384         FundingCreated_free(this_ptr_conv);
10385 }
10386
10387 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_FundingCreated_1clone(JNIEnv *env, jclass clz, int64_t orig) {
10388         LDKFundingCreated orig_conv;
10389         orig_conv.inner = (void*)(orig & (~1));
10390         orig_conv.is_owned = false;
10391         LDKFundingCreated ret_var = FundingCreated_clone(&orig_conv);
10392         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10393         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10394         long ret_ref = (long)ret_var.inner;
10395         if (ret_var.is_owned) {
10396                 ret_ref |= 1;
10397         }
10398         return ret_ref;
10399 }
10400
10401 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_FundingCreated_1get_1temporary_1channel_1id(JNIEnv *env, jclass clz, int64_t this_ptr) {
10402         LDKFundingCreated this_ptr_conv;
10403         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10404         this_ptr_conv.is_owned = false;
10405         int8_tArray ret_arr = (*env)->NewByteArray(env, 32);
10406         (*env)->SetByteArrayRegion(env, ret_arr, 0, 32, *FundingCreated_get_temporary_channel_id(&this_ptr_conv));
10407         return ret_arr;
10408 }
10409
10410 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_FundingCreated_1set_1temporary_1channel_1id(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
10411         LDKFundingCreated this_ptr_conv;
10412         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10413         this_ptr_conv.is_owned = false;
10414         LDKThirtyTwoBytes val_ref;
10415         CHECK((*env)->GetArrayLength(env, val) == 32);
10416         (*env)->GetByteArrayRegion(env, val, 0, 32, val_ref.data);
10417         FundingCreated_set_temporary_channel_id(&this_ptr_conv, val_ref);
10418 }
10419
10420 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_FundingCreated_1get_1funding_1txid(JNIEnv *env, jclass clz, int64_t this_ptr) {
10421         LDKFundingCreated this_ptr_conv;
10422         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10423         this_ptr_conv.is_owned = false;
10424         int8_tArray ret_arr = (*env)->NewByteArray(env, 32);
10425         (*env)->SetByteArrayRegion(env, ret_arr, 0, 32, *FundingCreated_get_funding_txid(&this_ptr_conv));
10426         return ret_arr;
10427 }
10428
10429 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_FundingCreated_1set_1funding_1txid(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
10430         LDKFundingCreated this_ptr_conv;
10431         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10432         this_ptr_conv.is_owned = false;
10433         LDKThirtyTwoBytes val_ref;
10434         CHECK((*env)->GetArrayLength(env, val) == 32);
10435         (*env)->GetByteArrayRegion(env, val, 0, 32, val_ref.data);
10436         FundingCreated_set_funding_txid(&this_ptr_conv, val_ref);
10437 }
10438
10439 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_FundingCreated_1get_1funding_1output_1index(JNIEnv *env, jclass clz, int64_t this_ptr) {
10440         LDKFundingCreated this_ptr_conv;
10441         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10442         this_ptr_conv.is_owned = false;
10443         jshort ret_val = FundingCreated_get_funding_output_index(&this_ptr_conv);
10444         return ret_val;
10445 }
10446
10447 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_FundingCreated_1set_1funding_1output_1index(JNIEnv *env, jclass clz, int64_t this_ptr, jshort val) {
10448         LDKFundingCreated this_ptr_conv;
10449         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10450         this_ptr_conv.is_owned = false;
10451         FundingCreated_set_funding_output_index(&this_ptr_conv, val);
10452 }
10453
10454 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_FundingCreated_1get_1signature(JNIEnv *env, jclass clz, int64_t this_ptr) {
10455         LDKFundingCreated this_ptr_conv;
10456         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10457         this_ptr_conv.is_owned = false;
10458         int8_tArray arg_arr = (*env)->NewByteArray(env, 64);
10459         (*env)->SetByteArrayRegion(env, arg_arr, 0, 64, FundingCreated_get_signature(&this_ptr_conv).compact_form);
10460         return arg_arr;
10461 }
10462
10463 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_FundingCreated_1set_1signature(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
10464         LDKFundingCreated this_ptr_conv;
10465         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10466         this_ptr_conv.is_owned = false;
10467         LDKSignature val_ref;
10468         CHECK((*env)->GetArrayLength(env, val) == 64);
10469         (*env)->GetByteArrayRegion(env, val, 0, 64, val_ref.compact_form);
10470         FundingCreated_set_signature(&this_ptr_conv, val_ref);
10471 }
10472
10473 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, jshort funding_output_index_arg, int8_tArray signature_arg) {
10474         LDKThirtyTwoBytes temporary_channel_id_arg_ref;
10475         CHECK((*env)->GetArrayLength(env, temporary_channel_id_arg) == 32);
10476         (*env)->GetByteArrayRegion(env, temporary_channel_id_arg, 0, 32, temporary_channel_id_arg_ref.data);
10477         LDKThirtyTwoBytes funding_txid_arg_ref;
10478         CHECK((*env)->GetArrayLength(env, funding_txid_arg) == 32);
10479         (*env)->GetByteArrayRegion(env, funding_txid_arg, 0, 32, funding_txid_arg_ref.data);
10480         LDKSignature signature_arg_ref;
10481         CHECK((*env)->GetArrayLength(env, signature_arg) == 64);
10482         (*env)->GetByteArrayRegion(env, signature_arg, 0, 64, signature_arg_ref.compact_form);
10483         LDKFundingCreated ret_var = FundingCreated_new(temporary_channel_id_arg_ref, funding_txid_arg_ref, funding_output_index_arg, signature_arg_ref);
10484         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10485         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10486         long ret_ref = (long)ret_var.inner;
10487         if (ret_var.is_owned) {
10488                 ret_ref |= 1;
10489         }
10490         return ret_ref;
10491 }
10492
10493 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_FundingSigned_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
10494         LDKFundingSigned this_ptr_conv;
10495         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10496         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10497         FundingSigned_free(this_ptr_conv);
10498 }
10499
10500 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_FundingSigned_1clone(JNIEnv *env, jclass clz, int64_t orig) {
10501         LDKFundingSigned orig_conv;
10502         orig_conv.inner = (void*)(orig & (~1));
10503         orig_conv.is_owned = false;
10504         LDKFundingSigned ret_var = FundingSigned_clone(&orig_conv);
10505         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10506         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10507         long ret_ref = (long)ret_var.inner;
10508         if (ret_var.is_owned) {
10509                 ret_ref |= 1;
10510         }
10511         return ret_ref;
10512 }
10513
10514 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_FundingSigned_1get_1channel_1id(JNIEnv *env, jclass clz, int64_t this_ptr) {
10515         LDKFundingSigned this_ptr_conv;
10516         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10517         this_ptr_conv.is_owned = false;
10518         int8_tArray ret_arr = (*env)->NewByteArray(env, 32);
10519         (*env)->SetByteArrayRegion(env, ret_arr, 0, 32, *FundingSigned_get_channel_id(&this_ptr_conv));
10520         return ret_arr;
10521 }
10522
10523 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_FundingSigned_1set_1channel_1id(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
10524         LDKFundingSigned this_ptr_conv;
10525         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10526         this_ptr_conv.is_owned = false;
10527         LDKThirtyTwoBytes val_ref;
10528         CHECK((*env)->GetArrayLength(env, val) == 32);
10529         (*env)->GetByteArrayRegion(env, val, 0, 32, val_ref.data);
10530         FundingSigned_set_channel_id(&this_ptr_conv, val_ref);
10531 }
10532
10533 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_FundingSigned_1get_1signature(JNIEnv *env, jclass clz, int64_t this_ptr) {
10534         LDKFundingSigned this_ptr_conv;
10535         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10536         this_ptr_conv.is_owned = false;
10537         int8_tArray arg_arr = (*env)->NewByteArray(env, 64);
10538         (*env)->SetByteArrayRegion(env, arg_arr, 0, 64, FundingSigned_get_signature(&this_ptr_conv).compact_form);
10539         return arg_arr;
10540 }
10541
10542 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_FundingSigned_1set_1signature(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
10543         LDKFundingSigned this_ptr_conv;
10544         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10545         this_ptr_conv.is_owned = false;
10546         LDKSignature val_ref;
10547         CHECK((*env)->GetArrayLength(env, val) == 64);
10548         (*env)->GetByteArrayRegion(env, val, 0, 64, val_ref.compact_form);
10549         FundingSigned_set_signature(&this_ptr_conv, val_ref);
10550 }
10551
10552 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_FundingSigned_1new(JNIEnv *env, jclass clz, int8_tArray channel_id_arg, int8_tArray signature_arg) {
10553         LDKThirtyTwoBytes channel_id_arg_ref;
10554         CHECK((*env)->GetArrayLength(env, channel_id_arg) == 32);
10555         (*env)->GetByteArrayRegion(env, channel_id_arg, 0, 32, channel_id_arg_ref.data);
10556         LDKSignature signature_arg_ref;
10557         CHECK((*env)->GetArrayLength(env, signature_arg) == 64);
10558         (*env)->GetByteArrayRegion(env, signature_arg, 0, 64, signature_arg_ref.compact_form);
10559         LDKFundingSigned ret_var = FundingSigned_new(channel_id_arg_ref, signature_arg_ref);
10560         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10561         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10562         long ret_ref = (long)ret_var.inner;
10563         if (ret_var.is_owned) {
10564                 ret_ref |= 1;
10565         }
10566         return ret_ref;
10567 }
10568
10569 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_FundingLocked_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
10570         LDKFundingLocked this_ptr_conv;
10571         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10572         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10573         FundingLocked_free(this_ptr_conv);
10574 }
10575
10576 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_FundingLocked_1clone(JNIEnv *env, jclass clz, int64_t orig) {
10577         LDKFundingLocked orig_conv;
10578         orig_conv.inner = (void*)(orig & (~1));
10579         orig_conv.is_owned = false;
10580         LDKFundingLocked ret_var = FundingLocked_clone(&orig_conv);
10581         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10582         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10583         long ret_ref = (long)ret_var.inner;
10584         if (ret_var.is_owned) {
10585                 ret_ref |= 1;
10586         }
10587         return ret_ref;
10588 }
10589
10590 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_FundingLocked_1get_1channel_1id(JNIEnv *env, jclass clz, int64_t this_ptr) {
10591         LDKFundingLocked this_ptr_conv;
10592         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10593         this_ptr_conv.is_owned = false;
10594         int8_tArray ret_arr = (*env)->NewByteArray(env, 32);
10595         (*env)->SetByteArrayRegion(env, ret_arr, 0, 32, *FundingLocked_get_channel_id(&this_ptr_conv));
10596         return ret_arr;
10597 }
10598
10599 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_FundingLocked_1set_1channel_1id(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
10600         LDKFundingLocked this_ptr_conv;
10601         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10602         this_ptr_conv.is_owned = false;
10603         LDKThirtyTwoBytes val_ref;
10604         CHECK((*env)->GetArrayLength(env, val) == 32);
10605         (*env)->GetByteArrayRegion(env, val, 0, 32, val_ref.data);
10606         FundingLocked_set_channel_id(&this_ptr_conv, val_ref);
10607 }
10608
10609 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_FundingLocked_1get_1next_1per_1commitment_1point(JNIEnv *env, jclass clz, int64_t this_ptr) {
10610         LDKFundingLocked this_ptr_conv;
10611         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10612         this_ptr_conv.is_owned = false;
10613         int8_tArray arg_arr = (*env)->NewByteArray(env, 33);
10614         (*env)->SetByteArrayRegion(env, arg_arr, 0, 33, FundingLocked_get_next_per_commitment_point(&this_ptr_conv).compressed_form);
10615         return arg_arr;
10616 }
10617
10618 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) {
10619         LDKFundingLocked this_ptr_conv;
10620         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10621         this_ptr_conv.is_owned = false;
10622         LDKPublicKey val_ref;
10623         CHECK((*env)->GetArrayLength(env, val) == 33);
10624         (*env)->GetByteArrayRegion(env, val, 0, 33, val_ref.compressed_form);
10625         FundingLocked_set_next_per_commitment_point(&this_ptr_conv, val_ref);
10626 }
10627
10628 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) {
10629         LDKThirtyTwoBytes channel_id_arg_ref;
10630         CHECK((*env)->GetArrayLength(env, channel_id_arg) == 32);
10631         (*env)->GetByteArrayRegion(env, channel_id_arg, 0, 32, channel_id_arg_ref.data);
10632         LDKPublicKey next_per_commitment_point_arg_ref;
10633         CHECK((*env)->GetArrayLength(env, next_per_commitment_point_arg) == 33);
10634         (*env)->GetByteArrayRegion(env, next_per_commitment_point_arg, 0, 33, next_per_commitment_point_arg_ref.compressed_form);
10635         LDKFundingLocked ret_var = FundingLocked_new(channel_id_arg_ref, next_per_commitment_point_arg_ref);
10636         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10637         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10638         long ret_ref = (long)ret_var.inner;
10639         if (ret_var.is_owned) {
10640                 ret_ref |= 1;
10641         }
10642         return ret_ref;
10643 }
10644
10645 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Shutdown_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
10646         LDKShutdown this_ptr_conv;
10647         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10648         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10649         Shutdown_free(this_ptr_conv);
10650 }
10651
10652 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_Shutdown_1clone(JNIEnv *env, jclass clz, int64_t orig) {
10653         LDKShutdown orig_conv;
10654         orig_conv.inner = (void*)(orig & (~1));
10655         orig_conv.is_owned = false;
10656         LDKShutdown ret_var = Shutdown_clone(&orig_conv);
10657         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10658         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10659         long ret_ref = (long)ret_var.inner;
10660         if (ret_var.is_owned) {
10661                 ret_ref |= 1;
10662         }
10663         return ret_ref;
10664 }
10665
10666 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_Shutdown_1get_1channel_1id(JNIEnv *env, jclass clz, int64_t this_ptr) {
10667         LDKShutdown this_ptr_conv;
10668         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10669         this_ptr_conv.is_owned = false;
10670         int8_tArray ret_arr = (*env)->NewByteArray(env, 32);
10671         (*env)->SetByteArrayRegion(env, ret_arr, 0, 32, *Shutdown_get_channel_id(&this_ptr_conv));
10672         return ret_arr;
10673 }
10674
10675 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Shutdown_1set_1channel_1id(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
10676         LDKShutdown this_ptr_conv;
10677         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10678         this_ptr_conv.is_owned = false;
10679         LDKThirtyTwoBytes val_ref;
10680         CHECK((*env)->GetArrayLength(env, val) == 32);
10681         (*env)->GetByteArrayRegion(env, val, 0, 32, val_ref.data);
10682         Shutdown_set_channel_id(&this_ptr_conv, val_ref);
10683 }
10684
10685 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_Shutdown_1get_1scriptpubkey(JNIEnv *env, jclass clz, int64_t this_ptr) {
10686         LDKShutdown this_ptr_conv;
10687         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10688         this_ptr_conv.is_owned = false;
10689         LDKu8slice arg_var = Shutdown_get_scriptpubkey(&this_ptr_conv);
10690         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
10691         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
10692         return arg_arr;
10693 }
10694
10695 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Shutdown_1set_1scriptpubkey(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
10696         LDKShutdown this_ptr_conv;
10697         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10698         this_ptr_conv.is_owned = false;
10699         LDKCVec_u8Z val_ref;
10700         val_ref.datalen = (*env)->GetArrayLength(env, val);
10701         val_ref.data = MALLOC(val_ref.datalen, "LDKCVec_u8Z Bytes");
10702         (*env)->GetByteArrayRegion(env, val, 0, val_ref.datalen, val_ref.data);
10703         Shutdown_set_scriptpubkey(&this_ptr_conv, val_ref);
10704 }
10705
10706 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_Shutdown_1new(JNIEnv *env, jclass clz, int8_tArray channel_id_arg, int8_tArray scriptpubkey_arg) {
10707         LDKThirtyTwoBytes channel_id_arg_ref;
10708         CHECK((*env)->GetArrayLength(env, channel_id_arg) == 32);
10709         (*env)->GetByteArrayRegion(env, channel_id_arg, 0, 32, channel_id_arg_ref.data);
10710         LDKCVec_u8Z scriptpubkey_arg_ref;
10711         scriptpubkey_arg_ref.datalen = (*env)->GetArrayLength(env, scriptpubkey_arg);
10712         scriptpubkey_arg_ref.data = MALLOC(scriptpubkey_arg_ref.datalen, "LDKCVec_u8Z Bytes");
10713         (*env)->GetByteArrayRegion(env, scriptpubkey_arg, 0, scriptpubkey_arg_ref.datalen, scriptpubkey_arg_ref.data);
10714         LDKShutdown ret_var = Shutdown_new(channel_id_arg_ref, scriptpubkey_arg_ref);
10715         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10716         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10717         long ret_ref = (long)ret_var.inner;
10718         if (ret_var.is_owned) {
10719                 ret_ref |= 1;
10720         }
10721         return ret_ref;
10722 }
10723
10724 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ClosingSigned_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
10725         LDKClosingSigned this_ptr_conv;
10726         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10727         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10728         ClosingSigned_free(this_ptr_conv);
10729 }
10730
10731 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ClosingSigned_1clone(JNIEnv *env, jclass clz, int64_t orig) {
10732         LDKClosingSigned orig_conv;
10733         orig_conv.inner = (void*)(orig & (~1));
10734         orig_conv.is_owned = false;
10735         LDKClosingSigned ret_var = ClosingSigned_clone(&orig_conv);
10736         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10737         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10738         long ret_ref = (long)ret_var.inner;
10739         if (ret_var.is_owned) {
10740                 ret_ref |= 1;
10741         }
10742         return ret_ref;
10743 }
10744
10745 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_ClosingSigned_1get_1channel_1id(JNIEnv *env, jclass clz, int64_t this_ptr) {
10746         LDKClosingSigned this_ptr_conv;
10747         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10748         this_ptr_conv.is_owned = false;
10749         int8_tArray ret_arr = (*env)->NewByteArray(env, 32);
10750         (*env)->SetByteArrayRegion(env, ret_arr, 0, 32, *ClosingSigned_get_channel_id(&this_ptr_conv));
10751         return ret_arr;
10752 }
10753
10754 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ClosingSigned_1set_1channel_1id(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
10755         LDKClosingSigned this_ptr_conv;
10756         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10757         this_ptr_conv.is_owned = false;
10758         LDKThirtyTwoBytes val_ref;
10759         CHECK((*env)->GetArrayLength(env, val) == 32);
10760         (*env)->GetByteArrayRegion(env, val, 0, 32, val_ref.data);
10761         ClosingSigned_set_channel_id(&this_ptr_conv, val_ref);
10762 }
10763
10764 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ClosingSigned_1get_1fee_1satoshis(JNIEnv *env, jclass clz, int64_t this_ptr) {
10765         LDKClosingSigned this_ptr_conv;
10766         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10767         this_ptr_conv.is_owned = false;
10768         int64_t ret_val = ClosingSigned_get_fee_satoshis(&this_ptr_conv);
10769         return ret_val;
10770 }
10771
10772 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ClosingSigned_1set_1fee_1satoshis(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
10773         LDKClosingSigned this_ptr_conv;
10774         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10775         this_ptr_conv.is_owned = false;
10776         ClosingSigned_set_fee_satoshis(&this_ptr_conv, val);
10777 }
10778
10779 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_ClosingSigned_1get_1signature(JNIEnv *env, jclass clz, int64_t this_ptr) {
10780         LDKClosingSigned this_ptr_conv;
10781         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10782         this_ptr_conv.is_owned = false;
10783         int8_tArray arg_arr = (*env)->NewByteArray(env, 64);
10784         (*env)->SetByteArrayRegion(env, arg_arr, 0, 64, ClosingSigned_get_signature(&this_ptr_conv).compact_form);
10785         return arg_arr;
10786 }
10787
10788 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ClosingSigned_1set_1signature(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
10789         LDKClosingSigned this_ptr_conv;
10790         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10791         this_ptr_conv.is_owned = false;
10792         LDKSignature val_ref;
10793         CHECK((*env)->GetArrayLength(env, val) == 64);
10794         (*env)->GetByteArrayRegion(env, val, 0, 64, val_ref.compact_form);
10795         ClosingSigned_set_signature(&this_ptr_conv, val_ref);
10796 }
10797
10798 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) {
10799         LDKThirtyTwoBytes channel_id_arg_ref;
10800         CHECK((*env)->GetArrayLength(env, channel_id_arg) == 32);
10801         (*env)->GetByteArrayRegion(env, channel_id_arg, 0, 32, channel_id_arg_ref.data);
10802         LDKSignature signature_arg_ref;
10803         CHECK((*env)->GetArrayLength(env, signature_arg) == 64);
10804         (*env)->GetByteArrayRegion(env, signature_arg, 0, 64, signature_arg_ref.compact_form);
10805         LDKClosingSigned ret_var = ClosingSigned_new(channel_id_arg_ref, fee_satoshis_arg, signature_arg_ref);
10806         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10807         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10808         long ret_ref = (long)ret_var.inner;
10809         if (ret_var.is_owned) {
10810                 ret_ref |= 1;
10811         }
10812         return ret_ref;
10813 }
10814
10815 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateAddHTLC_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
10816         LDKUpdateAddHTLC this_ptr_conv;
10817         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10818         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10819         UpdateAddHTLC_free(this_ptr_conv);
10820 }
10821
10822 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_UpdateAddHTLC_1clone(JNIEnv *env, jclass clz, int64_t orig) {
10823         LDKUpdateAddHTLC orig_conv;
10824         orig_conv.inner = (void*)(orig & (~1));
10825         orig_conv.is_owned = false;
10826         LDKUpdateAddHTLC ret_var = UpdateAddHTLC_clone(&orig_conv);
10827         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10828         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10829         long ret_ref = (long)ret_var.inner;
10830         if (ret_var.is_owned) {
10831                 ret_ref |= 1;
10832         }
10833         return ret_ref;
10834 }
10835
10836 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_UpdateAddHTLC_1get_1channel_1id(JNIEnv *env, jclass clz, int64_t this_ptr) {
10837         LDKUpdateAddHTLC this_ptr_conv;
10838         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10839         this_ptr_conv.is_owned = false;
10840         int8_tArray ret_arr = (*env)->NewByteArray(env, 32);
10841         (*env)->SetByteArrayRegion(env, ret_arr, 0, 32, *UpdateAddHTLC_get_channel_id(&this_ptr_conv));
10842         return ret_arr;
10843 }
10844
10845 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateAddHTLC_1set_1channel_1id(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
10846         LDKUpdateAddHTLC this_ptr_conv;
10847         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10848         this_ptr_conv.is_owned = false;
10849         LDKThirtyTwoBytes val_ref;
10850         CHECK((*env)->GetArrayLength(env, val) == 32);
10851         (*env)->GetByteArrayRegion(env, val, 0, 32, val_ref.data);
10852         UpdateAddHTLC_set_channel_id(&this_ptr_conv, val_ref);
10853 }
10854
10855 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_UpdateAddHTLC_1get_1htlc_1id(JNIEnv *env, jclass clz, int64_t this_ptr) {
10856         LDKUpdateAddHTLC this_ptr_conv;
10857         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10858         this_ptr_conv.is_owned = false;
10859         int64_t ret_val = UpdateAddHTLC_get_htlc_id(&this_ptr_conv);
10860         return ret_val;
10861 }
10862
10863 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateAddHTLC_1set_1htlc_1id(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
10864         LDKUpdateAddHTLC this_ptr_conv;
10865         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10866         this_ptr_conv.is_owned = false;
10867         UpdateAddHTLC_set_htlc_id(&this_ptr_conv, val);
10868 }
10869
10870 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_UpdateAddHTLC_1get_1amount_1msat(JNIEnv *env, jclass clz, int64_t this_ptr) {
10871         LDKUpdateAddHTLC this_ptr_conv;
10872         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10873         this_ptr_conv.is_owned = false;
10874         int64_t ret_val = UpdateAddHTLC_get_amount_msat(&this_ptr_conv);
10875         return ret_val;
10876 }
10877
10878 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateAddHTLC_1set_1amount_1msat(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
10879         LDKUpdateAddHTLC this_ptr_conv;
10880         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10881         this_ptr_conv.is_owned = false;
10882         UpdateAddHTLC_set_amount_msat(&this_ptr_conv, val);
10883 }
10884
10885 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_UpdateAddHTLC_1get_1payment_1hash(JNIEnv *env, jclass clz, int64_t this_ptr) {
10886         LDKUpdateAddHTLC this_ptr_conv;
10887         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10888         this_ptr_conv.is_owned = false;
10889         int8_tArray ret_arr = (*env)->NewByteArray(env, 32);
10890         (*env)->SetByteArrayRegion(env, ret_arr, 0, 32, *UpdateAddHTLC_get_payment_hash(&this_ptr_conv));
10891         return ret_arr;
10892 }
10893
10894 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateAddHTLC_1set_1payment_1hash(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
10895         LDKUpdateAddHTLC this_ptr_conv;
10896         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10897         this_ptr_conv.is_owned = false;
10898         LDKThirtyTwoBytes val_ref;
10899         CHECK((*env)->GetArrayLength(env, val) == 32);
10900         (*env)->GetByteArrayRegion(env, val, 0, 32, val_ref.data);
10901         UpdateAddHTLC_set_payment_hash(&this_ptr_conv, val_ref);
10902 }
10903
10904 JNIEXPORT int32_t JNICALL Java_org_ldk_impl_bindings_UpdateAddHTLC_1get_1cltv_1expiry(JNIEnv *env, jclass clz, int64_t this_ptr) {
10905         LDKUpdateAddHTLC this_ptr_conv;
10906         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10907         this_ptr_conv.is_owned = false;
10908         int32_t ret_val = UpdateAddHTLC_get_cltv_expiry(&this_ptr_conv);
10909         return ret_val;
10910 }
10911
10912 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateAddHTLC_1set_1cltv_1expiry(JNIEnv *env, jclass clz, int64_t this_ptr, int32_t val) {
10913         LDKUpdateAddHTLC this_ptr_conv;
10914         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10915         this_ptr_conv.is_owned = false;
10916         UpdateAddHTLC_set_cltv_expiry(&this_ptr_conv, val);
10917 }
10918
10919 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateFulfillHTLC_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
10920         LDKUpdateFulfillHTLC this_ptr_conv;
10921         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10922         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10923         UpdateFulfillHTLC_free(this_ptr_conv);
10924 }
10925
10926 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_UpdateFulfillHTLC_1clone(JNIEnv *env, jclass clz, int64_t orig) {
10927         LDKUpdateFulfillHTLC orig_conv;
10928         orig_conv.inner = (void*)(orig & (~1));
10929         orig_conv.is_owned = false;
10930         LDKUpdateFulfillHTLC ret_var = UpdateFulfillHTLC_clone(&orig_conv);
10931         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10932         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10933         long ret_ref = (long)ret_var.inner;
10934         if (ret_var.is_owned) {
10935                 ret_ref |= 1;
10936         }
10937         return ret_ref;
10938 }
10939
10940 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_UpdateFulfillHTLC_1get_1channel_1id(JNIEnv *env, jclass clz, int64_t this_ptr) {
10941         LDKUpdateFulfillHTLC this_ptr_conv;
10942         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10943         this_ptr_conv.is_owned = false;
10944         int8_tArray ret_arr = (*env)->NewByteArray(env, 32);
10945         (*env)->SetByteArrayRegion(env, ret_arr, 0, 32, *UpdateFulfillHTLC_get_channel_id(&this_ptr_conv));
10946         return ret_arr;
10947 }
10948
10949 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateFulfillHTLC_1set_1channel_1id(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
10950         LDKUpdateFulfillHTLC this_ptr_conv;
10951         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10952         this_ptr_conv.is_owned = false;
10953         LDKThirtyTwoBytes val_ref;
10954         CHECK((*env)->GetArrayLength(env, val) == 32);
10955         (*env)->GetByteArrayRegion(env, val, 0, 32, val_ref.data);
10956         UpdateFulfillHTLC_set_channel_id(&this_ptr_conv, val_ref);
10957 }
10958
10959 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_UpdateFulfillHTLC_1get_1htlc_1id(JNIEnv *env, jclass clz, int64_t this_ptr) {
10960         LDKUpdateFulfillHTLC this_ptr_conv;
10961         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10962         this_ptr_conv.is_owned = false;
10963         int64_t ret_val = UpdateFulfillHTLC_get_htlc_id(&this_ptr_conv);
10964         return ret_val;
10965 }
10966
10967 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateFulfillHTLC_1set_1htlc_1id(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
10968         LDKUpdateFulfillHTLC this_ptr_conv;
10969         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10970         this_ptr_conv.is_owned = false;
10971         UpdateFulfillHTLC_set_htlc_id(&this_ptr_conv, val);
10972 }
10973
10974 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_UpdateFulfillHTLC_1get_1payment_1preimage(JNIEnv *env, jclass clz, int64_t this_ptr) {
10975         LDKUpdateFulfillHTLC this_ptr_conv;
10976         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10977         this_ptr_conv.is_owned = false;
10978         int8_tArray ret_arr = (*env)->NewByteArray(env, 32);
10979         (*env)->SetByteArrayRegion(env, ret_arr, 0, 32, *UpdateFulfillHTLC_get_payment_preimage(&this_ptr_conv));
10980         return ret_arr;
10981 }
10982
10983 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateFulfillHTLC_1set_1payment_1preimage(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
10984         LDKUpdateFulfillHTLC this_ptr_conv;
10985         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10986         this_ptr_conv.is_owned = false;
10987         LDKThirtyTwoBytes val_ref;
10988         CHECK((*env)->GetArrayLength(env, val) == 32);
10989         (*env)->GetByteArrayRegion(env, val, 0, 32, val_ref.data);
10990         UpdateFulfillHTLC_set_payment_preimage(&this_ptr_conv, val_ref);
10991 }
10992
10993 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) {
10994         LDKThirtyTwoBytes channel_id_arg_ref;
10995         CHECK((*env)->GetArrayLength(env, channel_id_arg) == 32);
10996         (*env)->GetByteArrayRegion(env, channel_id_arg, 0, 32, channel_id_arg_ref.data);
10997         LDKThirtyTwoBytes payment_preimage_arg_ref;
10998         CHECK((*env)->GetArrayLength(env, payment_preimage_arg) == 32);
10999         (*env)->GetByteArrayRegion(env, payment_preimage_arg, 0, 32, payment_preimage_arg_ref.data);
11000         LDKUpdateFulfillHTLC ret_var = UpdateFulfillHTLC_new(channel_id_arg_ref, htlc_id_arg, payment_preimage_arg_ref);
11001         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11002         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11003         long ret_ref = (long)ret_var.inner;
11004         if (ret_var.is_owned) {
11005                 ret_ref |= 1;
11006         }
11007         return ret_ref;
11008 }
11009
11010 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateFailHTLC_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
11011         LDKUpdateFailHTLC this_ptr_conv;
11012         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11013         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
11014         UpdateFailHTLC_free(this_ptr_conv);
11015 }
11016
11017 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_UpdateFailHTLC_1clone(JNIEnv *env, jclass clz, int64_t orig) {
11018         LDKUpdateFailHTLC orig_conv;
11019         orig_conv.inner = (void*)(orig & (~1));
11020         orig_conv.is_owned = false;
11021         LDKUpdateFailHTLC ret_var = UpdateFailHTLC_clone(&orig_conv);
11022         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11023         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11024         long ret_ref = (long)ret_var.inner;
11025         if (ret_var.is_owned) {
11026                 ret_ref |= 1;
11027         }
11028         return ret_ref;
11029 }
11030
11031 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_UpdateFailHTLC_1get_1channel_1id(JNIEnv *env, jclass clz, int64_t this_ptr) {
11032         LDKUpdateFailHTLC this_ptr_conv;
11033         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11034         this_ptr_conv.is_owned = false;
11035         int8_tArray ret_arr = (*env)->NewByteArray(env, 32);
11036         (*env)->SetByteArrayRegion(env, ret_arr, 0, 32, *UpdateFailHTLC_get_channel_id(&this_ptr_conv));
11037         return ret_arr;
11038 }
11039
11040 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateFailHTLC_1set_1channel_1id(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
11041         LDKUpdateFailHTLC this_ptr_conv;
11042         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11043         this_ptr_conv.is_owned = false;
11044         LDKThirtyTwoBytes val_ref;
11045         CHECK((*env)->GetArrayLength(env, val) == 32);
11046         (*env)->GetByteArrayRegion(env, val, 0, 32, val_ref.data);
11047         UpdateFailHTLC_set_channel_id(&this_ptr_conv, val_ref);
11048 }
11049
11050 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_UpdateFailHTLC_1get_1htlc_1id(JNIEnv *env, jclass clz, int64_t this_ptr) {
11051         LDKUpdateFailHTLC this_ptr_conv;
11052         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11053         this_ptr_conv.is_owned = false;
11054         int64_t ret_val = UpdateFailHTLC_get_htlc_id(&this_ptr_conv);
11055         return ret_val;
11056 }
11057
11058 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateFailHTLC_1set_1htlc_1id(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
11059         LDKUpdateFailHTLC this_ptr_conv;
11060         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11061         this_ptr_conv.is_owned = false;
11062         UpdateFailHTLC_set_htlc_id(&this_ptr_conv, val);
11063 }
11064
11065 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateFailMalformedHTLC_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
11066         LDKUpdateFailMalformedHTLC this_ptr_conv;
11067         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11068         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
11069         UpdateFailMalformedHTLC_free(this_ptr_conv);
11070 }
11071
11072 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_UpdateFailMalformedHTLC_1clone(JNIEnv *env, jclass clz, int64_t orig) {
11073         LDKUpdateFailMalformedHTLC orig_conv;
11074         orig_conv.inner = (void*)(orig & (~1));
11075         orig_conv.is_owned = false;
11076         LDKUpdateFailMalformedHTLC ret_var = UpdateFailMalformedHTLC_clone(&orig_conv);
11077         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11078         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11079         long ret_ref = (long)ret_var.inner;
11080         if (ret_var.is_owned) {
11081                 ret_ref |= 1;
11082         }
11083         return ret_ref;
11084 }
11085
11086 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_UpdateFailMalformedHTLC_1get_1channel_1id(JNIEnv *env, jclass clz, int64_t this_ptr) {
11087         LDKUpdateFailMalformedHTLC this_ptr_conv;
11088         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11089         this_ptr_conv.is_owned = false;
11090         int8_tArray ret_arr = (*env)->NewByteArray(env, 32);
11091         (*env)->SetByteArrayRegion(env, ret_arr, 0, 32, *UpdateFailMalformedHTLC_get_channel_id(&this_ptr_conv));
11092         return ret_arr;
11093 }
11094
11095 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateFailMalformedHTLC_1set_1channel_1id(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
11096         LDKUpdateFailMalformedHTLC this_ptr_conv;
11097         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11098         this_ptr_conv.is_owned = false;
11099         LDKThirtyTwoBytes val_ref;
11100         CHECK((*env)->GetArrayLength(env, val) == 32);
11101         (*env)->GetByteArrayRegion(env, val, 0, 32, val_ref.data);
11102         UpdateFailMalformedHTLC_set_channel_id(&this_ptr_conv, val_ref);
11103 }
11104
11105 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_UpdateFailMalformedHTLC_1get_1htlc_1id(JNIEnv *env, jclass clz, int64_t this_ptr) {
11106         LDKUpdateFailMalformedHTLC this_ptr_conv;
11107         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11108         this_ptr_conv.is_owned = false;
11109         int64_t ret_val = UpdateFailMalformedHTLC_get_htlc_id(&this_ptr_conv);
11110         return ret_val;
11111 }
11112
11113 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateFailMalformedHTLC_1set_1htlc_1id(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
11114         LDKUpdateFailMalformedHTLC this_ptr_conv;
11115         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11116         this_ptr_conv.is_owned = false;
11117         UpdateFailMalformedHTLC_set_htlc_id(&this_ptr_conv, val);
11118 }
11119
11120 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_UpdateFailMalformedHTLC_1get_1failure_1code(JNIEnv *env, jclass clz, int64_t this_ptr) {
11121         LDKUpdateFailMalformedHTLC this_ptr_conv;
11122         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11123         this_ptr_conv.is_owned = false;
11124         jshort ret_val = UpdateFailMalformedHTLC_get_failure_code(&this_ptr_conv);
11125         return ret_val;
11126 }
11127
11128 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateFailMalformedHTLC_1set_1failure_1code(JNIEnv *env, jclass clz, int64_t this_ptr, jshort val) {
11129         LDKUpdateFailMalformedHTLC this_ptr_conv;
11130         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11131         this_ptr_conv.is_owned = false;
11132         UpdateFailMalformedHTLC_set_failure_code(&this_ptr_conv, val);
11133 }
11134
11135 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CommitmentSigned_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
11136         LDKCommitmentSigned this_ptr_conv;
11137         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11138         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
11139         CommitmentSigned_free(this_ptr_conv);
11140 }
11141
11142 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CommitmentSigned_1clone(JNIEnv *env, jclass clz, int64_t orig) {
11143         LDKCommitmentSigned orig_conv;
11144         orig_conv.inner = (void*)(orig & (~1));
11145         orig_conv.is_owned = false;
11146         LDKCommitmentSigned ret_var = CommitmentSigned_clone(&orig_conv);
11147         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11148         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11149         long ret_ref = (long)ret_var.inner;
11150         if (ret_var.is_owned) {
11151                 ret_ref |= 1;
11152         }
11153         return ret_ref;
11154 }
11155
11156 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_CommitmentSigned_1get_1channel_1id(JNIEnv *env, jclass clz, int64_t this_ptr) {
11157         LDKCommitmentSigned this_ptr_conv;
11158         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11159         this_ptr_conv.is_owned = false;
11160         int8_tArray ret_arr = (*env)->NewByteArray(env, 32);
11161         (*env)->SetByteArrayRegion(env, ret_arr, 0, 32, *CommitmentSigned_get_channel_id(&this_ptr_conv));
11162         return ret_arr;
11163 }
11164
11165 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CommitmentSigned_1set_1channel_1id(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
11166         LDKCommitmentSigned this_ptr_conv;
11167         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11168         this_ptr_conv.is_owned = false;
11169         LDKThirtyTwoBytes val_ref;
11170         CHECK((*env)->GetArrayLength(env, val) == 32);
11171         (*env)->GetByteArrayRegion(env, val, 0, 32, val_ref.data);
11172         CommitmentSigned_set_channel_id(&this_ptr_conv, val_ref);
11173 }
11174
11175 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_CommitmentSigned_1get_1signature(JNIEnv *env, jclass clz, int64_t this_ptr) {
11176         LDKCommitmentSigned this_ptr_conv;
11177         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11178         this_ptr_conv.is_owned = false;
11179         int8_tArray arg_arr = (*env)->NewByteArray(env, 64);
11180         (*env)->SetByteArrayRegion(env, arg_arr, 0, 64, CommitmentSigned_get_signature(&this_ptr_conv).compact_form);
11181         return arg_arr;
11182 }
11183
11184 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CommitmentSigned_1set_1signature(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
11185         LDKCommitmentSigned this_ptr_conv;
11186         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11187         this_ptr_conv.is_owned = false;
11188         LDKSignature val_ref;
11189         CHECK((*env)->GetArrayLength(env, val) == 64);
11190         (*env)->GetByteArrayRegion(env, val, 0, 64, val_ref.compact_form);
11191         CommitmentSigned_set_signature(&this_ptr_conv, val_ref);
11192 }
11193
11194 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CommitmentSigned_1set_1htlc_1signatures(JNIEnv *env, jclass clz, int64_t this_ptr, jobjectArray val) {
11195         LDKCommitmentSigned this_ptr_conv;
11196         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11197         this_ptr_conv.is_owned = false;
11198         LDKCVec_SignatureZ val_constr;
11199         val_constr.datalen = (*env)->GetArrayLength(env, val);
11200         if (val_constr.datalen > 0)
11201                 val_constr.data = MALLOC(val_constr.datalen * sizeof(LDKSignature), "LDKCVec_SignatureZ Elements");
11202         else
11203                 val_constr.data = NULL;
11204         for (size_t i = 0; i < val_constr.datalen; i++) {
11205                 int8_tArray arr_conv_8 = (*env)->GetObjectArrayElement(env, val, i);
11206                 LDKSignature arr_conv_8_ref;
11207                 CHECK((*env)->GetArrayLength(env, arr_conv_8) == 64);
11208                 (*env)->GetByteArrayRegion(env, arr_conv_8, 0, 64, arr_conv_8_ref.compact_form);
11209                 val_constr.data[i] = arr_conv_8_ref;
11210         }
11211         CommitmentSigned_set_htlc_signatures(&this_ptr_conv, val_constr);
11212 }
11213
11214 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) {
11215         LDKThirtyTwoBytes channel_id_arg_ref;
11216         CHECK((*env)->GetArrayLength(env, channel_id_arg) == 32);
11217         (*env)->GetByteArrayRegion(env, channel_id_arg, 0, 32, channel_id_arg_ref.data);
11218         LDKSignature signature_arg_ref;
11219         CHECK((*env)->GetArrayLength(env, signature_arg) == 64);
11220         (*env)->GetByteArrayRegion(env, signature_arg, 0, 64, signature_arg_ref.compact_form);
11221         LDKCVec_SignatureZ htlc_signatures_arg_constr;
11222         htlc_signatures_arg_constr.datalen = (*env)->GetArrayLength(env, htlc_signatures_arg);
11223         if (htlc_signatures_arg_constr.datalen > 0)
11224                 htlc_signatures_arg_constr.data = MALLOC(htlc_signatures_arg_constr.datalen * sizeof(LDKSignature), "LDKCVec_SignatureZ Elements");
11225         else
11226                 htlc_signatures_arg_constr.data = NULL;
11227         for (size_t i = 0; i < htlc_signatures_arg_constr.datalen; i++) {
11228                 int8_tArray arr_conv_8 = (*env)->GetObjectArrayElement(env, htlc_signatures_arg, i);
11229                 LDKSignature arr_conv_8_ref;
11230                 CHECK((*env)->GetArrayLength(env, arr_conv_8) == 64);
11231                 (*env)->GetByteArrayRegion(env, arr_conv_8, 0, 64, arr_conv_8_ref.compact_form);
11232                 htlc_signatures_arg_constr.data[i] = arr_conv_8_ref;
11233         }
11234         LDKCommitmentSigned ret_var = CommitmentSigned_new(channel_id_arg_ref, signature_arg_ref, htlc_signatures_arg_constr);
11235         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11236         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11237         long ret_ref = (long)ret_var.inner;
11238         if (ret_var.is_owned) {
11239                 ret_ref |= 1;
11240         }
11241         return ret_ref;
11242 }
11243
11244 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RevokeAndACK_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
11245         LDKRevokeAndACK this_ptr_conv;
11246         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11247         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
11248         RevokeAndACK_free(this_ptr_conv);
11249 }
11250
11251 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_RevokeAndACK_1clone(JNIEnv *env, jclass clz, int64_t orig) {
11252         LDKRevokeAndACK orig_conv;
11253         orig_conv.inner = (void*)(orig & (~1));
11254         orig_conv.is_owned = false;
11255         LDKRevokeAndACK ret_var = RevokeAndACK_clone(&orig_conv);
11256         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11257         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11258         long ret_ref = (long)ret_var.inner;
11259         if (ret_var.is_owned) {
11260                 ret_ref |= 1;
11261         }
11262         return ret_ref;
11263 }
11264
11265 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_RevokeAndACK_1get_1channel_1id(JNIEnv *env, jclass clz, int64_t this_ptr) {
11266         LDKRevokeAndACK this_ptr_conv;
11267         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11268         this_ptr_conv.is_owned = false;
11269         int8_tArray ret_arr = (*env)->NewByteArray(env, 32);
11270         (*env)->SetByteArrayRegion(env, ret_arr, 0, 32, *RevokeAndACK_get_channel_id(&this_ptr_conv));
11271         return ret_arr;
11272 }
11273
11274 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RevokeAndACK_1set_1channel_1id(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
11275         LDKRevokeAndACK this_ptr_conv;
11276         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11277         this_ptr_conv.is_owned = false;
11278         LDKThirtyTwoBytes val_ref;
11279         CHECK((*env)->GetArrayLength(env, val) == 32);
11280         (*env)->GetByteArrayRegion(env, val, 0, 32, val_ref.data);
11281         RevokeAndACK_set_channel_id(&this_ptr_conv, val_ref);
11282 }
11283
11284 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_RevokeAndACK_1get_1per_1commitment_1secret(JNIEnv *env, jclass clz, int64_t this_ptr) {
11285         LDKRevokeAndACK this_ptr_conv;
11286         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11287         this_ptr_conv.is_owned = false;
11288         int8_tArray ret_arr = (*env)->NewByteArray(env, 32);
11289         (*env)->SetByteArrayRegion(env, ret_arr, 0, 32, *RevokeAndACK_get_per_commitment_secret(&this_ptr_conv));
11290         return ret_arr;
11291 }
11292
11293 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RevokeAndACK_1set_1per_1commitment_1secret(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
11294         LDKRevokeAndACK this_ptr_conv;
11295         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11296         this_ptr_conv.is_owned = false;
11297         LDKThirtyTwoBytes val_ref;
11298         CHECK((*env)->GetArrayLength(env, val) == 32);
11299         (*env)->GetByteArrayRegion(env, val, 0, 32, val_ref.data);
11300         RevokeAndACK_set_per_commitment_secret(&this_ptr_conv, val_ref);
11301 }
11302
11303 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_RevokeAndACK_1get_1next_1per_1commitment_1point(JNIEnv *env, jclass clz, int64_t this_ptr) {
11304         LDKRevokeAndACK this_ptr_conv;
11305         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11306         this_ptr_conv.is_owned = false;
11307         int8_tArray arg_arr = (*env)->NewByteArray(env, 33);
11308         (*env)->SetByteArrayRegion(env, arg_arr, 0, 33, RevokeAndACK_get_next_per_commitment_point(&this_ptr_conv).compressed_form);
11309         return arg_arr;
11310 }
11311
11312 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) {
11313         LDKRevokeAndACK this_ptr_conv;
11314         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11315         this_ptr_conv.is_owned = false;
11316         LDKPublicKey val_ref;
11317         CHECK((*env)->GetArrayLength(env, val) == 33);
11318         (*env)->GetByteArrayRegion(env, val, 0, 33, val_ref.compressed_form);
11319         RevokeAndACK_set_next_per_commitment_point(&this_ptr_conv, val_ref);
11320 }
11321
11322 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) {
11323         LDKThirtyTwoBytes channel_id_arg_ref;
11324         CHECK((*env)->GetArrayLength(env, channel_id_arg) == 32);
11325         (*env)->GetByteArrayRegion(env, channel_id_arg, 0, 32, channel_id_arg_ref.data);
11326         LDKThirtyTwoBytes per_commitment_secret_arg_ref;
11327         CHECK((*env)->GetArrayLength(env, per_commitment_secret_arg) == 32);
11328         (*env)->GetByteArrayRegion(env, per_commitment_secret_arg, 0, 32, per_commitment_secret_arg_ref.data);
11329         LDKPublicKey next_per_commitment_point_arg_ref;
11330         CHECK((*env)->GetArrayLength(env, next_per_commitment_point_arg) == 33);
11331         (*env)->GetByteArrayRegion(env, next_per_commitment_point_arg, 0, 33, next_per_commitment_point_arg_ref.compressed_form);
11332         LDKRevokeAndACK ret_var = RevokeAndACK_new(channel_id_arg_ref, per_commitment_secret_arg_ref, next_per_commitment_point_arg_ref);
11333         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11334         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11335         long ret_ref = (long)ret_var.inner;
11336         if (ret_var.is_owned) {
11337                 ret_ref |= 1;
11338         }
11339         return ret_ref;
11340 }
11341
11342 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateFee_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
11343         LDKUpdateFee this_ptr_conv;
11344         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11345         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
11346         UpdateFee_free(this_ptr_conv);
11347 }
11348
11349 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_UpdateFee_1clone(JNIEnv *env, jclass clz, int64_t orig) {
11350         LDKUpdateFee orig_conv;
11351         orig_conv.inner = (void*)(orig & (~1));
11352         orig_conv.is_owned = false;
11353         LDKUpdateFee ret_var = UpdateFee_clone(&orig_conv);
11354         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11355         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11356         long ret_ref = (long)ret_var.inner;
11357         if (ret_var.is_owned) {
11358                 ret_ref |= 1;
11359         }
11360         return ret_ref;
11361 }
11362
11363 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_UpdateFee_1get_1channel_1id(JNIEnv *env, jclass clz, int64_t this_ptr) {
11364         LDKUpdateFee this_ptr_conv;
11365         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11366         this_ptr_conv.is_owned = false;
11367         int8_tArray ret_arr = (*env)->NewByteArray(env, 32);
11368         (*env)->SetByteArrayRegion(env, ret_arr, 0, 32, *UpdateFee_get_channel_id(&this_ptr_conv));
11369         return ret_arr;
11370 }
11371
11372 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateFee_1set_1channel_1id(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
11373         LDKUpdateFee this_ptr_conv;
11374         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11375         this_ptr_conv.is_owned = false;
11376         LDKThirtyTwoBytes val_ref;
11377         CHECK((*env)->GetArrayLength(env, val) == 32);
11378         (*env)->GetByteArrayRegion(env, val, 0, 32, val_ref.data);
11379         UpdateFee_set_channel_id(&this_ptr_conv, val_ref);
11380 }
11381
11382 JNIEXPORT int32_t JNICALL Java_org_ldk_impl_bindings_UpdateFee_1get_1feerate_1per_1kw(JNIEnv *env, jclass clz, int64_t this_ptr) {
11383         LDKUpdateFee this_ptr_conv;
11384         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11385         this_ptr_conv.is_owned = false;
11386         int32_t ret_val = UpdateFee_get_feerate_per_kw(&this_ptr_conv);
11387         return ret_val;
11388 }
11389
11390 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateFee_1set_1feerate_1per_1kw(JNIEnv *env, jclass clz, int64_t this_ptr, int32_t val) {
11391         LDKUpdateFee this_ptr_conv;
11392         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11393         this_ptr_conv.is_owned = false;
11394         UpdateFee_set_feerate_per_kw(&this_ptr_conv, val);
11395 }
11396
11397 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) {
11398         LDKThirtyTwoBytes channel_id_arg_ref;
11399         CHECK((*env)->GetArrayLength(env, channel_id_arg) == 32);
11400         (*env)->GetByteArrayRegion(env, channel_id_arg, 0, 32, channel_id_arg_ref.data);
11401         LDKUpdateFee ret_var = UpdateFee_new(channel_id_arg_ref, feerate_per_kw_arg);
11402         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11403         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11404         long ret_ref = (long)ret_var.inner;
11405         if (ret_var.is_owned) {
11406                 ret_ref |= 1;
11407         }
11408         return ret_ref;
11409 }
11410
11411 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_DataLossProtect_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
11412         LDKDataLossProtect this_ptr_conv;
11413         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11414         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
11415         DataLossProtect_free(this_ptr_conv);
11416 }
11417
11418 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_DataLossProtect_1clone(JNIEnv *env, jclass clz, int64_t orig) {
11419         LDKDataLossProtect orig_conv;
11420         orig_conv.inner = (void*)(orig & (~1));
11421         orig_conv.is_owned = false;
11422         LDKDataLossProtect ret_var = DataLossProtect_clone(&orig_conv);
11423         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11424         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11425         long ret_ref = (long)ret_var.inner;
11426         if (ret_var.is_owned) {
11427                 ret_ref |= 1;
11428         }
11429         return ret_ref;
11430 }
11431
11432 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_DataLossProtect_1get_1your_1last_1per_1commitment_1secret(JNIEnv *env, jclass clz, int64_t this_ptr) {
11433         LDKDataLossProtect this_ptr_conv;
11434         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11435         this_ptr_conv.is_owned = false;
11436         int8_tArray ret_arr = (*env)->NewByteArray(env, 32);
11437         (*env)->SetByteArrayRegion(env, ret_arr, 0, 32, *DataLossProtect_get_your_last_per_commitment_secret(&this_ptr_conv));
11438         return ret_arr;
11439 }
11440
11441 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) {
11442         LDKDataLossProtect this_ptr_conv;
11443         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11444         this_ptr_conv.is_owned = false;
11445         LDKThirtyTwoBytes val_ref;
11446         CHECK((*env)->GetArrayLength(env, val) == 32);
11447         (*env)->GetByteArrayRegion(env, val, 0, 32, val_ref.data);
11448         DataLossProtect_set_your_last_per_commitment_secret(&this_ptr_conv, val_ref);
11449 }
11450
11451 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_DataLossProtect_1get_1my_1current_1per_1commitment_1point(JNIEnv *env, jclass clz, int64_t this_ptr) {
11452         LDKDataLossProtect this_ptr_conv;
11453         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11454         this_ptr_conv.is_owned = false;
11455         int8_tArray arg_arr = (*env)->NewByteArray(env, 33);
11456         (*env)->SetByteArrayRegion(env, arg_arr, 0, 33, DataLossProtect_get_my_current_per_commitment_point(&this_ptr_conv).compressed_form);
11457         return arg_arr;
11458 }
11459
11460 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) {
11461         LDKDataLossProtect this_ptr_conv;
11462         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11463         this_ptr_conv.is_owned = false;
11464         LDKPublicKey val_ref;
11465         CHECK((*env)->GetArrayLength(env, val) == 33);
11466         (*env)->GetByteArrayRegion(env, val, 0, 33, val_ref.compressed_form);
11467         DataLossProtect_set_my_current_per_commitment_point(&this_ptr_conv, val_ref);
11468 }
11469
11470 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) {
11471         LDKThirtyTwoBytes your_last_per_commitment_secret_arg_ref;
11472         CHECK((*env)->GetArrayLength(env, your_last_per_commitment_secret_arg) == 32);
11473         (*env)->GetByteArrayRegion(env, your_last_per_commitment_secret_arg, 0, 32, your_last_per_commitment_secret_arg_ref.data);
11474         LDKPublicKey my_current_per_commitment_point_arg_ref;
11475         CHECK((*env)->GetArrayLength(env, my_current_per_commitment_point_arg) == 33);
11476         (*env)->GetByteArrayRegion(env, my_current_per_commitment_point_arg, 0, 33, my_current_per_commitment_point_arg_ref.compressed_form);
11477         LDKDataLossProtect ret_var = DataLossProtect_new(your_last_per_commitment_secret_arg_ref, my_current_per_commitment_point_arg_ref);
11478         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11479         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11480         long ret_ref = (long)ret_var.inner;
11481         if (ret_var.is_owned) {
11482                 ret_ref |= 1;
11483         }
11484         return ret_ref;
11485 }
11486
11487 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelReestablish_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
11488         LDKChannelReestablish this_ptr_conv;
11489         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11490         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
11491         ChannelReestablish_free(this_ptr_conv);
11492 }
11493
11494 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelReestablish_1clone(JNIEnv *env, jclass clz, int64_t orig) {
11495         LDKChannelReestablish orig_conv;
11496         orig_conv.inner = (void*)(orig & (~1));
11497         orig_conv.is_owned = false;
11498         LDKChannelReestablish ret_var = ChannelReestablish_clone(&orig_conv);
11499         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11500         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11501         long ret_ref = (long)ret_var.inner;
11502         if (ret_var.is_owned) {
11503                 ret_ref |= 1;
11504         }
11505         return ret_ref;
11506 }
11507
11508 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_ChannelReestablish_1get_1channel_1id(JNIEnv *env, jclass clz, int64_t this_ptr) {
11509         LDKChannelReestablish this_ptr_conv;
11510         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11511         this_ptr_conv.is_owned = false;
11512         int8_tArray ret_arr = (*env)->NewByteArray(env, 32);
11513         (*env)->SetByteArrayRegion(env, ret_arr, 0, 32, *ChannelReestablish_get_channel_id(&this_ptr_conv));
11514         return ret_arr;
11515 }
11516
11517 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelReestablish_1set_1channel_1id(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
11518         LDKChannelReestablish this_ptr_conv;
11519         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11520         this_ptr_conv.is_owned = false;
11521         LDKThirtyTwoBytes val_ref;
11522         CHECK((*env)->GetArrayLength(env, val) == 32);
11523         (*env)->GetByteArrayRegion(env, val, 0, 32, val_ref.data);
11524         ChannelReestablish_set_channel_id(&this_ptr_conv, val_ref);
11525 }
11526
11527 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelReestablish_1get_1next_1local_1commitment_1number(JNIEnv *env, jclass clz, int64_t this_ptr) {
11528         LDKChannelReestablish this_ptr_conv;
11529         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11530         this_ptr_conv.is_owned = false;
11531         int64_t ret_val = ChannelReestablish_get_next_local_commitment_number(&this_ptr_conv);
11532         return ret_val;
11533 }
11534
11535 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) {
11536         LDKChannelReestablish this_ptr_conv;
11537         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11538         this_ptr_conv.is_owned = false;
11539         ChannelReestablish_set_next_local_commitment_number(&this_ptr_conv, val);
11540 }
11541
11542 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelReestablish_1get_1next_1remote_1commitment_1number(JNIEnv *env, jclass clz, int64_t this_ptr) {
11543         LDKChannelReestablish this_ptr_conv;
11544         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11545         this_ptr_conv.is_owned = false;
11546         int64_t ret_val = ChannelReestablish_get_next_remote_commitment_number(&this_ptr_conv);
11547         return ret_val;
11548 }
11549
11550 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) {
11551         LDKChannelReestablish this_ptr_conv;
11552         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11553         this_ptr_conv.is_owned = false;
11554         ChannelReestablish_set_next_remote_commitment_number(&this_ptr_conv, val);
11555 }
11556
11557 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AnnouncementSignatures_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
11558         LDKAnnouncementSignatures this_ptr_conv;
11559         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11560         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
11561         AnnouncementSignatures_free(this_ptr_conv);
11562 }
11563
11564 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_AnnouncementSignatures_1clone(JNIEnv *env, jclass clz, int64_t orig) {
11565         LDKAnnouncementSignatures orig_conv;
11566         orig_conv.inner = (void*)(orig & (~1));
11567         orig_conv.is_owned = false;
11568         LDKAnnouncementSignatures ret_var = AnnouncementSignatures_clone(&orig_conv);
11569         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11570         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11571         long ret_ref = (long)ret_var.inner;
11572         if (ret_var.is_owned) {
11573                 ret_ref |= 1;
11574         }
11575         return ret_ref;
11576 }
11577
11578 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_AnnouncementSignatures_1get_1channel_1id(JNIEnv *env, jclass clz, int64_t this_ptr) {
11579         LDKAnnouncementSignatures this_ptr_conv;
11580         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11581         this_ptr_conv.is_owned = false;
11582         int8_tArray ret_arr = (*env)->NewByteArray(env, 32);
11583         (*env)->SetByteArrayRegion(env, ret_arr, 0, 32, *AnnouncementSignatures_get_channel_id(&this_ptr_conv));
11584         return ret_arr;
11585 }
11586
11587 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AnnouncementSignatures_1set_1channel_1id(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
11588         LDKAnnouncementSignatures this_ptr_conv;
11589         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11590         this_ptr_conv.is_owned = false;
11591         LDKThirtyTwoBytes val_ref;
11592         CHECK((*env)->GetArrayLength(env, val) == 32);
11593         (*env)->GetByteArrayRegion(env, val, 0, 32, val_ref.data);
11594         AnnouncementSignatures_set_channel_id(&this_ptr_conv, val_ref);
11595 }
11596
11597 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_AnnouncementSignatures_1get_1short_1channel_1id(JNIEnv *env, jclass clz, int64_t this_ptr) {
11598         LDKAnnouncementSignatures this_ptr_conv;
11599         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11600         this_ptr_conv.is_owned = false;
11601         int64_t ret_val = AnnouncementSignatures_get_short_channel_id(&this_ptr_conv);
11602         return ret_val;
11603 }
11604
11605 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AnnouncementSignatures_1set_1short_1channel_1id(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
11606         LDKAnnouncementSignatures this_ptr_conv;
11607         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11608         this_ptr_conv.is_owned = false;
11609         AnnouncementSignatures_set_short_channel_id(&this_ptr_conv, val);
11610 }
11611
11612 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_AnnouncementSignatures_1get_1node_1signature(JNIEnv *env, jclass clz, int64_t this_ptr) {
11613         LDKAnnouncementSignatures this_ptr_conv;
11614         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11615         this_ptr_conv.is_owned = false;
11616         int8_tArray arg_arr = (*env)->NewByteArray(env, 64);
11617         (*env)->SetByteArrayRegion(env, arg_arr, 0, 64, AnnouncementSignatures_get_node_signature(&this_ptr_conv).compact_form);
11618         return arg_arr;
11619 }
11620
11621 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AnnouncementSignatures_1set_1node_1signature(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
11622         LDKAnnouncementSignatures this_ptr_conv;
11623         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11624         this_ptr_conv.is_owned = false;
11625         LDKSignature val_ref;
11626         CHECK((*env)->GetArrayLength(env, val) == 64);
11627         (*env)->GetByteArrayRegion(env, val, 0, 64, val_ref.compact_form);
11628         AnnouncementSignatures_set_node_signature(&this_ptr_conv, val_ref);
11629 }
11630
11631 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_AnnouncementSignatures_1get_1bitcoin_1signature(JNIEnv *env, jclass clz, int64_t this_ptr) {
11632         LDKAnnouncementSignatures this_ptr_conv;
11633         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11634         this_ptr_conv.is_owned = false;
11635         int8_tArray arg_arr = (*env)->NewByteArray(env, 64);
11636         (*env)->SetByteArrayRegion(env, arg_arr, 0, 64, AnnouncementSignatures_get_bitcoin_signature(&this_ptr_conv).compact_form);
11637         return arg_arr;
11638 }
11639
11640 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AnnouncementSignatures_1set_1bitcoin_1signature(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
11641         LDKAnnouncementSignatures this_ptr_conv;
11642         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11643         this_ptr_conv.is_owned = false;
11644         LDKSignature val_ref;
11645         CHECK((*env)->GetArrayLength(env, val) == 64);
11646         (*env)->GetByteArrayRegion(env, val, 0, 64, val_ref.compact_form);
11647         AnnouncementSignatures_set_bitcoin_signature(&this_ptr_conv, val_ref);
11648 }
11649
11650 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) {
11651         LDKThirtyTwoBytes channel_id_arg_ref;
11652         CHECK((*env)->GetArrayLength(env, channel_id_arg) == 32);
11653         (*env)->GetByteArrayRegion(env, channel_id_arg, 0, 32, channel_id_arg_ref.data);
11654         LDKSignature node_signature_arg_ref;
11655         CHECK((*env)->GetArrayLength(env, node_signature_arg) == 64);
11656         (*env)->GetByteArrayRegion(env, node_signature_arg, 0, 64, node_signature_arg_ref.compact_form);
11657         LDKSignature bitcoin_signature_arg_ref;
11658         CHECK((*env)->GetArrayLength(env, bitcoin_signature_arg) == 64);
11659         (*env)->GetByteArrayRegion(env, bitcoin_signature_arg, 0, 64, bitcoin_signature_arg_ref.compact_form);
11660         LDKAnnouncementSignatures ret_var = AnnouncementSignatures_new(channel_id_arg_ref, short_channel_id_arg, node_signature_arg_ref, bitcoin_signature_arg_ref);
11661         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11662         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11663         long ret_ref = (long)ret_var.inner;
11664         if (ret_var.is_owned) {
11665                 ret_ref |= 1;
11666         }
11667         return ret_ref;
11668 }
11669
11670 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NetAddress_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
11671         LDKNetAddress this_ptr_conv = *(LDKNetAddress*)this_ptr;
11672         FREE((void*)this_ptr);
11673         NetAddress_free(this_ptr_conv);
11674 }
11675
11676 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_NetAddress_1clone(JNIEnv *env, jclass clz, int64_t orig) {
11677         LDKNetAddress* orig_conv = (LDKNetAddress*)orig;
11678         LDKNetAddress *ret_copy = MALLOC(sizeof(LDKNetAddress), "LDKNetAddress");
11679         *ret_copy = NetAddress_clone(orig_conv);
11680         long ret_ref = (long)ret_copy;
11681         return ret_ref;
11682 }
11683
11684 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_NetAddress_1write(JNIEnv *env, jclass clz, int64_t obj) {
11685         LDKNetAddress* obj_conv = (LDKNetAddress*)obj;
11686         LDKCVec_u8Z arg_var = NetAddress_write(obj_conv);
11687         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
11688         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
11689         CVec_u8Z_free(arg_var);
11690         return arg_arr;
11691 }
11692
11693 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_Result_1read(JNIEnv *env, jclass clz, int8_tArray ser) {
11694         LDKu8slice ser_ref;
11695         ser_ref.datalen = (*env)->GetArrayLength(env, ser);
11696         ser_ref.data = (*env)->GetByteArrayElements (env, ser, NULL);
11697         LDKCResult_CResult_NetAddressu8ZDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_CResult_NetAddressu8ZDecodeErrorZ), "LDKCResult_CResult_NetAddressu8ZDecodeErrorZ");
11698         *ret_conv = Result_read(ser_ref);
11699         (*env)->ReleaseByteArrayElements(env, ser, (int8_t*)ser_ref.data, 0);
11700         return (long)ret_conv;
11701 }
11702
11703 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedNodeAnnouncement_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
11704         LDKUnsignedNodeAnnouncement this_ptr_conv;
11705         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11706         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
11707         UnsignedNodeAnnouncement_free(this_ptr_conv);
11708 }
11709
11710 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_UnsignedNodeAnnouncement_1clone(JNIEnv *env, jclass clz, int64_t orig) {
11711         LDKUnsignedNodeAnnouncement orig_conv;
11712         orig_conv.inner = (void*)(orig & (~1));
11713         orig_conv.is_owned = false;
11714         LDKUnsignedNodeAnnouncement ret_var = UnsignedNodeAnnouncement_clone(&orig_conv);
11715         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11716         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11717         long ret_ref = (long)ret_var.inner;
11718         if (ret_var.is_owned) {
11719                 ret_ref |= 1;
11720         }
11721         return ret_ref;
11722 }
11723
11724 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_UnsignedNodeAnnouncement_1get_1features(JNIEnv *env, jclass clz, int64_t this_ptr) {
11725         LDKUnsignedNodeAnnouncement this_ptr_conv;
11726         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11727         this_ptr_conv.is_owned = false;
11728         LDKNodeFeatures ret_var = UnsignedNodeAnnouncement_get_features(&this_ptr_conv);
11729         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11730         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11731         long ret_ref = (long)ret_var.inner;
11732         if (ret_var.is_owned) {
11733                 ret_ref |= 1;
11734         }
11735         return ret_ref;
11736 }
11737
11738 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedNodeAnnouncement_1set_1features(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
11739         LDKUnsignedNodeAnnouncement this_ptr_conv;
11740         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11741         this_ptr_conv.is_owned = false;
11742         LDKNodeFeatures val_conv;
11743         val_conv.inner = (void*)(val & (~1));
11744         val_conv.is_owned = (val & 1) || (val == 0);
11745         // Warning: we may need a move here but can't clone!
11746         UnsignedNodeAnnouncement_set_features(&this_ptr_conv, val_conv);
11747 }
11748
11749 JNIEXPORT int32_t JNICALL Java_org_ldk_impl_bindings_UnsignedNodeAnnouncement_1get_1timestamp(JNIEnv *env, jclass clz, int64_t this_ptr) {
11750         LDKUnsignedNodeAnnouncement this_ptr_conv;
11751         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11752         this_ptr_conv.is_owned = false;
11753         int32_t ret_val = UnsignedNodeAnnouncement_get_timestamp(&this_ptr_conv);
11754         return ret_val;
11755 }
11756
11757 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedNodeAnnouncement_1set_1timestamp(JNIEnv *env, jclass clz, int64_t this_ptr, int32_t val) {
11758         LDKUnsignedNodeAnnouncement this_ptr_conv;
11759         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11760         this_ptr_conv.is_owned = false;
11761         UnsignedNodeAnnouncement_set_timestamp(&this_ptr_conv, val);
11762 }
11763
11764 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_UnsignedNodeAnnouncement_1get_1node_1id(JNIEnv *env, jclass clz, int64_t this_ptr) {
11765         LDKUnsignedNodeAnnouncement this_ptr_conv;
11766         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11767         this_ptr_conv.is_owned = false;
11768         int8_tArray arg_arr = (*env)->NewByteArray(env, 33);
11769         (*env)->SetByteArrayRegion(env, arg_arr, 0, 33, UnsignedNodeAnnouncement_get_node_id(&this_ptr_conv).compressed_form);
11770         return arg_arr;
11771 }
11772
11773 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedNodeAnnouncement_1set_1node_1id(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
11774         LDKUnsignedNodeAnnouncement this_ptr_conv;
11775         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11776         this_ptr_conv.is_owned = false;
11777         LDKPublicKey val_ref;
11778         CHECK((*env)->GetArrayLength(env, val) == 33);
11779         (*env)->GetByteArrayRegion(env, val, 0, 33, val_ref.compressed_form);
11780         UnsignedNodeAnnouncement_set_node_id(&this_ptr_conv, val_ref);
11781 }
11782
11783 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_UnsignedNodeAnnouncement_1get_1rgb(JNIEnv *env, jclass clz, int64_t this_ptr) {
11784         LDKUnsignedNodeAnnouncement this_ptr_conv;
11785         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11786         this_ptr_conv.is_owned = false;
11787         int8_tArray ret_arr = (*env)->NewByteArray(env, 3);
11788         (*env)->SetByteArrayRegion(env, ret_arr, 0, 3, *UnsignedNodeAnnouncement_get_rgb(&this_ptr_conv));
11789         return ret_arr;
11790 }
11791
11792 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedNodeAnnouncement_1set_1rgb(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
11793         LDKUnsignedNodeAnnouncement this_ptr_conv;
11794         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11795         this_ptr_conv.is_owned = false;
11796         LDKThreeBytes val_ref;
11797         CHECK((*env)->GetArrayLength(env, val) == 3);
11798         (*env)->GetByteArrayRegion(env, val, 0, 3, val_ref.data);
11799         UnsignedNodeAnnouncement_set_rgb(&this_ptr_conv, val_ref);
11800 }
11801
11802 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_UnsignedNodeAnnouncement_1get_1alias(JNIEnv *env, jclass clz, int64_t this_ptr) {
11803         LDKUnsignedNodeAnnouncement this_ptr_conv;
11804         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11805         this_ptr_conv.is_owned = false;
11806         int8_tArray ret_arr = (*env)->NewByteArray(env, 32);
11807         (*env)->SetByteArrayRegion(env, ret_arr, 0, 32, *UnsignedNodeAnnouncement_get_alias(&this_ptr_conv));
11808         return ret_arr;
11809 }
11810
11811 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedNodeAnnouncement_1set_1alias(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
11812         LDKUnsignedNodeAnnouncement this_ptr_conv;
11813         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11814         this_ptr_conv.is_owned = false;
11815         LDKThirtyTwoBytes val_ref;
11816         CHECK((*env)->GetArrayLength(env, val) == 32);
11817         (*env)->GetByteArrayRegion(env, val, 0, 32, val_ref.data);
11818         UnsignedNodeAnnouncement_set_alias(&this_ptr_conv, val_ref);
11819 }
11820
11821 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedNodeAnnouncement_1set_1addresses(JNIEnv *env, jclass clz, int64_t this_ptr, int64_tArray val) {
11822         LDKUnsignedNodeAnnouncement this_ptr_conv;
11823         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11824         this_ptr_conv.is_owned = false;
11825         LDKCVec_NetAddressZ val_constr;
11826         val_constr.datalen = (*env)->GetArrayLength(env, val);
11827         if (val_constr.datalen > 0)
11828                 val_constr.data = MALLOC(val_constr.datalen * sizeof(LDKNetAddress), "LDKCVec_NetAddressZ Elements");
11829         else
11830                 val_constr.data = NULL;
11831         int64_t* val_vals = (*env)->GetLongArrayElements (env, val, NULL);
11832         for (size_t m = 0; m < val_constr.datalen; m++) {
11833                 int64_t arr_conv_12 = val_vals[m];
11834                 LDKNetAddress arr_conv_12_conv = *(LDKNetAddress*)arr_conv_12;
11835                 FREE((void*)arr_conv_12);
11836                 val_constr.data[m] = arr_conv_12_conv;
11837         }
11838         (*env)->ReleaseLongArrayElements(env, val, val_vals, 0);
11839         UnsignedNodeAnnouncement_set_addresses(&this_ptr_conv, val_constr);
11840 }
11841
11842 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NodeAnnouncement_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
11843         LDKNodeAnnouncement this_ptr_conv;
11844         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11845         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
11846         NodeAnnouncement_free(this_ptr_conv);
11847 }
11848
11849 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_NodeAnnouncement_1clone(JNIEnv *env, jclass clz, int64_t orig) {
11850         LDKNodeAnnouncement orig_conv;
11851         orig_conv.inner = (void*)(orig & (~1));
11852         orig_conv.is_owned = false;
11853         LDKNodeAnnouncement ret_var = NodeAnnouncement_clone(&orig_conv);
11854         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11855         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11856         long ret_ref = (long)ret_var.inner;
11857         if (ret_var.is_owned) {
11858                 ret_ref |= 1;
11859         }
11860         return ret_ref;
11861 }
11862
11863 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_NodeAnnouncement_1get_1signature(JNIEnv *env, jclass clz, int64_t this_ptr) {
11864         LDKNodeAnnouncement this_ptr_conv;
11865         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11866         this_ptr_conv.is_owned = false;
11867         int8_tArray arg_arr = (*env)->NewByteArray(env, 64);
11868         (*env)->SetByteArrayRegion(env, arg_arr, 0, 64, NodeAnnouncement_get_signature(&this_ptr_conv).compact_form);
11869         return arg_arr;
11870 }
11871
11872 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NodeAnnouncement_1set_1signature(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
11873         LDKNodeAnnouncement this_ptr_conv;
11874         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11875         this_ptr_conv.is_owned = false;
11876         LDKSignature val_ref;
11877         CHECK((*env)->GetArrayLength(env, val) == 64);
11878         (*env)->GetByteArrayRegion(env, val, 0, 64, val_ref.compact_form);
11879         NodeAnnouncement_set_signature(&this_ptr_conv, val_ref);
11880 }
11881
11882 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_NodeAnnouncement_1get_1contents(JNIEnv *env, jclass clz, int64_t this_ptr) {
11883         LDKNodeAnnouncement this_ptr_conv;
11884         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11885         this_ptr_conv.is_owned = false;
11886         LDKUnsignedNodeAnnouncement ret_var = NodeAnnouncement_get_contents(&this_ptr_conv);
11887         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11888         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11889         long ret_ref = (long)ret_var.inner;
11890         if (ret_var.is_owned) {
11891                 ret_ref |= 1;
11892         }
11893         return ret_ref;
11894 }
11895
11896 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NodeAnnouncement_1set_1contents(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
11897         LDKNodeAnnouncement this_ptr_conv;
11898         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11899         this_ptr_conv.is_owned = false;
11900         LDKUnsignedNodeAnnouncement val_conv;
11901         val_conv.inner = (void*)(val & (~1));
11902         val_conv.is_owned = (val & 1) || (val == 0);
11903         if (val_conv.inner != NULL)
11904                 val_conv = UnsignedNodeAnnouncement_clone(&val_conv);
11905         NodeAnnouncement_set_contents(&this_ptr_conv, val_conv);
11906 }
11907
11908 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_NodeAnnouncement_1new(JNIEnv *env, jclass clz, int8_tArray signature_arg, int64_t contents_arg) {
11909         LDKSignature signature_arg_ref;
11910         CHECK((*env)->GetArrayLength(env, signature_arg) == 64);
11911         (*env)->GetByteArrayRegion(env, signature_arg, 0, 64, signature_arg_ref.compact_form);
11912         LDKUnsignedNodeAnnouncement contents_arg_conv;
11913         contents_arg_conv.inner = (void*)(contents_arg & (~1));
11914         contents_arg_conv.is_owned = (contents_arg & 1) || (contents_arg == 0);
11915         if (contents_arg_conv.inner != NULL)
11916                 contents_arg_conv = UnsignedNodeAnnouncement_clone(&contents_arg_conv);
11917         LDKNodeAnnouncement ret_var = NodeAnnouncement_new(signature_arg_ref, contents_arg_conv);
11918         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11919         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11920         long ret_ref = (long)ret_var.inner;
11921         if (ret_var.is_owned) {
11922                 ret_ref |= 1;
11923         }
11924         return ret_ref;
11925 }
11926
11927 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
11928         LDKUnsignedChannelAnnouncement this_ptr_conv;
11929         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11930         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
11931         UnsignedChannelAnnouncement_free(this_ptr_conv);
11932 }
11933
11934 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1clone(JNIEnv *env, jclass clz, int64_t orig) {
11935         LDKUnsignedChannelAnnouncement orig_conv;
11936         orig_conv.inner = (void*)(orig & (~1));
11937         orig_conv.is_owned = false;
11938         LDKUnsignedChannelAnnouncement ret_var = UnsignedChannelAnnouncement_clone(&orig_conv);
11939         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11940         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11941         long ret_ref = (long)ret_var.inner;
11942         if (ret_var.is_owned) {
11943                 ret_ref |= 1;
11944         }
11945         return ret_ref;
11946 }
11947
11948 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1get_1features(JNIEnv *env, jclass clz, int64_t this_ptr) {
11949         LDKUnsignedChannelAnnouncement this_ptr_conv;
11950         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11951         this_ptr_conv.is_owned = false;
11952         LDKChannelFeatures ret_var = UnsignedChannelAnnouncement_get_features(&this_ptr_conv);
11953         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11954         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11955         long ret_ref = (long)ret_var.inner;
11956         if (ret_var.is_owned) {
11957                 ret_ref |= 1;
11958         }
11959         return ret_ref;
11960 }
11961
11962 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1set_1features(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
11963         LDKUnsignedChannelAnnouncement this_ptr_conv;
11964         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11965         this_ptr_conv.is_owned = false;
11966         LDKChannelFeatures val_conv;
11967         val_conv.inner = (void*)(val & (~1));
11968         val_conv.is_owned = (val & 1) || (val == 0);
11969         // Warning: we may need a move here but can't clone!
11970         UnsignedChannelAnnouncement_set_features(&this_ptr_conv, val_conv);
11971 }
11972
11973 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1get_1chain_1hash(JNIEnv *env, jclass clz, int64_t this_ptr) {
11974         LDKUnsignedChannelAnnouncement this_ptr_conv;
11975         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11976         this_ptr_conv.is_owned = false;
11977         int8_tArray ret_arr = (*env)->NewByteArray(env, 32);
11978         (*env)->SetByteArrayRegion(env, ret_arr, 0, 32, *UnsignedChannelAnnouncement_get_chain_hash(&this_ptr_conv));
11979         return ret_arr;
11980 }
11981
11982 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1set_1chain_1hash(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
11983         LDKUnsignedChannelAnnouncement this_ptr_conv;
11984         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11985         this_ptr_conv.is_owned = false;
11986         LDKThirtyTwoBytes val_ref;
11987         CHECK((*env)->GetArrayLength(env, val) == 32);
11988         (*env)->GetByteArrayRegion(env, val, 0, 32, val_ref.data);
11989         UnsignedChannelAnnouncement_set_chain_hash(&this_ptr_conv, val_ref);
11990 }
11991
11992 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1get_1short_1channel_1id(JNIEnv *env, jclass clz, int64_t this_ptr) {
11993         LDKUnsignedChannelAnnouncement this_ptr_conv;
11994         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11995         this_ptr_conv.is_owned = false;
11996         int64_t ret_val = UnsignedChannelAnnouncement_get_short_channel_id(&this_ptr_conv);
11997         return ret_val;
11998 }
11999
12000 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1set_1short_1channel_1id(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
12001         LDKUnsignedChannelAnnouncement this_ptr_conv;
12002         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12003         this_ptr_conv.is_owned = false;
12004         UnsignedChannelAnnouncement_set_short_channel_id(&this_ptr_conv, val);
12005 }
12006
12007 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1get_1node_1id_11(JNIEnv *env, jclass clz, int64_t this_ptr) {
12008         LDKUnsignedChannelAnnouncement this_ptr_conv;
12009         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12010         this_ptr_conv.is_owned = false;
12011         int8_tArray arg_arr = (*env)->NewByteArray(env, 33);
12012         (*env)->SetByteArrayRegion(env, arg_arr, 0, 33, UnsignedChannelAnnouncement_get_node_id_1(&this_ptr_conv).compressed_form);
12013         return arg_arr;
12014 }
12015
12016 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1set_1node_1id_11(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
12017         LDKUnsignedChannelAnnouncement this_ptr_conv;
12018         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12019         this_ptr_conv.is_owned = false;
12020         LDKPublicKey val_ref;
12021         CHECK((*env)->GetArrayLength(env, val) == 33);
12022         (*env)->GetByteArrayRegion(env, val, 0, 33, val_ref.compressed_form);
12023         UnsignedChannelAnnouncement_set_node_id_1(&this_ptr_conv, val_ref);
12024 }
12025
12026 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1get_1node_1id_12(JNIEnv *env, jclass clz, int64_t this_ptr) {
12027         LDKUnsignedChannelAnnouncement this_ptr_conv;
12028         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12029         this_ptr_conv.is_owned = false;
12030         int8_tArray arg_arr = (*env)->NewByteArray(env, 33);
12031         (*env)->SetByteArrayRegion(env, arg_arr, 0, 33, UnsignedChannelAnnouncement_get_node_id_2(&this_ptr_conv).compressed_form);
12032         return arg_arr;
12033 }
12034
12035 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1set_1node_1id_12(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
12036         LDKUnsignedChannelAnnouncement this_ptr_conv;
12037         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12038         this_ptr_conv.is_owned = false;
12039         LDKPublicKey val_ref;
12040         CHECK((*env)->GetArrayLength(env, val) == 33);
12041         (*env)->GetByteArrayRegion(env, val, 0, 33, val_ref.compressed_form);
12042         UnsignedChannelAnnouncement_set_node_id_2(&this_ptr_conv, val_ref);
12043 }
12044
12045 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1get_1bitcoin_1key_11(JNIEnv *env, jclass clz, int64_t this_ptr) {
12046         LDKUnsignedChannelAnnouncement this_ptr_conv;
12047         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12048         this_ptr_conv.is_owned = false;
12049         int8_tArray arg_arr = (*env)->NewByteArray(env, 33);
12050         (*env)->SetByteArrayRegion(env, arg_arr, 0, 33, UnsignedChannelAnnouncement_get_bitcoin_key_1(&this_ptr_conv).compressed_form);
12051         return arg_arr;
12052 }
12053
12054 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1set_1bitcoin_1key_11(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
12055         LDKUnsignedChannelAnnouncement this_ptr_conv;
12056         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12057         this_ptr_conv.is_owned = false;
12058         LDKPublicKey val_ref;
12059         CHECK((*env)->GetArrayLength(env, val) == 33);
12060         (*env)->GetByteArrayRegion(env, val, 0, 33, val_ref.compressed_form);
12061         UnsignedChannelAnnouncement_set_bitcoin_key_1(&this_ptr_conv, val_ref);
12062 }
12063
12064 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1get_1bitcoin_1key_12(JNIEnv *env, jclass clz, int64_t this_ptr) {
12065         LDKUnsignedChannelAnnouncement this_ptr_conv;
12066         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12067         this_ptr_conv.is_owned = false;
12068         int8_tArray arg_arr = (*env)->NewByteArray(env, 33);
12069         (*env)->SetByteArrayRegion(env, arg_arr, 0, 33, UnsignedChannelAnnouncement_get_bitcoin_key_2(&this_ptr_conv).compressed_form);
12070         return arg_arr;
12071 }
12072
12073 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1set_1bitcoin_1key_12(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
12074         LDKUnsignedChannelAnnouncement this_ptr_conv;
12075         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12076         this_ptr_conv.is_owned = false;
12077         LDKPublicKey val_ref;
12078         CHECK((*env)->GetArrayLength(env, val) == 33);
12079         (*env)->GetByteArrayRegion(env, val, 0, 33, val_ref.compressed_form);
12080         UnsignedChannelAnnouncement_set_bitcoin_key_2(&this_ptr_conv, val_ref);
12081 }
12082
12083 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelAnnouncement_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
12084         LDKChannelAnnouncement this_ptr_conv;
12085         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12086         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12087         ChannelAnnouncement_free(this_ptr_conv);
12088 }
12089
12090 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelAnnouncement_1clone(JNIEnv *env, jclass clz, int64_t orig) {
12091         LDKChannelAnnouncement orig_conv;
12092         orig_conv.inner = (void*)(orig & (~1));
12093         orig_conv.is_owned = false;
12094         LDKChannelAnnouncement ret_var = ChannelAnnouncement_clone(&orig_conv);
12095         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12096         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12097         long ret_ref = (long)ret_var.inner;
12098         if (ret_var.is_owned) {
12099                 ret_ref |= 1;
12100         }
12101         return ret_ref;
12102 }
12103
12104 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_ChannelAnnouncement_1get_1node_1signature_11(JNIEnv *env, jclass clz, int64_t this_ptr) {
12105         LDKChannelAnnouncement this_ptr_conv;
12106         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12107         this_ptr_conv.is_owned = false;
12108         int8_tArray arg_arr = (*env)->NewByteArray(env, 64);
12109         (*env)->SetByteArrayRegion(env, arg_arr, 0, 64, ChannelAnnouncement_get_node_signature_1(&this_ptr_conv).compact_form);
12110         return arg_arr;
12111 }
12112
12113 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelAnnouncement_1set_1node_1signature_11(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
12114         LDKChannelAnnouncement this_ptr_conv;
12115         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12116         this_ptr_conv.is_owned = false;
12117         LDKSignature val_ref;
12118         CHECK((*env)->GetArrayLength(env, val) == 64);
12119         (*env)->GetByteArrayRegion(env, val, 0, 64, val_ref.compact_form);
12120         ChannelAnnouncement_set_node_signature_1(&this_ptr_conv, val_ref);
12121 }
12122
12123 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_ChannelAnnouncement_1get_1node_1signature_12(JNIEnv *env, jclass clz, int64_t this_ptr) {
12124         LDKChannelAnnouncement this_ptr_conv;
12125         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12126         this_ptr_conv.is_owned = false;
12127         int8_tArray arg_arr = (*env)->NewByteArray(env, 64);
12128         (*env)->SetByteArrayRegion(env, arg_arr, 0, 64, ChannelAnnouncement_get_node_signature_2(&this_ptr_conv).compact_form);
12129         return arg_arr;
12130 }
12131
12132 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelAnnouncement_1set_1node_1signature_12(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
12133         LDKChannelAnnouncement this_ptr_conv;
12134         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12135         this_ptr_conv.is_owned = false;
12136         LDKSignature val_ref;
12137         CHECK((*env)->GetArrayLength(env, val) == 64);
12138         (*env)->GetByteArrayRegion(env, val, 0, 64, val_ref.compact_form);
12139         ChannelAnnouncement_set_node_signature_2(&this_ptr_conv, val_ref);
12140 }
12141
12142 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_ChannelAnnouncement_1get_1bitcoin_1signature_11(JNIEnv *env, jclass clz, int64_t this_ptr) {
12143         LDKChannelAnnouncement this_ptr_conv;
12144         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12145         this_ptr_conv.is_owned = false;
12146         int8_tArray arg_arr = (*env)->NewByteArray(env, 64);
12147         (*env)->SetByteArrayRegion(env, arg_arr, 0, 64, ChannelAnnouncement_get_bitcoin_signature_1(&this_ptr_conv).compact_form);
12148         return arg_arr;
12149 }
12150
12151 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelAnnouncement_1set_1bitcoin_1signature_11(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
12152         LDKChannelAnnouncement this_ptr_conv;
12153         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12154         this_ptr_conv.is_owned = false;
12155         LDKSignature val_ref;
12156         CHECK((*env)->GetArrayLength(env, val) == 64);
12157         (*env)->GetByteArrayRegion(env, val, 0, 64, val_ref.compact_form);
12158         ChannelAnnouncement_set_bitcoin_signature_1(&this_ptr_conv, val_ref);
12159 }
12160
12161 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_ChannelAnnouncement_1get_1bitcoin_1signature_12(JNIEnv *env, jclass clz, int64_t this_ptr) {
12162         LDKChannelAnnouncement this_ptr_conv;
12163         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12164         this_ptr_conv.is_owned = false;
12165         int8_tArray arg_arr = (*env)->NewByteArray(env, 64);
12166         (*env)->SetByteArrayRegion(env, arg_arr, 0, 64, ChannelAnnouncement_get_bitcoin_signature_2(&this_ptr_conv).compact_form);
12167         return arg_arr;
12168 }
12169
12170 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelAnnouncement_1set_1bitcoin_1signature_12(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
12171         LDKChannelAnnouncement this_ptr_conv;
12172         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12173         this_ptr_conv.is_owned = false;
12174         LDKSignature val_ref;
12175         CHECK((*env)->GetArrayLength(env, val) == 64);
12176         (*env)->GetByteArrayRegion(env, val, 0, 64, val_ref.compact_form);
12177         ChannelAnnouncement_set_bitcoin_signature_2(&this_ptr_conv, val_ref);
12178 }
12179
12180 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelAnnouncement_1get_1contents(JNIEnv *env, jclass clz, int64_t this_ptr) {
12181         LDKChannelAnnouncement this_ptr_conv;
12182         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12183         this_ptr_conv.is_owned = false;
12184         LDKUnsignedChannelAnnouncement ret_var = ChannelAnnouncement_get_contents(&this_ptr_conv);
12185         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12186         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12187         long ret_ref = (long)ret_var.inner;
12188         if (ret_var.is_owned) {
12189                 ret_ref |= 1;
12190         }
12191         return ret_ref;
12192 }
12193
12194 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelAnnouncement_1set_1contents(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
12195         LDKChannelAnnouncement this_ptr_conv;
12196         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12197         this_ptr_conv.is_owned = false;
12198         LDKUnsignedChannelAnnouncement val_conv;
12199         val_conv.inner = (void*)(val & (~1));
12200         val_conv.is_owned = (val & 1) || (val == 0);
12201         if (val_conv.inner != NULL)
12202                 val_conv = UnsignedChannelAnnouncement_clone(&val_conv);
12203         ChannelAnnouncement_set_contents(&this_ptr_conv, val_conv);
12204 }
12205
12206 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) {
12207         LDKSignature node_signature_1_arg_ref;
12208         CHECK((*env)->GetArrayLength(env, node_signature_1_arg) == 64);
12209         (*env)->GetByteArrayRegion(env, node_signature_1_arg, 0, 64, node_signature_1_arg_ref.compact_form);
12210         LDKSignature node_signature_2_arg_ref;
12211         CHECK((*env)->GetArrayLength(env, node_signature_2_arg) == 64);
12212         (*env)->GetByteArrayRegion(env, node_signature_2_arg, 0, 64, node_signature_2_arg_ref.compact_form);
12213         LDKSignature bitcoin_signature_1_arg_ref;
12214         CHECK((*env)->GetArrayLength(env, bitcoin_signature_1_arg) == 64);
12215         (*env)->GetByteArrayRegion(env, bitcoin_signature_1_arg, 0, 64, bitcoin_signature_1_arg_ref.compact_form);
12216         LDKSignature bitcoin_signature_2_arg_ref;
12217         CHECK((*env)->GetArrayLength(env, bitcoin_signature_2_arg) == 64);
12218         (*env)->GetByteArrayRegion(env, bitcoin_signature_2_arg, 0, 64, bitcoin_signature_2_arg_ref.compact_form);
12219         LDKUnsignedChannelAnnouncement contents_arg_conv;
12220         contents_arg_conv.inner = (void*)(contents_arg & (~1));
12221         contents_arg_conv.is_owned = (contents_arg & 1) || (contents_arg == 0);
12222         if (contents_arg_conv.inner != NULL)
12223                 contents_arg_conv = UnsignedChannelAnnouncement_clone(&contents_arg_conv);
12224         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);
12225         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12226         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12227         long ret_ref = (long)ret_var.inner;
12228         if (ret_var.is_owned) {
12229                 ret_ref |= 1;
12230         }
12231         return ret_ref;
12232 }
12233
12234 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
12235         LDKUnsignedChannelUpdate this_ptr_conv;
12236         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12237         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12238         UnsignedChannelUpdate_free(this_ptr_conv);
12239 }
12240
12241 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1clone(JNIEnv *env, jclass clz, int64_t orig) {
12242         LDKUnsignedChannelUpdate orig_conv;
12243         orig_conv.inner = (void*)(orig & (~1));
12244         orig_conv.is_owned = false;
12245         LDKUnsignedChannelUpdate ret_var = UnsignedChannelUpdate_clone(&orig_conv);
12246         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12247         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12248         long ret_ref = (long)ret_var.inner;
12249         if (ret_var.is_owned) {
12250                 ret_ref |= 1;
12251         }
12252         return ret_ref;
12253 }
12254
12255 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1get_1chain_1hash(JNIEnv *env, jclass clz, int64_t this_ptr) {
12256         LDKUnsignedChannelUpdate this_ptr_conv;
12257         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12258         this_ptr_conv.is_owned = false;
12259         int8_tArray ret_arr = (*env)->NewByteArray(env, 32);
12260         (*env)->SetByteArrayRegion(env, ret_arr, 0, 32, *UnsignedChannelUpdate_get_chain_hash(&this_ptr_conv));
12261         return ret_arr;
12262 }
12263
12264 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1set_1chain_1hash(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
12265         LDKUnsignedChannelUpdate this_ptr_conv;
12266         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12267         this_ptr_conv.is_owned = false;
12268         LDKThirtyTwoBytes val_ref;
12269         CHECK((*env)->GetArrayLength(env, val) == 32);
12270         (*env)->GetByteArrayRegion(env, val, 0, 32, val_ref.data);
12271         UnsignedChannelUpdate_set_chain_hash(&this_ptr_conv, val_ref);
12272 }
12273
12274 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1get_1short_1channel_1id(JNIEnv *env, jclass clz, int64_t this_ptr) {
12275         LDKUnsignedChannelUpdate this_ptr_conv;
12276         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12277         this_ptr_conv.is_owned = false;
12278         int64_t ret_val = UnsignedChannelUpdate_get_short_channel_id(&this_ptr_conv);
12279         return ret_val;
12280 }
12281
12282 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1set_1short_1channel_1id(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
12283         LDKUnsignedChannelUpdate this_ptr_conv;
12284         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12285         this_ptr_conv.is_owned = false;
12286         UnsignedChannelUpdate_set_short_channel_id(&this_ptr_conv, val);
12287 }
12288
12289 JNIEXPORT int32_t JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1get_1timestamp(JNIEnv *env, jclass clz, int64_t this_ptr) {
12290         LDKUnsignedChannelUpdate this_ptr_conv;
12291         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12292         this_ptr_conv.is_owned = false;
12293         int32_t ret_val = UnsignedChannelUpdate_get_timestamp(&this_ptr_conv);
12294         return ret_val;
12295 }
12296
12297 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1set_1timestamp(JNIEnv *env, jclass clz, int64_t this_ptr, int32_t val) {
12298         LDKUnsignedChannelUpdate this_ptr_conv;
12299         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12300         this_ptr_conv.is_owned = false;
12301         UnsignedChannelUpdate_set_timestamp(&this_ptr_conv, val);
12302 }
12303
12304 JNIEXPORT int8_t JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1get_1flags(JNIEnv *env, jclass clz, int64_t this_ptr) {
12305         LDKUnsignedChannelUpdate this_ptr_conv;
12306         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12307         this_ptr_conv.is_owned = false;
12308         int8_t ret_val = UnsignedChannelUpdate_get_flags(&this_ptr_conv);
12309         return ret_val;
12310 }
12311
12312 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1set_1flags(JNIEnv *env, jclass clz, int64_t this_ptr, int8_t val) {
12313         LDKUnsignedChannelUpdate this_ptr_conv;
12314         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12315         this_ptr_conv.is_owned = false;
12316         UnsignedChannelUpdate_set_flags(&this_ptr_conv, val);
12317 }
12318
12319 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1get_1cltv_1expiry_1delta(JNIEnv *env, jclass clz, int64_t this_ptr) {
12320         LDKUnsignedChannelUpdate this_ptr_conv;
12321         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12322         this_ptr_conv.is_owned = false;
12323         jshort ret_val = UnsignedChannelUpdate_get_cltv_expiry_delta(&this_ptr_conv);
12324         return ret_val;
12325 }
12326
12327 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1set_1cltv_1expiry_1delta(JNIEnv *env, jclass clz, int64_t this_ptr, jshort val) {
12328         LDKUnsignedChannelUpdate this_ptr_conv;
12329         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12330         this_ptr_conv.is_owned = false;
12331         UnsignedChannelUpdate_set_cltv_expiry_delta(&this_ptr_conv, val);
12332 }
12333
12334 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1get_1htlc_1minimum_1msat(JNIEnv *env, jclass clz, int64_t this_ptr) {
12335         LDKUnsignedChannelUpdate this_ptr_conv;
12336         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12337         this_ptr_conv.is_owned = false;
12338         int64_t ret_val = UnsignedChannelUpdate_get_htlc_minimum_msat(&this_ptr_conv);
12339         return ret_val;
12340 }
12341
12342 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1set_1htlc_1minimum_1msat(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
12343         LDKUnsignedChannelUpdate this_ptr_conv;
12344         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12345         this_ptr_conv.is_owned = false;
12346         UnsignedChannelUpdate_set_htlc_minimum_msat(&this_ptr_conv, val);
12347 }
12348
12349 JNIEXPORT int32_t JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1get_1fee_1base_1msat(JNIEnv *env, jclass clz, int64_t this_ptr) {
12350         LDKUnsignedChannelUpdate this_ptr_conv;
12351         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12352         this_ptr_conv.is_owned = false;
12353         int32_t ret_val = UnsignedChannelUpdate_get_fee_base_msat(&this_ptr_conv);
12354         return ret_val;
12355 }
12356
12357 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1set_1fee_1base_1msat(JNIEnv *env, jclass clz, int64_t this_ptr, int32_t val) {
12358         LDKUnsignedChannelUpdate this_ptr_conv;
12359         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12360         this_ptr_conv.is_owned = false;
12361         UnsignedChannelUpdate_set_fee_base_msat(&this_ptr_conv, val);
12362 }
12363
12364 JNIEXPORT int32_t JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1get_1fee_1proportional_1millionths(JNIEnv *env, jclass clz, int64_t this_ptr) {
12365         LDKUnsignedChannelUpdate this_ptr_conv;
12366         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12367         this_ptr_conv.is_owned = false;
12368         int32_t ret_val = UnsignedChannelUpdate_get_fee_proportional_millionths(&this_ptr_conv);
12369         return ret_val;
12370 }
12371
12372 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1set_1fee_1proportional_1millionths(JNIEnv *env, jclass clz, int64_t this_ptr, int32_t val) {
12373         LDKUnsignedChannelUpdate this_ptr_conv;
12374         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12375         this_ptr_conv.is_owned = false;
12376         UnsignedChannelUpdate_set_fee_proportional_millionths(&this_ptr_conv, val);
12377 }
12378
12379 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelUpdate_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
12380         LDKChannelUpdate this_ptr_conv;
12381         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12382         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12383         ChannelUpdate_free(this_ptr_conv);
12384 }
12385
12386 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelUpdate_1clone(JNIEnv *env, jclass clz, int64_t orig) {
12387         LDKChannelUpdate orig_conv;
12388         orig_conv.inner = (void*)(orig & (~1));
12389         orig_conv.is_owned = false;
12390         LDKChannelUpdate ret_var = ChannelUpdate_clone(&orig_conv);
12391         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12392         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12393         long ret_ref = (long)ret_var.inner;
12394         if (ret_var.is_owned) {
12395                 ret_ref |= 1;
12396         }
12397         return ret_ref;
12398 }
12399
12400 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_ChannelUpdate_1get_1signature(JNIEnv *env, jclass clz, int64_t this_ptr) {
12401         LDKChannelUpdate this_ptr_conv;
12402         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12403         this_ptr_conv.is_owned = false;
12404         int8_tArray arg_arr = (*env)->NewByteArray(env, 64);
12405         (*env)->SetByteArrayRegion(env, arg_arr, 0, 64, ChannelUpdate_get_signature(&this_ptr_conv).compact_form);
12406         return arg_arr;
12407 }
12408
12409 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelUpdate_1set_1signature(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
12410         LDKChannelUpdate this_ptr_conv;
12411         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12412         this_ptr_conv.is_owned = false;
12413         LDKSignature val_ref;
12414         CHECK((*env)->GetArrayLength(env, val) == 64);
12415         (*env)->GetByteArrayRegion(env, val, 0, 64, val_ref.compact_form);
12416         ChannelUpdate_set_signature(&this_ptr_conv, val_ref);
12417 }
12418
12419 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelUpdate_1get_1contents(JNIEnv *env, jclass clz, int64_t this_ptr) {
12420         LDKChannelUpdate this_ptr_conv;
12421         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12422         this_ptr_conv.is_owned = false;
12423         LDKUnsignedChannelUpdate ret_var = ChannelUpdate_get_contents(&this_ptr_conv);
12424         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12425         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12426         long ret_ref = (long)ret_var.inner;
12427         if (ret_var.is_owned) {
12428                 ret_ref |= 1;
12429         }
12430         return ret_ref;
12431 }
12432
12433 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelUpdate_1set_1contents(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
12434         LDKChannelUpdate this_ptr_conv;
12435         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12436         this_ptr_conv.is_owned = false;
12437         LDKUnsignedChannelUpdate val_conv;
12438         val_conv.inner = (void*)(val & (~1));
12439         val_conv.is_owned = (val & 1) || (val == 0);
12440         if (val_conv.inner != NULL)
12441                 val_conv = UnsignedChannelUpdate_clone(&val_conv);
12442         ChannelUpdate_set_contents(&this_ptr_conv, val_conv);
12443 }
12444
12445 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelUpdate_1new(JNIEnv *env, jclass clz, int8_tArray signature_arg, int64_t contents_arg) {
12446         LDKSignature signature_arg_ref;
12447         CHECK((*env)->GetArrayLength(env, signature_arg) == 64);
12448         (*env)->GetByteArrayRegion(env, signature_arg, 0, 64, signature_arg_ref.compact_form);
12449         LDKUnsignedChannelUpdate contents_arg_conv;
12450         contents_arg_conv.inner = (void*)(contents_arg & (~1));
12451         contents_arg_conv.is_owned = (contents_arg & 1) || (contents_arg == 0);
12452         if (contents_arg_conv.inner != NULL)
12453                 contents_arg_conv = UnsignedChannelUpdate_clone(&contents_arg_conv);
12454         LDKChannelUpdate ret_var = ChannelUpdate_new(signature_arg_ref, contents_arg_conv);
12455         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12456         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12457         long ret_ref = (long)ret_var.inner;
12458         if (ret_var.is_owned) {
12459                 ret_ref |= 1;
12460         }
12461         return ret_ref;
12462 }
12463
12464 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_QueryChannelRange_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
12465         LDKQueryChannelRange this_ptr_conv;
12466         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12467         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12468         QueryChannelRange_free(this_ptr_conv);
12469 }
12470
12471 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_QueryChannelRange_1clone(JNIEnv *env, jclass clz, int64_t orig) {
12472         LDKQueryChannelRange orig_conv;
12473         orig_conv.inner = (void*)(orig & (~1));
12474         orig_conv.is_owned = false;
12475         LDKQueryChannelRange ret_var = QueryChannelRange_clone(&orig_conv);
12476         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12477         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12478         long ret_ref = (long)ret_var.inner;
12479         if (ret_var.is_owned) {
12480                 ret_ref |= 1;
12481         }
12482         return ret_ref;
12483 }
12484
12485 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_QueryChannelRange_1get_1chain_1hash(JNIEnv *env, jclass clz, int64_t this_ptr) {
12486         LDKQueryChannelRange this_ptr_conv;
12487         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12488         this_ptr_conv.is_owned = false;
12489         int8_tArray ret_arr = (*env)->NewByteArray(env, 32);
12490         (*env)->SetByteArrayRegion(env, ret_arr, 0, 32, *QueryChannelRange_get_chain_hash(&this_ptr_conv));
12491         return ret_arr;
12492 }
12493
12494 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_QueryChannelRange_1set_1chain_1hash(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
12495         LDKQueryChannelRange this_ptr_conv;
12496         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12497         this_ptr_conv.is_owned = false;
12498         LDKThirtyTwoBytes val_ref;
12499         CHECK((*env)->GetArrayLength(env, val) == 32);
12500         (*env)->GetByteArrayRegion(env, val, 0, 32, val_ref.data);
12501         QueryChannelRange_set_chain_hash(&this_ptr_conv, val_ref);
12502 }
12503
12504 JNIEXPORT int32_t JNICALL Java_org_ldk_impl_bindings_QueryChannelRange_1get_1first_1blocknum(JNIEnv *env, jclass clz, int64_t this_ptr) {
12505         LDKQueryChannelRange this_ptr_conv;
12506         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12507         this_ptr_conv.is_owned = false;
12508         int32_t ret_val = QueryChannelRange_get_first_blocknum(&this_ptr_conv);
12509         return ret_val;
12510 }
12511
12512 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_QueryChannelRange_1set_1first_1blocknum(JNIEnv *env, jclass clz, int64_t this_ptr, int32_t val) {
12513         LDKQueryChannelRange this_ptr_conv;
12514         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12515         this_ptr_conv.is_owned = false;
12516         QueryChannelRange_set_first_blocknum(&this_ptr_conv, val);
12517 }
12518
12519 JNIEXPORT int32_t JNICALL Java_org_ldk_impl_bindings_QueryChannelRange_1get_1number_1of_1blocks(JNIEnv *env, jclass clz, int64_t this_ptr) {
12520         LDKQueryChannelRange this_ptr_conv;
12521         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12522         this_ptr_conv.is_owned = false;
12523         int32_t ret_val = QueryChannelRange_get_number_of_blocks(&this_ptr_conv);
12524         return ret_val;
12525 }
12526
12527 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_QueryChannelRange_1set_1number_1of_1blocks(JNIEnv *env, jclass clz, int64_t this_ptr, int32_t val) {
12528         LDKQueryChannelRange this_ptr_conv;
12529         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12530         this_ptr_conv.is_owned = false;
12531         QueryChannelRange_set_number_of_blocks(&this_ptr_conv, val);
12532 }
12533
12534 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) {
12535         LDKThirtyTwoBytes chain_hash_arg_ref;
12536         CHECK((*env)->GetArrayLength(env, chain_hash_arg) == 32);
12537         (*env)->GetByteArrayRegion(env, chain_hash_arg, 0, 32, chain_hash_arg_ref.data);
12538         LDKQueryChannelRange ret_var = QueryChannelRange_new(chain_hash_arg_ref, first_blocknum_arg, number_of_blocks_arg);
12539         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12540         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12541         long ret_ref = (long)ret_var.inner;
12542         if (ret_var.is_owned) {
12543                 ret_ref |= 1;
12544         }
12545         return ret_ref;
12546 }
12547
12548 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ReplyChannelRange_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
12549         LDKReplyChannelRange this_ptr_conv;
12550         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12551         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12552         ReplyChannelRange_free(this_ptr_conv);
12553 }
12554
12555 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ReplyChannelRange_1clone(JNIEnv *env, jclass clz, int64_t orig) {
12556         LDKReplyChannelRange orig_conv;
12557         orig_conv.inner = (void*)(orig & (~1));
12558         orig_conv.is_owned = false;
12559         LDKReplyChannelRange ret_var = ReplyChannelRange_clone(&orig_conv);
12560         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12561         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12562         long ret_ref = (long)ret_var.inner;
12563         if (ret_var.is_owned) {
12564                 ret_ref |= 1;
12565         }
12566         return ret_ref;
12567 }
12568
12569 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_ReplyChannelRange_1get_1chain_1hash(JNIEnv *env, jclass clz, int64_t this_ptr) {
12570         LDKReplyChannelRange this_ptr_conv;
12571         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12572         this_ptr_conv.is_owned = false;
12573         int8_tArray ret_arr = (*env)->NewByteArray(env, 32);
12574         (*env)->SetByteArrayRegion(env, ret_arr, 0, 32, *ReplyChannelRange_get_chain_hash(&this_ptr_conv));
12575         return ret_arr;
12576 }
12577
12578 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ReplyChannelRange_1set_1chain_1hash(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
12579         LDKReplyChannelRange this_ptr_conv;
12580         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12581         this_ptr_conv.is_owned = false;
12582         LDKThirtyTwoBytes val_ref;
12583         CHECK((*env)->GetArrayLength(env, val) == 32);
12584         (*env)->GetByteArrayRegion(env, val, 0, 32, val_ref.data);
12585         ReplyChannelRange_set_chain_hash(&this_ptr_conv, val_ref);
12586 }
12587
12588 JNIEXPORT int32_t JNICALL Java_org_ldk_impl_bindings_ReplyChannelRange_1get_1first_1blocknum(JNIEnv *env, jclass clz, int64_t this_ptr) {
12589         LDKReplyChannelRange this_ptr_conv;
12590         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12591         this_ptr_conv.is_owned = false;
12592         int32_t ret_val = ReplyChannelRange_get_first_blocknum(&this_ptr_conv);
12593         return ret_val;
12594 }
12595
12596 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ReplyChannelRange_1set_1first_1blocknum(JNIEnv *env, jclass clz, int64_t this_ptr, int32_t val) {
12597         LDKReplyChannelRange this_ptr_conv;
12598         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12599         this_ptr_conv.is_owned = false;
12600         ReplyChannelRange_set_first_blocknum(&this_ptr_conv, val);
12601 }
12602
12603 JNIEXPORT int32_t JNICALL Java_org_ldk_impl_bindings_ReplyChannelRange_1get_1number_1of_1blocks(JNIEnv *env, jclass clz, int64_t this_ptr) {
12604         LDKReplyChannelRange this_ptr_conv;
12605         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12606         this_ptr_conv.is_owned = false;
12607         int32_t ret_val = ReplyChannelRange_get_number_of_blocks(&this_ptr_conv);
12608         return ret_val;
12609 }
12610
12611 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ReplyChannelRange_1set_1number_1of_1blocks(JNIEnv *env, jclass clz, int64_t this_ptr, int32_t val) {
12612         LDKReplyChannelRange this_ptr_conv;
12613         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12614         this_ptr_conv.is_owned = false;
12615         ReplyChannelRange_set_number_of_blocks(&this_ptr_conv, val);
12616 }
12617
12618 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_ReplyChannelRange_1get_1full_1information(JNIEnv *env, jclass clz, int64_t this_ptr) {
12619         LDKReplyChannelRange this_ptr_conv;
12620         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12621         this_ptr_conv.is_owned = false;
12622         jboolean ret_val = ReplyChannelRange_get_full_information(&this_ptr_conv);
12623         return ret_val;
12624 }
12625
12626 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ReplyChannelRange_1set_1full_1information(JNIEnv *env, jclass clz, int64_t this_ptr, jboolean val) {
12627         LDKReplyChannelRange this_ptr_conv;
12628         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12629         this_ptr_conv.is_owned = false;
12630         ReplyChannelRange_set_full_information(&this_ptr_conv, val);
12631 }
12632
12633 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ReplyChannelRange_1set_1short_1channel_1ids(JNIEnv *env, jclass clz, int64_t this_ptr, int64_tArray val) {
12634         LDKReplyChannelRange this_ptr_conv;
12635         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12636         this_ptr_conv.is_owned = false;
12637         LDKCVec_u64Z val_constr;
12638         val_constr.datalen = (*env)->GetArrayLength(env, val);
12639         if (val_constr.datalen > 0)
12640                 val_constr.data = MALLOC(val_constr.datalen * sizeof(int64_t), "LDKCVec_u64Z Elements");
12641         else
12642                 val_constr.data = NULL;
12643         int64_t* val_vals = (*env)->GetLongArrayElements (env, val, NULL);
12644         for (size_t g = 0; g < val_constr.datalen; g++) {
12645                 int64_t arr_conv_6 = val_vals[g];
12646                 val_constr.data[g] = arr_conv_6;
12647         }
12648         (*env)->ReleaseLongArrayElements(env, val, val_vals, 0);
12649         ReplyChannelRange_set_short_channel_ids(&this_ptr_conv, val_constr);
12650 }
12651
12652 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) {
12653         LDKThirtyTwoBytes chain_hash_arg_ref;
12654         CHECK((*env)->GetArrayLength(env, chain_hash_arg) == 32);
12655         (*env)->GetByteArrayRegion(env, chain_hash_arg, 0, 32, chain_hash_arg_ref.data);
12656         LDKCVec_u64Z short_channel_ids_arg_constr;
12657         short_channel_ids_arg_constr.datalen = (*env)->GetArrayLength(env, short_channel_ids_arg);
12658         if (short_channel_ids_arg_constr.datalen > 0)
12659                 short_channel_ids_arg_constr.data = MALLOC(short_channel_ids_arg_constr.datalen * sizeof(int64_t), "LDKCVec_u64Z Elements");
12660         else
12661                 short_channel_ids_arg_constr.data = NULL;
12662         int64_t* short_channel_ids_arg_vals = (*env)->GetLongArrayElements (env, short_channel_ids_arg, NULL);
12663         for (size_t g = 0; g < short_channel_ids_arg_constr.datalen; g++) {
12664                 int64_t arr_conv_6 = short_channel_ids_arg_vals[g];
12665                 short_channel_ids_arg_constr.data[g] = arr_conv_6;
12666         }
12667         (*env)->ReleaseLongArrayElements(env, short_channel_ids_arg, short_channel_ids_arg_vals, 0);
12668         LDKReplyChannelRange ret_var = ReplyChannelRange_new(chain_hash_arg_ref, first_blocknum_arg, number_of_blocks_arg, full_information_arg, short_channel_ids_arg_constr);
12669         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12670         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12671         long ret_ref = (long)ret_var.inner;
12672         if (ret_var.is_owned) {
12673                 ret_ref |= 1;
12674         }
12675         return ret_ref;
12676 }
12677
12678 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_QueryShortChannelIds_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
12679         LDKQueryShortChannelIds this_ptr_conv;
12680         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12681         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12682         QueryShortChannelIds_free(this_ptr_conv);
12683 }
12684
12685 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_QueryShortChannelIds_1clone(JNIEnv *env, jclass clz, int64_t orig) {
12686         LDKQueryShortChannelIds orig_conv;
12687         orig_conv.inner = (void*)(orig & (~1));
12688         orig_conv.is_owned = false;
12689         LDKQueryShortChannelIds ret_var = QueryShortChannelIds_clone(&orig_conv);
12690         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12691         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12692         long ret_ref = (long)ret_var.inner;
12693         if (ret_var.is_owned) {
12694                 ret_ref |= 1;
12695         }
12696         return ret_ref;
12697 }
12698
12699 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_QueryShortChannelIds_1get_1chain_1hash(JNIEnv *env, jclass clz, int64_t this_ptr) {
12700         LDKQueryShortChannelIds this_ptr_conv;
12701         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12702         this_ptr_conv.is_owned = false;
12703         int8_tArray ret_arr = (*env)->NewByteArray(env, 32);
12704         (*env)->SetByteArrayRegion(env, ret_arr, 0, 32, *QueryShortChannelIds_get_chain_hash(&this_ptr_conv));
12705         return ret_arr;
12706 }
12707
12708 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_QueryShortChannelIds_1set_1chain_1hash(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
12709         LDKQueryShortChannelIds this_ptr_conv;
12710         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12711         this_ptr_conv.is_owned = false;
12712         LDKThirtyTwoBytes val_ref;
12713         CHECK((*env)->GetArrayLength(env, val) == 32);
12714         (*env)->GetByteArrayRegion(env, val, 0, 32, val_ref.data);
12715         QueryShortChannelIds_set_chain_hash(&this_ptr_conv, val_ref);
12716 }
12717
12718 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_QueryShortChannelIds_1set_1short_1channel_1ids(JNIEnv *env, jclass clz, int64_t this_ptr, int64_tArray val) {
12719         LDKQueryShortChannelIds this_ptr_conv;
12720         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12721         this_ptr_conv.is_owned = false;
12722         LDKCVec_u64Z val_constr;
12723         val_constr.datalen = (*env)->GetArrayLength(env, val);
12724         if (val_constr.datalen > 0)
12725                 val_constr.data = MALLOC(val_constr.datalen * sizeof(int64_t), "LDKCVec_u64Z Elements");
12726         else
12727                 val_constr.data = NULL;
12728         int64_t* val_vals = (*env)->GetLongArrayElements (env, val, NULL);
12729         for (size_t g = 0; g < val_constr.datalen; g++) {
12730                 int64_t arr_conv_6 = val_vals[g];
12731                 val_constr.data[g] = arr_conv_6;
12732         }
12733         (*env)->ReleaseLongArrayElements(env, val, val_vals, 0);
12734         QueryShortChannelIds_set_short_channel_ids(&this_ptr_conv, val_constr);
12735 }
12736
12737 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) {
12738         LDKThirtyTwoBytes chain_hash_arg_ref;
12739         CHECK((*env)->GetArrayLength(env, chain_hash_arg) == 32);
12740         (*env)->GetByteArrayRegion(env, chain_hash_arg, 0, 32, chain_hash_arg_ref.data);
12741         LDKCVec_u64Z short_channel_ids_arg_constr;
12742         short_channel_ids_arg_constr.datalen = (*env)->GetArrayLength(env, short_channel_ids_arg);
12743         if (short_channel_ids_arg_constr.datalen > 0)
12744                 short_channel_ids_arg_constr.data = MALLOC(short_channel_ids_arg_constr.datalen * sizeof(int64_t), "LDKCVec_u64Z Elements");
12745         else
12746                 short_channel_ids_arg_constr.data = NULL;
12747         int64_t* short_channel_ids_arg_vals = (*env)->GetLongArrayElements (env, short_channel_ids_arg, NULL);
12748         for (size_t g = 0; g < short_channel_ids_arg_constr.datalen; g++) {
12749                 int64_t arr_conv_6 = short_channel_ids_arg_vals[g];
12750                 short_channel_ids_arg_constr.data[g] = arr_conv_6;
12751         }
12752         (*env)->ReleaseLongArrayElements(env, short_channel_ids_arg, short_channel_ids_arg_vals, 0);
12753         LDKQueryShortChannelIds ret_var = QueryShortChannelIds_new(chain_hash_arg_ref, short_channel_ids_arg_constr);
12754         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12755         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12756         long ret_ref = (long)ret_var.inner;
12757         if (ret_var.is_owned) {
12758                 ret_ref |= 1;
12759         }
12760         return ret_ref;
12761 }
12762
12763 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ReplyShortChannelIdsEnd_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
12764         LDKReplyShortChannelIdsEnd this_ptr_conv;
12765         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12766         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12767         ReplyShortChannelIdsEnd_free(this_ptr_conv);
12768 }
12769
12770 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ReplyShortChannelIdsEnd_1clone(JNIEnv *env, jclass clz, int64_t orig) {
12771         LDKReplyShortChannelIdsEnd orig_conv;
12772         orig_conv.inner = (void*)(orig & (~1));
12773         orig_conv.is_owned = false;
12774         LDKReplyShortChannelIdsEnd ret_var = ReplyShortChannelIdsEnd_clone(&orig_conv);
12775         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12776         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12777         long ret_ref = (long)ret_var.inner;
12778         if (ret_var.is_owned) {
12779                 ret_ref |= 1;
12780         }
12781         return ret_ref;
12782 }
12783
12784 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_ReplyShortChannelIdsEnd_1get_1chain_1hash(JNIEnv *env, jclass clz, int64_t this_ptr) {
12785         LDKReplyShortChannelIdsEnd this_ptr_conv;
12786         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12787         this_ptr_conv.is_owned = false;
12788         int8_tArray ret_arr = (*env)->NewByteArray(env, 32);
12789         (*env)->SetByteArrayRegion(env, ret_arr, 0, 32, *ReplyShortChannelIdsEnd_get_chain_hash(&this_ptr_conv));
12790         return ret_arr;
12791 }
12792
12793 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ReplyShortChannelIdsEnd_1set_1chain_1hash(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
12794         LDKReplyShortChannelIdsEnd this_ptr_conv;
12795         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12796         this_ptr_conv.is_owned = false;
12797         LDKThirtyTwoBytes val_ref;
12798         CHECK((*env)->GetArrayLength(env, val) == 32);
12799         (*env)->GetByteArrayRegion(env, val, 0, 32, val_ref.data);
12800         ReplyShortChannelIdsEnd_set_chain_hash(&this_ptr_conv, val_ref);
12801 }
12802
12803 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_ReplyShortChannelIdsEnd_1get_1full_1information(JNIEnv *env, jclass clz, int64_t this_ptr) {
12804         LDKReplyShortChannelIdsEnd this_ptr_conv;
12805         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12806         this_ptr_conv.is_owned = false;
12807         jboolean ret_val = ReplyShortChannelIdsEnd_get_full_information(&this_ptr_conv);
12808         return ret_val;
12809 }
12810
12811 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ReplyShortChannelIdsEnd_1set_1full_1information(JNIEnv *env, jclass clz, int64_t this_ptr, jboolean val) {
12812         LDKReplyShortChannelIdsEnd this_ptr_conv;
12813         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12814         this_ptr_conv.is_owned = false;
12815         ReplyShortChannelIdsEnd_set_full_information(&this_ptr_conv, val);
12816 }
12817
12818 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ReplyShortChannelIdsEnd_1new(JNIEnv *env, jclass clz, int8_tArray chain_hash_arg, jboolean full_information_arg) {
12819         LDKThirtyTwoBytes chain_hash_arg_ref;
12820         CHECK((*env)->GetArrayLength(env, chain_hash_arg) == 32);
12821         (*env)->GetByteArrayRegion(env, chain_hash_arg, 0, 32, chain_hash_arg_ref.data);
12822         LDKReplyShortChannelIdsEnd ret_var = ReplyShortChannelIdsEnd_new(chain_hash_arg_ref, full_information_arg);
12823         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12824         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12825         long ret_ref = (long)ret_var.inner;
12826         if (ret_var.is_owned) {
12827                 ret_ref |= 1;
12828         }
12829         return ret_ref;
12830 }
12831
12832 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_GossipTimestampFilter_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
12833         LDKGossipTimestampFilter this_ptr_conv;
12834         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12835         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12836         GossipTimestampFilter_free(this_ptr_conv);
12837 }
12838
12839 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_GossipTimestampFilter_1clone(JNIEnv *env, jclass clz, int64_t orig) {
12840         LDKGossipTimestampFilter orig_conv;
12841         orig_conv.inner = (void*)(orig & (~1));
12842         orig_conv.is_owned = false;
12843         LDKGossipTimestampFilter ret_var = GossipTimestampFilter_clone(&orig_conv);
12844         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12845         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12846         long ret_ref = (long)ret_var.inner;
12847         if (ret_var.is_owned) {
12848                 ret_ref |= 1;
12849         }
12850         return ret_ref;
12851 }
12852
12853 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_GossipTimestampFilter_1get_1chain_1hash(JNIEnv *env, jclass clz, int64_t this_ptr) {
12854         LDKGossipTimestampFilter this_ptr_conv;
12855         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12856         this_ptr_conv.is_owned = false;
12857         int8_tArray ret_arr = (*env)->NewByteArray(env, 32);
12858         (*env)->SetByteArrayRegion(env, ret_arr, 0, 32, *GossipTimestampFilter_get_chain_hash(&this_ptr_conv));
12859         return ret_arr;
12860 }
12861
12862 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_GossipTimestampFilter_1set_1chain_1hash(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
12863         LDKGossipTimestampFilter this_ptr_conv;
12864         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12865         this_ptr_conv.is_owned = false;
12866         LDKThirtyTwoBytes val_ref;
12867         CHECK((*env)->GetArrayLength(env, val) == 32);
12868         (*env)->GetByteArrayRegion(env, val, 0, 32, val_ref.data);
12869         GossipTimestampFilter_set_chain_hash(&this_ptr_conv, val_ref);
12870 }
12871
12872 JNIEXPORT int32_t JNICALL Java_org_ldk_impl_bindings_GossipTimestampFilter_1get_1first_1timestamp(JNIEnv *env, jclass clz, int64_t this_ptr) {
12873         LDKGossipTimestampFilter this_ptr_conv;
12874         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12875         this_ptr_conv.is_owned = false;
12876         int32_t ret_val = GossipTimestampFilter_get_first_timestamp(&this_ptr_conv);
12877         return ret_val;
12878 }
12879
12880 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_GossipTimestampFilter_1set_1first_1timestamp(JNIEnv *env, jclass clz, int64_t this_ptr, int32_t val) {
12881         LDKGossipTimestampFilter this_ptr_conv;
12882         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12883         this_ptr_conv.is_owned = false;
12884         GossipTimestampFilter_set_first_timestamp(&this_ptr_conv, val);
12885 }
12886
12887 JNIEXPORT int32_t JNICALL Java_org_ldk_impl_bindings_GossipTimestampFilter_1get_1timestamp_1range(JNIEnv *env, jclass clz, int64_t this_ptr) {
12888         LDKGossipTimestampFilter this_ptr_conv;
12889         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12890         this_ptr_conv.is_owned = false;
12891         int32_t ret_val = GossipTimestampFilter_get_timestamp_range(&this_ptr_conv);
12892         return ret_val;
12893 }
12894
12895 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_GossipTimestampFilter_1set_1timestamp_1range(JNIEnv *env, jclass clz, int64_t this_ptr, int32_t val) {
12896         LDKGossipTimestampFilter this_ptr_conv;
12897         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12898         this_ptr_conv.is_owned = false;
12899         GossipTimestampFilter_set_timestamp_range(&this_ptr_conv, val);
12900 }
12901
12902 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) {
12903         LDKThirtyTwoBytes chain_hash_arg_ref;
12904         CHECK((*env)->GetArrayLength(env, chain_hash_arg) == 32);
12905         (*env)->GetByteArrayRegion(env, chain_hash_arg, 0, 32, chain_hash_arg_ref.data);
12906         LDKGossipTimestampFilter ret_var = GossipTimestampFilter_new(chain_hash_arg_ref, first_timestamp_arg, timestamp_range_arg);
12907         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12908         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12909         long ret_ref = (long)ret_var.inner;
12910         if (ret_var.is_owned) {
12911                 ret_ref |= 1;
12912         }
12913         return ret_ref;
12914 }
12915
12916 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ErrorAction_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
12917         LDKErrorAction this_ptr_conv = *(LDKErrorAction*)this_ptr;
12918         FREE((void*)this_ptr);
12919         ErrorAction_free(this_ptr_conv);
12920 }
12921
12922 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ErrorAction_1clone(JNIEnv *env, jclass clz, int64_t orig) {
12923         LDKErrorAction* orig_conv = (LDKErrorAction*)orig;
12924         LDKErrorAction *ret_copy = MALLOC(sizeof(LDKErrorAction), "LDKErrorAction");
12925         *ret_copy = ErrorAction_clone(orig_conv);
12926         long ret_ref = (long)ret_copy;
12927         return ret_ref;
12928 }
12929
12930 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_LightningError_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
12931         LDKLightningError 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         LightningError_free(this_ptr_conv);
12935 }
12936
12937 JNIEXPORT jstring JNICALL Java_org_ldk_impl_bindings_LightningError_1get_1err(JNIEnv *env, jclass clz, int64_t this_ptr) {
12938         LDKLightningError this_ptr_conv;
12939         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12940         this_ptr_conv.is_owned = false;
12941         LDKStr _str = LightningError_get_err(&this_ptr_conv);
12942         char* _buf = MALLOC(_str.len + 1, "str conv buf");
12943         memcpy(_buf, _str.chars, _str.len);
12944         _buf[_str.len] = 0;
12945         jstring _conv = (*env)->NewStringUTF(env, _str.chars);
12946         FREE(_buf);
12947         return _conv;
12948 }
12949
12950 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_LightningError_1set_1err(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
12951         LDKLightningError this_ptr_conv;
12952         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12953         this_ptr_conv.is_owned = false;
12954         LDKCVec_u8Z val_ref;
12955         val_ref.datalen = (*env)->GetArrayLength(env, val);
12956         val_ref.data = MALLOC(val_ref.datalen, "LDKCVec_u8Z Bytes");
12957         (*env)->GetByteArrayRegion(env, val, 0, val_ref.datalen, val_ref.data);
12958         LightningError_set_err(&this_ptr_conv, val_ref);
12959 }
12960
12961 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LightningError_1get_1action(JNIEnv *env, jclass clz, int64_t this_ptr) {
12962         LDKLightningError this_ptr_conv;
12963         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12964         this_ptr_conv.is_owned = false;
12965         LDKErrorAction *ret_copy = MALLOC(sizeof(LDKErrorAction), "LDKErrorAction");
12966         *ret_copy = LightningError_get_action(&this_ptr_conv);
12967         long ret_ref = (long)ret_copy;
12968         return ret_ref;
12969 }
12970
12971 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_LightningError_1set_1action(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
12972         LDKLightningError this_ptr_conv;
12973         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12974         this_ptr_conv.is_owned = false;
12975         LDKErrorAction val_conv = *(LDKErrorAction*)val;
12976         FREE((void*)val);
12977         LightningError_set_action(&this_ptr_conv, val_conv);
12978 }
12979
12980 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LightningError_1new(JNIEnv *env, jclass clz, int8_tArray err_arg, int64_t action_arg) {
12981         LDKCVec_u8Z err_arg_ref;
12982         err_arg_ref.datalen = (*env)->GetArrayLength(env, err_arg);
12983         err_arg_ref.data = MALLOC(err_arg_ref.datalen, "LDKCVec_u8Z Bytes");
12984         (*env)->GetByteArrayRegion(env, err_arg, 0, err_arg_ref.datalen, err_arg_ref.data);
12985         LDKErrorAction action_arg_conv = *(LDKErrorAction*)action_arg;
12986         FREE((void*)action_arg);
12987         LDKLightningError ret_var = LightningError_new(err_arg_ref, action_arg_conv);
12988         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12989         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12990         long ret_ref = (long)ret_var.inner;
12991         if (ret_var.is_owned) {
12992                 ret_ref |= 1;
12993         }
12994         return ret_ref;
12995 }
12996
12997 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CommitmentUpdate_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
12998         LDKCommitmentUpdate this_ptr_conv;
12999         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13000         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13001         CommitmentUpdate_free(this_ptr_conv);
13002 }
13003
13004 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CommitmentUpdate_1clone(JNIEnv *env, jclass clz, int64_t orig) {
13005         LDKCommitmentUpdate orig_conv;
13006         orig_conv.inner = (void*)(orig & (~1));
13007         orig_conv.is_owned = false;
13008         LDKCommitmentUpdate ret_var = CommitmentUpdate_clone(&orig_conv);
13009         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13010         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13011         long ret_ref = (long)ret_var.inner;
13012         if (ret_var.is_owned) {
13013                 ret_ref |= 1;
13014         }
13015         return ret_ref;
13016 }
13017
13018 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CommitmentUpdate_1set_1update_1add_1htlcs(JNIEnv *env, jclass clz, int64_t this_ptr, int64_tArray val) {
13019         LDKCommitmentUpdate this_ptr_conv;
13020         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13021         this_ptr_conv.is_owned = false;
13022         LDKCVec_UpdateAddHTLCZ val_constr;
13023         val_constr.datalen = (*env)->GetArrayLength(env, val);
13024         if (val_constr.datalen > 0)
13025                 val_constr.data = MALLOC(val_constr.datalen * sizeof(LDKUpdateAddHTLC), "LDKCVec_UpdateAddHTLCZ Elements");
13026         else
13027                 val_constr.data = NULL;
13028         int64_t* val_vals = (*env)->GetLongArrayElements (env, val, NULL);
13029         for (size_t p = 0; p < val_constr.datalen; p++) {
13030                 int64_t arr_conv_15 = val_vals[p];
13031                 LDKUpdateAddHTLC arr_conv_15_conv;
13032                 arr_conv_15_conv.inner = (void*)(arr_conv_15 & (~1));
13033                 arr_conv_15_conv.is_owned = (arr_conv_15 & 1) || (arr_conv_15 == 0);
13034                 if (arr_conv_15_conv.inner != NULL)
13035                         arr_conv_15_conv = UpdateAddHTLC_clone(&arr_conv_15_conv);
13036                 val_constr.data[p] = arr_conv_15_conv;
13037         }
13038         (*env)->ReleaseLongArrayElements(env, val, val_vals, 0);
13039         CommitmentUpdate_set_update_add_htlcs(&this_ptr_conv, val_constr);
13040 }
13041
13042 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CommitmentUpdate_1set_1update_1fulfill_1htlcs(JNIEnv *env, jclass clz, int64_t this_ptr, int64_tArray val) {
13043         LDKCommitmentUpdate this_ptr_conv;
13044         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13045         this_ptr_conv.is_owned = false;
13046         LDKCVec_UpdateFulfillHTLCZ val_constr;
13047         val_constr.datalen = (*env)->GetArrayLength(env, val);
13048         if (val_constr.datalen > 0)
13049                 val_constr.data = MALLOC(val_constr.datalen * sizeof(LDKUpdateFulfillHTLC), "LDKCVec_UpdateFulfillHTLCZ Elements");
13050         else
13051                 val_constr.data = NULL;
13052         int64_t* val_vals = (*env)->GetLongArrayElements (env, val, NULL);
13053         for (size_t t = 0; t < val_constr.datalen; t++) {
13054                 int64_t arr_conv_19 = val_vals[t];
13055                 LDKUpdateFulfillHTLC arr_conv_19_conv;
13056                 arr_conv_19_conv.inner = (void*)(arr_conv_19 & (~1));
13057                 arr_conv_19_conv.is_owned = (arr_conv_19 & 1) || (arr_conv_19 == 0);
13058                 if (arr_conv_19_conv.inner != NULL)
13059                         arr_conv_19_conv = UpdateFulfillHTLC_clone(&arr_conv_19_conv);
13060                 val_constr.data[t] = arr_conv_19_conv;
13061         }
13062         (*env)->ReleaseLongArrayElements(env, val, val_vals, 0);
13063         CommitmentUpdate_set_update_fulfill_htlcs(&this_ptr_conv, val_constr);
13064 }
13065
13066 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CommitmentUpdate_1set_1update_1fail_1htlcs(JNIEnv *env, jclass clz, int64_t this_ptr, int64_tArray val) {
13067         LDKCommitmentUpdate this_ptr_conv;
13068         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13069         this_ptr_conv.is_owned = false;
13070         LDKCVec_UpdateFailHTLCZ val_constr;
13071         val_constr.datalen = (*env)->GetArrayLength(env, val);
13072         if (val_constr.datalen > 0)
13073                 val_constr.data = MALLOC(val_constr.datalen * sizeof(LDKUpdateFailHTLC), "LDKCVec_UpdateFailHTLCZ Elements");
13074         else
13075                 val_constr.data = NULL;
13076         int64_t* val_vals = (*env)->GetLongArrayElements (env, val, NULL);
13077         for (size_t q = 0; q < val_constr.datalen; q++) {
13078                 int64_t arr_conv_16 = val_vals[q];
13079                 LDKUpdateFailHTLC arr_conv_16_conv;
13080                 arr_conv_16_conv.inner = (void*)(arr_conv_16 & (~1));
13081                 arr_conv_16_conv.is_owned = (arr_conv_16 & 1) || (arr_conv_16 == 0);
13082                 if (arr_conv_16_conv.inner != NULL)
13083                         arr_conv_16_conv = UpdateFailHTLC_clone(&arr_conv_16_conv);
13084                 val_constr.data[q] = arr_conv_16_conv;
13085         }
13086         (*env)->ReleaseLongArrayElements(env, val, val_vals, 0);
13087         CommitmentUpdate_set_update_fail_htlcs(&this_ptr_conv, val_constr);
13088 }
13089
13090 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) {
13091         LDKCommitmentUpdate this_ptr_conv;
13092         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13093         this_ptr_conv.is_owned = false;
13094         LDKCVec_UpdateFailMalformedHTLCZ val_constr;
13095         val_constr.datalen = (*env)->GetArrayLength(env, val);
13096         if (val_constr.datalen > 0)
13097                 val_constr.data = MALLOC(val_constr.datalen * sizeof(LDKUpdateFailMalformedHTLC), "LDKCVec_UpdateFailMalformedHTLCZ Elements");
13098         else
13099                 val_constr.data = NULL;
13100         int64_t* val_vals = (*env)->GetLongArrayElements (env, val, NULL);
13101         for (size_t z = 0; z < val_constr.datalen; z++) {
13102                 int64_t arr_conv_25 = val_vals[z];
13103                 LDKUpdateFailMalformedHTLC arr_conv_25_conv;
13104                 arr_conv_25_conv.inner = (void*)(arr_conv_25 & (~1));
13105                 arr_conv_25_conv.is_owned = (arr_conv_25 & 1) || (arr_conv_25 == 0);
13106                 if (arr_conv_25_conv.inner != NULL)
13107                         arr_conv_25_conv = UpdateFailMalformedHTLC_clone(&arr_conv_25_conv);
13108                 val_constr.data[z] = arr_conv_25_conv;
13109         }
13110         (*env)->ReleaseLongArrayElements(env, val, val_vals, 0);
13111         CommitmentUpdate_set_update_fail_malformed_htlcs(&this_ptr_conv, val_constr);
13112 }
13113
13114 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CommitmentUpdate_1get_1update_1fee(JNIEnv *env, jclass clz, int64_t this_ptr) {
13115         LDKCommitmentUpdate this_ptr_conv;
13116         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13117         this_ptr_conv.is_owned = false;
13118         LDKUpdateFee ret_var = CommitmentUpdate_get_update_fee(&this_ptr_conv);
13119         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13120         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13121         long ret_ref = (long)ret_var.inner;
13122         if (ret_var.is_owned) {
13123                 ret_ref |= 1;
13124         }
13125         return ret_ref;
13126 }
13127
13128 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CommitmentUpdate_1set_1update_1fee(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
13129         LDKCommitmentUpdate this_ptr_conv;
13130         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13131         this_ptr_conv.is_owned = false;
13132         LDKUpdateFee val_conv;
13133         val_conv.inner = (void*)(val & (~1));
13134         val_conv.is_owned = (val & 1) || (val == 0);
13135         if (val_conv.inner != NULL)
13136                 val_conv = UpdateFee_clone(&val_conv);
13137         CommitmentUpdate_set_update_fee(&this_ptr_conv, val_conv);
13138 }
13139
13140 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CommitmentUpdate_1get_1commitment_1signed(JNIEnv *env, jclass clz, int64_t this_ptr) {
13141         LDKCommitmentUpdate this_ptr_conv;
13142         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13143         this_ptr_conv.is_owned = false;
13144         LDKCommitmentSigned ret_var = CommitmentUpdate_get_commitment_signed(&this_ptr_conv);
13145         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13146         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13147         long ret_ref = (long)ret_var.inner;
13148         if (ret_var.is_owned) {
13149                 ret_ref |= 1;
13150         }
13151         return ret_ref;
13152 }
13153
13154 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CommitmentUpdate_1set_1commitment_1signed(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
13155         LDKCommitmentUpdate this_ptr_conv;
13156         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13157         this_ptr_conv.is_owned = false;
13158         LDKCommitmentSigned val_conv;
13159         val_conv.inner = (void*)(val & (~1));
13160         val_conv.is_owned = (val & 1) || (val == 0);
13161         if (val_conv.inner != NULL)
13162                 val_conv = CommitmentSigned_clone(&val_conv);
13163         CommitmentUpdate_set_commitment_signed(&this_ptr_conv, val_conv);
13164 }
13165
13166 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) {
13167         LDKCVec_UpdateAddHTLCZ update_add_htlcs_arg_constr;
13168         update_add_htlcs_arg_constr.datalen = (*env)->GetArrayLength(env, update_add_htlcs_arg);
13169         if (update_add_htlcs_arg_constr.datalen > 0)
13170                 update_add_htlcs_arg_constr.data = MALLOC(update_add_htlcs_arg_constr.datalen * sizeof(LDKUpdateAddHTLC), "LDKCVec_UpdateAddHTLCZ Elements");
13171         else
13172                 update_add_htlcs_arg_constr.data = NULL;
13173         int64_t* update_add_htlcs_arg_vals = (*env)->GetLongArrayElements (env, update_add_htlcs_arg, NULL);
13174         for (size_t p = 0; p < update_add_htlcs_arg_constr.datalen; p++) {
13175                 int64_t arr_conv_15 = update_add_htlcs_arg_vals[p];
13176                 LDKUpdateAddHTLC arr_conv_15_conv;
13177                 arr_conv_15_conv.inner = (void*)(arr_conv_15 & (~1));
13178                 arr_conv_15_conv.is_owned = (arr_conv_15 & 1) || (arr_conv_15 == 0);
13179                 if (arr_conv_15_conv.inner != NULL)
13180                         arr_conv_15_conv = UpdateAddHTLC_clone(&arr_conv_15_conv);
13181                 update_add_htlcs_arg_constr.data[p] = arr_conv_15_conv;
13182         }
13183         (*env)->ReleaseLongArrayElements(env, update_add_htlcs_arg, update_add_htlcs_arg_vals, 0);
13184         LDKCVec_UpdateFulfillHTLCZ update_fulfill_htlcs_arg_constr;
13185         update_fulfill_htlcs_arg_constr.datalen = (*env)->GetArrayLength(env, update_fulfill_htlcs_arg);
13186         if (update_fulfill_htlcs_arg_constr.datalen > 0)
13187                 update_fulfill_htlcs_arg_constr.data = MALLOC(update_fulfill_htlcs_arg_constr.datalen * sizeof(LDKUpdateFulfillHTLC), "LDKCVec_UpdateFulfillHTLCZ Elements");
13188         else
13189                 update_fulfill_htlcs_arg_constr.data = NULL;
13190         int64_t* update_fulfill_htlcs_arg_vals = (*env)->GetLongArrayElements (env, update_fulfill_htlcs_arg, NULL);
13191         for (size_t t = 0; t < update_fulfill_htlcs_arg_constr.datalen; t++) {
13192                 int64_t arr_conv_19 = update_fulfill_htlcs_arg_vals[t];
13193                 LDKUpdateFulfillHTLC arr_conv_19_conv;
13194                 arr_conv_19_conv.inner = (void*)(arr_conv_19 & (~1));
13195                 arr_conv_19_conv.is_owned = (arr_conv_19 & 1) || (arr_conv_19 == 0);
13196                 if (arr_conv_19_conv.inner != NULL)
13197                         arr_conv_19_conv = UpdateFulfillHTLC_clone(&arr_conv_19_conv);
13198                 update_fulfill_htlcs_arg_constr.data[t] = arr_conv_19_conv;
13199         }
13200         (*env)->ReleaseLongArrayElements(env, update_fulfill_htlcs_arg, update_fulfill_htlcs_arg_vals, 0);
13201         LDKCVec_UpdateFailHTLCZ update_fail_htlcs_arg_constr;
13202         update_fail_htlcs_arg_constr.datalen = (*env)->GetArrayLength(env, update_fail_htlcs_arg);
13203         if (update_fail_htlcs_arg_constr.datalen > 0)
13204                 update_fail_htlcs_arg_constr.data = MALLOC(update_fail_htlcs_arg_constr.datalen * sizeof(LDKUpdateFailHTLC), "LDKCVec_UpdateFailHTLCZ Elements");
13205         else
13206                 update_fail_htlcs_arg_constr.data = NULL;
13207         int64_t* update_fail_htlcs_arg_vals = (*env)->GetLongArrayElements (env, update_fail_htlcs_arg, NULL);
13208         for (size_t q = 0; q < update_fail_htlcs_arg_constr.datalen; q++) {
13209                 int64_t arr_conv_16 = update_fail_htlcs_arg_vals[q];
13210                 LDKUpdateFailHTLC arr_conv_16_conv;
13211                 arr_conv_16_conv.inner = (void*)(arr_conv_16 & (~1));
13212                 arr_conv_16_conv.is_owned = (arr_conv_16 & 1) || (arr_conv_16 == 0);
13213                 if (arr_conv_16_conv.inner != NULL)
13214                         arr_conv_16_conv = UpdateFailHTLC_clone(&arr_conv_16_conv);
13215                 update_fail_htlcs_arg_constr.data[q] = arr_conv_16_conv;
13216         }
13217         (*env)->ReleaseLongArrayElements(env, update_fail_htlcs_arg, update_fail_htlcs_arg_vals, 0);
13218         LDKCVec_UpdateFailMalformedHTLCZ update_fail_malformed_htlcs_arg_constr;
13219         update_fail_malformed_htlcs_arg_constr.datalen = (*env)->GetArrayLength(env, update_fail_malformed_htlcs_arg);
13220         if (update_fail_malformed_htlcs_arg_constr.datalen > 0)
13221                 update_fail_malformed_htlcs_arg_constr.data = MALLOC(update_fail_malformed_htlcs_arg_constr.datalen * sizeof(LDKUpdateFailMalformedHTLC), "LDKCVec_UpdateFailMalformedHTLCZ Elements");
13222         else
13223                 update_fail_malformed_htlcs_arg_constr.data = NULL;
13224         int64_t* update_fail_malformed_htlcs_arg_vals = (*env)->GetLongArrayElements (env, update_fail_malformed_htlcs_arg, NULL);
13225         for (size_t z = 0; z < update_fail_malformed_htlcs_arg_constr.datalen; z++) {
13226                 int64_t arr_conv_25 = update_fail_malformed_htlcs_arg_vals[z];
13227                 LDKUpdateFailMalformedHTLC arr_conv_25_conv;
13228                 arr_conv_25_conv.inner = (void*)(arr_conv_25 & (~1));
13229                 arr_conv_25_conv.is_owned = (arr_conv_25 & 1) || (arr_conv_25 == 0);
13230                 if (arr_conv_25_conv.inner != NULL)
13231                         arr_conv_25_conv = UpdateFailMalformedHTLC_clone(&arr_conv_25_conv);
13232                 update_fail_malformed_htlcs_arg_constr.data[z] = arr_conv_25_conv;
13233         }
13234         (*env)->ReleaseLongArrayElements(env, update_fail_malformed_htlcs_arg, update_fail_malformed_htlcs_arg_vals, 0);
13235         LDKUpdateFee update_fee_arg_conv;
13236         update_fee_arg_conv.inner = (void*)(update_fee_arg & (~1));
13237         update_fee_arg_conv.is_owned = (update_fee_arg & 1) || (update_fee_arg == 0);
13238         if (update_fee_arg_conv.inner != NULL)
13239                 update_fee_arg_conv = UpdateFee_clone(&update_fee_arg_conv);
13240         LDKCommitmentSigned commitment_signed_arg_conv;
13241         commitment_signed_arg_conv.inner = (void*)(commitment_signed_arg & (~1));
13242         commitment_signed_arg_conv.is_owned = (commitment_signed_arg & 1) || (commitment_signed_arg == 0);
13243         if (commitment_signed_arg_conv.inner != NULL)
13244                 commitment_signed_arg_conv = CommitmentSigned_clone(&commitment_signed_arg_conv);
13245         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);
13246         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13247         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13248         long ret_ref = (long)ret_var.inner;
13249         if (ret_var.is_owned) {
13250                 ret_ref |= 1;
13251         }
13252         return ret_ref;
13253 }
13254
13255 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_HTLCFailChannelUpdate_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
13256         LDKHTLCFailChannelUpdate this_ptr_conv = *(LDKHTLCFailChannelUpdate*)this_ptr;
13257         FREE((void*)this_ptr);
13258         HTLCFailChannelUpdate_free(this_ptr_conv);
13259 }
13260
13261 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_HTLCFailChannelUpdate_1clone(JNIEnv *env, jclass clz, int64_t orig) {
13262         LDKHTLCFailChannelUpdate* orig_conv = (LDKHTLCFailChannelUpdate*)orig;
13263         LDKHTLCFailChannelUpdate *ret_copy = MALLOC(sizeof(LDKHTLCFailChannelUpdate), "LDKHTLCFailChannelUpdate");
13264         *ret_copy = HTLCFailChannelUpdate_clone(orig_conv);
13265         long ret_ref = (long)ret_copy;
13266         return ret_ref;
13267 }
13268
13269 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelMessageHandler_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
13270         LDKChannelMessageHandler this_ptr_conv = *(LDKChannelMessageHandler*)this_ptr;
13271         FREE((void*)this_ptr);
13272         ChannelMessageHandler_free(this_ptr_conv);
13273 }
13274
13275 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RoutingMessageHandler_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
13276         LDKRoutingMessageHandler this_ptr_conv = *(LDKRoutingMessageHandler*)this_ptr;
13277         FREE((void*)this_ptr);
13278         RoutingMessageHandler_free(this_ptr_conv);
13279 }
13280
13281 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1write(JNIEnv *env, jclass clz, int64_t obj) {
13282         LDKAcceptChannel obj_conv;
13283         obj_conv.inner = (void*)(obj & (~1));
13284         obj_conv.is_owned = false;
13285         LDKCVec_u8Z arg_var = AcceptChannel_write(&obj_conv);
13286         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
13287         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
13288         CVec_u8Z_free(arg_var);
13289         return arg_arr;
13290 }
13291
13292 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1read(JNIEnv *env, jclass clz, int8_tArray ser) {
13293         LDKu8slice ser_ref;
13294         ser_ref.datalen = (*env)->GetArrayLength(env, ser);
13295         ser_ref.data = (*env)->GetByteArrayElements (env, ser, NULL);
13296         LDKAcceptChannel ret_var = AcceptChannel_read(ser_ref);
13297         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13298         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13299         long ret_ref = (long)ret_var.inner;
13300         if (ret_var.is_owned) {
13301                 ret_ref |= 1;
13302         }
13303         (*env)->ReleaseByteArrayElements(env, ser, (int8_t*)ser_ref.data, 0);
13304         return ret_ref;
13305 }
13306
13307 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_AnnouncementSignatures_1write(JNIEnv *env, jclass clz, int64_t obj) {
13308         LDKAnnouncementSignatures obj_conv;
13309         obj_conv.inner = (void*)(obj & (~1));
13310         obj_conv.is_owned = false;
13311         LDKCVec_u8Z arg_var = AnnouncementSignatures_write(&obj_conv);
13312         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
13313         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
13314         CVec_u8Z_free(arg_var);
13315         return arg_arr;
13316 }
13317
13318 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_AnnouncementSignatures_1read(JNIEnv *env, jclass clz, int8_tArray ser) {
13319         LDKu8slice ser_ref;
13320         ser_ref.datalen = (*env)->GetArrayLength(env, ser);
13321         ser_ref.data = (*env)->GetByteArrayElements (env, ser, NULL);
13322         LDKAnnouncementSignatures ret_var = AnnouncementSignatures_read(ser_ref);
13323         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13324         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13325         long ret_ref = (long)ret_var.inner;
13326         if (ret_var.is_owned) {
13327                 ret_ref |= 1;
13328         }
13329         (*env)->ReleaseByteArrayElements(env, ser, (int8_t*)ser_ref.data, 0);
13330         return ret_ref;
13331 }
13332
13333 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_ChannelReestablish_1write(JNIEnv *env, jclass clz, int64_t obj) {
13334         LDKChannelReestablish obj_conv;
13335         obj_conv.inner = (void*)(obj & (~1));
13336         obj_conv.is_owned = false;
13337         LDKCVec_u8Z arg_var = ChannelReestablish_write(&obj_conv);
13338         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
13339         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
13340         CVec_u8Z_free(arg_var);
13341         return arg_arr;
13342 }
13343
13344 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelReestablish_1read(JNIEnv *env, jclass clz, int8_tArray ser) {
13345         LDKu8slice ser_ref;
13346         ser_ref.datalen = (*env)->GetArrayLength(env, ser);
13347         ser_ref.data = (*env)->GetByteArrayElements (env, ser, NULL);
13348         LDKCResult_ChannelReestablishDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ChannelReestablishDecodeErrorZ), "LDKCResult_ChannelReestablishDecodeErrorZ");
13349         *ret_conv = ChannelReestablish_read(ser_ref);
13350         (*env)->ReleaseByteArrayElements(env, ser, (int8_t*)ser_ref.data, 0);
13351         return (long)ret_conv;
13352 }
13353
13354 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_ClosingSigned_1write(JNIEnv *env, jclass clz, int64_t obj) {
13355         LDKClosingSigned obj_conv;
13356         obj_conv.inner = (void*)(obj & (~1));
13357         obj_conv.is_owned = false;
13358         LDKCVec_u8Z arg_var = ClosingSigned_write(&obj_conv);
13359         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
13360         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
13361         CVec_u8Z_free(arg_var);
13362         return arg_arr;
13363 }
13364
13365 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ClosingSigned_1read(JNIEnv *env, jclass clz, int8_tArray ser) {
13366         LDKu8slice ser_ref;
13367         ser_ref.datalen = (*env)->GetArrayLength(env, ser);
13368         ser_ref.data = (*env)->GetByteArrayElements (env, ser, NULL);
13369         LDKClosingSigned ret_var = ClosingSigned_read(ser_ref);
13370         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13371         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13372         long ret_ref = (long)ret_var.inner;
13373         if (ret_var.is_owned) {
13374                 ret_ref |= 1;
13375         }
13376         (*env)->ReleaseByteArrayElements(env, ser, (int8_t*)ser_ref.data, 0);
13377         return ret_ref;
13378 }
13379
13380 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_CommitmentSigned_1write(JNIEnv *env, jclass clz, int64_t obj) {
13381         LDKCommitmentSigned obj_conv;
13382         obj_conv.inner = (void*)(obj & (~1));
13383         obj_conv.is_owned = false;
13384         LDKCVec_u8Z arg_var = CommitmentSigned_write(&obj_conv);
13385         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
13386         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
13387         CVec_u8Z_free(arg_var);
13388         return arg_arr;
13389 }
13390
13391 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CommitmentSigned_1read(JNIEnv *env, jclass clz, int8_tArray ser) {
13392         LDKu8slice ser_ref;
13393         ser_ref.datalen = (*env)->GetArrayLength(env, ser);
13394         ser_ref.data = (*env)->GetByteArrayElements (env, ser, NULL);
13395         LDKCommitmentSigned ret_var = CommitmentSigned_read(ser_ref);
13396         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13397         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13398         long ret_ref = (long)ret_var.inner;
13399         if (ret_var.is_owned) {
13400                 ret_ref |= 1;
13401         }
13402         (*env)->ReleaseByteArrayElements(env, ser, (int8_t*)ser_ref.data, 0);
13403         return ret_ref;
13404 }
13405
13406 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_FundingCreated_1write(JNIEnv *env, jclass clz, int64_t obj) {
13407         LDKFundingCreated obj_conv;
13408         obj_conv.inner = (void*)(obj & (~1));
13409         obj_conv.is_owned = false;
13410         LDKCVec_u8Z arg_var = FundingCreated_write(&obj_conv);
13411         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
13412         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
13413         CVec_u8Z_free(arg_var);
13414         return arg_arr;
13415 }
13416
13417 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_FundingCreated_1read(JNIEnv *env, jclass clz, int8_tArray ser) {
13418         LDKu8slice ser_ref;
13419         ser_ref.datalen = (*env)->GetArrayLength(env, ser);
13420         ser_ref.data = (*env)->GetByteArrayElements (env, ser, NULL);
13421         LDKFundingCreated ret_var = FundingCreated_read(ser_ref);
13422         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13423         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13424         long ret_ref = (long)ret_var.inner;
13425         if (ret_var.is_owned) {
13426                 ret_ref |= 1;
13427         }
13428         (*env)->ReleaseByteArrayElements(env, ser, (int8_t*)ser_ref.data, 0);
13429         return ret_ref;
13430 }
13431
13432 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_FundingSigned_1write(JNIEnv *env, jclass clz, int64_t obj) {
13433         LDKFundingSigned obj_conv;
13434         obj_conv.inner = (void*)(obj & (~1));
13435         obj_conv.is_owned = false;
13436         LDKCVec_u8Z arg_var = FundingSigned_write(&obj_conv);
13437         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
13438         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
13439         CVec_u8Z_free(arg_var);
13440         return arg_arr;
13441 }
13442
13443 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_FundingSigned_1read(JNIEnv *env, jclass clz, int8_tArray ser) {
13444         LDKu8slice ser_ref;
13445         ser_ref.datalen = (*env)->GetArrayLength(env, ser);
13446         ser_ref.data = (*env)->GetByteArrayElements (env, ser, NULL);
13447         LDKFundingSigned ret_var = FundingSigned_read(ser_ref);
13448         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13449         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13450         long ret_ref = (long)ret_var.inner;
13451         if (ret_var.is_owned) {
13452                 ret_ref |= 1;
13453         }
13454         (*env)->ReleaseByteArrayElements(env, ser, (int8_t*)ser_ref.data, 0);
13455         return ret_ref;
13456 }
13457
13458 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_FundingLocked_1write(JNIEnv *env, jclass clz, int64_t obj) {
13459         LDKFundingLocked obj_conv;
13460         obj_conv.inner = (void*)(obj & (~1));
13461         obj_conv.is_owned = false;
13462         LDKCVec_u8Z arg_var = FundingLocked_write(&obj_conv);
13463         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
13464         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
13465         CVec_u8Z_free(arg_var);
13466         return arg_arr;
13467 }
13468
13469 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_FundingLocked_1read(JNIEnv *env, jclass clz, int8_tArray ser) {
13470         LDKu8slice ser_ref;
13471         ser_ref.datalen = (*env)->GetArrayLength(env, ser);
13472         ser_ref.data = (*env)->GetByteArrayElements (env, ser, NULL);
13473         LDKFundingLocked ret_var = FundingLocked_read(ser_ref);
13474         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13475         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13476         long ret_ref = (long)ret_var.inner;
13477         if (ret_var.is_owned) {
13478                 ret_ref |= 1;
13479         }
13480         (*env)->ReleaseByteArrayElements(env, ser, (int8_t*)ser_ref.data, 0);
13481         return ret_ref;
13482 }
13483
13484 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_Init_1write(JNIEnv *env, jclass clz, int64_t obj) {
13485         LDKInit obj_conv;
13486         obj_conv.inner = (void*)(obj & (~1));
13487         obj_conv.is_owned = false;
13488         LDKCVec_u8Z arg_var = Init_write(&obj_conv);
13489         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
13490         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
13491         CVec_u8Z_free(arg_var);
13492         return arg_arr;
13493 }
13494
13495 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_Init_1read(JNIEnv *env, jclass clz, int8_tArray ser) {
13496         LDKu8slice ser_ref;
13497         ser_ref.datalen = (*env)->GetArrayLength(env, ser);
13498         ser_ref.data = (*env)->GetByteArrayElements (env, ser, NULL);
13499         LDKCResult_InitDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_InitDecodeErrorZ), "LDKCResult_InitDecodeErrorZ");
13500         *ret_conv = Init_read(ser_ref);
13501         (*env)->ReleaseByteArrayElements(env, ser, (int8_t*)ser_ref.data, 0);
13502         return (long)ret_conv;
13503 }
13504
13505 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_OpenChannel_1write(JNIEnv *env, jclass clz, int64_t obj) {
13506         LDKOpenChannel obj_conv;
13507         obj_conv.inner = (void*)(obj & (~1));
13508         obj_conv.is_owned = false;
13509         LDKCVec_u8Z arg_var = OpenChannel_write(&obj_conv);
13510         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
13511         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
13512         CVec_u8Z_free(arg_var);
13513         return arg_arr;
13514 }
13515
13516 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_OpenChannel_1read(JNIEnv *env, jclass clz, int8_tArray ser) {
13517         LDKu8slice ser_ref;
13518         ser_ref.datalen = (*env)->GetArrayLength(env, ser);
13519         ser_ref.data = (*env)->GetByteArrayElements (env, ser, NULL);
13520         LDKOpenChannel ret_var = OpenChannel_read(ser_ref);
13521         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13522         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13523         long ret_ref = (long)ret_var.inner;
13524         if (ret_var.is_owned) {
13525                 ret_ref |= 1;
13526         }
13527         (*env)->ReleaseByteArrayElements(env, ser, (int8_t*)ser_ref.data, 0);
13528         return ret_ref;
13529 }
13530
13531 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_RevokeAndACK_1write(JNIEnv *env, jclass clz, int64_t obj) {
13532         LDKRevokeAndACK obj_conv;
13533         obj_conv.inner = (void*)(obj & (~1));
13534         obj_conv.is_owned = false;
13535         LDKCVec_u8Z arg_var = RevokeAndACK_write(&obj_conv);
13536         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
13537         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
13538         CVec_u8Z_free(arg_var);
13539         return arg_arr;
13540 }
13541
13542 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_RevokeAndACK_1read(JNIEnv *env, jclass clz, int8_tArray ser) {
13543         LDKu8slice ser_ref;
13544         ser_ref.datalen = (*env)->GetArrayLength(env, ser);
13545         ser_ref.data = (*env)->GetByteArrayElements (env, ser, NULL);
13546         LDKRevokeAndACK ret_var = RevokeAndACK_read(ser_ref);
13547         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13548         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13549         long ret_ref = (long)ret_var.inner;
13550         if (ret_var.is_owned) {
13551                 ret_ref |= 1;
13552         }
13553         (*env)->ReleaseByteArrayElements(env, ser, (int8_t*)ser_ref.data, 0);
13554         return ret_ref;
13555 }
13556
13557 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_Shutdown_1write(JNIEnv *env, jclass clz, int64_t obj) {
13558         LDKShutdown obj_conv;
13559         obj_conv.inner = (void*)(obj & (~1));
13560         obj_conv.is_owned = false;
13561         LDKCVec_u8Z arg_var = Shutdown_write(&obj_conv);
13562         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
13563         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
13564         CVec_u8Z_free(arg_var);
13565         return arg_arr;
13566 }
13567
13568 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_Shutdown_1read(JNIEnv *env, jclass clz, int8_tArray ser) {
13569         LDKu8slice ser_ref;
13570         ser_ref.datalen = (*env)->GetArrayLength(env, ser);
13571         ser_ref.data = (*env)->GetByteArrayElements (env, ser, NULL);
13572         LDKShutdown ret_var = Shutdown_read(ser_ref);
13573         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13574         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13575         long ret_ref = (long)ret_var.inner;
13576         if (ret_var.is_owned) {
13577                 ret_ref |= 1;
13578         }
13579         (*env)->ReleaseByteArrayElements(env, ser, (int8_t*)ser_ref.data, 0);
13580         return ret_ref;
13581 }
13582
13583 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_UpdateFailHTLC_1write(JNIEnv *env, jclass clz, int64_t obj) {
13584         LDKUpdateFailHTLC obj_conv;
13585         obj_conv.inner = (void*)(obj & (~1));
13586         obj_conv.is_owned = false;
13587         LDKCVec_u8Z arg_var = UpdateFailHTLC_write(&obj_conv);
13588         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
13589         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
13590         CVec_u8Z_free(arg_var);
13591         return arg_arr;
13592 }
13593
13594 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_UpdateFailHTLC_1read(JNIEnv *env, jclass clz, int8_tArray ser) {
13595         LDKu8slice ser_ref;
13596         ser_ref.datalen = (*env)->GetArrayLength(env, ser);
13597         ser_ref.data = (*env)->GetByteArrayElements (env, ser, NULL);
13598         LDKUpdateFailHTLC ret_var = UpdateFailHTLC_read(ser_ref);
13599         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13600         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13601         long ret_ref = (long)ret_var.inner;
13602         if (ret_var.is_owned) {
13603                 ret_ref |= 1;
13604         }
13605         (*env)->ReleaseByteArrayElements(env, ser, (int8_t*)ser_ref.data, 0);
13606         return ret_ref;
13607 }
13608
13609 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_UpdateFailMalformedHTLC_1write(JNIEnv *env, jclass clz, int64_t obj) {
13610         LDKUpdateFailMalformedHTLC obj_conv;
13611         obj_conv.inner = (void*)(obj & (~1));
13612         obj_conv.is_owned = false;
13613         LDKCVec_u8Z arg_var = UpdateFailMalformedHTLC_write(&obj_conv);
13614         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
13615         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
13616         CVec_u8Z_free(arg_var);
13617         return arg_arr;
13618 }
13619
13620 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_UpdateFailMalformedHTLC_1read(JNIEnv *env, jclass clz, int8_tArray ser) {
13621         LDKu8slice ser_ref;
13622         ser_ref.datalen = (*env)->GetArrayLength(env, ser);
13623         ser_ref.data = (*env)->GetByteArrayElements (env, ser, NULL);
13624         LDKUpdateFailMalformedHTLC ret_var = UpdateFailMalformedHTLC_read(ser_ref);
13625         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13626         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13627         long ret_ref = (long)ret_var.inner;
13628         if (ret_var.is_owned) {
13629                 ret_ref |= 1;
13630         }
13631         (*env)->ReleaseByteArrayElements(env, ser, (int8_t*)ser_ref.data, 0);
13632         return ret_ref;
13633 }
13634
13635 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_UpdateFee_1write(JNIEnv *env, jclass clz, int64_t obj) {
13636         LDKUpdateFee obj_conv;
13637         obj_conv.inner = (void*)(obj & (~1));
13638         obj_conv.is_owned = false;
13639         LDKCVec_u8Z arg_var = UpdateFee_write(&obj_conv);
13640         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
13641         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
13642         CVec_u8Z_free(arg_var);
13643         return arg_arr;
13644 }
13645
13646 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_UpdateFee_1read(JNIEnv *env, jclass clz, int8_tArray ser) {
13647         LDKu8slice ser_ref;
13648         ser_ref.datalen = (*env)->GetArrayLength(env, ser);
13649         ser_ref.data = (*env)->GetByteArrayElements (env, ser, NULL);
13650         LDKUpdateFee ret_var = UpdateFee_read(ser_ref);
13651         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13652         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13653         long ret_ref = (long)ret_var.inner;
13654         if (ret_var.is_owned) {
13655                 ret_ref |= 1;
13656         }
13657         (*env)->ReleaseByteArrayElements(env, ser, (int8_t*)ser_ref.data, 0);
13658         return ret_ref;
13659 }
13660
13661 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_UpdateFulfillHTLC_1write(JNIEnv *env, jclass clz, int64_t obj) {
13662         LDKUpdateFulfillHTLC obj_conv;
13663         obj_conv.inner = (void*)(obj & (~1));
13664         obj_conv.is_owned = false;
13665         LDKCVec_u8Z arg_var = UpdateFulfillHTLC_write(&obj_conv);
13666         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
13667         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
13668         CVec_u8Z_free(arg_var);
13669         return arg_arr;
13670 }
13671
13672 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_UpdateFulfillHTLC_1read(JNIEnv *env, jclass clz, int8_tArray ser) {
13673         LDKu8slice ser_ref;
13674         ser_ref.datalen = (*env)->GetArrayLength(env, ser);
13675         ser_ref.data = (*env)->GetByteArrayElements (env, ser, NULL);
13676         LDKUpdateFulfillHTLC ret_var = UpdateFulfillHTLC_read(ser_ref);
13677         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13678         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13679         long ret_ref = (long)ret_var.inner;
13680         if (ret_var.is_owned) {
13681                 ret_ref |= 1;
13682         }
13683         (*env)->ReleaseByteArrayElements(env, ser, (int8_t*)ser_ref.data, 0);
13684         return ret_ref;
13685 }
13686
13687 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_UpdateAddHTLC_1write(JNIEnv *env, jclass clz, int64_t obj) {
13688         LDKUpdateAddHTLC obj_conv;
13689         obj_conv.inner = (void*)(obj & (~1));
13690         obj_conv.is_owned = false;
13691         LDKCVec_u8Z arg_var = UpdateAddHTLC_write(&obj_conv);
13692         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
13693         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
13694         CVec_u8Z_free(arg_var);
13695         return arg_arr;
13696 }
13697
13698 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_UpdateAddHTLC_1read(JNIEnv *env, jclass clz, int8_tArray ser) {
13699         LDKu8slice ser_ref;
13700         ser_ref.datalen = (*env)->GetArrayLength(env, ser);
13701         ser_ref.data = (*env)->GetByteArrayElements (env, ser, NULL);
13702         LDKUpdateAddHTLC ret_var = UpdateAddHTLC_read(ser_ref);
13703         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13704         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13705         long ret_ref = (long)ret_var.inner;
13706         if (ret_var.is_owned) {
13707                 ret_ref |= 1;
13708         }
13709         (*env)->ReleaseByteArrayElements(env, ser, (int8_t*)ser_ref.data, 0);
13710         return ret_ref;
13711 }
13712
13713 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_Ping_1write(JNIEnv *env, jclass clz, int64_t obj) {
13714         LDKPing obj_conv;
13715         obj_conv.inner = (void*)(obj & (~1));
13716         obj_conv.is_owned = false;
13717         LDKCVec_u8Z arg_var = Ping_write(&obj_conv);
13718         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
13719         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
13720         CVec_u8Z_free(arg_var);
13721         return arg_arr;
13722 }
13723
13724 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_Ping_1read(JNIEnv *env, jclass clz, int8_tArray ser) {
13725         LDKu8slice ser_ref;
13726         ser_ref.datalen = (*env)->GetArrayLength(env, ser);
13727         ser_ref.data = (*env)->GetByteArrayElements (env, ser, NULL);
13728         LDKCResult_PingDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_PingDecodeErrorZ), "LDKCResult_PingDecodeErrorZ");
13729         *ret_conv = Ping_read(ser_ref);
13730         (*env)->ReleaseByteArrayElements(env, ser, (int8_t*)ser_ref.data, 0);
13731         return (long)ret_conv;
13732 }
13733
13734 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_Pong_1write(JNIEnv *env, jclass clz, int64_t obj) {
13735         LDKPong obj_conv;
13736         obj_conv.inner = (void*)(obj & (~1));
13737         obj_conv.is_owned = false;
13738         LDKCVec_u8Z arg_var = Pong_write(&obj_conv);
13739         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
13740         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
13741         CVec_u8Z_free(arg_var);
13742         return arg_arr;
13743 }
13744
13745 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_Pong_1read(JNIEnv *env, jclass clz, int8_tArray ser) {
13746         LDKu8slice ser_ref;
13747         ser_ref.datalen = (*env)->GetArrayLength(env, ser);
13748         ser_ref.data = (*env)->GetByteArrayElements (env, ser, NULL);
13749         LDKCResult_PongDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_PongDecodeErrorZ), "LDKCResult_PongDecodeErrorZ");
13750         *ret_conv = Pong_read(ser_ref);
13751         (*env)->ReleaseByteArrayElements(env, ser, (int8_t*)ser_ref.data, 0);
13752         return (long)ret_conv;
13753 }
13754
13755 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1write(JNIEnv *env, jclass clz, int64_t obj) {
13756         LDKUnsignedChannelAnnouncement obj_conv;
13757         obj_conv.inner = (void*)(obj & (~1));
13758         obj_conv.is_owned = false;
13759         LDKCVec_u8Z arg_var = UnsignedChannelAnnouncement_write(&obj_conv);
13760         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
13761         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
13762         CVec_u8Z_free(arg_var);
13763         return arg_arr;
13764 }
13765
13766 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1read(JNIEnv *env, jclass clz, int8_tArray ser) {
13767         LDKu8slice ser_ref;
13768         ser_ref.datalen = (*env)->GetArrayLength(env, ser);
13769         ser_ref.data = (*env)->GetByteArrayElements (env, ser, NULL);
13770         LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ), "LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ");
13771         *ret_conv = UnsignedChannelAnnouncement_read(ser_ref);
13772         (*env)->ReleaseByteArrayElements(env, ser, (int8_t*)ser_ref.data, 0);
13773         return (long)ret_conv;
13774 }
13775
13776 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_ChannelAnnouncement_1write(JNIEnv *env, jclass clz, int64_t obj) {
13777         LDKChannelAnnouncement obj_conv;
13778         obj_conv.inner = (void*)(obj & (~1));
13779         obj_conv.is_owned = false;
13780         LDKCVec_u8Z arg_var = ChannelAnnouncement_write(&obj_conv);
13781         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
13782         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
13783         CVec_u8Z_free(arg_var);
13784         return arg_arr;
13785 }
13786
13787 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelAnnouncement_1read(JNIEnv *env, jclass clz, int8_tArray ser) {
13788         LDKu8slice ser_ref;
13789         ser_ref.datalen = (*env)->GetArrayLength(env, ser);
13790         ser_ref.data = (*env)->GetByteArrayElements (env, ser, NULL);
13791         LDKChannelAnnouncement ret_var = ChannelAnnouncement_read(ser_ref);
13792         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13793         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13794         long ret_ref = (long)ret_var.inner;
13795         if (ret_var.is_owned) {
13796                 ret_ref |= 1;
13797         }
13798         (*env)->ReleaseByteArrayElements(env, ser, (int8_t*)ser_ref.data, 0);
13799         return ret_ref;
13800 }
13801
13802 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1write(JNIEnv *env, jclass clz, int64_t obj) {
13803         LDKUnsignedChannelUpdate obj_conv;
13804         obj_conv.inner = (void*)(obj & (~1));
13805         obj_conv.is_owned = false;
13806         LDKCVec_u8Z arg_var = UnsignedChannelUpdate_write(&obj_conv);
13807         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
13808         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
13809         CVec_u8Z_free(arg_var);
13810         return arg_arr;
13811 }
13812
13813 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1read(JNIEnv *env, jclass clz, int8_tArray ser) {
13814         LDKu8slice ser_ref;
13815         ser_ref.datalen = (*env)->GetArrayLength(env, ser);
13816         ser_ref.data = (*env)->GetByteArrayElements (env, ser, NULL);
13817         LDKCResult_UnsignedChannelUpdateDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_UnsignedChannelUpdateDecodeErrorZ), "LDKCResult_UnsignedChannelUpdateDecodeErrorZ");
13818         *ret_conv = UnsignedChannelUpdate_read(ser_ref);
13819         (*env)->ReleaseByteArrayElements(env, ser, (int8_t*)ser_ref.data, 0);
13820         return (long)ret_conv;
13821 }
13822
13823 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_ChannelUpdate_1write(JNIEnv *env, jclass clz, int64_t obj) {
13824         LDKChannelUpdate obj_conv;
13825         obj_conv.inner = (void*)(obj & (~1));
13826         obj_conv.is_owned = false;
13827         LDKCVec_u8Z arg_var = ChannelUpdate_write(&obj_conv);
13828         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
13829         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
13830         CVec_u8Z_free(arg_var);
13831         return arg_arr;
13832 }
13833
13834 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelUpdate_1read(JNIEnv *env, jclass clz, int8_tArray ser) {
13835         LDKu8slice ser_ref;
13836         ser_ref.datalen = (*env)->GetArrayLength(env, ser);
13837         ser_ref.data = (*env)->GetByteArrayElements (env, ser, NULL);
13838         LDKChannelUpdate ret_var = ChannelUpdate_read(ser_ref);
13839         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13840         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13841         long ret_ref = (long)ret_var.inner;
13842         if (ret_var.is_owned) {
13843                 ret_ref |= 1;
13844         }
13845         (*env)->ReleaseByteArrayElements(env, ser, (int8_t*)ser_ref.data, 0);
13846         return ret_ref;
13847 }
13848
13849 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_ErrorMessage_1write(JNIEnv *env, jclass clz, int64_t obj) {
13850         LDKErrorMessage obj_conv;
13851         obj_conv.inner = (void*)(obj & (~1));
13852         obj_conv.is_owned = false;
13853         LDKCVec_u8Z arg_var = ErrorMessage_write(&obj_conv);
13854         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
13855         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
13856         CVec_u8Z_free(arg_var);
13857         return arg_arr;
13858 }
13859
13860 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ErrorMessage_1read(JNIEnv *env, jclass clz, int8_tArray ser) {
13861         LDKu8slice ser_ref;
13862         ser_ref.datalen = (*env)->GetArrayLength(env, ser);
13863         ser_ref.data = (*env)->GetByteArrayElements (env, ser, NULL);
13864         LDKCResult_ErrorMessageDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ErrorMessageDecodeErrorZ), "LDKCResult_ErrorMessageDecodeErrorZ");
13865         *ret_conv = ErrorMessage_read(ser_ref);
13866         (*env)->ReleaseByteArrayElements(env, ser, (int8_t*)ser_ref.data, 0);
13867         return (long)ret_conv;
13868 }
13869
13870 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_UnsignedNodeAnnouncement_1write(JNIEnv *env, jclass clz, int64_t obj) {
13871         LDKUnsignedNodeAnnouncement obj_conv;
13872         obj_conv.inner = (void*)(obj & (~1));
13873         obj_conv.is_owned = false;
13874         LDKCVec_u8Z arg_var = UnsignedNodeAnnouncement_write(&obj_conv);
13875         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
13876         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
13877         CVec_u8Z_free(arg_var);
13878         return arg_arr;
13879 }
13880
13881 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_UnsignedNodeAnnouncement_1read(JNIEnv *env, jclass clz, int8_tArray ser) {
13882         LDKu8slice ser_ref;
13883         ser_ref.datalen = (*env)->GetArrayLength(env, ser);
13884         ser_ref.data = (*env)->GetByteArrayElements (env, ser, NULL);
13885         LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ), "LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ");
13886         *ret_conv = UnsignedNodeAnnouncement_read(ser_ref);
13887         (*env)->ReleaseByteArrayElements(env, ser, (int8_t*)ser_ref.data, 0);
13888         return (long)ret_conv;
13889 }
13890
13891 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_NodeAnnouncement_1write(JNIEnv *env, jclass clz, int64_t obj) {
13892         LDKNodeAnnouncement obj_conv;
13893         obj_conv.inner = (void*)(obj & (~1));
13894         obj_conv.is_owned = false;
13895         LDKCVec_u8Z arg_var = NodeAnnouncement_write(&obj_conv);
13896         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
13897         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
13898         CVec_u8Z_free(arg_var);
13899         return arg_arr;
13900 }
13901
13902 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_NodeAnnouncement_1read(JNIEnv *env, jclass clz, int8_tArray ser) {
13903         LDKu8slice ser_ref;
13904         ser_ref.datalen = (*env)->GetArrayLength(env, ser);
13905         ser_ref.data = (*env)->GetByteArrayElements (env, ser, NULL);
13906         LDKNodeAnnouncement ret_var = NodeAnnouncement_read(ser_ref);
13907         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13908         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13909         long ret_ref = (long)ret_var.inner;
13910         if (ret_var.is_owned) {
13911                 ret_ref |= 1;
13912         }
13913         (*env)->ReleaseByteArrayElements(env, ser, (int8_t*)ser_ref.data, 0);
13914         return ret_ref;
13915 }
13916
13917 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_QueryShortChannelIds_1read(JNIEnv *env, jclass clz, int8_tArray ser) {
13918         LDKu8slice ser_ref;
13919         ser_ref.datalen = (*env)->GetArrayLength(env, ser);
13920         ser_ref.data = (*env)->GetByteArrayElements (env, ser, NULL);
13921         LDKCResult_QueryShortChannelIdsDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_QueryShortChannelIdsDecodeErrorZ), "LDKCResult_QueryShortChannelIdsDecodeErrorZ");
13922         *ret_conv = QueryShortChannelIds_read(ser_ref);
13923         (*env)->ReleaseByteArrayElements(env, ser, (int8_t*)ser_ref.data, 0);
13924         return (long)ret_conv;
13925 }
13926
13927 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_QueryShortChannelIds_1write(JNIEnv *env, jclass clz, int64_t obj) {
13928         LDKQueryShortChannelIds obj_conv;
13929         obj_conv.inner = (void*)(obj & (~1));
13930         obj_conv.is_owned = false;
13931         LDKCVec_u8Z arg_var = QueryShortChannelIds_write(&obj_conv);
13932         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
13933         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
13934         CVec_u8Z_free(arg_var);
13935         return arg_arr;
13936 }
13937
13938 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ReplyShortChannelIdsEnd_1read(JNIEnv *env, jclass clz, int8_tArray ser) {
13939         LDKu8slice ser_ref;
13940         ser_ref.datalen = (*env)->GetArrayLength(env, ser);
13941         ser_ref.data = (*env)->GetByteArrayElements (env, ser, NULL);
13942         LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ), "LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ");
13943         *ret_conv = ReplyShortChannelIdsEnd_read(ser_ref);
13944         (*env)->ReleaseByteArrayElements(env, ser, (int8_t*)ser_ref.data, 0);
13945         return (long)ret_conv;
13946 }
13947
13948 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_ReplyShortChannelIdsEnd_1write(JNIEnv *env, jclass clz, int64_t obj) {
13949         LDKReplyShortChannelIdsEnd obj_conv;
13950         obj_conv.inner = (void*)(obj & (~1));
13951         obj_conv.is_owned = false;
13952         LDKCVec_u8Z arg_var = ReplyShortChannelIdsEnd_write(&obj_conv);
13953         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
13954         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
13955         CVec_u8Z_free(arg_var);
13956         return arg_arr;
13957 }
13958
13959 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_QueryChannelRange_1read(JNIEnv *env, jclass clz, int8_tArray ser) {
13960         LDKu8slice ser_ref;
13961         ser_ref.datalen = (*env)->GetArrayLength(env, ser);
13962         ser_ref.data = (*env)->GetByteArrayElements (env, ser, NULL);
13963         LDKCResult_QueryChannelRangeDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_QueryChannelRangeDecodeErrorZ), "LDKCResult_QueryChannelRangeDecodeErrorZ");
13964         *ret_conv = QueryChannelRange_read(ser_ref);
13965         (*env)->ReleaseByteArrayElements(env, ser, (int8_t*)ser_ref.data, 0);
13966         return (long)ret_conv;
13967 }
13968
13969 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_QueryChannelRange_1write(JNIEnv *env, jclass clz, int64_t obj) {
13970         LDKQueryChannelRange obj_conv;
13971         obj_conv.inner = (void*)(obj & (~1));
13972         obj_conv.is_owned = false;
13973         LDKCVec_u8Z arg_var = QueryChannelRange_write(&obj_conv);
13974         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
13975         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
13976         CVec_u8Z_free(arg_var);
13977         return arg_arr;
13978 }
13979
13980 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ReplyChannelRange_1read(JNIEnv *env, jclass clz, int8_tArray ser) {
13981         LDKu8slice ser_ref;
13982         ser_ref.datalen = (*env)->GetArrayLength(env, ser);
13983         ser_ref.data = (*env)->GetByteArrayElements (env, ser, NULL);
13984         LDKCResult_ReplyChannelRangeDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ReplyChannelRangeDecodeErrorZ), "LDKCResult_ReplyChannelRangeDecodeErrorZ");
13985         *ret_conv = ReplyChannelRange_read(ser_ref);
13986         (*env)->ReleaseByteArrayElements(env, ser, (int8_t*)ser_ref.data, 0);
13987         return (long)ret_conv;
13988 }
13989
13990 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_ReplyChannelRange_1write(JNIEnv *env, jclass clz, int64_t obj) {
13991         LDKReplyChannelRange obj_conv;
13992         obj_conv.inner = (void*)(obj & (~1));
13993         obj_conv.is_owned = false;
13994         LDKCVec_u8Z arg_var = ReplyChannelRange_write(&obj_conv);
13995         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
13996         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
13997         CVec_u8Z_free(arg_var);
13998         return arg_arr;
13999 }
14000
14001 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_GossipTimestampFilter_1read(JNIEnv *env, jclass clz, int8_tArray ser) {
14002         LDKu8slice ser_ref;
14003         ser_ref.datalen = (*env)->GetArrayLength(env, ser);
14004         ser_ref.data = (*env)->GetByteArrayElements (env, ser, NULL);
14005         LDKCResult_GossipTimestampFilterDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_GossipTimestampFilterDecodeErrorZ), "LDKCResult_GossipTimestampFilterDecodeErrorZ");
14006         *ret_conv = GossipTimestampFilter_read(ser_ref);
14007         (*env)->ReleaseByteArrayElements(env, ser, (int8_t*)ser_ref.data, 0);
14008         return (long)ret_conv;
14009 }
14010
14011 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_GossipTimestampFilter_1write(JNIEnv *env, jclass clz, int64_t obj) {
14012         LDKGossipTimestampFilter obj_conv;
14013         obj_conv.inner = (void*)(obj & (~1));
14014         obj_conv.is_owned = false;
14015         LDKCVec_u8Z arg_var = GossipTimestampFilter_write(&obj_conv);
14016         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
14017         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
14018         CVec_u8Z_free(arg_var);
14019         return arg_arr;
14020 }
14021
14022 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_MessageHandler_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
14023         LDKMessageHandler this_ptr_conv;
14024         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14025         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
14026         MessageHandler_free(this_ptr_conv);
14027 }
14028
14029 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_MessageHandler_1get_1chan_1handler(JNIEnv *env, jclass clz, int64_t this_ptr) {
14030         LDKMessageHandler this_ptr_conv;
14031         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14032         this_ptr_conv.is_owned = false;
14033         long ret_ret = (long)MessageHandler_get_chan_handler(&this_ptr_conv);
14034         return ret_ret;
14035 }
14036
14037 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_MessageHandler_1set_1chan_1handler(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
14038         LDKMessageHandler this_ptr_conv;
14039         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14040         this_ptr_conv.is_owned = false;
14041         LDKChannelMessageHandler val_conv = *(LDKChannelMessageHandler*)val;
14042         if (val_conv.free == LDKChannelMessageHandler_JCalls_free) {
14043                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
14044                 LDKChannelMessageHandler_JCalls_clone(val_conv.this_arg);
14045         }
14046         MessageHandler_set_chan_handler(&this_ptr_conv, val_conv);
14047 }
14048
14049 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_MessageHandler_1get_1route_1handler(JNIEnv *env, jclass clz, int64_t this_ptr) {
14050         LDKMessageHandler this_ptr_conv;
14051         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14052         this_ptr_conv.is_owned = false;
14053         long ret_ret = (long)MessageHandler_get_route_handler(&this_ptr_conv);
14054         return ret_ret;
14055 }
14056
14057 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_MessageHandler_1set_1route_1handler(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
14058         LDKMessageHandler this_ptr_conv;
14059         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14060         this_ptr_conv.is_owned = false;
14061         LDKRoutingMessageHandler val_conv = *(LDKRoutingMessageHandler*)val;
14062         if (val_conv.free == LDKRoutingMessageHandler_JCalls_free) {
14063                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
14064                 LDKRoutingMessageHandler_JCalls_clone(val_conv.this_arg);
14065         }
14066         MessageHandler_set_route_handler(&this_ptr_conv, val_conv);
14067 }
14068
14069 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) {
14070         LDKChannelMessageHandler chan_handler_arg_conv = *(LDKChannelMessageHandler*)chan_handler_arg;
14071         if (chan_handler_arg_conv.free == LDKChannelMessageHandler_JCalls_free) {
14072                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
14073                 LDKChannelMessageHandler_JCalls_clone(chan_handler_arg_conv.this_arg);
14074         }
14075         LDKRoutingMessageHandler route_handler_arg_conv = *(LDKRoutingMessageHandler*)route_handler_arg;
14076         if (route_handler_arg_conv.free == LDKRoutingMessageHandler_JCalls_free) {
14077                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
14078                 LDKRoutingMessageHandler_JCalls_clone(route_handler_arg_conv.this_arg);
14079         }
14080         LDKMessageHandler ret_var = MessageHandler_new(chan_handler_arg_conv, route_handler_arg_conv);
14081         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14082         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14083         long ret_ref = (long)ret_var.inner;
14084         if (ret_var.is_owned) {
14085                 ret_ref |= 1;
14086         }
14087         return ret_ref;
14088 }
14089
14090 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_SocketDescriptor_1clone(JNIEnv *env, jclass clz, int64_t orig) {
14091         LDKSocketDescriptor* orig_conv = (LDKSocketDescriptor*)orig;
14092         LDKSocketDescriptor* ret = MALLOC(sizeof(LDKSocketDescriptor), "LDKSocketDescriptor");
14093         *ret = SocketDescriptor_clone(orig_conv);
14094         return (long)ret;
14095 }
14096
14097 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_SocketDescriptor_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
14098         LDKSocketDescriptor this_ptr_conv = *(LDKSocketDescriptor*)this_ptr;
14099         FREE((void*)this_ptr);
14100         SocketDescriptor_free(this_ptr_conv);
14101 }
14102
14103 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_PeerHandleError_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
14104         LDKPeerHandleError this_ptr_conv;
14105         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14106         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
14107         PeerHandleError_free(this_ptr_conv);
14108 }
14109
14110 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_PeerHandleError_1get_1no_1connection_1possible(JNIEnv *env, jclass clz, int64_t this_ptr) {
14111         LDKPeerHandleError this_ptr_conv;
14112         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14113         this_ptr_conv.is_owned = false;
14114         jboolean ret_val = PeerHandleError_get_no_connection_possible(&this_ptr_conv);
14115         return ret_val;
14116 }
14117
14118 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_PeerHandleError_1set_1no_1connection_1possible(JNIEnv *env, jclass clz, int64_t this_ptr, jboolean val) {
14119         LDKPeerHandleError this_ptr_conv;
14120         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14121         this_ptr_conv.is_owned = false;
14122         PeerHandleError_set_no_connection_possible(&this_ptr_conv, val);
14123 }
14124
14125 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_PeerHandleError_1new(JNIEnv *env, jclass clz, jboolean no_connection_possible_arg) {
14126         LDKPeerHandleError ret_var = PeerHandleError_new(no_connection_possible_arg);
14127         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14128         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14129         long ret_ref = (long)ret_var.inner;
14130         if (ret_var.is_owned) {
14131                 ret_ref |= 1;
14132         }
14133         return ret_ref;
14134 }
14135
14136 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_PeerManager_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
14137         LDKPeerManager this_ptr_conv;
14138         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14139         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
14140         PeerManager_free(this_ptr_conv);
14141 }
14142
14143 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) {
14144         LDKMessageHandler message_handler_conv;
14145         message_handler_conv.inner = (void*)(message_handler & (~1));
14146         message_handler_conv.is_owned = (message_handler & 1) || (message_handler == 0);
14147         // Warning: we may need a move here but can't clone!
14148         LDKSecretKey our_node_secret_ref;
14149         CHECK((*env)->GetArrayLength(env, our_node_secret) == 32);
14150         (*env)->GetByteArrayRegion(env, our_node_secret, 0, 32, our_node_secret_ref.bytes);
14151         unsigned char ephemeral_random_data_arr[32];
14152         CHECK((*env)->GetArrayLength(env, ephemeral_random_data) == 32);
14153         (*env)->GetByteArrayRegion(env, ephemeral_random_data, 0, 32, ephemeral_random_data_arr);
14154         unsigned char (*ephemeral_random_data_ref)[32] = &ephemeral_random_data_arr;
14155         LDKLogger logger_conv = *(LDKLogger*)logger;
14156         if (logger_conv.free == LDKLogger_JCalls_free) {
14157                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
14158                 LDKLogger_JCalls_clone(logger_conv.this_arg);
14159         }
14160         LDKPeerManager ret_var = PeerManager_new(message_handler_conv, our_node_secret_ref, ephemeral_random_data_ref, logger_conv);
14161         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14162         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14163         long ret_ref = (long)ret_var.inner;
14164         if (ret_var.is_owned) {
14165                 ret_ref |= 1;
14166         }
14167         return ret_ref;
14168 }
14169
14170 JNIEXPORT jobjectArray JNICALL Java_org_ldk_impl_bindings_PeerManager_1get_1peer_1node_1ids(JNIEnv *env, jclass clz, int64_t this_arg) {
14171         LDKPeerManager this_arg_conv;
14172         this_arg_conv.inner = (void*)(this_arg & (~1));
14173         this_arg_conv.is_owned = false;
14174         LDKCVec_PublicKeyZ ret_var = PeerManager_get_peer_node_ids(&this_arg_conv);
14175         jobjectArray ret_arr = (*env)->NewObjectArray(env, ret_var.datalen, arr_of_B_clz, NULL);
14176         for (size_t i = 0; i < ret_var.datalen; i++) {
14177                 int8_tArray arr_conv_8_arr = (*env)->NewByteArray(env, 33);
14178                 (*env)->SetByteArrayRegion(env, arr_conv_8_arr, 0, 33, ret_var.data[i].compressed_form);
14179                 (*env)->SetObjectArrayElement(env, ret_arr, i, arr_conv_8_arr);
14180         }
14181         FREE(ret_var.data);
14182         return ret_arr;
14183 }
14184
14185 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) {
14186         LDKPeerManager this_arg_conv;
14187         this_arg_conv.inner = (void*)(this_arg & (~1));
14188         this_arg_conv.is_owned = false;
14189         LDKPublicKey their_node_id_ref;
14190         CHECK((*env)->GetArrayLength(env, their_node_id) == 33);
14191         (*env)->GetByteArrayRegion(env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
14192         LDKSocketDescriptor descriptor_conv = *(LDKSocketDescriptor*)descriptor;
14193         if (descriptor_conv.free == LDKSocketDescriptor_JCalls_free) {
14194                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
14195                 LDKSocketDescriptor_JCalls_clone(descriptor_conv.this_arg);
14196         }
14197         LDKCResult_CVec_u8ZPeerHandleErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_CVec_u8ZPeerHandleErrorZ), "LDKCResult_CVec_u8ZPeerHandleErrorZ");
14198         *ret_conv = PeerManager_new_outbound_connection(&this_arg_conv, their_node_id_ref, descriptor_conv);
14199         return (long)ret_conv;
14200 }
14201
14202 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_PeerManager_1new_1inbound_1connection(JNIEnv *env, jclass clz, int64_t this_arg, int64_t descriptor) {
14203         LDKPeerManager this_arg_conv;
14204         this_arg_conv.inner = (void*)(this_arg & (~1));
14205         this_arg_conv.is_owned = false;
14206         LDKSocketDescriptor descriptor_conv = *(LDKSocketDescriptor*)descriptor;
14207         if (descriptor_conv.free == LDKSocketDescriptor_JCalls_free) {
14208                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
14209                 LDKSocketDescriptor_JCalls_clone(descriptor_conv.this_arg);
14210         }
14211         LDKCResult_NonePeerHandleErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NonePeerHandleErrorZ), "LDKCResult_NonePeerHandleErrorZ");
14212         *ret_conv = PeerManager_new_inbound_connection(&this_arg_conv, descriptor_conv);
14213         return (long)ret_conv;
14214 }
14215
14216 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) {
14217         LDKPeerManager this_arg_conv;
14218         this_arg_conv.inner = (void*)(this_arg & (~1));
14219         this_arg_conv.is_owned = false;
14220         LDKSocketDescriptor* descriptor_conv = (LDKSocketDescriptor*)descriptor;
14221         LDKCResult_NonePeerHandleErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NonePeerHandleErrorZ), "LDKCResult_NonePeerHandleErrorZ");
14222         *ret_conv = PeerManager_write_buffer_space_avail(&this_arg_conv, descriptor_conv);
14223         return (long)ret_conv;
14224 }
14225
14226 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) {
14227         LDKPeerManager this_arg_conv;
14228         this_arg_conv.inner = (void*)(this_arg & (~1));
14229         this_arg_conv.is_owned = false;
14230         LDKSocketDescriptor* peer_descriptor_conv = (LDKSocketDescriptor*)peer_descriptor;
14231         LDKu8slice data_ref;
14232         data_ref.datalen = (*env)->GetArrayLength(env, data);
14233         data_ref.data = (*env)->GetByteArrayElements (env, data, NULL);
14234         LDKCResult_boolPeerHandleErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_boolPeerHandleErrorZ), "LDKCResult_boolPeerHandleErrorZ");
14235         *ret_conv = PeerManager_read_event(&this_arg_conv, peer_descriptor_conv, data_ref);
14236         (*env)->ReleaseByteArrayElements(env, data, (int8_t*)data_ref.data, 0);
14237         return (long)ret_conv;
14238 }
14239
14240 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_PeerManager_1process_1events(JNIEnv *env, jclass clz, int64_t this_arg) {
14241         LDKPeerManager this_arg_conv;
14242         this_arg_conv.inner = (void*)(this_arg & (~1));
14243         this_arg_conv.is_owned = false;
14244         PeerManager_process_events(&this_arg_conv);
14245 }
14246
14247 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_PeerManager_1socket_1disconnected(JNIEnv *env, jclass clz, int64_t this_arg, int64_t descriptor) {
14248         LDKPeerManager this_arg_conv;
14249         this_arg_conv.inner = (void*)(this_arg & (~1));
14250         this_arg_conv.is_owned = false;
14251         LDKSocketDescriptor* descriptor_conv = (LDKSocketDescriptor*)descriptor;
14252         PeerManager_socket_disconnected(&this_arg_conv, descriptor_conv);
14253 }
14254
14255 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_PeerManager_1timer_1tick_1occured(JNIEnv *env, jclass clz, int64_t this_arg) {
14256         LDKPeerManager this_arg_conv;
14257         this_arg_conv.inner = (void*)(this_arg & (~1));
14258         this_arg_conv.is_owned = false;
14259         PeerManager_timer_tick_occured(&this_arg_conv);
14260 }
14261
14262 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_build_1commitment_1secret(JNIEnv *env, jclass clz, int8_tArray commitment_seed, int64_t idx) {
14263         unsigned char commitment_seed_arr[32];
14264         CHECK((*env)->GetArrayLength(env, commitment_seed) == 32);
14265         (*env)->GetByteArrayRegion(env, commitment_seed, 0, 32, commitment_seed_arr);
14266         unsigned char (*commitment_seed_ref)[32] = &commitment_seed_arr;
14267         int8_tArray arg_arr = (*env)->NewByteArray(env, 32);
14268         (*env)->SetByteArrayRegion(env, arg_arr, 0, 32, build_commitment_secret(commitment_seed_ref, idx).data);
14269         return arg_arr;
14270 }
14271
14272 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) {
14273         LDKPublicKey per_commitment_point_ref;
14274         CHECK((*env)->GetArrayLength(env, per_commitment_point) == 33);
14275         (*env)->GetByteArrayRegion(env, per_commitment_point, 0, 33, per_commitment_point_ref.compressed_form);
14276         unsigned char base_secret_arr[32];
14277         CHECK((*env)->GetArrayLength(env, base_secret) == 32);
14278         (*env)->GetByteArrayRegion(env, base_secret, 0, 32, base_secret_arr);
14279         unsigned char (*base_secret_ref)[32] = &base_secret_arr;
14280         LDKCResult_SecretKeySecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_SecretKeySecpErrorZ), "LDKCResult_SecretKeySecpErrorZ");
14281         *ret_conv = derive_private_key(per_commitment_point_ref, base_secret_ref);
14282         return (long)ret_conv;
14283 }
14284
14285 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) {
14286         LDKPublicKey per_commitment_point_ref;
14287         CHECK((*env)->GetArrayLength(env, per_commitment_point) == 33);
14288         (*env)->GetByteArrayRegion(env, per_commitment_point, 0, 33, per_commitment_point_ref.compressed_form);
14289         LDKPublicKey base_point_ref;
14290         CHECK((*env)->GetArrayLength(env, base_point) == 33);
14291         (*env)->GetByteArrayRegion(env, base_point, 0, 33, base_point_ref.compressed_form);
14292         LDKCResult_PublicKeySecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_PublicKeySecpErrorZ), "LDKCResult_PublicKeySecpErrorZ");
14293         *ret_conv = derive_public_key(per_commitment_point_ref, base_point_ref);
14294         return (long)ret_conv;
14295 }
14296
14297 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) {
14298         unsigned char per_commitment_secret_arr[32];
14299         CHECK((*env)->GetArrayLength(env, per_commitment_secret) == 32);
14300         (*env)->GetByteArrayRegion(env, per_commitment_secret, 0, 32, per_commitment_secret_arr);
14301         unsigned char (*per_commitment_secret_ref)[32] = &per_commitment_secret_arr;
14302         unsigned char countersignatory_revocation_base_secret_arr[32];
14303         CHECK((*env)->GetArrayLength(env, countersignatory_revocation_base_secret) == 32);
14304         (*env)->GetByteArrayRegion(env, countersignatory_revocation_base_secret, 0, 32, countersignatory_revocation_base_secret_arr);
14305         unsigned char (*countersignatory_revocation_base_secret_ref)[32] = &countersignatory_revocation_base_secret_arr;
14306         LDKCResult_SecretKeySecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_SecretKeySecpErrorZ), "LDKCResult_SecretKeySecpErrorZ");
14307         *ret_conv = derive_private_revocation_key(per_commitment_secret_ref, countersignatory_revocation_base_secret_ref);
14308         return (long)ret_conv;
14309 }
14310
14311 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) {
14312         LDKPublicKey per_commitment_point_ref;
14313         CHECK((*env)->GetArrayLength(env, per_commitment_point) == 33);
14314         (*env)->GetByteArrayRegion(env, per_commitment_point, 0, 33, per_commitment_point_ref.compressed_form);
14315         LDKPublicKey countersignatory_revocation_base_point_ref;
14316         CHECK((*env)->GetArrayLength(env, countersignatory_revocation_base_point) == 33);
14317         (*env)->GetByteArrayRegion(env, countersignatory_revocation_base_point, 0, 33, countersignatory_revocation_base_point_ref.compressed_form);
14318         LDKCResult_PublicKeySecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_PublicKeySecpErrorZ), "LDKCResult_PublicKeySecpErrorZ");
14319         *ret_conv = derive_public_revocation_key(per_commitment_point_ref, countersignatory_revocation_base_point_ref);
14320         return (long)ret_conv;
14321 }
14322
14323 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_TxCreationKeys_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
14324         LDKTxCreationKeys this_ptr_conv;
14325         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14326         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
14327         TxCreationKeys_free(this_ptr_conv);
14328 }
14329
14330 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_TxCreationKeys_1clone(JNIEnv *env, jclass clz, int64_t orig) {
14331         LDKTxCreationKeys orig_conv;
14332         orig_conv.inner = (void*)(orig & (~1));
14333         orig_conv.is_owned = false;
14334         LDKTxCreationKeys ret_var = TxCreationKeys_clone(&orig_conv);
14335         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14336         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14337         long ret_ref = (long)ret_var.inner;
14338         if (ret_var.is_owned) {
14339                 ret_ref |= 1;
14340         }
14341         return ret_ref;
14342 }
14343
14344 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_TxCreationKeys_1get_1per_1commitment_1point(JNIEnv *env, jclass clz, int64_t this_ptr) {
14345         LDKTxCreationKeys this_ptr_conv;
14346         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14347         this_ptr_conv.is_owned = false;
14348         int8_tArray arg_arr = (*env)->NewByteArray(env, 33);
14349         (*env)->SetByteArrayRegion(env, arg_arr, 0, 33, TxCreationKeys_get_per_commitment_point(&this_ptr_conv).compressed_form);
14350         return arg_arr;
14351 }
14352
14353 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_TxCreationKeys_1set_1per_1commitment_1point(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
14354         LDKTxCreationKeys this_ptr_conv;
14355         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14356         this_ptr_conv.is_owned = false;
14357         LDKPublicKey val_ref;
14358         CHECK((*env)->GetArrayLength(env, val) == 33);
14359         (*env)->GetByteArrayRegion(env, val, 0, 33, val_ref.compressed_form);
14360         TxCreationKeys_set_per_commitment_point(&this_ptr_conv, val_ref);
14361 }
14362
14363 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_TxCreationKeys_1get_1revocation_1key(JNIEnv *env, jclass clz, int64_t this_ptr) {
14364         LDKTxCreationKeys this_ptr_conv;
14365         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14366         this_ptr_conv.is_owned = false;
14367         int8_tArray arg_arr = (*env)->NewByteArray(env, 33);
14368         (*env)->SetByteArrayRegion(env, arg_arr, 0, 33, TxCreationKeys_get_revocation_key(&this_ptr_conv).compressed_form);
14369         return arg_arr;
14370 }
14371
14372 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_TxCreationKeys_1set_1revocation_1key(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
14373         LDKTxCreationKeys this_ptr_conv;
14374         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14375         this_ptr_conv.is_owned = false;
14376         LDKPublicKey val_ref;
14377         CHECK((*env)->GetArrayLength(env, val) == 33);
14378         (*env)->GetByteArrayRegion(env, val, 0, 33, val_ref.compressed_form);
14379         TxCreationKeys_set_revocation_key(&this_ptr_conv, val_ref);
14380 }
14381
14382 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_TxCreationKeys_1get_1broadcaster_1htlc_1key(JNIEnv *env, jclass clz, int64_t this_ptr) {
14383         LDKTxCreationKeys this_ptr_conv;
14384         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14385         this_ptr_conv.is_owned = false;
14386         int8_tArray arg_arr = (*env)->NewByteArray(env, 33);
14387         (*env)->SetByteArrayRegion(env, arg_arr, 0, 33, TxCreationKeys_get_broadcaster_htlc_key(&this_ptr_conv).compressed_form);
14388         return arg_arr;
14389 }
14390
14391 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_TxCreationKeys_1set_1broadcaster_1htlc_1key(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
14392         LDKTxCreationKeys this_ptr_conv;
14393         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14394         this_ptr_conv.is_owned = false;
14395         LDKPublicKey val_ref;
14396         CHECK((*env)->GetArrayLength(env, val) == 33);
14397         (*env)->GetByteArrayRegion(env, val, 0, 33, val_ref.compressed_form);
14398         TxCreationKeys_set_broadcaster_htlc_key(&this_ptr_conv, val_ref);
14399 }
14400
14401 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_TxCreationKeys_1get_1countersignatory_1htlc_1key(JNIEnv *env, jclass clz, int64_t this_ptr) {
14402         LDKTxCreationKeys this_ptr_conv;
14403         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14404         this_ptr_conv.is_owned = false;
14405         int8_tArray arg_arr = (*env)->NewByteArray(env, 33);
14406         (*env)->SetByteArrayRegion(env, arg_arr, 0, 33, TxCreationKeys_get_countersignatory_htlc_key(&this_ptr_conv).compressed_form);
14407         return arg_arr;
14408 }
14409
14410 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_TxCreationKeys_1set_1countersignatory_1htlc_1key(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
14411         LDKTxCreationKeys this_ptr_conv;
14412         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14413         this_ptr_conv.is_owned = false;
14414         LDKPublicKey val_ref;
14415         CHECK((*env)->GetArrayLength(env, val) == 33);
14416         (*env)->GetByteArrayRegion(env, val, 0, 33, val_ref.compressed_form);
14417         TxCreationKeys_set_countersignatory_htlc_key(&this_ptr_conv, val_ref);
14418 }
14419
14420 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_TxCreationKeys_1get_1broadcaster_1delayed_1payment_1key(JNIEnv *env, jclass clz, int64_t this_ptr) {
14421         LDKTxCreationKeys this_ptr_conv;
14422         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14423         this_ptr_conv.is_owned = false;
14424         int8_tArray arg_arr = (*env)->NewByteArray(env, 33);
14425         (*env)->SetByteArrayRegion(env, arg_arr, 0, 33, TxCreationKeys_get_broadcaster_delayed_payment_key(&this_ptr_conv).compressed_form);
14426         return arg_arr;
14427 }
14428
14429 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) {
14430         LDKTxCreationKeys this_ptr_conv;
14431         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14432         this_ptr_conv.is_owned = false;
14433         LDKPublicKey val_ref;
14434         CHECK((*env)->GetArrayLength(env, val) == 33);
14435         (*env)->GetByteArrayRegion(env, val, 0, 33, val_ref.compressed_form);
14436         TxCreationKeys_set_broadcaster_delayed_payment_key(&this_ptr_conv, val_ref);
14437 }
14438
14439 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) {
14440         LDKPublicKey per_commitment_point_arg_ref;
14441         CHECK((*env)->GetArrayLength(env, per_commitment_point_arg) == 33);
14442         (*env)->GetByteArrayRegion(env, per_commitment_point_arg, 0, 33, per_commitment_point_arg_ref.compressed_form);
14443         LDKPublicKey revocation_key_arg_ref;
14444         CHECK((*env)->GetArrayLength(env, revocation_key_arg) == 33);
14445         (*env)->GetByteArrayRegion(env, revocation_key_arg, 0, 33, revocation_key_arg_ref.compressed_form);
14446         LDKPublicKey broadcaster_htlc_key_arg_ref;
14447         CHECK((*env)->GetArrayLength(env, broadcaster_htlc_key_arg) == 33);
14448         (*env)->GetByteArrayRegion(env, broadcaster_htlc_key_arg, 0, 33, broadcaster_htlc_key_arg_ref.compressed_form);
14449         LDKPublicKey countersignatory_htlc_key_arg_ref;
14450         CHECK((*env)->GetArrayLength(env, countersignatory_htlc_key_arg) == 33);
14451         (*env)->GetByteArrayRegion(env, countersignatory_htlc_key_arg, 0, 33, countersignatory_htlc_key_arg_ref.compressed_form);
14452         LDKPublicKey broadcaster_delayed_payment_key_arg_ref;
14453         CHECK((*env)->GetArrayLength(env, broadcaster_delayed_payment_key_arg) == 33);
14454         (*env)->GetByteArrayRegion(env, broadcaster_delayed_payment_key_arg, 0, 33, broadcaster_delayed_payment_key_arg_ref.compressed_form);
14455         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);
14456         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14457         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14458         long ret_ref = (long)ret_var.inner;
14459         if (ret_var.is_owned) {
14460                 ret_ref |= 1;
14461         }
14462         return ret_ref;
14463 }
14464
14465 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_TxCreationKeys_1write(JNIEnv *env, jclass clz, int64_t obj) {
14466         LDKTxCreationKeys obj_conv;
14467         obj_conv.inner = (void*)(obj & (~1));
14468         obj_conv.is_owned = false;
14469         LDKCVec_u8Z arg_var = TxCreationKeys_write(&obj_conv);
14470         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
14471         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
14472         CVec_u8Z_free(arg_var);
14473         return arg_arr;
14474 }
14475
14476 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_TxCreationKeys_1read(JNIEnv *env, jclass clz, int8_tArray ser) {
14477         LDKu8slice ser_ref;
14478         ser_ref.datalen = (*env)->GetArrayLength(env, ser);
14479         ser_ref.data = (*env)->GetByteArrayElements (env, ser, NULL);
14480         LDKTxCreationKeys ret_var = TxCreationKeys_read(ser_ref);
14481         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14482         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14483         long ret_ref = (long)ret_var.inner;
14484         if (ret_var.is_owned) {
14485                 ret_ref |= 1;
14486         }
14487         (*env)->ReleaseByteArrayElements(env, ser, (int8_t*)ser_ref.data, 0);
14488         return ret_ref;
14489 }
14490
14491 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelPublicKeys_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
14492         LDKChannelPublicKeys this_ptr_conv;
14493         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14494         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
14495         ChannelPublicKeys_free(this_ptr_conv);
14496 }
14497
14498 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelPublicKeys_1clone(JNIEnv *env, jclass clz, int64_t orig) {
14499         LDKChannelPublicKeys orig_conv;
14500         orig_conv.inner = (void*)(orig & (~1));
14501         orig_conv.is_owned = false;
14502         LDKChannelPublicKeys ret_var = ChannelPublicKeys_clone(&orig_conv);
14503         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14504         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14505         long ret_ref = (long)ret_var.inner;
14506         if (ret_var.is_owned) {
14507                 ret_ref |= 1;
14508         }
14509         return ret_ref;
14510 }
14511
14512 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_ChannelPublicKeys_1get_1funding_1pubkey(JNIEnv *env, jclass clz, int64_t this_ptr) {
14513         LDKChannelPublicKeys this_ptr_conv;
14514         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14515         this_ptr_conv.is_owned = false;
14516         int8_tArray arg_arr = (*env)->NewByteArray(env, 33);
14517         (*env)->SetByteArrayRegion(env, arg_arr, 0, 33, ChannelPublicKeys_get_funding_pubkey(&this_ptr_conv).compressed_form);
14518         return arg_arr;
14519 }
14520
14521 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelPublicKeys_1set_1funding_1pubkey(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
14522         LDKChannelPublicKeys this_ptr_conv;
14523         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14524         this_ptr_conv.is_owned = false;
14525         LDKPublicKey val_ref;
14526         CHECK((*env)->GetArrayLength(env, val) == 33);
14527         (*env)->GetByteArrayRegion(env, val, 0, 33, val_ref.compressed_form);
14528         ChannelPublicKeys_set_funding_pubkey(&this_ptr_conv, val_ref);
14529 }
14530
14531 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_ChannelPublicKeys_1get_1revocation_1basepoint(JNIEnv *env, jclass clz, int64_t this_ptr) {
14532         LDKChannelPublicKeys this_ptr_conv;
14533         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14534         this_ptr_conv.is_owned = false;
14535         int8_tArray arg_arr = (*env)->NewByteArray(env, 33);
14536         (*env)->SetByteArrayRegion(env, arg_arr, 0, 33, ChannelPublicKeys_get_revocation_basepoint(&this_ptr_conv).compressed_form);
14537         return arg_arr;
14538 }
14539
14540 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelPublicKeys_1set_1revocation_1basepoint(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
14541         LDKChannelPublicKeys this_ptr_conv;
14542         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14543         this_ptr_conv.is_owned = false;
14544         LDKPublicKey val_ref;
14545         CHECK((*env)->GetArrayLength(env, val) == 33);
14546         (*env)->GetByteArrayRegion(env, val, 0, 33, val_ref.compressed_form);
14547         ChannelPublicKeys_set_revocation_basepoint(&this_ptr_conv, val_ref);
14548 }
14549
14550 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_ChannelPublicKeys_1get_1payment_1point(JNIEnv *env, jclass clz, int64_t this_ptr) {
14551         LDKChannelPublicKeys this_ptr_conv;
14552         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14553         this_ptr_conv.is_owned = false;
14554         int8_tArray arg_arr = (*env)->NewByteArray(env, 33);
14555         (*env)->SetByteArrayRegion(env, arg_arr, 0, 33, ChannelPublicKeys_get_payment_point(&this_ptr_conv).compressed_form);
14556         return arg_arr;
14557 }
14558
14559 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelPublicKeys_1set_1payment_1point(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
14560         LDKChannelPublicKeys this_ptr_conv;
14561         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14562         this_ptr_conv.is_owned = false;
14563         LDKPublicKey val_ref;
14564         CHECK((*env)->GetArrayLength(env, val) == 33);
14565         (*env)->GetByteArrayRegion(env, val, 0, 33, val_ref.compressed_form);
14566         ChannelPublicKeys_set_payment_point(&this_ptr_conv, val_ref);
14567 }
14568
14569 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_ChannelPublicKeys_1get_1delayed_1payment_1basepoint(JNIEnv *env, jclass clz, int64_t this_ptr) {
14570         LDKChannelPublicKeys this_ptr_conv;
14571         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14572         this_ptr_conv.is_owned = false;
14573         int8_tArray arg_arr = (*env)->NewByteArray(env, 33);
14574         (*env)->SetByteArrayRegion(env, arg_arr, 0, 33, ChannelPublicKeys_get_delayed_payment_basepoint(&this_ptr_conv).compressed_form);
14575         return arg_arr;
14576 }
14577
14578 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelPublicKeys_1set_1delayed_1payment_1basepoint(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
14579         LDKChannelPublicKeys this_ptr_conv;
14580         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14581         this_ptr_conv.is_owned = false;
14582         LDKPublicKey val_ref;
14583         CHECK((*env)->GetArrayLength(env, val) == 33);
14584         (*env)->GetByteArrayRegion(env, val, 0, 33, val_ref.compressed_form);
14585         ChannelPublicKeys_set_delayed_payment_basepoint(&this_ptr_conv, val_ref);
14586 }
14587
14588 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_ChannelPublicKeys_1get_1htlc_1basepoint(JNIEnv *env, jclass clz, int64_t this_ptr) {
14589         LDKChannelPublicKeys this_ptr_conv;
14590         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14591         this_ptr_conv.is_owned = false;
14592         int8_tArray arg_arr = (*env)->NewByteArray(env, 33);
14593         (*env)->SetByteArrayRegion(env, arg_arr, 0, 33, ChannelPublicKeys_get_htlc_basepoint(&this_ptr_conv).compressed_form);
14594         return arg_arr;
14595 }
14596
14597 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelPublicKeys_1set_1htlc_1basepoint(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
14598         LDKChannelPublicKeys this_ptr_conv;
14599         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14600         this_ptr_conv.is_owned = false;
14601         LDKPublicKey val_ref;
14602         CHECK((*env)->GetArrayLength(env, val) == 33);
14603         (*env)->GetByteArrayRegion(env, val, 0, 33, val_ref.compressed_form);
14604         ChannelPublicKeys_set_htlc_basepoint(&this_ptr_conv, val_ref);
14605 }
14606
14607 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) {
14608         LDKPublicKey funding_pubkey_arg_ref;
14609         CHECK((*env)->GetArrayLength(env, funding_pubkey_arg) == 33);
14610         (*env)->GetByteArrayRegion(env, funding_pubkey_arg, 0, 33, funding_pubkey_arg_ref.compressed_form);
14611         LDKPublicKey revocation_basepoint_arg_ref;
14612         CHECK((*env)->GetArrayLength(env, revocation_basepoint_arg) == 33);
14613         (*env)->GetByteArrayRegion(env, revocation_basepoint_arg, 0, 33, revocation_basepoint_arg_ref.compressed_form);
14614         LDKPublicKey payment_point_arg_ref;
14615         CHECK((*env)->GetArrayLength(env, payment_point_arg) == 33);
14616         (*env)->GetByteArrayRegion(env, payment_point_arg, 0, 33, payment_point_arg_ref.compressed_form);
14617         LDKPublicKey delayed_payment_basepoint_arg_ref;
14618         CHECK((*env)->GetArrayLength(env, delayed_payment_basepoint_arg) == 33);
14619         (*env)->GetByteArrayRegion(env, delayed_payment_basepoint_arg, 0, 33, delayed_payment_basepoint_arg_ref.compressed_form);
14620         LDKPublicKey htlc_basepoint_arg_ref;
14621         CHECK((*env)->GetArrayLength(env, htlc_basepoint_arg) == 33);
14622         (*env)->GetByteArrayRegion(env, htlc_basepoint_arg, 0, 33, htlc_basepoint_arg_ref.compressed_form);
14623         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);
14624         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14625         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14626         long ret_ref = (long)ret_var.inner;
14627         if (ret_var.is_owned) {
14628                 ret_ref |= 1;
14629         }
14630         return ret_ref;
14631 }
14632
14633 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_ChannelPublicKeys_1write(JNIEnv *env, jclass clz, int64_t obj) {
14634         LDKChannelPublicKeys obj_conv;
14635         obj_conv.inner = (void*)(obj & (~1));
14636         obj_conv.is_owned = false;
14637         LDKCVec_u8Z arg_var = ChannelPublicKeys_write(&obj_conv);
14638         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
14639         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
14640         CVec_u8Z_free(arg_var);
14641         return arg_arr;
14642 }
14643
14644 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelPublicKeys_1read(JNIEnv *env, jclass clz, int8_tArray ser) {
14645         LDKu8slice ser_ref;
14646         ser_ref.datalen = (*env)->GetArrayLength(env, ser);
14647         ser_ref.data = (*env)->GetByteArrayElements (env, ser, NULL);
14648         LDKChannelPublicKeys ret_var = ChannelPublicKeys_read(ser_ref);
14649         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14650         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14651         long ret_ref = (long)ret_var.inner;
14652         if (ret_var.is_owned) {
14653                 ret_ref |= 1;
14654         }
14655         (*env)->ReleaseByteArrayElements(env, ser, (int8_t*)ser_ref.data, 0);
14656         return ret_ref;
14657 }
14658
14659 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) {
14660         LDKPublicKey per_commitment_point_ref;
14661         CHECK((*env)->GetArrayLength(env, per_commitment_point) == 33);
14662         (*env)->GetByteArrayRegion(env, per_commitment_point, 0, 33, per_commitment_point_ref.compressed_form);
14663         LDKPublicKey broadcaster_delayed_payment_base_ref;
14664         CHECK((*env)->GetArrayLength(env, broadcaster_delayed_payment_base) == 33);
14665         (*env)->GetByteArrayRegion(env, broadcaster_delayed_payment_base, 0, 33, broadcaster_delayed_payment_base_ref.compressed_form);
14666         LDKPublicKey broadcaster_htlc_base_ref;
14667         CHECK((*env)->GetArrayLength(env, broadcaster_htlc_base) == 33);
14668         (*env)->GetByteArrayRegion(env, broadcaster_htlc_base, 0, 33, broadcaster_htlc_base_ref.compressed_form);
14669         LDKPublicKey countersignatory_revocation_base_ref;
14670         CHECK((*env)->GetArrayLength(env, countersignatory_revocation_base) == 33);
14671         (*env)->GetByteArrayRegion(env, countersignatory_revocation_base, 0, 33, countersignatory_revocation_base_ref.compressed_form);
14672         LDKPublicKey countersignatory_htlc_base_ref;
14673         CHECK((*env)->GetArrayLength(env, countersignatory_htlc_base) == 33);
14674         (*env)->GetByteArrayRegion(env, countersignatory_htlc_base, 0, 33, countersignatory_htlc_base_ref.compressed_form);
14675         LDKCResult_TxCreationKeysSecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_TxCreationKeysSecpErrorZ), "LDKCResult_TxCreationKeysSecpErrorZ");
14676         *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);
14677         return (long)ret_conv;
14678 }
14679
14680 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) {
14681         LDKPublicKey per_commitment_point_ref;
14682         CHECK((*env)->GetArrayLength(env, per_commitment_point) == 33);
14683         (*env)->GetByteArrayRegion(env, per_commitment_point, 0, 33, per_commitment_point_ref.compressed_form);
14684         LDKChannelPublicKeys broadcaster_keys_conv;
14685         broadcaster_keys_conv.inner = (void*)(broadcaster_keys & (~1));
14686         broadcaster_keys_conv.is_owned = false;
14687         LDKChannelPublicKeys countersignatory_keys_conv;
14688         countersignatory_keys_conv.inner = (void*)(countersignatory_keys & (~1));
14689         countersignatory_keys_conv.is_owned = false;
14690         LDKCResult_TxCreationKeysSecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_TxCreationKeysSecpErrorZ), "LDKCResult_TxCreationKeysSecpErrorZ");
14691         *ret_conv = TxCreationKeys_from_channel_static_keys(per_commitment_point_ref, &broadcaster_keys_conv, &countersignatory_keys_conv);
14692         return (long)ret_conv;
14693 }
14694
14695 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_get_1revokeable_1redeemscript(JNIEnv *env, jclass clz, int8_tArray revocation_key, jshort contest_delay, int8_tArray broadcaster_delayed_payment_key) {
14696         LDKPublicKey revocation_key_ref;
14697         CHECK((*env)->GetArrayLength(env, revocation_key) == 33);
14698         (*env)->GetByteArrayRegion(env, revocation_key, 0, 33, revocation_key_ref.compressed_form);
14699         LDKPublicKey broadcaster_delayed_payment_key_ref;
14700         CHECK((*env)->GetArrayLength(env, broadcaster_delayed_payment_key) == 33);
14701         (*env)->GetByteArrayRegion(env, broadcaster_delayed_payment_key, 0, 33, broadcaster_delayed_payment_key_ref.compressed_form);
14702         LDKCVec_u8Z arg_var = get_revokeable_redeemscript(revocation_key_ref, contest_delay, broadcaster_delayed_payment_key_ref);
14703         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
14704         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
14705         CVec_u8Z_free(arg_var);
14706         return arg_arr;
14707 }
14708
14709 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_HTLCOutputInCommitment_1free(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 = (this_ptr & 1) || (this_ptr == 0);
14713         HTLCOutputInCommitment_free(this_ptr_conv);
14714 }
14715
14716 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_HTLCOutputInCommitment_1clone(JNIEnv *env, jclass clz, int64_t orig) {
14717         LDKHTLCOutputInCommitment orig_conv;
14718         orig_conv.inner = (void*)(orig & (~1));
14719         orig_conv.is_owned = false;
14720         LDKHTLCOutputInCommitment ret_var = HTLCOutputInCommitment_clone(&orig_conv);
14721         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14722         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14723         long ret_ref = (long)ret_var.inner;
14724         if (ret_var.is_owned) {
14725                 ret_ref |= 1;
14726         }
14727         return ret_ref;
14728 }
14729
14730 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_HTLCOutputInCommitment_1get_1offered(JNIEnv *env, jclass clz, int64_t this_ptr) {
14731         LDKHTLCOutputInCommitment this_ptr_conv;
14732         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14733         this_ptr_conv.is_owned = false;
14734         jboolean ret_val = HTLCOutputInCommitment_get_offered(&this_ptr_conv);
14735         return ret_val;
14736 }
14737
14738 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_HTLCOutputInCommitment_1set_1offered(JNIEnv *env, jclass clz, int64_t this_ptr, jboolean val) {
14739         LDKHTLCOutputInCommitment this_ptr_conv;
14740         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14741         this_ptr_conv.is_owned = false;
14742         HTLCOutputInCommitment_set_offered(&this_ptr_conv, val);
14743 }
14744
14745 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_HTLCOutputInCommitment_1get_1amount_1msat(JNIEnv *env, jclass clz, int64_t this_ptr) {
14746         LDKHTLCOutputInCommitment this_ptr_conv;
14747         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14748         this_ptr_conv.is_owned = false;
14749         int64_t ret_val = HTLCOutputInCommitment_get_amount_msat(&this_ptr_conv);
14750         return ret_val;
14751 }
14752
14753 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_HTLCOutputInCommitment_1set_1amount_1msat(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
14754         LDKHTLCOutputInCommitment this_ptr_conv;
14755         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14756         this_ptr_conv.is_owned = false;
14757         HTLCOutputInCommitment_set_amount_msat(&this_ptr_conv, val);
14758 }
14759
14760 JNIEXPORT int32_t JNICALL Java_org_ldk_impl_bindings_HTLCOutputInCommitment_1get_1cltv_1expiry(JNIEnv *env, jclass clz, int64_t this_ptr) {
14761         LDKHTLCOutputInCommitment this_ptr_conv;
14762         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14763         this_ptr_conv.is_owned = false;
14764         int32_t ret_val = HTLCOutputInCommitment_get_cltv_expiry(&this_ptr_conv);
14765         return ret_val;
14766 }
14767
14768 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_HTLCOutputInCommitment_1set_1cltv_1expiry(JNIEnv *env, jclass clz, int64_t this_ptr, int32_t val) {
14769         LDKHTLCOutputInCommitment this_ptr_conv;
14770         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14771         this_ptr_conv.is_owned = false;
14772         HTLCOutputInCommitment_set_cltv_expiry(&this_ptr_conv, val);
14773 }
14774
14775 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_HTLCOutputInCommitment_1get_1payment_1hash(JNIEnv *env, jclass clz, int64_t this_ptr) {
14776         LDKHTLCOutputInCommitment this_ptr_conv;
14777         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14778         this_ptr_conv.is_owned = false;
14779         int8_tArray ret_arr = (*env)->NewByteArray(env, 32);
14780         (*env)->SetByteArrayRegion(env, ret_arr, 0, 32, *HTLCOutputInCommitment_get_payment_hash(&this_ptr_conv));
14781         return ret_arr;
14782 }
14783
14784 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_HTLCOutputInCommitment_1set_1payment_1hash(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
14785         LDKHTLCOutputInCommitment this_ptr_conv;
14786         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14787         this_ptr_conv.is_owned = false;
14788         LDKThirtyTwoBytes val_ref;
14789         CHECK((*env)->GetArrayLength(env, val) == 32);
14790         (*env)->GetByteArrayRegion(env, val, 0, 32, val_ref.data);
14791         HTLCOutputInCommitment_set_payment_hash(&this_ptr_conv, val_ref);
14792 }
14793
14794 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_HTLCOutputInCommitment_1write(JNIEnv *env, jclass clz, int64_t obj) {
14795         LDKHTLCOutputInCommitment obj_conv;
14796         obj_conv.inner = (void*)(obj & (~1));
14797         obj_conv.is_owned = false;
14798         LDKCVec_u8Z arg_var = HTLCOutputInCommitment_write(&obj_conv);
14799         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
14800         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
14801         CVec_u8Z_free(arg_var);
14802         return arg_arr;
14803 }
14804
14805 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_HTLCOutputInCommitment_1read(JNIEnv *env, jclass clz, int8_tArray ser) {
14806         LDKu8slice ser_ref;
14807         ser_ref.datalen = (*env)->GetArrayLength(env, ser);
14808         ser_ref.data = (*env)->GetByteArrayElements (env, ser, NULL);
14809         LDKHTLCOutputInCommitment ret_var = HTLCOutputInCommitment_read(ser_ref);
14810         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14811         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14812         long ret_ref = (long)ret_var.inner;
14813         if (ret_var.is_owned) {
14814                 ret_ref |= 1;
14815         }
14816         (*env)->ReleaseByteArrayElements(env, ser, (int8_t*)ser_ref.data, 0);
14817         return ret_ref;
14818 }
14819
14820 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_get_1htlc_1redeemscript(JNIEnv *env, jclass clz, int64_t htlc, int64_t keys) {
14821         LDKHTLCOutputInCommitment htlc_conv;
14822         htlc_conv.inner = (void*)(htlc & (~1));
14823         htlc_conv.is_owned = false;
14824         LDKTxCreationKeys keys_conv;
14825         keys_conv.inner = (void*)(keys & (~1));
14826         keys_conv.is_owned = false;
14827         LDKCVec_u8Z arg_var = get_htlc_redeemscript(&htlc_conv, &keys_conv);
14828         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
14829         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
14830         CVec_u8Z_free(arg_var);
14831         return arg_arr;
14832 }
14833
14834 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_make_1funding_1redeemscript(JNIEnv *env, jclass clz, int8_tArray broadcaster, int8_tArray countersignatory) {
14835         LDKPublicKey broadcaster_ref;
14836         CHECK((*env)->GetArrayLength(env, broadcaster) == 33);
14837         (*env)->GetByteArrayRegion(env, broadcaster, 0, 33, broadcaster_ref.compressed_form);
14838         LDKPublicKey countersignatory_ref;
14839         CHECK((*env)->GetArrayLength(env, countersignatory) == 33);
14840         (*env)->GetByteArrayRegion(env, countersignatory, 0, 33, countersignatory_ref.compressed_form);
14841         LDKCVec_u8Z arg_var = make_funding_redeemscript(broadcaster_ref, countersignatory_ref);
14842         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
14843         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
14844         CVec_u8Z_free(arg_var);
14845         return arg_arr;
14846 }
14847
14848 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, jshort contest_delay, int64_t htlc, int8_tArray broadcaster_delayed_payment_key, int8_tArray revocation_key) {
14849         unsigned char prev_hash_arr[32];
14850         CHECK((*env)->GetArrayLength(env, prev_hash) == 32);
14851         (*env)->GetByteArrayRegion(env, prev_hash, 0, 32, prev_hash_arr);
14852         unsigned char (*prev_hash_ref)[32] = &prev_hash_arr;
14853         LDKHTLCOutputInCommitment htlc_conv;
14854         htlc_conv.inner = (void*)(htlc & (~1));
14855         htlc_conv.is_owned = false;
14856         LDKPublicKey broadcaster_delayed_payment_key_ref;
14857         CHECK((*env)->GetArrayLength(env, broadcaster_delayed_payment_key) == 33);
14858         (*env)->GetByteArrayRegion(env, broadcaster_delayed_payment_key, 0, 33, broadcaster_delayed_payment_key_ref.compressed_form);
14859         LDKPublicKey revocation_key_ref;
14860         CHECK((*env)->GetArrayLength(env, revocation_key) == 33);
14861         (*env)->GetByteArrayRegion(env, revocation_key, 0, 33, revocation_key_ref.compressed_form);
14862         LDKTransaction arg_var = build_htlc_transaction(prev_hash_ref, feerate_per_kw, contest_delay, &htlc_conv, broadcaster_delayed_payment_key_ref, revocation_key_ref);
14863         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
14864         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
14865         Transaction_free(arg_var);
14866         return arg_arr;
14867 }
14868
14869 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelTransactionParameters_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
14870         LDKChannelTransactionParameters this_ptr_conv;
14871         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14872         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
14873         ChannelTransactionParameters_free(this_ptr_conv);
14874 }
14875
14876 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelTransactionParameters_1clone(JNIEnv *env, jclass clz, int64_t orig) {
14877         LDKChannelTransactionParameters orig_conv;
14878         orig_conv.inner = (void*)(orig & (~1));
14879         orig_conv.is_owned = false;
14880         LDKChannelTransactionParameters ret_var = ChannelTransactionParameters_clone(&orig_conv);
14881         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14882         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14883         long ret_ref = (long)ret_var.inner;
14884         if (ret_var.is_owned) {
14885                 ret_ref |= 1;
14886         }
14887         return ret_ref;
14888 }
14889
14890 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelTransactionParameters_1get_1holder_1pubkeys(JNIEnv *env, jclass clz, int64_t this_ptr) {
14891         LDKChannelTransactionParameters this_ptr_conv;
14892         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14893         this_ptr_conv.is_owned = false;
14894         LDKChannelPublicKeys ret_var = ChannelTransactionParameters_get_holder_pubkeys(&this_ptr_conv);
14895         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14896         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14897         long ret_ref = (long)ret_var.inner;
14898         if (ret_var.is_owned) {
14899                 ret_ref |= 1;
14900         }
14901         return ret_ref;
14902 }
14903
14904 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelTransactionParameters_1set_1holder_1pubkeys(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
14905         LDKChannelTransactionParameters this_ptr_conv;
14906         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14907         this_ptr_conv.is_owned = false;
14908         LDKChannelPublicKeys val_conv;
14909         val_conv.inner = (void*)(val & (~1));
14910         val_conv.is_owned = (val & 1) || (val == 0);
14911         if (val_conv.inner != NULL)
14912                 val_conv = ChannelPublicKeys_clone(&val_conv);
14913         ChannelTransactionParameters_set_holder_pubkeys(&this_ptr_conv, val_conv);
14914 }
14915
14916 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_ChannelTransactionParameters_1get_1holder_1selected_1contest_1delay(JNIEnv *env, jclass clz, int64_t this_ptr) {
14917         LDKChannelTransactionParameters this_ptr_conv;
14918         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14919         this_ptr_conv.is_owned = false;
14920         jshort ret_val = ChannelTransactionParameters_get_holder_selected_contest_delay(&this_ptr_conv);
14921         return ret_val;
14922 }
14923
14924 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelTransactionParameters_1set_1holder_1selected_1contest_1delay(JNIEnv *env, jclass clz, int64_t this_ptr, jshort val) {
14925         LDKChannelTransactionParameters this_ptr_conv;
14926         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14927         this_ptr_conv.is_owned = false;
14928         ChannelTransactionParameters_set_holder_selected_contest_delay(&this_ptr_conv, val);
14929 }
14930
14931 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_ChannelTransactionParameters_1get_1is_1outbound_1from_1holder(JNIEnv *env, jclass clz, int64_t this_ptr) {
14932         LDKChannelTransactionParameters this_ptr_conv;
14933         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14934         this_ptr_conv.is_owned = false;
14935         jboolean ret_val = ChannelTransactionParameters_get_is_outbound_from_holder(&this_ptr_conv);
14936         return ret_val;
14937 }
14938
14939 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelTransactionParameters_1set_1is_1outbound_1from_1holder(JNIEnv *env, jclass clz, int64_t this_ptr, jboolean val) {
14940         LDKChannelTransactionParameters this_ptr_conv;
14941         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14942         this_ptr_conv.is_owned = false;
14943         ChannelTransactionParameters_set_is_outbound_from_holder(&this_ptr_conv, val);
14944 }
14945
14946 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelTransactionParameters_1get_1counterparty_1parameters(JNIEnv *env, jclass clz, int64_t this_ptr) {
14947         LDKChannelTransactionParameters this_ptr_conv;
14948         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14949         this_ptr_conv.is_owned = false;
14950         LDKCounterpartyChannelTransactionParameters ret_var = ChannelTransactionParameters_get_counterparty_parameters(&this_ptr_conv);
14951         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14952         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14953         long ret_ref = (long)ret_var.inner;
14954         if (ret_var.is_owned) {
14955                 ret_ref |= 1;
14956         }
14957         return ret_ref;
14958 }
14959
14960 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelTransactionParameters_1set_1counterparty_1parameters(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
14961         LDKChannelTransactionParameters this_ptr_conv;
14962         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14963         this_ptr_conv.is_owned = false;
14964         LDKCounterpartyChannelTransactionParameters val_conv;
14965         val_conv.inner = (void*)(val & (~1));
14966         val_conv.is_owned = (val & 1) || (val == 0);
14967         if (val_conv.inner != NULL)
14968                 val_conv = CounterpartyChannelTransactionParameters_clone(&val_conv);
14969         ChannelTransactionParameters_set_counterparty_parameters(&this_ptr_conv, val_conv);
14970 }
14971
14972 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelTransactionParameters_1get_1funding_1outpoint(JNIEnv *env, jclass clz, int64_t this_ptr) {
14973         LDKChannelTransactionParameters this_ptr_conv;
14974         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14975         this_ptr_conv.is_owned = false;
14976         LDKOutPoint ret_var = ChannelTransactionParameters_get_funding_outpoint(&this_ptr_conv);
14977         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14978         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14979         long ret_ref = (long)ret_var.inner;
14980         if (ret_var.is_owned) {
14981                 ret_ref |= 1;
14982         }
14983         return ret_ref;
14984 }
14985
14986 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelTransactionParameters_1set_1funding_1outpoint(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
14987         LDKChannelTransactionParameters this_ptr_conv;
14988         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14989         this_ptr_conv.is_owned = false;
14990         LDKOutPoint val_conv;
14991         val_conv.inner = (void*)(val & (~1));
14992         val_conv.is_owned = (val & 1) || (val == 0);
14993         if (val_conv.inner != NULL)
14994                 val_conv = OutPoint_clone(&val_conv);
14995         ChannelTransactionParameters_set_funding_outpoint(&this_ptr_conv, val_conv);
14996 }
14997
14998 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelTransactionParameters_1new(JNIEnv *env, jclass clz, int64_t holder_pubkeys_arg, jshort holder_selected_contest_delay_arg, jboolean is_outbound_from_holder_arg, int64_t counterparty_parameters_arg, int64_t funding_outpoint_arg) {
14999         LDKChannelPublicKeys holder_pubkeys_arg_conv;
15000         holder_pubkeys_arg_conv.inner = (void*)(holder_pubkeys_arg & (~1));
15001         holder_pubkeys_arg_conv.is_owned = (holder_pubkeys_arg & 1) || (holder_pubkeys_arg == 0);
15002         if (holder_pubkeys_arg_conv.inner != NULL)
15003                 holder_pubkeys_arg_conv = ChannelPublicKeys_clone(&holder_pubkeys_arg_conv);
15004         LDKCounterpartyChannelTransactionParameters counterparty_parameters_arg_conv;
15005         counterparty_parameters_arg_conv.inner = (void*)(counterparty_parameters_arg & (~1));
15006         counterparty_parameters_arg_conv.is_owned = (counterparty_parameters_arg & 1) || (counterparty_parameters_arg == 0);
15007         if (counterparty_parameters_arg_conv.inner != NULL)
15008                 counterparty_parameters_arg_conv = CounterpartyChannelTransactionParameters_clone(&counterparty_parameters_arg_conv);
15009         LDKOutPoint funding_outpoint_arg_conv;
15010         funding_outpoint_arg_conv.inner = (void*)(funding_outpoint_arg & (~1));
15011         funding_outpoint_arg_conv.is_owned = (funding_outpoint_arg & 1) || (funding_outpoint_arg == 0);
15012         if (funding_outpoint_arg_conv.inner != NULL)
15013                 funding_outpoint_arg_conv = OutPoint_clone(&funding_outpoint_arg_conv);
15014         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);
15015         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15016         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15017         long ret_ref = (long)ret_var.inner;
15018         if (ret_var.is_owned) {
15019                 ret_ref |= 1;
15020         }
15021         return ret_ref;
15022 }
15023
15024 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CounterpartyChannelTransactionParameters_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
15025         LDKCounterpartyChannelTransactionParameters this_ptr_conv;
15026         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15027         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
15028         CounterpartyChannelTransactionParameters_free(this_ptr_conv);
15029 }
15030
15031 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CounterpartyChannelTransactionParameters_1clone(JNIEnv *env, jclass clz, int64_t orig) {
15032         LDKCounterpartyChannelTransactionParameters orig_conv;
15033         orig_conv.inner = (void*)(orig & (~1));
15034         orig_conv.is_owned = false;
15035         LDKCounterpartyChannelTransactionParameters ret_var = CounterpartyChannelTransactionParameters_clone(&orig_conv);
15036         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15037         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15038         long ret_ref = (long)ret_var.inner;
15039         if (ret_var.is_owned) {
15040                 ret_ref |= 1;
15041         }
15042         return ret_ref;
15043 }
15044
15045 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CounterpartyChannelTransactionParameters_1get_1pubkeys(JNIEnv *env, jclass clz, int64_t this_ptr) {
15046         LDKCounterpartyChannelTransactionParameters this_ptr_conv;
15047         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15048         this_ptr_conv.is_owned = false;
15049         LDKChannelPublicKeys ret_var = CounterpartyChannelTransactionParameters_get_pubkeys(&this_ptr_conv);
15050         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15051         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15052         long ret_ref = (long)ret_var.inner;
15053         if (ret_var.is_owned) {
15054                 ret_ref |= 1;
15055         }
15056         return ret_ref;
15057 }
15058
15059 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CounterpartyChannelTransactionParameters_1set_1pubkeys(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
15060         LDKCounterpartyChannelTransactionParameters this_ptr_conv;
15061         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15062         this_ptr_conv.is_owned = false;
15063         LDKChannelPublicKeys val_conv;
15064         val_conv.inner = (void*)(val & (~1));
15065         val_conv.is_owned = (val & 1) || (val == 0);
15066         if (val_conv.inner != NULL)
15067                 val_conv = ChannelPublicKeys_clone(&val_conv);
15068         CounterpartyChannelTransactionParameters_set_pubkeys(&this_ptr_conv, val_conv);
15069 }
15070
15071 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_CounterpartyChannelTransactionParameters_1get_1selected_1contest_1delay(JNIEnv *env, jclass clz, int64_t this_ptr) {
15072         LDKCounterpartyChannelTransactionParameters this_ptr_conv;
15073         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15074         this_ptr_conv.is_owned = false;
15075         jshort ret_val = CounterpartyChannelTransactionParameters_get_selected_contest_delay(&this_ptr_conv);
15076         return ret_val;
15077 }
15078
15079 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CounterpartyChannelTransactionParameters_1set_1selected_1contest_1delay(JNIEnv *env, jclass clz, int64_t this_ptr, jshort val) {
15080         LDKCounterpartyChannelTransactionParameters this_ptr_conv;
15081         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15082         this_ptr_conv.is_owned = false;
15083         CounterpartyChannelTransactionParameters_set_selected_contest_delay(&this_ptr_conv, val);
15084 }
15085
15086 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CounterpartyChannelTransactionParameters_1new(JNIEnv *env, jclass clz, int64_t pubkeys_arg, jshort selected_contest_delay_arg) {
15087         LDKChannelPublicKeys pubkeys_arg_conv;
15088         pubkeys_arg_conv.inner = (void*)(pubkeys_arg & (~1));
15089         pubkeys_arg_conv.is_owned = (pubkeys_arg & 1) || (pubkeys_arg == 0);
15090         if (pubkeys_arg_conv.inner != NULL)
15091                 pubkeys_arg_conv = ChannelPublicKeys_clone(&pubkeys_arg_conv);
15092         LDKCounterpartyChannelTransactionParameters ret_var = CounterpartyChannelTransactionParameters_new(pubkeys_arg_conv, selected_contest_delay_arg);
15093         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15094         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15095         long ret_ref = (long)ret_var.inner;
15096         if (ret_var.is_owned) {
15097                 ret_ref |= 1;
15098         }
15099         return ret_ref;
15100 }
15101
15102 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_ChannelTransactionParameters_1is_1populated(JNIEnv *env, jclass clz, int64_t this_arg) {
15103         LDKChannelTransactionParameters this_arg_conv;
15104         this_arg_conv.inner = (void*)(this_arg & (~1));
15105         this_arg_conv.is_owned = false;
15106         jboolean ret_val = ChannelTransactionParameters_is_populated(&this_arg_conv);
15107         return ret_val;
15108 }
15109
15110 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelTransactionParameters_1as_1holder_1broadcastable(JNIEnv *env, jclass clz, int64_t this_arg) {
15111         LDKChannelTransactionParameters this_arg_conv;
15112         this_arg_conv.inner = (void*)(this_arg & (~1));
15113         this_arg_conv.is_owned = false;
15114         LDKDirectedChannelTransactionParameters ret_var = ChannelTransactionParameters_as_holder_broadcastable(&this_arg_conv);
15115         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15116         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15117         long ret_ref = (long)ret_var.inner;
15118         if (ret_var.is_owned) {
15119                 ret_ref |= 1;
15120         }
15121         return ret_ref;
15122 }
15123
15124 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelTransactionParameters_1as_1counterparty_1broadcastable(JNIEnv *env, jclass clz, int64_t this_arg) {
15125         LDKChannelTransactionParameters this_arg_conv;
15126         this_arg_conv.inner = (void*)(this_arg & (~1));
15127         this_arg_conv.is_owned = false;
15128         LDKDirectedChannelTransactionParameters ret_var = ChannelTransactionParameters_as_counterparty_broadcastable(&this_arg_conv);
15129         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15130         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15131         long ret_ref = (long)ret_var.inner;
15132         if (ret_var.is_owned) {
15133                 ret_ref |= 1;
15134         }
15135         return ret_ref;
15136 }
15137
15138 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_CounterpartyChannelTransactionParameters_1write(JNIEnv *env, jclass clz, int64_t obj) {
15139         LDKCounterpartyChannelTransactionParameters obj_conv;
15140         obj_conv.inner = (void*)(obj & (~1));
15141         obj_conv.is_owned = false;
15142         LDKCVec_u8Z arg_var = CounterpartyChannelTransactionParameters_write(&obj_conv);
15143         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
15144         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
15145         CVec_u8Z_free(arg_var);
15146         return arg_arr;
15147 }
15148
15149 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CounterpartyChannelTransactionParameters_1read(JNIEnv *env, jclass clz, int8_tArray ser) {
15150         LDKu8slice ser_ref;
15151         ser_ref.datalen = (*env)->GetArrayLength(env, ser);
15152         ser_ref.data = (*env)->GetByteArrayElements (env, ser, NULL);
15153         LDKCounterpartyChannelTransactionParameters ret_var = CounterpartyChannelTransactionParameters_read(ser_ref);
15154         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15155         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15156         long ret_ref = (long)ret_var.inner;
15157         if (ret_var.is_owned) {
15158                 ret_ref |= 1;
15159         }
15160         (*env)->ReleaseByteArrayElements(env, ser, (int8_t*)ser_ref.data, 0);
15161         return ret_ref;
15162 }
15163
15164 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_ChannelTransactionParameters_1write(JNIEnv *env, jclass clz, int64_t obj) {
15165         LDKChannelTransactionParameters obj_conv;
15166         obj_conv.inner = (void*)(obj & (~1));
15167         obj_conv.is_owned = false;
15168         LDKCVec_u8Z arg_var = ChannelTransactionParameters_write(&obj_conv);
15169         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
15170         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
15171         CVec_u8Z_free(arg_var);
15172         return arg_arr;
15173 }
15174
15175 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelTransactionParameters_1read(JNIEnv *env, jclass clz, int8_tArray ser) {
15176         LDKu8slice ser_ref;
15177         ser_ref.datalen = (*env)->GetArrayLength(env, ser);
15178         ser_ref.data = (*env)->GetByteArrayElements (env, ser, NULL);
15179         LDKChannelTransactionParameters ret_var = ChannelTransactionParameters_read(ser_ref);
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         (*env)->ReleaseByteArrayElements(env, ser, (int8_t*)ser_ref.data, 0);
15187         return ret_ref;
15188 }
15189
15190 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_DirectedChannelTransactionParameters_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
15191         LDKDirectedChannelTransactionParameters this_ptr_conv;
15192         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15193         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
15194         DirectedChannelTransactionParameters_free(this_ptr_conv);
15195 }
15196
15197 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_DirectedChannelTransactionParameters_1broadcaster_1pubkeys(JNIEnv *env, jclass clz, int64_t this_arg) {
15198         LDKDirectedChannelTransactionParameters this_arg_conv;
15199         this_arg_conv.inner = (void*)(this_arg & (~1));
15200         this_arg_conv.is_owned = false;
15201         LDKChannelPublicKeys ret_var = DirectedChannelTransactionParameters_broadcaster_pubkeys(&this_arg_conv);
15202         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15203         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15204         long ret_ref = (long)ret_var.inner;
15205         if (ret_var.is_owned) {
15206                 ret_ref |= 1;
15207         }
15208         return ret_ref;
15209 }
15210
15211 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_DirectedChannelTransactionParameters_1countersignatory_1pubkeys(JNIEnv *env, jclass clz, int64_t this_arg) {
15212         LDKDirectedChannelTransactionParameters this_arg_conv;
15213         this_arg_conv.inner = (void*)(this_arg & (~1));
15214         this_arg_conv.is_owned = false;
15215         LDKChannelPublicKeys ret_var = DirectedChannelTransactionParameters_countersignatory_pubkeys(&this_arg_conv);
15216         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15217         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15218         long ret_ref = (long)ret_var.inner;
15219         if (ret_var.is_owned) {
15220                 ret_ref |= 1;
15221         }
15222         return ret_ref;
15223 }
15224
15225 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_DirectedChannelTransactionParameters_1contest_1delay(JNIEnv *env, jclass clz, int64_t this_arg) {
15226         LDKDirectedChannelTransactionParameters this_arg_conv;
15227         this_arg_conv.inner = (void*)(this_arg & (~1));
15228         this_arg_conv.is_owned = false;
15229         jshort ret_val = DirectedChannelTransactionParameters_contest_delay(&this_arg_conv);
15230         return ret_val;
15231 }
15232
15233 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_DirectedChannelTransactionParameters_1is_1outbound(JNIEnv *env, jclass clz, int64_t this_arg) {
15234         LDKDirectedChannelTransactionParameters this_arg_conv;
15235         this_arg_conv.inner = (void*)(this_arg & (~1));
15236         this_arg_conv.is_owned = false;
15237         jboolean ret_val = DirectedChannelTransactionParameters_is_outbound(&this_arg_conv);
15238         return ret_val;
15239 }
15240
15241 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_DirectedChannelTransactionParameters_1funding_1outpoint(JNIEnv *env, jclass clz, int64_t this_arg) {
15242         LDKDirectedChannelTransactionParameters this_arg_conv;
15243         this_arg_conv.inner = (void*)(this_arg & (~1));
15244         this_arg_conv.is_owned = false;
15245         LDKOutPoint ret_var = DirectedChannelTransactionParameters_funding_outpoint(&this_arg_conv);
15246         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15247         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15248         long ret_ref = (long)ret_var.inner;
15249         if (ret_var.is_owned) {
15250                 ret_ref |= 1;
15251         }
15252         return ret_ref;
15253 }
15254
15255 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_HolderCommitmentTransaction_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
15256         LDKHolderCommitmentTransaction this_ptr_conv;
15257         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15258         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
15259         HolderCommitmentTransaction_free(this_ptr_conv);
15260 }
15261
15262 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_HolderCommitmentTransaction_1clone(JNIEnv *env, jclass clz, int64_t orig) {
15263         LDKHolderCommitmentTransaction orig_conv;
15264         orig_conv.inner = (void*)(orig & (~1));
15265         orig_conv.is_owned = false;
15266         LDKHolderCommitmentTransaction ret_var = HolderCommitmentTransaction_clone(&orig_conv);
15267         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15268         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15269         long ret_ref = (long)ret_var.inner;
15270         if (ret_var.is_owned) {
15271                 ret_ref |= 1;
15272         }
15273         return ret_ref;
15274 }
15275
15276 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_HolderCommitmentTransaction_1get_1counterparty_1sig(JNIEnv *env, jclass clz, int64_t this_ptr) {
15277         LDKHolderCommitmentTransaction this_ptr_conv;
15278         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15279         this_ptr_conv.is_owned = false;
15280         int8_tArray arg_arr = (*env)->NewByteArray(env, 64);
15281         (*env)->SetByteArrayRegion(env, arg_arr, 0, 64, HolderCommitmentTransaction_get_counterparty_sig(&this_ptr_conv).compact_form);
15282         return arg_arr;
15283 }
15284
15285 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_HolderCommitmentTransaction_1set_1counterparty_1sig(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
15286         LDKHolderCommitmentTransaction this_ptr_conv;
15287         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15288         this_ptr_conv.is_owned = false;
15289         LDKSignature val_ref;
15290         CHECK((*env)->GetArrayLength(env, val) == 64);
15291         (*env)->GetByteArrayRegion(env, val, 0, 64, val_ref.compact_form);
15292         HolderCommitmentTransaction_set_counterparty_sig(&this_ptr_conv, val_ref);
15293 }
15294
15295 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_HolderCommitmentTransaction_1set_1counterparty_1htlc_1sigs(JNIEnv *env, jclass clz, int64_t this_ptr, jobjectArray val) {
15296         LDKHolderCommitmentTransaction this_ptr_conv;
15297         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15298         this_ptr_conv.is_owned = false;
15299         LDKCVec_SignatureZ val_constr;
15300         val_constr.datalen = (*env)->GetArrayLength(env, val);
15301         if (val_constr.datalen > 0)
15302                 val_constr.data = MALLOC(val_constr.datalen * sizeof(LDKSignature), "LDKCVec_SignatureZ Elements");
15303         else
15304                 val_constr.data = NULL;
15305         for (size_t i = 0; i < val_constr.datalen; i++) {
15306                 int8_tArray arr_conv_8 = (*env)->GetObjectArrayElement(env, val, i);
15307                 LDKSignature arr_conv_8_ref;
15308                 CHECK((*env)->GetArrayLength(env, arr_conv_8) == 64);
15309                 (*env)->GetByteArrayRegion(env, arr_conv_8, 0, 64, arr_conv_8_ref.compact_form);
15310                 val_constr.data[i] = arr_conv_8_ref;
15311         }
15312         HolderCommitmentTransaction_set_counterparty_htlc_sigs(&this_ptr_conv, val_constr);
15313 }
15314
15315 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_HolderCommitmentTransaction_1write(JNIEnv *env, jclass clz, int64_t obj) {
15316         LDKHolderCommitmentTransaction obj_conv;
15317         obj_conv.inner = (void*)(obj & (~1));
15318         obj_conv.is_owned = false;
15319         LDKCVec_u8Z arg_var = HolderCommitmentTransaction_write(&obj_conv);
15320         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
15321         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
15322         CVec_u8Z_free(arg_var);
15323         return arg_arr;
15324 }
15325
15326 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_HolderCommitmentTransaction_1read(JNIEnv *env, jclass clz, int8_tArray ser) {
15327         LDKu8slice ser_ref;
15328         ser_ref.datalen = (*env)->GetArrayLength(env, ser);
15329         ser_ref.data = (*env)->GetByteArrayElements (env, ser, NULL);
15330         LDKHolderCommitmentTransaction ret_var = HolderCommitmentTransaction_read(ser_ref);
15331         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15332         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15333         long ret_ref = (long)ret_var.inner;
15334         if (ret_var.is_owned) {
15335                 ret_ref |= 1;
15336         }
15337         (*env)->ReleaseByteArrayElements(env, ser, (int8_t*)ser_ref.data, 0);
15338         return ret_ref;
15339 }
15340
15341 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) {
15342         LDKCommitmentTransaction commitment_tx_conv;
15343         commitment_tx_conv.inner = (void*)(commitment_tx & (~1));
15344         commitment_tx_conv.is_owned = (commitment_tx & 1) || (commitment_tx == 0);
15345         if (commitment_tx_conv.inner != NULL)
15346                 commitment_tx_conv = CommitmentTransaction_clone(&commitment_tx_conv);
15347         LDKSignature counterparty_sig_ref;
15348         CHECK((*env)->GetArrayLength(env, counterparty_sig) == 64);
15349         (*env)->GetByteArrayRegion(env, counterparty_sig, 0, 64, counterparty_sig_ref.compact_form);
15350         LDKCVec_SignatureZ counterparty_htlc_sigs_constr;
15351         counterparty_htlc_sigs_constr.datalen = (*env)->GetArrayLength(env, counterparty_htlc_sigs);
15352         if (counterparty_htlc_sigs_constr.datalen > 0)
15353                 counterparty_htlc_sigs_constr.data = MALLOC(counterparty_htlc_sigs_constr.datalen * sizeof(LDKSignature), "LDKCVec_SignatureZ Elements");
15354         else
15355                 counterparty_htlc_sigs_constr.data = NULL;
15356         for (size_t i = 0; i < counterparty_htlc_sigs_constr.datalen; i++) {
15357                 int8_tArray arr_conv_8 = (*env)->GetObjectArrayElement(env, counterparty_htlc_sigs, i);
15358                 LDKSignature arr_conv_8_ref;
15359                 CHECK((*env)->GetArrayLength(env, arr_conv_8) == 64);
15360                 (*env)->GetByteArrayRegion(env, arr_conv_8, 0, 64, arr_conv_8_ref.compact_form);
15361                 counterparty_htlc_sigs_constr.data[i] = arr_conv_8_ref;
15362         }
15363         LDKPublicKey holder_funding_key_ref;
15364         CHECK((*env)->GetArrayLength(env, holder_funding_key) == 33);
15365         (*env)->GetByteArrayRegion(env, holder_funding_key, 0, 33, holder_funding_key_ref.compressed_form);
15366         LDKPublicKey counterparty_funding_key_ref;
15367         CHECK((*env)->GetArrayLength(env, counterparty_funding_key) == 33);
15368         (*env)->GetByteArrayRegion(env, counterparty_funding_key, 0, 33, counterparty_funding_key_ref.compressed_form);
15369         LDKHolderCommitmentTransaction ret_var = HolderCommitmentTransaction_new(commitment_tx_conv, counterparty_sig_ref, counterparty_htlc_sigs_constr, holder_funding_key_ref, counterparty_funding_key_ref);
15370         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15371         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15372         long ret_ref = (long)ret_var.inner;
15373         if (ret_var.is_owned) {
15374                 ret_ref |= 1;
15375         }
15376         return ret_ref;
15377 }
15378
15379 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_BuiltCommitmentTransaction_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
15380         LDKBuiltCommitmentTransaction this_ptr_conv;
15381         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15382         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
15383         BuiltCommitmentTransaction_free(this_ptr_conv);
15384 }
15385
15386 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_BuiltCommitmentTransaction_1clone(JNIEnv *env, jclass clz, int64_t orig) {
15387         LDKBuiltCommitmentTransaction orig_conv;
15388         orig_conv.inner = (void*)(orig & (~1));
15389         orig_conv.is_owned = false;
15390         LDKBuiltCommitmentTransaction ret_var = BuiltCommitmentTransaction_clone(&orig_conv);
15391         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15392         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15393         long ret_ref = (long)ret_var.inner;
15394         if (ret_var.is_owned) {
15395                 ret_ref |= 1;
15396         }
15397         return ret_ref;
15398 }
15399
15400 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_BuiltCommitmentTransaction_1get_1transaction(JNIEnv *env, jclass clz, int64_t this_ptr) {
15401         LDKBuiltCommitmentTransaction this_ptr_conv;
15402         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15403         this_ptr_conv.is_owned = false;
15404         LDKTransaction arg_var = BuiltCommitmentTransaction_get_transaction(&this_ptr_conv);
15405         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
15406         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
15407         Transaction_free(arg_var);
15408         return arg_arr;
15409 }
15410
15411 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_BuiltCommitmentTransaction_1set_1transaction(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
15412         LDKBuiltCommitmentTransaction this_ptr_conv;
15413         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15414         this_ptr_conv.is_owned = false;
15415         LDKTransaction val_ref;
15416         val_ref.datalen = (*env)->GetArrayLength(env, val);
15417         val_ref.data = MALLOC(val_ref.datalen, "LDKTransaction Bytes");
15418         (*env)->GetByteArrayRegion(env, val, 0, val_ref.datalen, val_ref.data);
15419         val_ref.data_is_owned = true;
15420         BuiltCommitmentTransaction_set_transaction(&this_ptr_conv, val_ref);
15421 }
15422
15423 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_BuiltCommitmentTransaction_1get_1txid(JNIEnv *env, jclass clz, int64_t this_ptr) {
15424         LDKBuiltCommitmentTransaction this_ptr_conv;
15425         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15426         this_ptr_conv.is_owned = false;
15427         int8_tArray ret_arr = (*env)->NewByteArray(env, 32);
15428         (*env)->SetByteArrayRegion(env, ret_arr, 0, 32, *BuiltCommitmentTransaction_get_txid(&this_ptr_conv));
15429         return ret_arr;
15430 }
15431
15432 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_BuiltCommitmentTransaction_1set_1txid(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
15433         LDKBuiltCommitmentTransaction this_ptr_conv;
15434         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15435         this_ptr_conv.is_owned = false;
15436         LDKThirtyTwoBytes val_ref;
15437         CHECK((*env)->GetArrayLength(env, val) == 32);
15438         (*env)->GetByteArrayRegion(env, val, 0, 32, val_ref.data);
15439         BuiltCommitmentTransaction_set_txid(&this_ptr_conv, val_ref);
15440 }
15441
15442 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_BuiltCommitmentTransaction_1new(JNIEnv *env, jclass clz, int8_tArray transaction_arg, int8_tArray txid_arg) {
15443         LDKTransaction transaction_arg_ref;
15444         transaction_arg_ref.datalen = (*env)->GetArrayLength(env, transaction_arg);
15445         transaction_arg_ref.data = MALLOC(transaction_arg_ref.datalen, "LDKTransaction Bytes");
15446         (*env)->GetByteArrayRegion(env, transaction_arg, 0, transaction_arg_ref.datalen, transaction_arg_ref.data);
15447         transaction_arg_ref.data_is_owned = true;
15448         LDKThirtyTwoBytes txid_arg_ref;
15449         CHECK((*env)->GetArrayLength(env, txid_arg) == 32);
15450         (*env)->GetByteArrayRegion(env, txid_arg, 0, 32, txid_arg_ref.data);
15451         LDKBuiltCommitmentTransaction ret_var = BuiltCommitmentTransaction_new(transaction_arg_ref, txid_arg_ref);
15452         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15453         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15454         long ret_ref = (long)ret_var.inner;
15455         if (ret_var.is_owned) {
15456                 ret_ref |= 1;
15457         }
15458         return ret_ref;
15459 }
15460
15461 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_BuiltCommitmentTransaction_1write(JNIEnv *env, jclass clz, int64_t obj) {
15462         LDKBuiltCommitmentTransaction obj_conv;
15463         obj_conv.inner = (void*)(obj & (~1));
15464         obj_conv.is_owned = false;
15465         LDKCVec_u8Z arg_var = BuiltCommitmentTransaction_write(&obj_conv);
15466         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
15467         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
15468         CVec_u8Z_free(arg_var);
15469         return arg_arr;
15470 }
15471
15472 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_BuiltCommitmentTransaction_1read(JNIEnv *env, jclass clz, int8_tArray ser) {
15473         LDKu8slice ser_ref;
15474         ser_ref.datalen = (*env)->GetArrayLength(env, ser);
15475         ser_ref.data = (*env)->GetByteArrayElements (env, ser, NULL);
15476         LDKBuiltCommitmentTransaction ret_var = BuiltCommitmentTransaction_read(ser_ref);
15477         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15478         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15479         long ret_ref = (long)ret_var.inner;
15480         if (ret_var.is_owned) {
15481                 ret_ref |= 1;
15482         }
15483         (*env)->ReleaseByteArrayElements(env, ser, (int8_t*)ser_ref.data, 0);
15484         return ret_ref;
15485 }
15486
15487 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) {
15488         LDKBuiltCommitmentTransaction this_arg_conv;
15489         this_arg_conv.inner = (void*)(this_arg & (~1));
15490         this_arg_conv.is_owned = false;
15491         LDKu8slice funding_redeemscript_ref;
15492         funding_redeemscript_ref.datalen = (*env)->GetArrayLength(env, funding_redeemscript);
15493         funding_redeemscript_ref.data = (*env)->GetByteArrayElements (env, funding_redeemscript, NULL);
15494         int8_tArray arg_arr = (*env)->NewByteArray(env, 32);
15495         (*env)->SetByteArrayRegion(env, arg_arr, 0, 32, BuiltCommitmentTransaction_get_sighash_all(&this_arg_conv, funding_redeemscript_ref, channel_value_satoshis).data);
15496         (*env)->ReleaseByteArrayElements(env, funding_redeemscript, (int8_t*)funding_redeemscript_ref.data, 0);
15497         return arg_arr;
15498 }
15499
15500 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) {
15501         LDKBuiltCommitmentTransaction this_arg_conv;
15502         this_arg_conv.inner = (void*)(this_arg & (~1));
15503         this_arg_conv.is_owned = false;
15504         unsigned char funding_key_arr[32];
15505         CHECK((*env)->GetArrayLength(env, funding_key) == 32);
15506         (*env)->GetByteArrayRegion(env, funding_key, 0, 32, funding_key_arr);
15507         unsigned char (*funding_key_ref)[32] = &funding_key_arr;
15508         LDKu8slice funding_redeemscript_ref;
15509         funding_redeemscript_ref.datalen = (*env)->GetArrayLength(env, funding_redeemscript);
15510         funding_redeemscript_ref.data = (*env)->GetByteArrayElements (env, funding_redeemscript, NULL);
15511         int8_tArray arg_arr = (*env)->NewByteArray(env, 64);
15512         (*env)->SetByteArrayRegion(env, arg_arr, 0, 64, BuiltCommitmentTransaction_sign(&this_arg_conv, funding_key_ref, funding_redeemscript_ref, channel_value_satoshis).compact_form);
15513         (*env)->ReleaseByteArrayElements(env, funding_redeemscript, (int8_t*)funding_redeemscript_ref.data, 0);
15514         return arg_arr;
15515 }
15516
15517 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CommitmentTransaction_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
15518         LDKCommitmentTransaction this_ptr_conv;
15519         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15520         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
15521         CommitmentTransaction_free(this_ptr_conv);
15522 }
15523
15524 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CommitmentTransaction_1clone(JNIEnv *env, jclass clz, int64_t orig) {
15525         LDKCommitmentTransaction orig_conv;
15526         orig_conv.inner = (void*)(orig & (~1));
15527         orig_conv.is_owned = false;
15528         LDKCommitmentTransaction ret_var = CommitmentTransaction_clone(&orig_conv);
15529         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15530         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15531         long ret_ref = (long)ret_var.inner;
15532         if (ret_var.is_owned) {
15533                 ret_ref |= 1;
15534         }
15535         return ret_ref;
15536 }
15537
15538 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_CommitmentTransaction_1write(JNIEnv *env, jclass clz, int64_t obj) {
15539         LDKCommitmentTransaction obj_conv;
15540         obj_conv.inner = (void*)(obj & (~1));
15541         obj_conv.is_owned = false;
15542         LDKCVec_u8Z arg_var = CommitmentTransaction_write(&obj_conv);
15543         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
15544         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
15545         CVec_u8Z_free(arg_var);
15546         return arg_arr;
15547 }
15548
15549 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CommitmentTransaction_1read(JNIEnv *env, jclass clz, int8_tArray ser) {
15550         LDKu8slice ser_ref;
15551         ser_ref.datalen = (*env)->GetArrayLength(env, ser);
15552         ser_ref.data = (*env)->GetByteArrayElements (env, ser, NULL);
15553         LDKCommitmentTransaction ret_var = CommitmentTransaction_read(ser_ref);
15554         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15555         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15556         long ret_ref = (long)ret_var.inner;
15557         if (ret_var.is_owned) {
15558                 ret_ref |= 1;
15559         }
15560         (*env)->ReleaseByteArrayElements(env, ser, (int8_t*)ser_ref.data, 0);
15561         return ret_ref;
15562 }
15563
15564 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CommitmentTransaction_1commitment_1number(JNIEnv *env, jclass clz, int64_t this_arg) {
15565         LDKCommitmentTransaction this_arg_conv;
15566         this_arg_conv.inner = (void*)(this_arg & (~1));
15567         this_arg_conv.is_owned = false;
15568         int64_t ret_val = CommitmentTransaction_commitment_number(&this_arg_conv);
15569         return ret_val;
15570 }
15571
15572 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CommitmentTransaction_1to_1broadcaster_1value_1sat(JNIEnv *env, jclass clz, int64_t this_arg) {
15573         LDKCommitmentTransaction this_arg_conv;
15574         this_arg_conv.inner = (void*)(this_arg & (~1));
15575         this_arg_conv.is_owned = false;
15576         int64_t ret_val = CommitmentTransaction_to_broadcaster_value_sat(&this_arg_conv);
15577         return ret_val;
15578 }
15579
15580 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CommitmentTransaction_1to_1countersignatory_1value_1sat(JNIEnv *env, jclass clz, int64_t this_arg) {
15581         LDKCommitmentTransaction this_arg_conv;
15582         this_arg_conv.inner = (void*)(this_arg & (~1));
15583         this_arg_conv.is_owned = false;
15584         int64_t ret_val = CommitmentTransaction_to_countersignatory_value_sat(&this_arg_conv);
15585         return ret_val;
15586 }
15587
15588 JNIEXPORT int32_t JNICALL Java_org_ldk_impl_bindings_CommitmentTransaction_1feerate_1per_1kw(JNIEnv *env, jclass clz, int64_t this_arg) {
15589         LDKCommitmentTransaction this_arg_conv;
15590         this_arg_conv.inner = (void*)(this_arg & (~1));
15591         this_arg_conv.is_owned = false;
15592         int32_t ret_val = CommitmentTransaction_feerate_per_kw(&this_arg_conv);
15593         return ret_val;
15594 }
15595
15596 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_CommitmentTransaction_1trust(JNIEnv *env, jclass clz, int64_t this_arg) {
15597         LDKCommitmentTransaction this_arg_conv;
15598         this_arg_conv.inner = (void*)(this_arg & (~1));
15599         this_arg_conv.is_owned = false;
15600         LDKTrustedCommitmentTransaction ret_var = CommitmentTransaction_trust(&this_arg_conv);
15601         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15602         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15603         long ret_ref = (long)ret_var.inner;
15604         if (ret_var.is_owned) {
15605                 ret_ref |= 1;
15606         }
15607         return ret_ref;
15608 }
15609
15610 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) {
15611         LDKCommitmentTransaction this_arg_conv;
15612         this_arg_conv.inner = (void*)(this_arg & (~1));
15613         this_arg_conv.is_owned = false;
15614         LDKDirectedChannelTransactionParameters channel_parameters_conv;
15615         channel_parameters_conv.inner = (void*)(channel_parameters & (~1));
15616         channel_parameters_conv.is_owned = false;
15617         LDKChannelPublicKeys broadcaster_keys_conv;
15618         broadcaster_keys_conv.inner = (void*)(broadcaster_keys & (~1));
15619         broadcaster_keys_conv.is_owned = false;
15620         LDKChannelPublicKeys countersignatory_keys_conv;
15621         countersignatory_keys_conv.inner = (void*)(countersignatory_keys & (~1));
15622         countersignatory_keys_conv.is_owned = false;
15623         LDKCResult_TrustedCommitmentTransactionNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_TrustedCommitmentTransactionNoneZ), "LDKCResult_TrustedCommitmentTransactionNoneZ");
15624         *ret_conv = CommitmentTransaction_verify(&this_arg_conv, &channel_parameters_conv, &broadcaster_keys_conv, &countersignatory_keys_conv);
15625         return (long)ret_conv;
15626 }
15627
15628 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_TrustedCommitmentTransaction_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
15629         LDKTrustedCommitmentTransaction this_ptr_conv;
15630         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15631         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
15632         TrustedCommitmentTransaction_free(this_ptr_conv);
15633 }
15634
15635 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_TrustedCommitmentTransaction_1txid(JNIEnv *env, jclass clz, int64_t this_arg) {
15636         LDKTrustedCommitmentTransaction this_arg_conv;
15637         this_arg_conv.inner = (void*)(this_arg & (~1));
15638         this_arg_conv.is_owned = false;
15639         int8_tArray arg_arr = (*env)->NewByteArray(env, 32);
15640         (*env)->SetByteArrayRegion(env, arg_arr, 0, 32, TrustedCommitmentTransaction_txid(&this_arg_conv).data);
15641         return arg_arr;
15642 }
15643
15644 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_TrustedCommitmentTransaction_1built_1transaction(JNIEnv *env, jclass clz, int64_t this_arg) {
15645         LDKTrustedCommitmentTransaction this_arg_conv;
15646         this_arg_conv.inner = (void*)(this_arg & (~1));
15647         this_arg_conv.is_owned = false;
15648         LDKBuiltCommitmentTransaction ret_var = TrustedCommitmentTransaction_built_transaction(&this_arg_conv);
15649         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15650         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15651         long ret_ref = (long)ret_var.inner;
15652         if (ret_var.is_owned) {
15653                 ret_ref |= 1;
15654         }
15655         return ret_ref;
15656 }
15657
15658 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_TrustedCommitmentTransaction_1keys(JNIEnv *env, jclass clz, int64_t this_arg) {
15659         LDKTrustedCommitmentTransaction this_arg_conv;
15660         this_arg_conv.inner = (void*)(this_arg & (~1));
15661         this_arg_conv.is_owned = false;
15662         LDKTxCreationKeys ret_var = TrustedCommitmentTransaction_keys(&this_arg_conv);
15663         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15664         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15665         long ret_ref = (long)ret_var.inner;
15666         if (ret_var.is_owned) {
15667                 ret_ref |= 1;
15668         }
15669         return ret_ref;
15670 }
15671
15672 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) {
15673         LDKTrustedCommitmentTransaction this_arg_conv;
15674         this_arg_conv.inner = (void*)(this_arg & (~1));
15675         this_arg_conv.is_owned = false;
15676         unsigned char htlc_base_key_arr[32];
15677         CHECK((*env)->GetArrayLength(env, htlc_base_key) == 32);
15678         (*env)->GetByteArrayRegion(env, htlc_base_key, 0, 32, htlc_base_key_arr);
15679         unsigned char (*htlc_base_key_ref)[32] = &htlc_base_key_arr;
15680         LDKDirectedChannelTransactionParameters channel_parameters_conv;
15681         channel_parameters_conv.inner = (void*)(channel_parameters & (~1));
15682         channel_parameters_conv.is_owned = false;
15683         LDKCResult_CVec_SignatureZNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_CVec_SignatureZNoneZ), "LDKCResult_CVec_SignatureZNoneZ");
15684         *ret_conv = TrustedCommitmentTransaction_get_htlc_sigs(&this_arg_conv, htlc_base_key_ref, &channel_parameters_conv);
15685         return (long)ret_conv;
15686 }
15687
15688 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) {
15689         LDKPublicKey broadcaster_payment_basepoint_ref;
15690         CHECK((*env)->GetArrayLength(env, broadcaster_payment_basepoint) == 33);
15691         (*env)->GetByteArrayRegion(env, broadcaster_payment_basepoint, 0, 33, broadcaster_payment_basepoint_ref.compressed_form);
15692         LDKPublicKey countersignatory_payment_basepoint_ref;
15693         CHECK((*env)->GetArrayLength(env, countersignatory_payment_basepoint) == 33);
15694         (*env)->GetByteArrayRegion(env, countersignatory_payment_basepoint, 0, 33, countersignatory_payment_basepoint_ref.compressed_form);
15695         int64_t ret_val = get_commitment_transaction_number_obscure_factor(broadcaster_payment_basepoint_ref, countersignatory_payment_basepoint_ref, outbound_from_broadcaster);
15696         return ret_val;
15697 }
15698
15699 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_InitFeatures_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
15700         LDKInitFeatures this_ptr_conv;
15701         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15702         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
15703         InitFeatures_free(this_ptr_conv);
15704 }
15705
15706 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NodeFeatures_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
15707         LDKNodeFeatures this_ptr_conv;
15708         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15709         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
15710         NodeFeatures_free(this_ptr_conv);
15711 }
15712
15713 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelFeatures_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
15714         LDKChannelFeatures this_ptr_conv;
15715         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15716         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
15717         ChannelFeatures_free(this_ptr_conv);
15718 }
15719
15720 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RouteHop_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
15721         LDKRouteHop this_ptr_conv;
15722         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15723         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
15724         RouteHop_free(this_ptr_conv);
15725 }
15726
15727 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_RouteHop_1clone(JNIEnv *env, jclass clz, int64_t orig) {
15728         LDKRouteHop orig_conv;
15729         orig_conv.inner = (void*)(orig & (~1));
15730         orig_conv.is_owned = false;
15731         LDKRouteHop ret_var = RouteHop_clone(&orig_conv);
15732         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15733         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15734         long ret_ref = (long)ret_var.inner;
15735         if (ret_var.is_owned) {
15736                 ret_ref |= 1;
15737         }
15738         return ret_ref;
15739 }
15740
15741 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_RouteHop_1get_1pubkey(JNIEnv *env, jclass clz, int64_t this_ptr) {
15742         LDKRouteHop this_ptr_conv;
15743         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15744         this_ptr_conv.is_owned = false;
15745         int8_tArray arg_arr = (*env)->NewByteArray(env, 33);
15746         (*env)->SetByteArrayRegion(env, arg_arr, 0, 33, RouteHop_get_pubkey(&this_ptr_conv).compressed_form);
15747         return arg_arr;
15748 }
15749
15750 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RouteHop_1set_1pubkey(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
15751         LDKRouteHop this_ptr_conv;
15752         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15753         this_ptr_conv.is_owned = false;
15754         LDKPublicKey val_ref;
15755         CHECK((*env)->GetArrayLength(env, val) == 33);
15756         (*env)->GetByteArrayRegion(env, val, 0, 33, val_ref.compressed_form);
15757         RouteHop_set_pubkey(&this_ptr_conv, val_ref);
15758 }
15759
15760 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_RouteHop_1get_1node_1features(JNIEnv *env, jclass clz, int64_t this_ptr) {
15761         LDKRouteHop this_ptr_conv;
15762         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15763         this_ptr_conv.is_owned = false;
15764         LDKNodeFeatures ret_var = RouteHop_get_node_features(&this_ptr_conv);
15765         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15766         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15767         long ret_ref = (long)ret_var.inner;
15768         if (ret_var.is_owned) {
15769                 ret_ref |= 1;
15770         }
15771         return ret_ref;
15772 }
15773
15774 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RouteHop_1set_1node_1features(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
15775         LDKRouteHop this_ptr_conv;
15776         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15777         this_ptr_conv.is_owned = false;
15778         LDKNodeFeatures val_conv;
15779         val_conv.inner = (void*)(val & (~1));
15780         val_conv.is_owned = (val & 1) || (val == 0);
15781         // Warning: we may need a move here but can't clone!
15782         RouteHop_set_node_features(&this_ptr_conv, val_conv);
15783 }
15784
15785 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_RouteHop_1get_1short_1channel_1id(JNIEnv *env, jclass clz, int64_t this_ptr) {
15786         LDKRouteHop this_ptr_conv;
15787         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15788         this_ptr_conv.is_owned = false;
15789         int64_t ret_val = RouteHop_get_short_channel_id(&this_ptr_conv);
15790         return ret_val;
15791 }
15792
15793 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RouteHop_1set_1short_1channel_1id(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
15794         LDKRouteHop this_ptr_conv;
15795         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15796         this_ptr_conv.is_owned = false;
15797         RouteHop_set_short_channel_id(&this_ptr_conv, val);
15798 }
15799
15800 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_RouteHop_1get_1channel_1features(JNIEnv *env, jclass clz, int64_t this_ptr) {
15801         LDKRouteHop this_ptr_conv;
15802         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15803         this_ptr_conv.is_owned = false;
15804         LDKChannelFeatures ret_var = RouteHop_get_channel_features(&this_ptr_conv);
15805         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15806         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15807         long ret_ref = (long)ret_var.inner;
15808         if (ret_var.is_owned) {
15809                 ret_ref |= 1;
15810         }
15811         return ret_ref;
15812 }
15813
15814 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RouteHop_1set_1channel_1features(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
15815         LDKRouteHop this_ptr_conv;
15816         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15817         this_ptr_conv.is_owned = false;
15818         LDKChannelFeatures val_conv;
15819         val_conv.inner = (void*)(val & (~1));
15820         val_conv.is_owned = (val & 1) || (val == 0);
15821         // Warning: we may need a move here but can't clone!
15822         RouteHop_set_channel_features(&this_ptr_conv, val_conv);
15823 }
15824
15825 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_RouteHop_1get_1fee_1msat(JNIEnv *env, jclass clz, int64_t this_ptr) {
15826         LDKRouteHop this_ptr_conv;
15827         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15828         this_ptr_conv.is_owned = false;
15829         int64_t ret_val = RouteHop_get_fee_msat(&this_ptr_conv);
15830         return ret_val;
15831 }
15832
15833 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RouteHop_1set_1fee_1msat(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
15834         LDKRouteHop this_ptr_conv;
15835         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15836         this_ptr_conv.is_owned = false;
15837         RouteHop_set_fee_msat(&this_ptr_conv, val);
15838 }
15839
15840 JNIEXPORT int32_t JNICALL Java_org_ldk_impl_bindings_RouteHop_1get_1cltv_1expiry_1delta(JNIEnv *env, jclass clz, int64_t this_ptr) {
15841         LDKRouteHop this_ptr_conv;
15842         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15843         this_ptr_conv.is_owned = false;
15844         int32_t ret_val = RouteHop_get_cltv_expiry_delta(&this_ptr_conv);
15845         return ret_val;
15846 }
15847
15848 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RouteHop_1set_1cltv_1expiry_1delta(JNIEnv *env, jclass clz, int64_t this_ptr, int32_t val) {
15849         LDKRouteHop this_ptr_conv;
15850         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15851         this_ptr_conv.is_owned = false;
15852         RouteHop_set_cltv_expiry_delta(&this_ptr_conv, val);
15853 }
15854
15855 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) {
15856         LDKPublicKey pubkey_arg_ref;
15857         CHECK((*env)->GetArrayLength(env, pubkey_arg) == 33);
15858         (*env)->GetByteArrayRegion(env, pubkey_arg, 0, 33, pubkey_arg_ref.compressed_form);
15859         LDKNodeFeatures node_features_arg_conv;
15860         node_features_arg_conv.inner = (void*)(node_features_arg & (~1));
15861         node_features_arg_conv.is_owned = (node_features_arg & 1) || (node_features_arg == 0);
15862         // Warning: we may need a move here but can't clone!
15863         LDKChannelFeatures channel_features_arg_conv;
15864         channel_features_arg_conv.inner = (void*)(channel_features_arg & (~1));
15865         channel_features_arg_conv.is_owned = (channel_features_arg & 1) || (channel_features_arg == 0);
15866         // Warning: we may need a move here but can't clone!
15867         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);
15868         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15869         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15870         long ret_ref = (long)ret_var.inner;
15871         if (ret_var.is_owned) {
15872                 ret_ref |= 1;
15873         }
15874         return ret_ref;
15875 }
15876
15877 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Route_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
15878         LDKRoute this_ptr_conv;
15879         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15880         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
15881         Route_free(this_ptr_conv);
15882 }
15883
15884 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_Route_1clone(JNIEnv *env, jclass clz, int64_t orig) {
15885         LDKRoute orig_conv;
15886         orig_conv.inner = (void*)(orig & (~1));
15887         orig_conv.is_owned = false;
15888         LDKRoute ret_var = Route_clone(&orig_conv);
15889         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15890         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15891         long ret_ref = (long)ret_var.inner;
15892         if (ret_var.is_owned) {
15893                 ret_ref |= 1;
15894         }
15895         return ret_ref;
15896 }
15897
15898 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Route_1set_1paths(JNIEnv *env, jclass clz, int64_t this_ptr, jobjectArray val) {
15899         LDKRoute this_ptr_conv;
15900         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15901         this_ptr_conv.is_owned = false;
15902         LDKCVec_CVec_RouteHopZZ val_constr;
15903         val_constr.datalen = (*env)->GetArrayLength(env, val);
15904         if (val_constr.datalen > 0)
15905                 val_constr.data = MALLOC(val_constr.datalen * sizeof(LDKCVec_RouteHopZ), "LDKCVec_CVec_RouteHopZZ Elements");
15906         else
15907                 val_constr.data = NULL;
15908         for (size_t m = 0; m < val_constr.datalen; m++) {
15909                 int64_tArray arr_conv_12 = (*env)->GetObjectArrayElement(env, val, m);
15910                 LDKCVec_RouteHopZ arr_conv_12_constr;
15911                 arr_conv_12_constr.datalen = (*env)->GetArrayLength(env, arr_conv_12);
15912                 if (arr_conv_12_constr.datalen > 0)
15913                         arr_conv_12_constr.data = MALLOC(arr_conv_12_constr.datalen * sizeof(LDKRouteHop), "LDKCVec_RouteHopZ Elements");
15914                 else
15915                         arr_conv_12_constr.data = NULL;
15916                 int64_t* arr_conv_12_vals = (*env)->GetLongArrayElements (env, arr_conv_12, NULL);
15917                 for (size_t k = 0; k < arr_conv_12_constr.datalen; k++) {
15918                         int64_t arr_conv_10 = arr_conv_12_vals[k];
15919                         LDKRouteHop arr_conv_10_conv;
15920                         arr_conv_10_conv.inner = (void*)(arr_conv_10 & (~1));
15921                         arr_conv_10_conv.is_owned = (arr_conv_10 & 1) || (arr_conv_10 == 0);
15922                         if (arr_conv_10_conv.inner != NULL)
15923                                 arr_conv_10_conv = RouteHop_clone(&arr_conv_10_conv);
15924                         arr_conv_12_constr.data[k] = arr_conv_10_conv;
15925                 }
15926                 (*env)->ReleaseLongArrayElements(env, arr_conv_12, arr_conv_12_vals, 0);
15927                 val_constr.data[m] = arr_conv_12_constr;
15928         }
15929         Route_set_paths(&this_ptr_conv, val_constr);
15930 }
15931
15932 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_Route_1new(JNIEnv *env, jclass clz, jobjectArray paths_arg) {
15933         LDKCVec_CVec_RouteHopZZ paths_arg_constr;
15934         paths_arg_constr.datalen = (*env)->GetArrayLength(env, paths_arg);
15935         if (paths_arg_constr.datalen > 0)
15936                 paths_arg_constr.data = MALLOC(paths_arg_constr.datalen * sizeof(LDKCVec_RouteHopZ), "LDKCVec_CVec_RouteHopZZ Elements");
15937         else
15938                 paths_arg_constr.data = NULL;
15939         for (size_t m = 0; m < paths_arg_constr.datalen; m++) {
15940                 int64_tArray arr_conv_12 = (*env)->GetObjectArrayElement(env, paths_arg, m);
15941                 LDKCVec_RouteHopZ arr_conv_12_constr;
15942                 arr_conv_12_constr.datalen = (*env)->GetArrayLength(env, arr_conv_12);
15943                 if (arr_conv_12_constr.datalen > 0)
15944                         arr_conv_12_constr.data = MALLOC(arr_conv_12_constr.datalen * sizeof(LDKRouteHop), "LDKCVec_RouteHopZ Elements");
15945                 else
15946                         arr_conv_12_constr.data = NULL;
15947                 int64_t* arr_conv_12_vals = (*env)->GetLongArrayElements (env, arr_conv_12, NULL);
15948                 for (size_t k = 0; k < arr_conv_12_constr.datalen; k++) {
15949                         int64_t arr_conv_10 = arr_conv_12_vals[k];
15950                         LDKRouteHop arr_conv_10_conv;
15951                         arr_conv_10_conv.inner = (void*)(arr_conv_10 & (~1));
15952                         arr_conv_10_conv.is_owned = (arr_conv_10 & 1) || (arr_conv_10 == 0);
15953                         if (arr_conv_10_conv.inner != NULL)
15954                                 arr_conv_10_conv = RouteHop_clone(&arr_conv_10_conv);
15955                         arr_conv_12_constr.data[k] = arr_conv_10_conv;
15956                 }
15957                 (*env)->ReleaseLongArrayElements(env, arr_conv_12, arr_conv_12_vals, 0);
15958                 paths_arg_constr.data[m] = arr_conv_12_constr;
15959         }
15960         LDKRoute ret_var = Route_new(paths_arg_constr);
15961         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15962         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15963         long ret_ref = (long)ret_var.inner;
15964         if (ret_var.is_owned) {
15965                 ret_ref |= 1;
15966         }
15967         return ret_ref;
15968 }
15969
15970 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_Route_1write(JNIEnv *env, jclass clz, int64_t obj) {
15971         LDKRoute obj_conv;
15972         obj_conv.inner = (void*)(obj & (~1));
15973         obj_conv.is_owned = false;
15974         LDKCVec_u8Z arg_var = Route_write(&obj_conv);
15975         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
15976         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
15977         CVec_u8Z_free(arg_var);
15978         return arg_arr;
15979 }
15980
15981 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_Route_1read(JNIEnv *env, jclass clz, int8_tArray ser) {
15982         LDKu8slice ser_ref;
15983         ser_ref.datalen = (*env)->GetArrayLength(env, ser);
15984         ser_ref.data = (*env)->GetByteArrayElements (env, ser, NULL);
15985         LDKCResult_RouteDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_RouteDecodeErrorZ), "LDKCResult_RouteDecodeErrorZ");
15986         *ret_conv = Route_read(ser_ref);
15987         (*env)->ReleaseByteArrayElements(env, ser, (int8_t*)ser_ref.data, 0);
15988         return (long)ret_conv;
15989 }
15990
15991 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RouteHint_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
15992         LDKRouteHint this_ptr_conv;
15993         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15994         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
15995         RouteHint_free(this_ptr_conv);
15996 }
15997
15998 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_RouteHint_1clone(JNIEnv *env, jclass clz, int64_t orig) {
15999         LDKRouteHint orig_conv;
16000         orig_conv.inner = (void*)(orig & (~1));
16001         orig_conv.is_owned = false;
16002         LDKRouteHint ret_var = RouteHint_clone(&orig_conv);
16003         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
16004         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
16005         long ret_ref = (long)ret_var.inner;
16006         if (ret_var.is_owned) {
16007                 ret_ref |= 1;
16008         }
16009         return ret_ref;
16010 }
16011
16012 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_RouteHint_1get_1src_1node_1id(JNIEnv *env, jclass clz, int64_t this_ptr) {
16013         LDKRouteHint this_ptr_conv;
16014         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16015         this_ptr_conv.is_owned = false;
16016         int8_tArray arg_arr = (*env)->NewByteArray(env, 33);
16017         (*env)->SetByteArrayRegion(env, arg_arr, 0, 33, RouteHint_get_src_node_id(&this_ptr_conv).compressed_form);
16018         return arg_arr;
16019 }
16020
16021 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RouteHint_1set_1src_1node_1id(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
16022         LDKRouteHint this_ptr_conv;
16023         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16024         this_ptr_conv.is_owned = false;
16025         LDKPublicKey val_ref;
16026         CHECK((*env)->GetArrayLength(env, val) == 33);
16027         (*env)->GetByteArrayRegion(env, val, 0, 33, val_ref.compressed_form);
16028         RouteHint_set_src_node_id(&this_ptr_conv, val_ref);
16029 }
16030
16031 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_RouteHint_1get_1short_1channel_1id(JNIEnv *env, jclass clz, int64_t this_ptr) {
16032         LDKRouteHint this_ptr_conv;
16033         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16034         this_ptr_conv.is_owned = false;
16035         int64_t ret_val = RouteHint_get_short_channel_id(&this_ptr_conv);
16036         return ret_val;
16037 }
16038
16039 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RouteHint_1set_1short_1channel_1id(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
16040         LDKRouteHint this_ptr_conv;
16041         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16042         this_ptr_conv.is_owned = false;
16043         RouteHint_set_short_channel_id(&this_ptr_conv, val);
16044 }
16045
16046 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_RouteHint_1get_1fees(JNIEnv *env, jclass clz, int64_t this_ptr) {
16047         LDKRouteHint this_ptr_conv;
16048         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16049         this_ptr_conv.is_owned = false;
16050         LDKRoutingFees ret_var = RouteHint_get_fees(&this_ptr_conv);
16051         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
16052         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
16053         long ret_ref = (long)ret_var.inner;
16054         if (ret_var.is_owned) {
16055                 ret_ref |= 1;
16056         }
16057         return ret_ref;
16058 }
16059
16060 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RouteHint_1set_1fees(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
16061         LDKRouteHint this_ptr_conv;
16062         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16063         this_ptr_conv.is_owned = false;
16064         LDKRoutingFees val_conv;
16065         val_conv.inner = (void*)(val & (~1));
16066         val_conv.is_owned = (val & 1) || (val == 0);
16067         if (val_conv.inner != NULL)
16068                 val_conv = RoutingFees_clone(&val_conv);
16069         RouteHint_set_fees(&this_ptr_conv, val_conv);
16070 }
16071
16072 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_RouteHint_1get_1cltv_1expiry_1delta(JNIEnv *env, jclass clz, int64_t this_ptr) {
16073         LDKRouteHint this_ptr_conv;
16074         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16075         this_ptr_conv.is_owned = false;
16076         jshort ret_val = RouteHint_get_cltv_expiry_delta(&this_ptr_conv);
16077         return ret_val;
16078 }
16079
16080 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RouteHint_1set_1cltv_1expiry_1delta(JNIEnv *env, jclass clz, int64_t this_ptr, jshort val) {
16081         LDKRouteHint this_ptr_conv;
16082         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16083         this_ptr_conv.is_owned = false;
16084         RouteHint_set_cltv_expiry_delta(&this_ptr_conv, val);
16085 }
16086
16087 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_RouteHint_1get_1htlc_1minimum_1msat(JNIEnv *env, jclass clz, int64_t this_ptr) {
16088         LDKRouteHint this_ptr_conv;
16089         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16090         this_ptr_conv.is_owned = false;
16091         int64_t ret_val = RouteHint_get_htlc_minimum_msat(&this_ptr_conv);
16092         return ret_val;
16093 }
16094
16095 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RouteHint_1set_1htlc_1minimum_1msat(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
16096         LDKRouteHint this_ptr_conv;
16097         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16098         this_ptr_conv.is_owned = false;
16099         RouteHint_set_htlc_minimum_msat(&this_ptr_conv, val);
16100 }
16101
16102 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, jshort cltv_expiry_delta_arg, int64_t htlc_minimum_msat_arg) {
16103         LDKPublicKey src_node_id_arg_ref;
16104         CHECK((*env)->GetArrayLength(env, src_node_id_arg) == 33);
16105         (*env)->GetByteArrayRegion(env, src_node_id_arg, 0, 33, src_node_id_arg_ref.compressed_form);
16106         LDKRoutingFees fees_arg_conv;
16107         fees_arg_conv.inner = (void*)(fees_arg & (~1));
16108         fees_arg_conv.is_owned = (fees_arg & 1) || (fees_arg == 0);
16109         if (fees_arg_conv.inner != NULL)
16110                 fees_arg_conv = RoutingFees_clone(&fees_arg_conv);
16111         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);
16112         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
16113         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
16114         long ret_ref = (long)ret_var.inner;
16115         if (ret_var.is_owned) {
16116                 ret_ref |= 1;
16117         }
16118         return ret_ref;
16119 }
16120
16121 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) {
16122         LDKPublicKey our_node_id_ref;
16123         CHECK((*env)->GetArrayLength(env, our_node_id) == 33);
16124         (*env)->GetByteArrayRegion(env, our_node_id, 0, 33, our_node_id_ref.compressed_form);
16125         LDKNetworkGraph network_conv;
16126         network_conv.inner = (void*)(network & (~1));
16127         network_conv.is_owned = false;
16128         LDKPublicKey target_ref;
16129         CHECK((*env)->GetArrayLength(env, target) == 33);
16130         (*env)->GetByteArrayRegion(env, target, 0, 33, target_ref.compressed_form);
16131         LDKCVec_ChannelDetailsZ first_hops_constr;
16132         first_hops_constr.datalen = (*env)->GetArrayLength(env, first_hops);
16133         if (first_hops_constr.datalen > 0)
16134                 first_hops_constr.data = MALLOC(first_hops_constr.datalen * sizeof(LDKChannelDetails), "LDKCVec_ChannelDetailsZ Elements");
16135         else
16136                 first_hops_constr.data = NULL;
16137         int64_t* first_hops_vals = (*env)->GetLongArrayElements (env, first_hops, NULL);
16138         for (size_t q = 0; q < first_hops_constr.datalen; q++) {
16139                 int64_t arr_conv_16 = first_hops_vals[q];
16140                 LDKChannelDetails arr_conv_16_conv;
16141                 arr_conv_16_conv.inner = (void*)(arr_conv_16 & (~1));
16142                 arr_conv_16_conv.is_owned = (arr_conv_16 & 1) || (arr_conv_16 == 0);
16143                 first_hops_constr.data[q] = arr_conv_16_conv;
16144         }
16145         (*env)->ReleaseLongArrayElements(env, first_hops, first_hops_vals, 0);
16146         LDKCVec_RouteHintZ last_hops_constr;
16147         last_hops_constr.datalen = (*env)->GetArrayLength(env, last_hops);
16148         if (last_hops_constr.datalen > 0)
16149                 last_hops_constr.data = MALLOC(last_hops_constr.datalen * sizeof(LDKRouteHint), "LDKCVec_RouteHintZ Elements");
16150         else
16151                 last_hops_constr.data = NULL;
16152         int64_t* last_hops_vals = (*env)->GetLongArrayElements (env, last_hops, NULL);
16153         for (size_t l = 0; l < last_hops_constr.datalen; l++) {
16154                 int64_t arr_conv_11 = last_hops_vals[l];
16155                 LDKRouteHint arr_conv_11_conv;
16156                 arr_conv_11_conv.inner = (void*)(arr_conv_11 & (~1));
16157                 arr_conv_11_conv.is_owned = (arr_conv_11 & 1) || (arr_conv_11 == 0);
16158                 if (arr_conv_11_conv.inner != NULL)
16159                         arr_conv_11_conv = RouteHint_clone(&arr_conv_11_conv);
16160                 last_hops_constr.data[l] = arr_conv_11_conv;
16161         }
16162         (*env)->ReleaseLongArrayElements(env, last_hops, last_hops_vals, 0);
16163         LDKLogger logger_conv = *(LDKLogger*)logger;
16164         if (logger_conv.free == LDKLogger_JCalls_free) {
16165                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
16166                 LDKLogger_JCalls_clone(logger_conv.this_arg);
16167         }
16168         LDKCResult_RouteLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_RouteLightningErrorZ), "LDKCResult_RouteLightningErrorZ");
16169         *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);
16170         FREE(first_hops_constr.data);
16171         return (long)ret_conv;
16172 }
16173
16174 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NetworkGraph_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
16175         LDKNetworkGraph this_ptr_conv;
16176         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16177         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
16178         NetworkGraph_free(this_ptr_conv);
16179 }
16180
16181 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_LockedNetworkGraph_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
16182         LDKLockedNetworkGraph this_ptr_conv;
16183         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16184         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
16185         LockedNetworkGraph_free(this_ptr_conv);
16186 }
16187
16188 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NetGraphMsgHandler_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
16189         LDKNetGraphMsgHandler this_ptr_conv;
16190         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16191         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
16192         NetGraphMsgHandler_free(this_ptr_conv);
16193 }
16194
16195 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) {
16196         LDKThirtyTwoBytes genesis_hash_ref;
16197         CHECK((*env)->GetArrayLength(env, genesis_hash) == 32);
16198         (*env)->GetByteArrayRegion(env, genesis_hash, 0, 32, genesis_hash_ref.data);
16199         LDKAccess* chain_access_conv = (LDKAccess*)chain_access;
16200         LDKLogger logger_conv = *(LDKLogger*)logger;
16201         if (logger_conv.free == LDKLogger_JCalls_free) {
16202                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
16203                 LDKLogger_JCalls_clone(logger_conv.this_arg);
16204         }
16205         LDKNetGraphMsgHandler ret_var = NetGraphMsgHandler_new(genesis_hash_ref, chain_access_conv, logger_conv);
16206         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
16207         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
16208         long ret_ref = (long)ret_var.inner;
16209         if (ret_var.is_owned) {
16210                 ret_ref |= 1;
16211         }
16212         return ret_ref;
16213 }
16214
16215 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) {
16216         LDKAccess* chain_access_conv = (LDKAccess*)chain_access;
16217         LDKLogger logger_conv = *(LDKLogger*)logger;
16218         if (logger_conv.free == LDKLogger_JCalls_free) {
16219                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
16220                 LDKLogger_JCalls_clone(logger_conv.this_arg);
16221         }
16222         LDKNetworkGraph network_graph_conv;
16223         network_graph_conv.inner = (void*)(network_graph & (~1));
16224         network_graph_conv.is_owned = (network_graph & 1) || (network_graph == 0);
16225         // Warning: we may need a move here but can't clone!
16226         LDKNetGraphMsgHandler ret_var = NetGraphMsgHandler_from_net_graph(chain_access_conv, logger_conv, network_graph_conv);
16227         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
16228         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
16229         long ret_ref = (long)ret_var.inner;
16230         if (ret_var.is_owned) {
16231                 ret_ref |= 1;
16232         }
16233         return ret_ref;
16234 }
16235
16236 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_NetGraphMsgHandler_1read_1locked_1graph(JNIEnv *env, jclass clz, int64_t this_arg) {
16237         LDKNetGraphMsgHandler this_arg_conv;
16238         this_arg_conv.inner = (void*)(this_arg & (~1));
16239         this_arg_conv.is_owned = false;
16240         LDKLockedNetworkGraph ret_var = NetGraphMsgHandler_read_locked_graph(&this_arg_conv);
16241         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
16242         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
16243         long ret_ref = (long)ret_var.inner;
16244         if (ret_var.is_owned) {
16245                 ret_ref |= 1;
16246         }
16247         return ret_ref;
16248 }
16249
16250 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_LockedNetworkGraph_1graph(JNIEnv *env, jclass clz, int64_t this_arg) {
16251         LDKLockedNetworkGraph this_arg_conv;
16252         this_arg_conv.inner = (void*)(this_arg & (~1));
16253         this_arg_conv.is_owned = false;
16254         LDKNetworkGraph ret_var = LockedNetworkGraph_graph(&this_arg_conv);
16255         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
16256         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
16257         long ret_ref = (long)ret_var.inner;
16258         if (ret_var.is_owned) {
16259                 ret_ref |= 1;
16260         }
16261         return ret_ref;
16262 }
16263
16264 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_NetGraphMsgHandler_1as_1RoutingMessageHandler(JNIEnv *env, jclass clz, int64_t this_arg) {
16265         LDKNetGraphMsgHandler this_arg_conv;
16266         this_arg_conv.inner = (void*)(this_arg & (~1));
16267         this_arg_conv.is_owned = false;
16268         LDKRoutingMessageHandler* ret = MALLOC(sizeof(LDKRoutingMessageHandler), "LDKRoutingMessageHandler");
16269         *ret = NetGraphMsgHandler_as_RoutingMessageHandler(&this_arg_conv);
16270         return (long)ret;
16271 }
16272
16273 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_NetGraphMsgHandler_1as_1MessageSendEventsProvider(JNIEnv *env, jclass clz, int64_t this_arg) {
16274         LDKNetGraphMsgHandler this_arg_conv;
16275         this_arg_conv.inner = (void*)(this_arg & (~1));
16276         this_arg_conv.is_owned = false;
16277         LDKMessageSendEventsProvider* ret = MALLOC(sizeof(LDKMessageSendEventsProvider), "LDKMessageSendEventsProvider");
16278         *ret = NetGraphMsgHandler_as_MessageSendEventsProvider(&this_arg_conv);
16279         return (long)ret;
16280 }
16281
16282 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_DirectionalChannelInfo_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
16283         LDKDirectionalChannelInfo this_ptr_conv;
16284         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16285         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
16286         DirectionalChannelInfo_free(this_ptr_conv);
16287 }
16288
16289 JNIEXPORT int32_t JNICALL Java_org_ldk_impl_bindings_DirectionalChannelInfo_1get_1last_1update(JNIEnv *env, jclass clz, int64_t this_ptr) {
16290         LDKDirectionalChannelInfo this_ptr_conv;
16291         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16292         this_ptr_conv.is_owned = false;
16293         int32_t ret_val = DirectionalChannelInfo_get_last_update(&this_ptr_conv);
16294         return ret_val;
16295 }
16296
16297 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_DirectionalChannelInfo_1set_1last_1update(JNIEnv *env, jclass clz, int64_t this_ptr, int32_t val) {
16298         LDKDirectionalChannelInfo this_ptr_conv;
16299         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16300         this_ptr_conv.is_owned = false;
16301         DirectionalChannelInfo_set_last_update(&this_ptr_conv, val);
16302 }
16303
16304 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_DirectionalChannelInfo_1get_1enabled(JNIEnv *env, jclass clz, int64_t this_ptr) {
16305         LDKDirectionalChannelInfo this_ptr_conv;
16306         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16307         this_ptr_conv.is_owned = false;
16308         jboolean ret_val = DirectionalChannelInfo_get_enabled(&this_ptr_conv);
16309         return ret_val;
16310 }
16311
16312 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_DirectionalChannelInfo_1set_1enabled(JNIEnv *env, jclass clz, int64_t this_ptr, jboolean val) {
16313         LDKDirectionalChannelInfo this_ptr_conv;
16314         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16315         this_ptr_conv.is_owned = false;
16316         DirectionalChannelInfo_set_enabled(&this_ptr_conv, val);
16317 }
16318
16319 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_DirectionalChannelInfo_1get_1cltv_1expiry_1delta(JNIEnv *env, jclass clz, int64_t this_ptr) {
16320         LDKDirectionalChannelInfo this_ptr_conv;
16321         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16322         this_ptr_conv.is_owned = false;
16323         jshort ret_val = DirectionalChannelInfo_get_cltv_expiry_delta(&this_ptr_conv);
16324         return ret_val;
16325 }
16326
16327 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_DirectionalChannelInfo_1set_1cltv_1expiry_1delta(JNIEnv *env, jclass clz, int64_t this_ptr, jshort val) {
16328         LDKDirectionalChannelInfo this_ptr_conv;
16329         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16330         this_ptr_conv.is_owned = false;
16331         DirectionalChannelInfo_set_cltv_expiry_delta(&this_ptr_conv, val);
16332 }
16333
16334 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_DirectionalChannelInfo_1get_1htlc_1minimum_1msat(JNIEnv *env, jclass clz, int64_t this_ptr) {
16335         LDKDirectionalChannelInfo this_ptr_conv;
16336         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16337         this_ptr_conv.is_owned = false;
16338         int64_t ret_val = DirectionalChannelInfo_get_htlc_minimum_msat(&this_ptr_conv);
16339         return ret_val;
16340 }
16341
16342 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_DirectionalChannelInfo_1set_1htlc_1minimum_1msat(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
16343         LDKDirectionalChannelInfo this_ptr_conv;
16344         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16345         this_ptr_conv.is_owned = false;
16346         DirectionalChannelInfo_set_htlc_minimum_msat(&this_ptr_conv, val);
16347 }
16348
16349 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_DirectionalChannelInfo_1get_1fees(JNIEnv *env, jclass clz, int64_t this_ptr) {
16350         LDKDirectionalChannelInfo this_ptr_conv;
16351         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16352         this_ptr_conv.is_owned = false;
16353         LDKRoutingFees ret_var = DirectionalChannelInfo_get_fees(&this_ptr_conv);
16354         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
16355         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
16356         long ret_ref = (long)ret_var.inner;
16357         if (ret_var.is_owned) {
16358                 ret_ref |= 1;
16359         }
16360         return ret_ref;
16361 }
16362
16363 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_DirectionalChannelInfo_1set_1fees(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
16364         LDKDirectionalChannelInfo this_ptr_conv;
16365         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16366         this_ptr_conv.is_owned = false;
16367         LDKRoutingFees val_conv;
16368         val_conv.inner = (void*)(val & (~1));
16369         val_conv.is_owned = (val & 1) || (val == 0);
16370         if (val_conv.inner != NULL)
16371                 val_conv = RoutingFees_clone(&val_conv);
16372         DirectionalChannelInfo_set_fees(&this_ptr_conv, val_conv);
16373 }
16374
16375 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_DirectionalChannelInfo_1get_1last_1update_1message(JNIEnv *env, jclass clz, int64_t this_ptr) {
16376         LDKDirectionalChannelInfo this_ptr_conv;
16377         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16378         this_ptr_conv.is_owned = false;
16379         LDKChannelUpdate ret_var = DirectionalChannelInfo_get_last_update_message(&this_ptr_conv);
16380         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
16381         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
16382         long ret_ref = (long)ret_var.inner;
16383         if (ret_var.is_owned) {
16384                 ret_ref |= 1;
16385         }
16386         return ret_ref;
16387 }
16388
16389 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_DirectionalChannelInfo_1set_1last_1update_1message(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
16390         LDKDirectionalChannelInfo this_ptr_conv;
16391         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16392         this_ptr_conv.is_owned = false;
16393         LDKChannelUpdate val_conv;
16394         val_conv.inner = (void*)(val & (~1));
16395         val_conv.is_owned = (val & 1) || (val == 0);
16396         if (val_conv.inner != NULL)
16397                 val_conv = ChannelUpdate_clone(&val_conv);
16398         DirectionalChannelInfo_set_last_update_message(&this_ptr_conv, val_conv);
16399 }
16400
16401 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_DirectionalChannelInfo_1write(JNIEnv *env, jclass clz, int64_t obj) {
16402         LDKDirectionalChannelInfo obj_conv;
16403         obj_conv.inner = (void*)(obj & (~1));
16404         obj_conv.is_owned = false;
16405         LDKCVec_u8Z arg_var = DirectionalChannelInfo_write(&obj_conv);
16406         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
16407         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
16408         CVec_u8Z_free(arg_var);
16409         return arg_arr;
16410 }
16411
16412 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_DirectionalChannelInfo_1read(JNIEnv *env, jclass clz, int8_tArray ser) {
16413         LDKu8slice ser_ref;
16414         ser_ref.datalen = (*env)->GetArrayLength(env, ser);
16415         ser_ref.data = (*env)->GetByteArrayElements (env, ser, NULL);
16416         LDKDirectionalChannelInfo ret_var = DirectionalChannelInfo_read(ser_ref);
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         (*env)->ReleaseByteArrayElements(env, ser, (int8_t*)ser_ref.data, 0);
16424         return ret_ref;
16425 }
16426
16427 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelInfo_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
16428         LDKChannelInfo this_ptr_conv;
16429         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16430         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
16431         ChannelInfo_free(this_ptr_conv);
16432 }
16433
16434 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelInfo_1get_1features(JNIEnv *env, jclass clz, int64_t this_ptr) {
16435         LDKChannelInfo this_ptr_conv;
16436         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16437         this_ptr_conv.is_owned = false;
16438         LDKChannelFeatures ret_var = ChannelInfo_get_features(&this_ptr_conv);
16439         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
16440         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
16441         long ret_ref = (long)ret_var.inner;
16442         if (ret_var.is_owned) {
16443                 ret_ref |= 1;
16444         }
16445         return ret_ref;
16446 }
16447
16448 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelInfo_1set_1features(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
16449         LDKChannelInfo this_ptr_conv;
16450         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16451         this_ptr_conv.is_owned = false;
16452         LDKChannelFeatures val_conv;
16453         val_conv.inner = (void*)(val & (~1));
16454         val_conv.is_owned = (val & 1) || (val == 0);
16455         // Warning: we may need a move here but can't clone!
16456         ChannelInfo_set_features(&this_ptr_conv, val_conv);
16457 }
16458
16459 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_ChannelInfo_1get_1node_1one(JNIEnv *env, jclass clz, int64_t this_ptr) {
16460         LDKChannelInfo this_ptr_conv;
16461         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16462         this_ptr_conv.is_owned = false;
16463         int8_tArray arg_arr = (*env)->NewByteArray(env, 33);
16464         (*env)->SetByteArrayRegion(env, arg_arr, 0, 33, ChannelInfo_get_node_one(&this_ptr_conv).compressed_form);
16465         return arg_arr;
16466 }
16467
16468 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelInfo_1set_1node_1one(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
16469         LDKChannelInfo this_ptr_conv;
16470         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16471         this_ptr_conv.is_owned = false;
16472         LDKPublicKey val_ref;
16473         CHECK((*env)->GetArrayLength(env, val) == 33);
16474         (*env)->GetByteArrayRegion(env, val, 0, 33, val_ref.compressed_form);
16475         ChannelInfo_set_node_one(&this_ptr_conv, val_ref);
16476 }
16477
16478 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelInfo_1get_1one_1to_1two(JNIEnv *env, jclass clz, int64_t this_ptr) {
16479         LDKChannelInfo this_ptr_conv;
16480         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16481         this_ptr_conv.is_owned = false;
16482         LDKDirectionalChannelInfo ret_var = ChannelInfo_get_one_to_two(&this_ptr_conv);
16483         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
16484         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
16485         long ret_ref = (long)ret_var.inner;
16486         if (ret_var.is_owned) {
16487                 ret_ref |= 1;
16488         }
16489         return ret_ref;
16490 }
16491
16492 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelInfo_1set_1one_1to_1two(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
16493         LDKChannelInfo this_ptr_conv;
16494         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16495         this_ptr_conv.is_owned = false;
16496         LDKDirectionalChannelInfo val_conv;
16497         val_conv.inner = (void*)(val & (~1));
16498         val_conv.is_owned = (val & 1) || (val == 0);
16499         // Warning: we may need a move here but can't clone!
16500         ChannelInfo_set_one_to_two(&this_ptr_conv, val_conv);
16501 }
16502
16503 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_ChannelInfo_1get_1node_1two(JNIEnv *env, jclass clz, int64_t this_ptr) {
16504         LDKChannelInfo this_ptr_conv;
16505         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16506         this_ptr_conv.is_owned = false;
16507         int8_tArray arg_arr = (*env)->NewByteArray(env, 33);
16508         (*env)->SetByteArrayRegion(env, arg_arr, 0, 33, ChannelInfo_get_node_two(&this_ptr_conv).compressed_form);
16509         return arg_arr;
16510 }
16511
16512 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelInfo_1set_1node_1two(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
16513         LDKChannelInfo this_ptr_conv;
16514         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16515         this_ptr_conv.is_owned = false;
16516         LDKPublicKey val_ref;
16517         CHECK((*env)->GetArrayLength(env, val) == 33);
16518         (*env)->GetByteArrayRegion(env, val, 0, 33, val_ref.compressed_form);
16519         ChannelInfo_set_node_two(&this_ptr_conv, val_ref);
16520 }
16521
16522 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelInfo_1get_1two_1to_1one(JNIEnv *env, jclass clz, int64_t this_ptr) {
16523         LDKChannelInfo this_ptr_conv;
16524         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16525         this_ptr_conv.is_owned = false;
16526         LDKDirectionalChannelInfo ret_var = ChannelInfo_get_two_to_one(&this_ptr_conv);
16527         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
16528         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
16529         long ret_ref = (long)ret_var.inner;
16530         if (ret_var.is_owned) {
16531                 ret_ref |= 1;
16532         }
16533         return ret_ref;
16534 }
16535
16536 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelInfo_1set_1two_1to_1one(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
16537         LDKChannelInfo this_ptr_conv;
16538         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16539         this_ptr_conv.is_owned = false;
16540         LDKDirectionalChannelInfo val_conv;
16541         val_conv.inner = (void*)(val & (~1));
16542         val_conv.is_owned = (val & 1) || (val == 0);
16543         // Warning: we may need a move here but can't clone!
16544         ChannelInfo_set_two_to_one(&this_ptr_conv, val_conv);
16545 }
16546
16547 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelInfo_1get_1announcement_1message(JNIEnv *env, jclass clz, int64_t this_ptr) {
16548         LDKChannelInfo this_ptr_conv;
16549         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16550         this_ptr_conv.is_owned = false;
16551         LDKChannelAnnouncement ret_var = ChannelInfo_get_announcement_message(&this_ptr_conv);
16552         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
16553         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
16554         long ret_ref = (long)ret_var.inner;
16555         if (ret_var.is_owned) {
16556                 ret_ref |= 1;
16557         }
16558         return ret_ref;
16559 }
16560
16561 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelInfo_1set_1announcement_1message(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
16562         LDKChannelInfo this_ptr_conv;
16563         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16564         this_ptr_conv.is_owned = false;
16565         LDKChannelAnnouncement val_conv;
16566         val_conv.inner = (void*)(val & (~1));
16567         val_conv.is_owned = (val & 1) || (val == 0);
16568         if (val_conv.inner != NULL)
16569                 val_conv = ChannelAnnouncement_clone(&val_conv);
16570         ChannelInfo_set_announcement_message(&this_ptr_conv, val_conv);
16571 }
16572
16573 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_ChannelInfo_1write(JNIEnv *env, jclass clz, int64_t obj) {
16574         LDKChannelInfo obj_conv;
16575         obj_conv.inner = (void*)(obj & (~1));
16576         obj_conv.is_owned = false;
16577         LDKCVec_u8Z arg_var = ChannelInfo_write(&obj_conv);
16578         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
16579         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
16580         CVec_u8Z_free(arg_var);
16581         return arg_arr;
16582 }
16583
16584 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_ChannelInfo_1read(JNIEnv *env, jclass clz, int8_tArray ser) {
16585         LDKu8slice ser_ref;
16586         ser_ref.datalen = (*env)->GetArrayLength(env, ser);
16587         ser_ref.data = (*env)->GetByteArrayElements (env, ser, NULL);
16588         LDKChannelInfo ret_var = ChannelInfo_read(ser_ref);
16589         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
16590         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
16591         long ret_ref = (long)ret_var.inner;
16592         if (ret_var.is_owned) {
16593                 ret_ref |= 1;
16594         }
16595         (*env)->ReleaseByteArrayElements(env, ser, (int8_t*)ser_ref.data, 0);
16596         return ret_ref;
16597 }
16598
16599 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RoutingFees_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
16600         LDKRoutingFees this_ptr_conv;
16601         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16602         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
16603         RoutingFees_free(this_ptr_conv);
16604 }
16605
16606 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_RoutingFees_1clone(JNIEnv *env, jclass clz, int64_t orig) {
16607         LDKRoutingFees orig_conv;
16608         orig_conv.inner = (void*)(orig & (~1));
16609         orig_conv.is_owned = false;
16610         LDKRoutingFees ret_var = RoutingFees_clone(&orig_conv);
16611         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
16612         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
16613         long ret_ref = (long)ret_var.inner;
16614         if (ret_var.is_owned) {
16615                 ret_ref |= 1;
16616         }
16617         return ret_ref;
16618 }
16619
16620 JNIEXPORT int32_t JNICALL Java_org_ldk_impl_bindings_RoutingFees_1get_1base_1msat(JNIEnv *env, jclass clz, int64_t this_ptr) {
16621         LDKRoutingFees this_ptr_conv;
16622         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16623         this_ptr_conv.is_owned = false;
16624         int32_t ret_val = RoutingFees_get_base_msat(&this_ptr_conv);
16625         return ret_val;
16626 }
16627
16628 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RoutingFees_1set_1base_1msat(JNIEnv *env, jclass clz, int64_t this_ptr, int32_t val) {
16629         LDKRoutingFees this_ptr_conv;
16630         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16631         this_ptr_conv.is_owned = false;
16632         RoutingFees_set_base_msat(&this_ptr_conv, val);
16633 }
16634
16635 JNIEXPORT int32_t JNICALL Java_org_ldk_impl_bindings_RoutingFees_1get_1proportional_1millionths(JNIEnv *env, jclass clz, int64_t this_ptr) {
16636         LDKRoutingFees this_ptr_conv;
16637         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16638         this_ptr_conv.is_owned = false;
16639         int32_t ret_val = RoutingFees_get_proportional_millionths(&this_ptr_conv);
16640         return ret_val;
16641 }
16642
16643 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RoutingFees_1set_1proportional_1millionths(JNIEnv *env, jclass clz, int64_t this_ptr, int32_t val) {
16644         LDKRoutingFees this_ptr_conv;
16645         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16646         this_ptr_conv.is_owned = false;
16647         RoutingFees_set_proportional_millionths(&this_ptr_conv, val);
16648 }
16649
16650 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) {
16651         LDKRoutingFees ret_var = RoutingFees_new(base_msat_arg, proportional_millionths_arg);
16652         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
16653         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
16654         long ret_ref = (long)ret_var.inner;
16655         if (ret_var.is_owned) {
16656                 ret_ref |= 1;
16657         }
16658         return ret_ref;
16659 }
16660
16661 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_RoutingFees_1read(JNIEnv *env, jclass clz, int8_tArray ser) {
16662         LDKu8slice ser_ref;
16663         ser_ref.datalen = (*env)->GetArrayLength(env, ser);
16664         ser_ref.data = (*env)->GetByteArrayElements (env, ser, NULL);
16665         LDKCResult_RoutingFeesDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_RoutingFeesDecodeErrorZ), "LDKCResult_RoutingFeesDecodeErrorZ");
16666         *ret_conv = RoutingFees_read(ser_ref);
16667         (*env)->ReleaseByteArrayElements(env, ser, (int8_t*)ser_ref.data, 0);
16668         return (long)ret_conv;
16669 }
16670
16671 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_RoutingFees_1write(JNIEnv *env, jclass clz, int64_t obj) {
16672         LDKRoutingFees obj_conv;
16673         obj_conv.inner = (void*)(obj & (~1));
16674         obj_conv.is_owned = false;
16675         LDKCVec_u8Z arg_var = RoutingFees_write(&obj_conv);
16676         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
16677         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
16678         CVec_u8Z_free(arg_var);
16679         return arg_arr;
16680 }
16681
16682 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NodeAnnouncementInfo_1free(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 = (this_ptr & 1) || (this_ptr == 0);
16686         NodeAnnouncementInfo_free(this_ptr_conv);
16687 }
16688
16689 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_NodeAnnouncementInfo_1get_1features(JNIEnv *env, jclass clz, int64_t this_ptr) {
16690         LDKNodeAnnouncementInfo this_ptr_conv;
16691         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16692         this_ptr_conv.is_owned = false;
16693         LDKNodeFeatures ret_var = NodeAnnouncementInfo_get_features(&this_ptr_conv);
16694         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
16695         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
16696         long ret_ref = (long)ret_var.inner;
16697         if (ret_var.is_owned) {
16698                 ret_ref |= 1;
16699         }
16700         return ret_ref;
16701 }
16702
16703 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NodeAnnouncementInfo_1set_1features(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
16704         LDKNodeAnnouncementInfo this_ptr_conv;
16705         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16706         this_ptr_conv.is_owned = false;
16707         LDKNodeFeatures val_conv;
16708         val_conv.inner = (void*)(val & (~1));
16709         val_conv.is_owned = (val & 1) || (val == 0);
16710         // Warning: we may need a move here but can't clone!
16711         NodeAnnouncementInfo_set_features(&this_ptr_conv, val_conv);
16712 }
16713
16714 JNIEXPORT int32_t JNICALL Java_org_ldk_impl_bindings_NodeAnnouncementInfo_1get_1last_1update(JNIEnv *env, jclass clz, int64_t this_ptr) {
16715         LDKNodeAnnouncementInfo this_ptr_conv;
16716         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16717         this_ptr_conv.is_owned = false;
16718         int32_t ret_val = NodeAnnouncementInfo_get_last_update(&this_ptr_conv);
16719         return ret_val;
16720 }
16721
16722 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NodeAnnouncementInfo_1set_1last_1update(JNIEnv *env, jclass clz, int64_t this_ptr, int32_t val) {
16723         LDKNodeAnnouncementInfo this_ptr_conv;
16724         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16725         this_ptr_conv.is_owned = false;
16726         NodeAnnouncementInfo_set_last_update(&this_ptr_conv, val);
16727 }
16728
16729 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_NodeAnnouncementInfo_1get_1rgb(JNIEnv *env, jclass clz, int64_t this_ptr) {
16730         LDKNodeAnnouncementInfo this_ptr_conv;
16731         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16732         this_ptr_conv.is_owned = false;
16733         int8_tArray ret_arr = (*env)->NewByteArray(env, 3);
16734         (*env)->SetByteArrayRegion(env, ret_arr, 0, 3, *NodeAnnouncementInfo_get_rgb(&this_ptr_conv));
16735         return ret_arr;
16736 }
16737
16738 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NodeAnnouncementInfo_1set_1rgb(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
16739         LDKNodeAnnouncementInfo this_ptr_conv;
16740         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16741         this_ptr_conv.is_owned = false;
16742         LDKThreeBytes val_ref;
16743         CHECK((*env)->GetArrayLength(env, val) == 3);
16744         (*env)->GetByteArrayRegion(env, val, 0, 3, val_ref.data);
16745         NodeAnnouncementInfo_set_rgb(&this_ptr_conv, val_ref);
16746 }
16747
16748 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_NodeAnnouncementInfo_1get_1alias(JNIEnv *env, jclass clz, int64_t this_ptr) {
16749         LDKNodeAnnouncementInfo this_ptr_conv;
16750         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16751         this_ptr_conv.is_owned = false;
16752         int8_tArray ret_arr = (*env)->NewByteArray(env, 32);
16753         (*env)->SetByteArrayRegion(env, ret_arr, 0, 32, *NodeAnnouncementInfo_get_alias(&this_ptr_conv));
16754         return ret_arr;
16755 }
16756
16757 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NodeAnnouncementInfo_1set_1alias(JNIEnv *env, jclass clz, int64_t this_ptr, int8_tArray val) {
16758         LDKNodeAnnouncementInfo this_ptr_conv;
16759         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16760         this_ptr_conv.is_owned = false;
16761         LDKThirtyTwoBytes val_ref;
16762         CHECK((*env)->GetArrayLength(env, val) == 32);
16763         (*env)->GetByteArrayRegion(env, val, 0, 32, val_ref.data);
16764         NodeAnnouncementInfo_set_alias(&this_ptr_conv, val_ref);
16765 }
16766
16767 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NodeAnnouncementInfo_1set_1addresses(JNIEnv *env, jclass clz, int64_t this_ptr, int64_tArray val) {
16768         LDKNodeAnnouncementInfo this_ptr_conv;
16769         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16770         this_ptr_conv.is_owned = false;
16771         LDKCVec_NetAddressZ val_constr;
16772         val_constr.datalen = (*env)->GetArrayLength(env, val);
16773         if (val_constr.datalen > 0)
16774                 val_constr.data = MALLOC(val_constr.datalen * sizeof(LDKNetAddress), "LDKCVec_NetAddressZ Elements");
16775         else
16776                 val_constr.data = NULL;
16777         int64_t* val_vals = (*env)->GetLongArrayElements (env, val, NULL);
16778         for (size_t m = 0; m < val_constr.datalen; m++) {
16779                 int64_t arr_conv_12 = val_vals[m];
16780                 LDKNetAddress arr_conv_12_conv = *(LDKNetAddress*)arr_conv_12;
16781                 FREE((void*)arr_conv_12);
16782                 val_constr.data[m] = arr_conv_12_conv;
16783         }
16784         (*env)->ReleaseLongArrayElements(env, val, val_vals, 0);
16785         NodeAnnouncementInfo_set_addresses(&this_ptr_conv, val_constr);
16786 }
16787
16788 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_NodeAnnouncementInfo_1get_1announcement_1message(JNIEnv *env, jclass clz, int64_t this_ptr) {
16789         LDKNodeAnnouncementInfo this_ptr_conv;
16790         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16791         this_ptr_conv.is_owned = false;
16792         LDKNodeAnnouncement ret_var = NodeAnnouncementInfo_get_announcement_message(&this_ptr_conv);
16793         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
16794         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
16795         long ret_ref = (long)ret_var.inner;
16796         if (ret_var.is_owned) {
16797                 ret_ref |= 1;
16798         }
16799         return ret_ref;
16800 }
16801
16802 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NodeAnnouncementInfo_1set_1announcement_1message(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
16803         LDKNodeAnnouncementInfo this_ptr_conv;
16804         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16805         this_ptr_conv.is_owned = false;
16806         LDKNodeAnnouncement val_conv;
16807         val_conv.inner = (void*)(val & (~1));
16808         val_conv.is_owned = (val & 1) || (val == 0);
16809         if (val_conv.inner != NULL)
16810                 val_conv = NodeAnnouncement_clone(&val_conv);
16811         NodeAnnouncementInfo_set_announcement_message(&this_ptr_conv, val_conv);
16812 }
16813
16814 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) {
16815         LDKNodeFeatures features_arg_conv;
16816         features_arg_conv.inner = (void*)(features_arg & (~1));
16817         features_arg_conv.is_owned = (features_arg & 1) || (features_arg == 0);
16818         // Warning: we may need a move here but can't clone!
16819         LDKThreeBytes rgb_arg_ref;
16820         CHECK((*env)->GetArrayLength(env, rgb_arg) == 3);
16821         (*env)->GetByteArrayRegion(env, rgb_arg, 0, 3, rgb_arg_ref.data);
16822         LDKThirtyTwoBytes alias_arg_ref;
16823         CHECK((*env)->GetArrayLength(env, alias_arg) == 32);
16824         (*env)->GetByteArrayRegion(env, alias_arg, 0, 32, alias_arg_ref.data);
16825         LDKCVec_NetAddressZ addresses_arg_constr;
16826         addresses_arg_constr.datalen = (*env)->GetArrayLength(env, addresses_arg);
16827         if (addresses_arg_constr.datalen > 0)
16828                 addresses_arg_constr.data = MALLOC(addresses_arg_constr.datalen * sizeof(LDKNetAddress), "LDKCVec_NetAddressZ Elements");
16829         else
16830                 addresses_arg_constr.data = NULL;
16831         int64_t* addresses_arg_vals = (*env)->GetLongArrayElements (env, addresses_arg, NULL);
16832         for (size_t m = 0; m < addresses_arg_constr.datalen; m++) {
16833                 int64_t arr_conv_12 = addresses_arg_vals[m];
16834                 LDKNetAddress arr_conv_12_conv = *(LDKNetAddress*)arr_conv_12;
16835                 FREE((void*)arr_conv_12);
16836                 addresses_arg_constr.data[m] = arr_conv_12_conv;
16837         }
16838         (*env)->ReleaseLongArrayElements(env, addresses_arg, addresses_arg_vals, 0);
16839         LDKNodeAnnouncement announcement_message_arg_conv;
16840         announcement_message_arg_conv.inner = (void*)(announcement_message_arg & (~1));
16841         announcement_message_arg_conv.is_owned = (announcement_message_arg & 1) || (announcement_message_arg == 0);
16842         if (announcement_message_arg_conv.inner != NULL)
16843                 announcement_message_arg_conv = NodeAnnouncement_clone(&announcement_message_arg_conv);
16844         LDKNodeAnnouncementInfo ret_var = NodeAnnouncementInfo_new(features_arg_conv, last_update_arg, rgb_arg_ref, alias_arg_ref, addresses_arg_constr, announcement_message_arg_conv);
16845         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
16846         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
16847         long ret_ref = (long)ret_var.inner;
16848         if (ret_var.is_owned) {
16849                 ret_ref |= 1;
16850         }
16851         return ret_ref;
16852 }
16853
16854 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_NodeAnnouncementInfo_1write(JNIEnv *env, jclass clz, int64_t obj) {
16855         LDKNodeAnnouncementInfo obj_conv;
16856         obj_conv.inner = (void*)(obj & (~1));
16857         obj_conv.is_owned = false;
16858         LDKCVec_u8Z arg_var = NodeAnnouncementInfo_write(&obj_conv);
16859         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
16860         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
16861         CVec_u8Z_free(arg_var);
16862         return arg_arr;
16863 }
16864
16865 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_NodeAnnouncementInfo_1read(JNIEnv *env, jclass clz, int8_tArray ser) {
16866         LDKu8slice ser_ref;
16867         ser_ref.datalen = (*env)->GetArrayLength(env, ser);
16868         ser_ref.data = (*env)->GetByteArrayElements (env, ser, NULL);
16869         LDKCResult_NodeAnnouncementInfoDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NodeAnnouncementInfoDecodeErrorZ), "LDKCResult_NodeAnnouncementInfoDecodeErrorZ");
16870         *ret_conv = NodeAnnouncementInfo_read(ser_ref);
16871         (*env)->ReleaseByteArrayElements(env, ser, (int8_t*)ser_ref.data, 0);
16872         return (long)ret_conv;
16873 }
16874
16875 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NodeInfo_1free(JNIEnv *env, jclass clz, int64_t this_ptr) {
16876         LDKNodeInfo this_ptr_conv;
16877         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16878         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
16879         NodeInfo_free(this_ptr_conv);
16880 }
16881
16882 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NodeInfo_1set_1channels(JNIEnv *env, jclass clz, int64_t this_ptr, int64_tArray val) {
16883         LDKNodeInfo this_ptr_conv;
16884         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16885         this_ptr_conv.is_owned = false;
16886         LDKCVec_u64Z val_constr;
16887         val_constr.datalen = (*env)->GetArrayLength(env, val);
16888         if (val_constr.datalen > 0)
16889                 val_constr.data = MALLOC(val_constr.datalen * sizeof(int64_t), "LDKCVec_u64Z Elements");
16890         else
16891                 val_constr.data = NULL;
16892         int64_t* val_vals = (*env)->GetLongArrayElements (env, val, NULL);
16893         for (size_t g = 0; g < val_constr.datalen; g++) {
16894                 int64_t arr_conv_6 = val_vals[g];
16895                 val_constr.data[g] = arr_conv_6;
16896         }
16897         (*env)->ReleaseLongArrayElements(env, val, val_vals, 0);
16898         NodeInfo_set_channels(&this_ptr_conv, val_constr);
16899 }
16900
16901 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_NodeInfo_1get_1lowest_1inbound_1channel_1fees(JNIEnv *env, jclass clz, int64_t this_ptr) {
16902         LDKNodeInfo this_ptr_conv;
16903         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16904         this_ptr_conv.is_owned = false;
16905         LDKRoutingFees ret_var = NodeInfo_get_lowest_inbound_channel_fees(&this_ptr_conv);
16906         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
16907         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
16908         long ret_ref = (long)ret_var.inner;
16909         if (ret_var.is_owned) {
16910                 ret_ref |= 1;
16911         }
16912         return ret_ref;
16913 }
16914
16915 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) {
16916         LDKNodeInfo this_ptr_conv;
16917         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16918         this_ptr_conv.is_owned = false;
16919         LDKRoutingFees val_conv;
16920         val_conv.inner = (void*)(val & (~1));
16921         val_conv.is_owned = (val & 1) || (val == 0);
16922         if (val_conv.inner != NULL)
16923                 val_conv = RoutingFees_clone(&val_conv);
16924         NodeInfo_set_lowest_inbound_channel_fees(&this_ptr_conv, val_conv);
16925 }
16926
16927 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_NodeInfo_1get_1announcement_1info(JNIEnv *env, jclass clz, int64_t this_ptr) {
16928         LDKNodeInfo this_ptr_conv;
16929         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16930         this_ptr_conv.is_owned = false;
16931         LDKNodeAnnouncementInfo ret_var = NodeInfo_get_announcement_info(&this_ptr_conv);
16932         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
16933         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
16934         long ret_ref = (long)ret_var.inner;
16935         if (ret_var.is_owned) {
16936                 ret_ref |= 1;
16937         }
16938         return ret_ref;
16939 }
16940
16941 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NodeInfo_1set_1announcement_1info(JNIEnv *env, jclass clz, int64_t this_ptr, int64_t val) {
16942         LDKNodeInfo this_ptr_conv;
16943         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16944         this_ptr_conv.is_owned = false;
16945         LDKNodeAnnouncementInfo val_conv;
16946         val_conv.inner = (void*)(val & (~1));
16947         val_conv.is_owned = (val & 1) || (val == 0);
16948         // Warning: we may need a move here but can't clone!
16949         NodeInfo_set_announcement_info(&this_ptr_conv, val_conv);
16950 }
16951
16952 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) {
16953         LDKCVec_u64Z channels_arg_constr;
16954         channels_arg_constr.datalen = (*env)->GetArrayLength(env, channels_arg);
16955         if (channels_arg_constr.datalen > 0)
16956                 channels_arg_constr.data = MALLOC(channels_arg_constr.datalen * sizeof(int64_t), "LDKCVec_u64Z Elements");
16957         else
16958                 channels_arg_constr.data = NULL;
16959         int64_t* channels_arg_vals = (*env)->GetLongArrayElements (env, channels_arg, NULL);
16960         for (size_t g = 0; g < channels_arg_constr.datalen; g++) {
16961                 int64_t arr_conv_6 = channels_arg_vals[g];
16962                 channels_arg_constr.data[g] = arr_conv_6;
16963         }
16964         (*env)->ReleaseLongArrayElements(env, channels_arg, channels_arg_vals, 0);
16965         LDKRoutingFees lowest_inbound_channel_fees_arg_conv;
16966         lowest_inbound_channel_fees_arg_conv.inner = (void*)(lowest_inbound_channel_fees_arg & (~1));
16967         lowest_inbound_channel_fees_arg_conv.is_owned = (lowest_inbound_channel_fees_arg & 1) || (lowest_inbound_channel_fees_arg == 0);
16968         if (lowest_inbound_channel_fees_arg_conv.inner != NULL)
16969                 lowest_inbound_channel_fees_arg_conv = RoutingFees_clone(&lowest_inbound_channel_fees_arg_conv);
16970         LDKNodeAnnouncementInfo announcement_info_arg_conv;
16971         announcement_info_arg_conv.inner = (void*)(announcement_info_arg & (~1));
16972         announcement_info_arg_conv.is_owned = (announcement_info_arg & 1) || (announcement_info_arg == 0);
16973         // Warning: we may need a move here but can't clone!
16974         LDKNodeInfo ret_var = NodeInfo_new(channels_arg_constr, lowest_inbound_channel_fees_arg_conv, announcement_info_arg_conv);
16975         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
16976         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
16977         long ret_ref = (long)ret_var.inner;
16978         if (ret_var.is_owned) {
16979                 ret_ref |= 1;
16980         }
16981         return ret_ref;
16982 }
16983
16984 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_NodeInfo_1write(JNIEnv *env, jclass clz, int64_t obj) {
16985         LDKNodeInfo obj_conv;
16986         obj_conv.inner = (void*)(obj & (~1));
16987         obj_conv.is_owned = false;
16988         LDKCVec_u8Z arg_var = NodeInfo_write(&obj_conv);
16989         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
16990         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
16991         CVec_u8Z_free(arg_var);
16992         return arg_arr;
16993 }
16994
16995 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_NodeInfo_1read(JNIEnv *env, jclass clz, int8_tArray ser) {
16996         LDKu8slice ser_ref;
16997         ser_ref.datalen = (*env)->GetArrayLength(env, ser);
16998         ser_ref.data = (*env)->GetByteArrayElements (env, ser, NULL);
16999         LDKCResult_NodeInfoDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NodeInfoDecodeErrorZ), "LDKCResult_NodeInfoDecodeErrorZ");
17000         *ret_conv = NodeInfo_read(ser_ref);
17001         (*env)->ReleaseByteArrayElements(env, ser, (int8_t*)ser_ref.data, 0);
17002         return (long)ret_conv;
17003 }
17004
17005 JNIEXPORT int8_tArray JNICALL Java_org_ldk_impl_bindings_NetworkGraph_1write(JNIEnv *env, jclass clz, int64_t obj) {
17006         LDKNetworkGraph obj_conv;
17007         obj_conv.inner = (void*)(obj & (~1));
17008         obj_conv.is_owned = false;
17009         LDKCVec_u8Z arg_var = NetworkGraph_write(&obj_conv);
17010         int8_tArray arg_arr = (*env)->NewByteArray(env, arg_var.datalen);
17011         (*env)->SetByteArrayRegion(env, arg_arr, 0, arg_var.datalen, arg_var.data);
17012         CVec_u8Z_free(arg_var);
17013         return arg_arr;
17014 }
17015
17016 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_NetworkGraph_1read(JNIEnv *env, jclass clz, int8_tArray ser) {
17017         LDKu8slice ser_ref;
17018         ser_ref.datalen = (*env)->GetArrayLength(env, ser);
17019         ser_ref.data = (*env)->GetByteArrayElements (env, ser, NULL);
17020         LDKCResult_NetworkGraphDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NetworkGraphDecodeErrorZ), "LDKCResult_NetworkGraphDecodeErrorZ");
17021         *ret_conv = NetworkGraph_read(ser_ref);
17022         (*env)->ReleaseByteArrayElements(env, ser, (int8_t*)ser_ref.data, 0);
17023         return (long)ret_conv;
17024 }
17025
17026 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_NetworkGraph_1new(JNIEnv *env, jclass clz, int8_tArray genesis_hash) {
17027         LDKThirtyTwoBytes genesis_hash_ref;
17028         CHECK((*env)->GetArrayLength(env, genesis_hash) == 32);
17029         (*env)->GetByteArrayRegion(env, genesis_hash, 0, 32, genesis_hash_ref.data);
17030         LDKNetworkGraph ret_var = NetworkGraph_new(genesis_hash_ref);
17031         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
17032         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
17033         long ret_ref = (long)ret_var.inner;
17034         if (ret_var.is_owned) {
17035                 ret_ref |= 1;
17036         }
17037         return ret_ref;
17038 }
17039
17040 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) {
17041         LDKNetworkGraph this_arg_conv;
17042         this_arg_conv.inner = (void*)(this_arg & (~1));
17043         this_arg_conv.is_owned = false;
17044         LDKNodeAnnouncement msg_conv;
17045         msg_conv.inner = (void*)(msg & (~1));
17046         msg_conv.is_owned = false;
17047         LDKCResult_NoneLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneLightningErrorZ), "LDKCResult_NoneLightningErrorZ");
17048         *ret_conv = NetworkGraph_update_node_from_announcement(&this_arg_conv, &msg_conv);
17049         return (long)ret_conv;
17050 }
17051
17052 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) {
17053         LDKNetworkGraph this_arg_conv;
17054         this_arg_conv.inner = (void*)(this_arg & (~1));
17055         this_arg_conv.is_owned = false;
17056         LDKUnsignedNodeAnnouncement msg_conv;
17057         msg_conv.inner = (void*)(msg & (~1));
17058         msg_conv.is_owned = false;
17059         LDKCResult_NoneLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneLightningErrorZ), "LDKCResult_NoneLightningErrorZ");
17060         *ret_conv = NetworkGraph_update_node_from_unsigned_announcement(&this_arg_conv, &msg_conv);
17061         return (long)ret_conv;
17062 }
17063
17064 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) {
17065         LDKNetworkGraph this_arg_conv;
17066         this_arg_conv.inner = (void*)(this_arg & (~1));
17067         this_arg_conv.is_owned = false;
17068         LDKChannelAnnouncement msg_conv;
17069         msg_conv.inner = (void*)(msg & (~1));
17070         msg_conv.is_owned = false;
17071         LDKAccess* chain_access_conv = (LDKAccess*)chain_access;
17072         LDKCResult_NoneLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneLightningErrorZ), "LDKCResult_NoneLightningErrorZ");
17073         *ret_conv = NetworkGraph_update_channel_from_announcement(&this_arg_conv, &msg_conv, chain_access_conv);
17074         return (long)ret_conv;
17075 }
17076
17077 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) {
17078         LDKNetworkGraph this_arg_conv;
17079         this_arg_conv.inner = (void*)(this_arg & (~1));
17080         this_arg_conv.is_owned = false;
17081         LDKUnsignedChannelAnnouncement msg_conv;
17082         msg_conv.inner = (void*)(msg & (~1));
17083         msg_conv.is_owned = false;
17084         LDKAccess* chain_access_conv = (LDKAccess*)chain_access;
17085         LDKCResult_NoneLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneLightningErrorZ), "LDKCResult_NoneLightningErrorZ");
17086         *ret_conv = NetworkGraph_update_channel_from_unsigned_announcement(&this_arg_conv, &msg_conv, chain_access_conv);
17087         return (long)ret_conv;
17088 }
17089
17090 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) {
17091         LDKNetworkGraph this_arg_conv;
17092         this_arg_conv.inner = (void*)(this_arg & (~1));
17093         this_arg_conv.is_owned = false;
17094         NetworkGraph_close_channel_from_update(&this_arg_conv, short_channel_id, is_permanent);
17095 }
17096
17097 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_NetworkGraph_1update_1channel(JNIEnv *env, jclass clz, int64_t this_arg, int64_t msg) {
17098         LDKNetworkGraph this_arg_conv;
17099         this_arg_conv.inner = (void*)(this_arg & (~1));
17100         this_arg_conv.is_owned = false;
17101         LDKChannelUpdate msg_conv;
17102         msg_conv.inner = (void*)(msg & (~1));
17103         msg_conv.is_owned = false;
17104         LDKCResult_NoneLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneLightningErrorZ), "LDKCResult_NoneLightningErrorZ");
17105         *ret_conv = NetworkGraph_update_channel(&this_arg_conv, &msg_conv);
17106         return (long)ret_conv;
17107 }
17108
17109 JNIEXPORT int64_t JNICALL Java_org_ldk_impl_bindings_NetworkGraph_1update_1channel_1unsigned(JNIEnv *env, jclass clz, int64_t this_arg, int64_t msg) {
17110         LDKNetworkGraph this_arg_conv;
17111         this_arg_conv.inner = (void*)(this_arg & (~1));
17112         this_arg_conv.is_owned = false;
17113         LDKUnsignedChannelUpdate msg_conv;
17114         msg_conv.inner = (void*)(msg & (~1));
17115         msg_conv.is_owned = false;
17116         LDKCResult_NoneLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneLightningErrorZ), "LDKCResult_NoneLightningErrorZ");
17117         *ret_conv = NetworkGraph_update_channel_unsigned(&this_arg_conv, &msg_conv);
17118         return (long)ret_conv;
17119 }
17120