updated bindings
[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 <assert.h>
7 // Always run a, then assert it is true:
8 #define DO_ASSERT(a) do { bool _assert_val = (a); assert(_assert_val); } while(0)
9 // Assert a is true or do nothing
10 #define CHECK(a) DO_ASSERT(a)
11
12 // Running a leak check across all the allocations and frees of the JDK is a mess,
13 // so instead we implement our own naive leak checker here, relying on the -wrap
14 // linker option to wrap malloc/calloc/realloc/free, tracking everyhing allocated
15 // and free'd in Rust or C across the generated bindings shared library.
16 #include <threads.h>
17 #include <execinfo.h>
18 #include <unistd.h>
19 static mtx_t allocation_mtx;
20
21 void __attribute__((constructor)) init_mtx() {
22         DO_ASSERT(mtx_init(&allocation_mtx, mtx_plain) == thrd_success);
23 }
24
25 #define BT_MAX 128
26 typedef struct allocation {
27         struct allocation* next;
28         void* ptr;
29         const char* struct_name;
30         void* bt[BT_MAX];
31         int bt_len;
32 } allocation;
33 static allocation* allocation_ll = NULL;
34
35 void* __real_malloc(size_t len);
36 void* __real_calloc(size_t nmemb, size_t len);
37 static void new_allocation(void* res, const char* struct_name) {
38         allocation* new_alloc = __real_malloc(sizeof(allocation));
39         new_alloc->ptr = res;
40         new_alloc->struct_name = struct_name;
41         new_alloc->bt_len = backtrace(new_alloc->bt, BT_MAX);
42         DO_ASSERT(mtx_lock(&allocation_mtx) == thrd_success);
43         new_alloc->next = allocation_ll;
44         allocation_ll = new_alloc;
45         DO_ASSERT(mtx_unlock(&allocation_mtx) == thrd_success);
46 }
47 static void* MALLOC(size_t len, const char* struct_name) {
48         void* res = __real_malloc(len);
49         new_allocation(res, struct_name);
50         return res;
51 }
52 void __real_free(void* ptr);
53 static void alloc_freed(void* ptr) {
54         allocation* p = NULL;
55         DO_ASSERT(mtx_lock(&allocation_mtx) == thrd_success);
56         allocation* it = allocation_ll;
57         while (it->ptr != ptr) {
58                 p = it; it = it->next;
59                 if (it == NULL) {
60                         fprintf(stderr, "Tried to free unknown pointer %p at:\n", ptr);
61                         void* bt[BT_MAX];
62                         int bt_len = backtrace(bt, BT_MAX);
63                         backtrace_symbols_fd(bt, bt_len, STDERR_FILENO);
64                         fprintf(stderr, "\n\n");
65                         DO_ASSERT(mtx_unlock(&allocation_mtx) == thrd_success);
66                         return; // addrsan should catch malloc-unknown and print more info than we have
67                 }
68         }
69         if (p) { p->next = it->next; } else { allocation_ll = it->next; }
70         DO_ASSERT(mtx_unlock(&allocation_mtx) == thrd_success);
71         DO_ASSERT(it->ptr == ptr);
72         __real_free(it);
73 }
74 static void FREE(void* ptr) {
75         if ((long)ptr < 1024) return; // Rust loves to create pointers to the NULL page for dummys
76         alloc_freed(ptr);
77         __real_free(ptr);
78 }
79
80 void* __wrap_malloc(size_t len) {
81         void* res = __real_malloc(len);
82         new_allocation(res, "malloc call");
83         return res;
84 }
85 void* __wrap_calloc(size_t nmemb, size_t len) {
86         void* res = __real_calloc(nmemb, len);
87         new_allocation(res, "calloc call");
88         return res;
89 }
90 void __wrap_free(void* ptr) {
91         if (ptr == NULL) return;
92         alloc_freed(ptr);
93         __real_free(ptr);
94 }
95
96 void* __real_realloc(void* ptr, size_t newlen);
97 void* __wrap_realloc(void* ptr, size_t len) {
98         if (ptr != NULL) alloc_freed(ptr);
99         void* res = __real_realloc(ptr, len);
100         new_allocation(res, "realloc call");
101         return res;
102 }
103 void __wrap_reallocarray(void* ptr, size_t new_sz) {
104         // Rust doesn't seem to use reallocarray currently
105         assert(false);
106 }
107
108 void __attribute__((destructor)) check_leaks() {
109         for (allocation* a = allocation_ll; a != NULL; a = a->next) {
110                 fprintf(stderr, "%s %p remains:\n", a->struct_name, a->ptr);
111                 backtrace_symbols_fd(a->bt, a->bt_len, STDERR_FILENO);
112                 fprintf(stderr, "\n\n");
113         }
114         DO_ASSERT(allocation_ll == NULL);
115 }
116 static jclass arr_of_B_clz = NULL;
117 JNIEXPORT void Java_org_ldk_impl_bindings_init_1class_1cache(JNIEnv * env, jclass _b) {
118         arr_of_B_clz = (*env)->FindClass(env, "[B");
119         CHECK(arr_of_B_clz != NULL);
120         arr_of_B_clz = (*env)->NewGlobalRef(env, arr_of_B_clz);
121 }
122 static inline struct LDKThirtyTwoBytes ThirtyTwoBytes_clone(const struct LDKThirtyTwoBytes *orig) { struct LDKThirtyTwoBytes ret; memcpy(ret.data, orig->data, 32); return ret; }
123
124 static jmethodID ordinal_meth = NULL;
125 static jmethodID slicedef_meth = NULL;
126 static jclass slicedef_cls = NULL;
127 JNIEXPORT void Java_org_ldk_impl_bindings_init(JNIEnv * env, jclass _b, jclass enum_class, jclass slicedef_class) {
128         ordinal_meth = (*env)->GetMethodID(env, enum_class, "ordinal", "()I");
129         CHECK(ordinal_meth != NULL);
130         slicedef_meth = (*env)->GetMethodID(env, slicedef_class, "<init>", "(JJJ)V");
131         CHECK(slicedef_meth != NULL);
132         slicedef_cls = (*env)->NewGlobalRef(env, slicedef_class);
133         CHECK(slicedef_cls != NULL);
134 }
135
136 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_deref_1bool (JNIEnv * env, jclass _a, jlong ptr) {
137         return *((bool*)ptr);
138 }
139 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_deref_1long (JNIEnv * env, jclass _a, jlong ptr) {
140         return *((long*)ptr);
141 }
142 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_free_1heap_1ptr (JNIEnv * env, jclass _a, jlong ptr) {
143         FREE((void*)ptr);
144 }
145 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_read_1bytes (JNIEnv * _env, jclass _b, jlong ptr, jlong len) {
146         jbyteArray ret_arr = (*_env)->NewByteArray(_env, len);
147         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, len, (unsigned char*)ptr);
148         return ret_arr;
149 }
150 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_get_1u8_1slice_1bytes (JNIEnv * _env, jclass _b, jlong slice_ptr) {
151         LDKu8slice *slice = (LDKu8slice*)slice_ptr;
152         jbyteArray ret_arr = (*_env)->NewByteArray(_env, slice->datalen);
153         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, slice->datalen, slice->data);
154         return ret_arr;
155 }
156 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_bytes_1to_1u8_1vec (JNIEnv * _env, jclass _b, jbyteArray bytes) {
157         LDKCVec_u8Z *vec = (LDKCVec_u8Z*)MALLOC(sizeof(LDKCVec_u8Z), "LDKCVec_u8");
158         vec->datalen = (*_env)->GetArrayLength(_env, bytes);
159         vec->data = (uint8_t*)MALLOC(vec->datalen, "LDKCVec_u8Z Bytes");
160         (*_env)->GetByteArrayRegion (_env, bytes, 0, vec->datalen, vec->data);
161         return (long)vec;
162 }
163 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_txpointer_1get_1buffer (JNIEnv * env, jclass _b, jlong ptr) {
164         LDKTransaction *txdata = (LDKTransaction*)ptr;
165         LDKu8slice slice;
166         slice.data = txdata->data;
167         slice.datalen = txdata->datalen;
168         return Java_org_ldk_impl_bindings_get_1u8_1slice_1bytes(env, _b, (long)&slice);
169 }
170 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_new_1txpointer_1copy_1data (JNIEnv * env, jclass _b, jbyteArray bytes) {
171         LDKTransaction *txdata = (LDKTransaction*)MALLOC(sizeof(LDKTransaction), "LDKTransaction");
172         txdata->datalen = (*env)->GetArrayLength(env, bytes);
173         txdata->data = (uint8_t*)MALLOC(txdata->datalen, "Tx Data Bytes");
174         txdata->data_is_owned = false;
175         (*env)->GetByteArrayRegion (env, bytes, 0, txdata->datalen, txdata->data);
176         return (long)txdata;
177 }
178 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_txpointer_1free (JNIEnv * env, jclass _b, jlong ptr) {
179         LDKTransaction *tx = (LDKTransaction*)ptr;
180         tx->data_is_owned = true;
181         Transaction_free(*tx);
182         FREE((void*)ptr);
183 }
184 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_vec_1slice_1len (JNIEnv * env, jclass _a, jlong ptr) {
185         // Check offsets of a few Vec types are all consistent as we're meant to be generic across types
186         _Static_assert(offsetof(LDKCVec_u8Z, datalen) == offsetof(LDKCVec_SignatureZ, datalen), "Vec<*> needs to be mapped identically");
187         _Static_assert(offsetof(LDKCVec_u8Z, datalen) == offsetof(LDKCVec_MessageSendEventZ, datalen), "Vec<*> needs to be mapped identically");
188         _Static_assert(offsetof(LDKCVec_u8Z, datalen) == offsetof(LDKCVec_EventZ, datalen), "Vec<*> needs to be mapped identically");
189         _Static_assert(offsetof(LDKCVec_u8Z, datalen) == offsetof(LDKCVec_C2Tuple_usizeTransactionZZ, datalen), "Vec<*> needs to be mapped identically");
190         LDKCVec_u8Z *vec = (LDKCVec_u8Z*)ptr;
191         return (long)vec->datalen;
192 }
193 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_new_1empty_1slice_1vec (JNIEnv * _env, jclass _b) {
194         // Check sizes of a few Vec types are all consistent as we're meant to be generic across types
195         _Static_assert(sizeof(LDKCVec_u8Z) == sizeof(LDKCVec_SignatureZ), "Vec<*> needs to be mapped identically");
196         _Static_assert(sizeof(LDKCVec_u8Z) == sizeof(LDKCVec_MessageSendEventZ), "Vec<*> needs to be mapped identically");
197         _Static_assert(sizeof(LDKCVec_u8Z) == sizeof(LDKCVec_EventZ), "Vec<*> needs to be mapped identically");
198         _Static_assert(sizeof(LDKCVec_u8Z) == sizeof(LDKCVec_C2Tuple_usizeTransactionZZ), "Vec<*> needs to be mapped identically");
199         LDKCVec_u8Z *vec = (LDKCVec_u8Z*)MALLOC(sizeof(LDKCVec_u8Z), "Empty LDKCVec");
200         vec->data = NULL;
201         vec->datalen = 0;
202         return (long)vec;
203 }
204
205 // We assume that CVec_u8Z and u8slice are the same size and layout (and thus pointers to the two can be mixed)
206 _Static_assert(sizeof(LDKCVec_u8Z) == sizeof(LDKu8slice), "Vec<u8> and [u8] need to have been mapped identically");
207 _Static_assert(offsetof(LDKCVec_u8Z, data) == offsetof(LDKu8slice, data), "Vec<u8> and [u8] need to have been mapped identically");
208 _Static_assert(offsetof(LDKCVec_u8Z, datalen) == offsetof(LDKu8slice, datalen), "Vec<u8> and [u8] need to have been mapped identically");
209
210 static inline LDKAccessError LDKAccessError_from_java(JNIEnv *env, jclass val) {
211         switch ((*env)->CallIntMethod(env, val, ordinal_meth)) {
212                 case 0: return LDKAccessError_UnknownChain;
213                 case 1: return LDKAccessError_UnknownTx;
214         }
215         abort();
216 }
217 static jclass LDKAccessError_class = NULL;
218 static jfieldID LDKAccessError_LDKAccessError_UnknownChain = NULL;
219 static jfieldID LDKAccessError_LDKAccessError_UnknownTx = NULL;
220 JNIEXPORT void JNICALL Java_org_ldk_enums_LDKAccessError_init (JNIEnv * env, jclass clz) {
221         LDKAccessError_class = (*env)->NewGlobalRef(env, clz);
222         CHECK(LDKAccessError_class != NULL);
223         LDKAccessError_LDKAccessError_UnknownChain = (*env)->GetStaticFieldID(env, LDKAccessError_class, "LDKAccessError_UnknownChain", "Lorg/ldk/enums/LDKAccessError;");
224         CHECK(LDKAccessError_LDKAccessError_UnknownChain != NULL);
225         LDKAccessError_LDKAccessError_UnknownTx = (*env)->GetStaticFieldID(env, LDKAccessError_class, "LDKAccessError_UnknownTx", "Lorg/ldk/enums/LDKAccessError;");
226         CHECK(LDKAccessError_LDKAccessError_UnknownTx != NULL);
227 }
228 static inline jclass LDKAccessError_to_java(JNIEnv *env, LDKAccessError val) {
229         switch (val) {
230                 case LDKAccessError_UnknownChain:
231                         return (*env)->GetStaticObjectField(env, LDKAccessError_class, LDKAccessError_LDKAccessError_UnknownChain);
232                 case LDKAccessError_UnknownTx:
233                         return (*env)->GetStaticObjectField(env, LDKAccessError_class, LDKAccessError_LDKAccessError_UnknownTx);
234                 default: abort();
235         }
236 }
237
238 static inline LDKChannelMonitorUpdateErr LDKChannelMonitorUpdateErr_from_java(JNIEnv *env, jclass val) {
239         switch ((*env)->CallIntMethod(env, val, ordinal_meth)) {
240                 case 0: return LDKChannelMonitorUpdateErr_TemporaryFailure;
241                 case 1: return LDKChannelMonitorUpdateErr_PermanentFailure;
242         }
243         abort();
244 }
245 static jclass LDKChannelMonitorUpdateErr_class = NULL;
246 static jfieldID LDKChannelMonitorUpdateErr_LDKChannelMonitorUpdateErr_TemporaryFailure = NULL;
247 static jfieldID LDKChannelMonitorUpdateErr_LDKChannelMonitorUpdateErr_PermanentFailure = NULL;
248 JNIEXPORT void JNICALL Java_org_ldk_enums_LDKChannelMonitorUpdateErr_init (JNIEnv * env, jclass clz) {
249         LDKChannelMonitorUpdateErr_class = (*env)->NewGlobalRef(env, clz);
250         CHECK(LDKChannelMonitorUpdateErr_class != NULL);
251         LDKChannelMonitorUpdateErr_LDKChannelMonitorUpdateErr_TemporaryFailure = (*env)->GetStaticFieldID(env, LDKChannelMonitorUpdateErr_class, "LDKChannelMonitorUpdateErr_TemporaryFailure", "Lorg/ldk/enums/LDKChannelMonitorUpdateErr;");
252         CHECK(LDKChannelMonitorUpdateErr_LDKChannelMonitorUpdateErr_TemporaryFailure != NULL);
253         LDKChannelMonitorUpdateErr_LDKChannelMonitorUpdateErr_PermanentFailure = (*env)->GetStaticFieldID(env, LDKChannelMonitorUpdateErr_class, "LDKChannelMonitorUpdateErr_PermanentFailure", "Lorg/ldk/enums/LDKChannelMonitorUpdateErr;");
254         CHECK(LDKChannelMonitorUpdateErr_LDKChannelMonitorUpdateErr_PermanentFailure != NULL);
255 }
256 static inline jclass LDKChannelMonitorUpdateErr_to_java(JNIEnv *env, LDKChannelMonitorUpdateErr val) {
257         switch (val) {
258                 case LDKChannelMonitorUpdateErr_TemporaryFailure:
259                         return (*env)->GetStaticObjectField(env, LDKChannelMonitorUpdateErr_class, LDKChannelMonitorUpdateErr_LDKChannelMonitorUpdateErr_TemporaryFailure);
260                 case LDKChannelMonitorUpdateErr_PermanentFailure:
261                         return (*env)->GetStaticObjectField(env, LDKChannelMonitorUpdateErr_class, LDKChannelMonitorUpdateErr_LDKChannelMonitorUpdateErr_PermanentFailure);
262                 default: abort();
263         }
264 }
265
266 static inline LDKConfirmationTarget LDKConfirmationTarget_from_java(JNIEnv *env, jclass val) {
267         switch ((*env)->CallIntMethod(env, val, ordinal_meth)) {
268                 case 0: return LDKConfirmationTarget_Background;
269                 case 1: return LDKConfirmationTarget_Normal;
270                 case 2: return LDKConfirmationTarget_HighPriority;
271         }
272         abort();
273 }
274 static jclass LDKConfirmationTarget_class = NULL;
275 static jfieldID LDKConfirmationTarget_LDKConfirmationTarget_Background = NULL;
276 static jfieldID LDKConfirmationTarget_LDKConfirmationTarget_Normal = NULL;
277 static jfieldID LDKConfirmationTarget_LDKConfirmationTarget_HighPriority = NULL;
278 JNIEXPORT void JNICALL Java_org_ldk_enums_LDKConfirmationTarget_init (JNIEnv * env, jclass clz) {
279         LDKConfirmationTarget_class = (*env)->NewGlobalRef(env, clz);
280         CHECK(LDKConfirmationTarget_class != NULL);
281         LDKConfirmationTarget_LDKConfirmationTarget_Background = (*env)->GetStaticFieldID(env, LDKConfirmationTarget_class, "LDKConfirmationTarget_Background", "Lorg/ldk/enums/LDKConfirmationTarget;");
282         CHECK(LDKConfirmationTarget_LDKConfirmationTarget_Background != NULL);
283         LDKConfirmationTarget_LDKConfirmationTarget_Normal = (*env)->GetStaticFieldID(env, LDKConfirmationTarget_class, "LDKConfirmationTarget_Normal", "Lorg/ldk/enums/LDKConfirmationTarget;");
284         CHECK(LDKConfirmationTarget_LDKConfirmationTarget_Normal != NULL);
285         LDKConfirmationTarget_LDKConfirmationTarget_HighPriority = (*env)->GetStaticFieldID(env, LDKConfirmationTarget_class, "LDKConfirmationTarget_HighPriority", "Lorg/ldk/enums/LDKConfirmationTarget;");
286         CHECK(LDKConfirmationTarget_LDKConfirmationTarget_HighPriority != NULL);
287 }
288 static inline jclass LDKConfirmationTarget_to_java(JNIEnv *env, LDKConfirmationTarget val) {
289         switch (val) {
290                 case LDKConfirmationTarget_Background:
291                         return (*env)->GetStaticObjectField(env, LDKConfirmationTarget_class, LDKConfirmationTarget_LDKConfirmationTarget_Background);
292                 case LDKConfirmationTarget_Normal:
293                         return (*env)->GetStaticObjectField(env, LDKConfirmationTarget_class, LDKConfirmationTarget_LDKConfirmationTarget_Normal);
294                 case LDKConfirmationTarget_HighPriority:
295                         return (*env)->GetStaticObjectField(env, LDKConfirmationTarget_class, LDKConfirmationTarget_LDKConfirmationTarget_HighPriority);
296                 default: abort();
297         }
298 }
299
300 static inline LDKLevel LDKLevel_from_java(JNIEnv *env, jclass val) {
301         switch ((*env)->CallIntMethod(env, val, ordinal_meth)) {
302                 case 0: return LDKLevel_Off;
303                 case 1: return LDKLevel_Error;
304                 case 2: return LDKLevel_Warn;
305                 case 3: return LDKLevel_Info;
306                 case 4: return LDKLevel_Debug;
307                 case 5: return LDKLevel_Trace;
308         }
309         abort();
310 }
311 static jclass LDKLevel_class = NULL;
312 static jfieldID LDKLevel_LDKLevel_Off = NULL;
313 static jfieldID LDKLevel_LDKLevel_Error = NULL;
314 static jfieldID LDKLevel_LDKLevel_Warn = NULL;
315 static jfieldID LDKLevel_LDKLevel_Info = NULL;
316 static jfieldID LDKLevel_LDKLevel_Debug = NULL;
317 static jfieldID LDKLevel_LDKLevel_Trace = NULL;
318 JNIEXPORT void JNICALL Java_org_ldk_enums_LDKLevel_init (JNIEnv * env, jclass clz) {
319         LDKLevel_class = (*env)->NewGlobalRef(env, clz);
320         CHECK(LDKLevel_class != NULL);
321         LDKLevel_LDKLevel_Off = (*env)->GetStaticFieldID(env, LDKLevel_class, "LDKLevel_Off", "Lorg/ldk/enums/LDKLevel;");
322         CHECK(LDKLevel_LDKLevel_Off != NULL);
323         LDKLevel_LDKLevel_Error = (*env)->GetStaticFieldID(env, LDKLevel_class, "LDKLevel_Error", "Lorg/ldk/enums/LDKLevel;");
324         CHECK(LDKLevel_LDKLevel_Error != NULL);
325         LDKLevel_LDKLevel_Warn = (*env)->GetStaticFieldID(env, LDKLevel_class, "LDKLevel_Warn", "Lorg/ldk/enums/LDKLevel;");
326         CHECK(LDKLevel_LDKLevel_Warn != NULL);
327         LDKLevel_LDKLevel_Info = (*env)->GetStaticFieldID(env, LDKLevel_class, "LDKLevel_Info", "Lorg/ldk/enums/LDKLevel;");
328         CHECK(LDKLevel_LDKLevel_Info != NULL);
329         LDKLevel_LDKLevel_Debug = (*env)->GetStaticFieldID(env, LDKLevel_class, "LDKLevel_Debug", "Lorg/ldk/enums/LDKLevel;");
330         CHECK(LDKLevel_LDKLevel_Debug != NULL);
331         LDKLevel_LDKLevel_Trace = (*env)->GetStaticFieldID(env, LDKLevel_class, "LDKLevel_Trace", "Lorg/ldk/enums/LDKLevel;");
332         CHECK(LDKLevel_LDKLevel_Trace != NULL);
333 }
334 static inline jclass LDKLevel_to_java(JNIEnv *env, LDKLevel val) {
335         switch (val) {
336                 case LDKLevel_Off:
337                         return (*env)->GetStaticObjectField(env, LDKLevel_class, LDKLevel_LDKLevel_Off);
338                 case LDKLevel_Error:
339                         return (*env)->GetStaticObjectField(env, LDKLevel_class, LDKLevel_LDKLevel_Error);
340                 case LDKLevel_Warn:
341                         return (*env)->GetStaticObjectField(env, LDKLevel_class, LDKLevel_LDKLevel_Warn);
342                 case LDKLevel_Info:
343                         return (*env)->GetStaticObjectField(env, LDKLevel_class, LDKLevel_LDKLevel_Info);
344                 case LDKLevel_Debug:
345                         return (*env)->GetStaticObjectField(env, LDKLevel_class, LDKLevel_LDKLevel_Debug);
346                 case LDKLevel_Trace:
347                         return (*env)->GetStaticObjectField(env, LDKLevel_class, LDKLevel_LDKLevel_Trace);
348                 default: abort();
349         }
350 }
351
352 static inline LDKNetwork LDKNetwork_from_java(JNIEnv *env, jclass val) {
353         switch ((*env)->CallIntMethod(env, val, ordinal_meth)) {
354                 case 0: return LDKNetwork_Bitcoin;
355                 case 1: return LDKNetwork_Testnet;
356                 case 2: return LDKNetwork_Regtest;
357         }
358         abort();
359 }
360 static jclass LDKNetwork_class = NULL;
361 static jfieldID LDKNetwork_LDKNetwork_Bitcoin = NULL;
362 static jfieldID LDKNetwork_LDKNetwork_Testnet = NULL;
363 static jfieldID LDKNetwork_LDKNetwork_Regtest = NULL;
364 JNIEXPORT void JNICALL Java_org_ldk_enums_LDKNetwork_init (JNIEnv * env, jclass clz) {
365         LDKNetwork_class = (*env)->NewGlobalRef(env, clz);
366         CHECK(LDKNetwork_class != NULL);
367         LDKNetwork_LDKNetwork_Bitcoin = (*env)->GetStaticFieldID(env, LDKNetwork_class, "LDKNetwork_Bitcoin", "Lorg/ldk/enums/LDKNetwork;");
368         CHECK(LDKNetwork_LDKNetwork_Bitcoin != NULL);
369         LDKNetwork_LDKNetwork_Testnet = (*env)->GetStaticFieldID(env, LDKNetwork_class, "LDKNetwork_Testnet", "Lorg/ldk/enums/LDKNetwork;");
370         CHECK(LDKNetwork_LDKNetwork_Testnet != NULL);
371         LDKNetwork_LDKNetwork_Regtest = (*env)->GetStaticFieldID(env, LDKNetwork_class, "LDKNetwork_Regtest", "Lorg/ldk/enums/LDKNetwork;");
372         CHECK(LDKNetwork_LDKNetwork_Regtest != NULL);
373 }
374 static inline jclass LDKNetwork_to_java(JNIEnv *env, LDKNetwork val) {
375         switch (val) {
376                 case LDKNetwork_Bitcoin:
377                         return (*env)->GetStaticObjectField(env, LDKNetwork_class, LDKNetwork_LDKNetwork_Bitcoin);
378                 case LDKNetwork_Testnet:
379                         return (*env)->GetStaticObjectField(env, LDKNetwork_class, LDKNetwork_LDKNetwork_Testnet);
380                 case LDKNetwork_Regtest:
381                         return (*env)->GetStaticObjectField(env, LDKNetwork_class, LDKNetwork_LDKNetwork_Regtest);
382                 default: abort();
383         }
384 }
385
386 static inline LDKSecp256k1Error LDKSecp256k1Error_from_java(JNIEnv *env, jclass val) {
387         switch ((*env)->CallIntMethod(env, val, ordinal_meth)) {
388                 case 0: return LDKSecp256k1Error_IncorrectSignature;
389                 case 1: return LDKSecp256k1Error_InvalidMessage;
390                 case 2: return LDKSecp256k1Error_InvalidPublicKey;
391                 case 3: return LDKSecp256k1Error_InvalidSignature;
392                 case 4: return LDKSecp256k1Error_InvalidSecretKey;
393                 case 5: return LDKSecp256k1Error_InvalidRecoveryId;
394                 case 6: return LDKSecp256k1Error_InvalidTweak;
395                 case 7: return LDKSecp256k1Error_NotEnoughMemory;
396                 case 8: return LDKSecp256k1Error_CallbackPanicked;
397         }
398         abort();
399 }
400 static jclass LDKSecp256k1Error_class = NULL;
401 static jfieldID LDKSecp256k1Error_LDKSecp256k1Error_IncorrectSignature = NULL;
402 static jfieldID LDKSecp256k1Error_LDKSecp256k1Error_InvalidMessage = NULL;
403 static jfieldID LDKSecp256k1Error_LDKSecp256k1Error_InvalidPublicKey = NULL;
404 static jfieldID LDKSecp256k1Error_LDKSecp256k1Error_InvalidSignature = NULL;
405 static jfieldID LDKSecp256k1Error_LDKSecp256k1Error_InvalidSecretKey = NULL;
406 static jfieldID LDKSecp256k1Error_LDKSecp256k1Error_InvalidRecoveryId = NULL;
407 static jfieldID LDKSecp256k1Error_LDKSecp256k1Error_InvalidTweak = NULL;
408 static jfieldID LDKSecp256k1Error_LDKSecp256k1Error_NotEnoughMemory = NULL;
409 static jfieldID LDKSecp256k1Error_LDKSecp256k1Error_CallbackPanicked = NULL;
410 JNIEXPORT void JNICALL Java_org_ldk_enums_LDKSecp256k1Error_init (JNIEnv * env, jclass clz) {
411         LDKSecp256k1Error_class = (*env)->NewGlobalRef(env, clz);
412         CHECK(LDKSecp256k1Error_class != NULL);
413         LDKSecp256k1Error_LDKSecp256k1Error_IncorrectSignature = (*env)->GetStaticFieldID(env, LDKSecp256k1Error_class, "LDKSecp256k1Error_IncorrectSignature", "Lorg/ldk/enums/LDKSecp256k1Error;");
414         CHECK(LDKSecp256k1Error_LDKSecp256k1Error_IncorrectSignature != NULL);
415         LDKSecp256k1Error_LDKSecp256k1Error_InvalidMessage = (*env)->GetStaticFieldID(env, LDKSecp256k1Error_class, "LDKSecp256k1Error_InvalidMessage", "Lorg/ldk/enums/LDKSecp256k1Error;");
416         CHECK(LDKSecp256k1Error_LDKSecp256k1Error_InvalidMessage != NULL);
417         LDKSecp256k1Error_LDKSecp256k1Error_InvalidPublicKey = (*env)->GetStaticFieldID(env, LDKSecp256k1Error_class, "LDKSecp256k1Error_InvalidPublicKey", "Lorg/ldk/enums/LDKSecp256k1Error;");
418         CHECK(LDKSecp256k1Error_LDKSecp256k1Error_InvalidPublicKey != NULL);
419         LDKSecp256k1Error_LDKSecp256k1Error_InvalidSignature = (*env)->GetStaticFieldID(env, LDKSecp256k1Error_class, "LDKSecp256k1Error_InvalidSignature", "Lorg/ldk/enums/LDKSecp256k1Error;");
420         CHECK(LDKSecp256k1Error_LDKSecp256k1Error_InvalidSignature != NULL);
421         LDKSecp256k1Error_LDKSecp256k1Error_InvalidSecretKey = (*env)->GetStaticFieldID(env, LDKSecp256k1Error_class, "LDKSecp256k1Error_InvalidSecretKey", "Lorg/ldk/enums/LDKSecp256k1Error;");
422         CHECK(LDKSecp256k1Error_LDKSecp256k1Error_InvalidSecretKey != NULL);
423         LDKSecp256k1Error_LDKSecp256k1Error_InvalidRecoveryId = (*env)->GetStaticFieldID(env, LDKSecp256k1Error_class, "LDKSecp256k1Error_InvalidRecoveryId", "Lorg/ldk/enums/LDKSecp256k1Error;");
424         CHECK(LDKSecp256k1Error_LDKSecp256k1Error_InvalidRecoveryId != NULL);
425         LDKSecp256k1Error_LDKSecp256k1Error_InvalidTweak = (*env)->GetStaticFieldID(env, LDKSecp256k1Error_class, "LDKSecp256k1Error_InvalidTweak", "Lorg/ldk/enums/LDKSecp256k1Error;");
426         CHECK(LDKSecp256k1Error_LDKSecp256k1Error_InvalidTweak != NULL);
427         LDKSecp256k1Error_LDKSecp256k1Error_NotEnoughMemory = (*env)->GetStaticFieldID(env, LDKSecp256k1Error_class, "LDKSecp256k1Error_NotEnoughMemory", "Lorg/ldk/enums/LDKSecp256k1Error;");
428         CHECK(LDKSecp256k1Error_LDKSecp256k1Error_NotEnoughMemory != NULL);
429         LDKSecp256k1Error_LDKSecp256k1Error_CallbackPanicked = (*env)->GetStaticFieldID(env, LDKSecp256k1Error_class, "LDKSecp256k1Error_CallbackPanicked", "Lorg/ldk/enums/LDKSecp256k1Error;");
430         CHECK(LDKSecp256k1Error_LDKSecp256k1Error_CallbackPanicked != NULL);
431 }
432 static inline jclass LDKSecp256k1Error_to_java(JNIEnv *env, LDKSecp256k1Error val) {
433         switch (val) {
434                 case LDKSecp256k1Error_IncorrectSignature:
435                         return (*env)->GetStaticObjectField(env, LDKSecp256k1Error_class, LDKSecp256k1Error_LDKSecp256k1Error_IncorrectSignature);
436                 case LDKSecp256k1Error_InvalidMessage:
437                         return (*env)->GetStaticObjectField(env, LDKSecp256k1Error_class, LDKSecp256k1Error_LDKSecp256k1Error_InvalidMessage);
438                 case LDKSecp256k1Error_InvalidPublicKey:
439                         return (*env)->GetStaticObjectField(env, LDKSecp256k1Error_class, LDKSecp256k1Error_LDKSecp256k1Error_InvalidPublicKey);
440                 case LDKSecp256k1Error_InvalidSignature:
441                         return (*env)->GetStaticObjectField(env, LDKSecp256k1Error_class, LDKSecp256k1Error_LDKSecp256k1Error_InvalidSignature);
442                 case LDKSecp256k1Error_InvalidSecretKey:
443                         return (*env)->GetStaticObjectField(env, LDKSecp256k1Error_class, LDKSecp256k1Error_LDKSecp256k1Error_InvalidSecretKey);
444                 case LDKSecp256k1Error_InvalidRecoveryId:
445                         return (*env)->GetStaticObjectField(env, LDKSecp256k1Error_class, LDKSecp256k1Error_LDKSecp256k1Error_InvalidRecoveryId);
446                 case LDKSecp256k1Error_InvalidTweak:
447                         return (*env)->GetStaticObjectField(env, LDKSecp256k1Error_class, LDKSecp256k1Error_LDKSecp256k1Error_InvalidTweak);
448                 case LDKSecp256k1Error_NotEnoughMemory:
449                         return (*env)->GetStaticObjectField(env, LDKSecp256k1Error_class, LDKSecp256k1Error_LDKSecp256k1Error_NotEnoughMemory);
450                 case LDKSecp256k1Error_CallbackPanicked:
451                         return (*env)->GetStaticObjectField(env, LDKSecp256k1Error_class, LDKSecp256k1Error_LDKSecp256k1Error_CallbackPanicked);
452                 default: abort();
453         }
454 }
455
456 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKCVec_1u8Z_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
457         LDKCVec_u8Z *vec = (LDKCVec_u8Z*)ptr;
458         return (*env)->NewObject(env, slicedef_cls, slicedef_meth, (long)vec->data, (long)vec->datalen, sizeof(uint8_t));
459 }
460 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVec_1u8Z_1new(JNIEnv *env, jclass _b, jbyteArray elems){
461         LDKCVec_u8Z *ret = MALLOC(sizeof(LDKCVec_u8Z), "LDKCVec_u8Z");
462         ret->datalen = (*env)->GetArrayLength(env, elems);
463         if (ret->datalen == 0) {
464                 ret->data = NULL;
465         } else {
466                 ret->data = MALLOC(sizeof(uint8_t) * ret->datalen, "LDKCVec_u8Z Data");
467                 jbyte *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
468                 for (size_t i = 0; i < ret->datalen; i++) {
469                         ret->data[i] = java_elems[i];
470                 }
471                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
472         }
473         return (long)ret;
474 }
475 static inline LDKCVec_u8Z CVec_u8Z_clone(const LDKCVec_u8Z *orig) {
476         LDKCVec_u8Z ret = { .data = MALLOC(sizeof(jbyte) * orig->datalen, "LDKCVec_u8Z clone bytes"), .datalen = orig->datalen };
477         memcpy(ret.data, orig->data, sizeof(jbyte) * ret.datalen);
478         return ret;
479 }
480 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKC2Tuple_1u64u64Z_1new(JNIEnv *_env, jclass _b, jlong a, jlong b) {
481         LDKC2Tuple_u64u64Z* ret = MALLOC(sizeof(LDKC2Tuple_u64u64Z), "LDKC2Tuple_u64u64Z");
482         ret->a = a;
483         ret->b = b;
484         return (long)ret;
485 }
486 static inline LDKC2Tuple_u64u64Z C2Tuple_u64u64Z_clone(const LDKC2Tuple_u64u64Z *orig) {
487         LDKC2Tuple_u64u64Z ret = {
488                 .a = orig->a,
489                 .b = orig->b,
490         };
491         return ret;
492 }
493 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKC2Tuple_1u64u64Z_1get_1a(JNIEnv *_env, jclass _b, jlong ptr) {
494         LDKC2Tuple_u64u64Z *tuple = (LDKC2Tuple_u64u64Z*)ptr;
495         return tuple->a;
496 }
497 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKC2Tuple_1u64u64Z_1get_1b(JNIEnv *_env, jclass _b, jlong ptr) {
498         LDKC2Tuple_u64u64Z *tuple = (LDKC2Tuple_u64u64Z*)ptr;
499         return tuple->b;
500 }
501 static jclass LDKSpendableOutputDescriptor_StaticOutput_class = NULL;
502 static jmethodID LDKSpendableOutputDescriptor_StaticOutput_meth = NULL;
503 static jclass LDKSpendableOutputDescriptor_DynamicOutputP2WSH_class = NULL;
504 static jmethodID LDKSpendableOutputDescriptor_DynamicOutputP2WSH_meth = NULL;
505 static jclass LDKSpendableOutputDescriptor_StaticOutputCounterpartyPayment_class = NULL;
506 static jmethodID LDKSpendableOutputDescriptor_StaticOutputCounterpartyPayment_meth = NULL;
507 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_00024LDKSpendableOutputDescriptor_init (JNIEnv * env, jclass _a) {
508         LDKSpendableOutputDescriptor_StaticOutput_class =
509                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKSpendableOutputDescriptor$StaticOutput;"));
510         CHECK(LDKSpendableOutputDescriptor_StaticOutput_class != NULL);
511         LDKSpendableOutputDescriptor_StaticOutput_meth = (*env)->GetMethodID(env, LDKSpendableOutputDescriptor_StaticOutput_class, "<init>", "(JJ)V");
512         CHECK(LDKSpendableOutputDescriptor_StaticOutput_meth != NULL);
513         LDKSpendableOutputDescriptor_DynamicOutputP2WSH_class =
514                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKSpendableOutputDescriptor$DynamicOutputP2WSH;"));
515         CHECK(LDKSpendableOutputDescriptor_DynamicOutputP2WSH_class != NULL);
516         LDKSpendableOutputDescriptor_DynamicOutputP2WSH_meth = (*env)->GetMethodID(env, LDKSpendableOutputDescriptor_DynamicOutputP2WSH_class, "<init>", "(J[BSJJ[B)V");
517         CHECK(LDKSpendableOutputDescriptor_DynamicOutputP2WSH_meth != NULL);
518         LDKSpendableOutputDescriptor_StaticOutputCounterpartyPayment_class =
519                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKSpendableOutputDescriptor$StaticOutputCounterpartyPayment;"));
520         CHECK(LDKSpendableOutputDescriptor_StaticOutputCounterpartyPayment_class != NULL);
521         LDKSpendableOutputDescriptor_StaticOutputCounterpartyPayment_meth = (*env)->GetMethodID(env, LDKSpendableOutputDescriptor_StaticOutputCounterpartyPayment_class, "<init>", "(JJJ)V");
522         CHECK(LDKSpendableOutputDescriptor_StaticOutputCounterpartyPayment_meth != NULL);
523 }
524 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKSpendableOutputDescriptor_1ref_1from_1ptr (JNIEnv * _env, jclass _c, jlong ptr) {
525         LDKSpendableOutputDescriptor *obj = (LDKSpendableOutputDescriptor*)ptr;
526         switch(obj->tag) {
527                 case LDKSpendableOutputDescriptor_StaticOutput: {
528                         LDKOutPoint outpoint_var = obj->static_output.outpoint;
529                         CHECK((((long)outpoint_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
530                         CHECK((((long)&outpoint_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
531                         long outpoint_ref = (long)outpoint_var.inner & ~1;
532                         long output_ref = (long)&obj->static_output.output;
533                         return (*_env)->NewObject(_env, LDKSpendableOutputDescriptor_StaticOutput_class, LDKSpendableOutputDescriptor_StaticOutput_meth, outpoint_ref, (long)output_ref);
534                 }
535                 case LDKSpendableOutputDescriptor_DynamicOutputP2WSH: {
536                         LDKOutPoint outpoint_var = obj->dynamic_output_p2wsh.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                         jbyteArray per_commitment_point_arr = (*_env)->NewByteArray(_env, 33);
541                         (*_env)->SetByteArrayRegion(_env, per_commitment_point_arr, 0, 33, obj->dynamic_output_p2wsh.per_commitment_point.compressed_form);
542                         long output_ref = (long)&obj->dynamic_output_p2wsh.output;
543                         long key_derivation_params_ref = (long)&obj->dynamic_output_p2wsh.key_derivation_params;
544                         jbyteArray revocation_pubkey_arr = (*_env)->NewByteArray(_env, 33);
545                         (*_env)->SetByteArrayRegion(_env, revocation_pubkey_arr, 0, 33, obj->dynamic_output_p2wsh.revocation_pubkey.compressed_form);
546                         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);
547                 }
548                 case LDKSpendableOutputDescriptor_StaticOutputCounterpartyPayment: {
549                         LDKOutPoint outpoint_var = obj->static_output_counterparty_payment.outpoint;
550                         CHECK((((long)outpoint_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
551                         CHECK((((long)&outpoint_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
552                         long outpoint_ref = (long)outpoint_var.inner & ~1;
553                         long output_ref = (long)&obj->static_output_counterparty_payment.output;
554                         long key_derivation_params_ref = (long)&obj->static_output_counterparty_payment.key_derivation_params;
555                         return (*_env)->NewObject(_env, LDKSpendableOutputDescriptor_StaticOutputCounterpartyPayment_class, LDKSpendableOutputDescriptor_StaticOutputCounterpartyPayment_meth, outpoint_ref, (long)output_ref, key_derivation_params_ref);
556                 }
557                 default: abort();
558         }
559 }
560 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKCVec_1SpendableOutputDescriptorZ_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
561         LDKCVec_SpendableOutputDescriptorZ *vec = (LDKCVec_SpendableOutputDescriptorZ*)ptr;
562         return (*env)->NewObject(env, slicedef_cls, slicedef_meth, (long)vec->data, (long)vec->datalen, sizeof(LDKSpendableOutputDescriptor));
563 }
564 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVec_1SpendableOutputDescriptorZ_1new(JNIEnv *env, jclass _b, jlongArray elems){
565         LDKCVec_SpendableOutputDescriptorZ *ret = MALLOC(sizeof(LDKCVec_SpendableOutputDescriptorZ), "LDKCVec_SpendableOutputDescriptorZ");
566         ret->datalen = (*env)->GetArrayLength(env, elems);
567         if (ret->datalen == 0) {
568                 ret->data = NULL;
569         } else {
570                 ret->data = MALLOC(sizeof(LDKSpendableOutputDescriptor) * ret->datalen, "LDKCVec_SpendableOutputDescriptorZ Data");
571                 jlong *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
572                 for (size_t i = 0; i < ret->datalen; i++) {
573                         jlong arr_elem = java_elems[i];
574                         LDKSpendableOutputDescriptor arr_elem_conv = *(LDKSpendableOutputDescriptor*)arr_elem;
575                         FREE((void*)arr_elem);
576                         ret->data[i] = arr_elem_conv;
577                 }
578                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
579         }
580         return (long)ret;
581 }
582 static inline LDKCVec_SpendableOutputDescriptorZ CVec_SpendableOutputDescriptorZ_clone(const LDKCVec_SpendableOutputDescriptorZ *orig) {
583         LDKCVec_SpendableOutputDescriptorZ ret = { .data = MALLOC(sizeof(LDKSpendableOutputDescriptor) * orig->datalen, "LDKCVec_SpendableOutputDescriptorZ clone bytes"), .datalen = orig->datalen };
584         for (size_t i = 0; i < ret.datalen; i++) {
585                 ret.data[i] = SpendableOutputDescriptor_clone(&orig->data[i]);
586         }
587         return ret;
588 }
589 static jclass LDKErrorAction_DisconnectPeer_class = NULL;
590 static jmethodID LDKErrorAction_DisconnectPeer_meth = NULL;
591 static jclass LDKErrorAction_IgnoreError_class = NULL;
592 static jmethodID LDKErrorAction_IgnoreError_meth = NULL;
593 static jclass LDKErrorAction_SendErrorMessage_class = NULL;
594 static jmethodID LDKErrorAction_SendErrorMessage_meth = NULL;
595 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_00024LDKErrorAction_init (JNIEnv * env, jclass _a) {
596         LDKErrorAction_DisconnectPeer_class =
597                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKErrorAction$DisconnectPeer;"));
598         CHECK(LDKErrorAction_DisconnectPeer_class != NULL);
599         LDKErrorAction_DisconnectPeer_meth = (*env)->GetMethodID(env, LDKErrorAction_DisconnectPeer_class, "<init>", "(J)V");
600         CHECK(LDKErrorAction_DisconnectPeer_meth != NULL);
601         LDKErrorAction_IgnoreError_class =
602                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKErrorAction$IgnoreError;"));
603         CHECK(LDKErrorAction_IgnoreError_class != NULL);
604         LDKErrorAction_IgnoreError_meth = (*env)->GetMethodID(env, LDKErrorAction_IgnoreError_class, "<init>", "()V");
605         CHECK(LDKErrorAction_IgnoreError_meth != NULL);
606         LDKErrorAction_SendErrorMessage_class =
607                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKErrorAction$SendErrorMessage;"));
608         CHECK(LDKErrorAction_SendErrorMessage_class != NULL);
609         LDKErrorAction_SendErrorMessage_meth = (*env)->GetMethodID(env, LDKErrorAction_SendErrorMessage_class, "<init>", "(J)V");
610         CHECK(LDKErrorAction_SendErrorMessage_meth != NULL);
611 }
612 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKErrorAction_1ref_1from_1ptr (JNIEnv * _env, jclass _c, jlong ptr) {
613         LDKErrorAction *obj = (LDKErrorAction*)ptr;
614         switch(obj->tag) {
615                 case LDKErrorAction_DisconnectPeer: {
616                         LDKErrorMessage msg_var = obj->disconnect_peer.msg;
617                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
618                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
619                         long msg_ref = (long)msg_var.inner & ~1;
620                         return (*_env)->NewObject(_env, LDKErrorAction_DisconnectPeer_class, LDKErrorAction_DisconnectPeer_meth, msg_ref);
621                 }
622                 case LDKErrorAction_IgnoreError: {
623                         return (*_env)->NewObject(_env, LDKErrorAction_IgnoreError_class, LDKErrorAction_IgnoreError_meth);
624                 }
625                 case LDKErrorAction_SendErrorMessage: {
626                         LDKErrorMessage msg_var = obj->send_error_message.msg;
627                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
628                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
629                         long msg_ref = (long)msg_var.inner & ~1;
630                         return (*_env)->NewObject(_env, LDKErrorAction_SendErrorMessage_class, LDKErrorAction_SendErrorMessage_meth, msg_ref);
631                 }
632                 default: abort();
633         }
634 }
635 static jclass LDKHTLCFailChannelUpdate_ChannelUpdateMessage_class = NULL;
636 static jmethodID LDKHTLCFailChannelUpdate_ChannelUpdateMessage_meth = NULL;
637 static jclass LDKHTLCFailChannelUpdate_ChannelClosed_class = NULL;
638 static jmethodID LDKHTLCFailChannelUpdate_ChannelClosed_meth = NULL;
639 static jclass LDKHTLCFailChannelUpdate_NodeFailure_class = NULL;
640 static jmethodID LDKHTLCFailChannelUpdate_NodeFailure_meth = NULL;
641 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_00024LDKHTLCFailChannelUpdate_init (JNIEnv * env, jclass _a) {
642         LDKHTLCFailChannelUpdate_ChannelUpdateMessage_class =
643                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKHTLCFailChannelUpdate$ChannelUpdateMessage;"));
644         CHECK(LDKHTLCFailChannelUpdate_ChannelUpdateMessage_class != NULL);
645         LDKHTLCFailChannelUpdate_ChannelUpdateMessage_meth = (*env)->GetMethodID(env, LDKHTLCFailChannelUpdate_ChannelUpdateMessage_class, "<init>", "(J)V");
646         CHECK(LDKHTLCFailChannelUpdate_ChannelUpdateMessage_meth != NULL);
647         LDKHTLCFailChannelUpdate_ChannelClosed_class =
648                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKHTLCFailChannelUpdate$ChannelClosed;"));
649         CHECK(LDKHTLCFailChannelUpdate_ChannelClosed_class != NULL);
650         LDKHTLCFailChannelUpdate_ChannelClosed_meth = (*env)->GetMethodID(env, LDKHTLCFailChannelUpdate_ChannelClosed_class, "<init>", "(JZ)V");
651         CHECK(LDKHTLCFailChannelUpdate_ChannelClosed_meth != NULL);
652         LDKHTLCFailChannelUpdate_NodeFailure_class =
653                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKHTLCFailChannelUpdate$NodeFailure;"));
654         CHECK(LDKHTLCFailChannelUpdate_NodeFailure_class != NULL);
655         LDKHTLCFailChannelUpdate_NodeFailure_meth = (*env)->GetMethodID(env, LDKHTLCFailChannelUpdate_NodeFailure_class, "<init>", "([BZ)V");
656         CHECK(LDKHTLCFailChannelUpdate_NodeFailure_meth != NULL);
657 }
658 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKHTLCFailChannelUpdate_1ref_1from_1ptr (JNIEnv * _env, jclass _c, jlong ptr) {
659         LDKHTLCFailChannelUpdate *obj = (LDKHTLCFailChannelUpdate*)ptr;
660         switch(obj->tag) {
661                 case LDKHTLCFailChannelUpdate_ChannelUpdateMessage: {
662                         LDKChannelUpdate msg_var = obj->channel_update_message.msg;
663                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
664                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
665                         long msg_ref = (long)msg_var.inner & ~1;
666                         return (*_env)->NewObject(_env, LDKHTLCFailChannelUpdate_ChannelUpdateMessage_class, LDKHTLCFailChannelUpdate_ChannelUpdateMessage_meth, msg_ref);
667                 }
668                 case LDKHTLCFailChannelUpdate_ChannelClosed: {
669                         return (*_env)->NewObject(_env, LDKHTLCFailChannelUpdate_ChannelClosed_class, LDKHTLCFailChannelUpdate_ChannelClosed_meth, obj->channel_closed.short_channel_id, obj->channel_closed.is_permanent);
670                 }
671                 case LDKHTLCFailChannelUpdate_NodeFailure: {
672                         jbyteArray node_id_arr = (*_env)->NewByteArray(_env, 33);
673                         (*_env)->SetByteArrayRegion(_env, node_id_arr, 0, 33, obj->node_failure.node_id.compressed_form);
674                         return (*_env)->NewObject(_env, LDKHTLCFailChannelUpdate_NodeFailure_class, LDKHTLCFailChannelUpdate_NodeFailure_meth, node_id_arr, obj->node_failure.is_permanent);
675                 }
676                 default: abort();
677         }
678 }
679 static jclass LDKMessageSendEvent_SendAcceptChannel_class = NULL;
680 static jmethodID LDKMessageSendEvent_SendAcceptChannel_meth = NULL;
681 static jclass LDKMessageSendEvent_SendOpenChannel_class = NULL;
682 static jmethodID LDKMessageSendEvent_SendOpenChannel_meth = NULL;
683 static jclass LDKMessageSendEvent_SendFundingCreated_class = NULL;
684 static jmethodID LDKMessageSendEvent_SendFundingCreated_meth = NULL;
685 static jclass LDKMessageSendEvent_SendFundingSigned_class = NULL;
686 static jmethodID LDKMessageSendEvent_SendFundingSigned_meth = NULL;
687 static jclass LDKMessageSendEvent_SendFundingLocked_class = NULL;
688 static jmethodID LDKMessageSendEvent_SendFundingLocked_meth = NULL;
689 static jclass LDKMessageSendEvent_SendAnnouncementSignatures_class = NULL;
690 static jmethodID LDKMessageSendEvent_SendAnnouncementSignatures_meth = NULL;
691 static jclass LDKMessageSendEvent_UpdateHTLCs_class = NULL;
692 static jmethodID LDKMessageSendEvent_UpdateHTLCs_meth = NULL;
693 static jclass LDKMessageSendEvent_SendRevokeAndACK_class = NULL;
694 static jmethodID LDKMessageSendEvent_SendRevokeAndACK_meth = NULL;
695 static jclass LDKMessageSendEvent_SendClosingSigned_class = NULL;
696 static jmethodID LDKMessageSendEvent_SendClosingSigned_meth = NULL;
697 static jclass LDKMessageSendEvent_SendShutdown_class = NULL;
698 static jmethodID LDKMessageSendEvent_SendShutdown_meth = NULL;
699 static jclass LDKMessageSendEvent_SendChannelReestablish_class = NULL;
700 static jmethodID LDKMessageSendEvent_SendChannelReestablish_meth = NULL;
701 static jclass LDKMessageSendEvent_BroadcastChannelAnnouncement_class = NULL;
702 static jmethodID LDKMessageSendEvent_BroadcastChannelAnnouncement_meth = NULL;
703 static jclass LDKMessageSendEvent_BroadcastNodeAnnouncement_class = NULL;
704 static jmethodID LDKMessageSendEvent_BroadcastNodeAnnouncement_meth = NULL;
705 static jclass LDKMessageSendEvent_BroadcastChannelUpdate_class = NULL;
706 static jmethodID LDKMessageSendEvent_BroadcastChannelUpdate_meth = NULL;
707 static jclass LDKMessageSendEvent_HandleError_class = NULL;
708 static jmethodID LDKMessageSendEvent_HandleError_meth = NULL;
709 static jclass LDKMessageSendEvent_PaymentFailureNetworkUpdate_class = NULL;
710 static jmethodID LDKMessageSendEvent_PaymentFailureNetworkUpdate_meth = NULL;
711 static jclass LDKMessageSendEvent_SendChannelRangeQuery_class = NULL;
712 static jmethodID LDKMessageSendEvent_SendChannelRangeQuery_meth = NULL;
713 static jclass LDKMessageSendEvent_SendShortIdsQuery_class = NULL;
714 static jmethodID LDKMessageSendEvent_SendShortIdsQuery_meth = NULL;
715 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_00024LDKMessageSendEvent_init (JNIEnv * env, jclass _a) {
716         LDKMessageSendEvent_SendAcceptChannel_class =
717                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKMessageSendEvent$SendAcceptChannel;"));
718         CHECK(LDKMessageSendEvent_SendAcceptChannel_class != NULL);
719         LDKMessageSendEvent_SendAcceptChannel_meth = (*env)->GetMethodID(env, LDKMessageSendEvent_SendAcceptChannel_class, "<init>", "([BJ)V");
720         CHECK(LDKMessageSendEvent_SendAcceptChannel_meth != NULL);
721         LDKMessageSendEvent_SendOpenChannel_class =
722                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKMessageSendEvent$SendOpenChannel;"));
723         CHECK(LDKMessageSendEvent_SendOpenChannel_class != NULL);
724         LDKMessageSendEvent_SendOpenChannel_meth = (*env)->GetMethodID(env, LDKMessageSendEvent_SendOpenChannel_class, "<init>", "([BJ)V");
725         CHECK(LDKMessageSendEvent_SendOpenChannel_meth != NULL);
726         LDKMessageSendEvent_SendFundingCreated_class =
727                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKMessageSendEvent$SendFundingCreated;"));
728         CHECK(LDKMessageSendEvent_SendFundingCreated_class != NULL);
729         LDKMessageSendEvent_SendFundingCreated_meth = (*env)->GetMethodID(env, LDKMessageSendEvent_SendFundingCreated_class, "<init>", "([BJ)V");
730         CHECK(LDKMessageSendEvent_SendFundingCreated_meth != NULL);
731         LDKMessageSendEvent_SendFundingSigned_class =
732                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKMessageSendEvent$SendFundingSigned;"));
733         CHECK(LDKMessageSendEvent_SendFundingSigned_class != NULL);
734         LDKMessageSendEvent_SendFundingSigned_meth = (*env)->GetMethodID(env, LDKMessageSendEvent_SendFundingSigned_class, "<init>", "([BJ)V");
735         CHECK(LDKMessageSendEvent_SendFundingSigned_meth != NULL);
736         LDKMessageSendEvent_SendFundingLocked_class =
737                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKMessageSendEvent$SendFundingLocked;"));
738         CHECK(LDKMessageSendEvent_SendFundingLocked_class != NULL);
739         LDKMessageSendEvent_SendFundingLocked_meth = (*env)->GetMethodID(env, LDKMessageSendEvent_SendFundingLocked_class, "<init>", "([BJ)V");
740         CHECK(LDKMessageSendEvent_SendFundingLocked_meth != NULL);
741         LDKMessageSendEvent_SendAnnouncementSignatures_class =
742                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKMessageSendEvent$SendAnnouncementSignatures;"));
743         CHECK(LDKMessageSendEvent_SendAnnouncementSignatures_class != NULL);
744         LDKMessageSendEvent_SendAnnouncementSignatures_meth = (*env)->GetMethodID(env, LDKMessageSendEvent_SendAnnouncementSignatures_class, "<init>", "([BJ)V");
745         CHECK(LDKMessageSendEvent_SendAnnouncementSignatures_meth != NULL);
746         LDKMessageSendEvent_UpdateHTLCs_class =
747                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKMessageSendEvent$UpdateHTLCs;"));
748         CHECK(LDKMessageSendEvent_UpdateHTLCs_class != NULL);
749         LDKMessageSendEvent_UpdateHTLCs_meth = (*env)->GetMethodID(env, LDKMessageSendEvent_UpdateHTLCs_class, "<init>", "([BJ)V");
750         CHECK(LDKMessageSendEvent_UpdateHTLCs_meth != NULL);
751         LDKMessageSendEvent_SendRevokeAndACK_class =
752                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKMessageSendEvent$SendRevokeAndACK;"));
753         CHECK(LDKMessageSendEvent_SendRevokeAndACK_class != NULL);
754         LDKMessageSendEvent_SendRevokeAndACK_meth = (*env)->GetMethodID(env, LDKMessageSendEvent_SendRevokeAndACK_class, "<init>", "([BJ)V");
755         CHECK(LDKMessageSendEvent_SendRevokeAndACK_meth != NULL);
756         LDKMessageSendEvent_SendClosingSigned_class =
757                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKMessageSendEvent$SendClosingSigned;"));
758         CHECK(LDKMessageSendEvent_SendClosingSigned_class != NULL);
759         LDKMessageSendEvent_SendClosingSigned_meth = (*env)->GetMethodID(env, LDKMessageSendEvent_SendClosingSigned_class, "<init>", "([BJ)V");
760         CHECK(LDKMessageSendEvent_SendClosingSigned_meth != NULL);
761         LDKMessageSendEvent_SendShutdown_class =
762                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKMessageSendEvent$SendShutdown;"));
763         CHECK(LDKMessageSendEvent_SendShutdown_class != NULL);
764         LDKMessageSendEvent_SendShutdown_meth = (*env)->GetMethodID(env, LDKMessageSendEvent_SendShutdown_class, "<init>", "([BJ)V");
765         CHECK(LDKMessageSendEvent_SendShutdown_meth != NULL);
766         LDKMessageSendEvent_SendChannelReestablish_class =
767                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKMessageSendEvent$SendChannelReestablish;"));
768         CHECK(LDKMessageSendEvent_SendChannelReestablish_class != NULL);
769         LDKMessageSendEvent_SendChannelReestablish_meth = (*env)->GetMethodID(env, LDKMessageSendEvent_SendChannelReestablish_class, "<init>", "([BJ)V");
770         CHECK(LDKMessageSendEvent_SendChannelReestablish_meth != NULL);
771         LDKMessageSendEvent_BroadcastChannelAnnouncement_class =
772                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKMessageSendEvent$BroadcastChannelAnnouncement;"));
773         CHECK(LDKMessageSendEvent_BroadcastChannelAnnouncement_class != NULL);
774         LDKMessageSendEvent_BroadcastChannelAnnouncement_meth = (*env)->GetMethodID(env, LDKMessageSendEvent_BroadcastChannelAnnouncement_class, "<init>", "(JJ)V");
775         CHECK(LDKMessageSendEvent_BroadcastChannelAnnouncement_meth != NULL);
776         LDKMessageSendEvent_BroadcastNodeAnnouncement_class =
777                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKMessageSendEvent$BroadcastNodeAnnouncement;"));
778         CHECK(LDKMessageSendEvent_BroadcastNodeAnnouncement_class != NULL);
779         LDKMessageSendEvent_BroadcastNodeAnnouncement_meth = (*env)->GetMethodID(env, LDKMessageSendEvent_BroadcastNodeAnnouncement_class, "<init>", "(J)V");
780         CHECK(LDKMessageSendEvent_BroadcastNodeAnnouncement_meth != NULL);
781         LDKMessageSendEvent_BroadcastChannelUpdate_class =
782                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKMessageSendEvent$BroadcastChannelUpdate;"));
783         CHECK(LDKMessageSendEvent_BroadcastChannelUpdate_class != NULL);
784         LDKMessageSendEvent_BroadcastChannelUpdate_meth = (*env)->GetMethodID(env, LDKMessageSendEvent_BroadcastChannelUpdate_class, "<init>", "(J)V");
785         CHECK(LDKMessageSendEvent_BroadcastChannelUpdate_meth != NULL);
786         LDKMessageSendEvent_HandleError_class =
787                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKMessageSendEvent$HandleError;"));
788         CHECK(LDKMessageSendEvent_HandleError_class != NULL);
789         LDKMessageSendEvent_HandleError_meth = (*env)->GetMethodID(env, LDKMessageSendEvent_HandleError_class, "<init>", "([BJ)V");
790         CHECK(LDKMessageSendEvent_HandleError_meth != NULL);
791         LDKMessageSendEvent_PaymentFailureNetworkUpdate_class =
792                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKMessageSendEvent$PaymentFailureNetworkUpdate;"));
793         CHECK(LDKMessageSendEvent_PaymentFailureNetworkUpdate_class != NULL);
794         LDKMessageSendEvent_PaymentFailureNetworkUpdate_meth = (*env)->GetMethodID(env, LDKMessageSendEvent_PaymentFailureNetworkUpdate_class, "<init>", "(J)V");
795         CHECK(LDKMessageSendEvent_PaymentFailureNetworkUpdate_meth != NULL);
796         LDKMessageSendEvent_SendChannelRangeQuery_class =
797                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKMessageSendEvent$SendChannelRangeQuery;"));
798         CHECK(LDKMessageSendEvent_SendChannelRangeQuery_class != NULL);
799         LDKMessageSendEvent_SendChannelRangeQuery_meth = (*env)->GetMethodID(env, LDKMessageSendEvent_SendChannelRangeQuery_class, "<init>", "([BJ)V");
800         CHECK(LDKMessageSendEvent_SendChannelRangeQuery_meth != NULL);
801         LDKMessageSendEvent_SendShortIdsQuery_class =
802                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKMessageSendEvent$SendShortIdsQuery;"));
803         CHECK(LDKMessageSendEvent_SendShortIdsQuery_class != NULL);
804         LDKMessageSendEvent_SendShortIdsQuery_meth = (*env)->GetMethodID(env, LDKMessageSendEvent_SendShortIdsQuery_class, "<init>", "([BJ)V");
805         CHECK(LDKMessageSendEvent_SendShortIdsQuery_meth != NULL);
806 }
807 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKMessageSendEvent_1ref_1from_1ptr (JNIEnv * _env, jclass _c, jlong ptr) {
808         LDKMessageSendEvent *obj = (LDKMessageSendEvent*)ptr;
809         switch(obj->tag) {
810                 case LDKMessageSendEvent_SendAcceptChannel: {
811                         jbyteArray node_id_arr = (*_env)->NewByteArray(_env, 33);
812                         (*_env)->SetByteArrayRegion(_env, node_id_arr, 0, 33, obj->send_accept_channel.node_id.compressed_form);
813                         LDKAcceptChannel msg_var = obj->send_accept_channel.msg;
814                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
815                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
816                         long msg_ref = (long)msg_var.inner & ~1;
817                         return (*_env)->NewObject(_env, LDKMessageSendEvent_SendAcceptChannel_class, LDKMessageSendEvent_SendAcceptChannel_meth, node_id_arr, msg_ref);
818                 }
819                 case LDKMessageSendEvent_SendOpenChannel: {
820                         jbyteArray node_id_arr = (*_env)->NewByteArray(_env, 33);
821                         (*_env)->SetByteArrayRegion(_env, node_id_arr, 0, 33, obj->send_open_channel.node_id.compressed_form);
822                         LDKOpenChannel msg_var = obj->send_open_channel.msg;
823                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
824                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
825                         long msg_ref = (long)msg_var.inner & ~1;
826                         return (*_env)->NewObject(_env, LDKMessageSendEvent_SendOpenChannel_class, LDKMessageSendEvent_SendOpenChannel_meth, node_id_arr, msg_ref);
827                 }
828                 case LDKMessageSendEvent_SendFundingCreated: {
829                         jbyteArray node_id_arr = (*_env)->NewByteArray(_env, 33);
830                         (*_env)->SetByteArrayRegion(_env, node_id_arr, 0, 33, obj->send_funding_created.node_id.compressed_form);
831                         LDKFundingCreated msg_var = obj->send_funding_created.msg;
832                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
833                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
834                         long msg_ref = (long)msg_var.inner & ~1;
835                         return (*_env)->NewObject(_env, LDKMessageSendEvent_SendFundingCreated_class, LDKMessageSendEvent_SendFundingCreated_meth, node_id_arr, msg_ref);
836                 }
837                 case LDKMessageSendEvent_SendFundingSigned: {
838                         jbyteArray node_id_arr = (*_env)->NewByteArray(_env, 33);
839                         (*_env)->SetByteArrayRegion(_env, node_id_arr, 0, 33, obj->send_funding_signed.node_id.compressed_form);
840                         LDKFundingSigned msg_var = obj->send_funding_signed.msg;
841                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
842                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
843                         long msg_ref = (long)msg_var.inner & ~1;
844                         return (*_env)->NewObject(_env, LDKMessageSendEvent_SendFundingSigned_class, LDKMessageSendEvent_SendFundingSigned_meth, node_id_arr, msg_ref);
845                 }
846                 case LDKMessageSendEvent_SendFundingLocked: {
847                         jbyteArray node_id_arr = (*_env)->NewByteArray(_env, 33);
848                         (*_env)->SetByteArrayRegion(_env, node_id_arr, 0, 33, obj->send_funding_locked.node_id.compressed_form);
849                         LDKFundingLocked msg_var = obj->send_funding_locked.msg;
850                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
851                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
852                         long msg_ref = (long)msg_var.inner & ~1;
853                         return (*_env)->NewObject(_env, LDKMessageSendEvent_SendFundingLocked_class, LDKMessageSendEvent_SendFundingLocked_meth, node_id_arr, msg_ref);
854                 }
855                 case LDKMessageSendEvent_SendAnnouncementSignatures: {
856                         jbyteArray node_id_arr = (*_env)->NewByteArray(_env, 33);
857                         (*_env)->SetByteArrayRegion(_env, node_id_arr, 0, 33, obj->send_announcement_signatures.node_id.compressed_form);
858                         LDKAnnouncementSignatures msg_var = obj->send_announcement_signatures.msg;
859                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
860                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
861                         long msg_ref = (long)msg_var.inner & ~1;
862                         return (*_env)->NewObject(_env, LDKMessageSendEvent_SendAnnouncementSignatures_class, LDKMessageSendEvent_SendAnnouncementSignatures_meth, node_id_arr, msg_ref);
863                 }
864                 case LDKMessageSendEvent_UpdateHTLCs: {
865                         jbyteArray node_id_arr = (*_env)->NewByteArray(_env, 33);
866                         (*_env)->SetByteArrayRegion(_env, node_id_arr, 0, 33, obj->update_htl_cs.node_id.compressed_form);
867                         LDKCommitmentUpdate updates_var = obj->update_htl_cs.updates;
868                         CHECK((((long)updates_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
869                         CHECK((((long)&updates_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
870                         long updates_ref = (long)updates_var.inner & ~1;
871                         return (*_env)->NewObject(_env, LDKMessageSendEvent_UpdateHTLCs_class, LDKMessageSendEvent_UpdateHTLCs_meth, node_id_arr, updates_ref);
872                 }
873                 case LDKMessageSendEvent_SendRevokeAndACK: {
874                         jbyteArray node_id_arr = (*_env)->NewByteArray(_env, 33);
875                         (*_env)->SetByteArrayRegion(_env, node_id_arr, 0, 33, obj->send_revoke_and_ack.node_id.compressed_form);
876                         LDKRevokeAndACK msg_var = obj->send_revoke_and_ack.msg;
877                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
878                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
879                         long msg_ref = (long)msg_var.inner & ~1;
880                         return (*_env)->NewObject(_env, LDKMessageSendEvent_SendRevokeAndACK_class, LDKMessageSendEvent_SendRevokeAndACK_meth, node_id_arr, msg_ref);
881                 }
882                 case LDKMessageSendEvent_SendClosingSigned: {
883                         jbyteArray node_id_arr = (*_env)->NewByteArray(_env, 33);
884                         (*_env)->SetByteArrayRegion(_env, node_id_arr, 0, 33, obj->send_closing_signed.node_id.compressed_form);
885                         LDKClosingSigned msg_var = obj->send_closing_signed.msg;
886                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
887                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
888                         long msg_ref = (long)msg_var.inner & ~1;
889                         return (*_env)->NewObject(_env, LDKMessageSendEvent_SendClosingSigned_class, LDKMessageSendEvent_SendClosingSigned_meth, node_id_arr, msg_ref);
890                 }
891                 case LDKMessageSendEvent_SendShutdown: {
892                         jbyteArray node_id_arr = (*_env)->NewByteArray(_env, 33);
893                         (*_env)->SetByteArrayRegion(_env, node_id_arr, 0, 33, obj->send_shutdown.node_id.compressed_form);
894                         LDKShutdown msg_var = obj->send_shutdown.msg;
895                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
896                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
897                         long msg_ref = (long)msg_var.inner & ~1;
898                         return (*_env)->NewObject(_env, LDKMessageSendEvent_SendShutdown_class, LDKMessageSendEvent_SendShutdown_meth, node_id_arr, msg_ref);
899                 }
900                 case LDKMessageSendEvent_SendChannelReestablish: {
901                         jbyteArray node_id_arr = (*_env)->NewByteArray(_env, 33);
902                         (*_env)->SetByteArrayRegion(_env, node_id_arr, 0, 33, obj->send_channel_reestablish.node_id.compressed_form);
903                         LDKChannelReestablish msg_var = obj->send_channel_reestablish.msg;
904                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
905                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
906                         long msg_ref = (long)msg_var.inner & ~1;
907                         return (*_env)->NewObject(_env, LDKMessageSendEvent_SendChannelReestablish_class, LDKMessageSendEvent_SendChannelReestablish_meth, node_id_arr, msg_ref);
908                 }
909                 case LDKMessageSendEvent_BroadcastChannelAnnouncement: {
910                         LDKChannelAnnouncement msg_var = obj->broadcast_channel_announcement.msg;
911                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
912                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
913                         long msg_ref = (long)msg_var.inner & ~1;
914                         LDKChannelUpdate update_msg_var = obj->broadcast_channel_announcement.update_msg;
915                         CHECK((((long)update_msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
916                         CHECK((((long)&update_msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
917                         long update_msg_ref = (long)update_msg_var.inner & ~1;
918                         return (*_env)->NewObject(_env, LDKMessageSendEvent_BroadcastChannelAnnouncement_class, LDKMessageSendEvent_BroadcastChannelAnnouncement_meth, msg_ref, update_msg_ref);
919                 }
920                 case LDKMessageSendEvent_BroadcastNodeAnnouncement: {
921                         LDKNodeAnnouncement msg_var = obj->broadcast_node_announcement.msg;
922                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
923                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
924                         long msg_ref = (long)msg_var.inner & ~1;
925                         return (*_env)->NewObject(_env, LDKMessageSendEvent_BroadcastNodeAnnouncement_class, LDKMessageSendEvent_BroadcastNodeAnnouncement_meth, msg_ref);
926                 }
927                 case LDKMessageSendEvent_BroadcastChannelUpdate: {
928                         LDKChannelUpdate msg_var = obj->broadcast_channel_update.msg;
929                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
930                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
931                         long msg_ref = (long)msg_var.inner & ~1;
932                         return (*_env)->NewObject(_env, LDKMessageSendEvent_BroadcastChannelUpdate_class, LDKMessageSendEvent_BroadcastChannelUpdate_meth, msg_ref);
933                 }
934                 case LDKMessageSendEvent_HandleError: {
935                         jbyteArray node_id_arr = (*_env)->NewByteArray(_env, 33);
936                         (*_env)->SetByteArrayRegion(_env, node_id_arr, 0, 33, obj->handle_error.node_id.compressed_form);
937                         long action_ref = (long)&obj->handle_error.action;
938                         return (*_env)->NewObject(_env, LDKMessageSendEvent_HandleError_class, LDKMessageSendEvent_HandleError_meth, node_id_arr, action_ref);
939                 }
940                 case LDKMessageSendEvent_PaymentFailureNetworkUpdate: {
941                         long update_ref = (long)&obj->payment_failure_network_update.update;
942                         return (*_env)->NewObject(_env, LDKMessageSendEvent_PaymentFailureNetworkUpdate_class, LDKMessageSendEvent_PaymentFailureNetworkUpdate_meth, update_ref);
943                 }
944                 case LDKMessageSendEvent_SendChannelRangeQuery: {
945                         jbyteArray node_id_arr = (*_env)->NewByteArray(_env, 33);
946                         (*_env)->SetByteArrayRegion(_env, node_id_arr, 0, 33, obj->send_channel_range_query.node_id.compressed_form);
947                         LDKQueryChannelRange msg_var = obj->send_channel_range_query.msg;
948                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
949                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
950                         long msg_ref = (long)msg_var.inner & ~1;
951                         return (*_env)->NewObject(_env, LDKMessageSendEvent_SendChannelRangeQuery_class, LDKMessageSendEvent_SendChannelRangeQuery_meth, node_id_arr, msg_ref);
952                 }
953                 case LDKMessageSendEvent_SendShortIdsQuery: {
954                         jbyteArray node_id_arr = (*_env)->NewByteArray(_env, 33);
955                         (*_env)->SetByteArrayRegion(_env, node_id_arr, 0, 33, obj->send_short_ids_query.node_id.compressed_form);
956                         LDKQueryShortChannelIds msg_var = obj->send_short_ids_query.msg;
957                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
958                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
959                         long msg_ref = (long)msg_var.inner & ~1;
960                         return (*_env)->NewObject(_env, LDKMessageSendEvent_SendShortIdsQuery_class, LDKMessageSendEvent_SendShortIdsQuery_meth, node_id_arr, msg_ref);
961                 }
962                 default: abort();
963         }
964 }
965 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKCVec_1MessageSendEventZ_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
966         LDKCVec_MessageSendEventZ *vec = (LDKCVec_MessageSendEventZ*)ptr;
967         return (*env)->NewObject(env, slicedef_cls, slicedef_meth, (long)vec->data, (long)vec->datalen, sizeof(LDKMessageSendEvent));
968 }
969 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVec_1MessageSendEventZ_1new(JNIEnv *env, jclass _b, jlongArray 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                 jlong *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
977                 for (size_t i = 0; i < ret->datalen; i++) {
978                         jlong 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 _a) {
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 _c, jlong ptr) {
1046         LDKEvent *obj = (LDKEvent*)ptr;
1047         switch(obj->tag) {
1048                 case LDKEvent_FundingGenerationReady: {
1049                         jbyteArray 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                         jbyteArray 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                         jbyteArray payment_hash_arr = (*_env)->NewByteArray(_env, 32);
1065                         (*_env)->SetByteArrayRegion(_env, payment_hash_arr, 0, 32, obj->payment_received.payment_hash.data);
1066                         jbyteArray 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                         jbyteArray 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                         jbyteArray 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                         jlongArray outputs_arr = (*_env)->NewLongArray(_env, outputs_var.datalen);
1086                         jlong *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 jobject JNICALL Java_org_ldk_impl_bindings_LDKCVec_1EventZ_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
1098         LDKCVec_EventZ *vec = (LDKCVec_EventZ*)ptr;
1099         return (*env)->NewObject(env, slicedef_cls, slicedef_meth, (long)vec->data, (long)vec->datalen, sizeof(LDKEvent));
1100 }
1101 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVec_1EventZ_1new(JNIEnv *env, jclass _b, jlongArray elems){
1102         LDKCVec_EventZ *ret = MALLOC(sizeof(LDKCVec_EventZ), "LDKCVec_EventZ");
1103         ret->datalen = (*env)->GetArrayLength(env, elems);
1104         if (ret->datalen == 0) {
1105                 ret->data = NULL;
1106         } else {
1107                 ret->data = MALLOC(sizeof(LDKEvent) * ret->datalen, "LDKCVec_EventZ Data");
1108                 jlong *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
1109                 for (size_t i = 0; i < ret->datalen; i++) {
1110                         jlong arr_elem = java_elems[i];
1111                         LDKEvent arr_elem_conv = *(LDKEvent*)arr_elem;
1112                         FREE((void*)arr_elem);
1113                         ret->data[i] = arr_elem_conv;
1114                 }
1115                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
1116         }
1117         return (long)ret;
1118 }
1119 static inline LDKCVec_EventZ CVec_EventZ_clone(const LDKCVec_EventZ *orig) {
1120         LDKCVec_EventZ ret = { .data = MALLOC(sizeof(LDKEvent) * orig->datalen, "LDKCVec_EventZ clone bytes"), .datalen = orig->datalen };
1121         for (size_t i = 0; i < ret.datalen; i++) {
1122                 ret.data[i] = Event_clone(&orig->data[i]);
1123         }
1124         return ret;
1125 }
1126 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKC2Tuple_1usizeTransactionZ_1new(JNIEnv *_env, jclass _b, jlong a, jbyteArray b) {
1127         LDKC2Tuple_usizeTransactionZ* ret = MALLOC(sizeof(LDKC2Tuple_usizeTransactionZ), "LDKC2Tuple_usizeTransactionZ");
1128         ret->a = a;
1129         LDKTransaction b_ref;
1130         b_ref.datalen = (*_env)->GetArrayLength (_env, b);
1131         b_ref.data = MALLOC(b_ref.datalen, "LDKTransaction Bytes");
1132         (*_env)->GetByteArrayRegion(_env, b, 0, b_ref.datalen, b_ref.data);
1133         b_ref.data_is_owned = false;
1134         ret->b = b_ref;
1135         return (long)ret;
1136 }
1137 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKC2Tuple_1usizeTransactionZ_1get_1a(JNIEnv *_env, jclass _b, jlong ptr) {
1138         LDKC2Tuple_usizeTransactionZ *tuple = (LDKC2Tuple_usizeTransactionZ*)ptr;
1139         return tuple->a;
1140 }
1141 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_LDKC2Tuple_1usizeTransactionZ_1get_1b(JNIEnv *_env, jclass _b, jlong ptr) {
1142         LDKC2Tuple_usizeTransactionZ *tuple = (LDKC2Tuple_usizeTransactionZ*)ptr;
1143         LDKTransaction b_var = tuple->b;
1144         jbyteArray b_arr = (*_env)->NewByteArray(_env, b_var.datalen);
1145         (*_env)->SetByteArrayRegion(_env, b_arr, 0, b_var.datalen, b_var.data);
1146         return b_arr;
1147 }
1148 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKCVec_1C2Tuple_1usizeTransactionZZ_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
1149         LDKCVec_C2Tuple_usizeTransactionZZ *vec = (LDKCVec_C2Tuple_usizeTransactionZZ*)ptr;
1150         return (*env)->NewObject(env, slicedef_cls, slicedef_meth, (long)vec->data, (long)vec->datalen, sizeof(LDKC2Tuple_usizeTransactionZ));
1151 }
1152 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVec_1C2Tuple_1usizeTransactionZZ_1new(JNIEnv *env, jclass _b, jlongArray elems){
1153         LDKCVec_C2Tuple_usizeTransactionZZ *ret = MALLOC(sizeof(LDKCVec_C2Tuple_usizeTransactionZZ), "LDKCVec_C2Tuple_usizeTransactionZZ");
1154         ret->datalen = (*env)->GetArrayLength(env, elems);
1155         if (ret->datalen == 0) {
1156                 ret->data = NULL;
1157         } else {
1158                 ret->data = MALLOC(sizeof(LDKC2Tuple_usizeTransactionZ) * ret->datalen, "LDKCVec_C2Tuple_usizeTransactionZZ Data");
1159                 jlong *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
1160                 for (size_t i = 0; i < ret->datalen; i++) {
1161                         jlong arr_elem = java_elems[i];
1162                         LDKC2Tuple_usizeTransactionZ arr_elem_conv = *(LDKC2Tuple_usizeTransactionZ*)arr_elem;
1163                         FREE((void*)arr_elem);
1164                         ret->data[i] = arr_elem_conv;
1165                 }
1166                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
1167         }
1168         return (long)ret;
1169 }
1170 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NoneChannelMonitorUpdateErrZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
1171         return ((LDKCResult_NoneChannelMonitorUpdateErrZ*)arg)->result_ok;
1172 }
1173 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NoneChannelMonitorUpdateErrZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
1174         LDKCResult_NoneChannelMonitorUpdateErrZ *val = (LDKCResult_NoneChannelMonitorUpdateErrZ*)arg;
1175         CHECK(val->result_ok);
1176         return *val->contents.result;
1177 }
1178 JNIEXPORT jclass JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NoneChannelMonitorUpdateErrZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
1179         LDKCResult_NoneChannelMonitorUpdateErrZ *val = (LDKCResult_NoneChannelMonitorUpdateErrZ*)arg;
1180         CHECK(!val->result_ok);
1181         jclass err_conv = LDKChannelMonitorUpdateErr_to_java(_env, (*val->contents.err));
1182         return err_conv;
1183 }
1184 static inline LDKCResult_NoneChannelMonitorUpdateErrZ CResult_NoneChannelMonitorUpdateErrZ_clone(const LDKCResult_NoneChannelMonitorUpdateErrZ *orig) {
1185         LDKCResult_NoneChannelMonitorUpdateErrZ res = { .result_ok = orig->result_ok };
1186         if (orig->result_ok) {
1187                 res.contents.result = NULL;
1188         } else {
1189                 LDKChannelMonitorUpdateErr* contents = MALLOC(sizeof(LDKChannelMonitorUpdateErr), "LDKChannelMonitorUpdateErr result Err clone");
1190                 *contents = ChannelMonitorUpdateErr_clone(orig->contents.err);
1191                 res.contents.err = contents;
1192         }
1193         return res;
1194 }
1195 JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_LDKCVec_1MonitorEventZ_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
1196         LDKCVec_MonitorEventZ *vec = (LDKCVec_MonitorEventZ*)ptr;
1197         jlongArray ret = (*env)->NewLongArray(env, vec->datalen);
1198         jlong *ret_elems = (*env)->GetPrimitiveArrayCritical(env, ret, NULL);
1199         for (size_t i = 0; i < vec->datalen; i++) {
1200                 CHECK((((long)vec->data[i].inner) & 1) == 0);
1201                 ret_elems[i] = (long)vec->data[i].inner | (vec->data[i].is_owned ? 1 : 0);
1202         }
1203         (*env)->ReleasePrimitiveArrayCritical(env, ret, ret_elems, 0);
1204         return ret;
1205 }
1206 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVec_1MonitorEventZ_1new(JNIEnv *env, jclass _b, jlongArray elems){
1207         LDKCVec_MonitorEventZ *ret = MALLOC(sizeof(LDKCVec_MonitorEventZ), "LDKCVec_MonitorEventZ");
1208         ret->datalen = (*env)->GetArrayLength(env, elems);
1209         if (ret->datalen == 0) {
1210                 ret->data = NULL;
1211         } else {
1212                 ret->data = MALLOC(sizeof(LDKMonitorEvent) * ret->datalen, "LDKCVec_MonitorEventZ Data");
1213                 jlong *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
1214                 for (size_t i = 0; i < ret->datalen; i++) {
1215                         jlong arr_elem = java_elems[i];
1216                         LDKMonitorEvent arr_elem_conv;
1217                         arr_elem_conv.inner = (void*)(arr_elem & (~1));
1218                         arr_elem_conv.is_owned = (arr_elem & 1) || (arr_elem == 0);
1219                         if (arr_elem_conv.inner != NULL)
1220                                 arr_elem_conv = MonitorEvent_clone(&arr_elem_conv);
1221                         ret->data[i] = arr_elem_conv;
1222                 }
1223                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
1224         }
1225         return (long)ret;
1226 }
1227 static inline LDKCVec_MonitorEventZ CVec_MonitorEventZ_clone(const LDKCVec_MonitorEventZ *orig) {
1228         LDKCVec_MonitorEventZ ret = { .data = MALLOC(sizeof(LDKMonitorEvent) * orig->datalen, "LDKCVec_MonitorEventZ clone bytes"), .datalen = orig->datalen };
1229         for (size_t i = 0; i < ret.datalen; i++) {
1230                 ret.data[i] = MonitorEvent_clone(&orig->data[i]);
1231         }
1232         return ret;
1233 }
1234 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1ChannelMonitorUpdateDecodeErrorZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
1235         return ((LDKCResult_ChannelMonitorUpdateDecodeErrorZ*)arg)->result_ok;
1236 }
1237 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1ChannelMonitorUpdateDecodeErrorZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
1238         LDKCResult_ChannelMonitorUpdateDecodeErrorZ *val = (LDKCResult_ChannelMonitorUpdateDecodeErrorZ*)arg;
1239         CHECK(val->result_ok);
1240         LDKChannelMonitorUpdate res_var = (*val->contents.result);
1241         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1242         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1243         long res_ref = (long)res_var.inner & ~1;
1244         return res_ref;
1245 }
1246 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1ChannelMonitorUpdateDecodeErrorZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
1247         LDKCResult_ChannelMonitorUpdateDecodeErrorZ *val = (LDKCResult_ChannelMonitorUpdateDecodeErrorZ*)arg;
1248         CHECK(!val->result_ok);
1249         LDKDecodeError err_var = (*val->contents.err);
1250         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1251         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1252         long err_ref = (long)err_var.inner & ~1;
1253         return err_ref;
1254 }
1255 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NoneMonitorUpdateErrorZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
1256         return ((LDKCResult_NoneMonitorUpdateErrorZ*)arg)->result_ok;
1257 }
1258 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NoneMonitorUpdateErrorZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
1259         LDKCResult_NoneMonitorUpdateErrorZ *val = (LDKCResult_NoneMonitorUpdateErrorZ*)arg;
1260         CHECK(val->result_ok);
1261         return *val->contents.result;
1262 }
1263 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NoneMonitorUpdateErrorZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
1264         LDKCResult_NoneMonitorUpdateErrorZ *val = (LDKCResult_NoneMonitorUpdateErrorZ*)arg;
1265         CHECK(!val->result_ok);
1266         LDKMonitorUpdateError err_var = (*val->contents.err);
1267         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1268         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1269         long err_ref = (long)err_var.inner & ~1;
1270         return err_ref;
1271 }
1272 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKC2Tuple_1OutPointScriptZ_1new(JNIEnv *_env, jclass _b, jlong a, jbyteArray b) {
1273         LDKC2Tuple_OutPointScriptZ* ret = MALLOC(sizeof(LDKC2Tuple_OutPointScriptZ), "LDKC2Tuple_OutPointScriptZ");
1274         LDKOutPoint a_conv;
1275         a_conv.inner = (void*)(a & (~1));
1276         a_conv.is_owned = (a & 1) || (a == 0);
1277         if (a_conv.inner != NULL)
1278                 a_conv = OutPoint_clone(&a_conv);
1279         ret->a = a_conv;
1280         LDKCVec_u8Z b_ref;
1281         b_ref.datalen = (*_env)->GetArrayLength (_env, b);
1282         b_ref.data = MALLOC(b_ref.datalen, "LDKCVec_u8Z Bytes");
1283         (*_env)->GetByteArrayRegion(_env, b, 0, b_ref.datalen, b_ref.data);
1284         ret->b = b_ref;
1285         return (long)ret;
1286 }
1287 static inline LDKC2Tuple_OutPointScriptZ C2Tuple_OutPointScriptZ_clone(const LDKC2Tuple_OutPointScriptZ *orig) {
1288         LDKC2Tuple_OutPointScriptZ ret = {
1289                 .a = OutPoint_clone(&orig->a),
1290                 .b = CVec_u8Z_clone(&orig->b),
1291         };
1292         return ret;
1293 }
1294 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKC2Tuple_1OutPointScriptZ_1get_1a(JNIEnv *_env, jclass _b, jlong ptr) {
1295         LDKC2Tuple_OutPointScriptZ *tuple = (LDKC2Tuple_OutPointScriptZ*)ptr;
1296         LDKOutPoint a_var = tuple->a;
1297         CHECK((((long)a_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1298         CHECK((((long)&a_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1299         long a_ref = (long)a_var.inner & ~1;
1300         return a_ref;
1301 }
1302 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_LDKC2Tuple_1OutPointScriptZ_1get_1b(JNIEnv *_env, jclass _b, jlong ptr) {
1303         LDKC2Tuple_OutPointScriptZ *tuple = (LDKC2Tuple_OutPointScriptZ*)ptr;
1304         LDKCVec_u8Z b_var = tuple->b;
1305         jbyteArray b_arr = (*_env)->NewByteArray(_env, b_var.datalen);
1306         (*_env)->SetByteArrayRegion(_env, b_arr, 0, b_var.datalen, b_var.data);
1307         return b_arr;
1308 }
1309 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKCVec_1TransactionZ_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
1310         LDKCVec_TransactionZ *vec = (LDKCVec_TransactionZ*)ptr;
1311         return (*env)->NewObject(env, slicedef_cls, slicedef_meth, (long)vec->data, (long)vec->datalen, sizeof(LDKTransaction));
1312 }
1313 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKC2Tuple_1u32TxOutZ_1new(JNIEnv *_env, jclass _b, jint a, jlong b) {
1314         LDKC2Tuple_u32TxOutZ* ret = MALLOC(sizeof(LDKC2Tuple_u32TxOutZ), "LDKC2Tuple_u32TxOutZ");
1315         ret->a = a;
1316         LDKTxOut b_conv = *(LDKTxOut*)b;
1317         FREE((void*)b);
1318         ret->b = b_conv;
1319         return (long)ret;
1320 }
1321 static inline LDKC2Tuple_u32TxOutZ C2Tuple_u32TxOutZ_clone(const LDKC2Tuple_u32TxOutZ *orig) {
1322         LDKC2Tuple_u32TxOutZ ret = {
1323                 .a = orig->a,
1324                 .b = TxOut_clone(&orig->b),
1325         };
1326         return ret;
1327 }
1328 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_LDKC2Tuple_1u32TxOutZ_1get_1a(JNIEnv *_env, jclass _b, jlong ptr) {
1329         LDKC2Tuple_u32TxOutZ *tuple = (LDKC2Tuple_u32TxOutZ*)ptr;
1330         return tuple->a;
1331 }
1332 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKC2Tuple_1u32TxOutZ_1get_1b(JNIEnv *_env, jclass _b, jlong ptr) {
1333         LDKC2Tuple_u32TxOutZ *tuple = (LDKC2Tuple_u32TxOutZ*)ptr;
1334         long b_ref = (long)&tuple->b;
1335         return (long)b_ref;
1336 }
1337 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKCVec_1C2Tuple_1u32TxOutZZ_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
1338         LDKCVec_C2Tuple_u32TxOutZZ *vec = (LDKCVec_C2Tuple_u32TxOutZZ*)ptr;
1339         return (*env)->NewObject(env, slicedef_cls, slicedef_meth, (long)vec->data, (long)vec->datalen, sizeof(LDKC2Tuple_u32TxOutZ));
1340 }
1341 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVec_1C2Tuple_1u32TxOutZZ_1new(JNIEnv *env, jclass _b, jlongArray elems){
1342         LDKCVec_C2Tuple_u32TxOutZZ *ret = MALLOC(sizeof(LDKCVec_C2Tuple_u32TxOutZZ), "LDKCVec_C2Tuple_u32TxOutZZ");
1343         ret->datalen = (*env)->GetArrayLength(env, elems);
1344         if (ret->datalen == 0) {
1345                 ret->data = NULL;
1346         } else {
1347                 ret->data = MALLOC(sizeof(LDKC2Tuple_u32TxOutZ) * ret->datalen, "LDKCVec_C2Tuple_u32TxOutZZ Data");
1348                 jlong *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
1349                 for (size_t i = 0; i < ret->datalen; i++) {
1350                         jlong arr_elem = java_elems[i];
1351                         LDKC2Tuple_u32TxOutZ arr_elem_conv = *(LDKC2Tuple_u32TxOutZ*)arr_elem;
1352                         FREE((void*)arr_elem);
1353                         ret->data[i] = arr_elem_conv;
1354                 }
1355                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
1356         }
1357         return (long)ret;
1358 }
1359 static inline LDKCVec_C2Tuple_u32TxOutZZ CVec_C2Tuple_u32TxOutZZ_clone(const LDKCVec_C2Tuple_u32TxOutZZ *orig) {
1360         LDKCVec_C2Tuple_u32TxOutZZ ret = { .data = MALLOC(sizeof(LDKC2Tuple_u32TxOutZ) * orig->datalen, "LDKCVec_C2Tuple_u32TxOutZZ clone bytes"), .datalen = orig->datalen };
1361         for (size_t i = 0; i < ret.datalen; i++) {
1362                 ret.data[i] = C2Tuple_u32TxOutZ_clone(&orig->data[i]);
1363         }
1364         return ret;
1365 }
1366 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKC2Tuple_1TxidCVec_1C2Tuple_1u32TxOutZZZ_1new(JNIEnv *_env, jclass _b, jbyteArray a, jlongArray b) {
1367         LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ* ret = MALLOC(sizeof(LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ), "LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ");
1368         LDKThirtyTwoBytes a_ref;
1369         CHECK((*_env)->GetArrayLength (_env, a) == 32);
1370         (*_env)->GetByteArrayRegion (_env, a, 0, 32, a_ref.data);
1371         ret->a = a_ref;
1372         LDKCVec_C2Tuple_u32TxOutZZ b_constr;
1373         b_constr.datalen = (*_env)->GetArrayLength (_env, b);
1374         if (b_constr.datalen > 0)
1375                 b_constr.data = MALLOC(b_constr.datalen * sizeof(LDKC2Tuple_u32TxOutZ), "LDKCVec_C2Tuple_u32TxOutZZ Elements");
1376         else
1377                 b_constr.data = NULL;
1378         long* b_vals = (*_env)->GetLongArrayElements (_env, b, NULL);
1379         for (size_t a = 0; a < b_constr.datalen; a++) {
1380                 long arr_conv_26 = b_vals[a];
1381                 LDKC2Tuple_u32TxOutZ arr_conv_26_conv = *(LDKC2Tuple_u32TxOutZ*)arr_conv_26;
1382                 FREE((void*)arr_conv_26);
1383                 b_constr.data[a] = arr_conv_26_conv;
1384         }
1385         (*_env)->ReleaseLongArrayElements (_env, b, b_vals, 0);
1386         ret->b = b_constr;
1387         return (long)ret;
1388 }
1389 static inline LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ_clone(const LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ *orig) {
1390         LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ ret = {
1391                 .a = ThirtyTwoBytes_clone(&orig->a),
1392                 .b = CVec_C2Tuple_u32TxOutZZ_clone(&orig->b),
1393         };
1394         return ret;
1395 }
1396 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_LDKC2Tuple_1TxidCVec_1C2Tuple_1u32TxOutZZZ_1get_1a(JNIEnv *_env, jclass _b, jlong ptr) {
1397         LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ *tuple = (LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ*)ptr;
1398         jbyteArray a_arr = (*_env)->NewByteArray(_env, 32);
1399         (*_env)->SetByteArrayRegion(_env, a_arr, 0, 32, tuple->a.data);
1400         return a_arr;
1401 }
1402 JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_LDKC2Tuple_1TxidCVec_1C2Tuple_1u32TxOutZZZ_1get_1b(JNIEnv *_env, jclass _b, jlong ptr) {
1403         LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ *tuple = (LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ*)ptr;
1404         LDKCVec_C2Tuple_u32TxOutZZ b_var = tuple->b;
1405         jlongArray b_arr = (*_env)->NewLongArray(_env, b_var.datalen);
1406         jlong *b_arr_ptr = (*_env)->GetPrimitiveArrayCritical(_env, b_arr, NULL);
1407         for (size_t a = 0; a < b_var.datalen; a++) {
1408                 long arr_conv_26_ref = (long)&b_var.data[a];
1409                 b_arr_ptr[a] = arr_conv_26_ref;
1410         }
1411         (*_env)->ReleasePrimitiveArrayCritical(_env, b_arr, b_arr_ptr, 0);
1412         return b_arr;
1413 }
1414 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKCVec_1C2Tuple_1TxidCVec_1C2Tuple_1u32TxOutZZZZ_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
1415         LDKCVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ *vec = (LDKCVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ*)ptr;
1416         return (*env)->NewObject(env, slicedef_cls, slicedef_meth, (long)vec->data, (long)vec->datalen, sizeof(LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ));
1417 }
1418 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVec_1C2Tuple_1TxidCVec_1C2Tuple_1u32TxOutZZZZ_1new(JNIEnv *env, jclass _b, jlongArray elems){
1419         LDKCVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ *ret = MALLOC(sizeof(LDKCVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ), "LDKCVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ");
1420         ret->datalen = (*env)->GetArrayLength(env, elems);
1421         if (ret->datalen == 0) {
1422                 ret->data = NULL;
1423         } else {
1424                 ret->data = MALLOC(sizeof(LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ) * ret->datalen, "LDKCVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ Data");
1425                 jlong *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
1426                 for (size_t i = 0; i < ret->datalen; i++) {
1427                         jlong arr_elem = java_elems[i];
1428                         LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ arr_elem_conv = *(LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ*)arr_elem;
1429                         FREE((void*)arr_elem);
1430                         ret->data[i] = arr_elem_conv;
1431                 }
1432                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
1433         }
1434         return (long)ret;
1435 }
1436 static inline LDKCVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ CVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ_clone(const LDKCVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ *orig) {
1437         LDKCVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ ret = { .data = MALLOC(sizeof(LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ) * orig->datalen, "LDKCVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ clone bytes"), .datalen = orig->datalen };
1438         for (size_t i = 0; i < ret.datalen; i++) {
1439                 ret.data[i] = C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ_clone(&orig->data[i]);
1440         }
1441         return ret;
1442 }
1443 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKCVec_1SignatureZ_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
1444         LDKCVec_SignatureZ *vec = (LDKCVec_SignatureZ*)ptr;
1445         return (*env)->NewObject(env, slicedef_cls, slicedef_meth, (long)vec->data, (long)vec->datalen, sizeof(LDKSignature));
1446 }
1447 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKC2Tuple_1SignatureCVec_1SignatureZZ_1new(JNIEnv *_env, jclass _b, jbyteArray a, jobjectArray b) {
1448         LDKC2Tuple_SignatureCVec_SignatureZZ* ret = MALLOC(sizeof(LDKC2Tuple_SignatureCVec_SignatureZZ), "LDKC2Tuple_SignatureCVec_SignatureZZ");
1449         LDKSignature a_ref;
1450         CHECK((*_env)->GetArrayLength (_env, a) == 64);
1451         (*_env)->GetByteArrayRegion (_env, a, 0, 64, a_ref.compact_form);
1452         ret->a = a_ref;
1453         LDKCVec_SignatureZ b_constr;
1454         b_constr.datalen = (*_env)->GetArrayLength (_env, b);
1455         if (b_constr.datalen > 0)
1456                 b_constr.data = MALLOC(b_constr.datalen * sizeof(LDKSignature), "LDKCVec_SignatureZ Elements");
1457         else
1458                 b_constr.data = NULL;
1459         for (size_t i = 0; i < b_constr.datalen; i++) {
1460                 jobject arr_conv_8 = (*_env)->GetObjectArrayElement(_env, b, i);
1461                 LDKSignature arr_conv_8_ref;
1462                 CHECK((*_env)->GetArrayLength (_env, arr_conv_8) == 64);
1463                 (*_env)->GetByteArrayRegion (_env, arr_conv_8, 0, 64, arr_conv_8_ref.compact_form);
1464                 b_constr.data[i] = arr_conv_8_ref;
1465         }
1466         ret->b = b_constr;
1467         return (long)ret;
1468 }
1469 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_LDKC2Tuple_1SignatureCVec_1SignatureZZ_1get_1a(JNIEnv *_env, jclass _b, jlong ptr) {
1470         LDKC2Tuple_SignatureCVec_SignatureZZ *tuple = (LDKC2Tuple_SignatureCVec_SignatureZZ*)ptr;
1471         jbyteArray a_arr = (*_env)->NewByteArray(_env, 64);
1472         (*_env)->SetByteArrayRegion(_env, a_arr, 0, 64, tuple->a.compact_form);
1473         return a_arr;
1474 }
1475 JNIEXPORT jobjectArray JNICALL Java_org_ldk_impl_bindings_LDKC2Tuple_1SignatureCVec_1SignatureZZ_1get_1b(JNIEnv *_env, jclass _b, jlong ptr) {
1476         LDKC2Tuple_SignatureCVec_SignatureZZ *tuple = (LDKC2Tuple_SignatureCVec_SignatureZZ*)ptr;
1477         LDKCVec_SignatureZ b_var = tuple->b;
1478         jobjectArray b_arr = (*_env)->NewObjectArray(_env, b_var.datalen, arr_of_B_clz, NULL);
1479         for (size_t i = 0; i < b_var.datalen; i++) {
1480                 jbyteArray arr_conv_8_arr = (*_env)->NewByteArray(_env, 64);
1481                 (*_env)->SetByteArrayRegion(_env, arr_conv_8_arr, 0, 64, b_var.data[i].compact_form);
1482                 (*_env)->SetObjectArrayElement(_env, b_arr, i, arr_conv_8_arr);
1483         }
1484         return b_arr;
1485 }
1486 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1C2Tuple_1SignatureCVec_1SignatureZZNoneZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
1487         return ((LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ*)arg)->result_ok;
1488 }
1489 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1C2Tuple_1SignatureCVec_1SignatureZZNoneZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
1490         LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ *val = (LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ*)arg;
1491         CHECK(val->result_ok);
1492         long res_ref = (long)&(*val->contents.result);
1493         return res_ref;
1494 }
1495 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_LDKCResult_1C2Tuple_1SignatureCVec_1SignatureZZNoneZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
1496         LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ *val = (LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ*)arg;
1497         CHECK(!val->result_ok);
1498         return *val->contents.err;
1499 }
1500 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1SignatureNoneZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
1501         return ((LDKCResult_SignatureNoneZ*)arg)->result_ok;
1502 }
1503 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_LDKCResult_1SignatureNoneZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
1504         LDKCResult_SignatureNoneZ *val = (LDKCResult_SignatureNoneZ*)arg;
1505         CHECK(val->result_ok);
1506         jbyteArray res_arr = (*_env)->NewByteArray(_env, 64);
1507         (*_env)->SetByteArrayRegion(_env, res_arr, 0, 64, (*val->contents.result).compact_form);
1508         return res_arr;
1509 }
1510 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_LDKCResult_1SignatureNoneZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
1511         LDKCResult_SignatureNoneZ *val = (LDKCResult_SignatureNoneZ*)arg;
1512         CHECK(!val->result_ok);
1513         return *val->contents.err;
1514 }
1515 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1CVec_1SignatureZNoneZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
1516         return ((LDKCResult_CVec_SignatureZNoneZ*)arg)->result_ok;
1517 }
1518 JNIEXPORT jobjectArray JNICALL Java_org_ldk_impl_bindings_LDKCResult_1CVec_1SignatureZNoneZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
1519         LDKCResult_CVec_SignatureZNoneZ *val = (LDKCResult_CVec_SignatureZNoneZ*)arg;
1520         CHECK(val->result_ok);
1521         LDKCVec_SignatureZ res_var = (*val->contents.result);
1522         jobjectArray res_arr = (*_env)->NewObjectArray(_env, res_var.datalen, arr_of_B_clz, NULL);
1523         for (size_t i = 0; i < res_var.datalen; i++) {
1524                 jbyteArray arr_conv_8_arr = (*_env)->NewByteArray(_env, 64);
1525                 (*_env)->SetByteArrayRegion(_env, arr_conv_8_arr, 0, 64, res_var.data[i].compact_form);
1526                 (*_env)->SetObjectArrayElement(_env, res_arr, i, arr_conv_8_arr);
1527         }
1528         return res_arr;
1529 }
1530 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_LDKCResult_1CVec_1SignatureZNoneZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
1531         LDKCResult_CVec_SignatureZNoneZ *val = (LDKCResult_CVec_SignatureZNoneZ*)arg;
1532         CHECK(!val->result_ok);
1533         return *val->contents.err;
1534 }
1535 typedef struct LDKChannelKeys_JCalls {
1536         atomic_size_t refcnt;
1537         JavaVM *vm;
1538         jweak o;
1539         jmethodID get_per_commitment_point_meth;
1540         jmethodID release_commitment_secret_meth;
1541         jmethodID key_derivation_params_meth;
1542         jmethodID sign_counterparty_commitment_meth;
1543         jmethodID sign_holder_commitment_meth;
1544         jmethodID sign_holder_commitment_htlc_transactions_meth;
1545         jmethodID sign_justice_transaction_meth;
1546         jmethodID sign_counterparty_htlc_transaction_meth;
1547         jmethodID sign_closing_transaction_meth;
1548         jmethodID sign_channel_announcement_meth;
1549         jmethodID ready_channel_meth;
1550         jmethodID write_meth;
1551 } LDKChannelKeys_JCalls;
1552 LDKPublicKey get_per_commitment_point_jcall(const void* this_arg, uint64_t idx) {
1553         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1554         JNIEnv *_env;
1555         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
1556         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
1557         CHECK(obj != NULL);
1558         jbyteArray arg = (*_env)->CallObjectMethod(_env, obj, j_calls->get_per_commitment_point_meth, idx);
1559         LDKPublicKey arg_ref;
1560         CHECK((*_env)->GetArrayLength (_env, arg) == 33);
1561         (*_env)->GetByteArrayRegion (_env, arg, 0, 33, arg_ref.compressed_form);
1562         return arg_ref;
1563 }
1564 LDKThirtyTwoBytes release_commitment_secret_jcall(const void* this_arg, uint64_t idx) {
1565         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1566         JNIEnv *_env;
1567         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
1568         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
1569         CHECK(obj != NULL);
1570         jbyteArray arg = (*_env)->CallObjectMethod(_env, obj, j_calls->release_commitment_secret_meth, idx);
1571         LDKThirtyTwoBytes arg_ref;
1572         CHECK((*_env)->GetArrayLength (_env, arg) == 32);
1573         (*_env)->GetByteArrayRegion (_env, arg, 0, 32, arg_ref.data);
1574         return arg_ref;
1575 }
1576 LDKC2Tuple_u64u64Z key_derivation_params_jcall(const void* this_arg) {
1577         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1578         JNIEnv *_env;
1579         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
1580         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
1581         CHECK(obj != NULL);
1582         LDKC2Tuple_u64u64Z* ret = (LDKC2Tuple_u64u64Z*)(*_env)->CallLongMethod(_env, obj, j_calls->key_derivation_params_meth);
1583         LDKC2Tuple_u64u64Z ret_conv = *(LDKC2Tuple_u64u64Z*)ret;
1584         FREE((void*)ret);
1585         return ret_conv;
1586 }
1587 LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ sign_counterparty_commitment_jcall(const void* this_arg, const struct LDKCommitmentTransaction *NONNULL_PTR commitment_tx) {
1588         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1589         JNIEnv *_env;
1590         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
1591         LDKCommitmentTransaction commitment_tx_var = *commitment_tx;
1592         if (commitment_tx->inner != NULL)
1593                 commitment_tx_var = CommitmentTransaction_clone(commitment_tx);
1594         CHECK((((long)commitment_tx_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1595         CHECK((((long)&commitment_tx_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1596         long commitment_tx_ref = (long)commitment_tx_var.inner;
1597         if (commitment_tx_var.is_owned) {
1598                 commitment_tx_ref |= 1;
1599         }
1600         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
1601         CHECK(obj != NULL);
1602         LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ* ret = (LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ*)(*_env)->CallLongMethod(_env, obj, j_calls->sign_counterparty_commitment_meth, commitment_tx_ref);
1603         LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ ret_conv = *(LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ*)ret;
1604         FREE((void*)ret);
1605         return ret_conv;
1606 }
1607 LDKCResult_SignatureNoneZ sign_holder_commitment_jcall(const void* this_arg, const struct LDKHolderCommitmentTransaction *NONNULL_PTR commitment_tx) {
1608         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1609         JNIEnv *_env;
1610         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
1611         LDKHolderCommitmentTransaction commitment_tx_var = *commitment_tx;
1612         if (commitment_tx->inner != NULL)
1613                 commitment_tx_var = HolderCommitmentTransaction_clone(commitment_tx);
1614         CHECK((((long)commitment_tx_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1615         CHECK((((long)&commitment_tx_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1616         long commitment_tx_ref = (long)commitment_tx_var.inner;
1617         if (commitment_tx_var.is_owned) {
1618                 commitment_tx_ref |= 1;
1619         }
1620         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
1621         CHECK(obj != NULL);
1622         LDKCResult_SignatureNoneZ* ret = (LDKCResult_SignatureNoneZ*)(*_env)->CallLongMethod(_env, obj, j_calls->sign_holder_commitment_meth, commitment_tx_ref);
1623         LDKCResult_SignatureNoneZ ret_conv = *(LDKCResult_SignatureNoneZ*)ret;
1624         FREE((void*)ret);
1625         return ret_conv;
1626 }
1627 LDKCResult_CVec_SignatureZNoneZ sign_holder_commitment_htlc_transactions_jcall(const void* this_arg, const struct LDKHolderCommitmentTransaction *NONNULL_PTR commitment_tx) {
1628         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1629         JNIEnv *_env;
1630         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
1631         LDKHolderCommitmentTransaction commitment_tx_var = *commitment_tx;
1632         if (commitment_tx->inner != NULL)
1633                 commitment_tx_var = HolderCommitmentTransaction_clone(commitment_tx);
1634         CHECK((((long)commitment_tx_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1635         CHECK((((long)&commitment_tx_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1636         long commitment_tx_ref = (long)commitment_tx_var.inner;
1637         if (commitment_tx_var.is_owned) {
1638                 commitment_tx_ref |= 1;
1639         }
1640         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
1641         CHECK(obj != NULL);
1642         LDKCResult_CVec_SignatureZNoneZ* ret = (LDKCResult_CVec_SignatureZNoneZ*)(*_env)->CallLongMethod(_env, obj, j_calls->sign_holder_commitment_htlc_transactions_meth, commitment_tx_ref);
1643         LDKCResult_CVec_SignatureZNoneZ ret_conv = *(LDKCResult_CVec_SignatureZNoneZ*)ret;
1644         FREE((void*)ret);
1645         return ret_conv;
1646 }
1647 LDKCResult_SignatureNoneZ sign_justice_transaction_jcall(const void* this_arg, struct LDKTransaction justice_tx, uintptr_t input, uint64_t amount, const uint8_t (*per_commitment_key)[32], const struct LDKHTLCOutputInCommitment *NONNULL_PTR htlc) {
1648         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1649         JNIEnv *_env;
1650         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
1651         LDKTransaction justice_tx_var = justice_tx;
1652         jbyteArray justice_tx_arr = (*_env)->NewByteArray(_env, justice_tx_var.datalen);
1653         (*_env)->SetByteArrayRegion(_env, justice_tx_arr, 0, justice_tx_var.datalen, justice_tx_var.data);
1654         Transaction_free(justice_tx_var);
1655         jbyteArray per_commitment_key_arr = (*_env)->NewByteArray(_env, 32);
1656         (*_env)->SetByteArrayRegion(_env, per_commitment_key_arr, 0, 32, *per_commitment_key);
1657         LDKHTLCOutputInCommitment htlc_var = *htlc;
1658         if (htlc->inner != NULL)
1659                 htlc_var = HTLCOutputInCommitment_clone(htlc);
1660         CHECK((((long)htlc_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1661         CHECK((((long)&htlc_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1662         long htlc_ref = (long)htlc_var.inner;
1663         if (htlc_var.is_owned) {
1664                 htlc_ref |= 1;
1665         }
1666         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
1667         CHECK(obj != NULL);
1668         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);
1669         LDKCResult_SignatureNoneZ ret_conv = *(LDKCResult_SignatureNoneZ*)ret;
1670         FREE((void*)ret);
1671         return ret_conv;
1672 }
1673 LDKCResult_SignatureNoneZ sign_counterparty_htlc_transaction_jcall(const void* this_arg, struct LDKTransaction htlc_tx, uintptr_t input, uint64_t amount, struct LDKPublicKey per_commitment_point, const struct LDKHTLCOutputInCommitment *NONNULL_PTR htlc) {
1674         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1675         JNIEnv *_env;
1676         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
1677         LDKTransaction htlc_tx_var = htlc_tx;
1678         jbyteArray htlc_tx_arr = (*_env)->NewByteArray(_env, htlc_tx_var.datalen);
1679         (*_env)->SetByteArrayRegion(_env, htlc_tx_arr, 0, htlc_tx_var.datalen, htlc_tx_var.data);
1680         Transaction_free(htlc_tx_var);
1681         jbyteArray per_commitment_point_arr = (*_env)->NewByteArray(_env, 33);
1682         (*_env)->SetByteArrayRegion(_env, per_commitment_point_arr, 0, 33, per_commitment_point.compressed_form);
1683         LDKHTLCOutputInCommitment htlc_var = *htlc;
1684         if (htlc->inner != NULL)
1685                 htlc_var = HTLCOutputInCommitment_clone(htlc);
1686         CHECK((((long)htlc_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1687         CHECK((((long)&htlc_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1688         long htlc_ref = (long)htlc_var.inner;
1689         if (htlc_var.is_owned) {
1690                 htlc_ref |= 1;
1691         }
1692         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
1693         CHECK(obj != NULL);
1694         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);
1695         LDKCResult_SignatureNoneZ ret_conv = *(LDKCResult_SignatureNoneZ*)ret;
1696         FREE((void*)ret);
1697         return ret_conv;
1698 }
1699 LDKCResult_SignatureNoneZ sign_closing_transaction_jcall(const void* this_arg, struct LDKTransaction closing_tx) {
1700         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1701         JNIEnv *_env;
1702         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
1703         LDKTransaction closing_tx_var = closing_tx;
1704         jbyteArray closing_tx_arr = (*_env)->NewByteArray(_env, closing_tx_var.datalen);
1705         (*_env)->SetByteArrayRegion(_env, closing_tx_arr, 0, closing_tx_var.datalen, closing_tx_var.data);
1706         Transaction_free(closing_tx_var);
1707         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
1708         CHECK(obj != NULL);
1709         LDKCResult_SignatureNoneZ* ret = (LDKCResult_SignatureNoneZ*)(*_env)->CallLongMethod(_env, obj, j_calls->sign_closing_transaction_meth, closing_tx_arr);
1710         LDKCResult_SignatureNoneZ ret_conv = *(LDKCResult_SignatureNoneZ*)ret;
1711         FREE((void*)ret);
1712         return ret_conv;
1713 }
1714 LDKCResult_SignatureNoneZ sign_channel_announcement_jcall(const void* this_arg, const struct LDKUnsignedChannelAnnouncement *NONNULL_PTR msg) {
1715         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1716         JNIEnv *_env;
1717         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
1718         LDKUnsignedChannelAnnouncement msg_var = *msg;
1719         if (msg->inner != NULL)
1720                 msg_var = UnsignedChannelAnnouncement_clone(msg);
1721         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1722         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1723         long msg_ref = (long)msg_var.inner;
1724         if (msg_var.is_owned) {
1725                 msg_ref |= 1;
1726         }
1727         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
1728         CHECK(obj != NULL);
1729         LDKCResult_SignatureNoneZ* ret = (LDKCResult_SignatureNoneZ*)(*_env)->CallLongMethod(_env, obj, j_calls->sign_channel_announcement_meth, msg_ref);
1730         LDKCResult_SignatureNoneZ ret_conv = *(LDKCResult_SignatureNoneZ*)ret;
1731         FREE((void*)ret);
1732         return ret_conv;
1733 }
1734 void ready_channel_jcall(void* this_arg, const struct LDKChannelTransactionParameters *NONNULL_PTR channel_parameters) {
1735         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1736         JNIEnv *_env;
1737         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
1738         LDKChannelTransactionParameters channel_parameters_var = *channel_parameters;
1739         if (channel_parameters->inner != NULL)
1740                 channel_parameters_var = ChannelTransactionParameters_clone(channel_parameters);
1741         CHECK((((long)channel_parameters_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1742         CHECK((((long)&channel_parameters_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1743         long channel_parameters_ref = (long)channel_parameters_var.inner;
1744         if (channel_parameters_var.is_owned) {
1745                 channel_parameters_ref |= 1;
1746         }
1747         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
1748         CHECK(obj != NULL);
1749         return (*_env)->CallVoidMethod(_env, obj, j_calls->ready_channel_meth, channel_parameters_ref);
1750 }
1751 LDKCVec_u8Z write_jcall(const void* this_arg) {
1752         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1753         JNIEnv *_env;
1754         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
1755         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
1756         CHECK(obj != NULL);
1757         jbyteArray arg = (*_env)->CallObjectMethod(_env, obj, j_calls->write_meth);
1758         LDKCVec_u8Z arg_ref;
1759         arg_ref.datalen = (*_env)->GetArrayLength (_env, arg);
1760         arg_ref.data = MALLOC(arg_ref.datalen, "LDKCVec_u8Z Bytes");
1761         (*_env)->GetByteArrayRegion(_env, arg, 0, arg_ref.datalen, arg_ref.data);
1762         return arg_ref;
1763 }
1764 static void LDKChannelKeys_JCalls_free(void* this_arg) {
1765         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1766         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
1767                 JNIEnv *env;
1768                 DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
1769                 (*env)->DeleteWeakGlobalRef(env, j_calls->o);
1770                 FREE(j_calls);
1771         }
1772 }
1773 static void* LDKChannelKeys_JCalls_clone(const void* this_arg) {
1774         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1775         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
1776         return (void*) this_arg;
1777 }
1778 static inline LDKChannelKeys LDKChannelKeys_init (JNIEnv * env, jclass _a, jobject o, jlong pubkeys) {
1779         jclass c = (*env)->GetObjectClass(env, o);
1780         CHECK(c != NULL);
1781         LDKChannelKeys_JCalls *calls = MALLOC(sizeof(LDKChannelKeys_JCalls), "LDKChannelKeys_JCalls");
1782         atomic_init(&calls->refcnt, 1);
1783         DO_ASSERT((*env)->GetJavaVM(env, &calls->vm) == 0);
1784         calls->o = (*env)->NewWeakGlobalRef(env, o);
1785         calls->get_per_commitment_point_meth = (*env)->GetMethodID(env, c, "get_per_commitment_point", "(J)[B");
1786         CHECK(calls->get_per_commitment_point_meth != NULL);
1787         calls->release_commitment_secret_meth = (*env)->GetMethodID(env, c, "release_commitment_secret", "(J)[B");
1788         CHECK(calls->release_commitment_secret_meth != NULL);
1789         calls->key_derivation_params_meth = (*env)->GetMethodID(env, c, "key_derivation_params", "()J");
1790         CHECK(calls->key_derivation_params_meth != NULL);
1791         calls->sign_counterparty_commitment_meth = (*env)->GetMethodID(env, c, "sign_counterparty_commitment", "(J)J");
1792         CHECK(calls->sign_counterparty_commitment_meth != NULL);
1793         calls->sign_holder_commitment_meth = (*env)->GetMethodID(env, c, "sign_holder_commitment", "(J)J");
1794         CHECK(calls->sign_holder_commitment_meth != NULL);
1795         calls->sign_holder_commitment_htlc_transactions_meth = (*env)->GetMethodID(env, c, "sign_holder_commitment_htlc_transactions", "(J)J");
1796         CHECK(calls->sign_holder_commitment_htlc_transactions_meth != NULL);
1797         calls->sign_justice_transaction_meth = (*env)->GetMethodID(env, c, "sign_justice_transaction", "([BJJ[BJ)J");
1798         CHECK(calls->sign_justice_transaction_meth != NULL);
1799         calls->sign_counterparty_htlc_transaction_meth = (*env)->GetMethodID(env, c, "sign_counterparty_htlc_transaction", "([BJJ[BJ)J");
1800         CHECK(calls->sign_counterparty_htlc_transaction_meth != NULL);
1801         calls->sign_closing_transaction_meth = (*env)->GetMethodID(env, c, "sign_closing_transaction", "([B)J");
1802         CHECK(calls->sign_closing_transaction_meth != NULL);
1803         calls->sign_channel_announcement_meth = (*env)->GetMethodID(env, c, "sign_channel_announcement", "(J)J");
1804         CHECK(calls->sign_channel_announcement_meth != NULL);
1805         calls->ready_channel_meth = (*env)->GetMethodID(env, c, "ready_channel", "(J)V");
1806         CHECK(calls->ready_channel_meth != NULL);
1807         calls->write_meth = (*env)->GetMethodID(env, c, "write", "()[B");
1808         CHECK(calls->write_meth != NULL);
1809
1810         LDKChannelPublicKeys pubkeys_conv;
1811         pubkeys_conv.inner = (void*)(pubkeys & (~1));
1812         pubkeys_conv.is_owned = (pubkeys & 1) || (pubkeys == 0);
1813         if (pubkeys_conv.inner != NULL)
1814                 pubkeys_conv = ChannelPublicKeys_clone(&pubkeys_conv);
1815
1816         LDKChannelKeys ret = {
1817                 .this_arg = (void*) calls,
1818                 .get_per_commitment_point = get_per_commitment_point_jcall,
1819                 .release_commitment_secret = release_commitment_secret_jcall,
1820                 .key_derivation_params = key_derivation_params_jcall,
1821                 .sign_counterparty_commitment = sign_counterparty_commitment_jcall,
1822                 .sign_holder_commitment = sign_holder_commitment_jcall,
1823                 .sign_holder_commitment_htlc_transactions = sign_holder_commitment_htlc_transactions_jcall,
1824                 .sign_justice_transaction = sign_justice_transaction_jcall,
1825                 .sign_counterparty_htlc_transaction = sign_counterparty_htlc_transaction_jcall,
1826                 .sign_closing_transaction = sign_closing_transaction_jcall,
1827                 .sign_channel_announcement = sign_channel_announcement_jcall,
1828                 .ready_channel = ready_channel_jcall,
1829                 .clone = LDKChannelKeys_JCalls_clone,
1830                 .write = write_jcall,
1831                 .free = LDKChannelKeys_JCalls_free,
1832                 .pubkeys = pubkeys_conv,
1833                 .set_pubkeys = NULL,
1834         };
1835         return ret;
1836 }
1837 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_LDKChannelKeys_1new (JNIEnv * env, jclass _a, jobject o, jlong pubkeys) {
1838         LDKChannelKeys *res_ptr = MALLOC(sizeof(LDKChannelKeys), "LDKChannelKeys");
1839         *res_ptr = LDKChannelKeys_init(env, _a, o, pubkeys);
1840         return (long)res_ptr;
1841 }
1842 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKChannelKeys_1get_1obj_1from_1jcalls (JNIEnv * env, jclass _a, jlong val) {
1843         jobject ret = (*env)->NewLocalRef(env, ((LDKChannelKeys_JCalls*)val)->o);
1844         CHECK(ret != NULL);
1845         return ret;
1846 }
1847 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1get_1per_1commitment_1point(JNIEnv * _env, jclass _b, jlong this_arg, jlong idx) {
1848         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
1849         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
1850         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, (this_arg_conv->get_per_commitment_point)(this_arg_conv->this_arg, idx).compressed_form);
1851         return arg_arr;
1852 }
1853
1854 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1release_1commitment_1secret(JNIEnv * _env, jclass _b, jlong this_arg, jlong idx) {
1855         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
1856         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 32);
1857         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 32, (this_arg_conv->release_commitment_secret)(this_arg_conv->this_arg, idx).data);
1858         return arg_arr;
1859 }
1860
1861 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1key_1derivation_1params(JNIEnv * _env, jclass _b, jlong this_arg) {
1862         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
1863         LDKC2Tuple_u64u64Z* ret_ref = MALLOC(sizeof(LDKC2Tuple_u64u64Z), "LDKC2Tuple_u64u64Z");
1864         *ret_ref = (this_arg_conv->key_derivation_params)(this_arg_conv->this_arg);
1865         return (long)ret_ref;
1866 }
1867
1868 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1sign_1counterparty_1commitment(JNIEnv * _env, jclass _b, jlong this_arg, jlong commitment_tx) {
1869         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
1870         LDKCommitmentTransaction commitment_tx_conv;
1871         commitment_tx_conv.inner = (void*)(commitment_tx & (~1));
1872         commitment_tx_conv.is_owned = false;
1873         LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ), "LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ");
1874         *ret_conv = (this_arg_conv->sign_counterparty_commitment)(this_arg_conv->this_arg, &commitment_tx_conv);
1875         return (long)ret_conv;
1876 }
1877
1878 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1sign_1holder_1commitment(JNIEnv * _env, jclass _b, jlong this_arg, jlong commitment_tx) {
1879         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
1880         LDKHolderCommitmentTransaction commitment_tx_conv;
1881         commitment_tx_conv.inner = (void*)(commitment_tx & (~1));
1882         commitment_tx_conv.is_owned = false;
1883         LDKCResult_SignatureNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_SignatureNoneZ), "LDKCResult_SignatureNoneZ");
1884         *ret_conv = (this_arg_conv->sign_holder_commitment)(this_arg_conv->this_arg, &commitment_tx_conv);
1885         return (long)ret_conv;
1886 }
1887
1888 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1sign_1holder_1commitment_1htlc_1transactions(JNIEnv * _env, jclass _b, jlong this_arg, jlong commitment_tx) {
1889         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
1890         LDKHolderCommitmentTransaction commitment_tx_conv;
1891         commitment_tx_conv.inner = (void*)(commitment_tx & (~1));
1892         commitment_tx_conv.is_owned = false;
1893         LDKCResult_CVec_SignatureZNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_CVec_SignatureZNoneZ), "LDKCResult_CVec_SignatureZNoneZ");
1894         *ret_conv = (this_arg_conv->sign_holder_commitment_htlc_transactions)(this_arg_conv->this_arg, &commitment_tx_conv);
1895         return (long)ret_conv;
1896 }
1897
1898 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1sign_1justice_1transaction(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray justice_tx, jlong input, jlong amount, jbyteArray per_commitment_key, jlong htlc) {
1899         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
1900         LDKTransaction justice_tx_ref;
1901         justice_tx_ref.datalen = (*_env)->GetArrayLength (_env, justice_tx);
1902         justice_tx_ref.data = MALLOC(justice_tx_ref.datalen, "LDKTransaction Bytes");
1903         (*_env)->GetByteArrayRegion(_env, justice_tx, 0, justice_tx_ref.datalen, justice_tx_ref.data);
1904         justice_tx_ref.data_is_owned = true;
1905         unsigned char per_commitment_key_arr[32];
1906         CHECK((*_env)->GetArrayLength (_env, per_commitment_key) == 32);
1907         (*_env)->GetByteArrayRegion (_env, per_commitment_key, 0, 32, per_commitment_key_arr);
1908         unsigned char (*per_commitment_key_ref)[32] = &per_commitment_key_arr;
1909         LDKHTLCOutputInCommitment htlc_conv;
1910         htlc_conv.inner = (void*)(htlc & (~1));
1911         htlc_conv.is_owned = false;
1912         LDKCResult_SignatureNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_SignatureNoneZ), "LDKCResult_SignatureNoneZ");
1913         *ret_conv = (this_arg_conv->sign_justice_transaction)(this_arg_conv->this_arg, justice_tx_ref, input, amount, per_commitment_key_ref, &htlc_conv);
1914         return (long)ret_conv;
1915 }
1916
1917 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1sign_1counterparty_1htlc_1transaction(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray htlc_tx, jlong input, jlong amount, jbyteArray per_commitment_point, jlong htlc) {
1918         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
1919         LDKTransaction htlc_tx_ref;
1920         htlc_tx_ref.datalen = (*_env)->GetArrayLength (_env, htlc_tx);
1921         htlc_tx_ref.data = MALLOC(htlc_tx_ref.datalen, "LDKTransaction Bytes");
1922         (*_env)->GetByteArrayRegion(_env, htlc_tx, 0, htlc_tx_ref.datalen, htlc_tx_ref.data);
1923         htlc_tx_ref.data_is_owned = true;
1924         LDKPublicKey per_commitment_point_ref;
1925         CHECK((*_env)->GetArrayLength (_env, per_commitment_point) == 33);
1926         (*_env)->GetByteArrayRegion (_env, per_commitment_point, 0, 33, per_commitment_point_ref.compressed_form);
1927         LDKHTLCOutputInCommitment htlc_conv;
1928         htlc_conv.inner = (void*)(htlc & (~1));
1929         htlc_conv.is_owned = false;
1930         LDKCResult_SignatureNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_SignatureNoneZ), "LDKCResult_SignatureNoneZ");
1931         *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);
1932         return (long)ret_conv;
1933 }
1934
1935 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1sign_1closing_1transaction(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray closing_tx) {
1936         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
1937         LDKTransaction closing_tx_ref;
1938         closing_tx_ref.datalen = (*_env)->GetArrayLength (_env, closing_tx);
1939         closing_tx_ref.data = MALLOC(closing_tx_ref.datalen, "LDKTransaction Bytes");
1940         (*_env)->GetByteArrayRegion(_env, closing_tx, 0, closing_tx_ref.datalen, closing_tx_ref.data);
1941         closing_tx_ref.data_is_owned = true;
1942         LDKCResult_SignatureNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_SignatureNoneZ), "LDKCResult_SignatureNoneZ");
1943         *ret_conv = (this_arg_conv->sign_closing_transaction)(this_arg_conv->this_arg, closing_tx_ref);
1944         return (long)ret_conv;
1945 }
1946
1947 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1sign_1channel_1announcement(JNIEnv * _env, jclass _b, jlong this_arg, jlong msg) {
1948         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
1949         LDKUnsignedChannelAnnouncement msg_conv;
1950         msg_conv.inner = (void*)(msg & (~1));
1951         msg_conv.is_owned = false;
1952         LDKCResult_SignatureNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_SignatureNoneZ), "LDKCResult_SignatureNoneZ");
1953         *ret_conv = (this_arg_conv->sign_channel_announcement)(this_arg_conv->this_arg, &msg_conv);
1954         return (long)ret_conv;
1955 }
1956
1957 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1ready_1channel(JNIEnv * _env, jclass _b, jlong this_arg, jlong channel_parameters) {
1958         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
1959         LDKChannelTransactionParameters channel_parameters_conv;
1960         channel_parameters_conv.inner = (void*)(channel_parameters & (~1));
1961         channel_parameters_conv.is_owned = false;
1962         (this_arg_conv->ready_channel)(this_arg_conv->this_arg, &channel_parameters_conv);
1963 }
1964
1965 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1write(JNIEnv * _env, jclass _b, jlong this_arg) {
1966         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
1967         LDKCVec_u8Z arg_var = (this_arg_conv->write)(this_arg_conv->this_arg);
1968         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
1969         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
1970         CVec_u8Z_free(arg_var);
1971         return arg_arr;
1972 }
1973
1974 LDKChannelPublicKeys LDKChannelKeys_set_get_pubkeys(LDKChannelKeys* this_arg) {
1975         if (this_arg->set_pubkeys != NULL)
1976                 this_arg->set_pubkeys(this_arg);
1977         return this_arg->pubkeys;
1978 }
1979 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1get_1pubkeys(JNIEnv * _env, jclass _b, jlong this_arg) {
1980         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
1981         LDKChannelPublicKeys ret_var = LDKChannelKeys_set_get_pubkeys(this_arg_conv);
1982         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1983         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1984         long ret_ref = (long)ret_var.inner;
1985         if (ret_var.is_owned) {
1986                 ret_ref |= 1;
1987         }
1988         return ret_ref;
1989 }
1990
1991 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKC2Tuple_1BlockHashChannelMonitorZ_1new(JNIEnv *_env, jclass _b, jbyteArray a, jlong b) {
1992         LDKC2Tuple_BlockHashChannelMonitorZ* ret = MALLOC(sizeof(LDKC2Tuple_BlockHashChannelMonitorZ), "LDKC2Tuple_BlockHashChannelMonitorZ");
1993         LDKThirtyTwoBytes a_ref;
1994         CHECK((*_env)->GetArrayLength (_env, a) == 32);
1995         (*_env)->GetByteArrayRegion (_env, a, 0, 32, a_ref.data);
1996         ret->a = a_ref;
1997         LDKChannelMonitor b_conv;
1998         b_conv.inner = (void*)(b & (~1));
1999         b_conv.is_owned = (b & 1) || (b == 0);
2000         // Warning: we may need a move here but can't clone!
2001         ret->b = b_conv;
2002         return (long)ret;
2003 }
2004 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_LDKC2Tuple_1BlockHashChannelMonitorZ_1get_1a(JNIEnv *_env, jclass _b, jlong ptr) {
2005         LDKC2Tuple_BlockHashChannelMonitorZ *tuple = (LDKC2Tuple_BlockHashChannelMonitorZ*)ptr;
2006         jbyteArray a_arr = (*_env)->NewByteArray(_env, 32);
2007         (*_env)->SetByteArrayRegion(_env, a_arr, 0, 32, tuple->a.data);
2008         return a_arr;
2009 }
2010 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKC2Tuple_1BlockHashChannelMonitorZ_1get_1b(JNIEnv *_env, jclass _b, jlong ptr) {
2011         LDKC2Tuple_BlockHashChannelMonitorZ *tuple = (LDKC2Tuple_BlockHashChannelMonitorZ*)ptr;
2012         LDKChannelMonitor b_var = tuple->b;
2013         CHECK((((long)b_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2014         CHECK((((long)&b_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2015         long b_ref = (long)b_var.inner & ~1;
2016         return b_ref;
2017 }
2018 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1C2Tuple_1BlockHashChannelMonitorZDecodeErrorZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
2019         return ((LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ*)arg)->result_ok;
2020 }
2021 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1C2Tuple_1BlockHashChannelMonitorZDecodeErrorZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
2022         LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ *val = (LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ*)arg;
2023         CHECK(val->result_ok);
2024         long res_ref = (long)&(*val->contents.result);
2025         return res_ref;
2026 }
2027 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1C2Tuple_1BlockHashChannelMonitorZDecodeErrorZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
2028         LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ *val = (LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ*)arg;
2029         CHECK(!val->result_ok);
2030         LDKDecodeError err_var = (*val->contents.err);
2031         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2032         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2033         long err_ref = (long)err_var.inner & ~1;
2034         return err_ref;
2035 }
2036 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1SpendableOutputDescriptorDecodeErrorZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
2037         return ((LDKCResult_SpendableOutputDescriptorDecodeErrorZ*)arg)->result_ok;
2038 }
2039 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1SpendableOutputDescriptorDecodeErrorZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
2040         LDKCResult_SpendableOutputDescriptorDecodeErrorZ *val = (LDKCResult_SpendableOutputDescriptorDecodeErrorZ*)arg;
2041         CHECK(val->result_ok);
2042         long res_ref = (long)&(*val->contents.result);
2043         return res_ref;
2044 }
2045 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1SpendableOutputDescriptorDecodeErrorZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
2046         LDKCResult_SpendableOutputDescriptorDecodeErrorZ *val = (LDKCResult_SpendableOutputDescriptorDecodeErrorZ*)arg;
2047         CHECK(!val->result_ok);
2048         LDKDecodeError err_var = (*val->contents.err);
2049         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2050         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2051         long err_ref = (long)err_var.inner & ~1;
2052         return err_ref;
2053 }
2054 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1ChanKeySignerDecodeErrorZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
2055         return ((LDKCResult_ChanKeySignerDecodeErrorZ*)arg)->result_ok;
2056 }
2057 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1ChanKeySignerDecodeErrorZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
2058         LDKCResult_ChanKeySignerDecodeErrorZ *val = (LDKCResult_ChanKeySignerDecodeErrorZ*)arg;
2059         CHECK(val->result_ok);
2060         LDKChannelKeys* ret = MALLOC(sizeof(LDKChannelKeys), "LDKChannelKeys");
2061         *ret = (*val->contents.result);
2062         return (long)ret;
2063 }
2064 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1ChanKeySignerDecodeErrorZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
2065         LDKCResult_ChanKeySignerDecodeErrorZ *val = (LDKCResult_ChanKeySignerDecodeErrorZ*)arg;
2066         CHECK(!val->result_ok);
2067         LDKDecodeError err_var = (*val->contents.err);
2068         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2069         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2070         long err_ref = (long)err_var.inner & ~1;
2071         return err_ref;
2072 }
2073 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1InMemoryChannelKeysDecodeErrorZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
2074         return ((LDKCResult_InMemoryChannelKeysDecodeErrorZ*)arg)->result_ok;
2075 }
2076 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1InMemoryChannelKeysDecodeErrorZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
2077         LDKCResult_InMemoryChannelKeysDecodeErrorZ *val = (LDKCResult_InMemoryChannelKeysDecodeErrorZ*)arg;
2078         CHECK(val->result_ok);
2079         LDKInMemoryChannelKeys res_var = (*val->contents.result);
2080         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2081         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2082         long res_ref = (long)res_var.inner & ~1;
2083         return res_ref;
2084 }
2085 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1InMemoryChannelKeysDecodeErrorZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
2086         LDKCResult_InMemoryChannelKeysDecodeErrorZ *val = (LDKCResult_InMemoryChannelKeysDecodeErrorZ*)arg;
2087         CHECK(!val->result_ok);
2088         LDKDecodeError err_var = (*val->contents.err);
2089         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2090         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2091         long err_ref = (long)err_var.inner & ~1;
2092         return err_ref;
2093 }
2094 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1TxOutAccessErrorZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
2095         return ((LDKCResult_TxOutAccessErrorZ*)arg)->result_ok;
2096 }
2097 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1TxOutAccessErrorZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
2098         LDKCResult_TxOutAccessErrorZ *val = (LDKCResult_TxOutAccessErrorZ*)arg;
2099         CHECK(val->result_ok);
2100         long res_ref = (long)&(*val->contents.result);
2101         return (long)res_ref;
2102 }
2103 JNIEXPORT jclass JNICALL Java_org_ldk_impl_bindings_LDKCResult_1TxOutAccessErrorZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
2104         LDKCResult_TxOutAccessErrorZ *val = (LDKCResult_TxOutAccessErrorZ*)arg;
2105         CHECK(!val->result_ok);
2106         jclass err_conv = LDKAccessError_to_java(_env, (*val->contents.err));
2107         return err_conv;
2108 }
2109 static inline LDKCResult_TxOutAccessErrorZ CResult_TxOutAccessErrorZ_clone(const LDKCResult_TxOutAccessErrorZ *orig) {
2110         LDKCResult_TxOutAccessErrorZ res = { .result_ok = orig->result_ok };
2111         if (orig->result_ok) {
2112                 LDKTxOut* contents = MALLOC(sizeof(LDKTxOut), "LDKTxOut result OK clone");
2113                 *contents = TxOut_clone(orig->contents.result);
2114                 res.contents.result = contents;
2115         } else {
2116                 LDKAccessError* contents = MALLOC(sizeof(LDKAccessError), "LDKAccessError result Err clone");
2117                 *contents = AccessError_clone(orig->contents.err);
2118                 res.contents.err = contents;
2119         }
2120         return res;
2121 }
2122 static jclass LDKAPIError_APIMisuseError_class = NULL;
2123 static jmethodID LDKAPIError_APIMisuseError_meth = NULL;
2124 static jclass LDKAPIError_FeeRateTooHigh_class = NULL;
2125 static jmethodID LDKAPIError_FeeRateTooHigh_meth = NULL;
2126 static jclass LDKAPIError_RouteError_class = NULL;
2127 static jmethodID LDKAPIError_RouteError_meth = NULL;
2128 static jclass LDKAPIError_ChannelUnavailable_class = NULL;
2129 static jmethodID LDKAPIError_ChannelUnavailable_meth = NULL;
2130 static jclass LDKAPIError_MonitorUpdateFailed_class = NULL;
2131 static jmethodID LDKAPIError_MonitorUpdateFailed_meth = NULL;
2132 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_00024LDKAPIError_init (JNIEnv * env, jclass _a) {
2133         LDKAPIError_APIMisuseError_class =
2134                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKAPIError$APIMisuseError;"));
2135         CHECK(LDKAPIError_APIMisuseError_class != NULL);
2136         LDKAPIError_APIMisuseError_meth = (*env)->GetMethodID(env, LDKAPIError_APIMisuseError_class, "<init>", "([B)V");
2137         CHECK(LDKAPIError_APIMisuseError_meth != NULL);
2138         LDKAPIError_FeeRateTooHigh_class =
2139                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKAPIError$FeeRateTooHigh;"));
2140         CHECK(LDKAPIError_FeeRateTooHigh_class != NULL);
2141         LDKAPIError_FeeRateTooHigh_meth = (*env)->GetMethodID(env, LDKAPIError_FeeRateTooHigh_class, "<init>", "([BI)V");
2142         CHECK(LDKAPIError_FeeRateTooHigh_meth != NULL);
2143         LDKAPIError_RouteError_class =
2144                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKAPIError$RouteError;"));
2145         CHECK(LDKAPIError_RouteError_class != NULL);
2146         LDKAPIError_RouteError_meth = (*env)->GetMethodID(env, LDKAPIError_RouteError_class, "<init>", "(Ljava/lang/String;)V");
2147         CHECK(LDKAPIError_RouteError_meth != NULL);
2148         LDKAPIError_ChannelUnavailable_class =
2149                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKAPIError$ChannelUnavailable;"));
2150         CHECK(LDKAPIError_ChannelUnavailable_class != NULL);
2151         LDKAPIError_ChannelUnavailable_meth = (*env)->GetMethodID(env, LDKAPIError_ChannelUnavailable_class, "<init>", "([B)V");
2152         CHECK(LDKAPIError_ChannelUnavailable_meth != NULL);
2153         LDKAPIError_MonitorUpdateFailed_class =
2154                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKAPIError$MonitorUpdateFailed;"));
2155         CHECK(LDKAPIError_MonitorUpdateFailed_class != NULL);
2156         LDKAPIError_MonitorUpdateFailed_meth = (*env)->GetMethodID(env, LDKAPIError_MonitorUpdateFailed_class, "<init>", "()V");
2157         CHECK(LDKAPIError_MonitorUpdateFailed_meth != NULL);
2158 }
2159 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKAPIError_1ref_1from_1ptr (JNIEnv * _env, jclass _c, jlong ptr) {
2160         LDKAPIError *obj = (LDKAPIError*)ptr;
2161         switch(obj->tag) {
2162                 case LDKAPIError_APIMisuseError: {
2163                         LDKCVec_u8Z err_var = obj->api_misuse_error.err;
2164                         jbyteArray err_arr = (*_env)->NewByteArray(_env, err_var.datalen);
2165                         (*_env)->SetByteArrayRegion(_env, err_arr, 0, err_var.datalen, err_var.data);
2166                         return (*_env)->NewObject(_env, LDKAPIError_APIMisuseError_class, LDKAPIError_APIMisuseError_meth, err_arr);
2167                 }
2168                 case LDKAPIError_FeeRateTooHigh: {
2169                         LDKCVec_u8Z err_var = obj->fee_rate_too_high.err;
2170                         jbyteArray err_arr = (*_env)->NewByteArray(_env, err_var.datalen);
2171                         (*_env)->SetByteArrayRegion(_env, err_arr, 0, err_var.datalen, err_var.data);
2172                         return (*_env)->NewObject(_env, LDKAPIError_FeeRateTooHigh_class, LDKAPIError_FeeRateTooHigh_meth, err_arr, obj->fee_rate_too_high.feerate);
2173                 }
2174                 case LDKAPIError_RouteError: {
2175                         LDKStr err_str = obj->route_error.err;
2176                         char* err_buf = MALLOC(err_str.len + 1, "str conv buf");
2177                         memcpy(err_buf, err_str.chars, err_str.len);
2178                         err_buf[err_str.len] = 0;
2179                         jstring err_conv = (*_env)->NewStringUTF(_env, err_str.chars);
2180                         FREE(err_buf);
2181                         return (*_env)->NewObject(_env, LDKAPIError_RouteError_class, LDKAPIError_RouteError_meth, err_conv);
2182                 }
2183                 case LDKAPIError_ChannelUnavailable: {
2184                         LDKCVec_u8Z err_var = obj->channel_unavailable.err;
2185                         jbyteArray err_arr = (*_env)->NewByteArray(_env, err_var.datalen);
2186                         (*_env)->SetByteArrayRegion(_env, err_arr, 0, err_var.datalen, err_var.data);
2187                         return (*_env)->NewObject(_env, LDKAPIError_ChannelUnavailable_class, LDKAPIError_ChannelUnavailable_meth, err_arr);
2188                 }
2189                 case LDKAPIError_MonitorUpdateFailed: {
2190                         return (*_env)->NewObject(_env, LDKAPIError_MonitorUpdateFailed_class, LDKAPIError_MonitorUpdateFailed_meth);
2191                 }
2192                 default: abort();
2193         }
2194 }
2195 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NoneAPIErrorZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
2196         return ((LDKCResult_NoneAPIErrorZ*)arg)->result_ok;
2197 }
2198 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NoneAPIErrorZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
2199         LDKCResult_NoneAPIErrorZ *val = (LDKCResult_NoneAPIErrorZ*)arg;
2200         CHECK(val->result_ok);
2201         return *val->contents.result;
2202 }
2203 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NoneAPIErrorZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
2204         LDKCResult_NoneAPIErrorZ *val = (LDKCResult_NoneAPIErrorZ*)arg;
2205         CHECK(!val->result_ok);
2206         long err_ref = (long)&(*val->contents.err);
2207         return err_ref;
2208 }
2209 static inline LDKCResult_NoneAPIErrorZ CResult_NoneAPIErrorZ_clone(const LDKCResult_NoneAPIErrorZ *orig) {
2210         LDKCResult_NoneAPIErrorZ res = { .result_ok = orig->result_ok };
2211         if (orig->result_ok) {
2212                 res.contents.result = NULL;
2213         } else {
2214                 LDKAPIError* contents = MALLOC(sizeof(LDKAPIError), "LDKAPIError result Err clone");
2215                 *contents = APIError_clone(orig->contents.err);
2216                 res.contents.err = contents;
2217         }
2218         return res;
2219 }
2220 JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_LDKCVec_1ChannelDetailsZ_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
2221         LDKCVec_ChannelDetailsZ *vec = (LDKCVec_ChannelDetailsZ*)ptr;
2222         jlongArray ret = (*env)->NewLongArray(env, vec->datalen);
2223         jlong *ret_elems = (*env)->GetPrimitiveArrayCritical(env, ret, NULL);
2224         for (size_t i = 0; i < vec->datalen; i++) {
2225                 CHECK((((long)vec->data[i].inner) & 1) == 0);
2226                 ret_elems[i] = (long)vec->data[i].inner | (vec->data[i].is_owned ? 1 : 0);
2227         }
2228         (*env)->ReleasePrimitiveArrayCritical(env, ret, ret_elems, 0);
2229         return ret;
2230 }
2231 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVec_1ChannelDetailsZ_1new(JNIEnv *env, jclass _b, jlongArray elems){
2232         LDKCVec_ChannelDetailsZ *ret = MALLOC(sizeof(LDKCVec_ChannelDetailsZ), "LDKCVec_ChannelDetailsZ");
2233         ret->datalen = (*env)->GetArrayLength(env, elems);
2234         if (ret->datalen == 0) {
2235                 ret->data = NULL;
2236         } else {
2237                 ret->data = MALLOC(sizeof(LDKChannelDetails) * ret->datalen, "LDKCVec_ChannelDetailsZ Data");
2238                 jlong *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
2239                 for (size_t i = 0; i < ret->datalen; i++) {
2240                         jlong arr_elem = java_elems[i];
2241                         LDKChannelDetails arr_elem_conv;
2242                         arr_elem_conv.inner = (void*)(arr_elem & (~1));
2243                         arr_elem_conv.is_owned = (arr_elem & 1) || (arr_elem == 0);
2244                         if (arr_elem_conv.inner != NULL)
2245                                 arr_elem_conv = ChannelDetails_clone(&arr_elem_conv);
2246                         ret->data[i] = arr_elem_conv;
2247                 }
2248                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
2249         }
2250         return (long)ret;
2251 }
2252 static inline LDKCVec_ChannelDetailsZ CVec_ChannelDetailsZ_clone(const LDKCVec_ChannelDetailsZ *orig) {
2253         LDKCVec_ChannelDetailsZ ret = { .data = MALLOC(sizeof(LDKChannelDetails) * orig->datalen, "LDKCVec_ChannelDetailsZ clone bytes"), .datalen = orig->datalen };
2254         for (size_t i = 0; i < ret.datalen; i++) {
2255                 ret.data[i] = ChannelDetails_clone(&orig->data[i]);
2256         }
2257         return ret;
2258 }
2259 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NonePaymentSendFailureZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
2260         return ((LDKCResult_NonePaymentSendFailureZ*)arg)->result_ok;
2261 }
2262 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NonePaymentSendFailureZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
2263         LDKCResult_NonePaymentSendFailureZ *val = (LDKCResult_NonePaymentSendFailureZ*)arg;
2264         CHECK(val->result_ok);
2265         return *val->contents.result;
2266 }
2267 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NonePaymentSendFailureZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
2268         LDKCResult_NonePaymentSendFailureZ *val = (LDKCResult_NonePaymentSendFailureZ*)arg;
2269         CHECK(!val->result_ok);
2270         LDKPaymentSendFailure err_var = (*val->contents.err);
2271         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2272         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2273         long err_ref = (long)err_var.inner & ~1;
2274         return err_ref;
2275 }
2276 static jclass LDKNetAddress_IPv4_class = NULL;
2277 static jmethodID LDKNetAddress_IPv4_meth = NULL;
2278 static jclass LDKNetAddress_IPv6_class = NULL;
2279 static jmethodID LDKNetAddress_IPv6_meth = NULL;
2280 static jclass LDKNetAddress_OnionV2_class = NULL;
2281 static jmethodID LDKNetAddress_OnionV2_meth = NULL;
2282 static jclass LDKNetAddress_OnionV3_class = NULL;
2283 static jmethodID LDKNetAddress_OnionV3_meth = NULL;
2284 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_00024LDKNetAddress_init (JNIEnv * env, jclass _a) {
2285         LDKNetAddress_IPv4_class =
2286                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKNetAddress$IPv4;"));
2287         CHECK(LDKNetAddress_IPv4_class != NULL);
2288         LDKNetAddress_IPv4_meth = (*env)->GetMethodID(env, LDKNetAddress_IPv4_class, "<init>", "([BS)V");
2289         CHECK(LDKNetAddress_IPv4_meth != NULL);
2290         LDKNetAddress_IPv6_class =
2291                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKNetAddress$IPv6;"));
2292         CHECK(LDKNetAddress_IPv6_class != NULL);
2293         LDKNetAddress_IPv6_meth = (*env)->GetMethodID(env, LDKNetAddress_IPv6_class, "<init>", "([BS)V");
2294         CHECK(LDKNetAddress_IPv6_meth != NULL);
2295         LDKNetAddress_OnionV2_class =
2296                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKNetAddress$OnionV2;"));
2297         CHECK(LDKNetAddress_OnionV2_class != NULL);
2298         LDKNetAddress_OnionV2_meth = (*env)->GetMethodID(env, LDKNetAddress_OnionV2_class, "<init>", "([BS)V");
2299         CHECK(LDKNetAddress_OnionV2_meth != NULL);
2300         LDKNetAddress_OnionV3_class =
2301                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKNetAddress$OnionV3;"));
2302         CHECK(LDKNetAddress_OnionV3_class != NULL);
2303         LDKNetAddress_OnionV3_meth = (*env)->GetMethodID(env, LDKNetAddress_OnionV3_class, "<init>", "([BSBS)V");
2304         CHECK(LDKNetAddress_OnionV3_meth != NULL);
2305 }
2306 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKNetAddress_1ref_1from_1ptr (JNIEnv * _env, jclass _c, jlong ptr) {
2307         LDKNetAddress *obj = (LDKNetAddress*)ptr;
2308         switch(obj->tag) {
2309                 case LDKNetAddress_IPv4: {
2310                         jbyteArray addr_arr = (*_env)->NewByteArray(_env, 4);
2311                         (*_env)->SetByteArrayRegion(_env, addr_arr, 0, 4, obj->i_pv4.addr.data);
2312                         return (*_env)->NewObject(_env, LDKNetAddress_IPv4_class, LDKNetAddress_IPv4_meth, addr_arr, obj->i_pv4.port);
2313                 }
2314                 case LDKNetAddress_IPv6: {
2315                         jbyteArray addr_arr = (*_env)->NewByteArray(_env, 16);
2316                         (*_env)->SetByteArrayRegion(_env, addr_arr, 0, 16, obj->i_pv6.addr.data);
2317                         return (*_env)->NewObject(_env, LDKNetAddress_IPv6_class, LDKNetAddress_IPv6_meth, addr_arr, obj->i_pv6.port);
2318                 }
2319                 case LDKNetAddress_OnionV2: {
2320                         jbyteArray addr_arr = (*_env)->NewByteArray(_env, 10);
2321                         (*_env)->SetByteArrayRegion(_env, addr_arr, 0, 10, obj->onion_v2.addr.data);
2322                         return (*_env)->NewObject(_env, LDKNetAddress_OnionV2_class, LDKNetAddress_OnionV2_meth, addr_arr, obj->onion_v2.port);
2323                 }
2324                 case LDKNetAddress_OnionV3: {
2325                         jbyteArray ed25519_pubkey_arr = (*_env)->NewByteArray(_env, 32);
2326                         (*_env)->SetByteArrayRegion(_env, ed25519_pubkey_arr, 0, 32, obj->onion_v3.ed25519_pubkey.data);
2327                         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);
2328                 }
2329                 default: abort();
2330         }
2331 }
2332 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKCVec_1NetAddressZ_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
2333         LDKCVec_NetAddressZ *vec = (LDKCVec_NetAddressZ*)ptr;
2334         return (*env)->NewObject(env, slicedef_cls, slicedef_meth, (long)vec->data, (long)vec->datalen, sizeof(LDKNetAddress));
2335 }
2336 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVec_1NetAddressZ_1new(JNIEnv *env, jclass _b, jlongArray elems){
2337         LDKCVec_NetAddressZ *ret = MALLOC(sizeof(LDKCVec_NetAddressZ), "LDKCVec_NetAddressZ");
2338         ret->datalen = (*env)->GetArrayLength(env, elems);
2339         if (ret->datalen == 0) {
2340                 ret->data = NULL;
2341         } else {
2342                 ret->data = MALLOC(sizeof(LDKNetAddress) * ret->datalen, "LDKCVec_NetAddressZ Data");
2343                 jlong *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
2344                 for (size_t i = 0; i < ret->datalen; i++) {
2345                         jlong arr_elem = java_elems[i];
2346                         LDKNetAddress arr_elem_conv = *(LDKNetAddress*)arr_elem;
2347                         FREE((void*)arr_elem);
2348                         ret->data[i] = arr_elem_conv;
2349                 }
2350                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
2351         }
2352         return (long)ret;
2353 }
2354 static inline LDKCVec_NetAddressZ CVec_NetAddressZ_clone(const LDKCVec_NetAddressZ *orig) {
2355         LDKCVec_NetAddressZ ret = { .data = MALLOC(sizeof(LDKNetAddress) * orig->datalen, "LDKCVec_NetAddressZ clone bytes"), .datalen = orig->datalen };
2356         for (size_t i = 0; i < ret.datalen; i++) {
2357                 ret.data[i] = NetAddress_clone(&orig->data[i]);
2358         }
2359         return ret;
2360 }
2361 JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_LDKCVec_1ChannelMonitorZ_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
2362         LDKCVec_ChannelMonitorZ *vec = (LDKCVec_ChannelMonitorZ*)ptr;
2363         jlongArray ret = (*env)->NewLongArray(env, vec->datalen);
2364         jlong *ret_elems = (*env)->GetPrimitiveArrayCritical(env, ret, NULL);
2365         for (size_t i = 0; i < vec->datalen; i++) {
2366                 CHECK((((long)vec->data[i].inner) & 1) == 0);
2367                 ret_elems[i] = (long)vec->data[i].inner | (vec->data[i].is_owned ? 1 : 0);
2368         }
2369         (*env)->ReleasePrimitiveArrayCritical(env, ret, ret_elems, 0);
2370         return ret;
2371 }
2372 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVec_1ChannelMonitorZ_1new(JNIEnv *env, jclass _b, jlongArray elems){
2373         LDKCVec_ChannelMonitorZ *ret = MALLOC(sizeof(LDKCVec_ChannelMonitorZ), "LDKCVec_ChannelMonitorZ");
2374         ret->datalen = (*env)->GetArrayLength(env, elems);
2375         if (ret->datalen == 0) {
2376                 ret->data = NULL;
2377         } else {
2378                 ret->data = MALLOC(sizeof(LDKChannelMonitor) * ret->datalen, "LDKCVec_ChannelMonitorZ Data");
2379                 jlong *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
2380                 for (size_t i = 0; i < ret->datalen; i++) {
2381                         jlong arr_elem = java_elems[i];
2382                         LDKChannelMonitor arr_elem_conv;
2383                         arr_elem_conv.inner = (void*)(arr_elem & (~1));
2384                         arr_elem_conv.is_owned = (arr_elem & 1) || (arr_elem == 0);
2385                         // Warning: we may need a move here but can't clone!
2386                         ret->data[i] = arr_elem_conv;
2387                 }
2388                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
2389         }
2390         return (long)ret;
2391 }
2392 typedef struct LDKWatch_JCalls {
2393         atomic_size_t refcnt;
2394         JavaVM *vm;
2395         jweak o;
2396         jmethodID watch_channel_meth;
2397         jmethodID update_channel_meth;
2398         jmethodID release_pending_monitor_events_meth;
2399 } LDKWatch_JCalls;
2400 LDKCResult_NoneChannelMonitorUpdateErrZ watch_channel_jcall(const void* this_arg, struct LDKOutPoint funding_txo, struct LDKChannelMonitor monitor) {
2401         LDKWatch_JCalls *j_calls = (LDKWatch_JCalls*) this_arg;
2402         JNIEnv *_env;
2403         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
2404         LDKOutPoint funding_txo_var = funding_txo;
2405         CHECK((((long)funding_txo_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2406         CHECK((((long)&funding_txo_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2407         long funding_txo_ref = (long)funding_txo_var.inner;
2408         if (funding_txo_var.is_owned) {
2409                 funding_txo_ref |= 1;
2410         }
2411         LDKChannelMonitor monitor_var = monitor;
2412         CHECK((((long)monitor_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2413         CHECK((((long)&monitor_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2414         long monitor_ref = (long)monitor_var.inner;
2415         if (monitor_var.is_owned) {
2416                 monitor_ref |= 1;
2417         }
2418         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
2419         CHECK(obj != NULL);
2420         LDKCResult_NoneChannelMonitorUpdateErrZ* ret = (LDKCResult_NoneChannelMonitorUpdateErrZ*)(*_env)->CallLongMethod(_env, obj, j_calls->watch_channel_meth, funding_txo_ref, monitor_ref);
2421         LDKCResult_NoneChannelMonitorUpdateErrZ ret_conv = *(LDKCResult_NoneChannelMonitorUpdateErrZ*)ret;
2422         FREE((void*)ret);
2423         return ret_conv;
2424 }
2425 LDKCResult_NoneChannelMonitorUpdateErrZ update_channel_jcall(const void* this_arg, struct LDKOutPoint funding_txo, struct LDKChannelMonitorUpdate update) {
2426         LDKWatch_JCalls *j_calls = (LDKWatch_JCalls*) this_arg;
2427         JNIEnv *_env;
2428         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
2429         LDKOutPoint funding_txo_var = funding_txo;
2430         CHECK((((long)funding_txo_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2431         CHECK((((long)&funding_txo_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2432         long funding_txo_ref = (long)funding_txo_var.inner;
2433         if (funding_txo_var.is_owned) {
2434                 funding_txo_ref |= 1;
2435         }
2436         LDKChannelMonitorUpdate update_var = update;
2437         CHECK((((long)update_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2438         CHECK((((long)&update_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2439         long update_ref = (long)update_var.inner;
2440         if (update_var.is_owned) {
2441                 update_ref |= 1;
2442         }
2443         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
2444         CHECK(obj != NULL);
2445         LDKCResult_NoneChannelMonitorUpdateErrZ* ret = (LDKCResult_NoneChannelMonitorUpdateErrZ*)(*_env)->CallLongMethod(_env, obj, j_calls->update_channel_meth, funding_txo_ref, update_ref);
2446         LDKCResult_NoneChannelMonitorUpdateErrZ ret_conv = *(LDKCResult_NoneChannelMonitorUpdateErrZ*)ret;
2447         FREE((void*)ret);
2448         return ret_conv;
2449 }
2450 LDKCVec_MonitorEventZ release_pending_monitor_events_jcall(const void* this_arg) {
2451         LDKWatch_JCalls *j_calls = (LDKWatch_JCalls*) this_arg;
2452         JNIEnv *_env;
2453         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
2454         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
2455         CHECK(obj != NULL);
2456         jlongArray arg = (*_env)->CallObjectMethod(_env, obj, j_calls->release_pending_monitor_events_meth);
2457         LDKCVec_MonitorEventZ arg_constr;
2458         arg_constr.datalen = (*_env)->GetArrayLength (_env, arg);
2459         if (arg_constr.datalen > 0)
2460                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKMonitorEvent), "LDKCVec_MonitorEventZ Elements");
2461         else
2462                 arg_constr.data = NULL;
2463         long* arg_vals = (*_env)->GetLongArrayElements (_env, arg, NULL);
2464         for (size_t o = 0; o < arg_constr.datalen; o++) {
2465                 long arr_conv_14 = arg_vals[o];
2466                 LDKMonitorEvent arr_conv_14_conv;
2467                 arr_conv_14_conv.inner = (void*)(arr_conv_14 & (~1));
2468                 arr_conv_14_conv.is_owned = (arr_conv_14 & 1) || (arr_conv_14 == 0);
2469                 if (arr_conv_14_conv.inner != NULL)
2470                         arr_conv_14_conv = MonitorEvent_clone(&arr_conv_14_conv);
2471                 arg_constr.data[o] = arr_conv_14_conv;
2472         }
2473         (*_env)->ReleaseLongArrayElements (_env, arg, arg_vals, 0);
2474         return arg_constr;
2475 }
2476 static void LDKWatch_JCalls_free(void* this_arg) {
2477         LDKWatch_JCalls *j_calls = (LDKWatch_JCalls*) this_arg;
2478         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
2479                 JNIEnv *env;
2480                 DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
2481                 (*env)->DeleteWeakGlobalRef(env, j_calls->o);
2482                 FREE(j_calls);
2483         }
2484 }
2485 static void* LDKWatch_JCalls_clone(const void* this_arg) {
2486         LDKWatch_JCalls *j_calls = (LDKWatch_JCalls*) this_arg;
2487         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
2488         return (void*) this_arg;
2489 }
2490 static inline LDKWatch LDKWatch_init (JNIEnv * env, jclass _a, jobject o) {
2491         jclass c = (*env)->GetObjectClass(env, o);
2492         CHECK(c != NULL);
2493         LDKWatch_JCalls *calls = MALLOC(sizeof(LDKWatch_JCalls), "LDKWatch_JCalls");
2494         atomic_init(&calls->refcnt, 1);
2495         DO_ASSERT((*env)->GetJavaVM(env, &calls->vm) == 0);
2496         calls->o = (*env)->NewWeakGlobalRef(env, o);
2497         calls->watch_channel_meth = (*env)->GetMethodID(env, c, "watch_channel", "(JJ)J");
2498         CHECK(calls->watch_channel_meth != NULL);
2499         calls->update_channel_meth = (*env)->GetMethodID(env, c, "update_channel", "(JJ)J");
2500         CHECK(calls->update_channel_meth != NULL);
2501         calls->release_pending_monitor_events_meth = (*env)->GetMethodID(env, c, "release_pending_monitor_events", "()[J");
2502         CHECK(calls->release_pending_monitor_events_meth != NULL);
2503
2504         LDKWatch ret = {
2505                 .this_arg = (void*) calls,
2506                 .watch_channel = watch_channel_jcall,
2507                 .update_channel = update_channel_jcall,
2508                 .release_pending_monitor_events = release_pending_monitor_events_jcall,
2509                 .free = LDKWatch_JCalls_free,
2510         };
2511         return ret;
2512 }
2513 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_LDKWatch_1new (JNIEnv * env, jclass _a, jobject o) {
2514         LDKWatch *res_ptr = MALLOC(sizeof(LDKWatch), "LDKWatch");
2515         *res_ptr = LDKWatch_init(env, _a, o);
2516         return (long)res_ptr;
2517 }
2518 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKWatch_1get_1obj_1from_1jcalls (JNIEnv * env, jclass _a, jlong val) {
2519         jobject ret = (*env)->NewLocalRef(env, ((LDKWatch_JCalls*)val)->o);
2520         CHECK(ret != NULL);
2521         return ret;
2522 }
2523 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_Watch_1watch_1channel(JNIEnv * _env, jclass _b, jlong this_arg, jlong funding_txo, jlong monitor) {
2524         LDKWatch* this_arg_conv = (LDKWatch*)this_arg;
2525         LDKOutPoint funding_txo_conv;
2526         funding_txo_conv.inner = (void*)(funding_txo & (~1));
2527         funding_txo_conv.is_owned = (funding_txo & 1) || (funding_txo == 0);
2528         if (funding_txo_conv.inner != NULL)
2529                 funding_txo_conv = OutPoint_clone(&funding_txo_conv);
2530         LDKChannelMonitor monitor_conv;
2531         monitor_conv.inner = (void*)(monitor & (~1));
2532         monitor_conv.is_owned = (monitor & 1) || (monitor == 0);
2533         // Warning: we may need a move here but can't clone!
2534         LDKCResult_NoneChannelMonitorUpdateErrZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneChannelMonitorUpdateErrZ), "LDKCResult_NoneChannelMonitorUpdateErrZ");
2535         *ret_conv = (this_arg_conv->watch_channel)(this_arg_conv->this_arg, funding_txo_conv, monitor_conv);
2536         return (long)ret_conv;
2537 }
2538
2539 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_Watch_1update_1channel(JNIEnv * _env, jclass _b, jlong this_arg, jlong funding_txo, jlong update) {
2540         LDKWatch* this_arg_conv = (LDKWatch*)this_arg;
2541         LDKOutPoint funding_txo_conv;
2542         funding_txo_conv.inner = (void*)(funding_txo & (~1));
2543         funding_txo_conv.is_owned = (funding_txo & 1) || (funding_txo == 0);
2544         if (funding_txo_conv.inner != NULL)
2545                 funding_txo_conv = OutPoint_clone(&funding_txo_conv);
2546         LDKChannelMonitorUpdate update_conv;
2547         update_conv.inner = (void*)(update & (~1));
2548         update_conv.is_owned = (update & 1) || (update == 0);
2549         if (update_conv.inner != NULL)
2550                 update_conv = ChannelMonitorUpdate_clone(&update_conv);
2551         LDKCResult_NoneChannelMonitorUpdateErrZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneChannelMonitorUpdateErrZ), "LDKCResult_NoneChannelMonitorUpdateErrZ");
2552         *ret_conv = (this_arg_conv->update_channel)(this_arg_conv->this_arg, funding_txo_conv, update_conv);
2553         return (long)ret_conv;
2554 }
2555
2556 JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_Watch_1release_1pending_1monitor_1events(JNIEnv * _env, jclass _b, jlong this_arg) {
2557         LDKWatch* this_arg_conv = (LDKWatch*)this_arg;
2558         LDKCVec_MonitorEventZ ret_var = (this_arg_conv->release_pending_monitor_events)(this_arg_conv->this_arg);
2559         jlongArray ret_arr = (*_env)->NewLongArray(_env, ret_var.datalen);
2560         jlong *ret_arr_ptr = (*_env)->GetPrimitiveArrayCritical(_env, ret_arr, NULL);
2561         for (size_t o = 0; o < ret_var.datalen; o++) {
2562                 LDKMonitorEvent arr_conv_14_var = ret_var.data[o];
2563                 CHECK((((long)arr_conv_14_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2564                 CHECK((((long)&arr_conv_14_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2565                 long arr_conv_14_ref = (long)arr_conv_14_var.inner;
2566                 if (arr_conv_14_var.is_owned) {
2567                         arr_conv_14_ref |= 1;
2568                 }
2569                 ret_arr_ptr[o] = arr_conv_14_ref;
2570         }
2571         (*_env)->ReleasePrimitiveArrayCritical(_env, ret_arr, ret_arr_ptr, 0);
2572         FREE(ret_var.data);
2573         return ret_arr;
2574 }
2575
2576 typedef struct LDKBroadcasterInterface_JCalls {
2577         atomic_size_t refcnt;
2578         JavaVM *vm;
2579         jweak o;
2580         jmethodID broadcast_transaction_meth;
2581 } LDKBroadcasterInterface_JCalls;
2582 void broadcast_transaction_jcall(const void* this_arg, struct LDKTransaction tx) {
2583         LDKBroadcasterInterface_JCalls *j_calls = (LDKBroadcasterInterface_JCalls*) this_arg;
2584         JNIEnv *_env;
2585         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
2586         LDKTransaction tx_var = tx;
2587         jbyteArray tx_arr = (*_env)->NewByteArray(_env, tx_var.datalen);
2588         (*_env)->SetByteArrayRegion(_env, tx_arr, 0, tx_var.datalen, tx_var.data);
2589         Transaction_free(tx_var);
2590         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
2591         CHECK(obj != NULL);
2592         return (*_env)->CallVoidMethod(_env, obj, j_calls->broadcast_transaction_meth, tx_arr);
2593 }
2594 static void LDKBroadcasterInterface_JCalls_free(void* this_arg) {
2595         LDKBroadcasterInterface_JCalls *j_calls = (LDKBroadcasterInterface_JCalls*) this_arg;
2596         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
2597                 JNIEnv *env;
2598                 DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
2599                 (*env)->DeleteWeakGlobalRef(env, j_calls->o);
2600                 FREE(j_calls);
2601         }
2602 }
2603 static void* LDKBroadcasterInterface_JCalls_clone(const void* this_arg) {
2604         LDKBroadcasterInterface_JCalls *j_calls = (LDKBroadcasterInterface_JCalls*) this_arg;
2605         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
2606         return (void*) this_arg;
2607 }
2608 static inline LDKBroadcasterInterface LDKBroadcasterInterface_init (JNIEnv * env, jclass _a, jobject o) {
2609         jclass c = (*env)->GetObjectClass(env, o);
2610         CHECK(c != NULL);
2611         LDKBroadcasterInterface_JCalls *calls = MALLOC(sizeof(LDKBroadcasterInterface_JCalls), "LDKBroadcasterInterface_JCalls");
2612         atomic_init(&calls->refcnt, 1);
2613         DO_ASSERT((*env)->GetJavaVM(env, &calls->vm) == 0);
2614         calls->o = (*env)->NewWeakGlobalRef(env, o);
2615         calls->broadcast_transaction_meth = (*env)->GetMethodID(env, c, "broadcast_transaction", "([B)V");
2616         CHECK(calls->broadcast_transaction_meth != NULL);
2617
2618         LDKBroadcasterInterface ret = {
2619                 .this_arg = (void*) calls,
2620                 .broadcast_transaction = broadcast_transaction_jcall,
2621                 .free = LDKBroadcasterInterface_JCalls_free,
2622         };
2623         return ret;
2624 }
2625 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_LDKBroadcasterInterface_1new (JNIEnv * env, jclass _a, jobject o) {
2626         LDKBroadcasterInterface *res_ptr = MALLOC(sizeof(LDKBroadcasterInterface), "LDKBroadcasterInterface");
2627         *res_ptr = LDKBroadcasterInterface_init(env, _a, o);
2628         return (long)res_ptr;
2629 }
2630 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKBroadcasterInterface_1get_1obj_1from_1jcalls (JNIEnv * env, jclass _a, jlong val) {
2631         jobject ret = (*env)->NewLocalRef(env, ((LDKBroadcasterInterface_JCalls*)val)->o);
2632         CHECK(ret != NULL);
2633         return ret;
2634 }
2635 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_BroadcasterInterface_1broadcast_1transaction(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray tx) {
2636         LDKBroadcasterInterface* this_arg_conv = (LDKBroadcasterInterface*)this_arg;
2637         LDKTransaction tx_ref;
2638         tx_ref.datalen = (*_env)->GetArrayLength (_env, tx);
2639         tx_ref.data = MALLOC(tx_ref.datalen, "LDKTransaction Bytes");
2640         (*_env)->GetByteArrayRegion(_env, tx, 0, tx_ref.datalen, tx_ref.data);
2641         tx_ref.data_is_owned = true;
2642         (this_arg_conv->broadcast_transaction)(this_arg_conv->this_arg, tx_ref);
2643 }
2644
2645 typedef struct LDKKeysInterface_JCalls {
2646         atomic_size_t refcnt;
2647         JavaVM *vm;
2648         jweak o;
2649         jmethodID get_node_secret_meth;
2650         jmethodID get_destination_script_meth;
2651         jmethodID get_shutdown_pubkey_meth;
2652         jmethodID get_channel_keys_meth;
2653         jmethodID get_secure_random_bytes_meth;
2654         jmethodID read_chan_signer_meth;
2655 } LDKKeysInterface_JCalls;
2656 LDKSecretKey get_node_secret_jcall(const void* this_arg) {
2657         LDKKeysInterface_JCalls *j_calls = (LDKKeysInterface_JCalls*) this_arg;
2658         JNIEnv *_env;
2659         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
2660         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
2661         CHECK(obj != NULL);
2662         jbyteArray arg = (*_env)->CallObjectMethod(_env, obj, j_calls->get_node_secret_meth);
2663         LDKSecretKey arg_ref;
2664         CHECK((*_env)->GetArrayLength (_env, arg) == 32);
2665         (*_env)->GetByteArrayRegion (_env, arg, 0, 32, arg_ref.bytes);
2666         return arg_ref;
2667 }
2668 LDKCVec_u8Z get_destination_script_jcall(const void* this_arg) {
2669         LDKKeysInterface_JCalls *j_calls = (LDKKeysInterface_JCalls*) this_arg;
2670         JNIEnv *_env;
2671         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
2672         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
2673         CHECK(obj != NULL);
2674         jbyteArray arg = (*_env)->CallObjectMethod(_env, obj, j_calls->get_destination_script_meth);
2675         LDKCVec_u8Z arg_ref;
2676         arg_ref.datalen = (*_env)->GetArrayLength (_env, arg);
2677         arg_ref.data = MALLOC(arg_ref.datalen, "LDKCVec_u8Z Bytes");
2678         (*_env)->GetByteArrayRegion(_env, arg, 0, arg_ref.datalen, arg_ref.data);
2679         return arg_ref;
2680 }
2681 LDKPublicKey get_shutdown_pubkey_jcall(const void* this_arg) {
2682         LDKKeysInterface_JCalls *j_calls = (LDKKeysInterface_JCalls*) this_arg;
2683         JNIEnv *_env;
2684         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
2685         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
2686         CHECK(obj != NULL);
2687         jbyteArray arg = (*_env)->CallObjectMethod(_env, obj, j_calls->get_shutdown_pubkey_meth);
2688         LDKPublicKey arg_ref;
2689         CHECK((*_env)->GetArrayLength (_env, arg) == 33);
2690         (*_env)->GetByteArrayRegion (_env, arg, 0, 33, arg_ref.compressed_form);
2691         return arg_ref;
2692 }
2693 LDKChannelKeys get_channel_keys_jcall(const void* this_arg, bool inbound, uint64_t channel_value_satoshis) {
2694         LDKKeysInterface_JCalls *j_calls = (LDKKeysInterface_JCalls*) this_arg;
2695         JNIEnv *_env;
2696         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
2697         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
2698         CHECK(obj != NULL);
2699         LDKChannelKeys* ret = (LDKChannelKeys*)(*_env)->CallLongMethod(_env, obj, j_calls->get_channel_keys_meth, inbound, channel_value_satoshis);
2700         LDKChannelKeys ret_conv = *(LDKChannelKeys*)ret;
2701         ret_conv = ChannelKeys_clone(ret);
2702         return ret_conv;
2703 }
2704 LDKThirtyTwoBytes get_secure_random_bytes_jcall(const void* this_arg) {
2705         LDKKeysInterface_JCalls *j_calls = (LDKKeysInterface_JCalls*) this_arg;
2706         JNIEnv *_env;
2707         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
2708         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
2709         CHECK(obj != NULL);
2710         jbyteArray arg = (*_env)->CallObjectMethod(_env, obj, j_calls->get_secure_random_bytes_meth);
2711         LDKThirtyTwoBytes arg_ref;
2712         CHECK((*_env)->GetArrayLength (_env, arg) == 32);
2713         (*_env)->GetByteArrayRegion (_env, arg, 0, 32, arg_ref.data);
2714         return arg_ref;
2715 }
2716 LDKCResult_ChanKeySignerDecodeErrorZ read_chan_signer_jcall(const void* this_arg, struct LDKu8slice reader) {
2717         LDKKeysInterface_JCalls *j_calls = (LDKKeysInterface_JCalls*) this_arg;
2718         JNIEnv *_env;
2719         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
2720         LDKu8slice reader_var = reader;
2721         jbyteArray reader_arr = (*_env)->NewByteArray(_env, reader_var.datalen);
2722         (*_env)->SetByteArrayRegion(_env, reader_arr, 0, reader_var.datalen, reader_var.data);
2723         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
2724         CHECK(obj != NULL);
2725         LDKCResult_ChanKeySignerDecodeErrorZ* ret = (LDKCResult_ChanKeySignerDecodeErrorZ*)(*_env)->CallLongMethod(_env, obj, j_calls->read_chan_signer_meth, reader_arr);
2726         LDKCResult_ChanKeySignerDecodeErrorZ ret_conv = *(LDKCResult_ChanKeySignerDecodeErrorZ*)ret;
2727         FREE((void*)ret);
2728         return ret_conv;
2729 }
2730 static void LDKKeysInterface_JCalls_free(void* this_arg) {
2731         LDKKeysInterface_JCalls *j_calls = (LDKKeysInterface_JCalls*) this_arg;
2732         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
2733                 JNIEnv *env;
2734                 DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
2735                 (*env)->DeleteWeakGlobalRef(env, j_calls->o);
2736                 FREE(j_calls);
2737         }
2738 }
2739 static void* LDKKeysInterface_JCalls_clone(const void* this_arg) {
2740         LDKKeysInterface_JCalls *j_calls = (LDKKeysInterface_JCalls*) this_arg;
2741         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
2742         return (void*) this_arg;
2743 }
2744 static inline LDKKeysInterface LDKKeysInterface_init (JNIEnv * env, jclass _a, jobject o) {
2745         jclass c = (*env)->GetObjectClass(env, o);
2746         CHECK(c != NULL);
2747         LDKKeysInterface_JCalls *calls = MALLOC(sizeof(LDKKeysInterface_JCalls), "LDKKeysInterface_JCalls");
2748         atomic_init(&calls->refcnt, 1);
2749         DO_ASSERT((*env)->GetJavaVM(env, &calls->vm) == 0);
2750         calls->o = (*env)->NewWeakGlobalRef(env, o);
2751         calls->get_node_secret_meth = (*env)->GetMethodID(env, c, "get_node_secret", "()[B");
2752         CHECK(calls->get_node_secret_meth != NULL);
2753         calls->get_destination_script_meth = (*env)->GetMethodID(env, c, "get_destination_script", "()[B");
2754         CHECK(calls->get_destination_script_meth != NULL);
2755         calls->get_shutdown_pubkey_meth = (*env)->GetMethodID(env, c, "get_shutdown_pubkey", "()[B");
2756         CHECK(calls->get_shutdown_pubkey_meth != NULL);
2757         calls->get_channel_keys_meth = (*env)->GetMethodID(env, c, "get_channel_keys", "(ZJ)J");
2758         CHECK(calls->get_channel_keys_meth != NULL);
2759         calls->get_secure_random_bytes_meth = (*env)->GetMethodID(env, c, "get_secure_random_bytes", "()[B");
2760         CHECK(calls->get_secure_random_bytes_meth != NULL);
2761         calls->read_chan_signer_meth = (*env)->GetMethodID(env, c, "read_chan_signer", "([B)J");
2762         CHECK(calls->read_chan_signer_meth != NULL);
2763
2764         LDKKeysInterface ret = {
2765                 .this_arg = (void*) calls,
2766                 .get_node_secret = get_node_secret_jcall,
2767                 .get_destination_script = get_destination_script_jcall,
2768                 .get_shutdown_pubkey = get_shutdown_pubkey_jcall,
2769                 .get_channel_keys = get_channel_keys_jcall,
2770                 .get_secure_random_bytes = get_secure_random_bytes_jcall,
2771                 .read_chan_signer = read_chan_signer_jcall,
2772                 .free = LDKKeysInterface_JCalls_free,
2773         };
2774         return ret;
2775 }
2776 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_LDKKeysInterface_1new (JNIEnv * env, jclass _a, jobject o) {
2777         LDKKeysInterface *res_ptr = MALLOC(sizeof(LDKKeysInterface), "LDKKeysInterface");
2778         *res_ptr = LDKKeysInterface_init(env, _a, o);
2779         return (long)res_ptr;
2780 }
2781 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKKeysInterface_1get_1obj_1from_1jcalls (JNIEnv * env, jclass _a, jlong val) {
2782         jobject ret = (*env)->NewLocalRef(env, ((LDKKeysInterface_JCalls*)val)->o);
2783         CHECK(ret != NULL);
2784         return ret;
2785 }
2786 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_KeysInterface_1get_1node_1secret(JNIEnv * _env, jclass _b, jlong this_arg) {
2787         LDKKeysInterface* this_arg_conv = (LDKKeysInterface*)this_arg;
2788         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 32);
2789         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 32, (this_arg_conv->get_node_secret)(this_arg_conv->this_arg).bytes);
2790         return arg_arr;
2791 }
2792
2793 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_KeysInterface_1get_1destination_1script(JNIEnv * _env, jclass _b, jlong this_arg) {
2794         LDKKeysInterface* this_arg_conv = (LDKKeysInterface*)this_arg;
2795         LDKCVec_u8Z arg_var = (this_arg_conv->get_destination_script)(this_arg_conv->this_arg);
2796         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
2797         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
2798         CVec_u8Z_free(arg_var);
2799         return arg_arr;
2800 }
2801
2802 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_KeysInterface_1get_1shutdown_1pubkey(JNIEnv * _env, jclass _b, jlong this_arg) {
2803         LDKKeysInterface* this_arg_conv = (LDKKeysInterface*)this_arg;
2804         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
2805         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, (this_arg_conv->get_shutdown_pubkey)(this_arg_conv->this_arg).compressed_form);
2806         return arg_arr;
2807 }
2808
2809 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_KeysInterface_1get_1channel_1keys(JNIEnv * _env, jclass _b, jlong this_arg, jboolean inbound, jlong channel_value_satoshis) {
2810         LDKKeysInterface* this_arg_conv = (LDKKeysInterface*)this_arg;
2811         LDKChannelKeys* ret = MALLOC(sizeof(LDKChannelKeys), "LDKChannelKeys");
2812         *ret = (this_arg_conv->get_channel_keys)(this_arg_conv->this_arg, inbound, channel_value_satoshis);
2813         return (long)ret;
2814 }
2815
2816 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_KeysInterface_1get_1secure_1random_1bytes(JNIEnv * _env, jclass _b, jlong this_arg) {
2817         LDKKeysInterface* this_arg_conv = (LDKKeysInterface*)this_arg;
2818         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 32);
2819         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 32, (this_arg_conv->get_secure_random_bytes)(this_arg_conv->this_arg).data);
2820         return arg_arr;
2821 }
2822
2823 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_KeysInterface_1read_1chan_1signer(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray reader) {
2824         LDKKeysInterface* this_arg_conv = (LDKKeysInterface*)this_arg;
2825         LDKu8slice reader_ref;
2826         reader_ref.datalen = (*_env)->GetArrayLength (_env, reader);
2827         reader_ref.data = (*_env)->GetByteArrayElements (_env, reader, NULL);
2828         LDKCResult_ChanKeySignerDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ChanKeySignerDecodeErrorZ), "LDKCResult_ChanKeySignerDecodeErrorZ");
2829         *ret_conv = (this_arg_conv->read_chan_signer)(this_arg_conv->this_arg, reader_ref);
2830         (*_env)->ReleaseByteArrayElements(_env, reader, (int8_t*)reader_ref.data, 0);
2831         return (long)ret_conv;
2832 }
2833
2834 typedef struct LDKFeeEstimator_JCalls {
2835         atomic_size_t refcnt;
2836         JavaVM *vm;
2837         jweak o;
2838         jmethodID get_est_sat_per_1000_weight_meth;
2839 } LDKFeeEstimator_JCalls;
2840 uint32_t get_est_sat_per_1000_weight_jcall(const void* this_arg, enum LDKConfirmationTarget confirmation_target) {
2841         LDKFeeEstimator_JCalls *j_calls = (LDKFeeEstimator_JCalls*) this_arg;
2842         JNIEnv *_env;
2843         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
2844         jclass confirmation_target_conv = LDKConfirmationTarget_to_java(_env, confirmation_target);
2845         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
2846         CHECK(obj != NULL);
2847         return (*_env)->CallIntMethod(_env, obj, j_calls->get_est_sat_per_1000_weight_meth, confirmation_target_conv);
2848 }
2849 static void LDKFeeEstimator_JCalls_free(void* this_arg) {
2850         LDKFeeEstimator_JCalls *j_calls = (LDKFeeEstimator_JCalls*) this_arg;
2851         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
2852                 JNIEnv *env;
2853                 DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
2854                 (*env)->DeleteWeakGlobalRef(env, j_calls->o);
2855                 FREE(j_calls);
2856         }
2857 }
2858 static void* LDKFeeEstimator_JCalls_clone(const void* this_arg) {
2859         LDKFeeEstimator_JCalls *j_calls = (LDKFeeEstimator_JCalls*) this_arg;
2860         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
2861         return (void*) this_arg;
2862 }
2863 static inline LDKFeeEstimator LDKFeeEstimator_init (JNIEnv * env, jclass _a, jobject o) {
2864         jclass c = (*env)->GetObjectClass(env, o);
2865         CHECK(c != NULL);
2866         LDKFeeEstimator_JCalls *calls = MALLOC(sizeof(LDKFeeEstimator_JCalls), "LDKFeeEstimator_JCalls");
2867         atomic_init(&calls->refcnt, 1);
2868         DO_ASSERT((*env)->GetJavaVM(env, &calls->vm) == 0);
2869         calls->o = (*env)->NewWeakGlobalRef(env, o);
2870         calls->get_est_sat_per_1000_weight_meth = (*env)->GetMethodID(env, c, "get_est_sat_per_1000_weight", "(Lorg/ldk/enums/LDKConfirmationTarget;)I");
2871         CHECK(calls->get_est_sat_per_1000_weight_meth != NULL);
2872
2873         LDKFeeEstimator ret = {
2874                 .this_arg = (void*) calls,
2875                 .get_est_sat_per_1000_weight = get_est_sat_per_1000_weight_jcall,
2876                 .free = LDKFeeEstimator_JCalls_free,
2877         };
2878         return ret;
2879 }
2880 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_LDKFeeEstimator_1new (JNIEnv * env, jclass _a, jobject o) {
2881         LDKFeeEstimator *res_ptr = MALLOC(sizeof(LDKFeeEstimator), "LDKFeeEstimator");
2882         *res_ptr = LDKFeeEstimator_init(env, _a, o);
2883         return (long)res_ptr;
2884 }
2885 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKFeeEstimator_1get_1obj_1from_1jcalls (JNIEnv * env, jclass _a, jlong val) {
2886         jobject ret = (*env)->NewLocalRef(env, ((LDKFeeEstimator_JCalls*)val)->o);
2887         CHECK(ret != NULL);
2888         return ret;
2889 }
2890 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_FeeEstimator_1get_1est_1sat_1per_11000_1weight(JNIEnv * _env, jclass _b, jlong this_arg, jclass confirmation_target) {
2891         LDKFeeEstimator* this_arg_conv = (LDKFeeEstimator*)this_arg;
2892         LDKConfirmationTarget confirmation_target_conv = LDKConfirmationTarget_from_java(_env, confirmation_target);
2893         jint ret_val = (this_arg_conv->get_est_sat_per_1000_weight)(this_arg_conv->this_arg, confirmation_target_conv);
2894         return ret_val;
2895 }
2896
2897 typedef struct LDKLogger_JCalls {
2898         atomic_size_t refcnt;
2899         JavaVM *vm;
2900         jweak o;
2901         jmethodID log_meth;
2902 } LDKLogger_JCalls;
2903 void log_jcall(const void* this_arg, const char *record) {
2904         LDKLogger_JCalls *j_calls = (LDKLogger_JCalls*) this_arg;
2905         JNIEnv *_env;
2906         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
2907         jstring record_conv = (*_env)->NewStringUTF(_env, record);
2908         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
2909         CHECK(obj != NULL);
2910         return (*_env)->CallVoidMethod(_env, obj, j_calls->log_meth, record_conv);
2911 }
2912 static void LDKLogger_JCalls_free(void* this_arg) {
2913         LDKLogger_JCalls *j_calls = (LDKLogger_JCalls*) this_arg;
2914         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
2915                 JNIEnv *env;
2916                 DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
2917                 (*env)->DeleteWeakGlobalRef(env, j_calls->o);
2918                 FREE(j_calls);
2919         }
2920 }
2921 static void* LDKLogger_JCalls_clone(const void* this_arg) {
2922         LDKLogger_JCalls *j_calls = (LDKLogger_JCalls*) this_arg;
2923         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
2924         return (void*) this_arg;
2925 }
2926 static inline LDKLogger LDKLogger_init (JNIEnv * env, jclass _a, jobject o) {
2927         jclass c = (*env)->GetObjectClass(env, o);
2928         CHECK(c != NULL);
2929         LDKLogger_JCalls *calls = MALLOC(sizeof(LDKLogger_JCalls), "LDKLogger_JCalls");
2930         atomic_init(&calls->refcnt, 1);
2931         DO_ASSERT((*env)->GetJavaVM(env, &calls->vm) == 0);
2932         calls->o = (*env)->NewWeakGlobalRef(env, o);
2933         calls->log_meth = (*env)->GetMethodID(env, c, "log", "(Ljava/lang/String;)V");
2934         CHECK(calls->log_meth != NULL);
2935
2936         LDKLogger ret = {
2937                 .this_arg = (void*) calls,
2938                 .log = log_jcall,
2939                 .free = LDKLogger_JCalls_free,
2940         };
2941         return ret;
2942 }
2943 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_LDKLogger_1new (JNIEnv * env, jclass _a, jobject o) {
2944         LDKLogger *res_ptr = MALLOC(sizeof(LDKLogger), "LDKLogger");
2945         *res_ptr = LDKLogger_init(env, _a, o);
2946         return (long)res_ptr;
2947 }
2948 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKLogger_1get_1obj_1from_1jcalls (JNIEnv * env, jclass _a, jlong val) {
2949         jobject ret = (*env)->NewLocalRef(env, ((LDKLogger_JCalls*)val)->o);
2950         CHECK(ret != NULL);
2951         return ret;
2952 }
2953 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKC2Tuple_1BlockHashChannelManagerZ_1new(JNIEnv *_env, jclass _b, jbyteArray a, jlong b) {
2954         LDKC2Tuple_BlockHashChannelManagerZ* ret = MALLOC(sizeof(LDKC2Tuple_BlockHashChannelManagerZ), "LDKC2Tuple_BlockHashChannelManagerZ");
2955         LDKThirtyTwoBytes a_ref;
2956         CHECK((*_env)->GetArrayLength (_env, a) == 32);
2957         (*_env)->GetByteArrayRegion (_env, a, 0, 32, a_ref.data);
2958         ret->a = a_ref;
2959         LDKChannelManager b_conv;
2960         b_conv.inner = (void*)(b & (~1));
2961         b_conv.is_owned = (b & 1) || (b == 0);
2962         // Warning: we may need a move here but can't clone!
2963         ret->b = b_conv;
2964         return (long)ret;
2965 }
2966 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_LDKC2Tuple_1BlockHashChannelManagerZ_1get_1a(JNIEnv *_env, jclass _b, jlong ptr) {
2967         LDKC2Tuple_BlockHashChannelManagerZ *tuple = (LDKC2Tuple_BlockHashChannelManagerZ*)ptr;
2968         jbyteArray a_arr = (*_env)->NewByteArray(_env, 32);
2969         (*_env)->SetByteArrayRegion(_env, a_arr, 0, 32, tuple->a.data);
2970         return a_arr;
2971 }
2972 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKC2Tuple_1BlockHashChannelManagerZ_1get_1b(JNIEnv *_env, jclass _b, jlong ptr) {
2973         LDKC2Tuple_BlockHashChannelManagerZ *tuple = (LDKC2Tuple_BlockHashChannelManagerZ*)ptr;
2974         LDKChannelManager b_var = tuple->b;
2975         CHECK((((long)b_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2976         CHECK((((long)&b_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2977         long b_ref = (long)b_var.inner & ~1;
2978         return b_ref;
2979 }
2980 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1C2Tuple_1BlockHashChannelManagerZDecodeErrorZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
2981         return ((LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ*)arg)->result_ok;
2982 }
2983 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1C2Tuple_1BlockHashChannelManagerZDecodeErrorZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
2984         LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ *val = (LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ*)arg;
2985         CHECK(val->result_ok);
2986         long res_ref = (long)&(*val->contents.result);
2987         return res_ref;
2988 }
2989 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1C2Tuple_1BlockHashChannelManagerZDecodeErrorZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
2990         LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ *val = (LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ*)arg;
2991         CHECK(!val->result_ok);
2992         LDKDecodeError err_var = (*val->contents.err);
2993         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2994         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2995         long err_ref = (long)err_var.inner & ~1;
2996         return err_ref;
2997 }
2998 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NetAddressu8Z_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
2999         return ((LDKCResult_NetAddressu8Z*)arg)->result_ok;
3000 }
3001 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NetAddressu8Z_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
3002         LDKCResult_NetAddressu8Z *val = (LDKCResult_NetAddressu8Z*)arg;
3003         CHECK(val->result_ok);
3004         long res_ref = (long)&(*val->contents.result);
3005         return res_ref;
3006 }
3007 JNIEXPORT jbyte JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NetAddressu8Z_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
3008         LDKCResult_NetAddressu8Z *val = (LDKCResult_NetAddressu8Z*)arg;
3009         CHECK(!val->result_ok);
3010         return *val->contents.err;
3011 }
3012 static inline LDKCResult_NetAddressu8Z CResult_NetAddressu8Z_clone(const LDKCResult_NetAddressu8Z *orig) {
3013         LDKCResult_NetAddressu8Z res = { .result_ok = orig->result_ok };
3014         if (orig->result_ok) {
3015                 LDKNetAddress* contents = MALLOC(sizeof(LDKNetAddress), "LDKNetAddress result OK clone");
3016                 *contents = NetAddress_clone(orig->contents.result);
3017                 res.contents.result = contents;
3018         } else {
3019                 jbyte* contents = MALLOC(sizeof(jbyte), "jbyte result Err clone");
3020                 *contents = *orig->contents.err;
3021                 res.contents.err = contents;
3022         }
3023         return res;
3024 }
3025 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1CResult_1NetAddressu8ZDecodeErrorZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
3026         return ((LDKCResult_CResult_NetAddressu8ZDecodeErrorZ*)arg)->result_ok;
3027 }
3028 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1CResult_1NetAddressu8ZDecodeErrorZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
3029         LDKCResult_CResult_NetAddressu8ZDecodeErrorZ *val = (LDKCResult_CResult_NetAddressu8ZDecodeErrorZ*)arg;
3030         CHECK(val->result_ok);
3031         LDKCResult_NetAddressu8Z* res_conv = MALLOC(sizeof(LDKCResult_NetAddressu8Z), "LDKCResult_NetAddressu8Z");
3032         *res_conv = (*val->contents.result);
3033         *res_conv = CResult_NetAddressu8Z_clone(res_conv);
3034         return (long)res_conv;
3035 }
3036 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1CResult_1NetAddressu8ZDecodeErrorZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
3037         LDKCResult_CResult_NetAddressu8ZDecodeErrorZ *val = (LDKCResult_CResult_NetAddressu8ZDecodeErrorZ*)arg;
3038         CHECK(!val->result_ok);
3039         LDKDecodeError err_var = (*val->contents.err);
3040         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3041         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3042         long err_ref = (long)err_var.inner & ~1;
3043         return err_ref;
3044 }
3045 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKCVec_1u64Z_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
3046         LDKCVec_u64Z *vec = (LDKCVec_u64Z*)ptr;
3047         return (*env)->NewObject(env, slicedef_cls, slicedef_meth, (long)vec->data, (long)vec->datalen, sizeof(uint64_t));
3048 }
3049 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVec_1u64Z_1new(JNIEnv *env, jclass _b, jlongArray elems){
3050         LDKCVec_u64Z *ret = MALLOC(sizeof(LDKCVec_u64Z), "LDKCVec_u64Z");
3051         ret->datalen = (*env)->GetArrayLength(env, elems);
3052         if (ret->datalen == 0) {
3053                 ret->data = NULL;
3054         } else {
3055                 ret->data = MALLOC(sizeof(uint64_t) * ret->datalen, "LDKCVec_u64Z Data");
3056                 jlong *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
3057                 for (size_t i = 0; i < ret->datalen; i++) {
3058                         ret->data[i] = java_elems[i];
3059                 }
3060                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
3061         }
3062         return (long)ret;
3063 }
3064 static inline LDKCVec_u64Z CVec_u64Z_clone(const LDKCVec_u64Z *orig) {
3065         LDKCVec_u64Z ret = { .data = MALLOC(sizeof(jlong) * orig->datalen, "LDKCVec_u64Z clone bytes"), .datalen = orig->datalen };
3066         memcpy(ret.data, orig->data, sizeof(jlong) * ret.datalen);
3067         return ret;
3068 }
3069 JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_LDKCVec_1UpdateAddHTLCZ_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
3070         LDKCVec_UpdateAddHTLCZ *vec = (LDKCVec_UpdateAddHTLCZ*)ptr;
3071         jlongArray ret = (*env)->NewLongArray(env, vec->datalen);
3072         jlong *ret_elems = (*env)->GetPrimitiveArrayCritical(env, ret, NULL);
3073         for (size_t i = 0; i < vec->datalen; i++) {
3074                 CHECK((((long)vec->data[i].inner) & 1) == 0);
3075                 ret_elems[i] = (long)vec->data[i].inner | (vec->data[i].is_owned ? 1 : 0);
3076         }
3077         (*env)->ReleasePrimitiveArrayCritical(env, ret, ret_elems, 0);
3078         return ret;
3079 }
3080 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVec_1UpdateAddHTLCZ_1new(JNIEnv *env, jclass _b, jlongArray elems){
3081         LDKCVec_UpdateAddHTLCZ *ret = MALLOC(sizeof(LDKCVec_UpdateAddHTLCZ), "LDKCVec_UpdateAddHTLCZ");
3082         ret->datalen = (*env)->GetArrayLength(env, elems);
3083         if (ret->datalen == 0) {
3084                 ret->data = NULL;
3085         } else {
3086                 ret->data = MALLOC(sizeof(LDKUpdateAddHTLC) * ret->datalen, "LDKCVec_UpdateAddHTLCZ Data");
3087                 jlong *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
3088                 for (size_t i = 0; i < ret->datalen; i++) {
3089                         jlong arr_elem = java_elems[i];
3090                         LDKUpdateAddHTLC arr_elem_conv;
3091                         arr_elem_conv.inner = (void*)(arr_elem & (~1));
3092                         arr_elem_conv.is_owned = (arr_elem & 1) || (arr_elem == 0);
3093                         if (arr_elem_conv.inner != NULL)
3094                                 arr_elem_conv = UpdateAddHTLC_clone(&arr_elem_conv);
3095                         ret->data[i] = arr_elem_conv;
3096                 }
3097                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
3098         }
3099         return (long)ret;
3100 }
3101 static inline LDKCVec_UpdateAddHTLCZ CVec_UpdateAddHTLCZ_clone(const LDKCVec_UpdateAddHTLCZ *orig) {
3102         LDKCVec_UpdateAddHTLCZ ret = { .data = MALLOC(sizeof(LDKUpdateAddHTLC) * orig->datalen, "LDKCVec_UpdateAddHTLCZ clone bytes"), .datalen = orig->datalen };
3103         for (size_t i = 0; i < ret.datalen; i++) {
3104                 ret.data[i] = UpdateAddHTLC_clone(&orig->data[i]);
3105         }
3106         return ret;
3107 }
3108 JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_LDKCVec_1UpdateFulfillHTLCZ_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
3109         LDKCVec_UpdateFulfillHTLCZ *vec = (LDKCVec_UpdateFulfillHTLCZ*)ptr;
3110         jlongArray ret = (*env)->NewLongArray(env, vec->datalen);
3111         jlong *ret_elems = (*env)->GetPrimitiveArrayCritical(env, ret, NULL);
3112         for (size_t i = 0; i < vec->datalen; i++) {
3113                 CHECK((((long)vec->data[i].inner) & 1) == 0);
3114                 ret_elems[i] = (long)vec->data[i].inner | (vec->data[i].is_owned ? 1 : 0);
3115         }
3116         (*env)->ReleasePrimitiveArrayCritical(env, ret, ret_elems, 0);
3117         return ret;
3118 }
3119 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVec_1UpdateFulfillHTLCZ_1new(JNIEnv *env, jclass _b, jlongArray elems){
3120         LDKCVec_UpdateFulfillHTLCZ *ret = MALLOC(sizeof(LDKCVec_UpdateFulfillHTLCZ), "LDKCVec_UpdateFulfillHTLCZ");
3121         ret->datalen = (*env)->GetArrayLength(env, elems);
3122         if (ret->datalen == 0) {
3123                 ret->data = NULL;
3124         } else {
3125                 ret->data = MALLOC(sizeof(LDKUpdateFulfillHTLC) * ret->datalen, "LDKCVec_UpdateFulfillHTLCZ Data");
3126                 jlong *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
3127                 for (size_t i = 0; i < ret->datalen; i++) {
3128                         jlong arr_elem = java_elems[i];
3129                         LDKUpdateFulfillHTLC arr_elem_conv;
3130                         arr_elem_conv.inner = (void*)(arr_elem & (~1));
3131                         arr_elem_conv.is_owned = (arr_elem & 1) || (arr_elem == 0);
3132                         if (arr_elem_conv.inner != NULL)
3133                                 arr_elem_conv = UpdateFulfillHTLC_clone(&arr_elem_conv);
3134                         ret->data[i] = arr_elem_conv;
3135                 }
3136                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
3137         }
3138         return (long)ret;
3139 }
3140 static inline LDKCVec_UpdateFulfillHTLCZ CVec_UpdateFulfillHTLCZ_clone(const LDKCVec_UpdateFulfillHTLCZ *orig) {
3141         LDKCVec_UpdateFulfillHTLCZ ret = { .data = MALLOC(sizeof(LDKUpdateFulfillHTLC) * orig->datalen, "LDKCVec_UpdateFulfillHTLCZ clone bytes"), .datalen = orig->datalen };
3142         for (size_t i = 0; i < ret.datalen; i++) {
3143                 ret.data[i] = UpdateFulfillHTLC_clone(&orig->data[i]);
3144         }
3145         return ret;
3146 }
3147 JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_LDKCVec_1UpdateFailHTLCZ_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
3148         LDKCVec_UpdateFailHTLCZ *vec = (LDKCVec_UpdateFailHTLCZ*)ptr;
3149         jlongArray ret = (*env)->NewLongArray(env, vec->datalen);
3150         jlong *ret_elems = (*env)->GetPrimitiveArrayCritical(env, ret, NULL);
3151         for (size_t i = 0; i < vec->datalen; i++) {
3152                 CHECK((((long)vec->data[i].inner) & 1) == 0);
3153                 ret_elems[i] = (long)vec->data[i].inner | (vec->data[i].is_owned ? 1 : 0);
3154         }
3155         (*env)->ReleasePrimitiveArrayCritical(env, ret, ret_elems, 0);
3156         return ret;
3157 }
3158 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVec_1UpdateFailHTLCZ_1new(JNIEnv *env, jclass _b, jlongArray elems){
3159         LDKCVec_UpdateFailHTLCZ *ret = MALLOC(sizeof(LDKCVec_UpdateFailHTLCZ), "LDKCVec_UpdateFailHTLCZ");
3160         ret->datalen = (*env)->GetArrayLength(env, elems);
3161         if (ret->datalen == 0) {
3162                 ret->data = NULL;
3163         } else {
3164                 ret->data = MALLOC(sizeof(LDKUpdateFailHTLC) * ret->datalen, "LDKCVec_UpdateFailHTLCZ Data");
3165                 jlong *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
3166                 for (size_t i = 0; i < ret->datalen; i++) {
3167                         jlong arr_elem = java_elems[i];
3168                         LDKUpdateFailHTLC arr_elem_conv;
3169                         arr_elem_conv.inner = (void*)(arr_elem & (~1));
3170                         arr_elem_conv.is_owned = (arr_elem & 1) || (arr_elem == 0);
3171                         if (arr_elem_conv.inner != NULL)
3172                                 arr_elem_conv = UpdateFailHTLC_clone(&arr_elem_conv);
3173                         ret->data[i] = arr_elem_conv;
3174                 }
3175                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
3176         }
3177         return (long)ret;
3178 }
3179 static inline LDKCVec_UpdateFailHTLCZ CVec_UpdateFailHTLCZ_clone(const LDKCVec_UpdateFailHTLCZ *orig) {
3180         LDKCVec_UpdateFailHTLCZ ret = { .data = MALLOC(sizeof(LDKUpdateFailHTLC) * orig->datalen, "LDKCVec_UpdateFailHTLCZ clone bytes"), .datalen = orig->datalen };
3181         for (size_t i = 0; i < ret.datalen; i++) {
3182                 ret.data[i] = UpdateFailHTLC_clone(&orig->data[i]);
3183         }
3184         return ret;
3185 }
3186 JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_LDKCVec_1UpdateFailMalformedHTLCZ_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
3187         LDKCVec_UpdateFailMalformedHTLCZ *vec = (LDKCVec_UpdateFailMalformedHTLCZ*)ptr;
3188         jlongArray ret = (*env)->NewLongArray(env, vec->datalen);
3189         jlong *ret_elems = (*env)->GetPrimitiveArrayCritical(env, ret, NULL);
3190         for (size_t i = 0; i < vec->datalen; i++) {
3191                 CHECK((((long)vec->data[i].inner) & 1) == 0);
3192                 ret_elems[i] = (long)vec->data[i].inner | (vec->data[i].is_owned ? 1 : 0);
3193         }
3194         (*env)->ReleasePrimitiveArrayCritical(env, ret, ret_elems, 0);
3195         return ret;
3196 }
3197 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVec_1UpdateFailMalformedHTLCZ_1new(JNIEnv *env, jclass _b, jlongArray elems){
3198         LDKCVec_UpdateFailMalformedHTLCZ *ret = MALLOC(sizeof(LDKCVec_UpdateFailMalformedHTLCZ), "LDKCVec_UpdateFailMalformedHTLCZ");
3199         ret->datalen = (*env)->GetArrayLength(env, elems);
3200         if (ret->datalen == 0) {
3201                 ret->data = NULL;
3202         } else {
3203                 ret->data = MALLOC(sizeof(LDKUpdateFailMalformedHTLC) * ret->datalen, "LDKCVec_UpdateFailMalformedHTLCZ Data");
3204                 jlong *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
3205                 for (size_t i = 0; i < ret->datalen; i++) {
3206                         jlong arr_elem = java_elems[i];
3207                         LDKUpdateFailMalformedHTLC arr_elem_conv;
3208                         arr_elem_conv.inner = (void*)(arr_elem & (~1));
3209                         arr_elem_conv.is_owned = (arr_elem & 1) || (arr_elem == 0);
3210                         if (arr_elem_conv.inner != NULL)
3211                                 arr_elem_conv = UpdateFailMalformedHTLC_clone(&arr_elem_conv);
3212                         ret->data[i] = arr_elem_conv;
3213                 }
3214                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
3215         }
3216         return (long)ret;
3217 }
3218 static inline LDKCVec_UpdateFailMalformedHTLCZ CVec_UpdateFailMalformedHTLCZ_clone(const LDKCVec_UpdateFailMalformedHTLCZ *orig) {
3219         LDKCVec_UpdateFailMalformedHTLCZ ret = { .data = MALLOC(sizeof(LDKUpdateFailMalformedHTLC) * orig->datalen, "LDKCVec_UpdateFailMalformedHTLCZ clone bytes"), .datalen = orig->datalen };
3220         for (size_t i = 0; i < ret.datalen; i++) {
3221                 ret.data[i] = UpdateFailMalformedHTLC_clone(&orig->data[i]);
3222         }
3223         return ret;
3224 }
3225 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1boolLightningErrorZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
3226         return ((LDKCResult_boolLightningErrorZ*)arg)->result_ok;
3227 }
3228 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1boolLightningErrorZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
3229         LDKCResult_boolLightningErrorZ *val = (LDKCResult_boolLightningErrorZ*)arg;
3230         CHECK(val->result_ok);
3231         return *val->contents.result;
3232 }
3233 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1boolLightningErrorZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
3234         LDKCResult_boolLightningErrorZ *val = (LDKCResult_boolLightningErrorZ*)arg;
3235         CHECK(!val->result_ok);
3236         LDKLightningError err_var = (*val->contents.err);
3237         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3238         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3239         long err_ref = (long)err_var.inner & ~1;
3240         return err_ref;
3241 }
3242 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKC3Tuple_1ChannelAnnouncementChannelUpdateChannelUpdateZ_1new(JNIEnv *_env, jclass _b, jlong a, jlong b, jlong c) {
3243         LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ* ret = MALLOC(sizeof(LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ), "LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ");
3244         LDKChannelAnnouncement a_conv;
3245         a_conv.inner = (void*)(a & (~1));
3246         a_conv.is_owned = (a & 1) || (a == 0);
3247         if (a_conv.inner != NULL)
3248                 a_conv = ChannelAnnouncement_clone(&a_conv);
3249         ret->a = a_conv;
3250         LDKChannelUpdate b_conv;
3251         b_conv.inner = (void*)(b & (~1));
3252         b_conv.is_owned = (b & 1) || (b == 0);
3253         if (b_conv.inner != NULL)
3254                 b_conv = ChannelUpdate_clone(&b_conv);
3255         ret->b = b_conv;
3256         LDKChannelUpdate c_conv;
3257         c_conv.inner = (void*)(c & (~1));
3258         c_conv.is_owned = (c & 1) || (c == 0);
3259         if (c_conv.inner != NULL)
3260                 c_conv = ChannelUpdate_clone(&c_conv);
3261         ret->c = c_conv;
3262         return (long)ret;
3263 }
3264 static inline LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ_clone(const LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ *orig) {
3265         LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ ret = {
3266                 .a = ChannelAnnouncement_clone(&orig->a),
3267                 .b = ChannelUpdate_clone(&orig->b),
3268                 .c = ChannelUpdate_clone(&orig->c),
3269         };
3270         return ret;
3271 }
3272 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKC3Tuple_1ChannelAnnouncementChannelUpdateChannelUpdateZ_1get_1a(JNIEnv *_env, jclass _b, jlong ptr) {
3273         LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ *tuple = (LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ*)ptr;
3274         LDKChannelAnnouncement a_var = tuple->a;
3275         CHECK((((long)a_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3276         CHECK((((long)&a_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3277         long a_ref = (long)a_var.inner & ~1;
3278         return a_ref;
3279 }
3280 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKC3Tuple_1ChannelAnnouncementChannelUpdateChannelUpdateZ_1get_1b(JNIEnv *_env, jclass _b, jlong ptr) {
3281         LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ *tuple = (LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ*)ptr;
3282         LDKChannelUpdate b_var = tuple->b;
3283         CHECK((((long)b_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3284         CHECK((((long)&b_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3285         long b_ref = (long)b_var.inner & ~1;
3286         return b_ref;
3287 }
3288 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKC3Tuple_1ChannelAnnouncementChannelUpdateChannelUpdateZ_1get_1c(JNIEnv *_env, jclass _b, jlong ptr) {
3289         LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ *tuple = (LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ*)ptr;
3290         LDKChannelUpdate c_var = tuple->c;
3291         CHECK((((long)c_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3292         CHECK((((long)&c_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3293         long c_ref = (long)c_var.inner & ~1;
3294         return c_ref;
3295 }
3296 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKCVec_1C3Tuple_1ChannelAnnouncementChannelUpdateChannelUpdateZZ_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
3297         LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ *vec = (LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ*)ptr;
3298         return (*env)->NewObject(env, slicedef_cls, slicedef_meth, (long)vec->data, (long)vec->datalen, sizeof(LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ));
3299 }
3300 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVec_1C3Tuple_1ChannelAnnouncementChannelUpdateChannelUpdateZZ_1new(JNIEnv *env, jclass _b, jlongArray elems){
3301         LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ *ret = MALLOC(sizeof(LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ), "LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ");
3302         ret->datalen = (*env)->GetArrayLength(env, elems);
3303         if (ret->datalen == 0) {
3304                 ret->data = NULL;
3305         } else {
3306                 ret->data = MALLOC(sizeof(LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ) * ret->datalen, "LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ Data");
3307                 jlong *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
3308                 for (size_t i = 0; i < ret->datalen; i++) {
3309                         jlong arr_elem = java_elems[i];
3310                         LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ arr_elem_conv = *(LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ*)arr_elem;
3311                         FREE((void*)arr_elem);
3312                         ret->data[i] = arr_elem_conv;
3313                 }
3314                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
3315         }
3316         return (long)ret;
3317 }
3318 static inline LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ CVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ_clone(const LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ *orig) {
3319         LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ ret = { .data = MALLOC(sizeof(LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ) * orig->datalen, "LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ clone bytes"), .datalen = orig->datalen };
3320         for (size_t i = 0; i < ret.datalen; i++) {
3321                 ret.data[i] = C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ_clone(&orig->data[i]);
3322         }
3323         return ret;
3324 }
3325 JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_LDKCVec_1NodeAnnouncementZ_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
3326         LDKCVec_NodeAnnouncementZ *vec = (LDKCVec_NodeAnnouncementZ*)ptr;
3327         jlongArray ret = (*env)->NewLongArray(env, vec->datalen);
3328         jlong *ret_elems = (*env)->GetPrimitiveArrayCritical(env, ret, NULL);
3329         for (size_t i = 0; i < vec->datalen; i++) {
3330                 CHECK((((long)vec->data[i].inner) & 1) == 0);
3331                 ret_elems[i] = (long)vec->data[i].inner | (vec->data[i].is_owned ? 1 : 0);
3332         }
3333         (*env)->ReleasePrimitiveArrayCritical(env, ret, ret_elems, 0);
3334         return ret;
3335 }
3336 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVec_1NodeAnnouncementZ_1new(JNIEnv *env, jclass _b, jlongArray elems){
3337         LDKCVec_NodeAnnouncementZ *ret = MALLOC(sizeof(LDKCVec_NodeAnnouncementZ), "LDKCVec_NodeAnnouncementZ");
3338         ret->datalen = (*env)->GetArrayLength(env, elems);
3339         if (ret->datalen == 0) {
3340                 ret->data = NULL;
3341         } else {
3342                 ret->data = MALLOC(sizeof(LDKNodeAnnouncement) * ret->datalen, "LDKCVec_NodeAnnouncementZ Data");
3343                 jlong *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
3344                 for (size_t i = 0; i < ret->datalen; i++) {
3345                         jlong arr_elem = java_elems[i];
3346                         LDKNodeAnnouncement arr_elem_conv;
3347                         arr_elem_conv.inner = (void*)(arr_elem & (~1));
3348                         arr_elem_conv.is_owned = (arr_elem & 1) || (arr_elem == 0);
3349                         if (arr_elem_conv.inner != NULL)
3350                                 arr_elem_conv = NodeAnnouncement_clone(&arr_elem_conv);
3351                         ret->data[i] = arr_elem_conv;
3352                 }
3353                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
3354         }
3355         return (long)ret;
3356 }
3357 static inline LDKCVec_NodeAnnouncementZ CVec_NodeAnnouncementZ_clone(const LDKCVec_NodeAnnouncementZ *orig) {
3358         LDKCVec_NodeAnnouncementZ ret = { .data = MALLOC(sizeof(LDKNodeAnnouncement) * orig->datalen, "LDKCVec_NodeAnnouncementZ clone bytes"), .datalen = orig->datalen };
3359         for (size_t i = 0; i < ret.datalen; i++) {
3360                 ret.data[i] = NodeAnnouncement_clone(&orig->data[i]);
3361         }
3362         return ret;
3363 }
3364 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NoneLightningErrorZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
3365         return ((LDKCResult_NoneLightningErrorZ*)arg)->result_ok;
3366 }
3367 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NoneLightningErrorZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
3368         LDKCResult_NoneLightningErrorZ *val = (LDKCResult_NoneLightningErrorZ*)arg;
3369         CHECK(val->result_ok);
3370         return *val->contents.result;
3371 }
3372 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NoneLightningErrorZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
3373         LDKCResult_NoneLightningErrorZ *val = (LDKCResult_NoneLightningErrorZ*)arg;
3374         CHECK(!val->result_ok);
3375         LDKLightningError err_var = (*val->contents.err);
3376         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3377         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3378         long err_ref = (long)err_var.inner & ~1;
3379         return err_ref;
3380 }
3381 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1ChannelReestablishDecodeErrorZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
3382         return ((LDKCResult_ChannelReestablishDecodeErrorZ*)arg)->result_ok;
3383 }
3384 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1ChannelReestablishDecodeErrorZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
3385         LDKCResult_ChannelReestablishDecodeErrorZ *val = (LDKCResult_ChannelReestablishDecodeErrorZ*)arg;
3386         CHECK(val->result_ok);
3387         LDKChannelReestablish res_var = (*val->contents.result);
3388         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3389         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3390         long res_ref = (long)res_var.inner & ~1;
3391         return res_ref;
3392 }
3393 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1ChannelReestablishDecodeErrorZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
3394         LDKCResult_ChannelReestablishDecodeErrorZ *val = (LDKCResult_ChannelReestablishDecodeErrorZ*)arg;
3395         CHECK(!val->result_ok);
3396         LDKDecodeError err_var = (*val->contents.err);
3397         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3398         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3399         long err_ref = (long)err_var.inner & ~1;
3400         return err_ref;
3401 }
3402 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1InitDecodeErrorZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
3403         return ((LDKCResult_InitDecodeErrorZ*)arg)->result_ok;
3404 }
3405 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1InitDecodeErrorZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
3406         LDKCResult_InitDecodeErrorZ *val = (LDKCResult_InitDecodeErrorZ*)arg;
3407         CHECK(val->result_ok);
3408         LDKInit res_var = (*val->contents.result);
3409         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3410         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3411         long res_ref = (long)res_var.inner & ~1;
3412         return res_ref;
3413 }
3414 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1InitDecodeErrorZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
3415         LDKCResult_InitDecodeErrorZ *val = (LDKCResult_InitDecodeErrorZ*)arg;
3416         CHECK(!val->result_ok);
3417         LDKDecodeError err_var = (*val->contents.err);
3418         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3419         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3420         long err_ref = (long)err_var.inner & ~1;
3421         return err_ref;
3422 }
3423 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1PingDecodeErrorZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
3424         return ((LDKCResult_PingDecodeErrorZ*)arg)->result_ok;
3425 }
3426 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1PingDecodeErrorZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
3427         LDKCResult_PingDecodeErrorZ *val = (LDKCResult_PingDecodeErrorZ*)arg;
3428         CHECK(val->result_ok);
3429         LDKPing res_var = (*val->contents.result);
3430         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3431         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3432         long res_ref = (long)res_var.inner & ~1;
3433         return res_ref;
3434 }
3435 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1PingDecodeErrorZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
3436         LDKCResult_PingDecodeErrorZ *val = (LDKCResult_PingDecodeErrorZ*)arg;
3437         CHECK(!val->result_ok);
3438         LDKDecodeError err_var = (*val->contents.err);
3439         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3440         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3441         long err_ref = (long)err_var.inner & ~1;
3442         return err_ref;
3443 }
3444 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1PongDecodeErrorZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
3445         return ((LDKCResult_PongDecodeErrorZ*)arg)->result_ok;
3446 }
3447 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1PongDecodeErrorZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
3448         LDKCResult_PongDecodeErrorZ *val = (LDKCResult_PongDecodeErrorZ*)arg;
3449         CHECK(val->result_ok);
3450         LDKPong res_var = (*val->contents.result);
3451         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3452         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3453         long res_ref = (long)res_var.inner & ~1;
3454         return res_ref;
3455 }
3456 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1PongDecodeErrorZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
3457         LDKCResult_PongDecodeErrorZ *val = (LDKCResult_PongDecodeErrorZ*)arg;
3458         CHECK(!val->result_ok);
3459         LDKDecodeError err_var = (*val->contents.err);
3460         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3461         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3462         long err_ref = (long)err_var.inner & ~1;
3463         return err_ref;
3464 }
3465 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1UnsignedChannelAnnouncementDecodeErrorZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
3466         return ((LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ*)arg)->result_ok;
3467 }
3468 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1UnsignedChannelAnnouncementDecodeErrorZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
3469         LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ *val = (LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ*)arg;
3470         CHECK(val->result_ok);
3471         LDKUnsignedChannelAnnouncement res_var = (*val->contents.result);
3472         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3473         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3474         long res_ref = (long)res_var.inner & ~1;
3475         return res_ref;
3476 }
3477 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1UnsignedChannelAnnouncementDecodeErrorZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
3478         LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ *val = (LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ*)arg;
3479         CHECK(!val->result_ok);
3480         LDKDecodeError err_var = (*val->contents.err);
3481         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3482         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3483         long err_ref = (long)err_var.inner & ~1;
3484         return err_ref;
3485 }
3486 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1UnsignedChannelUpdateDecodeErrorZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
3487         return ((LDKCResult_UnsignedChannelUpdateDecodeErrorZ*)arg)->result_ok;
3488 }
3489 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1UnsignedChannelUpdateDecodeErrorZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
3490         LDKCResult_UnsignedChannelUpdateDecodeErrorZ *val = (LDKCResult_UnsignedChannelUpdateDecodeErrorZ*)arg;
3491         CHECK(val->result_ok);
3492         LDKUnsignedChannelUpdate res_var = (*val->contents.result);
3493         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3494         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3495         long res_ref = (long)res_var.inner & ~1;
3496         return res_ref;
3497 }
3498 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1UnsignedChannelUpdateDecodeErrorZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
3499         LDKCResult_UnsignedChannelUpdateDecodeErrorZ *val = (LDKCResult_UnsignedChannelUpdateDecodeErrorZ*)arg;
3500         CHECK(!val->result_ok);
3501         LDKDecodeError err_var = (*val->contents.err);
3502         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3503         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3504         long err_ref = (long)err_var.inner & ~1;
3505         return err_ref;
3506 }
3507 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1ErrorMessageDecodeErrorZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
3508         return ((LDKCResult_ErrorMessageDecodeErrorZ*)arg)->result_ok;
3509 }
3510 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1ErrorMessageDecodeErrorZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
3511         LDKCResult_ErrorMessageDecodeErrorZ *val = (LDKCResult_ErrorMessageDecodeErrorZ*)arg;
3512         CHECK(val->result_ok);
3513         LDKErrorMessage res_var = (*val->contents.result);
3514         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3515         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3516         long res_ref = (long)res_var.inner & ~1;
3517         return res_ref;
3518 }
3519 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1ErrorMessageDecodeErrorZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
3520         LDKCResult_ErrorMessageDecodeErrorZ *val = (LDKCResult_ErrorMessageDecodeErrorZ*)arg;
3521         CHECK(!val->result_ok);
3522         LDKDecodeError err_var = (*val->contents.err);
3523         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3524         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3525         long err_ref = (long)err_var.inner & ~1;
3526         return err_ref;
3527 }
3528 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1UnsignedNodeAnnouncementDecodeErrorZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
3529         return ((LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ*)arg)->result_ok;
3530 }
3531 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1UnsignedNodeAnnouncementDecodeErrorZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
3532         LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ *val = (LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ*)arg;
3533         CHECK(val->result_ok);
3534         LDKUnsignedNodeAnnouncement res_var = (*val->contents.result);
3535         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3536         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3537         long res_ref = (long)res_var.inner & ~1;
3538         return res_ref;
3539 }
3540 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1UnsignedNodeAnnouncementDecodeErrorZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
3541         LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ *val = (LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ*)arg;
3542         CHECK(!val->result_ok);
3543         LDKDecodeError err_var = (*val->contents.err);
3544         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3545         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3546         long err_ref = (long)err_var.inner & ~1;
3547         return err_ref;
3548 }
3549 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1QueryShortChannelIdsDecodeErrorZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
3550         return ((LDKCResult_QueryShortChannelIdsDecodeErrorZ*)arg)->result_ok;
3551 }
3552 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1QueryShortChannelIdsDecodeErrorZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
3553         LDKCResult_QueryShortChannelIdsDecodeErrorZ *val = (LDKCResult_QueryShortChannelIdsDecodeErrorZ*)arg;
3554         CHECK(val->result_ok);
3555         LDKQueryShortChannelIds res_var = (*val->contents.result);
3556         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3557         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3558         long res_ref = (long)res_var.inner & ~1;
3559         return res_ref;
3560 }
3561 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1QueryShortChannelIdsDecodeErrorZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
3562         LDKCResult_QueryShortChannelIdsDecodeErrorZ *val = (LDKCResult_QueryShortChannelIdsDecodeErrorZ*)arg;
3563         CHECK(!val->result_ok);
3564         LDKDecodeError err_var = (*val->contents.err);
3565         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3566         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3567         long err_ref = (long)err_var.inner & ~1;
3568         return err_ref;
3569 }
3570 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1ReplyShortChannelIdsEndDecodeErrorZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
3571         return ((LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ*)arg)->result_ok;
3572 }
3573 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1ReplyShortChannelIdsEndDecodeErrorZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
3574         LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ *val = (LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ*)arg;
3575         CHECK(val->result_ok);
3576         LDKReplyShortChannelIdsEnd res_var = (*val->contents.result);
3577         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3578         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3579         long res_ref = (long)res_var.inner & ~1;
3580         return res_ref;
3581 }
3582 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1ReplyShortChannelIdsEndDecodeErrorZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
3583         LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ *val = (LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ*)arg;
3584         CHECK(!val->result_ok);
3585         LDKDecodeError err_var = (*val->contents.err);
3586         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3587         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3588         long err_ref = (long)err_var.inner & ~1;
3589         return err_ref;
3590 }
3591 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1QueryChannelRangeDecodeErrorZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
3592         return ((LDKCResult_QueryChannelRangeDecodeErrorZ*)arg)->result_ok;
3593 }
3594 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1QueryChannelRangeDecodeErrorZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
3595         LDKCResult_QueryChannelRangeDecodeErrorZ *val = (LDKCResult_QueryChannelRangeDecodeErrorZ*)arg;
3596         CHECK(val->result_ok);
3597         LDKQueryChannelRange res_var = (*val->contents.result);
3598         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3599         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3600         long res_ref = (long)res_var.inner & ~1;
3601         return res_ref;
3602 }
3603 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1QueryChannelRangeDecodeErrorZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
3604         LDKCResult_QueryChannelRangeDecodeErrorZ *val = (LDKCResult_QueryChannelRangeDecodeErrorZ*)arg;
3605         CHECK(!val->result_ok);
3606         LDKDecodeError err_var = (*val->contents.err);
3607         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3608         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3609         long err_ref = (long)err_var.inner & ~1;
3610         return err_ref;
3611 }
3612 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1ReplyChannelRangeDecodeErrorZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
3613         return ((LDKCResult_ReplyChannelRangeDecodeErrorZ*)arg)->result_ok;
3614 }
3615 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1ReplyChannelRangeDecodeErrorZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
3616         LDKCResult_ReplyChannelRangeDecodeErrorZ *val = (LDKCResult_ReplyChannelRangeDecodeErrorZ*)arg;
3617         CHECK(val->result_ok);
3618         LDKReplyChannelRange res_var = (*val->contents.result);
3619         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3620         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3621         long res_ref = (long)res_var.inner & ~1;
3622         return res_ref;
3623 }
3624 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1ReplyChannelRangeDecodeErrorZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
3625         LDKCResult_ReplyChannelRangeDecodeErrorZ *val = (LDKCResult_ReplyChannelRangeDecodeErrorZ*)arg;
3626         CHECK(!val->result_ok);
3627         LDKDecodeError err_var = (*val->contents.err);
3628         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3629         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3630         long err_ref = (long)err_var.inner & ~1;
3631         return err_ref;
3632 }
3633 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1GossipTimestampFilterDecodeErrorZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
3634         return ((LDKCResult_GossipTimestampFilterDecodeErrorZ*)arg)->result_ok;
3635 }
3636 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1GossipTimestampFilterDecodeErrorZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
3637         LDKCResult_GossipTimestampFilterDecodeErrorZ *val = (LDKCResult_GossipTimestampFilterDecodeErrorZ*)arg;
3638         CHECK(val->result_ok);
3639         LDKGossipTimestampFilter res_var = (*val->contents.result);
3640         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3641         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3642         long res_ref = (long)res_var.inner & ~1;
3643         return res_ref;
3644 }
3645 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1GossipTimestampFilterDecodeErrorZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
3646         LDKCResult_GossipTimestampFilterDecodeErrorZ *val = (LDKCResult_GossipTimestampFilterDecodeErrorZ*)arg;
3647         CHECK(!val->result_ok);
3648         LDKDecodeError err_var = (*val->contents.err);
3649         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3650         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3651         long err_ref = (long)err_var.inner & ~1;
3652         return err_ref;
3653 }
3654 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKCVec_1PublicKeyZ_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
3655         LDKCVec_PublicKeyZ *vec = (LDKCVec_PublicKeyZ*)ptr;
3656         return (*env)->NewObject(env, slicedef_cls, slicedef_meth, (long)vec->data, (long)vec->datalen, sizeof(LDKPublicKey));
3657 }
3658 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1CVec_1u8ZPeerHandleErrorZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
3659         return ((LDKCResult_CVec_u8ZPeerHandleErrorZ*)arg)->result_ok;
3660 }
3661 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_LDKCResult_1CVec_1u8ZPeerHandleErrorZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
3662         LDKCResult_CVec_u8ZPeerHandleErrorZ *val = (LDKCResult_CVec_u8ZPeerHandleErrorZ*)arg;
3663         CHECK(val->result_ok);
3664         LDKCVec_u8Z res_var = (*val->contents.result);
3665         jbyteArray res_arr = (*_env)->NewByteArray(_env, res_var.datalen);
3666         (*_env)->SetByteArrayRegion(_env, res_arr, 0, res_var.datalen, res_var.data);
3667         return res_arr;
3668 }
3669 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1CVec_1u8ZPeerHandleErrorZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
3670         LDKCResult_CVec_u8ZPeerHandleErrorZ *val = (LDKCResult_CVec_u8ZPeerHandleErrorZ*)arg;
3671         CHECK(!val->result_ok);
3672         LDKPeerHandleError err_var = (*val->contents.err);
3673         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3674         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3675         long err_ref = (long)err_var.inner & ~1;
3676         return err_ref;
3677 }
3678 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NonePeerHandleErrorZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
3679         return ((LDKCResult_NonePeerHandleErrorZ*)arg)->result_ok;
3680 }
3681 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NonePeerHandleErrorZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
3682         LDKCResult_NonePeerHandleErrorZ *val = (LDKCResult_NonePeerHandleErrorZ*)arg;
3683         CHECK(val->result_ok);
3684         return *val->contents.result;
3685 }
3686 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NonePeerHandleErrorZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
3687         LDKCResult_NonePeerHandleErrorZ *val = (LDKCResult_NonePeerHandleErrorZ*)arg;
3688         CHECK(!val->result_ok);
3689         LDKPeerHandleError err_var = (*val->contents.err);
3690         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3691         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3692         long err_ref = (long)err_var.inner & ~1;
3693         return err_ref;
3694 }
3695 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1boolPeerHandleErrorZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
3696         return ((LDKCResult_boolPeerHandleErrorZ*)arg)->result_ok;
3697 }
3698 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1boolPeerHandleErrorZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
3699         LDKCResult_boolPeerHandleErrorZ *val = (LDKCResult_boolPeerHandleErrorZ*)arg;
3700         CHECK(val->result_ok);
3701         return *val->contents.result;
3702 }
3703 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1boolPeerHandleErrorZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
3704         LDKCResult_boolPeerHandleErrorZ *val = (LDKCResult_boolPeerHandleErrorZ*)arg;
3705         CHECK(!val->result_ok);
3706         LDKPeerHandleError err_var = (*val->contents.err);
3707         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3708         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3709         long err_ref = (long)err_var.inner & ~1;
3710         return err_ref;
3711 }
3712 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1SecretKeySecpErrorZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
3713         return ((LDKCResult_SecretKeySecpErrorZ*)arg)->result_ok;
3714 }
3715 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_LDKCResult_1SecretKeySecpErrorZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
3716         LDKCResult_SecretKeySecpErrorZ *val = (LDKCResult_SecretKeySecpErrorZ*)arg;
3717         CHECK(val->result_ok);
3718         jbyteArray res_arr = (*_env)->NewByteArray(_env, 32);
3719         (*_env)->SetByteArrayRegion(_env, res_arr, 0, 32, (*val->contents.result).bytes);
3720         return res_arr;
3721 }
3722 JNIEXPORT jclass JNICALL Java_org_ldk_impl_bindings_LDKCResult_1SecretKeySecpErrorZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
3723         LDKCResult_SecretKeySecpErrorZ *val = (LDKCResult_SecretKeySecpErrorZ*)arg;
3724         CHECK(!val->result_ok);
3725         jclass err_conv = LDKSecp256k1Error_to_java(_env, (*val->contents.err));
3726         return err_conv;
3727 }
3728 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1PublicKeySecpErrorZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
3729         return ((LDKCResult_PublicKeySecpErrorZ*)arg)->result_ok;
3730 }
3731 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_LDKCResult_1PublicKeySecpErrorZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
3732         LDKCResult_PublicKeySecpErrorZ *val = (LDKCResult_PublicKeySecpErrorZ*)arg;
3733         CHECK(val->result_ok);
3734         jbyteArray res_arr = (*_env)->NewByteArray(_env, 33);
3735         (*_env)->SetByteArrayRegion(_env, res_arr, 0, 33, (*val->contents.result).compressed_form);
3736         return res_arr;
3737 }
3738 JNIEXPORT jclass JNICALL Java_org_ldk_impl_bindings_LDKCResult_1PublicKeySecpErrorZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
3739         LDKCResult_PublicKeySecpErrorZ *val = (LDKCResult_PublicKeySecpErrorZ*)arg;
3740         CHECK(!val->result_ok);
3741         jclass err_conv = LDKSecp256k1Error_to_java(_env, (*val->contents.err));
3742         return err_conv;
3743 }
3744 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1TxCreationKeysSecpErrorZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
3745         return ((LDKCResult_TxCreationKeysSecpErrorZ*)arg)->result_ok;
3746 }
3747 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1TxCreationKeysSecpErrorZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
3748         LDKCResult_TxCreationKeysSecpErrorZ *val = (LDKCResult_TxCreationKeysSecpErrorZ*)arg;
3749         CHECK(val->result_ok);
3750         LDKTxCreationKeys res_var = (*val->contents.result);
3751         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3752         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3753         long res_ref = (long)res_var.inner & ~1;
3754         return res_ref;
3755 }
3756 JNIEXPORT jclass JNICALL Java_org_ldk_impl_bindings_LDKCResult_1TxCreationKeysSecpErrorZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
3757         LDKCResult_TxCreationKeysSecpErrorZ *val = (LDKCResult_TxCreationKeysSecpErrorZ*)arg;
3758         CHECK(!val->result_ok);
3759         jclass err_conv = LDKSecp256k1Error_to_java(_env, (*val->contents.err));
3760         return err_conv;
3761 }
3762 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1TrustedCommitmentTransactionNoneZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
3763         return ((LDKCResult_TrustedCommitmentTransactionNoneZ*)arg)->result_ok;
3764 }
3765 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1TrustedCommitmentTransactionNoneZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
3766         LDKCResult_TrustedCommitmentTransactionNoneZ *val = (LDKCResult_TrustedCommitmentTransactionNoneZ*)arg;
3767         CHECK(val->result_ok);
3768         LDKTrustedCommitmentTransaction res_var = (*val->contents.result);
3769         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3770         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3771         long res_ref = (long)res_var.inner & ~1;
3772         return res_ref;
3773 }
3774 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_LDKCResult_1TrustedCommitmentTransactionNoneZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
3775         LDKCResult_TrustedCommitmentTransactionNoneZ *val = (LDKCResult_TrustedCommitmentTransactionNoneZ*)arg;
3776         CHECK(!val->result_ok);
3777         return *val->contents.err;
3778 }
3779 JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_LDKCVec_1RouteHopZ_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
3780         LDKCVec_RouteHopZ *vec = (LDKCVec_RouteHopZ*)ptr;
3781         jlongArray ret = (*env)->NewLongArray(env, vec->datalen);
3782         jlong *ret_elems = (*env)->GetPrimitiveArrayCritical(env, ret, NULL);
3783         for (size_t i = 0; i < vec->datalen; i++) {
3784                 CHECK((((long)vec->data[i].inner) & 1) == 0);
3785                 ret_elems[i] = (long)vec->data[i].inner | (vec->data[i].is_owned ? 1 : 0);
3786         }
3787         (*env)->ReleasePrimitiveArrayCritical(env, ret, ret_elems, 0);
3788         return ret;
3789 }
3790 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVec_1RouteHopZ_1new(JNIEnv *env, jclass _b, jlongArray elems){
3791         LDKCVec_RouteHopZ *ret = MALLOC(sizeof(LDKCVec_RouteHopZ), "LDKCVec_RouteHopZ");
3792         ret->datalen = (*env)->GetArrayLength(env, elems);
3793         if (ret->datalen == 0) {
3794                 ret->data = NULL;
3795         } else {
3796                 ret->data = MALLOC(sizeof(LDKRouteHop) * ret->datalen, "LDKCVec_RouteHopZ Data");
3797                 jlong *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
3798                 for (size_t i = 0; i < ret->datalen; i++) {
3799                         jlong arr_elem = java_elems[i];
3800                         LDKRouteHop arr_elem_conv;
3801                         arr_elem_conv.inner = (void*)(arr_elem & (~1));
3802                         arr_elem_conv.is_owned = (arr_elem & 1) || (arr_elem == 0);
3803                         if (arr_elem_conv.inner != NULL)
3804                                 arr_elem_conv = RouteHop_clone(&arr_elem_conv);
3805                         ret->data[i] = arr_elem_conv;
3806                 }
3807                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
3808         }
3809         return (long)ret;
3810 }
3811 static inline LDKCVec_RouteHopZ CVec_RouteHopZ_clone(const LDKCVec_RouteHopZ *orig) {
3812         LDKCVec_RouteHopZ ret = { .data = MALLOC(sizeof(LDKRouteHop) * orig->datalen, "LDKCVec_RouteHopZ clone bytes"), .datalen = orig->datalen };
3813         for (size_t i = 0; i < ret.datalen; i++) {
3814                 ret.data[i] = RouteHop_clone(&orig->data[i]);
3815         }
3816         return ret;
3817 }
3818 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKCVec_1CVec_1RouteHopZZ_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
3819         LDKCVec_CVec_RouteHopZZ *vec = (LDKCVec_CVec_RouteHopZZ*)ptr;
3820         return (*env)->NewObject(env, slicedef_cls, slicedef_meth, (long)vec->data, (long)vec->datalen, sizeof(LDKCVec_RouteHopZ));
3821 }
3822 static inline LDKCVec_CVec_RouteHopZZ CVec_CVec_RouteHopZZ_clone(const LDKCVec_CVec_RouteHopZZ *orig) {
3823         LDKCVec_CVec_RouteHopZZ ret = { .data = MALLOC(sizeof(LDKCVec_RouteHopZ) * orig->datalen, "LDKCVec_CVec_RouteHopZZ clone bytes"), .datalen = orig->datalen };
3824         for (size_t i = 0; i < ret.datalen; i++) {
3825                 ret.data[i] = CVec_RouteHopZ_clone(&orig->data[i]);
3826         }
3827         return ret;
3828 }
3829 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1RouteDecodeErrorZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
3830         return ((LDKCResult_RouteDecodeErrorZ*)arg)->result_ok;
3831 }
3832 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1RouteDecodeErrorZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
3833         LDKCResult_RouteDecodeErrorZ *val = (LDKCResult_RouteDecodeErrorZ*)arg;
3834         CHECK(val->result_ok);
3835         LDKRoute res_var = (*val->contents.result);
3836         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3837         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3838         long res_ref = (long)res_var.inner & ~1;
3839         return res_ref;
3840 }
3841 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1RouteDecodeErrorZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
3842         LDKCResult_RouteDecodeErrorZ *val = (LDKCResult_RouteDecodeErrorZ*)arg;
3843         CHECK(!val->result_ok);
3844         LDKDecodeError err_var = (*val->contents.err);
3845         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3846         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3847         long err_ref = (long)err_var.inner & ~1;
3848         return err_ref;
3849 }
3850 JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_LDKCVec_1RouteHintZ_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
3851         LDKCVec_RouteHintZ *vec = (LDKCVec_RouteHintZ*)ptr;
3852         jlongArray ret = (*env)->NewLongArray(env, vec->datalen);
3853         jlong *ret_elems = (*env)->GetPrimitiveArrayCritical(env, ret, NULL);
3854         for (size_t i = 0; i < vec->datalen; i++) {
3855                 CHECK((((long)vec->data[i].inner) & 1) == 0);
3856                 ret_elems[i] = (long)vec->data[i].inner | (vec->data[i].is_owned ? 1 : 0);
3857         }
3858         (*env)->ReleasePrimitiveArrayCritical(env, ret, ret_elems, 0);
3859         return ret;
3860 }
3861 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVec_1RouteHintZ_1new(JNIEnv *env, jclass _b, jlongArray elems){
3862         LDKCVec_RouteHintZ *ret = MALLOC(sizeof(LDKCVec_RouteHintZ), "LDKCVec_RouteHintZ");
3863         ret->datalen = (*env)->GetArrayLength(env, elems);
3864         if (ret->datalen == 0) {
3865                 ret->data = NULL;
3866         } else {
3867                 ret->data = MALLOC(sizeof(LDKRouteHint) * ret->datalen, "LDKCVec_RouteHintZ Data");
3868                 jlong *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
3869                 for (size_t i = 0; i < ret->datalen; i++) {
3870                         jlong arr_elem = java_elems[i];
3871                         LDKRouteHint arr_elem_conv;
3872                         arr_elem_conv.inner = (void*)(arr_elem & (~1));
3873                         arr_elem_conv.is_owned = (arr_elem & 1) || (arr_elem == 0);
3874                         if (arr_elem_conv.inner != NULL)
3875                                 arr_elem_conv = RouteHint_clone(&arr_elem_conv);
3876                         ret->data[i] = arr_elem_conv;
3877                 }
3878                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
3879         }
3880         return (long)ret;
3881 }
3882 static inline LDKCVec_RouteHintZ CVec_RouteHintZ_clone(const LDKCVec_RouteHintZ *orig) {
3883         LDKCVec_RouteHintZ ret = { .data = MALLOC(sizeof(LDKRouteHint) * orig->datalen, "LDKCVec_RouteHintZ clone bytes"), .datalen = orig->datalen };
3884         for (size_t i = 0; i < ret.datalen; i++) {
3885                 ret.data[i] = RouteHint_clone(&orig->data[i]);
3886         }
3887         return ret;
3888 }
3889 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1RouteLightningErrorZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
3890         return ((LDKCResult_RouteLightningErrorZ*)arg)->result_ok;
3891 }
3892 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1RouteLightningErrorZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
3893         LDKCResult_RouteLightningErrorZ *val = (LDKCResult_RouteLightningErrorZ*)arg;
3894         CHECK(val->result_ok);
3895         LDKRoute res_var = (*val->contents.result);
3896         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3897         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3898         long res_ref = (long)res_var.inner & ~1;
3899         return res_ref;
3900 }
3901 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1RouteLightningErrorZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
3902         LDKCResult_RouteLightningErrorZ *val = (LDKCResult_RouteLightningErrorZ*)arg;
3903         CHECK(!val->result_ok);
3904         LDKLightningError err_var = (*val->contents.err);
3905         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3906         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3907         long err_ref = (long)err_var.inner & ~1;
3908         return err_ref;
3909 }
3910 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1RoutingFeesDecodeErrorZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
3911         return ((LDKCResult_RoutingFeesDecodeErrorZ*)arg)->result_ok;
3912 }
3913 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1RoutingFeesDecodeErrorZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
3914         LDKCResult_RoutingFeesDecodeErrorZ *val = (LDKCResult_RoutingFeesDecodeErrorZ*)arg;
3915         CHECK(val->result_ok);
3916         LDKRoutingFees res_var = (*val->contents.result);
3917         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3918         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3919         long res_ref = (long)res_var.inner & ~1;
3920         return res_ref;
3921 }
3922 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1RoutingFeesDecodeErrorZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
3923         LDKCResult_RoutingFeesDecodeErrorZ *val = (LDKCResult_RoutingFeesDecodeErrorZ*)arg;
3924         CHECK(!val->result_ok);
3925         LDKDecodeError err_var = (*val->contents.err);
3926         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3927         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3928         long err_ref = (long)err_var.inner & ~1;
3929         return err_ref;
3930 }
3931 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NodeAnnouncementInfoDecodeErrorZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
3932         return ((LDKCResult_NodeAnnouncementInfoDecodeErrorZ*)arg)->result_ok;
3933 }
3934 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NodeAnnouncementInfoDecodeErrorZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
3935         LDKCResult_NodeAnnouncementInfoDecodeErrorZ *val = (LDKCResult_NodeAnnouncementInfoDecodeErrorZ*)arg;
3936         CHECK(val->result_ok);
3937         LDKNodeAnnouncementInfo res_var = (*val->contents.result);
3938         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3939         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3940         long res_ref = (long)res_var.inner & ~1;
3941         return res_ref;
3942 }
3943 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NodeAnnouncementInfoDecodeErrorZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
3944         LDKCResult_NodeAnnouncementInfoDecodeErrorZ *val = (LDKCResult_NodeAnnouncementInfoDecodeErrorZ*)arg;
3945         CHECK(!val->result_ok);
3946         LDKDecodeError err_var = (*val->contents.err);
3947         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3948         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3949         long err_ref = (long)err_var.inner & ~1;
3950         return err_ref;
3951 }
3952 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NodeInfoDecodeErrorZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
3953         return ((LDKCResult_NodeInfoDecodeErrorZ*)arg)->result_ok;
3954 }
3955 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NodeInfoDecodeErrorZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
3956         LDKCResult_NodeInfoDecodeErrorZ *val = (LDKCResult_NodeInfoDecodeErrorZ*)arg;
3957         CHECK(val->result_ok);
3958         LDKNodeInfo res_var = (*val->contents.result);
3959         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3960         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3961         long res_ref = (long)res_var.inner & ~1;
3962         return res_ref;
3963 }
3964 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NodeInfoDecodeErrorZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
3965         LDKCResult_NodeInfoDecodeErrorZ *val = (LDKCResult_NodeInfoDecodeErrorZ*)arg;
3966         CHECK(!val->result_ok);
3967         LDKDecodeError err_var = (*val->contents.err);
3968         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3969         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3970         long err_ref = (long)err_var.inner & ~1;
3971         return err_ref;
3972 }
3973 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NetworkGraphDecodeErrorZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
3974         return ((LDKCResult_NetworkGraphDecodeErrorZ*)arg)->result_ok;
3975 }
3976 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NetworkGraphDecodeErrorZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
3977         LDKCResult_NetworkGraphDecodeErrorZ *val = (LDKCResult_NetworkGraphDecodeErrorZ*)arg;
3978         CHECK(val->result_ok);
3979         LDKNetworkGraph res_var = (*val->contents.result);
3980         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3981         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3982         long res_ref = (long)res_var.inner & ~1;
3983         return res_ref;
3984 }
3985 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NetworkGraphDecodeErrorZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
3986         LDKCResult_NetworkGraphDecodeErrorZ *val = (LDKCResult_NetworkGraphDecodeErrorZ*)arg;
3987         CHECK(!val->result_ok);
3988         LDKDecodeError err_var = (*val->contents.err);
3989         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3990         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3991         long err_ref = (long)err_var.inner & ~1;
3992         return err_ref;
3993 }
3994 typedef struct LDKMessageSendEventsProvider_JCalls {
3995         atomic_size_t refcnt;
3996         JavaVM *vm;
3997         jweak o;
3998         jmethodID get_and_clear_pending_msg_events_meth;
3999 } LDKMessageSendEventsProvider_JCalls;
4000 LDKCVec_MessageSendEventZ get_and_clear_pending_msg_events_jcall(const void* this_arg) {
4001         LDKMessageSendEventsProvider_JCalls *j_calls = (LDKMessageSendEventsProvider_JCalls*) this_arg;
4002         JNIEnv *_env;
4003         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
4004         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
4005         CHECK(obj != NULL);
4006         jlongArray arg = (*_env)->CallObjectMethod(_env, obj, j_calls->get_and_clear_pending_msg_events_meth);
4007         LDKCVec_MessageSendEventZ arg_constr;
4008         arg_constr.datalen = (*_env)->GetArrayLength (_env, arg);
4009         if (arg_constr.datalen > 0)
4010                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKMessageSendEvent), "LDKCVec_MessageSendEventZ Elements");
4011         else
4012                 arg_constr.data = NULL;
4013         long* arg_vals = (*_env)->GetLongArrayElements (_env, arg, NULL);
4014         for (size_t s = 0; s < arg_constr.datalen; s++) {
4015                 long arr_conv_18 = arg_vals[s];
4016                 LDKMessageSendEvent arr_conv_18_conv = *(LDKMessageSendEvent*)arr_conv_18;
4017                 FREE((void*)arr_conv_18);
4018                 arg_constr.data[s] = arr_conv_18_conv;
4019         }
4020         (*_env)->ReleaseLongArrayElements (_env, arg, arg_vals, 0);
4021         return arg_constr;
4022 }
4023 static void LDKMessageSendEventsProvider_JCalls_free(void* this_arg) {
4024         LDKMessageSendEventsProvider_JCalls *j_calls = (LDKMessageSendEventsProvider_JCalls*) this_arg;
4025         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
4026                 JNIEnv *env;
4027                 DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
4028                 (*env)->DeleteWeakGlobalRef(env, j_calls->o);
4029                 FREE(j_calls);
4030         }
4031 }
4032 static void* LDKMessageSendEventsProvider_JCalls_clone(const void* this_arg) {
4033         LDKMessageSendEventsProvider_JCalls *j_calls = (LDKMessageSendEventsProvider_JCalls*) this_arg;
4034         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
4035         return (void*) this_arg;
4036 }
4037 static inline LDKMessageSendEventsProvider LDKMessageSendEventsProvider_init (JNIEnv * env, jclass _a, jobject o) {
4038         jclass c = (*env)->GetObjectClass(env, o);
4039         CHECK(c != NULL);
4040         LDKMessageSendEventsProvider_JCalls *calls = MALLOC(sizeof(LDKMessageSendEventsProvider_JCalls), "LDKMessageSendEventsProvider_JCalls");
4041         atomic_init(&calls->refcnt, 1);
4042         DO_ASSERT((*env)->GetJavaVM(env, &calls->vm) == 0);
4043         calls->o = (*env)->NewWeakGlobalRef(env, o);
4044         calls->get_and_clear_pending_msg_events_meth = (*env)->GetMethodID(env, c, "get_and_clear_pending_msg_events", "()[J");
4045         CHECK(calls->get_and_clear_pending_msg_events_meth != NULL);
4046
4047         LDKMessageSendEventsProvider ret = {
4048                 .this_arg = (void*) calls,
4049                 .get_and_clear_pending_msg_events = get_and_clear_pending_msg_events_jcall,
4050                 .free = LDKMessageSendEventsProvider_JCalls_free,
4051         };
4052         return ret;
4053 }
4054 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_LDKMessageSendEventsProvider_1new (JNIEnv * env, jclass _a, jobject o) {
4055         LDKMessageSendEventsProvider *res_ptr = MALLOC(sizeof(LDKMessageSendEventsProvider), "LDKMessageSendEventsProvider");
4056         *res_ptr = LDKMessageSendEventsProvider_init(env, _a, o);
4057         return (long)res_ptr;
4058 }
4059 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKMessageSendEventsProvider_1get_1obj_1from_1jcalls (JNIEnv * env, jclass _a, jlong val) {
4060         jobject ret = (*env)->NewLocalRef(env, ((LDKMessageSendEventsProvider_JCalls*)val)->o);
4061         CHECK(ret != NULL);
4062         return ret;
4063 }
4064 JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_MessageSendEventsProvider_1get_1and_1clear_1pending_1msg_1events(JNIEnv * _env, jclass _b, jlong this_arg) {
4065         LDKMessageSendEventsProvider* this_arg_conv = (LDKMessageSendEventsProvider*)this_arg;
4066         LDKCVec_MessageSendEventZ ret_var = (this_arg_conv->get_and_clear_pending_msg_events)(this_arg_conv->this_arg);
4067         jlongArray ret_arr = (*_env)->NewLongArray(_env, ret_var.datalen);
4068         jlong *ret_arr_ptr = (*_env)->GetPrimitiveArrayCritical(_env, ret_arr, NULL);
4069         for (size_t s = 0; s < ret_var.datalen; s++) {
4070                 LDKMessageSendEvent *arr_conv_18_copy = MALLOC(sizeof(LDKMessageSendEvent), "LDKMessageSendEvent");
4071                 *arr_conv_18_copy = ret_var.data[s];
4072                 long arr_conv_18_ref = (long)arr_conv_18_copy;
4073                 ret_arr_ptr[s] = arr_conv_18_ref;
4074         }
4075         (*_env)->ReleasePrimitiveArrayCritical(_env, ret_arr, ret_arr_ptr, 0);
4076         FREE(ret_var.data);
4077         return ret_arr;
4078 }
4079
4080 typedef struct LDKEventsProvider_JCalls {
4081         atomic_size_t refcnt;
4082         JavaVM *vm;
4083         jweak o;
4084         jmethodID get_and_clear_pending_events_meth;
4085 } LDKEventsProvider_JCalls;
4086 LDKCVec_EventZ get_and_clear_pending_events_jcall(const void* this_arg) {
4087         LDKEventsProvider_JCalls *j_calls = (LDKEventsProvider_JCalls*) this_arg;
4088         JNIEnv *_env;
4089         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
4090         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
4091         CHECK(obj != NULL);
4092         jlongArray arg = (*_env)->CallObjectMethod(_env, obj, j_calls->get_and_clear_pending_events_meth);
4093         LDKCVec_EventZ arg_constr;
4094         arg_constr.datalen = (*_env)->GetArrayLength (_env, arg);
4095         if (arg_constr.datalen > 0)
4096                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKEvent), "LDKCVec_EventZ Elements");
4097         else
4098                 arg_constr.data = NULL;
4099         long* arg_vals = (*_env)->GetLongArrayElements (_env, arg, NULL);
4100         for (size_t h = 0; h < arg_constr.datalen; h++) {
4101                 long arr_conv_7 = arg_vals[h];
4102                 LDKEvent arr_conv_7_conv = *(LDKEvent*)arr_conv_7;
4103                 FREE((void*)arr_conv_7);
4104                 arg_constr.data[h] = arr_conv_7_conv;
4105         }
4106         (*_env)->ReleaseLongArrayElements (_env, arg, arg_vals, 0);
4107         return arg_constr;
4108 }
4109 static void LDKEventsProvider_JCalls_free(void* this_arg) {
4110         LDKEventsProvider_JCalls *j_calls = (LDKEventsProvider_JCalls*) this_arg;
4111         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
4112                 JNIEnv *env;
4113                 DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
4114                 (*env)->DeleteWeakGlobalRef(env, j_calls->o);
4115                 FREE(j_calls);
4116         }
4117 }
4118 static void* LDKEventsProvider_JCalls_clone(const void* this_arg) {
4119         LDKEventsProvider_JCalls *j_calls = (LDKEventsProvider_JCalls*) this_arg;
4120         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
4121         return (void*) this_arg;
4122 }
4123 static inline LDKEventsProvider LDKEventsProvider_init (JNIEnv * env, jclass _a, jobject o) {
4124         jclass c = (*env)->GetObjectClass(env, o);
4125         CHECK(c != NULL);
4126         LDKEventsProvider_JCalls *calls = MALLOC(sizeof(LDKEventsProvider_JCalls), "LDKEventsProvider_JCalls");
4127         atomic_init(&calls->refcnt, 1);
4128         DO_ASSERT((*env)->GetJavaVM(env, &calls->vm) == 0);
4129         calls->o = (*env)->NewWeakGlobalRef(env, o);
4130         calls->get_and_clear_pending_events_meth = (*env)->GetMethodID(env, c, "get_and_clear_pending_events", "()[J");
4131         CHECK(calls->get_and_clear_pending_events_meth != NULL);
4132
4133         LDKEventsProvider ret = {
4134                 .this_arg = (void*) calls,
4135                 .get_and_clear_pending_events = get_and_clear_pending_events_jcall,
4136                 .free = LDKEventsProvider_JCalls_free,
4137         };
4138         return ret;
4139 }
4140 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_LDKEventsProvider_1new (JNIEnv * env, jclass _a, jobject o) {
4141         LDKEventsProvider *res_ptr = MALLOC(sizeof(LDKEventsProvider), "LDKEventsProvider");
4142         *res_ptr = LDKEventsProvider_init(env, _a, o);
4143         return (long)res_ptr;
4144 }
4145 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKEventsProvider_1get_1obj_1from_1jcalls (JNIEnv * env, jclass _a, jlong val) {
4146         jobject ret = (*env)->NewLocalRef(env, ((LDKEventsProvider_JCalls*)val)->o);
4147         CHECK(ret != NULL);
4148         return ret;
4149 }
4150 JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_EventsProvider_1get_1and_1clear_1pending_1events(JNIEnv * _env, jclass _b, jlong this_arg) {
4151         LDKEventsProvider* this_arg_conv = (LDKEventsProvider*)this_arg;
4152         LDKCVec_EventZ ret_var = (this_arg_conv->get_and_clear_pending_events)(this_arg_conv->this_arg);
4153         jlongArray ret_arr = (*_env)->NewLongArray(_env, ret_var.datalen);
4154         jlong *ret_arr_ptr = (*_env)->GetPrimitiveArrayCritical(_env, ret_arr, NULL);
4155         for (size_t h = 0; h < ret_var.datalen; h++) {
4156                 LDKEvent *arr_conv_7_copy = MALLOC(sizeof(LDKEvent), "LDKEvent");
4157                 *arr_conv_7_copy = ret_var.data[h];
4158                 long arr_conv_7_ref = (long)arr_conv_7_copy;
4159                 ret_arr_ptr[h] = arr_conv_7_ref;
4160         }
4161         (*_env)->ReleasePrimitiveArrayCritical(_env, ret_arr, ret_arr_ptr, 0);
4162         FREE(ret_var.data);
4163         return ret_arr;
4164 }
4165
4166 typedef struct LDKAccess_JCalls {
4167         atomic_size_t refcnt;
4168         JavaVM *vm;
4169         jweak o;
4170         jmethodID get_utxo_meth;
4171 } LDKAccess_JCalls;
4172 LDKCResult_TxOutAccessErrorZ get_utxo_jcall(const void* this_arg, const uint8_t (*genesis_hash)[32], uint64_t short_channel_id) {
4173         LDKAccess_JCalls *j_calls = (LDKAccess_JCalls*) this_arg;
4174         JNIEnv *_env;
4175         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
4176         jbyteArray genesis_hash_arr = (*_env)->NewByteArray(_env, 32);
4177         (*_env)->SetByteArrayRegion(_env, genesis_hash_arr, 0, 32, *genesis_hash);
4178         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
4179         CHECK(obj != NULL);
4180         LDKCResult_TxOutAccessErrorZ* ret = (LDKCResult_TxOutAccessErrorZ*)(*_env)->CallLongMethod(_env, obj, j_calls->get_utxo_meth, genesis_hash_arr, short_channel_id);
4181         LDKCResult_TxOutAccessErrorZ ret_conv = *(LDKCResult_TxOutAccessErrorZ*)ret;
4182         FREE((void*)ret);
4183         return ret_conv;
4184 }
4185 static void LDKAccess_JCalls_free(void* this_arg) {
4186         LDKAccess_JCalls *j_calls = (LDKAccess_JCalls*) this_arg;
4187         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
4188                 JNIEnv *env;
4189                 DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
4190                 (*env)->DeleteWeakGlobalRef(env, j_calls->o);
4191                 FREE(j_calls);
4192         }
4193 }
4194 static void* LDKAccess_JCalls_clone(const void* this_arg) {
4195         LDKAccess_JCalls *j_calls = (LDKAccess_JCalls*) this_arg;
4196         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
4197         return (void*) this_arg;
4198 }
4199 static inline LDKAccess LDKAccess_init (JNIEnv * env, jclass _a, jobject o) {
4200         jclass c = (*env)->GetObjectClass(env, o);
4201         CHECK(c != NULL);
4202         LDKAccess_JCalls *calls = MALLOC(sizeof(LDKAccess_JCalls), "LDKAccess_JCalls");
4203         atomic_init(&calls->refcnt, 1);
4204         DO_ASSERT((*env)->GetJavaVM(env, &calls->vm) == 0);
4205         calls->o = (*env)->NewWeakGlobalRef(env, o);
4206         calls->get_utxo_meth = (*env)->GetMethodID(env, c, "get_utxo", "([BJ)J");
4207         CHECK(calls->get_utxo_meth != NULL);
4208
4209         LDKAccess ret = {
4210                 .this_arg = (void*) calls,
4211                 .get_utxo = get_utxo_jcall,
4212                 .free = LDKAccess_JCalls_free,
4213         };
4214         return ret;
4215 }
4216 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_LDKAccess_1new (JNIEnv * env, jclass _a, jobject o) {
4217         LDKAccess *res_ptr = MALLOC(sizeof(LDKAccess), "LDKAccess");
4218         *res_ptr = LDKAccess_init(env, _a, o);
4219         return (long)res_ptr;
4220 }
4221 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKAccess_1get_1obj_1from_1jcalls (JNIEnv * env, jclass _a, jlong val) {
4222         jobject ret = (*env)->NewLocalRef(env, ((LDKAccess_JCalls*)val)->o);
4223         CHECK(ret != NULL);
4224         return ret;
4225 }
4226 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_Access_1get_1utxo(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray genesis_hash, jlong short_channel_id) {
4227         LDKAccess* this_arg_conv = (LDKAccess*)this_arg;
4228         unsigned char genesis_hash_arr[32];
4229         CHECK((*_env)->GetArrayLength (_env, genesis_hash) == 32);
4230         (*_env)->GetByteArrayRegion (_env, genesis_hash, 0, 32, genesis_hash_arr);
4231         unsigned char (*genesis_hash_ref)[32] = &genesis_hash_arr;
4232         LDKCResult_TxOutAccessErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_TxOutAccessErrorZ), "LDKCResult_TxOutAccessErrorZ");
4233         *ret_conv = (this_arg_conv->get_utxo)(this_arg_conv->this_arg, genesis_hash_ref, short_channel_id);
4234         return (long)ret_conv;
4235 }
4236
4237 typedef struct LDKFilter_JCalls {
4238         atomic_size_t refcnt;
4239         JavaVM *vm;
4240         jweak o;
4241         jmethodID register_tx_meth;
4242         jmethodID register_output_meth;
4243 } LDKFilter_JCalls;
4244 void register_tx_jcall(const void* this_arg, const uint8_t (*txid)[32], struct LDKu8slice script_pubkey) {
4245         LDKFilter_JCalls *j_calls = (LDKFilter_JCalls*) this_arg;
4246         JNIEnv *_env;
4247         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
4248         jbyteArray txid_arr = (*_env)->NewByteArray(_env, 32);
4249         (*_env)->SetByteArrayRegion(_env, txid_arr, 0, 32, *txid);
4250         LDKu8slice script_pubkey_var = script_pubkey;
4251         jbyteArray script_pubkey_arr = (*_env)->NewByteArray(_env, script_pubkey_var.datalen);
4252         (*_env)->SetByteArrayRegion(_env, script_pubkey_arr, 0, script_pubkey_var.datalen, script_pubkey_var.data);
4253         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
4254         CHECK(obj != NULL);
4255         return (*_env)->CallVoidMethod(_env, obj, j_calls->register_tx_meth, txid_arr, script_pubkey_arr);
4256 }
4257 void register_output_jcall(const void* this_arg, const struct LDKOutPoint *NONNULL_PTR outpoint, struct LDKu8slice script_pubkey) {
4258         LDKFilter_JCalls *j_calls = (LDKFilter_JCalls*) this_arg;
4259         JNIEnv *_env;
4260         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
4261         LDKOutPoint outpoint_var = *outpoint;
4262         if (outpoint->inner != NULL)
4263                 outpoint_var = OutPoint_clone(outpoint);
4264         CHECK((((long)outpoint_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4265         CHECK((((long)&outpoint_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4266         long outpoint_ref = (long)outpoint_var.inner;
4267         if (outpoint_var.is_owned) {
4268                 outpoint_ref |= 1;
4269         }
4270         LDKu8slice script_pubkey_var = script_pubkey;
4271         jbyteArray script_pubkey_arr = (*_env)->NewByteArray(_env, script_pubkey_var.datalen);
4272         (*_env)->SetByteArrayRegion(_env, script_pubkey_arr, 0, script_pubkey_var.datalen, script_pubkey_var.data);
4273         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
4274         CHECK(obj != NULL);
4275         return (*_env)->CallVoidMethod(_env, obj, j_calls->register_output_meth, outpoint_ref, script_pubkey_arr);
4276 }
4277 static void LDKFilter_JCalls_free(void* this_arg) {
4278         LDKFilter_JCalls *j_calls = (LDKFilter_JCalls*) this_arg;
4279         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
4280                 JNIEnv *env;
4281                 DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
4282                 (*env)->DeleteWeakGlobalRef(env, j_calls->o);
4283                 FREE(j_calls);
4284         }
4285 }
4286 static void* LDKFilter_JCalls_clone(const void* this_arg) {
4287         LDKFilter_JCalls *j_calls = (LDKFilter_JCalls*) this_arg;
4288         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
4289         return (void*) this_arg;
4290 }
4291 static inline LDKFilter LDKFilter_init (JNIEnv * env, jclass _a, jobject o) {
4292         jclass c = (*env)->GetObjectClass(env, o);
4293         CHECK(c != NULL);
4294         LDKFilter_JCalls *calls = MALLOC(sizeof(LDKFilter_JCalls), "LDKFilter_JCalls");
4295         atomic_init(&calls->refcnt, 1);
4296         DO_ASSERT((*env)->GetJavaVM(env, &calls->vm) == 0);
4297         calls->o = (*env)->NewWeakGlobalRef(env, o);
4298         calls->register_tx_meth = (*env)->GetMethodID(env, c, "register_tx", "([B[B)V");
4299         CHECK(calls->register_tx_meth != NULL);
4300         calls->register_output_meth = (*env)->GetMethodID(env, c, "register_output", "(J[B)V");
4301         CHECK(calls->register_output_meth != NULL);
4302
4303         LDKFilter ret = {
4304                 .this_arg = (void*) calls,
4305                 .register_tx = register_tx_jcall,
4306                 .register_output = register_output_jcall,
4307                 .free = LDKFilter_JCalls_free,
4308         };
4309         return ret;
4310 }
4311 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_LDKFilter_1new (JNIEnv * env, jclass _a, jobject o) {
4312         LDKFilter *res_ptr = MALLOC(sizeof(LDKFilter), "LDKFilter");
4313         *res_ptr = LDKFilter_init(env, _a, o);
4314         return (long)res_ptr;
4315 }
4316 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKFilter_1get_1obj_1from_1jcalls (JNIEnv * env, jclass _a, jlong val) {
4317         jobject ret = (*env)->NewLocalRef(env, ((LDKFilter_JCalls*)val)->o);
4318         CHECK(ret != NULL);
4319         return ret;
4320 }
4321 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Filter_1register_1tx(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray txid, jbyteArray script_pubkey) {
4322         LDKFilter* this_arg_conv = (LDKFilter*)this_arg;
4323         unsigned char txid_arr[32];
4324         CHECK((*_env)->GetArrayLength (_env, txid) == 32);
4325         (*_env)->GetByteArrayRegion (_env, txid, 0, 32, txid_arr);
4326         unsigned char (*txid_ref)[32] = &txid_arr;
4327         LDKu8slice script_pubkey_ref;
4328         script_pubkey_ref.datalen = (*_env)->GetArrayLength (_env, script_pubkey);
4329         script_pubkey_ref.data = (*_env)->GetByteArrayElements (_env, script_pubkey, NULL);
4330         (this_arg_conv->register_tx)(this_arg_conv->this_arg, txid_ref, script_pubkey_ref);
4331         (*_env)->ReleaseByteArrayElements(_env, script_pubkey, (int8_t*)script_pubkey_ref.data, 0);
4332 }
4333
4334 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Filter_1register_1output(JNIEnv * _env, jclass _b, jlong this_arg, jlong outpoint, jbyteArray script_pubkey) {
4335         LDKFilter* this_arg_conv = (LDKFilter*)this_arg;
4336         LDKOutPoint outpoint_conv;
4337         outpoint_conv.inner = (void*)(outpoint & (~1));
4338         outpoint_conv.is_owned = false;
4339         LDKu8slice script_pubkey_ref;
4340         script_pubkey_ref.datalen = (*_env)->GetArrayLength (_env, script_pubkey);
4341         script_pubkey_ref.data = (*_env)->GetByteArrayElements (_env, script_pubkey, NULL);
4342         (this_arg_conv->register_output)(this_arg_conv->this_arg, &outpoint_conv, script_pubkey_ref);
4343         (*_env)->ReleaseByteArrayElements(_env, script_pubkey, (int8_t*)script_pubkey_ref.data, 0);
4344 }
4345
4346 typedef struct LDKPersist_JCalls {
4347         atomic_size_t refcnt;
4348         JavaVM *vm;
4349         jweak o;
4350         jmethodID persist_new_channel_meth;
4351         jmethodID update_persisted_channel_meth;
4352 } LDKPersist_JCalls;
4353 LDKCResult_NoneChannelMonitorUpdateErrZ persist_new_channel_jcall(const void* this_arg, struct LDKOutPoint id, const struct LDKChannelMonitor *NONNULL_PTR data) {
4354         LDKPersist_JCalls *j_calls = (LDKPersist_JCalls*) this_arg;
4355         JNIEnv *_env;
4356         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
4357         LDKOutPoint id_var = id;
4358         CHECK((((long)id_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4359         CHECK((((long)&id_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4360         long id_ref = (long)id_var.inner;
4361         if (id_var.is_owned) {
4362                 id_ref |= 1;
4363         }
4364         LDKChannelMonitor data_var = *data;
4365         // Warning: we may need a move here but can't clone!
4366         CHECK((((long)data_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4367         CHECK((((long)&data_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4368         long data_ref = (long)data_var.inner;
4369         if (data_var.is_owned) {
4370                 data_ref |= 1;
4371         }
4372         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
4373         CHECK(obj != NULL);
4374         LDKCResult_NoneChannelMonitorUpdateErrZ* ret = (LDKCResult_NoneChannelMonitorUpdateErrZ*)(*_env)->CallLongMethod(_env, obj, j_calls->persist_new_channel_meth, id_ref, data_ref);
4375         LDKCResult_NoneChannelMonitorUpdateErrZ ret_conv = *(LDKCResult_NoneChannelMonitorUpdateErrZ*)ret;
4376         FREE((void*)ret);
4377         return ret_conv;
4378 }
4379 LDKCResult_NoneChannelMonitorUpdateErrZ update_persisted_channel_jcall(const void* this_arg, struct LDKOutPoint id, const struct LDKChannelMonitorUpdate *NONNULL_PTR update, const struct LDKChannelMonitor *NONNULL_PTR data) {
4380         LDKPersist_JCalls *j_calls = (LDKPersist_JCalls*) this_arg;
4381         JNIEnv *_env;
4382         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
4383         LDKOutPoint id_var = id;
4384         CHECK((((long)id_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4385         CHECK((((long)&id_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4386         long id_ref = (long)id_var.inner;
4387         if (id_var.is_owned) {
4388                 id_ref |= 1;
4389         }
4390         LDKChannelMonitorUpdate update_var = *update;
4391         if (update->inner != NULL)
4392                 update_var = ChannelMonitorUpdate_clone(update);
4393         CHECK((((long)update_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4394         CHECK((((long)&update_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4395         long update_ref = (long)update_var.inner;
4396         if (update_var.is_owned) {
4397                 update_ref |= 1;
4398         }
4399         LDKChannelMonitor data_var = *data;
4400         // Warning: we may need a move here but can't clone!
4401         CHECK((((long)data_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4402         CHECK((((long)&data_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4403         long data_ref = (long)data_var.inner;
4404         if (data_var.is_owned) {
4405                 data_ref |= 1;
4406         }
4407         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
4408         CHECK(obj != NULL);
4409         LDKCResult_NoneChannelMonitorUpdateErrZ* ret = (LDKCResult_NoneChannelMonitorUpdateErrZ*)(*_env)->CallLongMethod(_env, obj, j_calls->update_persisted_channel_meth, id_ref, update_ref, data_ref);
4410         LDKCResult_NoneChannelMonitorUpdateErrZ ret_conv = *(LDKCResult_NoneChannelMonitorUpdateErrZ*)ret;
4411         FREE((void*)ret);
4412         return ret_conv;
4413 }
4414 static void LDKPersist_JCalls_free(void* this_arg) {
4415         LDKPersist_JCalls *j_calls = (LDKPersist_JCalls*) this_arg;
4416         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
4417                 JNIEnv *env;
4418                 DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
4419                 (*env)->DeleteWeakGlobalRef(env, j_calls->o);
4420                 FREE(j_calls);
4421         }
4422 }
4423 static void* LDKPersist_JCalls_clone(const void* this_arg) {
4424         LDKPersist_JCalls *j_calls = (LDKPersist_JCalls*) this_arg;
4425         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
4426         return (void*) this_arg;
4427 }
4428 static inline LDKPersist LDKPersist_init (JNIEnv * env, jclass _a, jobject o) {
4429         jclass c = (*env)->GetObjectClass(env, o);
4430         CHECK(c != NULL);
4431         LDKPersist_JCalls *calls = MALLOC(sizeof(LDKPersist_JCalls), "LDKPersist_JCalls");
4432         atomic_init(&calls->refcnt, 1);
4433         DO_ASSERT((*env)->GetJavaVM(env, &calls->vm) == 0);
4434         calls->o = (*env)->NewWeakGlobalRef(env, o);
4435         calls->persist_new_channel_meth = (*env)->GetMethodID(env, c, "persist_new_channel", "(JJ)J");
4436         CHECK(calls->persist_new_channel_meth != NULL);
4437         calls->update_persisted_channel_meth = (*env)->GetMethodID(env, c, "update_persisted_channel", "(JJJ)J");
4438         CHECK(calls->update_persisted_channel_meth != NULL);
4439
4440         LDKPersist ret = {
4441                 .this_arg = (void*) calls,
4442                 .persist_new_channel = persist_new_channel_jcall,
4443                 .update_persisted_channel = update_persisted_channel_jcall,
4444                 .free = LDKPersist_JCalls_free,
4445         };
4446         return ret;
4447 }
4448 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_LDKPersist_1new (JNIEnv * env, jclass _a, jobject o) {
4449         LDKPersist *res_ptr = MALLOC(sizeof(LDKPersist), "LDKPersist");
4450         *res_ptr = LDKPersist_init(env, _a, o);
4451         return (long)res_ptr;
4452 }
4453 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKPersist_1get_1obj_1from_1jcalls (JNIEnv * env, jclass _a, jlong val) {
4454         jobject ret = (*env)->NewLocalRef(env, ((LDKPersist_JCalls*)val)->o);
4455         CHECK(ret != NULL);
4456         return ret;
4457 }
4458 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_Persist_1persist_1new_1channel(JNIEnv * _env, jclass _b, jlong this_arg, jlong id, jlong data) {
4459         LDKPersist* this_arg_conv = (LDKPersist*)this_arg;
4460         LDKOutPoint id_conv;
4461         id_conv.inner = (void*)(id & (~1));
4462         id_conv.is_owned = (id & 1) || (id == 0);
4463         if (id_conv.inner != NULL)
4464                 id_conv = OutPoint_clone(&id_conv);
4465         LDKChannelMonitor data_conv;
4466         data_conv.inner = (void*)(data & (~1));
4467         data_conv.is_owned = false;
4468         LDKCResult_NoneChannelMonitorUpdateErrZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneChannelMonitorUpdateErrZ), "LDKCResult_NoneChannelMonitorUpdateErrZ");
4469         *ret_conv = (this_arg_conv->persist_new_channel)(this_arg_conv->this_arg, id_conv, &data_conv);
4470         return (long)ret_conv;
4471 }
4472
4473 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_Persist_1update_1persisted_1channel(JNIEnv * _env, jclass _b, jlong this_arg, jlong id, jlong update, jlong data) {
4474         LDKPersist* this_arg_conv = (LDKPersist*)this_arg;
4475         LDKOutPoint id_conv;
4476         id_conv.inner = (void*)(id & (~1));
4477         id_conv.is_owned = (id & 1) || (id == 0);
4478         if (id_conv.inner != NULL)
4479                 id_conv = OutPoint_clone(&id_conv);
4480         LDKChannelMonitorUpdate update_conv;
4481         update_conv.inner = (void*)(update & (~1));
4482         update_conv.is_owned = false;
4483         LDKChannelMonitor data_conv;
4484         data_conv.inner = (void*)(data & (~1));
4485         data_conv.is_owned = false;
4486         LDKCResult_NoneChannelMonitorUpdateErrZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneChannelMonitorUpdateErrZ), "LDKCResult_NoneChannelMonitorUpdateErrZ");
4487         *ret_conv = (this_arg_conv->update_persisted_channel)(this_arg_conv->this_arg, id_conv, &update_conv, &data_conv);
4488         return (long)ret_conv;
4489 }
4490
4491 typedef struct LDKChannelMessageHandler_JCalls {
4492         atomic_size_t refcnt;
4493         JavaVM *vm;
4494         jweak o;
4495         LDKMessageSendEventsProvider_JCalls* MessageSendEventsProvider;
4496         jmethodID handle_open_channel_meth;
4497         jmethodID handle_accept_channel_meth;
4498         jmethodID handle_funding_created_meth;
4499         jmethodID handle_funding_signed_meth;
4500         jmethodID handle_funding_locked_meth;
4501         jmethodID handle_shutdown_meth;
4502         jmethodID handle_closing_signed_meth;
4503         jmethodID handle_update_add_htlc_meth;
4504         jmethodID handle_update_fulfill_htlc_meth;
4505         jmethodID handle_update_fail_htlc_meth;
4506         jmethodID handle_update_fail_malformed_htlc_meth;
4507         jmethodID handle_commitment_signed_meth;
4508         jmethodID handle_revoke_and_ack_meth;
4509         jmethodID handle_update_fee_meth;
4510         jmethodID handle_announcement_signatures_meth;
4511         jmethodID peer_disconnected_meth;
4512         jmethodID peer_connected_meth;
4513         jmethodID handle_channel_reestablish_meth;
4514         jmethodID handle_error_meth;
4515 } LDKChannelMessageHandler_JCalls;
4516 void handle_open_channel_jcall(const void* this_arg, struct LDKPublicKey their_node_id, struct LDKInitFeatures their_features, const struct LDKOpenChannel *NONNULL_PTR msg) {
4517         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
4518         JNIEnv *_env;
4519         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
4520         jbyteArray their_node_id_arr = (*_env)->NewByteArray(_env, 33);
4521         (*_env)->SetByteArrayRegion(_env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
4522         LDKInitFeatures their_features_var = their_features;
4523         CHECK((((long)their_features_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4524         CHECK((((long)&their_features_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4525         long their_features_ref = (long)their_features_var.inner;
4526         if (their_features_var.is_owned) {
4527                 their_features_ref |= 1;
4528         }
4529         LDKOpenChannel msg_var = *msg;
4530         if (msg->inner != NULL)
4531                 msg_var = OpenChannel_clone(msg);
4532         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4533         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4534         long msg_ref = (long)msg_var.inner;
4535         if (msg_var.is_owned) {
4536                 msg_ref |= 1;
4537         }
4538         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
4539         CHECK(obj != NULL);
4540         return (*_env)->CallVoidMethod(_env, obj, j_calls->handle_open_channel_meth, their_node_id_arr, their_features_ref, msg_ref);
4541 }
4542 void handle_accept_channel_jcall(const void* this_arg, struct LDKPublicKey their_node_id, struct LDKInitFeatures their_features, const struct LDKAcceptChannel *NONNULL_PTR msg) {
4543         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
4544         JNIEnv *_env;
4545         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
4546         jbyteArray their_node_id_arr = (*_env)->NewByteArray(_env, 33);
4547         (*_env)->SetByteArrayRegion(_env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
4548         LDKInitFeatures their_features_var = their_features;
4549         CHECK((((long)their_features_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4550         CHECK((((long)&their_features_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4551         long their_features_ref = (long)their_features_var.inner;
4552         if (their_features_var.is_owned) {
4553                 their_features_ref |= 1;
4554         }
4555         LDKAcceptChannel msg_var = *msg;
4556         if (msg->inner != NULL)
4557                 msg_var = AcceptChannel_clone(msg);
4558         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4559         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4560         long msg_ref = (long)msg_var.inner;
4561         if (msg_var.is_owned) {
4562                 msg_ref |= 1;
4563         }
4564         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
4565         CHECK(obj != NULL);
4566         return (*_env)->CallVoidMethod(_env, obj, j_calls->handle_accept_channel_meth, their_node_id_arr, their_features_ref, msg_ref);
4567 }
4568 void handle_funding_created_jcall(const void* this_arg, struct LDKPublicKey their_node_id, const struct LDKFundingCreated *NONNULL_PTR msg) {
4569         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
4570         JNIEnv *_env;
4571         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
4572         jbyteArray their_node_id_arr = (*_env)->NewByteArray(_env, 33);
4573         (*_env)->SetByteArrayRegion(_env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
4574         LDKFundingCreated msg_var = *msg;
4575         if (msg->inner != NULL)
4576                 msg_var = FundingCreated_clone(msg);
4577         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4578         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4579         long msg_ref = (long)msg_var.inner;
4580         if (msg_var.is_owned) {
4581                 msg_ref |= 1;
4582         }
4583         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
4584         CHECK(obj != NULL);
4585         return (*_env)->CallVoidMethod(_env, obj, j_calls->handle_funding_created_meth, their_node_id_arr, msg_ref);
4586 }
4587 void handle_funding_signed_jcall(const void* this_arg, struct LDKPublicKey their_node_id, const struct LDKFundingSigned *NONNULL_PTR msg) {
4588         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
4589         JNIEnv *_env;
4590         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
4591         jbyteArray their_node_id_arr = (*_env)->NewByteArray(_env, 33);
4592         (*_env)->SetByteArrayRegion(_env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
4593         LDKFundingSigned msg_var = *msg;
4594         if (msg->inner != NULL)
4595                 msg_var = FundingSigned_clone(msg);
4596         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4597         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4598         long msg_ref = (long)msg_var.inner;
4599         if (msg_var.is_owned) {
4600                 msg_ref |= 1;
4601         }
4602         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
4603         CHECK(obj != NULL);
4604         return (*_env)->CallVoidMethod(_env, obj, j_calls->handle_funding_signed_meth, their_node_id_arr, msg_ref);
4605 }
4606 void handle_funding_locked_jcall(const void* this_arg, struct LDKPublicKey their_node_id, const struct LDKFundingLocked *NONNULL_PTR msg) {
4607         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
4608         JNIEnv *_env;
4609         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
4610         jbyteArray their_node_id_arr = (*_env)->NewByteArray(_env, 33);
4611         (*_env)->SetByteArrayRegion(_env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
4612         LDKFundingLocked msg_var = *msg;
4613         if (msg->inner != NULL)
4614                 msg_var = FundingLocked_clone(msg);
4615         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4616         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4617         long msg_ref = (long)msg_var.inner;
4618         if (msg_var.is_owned) {
4619                 msg_ref |= 1;
4620         }
4621         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
4622         CHECK(obj != NULL);
4623         return (*_env)->CallVoidMethod(_env, obj, j_calls->handle_funding_locked_meth, their_node_id_arr, msg_ref);
4624 }
4625 void handle_shutdown_jcall(const void* this_arg, struct LDKPublicKey their_node_id, const struct LDKShutdown *NONNULL_PTR msg) {
4626         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
4627         JNIEnv *_env;
4628         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
4629         jbyteArray their_node_id_arr = (*_env)->NewByteArray(_env, 33);
4630         (*_env)->SetByteArrayRegion(_env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
4631         LDKShutdown msg_var = *msg;
4632         if (msg->inner != NULL)
4633                 msg_var = Shutdown_clone(msg);
4634         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4635         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4636         long msg_ref = (long)msg_var.inner;
4637         if (msg_var.is_owned) {
4638                 msg_ref |= 1;
4639         }
4640         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
4641         CHECK(obj != NULL);
4642         return (*_env)->CallVoidMethod(_env, obj, j_calls->handle_shutdown_meth, their_node_id_arr, msg_ref);
4643 }
4644 void handle_closing_signed_jcall(const void* this_arg, struct LDKPublicKey their_node_id, const struct LDKClosingSigned *NONNULL_PTR msg) {
4645         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
4646         JNIEnv *_env;
4647         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
4648         jbyteArray their_node_id_arr = (*_env)->NewByteArray(_env, 33);
4649         (*_env)->SetByteArrayRegion(_env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
4650         LDKClosingSigned msg_var = *msg;
4651         if (msg->inner != NULL)
4652                 msg_var = ClosingSigned_clone(msg);
4653         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4654         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4655         long msg_ref = (long)msg_var.inner;
4656         if (msg_var.is_owned) {
4657                 msg_ref |= 1;
4658         }
4659         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
4660         CHECK(obj != NULL);
4661         return (*_env)->CallVoidMethod(_env, obj, j_calls->handle_closing_signed_meth, their_node_id_arr, msg_ref);
4662 }
4663 void handle_update_add_htlc_jcall(const void* this_arg, struct LDKPublicKey their_node_id, const struct LDKUpdateAddHTLC *NONNULL_PTR msg) {
4664         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
4665         JNIEnv *_env;
4666         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
4667         jbyteArray their_node_id_arr = (*_env)->NewByteArray(_env, 33);
4668         (*_env)->SetByteArrayRegion(_env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
4669         LDKUpdateAddHTLC msg_var = *msg;
4670         if (msg->inner != NULL)
4671                 msg_var = UpdateAddHTLC_clone(msg);
4672         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4673         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4674         long msg_ref = (long)msg_var.inner;
4675         if (msg_var.is_owned) {
4676                 msg_ref |= 1;
4677         }
4678         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
4679         CHECK(obj != NULL);
4680         return (*_env)->CallVoidMethod(_env, obj, j_calls->handle_update_add_htlc_meth, their_node_id_arr, msg_ref);
4681 }
4682 void handle_update_fulfill_htlc_jcall(const void* this_arg, struct LDKPublicKey their_node_id, const struct LDKUpdateFulfillHTLC *NONNULL_PTR msg) {
4683         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
4684         JNIEnv *_env;
4685         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
4686         jbyteArray their_node_id_arr = (*_env)->NewByteArray(_env, 33);
4687         (*_env)->SetByteArrayRegion(_env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
4688         LDKUpdateFulfillHTLC msg_var = *msg;
4689         if (msg->inner != NULL)
4690                 msg_var = UpdateFulfillHTLC_clone(msg);
4691         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4692         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4693         long msg_ref = (long)msg_var.inner;
4694         if (msg_var.is_owned) {
4695                 msg_ref |= 1;
4696         }
4697         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
4698         CHECK(obj != NULL);
4699         return (*_env)->CallVoidMethod(_env, obj, j_calls->handle_update_fulfill_htlc_meth, their_node_id_arr, msg_ref);
4700 }
4701 void handle_update_fail_htlc_jcall(const void* this_arg, struct LDKPublicKey their_node_id, const struct LDKUpdateFailHTLC *NONNULL_PTR msg) {
4702         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
4703         JNIEnv *_env;
4704         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
4705         jbyteArray their_node_id_arr = (*_env)->NewByteArray(_env, 33);
4706         (*_env)->SetByteArrayRegion(_env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
4707         LDKUpdateFailHTLC msg_var = *msg;
4708         if (msg->inner != NULL)
4709                 msg_var = UpdateFailHTLC_clone(msg);
4710         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4711         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4712         long msg_ref = (long)msg_var.inner;
4713         if (msg_var.is_owned) {
4714                 msg_ref |= 1;
4715         }
4716         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
4717         CHECK(obj != NULL);
4718         return (*_env)->CallVoidMethod(_env, obj, j_calls->handle_update_fail_htlc_meth, their_node_id_arr, msg_ref);
4719 }
4720 void handle_update_fail_malformed_htlc_jcall(const void* this_arg, struct LDKPublicKey their_node_id, const struct LDKUpdateFailMalformedHTLC *NONNULL_PTR msg) {
4721         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
4722         JNIEnv *_env;
4723         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
4724         jbyteArray their_node_id_arr = (*_env)->NewByteArray(_env, 33);
4725         (*_env)->SetByteArrayRegion(_env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
4726         LDKUpdateFailMalformedHTLC msg_var = *msg;
4727         if (msg->inner != NULL)
4728                 msg_var = UpdateFailMalformedHTLC_clone(msg);
4729         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4730         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4731         long msg_ref = (long)msg_var.inner;
4732         if (msg_var.is_owned) {
4733                 msg_ref |= 1;
4734         }
4735         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
4736         CHECK(obj != NULL);
4737         return (*_env)->CallVoidMethod(_env, obj, j_calls->handle_update_fail_malformed_htlc_meth, their_node_id_arr, msg_ref);
4738 }
4739 void handle_commitment_signed_jcall(const void* this_arg, struct LDKPublicKey their_node_id, const struct LDKCommitmentSigned *NONNULL_PTR msg) {
4740         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
4741         JNIEnv *_env;
4742         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
4743         jbyteArray their_node_id_arr = (*_env)->NewByteArray(_env, 33);
4744         (*_env)->SetByteArrayRegion(_env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
4745         LDKCommitmentSigned msg_var = *msg;
4746         if (msg->inner != NULL)
4747                 msg_var = CommitmentSigned_clone(msg);
4748         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4749         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4750         long msg_ref = (long)msg_var.inner;
4751         if (msg_var.is_owned) {
4752                 msg_ref |= 1;
4753         }
4754         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
4755         CHECK(obj != NULL);
4756         return (*_env)->CallVoidMethod(_env, obj, j_calls->handle_commitment_signed_meth, their_node_id_arr, msg_ref);
4757 }
4758 void handle_revoke_and_ack_jcall(const void* this_arg, struct LDKPublicKey their_node_id, const struct LDKRevokeAndACK *NONNULL_PTR msg) {
4759         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
4760         JNIEnv *_env;
4761         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
4762         jbyteArray their_node_id_arr = (*_env)->NewByteArray(_env, 33);
4763         (*_env)->SetByteArrayRegion(_env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
4764         LDKRevokeAndACK msg_var = *msg;
4765         if (msg->inner != NULL)
4766                 msg_var = RevokeAndACK_clone(msg);
4767         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4768         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4769         long msg_ref = (long)msg_var.inner;
4770         if (msg_var.is_owned) {
4771                 msg_ref |= 1;
4772         }
4773         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
4774         CHECK(obj != NULL);
4775         return (*_env)->CallVoidMethod(_env, obj, j_calls->handle_revoke_and_ack_meth, their_node_id_arr, msg_ref);
4776 }
4777 void handle_update_fee_jcall(const void* this_arg, struct LDKPublicKey their_node_id, const struct LDKUpdateFee *NONNULL_PTR msg) {
4778         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
4779         JNIEnv *_env;
4780         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
4781         jbyteArray their_node_id_arr = (*_env)->NewByteArray(_env, 33);
4782         (*_env)->SetByteArrayRegion(_env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
4783         LDKUpdateFee msg_var = *msg;
4784         if (msg->inner != NULL)
4785                 msg_var = UpdateFee_clone(msg);
4786         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4787         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4788         long msg_ref = (long)msg_var.inner;
4789         if (msg_var.is_owned) {
4790                 msg_ref |= 1;
4791         }
4792         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
4793         CHECK(obj != NULL);
4794         return (*_env)->CallVoidMethod(_env, obj, j_calls->handle_update_fee_meth, their_node_id_arr, msg_ref);
4795 }
4796 void handle_announcement_signatures_jcall(const void* this_arg, struct LDKPublicKey their_node_id, const struct LDKAnnouncementSignatures *NONNULL_PTR msg) {
4797         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
4798         JNIEnv *_env;
4799         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
4800         jbyteArray their_node_id_arr = (*_env)->NewByteArray(_env, 33);
4801         (*_env)->SetByteArrayRegion(_env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
4802         LDKAnnouncementSignatures msg_var = *msg;
4803         if (msg->inner != NULL)
4804                 msg_var = AnnouncementSignatures_clone(msg);
4805         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4806         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4807         long msg_ref = (long)msg_var.inner;
4808         if (msg_var.is_owned) {
4809                 msg_ref |= 1;
4810         }
4811         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
4812         CHECK(obj != NULL);
4813         return (*_env)->CallVoidMethod(_env, obj, j_calls->handle_announcement_signatures_meth, their_node_id_arr, msg_ref);
4814 }
4815 void peer_disconnected_jcall(const void* this_arg, struct LDKPublicKey their_node_id, bool no_connection_possible) {
4816         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
4817         JNIEnv *_env;
4818         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
4819         jbyteArray their_node_id_arr = (*_env)->NewByteArray(_env, 33);
4820         (*_env)->SetByteArrayRegion(_env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
4821         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
4822         CHECK(obj != NULL);
4823         return (*_env)->CallVoidMethod(_env, obj, j_calls->peer_disconnected_meth, their_node_id_arr, no_connection_possible);
4824 }
4825 void peer_connected_jcall(const void* this_arg, struct LDKPublicKey their_node_id, const struct LDKInit *NONNULL_PTR msg) {
4826         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
4827         JNIEnv *_env;
4828         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
4829         jbyteArray their_node_id_arr = (*_env)->NewByteArray(_env, 33);
4830         (*_env)->SetByteArrayRegion(_env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
4831         LDKInit msg_var = *msg;
4832         if (msg->inner != NULL)
4833                 msg_var = Init_clone(msg);
4834         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4835         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4836         long msg_ref = (long)msg_var.inner;
4837         if (msg_var.is_owned) {
4838                 msg_ref |= 1;
4839         }
4840         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
4841         CHECK(obj != NULL);
4842         return (*_env)->CallVoidMethod(_env, obj, j_calls->peer_connected_meth, their_node_id_arr, msg_ref);
4843 }
4844 void handle_channel_reestablish_jcall(const void* this_arg, struct LDKPublicKey their_node_id, const struct LDKChannelReestablish *NONNULL_PTR msg) {
4845         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
4846         JNIEnv *_env;
4847         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
4848         jbyteArray their_node_id_arr = (*_env)->NewByteArray(_env, 33);
4849         (*_env)->SetByteArrayRegion(_env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
4850         LDKChannelReestablish msg_var = *msg;
4851         if (msg->inner != NULL)
4852                 msg_var = ChannelReestablish_clone(msg);
4853         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4854         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4855         long msg_ref = (long)msg_var.inner;
4856         if (msg_var.is_owned) {
4857                 msg_ref |= 1;
4858         }
4859         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
4860         CHECK(obj != NULL);
4861         return (*_env)->CallVoidMethod(_env, obj, j_calls->handle_channel_reestablish_meth, their_node_id_arr, msg_ref);
4862 }
4863 void handle_error_jcall(const void* this_arg, struct LDKPublicKey their_node_id, const struct LDKErrorMessage *NONNULL_PTR msg) {
4864         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
4865         JNIEnv *_env;
4866         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
4867         jbyteArray their_node_id_arr = (*_env)->NewByteArray(_env, 33);
4868         (*_env)->SetByteArrayRegion(_env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
4869         LDKErrorMessage msg_var = *msg;
4870         if (msg->inner != NULL)
4871                 msg_var = ErrorMessage_clone(msg);
4872         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4873         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4874         long msg_ref = (long)msg_var.inner;
4875         if (msg_var.is_owned) {
4876                 msg_ref |= 1;
4877         }
4878         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
4879         CHECK(obj != NULL);
4880         return (*_env)->CallVoidMethod(_env, obj, j_calls->handle_error_meth, their_node_id_arr, msg_ref);
4881 }
4882 static void LDKChannelMessageHandler_JCalls_free(void* this_arg) {
4883         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
4884         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
4885                 JNIEnv *env;
4886                 DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
4887                 (*env)->DeleteWeakGlobalRef(env, j_calls->o);
4888                 FREE(j_calls);
4889         }
4890 }
4891 static void* LDKChannelMessageHandler_JCalls_clone(const void* this_arg) {
4892         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
4893         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
4894         atomic_fetch_add_explicit(&j_calls->MessageSendEventsProvider->refcnt, 1, memory_order_release);
4895         return (void*) this_arg;
4896 }
4897 static inline LDKChannelMessageHandler LDKChannelMessageHandler_init (JNIEnv * env, jclass _a, jobject o, jobject MessageSendEventsProvider) {
4898         jclass c = (*env)->GetObjectClass(env, o);
4899         CHECK(c != NULL);
4900         LDKChannelMessageHandler_JCalls *calls = MALLOC(sizeof(LDKChannelMessageHandler_JCalls), "LDKChannelMessageHandler_JCalls");
4901         atomic_init(&calls->refcnt, 1);
4902         DO_ASSERT((*env)->GetJavaVM(env, &calls->vm) == 0);
4903         calls->o = (*env)->NewWeakGlobalRef(env, o);
4904         calls->handle_open_channel_meth = (*env)->GetMethodID(env, c, "handle_open_channel", "([BJJ)V");
4905         CHECK(calls->handle_open_channel_meth != NULL);
4906         calls->handle_accept_channel_meth = (*env)->GetMethodID(env, c, "handle_accept_channel", "([BJJ)V");
4907         CHECK(calls->handle_accept_channel_meth != NULL);
4908         calls->handle_funding_created_meth = (*env)->GetMethodID(env, c, "handle_funding_created", "([BJ)V");
4909         CHECK(calls->handle_funding_created_meth != NULL);
4910         calls->handle_funding_signed_meth = (*env)->GetMethodID(env, c, "handle_funding_signed", "([BJ)V");
4911         CHECK(calls->handle_funding_signed_meth != NULL);
4912         calls->handle_funding_locked_meth = (*env)->GetMethodID(env, c, "handle_funding_locked", "([BJ)V");
4913         CHECK(calls->handle_funding_locked_meth != NULL);
4914         calls->handle_shutdown_meth = (*env)->GetMethodID(env, c, "handle_shutdown", "([BJ)V");
4915         CHECK(calls->handle_shutdown_meth != NULL);
4916         calls->handle_closing_signed_meth = (*env)->GetMethodID(env, c, "handle_closing_signed", "([BJ)V");
4917         CHECK(calls->handle_closing_signed_meth != NULL);
4918         calls->handle_update_add_htlc_meth = (*env)->GetMethodID(env, c, "handle_update_add_htlc", "([BJ)V");
4919         CHECK(calls->handle_update_add_htlc_meth != NULL);
4920         calls->handle_update_fulfill_htlc_meth = (*env)->GetMethodID(env, c, "handle_update_fulfill_htlc", "([BJ)V");
4921         CHECK(calls->handle_update_fulfill_htlc_meth != NULL);
4922         calls->handle_update_fail_htlc_meth = (*env)->GetMethodID(env, c, "handle_update_fail_htlc", "([BJ)V");
4923         CHECK(calls->handle_update_fail_htlc_meth != NULL);
4924         calls->handle_update_fail_malformed_htlc_meth = (*env)->GetMethodID(env, c, "handle_update_fail_malformed_htlc", "([BJ)V");
4925         CHECK(calls->handle_update_fail_malformed_htlc_meth != NULL);
4926         calls->handle_commitment_signed_meth = (*env)->GetMethodID(env, c, "handle_commitment_signed", "([BJ)V");
4927         CHECK(calls->handle_commitment_signed_meth != NULL);
4928         calls->handle_revoke_and_ack_meth = (*env)->GetMethodID(env, c, "handle_revoke_and_ack", "([BJ)V");
4929         CHECK(calls->handle_revoke_and_ack_meth != NULL);
4930         calls->handle_update_fee_meth = (*env)->GetMethodID(env, c, "handle_update_fee", "([BJ)V");
4931         CHECK(calls->handle_update_fee_meth != NULL);
4932         calls->handle_announcement_signatures_meth = (*env)->GetMethodID(env, c, "handle_announcement_signatures", "([BJ)V");
4933         CHECK(calls->handle_announcement_signatures_meth != NULL);
4934         calls->peer_disconnected_meth = (*env)->GetMethodID(env, c, "peer_disconnected", "([BZ)V");
4935         CHECK(calls->peer_disconnected_meth != NULL);
4936         calls->peer_connected_meth = (*env)->GetMethodID(env, c, "peer_connected", "([BJ)V");
4937         CHECK(calls->peer_connected_meth != NULL);
4938         calls->handle_channel_reestablish_meth = (*env)->GetMethodID(env, c, "handle_channel_reestablish", "([BJ)V");
4939         CHECK(calls->handle_channel_reestablish_meth != NULL);
4940         calls->handle_error_meth = (*env)->GetMethodID(env, c, "handle_error", "([BJ)V");
4941         CHECK(calls->handle_error_meth != NULL);
4942
4943         LDKChannelMessageHandler ret = {
4944                 .this_arg = (void*) calls,
4945                 .handle_open_channel = handle_open_channel_jcall,
4946                 .handle_accept_channel = handle_accept_channel_jcall,
4947                 .handle_funding_created = handle_funding_created_jcall,
4948                 .handle_funding_signed = handle_funding_signed_jcall,
4949                 .handle_funding_locked = handle_funding_locked_jcall,
4950                 .handle_shutdown = handle_shutdown_jcall,
4951                 .handle_closing_signed = handle_closing_signed_jcall,
4952                 .handle_update_add_htlc = handle_update_add_htlc_jcall,
4953                 .handle_update_fulfill_htlc = handle_update_fulfill_htlc_jcall,
4954                 .handle_update_fail_htlc = handle_update_fail_htlc_jcall,
4955                 .handle_update_fail_malformed_htlc = handle_update_fail_malformed_htlc_jcall,
4956                 .handle_commitment_signed = handle_commitment_signed_jcall,
4957                 .handle_revoke_and_ack = handle_revoke_and_ack_jcall,
4958                 .handle_update_fee = handle_update_fee_jcall,
4959                 .handle_announcement_signatures = handle_announcement_signatures_jcall,
4960                 .peer_disconnected = peer_disconnected_jcall,
4961                 .peer_connected = peer_connected_jcall,
4962                 .handle_channel_reestablish = handle_channel_reestablish_jcall,
4963                 .handle_error = handle_error_jcall,
4964                 .free = LDKChannelMessageHandler_JCalls_free,
4965                 .MessageSendEventsProvider = LDKMessageSendEventsProvider_init(env, _a, MessageSendEventsProvider),
4966         };
4967         calls->MessageSendEventsProvider = ret.MessageSendEventsProvider.this_arg;
4968         return ret;
4969 }
4970 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_LDKChannelMessageHandler_1new (JNIEnv * env, jclass _a, jobject o, jobject MessageSendEventsProvider) {
4971         LDKChannelMessageHandler *res_ptr = MALLOC(sizeof(LDKChannelMessageHandler), "LDKChannelMessageHandler");
4972         *res_ptr = LDKChannelMessageHandler_init(env, _a, o, MessageSendEventsProvider);
4973         return (long)res_ptr;
4974 }
4975 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKChannelMessageHandler_1get_1obj_1from_1jcalls (JNIEnv * env, jclass _a, jlong val) {
4976         jobject ret = (*env)->NewLocalRef(env, ((LDKChannelMessageHandler_JCalls*)val)->o);
4977         CHECK(ret != NULL);
4978         return ret;
4979 }
4980 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelMessageHandler_1handle_1open_1channel(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray their_node_id, jlong their_features, jlong msg) {
4981         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
4982         LDKPublicKey their_node_id_ref;
4983         CHECK((*_env)->GetArrayLength (_env, their_node_id) == 33);
4984         (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
4985         LDKInitFeatures their_features_conv;
4986         their_features_conv.inner = (void*)(their_features & (~1));
4987         their_features_conv.is_owned = (their_features & 1) || (their_features == 0);
4988         // Warning: we may need a move here but can't clone!
4989         LDKOpenChannel msg_conv;
4990         msg_conv.inner = (void*)(msg & (~1));
4991         msg_conv.is_owned = false;
4992         (this_arg_conv->handle_open_channel)(this_arg_conv->this_arg, their_node_id_ref, their_features_conv, &msg_conv);
4993 }
4994
4995 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelMessageHandler_1handle_1accept_1channel(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray their_node_id, jlong their_features, jlong msg) {
4996         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
4997         LDKPublicKey their_node_id_ref;
4998         CHECK((*_env)->GetArrayLength (_env, their_node_id) == 33);
4999         (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
5000         LDKInitFeatures their_features_conv;
5001         their_features_conv.inner = (void*)(their_features & (~1));
5002         their_features_conv.is_owned = (their_features & 1) || (their_features == 0);
5003         // Warning: we may need a move here but can't clone!
5004         LDKAcceptChannel msg_conv;
5005         msg_conv.inner = (void*)(msg & (~1));
5006         msg_conv.is_owned = false;
5007         (this_arg_conv->handle_accept_channel)(this_arg_conv->this_arg, their_node_id_ref, their_features_conv, &msg_conv);
5008 }
5009
5010 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelMessageHandler_1handle_1funding_1created(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray their_node_id, jlong msg) {
5011         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
5012         LDKPublicKey their_node_id_ref;
5013         CHECK((*_env)->GetArrayLength (_env, their_node_id) == 33);
5014         (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
5015         LDKFundingCreated msg_conv;
5016         msg_conv.inner = (void*)(msg & (~1));
5017         msg_conv.is_owned = false;
5018         (this_arg_conv->handle_funding_created)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
5019 }
5020
5021 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelMessageHandler_1handle_1funding_1signed(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray their_node_id, jlong msg) {
5022         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
5023         LDKPublicKey their_node_id_ref;
5024         CHECK((*_env)->GetArrayLength (_env, their_node_id) == 33);
5025         (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
5026         LDKFundingSigned msg_conv;
5027         msg_conv.inner = (void*)(msg & (~1));
5028         msg_conv.is_owned = false;
5029         (this_arg_conv->handle_funding_signed)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
5030 }
5031
5032 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelMessageHandler_1handle_1funding_1locked(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray their_node_id, jlong msg) {
5033         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
5034         LDKPublicKey their_node_id_ref;
5035         CHECK((*_env)->GetArrayLength (_env, their_node_id) == 33);
5036         (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
5037         LDKFundingLocked msg_conv;
5038         msg_conv.inner = (void*)(msg & (~1));
5039         msg_conv.is_owned = false;
5040         (this_arg_conv->handle_funding_locked)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
5041 }
5042
5043 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelMessageHandler_1handle_1shutdown(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray their_node_id, jlong msg) {
5044         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
5045         LDKPublicKey their_node_id_ref;
5046         CHECK((*_env)->GetArrayLength (_env, their_node_id) == 33);
5047         (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
5048         LDKShutdown msg_conv;
5049         msg_conv.inner = (void*)(msg & (~1));
5050         msg_conv.is_owned = false;
5051         (this_arg_conv->handle_shutdown)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
5052 }
5053
5054 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelMessageHandler_1handle_1closing_1signed(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray their_node_id, jlong msg) {
5055         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
5056         LDKPublicKey their_node_id_ref;
5057         CHECK((*_env)->GetArrayLength (_env, their_node_id) == 33);
5058         (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
5059         LDKClosingSigned msg_conv;
5060         msg_conv.inner = (void*)(msg & (~1));
5061         msg_conv.is_owned = false;
5062         (this_arg_conv->handle_closing_signed)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
5063 }
5064
5065 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelMessageHandler_1handle_1update_1add_1htlc(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray their_node_id, jlong msg) {
5066         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
5067         LDKPublicKey their_node_id_ref;
5068         CHECK((*_env)->GetArrayLength (_env, their_node_id) == 33);
5069         (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
5070         LDKUpdateAddHTLC msg_conv;
5071         msg_conv.inner = (void*)(msg & (~1));
5072         msg_conv.is_owned = false;
5073         (this_arg_conv->handle_update_add_htlc)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
5074 }
5075
5076 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelMessageHandler_1handle_1update_1fulfill_1htlc(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray their_node_id, jlong msg) {
5077         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
5078         LDKPublicKey their_node_id_ref;
5079         CHECK((*_env)->GetArrayLength (_env, their_node_id) == 33);
5080         (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
5081         LDKUpdateFulfillHTLC msg_conv;
5082         msg_conv.inner = (void*)(msg & (~1));
5083         msg_conv.is_owned = false;
5084         (this_arg_conv->handle_update_fulfill_htlc)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
5085 }
5086
5087 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelMessageHandler_1handle_1update_1fail_1htlc(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray their_node_id, jlong msg) {
5088         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
5089         LDKPublicKey their_node_id_ref;
5090         CHECK((*_env)->GetArrayLength (_env, their_node_id) == 33);
5091         (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
5092         LDKUpdateFailHTLC msg_conv;
5093         msg_conv.inner = (void*)(msg & (~1));
5094         msg_conv.is_owned = false;
5095         (this_arg_conv->handle_update_fail_htlc)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
5096 }
5097
5098 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelMessageHandler_1handle_1update_1fail_1malformed_1htlc(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray their_node_id, jlong msg) {
5099         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
5100         LDKPublicKey their_node_id_ref;
5101         CHECK((*_env)->GetArrayLength (_env, their_node_id) == 33);
5102         (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
5103         LDKUpdateFailMalformedHTLC msg_conv;
5104         msg_conv.inner = (void*)(msg & (~1));
5105         msg_conv.is_owned = false;
5106         (this_arg_conv->handle_update_fail_malformed_htlc)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
5107 }
5108
5109 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelMessageHandler_1handle_1commitment_1signed(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray their_node_id, jlong msg) {
5110         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
5111         LDKPublicKey their_node_id_ref;
5112         CHECK((*_env)->GetArrayLength (_env, their_node_id) == 33);
5113         (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
5114         LDKCommitmentSigned msg_conv;
5115         msg_conv.inner = (void*)(msg & (~1));
5116         msg_conv.is_owned = false;
5117         (this_arg_conv->handle_commitment_signed)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
5118 }
5119
5120 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelMessageHandler_1handle_1revoke_1and_1ack(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray their_node_id, jlong msg) {
5121         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
5122         LDKPublicKey their_node_id_ref;
5123         CHECK((*_env)->GetArrayLength (_env, their_node_id) == 33);
5124         (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
5125         LDKRevokeAndACK msg_conv;
5126         msg_conv.inner = (void*)(msg & (~1));
5127         msg_conv.is_owned = false;
5128         (this_arg_conv->handle_revoke_and_ack)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
5129 }
5130
5131 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelMessageHandler_1handle_1update_1fee(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray their_node_id, jlong msg) {
5132         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
5133         LDKPublicKey their_node_id_ref;
5134         CHECK((*_env)->GetArrayLength (_env, their_node_id) == 33);
5135         (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
5136         LDKUpdateFee msg_conv;
5137         msg_conv.inner = (void*)(msg & (~1));
5138         msg_conv.is_owned = false;
5139         (this_arg_conv->handle_update_fee)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
5140 }
5141
5142 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelMessageHandler_1handle_1announcement_1signatures(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray their_node_id, jlong msg) {
5143         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
5144         LDKPublicKey their_node_id_ref;
5145         CHECK((*_env)->GetArrayLength (_env, their_node_id) == 33);
5146         (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
5147         LDKAnnouncementSignatures msg_conv;
5148         msg_conv.inner = (void*)(msg & (~1));
5149         msg_conv.is_owned = false;
5150         (this_arg_conv->handle_announcement_signatures)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
5151 }
5152
5153 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelMessageHandler_1peer_1disconnected(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray their_node_id, jboolean no_connection_possible) {
5154         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
5155         LDKPublicKey their_node_id_ref;
5156         CHECK((*_env)->GetArrayLength (_env, their_node_id) == 33);
5157         (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
5158         (this_arg_conv->peer_disconnected)(this_arg_conv->this_arg, their_node_id_ref, no_connection_possible);
5159 }
5160
5161 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelMessageHandler_1peer_1connected(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray their_node_id, jlong msg) {
5162         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
5163         LDKPublicKey their_node_id_ref;
5164         CHECK((*_env)->GetArrayLength (_env, their_node_id) == 33);
5165         (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
5166         LDKInit msg_conv;
5167         msg_conv.inner = (void*)(msg & (~1));
5168         msg_conv.is_owned = false;
5169         (this_arg_conv->peer_connected)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
5170 }
5171
5172 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelMessageHandler_1handle_1channel_1reestablish(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray their_node_id, jlong msg) {
5173         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
5174         LDKPublicKey their_node_id_ref;
5175         CHECK((*_env)->GetArrayLength (_env, their_node_id) == 33);
5176         (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
5177         LDKChannelReestablish msg_conv;
5178         msg_conv.inner = (void*)(msg & (~1));
5179         msg_conv.is_owned = false;
5180         (this_arg_conv->handle_channel_reestablish)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
5181 }
5182
5183 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelMessageHandler_1handle_1error(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray their_node_id, jlong msg) {
5184         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
5185         LDKPublicKey their_node_id_ref;
5186         CHECK((*_env)->GetArrayLength (_env, their_node_id) == 33);
5187         (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
5188         LDKErrorMessage msg_conv;
5189         msg_conv.inner = (void*)(msg & (~1));
5190         msg_conv.is_owned = false;
5191         (this_arg_conv->handle_error)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
5192 }
5193
5194 typedef struct LDKRoutingMessageHandler_JCalls {
5195         atomic_size_t refcnt;
5196         JavaVM *vm;
5197         jweak o;
5198         LDKMessageSendEventsProvider_JCalls* MessageSendEventsProvider;
5199         jmethodID handle_node_announcement_meth;
5200         jmethodID handle_channel_announcement_meth;
5201         jmethodID handle_channel_update_meth;
5202         jmethodID handle_htlc_fail_channel_update_meth;
5203         jmethodID get_next_channel_announcements_meth;
5204         jmethodID get_next_node_announcements_meth;
5205         jmethodID sync_routing_table_meth;
5206         jmethodID handle_reply_channel_range_meth;
5207         jmethodID handle_reply_short_channel_ids_end_meth;
5208         jmethodID handle_query_channel_range_meth;
5209         jmethodID handle_query_short_channel_ids_meth;
5210 } LDKRoutingMessageHandler_JCalls;
5211 LDKCResult_boolLightningErrorZ handle_node_announcement_jcall(const void* this_arg, const struct LDKNodeAnnouncement *NONNULL_PTR msg) {
5212         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
5213         JNIEnv *_env;
5214         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
5215         LDKNodeAnnouncement msg_var = *msg;
5216         if (msg->inner != NULL)
5217                 msg_var = NodeAnnouncement_clone(msg);
5218         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
5219         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
5220         long msg_ref = (long)msg_var.inner;
5221         if (msg_var.is_owned) {
5222                 msg_ref |= 1;
5223         }
5224         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
5225         CHECK(obj != NULL);
5226         LDKCResult_boolLightningErrorZ* ret = (LDKCResult_boolLightningErrorZ*)(*_env)->CallLongMethod(_env, obj, j_calls->handle_node_announcement_meth, msg_ref);
5227         LDKCResult_boolLightningErrorZ ret_conv = *(LDKCResult_boolLightningErrorZ*)ret;
5228         FREE((void*)ret);
5229         return ret_conv;
5230 }
5231 LDKCResult_boolLightningErrorZ handle_channel_announcement_jcall(const void* this_arg, const struct LDKChannelAnnouncement *NONNULL_PTR msg) {
5232         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
5233         JNIEnv *_env;
5234         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
5235         LDKChannelAnnouncement msg_var = *msg;
5236         if (msg->inner != NULL)
5237                 msg_var = ChannelAnnouncement_clone(msg);
5238         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
5239         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
5240         long msg_ref = (long)msg_var.inner;
5241         if (msg_var.is_owned) {
5242                 msg_ref |= 1;
5243         }
5244         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
5245         CHECK(obj != NULL);
5246         LDKCResult_boolLightningErrorZ* ret = (LDKCResult_boolLightningErrorZ*)(*_env)->CallLongMethod(_env, obj, j_calls->handle_channel_announcement_meth, msg_ref);
5247         LDKCResult_boolLightningErrorZ ret_conv = *(LDKCResult_boolLightningErrorZ*)ret;
5248         FREE((void*)ret);
5249         return ret_conv;
5250 }
5251 LDKCResult_boolLightningErrorZ handle_channel_update_jcall(const void* this_arg, const struct LDKChannelUpdate *NONNULL_PTR msg) {
5252         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
5253         JNIEnv *_env;
5254         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
5255         LDKChannelUpdate msg_var = *msg;
5256         if (msg->inner != NULL)
5257                 msg_var = ChannelUpdate_clone(msg);
5258         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
5259         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
5260         long msg_ref = (long)msg_var.inner;
5261         if (msg_var.is_owned) {
5262                 msg_ref |= 1;
5263         }
5264         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
5265         CHECK(obj != NULL);
5266         LDKCResult_boolLightningErrorZ* ret = (LDKCResult_boolLightningErrorZ*)(*_env)->CallLongMethod(_env, obj, j_calls->handle_channel_update_meth, msg_ref);
5267         LDKCResult_boolLightningErrorZ ret_conv = *(LDKCResult_boolLightningErrorZ*)ret;
5268         FREE((void*)ret);
5269         return ret_conv;
5270 }
5271 void handle_htlc_fail_channel_update_jcall(const void* this_arg, const struct LDKHTLCFailChannelUpdate *NONNULL_PTR update) {
5272         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
5273         JNIEnv *_env;
5274         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
5275         long ret_update = (long)update;
5276         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
5277         CHECK(obj != NULL);
5278         return (*_env)->CallVoidMethod(_env, obj, j_calls->handle_htlc_fail_channel_update_meth, ret_update);
5279 }
5280 LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ get_next_channel_announcements_jcall(const void* this_arg, uint64_t starting_point, uint8_t batch_amount) {
5281         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
5282         JNIEnv *_env;
5283         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
5284         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
5285         CHECK(obj != NULL);
5286         jlongArray arg = (*_env)->CallObjectMethod(_env, obj, j_calls->get_next_channel_announcements_meth, starting_point, batch_amount);
5287         LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ arg_constr;
5288         arg_constr.datalen = (*_env)->GetArrayLength (_env, arg);
5289         if (arg_constr.datalen > 0)
5290                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ), "LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ Elements");
5291         else
5292                 arg_constr.data = NULL;
5293         long* arg_vals = (*_env)->GetLongArrayElements (_env, arg, NULL);
5294         for (size_t l = 0; l < arg_constr.datalen; l++) {
5295                 long arr_conv_63 = arg_vals[l];
5296                 LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ arr_conv_63_conv = *(LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ*)arr_conv_63;
5297                 FREE((void*)arr_conv_63);
5298                 arg_constr.data[l] = arr_conv_63_conv;
5299         }
5300         (*_env)->ReleaseLongArrayElements (_env, arg, arg_vals, 0);
5301         return arg_constr;
5302 }
5303 LDKCVec_NodeAnnouncementZ get_next_node_announcements_jcall(const void* this_arg, struct LDKPublicKey starting_point, uint8_t batch_amount) {
5304         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
5305         JNIEnv *_env;
5306         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
5307         jbyteArray starting_point_arr = (*_env)->NewByteArray(_env, 33);
5308         (*_env)->SetByteArrayRegion(_env, starting_point_arr, 0, 33, starting_point.compressed_form);
5309         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
5310         CHECK(obj != NULL);
5311         jlongArray arg = (*_env)->CallObjectMethod(_env, obj, j_calls->get_next_node_announcements_meth, starting_point_arr, batch_amount);
5312         LDKCVec_NodeAnnouncementZ arg_constr;
5313         arg_constr.datalen = (*_env)->GetArrayLength (_env, arg);
5314         if (arg_constr.datalen > 0)
5315                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKNodeAnnouncement), "LDKCVec_NodeAnnouncementZ Elements");
5316         else
5317                 arg_constr.data = NULL;
5318         long* arg_vals = (*_env)->GetLongArrayElements (_env, arg, NULL);
5319         for (size_t s = 0; s < arg_constr.datalen; s++) {
5320                 long arr_conv_18 = arg_vals[s];
5321                 LDKNodeAnnouncement arr_conv_18_conv;
5322                 arr_conv_18_conv.inner = (void*)(arr_conv_18 & (~1));
5323                 arr_conv_18_conv.is_owned = (arr_conv_18 & 1) || (arr_conv_18 == 0);
5324                 if (arr_conv_18_conv.inner != NULL)
5325                         arr_conv_18_conv = NodeAnnouncement_clone(&arr_conv_18_conv);
5326                 arg_constr.data[s] = arr_conv_18_conv;
5327         }
5328         (*_env)->ReleaseLongArrayElements (_env, arg, arg_vals, 0);
5329         return arg_constr;
5330 }
5331 void sync_routing_table_jcall(const void* this_arg, struct LDKPublicKey their_node_id, const struct LDKInit *NONNULL_PTR init) {
5332         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
5333         JNIEnv *_env;
5334         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
5335         jbyteArray their_node_id_arr = (*_env)->NewByteArray(_env, 33);
5336         (*_env)->SetByteArrayRegion(_env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
5337         LDKInit init_var = *init;
5338         if (init->inner != NULL)
5339                 init_var = Init_clone(init);
5340         CHECK((((long)init_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
5341         CHECK((((long)&init_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
5342         long init_ref = (long)init_var.inner;
5343         if (init_var.is_owned) {
5344                 init_ref |= 1;
5345         }
5346         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
5347         CHECK(obj != NULL);
5348         return (*_env)->CallVoidMethod(_env, obj, j_calls->sync_routing_table_meth, their_node_id_arr, init_ref);
5349 }
5350 LDKCResult_NoneLightningErrorZ handle_reply_channel_range_jcall(const void* this_arg, struct LDKPublicKey their_node_id, struct LDKReplyChannelRange msg) {
5351         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
5352         JNIEnv *_env;
5353         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
5354         jbyteArray their_node_id_arr = (*_env)->NewByteArray(_env, 33);
5355         (*_env)->SetByteArrayRegion(_env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
5356         LDKReplyChannelRange msg_var = msg;
5357         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
5358         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
5359         long msg_ref = (long)msg_var.inner;
5360         if (msg_var.is_owned) {
5361                 msg_ref |= 1;
5362         }
5363         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
5364         CHECK(obj != NULL);
5365         LDKCResult_NoneLightningErrorZ* ret = (LDKCResult_NoneLightningErrorZ*)(*_env)->CallLongMethod(_env, obj, j_calls->handle_reply_channel_range_meth, their_node_id_arr, msg_ref);
5366         LDKCResult_NoneLightningErrorZ ret_conv = *(LDKCResult_NoneLightningErrorZ*)ret;
5367         FREE((void*)ret);
5368         return ret_conv;
5369 }
5370 LDKCResult_NoneLightningErrorZ handle_reply_short_channel_ids_end_jcall(const void* this_arg, struct LDKPublicKey their_node_id, struct LDKReplyShortChannelIdsEnd msg) {
5371         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
5372         JNIEnv *_env;
5373         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
5374         jbyteArray their_node_id_arr = (*_env)->NewByteArray(_env, 33);
5375         (*_env)->SetByteArrayRegion(_env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
5376         LDKReplyShortChannelIdsEnd msg_var = msg;
5377         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
5378         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
5379         long msg_ref = (long)msg_var.inner;
5380         if (msg_var.is_owned) {
5381                 msg_ref |= 1;
5382         }
5383         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
5384         CHECK(obj != NULL);
5385         LDKCResult_NoneLightningErrorZ* ret = (LDKCResult_NoneLightningErrorZ*)(*_env)->CallLongMethod(_env, obj, j_calls->handle_reply_short_channel_ids_end_meth, their_node_id_arr, msg_ref);
5386         LDKCResult_NoneLightningErrorZ ret_conv = *(LDKCResult_NoneLightningErrorZ*)ret;
5387         FREE((void*)ret);
5388         return ret_conv;
5389 }
5390 LDKCResult_NoneLightningErrorZ handle_query_channel_range_jcall(const void* this_arg, struct LDKPublicKey their_node_id, struct LDKQueryChannelRange msg) {
5391         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
5392         JNIEnv *_env;
5393         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
5394         jbyteArray their_node_id_arr = (*_env)->NewByteArray(_env, 33);
5395         (*_env)->SetByteArrayRegion(_env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
5396         LDKQueryChannelRange msg_var = msg;
5397         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
5398         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
5399         long msg_ref = (long)msg_var.inner;
5400         if (msg_var.is_owned) {
5401                 msg_ref |= 1;
5402         }
5403         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
5404         CHECK(obj != NULL);
5405         LDKCResult_NoneLightningErrorZ* ret = (LDKCResult_NoneLightningErrorZ*)(*_env)->CallLongMethod(_env, obj, j_calls->handle_query_channel_range_meth, their_node_id_arr, msg_ref);
5406         LDKCResult_NoneLightningErrorZ ret_conv = *(LDKCResult_NoneLightningErrorZ*)ret;
5407         FREE((void*)ret);
5408         return ret_conv;
5409 }
5410 LDKCResult_NoneLightningErrorZ handle_query_short_channel_ids_jcall(const void* this_arg, struct LDKPublicKey their_node_id, struct LDKQueryShortChannelIds msg) {
5411         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
5412         JNIEnv *_env;
5413         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
5414         jbyteArray their_node_id_arr = (*_env)->NewByteArray(_env, 33);
5415         (*_env)->SetByteArrayRegion(_env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
5416         LDKQueryShortChannelIds msg_var = msg;
5417         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
5418         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
5419         long msg_ref = (long)msg_var.inner;
5420         if (msg_var.is_owned) {
5421                 msg_ref |= 1;
5422         }
5423         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
5424         CHECK(obj != NULL);
5425         LDKCResult_NoneLightningErrorZ* ret = (LDKCResult_NoneLightningErrorZ*)(*_env)->CallLongMethod(_env, obj, j_calls->handle_query_short_channel_ids_meth, their_node_id_arr, msg_ref);
5426         LDKCResult_NoneLightningErrorZ ret_conv = *(LDKCResult_NoneLightningErrorZ*)ret;
5427         FREE((void*)ret);
5428         return ret_conv;
5429 }
5430 static void LDKRoutingMessageHandler_JCalls_free(void* this_arg) {
5431         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
5432         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
5433                 JNIEnv *env;
5434                 DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
5435                 (*env)->DeleteWeakGlobalRef(env, j_calls->o);
5436                 FREE(j_calls);
5437         }
5438 }
5439 static void* LDKRoutingMessageHandler_JCalls_clone(const void* this_arg) {
5440         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
5441         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
5442         atomic_fetch_add_explicit(&j_calls->MessageSendEventsProvider->refcnt, 1, memory_order_release);
5443         return (void*) this_arg;
5444 }
5445 static inline LDKRoutingMessageHandler LDKRoutingMessageHandler_init (JNIEnv * env, jclass _a, jobject o, jobject MessageSendEventsProvider) {
5446         jclass c = (*env)->GetObjectClass(env, o);
5447         CHECK(c != NULL);
5448         LDKRoutingMessageHandler_JCalls *calls = MALLOC(sizeof(LDKRoutingMessageHandler_JCalls), "LDKRoutingMessageHandler_JCalls");
5449         atomic_init(&calls->refcnt, 1);
5450         DO_ASSERT((*env)->GetJavaVM(env, &calls->vm) == 0);
5451         calls->o = (*env)->NewWeakGlobalRef(env, o);
5452         calls->handle_node_announcement_meth = (*env)->GetMethodID(env, c, "handle_node_announcement", "(J)J");
5453         CHECK(calls->handle_node_announcement_meth != NULL);
5454         calls->handle_channel_announcement_meth = (*env)->GetMethodID(env, c, "handle_channel_announcement", "(J)J");
5455         CHECK(calls->handle_channel_announcement_meth != NULL);
5456         calls->handle_channel_update_meth = (*env)->GetMethodID(env, c, "handle_channel_update", "(J)J");
5457         CHECK(calls->handle_channel_update_meth != NULL);
5458         calls->handle_htlc_fail_channel_update_meth = (*env)->GetMethodID(env, c, "handle_htlc_fail_channel_update", "(J)V");
5459         CHECK(calls->handle_htlc_fail_channel_update_meth != NULL);
5460         calls->get_next_channel_announcements_meth = (*env)->GetMethodID(env, c, "get_next_channel_announcements", "(JB)[J");
5461         CHECK(calls->get_next_channel_announcements_meth != NULL);
5462         calls->get_next_node_announcements_meth = (*env)->GetMethodID(env, c, "get_next_node_announcements", "([BB)[J");
5463         CHECK(calls->get_next_node_announcements_meth != NULL);
5464         calls->sync_routing_table_meth = (*env)->GetMethodID(env, c, "sync_routing_table", "([BJ)V");
5465         CHECK(calls->sync_routing_table_meth != NULL);
5466         calls->handle_reply_channel_range_meth = (*env)->GetMethodID(env, c, "handle_reply_channel_range", "([BJ)J");
5467         CHECK(calls->handle_reply_channel_range_meth != NULL);
5468         calls->handle_reply_short_channel_ids_end_meth = (*env)->GetMethodID(env, c, "handle_reply_short_channel_ids_end", "([BJ)J");
5469         CHECK(calls->handle_reply_short_channel_ids_end_meth != NULL);
5470         calls->handle_query_channel_range_meth = (*env)->GetMethodID(env, c, "handle_query_channel_range", "([BJ)J");
5471         CHECK(calls->handle_query_channel_range_meth != NULL);
5472         calls->handle_query_short_channel_ids_meth = (*env)->GetMethodID(env, c, "handle_query_short_channel_ids", "([BJ)J");
5473         CHECK(calls->handle_query_short_channel_ids_meth != NULL);
5474
5475         LDKRoutingMessageHandler ret = {
5476                 .this_arg = (void*) calls,
5477                 .handle_node_announcement = handle_node_announcement_jcall,
5478                 .handle_channel_announcement = handle_channel_announcement_jcall,
5479                 .handle_channel_update = handle_channel_update_jcall,
5480                 .handle_htlc_fail_channel_update = handle_htlc_fail_channel_update_jcall,
5481                 .get_next_channel_announcements = get_next_channel_announcements_jcall,
5482                 .get_next_node_announcements = get_next_node_announcements_jcall,
5483                 .sync_routing_table = sync_routing_table_jcall,
5484                 .handle_reply_channel_range = handle_reply_channel_range_jcall,
5485                 .handle_reply_short_channel_ids_end = handle_reply_short_channel_ids_end_jcall,
5486                 .handle_query_channel_range = handle_query_channel_range_jcall,
5487                 .handle_query_short_channel_ids = handle_query_short_channel_ids_jcall,
5488                 .free = LDKRoutingMessageHandler_JCalls_free,
5489                 .MessageSendEventsProvider = LDKMessageSendEventsProvider_init(env, _a, MessageSendEventsProvider),
5490         };
5491         calls->MessageSendEventsProvider = ret.MessageSendEventsProvider.this_arg;
5492         return ret;
5493 }
5494 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_LDKRoutingMessageHandler_1new (JNIEnv * env, jclass _a, jobject o, jobject MessageSendEventsProvider) {
5495         LDKRoutingMessageHandler *res_ptr = MALLOC(sizeof(LDKRoutingMessageHandler), "LDKRoutingMessageHandler");
5496         *res_ptr = LDKRoutingMessageHandler_init(env, _a, o, MessageSendEventsProvider);
5497         return (long)res_ptr;
5498 }
5499 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKRoutingMessageHandler_1get_1obj_1from_1jcalls (JNIEnv * env, jclass _a, jlong val) {
5500         jobject ret = (*env)->NewLocalRef(env, ((LDKRoutingMessageHandler_JCalls*)val)->o);
5501         CHECK(ret != NULL);
5502         return ret;
5503 }
5504 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_RoutingMessageHandler_1handle_1node_1announcement(JNIEnv * _env, jclass _b, jlong this_arg, jlong msg) {
5505         LDKRoutingMessageHandler* this_arg_conv = (LDKRoutingMessageHandler*)this_arg;
5506         LDKNodeAnnouncement msg_conv;
5507         msg_conv.inner = (void*)(msg & (~1));
5508         msg_conv.is_owned = false;
5509         LDKCResult_boolLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_boolLightningErrorZ), "LDKCResult_boolLightningErrorZ");
5510         *ret_conv = (this_arg_conv->handle_node_announcement)(this_arg_conv->this_arg, &msg_conv);
5511         return (long)ret_conv;
5512 }
5513
5514 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_RoutingMessageHandler_1handle_1channel_1announcement(JNIEnv * _env, jclass _b, jlong this_arg, jlong msg) {
5515         LDKRoutingMessageHandler* this_arg_conv = (LDKRoutingMessageHandler*)this_arg;
5516         LDKChannelAnnouncement msg_conv;
5517         msg_conv.inner = (void*)(msg & (~1));
5518         msg_conv.is_owned = false;
5519         LDKCResult_boolLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_boolLightningErrorZ), "LDKCResult_boolLightningErrorZ");
5520         *ret_conv = (this_arg_conv->handle_channel_announcement)(this_arg_conv->this_arg, &msg_conv);
5521         return (long)ret_conv;
5522 }
5523
5524 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_RoutingMessageHandler_1handle_1channel_1update(JNIEnv * _env, jclass _b, jlong this_arg, jlong msg) {
5525         LDKRoutingMessageHandler* this_arg_conv = (LDKRoutingMessageHandler*)this_arg;
5526         LDKChannelUpdate msg_conv;
5527         msg_conv.inner = (void*)(msg & (~1));
5528         msg_conv.is_owned = false;
5529         LDKCResult_boolLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_boolLightningErrorZ), "LDKCResult_boolLightningErrorZ");
5530         *ret_conv = (this_arg_conv->handle_channel_update)(this_arg_conv->this_arg, &msg_conv);
5531         return (long)ret_conv;
5532 }
5533
5534 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RoutingMessageHandler_1handle_1htlc_1fail_1channel_1update(JNIEnv * _env, jclass _b, jlong this_arg, jlong update) {
5535         LDKRoutingMessageHandler* this_arg_conv = (LDKRoutingMessageHandler*)this_arg;
5536         LDKHTLCFailChannelUpdate* update_conv = (LDKHTLCFailChannelUpdate*)update;
5537         (this_arg_conv->handle_htlc_fail_channel_update)(this_arg_conv->this_arg, update_conv);
5538 }
5539
5540 JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_RoutingMessageHandler_1get_1next_1channel_1announcements(JNIEnv * _env, jclass _b, jlong this_arg, jlong starting_point, jbyte batch_amount) {
5541         LDKRoutingMessageHandler* this_arg_conv = (LDKRoutingMessageHandler*)this_arg;
5542         LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ ret_var = (this_arg_conv->get_next_channel_announcements)(this_arg_conv->this_arg, starting_point, batch_amount);
5543         jlongArray ret_arr = (*_env)->NewLongArray(_env, ret_var.datalen);
5544         jlong *ret_arr_ptr = (*_env)->GetPrimitiveArrayCritical(_env, ret_arr, NULL);
5545         for (size_t l = 0; l < ret_var.datalen; l++) {
5546                 LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ* arr_conv_63_ref = MALLOC(sizeof(LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ), "LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ");
5547                 *arr_conv_63_ref = ret_var.data[l];
5548                 ret_arr_ptr[l] = (long)arr_conv_63_ref;
5549         }
5550         (*_env)->ReleasePrimitiveArrayCritical(_env, ret_arr, ret_arr_ptr, 0);
5551         FREE(ret_var.data);
5552         return ret_arr;
5553 }
5554
5555 JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_RoutingMessageHandler_1get_1next_1node_1announcements(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray starting_point, jbyte batch_amount) {
5556         LDKRoutingMessageHandler* this_arg_conv = (LDKRoutingMessageHandler*)this_arg;
5557         LDKPublicKey starting_point_ref;
5558         CHECK((*_env)->GetArrayLength (_env, starting_point) == 33);
5559         (*_env)->GetByteArrayRegion (_env, starting_point, 0, 33, starting_point_ref.compressed_form);
5560         LDKCVec_NodeAnnouncementZ ret_var = (this_arg_conv->get_next_node_announcements)(this_arg_conv->this_arg, starting_point_ref, batch_amount);
5561         jlongArray ret_arr = (*_env)->NewLongArray(_env, ret_var.datalen);
5562         jlong *ret_arr_ptr = (*_env)->GetPrimitiveArrayCritical(_env, ret_arr, NULL);
5563         for (size_t s = 0; s < ret_var.datalen; s++) {
5564                 LDKNodeAnnouncement arr_conv_18_var = ret_var.data[s];
5565                 CHECK((((long)arr_conv_18_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
5566                 CHECK((((long)&arr_conv_18_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
5567                 long arr_conv_18_ref = (long)arr_conv_18_var.inner;
5568                 if (arr_conv_18_var.is_owned) {
5569                         arr_conv_18_ref |= 1;
5570                 }
5571                 ret_arr_ptr[s] = arr_conv_18_ref;
5572         }
5573         (*_env)->ReleasePrimitiveArrayCritical(_env, ret_arr, ret_arr_ptr, 0);
5574         FREE(ret_var.data);
5575         return ret_arr;
5576 }
5577
5578 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RoutingMessageHandler_1sync_1routing_1table(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray their_node_id, jlong init) {
5579         LDKRoutingMessageHandler* this_arg_conv = (LDKRoutingMessageHandler*)this_arg;
5580         LDKPublicKey their_node_id_ref;
5581         CHECK((*_env)->GetArrayLength (_env, their_node_id) == 33);
5582         (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
5583         LDKInit init_conv;
5584         init_conv.inner = (void*)(init & (~1));
5585         init_conv.is_owned = false;
5586         (this_arg_conv->sync_routing_table)(this_arg_conv->this_arg, their_node_id_ref, &init_conv);
5587 }
5588
5589 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_RoutingMessageHandler_1handle_1reply_1channel_1range(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray their_node_id, jlong msg) {
5590         LDKRoutingMessageHandler* this_arg_conv = (LDKRoutingMessageHandler*)this_arg;
5591         LDKPublicKey their_node_id_ref;
5592         CHECK((*_env)->GetArrayLength (_env, their_node_id) == 33);
5593         (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
5594         LDKReplyChannelRange msg_conv;
5595         msg_conv.inner = (void*)(msg & (~1));
5596         msg_conv.is_owned = (msg & 1) || (msg == 0);
5597         if (msg_conv.inner != NULL)
5598                 msg_conv = ReplyChannelRange_clone(&msg_conv);
5599         LDKCResult_NoneLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneLightningErrorZ), "LDKCResult_NoneLightningErrorZ");
5600         *ret_conv = (this_arg_conv->handle_reply_channel_range)(this_arg_conv->this_arg, their_node_id_ref, msg_conv);
5601         return (long)ret_conv;
5602 }
5603
5604 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_RoutingMessageHandler_1handle_1reply_1short_1channel_1ids_1end(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray their_node_id, jlong msg) {
5605         LDKRoutingMessageHandler* this_arg_conv = (LDKRoutingMessageHandler*)this_arg;
5606         LDKPublicKey their_node_id_ref;
5607         CHECK((*_env)->GetArrayLength (_env, their_node_id) == 33);
5608         (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
5609         LDKReplyShortChannelIdsEnd msg_conv;
5610         msg_conv.inner = (void*)(msg & (~1));
5611         msg_conv.is_owned = (msg & 1) || (msg == 0);
5612         if (msg_conv.inner != NULL)
5613                 msg_conv = ReplyShortChannelIdsEnd_clone(&msg_conv);
5614         LDKCResult_NoneLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneLightningErrorZ), "LDKCResult_NoneLightningErrorZ");
5615         *ret_conv = (this_arg_conv->handle_reply_short_channel_ids_end)(this_arg_conv->this_arg, their_node_id_ref, msg_conv);
5616         return (long)ret_conv;
5617 }
5618
5619 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_RoutingMessageHandler_1handle_1query_1channel_1range(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray their_node_id, jlong msg) {
5620         LDKRoutingMessageHandler* this_arg_conv = (LDKRoutingMessageHandler*)this_arg;
5621         LDKPublicKey their_node_id_ref;
5622         CHECK((*_env)->GetArrayLength (_env, their_node_id) == 33);
5623         (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
5624         LDKQueryChannelRange msg_conv;
5625         msg_conv.inner = (void*)(msg & (~1));
5626         msg_conv.is_owned = (msg & 1) || (msg == 0);
5627         if (msg_conv.inner != NULL)
5628                 msg_conv = QueryChannelRange_clone(&msg_conv);
5629         LDKCResult_NoneLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneLightningErrorZ), "LDKCResult_NoneLightningErrorZ");
5630         *ret_conv = (this_arg_conv->handle_query_channel_range)(this_arg_conv->this_arg, their_node_id_ref, msg_conv);
5631         return (long)ret_conv;
5632 }
5633
5634 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_RoutingMessageHandler_1handle_1query_1short_1channel_1ids(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray their_node_id, jlong msg) {
5635         LDKRoutingMessageHandler* this_arg_conv = (LDKRoutingMessageHandler*)this_arg;
5636         LDKPublicKey their_node_id_ref;
5637         CHECK((*_env)->GetArrayLength (_env, their_node_id) == 33);
5638         (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
5639         LDKQueryShortChannelIds msg_conv;
5640         msg_conv.inner = (void*)(msg & (~1));
5641         msg_conv.is_owned = (msg & 1) || (msg == 0);
5642         if (msg_conv.inner != NULL)
5643                 msg_conv = QueryShortChannelIds_clone(&msg_conv);
5644         LDKCResult_NoneLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneLightningErrorZ), "LDKCResult_NoneLightningErrorZ");
5645         *ret_conv = (this_arg_conv->handle_query_short_channel_ids)(this_arg_conv->this_arg, their_node_id_ref, msg_conv);
5646         return (long)ret_conv;
5647 }
5648
5649 typedef struct LDKSocketDescriptor_JCalls {
5650         atomic_size_t refcnt;
5651         JavaVM *vm;
5652         jweak o;
5653         jmethodID send_data_meth;
5654         jmethodID disconnect_socket_meth;
5655         jmethodID eq_meth;
5656         jmethodID hash_meth;
5657 } LDKSocketDescriptor_JCalls;
5658 uintptr_t send_data_jcall(void* this_arg, struct LDKu8slice data, bool resume_read) {
5659         LDKSocketDescriptor_JCalls *j_calls = (LDKSocketDescriptor_JCalls*) this_arg;
5660         JNIEnv *_env;
5661         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
5662         LDKu8slice data_var = data;
5663         jbyteArray data_arr = (*_env)->NewByteArray(_env, data_var.datalen);
5664         (*_env)->SetByteArrayRegion(_env, data_arr, 0, data_var.datalen, data_var.data);
5665         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
5666         CHECK(obj != NULL);
5667         return (*_env)->CallLongMethod(_env, obj, j_calls->send_data_meth, data_arr, resume_read);
5668 }
5669 void disconnect_socket_jcall(void* this_arg) {
5670         LDKSocketDescriptor_JCalls *j_calls = (LDKSocketDescriptor_JCalls*) this_arg;
5671         JNIEnv *_env;
5672         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
5673         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
5674         CHECK(obj != NULL);
5675         return (*_env)->CallVoidMethod(_env, obj, j_calls->disconnect_socket_meth);
5676 }
5677 bool eq_jcall(const void* this_arg, const struct LDKSocketDescriptor *NONNULL_PTR other_arg) {
5678         LDKSocketDescriptor_JCalls *j_calls = (LDKSocketDescriptor_JCalls*) this_arg;
5679         JNIEnv *_env;
5680         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
5681         LDKSocketDescriptor *other_arg_clone = MALLOC(sizeof(LDKSocketDescriptor), "LDKSocketDescriptor");
5682         *other_arg_clone = SocketDescriptor_clone(other_arg);
5683         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
5684         CHECK(obj != NULL);
5685         return (*_env)->CallBooleanMethod(_env, obj, j_calls->eq_meth, (long)other_arg_clone);
5686 }
5687 uint64_t hash_jcall(const void* this_arg) {
5688         LDKSocketDescriptor_JCalls *j_calls = (LDKSocketDescriptor_JCalls*) this_arg;
5689         JNIEnv *_env;
5690         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
5691         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
5692         CHECK(obj != NULL);
5693         return (*_env)->CallLongMethod(_env, obj, j_calls->hash_meth);
5694 }
5695 static void LDKSocketDescriptor_JCalls_free(void* this_arg) {
5696         LDKSocketDescriptor_JCalls *j_calls = (LDKSocketDescriptor_JCalls*) this_arg;
5697         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
5698                 JNIEnv *env;
5699                 DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
5700                 (*env)->DeleteWeakGlobalRef(env, j_calls->o);
5701                 FREE(j_calls);
5702         }
5703 }
5704 static void* LDKSocketDescriptor_JCalls_clone(const void* this_arg) {
5705         LDKSocketDescriptor_JCalls *j_calls = (LDKSocketDescriptor_JCalls*) this_arg;
5706         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
5707         return (void*) this_arg;
5708 }
5709 static inline LDKSocketDescriptor LDKSocketDescriptor_init (JNIEnv * env, jclass _a, jobject o) {
5710         jclass c = (*env)->GetObjectClass(env, o);
5711         CHECK(c != NULL);
5712         LDKSocketDescriptor_JCalls *calls = MALLOC(sizeof(LDKSocketDescriptor_JCalls), "LDKSocketDescriptor_JCalls");
5713         atomic_init(&calls->refcnt, 1);
5714         DO_ASSERT((*env)->GetJavaVM(env, &calls->vm) == 0);
5715         calls->o = (*env)->NewWeakGlobalRef(env, o);
5716         calls->send_data_meth = (*env)->GetMethodID(env, c, "send_data", "([BZ)J");
5717         CHECK(calls->send_data_meth != NULL);
5718         calls->disconnect_socket_meth = (*env)->GetMethodID(env, c, "disconnect_socket", "()V");
5719         CHECK(calls->disconnect_socket_meth != NULL);
5720         calls->eq_meth = (*env)->GetMethodID(env, c, "eq", "(J)Z");
5721         CHECK(calls->eq_meth != NULL);
5722         calls->hash_meth = (*env)->GetMethodID(env, c, "hash", "()J");
5723         CHECK(calls->hash_meth != NULL);
5724
5725         LDKSocketDescriptor ret = {
5726                 .this_arg = (void*) calls,
5727                 .send_data = send_data_jcall,
5728                 .disconnect_socket = disconnect_socket_jcall,
5729                 .eq = eq_jcall,
5730                 .hash = hash_jcall,
5731                 .clone = LDKSocketDescriptor_JCalls_clone,
5732                 .free = LDKSocketDescriptor_JCalls_free,
5733         };
5734         return ret;
5735 }
5736 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_LDKSocketDescriptor_1new (JNIEnv * env, jclass _a, jobject o) {
5737         LDKSocketDescriptor *res_ptr = MALLOC(sizeof(LDKSocketDescriptor), "LDKSocketDescriptor");
5738         *res_ptr = LDKSocketDescriptor_init(env, _a, o);
5739         return (long)res_ptr;
5740 }
5741 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKSocketDescriptor_1get_1obj_1from_1jcalls (JNIEnv * env, jclass _a, jlong val) {
5742         jobject ret = (*env)->NewLocalRef(env, ((LDKSocketDescriptor_JCalls*)val)->o);
5743         CHECK(ret != NULL);
5744         return ret;
5745 }
5746 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_SocketDescriptor_1send_1data(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray data, jboolean resume_read) {
5747         LDKSocketDescriptor* this_arg_conv = (LDKSocketDescriptor*)this_arg;
5748         LDKu8slice data_ref;
5749         data_ref.datalen = (*_env)->GetArrayLength (_env, data);
5750         data_ref.data = (*_env)->GetByteArrayElements (_env, data, NULL);
5751         jlong ret_val = (this_arg_conv->send_data)(this_arg_conv->this_arg, data_ref, resume_read);
5752         (*_env)->ReleaseByteArrayElements(_env, data, (int8_t*)data_ref.data, 0);
5753         return ret_val;
5754 }
5755
5756 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_SocketDescriptor_1disconnect_1socket(JNIEnv * _env, jclass _b, jlong this_arg) {
5757         LDKSocketDescriptor* this_arg_conv = (LDKSocketDescriptor*)this_arg;
5758         (this_arg_conv->disconnect_socket)(this_arg_conv->this_arg);
5759 }
5760
5761 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_SocketDescriptor_1hash(JNIEnv * _env, jclass _b, jlong this_arg) {
5762         LDKSocketDescriptor* this_arg_conv = (LDKSocketDescriptor*)this_arg;
5763         jlong ret_val = (this_arg_conv->hash)(this_arg_conv->this_arg);
5764         return ret_val;
5765 }
5766
5767 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Transaction_1free(JNIEnv * _env, jclass _b, jbyteArray _res) {
5768         LDKTransaction _res_ref;
5769         _res_ref.datalen = (*_env)->GetArrayLength (_env, _res);
5770         _res_ref.data = MALLOC(_res_ref.datalen, "LDKTransaction Bytes");
5771         (*_env)->GetByteArrayRegion(_env, _res, 0, _res_ref.datalen, _res_ref.data);
5772         _res_ref.data_is_owned = true;
5773         Transaction_free(_res_ref);
5774 }
5775
5776 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_TxOut_1free(JNIEnv * _env, jclass _b, jlong _res) {
5777         LDKTxOut _res_conv = *(LDKTxOut*)_res;
5778         FREE((void*)_res);
5779         TxOut_free(_res_conv);
5780 }
5781
5782 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_TxOut_1clone(JNIEnv * _env, jclass _b, jlong orig) {
5783         LDKTxOut* orig_conv = (LDKTxOut*)orig;
5784         LDKTxOut* ret_ref = MALLOC(sizeof(LDKTxOut), "LDKTxOut");
5785         *ret_ref = TxOut_clone(orig_conv);
5786         return (long)ret_ref;
5787 }
5788
5789 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1SpendableOutputDescriptorZ_1free(JNIEnv * _env, jclass _b, jlongArray _res) {
5790         LDKCVec_SpendableOutputDescriptorZ _res_constr;
5791         _res_constr.datalen = (*_env)->GetArrayLength (_env, _res);
5792         if (_res_constr.datalen > 0)
5793                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKSpendableOutputDescriptor), "LDKCVec_SpendableOutputDescriptorZ Elements");
5794         else
5795                 _res_constr.data = NULL;
5796         long* _res_vals = (*_env)->GetLongArrayElements (_env, _res, NULL);
5797         for (size_t b = 0; b < _res_constr.datalen; b++) {
5798                 long arr_conv_27 = _res_vals[b];
5799                 LDKSpendableOutputDescriptor arr_conv_27_conv = *(LDKSpendableOutputDescriptor*)arr_conv_27;
5800                 FREE((void*)arr_conv_27);
5801                 _res_constr.data[b] = arr_conv_27_conv;
5802         }
5803         (*_env)->ReleaseLongArrayElements (_env, _res, _res_vals, 0);
5804         CVec_SpendableOutputDescriptorZ_free(_res_constr);
5805 }
5806
5807 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1MessageSendEventZ_1free(JNIEnv * _env, jclass _b, jlongArray _res) {
5808         LDKCVec_MessageSendEventZ _res_constr;
5809         _res_constr.datalen = (*_env)->GetArrayLength (_env, _res);
5810         if (_res_constr.datalen > 0)
5811                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKMessageSendEvent), "LDKCVec_MessageSendEventZ Elements");
5812         else
5813                 _res_constr.data = NULL;
5814         long* _res_vals = (*_env)->GetLongArrayElements (_env, _res, NULL);
5815         for (size_t s = 0; s < _res_constr.datalen; s++) {
5816                 long arr_conv_18 = _res_vals[s];
5817                 LDKMessageSendEvent arr_conv_18_conv = *(LDKMessageSendEvent*)arr_conv_18;
5818                 FREE((void*)arr_conv_18);
5819                 _res_constr.data[s] = arr_conv_18_conv;
5820         }
5821         (*_env)->ReleaseLongArrayElements (_env, _res, _res_vals, 0);
5822         CVec_MessageSendEventZ_free(_res_constr);
5823 }
5824
5825 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1EventZ_1free(JNIEnv * _env, jclass _b, jlongArray _res) {
5826         LDKCVec_EventZ _res_constr;
5827         _res_constr.datalen = (*_env)->GetArrayLength (_env, _res);
5828         if (_res_constr.datalen > 0)
5829                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKEvent), "LDKCVec_EventZ Elements");
5830         else
5831                 _res_constr.data = NULL;
5832         long* _res_vals = (*_env)->GetLongArrayElements (_env, _res, NULL);
5833         for (size_t h = 0; h < _res_constr.datalen; h++) {
5834                 long arr_conv_7 = _res_vals[h];
5835                 LDKEvent arr_conv_7_conv = *(LDKEvent*)arr_conv_7;
5836                 FREE((void*)arr_conv_7);
5837                 _res_constr.data[h] = arr_conv_7_conv;
5838         }
5839         (*_env)->ReleaseLongArrayElements (_env, _res, _res_vals, 0);
5840         CVec_EventZ_free(_res_constr);
5841 }
5842
5843 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_C2Tuple_1usizeTransactionZ_1free(JNIEnv * _env, jclass _b, jlong _res) {
5844         LDKC2Tuple_usizeTransactionZ _res_conv = *(LDKC2Tuple_usizeTransactionZ*)_res;
5845         FREE((void*)_res);
5846         C2Tuple_usizeTransactionZ_free(_res_conv);
5847 }
5848
5849 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_C2Tuple_1usizeTransactionZ_1new(JNIEnv * _env, jclass _b, jlong a, jbyteArray b) {
5850         LDKTransaction b_ref;
5851         b_ref.datalen = (*_env)->GetArrayLength (_env, b);
5852         b_ref.data = MALLOC(b_ref.datalen, "LDKTransaction Bytes");
5853         (*_env)->GetByteArrayRegion(_env, b, 0, b_ref.datalen, b_ref.data);
5854         b_ref.data_is_owned = true;
5855         LDKC2Tuple_usizeTransactionZ* ret_ref = MALLOC(sizeof(LDKC2Tuple_usizeTransactionZ), "LDKC2Tuple_usizeTransactionZ");
5856         *ret_ref = C2Tuple_usizeTransactionZ_new(a, b_ref);
5857         return (long)ret_ref;
5858 }
5859
5860 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1C2Tuple_1usizeTransactionZZ_1free(JNIEnv * _env, jclass _b, jlongArray _res) {
5861         LDKCVec_C2Tuple_usizeTransactionZZ _res_constr;
5862         _res_constr.datalen = (*_env)->GetArrayLength (_env, _res);
5863         if (_res_constr.datalen > 0)
5864                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKC2Tuple_usizeTransactionZ), "LDKCVec_C2Tuple_usizeTransactionZZ Elements");
5865         else
5866                 _res_constr.data = NULL;
5867         long* _res_vals = (*_env)->GetLongArrayElements (_env, _res, NULL);
5868         for (size_t y = 0; y < _res_constr.datalen; y++) {
5869                 long arr_conv_24 = _res_vals[y];
5870                 LDKC2Tuple_usizeTransactionZ arr_conv_24_conv = *(LDKC2Tuple_usizeTransactionZ*)arr_conv_24;
5871                 FREE((void*)arr_conv_24);
5872                 _res_constr.data[y] = arr_conv_24_conv;
5873         }
5874         (*_env)->ReleaseLongArrayElements (_env, _res, _res_vals, 0);
5875         CVec_C2Tuple_usizeTransactionZZ_free(_res_constr);
5876 }
5877
5878 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1NoneChannelMonitorUpdateErrZ_1ok(JNIEnv * _env, jclass _b) {
5879         LDKCResult_NoneChannelMonitorUpdateErrZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneChannelMonitorUpdateErrZ), "LDKCResult_NoneChannelMonitorUpdateErrZ");
5880         *ret_conv = CResult_NoneChannelMonitorUpdateErrZ_ok();
5881         return (long)ret_conv;
5882 }
5883
5884 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1NoneChannelMonitorUpdateErrZ_1err(JNIEnv * _env, jclass _b, jclass e) {
5885         LDKChannelMonitorUpdateErr e_conv = LDKChannelMonitorUpdateErr_from_java(_env, e);
5886         LDKCResult_NoneChannelMonitorUpdateErrZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneChannelMonitorUpdateErrZ), "LDKCResult_NoneChannelMonitorUpdateErrZ");
5887         *ret_conv = CResult_NoneChannelMonitorUpdateErrZ_err(e_conv);
5888         return (long)ret_conv;
5889 }
5890
5891 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1NoneChannelMonitorUpdateErrZ_1free(JNIEnv * _env, jclass _b, jlong _res) {
5892         LDKCResult_NoneChannelMonitorUpdateErrZ _res_conv = *(LDKCResult_NoneChannelMonitorUpdateErrZ*)_res;
5893         FREE((void*)_res);
5894         CResult_NoneChannelMonitorUpdateErrZ_free(_res_conv);
5895 }
5896
5897 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1MonitorEventZ_1free(JNIEnv * _env, jclass _b, jlongArray _res) {
5898         LDKCVec_MonitorEventZ _res_constr;
5899         _res_constr.datalen = (*_env)->GetArrayLength (_env, _res);
5900         if (_res_constr.datalen > 0)
5901                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKMonitorEvent), "LDKCVec_MonitorEventZ Elements");
5902         else
5903                 _res_constr.data = NULL;
5904         long* _res_vals = (*_env)->GetLongArrayElements (_env, _res, NULL);
5905         for (size_t o = 0; o < _res_constr.datalen; o++) {
5906                 long arr_conv_14 = _res_vals[o];
5907                 LDKMonitorEvent arr_conv_14_conv;
5908                 arr_conv_14_conv.inner = (void*)(arr_conv_14 & (~1));
5909                 arr_conv_14_conv.is_owned = (arr_conv_14 & 1) || (arr_conv_14 == 0);
5910                 _res_constr.data[o] = arr_conv_14_conv;
5911         }
5912         (*_env)->ReleaseLongArrayElements (_env, _res, _res_vals, 0);
5913         CVec_MonitorEventZ_free(_res_constr);
5914 }
5915
5916 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1ChannelMonitorUpdateDecodeErrorZ_1ok(JNIEnv * _env, jclass _b, jlong o) {
5917         LDKChannelMonitorUpdate o_conv;
5918         o_conv.inner = (void*)(o & (~1));
5919         o_conv.is_owned = (o & 1) || (o == 0);
5920         if (o_conv.inner != NULL)
5921                 o_conv = ChannelMonitorUpdate_clone(&o_conv);
5922         LDKCResult_ChannelMonitorUpdateDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ChannelMonitorUpdateDecodeErrorZ), "LDKCResult_ChannelMonitorUpdateDecodeErrorZ");
5923         *ret_conv = CResult_ChannelMonitorUpdateDecodeErrorZ_ok(o_conv);
5924         return (long)ret_conv;
5925 }
5926
5927 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1ChannelMonitorUpdateDecodeErrorZ_1err(JNIEnv * _env, jclass _b, jlong e) {
5928         LDKDecodeError e_conv;
5929         e_conv.inner = (void*)(e & (~1));
5930         e_conv.is_owned = (e & 1) || (e == 0);
5931         // Warning: we may need a move here but can't clone!
5932         LDKCResult_ChannelMonitorUpdateDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ChannelMonitorUpdateDecodeErrorZ), "LDKCResult_ChannelMonitorUpdateDecodeErrorZ");
5933         *ret_conv = CResult_ChannelMonitorUpdateDecodeErrorZ_err(e_conv);
5934         return (long)ret_conv;
5935 }
5936
5937 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1ChannelMonitorUpdateDecodeErrorZ_1free(JNIEnv * _env, jclass _b, jlong _res) {
5938         LDKCResult_ChannelMonitorUpdateDecodeErrorZ _res_conv = *(LDKCResult_ChannelMonitorUpdateDecodeErrorZ*)_res;
5939         FREE((void*)_res);
5940         CResult_ChannelMonitorUpdateDecodeErrorZ_free(_res_conv);
5941 }
5942
5943 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1NoneMonitorUpdateErrorZ_1ok(JNIEnv * _env, jclass _b) {
5944         LDKCResult_NoneMonitorUpdateErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneMonitorUpdateErrorZ), "LDKCResult_NoneMonitorUpdateErrorZ");
5945         *ret_conv = CResult_NoneMonitorUpdateErrorZ_ok();
5946         return (long)ret_conv;
5947 }
5948
5949 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1NoneMonitorUpdateErrorZ_1err(JNIEnv * _env, jclass _b, jlong e) {
5950         LDKMonitorUpdateError e_conv;
5951         e_conv.inner = (void*)(e & (~1));
5952         e_conv.is_owned = (e & 1) || (e == 0);
5953         // Warning: we may need a move here but can't clone!
5954         LDKCResult_NoneMonitorUpdateErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneMonitorUpdateErrorZ), "LDKCResult_NoneMonitorUpdateErrorZ");
5955         *ret_conv = CResult_NoneMonitorUpdateErrorZ_err(e_conv);
5956         return (long)ret_conv;
5957 }
5958
5959 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1NoneMonitorUpdateErrorZ_1free(JNIEnv * _env, jclass _b, jlong _res) {
5960         LDKCResult_NoneMonitorUpdateErrorZ _res_conv = *(LDKCResult_NoneMonitorUpdateErrorZ*)_res;
5961         FREE((void*)_res);
5962         CResult_NoneMonitorUpdateErrorZ_free(_res_conv);
5963 }
5964
5965 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_C2Tuple_1OutPointScriptZ_1free(JNIEnv * _env, jclass _b, jlong _res) {
5966         LDKC2Tuple_OutPointScriptZ _res_conv = *(LDKC2Tuple_OutPointScriptZ*)_res;
5967         FREE((void*)_res);
5968         C2Tuple_OutPointScriptZ_free(_res_conv);
5969 }
5970
5971 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_C2Tuple_1OutPointScriptZ_1new(JNIEnv * _env, jclass _b, jlong a, jbyteArray b) {
5972         LDKOutPoint a_conv;
5973         a_conv.inner = (void*)(a & (~1));
5974         a_conv.is_owned = (a & 1) || (a == 0);
5975         if (a_conv.inner != NULL)
5976                 a_conv = OutPoint_clone(&a_conv);
5977         LDKCVec_u8Z b_ref;
5978         b_ref.datalen = (*_env)->GetArrayLength (_env, b);
5979         b_ref.data = MALLOC(b_ref.datalen, "LDKCVec_u8Z Bytes");
5980         (*_env)->GetByteArrayRegion(_env, b, 0, b_ref.datalen, b_ref.data);
5981         LDKC2Tuple_OutPointScriptZ* ret_ref = MALLOC(sizeof(LDKC2Tuple_OutPointScriptZ), "LDKC2Tuple_OutPointScriptZ");
5982         *ret_ref = C2Tuple_OutPointScriptZ_new(a_conv, b_ref);
5983         return (long)ret_ref;
5984 }
5985
5986 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1TransactionZ_1free(JNIEnv * _env, jclass _b, jobjectArray _res) {
5987         LDKCVec_TransactionZ _res_constr;
5988         _res_constr.datalen = (*_env)->GetArrayLength (_env, _res);
5989         if (_res_constr.datalen > 0)
5990                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKTransaction), "LDKCVec_TransactionZ Elements");
5991         else
5992                 _res_constr.data = NULL;
5993         for (size_t i = 0; i < _res_constr.datalen; i++) {
5994                 jobject arr_conv_8 = (*_env)->GetObjectArrayElement(_env, _res, i);
5995                 LDKTransaction arr_conv_8_ref;
5996                 arr_conv_8_ref.datalen = (*_env)->GetArrayLength (_env, arr_conv_8);
5997                 arr_conv_8_ref.data = MALLOC(arr_conv_8_ref.datalen, "LDKTransaction Bytes");
5998                 (*_env)->GetByteArrayRegion(_env, arr_conv_8, 0, arr_conv_8_ref.datalen, arr_conv_8_ref.data);
5999                 arr_conv_8_ref.data_is_owned = true;
6000                 _res_constr.data[i] = arr_conv_8_ref;
6001         }
6002         CVec_TransactionZ_free(_res_constr);
6003 }
6004
6005 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_C2Tuple_1u32TxOutZ_1free(JNIEnv * _env, jclass _b, jlong _res) {
6006         LDKC2Tuple_u32TxOutZ _res_conv = *(LDKC2Tuple_u32TxOutZ*)_res;
6007         FREE((void*)_res);
6008         C2Tuple_u32TxOutZ_free(_res_conv);
6009 }
6010
6011 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_C2Tuple_1u32TxOutZ_1new(JNIEnv * _env, jclass _b, jint a, jlong b) {
6012         LDKTxOut b_conv = *(LDKTxOut*)b;
6013         FREE((void*)b);
6014         LDKC2Tuple_u32TxOutZ* ret_ref = MALLOC(sizeof(LDKC2Tuple_u32TxOutZ), "LDKC2Tuple_u32TxOutZ");
6015         *ret_ref = C2Tuple_u32TxOutZ_new(a, b_conv);
6016         return (long)ret_ref;
6017 }
6018
6019 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1C2Tuple_1u32TxOutZZ_1free(JNIEnv * _env, jclass _b, jlongArray _res) {
6020         LDKCVec_C2Tuple_u32TxOutZZ _res_constr;
6021         _res_constr.datalen = (*_env)->GetArrayLength (_env, _res);
6022         if (_res_constr.datalen > 0)
6023                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKC2Tuple_u32TxOutZ), "LDKCVec_C2Tuple_u32TxOutZZ Elements");
6024         else
6025                 _res_constr.data = NULL;
6026         long* _res_vals = (*_env)->GetLongArrayElements (_env, _res, NULL);
6027         for (size_t a = 0; a < _res_constr.datalen; a++) {
6028                 long arr_conv_26 = _res_vals[a];
6029                 LDKC2Tuple_u32TxOutZ arr_conv_26_conv = *(LDKC2Tuple_u32TxOutZ*)arr_conv_26;
6030                 FREE((void*)arr_conv_26);
6031                 _res_constr.data[a] = arr_conv_26_conv;
6032         }
6033         (*_env)->ReleaseLongArrayElements (_env, _res, _res_vals, 0);
6034         CVec_C2Tuple_u32TxOutZZ_free(_res_constr);
6035 }
6036
6037 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_C2Tuple_1TxidCVec_1C2Tuple_1u32TxOutZZZ_1free(JNIEnv * _env, jclass _b, jlong _res) {
6038         LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ _res_conv = *(LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ*)_res;
6039         FREE((void*)_res);
6040         C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ_free(_res_conv);
6041 }
6042
6043 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_C2Tuple_1TxidCVec_1C2Tuple_1u32TxOutZZZ_1new(JNIEnv * _env, jclass _b, jbyteArray a, jlongArray b) {
6044         LDKThirtyTwoBytes a_ref;
6045         CHECK((*_env)->GetArrayLength (_env, a) == 32);
6046         (*_env)->GetByteArrayRegion (_env, a, 0, 32, a_ref.data);
6047         LDKCVec_C2Tuple_u32TxOutZZ b_constr;
6048         b_constr.datalen = (*_env)->GetArrayLength (_env, b);
6049         if (b_constr.datalen > 0)
6050                 b_constr.data = MALLOC(b_constr.datalen * sizeof(LDKC2Tuple_u32TxOutZ), "LDKCVec_C2Tuple_u32TxOutZZ Elements");
6051         else
6052                 b_constr.data = NULL;
6053         long* b_vals = (*_env)->GetLongArrayElements (_env, b, NULL);
6054         for (size_t a = 0; a < b_constr.datalen; a++) {
6055                 long arr_conv_26 = b_vals[a];
6056                 LDKC2Tuple_u32TxOutZ arr_conv_26_conv = *(LDKC2Tuple_u32TxOutZ*)arr_conv_26;
6057                 FREE((void*)arr_conv_26);
6058                 b_constr.data[a] = arr_conv_26_conv;
6059         }
6060         (*_env)->ReleaseLongArrayElements (_env, b, b_vals, 0);
6061         LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ* ret_ref = MALLOC(sizeof(LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ), "LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ");
6062         *ret_ref = C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ_new(a_ref, b_constr);
6063         return (long)ret_ref;
6064 }
6065
6066 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1C2Tuple_1TxidCVec_1C2Tuple_1u32TxOutZZZZ_1free(JNIEnv * _env, jclass _b, jlongArray _res) {
6067         LDKCVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ _res_constr;
6068         _res_constr.datalen = (*_env)->GetArrayLength (_env, _res);
6069         if (_res_constr.datalen > 0)
6070                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ), "LDKCVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ Elements");
6071         else
6072                 _res_constr.data = NULL;
6073         long* _res_vals = (*_env)->GetLongArrayElements (_env, _res, NULL);
6074         for (size_t u = 0; u < _res_constr.datalen; u++) {
6075                 long arr_conv_46 = _res_vals[u];
6076                 LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ arr_conv_46_conv = *(LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ*)arr_conv_46;
6077                 FREE((void*)arr_conv_46);
6078                 _res_constr.data[u] = arr_conv_46_conv;
6079         }
6080         (*_env)->ReleaseLongArrayElements (_env, _res, _res_vals, 0);
6081         CVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ_free(_res_constr);
6082 }
6083
6084 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_C2Tuple_1BlockHashChannelMonitorZ_1free(JNIEnv * _env, jclass _b, jlong _res) {
6085         LDKC2Tuple_BlockHashChannelMonitorZ _res_conv = *(LDKC2Tuple_BlockHashChannelMonitorZ*)_res;
6086         FREE((void*)_res);
6087         C2Tuple_BlockHashChannelMonitorZ_free(_res_conv);
6088 }
6089
6090 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_C2Tuple_1BlockHashChannelMonitorZ_1new(JNIEnv * _env, jclass _b, jbyteArray a, jlong b) {
6091         LDKThirtyTwoBytes a_ref;
6092         CHECK((*_env)->GetArrayLength (_env, a) == 32);
6093         (*_env)->GetByteArrayRegion (_env, a, 0, 32, a_ref.data);
6094         LDKChannelMonitor b_conv;
6095         b_conv.inner = (void*)(b & (~1));
6096         b_conv.is_owned = (b & 1) || (b == 0);
6097         // Warning: we may need a move here but can't clone!
6098         LDKC2Tuple_BlockHashChannelMonitorZ* ret_ref = MALLOC(sizeof(LDKC2Tuple_BlockHashChannelMonitorZ), "LDKC2Tuple_BlockHashChannelMonitorZ");
6099         *ret_ref = C2Tuple_BlockHashChannelMonitorZ_new(a_ref, b_conv);
6100         return (long)ret_ref;
6101 }
6102
6103 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1C2Tuple_1BlockHashChannelMonitorZDecodeErrorZ_1ok(JNIEnv * _env, jclass _b, jlong o) {
6104         LDKC2Tuple_BlockHashChannelMonitorZ o_conv = *(LDKC2Tuple_BlockHashChannelMonitorZ*)o;
6105         FREE((void*)o);
6106         LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ), "LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ");
6107         *ret_conv = CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ_ok(o_conv);
6108         return (long)ret_conv;
6109 }
6110
6111 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1C2Tuple_1BlockHashChannelMonitorZDecodeErrorZ_1err(JNIEnv * _env, jclass _b, jlong e) {
6112         LDKDecodeError e_conv;
6113         e_conv.inner = (void*)(e & (~1));
6114         e_conv.is_owned = (e & 1) || (e == 0);
6115         // Warning: we may need a move here but can't clone!
6116         LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ), "LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ");
6117         *ret_conv = CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ_err(e_conv);
6118         return (long)ret_conv;
6119 }
6120
6121 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1C2Tuple_1BlockHashChannelMonitorZDecodeErrorZ_1free(JNIEnv * _env, jclass _b, jlong _res) {
6122         LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ _res_conv = *(LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ*)_res;
6123         FREE((void*)_res);
6124         CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ_free(_res_conv);
6125 }
6126
6127 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_C2Tuple_1u64u64Z_1free(JNIEnv * _env, jclass _b, jlong _res) {
6128         LDKC2Tuple_u64u64Z _res_conv = *(LDKC2Tuple_u64u64Z*)_res;
6129         FREE((void*)_res);
6130         C2Tuple_u64u64Z_free(_res_conv);
6131 }
6132
6133 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_C2Tuple_1u64u64Z_1new(JNIEnv * _env, jclass _b, jlong a, jlong b) {
6134         LDKC2Tuple_u64u64Z* ret_ref = MALLOC(sizeof(LDKC2Tuple_u64u64Z), "LDKC2Tuple_u64u64Z");
6135         *ret_ref = C2Tuple_u64u64Z_new(a, b);
6136         return (long)ret_ref;
6137 }
6138
6139 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1SpendableOutputDescriptorDecodeErrorZ_1ok(JNIEnv * _env, jclass _b, jlong o) {
6140         LDKSpendableOutputDescriptor o_conv = *(LDKSpendableOutputDescriptor*)o;
6141         FREE((void*)o);
6142         LDKCResult_SpendableOutputDescriptorDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_SpendableOutputDescriptorDecodeErrorZ), "LDKCResult_SpendableOutputDescriptorDecodeErrorZ");
6143         *ret_conv = CResult_SpendableOutputDescriptorDecodeErrorZ_ok(o_conv);
6144         return (long)ret_conv;
6145 }
6146
6147 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1SpendableOutputDescriptorDecodeErrorZ_1err(JNIEnv * _env, jclass _b, jlong e) {
6148         LDKDecodeError e_conv;
6149         e_conv.inner = (void*)(e & (~1));
6150         e_conv.is_owned = (e & 1) || (e == 0);
6151         // Warning: we may need a move here but can't clone!
6152         LDKCResult_SpendableOutputDescriptorDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_SpendableOutputDescriptorDecodeErrorZ), "LDKCResult_SpendableOutputDescriptorDecodeErrorZ");
6153         *ret_conv = CResult_SpendableOutputDescriptorDecodeErrorZ_err(e_conv);
6154         return (long)ret_conv;
6155 }
6156
6157 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1SpendableOutputDescriptorDecodeErrorZ_1free(JNIEnv * _env, jclass _b, jlong _res) {
6158         LDKCResult_SpendableOutputDescriptorDecodeErrorZ _res_conv = *(LDKCResult_SpendableOutputDescriptorDecodeErrorZ*)_res;
6159         FREE((void*)_res);
6160         CResult_SpendableOutputDescriptorDecodeErrorZ_free(_res_conv);
6161 }
6162
6163 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1SignatureZ_1free(JNIEnv * _env, jclass _b, jobjectArray _res) {
6164         LDKCVec_SignatureZ _res_constr;
6165         _res_constr.datalen = (*_env)->GetArrayLength (_env, _res);
6166         if (_res_constr.datalen > 0)
6167                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKSignature), "LDKCVec_SignatureZ Elements");
6168         else
6169                 _res_constr.data = NULL;
6170         for (size_t i = 0; i < _res_constr.datalen; i++) {
6171                 jobject arr_conv_8 = (*_env)->GetObjectArrayElement(_env, _res, i);
6172                 LDKSignature arr_conv_8_ref;
6173                 CHECK((*_env)->GetArrayLength (_env, arr_conv_8) == 64);
6174                 (*_env)->GetByteArrayRegion (_env, arr_conv_8, 0, 64, arr_conv_8_ref.compact_form);
6175                 _res_constr.data[i] = arr_conv_8_ref;
6176         }
6177         CVec_SignatureZ_free(_res_constr);
6178 }
6179
6180 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_C2Tuple_1SignatureCVec_1SignatureZZ_1free(JNIEnv * _env, jclass _b, jlong _res) {
6181         LDKC2Tuple_SignatureCVec_SignatureZZ _res_conv = *(LDKC2Tuple_SignatureCVec_SignatureZZ*)_res;
6182         FREE((void*)_res);
6183         C2Tuple_SignatureCVec_SignatureZZ_free(_res_conv);
6184 }
6185
6186 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_C2Tuple_1SignatureCVec_1SignatureZZ_1new(JNIEnv * _env, jclass _b, jbyteArray a, jobjectArray b) {
6187         LDKSignature a_ref;
6188         CHECK((*_env)->GetArrayLength (_env, a) == 64);
6189         (*_env)->GetByteArrayRegion (_env, a, 0, 64, a_ref.compact_form);
6190         LDKCVec_SignatureZ b_constr;
6191         b_constr.datalen = (*_env)->GetArrayLength (_env, b);
6192         if (b_constr.datalen > 0)
6193                 b_constr.data = MALLOC(b_constr.datalen * sizeof(LDKSignature), "LDKCVec_SignatureZ Elements");
6194         else
6195                 b_constr.data = NULL;
6196         for (size_t i = 0; i < b_constr.datalen; i++) {
6197                 jobject arr_conv_8 = (*_env)->GetObjectArrayElement(_env, b, i);
6198                 LDKSignature arr_conv_8_ref;
6199                 CHECK((*_env)->GetArrayLength (_env, arr_conv_8) == 64);
6200                 (*_env)->GetByteArrayRegion (_env, arr_conv_8, 0, 64, arr_conv_8_ref.compact_form);
6201                 b_constr.data[i] = arr_conv_8_ref;
6202         }
6203         LDKC2Tuple_SignatureCVec_SignatureZZ* ret_ref = MALLOC(sizeof(LDKC2Tuple_SignatureCVec_SignatureZZ), "LDKC2Tuple_SignatureCVec_SignatureZZ");
6204         *ret_ref = C2Tuple_SignatureCVec_SignatureZZ_new(a_ref, b_constr);
6205         return (long)ret_ref;
6206 }
6207
6208 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1C2Tuple_1SignatureCVec_1SignatureZZNoneZ_1ok(JNIEnv * _env, jclass _b, jlong o) {
6209         LDKC2Tuple_SignatureCVec_SignatureZZ o_conv = *(LDKC2Tuple_SignatureCVec_SignatureZZ*)o;
6210         FREE((void*)o);
6211         LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ), "LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ");
6212         *ret_conv = CResult_C2Tuple_SignatureCVec_SignatureZZNoneZ_ok(o_conv);
6213         return (long)ret_conv;
6214 }
6215
6216 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1C2Tuple_1SignatureCVec_1SignatureZZNoneZ_1err(JNIEnv * _env, jclass _b) {
6217         LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ), "LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ");
6218         *ret_conv = CResult_C2Tuple_SignatureCVec_SignatureZZNoneZ_err();
6219         return (long)ret_conv;
6220 }
6221
6222 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1C2Tuple_1SignatureCVec_1SignatureZZNoneZ_1free(JNIEnv * _env, jclass _b, jlong _res) {
6223         LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ _res_conv = *(LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ*)_res;
6224         FREE((void*)_res);
6225         CResult_C2Tuple_SignatureCVec_SignatureZZNoneZ_free(_res_conv);
6226 }
6227
6228 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1SignatureNoneZ_1ok(JNIEnv * _env, jclass _b, jbyteArray o) {
6229         LDKSignature o_ref;
6230         CHECK((*_env)->GetArrayLength (_env, o) == 64);
6231         (*_env)->GetByteArrayRegion (_env, o, 0, 64, o_ref.compact_form);
6232         LDKCResult_SignatureNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_SignatureNoneZ), "LDKCResult_SignatureNoneZ");
6233         *ret_conv = CResult_SignatureNoneZ_ok(o_ref);
6234         return (long)ret_conv;
6235 }
6236
6237 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1SignatureNoneZ_1err(JNIEnv * _env, jclass _b) {
6238         LDKCResult_SignatureNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_SignatureNoneZ), "LDKCResult_SignatureNoneZ");
6239         *ret_conv = CResult_SignatureNoneZ_err();
6240         return (long)ret_conv;
6241 }
6242
6243 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1SignatureNoneZ_1free(JNIEnv * _env, jclass _b, jlong _res) {
6244         LDKCResult_SignatureNoneZ _res_conv = *(LDKCResult_SignatureNoneZ*)_res;
6245         FREE((void*)_res);
6246         CResult_SignatureNoneZ_free(_res_conv);
6247 }
6248
6249 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1CVec_1SignatureZNoneZ_1ok(JNIEnv * _env, jclass _b, jobjectArray o) {
6250         LDKCVec_SignatureZ o_constr;
6251         o_constr.datalen = (*_env)->GetArrayLength (_env, o);
6252         if (o_constr.datalen > 0)
6253                 o_constr.data = MALLOC(o_constr.datalen * sizeof(LDKSignature), "LDKCVec_SignatureZ Elements");
6254         else
6255                 o_constr.data = NULL;
6256         for (size_t i = 0; i < o_constr.datalen; i++) {
6257                 jobject arr_conv_8 = (*_env)->GetObjectArrayElement(_env, o, i);
6258                 LDKSignature arr_conv_8_ref;
6259                 CHECK((*_env)->GetArrayLength (_env, arr_conv_8) == 64);
6260                 (*_env)->GetByteArrayRegion (_env, arr_conv_8, 0, 64, arr_conv_8_ref.compact_form);
6261                 o_constr.data[i] = arr_conv_8_ref;
6262         }
6263         LDKCResult_CVec_SignatureZNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_CVec_SignatureZNoneZ), "LDKCResult_CVec_SignatureZNoneZ");
6264         *ret_conv = CResult_CVec_SignatureZNoneZ_ok(o_constr);
6265         return (long)ret_conv;
6266 }
6267
6268 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1CVec_1SignatureZNoneZ_1err(JNIEnv * _env, jclass _b) {
6269         LDKCResult_CVec_SignatureZNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_CVec_SignatureZNoneZ), "LDKCResult_CVec_SignatureZNoneZ");
6270         *ret_conv = CResult_CVec_SignatureZNoneZ_err();
6271         return (long)ret_conv;
6272 }
6273
6274 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1CVec_1SignatureZNoneZ_1free(JNIEnv * _env, jclass _b, jlong _res) {
6275         LDKCResult_CVec_SignatureZNoneZ _res_conv = *(LDKCResult_CVec_SignatureZNoneZ*)_res;
6276         FREE((void*)_res);
6277         CResult_CVec_SignatureZNoneZ_free(_res_conv);
6278 }
6279
6280 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1ChanKeySignerDecodeErrorZ_1ok(JNIEnv * _env, jclass _b, jlong o) {
6281         LDKChannelKeys o_conv = *(LDKChannelKeys*)o;
6282         if (o_conv.free == LDKChannelKeys_JCalls_free) {
6283                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
6284                 LDKChannelKeys_JCalls_clone(o_conv.this_arg);
6285         }
6286         LDKCResult_ChanKeySignerDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ChanKeySignerDecodeErrorZ), "LDKCResult_ChanKeySignerDecodeErrorZ");
6287         *ret_conv = CResult_ChanKeySignerDecodeErrorZ_ok(o_conv);
6288         return (long)ret_conv;
6289 }
6290
6291 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1ChanKeySignerDecodeErrorZ_1err(JNIEnv * _env, jclass _b, jlong e) {
6292         LDKDecodeError e_conv;
6293         e_conv.inner = (void*)(e & (~1));
6294         e_conv.is_owned = (e & 1) || (e == 0);
6295         // Warning: we may need a move here but can't clone!
6296         LDKCResult_ChanKeySignerDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ChanKeySignerDecodeErrorZ), "LDKCResult_ChanKeySignerDecodeErrorZ");
6297         *ret_conv = CResult_ChanKeySignerDecodeErrorZ_err(e_conv);
6298         return (long)ret_conv;
6299 }
6300
6301 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1ChanKeySignerDecodeErrorZ_1free(JNIEnv * _env, jclass _b, jlong _res) {
6302         LDKCResult_ChanKeySignerDecodeErrorZ _res_conv = *(LDKCResult_ChanKeySignerDecodeErrorZ*)_res;
6303         FREE((void*)_res);
6304         CResult_ChanKeySignerDecodeErrorZ_free(_res_conv);
6305 }
6306
6307 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1InMemoryChannelKeysDecodeErrorZ_1ok(JNIEnv * _env, jclass _b, jlong o) {
6308         LDKInMemoryChannelKeys o_conv;
6309         o_conv.inner = (void*)(o & (~1));
6310         o_conv.is_owned = (o & 1) || (o == 0);
6311         if (o_conv.inner != NULL)
6312                 o_conv = InMemoryChannelKeys_clone(&o_conv);
6313         LDKCResult_InMemoryChannelKeysDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_InMemoryChannelKeysDecodeErrorZ), "LDKCResult_InMemoryChannelKeysDecodeErrorZ");
6314         *ret_conv = CResult_InMemoryChannelKeysDecodeErrorZ_ok(o_conv);
6315         return (long)ret_conv;
6316 }
6317
6318 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1InMemoryChannelKeysDecodeErrorZ_1err(JNIEnv * _env, jclass _b, jlong e) {
6319         LDKDecodeError e_conv;
6320         e_conv.inner = (void*)(e & (~1));
6321         e_conv.is_owned = (e & 1) || (e == 0);
6322         // Warning: we may need a move here but can't clone!
6323         LDKCResult_InMemoryChannelKeysDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_InMemoryChannelKeysDecodeErrorZ), "LDKCResult_InMemoryChannelKeysDecodeErrorZ");
6324         *ret_conv = CResult_InMemoryChannelKeysDecodeErrorZ_err(e_conv);
6325         return (long)ret_conv;
6326 }
6327
6328 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1InMemoryChannelKeysDecodeErrorZ_1free(JNIEnv * _env, jclass _b, jlong _res) {
6329         LDKCResult_InMemoryChannelKeysDecodeErrorZ _res_conv = *(LDKCResult_InMemoryChannelKeysDecodeErrorZ*)_res;
6330         FREE((void*)_res);
6331         CResult_InMemoryChannelKeysDecodeErrorZ_free(_res_conv);
6332 }
6333
6334 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1TxOutAccessErrorZ_1ok(JNIEnv * _env, jclass _b, jlong o) {
6335         LDKTxOut o_conv = *(LDKTxOut*)o;
6336         FREE((void*)o);
6337         LDKCResult_TxOutAccessErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_TxOutAccessErrorZ), "LDKCResult_TxOutAccessErrorZ");
6338         *ret_conv = CResult_TxOutAccessErrorZ_ok(o_conv);
6339         return (long)ret_conv;
6340 }
6341
6342 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1TxOutAccessErrorZ_1err(JNIEnv * _env, jclass _b, jclass e) {
6343         LDKAccessError e_conv = LDKAccessError_from_java(_env, e);
6344         LDKCResult_TxOutAccessErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_TxOutAccessErrorZ), "LDKCResult_TxOutAccessErrorZ");
6345         *ret_conv = CResult_TxOutAccessErrorZ_err(e_conv);
6346         return (long)ret_conv;
6347 }
6348
6349 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1TxOutAccessErrorZ_1free(JNIEnv * _env, jclass _b, jlong _res) {
6350         LDKCResult_TxOutAccessErrorZ _res_conv = *(LDKCResult_TxOutAccessErrorZ*)_res;
6351         FREE((void*)_res);
6352         CResult_TxOutAccessErrorZ_free(_res_conv);
6353 }
6354
6355 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1NoneAPIErrorZ_1ok(JNIEnv * _env, jclass _b) {
6356         LDKCResult_NoneAPIErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneAPIErrorZ), "LDKCResult_NoneAPIErrorZ");
6357         *ret_conv = CResult_NoneAPIErrorZ_ok();
6358         return (long)ret_conv;
6359 }
6360
6361 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1NoneAPIErrorZ_1err(JNIEnv * _env, jclass _b, jlong e) {
6362         LDKAPIError e_conv = *(LDKAPIError*)e;
6363         FREE((void*)e);
6364         LDKCResult_NoneAPIErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneAPIErrorZ), "LDKCResult_NoneAPIErrorZ");
6365         *ret_conv = CResult_NoneAPIErrorZ_err(e_conv);
6366         return (long)ret_conv;
6367 }
6368
6369 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1NoneAPIErrorZ_1free(JNIEnv * _env, jclass _b, jlong _res) {
6370         LDKCResult_NoneAPIErrorZ _res_conv = *(LDKCResult_NoneAPIErrorZ*)_res;
6371         FREE((void*)_res);
6372         CResult_NoneAPIErrorZ_free(_res_conv);
6373 }
6374
6375 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1ChannelDetailsZ_1free(JNIEnv * _env, jclass _b, jlongArray _res) {
6376         LDKCVec_ChannelDetailsZ _res_constr;
6377         _res_constr.datalen = (*_env)->GetArrayLength (_env, _res);
6378         if (_res_constr.datalen > 0)
6379                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKChannelDetails), "LDKCVec_ChannelDetailsZ Elements");
6380         else
6381                 _res_constr.data = NULL;
6382         long* _res_vals = (*_env)->GetLongArrayElements (_env, _res, NULL);
6383         for (size_t q = 0; q < _res_constr.datalen; q++) {
6384                 long arr_conv_16 = _res_vals[q];
6385                 LDKChannelDetails arr_conv_16_conv;
6386                 arr_conv_16_conv.inner = (void*)(arr_conv_16 & (~1));
6387                 arr_conv_16_conv.is_owned = (arr_conv_16 & 1) || (arr_conv_16 == 0);
6388                 _res_constr.data[q] = arr_conv_16_conv;
6389         }
6390         (*_env)->ReleaseLongArrayElements (_env, _res, _res_vals, 0);
6391         CVec_ChannelDetailsZ_free(_res_constr);
6392 }
6393
6394 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1NonePaymentSendFailureZ_1ok(JNIEnv * _env, jclass _b) {
6395         LDKCResult_NonePaymentSendFailureZ* ret_conv = MALLOC(sizeof(LDKCResult_NonePaymentSendFailureZ), "LDKCResult_NonePaymentSendFailureZ");
6396         *ret_conv = CResult_NonePaymentSendFailureZ_ok();
6397         return (long)ret_conv;
6398 }
6399
6400 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1NonePaymentSendFailureZ_1err(JNIEnv * _env, jclass _b, jlong e) {
6401         LDKPaymentSendFailure e_conv;
6402         e_conv.inner = (void*)(e & (~1));
6403         e_conv.is_owned = (e & 1) || (e == 0);
6404         // Warning: we may need a move here but can't clone!
6405         LDKCResult_NonePaymentSendFailureZ* ret_conv = MALLOC(sizeof(LDKCResult_NonePaymentSendFailureZ), "LDKCResult_NonePaymentSendFailureZ");
6406         *ret_conv = CResult_NonePaymentSendFailureZ_err(e_conv);
6407         return (long)ret_conv;
6408 }
6409
6410 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1NonePaymentSendFailureZ_1free(JNIEnv * _env, jclass _b, jlong _res) {
6411         LDKCResult_NonePaymentSendFailureZ _res_conv = *(LDKCResult_NonePaymentSendFailureZ*)_res;
6412         FREE((void*)_res);
6413         CResult_NonePaymentSendFailureZ_free(_res_conv);
6414 }
6415
6416 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1NetAddressZ_1free(JNIEnv * _env, jclass _b, jlongArray _res) {
6417         LDKCVec_NetAddressZ _res_constr;
6418         _res_constr.datalen = (*_env)->GetArrayLength (_env, _res);
6419         if (_res_constr.datalen > 0)
6420                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKNetAddress), "LDKCVec_NetAddressZ Elements");
6421         else
6422                 _res_constr.data = NULL;
6423         long* _res_vals = (*_env)->GetLongArrayElements (_env, _res, NULL);
6424         for (size_t m = 0; m < _res_constr.datalen; m++) {
6425                 long arr_conv_12 = _res_vals[m];
6426                 LDKNetAddress arr_conv_12_conv = *(LDKNetAddress*)arr_conv_12;
6427                 FREE((void*)arr_conv_12);
6428                 _res_constr.data[m] = arr_conv_12_conv;
6429         }
6430         (*_env)->ReleaseLongArrayElements (_env, _res, _res_vals, 0);
6431         CVec_NetAddressZ_free(_res_constr);
6432 }
6433
6434 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1ChannelMonitorZ_1free(JNIEnv * _env, jclass _b, jlongArray _res) {
6435         LDKCVec_ChannelMonitorZ _res_constr;
6436         _res_constr.datalen = (*_env)->GetArrayLength (_env, _res);
6437         if (_res_constr.datalen > 0)
6438                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKChannelMonitor), "LDKCVec_ChannelMonitorZ Elements");
6439         else
6440                 _res_constr.data = NULL;
6441         long* _res_vals = (*_env)->GetLongArrayElements (_env, _res, NULL);
6442         for (size_t q = 0; q < _res_constr.datalen; q++) {
6443                 long arr_conv_16 = _res_vals[q];
6444                 LDKChannelMonitor arr_conv_16_conv;
6445                 arr_conv_16_conv.inner = (void*)(arr_conv_16 & (~1));
6446                 arr_conv_16_conv.is_owned = (arr_conv_16 & 1) || (arr_conv_16 == 0);
6447                 _res_constr.data[q] = arr_conv_16_conv;
6448         }
6449         (*_env)->ReleaseLongArrayElements (_env, _res, _res_vals, 0);
6450         CVec_ChannelMonitorZ_free(_res_constr);
6451 }
6452
6453 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_C2Tuple_1BlockHashChannelManagerZ_1free(JNIEnv * _env, jclass _b, jlong _res) {
6454         LDKC2Tuple_BlockHashChannelManagerZ _res_conv = *(LDKC2Tuple_BlockHashChannelManagerZ*)_res;
6455         FREE((void*)_res);
6456         C2Tuple_BlockHashChannelManagerZ_free(_res_conv);
6457 }
6458
6459 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_C2Tuple_1BlockHashChannelManagerZ_1new(JNIEnv * _env, jclass _b, jbyteArray a, jlong b) {
6460         LDKThirtyTwoBytes a_ref;
6461         CHECK((*_env)->GetArrayLength (_env, a) == 32);
6462         (*_env)->GetByteArrayRegion (_env, a, 0, 32, a_ref.data);
6463         LDKChannelManager b_conv;
6464         b_conv.inner = (void*)(b & (~1));
6465         b_conv.is_owned = (b & 1) || (b == 0);
6466         // Warning: we may need a move here but can't clone!
6467         LDKC2Tuple_BlockHashChannelManagerZ* ret_ref = MALLOC(sizeof(LDKC2Tuple_BlockHashChannelManagerZ), "LDKC2Tuple_BlockHashChannelManagerZ");
6468         *ret_ref = C2Tuple_BlockHashChannelManagerZ_new(a_ref, b_conv);
6469         return (long)ret_ref;
6470 }
6471
6472 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1C2Tuple_1BlockHashChannelManagerZDecodeErrorZ_1ok(JNIEnv * _env, jclass _b, jlong o) {
6473         LDKC2Tuple_BlockHashChannelManagerZ o_conv = *(LDKC2Tuple_BlockHashChannelManagerZ*)o;
6474         FREE((void*)o);
6475         LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ), "LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ");
6476         *ret_conv = CResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ_ok(o_conv);
6477         return (long)ret_conv;
6478 }
6479
6480 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1C2Tuple_1BlockHashChannelManagerZDecodeErrorZ_1err(JNIEnv * _env, jclass _b, jlong e) {
6481         LDKDecodeError e_conv;
6482         e_conv.inner = (void*)(e & (~1));
6483         e_conv.is_owned = (e & 1) || (e == 0);
6484         // Warning: we may need a move here but can't clone!
6485         LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ), "LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ");
6486         *ret_conv = CResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ_err(e_conv);
6487         return (long)ret_conv;
6488 }
6489
6490 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1C2Tuple_1BlockHashChannelManagerZDecodeErrorZ_1free(JNIEnv * _env, jclass _b, jlong _res) {
6491         LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ _res_conv = *(LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ*)_res;
6492         FREE((void*)_res);
6493         CResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ_free(_res_conv);
6494 }
6495
6496 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1NetAddressu8Z_1ok(JNIEnv * _env, jclass _b, jlong o) {
6497         LDKNetAddress o_conv = *(LDKNetAddress*)o;
6498         FREE((void*)o);
6499         LDKCResult_NetAddressu8Z* ret_conv = MALLOC(sizeof(LDKCResult_NetAddressu8Z), "LDKCResult_NetAddressu8Z");
6500         *ret_conv = CResult_NetAddressu8Z_ok(o_conv);
6501         return (long)ret_conv;
6502 }
6503
6504 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1NetAddressu8Z_1err(JNIEnv * _env, jclass _b, jbyte e) {
6505         LDKCResult_NetAddressu8Z* ret_conv = MALLOC(sizeof(LDKCResult_NetAddressu8Z), "LDKCResult_NetAddressu8Z");
6506         *ret_conv = CResult_NetAddressu8Z_err(e);
6507         return (long)ret_conv;
6508 }
6509
6510 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1NetAddressu8Z_1free(JNIEnv * _env, jclass _b, jlong _res) {
6511         LDKCResult_NetAddressu8Z _res_conv = *(LDKCResult_NetAddressu8Z*)_res;
6512         FREE((void*)_res);
6513         CResult_NetAddressu8Z_free(_res_conv);
6514 }
6515
6516 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1CResult_1NetAddressu8ZDecodeErrorZ_1ok(JNIEnv * _env, jclass _b, jlong o) {
6517         LDKCResult_NetAddressu8Z o_conv = *(LDKCResult_NetAddressu8Z*)o;
6518         FREE((void*)o);
6519         LDKCResult_CResult_NetAddressu8ZDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_CResult_NetAddressu8ZDecodeErrorZ), "LDKCResult_CResult_NetAddressu8ZDecodeErrorZ");
6520         *ret_conv = CResult_CResult_NetAddressu8ZDecodeErrorZ_ok(o_conv);
6521         return (long)ret_conv;
6522 }
6523
6524 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1CResult_1NetAddressu8ZDecodeErrorZ_1err(JNIEnv * _env, jclass _b, jlong e) {
6525         LDKDecodeError e_conv;
6526         e_conv.inner = (void*)(e & (~1));
6527         e_conv.is_owned = (e & 1) || (e == 0);
6528         // Warning: we may need a move here but can't clone!
6529         LDKCResult_CResult_NetAddressu8ZDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_CResult_NetAddressu8ZDecodeErrorZ), "LDKCResult_CResult_NetAddressu8ZDecodeErrorZ");
6530         *ret_conv = CResult_CResult_NetAddressu8ZDecodeErrorZ_err(e_conv);
6531         return (long)ret_conv;
6532 }
6533
6534 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1CResult_1NetAddressu8ZDecodeErrorZ_1free(JNIEnv * _env, jclass _b, jlong _res) {
6535         LDKCResult_CResult_NetAddressu8ZDecodeErrorZ _res_conv = *(LDKCResult_CResult_NetAddressu8ZDecodeErrorZ*)_res;
6536         FREE((void*)_res);
6537         CResult_CResult_NetAddressu8ZDecodeErrorZ_free(_res_conv);
6538 }
6539
6540 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1u64Z_1free(JNIEnv * _env, jclass _b, jlongArray _res) {
6541         LDKCVec_u64Z _res_constr;
6542         _res_constr.datalen = (*_env)->GetArrayLength (_env, _res);
6543         if (_res_constr.datalen > 0)
6544                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(jlong), "LDKCVec_u64Z Elements");
6545         else
6546                 _res_constr.data = NULL;
6547         long* _res_vals = (*_env)->GetLongArrayElements (_env, _res, NULL);
6548         for (size_t g = 0; g < _res_constr.datalen; g++) {
6549                 long arr_conv_6 = _res_vals[g];
6550                 _res_constr.data[g] = arr_conv_6;
6551         }
6552         (*_env)->ReleaseLongArrayElements (_env, _res, _res_vals, 0);
6553         CVec_u64Z_free(_res_constr);
6554 }
6555
6556 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1UpdateAddHTLCZ_1free(JNIEnv * _env, jclass _b, jlongArray _res) {
6557         LDKCVec_UpdateAddHTLCZ _res_constr;
6558         _res_constr.datalen = (*_env)->GetArrayLength (_env, _res);
6559         if (_res_constr.datalen > 0)
6560                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKUpdateAddHTLC), "LDKCVec_UpdateAddHTLCZ Elements");
6561         else
6562                 _res_constr.data = NULL;
6563         long* _res_vals = (*_env)->GetLongArrayElements (_env, _res, NULL);
6564         for (size_t p = 0; p < _res_constr.datalen; p++) {
6565                 long arr_conv_15 = _res_vals[p];
6566                 LDKUpdateAddHTLC arr_conv_15_conv;
6567                 arr_conv_15_conv.inner = (void*)(arr_conv_15 & (~1));
6568                 arr_conv_15_conv.is_owned = (arr_conv_15 & 1) || (arr_conv_15 == 0);
6569                 _res_constr.data[p] = arr_conv_15_conv;
6570         }
6571         (*_env)->ReleaseLongArrayElements (_env, _res, _res_vals, 0);
6572         CVec_UpdateAddHTLCZ_free(_res_constr);
6573 }
6574
6575 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1UpdateFulfillHTLCZ_1free(JNIEnv * _env, jclass _b, jlongArray _res) {
6576         LDKCVec_UpdateFulfillHTLCZ _res_constr;
6577         _res_constr.datalen = (*_env)->GetArrayLength (_env, _res);
6578         if (_res_constr.datalen > 0)
6579                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKUpdateFulfillHTLC), "LDKCVec_UpdateFulfillHTLCZ Elements");
6580         else
6581                 _res_constr.data = NULL;
6582         long* _res_vals = (*_env)->GetLongArrayElements (_env, _res, NULL);
6583         for (size_t t = 0; t < _res_constr.datalen; t++) {
6584                 long arr_conv_19 = _res_vals[t];
6585                 LDKUpdateFulfillHTLC arr_conv_19_conv;
6586                 arr_conv_19_conv.inner = (void*)(arr_conv_19 & (~1));
6587                 arr_conv_19_conv.is_owned = (arr_conv_19 & 1) || (arr_conv_19 == 0);
6588                 _res_constr.data[t] = arr_conv_19_conv;
6589         }
6590         (*_env)->ReleaseLongArrayElements (_env, _res, _res_vals, 0);
6591         CVec_UpdateFulfillHTLCZ_free(_res_constr);
6592 }
6593
6594 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1UpdateFailHTLCZ_1free(JNIEnv * _env, jclass _b, jlongArray _res) {
6595         LDKCVec_UpdateFailHTLCZ _res_constr;
6596         _res_constr.datalen = (*_env)->GetArrayLength (_env, _res);
6597         if (_res_constr.datalen > 0)
6598                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKUpdateFailHTLC), "LDKCVec_UpdateFailHTLCZ Elements");
6599         else
6600                 _res_constr.data = NULL;
6601         long* _res_vals = (*_env)->GetLongArrayElements (_env, _res, NULL);
6602         for (size_t q = 0; q < _res_constr.datalen; q++) {
6603                 long arr_conv_16 = _res_vals[q];
6604                 LDKUpdateFailHTLC arr_conv_16_conv;
6605                 arr_conv_16_conv.inner = (void*)(arr_conv_16 & (~1));
6606                 arr_conv_16_conv.is_owned = (arr_conv_16 & 1) || (arr_conv_16 == 0);
6607                 _res_constr.data[q] = arr_conv_16_conv;
6608         }
6609         (*_env)->ReleaseLongArrayElements (_env, _res, _res_vals, 0);
6610         CVec_UpdateFailHTLCZ_free(_res_constr);
6611 }
6612
6613 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1UpdateFailMalformedHTLCZ_1free(JNIEnv * _env, jclass _b, jlongArray _res) {
6614         LDKCVec_UpdateFailMalformedHTLCZ _res_constr;
6615         _res_constr.datalen = (*_env)->GetArrayLength (_env, _res);
6616         if (_res_constr.datalen > 0)
6617                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKUpdateFailMalformedHTLC), "LDKCVec_UpdateFailMalformedHTLCZ Elements");
6618         else
6619                 _res_constr.data = NULL;
6620         long* _res_vals = (*_env)->GetLongArrayElements (_env, _res, NULL);
6621         for (size_t z = 0; z < _res_constr.datalen; z++) {
6622                 long arr_conv_25 = _res_vals[z];
6623                 LDKUpdateFailMalformedHTLC arr_conv_25_conv;
6624                 arr_conv_25_conv.inner = (void*)(arr_conv_25 & (~1));
6625                 arr_conv_25_conv.is_owned = (arr_conv_25 & 1) || (arr_conv_25 == 0);
6626                 _res_constr.data[z] = arr_conv_25_conv;
6627         }
6628         (*_env)->ReleaseLongArrayElements (_env, _res, _res_vals, 0);
6629         CVec_UpdateFailMalformedHTLCZ_free(_res_constr);
6630 }
6631
6632 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1boolLightningErrorZ_1ok(JNIEnv * _env, jclass _b, jboolean o) {
6633         LDKCResult_boolLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_boolLightningErrorZ), "LDKCResult_boolLightningErrorZ");
6634         *ret_conv = CResult_boolLightningErrorZ_ok(o);
6635         return (long)ret_conv;
6636 }
6637
6638 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1boolLightningErrorZ_1err(JNIEnv * _env, jclass _b, jlong e) {
6639         LDKLightningError e_conv;
6640         e_conv.inner = (void*)(e & (~1));
6641         e_conv.is_owned = (e & 1) || (e == 0);
6642         // Warning: we may need a move here but can't clone!
6643         LDKCResult_boolLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_boolLightningErrorZ), "LDKCResult_boolLightningErrorZ");
6644         *ret_conv = CResult_boolLightningErrorZ_err(e_conv);
6645         return (long)ret_conv;
6646 }
6647
6648 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1boolLightningErrorZ_1free(JNIEnv * _env, jclass _b, jlong _res) {
6649         LDKCResult_boolLightningErrorZ _res_conv = *(LDKCResult_boolLightningErrorZ*)_res;
6650         FREE((void*)_res);
6651         CResult_boolLightningErrorZ_free(_res_conv);
6652 }
6653
6654 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_C3Tuple_1ChannelAnnouncementChannelUpdateChannelUpdateZ_1free(JNIEnv * _env, jclass _b, jlong _res) {
6655         LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ _res_conv = *(LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ*)_res;
6656         FREE((void*)_res);
6657         C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ_free(_res_conv);
6658 }
6659
6660 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_C3Tuple_1ChannelAnnouncementChannelUpdateChannelUpdateZ_1new(JNIEnv * _env, jclass _b, jlong a, jlong b, jlong c) {
6661         LDKChannelAnnouncement a_conv;
6662         a_conv.inner = (void*)(a & (~1));
6663         a_conv.is_owned = (a & 1) || (a == 0);
6664         if (a_conv.inner != NULL)
6665                 a_conv = ChannelAnnouncement_clone(&a_conv);
6666         LDKChannelUpdate b_conv;
6667         b_conv.inner = (void*)(b & (~1));
6668         b_conv.is_owned = (b & 1) || (b == 0);
6669         if (b_conv.inner != NULL)
6670                 b_conv = ChannelUpdate_clone(&b_conv);
6671         LDKChannelUpdate c_conv;
6672         c_conv.inner = (void*)(c & (~1));
6673         c_conv.is_owned = (c & 1) || (c == 0);
6674         if (c_conv.inner != NULL)
6675                 c_conv = ChannelUpdate_clone(&c_conv);
6676         LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ* ret_ref = MALLOC(sizeof(LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ), "LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ");
6677         *ret_ref = C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ_new(a_conv, b_conv, c_conv);
6678         return (long)ret_ref;
6679 }
6680
6681 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1C3Tuple_1ChannelAnnouncementChannelUpdateChannelUpdateZZ_1free(JNIEnv * _env, jclass _b, jlongArray _res) {
6682         LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ _res_constr;
6683         _res_constr.datalen = (*_env)->GetArrayLength (_env, _res);
6684         if (_res_constr.datalen > 0)
6685                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ), "LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ Elements");
6686         else
6687                 _res_constr.data = NULL;
6688         long* _res_vals = (*_env)->GetLongArrayElements (_env, _res, NULL);
6689         for (size_t l = 0; l < _res_constr.datalen; l++) {
6690                 long arr_conv_63 = _res_vals[l];
6691                 LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ arr_conv_63_conv = *(LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ*)arr_conv_63;
6692                 FREE((void*)arr_conv_63);
6693                 _res_constr.data[l] = arr_conv_63_conv;
6694         }
6695         (*_env)->ReleaseLongArrayElements (_env, _res, _res_vals, 0);
6696         CVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ_free(_res_constr);
6697 }
6698
6699 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1NodeAnnouncementZ_1free(JNIEnv * _env, jclass _b, jlongArray _res) {
6700         LDKCVec_NodeAnnouncementZ _res_constr;
6701         _res_constr.datalen = (*_env)->GetArrayLength (_env, _res);
6702         if (_res_constr.datalen > 0)
6703                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKNodeAnnouncement), "LDKCVec_NodeAnnouncementZ Elements");
6704         else
6705                 _res_constr.data = NULL;
6706         long* _res_vals = (*_env)->GetLongArrayElements (_env, _res, NULL);
6707         for (size_t s = 0; s < _res_constr.datalen; s++) {
6708                 long arr_conv_18 = _res_vals[s];
6709                 LDKNodeAnnouncement arr_conv_18_conv;
6710                 arr_conv_18_conv.inner = (void*)(arr_conv_18 & (~1));
6711                 arr_conv_18_conv.is_owned = (arr_conv_18 & 1) || (arr_conv_18 == 0);
6712                 _res_constr.data[s] = arr_conv_18_conv;
6713         }
6714         (*_env)->ReleaseLongArrayElements (_env, _res, _res_vals, 0);
6715         CVec_NodeAnnouncementZ_free(_res_constr);
6716 }
6717
6718 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1NoneLightningErrorZ_1ok(JNIEnv * _env, jclass _b) {
6719         LDKCResult_NoneLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneLightningErrorZ), "LDKCResult_NoneLightningErrorZ");
6720         *ret_conv = CResult_NoneLightningErrorZ_ok();
6721         return (long)ret_conv;
6722 }
6723
6724 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1NoneLightningErrorZ_1err(JNIEnv * _env, jclass _b, jlong e) {
6725         LDKLightningError e_conv;
6726         e_conv.inner = (void*)(e & (~1));
6727         e_conv.is_owned = (e & 1) || (e == 0);
6728         // Warning: we may need a move here but can't clone!
6729         LDKCResult_NoneLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneLightningErrorZ), "LDKCResult_NoneLightningErrorZ");
6730         *ret_conv = CResult_NoneLightningErrorZ_err(e_conv);
6731         return (long)ret_conv;
6732 }
6733
6734 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1NoneLightningErrorZ_1free(JNIEnv * _env, jclass _b, jlong _res) {
6735         LDKCResult_NoneLightningErrorZ _res_conv = *(LDKCResult_NoneLightningErrorZ*)_res;
6736         FREE((void*)_res);
6737         CResult_NoneLightningErrorZ_free(_res_conv);
6738 }
6739
6740 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1ChannelReestablishDecodeErrorZ_1ok(JNIEnv * _env, jclass _b, jlong o) {
6741         LDKChannelReestablish o_conv;
6742         o_conv.inner = (void*)(o & (~1));
6743         o_conv.is_owned = (o & 1) || (o == 0);
6744         if (o_conv.inner != NULL)
6745                 o_conv = ChannelReestablish_clone(&o_conv);
6746         LDKCResult_ChannelReestablishDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ChannelReestablishDecodeErrorZ), "LDKCResult_ChannelReestablishDecodeErrorZ");
6747         *ret_conv = CResult_ChannelReestablishDecodeErrorZ_ok(o_conv);
6748         return (long)ret_conv;
6749 }
6750
6751 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1ChannelReestablishDecodeErrorZ_1err(JNIEnv * _env, jclass _b, jlong e) {
6752         LDKDecodeError e_conv;
6753         e_conv.inner = (void*)(e & (~1));
6754         e_conv.is_owned = (e & 1) || (e == 0);
6755         // Warning: we may need a move here but can't clone!
6756         LDKCResult_ChannelReestablishDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ChannelReestablishDecodeErrorZ), "LDKCResult_ChannelReestablishDecodeErrorZ");
6757         *ret_conv = CResult_ChannelReestablishDecodeErrorZ_err(e_conv);
6758         return (long)ret_conv;
6759 }
6760
6761 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1ChannelReestablishDecodeErrorZ_1free(JNIEnv * _env, jclass _b, jlong _res) {
6762         LDKCResult_ChannelReestablishDecodeErrorZ _res_conv = *(LDKCResult_ChannelReestablishDecodeErrorZ*)_res;
6763         FREE((void*)_res);
6764         CResult_ChannelReestablishDecodeErrorZ_free(_res_conv);
6765 }
6766
6767 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1InitDecodeErrorZ_1ok(JNIEnv * _env, jclass _b, jlong o) {
6768         LDKInit o_conv;
6769         o_conv.inner = (void*)(o & (~1));
6770         o_conv.is_owned = (o & 1) || (o == 0);
6771         if (o_conv.inner != NULL)
6772                 o_conv = Init_clone(&o_conv);
6773         LDKCResult_InitDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_InitDecodeErrorZ), "LDKCResult_InitDecodeErrorZ");
6774         *ret_conv = CResult_InitDecodeErrorZ_ok(o_conv);
6775         return (long)ret_conv;
6776 }
6777
6778 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1InitDecodeErrorZ_1err(JNIEnv * _env, jclass _b, jlong e) {
6779         LDKDecodeError e_conv;
6780         e_conv.inner = (void*)(e & (~1));
6781         e_conv.is_owned = (e & 1) || (e == 0);
6782         // Warning: we may need a move here but can't clone!
6783         LDKCResult_InitDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_InitDecodeErrorZ), "LDKCResult_InitDecodeErrorZ");
6784         *ret_conv = CResult_InitDecodeErrorZ_err(e_conv);
6785         return (long)ret_conv;
6786 }
6787
6788 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1InitDecodeErrorZ_1free(JNIEnv * _env, jclass _b, jlong _res) {
6789         LDKCResult_InitDecodeErrorZ _res_conv = *(LDKCResult_InitDecodeErrorZ*)_res;
6790         FREE((void*)_res);
6791         CResult_InitDecodeErrorZ_free(_res_conv);
6792 }
6793
6794 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1PingDecodeErrorZ_1ok(JNIEnv * _env, jclass _b, jlong o) {
6795         LDKPing o_conv;
6796         o_conv.inner = (void*)(o & (~1));
6797         o_conv.is_owned = (o & 1) || (o == 0);
6798         if (o_conv.inner != NULL)
6799                 o_conv = Ping_clone(&o_conv);
6800         LDKCResult_PingDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_PingDecodeErrorZ), "LDKCResult_PingDecodeErrorZ");
6801         *ret_conv = CResult_PingDecodeErrorZ_ok(o_conv);
6802         return (long)ret_conv;
6803 }
6804
6805 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1PingDecodeErrorZ_1err(JNIEnv * _env, jclass _b, jlong e) {
6806         LDKDecodeError e_conv;
6807         e_conv.inner = (void*)(e & (~1));
6808         e_conv.is_owned = (e & 1) || (e == 0);
6809         // Warning: we may need a move here but can't clone!
6810         LDKCResult_PingDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_PingDecodeErrorZ), "LDKCResult_PingDecodeErrorZ");
6811         *ret_conv = CResult_PingDecodeErrorZ_err(e_conv);
6812         return (long)ret_conv;
6813 }
6814
6815 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1PingDecodeErrorZ_1free(JNIEnv * _env, jclass _b, jlong _res) {
6816         LDKCResult_PingDecodeErrorZ _res_conv = *(LDKCResult_PingDecodeErrorZ*)_res;
6817         FREE((void*)_res);
6818         CResult_PingDecodeErrorZ_free(_res_conv);
6819 }
6820
6821 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1PongDecodeErrorZ_1ok(JNIEnv * _env, jclass _b, jlong o) {
6822         LDKPong o_conv;
6823         o_conv.inner = (void*)(o & (~1));
6824         o_conv.is_owned = (o & 1) || (o == 0);
6825         if (o_conv.inner != NULL)
6826                 o_conv = Pong_clone(&o_conv);
6827         LDKCResult_PongDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_PongDecodeErrorZ), "LDKCResult_PongDecodeErrorZ");
6828         *ret_conv = CResult_PongDecodeErrorZ_ok(o_conv);
6829         return (long)ret_conv;
6830 }
6831
6832 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1PongDecodeErrorZ_1err(JNIEnv * _env, jclass _b, jlong e) {
6833         LDKDecodeError e_conv;
6834         e_conv.inner = (void*)(e & (~1));
6835         e_conv.is_owned = (e & 1) || (e == 0);
6836         // Warning: we may need a move here but can't clone!
6837         LDKCResult_PongDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_PongDecodeErrorZ), "LDKCResult_PongDecodeErrorZ");
6838         *ret_conv = CResult_PongDecodeErrorZ_err(e_conv);
6839         return (long)ret_conv;
6840 }
6841
6842 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1PongDecodeErrorZ_1free(JNIEnv * _env, jclass _b, jlong _res) {
6843         LDKCResult_PongDecodeErrorZ _res_conv = *(LDKCResult_PongDecodeErrorZ*)_res;
6844         FREE((void*)_res);
6845         CResult_PongDecodeErrorZ_free(_res_conv);
6846 }
6847
6848 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1UnsignedChannelAnnouncementDecodeErrorZ_1ok(JNIEnv * _env, jclass _b, jlong o) {
6849         LDKUnsignedChannelAnnouncement o_conv;
6850         o_conv.inner = (void*)(o & (~1));
6851         o_conv.is_owned = (o & 1) || (o == 0);
6852         if (o_conv.inner != NULL)
6853                 o_conv = UnsignedChannelAnnouncement_clone(&o_conv);
6854         LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ), "LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ");
6855         *ret_conv = CResult_UnsignedChannelAnnouncementDecodeErrorZ_ok(o_conv);
6856         return (long)ret_conv;
6857 }
6858
6859 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1UnsignedChannelAnnouncementDecodeErrorZ_1err(JNIEnv * _env, jclass _b, jlong e) {
6860         LDKDecodeError e_conv;
6861         e_conv.inner = (void*)(e & (~1));
6862         e_conv.is_owned = (e & 1) || (e == 0);
6863         // Warning: we may need a move here but can't clone!
6864         LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ), "LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ");
6865         *ret_conv = CResult_UnsignedChannelAnnouncementDecodeErrorZ_err(e_conv);
6866         return (long)ret_conv;
6867 }
6868
6869 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1UnsignedChannelAnnouncementDecodeErrorZ_1free(JNIEnv * _env, jclass _b, jlong _res) {
6870         LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ _res_conv = *(LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ*)_res;
6871         FREE((void*)_res);
6872         CResult_UnsignedChannelAnnouncementDecodeErrorZ_free(_res_conv);
6873 }
6874
6875 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1UnsignedChannelUpdateDecodeErrorZ_1ok(JNIEnv * _env, jclass _b, jlong o) {
6876         LDKUnsignedChannelUpdate o_conv;
6877         o_conv.inner = (void*)(o & (~1));
6878         o_conv.is_owned = (o & 1) || (o == 0);
6879         if (o_conv.inner != NULL)
6880                 o_conv = UnsignedChannelUpdate_clone(&o_conv);
6881         LDKCResult_UnsignedChannelUpdateDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_UnsignedChannelUpdateDecodeErrorZ), "LDKCResult_UnsignedChannelUpdateDecodeErrorZ");
6882         *ret_conv = CResult_UnsignedChannelUpdateDecodeErrorZ_ok(o_conv);
6883         return (long)ret_conv;
6884 }
6885
6886 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1UnsignedChannelUpdateDecodeErrorZ_1err(JNIEnv * _env, jclass _b, jlong e) {
6887         LDKDecodeError e_conv;
6888         e_conv.inner = (void*)(e & (~1));
6889         e_conv.is_owned = (e & 1) || (e == 0);
6890         // Warning: we may need a move here but can't clone!
6891         LDKCResult_UnsignedChannelUpdateDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_UnsignedChannelUpdateDecodeErrorZ), "LDKCResult_UnsignedChannelUpdateDecodeErrorZ");
6892         *ret_conv = CResult_UnsignedChannelUpdateDecodeErrorZ_err(e_conv);
6893         return (long)ret_conv;
6894 }
6895
6896 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1UnsignedChannelUpdateDecodeErrorZ_1free(JNIEnv * _env, jclass _b, jlong _res) {
6897         LDKCResult_UnsignedChannelUpdateDecodeErrorZ _res_conv = *(LDKCResult_UnsignedChannelUpdateDecodeErrorZ*)_res;
6898         FREE((void*)_res);
6899         CResult_UnsignedChannelUpdateDecodeErrorZ_free(_res_conv);
6900 }
6901
6902 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1ErrorMessageDecodeErrorZ_1ok(JNIEnv * _env, jclass _b, jlong o) {
6903         LDKErrorMessage o_conv;
6904         o_conv.inner = (void*)(o & (~1));
6905         o_conv.is_owned = (o & 1) || (o == 0);
6906         if (o_conv.inner != NULL)
6907                 o_conv = ErrorMessage_clone(&o_conv);
6908         LDKCResult_ErrorMessageDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ErrorMessageDecodeErrorZ), "LDKCResult_ErrorMessageDecodeErrorZ");
6909         *ret_conv = CResult_ErrorMessageDecodeErrorZ_ok(o_conv);
6910         return (long)ret_conv;
6911 }
6912
6913 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1ErrorMessageDecodeErrorZ_1err(JNIEnv * _env, jclass _b, jlong e) {
6914         LDKDecodeError e_conv;
6915         e_conv.inner = (void*)(e & (~1));
6916         e_conv.is_owned = (e & 1) || (e == 0);
6917         // Warning: we may need a move here but can't clone!
6918         LDKCResult_ErrorMessageDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ErrorMessageDecodeErrorZ), "LDKCResult_ErrorMessageDecodeErrorZ");
6919         *ret_conv = CResult_ErrorMessageDecodeErrorZ_err(e_conv);
6920         return (long)ret_conv;
6921 }
6922
6923 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1ErrorMessageDecodeErrorZ_1free(JNIEnv * _env, jclass _b, jlong _res) {
6924         LDKCResult_ErrorMessageDecodeErrorZ _res_conv = *(LDKCResult_ErrorMessageDecodeErrorZ*)_res;
6925         FREE((void*)_res);
6926         CResult_ErrorMessageDecodeErrorZ_free(_res_conv);
6927 }
6928
6929 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1UnsignedNodeAnnouncementDecodeErrorZ_1ok(JNIEnv * _env, jclass _b, jlong o) {
6930         LDKUnsignedNodeAnnouncement o_conv;
6931         o_conv.inner = (void*)(o & (~1));
6932         o_conv.is_owned = (o & 1) || (o == 0);
6933         if (o_conv.inner != NULL)
6934                 o_conv = UnsignedNodeAnnouncement_clone(&o_conv);
6935         LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ), "LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ");
6936         *ret_conv = CResult_UnsignedNodeAnnouncementDecodeErrorZ_ok(o_conv);
6937         return (long)ret_conv;
6938 }
6939
6940 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1UnsignedNodeAnnouncementDecodeErrorZ_1err(JNIEnv * _env, jclass _b, jlong e) {
6941         LDKDecodeError e_conv;
6942         e_conv.inner = (void*)(e & (~1));
6943         e_conv.is_owned = (e & 1) || (e == 0);
6944         // Warning: we may need a move here but can't clone!
6945         LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ), "LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ");
6946         *ret_conv = CResult_UnsignedNodeAnnouncementDecodeErrorZ_err(e_conv);
6947         return (long)ret_conv;
6948 }
6949
6950 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1UnsignedNodeAnnouncementDecodeErrorZ_1free(JNIEnv * _env, jclass _b, jlong _res) {
6951         LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ _res_conv = *(LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ*)_res;
6952         FREE((void*)_res);
6953         CResult_UnsignedNodeAnnouncementDecodeErrorZ_free(_res_conv);
6954 }
6955
6956 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1QueryShortChannelIdsDecodeErrorZ_1ok(JNIEnv * _env, jclass _b, jlong o) {
6957         LDKQueryShortChannelIds o_conv;
6958         o_conv.inner = (void*)(o & (~1));
6959         o_conv.is_owned = (o & 1) || (o == 0);
6960         if (o_conv.inner != NULL)
6961                 o_conv = QueryShortChannelIds_clone(&o_conv);
6962         LDKCResult_QueryShortChannelIdsDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_QueryShortChannelIdsDecodeErrorZ), "LDKCResult_QueryShortChannelIdsDecodeErrorZ");
6963         *ret_conv = CResult_QueryShortChannelIdsDecodeErrorZ_ok(o_conv);
6964         return (long)ret_conv;
6965 }
6966
6967 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1QueryShortChannelIdsDecodeErrorZ_1err(JNIEnv * _env, jclass _b, jlong e) {
6968         LDKDecodeError e_conv;
6969         e_conv.inner = (void*)(e & (~1));
6970         e_conv.is_owned = (e & 1) || (e == 0);
6971         // Warning: we may need a move here but can't clone!
6972         LDKCResult_QueryShortChannelIdsDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_QueryShortChannelIdsDecodeErrorZ), "LDKCResult_QueryShortChannelIdsDecodeErrorZ");
6973         *ret_conv = CResult_QueryShortChannelIdsDecodeErrorZ_err(e_conv);
6974         return (long)ret_conv;
6975 }
6976
6977 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1QueryShortChannelIdsDecodeErrorZ_1free(JNIEnv * _env, jclass _b, jlong _res) {
6978         LDKCResult_QueryShortChannelIdsDecodeErrorZ _res_conv = *(LDKCResult_QueryShortChannelIdsDecodeErrorZ*)_res;
6979         FREE((void*)_res);
6980         CResult_QueryShortChannelIdsDecodeErrorZ_free(_res_conv);
6981 }
6982
6983 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1ReplyShortChannelIdsEndDecodeErrorZ_1ok(JNIEnv * _env, jclass _b, jlong o) {
6984         LDKReplyShortChannelIdsEnd o_conv;
6985         o_conv.inner = (void*)(o & (~1));
6986         o_conv.is_owned = (o & 1) || (o == 0);
6987         if (o_conv.inner != NULL)
6988                 o_conv = ReplyShortChannelIdsEnd_clone(&o_conv);
6989         LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ), "LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ");
6990         *ret_conv = CResult_ReplyShortChannelIdsEndDecodeErrorZ_ok(o_conv);
6991         return (long)ret_conv;
6992 }
6993
6994 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1ReplyShortChannelIdsEndDecodeErrorZ_1err(JNIEnv * _env, jclass _b, jlong e) {
6995         LDKDecodeError e_conv;
6996         e_conv.inner = (void*)(e & (~1));
6997         e_conv.is_owned = (e & 1) || (e == 0);
6998         // Warning: we may need a move here but can't clone!
6999         LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ), "LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ");
7000         *ret_conv = CResult_ReplyShortChannelIdsEndDecodeErrorZ_err(e_conv);
7001         return (long)ret_conv;
7002 }
7003
7004 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1ReplyShortChannelIdsEndDecodeErrorZ_1free(JNIEnv * _env, jclass _b, jlong _res) {
7005         LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ _res_conv = *(LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ*)_res;
7006         FREE((void*)_res);
7007         CResult_ReplyShortChannelIdsEndDecodeErrorZ_free(_res_conv);
7008 }
7009
7010 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1QueryChannelRangeDecodeErrorZ_1ok(JNIEnv * _env, jclass _b, jlong o) {
7011         LDKQueryChannelRange o_conv;
7012         o_conv.inner = (void*)(o & (~1));
7013         o_conv.is_owned = (o & 1) || (o == 0);
7014         if (o_conv.inner != NULL)
7015                 o_conv = QueryChannelRange_clone(&o_conv);
7016         LDKCResult_QueryChannelRangeDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_QueryChannelRangeDecodeErrorZ), "LDKCResult_QueryChannelRangeDecodeErrorZ");
7017         *ret_conv = CResult_QueryChannelRangeDecodeErrorZ_ok(o_conv);
7018         return (long)ret_conv;
7019 }
7020
7021 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1QueryChannelRangeDecodeErrorZ_1err(JNIEnv * _env, jclass _b, jlong e) {
7022         LDKDecodeError e_conv;
7023         e_conv.inner = (void*)(e & (~1));
7024         e_conv.is_owned = (e & 1) || (e == 0);
7025         // Warning: we may need a move here but can't clone!
7026         LDKCResult_QueryChannelRangeDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_QueryChannelRangeDecodeErrorZ), "LDKCResult_QueryChannelRangeDecodeErrorZ");
7027         *ret_conv = CResult_QueryChannelRangeDecodeErrorZ_err(e_conv);
7028         return (long)ret_conv;
7029 }
7030
7031 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1QueryChannelRangeDecodeErrorZ_1free(JNIEnv * _env, jclass _b, jlong _res) {
7032         LDKCResult_QueryChannelRangeDecodeErrorZ _res_conv = *(LDKCResult_QueryChannelRangeDecodeErrorZ*)_res;
7033         FREE((void*)_res);
7034         CResult_QueryChannelRangeDecodeErrorZ_free(_res_conv);
7035 }
7036
7037 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1ReplyChannelRangeDecodeErrorZ_1ok(JNIEnv * _env, jclass _b, jlong o) {
7038         LDKReplyChannelRange o_conv;
7039         o_conv.inner = (void*)(o & (~1));
7040         o_conv.is_owned = (o & 1) || (o == 0);
7041         if (o_conv.inner != NULL)
7042                 o_conv = ReplyChannelRange_clone(&o_conv);
7043         LDKCResult_ReplyChannelRangeDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ReplyChannelRangeDecodeErrorZ), "LDKCResult_ReplyChannelRangeDecodeErrorZ");
7044         *ret_conv = CResult_ReplyChannelRangeDecodeErrorZ_ok(o_conv);
7045         return (long)ret_conv;
7046 }
7047
7048 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1ReplyChannelRangeDecodeErrorZ_1err(JNIEnv * _env, jclass _b, jlong e) {
7049         LDKDecodeError e_conv;
7050         e_conv.inner = (void*)(e & (~1));
7051         e_conv.is_owned = (e & 1) || (e == 0);
7052         // Warning: we may need a move here but can't clone!
7053         LDKCResult_ReplyChannelRangeDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ReplyChannelRangeDecodeErrorZ), "LDKCResult_ReplyChannelRangeDecodeErrorZ");
7054         *ret_conv = CResult_ReplyChannelRangeDecodeErrorZ_err(e_conv);
7055         return (long)ret_conv;
7056 }
7057
7058 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1ReplyChannelRangeDecodeErrorZ_1free(JNIEnv * _env, jclass _b, jlong _res) {
7059         LDKCResult_ReplyChannelRangeDecodeErrorZ _res_conv = *(LDKCResult_ReplyChannelRangeDecodeErrorZ*)_res;
7060         FREE((void*)_res);
7061         CResult_ReplyChannelRangeDecodeErrorZ_free(_res_conv);
7062 }
7063
7064 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1GossipTimestampFilterDecodeErrorZ_1ok(JNIEnv * _env, jclass _b, jlong o) {
7065         LDKGossipTimestampFilter o_conv;
7066         o_conv.inner = (void*)(o & (~1));
7067         o_conv.is_owned = (o & 1) || (o == 0);
7068         if (o_conv.inner != NULL)
7069                 o_conv = GossipTimestampFilter_clone(&o_conv);
7070         LDKCResult_GossipTimestampFilterDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_GossipTimestampFilterDecodeErrorZ), "LDKCResult_GossipTimestampFilterDecodeErrorZ");
7071         *ret_conv = CResult_GossipTimestampFilterDecodeErrorZ_ok(o_conv);
7072         return (long)ret_conv;
7073 }
7074
7075 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1GossipTimestampFilterDecodeErrorZ_1err(JNIEnv * _env, jclass _b, jlong e) {
7076         LDKDecodeError e_conv;
7077         e_conv.inner = (void*)(e & (~1));
7078         e_conv.is_owned = (e & 1) || (e == 0);
7079         // Warning: we may need a move here but can't clone!
7080         LDKCResult_GossipTimestampFilterDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_GossipTimestampFilterDecodeErrorZ), "LDKCResult_GossipTimestampFilterDecodeErrorZ");
7081         *ret_conv = CResult_GossipTimestampFilterDecodeErrorZ_err(e_conv);
7082         return (long)ret_conv;
7083 }
7084
7085 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1GossipTimestampFilterDecodeErrorZ_1free(JNIEnv * _env, jclass _b, jlong _res) {
7086         LDKCResult_GossipTimestampFilterDecodeErrorZ _res_conv = *(LDKCResult_GossipTimestampFilterDecodeErrorZ*)_res;
7087         FREE((void*)_res);
7088         CResult_GossipTimestampFilterDecodeErrorZ_free(_res_conv);
7089 }
7090
7091 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1PublicKeyZ_1free(JNIEnv * _env, jclass _b, jobjectArray _res) {
7092         LDKCVec_PublicKeyZ _res_constr;
7093         _res_constr.datalen = (*_env)->GetArrayLength (_env, _res);
7094         if (_res_constr.datalen > 0)
7095                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKPublicKey), "LDKCVec_PublicKeyZ Elements");
7096         else
7097                 _res_constr.data = NULL;
7098         for (size_t i = 0; i < _res_constr.datalen; i++) {
7099                 jobject arr_conv_8 = (*_env)->GetObjectArrayElement(_env, _res, i);
7100                 LDKPublicKey arr_conv_8_ref;
7101                 CHECK((*_env)->GetArrayLength (_env, arr_conv_8) == 33);
7102                 (*_env)->GetByteArrayRegion (_env, arr_conv_8, 0, 33, arr_conv_8_ref.compressed_form);
7103                 _res_constr.data[i] = arr_conv_8_ref;
7104         }
7105         CVec_PublicKeyZ_free(_res_constr);
7106 }
7107
7108 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1u8Z_1free(JNIEnv * _env, jclass _b, jbyteArray _res) {
7109         LDKCVec_u8Z _res_ref;
7110         _res_ref.datalen = (*_env)->GetArrayLength (_env, _res);
7111         _res_ref.data = MALLOC(_res_ref.datalen, "LDKCVec_u8Z Bytes");
7112         (*_env)->GetByteArrayRegion(_env, _res, 0, _res_ref.datalen, _res_ref.data);
7113         CVec_u8Z_free(_res_ref);
7114 }
7115
7116 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1CVec_1u8ZPeerHandleErrorZ_1ok(JNIEnv * _env, jclass _b, jbyteArray o) {
7117         LDKCVec_u8Z o_ref;
7118         o_ref.datalen = (*_env)->GetArrayLength (_env, o);
7119         o_ref.data = MALLOC(o_ref.datalen, "LDKCVec_u8Z Bytes");
7120         (*_env)->GetByteArrayRegion(_env, o, 0, o_ref.datalen, o_ref.data);
7121         LDKCResult_CVec_u8ZPeerHandleErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_CVec_u8ZPeerHandleErrorZ), "LDKCResult_CVec_u8ZPeerHandleErrorZ");
7122         *ret_conv = CResult_CVec_u8ZPeerHandleErrorZ_ok(o_ref);
7123         return (long)ret_conv;
7124 }
7125
7126 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1CVec_1u8ZPeerHandleErrorZ_1err(JNIEnv * _env, jclass _b, jlong e) {
7127         LDKPeerHandleError e_conv;
7128         e_conv.inner = (void*)(e & (~1));
7129         e_conv.is_owned = (e & 1) || (e == 0);
7130         // Warning: we may need a move here but can't clone!
7131         LDKCResult_CVec_u8ZPeerHandleErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_CVec_u8ZPeerHandleErrorZ), "LDKCResult_CVec_u8ZPeerHandleErrorZ");
7132         *ret_conv = CResult_CVec_u8ZPeerHandleErrorZ_err(e_conv);
7133         return (long)ret_conv;
7134 }
7135
7136 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1CVec_1u8ZPeerHandleErrorZ_1free(JNIEnv * _env, jclass _b, jlong _res) {
7137         LDKCResult_CVec_u8ZPeerHandleErrorZ _res_conv = *(LDKCResult_CVec_u8ZPeerHandleErrorZ*)_res;
7138         FREE((void*)_res);
7139         CResult_CVec_u8ZPeerHandleErrorZ_free(_res_conv);
7140 }
7141
7142 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1NonePeerHandleErrorZ_1ok(JNIEnv * _env, jclass _b) {
7143         LDKCResult_NonePeerHandleErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NonePeerHandleErrorZ), "LDKCResult_NonePeerHandleErrorZ");
7144         *ret_conv = CResult_NonePeerHandleErrorZ_ok();
7145         return (long)ret_conv;
7146 }
7147
7148 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1NonePeerHandleErrorZ_1err(JNIEnv * _env, jclass _b, jlong e) {
7149         LDKPeerHandleError e_conv;
7150         e_conv.inner = (void*)(e & (~1));
7151         e_conv.is_owned = (e & 1) || (e == 0);
7152         // Warning: we may need a move here but can't clone!
7153         LDKCResult_NonePeerHandleErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NonePeerHandleErrorZ), "LDKCResult_NonePeerHandleErrorZ");
7154         *ret_conv = CResult_NonePeerHandleErrorZ_err(e_conv);
7155         return (long)ret_conv;
7156 }
7157
7158 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1NonePeerHandleErrorZ_1free(JNIEnv * _env, jclass _b, jlong _res) {
7159         LDKCResult_NonePeerHandleErrorZ _res_conv = *(LDKCResult_NonePeerHandleErrorZ*)_res;
7160         FREE((void*)_res);
7161         CResult_NonePeerHandleErrorZ_free(_res_conv);
7162 }
7163
7164 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1boolPeerHandleErrorZ_1ok(JNIEnv * _env, jclass _b, jboolean o) {
7165         LDKCResult_boolPeerHandleErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_boolPeerHandleErrorZ), "LDKCResult_boolPeerHandleErrorZ");
7166         *ret_conv = CResult_boolPeerHandleErrorZ_ok(o);
7167         return (long)ret_conv;
7168 }
7169
7170 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1boolPeerHandleErrorZ_1err(JNIEnv * _env, jclass _b, jlong e) {
7171         LDKPeerHandleError e_conv;
7172         e_conv.inner = (void*)(e & (~1));
7173         e_conv.is_owned = (e & 1) || (e == 0);
7174         // Warning: we may need a move here but can't clone!
7175         LDKCResult_boolPeerHandleErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_boolPeerHandleErrorZ), "LDKCResult_boolPeerHandleErrorZ");
7176         *ret_conv = CResult_boolPeerHandleErrorZ_err(e_conv);
7177         return (long)ret_conv;
7178 }
7179
7180 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1boolPeerHandleErrorZ_1free(JNIEnv * _env, jclass _b, jlong _res) {
7181         LDKCResult_boolPeerHandleErrorZ _res_conv = *(LDKCResult_boolPeerHandleErrorZ*)_res;
7182         FREE((void*)_res);
7183         CResult_boolPeerHandleErrorZ_free(_res_conv);
7184 }
7185
7186 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1SecretKeySecpErrorZ_1ok(JNIEnv * _env, jclass _b, jbyteArray o) {
7187         LDKSecretKey o_ref;
7188         CHECK((*_env)->GetArrayLength (_env, o) == 32);
7189         (*_env)->GetByteArrayRegion (_env, o, 0, 32, o_ref.bytes);
7190         LDKCResult_SecretKeySecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_SecretKeySecpErrorZ), "LDKCResult_SecretKeySecpErrorZ");
7191         *ret_conv = CResult_SecretKeySecpErrorZ_ok(o_ref);
7192         return (long)ret_conv;
7193 }
7194
7195 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1SecretKeySecpErrorZ_1err(JNIEnv * _env, jclass _b, jclass e) {
7196         LDKSecp256k1Error e_conv = LDKSecp256k1Error_from_java(_env, e);
7197         LDKCResult_SecretKeySecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_SecretKeySecpErrorZ), "LDKCResult_SecretKeySecpErrorZ");
7198         *ret_conv = CResult_SecretKeySecpErrorZ_err(e_conv);
7199         return (long)ret_conv;
7200 }
7201
7202 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1SecretKeySecpErrorZ_1free(JNIEnv * _env, jclass _b, jlong _res) {
7203         LDKCResult_SecretKeySecpErrorZ _res_conv = *(LDKCResult_SecretKeySecpErrorZ*)_res;
7204         FREE((void*)_res);
7205         CResult_SecretKeySecpErrorZ_free(_res_conv);
7206 }
7207
7208 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1PublicKeySecpErrorZ_1ok(JNIEnv * _env, jclass _b, jbyteArray o) {
7209         LDKPublicKey o_ref;
7210         CHECK((*_env)->GetArrayLength (_env, o) == 33);
7211         (*_env)->GetByteArrayRegion (_env, o, 0, 33, o_ref.compressed_form);
7212         LDKCResult_PublicKeySecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_PublicKeySecpErrorZ), "LDKCResult_PublicKeySecpErrorZ");
7213         *ret_conv = CResult_PublicKeySecpErrorZ_ok(o_ref);
7214         return (long)ret_conv;
7215 }
7216
7217 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1PublicKeySecpErrorZ_1err(JNIEnv * _env, jclass _b, jclass e) {
7218         LDKSecp256k1Error e_conv = LDKSecp256k1Error_from_java(_env, e);
7219         LDKCResult_PublicKeySecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_PublicKeySecpErrorZ), "LDKCResult_PublicKeySecpErrorZ");
7220         *ret_conv = CResult_PublicKeySecpErrorZ_err(e_conv);
7221         return (long)ret_conv;
7222 }
7223
7224 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1PublicKeySecpErrorZ_1free(JNIEnv * _env, jclass _b, jlong _res) {
7225         LDKCResult_PublicKeySecpErrorZ _res_conv = *(LDKCResult_PublicKeySecpErrorZ*)_res;
7226         FREE((void*)_res);
7227         CResult_PublicKeySecpErrorZ_free(_res_conv);
7228 }
7229
7230 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1TxCreationKeysSecpErrorZ_1ok(JNIEnv * _env, jclass _b, jlong o) {
7231         LDKTxCreationKeys o_conv;
7232         o_conv.inner = (void*)(o & (~1));
7233         o_conv.is_owned = (o & 1) || (o == 0);
7234         if (o_conv.inner != NULL)
7235                 o_conv = TxCreationKeys_clone(&o_conv);
7236         LDKCResult_TxCreationKeysSecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_TxCreationKeysSecpErrorZ), "LDKCResult_TxCreationKeysSecpErrorZ");
7237         *ret_conv = CResult_TxCreationKeysSecpErrorZ_ok(o_conv);
7238         return (long)ret_conv;
7239 }
7240
7241 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1TxCreationKeysSecpErrorZ_1err(JNIEnv * _env, jclass _b, jclass e) {
7242         LDKSecp256k1Error e_conv = LDKSecp256k1Error_from_java(_env, e);
7243         LDKCResult_TxCreationKeysSecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_TxCreationKeysSecpErrorZ), "LDKCResult_TxCreationKeysSecpErrorZ");
7244         *ret_conv = CResult_TxCreationKeysSecpErrorZ_err(e_conv);
7245         return (long)ret_conv;
7246 }
7247
7248 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1TxCreationKeysSecpErrorZ_1free(JNIEnv * _env, jclass _b, jlong _res) {
7249         LDKCResult_TxCreationKeysSecpErrorZ _res_conv = *(LDKCResult_TxCreationKeysSecpErrorZ*)_res;
7250         FREE((void*)_res);
7251         CResult_TxCreationKeysSecpErrorZ_free(_res_conv);
7252 }
7253
7254 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1TrustedCommitmentTransactionNoneZ_1ok(JNIEnv * _env, jclass _b, jlong o) {
7255         LDKTrustedCommitmentTransaction o_conv;
7256         o_conv.inner = (void*)(o & (~1));
7257         o_conv.is_owned = (o & 1) || (o == 0);
7258         // Warning: we may need a move here but can't clone!
7259         LDKCResult_TrustedCommitmentTransactionNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_TrustedCommitmentTransactionNoneZ), "LDKCResult_TrustedCommitmentTransactionNoneZ");
7260         *ret_conv = CResult_TrustedCommitmentTransactionNoneZ_ok(o_conv);
7261         return (long)ret_conv;
7262 }
7263
7264 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1TrustedCommitmentTransactionNoneZ_1err(JNIEnv * _env, jclass _b) {
7265         LDKCResult_TrustedCommitmentTransactionNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_TrustedCommitmentTransactionNoneZ), "LDKCResult_TrustedCommitmentTransactionNoneZ");
7266         *ret_conv = CResult_TrustedCommitmentTransactionNoneZ_err();
7267         return (long)ret_conv;
7268 }
7269
7270 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1TrustedCommitmentTransactionNoneZ_1free(JNIEnv * _env, jclass _b, jlong _res) {
7271         LDKCResult_TrustedCommitmentTransactionNoneZ _res_conv = *(LDKCResult_TrustedCommitmentTransactionNoneZ*)_res;
7272         FREE((void*)_res);
7273         CResult_TrustedCommitmentTransactionNoneZ_free(_res_conv);
7274 }
7275
7276 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1RouteHopZ_1free(JNIEnv * _env, jclass _b, jlongArray _res) {
7277         LDKCVec_RouteHopZ _res_constr;
7278         _res_constr.datalen = (*_env)->GetArrayLength (_env, _res);
7279         if (_res_constr.datalen > 0)
7280                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKRouteHop), "LDKCVec_RouteHopZ Elements");
7281         else
7282                 _res_constr.data = NULL;
7283         long* _res_vals = (*_env)->GetLongArrayElements (_env, _res, NULL);
7284         for (size_t k = 0; k < _res_constr.datalen; k++) {
7285                 long arr_conv_10 = _res_vals[k];
7286                 LDKRouteHop arr_conv_10_conv;
7287                 arr_conv_10_conv.inner = (void*)(arr_conv_10 & (~1));
7288                 arr_conv_10_conv.is_owned = (arr_conv_10 & 1) || (arr_conv_10 == 0);
7289                 _res_constr.data[k] = arr_conv_10_conv;
7290         }
7291         (*_env)->ReleaseLongArrayElements (_env, _res, _res_vals, 0);
7292         CVec_RouteHopZ_free(_res_constr);
7293 }
7294
7295 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1CVec_1RouteHopZZ_1free(JNIEnv * _env, jclass _b, jobjectArray _res) {
7296         LDKCVec_CVec_RouteHopZZ _res_constr;
7297         _res_constr.datalen = (*_env)->GetArrayLength (_env, _res);
7298         if (_res_constr.datalen > 0)
7299                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKCVec_RouteHopZ), "LDKCVec_CVec_RouteHopZZ Elements");
7300         else
7301                 _res_constr.data = NULL;
7302         for (size_t m = 0; m < _res_constr.datalen; m++) {
7303                 jobject arr_conv_12 = (*_env)->GetObjectArrayElement(_env, _res, m);
7304                 LDKCVec_RouteHopZ arr_conv_12_constr;
7305                 arr_conv_12_constr.datalen = (*_env)->GetArrayLength (_env, arr_conv_12);
7306                 if (arr_conv_12_constr.datalen > 0)
7307                         arr_conv_12_constr.data = MALLOC(arr_conv_12_constr.datalen * sizeof(LDKRouteHop), "LDKCVec_RouteHopZ Elements");
7308                 else
7309                         arr_conv_12_constr.data = NULL;
7310                 long* arr_conv_12_vals = (*_env)->GetLongArrayElements (_env, arr_conv_12, NULL);
7311                 for (size_t k = 0; k < arr_conv_12_constr.datalen; k++) {
7312                         long arr_conv_10 = arr_conv_12_vals[k];
7313                         LDKRouteHop arr_conv_10_conv;
7314                         arr_conv_10_conv.inner = (void*)(arr_conv_10 & (~1));
7315                         arr_conv_10_conv.is_owned = (arr_conv_10 & 1) || (arr_conv_10 == 0);
7316                         arr_conv_12_constr.data[k] = arr_conv_10_conv;
7317                 }
7318                 (*_env)->ReleaseLongArrayElements (_env, arr_conv_12, arr_conv_12_vals, 0);
7319                 _res_constr.data[m] = arr_conv_12_constr;
7320         }
7321         CVec_CVec_RouteHopZZ_free(_res_constr);
7322 }
7323
7324 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1RouteDecodeErrorZ_1ok(JNIEnv * _env, jclass _b, jlong o) {
7325         LDKRoute o_conv;
7326         o_conv.inner = (void*)(o & (~1));
7327         o_conv.is_owned = (o & 1) || (o == 0);
7328         if (o_conv.inner != NULL)
7329                 o_conv = Route_clone(&o_conv);
7330         LDKCResult_RouteDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_RouteDecodeErrorZ), "LDKCResult_RouteDecodeErrorZ");
7331         *ret_conv = CResult_RouteDecodeErrorZ_ok(o_conv);
7332         return (long)ret_conv;
7333 }
7334
7335 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1RouteDecodeErrorZ_1err(JNIEnv * _env, jclass _b, jlong e) {
7336         LDKDecodeError e_conv;
7337         e_conv.inner = (void*)(e & (~1));
7338         e_conv.is_owned = (e & 1) || (e == 0);
7339         // Warning: we may need a move here but can't clone!
7340         LDKCResult_RouteDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_RouteDecodeErrorZ), "LDKCResult_RouteDecodeErrorZ");
7341         *ret_conv = CResult_RouteDecodeErrorZ_err(e_conv);
7342         return (long)ret_conv;
7343 }
7344
7345 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1RouteDecodeErrorZ_1free(JNIEnv * _env, jclass _b, jlong _res) {
7346         LDKCResult_RouteDecodeErrorZ _res_conv = *(LDKCResult_RouteDecodeErrorZ*)_res;
7347         FREE((void*)_res);
7348         CResult_RouteDecodeErrorZ_free(_res_conv);
7349 }
7350
7351 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1RouteHintZ_1free(JNIEnv * _env, jclass _b, jlongArray _res) {
7352         LDKCVec_RouteHintZ _res_constr;
7353         _res_constr.datalen = (*_env)->GetArrayLength (_env, _res);
7354         if (_res_constr.datalen > 0)
7355                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKRouteHint), "LDKCVec_RouteHintZ Elements");
7356         else
7357                 _res_constr.data = NULL;
7358         long* _res_vals = (*_env)->GetLongArrayElements (_env, _res, NULL);
7359         for (size_t l = 0; l < _res_constr.datalen; l++) {
7360                 long arr_conv_11 = _res_vals[l];
7361                 LDKRouteHint arr_conv_11_conv;
7362                 arr_conv_11_conv.inner = (void*)(arr_conv_11 & (~1));
7363                 arr_conv_11_conv.is_owned = (arr_conv_11 & 1) || (arr_conv_11 == 0);
7364                 _res_constr.data[l] = arr_conv_11_conv;
7365         }
7366         (*_env)->ReleaseLongArrayElements (_env, _res, _res_vals, 0);
7367         CVec_RouteHintZ_free(_res_constr);
7368 }
7369
7370 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1RouteLightningErrorZ_1ok(JNIEnv * _env, jclass _b, jlong o) {
7371         LDKRoute o_conv;
7372         o_conv.inner = (void*)(o & (~1));
7373         o_conv.is_owned = (o & 1) || (o == 0);
7374         if (o_conv.inner != NULL)
7375                 o_conv = Route_clone(&o_conv);
7376         LDKCResult_RouteLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_RouteLightningErrorZ), "LDKCResult_RouteLightningErrorZ");
7377         *ret_conv = CResult_RouteLightningErrorZ_ok(o_conv);
7378         return (long)ret_conv;
7379 }
7380
7381 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1RouteLightningErrorZ_1err(JNIEnv * _env, jclass _b, jlong e) {
7382         LDKLightningError e_conv;
7383         e_conv.inner = (void*)(e & (~1));
7384         e_conv.is_owned = (e & 1) || (e == 0);
7385         // Warning: we may need a move here but can't clone!
7386         LDKCResult_RouteLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_RouteLightningErrorZ), "LDKCResult_RouteLightningErrorZ");
7387         *ret_conv = CResult_RouteLightningErrorZ_err(e_conv);
7388         return (long)ret_conv;
7389 }
7390
7391 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1RouteLightningErrorZ_1free(JNIEnv * _env, jclass _b, jlong _res) {
7392         LDKCResult_RouteLightningErrorZ _res_conv = *(LDKCResult_RouteLightningErrorZ*)_res;
7393         FREE((void*)_res);
7394         CResult_RouteLightningErrorZ_free(_res_conv);
7395 }
7396
7397 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1RoutingFeesDecodeErrorZ_1ok(JNIEnv * _env, jclass _b, jlong o) {
7398         LDKRoutingFees o_conv;
7399         o_conv.inner = (void*)(o & (~1));
7400         o_conv.is_owned = (o & 1) || (o == 0);
7401         if (o_conv.inner != NULL)
7402                 o_conv = RoutingFees_clone(&o_conv);
7403         LDKCResult_RoutingFeesDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_RoutingFeesDecodeErrorZ), "LDKCResult_RoutingFeesDecodeErrorZ");
7404         *ret_conv = CResult_RoutingFeesDecodeErrorZ_ok(o_conv);
7405         return (long)ret_conv;
7406 }
7407
7408 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1RoutingFeesDecodeErrorZ_1err(JNIEnv * _env, jclass _b, jlong e) {
7409         LDKDecodeError e_conv;
7410         e_conv.inner = (void*)(e & (~1));
7411         e_conv.is_owned = (e & 1) || (e == 0);
7412         // Warning: we may need a move here but can't clone!
7413         LDKCResult_RoutingFeesDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_RoutingFeesDecodeErrorZ), "LDKCResult_RoutingFeesDecodeErrorZ");
7414         *ret_conv = CResult_RoutingFeesDecodeErrorZ_err(e_conv);
7415         return (long)ret_conv;
7416 }
7417
7418 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1RoutingFeesDecodeErrorZ_1free(JNIEnv * _env, jclass _b, jlong _res) {
7419         LDKCResult_RoutingFeesDecodeErrorZ _res_conv = *(LDKCResult_RoutingFeesDecodeErrorZ*)_res;
7420         FREE((void*)_res);
7421         CResult_RoutingFeesDecodeErrorZ_free(_res_conv);
7422 }
7423
7424 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1NodeAnnouncementInfoDecodeErrorZ_1ok(JNIEnv * _env, jclass _b, jlong o) {
7425         LDKNodeAnnouncementInfo o_conv;
7426         o_conv.inner = (void*)(o & (~1));
7427         o_conv.is_owned = (o & 1) || (o == 0);
7428         // Warning: we may need a move here but can't clone!
7429         LDKCResult_NodeAnnouncementInfoDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NodeAnnouncementInfoDecodeErrorZ), "LDKCResult_NodeAnnouncementInfoDecodeErrorZ");
7430         *ret_conv = CResult_NodeAnnouncementInfoDecodeErrorZ_ok(o_conv);
7431         return (long)ret_conv;
7432 }
7433
7434 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1NodeAnnouncementInfoDecodeErrorZ_1err(JNIEnv * _env, jclass _b, jlong e) {
7435         LDKDecodeError e_conv;
7436         e_conv.inner = (void*)(e & (~1));
7437         e_conv.is_owned = (e & 1) || (e == 0);
7438         // Warning: we may need a move here but can't clone!
7439         LDKCResult_NodeAnnouncementInfoDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NodeAnnouncementInfoDecodeErrorZ), "LDKCResult_NodeAnnouncementInfoDecodeErrorZ");
7440         *ret_conv = CResult_NodeAnnouncementInfoDecodeErrorZ_err(e_conv);
7441         return (long)ret_conv;
7442 }
7443
7444 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1NodeAnnouncementInfoDecodeErrorZ_1free(JNIEnv * _env, jclass _b, jlong _res) {
7445         LDKCResult_NodeAnnouncementInfoDecodeErrorZ _res_conv = *(LDKCResult_NodeAnnouncementInfoDecodeErrorZ*)_res;
7446         FREE((void*)_res);
7447         CResult_NodeAnnouncementInfoDecodeErrorZ_free(_res_conv);
7448 }
7449
7450 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1NodeInfoDecodeErrorZ_1ok(JNIEnv * _env, jclass _b, jlong o) {
7451         LDKNodeInfo o_conv;
7452         o_conv.inner = (void*)(o & (~1));
7453         o_conv.is_owned = (o & 1) || (o == 0);
7454         // Warning: we may need a move here but can't clone!
7455         LDKCResult_NodeInfoDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NodeInfoDecodeErrorZ), "LDKCResult_NodeInfoDecodeErrorZ");
7456         *ret_conv = CResult_NodeInfoDecodeErrorZ_ok(o_conv);
7457         return (long)ret_conv;
7458 }
7459
7460 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1NodeInfoDecodeErrorZ_1err(JNIEnv * _env, jclass _b, jlong e) {
7461         LDKDecodeError e_conv;
7462         e_conv.inner = (void*)(e & (~1));
7463         e_conv.is_owned = (e & 1) || (e == 0);
7464         // Warning: we may need a move here but can't clone!
7465         LDKCResult_NodeInfoDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NodeInfoDecodeErrorZ), "LDKCResult_NodeInfoDecodeErrorZ");
7466         *ret_conv = CResult_NodeInfoDecodeErrorZ_err(e_conv);
7467         return (long)ret_conv;
7468 }
7469
7470 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1NodeInfoDecodeErrorZ_1free(JNIEnv * _env, jclass _b, jlong _res) {
7471         LDKCResult_NodeInfoDecodeErrorZ _res_conv = *(LDKCResult_NodeInfoDecodeErrorZ*)_res;
7472         FREE((void*)_res);
7473         CResult_NodeInfoDecodeErrorZ_free(_res_conv);
7474 }
7475
7476 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1NetworkGraphDecodeErrorZ_1ok(JNIEnv * _env, jclass _b, jlong o) {
7477         LDKNetworkGraph o_conv;
7478         o_conv.inner = (void*)(o & (~1));
7479         o_conv.is_owned = (o & 1) || (o == 0);
7480         // Warning: we may need a move here but can't clone!
7481         LDKCResult_NetworkGraphDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NetworkGraphDecodeErrorZ), "LDKCResult_NetworkGraphDecodeErrorZ");
7482         *ret_conv = CResult_NetworkGraphDecodeErrorZ_ok(o_conv);
7483         return (long)ret_conv;
7484 }
7485
7486 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1NetworkGraphDecodeErrorZ_1err(JNIEnv * _env, jclass _b, jlong e) {
7487         LDKDecodeError e_conv;
7488         e_conv.inner = (void*)(e & (~1));
7489         e_conv.is_owned = (e & 1) || (e == 0);
7490         // Warning: we may need a move here but can't clone!
7491         LDKCResult_NetworkGraphDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NetworkGraphDecodeErrorZ), "LDKCResult_NetworkGraphDecodeErrorZ");
7492         *ret_conv = CResult_NetworkGraphDecodeErrorZ_err(e_conv);
7493         return (long)ret_conv;
7494 }
7495
7496 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1NetworkGraphDecodeErrorZ_1free(JNIEnv * _env, jclass _b, jlong _res) {
7497         LDKCResult_NetworkGraphDecodeErrorZ _res_conv = *(LDKCResult_NetworkGraphDecodeErrorZ*)_res;
7498         FREE((void*)_res);
7499         CResult_NetworkGraphDecodeErrorZ_free(_res_conv);
7500 }
7501
7502 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Event_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
7503         LDKEvent this_ptr_conv = *(LDKEvent*)this_ptr;
7504         FREE((void*)this_ptr);
7505         Event_free(this_ptr_conv);
7506 }
7507
7508 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_Event_1clone(JNIEnv * _env, jclass _b, jlong orig) {
7509         LDKEvent* orig_conv = (LDKEvent*)orig;
7510         LDKEvent *ret_copy = MALLOC(sizeof(LDKEvent), "LDKEvent");
7511         *ret_copy = Event_clone(orig_conv);
7512         long ret_ref = (long)ret_copy;
7513         return ret_ref;
7514 }
7515
7516 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_Event_1write(JNIEnv * _env, jclass _b, jlong obj) {
7517         LDKEvent* obj_conv = (LDKEvent*)obj;
7518         LDKCVec_u8Z arg_var = Event_write(obj_conv);
7519         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
7520         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
7521         CVec_u8Z_free(arg_var);
7522         return arg_arr;
7523 }
7524
7525 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_MessageSendEvent_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
7526         LDKMessageSendEvent this_ptr_conv = *(LDKMessageSendEvent*)this_ptr;
7527         FREE((void*)this_ptr);
7528         MessageSendEvent_free(this_ptr_conv);
7529 }
7530
7531 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_MessageSendEvent_1clone(JNIEnv * _env, jclass _b, jlong orig) {
7532         LDKMessageSendEvent* orig_conv = (LDKMessageSendEvent*)orig;
7533         LDKMessageSendEvent *ret_copy = MALLOC(sizeof(LDKMessageSendEvent), "LDKMessageSendEvent");
7534         *ret_copy = MessageSendEvent_clone(orig_conv);
7535         long ret_ref = (long)ret_copy;
7536         return ret_ref;
7537 }
7538
7539 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_MessageSendEventsProvider_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
7540         LDKMessageSendEventsProvider this_ptr_conv = *(LDKMessageSendEventsProvider*)this_ptr;
7541         FREE((void*)this_ptr);
7542         MessageSendEventsProvider_free(this_ptr_conv);
7543 }
7544
7545 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_EventsProvider_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
7546         LDKEventsProvider this_ptr_conv = *(LDKEventsProvider*)this_ptr;
7547         FREE((void*)this_ptr);
7548         EventsProvider_free(this_ptr_conv);
7549 }
7550
7551 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_APIError_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
7552         LDKAPIError this_ptr_conv = *(LDKAPIError*)this_ptr;
7553         FREE((void*)this_ptr);
7554         APIError_free(this_ptr_conv);
7555 }
7556
7557 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_APIError_1clone(JNIEnv * _env, jclass _b, jlong orig) {
7558         LDKAPIError* orig_conv = (LDKAPIError*)orig;
7559         LDKAPIError *ret_copy = MALLOC(sizeof(LDKAPIError), "LDKAPIError");
7560         *ret_copy = APIError_clone(orig_conv);
7561         long ret_ref = (long)ret_copy;
7562         return ret_ref;
7563 }
7564
7565 JNIEXPORT jclass JNICALL Java_org_ldk_impl_bindings_Level_1clone(JNIEnv * _env, jclass _b, jlong orig) {
7566         LDKLevel* orig_conv = (LDKLevel*)orig;
7567         jclass ret_conv = LDKLevel_to_java(_env, Level_clone(orig_conv));
7568         return ret_conv;
7569 }
7570
7571 JNIEXPORT jclass JNICALL Java_org_ldk_impl_bindings_Level_1max(JNIEnv * _env, jclass _b) {
7572         jclass ret_conv = LDKLevel_to_java(_env, Level_max());
7573         return ret_conv;
7574 }
7575
7576 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Logger_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
7577         LDKLogger this_ptr_conv = *(LDKLogger*)this_ptr;
7578         FREE((void*)this_ptr);
7579         Logger_free(this_ptr_conv);
7580 }
7581
7582 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeConfig_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
7583         LDKChannelHandshakeConfig this_ptr_conv;
7584         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7585         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7586         ChannelHandshakeConfig_free(this_ptr_conv);
7587 }
7588
7589 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeConfig_1clone(JNIEnv * _env, jclass _b, jlong orig) {
7590         LDKChannelHandshakeConfig orig_conv;
7591         orig_conv.inner = (void*)(orig & (~1));
7592         orig_conv.is_owned = false;
7593         LDKChannelHandshakeConfig ret_var = ChannelHandshakeConfig_clone(&orig_conv);
7594         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7595         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7596         long ret_ref = (long)ret_var.inner;
7597         if (ret_var.is_owned) {
7598                 ret_ref |= 1;
7599         }
7600         return ret_ref;
7601 }
7602
7603 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeConfig_1get_1minimum_1depth(JNIEnv * _env, jclass _b, jlong this_ptr) {
7604         LDKChannelHandshakeConfig this_ptr_conv;
7605         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7606         this_ptr_conv.is_owned = false;
7607         jint ret_val = ChannelHandshakeConfig_get_minimum_depth(&this_ptr_conv);
7608         return ret_val;
7609 }
7610
7611 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeConfig_1set_1minimum_1depth(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
7612         LDKChannelHandshakeConfig this_ptr_conv;
7613         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7614         this_ptr_conv.is_owned = false;
7615         ChannelHandshakeConfig_set_minimum_depth(&this_ptr_conv, val);
7616 }
7617
7618 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeConfig_1get_1our_1to_1self_1delay(JNIEnv * _env, jclass _b, jlong this_ptr) {
7619         LDKChannelHandshakeConfig this_ptr_conv;
7620         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7621         this_ptr_conv.is_owned = false;
7622         jshort ret_val = ChannelHandshakeConfig_get_our_to_self_delay(&this_ptr_conv);
7623         return ret_val;
7624 }
7625
7626 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeConfig_1set_1our_1to_1self_1delay(JNIEnv * _env, jclass _b, jlong this_ptr, jshort val) {
7627         LDKChannelHandshakeConfig this_ptr_conv;
7628         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7629         this_ptr_conv.is_owned = false;
7630         ChannelHandshakeConfig_set_our_to_self_delay(&this_ptr_conv, val);
7631 }
7632
7633 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeConfig_1get_1our_1htlc_1minimum_1msat(JNIEnv * _env, jclass _b, jlong this_ptr) {
7634         LDKChannelHandshakeConfig this_ptr_conv;
7635         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7636         this_ptr_conv.is_owned = false;
7637         jlong ret_val = ChannelHandshakeConfig_get_our_htlc_minimum_msat(&this_ptr_conv);
7638         return ret_val;
7639 }
7640
7641 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeConfig_1set_1our_1htlc_1minimum_1msat(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
7642         LDKChannelHandshakeConfig this_ptr_conv;
7643         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7644         this_ptr_conv.is_owned = false;
7645         ChannelHandshakeConfig_set_our_htlc_minimum_msat(&this_ptr_conv, val);
7646 }
7647
7648 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeConfig_1new(JNIEnv * _env, jclass _b, jint minimum_depth_arg, jshort our_to_self_delay_arg, jlong our_htlc_minimum_msat_arg) {
7649         LDKChannelHandshakeConfig ret_var = ChannelHandshakeConfig_new(minimum_depth_arg, our_to_self_delay_arg, our_htlc_minimum_msat_arg);
7650         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7651         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7652         long ret_ref = (long)ret_var.inner;
7653         if (ret_var.is_owned) {
7654                 ret_ref |= 1;
7655         }
7656         return ret_ref;
7657 }
7658
7659 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeConfig_1default(JNIEnv * _env, jclass _b) {
7660         LDKChannelHandshakeConfig ret_var = ChannelHandshakeConfig_default();
7661         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7662         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7663         long ret_ref = (long)ret_var.inner;
7664         if (ret_var.is_owned) {
7665                 ret_ref |= 1;
7666         }
7667         return ret_ref;
7668 }
7669
7670 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
7671         LDKChannelHandshakeLimits this_ptr_conv;
7672         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7673         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7674         ChannelHandshakeLimits_free(this_ptr_conv);
7675 }
7676
7677 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1clone(JNIEnv * _env, jclass _b, jlong orig) {
7678         LDKChannelHandshakeLimits orig_conv;
7679         orig_conv.inner = (void*)(orig & (~1));
7680         orig_conv.is_owned = false;
7681         LDKChannelHandshakeLimits ret_var = ChannelHandshakeLimits_clone(&orig_conv);
7682         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7683         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7684         long ret_ref = (long)ret_var.inner;
7685         if (ret_var.is_owned) {
7686                 ret_ref |= 1;
7687         }
7688         return ret_ref;
7689 }
7690
7691 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1get_1min_1funding_1satoshis(JNIEnv * _env, jclass _b, jlong this_ptr) {
7692         LDKChannelHandshakeLimits this_ptr_conv;
7693         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7694         this_ptr_conv.is_owned = false;
7695         jlong ret_val = ChannelHandshakeLimits_get_min_funding_satoshis(&this_ptr_conv);
7696         return ret_val;
7697 }
7698
7699 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1set_1min_1funding_1satoshis(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
7700         LDKChannelHandshakeLimits this_ptr_conv;
7701         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7702         this_ptr_conv.is_owned = false;
7703         ChannelHandshakeLimits_set_min_funding_satoshis(&this_ptr_conv, val);
7704 }
7705
7706 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1get_1max_1htlc_1minimum_1msat(JNIEnv * _env, jclass _b, jlong this_ptr) {
7707         LDKChannelHandshakeLimits this_ptr_conv;
7708         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7709         this_ptr_conv.is_owned = false;
7710         jlong ret_val = ChannelHandshakeLimits_get_max_htlc_minimum_msat(&this_ptr_conv);
7711         return ret_val;
7712 }
7713
7714 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1set_1max_1htlc_1minimum_1msat(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
7715         LDKChannelHandshakeLimits this_ptr_conv;
7716         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7717         this_ptr_conv.is_owned = false;
7718         ChannelHandshakeLimits_set_max_htlc_minimum_msat(&this_ptr_conv, val);
7719 }
7720
7721 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1get_1min_1max_1htlc_1value_1in_1flight_1msat(JNIEnv * _env, jclass _b, jlong this_ptr) {
7722         LDKChannelHandshakeLimits this_ptr_conv;
7723         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7724         this_ptr_conv.is_owned = false;
7725         jlong ret_val = ChannelHandshakeLimits_get_min_max_htlc_value_in_flight_msat(&this_ptr_conv);
7726         return ret_val;
7727 }
7728
7729 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1set_1min_1max_1htlc_1value_1in_1flight_1msat(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
7730         LDKChannelHandshakeLimits this_ptr_conv;
7731         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7732         this_ptr_conv.is_owned = false;
7733         ChannelHandshakeLimits_set_min_max_htlc_value_in_flight_msat(&this_ptr_conv, val);
7734 }
7735
7736 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1get_1max_1channel_1reserve_1satoshis(JNIEnv * _env, jclass _b, jlong this_ptr) {
7737         LDKChannelHandshakeLimits this_ptr_conv;
7738         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7739         this_ptr_conv.is_owned = false;
7740         jlong ret_val = ChannelHandshakeLimits_get_max_channel_reserve_satoshis(&this_ptr_conv);
7741         return ret_val;
7742 }
7743
7744 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1set_1max_1channel_1reserve_1satoshis(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
7745         LDKChannelHandshakeLimits this_ptr_conv;
7746         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7747         this_ptr_conv.is_owned = false;
7748         ChannelHandshakeLimits_set_max_channel_reserve_satoshis(&this_ptr_conv, val);
7749 }
7750
7751 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1get_1min_1max_1accepted_1htlcs(JNIEnv * _env, jclass _b, jlong this_ptr) {
7752         LDKChannelHandshakeLimits this_ptr_conv;
7753         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7754         this_ptr_conv.is_owned = false;
7755         jshort ret_val = ChannelHandshakeLimits_get_min_max_accepted_htlcs(&this_ptr_conv);
7756         return ret_val;
7757 }
7758
7759 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1set_1min_1max_1accepted_1htlcs(JNIEnv * _env, jclass _b, jlong this_ptr, jshort val) {
7760         LDKChannelHandshakeLimits this_ptr_conv;
7761         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7762         this_ptr_conv.is_owned = false;
7763         ChannelHandshakeLimits_set_min_max_accepted_htlcs(&this_ptr_conv, val);
7764 }
7765
7766 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1get_1min_1dust_1limit_1satoshis(JNIEnv * _env, jclass _b, jlong this_ptr) {
7767         LDKChannelHandshakeLimits this_ptr_conv;
7768         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7769         this_ptr_conv.is_owned = false;
7770         jlong ret_val = ChannelHandshakeLimits_get_min_dust_limit_satoshis(&this_ptr_conv);
7771         return ret_val;
7772 }
7773
7774 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1set_1min_1dust_1limit_1satoshis(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
7775         LDKChannelHandshakeLimits this_ptr_conv;
7776         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7777         this_ptr_conv.is_owned = false;
7778         ChannelHandshakeLimits_set_min_dust_limit_satoshis(&this_ptr_conv, val);
7779 }
7780
7781 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1get_1max_1dust_1limit_1satoshis(JNIEnv * _env, jclass _b, jlong this_ptr) {
7782         LDKChannelHandshakeLimits this_ptr_conv;
7783         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7784         this_ptr_conv.is_owned = false;
7785         jlong ret_val = ChannelHandshakeLimits_get_max_dust_limit_satoshis(&this_ptr_conv);
7786         return ret_val;
7787 }
7788
7789 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1set_1max_1dust_1limit_1satoshis(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
7790         LDKChannelHandshakeLimits this_ptr_conv;
7791         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7792         this_ptr_conv.is_owned = false;
7793         ChannelHandshakeLimits_set_max_dust_limit_satoshis(&this_ptr_conv, val);
7794 }
7795
7796 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1get_1max_1minimum_1depth(JNIEnv * _env, jclass _b, jlong this_ptr) {
7797         LDKChannelHandshakeLimits this_ptr_conv;
7798         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7799         this_ptr_conv.is_owned = false;
7800         jint ret_val = ChannelHandshakeLimits_get_max_minimum_depth(&this_ptr_conv);
7801         return ret_val;
7802 }
7803
7804 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1set_1max_1minimum_1depth(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
7805         LDKChannelHandshakeLimits this_ptr_conv;
7806         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7807         this_ptr_conv.is_owned = false;
7808         ChannelHandshakeLimits_set_max_minimum_depth(&this_ptr_conv, val);
7809 }
7810
7811 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1get_1force_1announced_1channel_1preference(JNIEnv * _env, jclass _b, jlong this_ptr) {
7812         LDKChannelHandshakeLimits this_ptr_conv;
7813         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7814         this_ptr_conv.is_owned = false;
7815         jboolean ret_val = ChannelHandshakeLimits_get_force_announced_channel_preference(&this_ptr_conv);
7816         return ret_val;
7817 }
7818
7819 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1set_1force_1announced_1channel_1preference(JNIEnv * _env, jclass _b, jlong this_ptr, jboolean val) {
7820         LDKChannelHandshakeLimits this_ptr_conv;
7821         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7822         this_ptr_conv.is_owned = false;
7823         ChannelHandshakeLimits_set_force_announced_channel_preference(&this_ptr_conv, val);
7824 }
7825
7826 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1get_1their_1to_1self_1delay(JNIEnv * _env, jclass _b, jlong this_ptr) {
7827         LDKChannelHandshakeLimits this_ptr_conv;
7828         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7829         this_ptr_conv.is_owned = false;
7830         jshort ret_val = ChannelHandshakeLimits_get_their_to_self_delay(&this_ptr_conv);
7831         return ret_val;
7832 }
7833
7834 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1set_1their_1to_1self_1delay(JNIEnv * _env, jclass _b, jlong this_ptr, jshort val) {
7835         LDKChannelHandshakeLimits this_ptr_conv;
7836         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7837         this_ptr_conv.is_owned = false;
7838         ChannelHandshakeLimits_set_their_to_self_delay(&this_ptr_conv, val);
7839 }
7840
7841 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1new(JNIEnv * _env, jclass _b, jlong min_funding_satoshis_arg, jlong max_htlc_minimum_msat_arg, jlong min_max_htlc_value_in_flight_msat_arg, jlong max_channel_reserve_satoshis_arg, jshort min_max_accepted_htlcs_arg, jlong min_dust_limit_satoshis_arg, jlong max_dust_limit_satoshis_arg, jint max_minimum_depth_arg, jboolean force_announced_channel_preference_arg, jshort their_to_self_delay_arg) {
7842         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);
7843         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7844         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7845         long ret_ref = (long)ret_var.inner;
7846         if (ret_var.is_owned) {
7847                 ret_ref |= 1;
7848         }
7849         return ret_ref;
7850 }
7851
7852 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1default(JNIEnv * _env, jclass _b) {
7853         LDKChannelHandshakeLimits ret_var = ChannelHandshakeLimits_default();
7854         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7855         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7856         long ret_ref = (long)ret_var.inner;
7857         if (ret_var.is_owned) {
7858                 ret_ref |= 1;
7859         }
7860         return ret_ref;
7861 }
7862
7863 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelConfig_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
7864         LDKChannelConfig this_ptr_conv;
7865         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7866         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7867         ChannelConfig_free(this_ptr_conv);
7868 }
7869
7870 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelConfig_1clone(JNIEnv * _env, jclass _b, jlong orig) {
7871         LDKChannelConfig orig_conv;
7872         orig_conv.inner = (void*)(orig & (~1));
7873         orig_conv.is_owned = false;
7874         LDKChannelConfig ret_var = ChannelConfig_clone(&orig_conv);
7875         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7876         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7877         long ret_ref = (long)ret_var.inner;
7878         if (ret_var.is_owned) {
7879                 ret_ref |= 1;
7880         }
7881         return ret_ref;
7882 }
7883
7884 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_ChannelConfig_1get_1fee_1proportional_1millionths(JNIEnv * _env, jclass _b, jlong this_ptr) {
7885         LDKChannelConfig this_ptr_conv;
7886         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7887         this_ptr_conv.is_owned = false;
7888         jint ret_val = ChannelConfig_get_fee_proportional_millionths(&this_ptr_conv);
7889         return ret_val;
7890 }
7891
7892 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelConfig_1set_1fee_1proportional_1millionths(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
7893         LDKChannelConfig this_ptr_conv;
7894         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7895         this_ptr_conv.is_owned = false;
7896         ChannelConfig_set_fee_proportional_millionths(&this_ptr_conv, val);
7897 }
7898
7899 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_ChannelConfig_1get_1announced_1channel(JNIEnv * _env, jclass _b, jlong this_ptr) {
7900         LDKChannelConfig this_ptr_conv;
7901         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7902         this_ptr_conv.is_owned = false;
7903         jboolean ret_val = ChannelConfig_get_announced_channel(&this_ptr_conv);
7904         return ret_val;
7905 }
7906
7907 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelConfig_1set_1announced_1channel(JNIEnv * _env, jclass _b, jlong this_ptr, jboolean val) {
7908         LDKChannelConfig this_ptr_conv;
7909         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7910         this_ptr_conv.is_owned = false;
7911         ChannelConfig_set_announced_channel(&this_ptr_conv, val);
7912 }
7913
7914 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_ChannelConfig_1get_1commit_1upfront_1shutdown_1pubkey(JNIEnv * _env, jclass _b, jlong this_ptr) {
7915         LDKChannelConfig this_ptr_conv;
7916         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7917         this_ptr_conv.is_owned = false;
7918         jboolean ret_val = ChannelConfig_get_commit_upfront_shutdown_pubkey(&this_ptr_conv);
7919         return ret_val;
7920 }
7921
7922 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelConfig_1set_1commit_1upfront_1shutdown_1pubkey(JNIEnv * _env, jclass _b, jlong this_ptr, jboolean val) {
7923         LDKChannelConfig this_ptr_conv;
7924         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7925         this_ptr_conv.is_owned = false;
7926         ChannelConfig_set_commit_upfront_shutdown_pubkey(&this_ptr_conv, val);
7927 }
7928
7929 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelConfig_1new(JNIEnv * _env, jclass _b, jint fee_proportional_millionths_arg, jboolean announced_channel_arg, jboolean commit_upfront_shutdown_pubkey_arg) {
7930         LDKChannelConfig ret_var = ChannelConfig_new(fee_proportional_millionths_arg, announced_channel_arg, commit_upfront_shutdown_pubkey_arg);
7931         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7932         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7933         long ret_ref = (long)ret_var.inner;
7934         if (ret_var.is_owned) {
7935                 ret_ref |= 1;
7936         }
7937         return ret_ref;
7938 }
7939
7940 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelConfig_1default(JNIEnv * _env, jclass _b) {
7941         LDKChannelConfig ret_var = ChannelConfig_default();
7942         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7943         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7944         long ret_ref = (long)ret_var.inner;
7945         if (ret_var.is_owned) {
7946                 ret_ref |= 1;
7947         }
7948         return ret_ref;
7949 }
7950
7951 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelConfig_1write(JNIEnv * _env, jclass _b, jlong obj) {
7952         LDKChannelConfig obj_conv;
7953         obj_conv.inner = (void*)(obj & (~1));
7954         obj_conv.is_owned = false;
7955         LDKCVec_u8Z arg_var = ChannelConfig_write(&obj_conv);
7956         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
7957         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
7958         CVec_u8Z_free(arg_var);
7959         return arg_arr;
7960 }
7961
7962 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelConfig_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
7963         LDKu8slice ser_ref;
7964         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
7965         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
7966         LDKChannelConfig ret_var = ChannelConfig_read(ser_ref);
7967         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7968         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7969         long ret_ref = (long)ret_var.inner;
7970         if (ret_var.is_owned) {
7971                 ret_ref |= 1;
7972         }
7973         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
7974         return ret_ref;
7975 }
7976
7977 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UserConfig_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
7978         LDKUserConfig this_ptr_conv;
7979         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7980         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7981         UserConfig_free(this_ptr_conv);
7982 }
7983
7984 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UserConfig_1clone(JNIEnv * _env, jclass _b, jlong orig) {
7985         LDKUserConfig orig_conv;
7986         orig_conv.inner = (void*)(orig & (~1));
7987         orig_conv.is_owned = false;
7988         LDKUserConfig ret_var = UserConfig_clone(&orig_conv);
7989         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7990         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7991         long ret_ref = (long)ret_var.inner;
7992         if (ret_var.is_owned) {
7993                 ret_ref |= 1;
7994         }
7995         return ret_ref;
7996 }
7997
7998 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UserConfig_1get_1own_1channel_1config(JNIEnv * _env, jclass _b, jlong this_ptr) {
7999         LDKUserConfig this_ptr_conv;
8000         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8001         this_ptr_conv.is_owned = false;
8002         LDKChannelHandshakeConfig ret_var = UserConfig_get_own_channel_config(&this_ptr_conv);
8003         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8004         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8005         long ret_ref = (long)ret_var.inner;
8006         if (ret_var.is_owned) {
8007                 ret_ref |= 1;
8008         }
8009         return ret_ref;
8010 }
8011
8012 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UserConfig_1set_1own_1channel_1config(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
8013         LDKUserConfig this_ptr_conv;
8014         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8015         this_ptr_conv.is_owned = false;
8016         LDKChannelHandshakeConfig val_conv;
8017         val_conv.inner = (void*)(val & (~1));
8018         val_conv.is_owned = (val & 1) || (val == 0);
8019         if (val_conv.inner != NULL)
8020                 val_conv = ChannelHandshakeConfig_clone(&val_conv);
8021         UserConfig_set_own_channel_config(&this_ptr_conv, val_conv);
8022 }
8023
8024 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UserConfig_1get_1peer_1channel_1config_1limits(JNIEnv * _env, jclass _b, jlong this_ptr) {
8025         LDKUserConfig this_ptr_conv;
8026         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8027         this_ptr_conv.is_owned = false;
8028         LDKChannelHandshakeLimits ret_var = UserConfig_get_peer_channel_config_limits(&this_ptr_conv);
8029         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8030         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8031         long ret_ref = (long)ret_var.inner;
8032         if (ret_var.is_owned) {
8033                 ret_ref |= 1;
8034         }
8035         return ret_ref;
8036 }
8037
8038 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UserConfig_1set_1peer_1channel_1config_1limits(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
8039         LDKUserConfig this_ptr_conv;
8040         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8041         this_ptr_conv.is_owned = false;
8042         LDKChannelHandshakeLimits val_conv;
8043         val_conv.inner = (void*)(val & (~1));
8044         val_conv.is_owned = (val & 1) || (val == 0);
8045         if (val_conv.inner != NULL)
8046                 val_conv = ChannelHandshakeLimits_clone(&val_conv);
8047         UserConfig_set_peer_channel_config_limits(&this_ptr_conv, val_conv);
8048 }
8049
8050 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UserConfig_1get_1channel_1options(JNIEnv * _env, jclass _b, jlong this_ptr) {
8051         LDKUserConfig this_ptr_conv;
8052         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8053         this_ptr_conv.is_owned = false;
8054         LDKChannelConfig ret_var = UserConfig_get_channel_options(&this_ptr_conv);
8055         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8056         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8057         long ret_ref = (long)ret_var.inner;
8058         if (ret_var.is_owned) {
8059                 ret_ref |= 1;
8060         }
8061         return ret_ref;
8062 }
8063
8064 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UserConfig_1set_1channel_1options(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
8065         LDKUserConfig this_ptr_conv;
8066         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8067         this_ptr_conv.is_owned = false;
8068         LDKChannelConfig val_conv;
8069         val_conv.inner = (void*)(val & (~1));
8070         val_conv.is_owned = (val & 1) || (val == 0);
8071         if (val_conv.inner != NULL)
8072                 val_conv = ChannelConfig_clone(&val_conv);
8073         UserConfig_set_channel_options(&this_ptr_conv, val_conv);
8074 }
8075
8076 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UserConfig_1new(JNIEnv * _env, jclass _b, jlong own_channel_config_arg, jlong peer_channel_config_limits_arg, jlong channel_options_arg) {
8077         LDKChannelHandshakeConfig own_channel_config_arg_conv;
8078         own_channel_config_arg_conv.inner = (void*)(own_channel_config_arg & (~1));
8079         own_channel_config_arg_conv.is_owned = (own_channel_config_arg & 1) || (own_channel_config_arg == 0);
8080         if (own_channel_config_arg_conv.inner != NULL)
8081                 own_channel_config_arg_conv = ChannelHandshakeConfig_clone(&own_channel_config_arg_conv);
8082         LDKChannelHandshakeLimits peer_channel_config_limits_arg_conv;
8083         peer_channel_config_limits_arg_conv.inner = (void*)(peer_channel_config_limits_arg & (~1));
8084         peer_channel_config_limits_arg_conv.is_owned = (peer_channel_config_limits_arg & 1) || (peer_channel_config_limits_arg == 0);
8085         if (peer_channel_config_limits_arg_conv.inner != NULL)
8086                 peer_channel_config_limits_arg_conv = ChannelHandshakeLimits_clone(&peer_channel_config_limits_arg_conv);
8087         LDKChannelConfig channel_options_arg_conv;
8088         channel_options_arg_conv.inner = (void*)(channel_options_arg & (~1));
8089         channel_options_arg_conv.is_owned = (channel_options_arg & 1) || (channel_options_arg == 0);
8090         if (channel_options_arg_conv.inner != NULL)
8091                 channel_options_arg_conv = ChannelConfig_clone(&channel_options_arg_conv);
8092         LDKUserConfig ret_var = UserConfig_new(own_channel_config_arg_conv, peer_channel_config_limits_arg_conv, channel_options_arg_conv);
8093         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8094         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8095         long ret_ref = (long)ret_var.inner;
8096         if (ret_var.is_owned) {
8097                 ret_ref |= 1;
8098         }
8099         return ret_ref;
8100 }
8101
8102 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UserConfig_1default(JNIEnv * _env, jclass _b) {
8103         LDKUserConfig ret_var = UserConfig_default();
8104         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8105         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8106         long ret_ref = (long)ret_var.inner;
8107         if (ret_var.is_owned) {
8108                 ret_ref |= 1;
8109         }
8110         return ret_ref;
8111 }
8112
8113 JNIEXPORT jclass JNICALL Java_org_ldk_impl_bindings_AccessError_1clone(JNIEnv * _env, jclass _b, jlong orig) {
8114         LDKAccessError* orig_conv = (LDKAccessError*)orig;
8115         jclass ret_conv = LDKAccessError_to_java(_env, AccessError_clone(orig_conv));
8116         return ret_conv;
8117 }
8118
8119 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Access_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
8120         LDKAccess this_ptr_conv = *(LDKAccess*)this_ptr;
8121         FREE((void*)this_ptr);
8122         Access_free(this_ptr_conv);
8123 }
8124
8125 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Watch_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
8126         LDKWatch this_ptr_conv = *(LDKWatch*)this_ptr;
8127         FREE((void*)this_ptr);
8128         Watch_free(this_ptr_conv);
8129 }
8130
8131 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Filter_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
8132         LDKFilter this_ptr_conv = *(LDKFilter*)this_ptr;
8133         FREE((void*)this_ptr);
8134         Filter_free(this_ptr_conv);
8135 }
8136
8137 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_BroadcasterInterface_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
8138         LDKBroadcasterInterface this_ptr_conv = *(LDKBroadcasterInterface*)this_ptr;
8139         FREE((void*)this_ptr);
8140         BroadcasterInterface_free(this_ptr_conv);
8141 }
8142
8143 JNIEXPORT jclass JNICALL Java_org_ldk_impl_bindings_ConfirmationTarget_1clone(JNIEnv * _env, jclass _b, jlong orig) {
8144         LDKConfirmationTarget* orig_conv = (LDKConfirmationTarget*)orig;
8145         jclass ret_conv = LDKConfirmationTarget_to_java(_env, ConfirmationTarget_clone(orig_conv));
8146         return ret_conv;
8147 }
8148
8149 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_FeeEstimator_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
8150         LDKFeeEstimator this_ptr_conv = *(LDKFeeEstimator*)this_ptr;
8151         FREE((void*)this_ptr);
8152         FeeEstimator_free(this_ptr_conv);
8153 }
8154
8155 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChainMonitor_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
8156         LDKChainMonitor 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         ChainMonitor_free(this_ptr_conv);
8160 }
8161
8162 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChainMonitor_1block_1connected(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray header, jlongArray txdata, jint height) {
8163         LDKChainMonitor this_arg_conv;
8164         this_arg_conv.inner = (void*)(this_arg & (~1));
8165         this_arg_conv.is_owned = false;
8166         unsigned char header_arr[80];
8167         CHECK((*_env)->GetArrayLength (_env, header) == 80);
8168         (*_env)->GetByteArrayRegion (_env, header, 0, 80, header_arr);
8169         unsigned char (*header_ref)[80] = &header_arr;
8170         LDKCVec_C2Tuple_usizeTransactionZZ txdata_constr;
8171         txdata_constr.datalen = (*_env)->GetArrayLength (_env, txdata);
8172         if (txdata_constr.datalen > 0)
8173                 txdata_constr.data = MALLOC(txdata_constr.datalen * sizeof(LDKC2Tuple_usizeTransactionZ), "LDKCVec_C2Tuple_usizeTransactionZZ Elements");
8174         else
8175                 txdata_constr.data = NULL;
8176         long* txdata_vals = (*_env)->GetLongArrayElements (_env, txdata, NULL);
8177         for (size_t y = 0; y < txdata_constr.datalen; y++) {
8178                 long arr_conv_24 = txdata_vals[y];
8179                 LDKC2Tuple_usizeTransactionZ arr_conv_24_conv = *(LDKC2Tuple_usizeTransactionZ*)arr_conv_24;
8180                 FREE((void*)arr_conv_24);
8181                 txdata_constr.data[y] = arr_conv_24_conv;
8182         }
8183         (*_env)->ReleaseLongArrayElements (_env, txdata, txdata_vals, 0);
8184         ChainMonitor_block_connected(&this_arg_conv, header_ref, txdata_constr, height);
8185 }
8186
8187 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChainMonitor_1block_1disconnected(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray header, jint disconnected_height) {
8188         LDKChainMonitor this_arg_conv;
8189         this_arg_conv.inner = (void*)(this_arg & (~1));
8190         this_arg_conv.is_owned = false;
8191         unsigned char header_arr[80];
8192         CHECK((*_env)->GetArrayLength (_env, header) == 80);
8193         (*_env)->GetByteArrayRegion (_env, header, 0, 80, header_arr);
8194         unsigned char (*header_ref)[80] = &header_arr;
8195         ChainMonitor_block_disconnected(&this_arg_conv, header_ref, disconnected_height);
8196 }
8197
8198 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChainMonitor_1new(JNIEnv * _env, jclass _b, jlong chain_source, jlong broadcaster, jlong logger, jlong feeest, jlong persister) {
8199         LDKFilter* chain_source_conv = (LDKFilter*)chain_source;
8200         LDKBroadcasterInterface broadcaster_conv = *(LDKBroadcasterInterface*)broadcaster;
8201         if (broadcaster_conv.free == LDKBroadcasterInterface_JCalls_free) {
8202                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
8203                 LDKBroadcasterInterface_JCalls_clone(broadcaster_conv.this_arg);
8204         }
8205         LDKLogger logger_conv = *(LDKLogger*)logger;
8206         if (logger_conv.free == LDKLogger_JCalls_free) {
8207                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
8208                 LDKLogger_JCalls_clone(logger_conv.this_arg);
8209         }
8210         LDKFeeEstimator feeest_conv = *(LDKFeeEstimator*)feeest;
8211         if (feeest_conv.free == LDKFeeEstimator_JCalls_free) {
8212                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
8213                 LDKFeeEstimator_JCalls_clone(feeest_conv.this_arg);
8214         }
8215         LDKPersist persister_conv = *(LDKPersist*)persister;
8216         if (persister_conv.free == LDKPersist_JCalls_free) {
8217                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
8218                 LDKPersist_JCalls_clone(persister_conv.this_arg);
8219         }
8220         LDKChainMonitor ret_var = ChainMonitor_new(chain_source_conv, broadcaster_conv, logger_conv, feeest_conv, persister_conv);
8221         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8222         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8223         long ret_ref = (long)ret_var.inner;
8224         if (ret_var.is_owned) {
8225                 ret_ref |= 1;
8226         }
8227         return ret_ref;
8228 }
8229
8230 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChainMonitor_1as_1Watch(JNIEnv * _env, jclass _b, jlong this_arg) {
8231         LDKChainMonitor this_arg_conv;
8232         this_arg_conv.inner = (void*)(this_arg & (~1));
8233         this_arg_conv.is_owned = false;
8234         LDKWatch* ret = MALLOC(sizeof(LDKWatch), "LDKWatch");
8235         *ret = ChainMonitor_as_Watch(&this_arg_conv);
8236         return (long)ret;
8237 }
8238
8239 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChainMonitor_1as_1EventsProvider(JNIEnv * _env, jclass _b, jlong this_arg) {
8240         LDKChainMonitor this_arg_conv;
8241         this_arg_conv.inner = (void*)(this_arg & (~1));
8242         this_arg_conv.is_owned = false;
8243         LDKEventsProvider* ret = MALLOC(sizeof(LDKEventsProvider), "LDKEventsProvider");
8244         *ret = ChainMonitor_as_EventsProvider(&this_arg_conv);
8245         return (long)ret;
8246 }
8247
8248 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelMonitorUpdate_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
8249         LDKChannelMonitorUpdate this_ptr_conv;
8250         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8251         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8252         ChannelMonitorUpdate_free(this_ptr_conv);
8253 }
8254
8255 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelMonitorUpdate_1clone(JNIEnv * _env, jclass _b, jlong orig) {
8256         LDKChannelMonitorUpdate orig_conv;
8257         orig_conv.inner = (void*)(orig & (~1));
8258         orig_conv.is_owned = false;
8259         LDKChannelMonitorUpdate ret_var = ChannelMonitorUpdate_clone(&orig_conv);
8260         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8261         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8262         long ret_ref = (long)ret_var.inner;
8263         if (ret_var.is_owned) {
8264                 ret_ref |= 1;
8265         }
8266         return ret_ref;
8267 }
8268
8269 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelMonitorUpdate_1get_1update_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
8270         LDKChannelMonitorUpdate this_ptr_conv;
8271         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8272         this_ptr_conv.is_owned = false;
8273         jlong ret_val = ChannelMonitorUpdate_get_update_id(&this_ptr_conv);
8274         return ret_val;
8275 }
8276
8277 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelMonitorUpdate_1set_1update_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
8278         LDKChannelMonitorUpdate this_ptr_conv;
8279         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8280         this_ptr_conv.is_owned = false;
8281         ChannelMonitorUpdate_set_update_id(&this_ptr_conv, val);
8282 }
8283
8284 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelMonitorUpdate_1write(JNIEnv * _env, jclass _b, jlong obj) {
8285         LDKChannelMonitorUpdate obj_conv;
8286         obj_conv.inner = (void*)(obj & (~1));
8287         obj_conv.is_owned = false;
8288         LDKCVec_u8Z arg_var = ChannelMonitorUpdate_write(&obj_conv);
8289         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
8290         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
8291         CVec_u8Z_free(arg_var);
8292         return arg_arr;
8293 }
8294
8295 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelMonitorUpdate_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
8296         LDKu8slice ser_ref;
8297         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
8298         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
8299         LDKCResult_ChannelMonitorUpdateDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ChannelMonitorUpdateDecodeErrorZ), "LDKCResult_ChannelMonitorUpdateDecodeErrorZ");
8300         *ret_conv = ChannelMonitorUpdate_read(ser_ref);
8301         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
8302         return (long)ret_conv;
8303 }
8304
8305 JNIEXPORT jclass JNICALL Java_org_ldk_impl_bindings_ChannelMonitorUpdateErr_1clone(JNIEnv * _env, jclass _b, jlong orig) {
8306         LDKChannelMonitorUpdateErr* orig_conv = (LDKChannelMonitorUpdateErr*)orig;
8307         jclass ret_conv = LDKChannelMonitorUpdateErr_to_java(_env, ChannelMonitorUpdateErr_clone(orig_conv));
8308         return ret_conv;
8309 }
8310
8311 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_MonitorUpdateError_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
8312         LDKMonitorUpdateError this_ptr_conv;
8313         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8314         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8315         MonitorUpdateError_free(this_ptr_conv);
8316 }
8317
8318 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_MonitorEvent_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
8319         LDKMonitorEvent this_ptr_conv;
8320         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8321         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8322         MonitorEvent_free(this_ptr_conv);
8323 }
8324
8325 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_MonitorEvent_1clone(JNIEnv * _env, jclass _b, jlong orig) {
8326         LDKMonitorEvent orig_conv;
8327         orig_conv.inner = (void*)(orig & (~1));
8328         orig_conv.is_owned = false;
8329         LDKMonitorEvent ret_var = MonitorEvent_clone(&orig_conv);
8330         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8331         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8332         long ret_ref = (long)ret_var.inner;
8333         if (ret_var.is_owned) {
8334                 ret_ref |= 1;
8335         }
8336         return ret_ref;
8337 }
8338
8339 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_HTLCUpdate_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
8340         LDKHTLCUpdate this_ptr_conv;
8341         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8342         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8343         HTLCUpdate_free(this_ptr_conv);
8344 }
8345
8346 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_HTLCUpdate_1clone(JNIEnv * _env, jclass _b, jlong orig) {
8347         LDKHTLCUpdate orig_conv;
8348         orig_conv.inner = (void*)(orig & (~1));
8349         orig_conv.is_owned = false;
8350         LDKHTLCUpdate ret_var = HTLCUpdate_clone(&orig_conv);
8351         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8352         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8353         long ret_ref = (long)ret_var.inner;
8354         if (ret_var.is_owned) {
8355                 ret_ref |= 1;
8356         }
8357         return ret_ref;
8358 }
8359
8360 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_HTLCUpdate_1write(JNIEnv * _env, jclass _b, jlong obj) {
8361         LDKHTLCUpdate obj_conv;
8362         obj_conv.inner = (void*)(obj & (~1));
8363         obj_conv.is_owned = false;
8364         LDKCVec_u8Z arg_var = HTLCUpdate_write(&obj_conv);
8365         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
8366         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
8367         CVec_u8Z_free(arg_var);
8368         return arg_arr;
8369 }
8370
8371 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_HTLCUpdate_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
8372         LDKu8slice ser_ref;
8373         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
8374         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
8375         LDKHTLCUpdate ret_var = HTLCUpdate_read(ser_ref);
8376         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8377         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8378         long ret_ref = (long)ret_var.inner;
8379         if (ret_var.is_owned) {
8380                 ret_ref |= 1;
8381         }
8382         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
8383         return ret_ref;
8384 }
8385
8386 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelMonitor_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
8387         LDKChannelMonitor this_ptr_conv;
8388         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8389         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8390         ChannelMonitor_free(this_ptr_conv);
8391 }
8392
8393 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelMonitor_1write(JNIEnv * _env, jclass _b, jlong obj) {
8394         LDKChannelMonitor obj_conv;
8395         obj_conv.inner = (void*)(obj & (~1));
8396         obj_conv.is_owned = false;
8397         LDKCVec_u8Z arg_var = ChannelMonitor_write(&obj_conv);
8398         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
8399         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
8400         CVec_u8Z_free(arg_var);
8401         return arg_arr;
8402 }
8403
8404 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelMonitor_1update_1monitor(JNIEnv * _env, jclass _b, jlong this_arg, jlong updates, jlong broadcaster, jlong fee_estimator, jlong logger) {
8405         LDKChannelMonitor this_arg_conv;
8406         this_arg_conv.inner = (void*)(this_arg & (~1));
8407         this_arg_conv.is_owned = false;
8408         LDKChannelMonitorUpdate updates_conv;
8409         updates_conv.inner = (void*)(updates & (~1));
8410         updates_conv.is_owned = false;
8411         LDKBroadcasterInterface* broadcaster_conv = (LDKBroadcasterInterface*)broadcaster;
8412         LDKFeeEstimator* fee_estimator_conv = (LDKFeeEstimator*)fee_estimator;
8413         LDKLogger* logger_conv = (LDKLogger*)logger;
8414         LDKCResult_NoneMonitorUpdateErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneMonitorUpdateErrorZ), "LDKCResult_NoneMonitorUpdateErrorZ");
8415         *ret_conv = ChannelMonitor_update_monitor(&this_arg_conv, &updates_conv, broadcaster_conv, fee_estimator_conv, logger_conv);
8416         return (long)ret_conv;
8417 }
8418
8419 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelMonitor_1get_1latest_1update_1id(JNIEnv * _env, jclass _b, jlong this_arg) {
8420         LDKChannelMonitor this_arg_conv;
8421         this_arg_conv.inner = (void*)(this_arg & (~1));
8422         this_arg_conv.is_owned = false;
8423         jlong ret_val = ChannelMonitor_get_latest_update_id(&this_arg_conv);
8424         return ret_val;
8425 }
8426
8427 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelMonitor_1get_1funding_1txo(JNIEnv * _env, jclass _b, jlong this_arg) {
8428         LDKChannelMonitor this_arg_conv;
8429         this_arg_conv.inner = (void*)(this_arg & (~1));
8430         this_arg_conv.is_owned = false;
8431         LDKC2Tuple_OutPointScriptZ* ret_ref = MALLOC(sizeof(LDKC2Tuple_OutPointScriptZ), "LDKC2Tuple_OutPointScriptZ");
8432         *ret_ref = ChannelMonitor_get_funding_txo(&this_arg_conv);
8433         return (long)ret_ref;
8434 }
8435
8436 JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_ChannelMonitor_1get_1and_1clear_1pending_1monitor_1events(JNIEnv * _env, jclass _b, jlong this_arg) {
8437         LDKChannelMonitor this_arg_conv;
8438         this_arg_conv.inner = (void*)(this_arg & (~1));
8439         this_arg_conv.is_owned = false;
8440         LDKCVec_MonitorEventZ ret_var = ChannelMonitor_get_and_clear_pending_monitor_events(&this_arg_conv);
8441         jlongArray ret_arr = (*_env)->NewLongArray(_env, ret_var.datalen);
8442         jlong *ret_arr_ptr = (*_env)->GetPrimitiveArrayCritical(_env, ret_arr, NULL);
8443         for (size_t o = 0; o < ret_var.datalen; o++) {
8444                 LDKMonitorEvent arr_conv_14_var = ret_var.data[o];
8445                 CHECK((((long)arr_conv_14_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8446                 CHECK((((long)&arr_conv_14_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8447                 long arr_conv_14_ref = (long)arr_conv_14_var.inner;
8448                 if (arr_conv_14_var.is_owned) {
8449                         arr_conv_14_ref |= 1;
8450                 }
8451                 ret_arr_ptr[o] = arr_conv_14_ref;
8452         }
8453         (*_env)->ReleasePrimitiveArrayCritical(_env, ret_arr, ret_arr_ptr, 0);
8454         FREE(ret_var.data);
8455         return ret_arr;
8456 }
8457
8458 JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_ChannelMonitor_1get_1and_1clear_1pending_1events(JNIEnv * _env, jclass _b, jlong this_arg) {
8459         LDKChannelMonitor this_arg_conv;
8460         this_arg_conv.inner = (void*)(this_arg & (~1));
8461         this_arg_conv.is_owned = false;
8462         LDKCVec_EventZ ret_var = ChannelMonitor_get_and_clear_pending_events(&this_arg_conv);
8463         jlongArray ret_arr = (*_env)->NewLongArray(_env, ret_var.datalen);
8464         jlong *ret_arr_ptr = (*_env)->GetPrimitiveArrayCritical(_env, ret_arr, NULL);
8465         for (size_t h = 0; h < ret_var.datalen; h++) {
8466                 LDKEvent *arr_conv_7_copy = MALLOC(sizeof(LDKEvent), "LDKEvent");
8467                 *arr_conv_7_copy = ret_var.data[h];
8468                 long arr_conv_7_ref = (long)arr_conv_7_copy;
8469                 ret_arr_ptr[h] = arr_conv_7_ref;
8470         }
8471         (*_env)->ReleasePrimitiveArrayCritical(_env, ret_arr, ret_arr_ptr, 0);
8472         FREE(ret_var.data);
8473         return ret_arr;
8474 }
8475
8476 JNIEXPORT jobjectArray JNICALL Java_org_ldk_impl_bindings_ChannelMonitor_1get_1latest_1holder_1commitment_1txn(JNIEnv * _env, jclass _b, jlong this_arg, jlong logger) {
8477         LDKChannelMonitor this_arg_conv;
8478         this_arg_conv.inner = (void*)(this_arg & (~1));
8479         this_arg_conv.is_owned = false;
8480         LDKLogger* logger_conv = (LDKLogger*)logger;
8481         LDKCVec_TransactionZ ret_var = ChannelMonitor_get_latest_holder_commitment_txn(&this_arg_conv, logger_conv);
8482         jobjectArray ret_arr = (*_env)->NewObjectArray(_env, ret_var.datalen, arr_of_B_clz, NULL);
8483         for (size_t i = 0; i < ret_var.datalen; i++) {
8484                 LDKTransaction arr_conv_8_var = ret_var.data[i];
8485                 jbyteArray arr_conv_8_arr = (*_env)->NewByteArray(_env, arr_conv_8_var.datalen);
8486                 (*_env)->SetByteArrayRegion(_env, arr_conv_8_arr, 0, arr_conv_8_var.datalen, arr_conv_8_var.data);
8487                 Transaction_free(arr_conv_8_var);
8488                 (*_env)->SetObjectArrayElement(_env, ret_arr, i, arr_conv_8_arr);
8489         }
8490         FREE(ret_var.data);
8491         return ret_arr;
8492 }
8493
8494 JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_ChannelMonitor_1block_1connected(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray header, jlongArray txdata, jint height, jlong broadcaster, jlong fee_estimator, jlong logger) {
8495         LDKChannelMonitor this_arg_conv;
8496         this_arg_conv.inner = (void*)(this_arg & (~1));
8497         this_arg_conv.is_owned = false;
8498         unsigned char header_arr[80];
8499         CHECK((*_env)->GetArrayLength (_env, header) == 80);
8500         (*_env)->GetByteArrayRegion (_env, header, 0, 80, header_arr);
8501         unsigned char (*header_ref)[80] = &header_arr;
8502         LDKCVec_C2Tuple_usizeTransactionZZ txdata_constr;
8503         txdata_constr.datalen = (*_env)->GetArrayLength (_env, txdata);
8504         if (txdata_constr.datalen > 0)
8505                 txdata_constr.data = MALLOC(txdata_constr.datalen * sizeof(LDKC2Tuple_usizeTransactionZ), "LDKCVec_C2Tuple_usizeTransactionZZ Elements");
8506         else
8507                 txdata_constr.data = NULL;
8508         long* txdata_vals = (*_env)->GetLongArrayElements (_env, txdata, NULL);
8509         for (size_t y = 0; y < txdata_constr.datalen; y++) {
8510                 long arr_conv_24 = txdata_vals[y];
8511                 LDKC2Tuple_usizeTransactionZ arr_conv_24_conv = *(LDKC2Tuple_usizeTransactionZ*)arr_conv_24;
8512                 FREE((void*)arr_conv_24);
8513                 txdata_constr.data[y] = arr_conv_24_conv;
8514         }
8515         (*_env)->ReleaseLongArrayElements (_env, txdata, txdata_vals, 0);
8516         LDKBroadcasterInterface broadcaster_conv = *(LDKBroadcasterInterface*)broadcaster;
8517         if (broadcaster_conv.free == LDKBroadcasterInterface_JCalls_free) {
8518                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
8519                 LDKBroadcasterInterface_JCalls_clone(broadcaster_conv.this_arg);
8520         }
8521         LDKFeeEstimator fee_estimator_conv = *(LDKFeeEstimator*)fee_estimator;
8522         if (fee_estimator_conv.free == LDKFeeEstimator_JCalls_free) {
8523                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
8524                 LDKFeeEstimator_JCalls_clone(fee_estimator_conv.this_arg);
8525         }
8526         LDKLogger logger_conv = *(LDKLogger*)logger;
8527         if (logger_conv.free == LDKLogger_JCalls_free) {
8528                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
8529                 LDKLogger_JCalls_clone(logger_conv.this_arg);
8530         }
8531         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);
8532         jlongArray ret_arr = (*_env)->NewLongArray(_env, ret_var.datalen);
8533         jlong *ret_arr_ptr = (*_env)->GetPrimitiveArrayCritical(_env, ret_arr, NULL);
8534         for (size_t u = 0; u < ret_var.datalen; u++) {
8535                 LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ* arr_conv_46_ref = MALLOC(sizeof(LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ), "LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ");
8536                 *arr_conv_46_ref = ret_var.data[u];
8537                 ret_arr_ptr[u] = (long)arr_conv_46_ref;
8538         }
8539         (*_env)->ReleasePrimitiveArrayCritical(_env, ret_arr, ret_arr_ptr, 0);
8540         FREE(ret_var.data);
8541         return ret_arr;
8542 }
8543
8544 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelMonitor_1block_1disconnected(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray header, jint height, jlong broadcaster, jlong fee_estimator, jlong logger) {
8545         LDKChannelMonitor this_arg_conv;
8546         this_arg_conv.inner = (void*)(this_arg & (~1));
8547         this_arg_conv.is_owned = false;
8548         unsigned char header_arr[80];
8549         CHECK((*_env)->GetArrayLength (_env, header) == 80);
8550         (*_env)->GetByteArrayRegion (_env, header, 0, 80, header_arr);
8551         unsigned char (*header_ref)[80] = &header_arr;
8552         LDKBroadcasterInterface broadcaster_conv = *(LDKBroadcasterInterface*)broadcaster;
8553         if (broadcaster_conv.free == LDKBroadcasterInterface_JCalls_free) {
8554                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
8555                 LDKBroadcasterInterface_JCalls_clone(broadcaster_conv.this_arg);
8556         }
8557         LDKFeeEstimator fee_estimator_conv = *(LDKFeeEstimator*)fee_estimator;
8558         if (fee_estimator_conv.free == LDKFeeEstimator_JCalls_free) {
8559                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
8560                 LDKFeeEstimator_JCalls_clone(fee_estimator_conv.this_arg);
8561         }
8562         LDKLogger logger_conv = *(LDKLogger*)logger;
8563         if (logger_conv.free == LDKLogger_JCalls_free) {
8564                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
8565                 LDKLogger_JCalls_clone(logger_conv.this_arg);
8566         }
8567         ChannelMonitor_block_disconnected(&this_arg_conv, header_ref, height, broadcaster_conv, fee_estimator_conv, logger_conv);
8568 }
8569
8570 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Persist_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
8571         LDKPersist this_ptr_conv = *(LDKPersist*)this_ptr;
8572         FREE((void*)this_ptr);
8573         Persist_free(this_ptr_conv);
8574 }
8575
8576 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_C2Tuple_1BlockHashChannelMonitorZ_1read(JNIEnv * _env, jclass _b, jbyteArray ser, jlong arg) {
8577         LDKu8slice ser_ref;
8578         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
8579         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
8580         LDKKeysInterface* arg_conv = (LDKKeysInterface*)arg;
8581         LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ), "LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ");
8582         *ret_conv = C2Tuple_BlockHashChannelMonitorZ_read(ser_ref, arg_conv);
8583         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
8584         return (long)ret_conv;
8585 }
8586
8587 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OutPoint_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
8588         LDKOutPoint this_ptr_conv;
8589         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8590         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8591         OutPoint_free(this_ptr_conv);
8592 }
8593
8594 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_OutPoint_1clone(JNIEnv * _env, jclass _b, jlong orig) {
8595         LDKOutPoint orig_conv;
8596         orig_conv.inner = (void*)(orig & (~1));
8597         orig_conv.is_owned = false;
8598         LDKOutPoint ret_var = OutPoint_clone(&orig_conv);
8599         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8600         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8601         long ret_ref = (long)ret_var.inner;
8602         if (ret_var.is_owned) {
8603                 ret_ref |= 1;
8604         }
8605         return ret_ref;
8606 }
8607
8608 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_OutPoint_1get_1txid(JNIEnv * _env, jclass _b, jlong this_ptr) {
8609         LDKOutPoint this_ptr_conv;
8610         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8611         this_ptr_conv.is_owned = false;
8612         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
8613         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *OutPoint_get_txid(&this_ptr_conv));
8614         return ret_arr;
8615 }
8616
8617 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OutPoint_1set_1txid(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
8618         LDKOutPoint this_ptr_conv;
8619         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8620         this_ptr_conv.is_owned = false;
8621         LDKThirtyTwoBytes val_ref;
8622         CHECK((*_env)->GetArrayLength (_env, val) == 32);
8623         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
8624         OutPoint_set_txid(&this_ptr_conv, val_ref);
8625 }
8626
8627 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_OutPoint_1get_1index(JNIEnv * _env, jclass _b, jlong this_ptr) {
8628         LDKOutPoint this_ptr_conv;
8629         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8630         this_ptr_conv.is_owned = false;
8631         jshort ret_val = OutPoint_get_index(&this_ptr_conv);
8632         return ret_val;
8633 }
8634
8635 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OutPoint_1set_1index(JNIEnv * _env, jclass _b, jlong this_ptr, jshort val) {
8636         LDKOutPoint this_ptr_conv;
8637         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8638         this_ptr_conv.is_owned = false;
8639         OutPoint_set_index(&this_ptr_conv, val);
8640 }
8641
8642 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_OutPoint_1new(JNIEnv * _env, jclass _b, jbyteArray txid_arg, jshort index_arg) {
8643         LDKThirtyTwoBytes txid_arg_ref;
8644         CHECK((*_env)->GetArrayLength (_env, txid_arg) == 32);
8645         (*_env)->GetByteArrayRegion (_env, txid_arg, 0, 32, txid_arg_ref.data);
8646         LDKOutPoint ret_var = OutPoint_new(txid_arg_ref, index_arg);
8647         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8648         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8649         long ret_ref = (long)ret_var.inner;
8650         if (ret_var.is_owned) {
8651                 ret_ref |= 1;
8652         }
8653         return ret_ref;
8654 }
8655
8656 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_OutPoint_1to_1channel_1id(JNIEnv * _env, jclass _b, jlong this_arg) {
8657         LDKOutPoint this_arg_conv;
8658         this_arg_conv.inner = (void*)(this_arg & (~1));
8659         this_arg_conv.is_owned = false;
8660         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 32);
8661         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 32, OutPoint_to_channel_id(&this_arg_conv).data);
8662         return arg_arr;
8663 }
8664
8665 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_OutPoint_1write(JNIEnv * _env, jclass _b, jlong obj) {
8666         LDKOutPoint obj_conv;
8667         obj_conv.inner = (void*)(obj & (~1));
8668         obj_conv.is_owned = false;
8669         LDKCVec_u8Z arg_var = OutPoint_write(&obj_conv);
8670         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
8671         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
8672         CVec_u8Z_free(arg_var);
8673         return arg_arr;
8674 }
8675
8676 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_OutPoint_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
8677         LDKu8slice ser_ref;
8678         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
8679         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
8680         LDKOutPoint ret_var = OutPoint_read(ser_ref);
8681         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8682         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8683         long ret_ref = (long)ret_var.inner;
8684         if (ret_var.is_owned) {
8685                 ret_ref |= 1;
8686         }
8687         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
8688         return ret_ref;
8689 }
8690
8691 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_SpendableOutputDescriptor_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
8692         LDKSpendableOutputDescriptor this_ptr_conv = *(LDKSpendableOutputDescriptor*)this_ptr;
8693         FREE((void*)this_ptr);
8694         SpendableOutputDescriptor_free(this_ptr_conv);
8695 }
8696
8697 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_SpendableOutputDescriptor_1clone(JNIEnv * _env, jclass _b, jlong orig) {
8698         LDKSpendableOutputDescriptor* orig_conv = (LDKSpendableOutputDescriptor*)orig;
8699         LDKSpendableOutputDescriptor *ret_copy = MALLOC(sizeof(LDKSpendableOutputDescriptor), "LDKSpendableOutputDescriptor");
8700         *ret_copy = SpendableOutputDescriptor_clone(orig_conv);
8701         long ret_ref = (long)ret_copy;
8702         return ret_ref;
8703 }
8704
8705 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_SpendableOutputDescriptor_1write(JNIEnv * _env, jclass _b, jlong obj) {
8706         LDKSpendableOutputDescriptor* obj_conv = (LDKSpendableOutputDescriptor*)obj;
8707         LDKCVec_u8Z arg_var = SpendableOutputDescriptor_write(obj_conv);
8708         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
8709         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
8710         CVec_u8Z_free(arg_var);
8711         return arg_arr;
8712 }
8713
8714 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_SpendableOutputDescriptor_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
8715         LDKu8slice ser_ref;
8716         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
8717         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
8718         LDKCResult_SpendableOutputDescriptorDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_SpendableOutputDescriptorDecodeErrorZ), "LDKCResult_SpendableOutputDescriptorDecodeErrorZ");
8719         *ret_conv = SpendableOutputDescriptor_read(ser_ref);
8720         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
8721         return (long)ret_conv;
8722 }
8723
8724 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1clone(JNIEnv * _env, jclass _b, jlong orig) {
8725         LDKChannelKeys* orig_conv = (LDKChannelKeys*)orig;
8726         LDKChannelKeys* ret = MALLOC(sizeof(LDKChannelKeys), "LDKChannelKeys");
8727         *ret = ChannelKeys_clone(orig_conv);
8728         return (long)ret;
8729 }
8730
8731 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
8732         LDKChannelKeys this_ptr_conv = *(LDKChannelKeys*)this_ptr;
8733         FREE((void*)this_ptr);
8734         ChannelKeys_free(this_ptr_conv);
8735 }
8736
8737 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_KeysInterface_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
8738         LDKKeysInterface this_ptr_conv = *(LDKKeysInterface*)this_ptr;
8739         FREE((void*)this_ptr);
8740         KeysInterface_free(this_ptr_conv);
8741 }
8742
8743 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
8744         LDKInMemoryChannelKeys this_ptr_conv;
8745         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8746         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8747         InMemoryChannelKeys_free(this_ptr_conv);
8748 }
8749
8750 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1clone(JNIEnv * _env, jclass _b, jlong orig) {
8751         LDKInMemoryChannelKeys orig_conv;
8752         orig_conv.inner = (void*)(orig & (~1));
8753         orig_conv.is_owned = false;
8754         LDKInMemoryChannelKeys ret_var = InMemoryChannelKeys_clone(&orig_conv);
8755         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8756         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8757         long ret_ref = (long)ret_var.inner;
8758         if (ret_var.is_owned) {
8759                 ret_ref |= 1;
8760         }
8761         return ret_ref;
8762 }
8763
8764 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1get_1funding_1key(JNIEnv * _env, jclass _b, jlong this_ptr) {
8765         LDKInMemoryChannelKeys this_ptr_conv;
8766         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8767         this_ptr_conv.is_owned = false;
8768         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
8769         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *InMemoryChannelKeys_get_funding_key(&this_ptr_conv));
8770         return ret_arr;
8771 }
8772
8773 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1set_1funding_1key(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
8774         LDKInMemoryChannelKeys this_ptr_conv;
8775         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8776         this_ptr_conv.is_owned = false;
8777         LDKSecretKey val_ref;
8778         CHECK((*_env)->GetArrayLength (_env, val) == 32);
8779         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.bytes);
8780         InMemoryChannelKeys_set_funding_key(&this_ptr_conv, val_ref);
8781 }
8782
8783 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1get_1revocation_1base_1key(JNIEnv * _env, jclass _b, jlong this_ptr) {
8784         LDKInMemoryChannelKeys this_ptr_conv;
8785         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8786         this_ptr_conv.is_owned = false;
8787         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
8788         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *InMemoryChannelKeys_get_revocation_base_key(&this_ptr_conv));
8789         return ret_arr;
8790 }
8791
8792 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1set_1revocation_1base_1key(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
8793         LDKInMemoryChannelKeys this_ptr_conv;
8794         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8795         this_ptr_conv.is_owned = false;
8796         LDKSecretKey val_ref;
8797         CHECK((*_env)->GetArrayLength (_env, val) == 32);
8798         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.bytes);
8799         InMemoryChannelKeys_set_revocation_base_key(&this_ptr_conv, val_ref);
8800 }
8801
8802 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1get_1payment_1key(JNIEnv * _env, jclass _b, jlong this_ptr) {
8803         LDKInMemoryChannelKeys this_ptr_conv;
8804         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8805         this_ptr_conv.is_owned = false;
8806         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
8807         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *InMemoryChannelKeys_get_payment_key(&this_ptr_conv));
8808         return ret_arr;
8809 }
8810
8811 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1set_1payment_1key(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
8812         LDKInMemoryChannelKeys this_ptr_conv;
8813         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8814         this_ptr_conv.is_owned = false;
8815         LDKSecretKey val_ref;
8816         CHECK((*_env)->GetArrayLength (_env, val) == 32);
8817         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.bytes);
8818         InMemoryChannelKeys_set_payment_key(&this_ptr_conv, val_ref);
8819 }
8820
8821 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1get_1delayed_1payment_1base_1key(JNIEnv * _env, jclass _b, jlong this_ptr) {
8822         LDKInMemoryChannelKeys this_ptr_conv;
8823         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8824         this_ptr_conv.is_owned = false;
8825         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
8826         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *InMemoryChannelKeys_get_delayed_payment_base_key(&this_ptr_conv));
8827         return ret_arr;
8828 }
8829
8830 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1set_1delayed_1payment_1base_1key(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
8831         LDKInMemoryChannelKeys this_ptr_conv;
8832         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8833         this_ptr_conv.is_owned = false;
8834         LDKSecretKey val_ref;
8835         CHECK((*_env)->GetArrayLength (_env, val) == 32);
8836         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.bytes);
8837         InMemoryChannelKeys_set_delayed_payment_base_key(&this_ptr_conv, val_ref);
8838 }
8839
8840 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1get_1htlc_1base_1key(JNIEnv * _env, jclass _b, jlong this_ptr) {
8841         LDKInMemoryChannelKeys this_ptr_conv;
8842         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8843         this_ptr_conv.is_owned = false;
8844         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
8845         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *InMemoryChannelKeys_get_htlc_base_key(&this_ptr_conv));
8846         return ret_arr;
8847 }
8848
8849 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1set_1htlc_1base_1key(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
8850         LDKInMemoryChannelKeys this_ptr_conv;
8851         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8852         this_ptr_conv.is_owned = false;
8853         LDKSecretKey val_ref;
8854         CHECK((*_env)->GetArrayLength (_env, val) == 32);
8855         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.bytes);
8856         InMemoryChannelKeys_set_htlc_base_key(&this_ptr_conv, val_ref);
8857 }
8858
8859 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1get_1commitment_1seed(JNIEnv * _env, jclass _b, jlong this_ptr) {
8860         LDKInMemoryChannelKeys this_ptr_conv;
8861         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8862         this_ptr_conv.is_owned = false;
8863         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
8864         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *InMemoryChannelKeys_get_commitment_seed(&this_ptr_conv));
8865         return ret_arr;
8866 }
8867
8868 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1set_1commitment_1seed(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
8869         LDKInMemoryChannelKeys this_ptr_conv;
8870         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8871         this_ptr_conv.is_owned = false;
8872         LDKThirtyTwoBytes val_ref;
8873         CHECK((*_env)->GetArrayLength (_env, val) == 32);
8874         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
8875         InMemoryChannelKeys_set_commitment_seed(&this_ptr_conv, val_ref);
8876 }
8877
8878 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1new(JNIEnv * _env, jclass _b, jbyteArray funding_key, jbyteArray revocation_base_key, jbyteArray payment_key, jbyteArray delayed_payment_base_key, jbyteArray htlc_base_key, jbyteArray commitment_seed, jlong channel_value_satoshis, jlong key_derivation_params) {
8879         LDKSecretKey funding_key_ref;
8880         CHECK((*_env)->GetArrayLength (_env, funding_key) == 32);
8881         (*_env)->GetByteArrayRegion (_env, funding_key, 0, 32, funding_key_ref.bytes);
8882         LDKSecretKey revocation_base_key_ref;
8883         CHECK((*_env)->GetArrayLength (_env, revocation_base_key) == 32);
8884         (*_env)->GetByteArrayRegion (_env, revocation_base_key, 0, 32, revocation_base_key_ref.bytes);
8885         LDKSecretKey payment_key_ref;
8886         CHECK((*_env)->GetArrayLength (_env, payment_key) == 32);
8887         (*_env)->GetByteArrayRegion (_env, payment_key, 0, 32, payment_key_ref.bytes);
8888         LDKSecretKey delayed_payment_base_key_ref;
8889         CHECK((*_env)->GetArrayLength (_env, delayed_payment_base_key) == 32);
8890         (*_env)->GetByteArrayRegion (_env, delayed_payment_base_key, 0, 32, delayed_payment_base_key_ref.bytes);
8891         LDKSecretKey htlc_base_key_ref;
8892         CHECK((*_env)->GetArrayLength (_env, htlc_base_key) == 32);
8893         (*_env)->GetByteArrayRegion (_env, htlc_base_key, 0, 32, htlc_base_key_ref.bytes);
8894         LDKThirtyTwoBytes commitment_seed_ref;
8895         CHECK((*_env)->GetArrayLength (_env, commitment_seed) == 32);
8896         (*_env)->GetByteArrayRegion (_env, commitment_seed, 0, 32, commitment_seed_ref.data);
8897         LDKC2Tuple_u64u64Z key_derivation_params_conv = *(LDKC2Tuple_u64u64Z*)key_derivation_params;
8898         FREE((void*)key_derivation_params);
8899         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);
8900         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8901         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8902         long ret_ref = (long)ret_var.inner;
8903         if (ret_var.is_owned) {
8904                 ret_ref |= 1;
8905         }
8906         return ret_ref;
8907 }
8908
8909 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1counterparty_1pubkeys(JNIEnv * _env, jclass _b, jlong this_arg) {
8910         LDKInMemoryChannelKeys this_arg_conv;
8911         this_arg_conv.inner = (void*)(this_arg & (~1));
8912         this_arg_conv.is_owned = false;
8913         LDKChannelPublicKeys ret_var = InMemoryChannelKeys_counterparty_pubkeys(&this_arg_conv);
8914         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8915         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8916         long ret_ref = (long)ret_var.inner;
8917         if (ret_var.is_owned) {
8918                 ret_ref |= 1;
8919         }
8920         return ret_ref;
8921 }
8922
8923 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1counterparty_1selected_1contest_1delay(JNIEnv * _env, jclass _b, jlong this_arg) {
8924         LDKInMemoryChannelKeys this_arg_conv;
8925         this_arg_conv.inner = (void*)(this_arg & (~1));
8926         this_arg_conv.is_owned = false;
8927         jshort ret_val = InMemoryChannelKeys_counterparty_selected_contest_delay(&this_arg_conv);
8928         return ret_val;
8929 }
8930
8931 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1holder_1selected_1contest_1delay(JNIEnv * _env, jclass _b, jlong this_arg) {
8932         LDKInMemoryChannelKeys this_arg_conv;
8933         this_arg_conv.inner = (void*)(this_arg & (~1));
8934         this_arg_conv.is_owned = false;
8935         jshort ret_val = InMemoryChannelKeys_holder_selected_contest_delay(&this_arg_conv);
8936         return ret_val;
8937 }
8938
8939 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1is_1outbound(JNIEnv * _env, jclass _b, jlong this_arg) {
8940         LDKInMemoryChannelKeys this_arg_conv;
8941         this_arg_conv.inner = (void*)(this_arg & (~1));
8942         this_arg_conv.is_owned = false;
8943         jboolean ret_val = InMemoryChannelKeys_is_outbound(&this_arg_conv);
8944         return ret_val;
8945 }
8946
8947 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1funding_1outpoint(JNIEnv * _env, jclass _b, jlong this_arg) {
8948         LDKInMemoryChannelKeys this_arg_conv;
8949         this_arg_conv.inner = (void*)(this_arg & (~1));
8950         this_arg_conv.is_owned = false;
8951         LDKOutPoint ret_var = InMemoryChannelKeys_funding_outpoint(&this_arg_conv);
8952         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8953         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8954         long ret_ref = (long)ret_var.inner;
8955         if (ret_var.is_owned) {
8956                 ret_ref |= 1;
8957         }
8958         return ret_ref;
8959 }
8960
8961 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1get_1channel_1parameters(JNIEnv * _env, jclass _b, jlong this_arg) {
8962         LDKInMemoryChannelKeys this_arg_conv;
8963         this_arg_conv.inner = (void*)(this_arg & (~1));
8964         this_arg_conv.is_owned = false;
8965         LDKChannelTransactionParameters ret_var = InMemoryChannelKeys_get_channel_parameters(&this_arg_conv);
8966         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8967         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8968         long ret_ref = (long)ret_var.inner;
8969         if (ret_var.is_owned) {
8970                 ret_ref |= 1;
8971         }
8972         return ret_ref;
8973 }
8974
8975 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1as_1ChannelKeys(JNIEnv * _env, jclass _b, jlong this_arg) {
8976         LDKInMemoryChannelKeys this_arg_conv;
8977         this_arg_conv.inner = (void*)(this_arg & (~1));
8978         this_arg_conv.is_owned = false;
8979         LDKChannelKeys* ret = MALLOC(sizeof(LDKChannelKeys), "LDKChannelKeys");
8980         *ret = InMemoryChannelKeys_as_ChannelKeys(&this_arg_conv);
8981         return (long)ret;
8982 }
8983
8984 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1write(JNIEnv * _env, jclass _b, jlong obj) {
8985         LDKInMemoryChannelKeys obj_conv;
8986         obj_conv.inner = (void*)(obj & (~1));
8987         obj_conv.is_owned = false;
8988         LDKCVec_u8Z arg_var = InMemoryChannelKeys_write(&obj_conv);
8989         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
8990         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
8991         CVec_u8Z_free(arg_var);
8992         return arg_arr;
8993 }
8994
8995 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
8996         LDKu8slice ser_ref;
8997         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
8998         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
8999         LDKCResult_InMemoryChannelKeysDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_InMemoryChannelKeysDecodeErrorZ), "LDKCResult_InMemoryChannelKeysDecodeErrorZ");
9000         *ret_conv = InMemoryChannelKeys_read(ser_ref);
9001         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
9002         return (long)ret_conv;
9003 }
9004
9005 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_KeysManager_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
9006         LDKKeysManager this_ptr_conv;
9007         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9008         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9009         KeysManager_free(this_ptr_conv);
9010 }
9011
9012 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_KeysManager_1new(JNIEnv * _env, jclass _b, jbyteArray seed, jclass network, jlong starting_time_secs, jint starting_time_nanos) {
9013         unsigned char seed_arr[32];
9014         CHECK((*_env)->GetArrayLength (_env, seed) == 32);
9015         (*_env)->GetByteArrayRegion (_env, seed, 0, 32, seed_arr);
9016         unsigned char (*seed_ref)[32] = &seed_arr;
9017         LDKNetwork network_conv = LDKNetwork_from_java(_env, network);
9018         LDKKeysManager ret_var = KeysManager_new(seed_ref, network_conv, starting_time_secs, starting_time_nanos);
9019         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9020         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9021         long ret_ref = (long)ret_var.inner;
9022         if (ret_var.is_owned) {
9023                 ret_ref |= 1;
9024         }
9025         return ret_ref;
9026 }
9027
9028 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_KeysManager_1derive_1channel_1keys(JNIEnv * _env, jclass _b, jlong this_arg, jlong channel_value_satoshis, jlong params_1, jlong params_2) {
9029         LDKKeysManager this_arg_conv;
9030         this_arg_conv.inner = (void*)(this_arg & (~1));
9031         this_arg_conv.is_owned = false;
9032         LDKInMemoryChannelKeys ret_var = KeysManager_derive_channel_keys(&this_arg_conv, channel_value_satoshis, params_1, params_2);
9033         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9034         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9035         long ret_ref = (long)ret_var.inner;
9036         if (ret_var.is_owned) {
9037                 ret_ref |= 1;
9038         }
9039         return ret_ref;
9040 }
9041
9042 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_KeysManager_1as_1KeysInterface(JNIEnv * _env, jclass _b, jlong this_arg) {
9043         LDKKeysManager this_arg_conv;
9044         this_arg_conv.inner = (void*)(this_arg & (~1));
9045         this_arg_conv.is_owned = false;
9046         LDKKeysInterface* ret = MALLOC(sizeof(LDKKeysInterface), "LDKKeysInterface");
9047         *ret = KeysManager_as_KeysInterface(&this_arg_conv);
9048         return (long)ret;
9049 }
9050
9051 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelManager_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
9052         LDKChannelManager this_ptr_conv;
9053         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9054         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9055         ChannelManager_free(this_ptr_conv);
9056 }
9057
9058 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
9059         LDKChannelDetails this_ptr_conv;
9060         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9061         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9062         ChannelDetails_free(this_ptr_conv);
9063 }
9064
9065 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1clone(JNIEnv * _env, jclass _b, jlong orig) {
9066         LDKChannelDetails orig_conv;
9067         orig_conv.inner = (void*)(orig & (~1));
9068         orig_conv.is_owned = false;
9069         LDKChannelDetails ret_var = ChannelDetails_clone(&orig_conv);
9070         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9071         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9072         long ret_ref = (long)ret_var.inner;
9073         if (ret_var.is_owned) {
9074                 ret_ref |= 1;
9075         }
9076         return ret_ref;
9077 }
9078
9079 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1get_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
9080         LDKChannelDetails this_ptr_conv;
9081         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9082         this_ptr_conv.is_owned = false;
9083         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
9084         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *ChannelDetails_get_channel_id(&this_ptr_conv));
9085         return ret_arr;
9086 }
9087
9088 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1set_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
9089         LDKChannelDetails this_ptr_conv;
9090         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9091         this_ptr_conv.is_owned = false;
9092         LDKThirtyTwoBytes val_ref;
9093         CHECK((*_env)->GetArrayLength (_env, val) == 32);
9094         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
9095         ChannelDetails_set_channel_id(&this_ptr_conv, val_ref);
9096 }
9097
9098 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1get_1remote_1network_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
9099         LDKChannelDetails this_ptr_conv;
9100         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9101         this_ptr_conv.is_owned = false;
9102         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
9103         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, ChannelDetails_get_remote_network_id(&this_ptr_conv).compressed_form);
9104         return arg_arr;
9105 }
9106
9107 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1set_1remote_1network_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
9108         LDKChannelDetails this_ptr_conv;
9109         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9110         this_ptr_conv.is_owned = false;
9111         LDKPublicKey val_ref;
9112         CHECK((*_env)->GetArrayLength (_env, val) == 33);
9113         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
9114         ChannelDetails_set_remote_network_id(&this_ptr_conv, val_ref);
9115 }
9116
9117 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1get_1counterparty_1features(JNIEnv * _env, jclass _b, jlong this_ptr) {
9118         LDKChannelDetails this_ptr_conv;
9119         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9120         this_ptr_conv.is_owned = false;
9121         LDKInitFeatures ret_var = ChannelDetails_get_counterparty_features(&this_ptr_conv);
9122         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9123         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9124         long ret_ref = (long)ret_var.inner;
9125         if (ret_var.is_owned) {
9126                 ret_ref |= 1;
9127         }
9128         return ret_ref;
9129 }
9130
9131 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1set_1counterparty_1features(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
9132         LDKChannelDetails this_ptr_conv;
9133         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9134         this_ptr_conv.is_owned = false;
9135         LDKInitFeatures val_conv;
9136         val_conv.inner = (void*)(val & (~1));
9137         val_conv.is_owned = (val & 1) || (val == 0);
9138         // Warning: we may need a move here but can't clone!
9139         ChannelDetails_set_counterparty_features(&this_ptr_conv, val_conv);
9140 }
9141
9142 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1get_1channel_1value_1satoshis(JNIEnv * _env, jclass _b, jlong this_ptr) {
9143         LDKChannelDetails this_ptr_conv;
9144         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9145         this_ptr_conv.is_owned = false;
9146         jlong ret_val = ChannelDetails_get_channel_value_satoshis(&this_ptr_conv);
9147         return ret_val;
9148 }
9149
9150 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1set_1channel_1value_1satoshis(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
9151         LDKChannelDetails this_ptr_conv;
9152         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9153         this_ptr_conv.is_owned = false;
9154         ChannelDetails_set_channel_value_satoshis(&this_ptr_conv, val);
9155 }
9156
9157 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1get_1user_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
9158         LDKChannelDetails this_ptr_conv;
9159         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9160         this_ptr_conv.is_owned = false;
9161         jlong ret_val = ChannelDetails_get_user_id(&this_ptr_conv);
9162         return ret_val;
9163 }
9164
9165 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1set_1user_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
9166         LDKChannelDetails this_ptr_conv;
9167         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9168         this_ptr_conv.is_owned = false;
9169         ChannelDetails_set_user_id(&this_ptr_conv, val);
9170 }
9171
9172 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1get_1outbound_1capacity_1msat(JNIEnv * _env, jclass _b, jlong this_ptr) {
9173         LDKChannelDetails this_ptr_conv;
9174         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9175         this_ptr_conv.is_owned = false;
9176         jlong ret_val = ChannelDetails_get_outbound_capacity_msat(&this_ptr_conv);
9177         return ret_val;
9178 }
9179
9180 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1set_1outbound_1capacity_1msat(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
9181         LDKChannelDetails this_ptr_conv;
9182         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9183         this_ptr_conv.is_owned = false;
9184         ChannelDetails_set_outbound_capacity_msat(&this_ptr_conv, val);
9185 }
9186
9187 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1get_1inbound_1capacity_1msat(JNIEnv * _env, jclass _b, jlong this_ptr) {
9188         LDKChannelDetails this_ptr_conv;
9189         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9190         this_ptr_conv.is_owned = false;
9191         jlong ret_val = ChannelDetails_get_inbound_capacity_msat(&this_ptr_conv);
9192         return ret_val;
9193 }
9194
9195 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1set_1inbound_1capacity_1msat(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
9196         LDKChannelDetails this_ptr_conv;
9197         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9198         this_ptr_conv.is_owned = false;
9199         ChannelDetails_set_inbound_capacity_msat(&this_ptr_conv, val);
9200 }
9201
9202 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1get_1is_1live(JNIEnv * _env, jclass _b, jlong this_ptr) {
9203         LDKChannelDetails this_ptr_conv;
9204         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9205         this_ptr_conv.is_owned = false;
9206         jboolean ret_val = ChannelDetails_get_is_live(&this_ptr_conv);
9207         return ret_val;
9208 }
9209
9210 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1set_1is_1live(JNIEnv * _env, jclass _b, jlong this_ptr, jboolean val) {
9211         LDKChannelDetails this_ptr_conv;
9212         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9213         this_ptr_conv.is_owned = false;
9214         ChannelDetails_set_is_live(&this_ptr_conv, val);
9215 }
9216
9217 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_PaymentSendFailure_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
9218         LDKPaymentSendFailure this_ptr_conv;
9219         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9220         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9221         PaymentSendFailure_free(this_ptr_conv);
9222 }
9223
9224 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelManager_1new(JNIEnv * _env, jclass _b, jclass network, jlong fee_est, jlong chain_monitor, jlong tx_broadcaster, jlong logger, jlong keys_manager, jlong config, jlong current_blockchain_height) {
9225         LDKNetwork network_conv = LDKNetwork_from_java(_env, network);
9226         LDKFeeEstimator fee_est_conv = *(LDKFeeEstimator*)fee_est;
9227         if (fee_est_conv.free == LDKFeeEstimator_JCalls_free) {
9228                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
9229                 LDKFeeEstimator_JCalls_clone(fee_est_conv.this_arg);
9230         }
9231         LDKWatch chain_monitor_conv = *(LDKWatch*)chain_monitor;
9232         if (chain_monitor_conv.free == LDKWatch_JCalls_free) {
9233                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
9234                 LDKWatch_JCalls_clone(chain_monitor_conv.this_arg);
9235         }
9236         LDKBroadcasterInterface tx_broadcaster_conv = *(LDKBroadcasterInterface*)tx_broadcaster;
9237         if (tx_broadcaster_conv.free == LDKBroadcasterInterface_JCalls_free) {
9238                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
9239                 LDKBroadcasterInterface_JCalls_clone(tx_broadcaster_conv.this_arg);
9240         }
9241         LDKLogger logger_conv = *(LDKLogger*)logger;
9242         if (logger_conv.free == LDKLogger_JCalls_free) {
9243                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
9244                 LDKLogger_JCalls_clone(logger_conv.this_arg);
9245         }
9246         LDKKeysInterface keys_manager_conv = *(LDKKeysInterface*)keys_manager;
9247         if (keys_manager_conv.free == LDKKeysInterface_JCalls_free) {
9248                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
9249                 LDKKeysInterface_JCalls_clone(keys_manager_conv.this_arg);
9250         }
9251         LDKUserConfig config_conv;
9252         config_conv.inner = (void*)(config & (~1));
9253         config_conv.is_owned = (config & 1) || (config == 0);
9254         if (config_conv.inner != NULL)
9255                 config_conv = UserConfig_clone(&config_conv);
9256         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);
9257         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9258         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9259         long ret_ref = (long)ret_var.inner;
9260         if (ret_var.is_owned) {
9261                 ret_ref |= 1;
9262         }
9263         return ret_ref;
9264 }
9265
9266 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelManager_1create_1channel(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray their_network_key, jlong channel_value_satoshis, jlong push_msat, jlong user_id, jlong override_config) {
9267         LDKChannelManager this_arg_conv;
9268         this_arg_conv.inner = (void*)(this_arg & (~1));
9269         this_arg_conv.is_owned = false;
9270         LDKPublicKey their_network_key_ref;
9271         CHECK((*_env)->GetArrayLength (_env, their_network_key) == 33);
9272         (*_env)->GetByteArrayRegion (_env, their_network_key, 0, 33, their_network_key_ref.compressed_form);
9273         LDKUserConfig override_config_conv;
9274         override_config_conv.inner = (void*)(override_config & (~1));
9275         override_config_conv.is_owned = (override_config & 1) || (override_config == 0);
9276         if (override_config_conv.inner != NULL)
9277                 override_config_conv = UserConfig_clone(&override_config_conv);
9278         LDKCResult_NoneAPIErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneAPIErrorZ), "LDKCResult_NoneAPIErrorZ");
9279         *ret_conv = ChannelManager_create_channel(&this_arg_conv, their_network_key_ref, channel_value_satoshis, push_msat, user_id, override_config_conv);
9280         return (long)ret_conv;
9281 }
9282
9283 JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_ChannelManager_1list_1channels(JNIEnv * _env, jclass _b, jlong this_arg) {
9284         LDKChannelManager this_arg_conv;
9285         this_arg_conv.inner = (void*)(this_arg & (~1));
9286         this_arg_conv.is_owned = false;
9287         LDKCVec_ChannelDetailsZ ret_var = ChannelManager_list_channels(&this_arg_conv);
9288         jlongArray ret_arr = (*_env)->NewLongArray(_env, ret_var.datalen);
9289         jlong *ret_arr_ptr = (*_env)->GetPrimitiveArrayCritical(_env, ret_arr, NULL);
9290         for (size_t q = 0; q < ret_var.datalen; q++) {
9291                 LDKChannelDetails arr_conv_16_var = ret_var.data[q];
9292                 CHECK((((long)arr_conv_16_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9293                 CHECK((((long)&arr_conv_16_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9294                 long arr_conv_16_ref = (long)arr_conv_16_var.inner;
9295                 if (arr_conv_16_var.is_owned) {
9296                         arr_conv_16_ref |= 1;
9297                 }
9298                 ret_arr_ptr[q] = arr_conv_16_ref;
9299         }
9300         (*_env)->ReleasePrimitiveArrayCritical(_env, ret_arr, ret_arr_ptr, 0);
9301         FREE(ret_var.data);
9302         return ret_arr;
9303 }
9304
9305 JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_ChannelManager_1list_1usable_1channels(JNIEnv * _env, jclass _b, jlong this_arg) {
9306         LDKChannelManager this_arg_conv;
9307         this_arg_conv.inner = (void*)(this_arg & (~1));
9308         this_arg_conv.is_owned = false;
9309         LDKCVec_ChannelDetailsZ ret_var = ChannelManager_list_usable_channels(&this_arg_conv);
9310         jlongArray ret_arr = (*_env)->NewLongArray(_env, ret_var.datalen);
9311         jlong *ret_arr_ptr = (*_env)->GetPrimitiveArrayCritical(_env, ret_arr, NULL);
9312         for (size_t q = 0; q < ret_var.datalen; q++) {
9313                 LDKChannelDetails arr_conv_16_var = ret_var.data[q];
9314                 CHECK((((long)arr_conv_16_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9315                 CHECK((((long)&arr_conv_16_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9316                 long arr_conv_16_ref = (long)arr_conv_16_var.inner;
9317                 if (arr_conv_16_var.is_owned) {
9318                         arr_conv_16_ref |= 1;
9319                 }
9320                 ret_arr_ptr[q] = arr_conv_16_ref;
9321         }
9322         (*_env)->ReleasePrimitiveArrayCritical(_env, ret_arr, ret_arr_ptr, 0);
9323         FREE(ret_var.data);
9324         return ret_arr;
9325 }
9326
9327 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelManager_1close_1channel(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray channel_id) {
9328         LDKChannelManager this_arg_conv;
9329         this_arg_conv.inner = (void*)(this_arg & (~1));
9330         this_arg_conv.is_owned = false;
9331         unsigned char channel_id_arr[32];
9332         CHECK((*_env)->GetArrayLength (_env, channel_id) == 32);
9333         (*_env)->GetByteArrayRegion (_env, channel_id, 0, 32, channel_id_arr);
9334         unsigned char (*channel_id_ref)[32] = &channel_id_arr;
9335         LDKCResult_NoneAPIErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneAPIErrorZ), "LDKCResult_NoneAPIErrorZ");
9336         *ret_conv = ChannelManager_close_channel(&this_arg_conv, channel_id_ref);
9337         return (long)ret_conv;
9338 }
9339
9340 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelManager_1force_1close_1channel(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray channel_id) {
9341         LDKChannelManager this_arg_conv;
9342         this_arg_conv.inner = (void*)(this_arg & (~1));
9343         this_arg_conv.is_owned = false;
9344         unsigned char channel_id_arr[32];
9345         CHECK((*_env)->GetArrayLength (_env, channel_id) == 32);
9346         (*_env)->GetByteArrayRegion (_env, channel_id, 0, 32, channel_id_arr);
9347         unsigned char (*channel_id_ref)[32] = &channel_id_arr;
9348         ChannelManager_force_close_channel(&this_arg_conv, channel_id_ref);
9349 }
9350
9351 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelManager_1force_1close_1all_1channels(JNIEnv * _env, jclass _b, jlong this_arg) {
9352         LDKChannelManager this_arg_conv;
9353         this_arg_conv.inner = (void*)(this_arg & (~1));
9354         this_arg_conv.is_owned = false;
9355         ChannelManager_force_close_all_channels(&this_arg_conv);
9356 }
9357
9358 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelManager_1send_1payment(JNIEnv * _env, jclass _b, jlong this_arg, jlong route, jbyteArray payment_hash, jbyteArray payment_secret) {
9359         LDKChannelManager this_arg_conv;
9360         this_arg_conv.inner = (void*)(this_arg & (~1));
9361         this_arg_conv.is_owned = false;
9362         LDKRoute route_conv;
9363         route_conv.inner = (void*)(route & (~1));
9364         route_conv.is_owned = false;
9365         LDKThirtyTwoBytes payment_hash_ref;
9366         CHECK((*_env)->GetArrayLength (_env, payment_hash) == 32);
9367         (*_env)->GetByteArrayRegion (_env, payment_hash, 0, 32, payment_hash_ref.data);
9368         LDKThirtyTwoBytes payment_secret_ref;
9369         CHECK((*_env)->GetArrayLength (_env, payment_secret) == 32);
9370         (*_env)->GetByteArrayRegion (_env, payment_secret, 0, 32, payment_secret_ref.data);
9371         LDKCResult_NonePaymentSendFailureZ* ret_conv = MALLOC(sizeof(LDKCResult_NonePaymentSendFailureZ), "LDKCResult_NonePaymentSendFailureZ");
9372         *ret_conv = ChannelManager_send_payment(&this_arg_conv, &route_conv, payment_hash_ref, payment_secret_ref);
9373         return (long)ret_conv;
9374 }
9375
9376 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelManager_1funding_1transaction_1generated(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray temporary_channel_id, jlong funding_txo) {
9377         LDKChannelManager this_arg_conv;
9378         this_arg_conv.inner = (void*)(this_arg & (~1));
9379         this_arg_conv.is_owned = false;
9380         unsigned char temporary_channel_id_arr[32];
9381         CHECK((*_env)->GetArrayLength (_env, temporary_channel_id) == 32);
9382         (*_env)->GetByteArrayRegion (_env, temporary_channel_id, 0, 32, temporary_channel_id_arr);
9383         unsigned char (*temporary_channel_id_ref)[32] = &temporary_channel_id_arr;
9384         LDKOutPoint funding_txo_conv;
9385         funding_txo_conv.inner = (void*)(funding_txo & (~1));
9386         funding_txo_conv.is_owned = (funding_txo & 1) || (funding_txo == 0);
9387         if (funding_txo_conv.inner != NULL)
9388                 funding_txo_conv = OutPoint_clone(&funding_txo_conv);
9389         ChannelManager_funding_transaction_generated(&this_arg_conv, temporary_channel_id_ref, funding_txo_conv);
9390 }
9391
9392 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelManager_1broadcast_1node_1announcement(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray rgb, jbyteArray alias, jlongArray addresses) {
9393         LDKChannelManager this_arg_conv;
9394         this_arg_conv.inner = (void*)(this_arg & (~1));
9395         this_arg_conv.is_owned = false;
9396         LDKThreeBytes rgb_ref;
9397         CHECK((*_env)->GetArrayLength (_env, rgb) == 3);
9398         (*_env)->GetByteArrayRegion (_env, rgb, 0, 3, rgb_ref.data);
9399         LDKThirtyTwoBytes alias_ref;
9400         CHECK((*_env)->GetArrayLength (_env, alias) == 32);
9401         (*_env)->GetByteArrayRegion (_env, alias, 0, 32, alias_ref.data);
9402         LDKCVec_NetAddressZ addresses_constr;
9403         addresses_constr.datalen = (*_env)->GetArrayLength (_env, addresses);
9404         if (addresses_constr.datalen > 0)
9405                 addresses_constr.data = MALLOC(addresses_constr.datalen * sizeof(LDKNetAddress), "LDKCVec_NetAddressZ Elements");
9406         else
9407                 addresses_constr.data = NULL;
9408         long* addresses_vals = (*_env)->GetLongArrayElements (_env, addresses, NULL);
9409         for (size_t m = 0; m < addresses_constr.datalen; m++) {
9410                 long arr_conv_12 = addresses_vals[m];
9411                 LDKNetAddress arr_conv_12_conv = *(LDKNetAddress*)arr_conv_12;
9412                 FREE((void*)arr_conv_12);
9413                 addresses_constr.data[m] = arr_conv_12_conv;
9414         }
9415         (*_env)->ReleaseLongArrayElements (_env, addresses, addresses_vals, 0);
9416         ChannelManager_broadcast_node_announcement(&this_arg_conv, rgb_ref, alias_ref, addresses_constr);
9417 }
9418
9419 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelManager_1process_1pending_1htlc_1forwards(JNIEnv * _env, jclass _b, jlong this_arg) {
9420         LDKChannelManager this_arg_conv;
9421         this_arg_conv.inner = (void*)(this_arg & (~1));
9422         this_arg_conv.is_owned = false;
9423         ChannelManager_process_pending_htlc_forwards(&this_arg_conv);
9424 }
9425
9426 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelManager_1timer_1chan_1freshness_1every_1min(JNIEnv * _env, jclass _b, jlong this_arg) {
9427         LDKChannelManager this_arg_conv;
9428         this_arg_conv.inner = (void*)(this_arg & (~1));
9429         this_arg_conv.is_owned = false;
9430         ChannelManager_timer_chan_freshness_every_min(&this_arg_conv);
9431 }
9432
9433 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_ChannelManager_1fail_1htlc_1backwards(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray payment_hash, jbyteArray payment_secret) {
9434         LDKChannelManager this_arg_conv;
9435         this_arg_conv.inner = (void*)(this_arg & (~1));
9436         this_arg_conv.is_owned = false;
9437         unsigned char payment_hash_arr[32];
9438         CHECK((*_env)->GetArrayLength (_env, payment_hash) == 32);
9439         (*_env)->GetByteArrayRegion (_env, payment_hash, 0, 32, payment_hash_arr);
9440         unsigned char (*payment_hash_ref)[32] = &payment_hash_arr;
9441         LDKThirtyTwoBytes payment_secret_ref;
9442         CHECK((*_env)->GetArrayLength (_env, payment_secret) == 32);
9443         (*_env)->GetByteArrayRegion (_env, payment_secret, 0, 32, payment_secret_ref.data);
9444         jboolean ret_val = ChannelManager_fail_htlc_backwards(&this_arg_conv, payment_hash_ref, payment_secret_ref);
9445         return ret_val;
9446 }
9447
9448 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_ChannelManager_1claim_1funds(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray payment_preimage, jbyteArray payment_secret, jlong expected_amount) {
9449         LDKChannelManager this_arg_conv;
9450         this_arg_conv.inner = (void*)(this_arg & (~1));
9451         this_arg_conv.is_owned = false;
9452         LDKThirtyTwoBytes payment_preimage_ref;
9453         CHECK((*_env)->GetArrayLength (_env, payment_preimage) == 32);
9454         (*_env)->GetByteArrayRegion (_env, payment_preimage, 0, 32, payment_preimage_ref.data);
9455         LDKThirtyTwoBytes payment_secret_ref;
9456         CHECK((*_env)->GetArrayLength (_env, payment_secret) == 32);
9457         (*_env)->GetByteArrayRegion (_env, payment_secret, 0, 32, payment_secret_ref.data);
9458         jboolean ret_val = ChannelManager_claim_funds(&this_arg_conv, payment_preimage_ref, payment_secret_ref, expected_amount);
9459         return ret_val;
9460 }
9461
9462 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelManager_1get_1our_1node_1id(JNIEnv * _env, jclass _b, jlong this_arg) {
9463         LDKChannelManager this_arg_conv;
9464         this_arg_conv.inner = (void*)(this_arg & (~1));
9465         this_arg_conv.is_owned = false;
9466         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
9467         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, ChannelManager_get_our_node_id(&this_arg_conv).compressed_form);
9468         return arg_arr;
9469 }
9470
9471 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelManager_1channel_1monitor_1updated(JNIEnv * _env, jclass _b, jlong this_arg, jlong funding_txo, jlong highest_applied_update_id) {
9472         LDKChannelManager this_arg_conv;
9473         this_arg_conv.inner = (void*)(this_arg & (~1));
9474         this_arg_conv.is_owned = false;
9475         LDKOutPoint funding_txo_conv;
9476         funding_txo_conv.inner = (void*)(funding_txo & (~1));
9477         funding_txo_conv.is_owned = false;
9478         ChannelManager_channel_monitor_updated(&this_arg_conv, &funding_txo_conv, highest_applied_update_id);
9479 }
9480
9481 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelManager_1as_1MessageSendEventsProvider(JNIEnv * _env, jclass _b, jlong this_arg) {
9482         LDKChannelManager this_arg_conv;
9483         this_arg_conv.inner = (void*)(this_arg & (~1));
9484         this_arg_conv.is_owned = false;
9485         LDKMessageSendEventsProvider* ret = MALLOC(sizeof(LDKMessageSendEventsProvider), "LDKMessageSendEventsProvider");
9486         *ret = ChannelManager_as_MessageSendEventsProvider(&this_arg_conv);
9487         return (long)ret;
9488 }
9489
9490 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelManager_1as_1EventsProvider(JNIEnv * _env, jclass _b, jlong this_arg) {
9491         LDKChannelManager this_arg_conv;
9492         this_arg_conv.inner = (void*)(this_arg & (~1));
9493         this_arg_conv.is_owned = false;
9494         LDKEventsProvider* ret = MALLOC(sizeof(LDKEventsProvider), "LDKEventsProvider");
9495         *ret = ChannelManager_as_EventsProvider(&this_arg_conv);
9496         return (long)ret;
9497 }
9498
9499 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelManager_1block_1connected(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray header, jlongArray txdata, jint height) {
9500         LDKChannelManager this_arg_conv;
9501         this_arg_conv.inner = (void*)(this_arg & (~1));
9502         this_arg_conv.is_owned = false;
9503         unsigned char header_arr[80];
9504         CHECK((*_env)->GetArrayLength (_env, header) == 80);
9505         (*_env)->GetByteArrayRegion (_env, header, 0, 80, header_arr);
9506         unsigned char (*header_ref)[80] = &header_arr;
9507         LDKCVec_C2Tuple_usizeTransactionZZ txdata_constr;
9508         txdata_constr.datalen = (*_env)->GetArrayLength (_env, txdata);
9509         if (txdata_constr.datalen > 0)
9510                 txdata_constr.data = MALLOC(txdata_constr.datalen * sizeof(LDKC2Tuple_usizeTransactionZ), "LDKCVec_C2Tuple_usizeTransactionZZ Elements");
9511         else
9512                 txdata_constr.data = NULL;
9513         long* txdata_vals = (*_env)->GetLongArrayElements (_env, txdata, NULL);
9514         for (size_t y = 0; y < txdata_constr.datalen; y++) {
9515                 long arr_conv_24 = txdata_vals[y];
9516                 LDKC2Tuple_usizeTransactionZ arr_conv_24_conv = *(LDKC2Tuple_usizeTransactionZ*)arr_conv_24;
9517                 FREE((void*)arr_conv_24);
9518                 txdata_constr.data[y] = arr_conv_24_conv;
9519         }
9520         (*_env)->ReleaseLongArrayElements (_env, txdata, txdata_vals, 0);
9521         ChannelManager_block_connected(&this_arg_conv, header_ref, txdata_constr, height);
9522 }
9523
9524 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelManager_1block_1disconnected(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray header) {
9525         LDKChannelManager this_arg_conv;
9526         this_arg_conv.inner = (void*)(this_arg & (~1));
9527         this_arg_conv.is_owned = false;
9528         unsigned char header_arr[80];
9529         CHECK((*_env)->GetArrayLength (_env, header) == 80);
9530         (*_env)->GetByteArrayRegion (_env, header, 0, 80, header_arr);
9531         unsigned char (*header_ref)[80] = &header_arr;
9532         ChannelManager_block_disconnected(&this_arg_conv, header_ref);
9533 }
9534
9535 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelManager_1as_1ChannelMessageHandler(JNIEnv * _env, jclass _b, jlong this_arg) {
9536         LDKChannelManager this_arg_conv;
9537         this_arg_conv.inner = (void*)(this_arg & (~1));
9538         this_arg_conv.is_owned = false;
9539         LDKChannelMessageHandler* ret = MALLOC(sizeof(LDKChannelMessageHandler), "LDKChannelMessageHandler");
9540         *ret = ChannelManager_as_ChannelMessageHandler(&this_arg_conv);
9541         return (long)ret;
9542 }
9543
9544 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelManager_1write(JNIEnv * _env, jclass _b, jlong obj) {
9545         LDKChannelManager obj_conv;
9546         obj_conv.inner = (void*)(obj & (~1));
9547         obj_conv.is_owned = false;
9548         LDKCVec_u8Z arg_var = ChannelManager_write(&obj_conv);
9549         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
9550         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
9551         CVec_u8Z_free(arg_var);
9552         return arg_arr;
9553 }
9554
9555 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelManagerReadArgs_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
9556         LDKChannelManagerReadArgs this_ptr_conv;
9557         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9558         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9559         ChannelManagerReadArgs_free(this_ptr_conv);
9560 }
9561
9562 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelManagerReadArgs_1get_1keys_1manager(JNIEnv * _env, jclass _b, jlong this_ptr) {
9563         LDKChannelManagerReadArgs this_ptr_conv;
9564         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9565         this_ptr_conv.is_owned = false;
9566         long ret_ret = (long)ChannelManagerReadArgs_get_keys_manager(&this_ptr_conv);
9567         return ret_ret;
9568 }
9569
9570 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelManagerReadArgs_1set_1keys_1manager(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
9571         LDKChannelManagerReadArgs this_ptr_conv;
9572         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9573         this_ptr_conv.is_owned = false;
9574         LDKKeysInterface val_conv = *(LDKKeysInterface*)val;
9575         if (val_conv.free == LDKKeysInterface_JCalls_free) {
9576                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
9577                 LDKKeysInterface_JCalls_clone(val_conv.this_arg);
9578         }
9579         ChannelManagerReadArgs_set_keys_manager(&this_ptr_conv, val_conv);
9580 }
9581
9582 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelManagerReadArgs_1get_1fee_1estimator(JNIEnv * _env, jclass _b, jlong this_ptr) {
9583         LDKChannelManagerReadArgs this_ptr_conv;
9584         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9585         this_ptr_conv.is_owned = false;
9586         long ret_ret = (long)ChannelManagerReadArgs_get_fee_estimator(&this_ptr_conv);
9587         return ret_ret;
9588 }
9589
9590 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelManagerReadArgs_1set_1fee_1estimator(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
9591         LDKChannelManagerReadArgs this_ptr_conv;
9592         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9593         this_ptr_conv.is_owned = false;
9594         LDKFeeEstimator val_conv = *(LDKFeeEstimator*)val;
9595         if (val_conv.free == LDKFeeEstimator_JCalls_free) {
9596                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
9597                 LDKFeeEstimator_JCalls_clone(val_conv.this_arg);
9598         }
9599         ChannelManagerReadArgs_set_fee_estimator(&this_ptr_conv, val_conv);
9600 }
9601
9602 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelManagerReadArgs_1get_1chain_1monitor(JNIEnv * _env, jclass _b, jlong this_ptr) {
9603         LDKChannelManagerReadArgs this_ptr_conv;
9604         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9605         this_ptr_conv.is_owned = false;
9606         long ret_ret = (long)ChannelManagerReadArgs_get_chain_monitor(&this_ptr_conv);
9607         return ret_ret;
9608 }
9609
9610 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelManagerReadArgs_1set_1chain_1monitor(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
9611         LDKChannelManagerReadArgs this_ptr_conv;
9612         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9613         this_ptr_conv.is_owned = false;
9614         LDKWatch val_conv = *(LDKWatch*)val;
9615         if (val_conv.free == LDKWatch_JCalls_free) {
9616                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
9617                 LDKWatch_JCalls_clone(val_conv.this_arg);
9618         }
9619         ChannelManagerReadArgs_set_chain_monitor(&this_ptr_conv, val_conv);
9620 }
9621
9622 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelManagerReadArgs_1get_1tx_1broadcaster(JNIEnv * _env, jclass _b, jlong this_ptr) {
9623         LDKChannelManagerReadArgs this_ptr_conv;
9624         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9625         this_ptr_conv.is_owned = false;
9626         long ret_ret = (long)ChannelManagerReadArgs_get_tx_broadcaster(&this_ptr_conv);
9627         return ret_ret;
9628 }
9629
9630 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelManagerReadArgs_1set_1tx_1broadcaster(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
9631         LDKChannelManagerReadArgs this_ptr_conv;
9632         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9633         this_ptr_conv.is_owned = false;
9634         LDKBroadcasterInterface val_conv = *(LDKBroadcasterInterface*)val;
9635         if (val_conv.free == LDKBroadcasterInterface_JCalls_free) {
9636                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
9637                 LDKBroadcasterInterface_JCalls_clone(val_conv.this_arg);
9638         }
9639         ChannelManagerReadArgs_set_tx_broadcaster(&this_ptr_conv, val_conv);
9640 }
9641
9642 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelManagerReadArgs_1get_1logger(JNIEnv * _env, jclass _b, jlong this_ptr) {
9643         LDKChannelManagerReadArgs this_ptr_conv;
9644         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9645         this_ptr_conv.is_owned = false;
9646         long ret_ret = (long)ChannelManagerReadArgs_get_logger(&this_ptr_conv);
9647         return ret_ret;
9648 }
9649
9650 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelManagerReadArgs_1set_1logger(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
9651         LDKChannelManagerReadArgs this_ptr_conv;
9652         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9653         this_ptr_conv.is_owned = false;
9654         LDKLogger val_conv = *(LDKLogger*)val;
9655         if (val_conv.free == LDKLogger_JCalls_free) {
9656                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
9657                 LDKLogger_JCalls_clone(val_conv.this_arg);
9658         }
9659         ChannelManagerReadArgs_set_logger(&this_ptr_conv, val_conv);
9660 }
9661
9662 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelManagerReadArgs_1get_1default_1config(JNIEnv * _env, jclass _b, jlong this_ptr) {
9663         LDKChannelManagerReadArgs this_ptr_conv;
9664         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9665         this_ptr_conv.is_owned = false;
9666         LDKUserConfig ret_var = ChannelManagerReadArgs_get_default_config(&this_ptr_conv);
9667         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9668         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9669         long ret_ref = (long)ret_var.inner;
9670         if (ret_var.is_owned) {
9671                 ret_ref |= 1;
9672         }
9673         return ret_ref;
9674 }
9675
9676 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelManagerReadArgs_1set_1default_1config(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
9677         LDKChannelManagerReadArgs this_ptr_conv;
9678         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9679         this_ptr_conv.is_owned = false;
9680         LDKUserConfig val_conv;
9681         val_conv.inner = (void*)(val & (~1));
9682         val_conv.is_owned = (val & 1) || (val == 0);
9683         if (val_conv.inner != NULL)
9684                 val_conv = UserConfig_clone(&val_conv);
9685         ChannelManagerReadArgs_set_default_config(&this_ptr_conv, val_conv);
9686 }
9687
9688 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelManagerReadArgs_1new(JNIEnv * _env, jclass _b, jlong keys_manager, jlong fee_estimator, jlong chain_monitor, jlong tx_broadcaster, jlong logger, jlong default_config, jlongArray channel_monitors) {
9689         LDKKeysInterface keys_manager_conv = *(LDKKeysInterface*)keys_manager;
9690         if (keys_manager_conv.free == LDKKeysInterface_JCalls_free) {
9691                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
9692                 LDKKeysInterface_JCalls_clone(keys_manager_conv.this_arg);
9693         }
9694         LDKFeeEstimator fee_estimator_conv = *(LDKFeeEstimator*)fee_estimator;
9695         if (fee_estimator_conv.free == LDKFeeEstimator_JCalls_free) {
9696                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
9697                 LDKFeeEstimator_JCalls_clone(fee_estimator_conv.this_arg);
9698         }
9699         LDKWatch chain_monitor_conv = *(LDKWatch*)chain_monitor;
9700         if (chain_monitor_conv.free == LDKWatch_JCalls_free) {
9701                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
9702                 LDKWatch_JCalls_clone(chain_monitor_conv.this_arg);
9703         }
9704         LDKBroadcasterInterface tx_broadcaster_conv = *(LDKBroadcasterInterface*)tx_broadcaster;
9705         if (tx_broadcaster_conv.free == LDKBroadcasterInterface_JCalls_free) {
9706                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
9707                 LDKBroadcasterInterface_JCalls_clone(tx_broadcaster_conv.this_arg);
9708         }
9709         LDKLogger logger_conv = *(LDKLogger*)logger;
9710         if (logger_conv.free == LDKLogger_JCalls_free) {
9711                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
9712                 LDKLogger_JCalls_clone(logger_conv.this_arg);
9713         }
9714         LDKUserConfig default_config_conv;
9715         default_config_conv.inner = (void*)(default_config & (~1));
9716         default_config_conv.is_owned = (default_config & 1) || (default_config == 0);
9717         if (default_config_conv.inner != NULL)
9718                 default_config_conv = UserConfig_clone(&default_config_conv);
9719         LDKCVec_ChannelMonitorZ channel_monitors_constr;
9720         channel_monitors_constr.datalen = (*_env)->GetArrayLength (_env, channel_monitors);
9721         if (channel_monitors_constr.datalen > 0)
9722                 channel_monitors_constr.data = MALLOC(channel_monitors_constr.datalen * sizeof(LDKChannelMonitor), "LDKCVec_ChannelMonitorZ Elements");
9723         else
9724                 channel_monitors_constr.data = NULL;
9725         long* channel_monitors_vals = (*_env)->GetLongArrayElements (_env, channel_monitors, NULL);
9726         for (size_t q = 0; q < channel_monitors_constr.datalen; q++) {
9727                 long arr_conv_16 = channel_monitors_vals[q];
9728                 LDKChannelMonitor arr_conv_16_conv;
9729                 arr_conv_16_conv.inner = (void*)(arr_conv_16 & (~1));
9730                 arr_conv_16_conv.is_owned = (arr_conv_16 & 1) || (arr_conv_16 == 0);
9731                 channel_monitors_constr.data[q] = arr_conv_16_conv;
9732         }
9733         (*_env)->ReleaseLongArrayElements (_env, channel_monitors, channel_monitors_vals, 0);
9734         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);
9735         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9736         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9737         long ret_ref = (long)ret_var.inner;
9738         if (ret_var.is_owned) {
9739                 ret_ref |= 1;
9740         }
9741         return ret_ref;
9742 }
9743
9744 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_C2Tuple_1BlockHashChannelManagerZ_1read(JNIEnv * _env, jclass _b, jbyteArray ser, jlong arg) {
9745         LDKu8slice ser_ref;
9746         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
9747         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
9748         LDKChannelManagerReadArgs arg_conv;
9749         arg_conv.inner = (void*)(arg & (~1));
9750         arg_conv.is_owned = (arg & 1) || (arg == 0);
9751         // Warning: we may need a move here but can't clone!
9752         LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ), "LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ");
9753         *ret_conv = C2Tuple_BlockHashChannelManagerZ_read(ser_ref, arg_conv);
9754         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
9755         return (long)ret_conv;
9756 }
9757
9758 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_DecodeError_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
9759         LDKDecodeError this_ptr_conv;
9760         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9761         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9762         DecodeError_free(this_ptr_conv);
9763 }
9764
9765 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Init_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
9766         LDKInit this_ptr_conv;
9767         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9768         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9769         Init_free(this_ptr_conv);
9770 }
9771
9772 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_Init_1clone(JNIEnv * _env, jclass _b, jlong orig) {
9773         LDKInit orig_conv;
9774         orig_conv.inner = (void*)(orig & (~1));
9775         orig_conv.is_owned = false;
9776         LDKInit ret_var = Init_clone(&orig_conv);
9777         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9778         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9779         long ret_ref = (long)ret_var.inner;
9780         if (ret_var.is_owned) {
9781                 ret_ref |= 1;
9782         }
9783         return ret_ref;
9784 }
9785
9786 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ErrorMessage_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
9787         LDKErrorMessage this_ptr_conv;
9788         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9789         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9790         ErrorMessage_free(this_ptr_conv);
9791 }
9792
9793 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ErrorMessage_1clone(JNIEnv * _env, jclass _b, jlong orig) {
9794         LDKErrorMessage orig_conv;
9795         orig_conv.inner = (void*)(orig & (~1));
9796         orig_conv.is_owned = false;
9797         LDKErrorMessage ret_var = ErrorMessage_clone(&orig_conv);
9798         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9799         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9800         long ret_ref = (long)ret_var.inner;
9801         if (ret_var.is_owned) {
9802                 ret_ref |= 1;
9803         }
9804         return ret_ref;
9805 }
9806
9807 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ErrorMessage_1get_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
9808         LDKErrorMessage this_ptr_conv;
9809         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9810         this_ptr_conv.is_owned = false;
9811         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
9812         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *ErrorMessage_get_channel_id(&this_ptr_conv));
9813         return ret_arr;
9814 }
9815
9816 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ErrorMessage_1set_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
9817         LDKErrorMessage this_ptr_conv;
9818         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9819         this_ptr_conv.is_owned = false;
9820         LDKThirtyTwoBytes val_ref;
9821         CHECK((*_env)->GetArrayLength (_env, val) == 32);
9822         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
9823         ErrorMessage_set_channel_id(&this_ptr_conv, val_ref);
9824 }
9825
9826 JNIEXPORT jstring JNICALL Java_org_ldk_impl_bindings_ErrorMessage_1get_1data(JNIEnv * _env, jclass _b, jlong this_ptr) {
9827         LDKErrorMessage this_ptr_conv;
9828         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9829         this_ptr_conv.is_owned = false;
9830         LDKStr _str = ErrorMessage_get_data(&this_ptr_conv);
9831         char* _buf = MALLOC(_str.len + 1, "str conv buf");
9832         memcpy(_buf, _str.chars, _str.len);
9833         _buf[_str.len] = 0;
9834         jstring _conv = (*_env)->NewStringUTF(_env, _str.chars);
9835         FREE(_buf);
9836         return _conv;
9837 }
9838
9839 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ErrorMessage_1set_1data(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
9840         LDKErrorMessage this_ptr_conv;
9841         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9842         this_ptr_conv.is_owned = false;
9843         LDKCVec_u8Z val_ref;
9844         val_ref.datalen = (*_env)->GetArrayLength (_env, val);
9845         val_ref.data = MALLOC(val_ref.datalen, "LDKCVec_u8Z Bytes");
9846         (*_env)->GetByteArrayRegion(_env, val, 0, val_ref.datalen, val_ref.data);
9847         ErrorMessage_set_data(&this_ptr_conv, val_ref);
9848 }
9849
9850 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ErrorMessage_1new(JNIEnv * _env, jclass _b, jbyteArray channel_id_arg, jbyteArray data_arg) {
9851         LDKThirtyTwoBytes channel_id_arg_ref;
9852         CHECK((*_env)->GetArrayLength (_env, channel_id_arg) == 32);
9853         (*_env)->GetByteArrayRegion (_env, channel_id_arg, 0, 32, channel_id_arg_ref.data);
9854         LDKCVec_u8Z data_arg_ref;
9855         data_arg_ref.datalen = (*_env)->GetArrayLength (_env, data_arg);
9856         data_arg_ref.data = MALLOC(data_arg_ref.datalen, "LDKCVec_u8Z Bytes");
9857         (*_env)->GetByteArrayRegion(_env, data_arg, 0, data_arg_ref.datalen, data_arg_ref.data);
9858         LDKErrorMessage ret_var = ErrorMessage_new(channel_id_arg_ref, data_arg_ref);
9859         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9860         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9861         long ret_ref = (long)ret_var.inner;
9862         if (ret_var.is_owned) {
9863                 ret_ref |= 1;
9864         }
9865         return ret_ref;
9866 }
9867
9868 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Ping_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
9869         LDKPing this_ptr_conv;
9870         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9871         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9872         Ping_free(this_ptr_conv);
9873 }
9874
9875 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_Ping_1clone(JNIEnv * _env, jclass _b, jlong orig) {
9876         LDKPing orig_conv;
9877         orig_conv.inner = (void*)(orig & (~1));
9878         orig_conv.is_owned = false;
9879         LDKPing ret_var = Ping_clone(&orig_conv);
9880         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9881         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9882         long ret_ref = (long)ret_var.inner;
9883         if (ret_var.is_owned) {
9884                 ret_ref |= 1;
9885         }
9886         return ret_ref;
9887 }
9888
9889 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_Ping_1get_1ponglen(JNIEnv * _env, jclass _b, jlong this_ptr) {
9890         LDKPing this_ptr_conv;
9891         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9892         this_ptr_conv.is_owned = false;
9893         jshort ret_val = Ping_get_ponglen(&this_ptr_conv);
9894         return ret_val;
9895 }
9896
9897 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Ping_1set_1ponglen(JNIEnv * _env, jclass _b, jlong this_ptr, jshort val) {
9898         LDKPing this_ptr_conv;
9899         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9900         this_ptr_conv.is_owned = false;
9901         Ping_set_ponglen(&this_ptr_conv, val);
9902 }
9903
9904 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_Ping_1get_1byteslen(JNIEnv * _env, jclass _b, jlong this_ptr) {
9905         LDKPing this_ptr_conv;
9906         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9907         this_ptr_conv.is_owned = false;
9908         jshort ret_val = Ping_get_byteslen(&this_ptr_conv);
9909         return ret_val;
9910 }
9911
9912 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Ping_1set_1byteslen(JNIEnv * _env, jclass _b, jlong this_ptr, jshort val) {
9913         LDKPing this_ptr_conv;
9914         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9915         this_ptr_conv.is_owned = false;
9916         Ping_set_byteslen(&this_ptr_conv, val);
9917 }
9918
9919 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_Ping_1new(JNIEnv * _env, jclass _b, jshort ponglen_arg, jshort byteslen_arg) {
9920         LDKPing ret_var = Ping_new(ponglen_arg, byteslen_arg);
9921         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9922         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9923         long ret_ref = (long)ret_var.inner;
9924         if (ret_var.is_owned) {
9925                 ret_ref |= 1;
9926         }
9927         return ret_ref;
9928 }
9929
9930 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Pong_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
9931         LDKPong this_ptr_conv;
9932         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9933         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9934         Pong_free(this_ptr_conv);
9935 }
9936
9937 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_Pong_1clone(JNIEnv * _env, jclass _b, jlong orig) {
9938         LDKPong orig_conv;
9939         orig_conv.inner = (void*)(orig & (~1));
9940         orig_conv.is_owned = false;
9941         LDKPong ret_var = Pong_clone(&orig_conv);
9942         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9943         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9944         long ret_ref = (long)ret_var.inner;
9945         if (ret_var.is_owned) {
9946                 ret_ref |= 1;
9947         }
9948         return ret_ref;
9949 }
9950
9951 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_Pong_1get_1byteslen(JNIEnv * _env, jclass _b, jlong this_ptr) {
9952         LDKPong this_ptr_conv;
9953         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9954         this_ptr_conv.is_owned = false;
9955         jshort ret_val = Pong_get_byteslen(&this_ptr_conv);
9956         return ret_val;
9957 }
9958
9959 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Pong_1set_1byteslen(JNIEnv * _env, jclass _b, jlong this_ptr, jshort val) {
9960         LDKPong this_ptr_conv;
9961         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9962         this_ptr_conv.is_owned = false;
9963         Pong_set_byteslen(&this_ptr_conv, val);
9964 }
9965
9966 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_Pong_1new(JNIEnv * _env, jclass _b, jshort byteslen_arg) {
9967         LDKPong ret_var = Pong_new(byteslen_arg);
9968         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9969         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9970         long ret_ref = (long)ret_var.inner;
9971         if (ret_var.is_owned) {
9972                 ret_ref |= 1;
9973         }
9974         return ret_ref;
9975 }
9976
9977 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
9978         LDKOpenChannel this_ptr_conv;
9979         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9980         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9981         OpenChannel_free(this_ptr_conv);
9982 }
9983
9984 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_OpenChannel_1clone(JNIEnv * _env, jclass _b, jlong orig) {
9985         LDKOpenChannel orig_conv;
9986         orig_conv.inner = (void*)(orig & (~1));
9987         orig_conv.is_owned = false;
9988         LDKOpenChannel ret_var = OpenChannel_clone(&orig_conv);
9989         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9990         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9991         long ret_ref = (long)ret_var.inner;
9992         if (ret_var.is_owned) {
9993                 ret_ref |= 1;
9994         }
9995         return ret_ref;
9996 }
9997
9998 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1chain_1hash(JNIEnv * _env, jclass _b, jlong this_ptr) {
9999         LDKOpenChannel this_ptr_conv;
10000         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10001         this_ptr_conv.is_owned = false;
10002         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
10003         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *OpenChannel_get_chain_hash(&this_ptr_conv));
10004         return ret_arr;
10005 }
10006
10007 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1chain_1hash(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
10008         LDKOpenChannel this_ptr_conv;
10009         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10010         this_ptr_conv.is_owned = false;
10011         LDKThirtyTwoBytes val_ref;
10012         CHECK((*_env)->GetArrayLength (_env, val) == 32);
10013         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
10014         OpenChannel_set_chain_hash(&this_ptr_conv, val_ref);
10015 }
10016
10017 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1temporary_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
10018         LDKOpenChannel this_ptr_conv;
10019         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10020         this_ptr_conv.is_owned = false;
10021         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
10022         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *OpenChannel_get_temporary_channel_id(&this_ptr_conv));
10023         return ret_arr;
10024 }
10025
10026 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1temporary_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
10027         LDKOpenChannel this_ptr_conv;
10028         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10029         this_ptr_conv.is_owned = false;
10030         LDKThirtyTwoBytes val_ref;
10031         CHECK((*_env)->GetArrayLength (_env, val) == 32);
10032         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
10033         OpenChannel_set_temporary_channel_id(&this_ptr_conv, val_ref);
10034 }
10035
10036 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1funding_1satoshis(JNIEnv * _env, jclass _b, jlong this_ptr) {
10037         LDKOpenChannel this_ptr_conv;
10038         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10039         this_ptr_conv.is_owned = false;
10040         jlong ret_val = OpenChannel_get_funding_satoshis(&this_ptr_conv);
10041         return ret_val;
10042 }
10043
10044 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1funding_1satoshis(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
10045         LDKOpenChannel this_ptr_conv;
10046         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10047         this_ptr_conv.is_owned = false;
10048         OpenChannel_set_funding_satoshis(&this_ptr_conv, val);
10049 }
10050
10051 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1push_1msat(JNIEnv * _env, jclass _b, jlong this_ptr) {
10052         LDKOpenChannel this_ptr_conv;
10053         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10054         this_ptr_conv.is_owned = false;
10055         jlong ret_val = OpenChannel_get_push_msat(&this_ptr_conv);
10056         return ret_val;
10057 }
10058
10059 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1push_1msat(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
10060         LDKOpenChannel this_ptr_conv;
10061         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10062         this_ptr_conv.is_owned = false;
10063         OpenChannel_set_push_msat(&this_ptr_conv, val);
10064 }
10065
10066 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1dust_1limit_1satoshis(JNIEnv * _env, jclass _b, jlong this_ptr) {
10067         LDKOpenChannel this_ptr_conv;
10068         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10069         this_ptr_conv.is_owned = false;
10070         jlong ret_val = OpenChannel_get_dust_limit_satoshis(&this_ptr_conv);
10071         return ret_val;
10072 }
10073
10074 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1dust_1limit_1satoshis(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
10075         LDKOpenChannel this_ptr_conv;
10076         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10077         this_ptr_conv.is_owned = false;
10078         OpenChannel_set_dust_limit_satoshis(&this_ptr_conv, val);
10079 }
10080
10081 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1max_1htlc_1value_1in_1flight_1msat(JNIEnv * _env, jclass _b, jlong this_ptr) {
10082         LDKOpenChannel this_ptr_conv;
10083         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10084         this_ptr_conv.is_owned = false;
10085         jlong ret_val = OpenChannel_get_max_htlc_value_in_flight_msat(&this_ptr_conv);
10086         return ret_val;
10087 }
10088
10089 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1max_1htlc_1value_1in_1flight_1msat(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
10090         LDKOpenChannel this_ptr_conv;
10091         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10092         this_ptr_conv.is_owned = false;
10093         OpenChannel_set_max_htlc_value_in_flight_msat(&this_ptr_conv, val);
10094 }
10095
10096 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1channel_1reserve_1satoshis(JNIEnv * _env, jclass _b, jlong this_ptr) {
10097         LDKOpenChannel this_ptr_conv;
10098         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10099         this_ptr_conv.is_owned = false;
10100         jlong ret_val = OpenChannel_get_channel_reserve_satoshis(&this_ptr_conv);
10101         return ret_val;
10102 }
10103
10104 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1channel_1reserve_1satoshis(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
10105         LDKOpenChannel this_ptr_conv;
10106         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10107         this_ptr_conv.is_owned = false;
10108         OpenChannel_set_channel_reserve_satoshis(&this_ptr_conv, val);
10109 }
10110
10111 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1htlc_1minimum_1msat(JNIEnv * _env, jclass _b, jlong this_ptr) {
10112         LDKOpenChannel this_ptr_conv;
10113         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10114         this_ptr_conv.is_owned = false;
10115         jlong ret_val = OpenChannel_get_htlc_minimum_msat(&this_ptr_conv);
10116         return ret_val;
10117 }
10118
10119 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1htlc_1minimum_1msat(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
10120         LDKOpenChannel this_ptr_conv;
10121         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10122         this_ptr_conv.is_owned = false;
10123         OpenChannel_set_htlc_minimum_msat(&this_ptr_conv, val);
10124 }
10125
10126 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1feerate_1per_1kw(JNIEnv * _env, jclass _b, jlong this_ptr) {
10127         LDKOpenChannel this_ptr_conv;
10128         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10129         this_ptr_conv.is_owned = false;
10130         jint ret_val = OpenChannel_get_feerate_per_kw(&this_ptr_conv);
10131         return ret_val;
10132 }
10133
10134 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1feerate_1per_1kw(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
10135         LDKOpenChannel this_ptr_conv;
10136         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10137         this_ptr_conv.is_owned = false;
10138         OpenChannel_set_feerate_per_kw(&this_ptr_conv, val);
10139 }
10140
10141 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1to_1self_1delay(JNIEnv * _env, jclass _b, jlong this_ptr) {
10142         LDKOpenChannel this_ptr_conv;
10143         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10144         this_ptr_conv.is_owned = false;
10145         jshort ret_val = OpenChannel_get_to_self_delay(&this_ptr_conv);
10146         return ret_val;
10147 }
10148
10149 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1to_1self_1delay(JNIEnv * _env, jclass _b, jlong this_ptr, jshort val) {
10150         LDKOpenChannel this_ptr_conv;
10151         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10152         this_ptr_conv.is_owned = false;
10153         OpenChannel_set_to_self_delay(&this_ptr_conv, val);
10154 }
10155
10156 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1max_1accepted_1htlcs(JNIEnv * _env, jclass _b, jlong this_ptr) {
10157         LDKOpenChannel this_ptr_conv;
10158         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10159         this_ptr_conv.is_owned = false;
10160         jshort ret_val = OpenChannel_get_max_accepted_htlcs(&this_ptr_conv);
10161         return ret_val;
10162 }
10163
10164 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1max_1accepted_1htlcs(JNIEnv * _env, jclass _b, jlong this_ptr, jshort val) {
10165         LDKOpenChannel this_ptr_conv;
10166         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10167         this_ptr_conv.is_owned = false;
10168         OpenChannel_set_max_accepted_htlcs(&this_ptr_conv, val);
10169 }
10170
10171 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1funding_1pubkey(JNIEnv * _env, jclass _b, jlong this_ptr) {
10172         LDKOpenChannel this_ptr_conv;
10173         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10174         this_ptr_conv.is_owned = false;
10175         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
10176         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, OpenChannel_get_funding_pubkey(&this_ptr_conv).compressed_form);
10177         return arg_arr;
10178 }
10179
10180 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1funding_1pubkey(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
10181         LDKOpenChannel this_ptr_conv;
10182         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10183         this_ptr_conv.is_owned = false;
10184         LDKPublicKey val_ref;
10185         CHECK((*_env)->GetArrayLength (_env, val) == 33);
10186         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
10187         OpenChannel_set_funding_pubkey(&this_ptr_conv, val_ref);
10188 }
10189
10190 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1revocation_1basepoint(JNIEnv * _env, jclass _b, jlong this_ptr) {
10191         LDKOpenChannel this_ptr_conv;
10192         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10193         this_ptr_conv.is_owned = false;
10194         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
10195         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, OpenChannel_get_revocation_basepoint(&this_ptr_conv).compressed_form);
10196         return arg_arr;
10197 }
10198
10199 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1revocation_1basepoint(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
10200         LDKOpenChannel this_ptr_conv;
10201         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10202         this_ptr_conv.is_owned = false;
10203         LDKPublicKey val_ref;
10204         CHECK((*_env)->GetArrayLength (_env, val) == 33);
10205         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
10206         OpenChannel_set_revocation_basepoint(&this_ptr_conv, val_ref);
10207 }
10208
10209 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1payment_1point(JNIEnv * _env, jclass _b, jlong this_ptr) {
10210         LDKOpenChannel this_ptr_conv;
10211         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10212         this_ptr_conv.is_owned = false;
10213         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
10214         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, OpenChannel_get_payment_point(&this_ptr_conv).compressed_form);
10215         return arg_arr;
10216 }
10217
10218 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1payment_1point(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
10219         LDKOpenChannel this_ptr_conv;
10220         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10221         this_ptr_conv.is_owned = false;
10222         LDKPublicKey val_ref;
10223         CHECK((*_env)->GetArrayLength (_env, val) == 33);
10224         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
10225         OpenChannel_set_payment_point(&this_ptr_conv, val_ref);
10226 }
10227
10228 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1delayed_1payment_1basepoint(JNIEnv * _env, jclass _b, jlong this_ptr) {
10229         LDKOpenChannel this_ptr_conv;
10230         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10231         this_ptr_conv.is_owned = false;
10232         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
10233         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, OpenChannel_get_delayed_payment_basepoint(&this_ptr_conv).compressed_form);
10234         return arg_arr;
10235 }
10236
10237 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1delayed_1payment_1basepoint(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
10238         LDKOpenChannel this_ptr_conv;
10239         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10240         this_ptr_conv.is_owned = false;
10241         LDKPublicKey val_ref;
10242         CHECK((*_env)->GetArrayLength (_env, val) == 33);
10243         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
10244         OpenChannel_set_delayed_payment_basepoint(&this_ptr_conv, val_ref);
10245 }
10246
10247 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1htlc_1basepoint(JNIEnv * _env, jclass _b, jlong this_ptr) {
10248         LDKOpenChannel this_ptr_conv;
10249         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10250         this_ptr_conv.is_owned = false;
10251         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
10252         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, OpenChannel_get_htlc_basepoint(&this_ptr_conv).compressed_form);
10253         return arg_arr;
10254 }
10255
10256 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1htlc_1basepoint(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
10257         LDKOpenChannel this_ptr_conv;
10258         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10259         this_ptr_conv.is_owned = false;
10260         LDKPublicKey val_ref;
10261         CHECK((*_env)->GetArrayLength (_env, val) == 33);
10262         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
10263         OpenChannel_set_htlc_basepoint(&this_ptr_conv, val_ref);
10264 }
10265
10266 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1first_1per_1commitment_1point(JNIEnv * _env, jclass _b, jlong this_ptr) {
10267         LDKOpenChannel this_ptr_conv;
10268         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10269         this_ptr_conv.is_owned = false;
10270         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
10271         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, OpenChannel_get_first_per_commitment_point(&this_ptr_conv).compressed_form);
10272         return arg_arr;
10273 }
10274
10275 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1first_1per_1commitment_1point(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
10276         LDKOpenChannel 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         OpenChannel_set_first_per_commitment_point(&this_ptr_conv, val_ref);
10283 }
10284
10285 JNIEXPORT jbyte JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1channel_1flags(JNIEnv * _env, jclass _b, jlong this_ptr) {
10286         LDKOpenChannel this_ptr_conv;
10287         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10288         this_ptr_conv.is_owned = false;
10289         jbyte ret_val = OpenChannel_get_channel_flags(&this_ptr_conv);
10290         return ret_val;
10291 }
10292
10293 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1channel_1flags(JNIEnv * _env, jclass _b, jlong this_ptr, jbyte val) {
10294         LDKOpenChannel this_ptr_conv;
10295         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10296         this_ptr_conv.is_owned = false;
10297         OpenChannel_set_channel_flags(&this_ptr_conv, val);
10298 }
10299
10300 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
10301         LDKAcceptChannel this_ptr_conv;
10302         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10303         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10304         AcceptChannel_free(this_ptr_conv);
10305 }
10306
10307 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1clone(JNIEnv * _env, jclass _b, jlong orig) {
10308         LDKAcceptChannel orig_conv;
10309         orig_conv.inner = (void*)(orig & (~1));
10310         orig_conv.is_owned = false;
10311         LDKAcceptChannel ret_var = AcceptChannel_clone(&orig_conv);
10312         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10313         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10314         long ret_ref = (long)ret_var.inner;
10315         if (ret_var.is_owned) {
10316                 ret_ref |= 1;
10317         }
10318         return ret_ref;
10319 }
10320
10321 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1get_1temporary_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
10322         LDKAcceptChannel this_ptr_conv;
10323         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10324         this_ptr_conv.is_owned = false;
10325         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
10326         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *AcceptChannel_get_temporary_channel_id(&this_ptr_conv));
10327         return ret_arr;
10328 }
10329
10330 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1set_1temporary_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
10331         LDKAcceptChannel this_ptr_conv;
10332         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10333         this_ptr_conv.is_owned = false;
10334         LDKThirtyTwoBytes val_ref;
10335         CHECK((*_env)->GetArrayLength (_env, val) == 32);
10336         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
10337         AcceptChannel_set_temporary_channel_id(&this_ptr_conv, val_ref);
10338 }
10339
10340 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1get_1dust_1limit_1satoshis(JNIEnv * _env, jclass _b, jlong this_ptr) {
10341         LDKAcceptChannel this_ptr_conv;
10342         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10343         this_ptr_conv.is_owned = false;
10344         jlong ret_val = AcceptChannel_get_dust_limit_satoshis(&this_ptr_conv);
10345         return ret_val;
10346 }
10347
10348 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1set_1dust_1limit_1satoshis(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
10349         LDKAcceptChannel this_ptr_conv;
10350         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10351         this_ptr_conv.is_owned = false;
10352         AcceptChannel_set_dust_limit_satoshis(&this_ptr_conv, val);
10353 }
10354
10355 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1get_1max_1htlc_1value_1in_1flight_1msat(JNIEnv * _env, jclass _b, jlong this_ptr) {
10356         LDKAcceptChannel this_ptr_conv;
10357         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10358         this_ptr_conv.is_owned = false;
10359         jlong ret_val = AcceptChannel_get_max_htlc_value_in_flight_msat(&this_ptr_conv);
10360         return ret_val;
10361 }
10362
10363 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1set_1max_1htlc_1value_1in_1flight_1msat(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
10364         LDKAcceptChannel this_ptr_conv;
10365         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10366         this_ptr_conv.is_owned = false;
10367         AcceptChannel_set_max_htlc_value_in_flight_msat(&this_ptr_conv, val);
10368 }
10369
10370 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1get_1channel_1reserve_1satoshis(JNIEnv * _env, jclass _b, jlong this_ptr) {
10371         LDKAcceptChannel this_ptr_conv;
10372         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10373         this_ptr_conv.is_owned = false;
10374         jlong ret_val = AcceptChannel_get_channel_reserve_satoshis(&this_ptr_conv);
10375         return ret_val;
10376 }
10377
10378 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1set_1channel_1reserve_1satoshis(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
10379         LDKAcceptChannel this_ptr_conv;
10380         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10381         this_ptr_conv.is_owned = false;
10382         AcceptChannel_set_channel_reserve_satoshis(&this_ptr_conv, val);
10383 }
10384
10385 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1get_1htlc_1minimum_1msat(JNIEnv * _env, jclass _b, jlong this_ptr) {
10386         LDKAcceptChannel this_ptr_conv;
10387         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10388         this_ptr_conv.is_owned = false;
10389         jlong ret_val = AcceptChannel_get_htlc_minimum_msat(&this_ptr_conv);
10390         return ret_val;
10391 }
10392
10393 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1set_1htlc_1minimum_1msat(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
10394         LDKAcceptChannel this_ptr_conv;
10395         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10396         this_ptr_conv.is_owned = false;
10397         AcceptChannel_set_htlc_minimum_msat(&this_ptr_conv, val);
10398 }
10399
10400 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1get_1minimum_1depth(JNIEnv * _env, jclass _b, jlong this_ptr) {
10401         LDKAcceptChannel this_ptr_conv;
10402         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10403         this_ptr_conv.is_owned = false;
10404         jint ret_val = AcceptChannel_get_minimum_depth(&this_ptr_conv);
10405         return ret_val;
10406 }
10407
10408 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1set_1minimum_1depth(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
10409         LDKAcceptChannel this_ptr_conv;
10410         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10411         this_ptr_conv.is_owned = false;
10412         AcceptChannel_set_minimum_depth(&this_ptr_conv, val);
10413 }
10414
10415 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1get_1to_1self_1delay(JNIEnv * _env, jclass _b, jlong this_ptr) {
10416         LDKAcceptChannel this_ptr_conv;
10417         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10418         this_ptr_conv.is_owned = false;
10419         jshort ret_val = AcceptChannel_get_to_self_delay(&this_ptr_conv);
10420         return ret_val;
10421 }
10422
10423 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1set_1to_1self_1delay(JNIEnv * _env, jclass _b, jlong this_ptr, jshort val) {
10424         LDKAcceptChannel this_ptr_conv;
10425         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10426         this_ptr_conv.is_owned = false;
10427         AcceptChannel_set_to_self_delay(&this_ptr_conv, val);
10428 }
10429
10430 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1get_1max_1accepted_1htlcs(JNIEnv * _env, jclass _b, jlong this_ptr) {
10431         LDKAcceptChannel this_ptr_conv;
10432         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10433         this_ptr_conv.is_owned = false;
10434         jshort ret_val = AcceptChannel_get_max_accepted_htlcs(&this_ptr_conv);
10435         return ret_val;
10436 }
10437
10438 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1set_1max_1accepted_1htlcs(JNIEnv * _env, jclass _b, jlong this_ptr, jshort val) {
10439         LDKAcceptChannel this_ptr_conv;
10440         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10441         this_ptr_conv.is_owned = false;
10442         AcceptChannel_set_max_accepted_htlcs(&this_ptr_conv, val);
10443 }
10444
10445 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1get_1funding_1pubkey(JNIEnv * _env, jclass _b, jlong this_ptr) {
10446         LDKAcceptChannel this_ptr_conv;
10447         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10448         this_ptr_conv.is_owned = false;
10449         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
10450         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, AcceptChannel_get_funding_pubkey(&this_ptr_conv).compressed_form);
10451         return arg_arr;
10452 }
10453
10454 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1set_1funding_1pubkey(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
10455         LDKAcceptChannel this_ptr_conv;
10456         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10457         this_ptr_conv.is_owned = false;
10458         LDKPublicKey val_ref;
10459         CHECK((*_env)->GetArrayLength (_env, val) == 33);
10460         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
10461         AcceptChannel_set_funding_pubkey(&this_ptr_conv, val_ref);
10462 }
10463
10464 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1get_1revocation_1basepoint(JNIEnv * _env, jclass _b, jlong this_ptr) {
10465         LDKAcceptChannel this_ptr_conv;
10466         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10467         this_ptr_conv.is_owned = false;
10468         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
10469         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, AcceptChannel_get_revocation_basepoint(&this_ptr_conv).compressed_form);
10470         return arg_arr;
10471 }
10472
10473 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1set_1revocation_1basepoint(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
10474         LDKAcceptChannel this_ptr_conv;
10475         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10476         this_ptr_conv.is_owned = false;
10477         LDKPublicKey val_ref;
10478         CHECK((*_env)->GetArrayLength (_env, val) == 33);
10479         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
10480         AcceptChannel_set_revocation_basepoint(&this_ptr_conv, val_ref);
10481 }
10482
10483 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1get_1payment_1point(JNIEnv * _env, jclass _b, jlong this_ptr) {
10484         LDKAcceptChannel this_ptr_conv;
10485         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10486         this_ptr_conv.is_owned = false;
10487         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
10488         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, AcceptChannel_get_payment_point(&this_ptr_conv).compressed_form);
10489         return arg_arr;
10490 }
10491
10492 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1set_1payment_1point(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
10493         LDKAcceptChannel this_ptr_conv;
10494         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10495         this_ptr_conv.is_owned = false;
10496         LDKPublicKey val_ref;
10497         CHECK((*_env)->GetArrayLength (_env, val) == 33);
10498         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
10499         AcceptChannel_set_payment_point(&this_ptr_conv, val_ref);
10500 }
10501
10502 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1get_1delayed_1payment_1basepoint(JNIEnv * _env, jclass _b, jlong this_ptr) {
10503         LDKAcceptChannel this_ptr_conv;
10504         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10505         this_ptr_conv.is_owned = false;
10506         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
10507         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, AcceptChannel_get_delayed_payment_basepoint(&this_ptr_conv).compressed_form);
10508         return arg_arr;
10509 }
10510
10511 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1set_1delayed_1payment_1basepoint(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
10512         LDKAcceptChannel this_ptr_conv;
10513         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10514         this_ptr_conv.is_owned = false;
10515         LDKPublicKey val_ref;
10516         CHECK((*_env)->GetArrayLength (_env, val) == 33);
10517         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
10518         AcceptChannel_set_delayed_payment_basepoint(&this_ptr_conv, val_ref);
10519 }
10520
10521 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1get_1htlc_1basepoint(JNIEnv * _env, jclass _b, jlong this_ptr) {
10522         LDKAcceptChannel this_ptr_conv;
10523         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10524         this_ptr_conv.is_owned = false;
10525         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
10526         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, AcceptChannel_get_htlc_basepoint(&this_ptr_conv).compressed_form);
10527         return arg_arr;
10528 }
10529
10530 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1set_1htlc_1basepoint(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
10531         LDKAcceptChannel this_ptr_conv;
10532         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10533         this_ptr_conv.is_owned = false;
10534         LDKPublicKey val_ref;
10535         CHECK((*_env)->GetArrayLength (_env, val) == 33);
10536         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
10537         AcceptChannel_set_htlc_basepoint(&this_ptr_conv, val_ref);
10538 }
10539
10540 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1get_1first_1per_1commitment_1point(JNIEnv * _env, jclass _b, jlong this_ptr) {
10541         LDKAcceptChannel this_ptr_conv;
10542         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10543         this_ptr_conv.is_owned = false;
10544         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
10545         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, AcceptChannel_get_first_per_commitment_point(&this_ptr_conv).compressed_form);
10546         return arg_arr;
10547 }
10548
10549 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1set_1first_1per_1commitment_1point(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
10550         LDKAcceptChannel this_ptr_conv;
10551         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10552         this_ptr_conv.is_owned = false;
10553         LDKPublicKey val_ref;
10554         CHECK((*_env)->GetArrayLength (_env, val) == 33);
10555         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
10556         AcceptChannel_set_first_per_commitment_point(&this_ptr_conv, val_ref);
10557 }
10558
10559 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_FundingCreated_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
10560         LDKFundingCreated this_ptr_conv;
10561         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10562         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10563         FundingCreated_free(this_ptr_conv);
10564 }
10565
10566 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_FundingCreated_1clone(JNIEnv * _env, jclass _b, jlong orig) {
10567         LDKFundingCreated orig_conv;
10568         orig_conv.inner = (void*)(orig & (~1));
10569         orig_conv.is_owned = false;
10570         LDKFundingCreated ret_var = FundingCreated_clone(&orig_conv);
10571         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10572         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10573         long ret_ref = (long)ret_var.inner;
10574         if (ret_var.is_owned) {
10575                 ret_ref |= 1;
10576         }
10577         return ret_ref;
10578 }
10579
10580 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_FundingCreated_1get_1temporary_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
10581         LDKFundingCreated this_ptr_conv;
10582         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10583         this_ptr_conv.is_owned = false;
10584         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
10585         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *FundingCreated_get_temporary_channel_id(&this_ptr_conv));
10586         return ret_arr;
10587 }
10588
10589 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_FundingCreated_1set_1temporary_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
10590         LDKFundingCreated this_ptr_conv;
10591         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10592         this_ptr_conv.is_owned = false;
10593         LDKThirtyTwoBytes val_ref;
10594         CHECK((*_env)->GetArrayLength (_env, val) == 32);
10595         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
10596         FundingCreated_set_temporary_channel_id(&this_ptr_conv, val_ref);
10597 }
10598
10599 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_FundingCreated_1get_1funding_1txid(JNIEnv * _env, jclass _b, jlong this_ptr) {
10600         LDKFundingCreated this_ptr_conv;
10601         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10602         this_ptr_conv.is_owned = false;
10603         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
10604         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *FundingCreated_get_funding_txid(&this_ptr_conv));
10605         return ret_arr;
10606 }
10607
10608 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_FundingCreated_1set_1funding_1txid(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
10609         LDKFundingCreated this_ptr_conv;
10610         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10611         this_ptr_conv.is_owned = false;
10612         LDKThirtyTwoBytes val_ref;
10613         CHECK((*_env)->GetArrayLength (_env, val) == 32);
10614         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
10615         FundingCreated_set_funding_txid(&this_ptr_conv, val_ref);
10616 }
10617
10618 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_FundingCreated_1get_1funding_1output_1index(JNIEnv * _env, jclass _b, jlong this_ptr) {
10619         LDKFundingCreated this_ptr_conv;
10620         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10621         this_ptr_conv.is_owned = false;
10622         jshort ret_val = FundingCreated_get_funding_output_index(&this_ptr_conv);
10623         return ret_val;
10624 }
10625
10626 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_FundingCreated_1set_1funding_1output_1index(JNIEnv * _env, jclass _b, jlong this_ptr, jshort val) {
10627         LDKFundingCreated this_ptr_conv;
10628         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10629         this_ptr_conv.is_owned = false;
10630         FundingCreated_set_funding_output_index(&this_ptr_conv, val);
10631 }
10632
10633 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_FundingCreated_1get_1signature(JNIEnv * _env, jclass _b, jlong this_ptr) {
10634         LDKFundingCreated this_ptr_conv;
10635         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10636         this_ptr_conv.is_owned = false;
10637         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 64);
10638         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 64, FundingCreated_get_signature(&this_ptr_conv).compact_form);
10639         return arg_arr;
10640 }
10641
10642 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_FundingCreated_1set_1signature(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
10643         LDKFundingCreated this_ptr_conv;
10644         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10645         this_ptr_conv.is_owned = false;
10646         LDKSignature val_ref;
10647         CHECK((*_env)->GetArrayLength (_env, val) == 64);
10648         (*_env)->GetByteArrayRegion (_env, val, 0, 64, val_ref.compact_form);
10649         FundingCreated_set_signature(&this_ptr_conv, val_ref);
10650 }
10651
10652 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_FundingCreated_1new(JNIEnv * _env, jclass _b, jbyteArray temporary_channel_id_arg, jbyteArray funding_txid_arg, jshort funding_output_index_arg, jbyteArray signature_arg) {
10653         LDKThirtyTwoBytes temporary_channel_id_arg_ref;
10654         CHECK((*_env)->GetArrayLength (_env, temporary_channel_id_arg) == 32);
10655         (*_env)->GetByteArrayRegion (_env, temporary_channel_id_arg, 0, 32, temporary_channel_id_arg_ref.data);
10656         LDKThirtyTwoBytes funding_txid_arg_ref;
10657         CHECK((*_env)->GetArrayLength (_env, funding_txid_arg) == 32);
10658         (*_env)->GetByteArrayRegion (_env, funding_txid_arg, 0, 32, funding_txid_arg_ref.data);
10659         LDKSignature signature_arg_ref;
10660         CHECK((*_env)->GetArrayLength (_env, signature_arg) == 64);
10661         (*_env)->GetByteArrayRegion (_env, signature_arg, 0, 64, signature_arg_ref.compact_form);
10662         LDKFundingCreated ret_var = FundingCreated_new(temporary_channel_id_arg_ref, funding_txid_arg_ref, funding_output_index_arg, signature_arg_ref);
10663         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10664         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10665         long ret_ref = (long)ret_var.inner;
10666         if (ret_var.is_owned) {
10667                 ret_ref |= 1;
10668         }
10669         return ret_ref;
10670 }
10671
10672 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_FundingSigned_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
10673         LDKFundingSigned this_ptr_conv;
10674         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10675         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10676         FundingSigned_free(this_ptr_conv);
10677 }
10678
10679 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_FundingSigned_1clone(JNIEnv * _env, jclass _b, jlong orig) {
10680         LDKFundingSigned orig_conv;
10681         orig_conv.inner = (void*)(orig & (~1));
10682         orig_conv.is_owned = false;
10683         LDKFundingSigned ret_var = FundingSigned_clone(&orig_conv);
10684         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10685         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10686         long ret_ref = (long)ret_var.inner;
10687         if (ret_var.is_owned) {
10688                 ret_ref |= 1;
10689         }
10690         return ret_ref;
10691 }
10692
10693 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_FundingSigned_1get_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
10694         LDKFundingSigned this_ptr_conv;
10695         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10696         this_ptr_conv.is_owned = false;
10697         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
10698         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *FundingSigned_get_channel_id(&this_ptr_conv));
10699         return ret_arr;
10700 }
10701
10702 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_FundingSigned_1set_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
10703         LDKFundingSigned this_ptr_conv;
10704         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10705         this_ptr_conv.is_owned = false;
10706         LDKThirtyTwoBytes val_ref;
10707         CHECK((*_env)->GetArrayLength (_env, val) == 32);
10708         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
10709         FundingSigned_set_channel_id(&this_ptr_conv, val_ref);
10710 }
10711
10712 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_FundingSigned_1get_1signature(JNIEnv * _env, jclass _b, jlong this_ptr) {
10713         LDKFundingSigned this_ptr_conv;
10714         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10715         this_ptr_conv.is_owned = false;
10716         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 64);
10717         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 64, FundingSigned_get_signature(&this_ptr_conv).compact_form);
10718         return arg_arr;
10719 }
10720
10721 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_FundingSigned_1set_1signature(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
10722         LDKFundingSigned this_ptr_conv;
10723         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10724         this_ptr_conv.is_owned = false;
10725         LDKSignature val_ref;
10726         CHECK((*_env)->GetArrayLength (_env, val) == 64);
10727         (*_env)->GetByteArrayRegion (_env, val, 0, 64, val_ref.compact_form);
10728         FundingSigned_set_signature(&this_ptr_conv, val_ref);
10729 }
10730
10731 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_FundingSigned_1new(JNIEnv * _env, jclass _b, jbyteArray channel_id_arg, jbyteArray signature_arg) {
10732         LDKThirtyTwoBytes channel_id_arg_ref;
10733         CHECK((*_env)->GetArrayLength (_env, channel_id_arg) == 32);
10734         (*_env)->GetByteArrayRegion (_env, channel_id_arg, 0, 32, channel_id_arg_ref.data);
10735         LDKSignature signature_arg_ref;
10736         CHECK((*_env)->GetArrayLength (_env, signature_arg) == 64);
10737         (*_env)->GetByteArrayRegion (_env, signature_arg, 0, 64, signature_arg_ref.compact_form);
10738         LDKFundingSigned ret_var = FundingSigned_new(channel_id_arg_ref, signature_arg_ref);
10739         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10740         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10741         long ret_ref = (long)ret_var.inner;
10742         if (ret_var.is_owned) {
10743                 ret_ref |= 1;
10744         }
10745         return ret_ref;
10746 }
10747
10748 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_FundingLocked_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
10749         LDKFundingLocked this_ptr_conv;
10750         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10751         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10752         FundingLocked_free(this_ptr_conv);
10753 }
10754
10755 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_FundingLocked_1clone(JNIEnv * _env, jclass _b, jlong orig) {
10756         LDKFundingLocked orig_conv;
10757         orig_conv.inner = (void*)(orig & (~1));
10758         orig_conv.is_owned = false;
10759         LDKFundingLocked ret_var = FundingLocked_clone(&orig_conv);
10760         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10761         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10762         long ret_ref = (long)ret_var.inner;
10763         if (ret_var.is_owned) {
10764                 ret_ref |= 1;
10765         }
10766         return ret_ref;
10767 }
10768
10769 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_FundingLocked_1get_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
10770         LDKFundingLocked this_ptr_conv;
10771         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10772         this_ptr_conv.is_owned = false;
10773         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
10774         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *FundingLocked_get_channel_id(&this_ptr_conv));
10775         return ret_arr;
10776 }
10777
10778 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_FundingLocked_1set_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
10779         LDKFundingLocked this_ptr_conv;
10780         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10781         this_ptr_conv.is_owned = false;
10782         LDKThirtyTwoBytes val_ref;
10783         CHECK((*_env)->GetArrayLength (_env, val) == 32);
10784         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
10785         FundingLocked_set_channel_id(&this_ptr_conv, val_ref);
10786 }
10787
10788 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_FundingLocked_1get_1next_1per_1commitment_1point(JNIEnv * _env, jclass _b, jlong this_ptr) {
10789         LDKFundingLocked this_ptr_conv;
10790         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10791         this_ptr_conv.is_owned = false;
10792         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
10793         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, FundingLocked_get_next_per_commitment_point(&this_ptr_conv).compressed_form);
10794         return arg_arr;
10795 }
10796
10797 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_FundingLocked_1set_1next_1per_1commitment_1point(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
10798         LDKFundingLocked this_ptr_conv;
10799         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10800         this_ptr_conv.is_owned = false;
10801         LDKPublicKey val_ref;
10802         CHECK((*_env)->GetArrayLength (_env, val) == 33);
10803         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
10804         FundingLocked_set_next_per_commitment_point(&this_ptr_conv, val_ref);
10805 }
10806
10807 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_FundingLocked_1new(JNIEnv * _env, jclass _b, jbyteArray channel_id_arg, jbyteArray next_per_commitment_point_arg) {
10808         LDKThirtyTwoBytes channel_id_arg_ref;
10809         CHECK((*_env)->GetArrayLength (_env, channel_id_arg) == 32);
10810         (*_env)->GetByteArrayRegion (_env, channel_id_arg, 0, 32, channel_id_arg_ref.data);
10811         LDKPublicKey next_per_commitment_point_arg_ref;
10812         CHECK((*_env)->GetArrayLength (_env, next_per_commitment_point_arg) == 33);
10813         (*_env)->GetByteArrayRegion (_env, next_per_commitment_point_arg, 0, 33, next_per_commitment_point_arg_ref.compressed_form);
10814         LDKFundingLocked ret_var = FundingLocked_new(channel_id_arg_ref, next_per_commitment_point_arg_ref);
10815         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10816         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10817         long ret_ref = (long)ret_var.inner;
10818         if (ret_var.is_owned) {
10819                 ret_ref |= 1;
10820         }
10821         return ret_ref;
10822 }
10823
10824 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Shutdown_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
10825         LDKShutdown this_ptr_conv;
10826         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10827         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10828         Shutdown_free(this_ptr_conv);
10829 }
10830
10831 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_Shutdown_1clone(JNIEnv * _env, jclass _b, jlong orig) {
10832         LDKShutdown orig_conv;
10833         orig_conv.inner = (void*)(orig & (~1));
10834         orig_conv.is_owned = false;
10835         LDKShutdown ret_var = Shutdown_clone(&orig_conv);
10836         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10837         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10838         long ret_ref = (long)ret_var.inner;
10839         if (ret_var.is_owned) {
10840                 ret_ref |= 1;
10841         }
10842         return ret_ref;
10843 }
10844
10845 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_Shutdown_1get_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
10846         LDKShutdown this_ptr_conv;
10847         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10848         this_ptr_conv.is_owned = false;
10849         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
10850         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *Shutdown_get_channel_id(&this_ptr_conv));
10851         return ret_arr;
10852 }
10853
10854 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Shutdown_1set_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
10855         LDKShutdown this_ptr_conv;
10856         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10857         this_ptr_conv.is_owned = false;
10858         LDKThirtyTwoBytes val_ref;
10859         CHECK((*_env)->GetArrayLength (_env, val) == 32);
10860         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
10861         Shutdown_set_channel_id(&this_ptr_conv, val_ref);
10862 }
10863
10864 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_Shutdown_1get_1scriptpubkey(JNIEnv * _env, jclass _b, jlong this_ptr) {
10865         LDKShutdown this_ptr_conv;
10866         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10867         this_ptr_conv.is_owned = false;
10868         LDKu8slice arg_var = Shutdown_get_scriptpubkey(&this_ptr_conv);
10869         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
10870         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
10871         return arg_arr;
10872 }
10873
10874 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Shutdown_1set_1scriptpubkey(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
10875         LDKShutdown this_ptr_conv;
10876         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10877         this_ptr_conv.is_owned = false;
10878         LDKCVec_u8Z val_ref;
10879         val_ref.datalen = (*_env)->GetArrayLength (_env, val);
10880         val_ref.data = MALLOC(val_ref.datalen, "LDKCVec_u8Z Bytes");
10881         (*_env)->GetByteArrayRegion(_env, val, 0, val_ref.datalen, val_ref.data);
10882         Shutdown_set_scriptpubkey(&this_ptr_conv, val_ref);
10883 }
10884
10885 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_Shutdown_1new(JNIEnv * _env, jclass _b, jbyteArray channel_id_arg, jbyteArray scriptpubkey_arg) {
10886         LDKThirtyTwoBytes channel_id_arg_ref;
10887         CHECK((*_env)->GetArrayLength (_env, channel_id_arg) == 32);
10888         (*_env)->GetByteArrayRegion (_env, channel_id_arg, 0, 32, channel_id_arg_ref.data);
10889         LDKCVec_u8Z scriptpubkey_arg_ref;
10890         scriptpubkey_arg_ref.datalen = (*_env)->GetArrayLength (_env, scriptpubkey_arg);
10891         scriptpubkey_arg_ref.data = MALLOC(scriptpubkey_arg_ref.datalen, "LDKCVec_u8Z Bytes");
10892         (*_env)->GetByteArrayRegion(_env, scriptpubkey_arg, 0, scriptpubkey_arg_ref.datalen, scriptpubkey_arg_ref.data);
10893         LDKShutdown ret_var = Shutdown_new(channel_id_arg_ref, scriptpubkey_arg_ref);
10894         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10895         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10896         long ret_ref = (long)ret_var.inner;
10897         if (ret_var.is_owned) {
10898                 ret_ref |= 1;
10899         }
10900         return ret_ref;
10901 }
10902
10903 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ClosingSigned_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
10904         LDKClosingSigned this_ptr_conv;
10905         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10906         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10907         ClosingSigned_free(this_ptr_conv);
10908 }
10909
10910 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ClosingSigned_1clone(JNIEnv * _env, jclass _b, jlong orig) {
10911         LDKClosingSigned orig_conv;
10912         orig_conv.inner = (void*)(orig & (~1));
10913         orig_conv.is_owned = false;
10914         LDKClosingSigned ret_var = ClosingSigned_clone(&orig_conv);
10915         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10916         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10917         long ret_ref = (long)ret_var.inner;
10918         if (ret_var.is_owned) {
10919                 ret_ref |= 1;
10920         }
10921         return ret_ref;
10922 }
10923
10924 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ClosingSigned_1get_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
10925         LDKClosingSigned this_ptr_conv;
10926         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10927         this_ptr_conv.is_owned = false;
10928         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
10929         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *ClosingSigned_get_channel_id(&this_ptr_conv));
10930         return ret_arr;
10931 }
10932
10933 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ClosingSigned_1set_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
10934         LDKClosingSigned this_ptr_conv;
10935         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10936         this_ptr_conv.is_owned = false;
10937         LDKThirtyTwoBytes val_ref;
10938         CHECK((*_env)->GetArrayLength (_env, val) == 32);
10939         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
10940         ClosingSigned_set_channel_id(&this_ptr_conv, val_ref);
10941 }
10942
10943 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ClosingSigned_1get_1fee_1satoshis(JNIEnv * _env, jclass _b, jlong this_ptr) {
10944         LDKClosingSigned this_ptr_conv;
10945         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10946         this_ptr_conv.is_owned = false;
10947         jlong ret_val = ClosingSigned_get_fee_satoshis(&this_ptr_conv);
10948         return ret_val;
10949 }
10950
10951 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ClosingSigned_1set_1fee_1satoshis(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
10952         LDKClosingSigned this_ptr_conv;
10953         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10954         this_ptr_conv.is_owned = false;
10955         ClosingSigned_set_fee_satoshis(&this_ptr_conv, val);
10956 }
10957
10958 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ClosingSigned_1get_1signature(JNIEnv * _env, jclass _b, jlong this_ptr) {
10959         LDKClosingSigned this_ptr_conv;
10960         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10961         this_ptr_conv.is_owned = false;
10962         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 64);
10963         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 64, ClosingSigned_get_signature(&this_ptr_conv).compact_form);
10964         return arg_arr;
10965 }
10966
10967 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ClosingSigned_1set_1signature(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
10968         LDKClosingSigned this_ptr_conv;
10969         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10970         this_ptr_conv.is_owned = false;
10971         LDKSignature val_ref;
10972         CHECK((*_env)->GetArrayLength (_env, val) == 64);
10973         (*_env)->GetByteArrayRegion (_env, val, 0, 64, val_ref.compact_form);
10974         ClosingSigned_set_signature(&this_ptr_conv, val_ref);
10975 }
10976
10977 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ClosingSigned_1new(JNIEnv * _env, jclass _b, jbyteArray channel_id_arg, jlong fee_satoshis_arg, jbyteArray signature_arg) {
10978         LDKThirtyTwoBytes channel_id_arg_ref;
10979         CHECK((*_env)->GetArrayLength (_env, channel_id_arg) == 32);
10980         (*_env)->GetByteArrayRegion (_env, channel_id_arg, 0, 32, channel_id_arg_ref.data);
10981         LDKSignature signature_arg_ref;
10982         CHECK((*_env)->GetArrayLength (_env, signature_arg) == 64);
10983         (*_env)->GetByteArrayRegion (_env, signature_arg, 0, 64, signature_arg_ref.compact_form);
10984         LDKClosingSigned ret_var = ClosingSigned_new(channel_id_arg_ref, fee_satoshis_arg, signature_arg_ref);
10985         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10986         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10987         long ret_ref = (long)ret_var.inner;
10988         if (ret_var.is_owned) {
10989                 ret_ref |= 1;
10990         }
10991         return ret_ref;
10992 }
10993
10994 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateAddHTLC_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
10995         LDKUpdateAddHTLC this_ptr_conv;
10996         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10997         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10998         UpdateAddHTLC_free(this_ptr_conv);
10999 }
11000
11001 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UpdateAddHTLC_1clone(JNIEnv * _env, jclass _b, jlong orig) {
11002         LDKUpdateAddHTLC orig_conv;
11003         orig_conv.inner = (void*)(orig & (~1));
11004         orig_conv.is_owned = false;
11005         LDKUpdateAddHTLC ret_var = UpdateAddHTLC_clone(&orig_conv);
11006         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11007         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11008         long ret_ref = (long)ret_var.inner;
11009         if (ret_var.is_owned) {
11010                 ret_ref |= 1;
11011         }
11012         return ret_ref;
11013 }
11014
11015 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UpdateAddHTLC_1get_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
11016         LDKUpdateAddHTLC this_ptr_conv;
11017         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11018         this_ptr_conv.is_owned = false;
11019         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
11020         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *UpdateAddHTLC_get_channel_id(&this_ptr_conv));
11021         return ret_arr;
11022 }
11023
11024 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateAddHTLC_1set_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
11025         LDKUpdateAddHTLC this_ptr_conv;
11026         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11027         this_ptr_conv.is_owned = false;
11028         LDKThirtyTwoBytes val_ref;
11029         CHECK((*_env)->GetArrayLength (_env, val) == 32);
11030         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
11031         UpdateAddHTLC_set_channel_id(&this_ptr_conv, val_ref);
11032 }
11033
11034 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UpdateAddHTLC_1get_1htlc_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
11035         LDKUpdateAddHTLC this_ptr_conv;
11036         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11037         this_ptr_conv.is_owned = false;
11038         jlong ret_val = UpdateAddHTLC_get_htlc_id(&this_ptr_conv);
11039         return ret_val;
11040 }
11041
11042 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateAddHTLC_1set_1htlc_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
11043         LDKUpdateAddHTLC this_ptr_conv;
11044         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11045         this_ptr_conv.is_owned = false;
11046         UpdateAddHTLC_set_htlc_id(&this_ptr_conv, val);
11047 }
11048
11049 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UpdateAddHTLC_1get_1amount_1msat(JNIEnv * _env, jclass _b, jlong this_ptr) {
11050         LDKUpdateAddHTLC this_ptr_conv;
11051         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11052         this_ptr_conv.is_owned = false;
11053         jlong ret_val = UpdateAddHTLC_get_amount_msat(&this_ptr_conv);
11054         return ret_val;
11055 }
11056
11057 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateAddHTLC_1set_1amount_1msat(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
11058         LDKUpdateAddHTLC this_ptr_conv;
11059         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11060         this_ptr_conv.is_owned = false;
11061         UpdateAddHTLC_set_amount_msat(&this_ptr_conv, val);
11062 }
11063
11064 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UpdateAddHTLC_1get_1payment_1hash(JNIEnv * _env, jclass _b, jlong this_ptr) {
11065         LDKUpdateAddHTLC this_ptr_conv;
11066         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11067         this_ptr_conv.is_owned = false;
11068         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
11069         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *UpdateAddHTLC_get_payment_hash(&this_ptr_conv));
11070         return ret_arr;
11071 }
11072
11073 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateAddHTLC_1set_1payment_1hash(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
11074         LDKUpdateAddHTLC this_ptr_conv;
11075         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11076         this_ptr_conv.is_owned = false;
11077         LDKThirtyTwoBytes val_ref;
11078         CHECK((*_env)->GetArrayLength (_env, val) == 32);
11079         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
11080         UpdateAddHTLC_set_payment_hash(&this_ptr_conv, val_ref);
11081 }
11082
11083 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_UpdateAddHTLC_1get_1cltv_1expiry(JNIEnv * _env, jclass _b, jlong this_ptr) {
11084         LDKUpdateAddHTLC this_ptr_conv;
11085         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11086         this_ptr_conv.is_owned = false;
11087         jint ret_val = UpdateAddHTLC_get_cltv_expiry(&this_ptr_conv);
11088         return ret_val;
11089 }
11090
11091 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateAddHTLC_1set_1cltv_1expiry(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
11092         LDKUpdateAddHTLC this_ptr_conv;
11093         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11094         this_ptr_conv.is_owned = false;
11095         UpdateAddHTLC_set_cltv_expiry(&this_ptr_conv, val);
11096 }
11097
11098 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateFulfillHTLC_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
11099         LDKUpdateFulfillHTLC this_ptr_conv;
11100         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11101         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
11102         UpdateFulfillHTLC_free(this_ptr_conv);
11103 }
11104
11105 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UpdateFulfillHTLC_1clone(JNIEnv * _env, jclass _b, jlong orig) {
11106         LDKUpdateFulfillHTLC orig_conv;
11107         orig_conv.inner = (void*)(orig & (~1));
11108         orig_conv.is_owned = false;
11109         LDKUpdateFulfillHTLC ret_var = UpdateFulfillHTLC_clone(&orig_conv);
11110         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11111         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11112         long ret_ref = (long)ret_var.inner;
11113         if (ret_var.is_owned) {
11114                 ret_ref |= 1;
11115         }
11116         return ret_ref;
11117 }
11118
11119 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UpdateFulfillHTLC_1get_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
11120         LDKUpdateFulfillHTLC this_ptr_conv;
11121         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11122         this_ptr_conv.is_owned = false;
11123         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
11124         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *UpdateFulfillHTLC_get_channel_id(&this_ptr_conv));
11125         return ret_arr;
11126 }
11127
11128 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateFulfillHTLC_1set_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
11129         LDKUpdateFulfillHTLC this_ptr_conv;
11130         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11131         this_ptr_conv.is_owned = false;
11132         LDKThirtyTwoBytes val_ref;
11133         CHECK((*_env)->GetArrayLength (_env, val) == 32);
11134         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
11135         UpdateFulfillHTLC_set_channel_id(&this_ptr_conv, val_ref);
11136 }
11137
11138 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UpdateFulfillHTLC_1get_1htlc_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
11139         LDKUpdateFulfillHTLC this_ptr_conv;
11140         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11141         this_ptr_conv.is_owned = false;
11142         jlong ret_val = UpdateFulfillHTLC_get_htlc_id(&this_ptr_conv);
11143         return ret_val;
11144 }
11145
11146 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateFulfillHTLC_1set_1htlc_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
11147         LDKUpdateFulfillHTLC this_ptr_conv;
11148         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11149         this_ptr_conv.is_owned = false;
11150         UpdateFulfillHTLC_set_htlc_id(&this_ptr_conv, val);
11151 }
11152
11153 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UpdateFulfillHTLC_1get_1payment_1preimage(JNIEnv * _env, jclass _b, jlong this_ptr) {
11154         LDKUpdateFulfillHTLC this_ptr_conv;
11155         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11156         this_ptr_conv.is_owned = false;
11157         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
11158         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *UpdateFulfillHTLC_get_payment_preimage(&this_ptr_conv));
11159         return ret_arr;
11160 }
11161
11162 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateFulfillHTLC_1set_1payment_1preimage(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
11163         LDKUpdateFulfillHTLC this_ptr_conv;
11164         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11165         this_ptr_conv.is_owned = false;
11166         LDKThirtyTwoBytes val_ref;
11167         CHECK((*_env)->GetArrayLength (_env, val) == 32);
11168         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
11169         UpdateFulfillHTLC_set_payment_preimage(&this_ptr_conv, val_ref);
11170 }
11171
11172 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UpdateFulfillHTLC_1new(JNIEnv * _env, jclass _b, jbyteArray channel_id_arg, jlong htlc_id_arg, jbyteArray payment_preimage_arg) {
11173         LDKThirtyTwoBytes channel_id_arg_ref;
11174         CHECK((*_env)->GetArrayLength (_env, channel_id_arg) == 32);
11175         (*_env)->GetByteArrayRegion (_env, channel_id_arg, 0, 32, channel_id_arg_ref.data);
11176         LDKThirtyTwoBytes payment_preimage_arg_ref;
11177         CHECK((*_env)->GetArrayLength (_env, payment_preimage_arg) == 32);
11178         (*_env)->GetByteArrayRegion (_env, payment_preimage_arg, 0, 32, payment_preimage_arg_ref.data);
11179         LDKUpdateFulfillHTLC ret_var = UpdateFulfillHTLC_new(channel_id_arg_ref, htlc_id_arg, payment_preimage_arg_ref);
11180         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11181         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11182         long ret_ref = (long)ret_var.inner;
11183         if (ret_var.is_owned) {
11184                 ret_ref |= 1;
11185         }
11186         return ret_ref;
11187 }
11188
11189 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateFailHTLC_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
11190         LDKUpdateFailHTLC this_ptr_conv;
11191         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11192         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
11193         UpdateFailHTLC_free(this_ptr_conv);
11194 }
11195
11196 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UpdateFailHTLC_1clone(JNIEnv * _env, jclass _b, jlong orig) {
11197         LDKUpdateFailHTLC orig_conv;
11198         orig_conv.inner = (void*)(orig & (~1));
11199         orig_conv.is_owned = false;
11200         LDKUpdateFailHTLC ret_var = UpdateFailHTLC_clone(&orig_conv);
11201         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11202         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11203         long ret_ref = (long)ret_var.inner;
11204         if (ret_var.is_owned) {
11205                 ret_ref |= 1;
11206         }
11207         return ret_ref;
11208 }
11209
11210 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UpdateFailHTLC_1get_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
11211         LDKUpdateFailHTLC this_ptr_conv;
11212         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11213         this_ptr_conv.is_owned = false;
11214         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
11215         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *UpdateFailHTLC_get_channel_id(&this_ptr_conv));
11216         return ret_arr;
11217 }
11218
11219 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateFailHTLC_1set_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
11220         LDKUpdateFailHTLC this_ptr_conv;
11221         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11222         this_ptr_conv.is_owned = false;
11223         LDKThirtyTwoBytes val_ref;
11224         CHECK((*_env)->GetArrayLength (_env, val) == 32);
11225         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
11226         UpdateFailHTLC_set_channel_id(&this_ptr_conv, val_ref);
11227 }
11228
11229 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UpdateFailHTLC_1get_1htlc_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
11230         LDKUpdateFailHTLC this_ptr_conv;
11231         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11232         this_ptr_conv.is_owned = false;
11233         jlong ret_val = UpdateFailHTLC_get_htlc_id(&this_ptr_conv);
11234         return ret_val;
11235 }
11236
11237 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateFailHTLC_1set_1htlc_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
11238         LDKUpdateFailHTLC this_ptr_conv;
11239         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11240         this_ptr_conv.is_owned = false;
11241         UpdateFailHTLC_set_htlc_id(&this_ptr_conv, val);
11242 }
11243
11244 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateFailMalformedHTLC_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
11245         LDKUpdateFailMalformedHTLC 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         UpdateFailMalformedHTLC_free(this_ptr_conv);
11249 }
11250
11251 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UpdateFailMalformedHTLC_1clone(JNIEnv * _env, jclass _b, jlong orig) {
11252         LDKUpdateFailMalformedHTLC orig_conv;
11253         orig_conv.inner = (void*)(orig & (~1));
11254         orig_conv.is_owned = false;
11255         LDKUpdateFailMalformedHTLC ret_var = UpdateFailMalformedHTLC_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 jbyteArray JNICALL Java_org_ldk_impl_bindings_UpdateFailMalformedHTLC_1get_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
11266         LDKUpdateFailMalformedHTLC this_ptr_conv;
11267         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11268         this_ptr_conv.is_owned = false;
11269         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
11270         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *UpdateFailMalformedHTLC_get_channel_id(&this_ptr_conv));
11271         return ret_arr;
11272 }
11273
11274 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateFailMalformedHTLC_1set_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
11275         LDKUpdateFailMalformedHTLC 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         UpdateFailMalformedHTLC_set_channel_id(&this_ptr_conv, val_ref);
11282 }
11283
11284 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UpdateFailMalformedHTLC_1get_1htlc_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
11285         LDKUpdateFailMalformedHTLC this_ptr_conv;
11286         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11287         this_ptr_conv.is_owned = false;
11288         jlong ret_val = UpdateFailMalformedHTLC_get_htlc_id(&this_ptr_conv);
11289         return ret_val;
11290 }
11291
11292 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateFailMalformedHTLC_1set_1htlc_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
11293         LDKUpdateFailMalformedHTLC this_ptr_conv;
11294         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11295         this_ptr_conv.is_owned = false;
11296         UpdateFailMalformedHTLC_set_htlc_id(&this_ptr_conv, val);
11297 }
11298
11299 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_UpdateFailMalformedHTLC_1get_1failure_1code(JNIEnv * _env, jclass _b, jlong this_ptr) {
11300         LDKUpdateFailMalformedHTLC this_ptr_conv;
11301         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11302         this_ptr_conv.is_owned = false;
11303         jshort ret_val = UpdateFailMalformedHTLC_get_failure_code(&this_ptr_conv);
11304         return ret_val;
11305 }
11306
11307 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateFailMalformedHTLC_1set_1failure_1code(JNIEnv * _env, jclass _b, jlong this_ptr, jshort val) {
11308         LDKUpdateFailMalformedHTLC this_ptr_conv;
11309         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11310         this_ptr_conv.is_owned = false;
11311         UpdateFailMalformedHTLC_set_failure_code(&this_ptr_conv, val);
11312 }
11313
11314 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CommitmentSigned_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
11315         LDKCommitmentSigned this_ptr_conv;
11316         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11317         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
11318         CommitmentSigned_free(this_ptr_conv);
11319 }
11320
11321 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CommitmentSigned_1clone(JNIEnv * _env, jclass _b, jlong orig) {
11322         LDKCommitmentSigned orig_conv;
11323         orig_conv.inner = (void*)(orig & (~1));
11324         orig_conv.is_owned = false;
11325         LDKCommitmentSigned ret_var = CommitmentSigned_clone(&orig_conv);
11326         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11327         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11328         long ret_ref = (long)ret_var.inner;
11329         if (ret_var.is_owned) {
11330                 ret_ref |= 1;
11331         }
11332         return ret_ref;
11333 }
11334
11335 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_CommitmentSigned_1get_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
11336         LDKCommitmentSigned this_ptr_conv;
11337         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11338         this_ptr_conv.is_owned = false;
11339         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
11340         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *CommitmentSigned_get_channel_id(&this_ptr_conv));
11341         return ret_arr;
11342 }
11343
11344 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CommitmentSigned_1set_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
11345         LDKCommitmentSigned this_ptr_conv;
11346         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11347         this_ptr_conv.is_owned = false;
11348         LDKThirtyTwoBytes val_ref;
11349         CHECK((*_env)->GetArrayLength (_env, val) == 32);
11350         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
11351         CommitmentSigned_set_channel_id(&this_ptr_conv, val_ref);
11352 }
11353
11354 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_CommitmentSigned_1get_1signature(JNIEnv * _env, jclass _b, jlong this_ptr) {
11355         LDKCommitmentSigned this_ptr_conv;
11356         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11357         this_ptr_conv.is_owned = false;
11358         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 64);
11359         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 64, CommitmentSigned_get_signature(&this_ptr_conv).compact_form);
11360         return arg_arr;
11361 }
11362
11363 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CommitmentSigned_1set_1signature(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
11364         LDKCommitmentSigned this_ptr_conv;
11365         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11366         this_ptr_conv.is_owned = false;
11367         LDKSignature val_ref;
11368         CHECK((*_env)->GetArrayLength (_env, val) == 64);
11369         (*_env)->GetByteArrayRegion (_env, val, 0, 64, val_ref.compact_form);
11370         CommitmentSigned_set_signature(&this_ptr_conv, val_ref);
11371 }
11372
11373 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CommitmentSigned_1set_1htlc_1signatures(JNIEnv * _env, jclass _b, jlong this_ptr, jobjectArray val) {
11374         LDKCommitmentSigned this_ptr_conv;
11375         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11376         this_ptr_conv.is_owned = false;
11377         LDKCVec_SignatureZ val_constr;
11378         val_constr.datalen = (*_env)->GetArrayLength (_env, val);
11379         if (val_constr.datalen > 0)
11380                 val_constr.data = MALLOC(val_constr.datalen * sizeof(LDKSignature), "LDKCVec_SignatureZ Elements");
11381         else
11382                 val_constr.data = NULL;
11383         for (size_t i = 0; i < val_constr.datalen; i++) {
11384                 jobject arr_conv_8 = (*_env)->GetObjectArrayElement(_env, val, i);
11385                 LDKSignature arr_conv_8_ref;
11386                 CHECK((*_env)->GetArrayLength (_env, arr_conv_8) == 64);
11387                 (*_env)->GetByteArrayRegion (_env, arr_conv_8, 0, 64, arr_conv_8_ref.compact_form);
11388                 val_constr.data[i] = arr_conv_8_ref;
11389         }
11390         CommitmentSigned_set_htlc_signatures(&this_ptr_conv, val_constr);
11391 }
11392
11393 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CommitmentSigned_1new(JNIEnv * _env, jclass _b, jbyteArray channel_id_arg, jbyteArray signature_arg, jobjectArray htlc_signatures_arg) {
11394         LDKThirtyTwoBytes channel_id_arg_ref;
11395         CHECK((*_env)->GetArrayLength (_env, channel_id_arg) == 32);
11396         (*_env)->GetByteArrayRegion (_env, channel_id_arg, 0, 32, channel_id_arg_ref.data);
11397         LDKSignature signature_arg_ref;
11398         CHECK((*_env)->GetArrayLength (_env, signature_arg) == 64);
11399         (*_env)->GetByteArrayRegion (_env, signature_arg, 0, 64, signature_arg_ref.compact_form);
11400         LDKCVec_SignatureZ htlc_signatures_arg_constr;
11401         htlc_signatures_arg_constr.datalen = (*_env)->GetArrayLength (_env, htlc_signatures_arg);
11402         if (htlc_signatures_arg_constr.datalen > 0)
11403                 htlc_signatures_arg_constr.data = MALLOC(htlc_signatures_arg_constr.datalen * sizeof(LDKSignature), "LDKCVec_SignatureZ Elements");
11404         else
11405                 htlc_signatures_arg_constr.data = NULL;
11406         for (size_t i = 0; i < htlc_signatures_arg_constr.datalen; i++) {
11407                 jobject arr_conv_8 = (*_env)->GetObjectArrayElement(_env, htlc_signatures_arg, i);
11408                 LDKSignature arr_conv_8_ref;
11409                 CHECK((*_env)->GetArrayLength (_env, arr_conv_8) == 64);
11410                 (*_env)->GetByteArrayRegion (_env, arr_conv_8, 0, 64, arr_conv_8_ref.compact_form);
11411                 htlc_signatures_arg_constr.data[i] = arr_conv_8_ref;
11412         }
11413         LDKCommitmentSigned ret_var = CommitmentSigned_new(channel_id_arg_ref, signature_arg_ref, htlc_signatures_arg_constr);
11414         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11415         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11416         long ret_ref = (long)ret_var.inner;
11417         if (ret_var.is_owned) {
11418                 ret_ref |= 1;
11419         }
11420         return ret_ref;
11421 }
11422
11423 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RevokeAndACK_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
11424         LDKRevokeAndACK this_ptr_conv;
11425         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11426         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
11427         RevokeAndACK_free(this_ptr_conv);
11428 }
11429
11430 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_RevokeAndACK_1clone(JNIEnv * _env, jclass _b, jlong orig) {
11431         LDKRevokeAndACK orig_conv;
11432         orig_conv.inner = (void*)(orig & (~1));
11433         orig_conv.is_owned = false;
11434         LDKRevokeAndACK ret_var = RevokeAndACK_clone(&orig_conv);
11435         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11436         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11437         long ret_ref = (long)ret_var.inner;
11438         if (ret_var.is_owned) {
11439                 ret_ref |= 1;
11440         }
11441         return ret_ref;
11442 }
11443
11444 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_RevokeAndACK_1get_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
11445         LDKRevokeAndACK this_ptr_conv;
11446         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11447         this_ptr_conv.is_owned = false;
11448         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
11449         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *RevokeAndACK_get_channel_id(&this_ptr_conv));
11450         return ret_arr;
11451 }
11452
11453 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RevokeAndACK_1set_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
11454         LDKRevokeAndACK this_ptr_conv;
11455         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11456         this_ptr_conv.is_owned = false;
11457         LDKThirtyTwoBytes val_ref;
11458         CHECK((*_env)->GetArrayLength (_env, val) == 32);
11459         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
11460         RevokeAndACK_set_channel_id(&this_ptr_conv, val_ref);
11461 }
11462
11463 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_RevokeAndACK_1get_1per_1commitment_1secret(JNIEnv * _env, jclass _b, jlong this_ptr) {
11464         LDKRevokeAndACK this_ptr_conv;
11465         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11466         this_ptr_conv.is_owned = false;
11467         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
11468         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *RevokeAndACK_get_per_commitment_secret(&this_ptr_conv));
11469         return ret_arr;
11470 }
11471
11472 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RevokeAndACK_1set_1per_1commitment_1secret(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
11473         LDKRevokeAndACK this_ptr_conv;
11474         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11475         this_ptr_conv.is_owned = false;
11476         LDKThirtyTwoBytes val_ref;
11477         CHECK((*_env)->GetArrayLength (_env, val) == 32);
11478         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
11479         RevokeAndACK_set_per_commitment_secret(&this_ptr_conv, val_ref);
11480 }
11481
11482 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_RevokeAndACK_1get_1next_1per_1commitment_1point(JNIEnv * _env, jclass _b, jlong this_ptr) {
11483         LDKRevokeAndACK this_ptr_conv;
11484         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11485         this_ptr_conv.is_owned = false;
11486         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
11487         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, RevokeAndACK_get_next_per_commitment_point(&this_ptr_conv).compressed_form);
11488         return arg_arr;
11489 }
11490
11491 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RevokeAndACK_1set_1next_1per_1commitment_1point(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
11492         LDKRevokeAndACK this_ptr_conv;
11493         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11494         this_ptr_conv.is_owned = false;
11495         LDKPublicKey val_ref;
11496         CHECK((*_env)->GetArrayLength (_env, val) == 33);
11497         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
11498         RevokeAndACK_set_next_per_commitment_point(&this_ptr_conv, val_ref);
11499 }
11500
11501 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_RevokeAndACK_1new(JNIEnv * _env, jclass _b, jbyteArray channel_id_arg, jbyteArray per_commitment_secret_arg, jbyteArray next_per_commitment_point_arg) {
11502         LDKThirtyTwoBytes channel_id_arg_ref;
11503         CHECK((*_env)->GetArrayLength (_env, channel_id_arg) == 32);
11504         (*_env)->GetByteArrayRegion (_env, channel_id_arg, 0, 32, channel_id_arg_ref.data);
11505         LDKThirtyTwoBytes per_commitment_secret_arg_ref;
11506         CHECK((*_env)->GetArrayLength (_env, per_commitment_secret_arg) == 32);
11507         (*_env)->GetByteArrayRegion (_env, per_commitment_secret_arg, 0, 32, per_commitment_secret_arg_ref.data);
11508         LDKPublicKey next_per_commitment_point_arg_ref;
11509         CHECK((*_env)->GetArrayLength (_env, next_per_commitment_point_arg) == 33);
11510         (*_env)->GetByteArrayRegion (_env, next_per_commitment_point_arg, 0, 33, next_per_commitment_point_arg_ref.compressed_form);
11511         LDKRevokeAndACK ret_var = RevokeAndACK_new(channel_id_arg_ref, per_commitment_secret_arg_ref, next_per_commitment_point_arg_ref);
11512         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11513         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11514         long ret_ref = (long)ret_var.inner;
11515         if (ret_var.is_owned) {
11516                 ret_ref |= 1;
11517         }
11518         return ret_ref;
11519 }
11520
11521 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateFee_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
11522         LDKUpdateFee this_ptr_conv;
11523         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11524         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
11525         UpdateFee_free(this_ptr_conv);
11526 }
11527
11528 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UpdateFee_1clone(JNIEnv * _env, jclass _b, jlong orig) {
11529         LDKUpdateFee orig_conv;
11530         orig_conv.inner = (void*)(orig & (~1));
11531         orig_conv.is_owned = false;
11532         LDKUpdateFee ret_var = UpdateFee_clone(&orig_conv);
11533         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11534         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11535         long ret_ref = (long)ret_var.inner;
11536         if (ret_var.is_owned) {
11537                 ret_ref |= 1;
11538         }
11539         return ret_ref;
11540 }
11541
11542 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UpdateFee_1get_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
11543         LDKUpdateFee this_ptr_conv;
11544         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11545         this_ptr_conv.is_owned = false;
11546         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
11547         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *UpdateFee_get_channel_id(&this_ptr_conv));
11548         return ret_arr;
11549 }
11550
11551 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateFee_1set_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
11552         LDKUpdateFee this_ptr_conv;
11553         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11554         this_ptr_conv.is_owned = false;
11555         LDKThirtyTwoBytes val_ref;
11556         CHECK((*_env)->GetArrayLength (_env, val) == 32);
11557         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
11558         UpdateFee_set_channel_id(&this_ptr_conv, val_ref);
11559 }
11560
11561 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_UpdateFee_1get_1feerate_1per_1kw(JNIEnv * _env, jclass _b, jlong this_ptr) {
11562         LDKUpdateFee this_ptr_conv;
11563         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11564         this_ptr_conv.is_owned = false;
11565         jint ret_val = UpdateFee_get_feerate_per_kw(&this_ptr_conv);
11566         return ret_val;
11567 }
11568
11569 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateFee_1set_1feerate_1per_1kw(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
11570         LDKUpdateFee this_ptr_conv;
11571         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11572         this_ptr_conv.is_owned = false;
11573         UpdateFee_set_feerate_per_kw(&this_ptr_conv, val);
11574 }
11575
11576 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UpdateFee_1new(JNIEnv * _env, jclass _b, jbyteArray channel_id_arg, jint feerate_per_kw_arg) {
11577         LDKThirtyTwoBytes channel_id_arg_ref;
11578         CHECK((*_env)->GetArrayLength (_env, channel_id_arg) == 32);
11579         (*_env)->GetByteArrayRegion (_env, channel_id_arg, 0, 32, channel_id_arg_ref.data);
11580         LDKUpdateFee ret_var = UpdateFee_new(channel_id_arg_ref, feerate_per_kw_arg);
11581         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11582         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11583         long ret_ref = (long)ret_var.inner;
11584         if (ret_var.is_owned) {
11585                 ret_ref |= 1;
11586         }
11587         return ret_ref;
11588 }
11589
11590 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_DataLossProtect_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
11591         LDKDataLossProtect this_ptr_conv;
11592         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11593         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
11594         DataLossProtect_free(this_ptr_conv);
11595 }
11596
11597 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_DataLossProtect_1clone(JNIEnv * _env, jclass _b, jlong orig) {
11598         LDKDataLossProtect orig_conv;
11599         orig_conv.inner = (void*)(orig & (~1));
11600         orig_conv.is_owned = false;
11601         LDKDataLossProtect ret_var = DataLossProtect_clone(&orig_conv);
11602         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11603         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11604         long ret_ref = (long)ret_var.inner;
11605         if (ret_var.is_owned) {
11606                 ret_ref |= 1;
11607         }
11608         return ret_ref;
11609 }
11610
11611 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_DataLossProtect_1get_1your_1last_1per_1commitment_1secret(JNIEnv * _env, jclass _b, jlong this_ptr) {
11612         LDKDataLossProtect this_ptr_conv;
11613         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11614         this_ptr_conv.is_owned = false;
11615         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
11616         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *DataLossProtect_get_your_last_per_commitment_secret(&this_ptr_conv));
11617         return ret_arr;
11618 }
11619
11620 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_DataLossProtect_1set_1your_1last_1per_1commitment_1secret(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
11621         LDKDataLossProtect this_ptr_conv;
11622         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11623         this_ptr_conv.is_owned = false;
11624         LDKThirtyTwoBytes val_ref;
11625         CHECK((*_env)->GetArrayLength (_env, val) == 32);
11626         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
11627         DataLossProtect_set_your_last_per_commitment_secret(&this_ptr_conv, val_ref);
11628 }
11629
11630 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_DataLossProtect_1get_1my_1current_1per_1commitment_1point(JNIEnv * _env, jclass _b, jlong this_ptr) {
11631         LDKDataLossProtect this_ptr_conv;
11632         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11633         this_ptr_conv.is_owned = false;
11634         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
11635         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, DataLossProtect_get_my_current_per_commitment_point(&this_ptr_conv).compressed_form);
11636         return arg_arr;
11637 }
11638
11639 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_DataLossProtect_1set_1my_1current_1per_1commitment_1point(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
11640         LDKDataLossProtect this_ptr_conv;
11641         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11642         this_ptr_conv.is_owned = false;
11643         LDKPublicKey val_ref;
11644         CHECK((*_env)->GetArrayLength (_env, val) == 33);
11645         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
11646         DataLossProtect_set_my_current_per_commitment_point(&this_ptr_conv, val_ref);
11647 }
11648
11649 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_DataLossProtect_1new(JNIEnv * _env, jclass _b, jbyteArray your_last_per_commitment_secret_arg, jbyteArray my_current_per_commitment_point_arg) {
11650         LDKThirtyTwoBytes your_last_per_commitment_secret_arg_ref;
11651         CHECK((*_env)->GetArrayLength (_env, your_last_per_commitment_secret_arg) == 32);
11652         (*_env)->GetByteArrayRegion (_env, your_last_per_commitment_secret_arg, 0, 32, your_last_per_commitment_secret_arg_ref.data);
11653         LDKPublicKey my_current_per_commitment_point_arg_ref;
11654         CHECK((*_env)->GetArrayLength (_env, my_current_per_commitment_point_arg) == 33);
11655         (*_env)->GetByteArrayRegion (_env, my_current_per_commitment_point_arg, 0, 33, my_current_per_commitment_point_arg_ref.compressed_form);
11656         LDKDataLossProtect ret_var = DataLossProtect_new(your_last_per_commitment_secret_arg_ref, my_current_per_commitment_point_arg_ref);
11657         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11658         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11659         long ret_ref = (long)ret_var.inner;
11660         if (ret_var.is_owned) {
11661                 ret_ref |= 1;
11662         }
11663         return ret_ref;
11664 }
11665
11666 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelReestablish_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
11667         LDKChannelReestablish this_ptr_conv;
11668         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11669         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
11670         ChannelReestablish_free(this_ptr_conv);
11671 }
11672
11673 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelReestablish_1clone(JNIEnv * _env, jclass _b, jlong orig) {
11674         LDKChannelReestablish orig_conv;
11675         orig_conv.inner = (void*)(orig & (~1));
11676         orig_conv.is_owned = false;
11677         LDKChannelReestablish ret_var = ChannelReestablish_clone(&orig_conv);
11678         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11679         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11680         long ret_ref = (long)ret_var.inner;
11681         if (ret_var.is_owned) {
11682                 ret_ref |= 1;
11683         }
11684         return ret_ref;
11685 }
11686
11687 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelReestablish_1get_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
11688         LDKChannelReestablish this_ptr_conv;
11689         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11690         this_ptr_conv.is_owned = false;
11691         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
11692         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *ChannelReestablish_get_channel_id(&this_ptr_conv));
11693         return ret_arr;
11694 }
11695
11696 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelReestablish_1set_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
11697         LDKChannelReestablish this_ptr_conv;
11698         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11699         this_ptr_conv.is_owned = false;
11700         LDKThirtyTwoBytes val_ref;
11701         CHECK((*_env)->GetArrayLength (_env, val) == 32);
11702         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
11703         ChannelReestablish_set_channel_id(&this_ptr_conv, val_ref);
11704 }
11705
11706 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelReestablish_1get_1next_1local_1commitment_1number(JNIEnv * _env, jclass _b, jlong this_ptr) {
11707         LDKChannelReestablish this_ptr_conv;
11708         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11709         this_ptr_conv.is_owned = false;
11710         jlong ret_val = ChannelReestablish_get_next_local_commitment_number(&this_ptr_conv);
11711         return ret_val;
11712 }
11713
11714 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelReestablish_1set_1next_1local_1commitment_1number(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
11715         LDKChannelReestablish this_ptr_conv;
11716         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11717         this_ptr_conv.is_owned = false;
11718         ChannelReestablish_set_next_local_commitment_number(&this_ptr_conv, val);
11719 }
11720
11721 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelReestablish_1get_1next_1remote_1commitment_1number(JNIEnv * _env, jclass _b, jlong this_ptr) {
11722         LDKChannelReestablish this_ptr_conv;
11723         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11724         this_ptr_conv.is_owned = false;
11725         jlong ret_val = ChannelReestablish_get_next_remote_commitment_number(&this_ptr_conv);
11726         return ret_val;
11727 }
11728
11729 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelReestablish_1set_1next_1remote_1commitment_1number(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
11730         LDKChannelReestablish this_ptr_conv;
11731         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11732         this_ptr_conv.is_owned = false;
11733         ChannelReestablish_set_next_remote_commitment_number(&this_ptr_conv, val);
11734 }
11735
11736 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AnnouncementSignatures_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
11737         LDKAnnouncementSignatures this_ptr_conv;
11738         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11739         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
11740         AnnouncementSignatures_free(this_ptr_conv);
11741 }
11742
11743 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_AnnouncementSignatures_1clone(JNIEnv * _env, jclass _b, jlong orig) {
11744         LDKAnnouncementSignatures orig_conv;
11745         orig_conv.inner = (void*)(orig & (~1));
11746         orig_conv.is_owned = false;
11747         LDKAnnouncementSignatures ret_var = AnnouncementSignatures_clone(&orig_conv);
11748         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11749         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11750         long ret_ref = (long)ret_var.inner;
11751         if (ret_var.is_owned) {
11752                 ret_ref |= 1;
11753         }
11754         return ret_ref;
11755 }
11756
11757 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_AnnouncementSignatures_1get_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
11758         LDKAnnouncementSignatures this_ptr_conv;
11759         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11760         this_ptr_conv.is_owned = false;
11761         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
11762         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *AnnouncementSignatures_get_channel_id(&this_ptr_conv));
11763         return ret_arr;
11764 }
11765
11766 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AnnouncementSignatures_1set_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
11767         LDKAnnouncementSignatures this_ptr_conv;
11768         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11769         this_ptr_conv.is_owned = false;
11770         LDKThirtyTwoBytes val_ref;
11771         CHECK((*_env)->GetArrayLength (_env, val) == 32);
11772         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
11773         AnnouncementSignatures_set_channel_id(&this_ptr_conv, val_ref);
11774 }
11775
11776 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_AnnouncementSignatures_1get_1short_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
11777         LDKAnnouncementSignatures this_ptr_conv;
11778         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11779         this_ptr_conv.is_owned = false;
11780         jlong ret_val = AnnouncementSignatures_get_short_channel_id(&this_ptr_conv);
11781         return ret_val;
11782 }
11783
11784 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AnnouncementSignatures_1set_1short_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
11785         LDKAnnouncementSignatures this_ptr_conv;
11786         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11787         this_ptr_conv.is_owned = false;
11788         AnnouncementSignatures_set_short_channel_id(&this_ptr_conv, val);
11789 }
11790
11791 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_AnnouncementSignatures_1get_1node_1signature(JNIEnv * _env, jclass _b, jlong this_ptr) {
11792         LDKAnnouncementSignatures this_ptr_conv;
11793         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11794         this_ptr_conv.is_owned = false;
11795         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 64);
11796         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 64, AnnouncementSignatures_get_node_signature(&this_ptr_conv).compact_form);
11797         return arg_arr;
11798 }
11799
11800 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AnnouncementSignatures_1set_1node_1signature(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
11801         LDKAnnouncementSignatures this_ptr_conv;
11802         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11803         this_ptr_conv.is_owned = false;
11804         LDKSignature val_ref;
11805         CHECK((*_env)->GetArrayLength (_env, val) == 64);
11806         (*_env)->GetByteArrayRegion (_env, val, 0, 64, val_ref.compact_form);
11807         AnnouncementSignatures_set_node_signature(&this_ptr_conv, val_ref);
11808 }
11809
11810 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_AnnouncementSignatures_1get_1bitcoin_1signature(JNIEnv * _env, jclass _b, jlong this_ptr) {
11811         LDKAnnouncementSignatures this_ptr_conv;
11812         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11813         this_ptr_conv.is_owned = false;
11814         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 64);
11815         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 64, AnnouncementSignatures_get_bitcoin_signature(&this_ptr_conv).compact_form);
11816         return arg_arr;
11817 }
11818
11819 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AnnouncementSignatures_1set_1bitcoin_1signature(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
11820         LDKAnnouncementSignatures this_ptr_conv;
11821         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11822         this_ptr_conv.is_owned = false;
11823         LDKSignature val_ref;
11824         CHECK((*_env)->GetArrayLength (_env, val) == 64);
11825         (*_env)->GetByteArrayRegion (_env, val, 0, 64, val_ref.compact_form);
11826         AnnouncementSignatures_set_bitcoin_signature(&this_ptr_conv, val_ref);
11827 }
11828
11829 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_AnnouncementSignatures_1new(JNIEnv * _env, jclass _b, jbyteArray channel_id_arg, jlong short_channel_id_arg, jbyteArray node_signature_arg, jbyteArray bitcoin_signature_arg) {
11830         LDKThirtyTwoBytes channel_id_arg_ref;
11831         CHECK((*_env)->GetArrayLength (_env, channel_id_arg) == 32);
11832         (*_env)->GetByteArrayRegion (_env, channel_id_arg, 0, 32, channel_id_arg_ref.data);
11833         LDKSignature node_signature_arg_ref;
11834         CHECK((*_env)->GetArrayLength (_env, node_signature_arg) == 64);
11835         (*_env)->GetByteArrayRegion (_env, node_signature_arg, 0, 64, node_signature_arg_ref.compact_form);
11836         LDKSignature bitcoin_signature_arg_ref;
11837         CHECK((*_env)->GetArrayLength (_env, bitcoin_signature_arg) == 64);
11838         (*_env)->GetByteArrayRegion (_env, bitcoin_signature_arg, 0, 64, bitcoin_signature_arg_ref.compact_form);
11839         LDKAnnouncementSignatures ret_var = AnnouncementSignatures_new(channel_id_arg_ref, short_channel_id_arg, node_signature_arg_ref, bitcoin_signature_arg_ref);
11840         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11841         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11842         long ret_ref = (long)ret_var.inner;
11843         if (ret_var.is_owned) {
11844                 ret_ref |= 1;
11845         }
11846         return ret_ref;
11847 }
11848
11849 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NetAddress_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
11850         LDKNetAddress this_ptr_conv = *(LDKNetAddress*)this_ptr;
11851         FREE((void*)this_ptr);
11852         NetAddress_free(this_ptr_conv);
11853 }
11854
11855 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_NetAddress_1clone(JNIEnv * _env, jclass _b, jlong orig) {
11856         LDKNetAddress* orig_conv = (LDKNetAddress*)orig;
11857         LDKNetAddress *ret_copy = MALLOC(sizeof(LDKNetAddress), "LDKNetAddress");
11858         *ret_copy = NetAddress_clone(orig_conv);
11859         long ret_ref = (long)ret_copy;
11860         return ret_ref;
11861 }
11862
11863 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_NetAddress_1write(JNIEnv * _env, jclass _b, jlong obj) {
11864         LDKNetAddress* obj_conv = (LDKNetAddress*)obj;
11865         LDKCVec_u8Z arg_var = NetAddress_write(obj_conv);
11866         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
11867         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
11868         CVec_u8Z_free(arg_var);
11869         return arg_arr;
11870 }
11871
11872 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_Result_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
11873         LDKu8slice ser_ref;
11874         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
11875         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
11876         LDKCResult_CResult_NetAddressu8ZDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_CResult_NetAddressu8ZDecodeErrorZ), "LDKCResult_CResult_NetAddressu8ZDecodeErrorZ");
11877         *ret_conv = Result_read(ser_ref);
11878         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
11879         return (long)ret_conv;
11880 }
11881
11882 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedNodeAnnouncement_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
11883         LDKUnsignedNodeAnnouncement this_ptr_conv;
11884         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11885         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
11886         UnsignedNodeAnnouncement_free(this_ptr_conv);
11887 }
11888
11889 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UnsignedNodeAnnouncement_1clone(JNIEnv * _env, jclass _b, jlong orig) {
11890         LDKUnsignedNodeAnnouncement orig_conv;
11891         orig_conv.inner = (void*)(orig & (~1));
11892         orig_conv.is_owned = false;
11893         LDKUnsignedNodeAnnouncement ret_var = UnsignedNodeAnnouncement_clone(&orig_conv);
11894         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11895         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11896         long ret_ref = (long)ret_var.inner;
11897         if (ret_var.is_owned) {
11898                 ret_ref |= 1;
11899         }
11900         return ret_ref;
11901 }
11902
11903 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UnsignedNodeAnnouncement_1get_1features(JNIEnv * _env, jclass _b, jlong this_ptr) {
11904         LDKUnsignedNodeAnnouncement this_ptr_conv;
11905         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11906         this_ptr_conv.is_owned = false;
11907         LDKNodeFeatures ret_var = UnsignedNodeAnnouncement_get_features(&this_ptr_conv);
11908         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11909         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11910         long ret_ref = (long)ret_var.inner;
11911         if (ret_var.is_owned) {
11912                 ret_ref |= 1;
11913         }
11914         return ret_ref;
11915 }
11916
11917 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedNodeAnnouncement_1set_1features(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
11918         LDKUnsignedNodeAnnouncement this_ptr_conv;
11919         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11920         this_ptr_conv.is_owned = false;
11921         LDKNodeFeatures val_conv;
11922         val_conv.inner = (void*)(val & (~1));
11923         val_conv.is_owned = (val & 1) || (val == 0);
11924         // Warning: we may need a move here but can't clone!
11925         UnsignedNodeAnnouncement_set_features(&this_ptr_conv, val_conv);
11926 }
11927
11928 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_UnsignedNodeAnnouncement_1get_1timestamp(JNIEnv * _env, jclass _b, jlong this_ptr) {
11929         LDKUnsignedNodeAnnouncement this_ptr_conv;
11930         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11931         this_ptr_conv.is_owned = false;
11932         jint ret_val = UnsignedNodeAnnouncement_get_timestamp(&this_ptr_conv);
11933         return ret_val;
11934 }
11935
11936 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedNodeAnnouncement_1set_1timestamp(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
11937         LDKUnsignedNodeAnnouncement this_ptr_conv;
11938         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11939         this_ptr_conv.is_owned = false;
11940         UnsignedNodeAnnouncement_set_timestamp(&this_ptr_conv, val);
11941 }
11942
11943 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UnsignedNodeAnnouncement_1get_1node_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
11944         LDKUnsignedNodeAnnouncement this_ptr_conv;
11945         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11946         this_ptr_conv.is_owned = false;
11947         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
11948         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, UnsignedNodeAnnouncement_get_node_id(&this_ptr_conv).compressed_form);
11949         return arg_arr;
11950 }
11951
11952 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedNodeAnnouncement_1set_1node_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
11953         LDKUnsignedNodeAnnouncement this_ptr_conv;
11954         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11955         this_ptr_conv.is_owned = false;
11956         LDKPublicKey val_ref;
11957         CHECK((*_env)->GetArrayLength (_env, val) == 33);
11958         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
11959         UnsignedNodeAnnouncement_set_node_id(&this_ptr_conv, val_ref);
11960 }
11961
11962 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UnsignedNodeAnnouncement_1get_1rgb(JNIEnv * _env, jclass _b, jlong this_ptr) {
11963         LDKUnsignedNodeAnnouncement this_ptr_conv;
11964         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11965         this_ptr_conv.is_owned = false;
11966         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 3);
11967         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 3, *UnsignedNodeAnnouncement_get_rgb(&this_ptr_conv));
11968         return ret_arr;
11969 }
11970
11971 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedNodeAnnouncement_1set_1rgb(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
11972         LDKUnsignedNodeAnnouncement this_ptr_conv;
11973         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11974         this_ptr_conv.is_owned = false;
11975         LDKThreeBytes val_ref;
11976         CHECK((*_env)->GetArrayLength (_env, val) == 3);
11977         (*_env)->GetByteArrayRegion (_env, val, 0, 3, val_ref.data);
11978         UnsignedNodeAnnouncement_set_rgb(&this_ptr_conv, val_ref);
11979 }
11980
11981 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UnsignedNodeAnnouncement_1get_1alias(JNIEnv * _env, jclass _b, jlong this_ptr) {
11982         LDKUnsignedNodeAnnouncement this_ptr_conv;
11983         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11984         this_ptr_conv.is_owned = false;
11985         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
11986         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *UnsignedNodeAnnouncement_get_alias(&this_ptr_conv));
11987         return ret_arr;
11988 }
11989
11990 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedNodeAnnouncement_1set_1alias(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
11991         LDKUnsignedNodeAnnouncement this_ptr_conv;
11992         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11993         this_ptr_conv.is_owned = false;
11994         LDKThirtyTwoBytes val_ref;
11995         CHECK((*_env)->GetArrayLength (_env, val) == 32);
11996         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
11997         UnsignedNodeAnnouncement_set_alias(&this_ptr_conv, val_ref);
11998 }
11999
12000 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedNodeAnnouncement_1set_1addresses(JNIEnv * _env, jclass _b, jlong this_ptr, jlongArray val) {
12001         LDKUnsignedNodeAnnouncement this_ptr_conv;
12002         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12003         this_ptr_conv.is_owned = false;
12004         LDKCVec_NetAddressZ val_constr;
12005         val_constr.datalen = (*_env)->GetArrayLength (_env, val);
12006         if (val_constr.datalen > 0)
12007                 val_constr.data = MALLOC(val_constr.datalen * sizeof(LDKNetAddress), "LDKCVec_NetAddressZ Elements");
12008         else
12009                 val_constr.data = NULL;
12010         long* val_vals = (*_env)->GetLongArrayElements (_env, val, NULL);
12011         for (size_t m = 0; m < val_constr.datalen; m++) {
12012                 long arr_conv_12 = val_vals[m];
12013                 LDKNetAddress arr_conv_12_conv = *(LDKNetAddress*)arr_conv_12;
12014                 FREE((void*)arr_conv_12);
12015                 val_constr.data[m] = arr_conv_12_conv;
12016         }
12017         (*_env)->ReleaseLongArrayElements (_env, val, val_vals, 0);
12018         UnsignedNodeAnnouncement_set_addresses(&this_ptr_conv, val_constr);
12019 }
12020
12021 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NodeAnnouncement_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
12022         LDKNodeAnnouncement this_ptr_conv;
12023         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12024         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12025         NodeAnnouncement_free(this_ptr_conv);
12026 }
12027
12028 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_NodeAnnouncement_1clone(JNIEnv * _env, jclass _b, jlong orig) {
12029         LDKNodeAnnouncement orig_conv;
12030         orig_conv.inner = (void*)(orig & (~1));
12031         orig_conv.is_owned = false;
12032         LDKNodeAnnouncement ret_var = NodeAnnouncement_clone(&orig_conv);
12033         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12034         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12035         long ret_ref = (long)ret_var.inner;
12036         if (ret_var.is_owned) {
12037                 ret_ref |= 1;
12038         }
12039         return ret_ref;
12040 }
12041
12042 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_NodeAnnouncement_1get_1signature(JNIEnv * _env, jclass _b, jlong this_ptr) {
12043         LDKNodeAnnouncement this_ptr_conv;
12044         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12045         this_ptr_conv.is_owned = false;
12046         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 64);
12047         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 64, NodeAnnouncement_get_signature(&this_ptr_conv).compact_form);
12048         return arg_arr;
12049 }
12050
12051 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NodeAnnouncement_1set_1signature(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
12052         LDKNodeAnnouncement this_ptr_conv;
12053         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12054         this_ptr_conv.is_owned = false;
12055         LDKSignature val_ref;
12056         CHECK((*_env)->GetArrayLength (_env, val) == 64);
12057         (*_env)->GetByteArrayRegion (_env, val, 0, 64, val_ref.compact_form);
12058         NodeAnnouncement_set_signature(&this_ptr_conv, val_ref);
12059 }
12060
12061 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_NodeAnnouncement_1get_1contents(JNIEnv * _env, jclass _b, jlong this_ptr) {
12062         LDKNodeAnnouncement this_ptr_conv;
12063         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12064         this_ptr_conv.is_owned = false;
12065         LDKUnsignedNodeAnnouncement ret_var = NodeAnnouncement_get_contents(&this_ptr_conv);
12066         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12067         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12068         long ret_ref = (long)ret_var.inner;
12069         if (ret_var.is_owned) {
12070                 ret_ref |= 1;
12071         }
12072         return ret_ref;
12073 }
12074
12075 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NodeAnnouncement_1set_1contents(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
12076         LDKNodeAnnouncement this_ptr_conv;
12077         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12078         this_ptr_conv.is_owned = false;
12079         LDKUnsignedNodeAnnouncement val_conv;
12080         val_conv.inner = (void*)(val & (~1));
12081         val_conv.is_owned = (val & 1) || (val == 0);
12082         if (val_conv.inner != NULL)
12083                 val_conv = UnsignedNodeAnnouncement_clone(&val_conv);
12084         NodeAnnouncement_set_contents(&this_ptr_conv, val_conv);
12085 }
12086
12087 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_NodeAnnouncement_1new(JNIEnv * _env, jclass _b, jbyteArray signature_arg, jlong contents_arg) {
12088         LDKSignature signature_arg_ref;
12089         CHECK((*_env)->GetArrayLength (_env, signature_arg) == 64);
12090         (*_env)->GetByteArrayRegion (_env, signature_arg, 0, 64, signature_arg_ref.compact_form);
12091         LDKUnsignedNodeAnnouncement contents_arg_conv;
12092         contents_arg_conv.inner = (void*)(contents_arg & (~1));
12093         contents_arg_conv.is_owned = (contents_arg & 1) || (contents_arg == 0);
12094         if (contents_arg_conv.inner != NULL)
12095                 contents_arg_conv = UnsignedNodeAnnouncement_clone(&contents_arg_conv);
12096         LDKNodeAnnouncement ret_var = NodeAnnouncement_new(signature_arg_ref, contents_arg_conv);
12097         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12098         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12099         long ret_ref = (long)ret_var.inner;
12100         if (ret_var.is_owned) {
12101                 ret_ref |= 1;
12102         }
12103         return ret_ref;
12104 }
12105
12106 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
12107         LDKUnsignedChannelAnnouncement this_ptr_conv;
12108         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12109         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12110         UnsignedChannelAnnouncement_free(this_ptr_conv);
12111 }
12112
12113 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1clone(JNIEnv * _env, jclass _b, jlong orig) {
12114         LDKUnsignedChannelAnnouncement orig_conv;
12115         orig_conv.inner = (void*)(orig & (~1));
12116         orig_conv.is_owned = false;
12117         LDKUnsignedChannelAnnouncement ret_var = UnsignedChannelAnnouncement_clone(&orig_conv);
12118         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12119         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12120         long ret_ref = (long)ret_var.inner;
12121         if (ret_var.is_owned) {
12122                 ret_ref |= 1;
12123         }
12124         return ret_ref;
12125 }
12126
12127 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1get_1features(JNIEnv * _env, jclass _b, jlong this_ptr) {
12128         LDKUnsignedChannelAnnouncement this_ptr_conv;
12129         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12130         this_ptr_conv.is_owned = false;
12131         LDKChannelFeatures ret_var = UnsignedChannelAnnouncement_get_features(&this_ptr_conv);
12132         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12133         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12134         long ret_ref = (long)ret_var.inner;
12135         if (ret_var.is_owned) {
12136                 ret_ref |= 1;
12137         }
12138         return ret_ref;
12139 }
12140
12141 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1set_1features(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
12142         LDKUnsignedChannelAnnouncement this_ptr_conv;
12143         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12144         this_ptr_conv.is_owned = false;
12145         LDKChannelFeatures val_conv;
12146         val_conv.inner = (void*)(val & (~1));
12147         val_conv.is_owned = (val & 1) || (val == 0);
12148         // Warning: we may need a move here but can't clone!
12149         UnsignedChannelAnnouncement_set_features(&this_ptr_conv, val_conv);
12150 }
12151
12152 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1get_1chain_1hash(JNIEnv * _env, jclass _b, jlong this_ptr) {
12153         LDKUnsignedChannelAnnouncement this_ptr_conv;
12154         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12155         this_ptr_conv.is_owned = false;
12156         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
12157         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *UnsignedChannelAnnouncement_get_chain_hash(&this_ptr_conv));
12158         return ret_arr;
12159 }
12160
12161 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1set_1chain_1hash(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
12162         LDKUnsignedChannelAnnouncement this_ptr_conv;
12163         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12164         this_ptr_conv.is_owned = false;
12165         LDKThirtyTwoBytes val_ref;
12166         CHECK((*_env)->GetArrayLength (_env, val) == 32);
12167         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
12168         UnsignedChannelAnnouncement_set_chain_hash(&this_ptr_conv, val_ref);
12169 }
12170
12171 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1get_1short_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
12172         LDKUnsignedChannelAnnouncement this_ptr_conv;
12173         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12174         this_ptr_conv.is_owned = false;
12175         jlong ret_val = UnsignedChannelAnnouncement_get_short_channel_id(&this_ptr_conv);
12176         return ret_val;
12177 }
12178
12179 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1set_1short_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
12180         LDKUnsignedChannelAnnouncement this_ptr_conv;
12181         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12182         this_ptr_conv.is_owned = false;
12183         UnsignedChannelAnnouncement_set_short_channel_id(&this_ptr_conv, val);
12184 }
12185
12186 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1get_1node_1id_11(JNIEnv * _env, jclass _b, jlong this_ptr) {
12187         LDKUnsignedChannelAnnouncement this_ptr_conv;
12188         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12189         this_ptr_conv.is_owned = false;
12190         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
12191         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, UnsignedChannelAnnouncement_get_node_id_1(&this_ptr_conv).compressed_form);
12192         return arg_arr;
12193 }
12194
12195 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1set_1node_1id_11(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
12196         LDKUnsignedChannelAnnouncement this_ptr_conv;
12197         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12198         this_ptr_conv.is_owned = false;
12199         LDKPublicKey val_ref;
12200         CHECK((*_env)->GetArrayLength (_env, val) == 33);
12201         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
12202         UnsignedChannelAnnouncement_set_node_id_1(&this_ptr_conv, val_ref);
12203 }
12204
12205 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1get_1node_1id_12(JNIEnv * _env, jclass _b, jlong this_ptr) {
12206         LDKUnsignedChannelAnnouncement this_ptr_conv;
12207         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12208         this_ptr_conv.is_owned = false;
12209         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
12210         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, UnsignedChannelAnnouncement_get_node_id_2(&this_ptr_conv).compressed_form);
12211         return arg_arr;
12212 }
12213
12214 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1set_1node_1id_12(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
12215         LDKUnsignedChannelAnnouncement this_ptr_conv;
12216         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12217         this_ptr_conv.is_owned = false;
12218         LDKPublicKey val_ref;
12219         CHECK((*_env)->GetArrayLength (_env, val) == 33);
12220         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
12221         UnsignedChannelAnnouncement_set_node_id_2(&this_ptr_conv, val_ref);
12222 }
12223
12224 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1get_1bitcoin_1key_11(JNIEnv * _env, jclass _b, jlong this_ptr) {
12225         LDKUnsignedChannelAnnouncement this_ptr_conv;
12226         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12227         this_ptr_conv.is_owned = false;
12228         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
12229         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, UnsignedChannelAnnouncement_get_bitcoin_key_1(&this_ptr_conv).compressed_form);
12230         return arg_arr;
12231 }
12232
12233 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1set_1bitcoin_1key_11(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
12234         LDKUnsignedChannelAnnouncement this_ptr_conv;
12235         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12236         this_ptr_conv.is_owned = false;
12237         LDKPublicKey val_ref;
12238         CHECK((*_env)->GetArrayLength (_env, val) == 33);
12239         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
12240         UnsignedChannelAnnouncement_set_bitcoin_key_1(&this_ptr_conv, val_ref);
12241 }
12242
12243 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1get_1bitcoin_1key_12(JNIEnv * _env, jclass _b, jlong this_ptr) {
12244         LDKUnsignedChannelAnnouncement this_ptr_conv;
12245         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12246         this_ptr_conv.is_owned = false;
12247         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
12248         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, UnsignedChannelAnnouncement_get_bitcoin_key_2(&this_ptr_conv).compressed_form);
12249         return arg_arr;
12250 }
12251
12252 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1set_1bitcoin_1key_12(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
12253         LDKUnsignedChannelAnnouncement this_ptr_conv;
12254         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12255         this_ptr_conv.is_owned = false;
12256         LDKPublicKey val_ref;
12257         CHECK((*_env)->GetArrayLength (_env, val) == 33);
12258         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
12259         UnsignedChannelAnnouncement_set_bitcoin_key_2(&this_ptr_conv, val_ref);
12260 }
12261
12262 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelAnnouncement_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
12263         LDKChannelAnnouncement this_ptr_conv;
12264         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12265         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12266         ChannelAnnouncement_free(this_ptr_conv);
12267 }
12268
12269 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelAnnouncement_1clone(JNIEnv * _env, jclass _b, jlong orig) {
12270         LDKChannelAnnouncement orig_conv;
12271         orig_conv.inner = (void*)(orig & (~1));
12272         orig_conv.is_owned = false;
12273         LDKChannelAnnouncement ret_var = ChannelAnnouncement_clone(&orig_conv);
12274         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12275         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12276         long ret_ref = (long)ret_var.inner;
12277         if (ret_var.is_owned) {
12278                 ret_ref |= 1;
12279         }
12280         return ret_ref;
12281 }
12282
12283 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelAnnouncement_1get_1node_1signature_11(JNIEnv * _env, jclass _b, jlong this_ptr) {
12284         LDKChannelAnnouncement this_ptr_conv;
12285         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12286         this_ptr_conv.is_owned = false;
12287         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 64);
12288         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 64, ChannelAnnouncement_get_node_signature_1(&this_ptr_conv).compact_form);
12289         return arg_arr;
12290 }
12291
12292 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelAnnouncement_1set_1node_1signature_11(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
12293         LDKChannelAnnouncement this_ptr_conv;
12294         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12295         this_ptr_conv.is_owned = false;
12296         LDKSignature val_ref;
12297         CHECK((*_env)->GetArrayLength (_env, val) == 64);
12298         (*_env)->GetByteArrayRegion (_env, val, 0, 64, val_ref.compact_form);
12299         ChannelAnnouncement_set_node_signature_1(&this_ptr_conv, val_ref);
12300 }
12301
12302 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelAnnouncement_1get_1node_1signature_12(JNIEnv * _env, jclass _b, jlong this_ptr) {
12303         LDKChannelAnnouncement this_ptr_conv;
12304         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12305         this_ptr_conv.is_owned = false;
12306         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 64);
12307         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 64, ChannelAnnouncement_get_node_signature_2(&this_ptr_conv).compact_form);
12308         return arg_arr;
12309 }
12310
12311 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelAnnouncement_1set_1node_1signature_12(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
12312         LDKChannelAnnouncement this_ptr_conv;
12313         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12314         this_ptr_conv.is_owned = false;
12315         LDKSignature val_ref;
12316         CHECK((*_env)->GetArrayLength (_env, val) == 64);
12317         (*_env)->GetByteArrayRegion (_env, val, 0, 64, val_ref.compact_form);
12318         ChannelAnnouncement_set_node_signature_2(&this_ptr_conv, val_ref);
12319 }
12320
12321 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelAnnouncement_1get_1bitcoin_1signature_11(JNIEnv * _env, jclass _b, jlong this_ptr) {
12322         LDKChannelAnnouncement this_ptr_conv;
12323         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12324         this_ptr_conv.is_owned = false;
12325         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 64);
12326         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 64, ChannelAnnouncement_get_bitcoin_signature_1(&this_ptr_conv).compact_form);
12327         return arg_arr;
12328 }
12329
12330 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelAnnouncement_1set_1bitcoin_1signature_11(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
12331         LDKChannelAnnouncement this_ptr_conv;
12332         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12333         this_ptr_conv.is_owned = false;
12334         LDKSignature val_ref;
12335         CHECK((*_env)->GetArrayLength (_env, val) == 64);
12336         (*_env)->GetByteArrayRegion (_env, val, 0, 64, val_ref.compact_form);
12337         ChannelAnnouncement_set_bitcoin_signature_1(&this_ptr_conv, val_ref);
12338 }
12339
12340 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelAnnouncement_1get_1bitcoin_1signature_12(JNIEnv * _env, jclass _b, jlong this_ptr) {
12341         LDKChannelAnnouncement this_ptr_conv;
12342         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12343         this_ptr_conv.is_owned = false;
12344         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 64);
12345         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 64, ChannelAnnouncement_get_bitcoin_signature_2(&this_ptr_conv).compact_form);
12346         return arg_arr;
12347 }
12348
12349 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelAnnouncement_1set_1bitcoin_1signature_12(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
12350         LDKChannelAnnouncement this_ptr_conv;
12351         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12352         this_ptr_conv.is_owned = false;
12353         LDKSignature val_ref;
12354         CHECK((*_env)->GetArrayLength (_env, val) == 64);
12355         (*_env)->GetByteArrayRegion (_env, val, 0, 64, val_ref.compact_form);
12356         ChannelAnnouncement_set_bitcoin_signature_2(&this_ptr_conv, val_ref);
12357 }
12358
12359 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelAnnouncement_1get_1contents(JNIEnv * _env, jclass _b, jlong this_ptr) {
12360         LDKChannelAnnouncement this_ptr_conv;
12361         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12362         this_ptr_conv.is_owned = false;
12363         LDKUnsignedChannelAnnouncement ret_var = ChannelAnnouncement_get_contents(&this_ptr_conv);
12364         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12365         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12366         long ret_ref = (long)ret_var.inner;
12367         if (ret_var.is_owned) {
12368                 ret_ref |= 1;
12369         }
12370         return ret_ref;
12371 }
12372
12373 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelAnnouncement_1set_1contents(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
12374         LDKChannelAnnouncement this_ptr_conv;
12375         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12376         this_ptr_conv.is_owned = false;
12377         LDKUnsignedChannelAnnouncement val_conv;
12378         val_conv.inner = (void*)(val & (~1));
12379         val_conv.is_owned = (val & 1) || (val == 0);
12380         if (val_conv.inner != NULL)
12381                 val_conv = UnsignedChannelAnnouncement_clone(&val_conv);
12382         ChannelAnnouncement_set_contents(&this_ptr_conv, val_conv);
12383 }
12384
12385 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelAnnouncement_1new(JNIEnv * _env, jclass _b, jbyteArray node_signature_1_arg, jbyteArray node_signature_2_arg, jbyteArray bitcoin_signature_1_arg, jbyteArray bitcoin_signature_2_arg, jlong contents_arg) {
12386         LDKSignature node_signature_1_arg_ref;
12387         CHECK((*_env)->GetArrayLength (_env, node_signature_1_arg) == 64);
12388         (*_env)->GetByteArrayRegion (_env, node_signature_1_arg, 0, 64, node_signature_1_arg_ref.compact_form);
12389         LDKSignature node_signature_2_arg_ref;
12390         CHECK((*_env)->GetArrayLength (_env, node_signature_2_arg) == 64);
12391         (*_env)->GetByteArrayRegion (_env, node_signature_2_arg, 0, 64, node_signature_2_arg_ref.compact_form);
12392         LDKSignature bitcoin_signature_1_arg_ref;
12393         CHECK((*_env)->GetArrayLength (_env, bitcoin_signature_1_arg) == 64);
12394         (*_env)->GetByteArrayRegion (_env, bitcoin_signature_1_arg, 0, 64, bitcoin_signature_1_arg_ref.compact_form);
12395         LDKSignature bitcoin_signature_2_arg_ref;
12396         CHECK((*_env)->GetArrayLength (_env, bitcoin_signature_2_arg) == 64);
12397         (*_env)->GetByteArrayRegion (_env, bitcoin_signature_2_arg, 0, 64, bitcoin_signature_2_arg_ref.compact_form);
12398         LDKUnsignedChannelAnnouncement contents_arg_conv;
12399         contents_arg_conv.inner = (void*)(contents_arg & (~1));
12400         contents_arg_conv.is_owned = (contents_arg & 1) || (contents_arg == 0);
12401         if (contents_arg_conv.inner != NULL)
12402                 contents_arg_conv = UnsignedChannelAnnouncement_clone(&contents_arg_conv);
12403         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);
12404         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12405         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12406         long ret_ref = (long)ret_var.inner;
12407         if (ret_var.is_owned) {
12408                 ret_ref |= 1;
12409         }
12410         return ret_ref;
12411 }
12412
12413 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
12414         LDKUnsignedChannelUpdate this_ptr_conv;
12415         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12416         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12417         UnsignedChannelUpdate_free(this_ptr_conv);
12418 }
12419
12420 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1clone(JNIEnv * _env, jclass _b, jlong orig) {
12421         LDKUnsignedChannelUpdate orig_conv;
12422         orig_conv.inner = (void*)(orig & (~1));
12423         orig_conv.is_owned = false;
12424         LDKUnsignedChannelUpdate ret_var = UnsignedChannelUpdate_clone(&orig_conv);
12425         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12426         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12427         long ret_ref = (long)ret_var.inner;
12428         if (ret_var.is_owned) {
12429                 ret_ref |= 1;
12430         }
12431         return ret_ref;
12432 }
12433
12434 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1get_1chain_1hash(JNIEnv * _env, jclass _b, jlong this_ptr) {
12435         LDKUnsignedChannelUpdate this_ptr_conv;
12436         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12437         this_ptr_conv.is_owned = false;
12438         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
12439         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *UnsignedChannelUpdate_get_chain_hash(&this_ptr_conv));
12440         return ret_arr;
12441 }
12442
12443 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1set_1chain_1hash(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
12444         LDKUnsignedChannelUpdate this_ptr_conv;
12445         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12446         this_ptr_conv.is_owned = false;
12447         LDKThirtyTwoBytes val_ref;
12448         CHECK((*_env)->GetArrayLength (_env, val) == 32);
12449         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
12450         UnsignedChannelUpdate_set_chain_hash(&this_ptr_conv, val_ref);
12451 }
12452
12453 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1get_1short_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
12454         LDKUnsignedChannelUpdate this_ptr_conv;
12455         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12456         this_ptr_conv.is_owned = false;
12457         jlong ret_val = UnsignedChannelUpdate_get_short_channel_id(&this_ptr_conv);
12458         return ret_val;
12459 }
12460
12461 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1set_1short_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
12462         LDKUnsignedChannelUpdate this_ptr_conv;
12463         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12464         this_ptr_conv.is_owned = false;
12465         UnsignedChannelUpdate_set_short_channel_id(&this_ptr_conv, val);
12466 }
12467
12468 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1get_1timestamp(JNIEnv * _env, jclass _b, jlong this_ptr) {
12469         LDKUnsignedChannelUpdate this_ptr_conv;
12470         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12471         this_ptr_conv.is_owned = false;
12472         jint ret_val = UnsignedChannelUpdate_get_timestamp(&this_ptr_conv);
12473         return ret_val;
12474 }
12475
12476 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1set_1timestamp(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
12477         LDKUnsignedChannelUpdate this_ptr_conv;
12478         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12479         this_ptr_conv.is_owned = false;
12480         UnsignedChannelUpdate_set_timestamp(&this_ptr_conv, val);
12481 }
12482
12483 JNIEXPORT jbyte JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1get_1flags(JNIEnv * _env, jclass _b, jlong this_ptr) {
12484         LDKUnsignedChannelUpdate this_ptr_conv;
12485         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12486         this_ptr_conv.is_owned = false;
12487         jbyte ret_val = UnsignedChannelUpdate_get_flags(&this_ptr_conv);
12488         return ret_val;
12489 }
12490
12491 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1set_1flags(JNIEnv * _env, jclass _b, jlong this_ptr, jbyte val) {
12492         LDKUnsignedChannelUpdate this_ptr_conv;
12493         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12494         this_ptr_conv.is_owned = false;
12495         UnsignedChannelUpdate_set_flags(&this_ptr_conv, val);
12496 }
12497
12498 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1get_1cltv_1expiry_1delta(JNIEnv * _env, jclass _b, jlong this_ptr) {
12499         LDKUnsignedChannelUpdate this_ptr_conv;
12500         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12501         this_ptr_conv.is_owned = false;
12502         jshort ret_val = UnsignedChannelUpdate_get_cltv_expiry_delta(&this_ptr_conv);
12503         return ret_val;
12504 }
12505
12506 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1set_1cltv_1expiry_1delta(JNIEnv * _env, jclass _b, jlong this_ptr, jshort val) {
12507         LDKUnsignedChannelUpdate this_ptr_conv;
12508         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12509         this_ptr_conv.is_owned = false;
12510         UnsignedChannelUpdate_set_cltv_expiry_delta(&this_ptr_conv, val);
12511 }
12512
12513 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1get_1htlc_1minimum_1msat(JNIEnv * _env, jclass _b, jlong this_ptr) {
12514         LDKUnsignedChannelUpdate this_ptr_conv;
12515         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12516         this_ptr_conv.is_owned = false;
12517         jlong ret_val = UnsignedChannelUpdate_get_htlc_minimum_msat(&this_ptr_conv);
12518         return ret_val;
12519 }
12520
12521 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1set_1htlc_1minimum_1msat(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
12522         LDKUnsignedChannelUpdate this_ptr_conv;
12523         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12524         this_ptr_conv.is_owned = false;
12525         UnsignedChannelUpdate_set_htlc_minimum_msat(&this_ptr_conv, val);
12526 }
12527
12528 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1get_1fee_1base_1msat(JNIEnv * _env, jclass _b, jlong this_ptr) {
12529         LDKUnsignedChannelUpdate this_ptr_conv;
12530         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12531         this_ptr_conv.is_owned = false;
12532         jint ret_val = UnsignedChannelUpdate_get_fee_base_msat(&this_ptr_conv);
12533         return ret_val;
12534 }
12535
12536 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1set_1fee_1base_1msat(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
12537         LDKUnsignedChannelUpdate this_ptr_conv;
12538         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12539         this_ptr_conv.is_owned = false;
12540         UnsignedChannelUpdate_set_fee_base_msat(&this_ptr_conv, val);
12541 }
12542
12543 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1get_1fee_1proportional_1millionths(JNIEnv * _env, jclass _b, jlong this_ptr) {
12544         LDKUnsignedChannelUpdate this_ptr_conv;
12545         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12546         this_ptr_conv.is_owned = false;
12547         jint ret_val = UnsignedChannelUpdate_get_fee_proportional_millionths(&this_ptr_conv);
12548         return ret_val;
12549 }
12550
12551 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1set_1fee_1proportional_1millionths(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
12552         LDKUnsignedChannelUpdate this_ptr_conv;
12553         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12554         this_ptr_conv.is_owned = false;
12555         UnsignedChannelUpdate_set_fee_proportional_millionths(&this_ptr_conv, val);
12556 }
12557
12558 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelUpdate_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
12559         LDKChannelUpdate this_ptr_conv;
12560         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12561         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12562         ChannelUpdate_free(this_ptr_conv);
12563 }
12564
12565 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelUpdate_1clone(JNIEnv * _env, jclass _b, jlong orig) {
12566         LDKChannelUpdate orig_conv;
12567         orig_conv.inner = (void*)(orig & (~1));
12568         orig_conv.is_owned = false;
12569         LDKChannelUpdate ret_var = ChannelUpdate_clone(&orig_conv);
12570         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12571         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12572         long ret_ref = (long)ret_var.inner;
12573         if (ret_var.is_owned) {
12574                 ret_ref |= 1;
12575         }
12576         return ret_ref;
12577 }
12578
12579 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelUpdate_1get_1signature(JNIEnv * _env, jclass _b, jlong this_ptr) {
12580         LDKChannelUpdate this_ptr_conv;
12581         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12582         this_ptr_conv.is_owned = false;
12583         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 64);
12584         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 64, ChannelUpdate_get_signature(&this_ptr_conv).compact_form);
12585         return arg_arr;
12586 }
12587
12588 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelUpdate_1set_1signature(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
12589         LDKChannelUpdate this_ptr_conv;
12590         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12591         this_ptr_conv.is_owned = false;
12592         LDKSignature val_ref;
12593         CHECK((*_env)->GetArrayLength (_env, val) == 64);
12594         (*_env)->GetByteArrayRegion (_env, val, 0, 64, val_ref.compact_form);
12595         ChannelUpdate_set_signature(&this_ptr_conv, val_ref);
12596 }
12597
12598 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelUpdate_1get_1contents(JNIEnv * _env, jclass _b, jlong this_ptr) {
12599         LDKChannelUpdate this_ptr_conv;
12600         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12601         this_ptr_conv.is_owned = false;
12602         LDKUnsignedChannelUpdate ret_var = ChannelUpdate_get_contents(&this_ptr_conv);
12603         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12604         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12605         long ret_ref = (long)ret_var.inner;
12606         if (ret_var.is_owned) {
12607                 ret_ref |= 1;
12608         }
12609         return ret_ref;
12610 }
12611
12612 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelUpdate_1set_1contents(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
12613         LDKChannelUpdate this_ptr_conv;
12614         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12615         this_ptr_conv.is_owned = false;
12616         LDKUnsignedChannelUpdate val_conv;
12617         val_conv.inner = (void*)(val & (~1));
12618         val_conv.is_owned = (val & 1) || (val == 0);
12619         if (val_conv.inner != NULL)
12620                 val_conv = UnsignedChannelUpdate_clone(&val_conv);
12621         ChannelUpdate_set_contents(&this_ptr_conv, val_conv);
12622 }
12623
12624 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelUpdate_1new(JNIEnv * _env, jclass _b, jbyteArray signature_arg, jlong contents_arg) {
12625         LDKSignature signature_arg_ref;
12626         CHECK((*_env)->GetArrayLength (_env, signature_arg) == 64);
12627         (*_env)->GetByteArrayRegion (_env, signature_arg, 0, 64, signature_arg_ref.compact_form);
12628         LDKUnsignedChannelUpdate contents_arg_conv;
12629         contents_arg_conv.inner = (void*)(contents_arg & (~1));
12630         contents_arg_conv.is_owned = (contents_arg & 1) || (contents_arg == 0);
12631         if (contents_arg_conv.inner != NULL)
12632                 contents_arg_conv = UnsignedChannelUpdate_clone(&contents_arg_conv);
12633         LDKChannelUpdate ret_var = ChannelUpdate_new(signature_arg_ref, contents_arg_conv);
12634         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12635         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12636         long ret_ref = (long)ret_var.inner;
12637         if (ret_var.is_owned) {
12638                 ret_ref |= 1;
12639         }
12640         return ret_ref;
12641 }
12642
12643 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_QueryChannelRange_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
12644         LDKQueryChannelRange this_ptr_conv;
12645         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12646         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12647         QueryChannelRange_free(this_ptr_conv);
12648 }
12649
12650 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_QueryChannelRange_1clone(JNIEnv * _env, jclass _b, jlong orig) {
12651         LDKQueryChannelRange orig_conv;
12652         orig_conv.inner = (void*)(orig & (~1));
12653         orig_conv.is_owned = false;
12654         LDKQueryChannelRange ret_var = QueryChannelRange_clone(&orig_conv);
12655         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12656         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12657         long ret_ref = (long)ret_var.inner;
12658         if (ret_var.is_owned) {
12659                 ret_ref |= 1;
12660         }
12661         return ret_ref;
12662 }
12663
12664 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_QueryChannelRange_1get_1chain_1hash(JNIEnv * _env, jclass _b, jlong this_ptr) {
12665         LDKQueryChannelRange this_ptr_conv;
12666         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12667         this_ptr_conv.is_owned = false;
12668         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
12669         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *QueryChannelRange_get_chain_hash(&this_ptr_conv));
12670         return ret_arr;
12671 }
12672
12673 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_QueryChannelRange_1set_1chain_1hash(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
12674         LDKQueryChannelRange this_ptr_conv;
12675         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12676         this_ptr_conv.is_owned = false;
12677         LDKThirtyTwoBytes val_ref;
12678         CHECK((*_env)->GetArrayLength (_env, val) == 32);
12679         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
12680         QueryChannelRange_set_chain_hash(&this_ptr_conv, val_ref);
12681 }
12682
12683 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_QueryChannelRange_1get_1first_1blocknum(JNIEnv * _env, jclass _b, jlong this_ptr) {
12684         LDKQueryChannelRange this_ptr_conv;
12685         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12686         this_ptr_conv.is_owned = false;
12687         jint ret_val = QueryChannelRange_get_first_blocknum(&this_ptr_conv);
12688         return ret_val;
12689 }
12690
12691 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_QueryChannelRange_1set_1first_1blocknum(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
12692         LDKQueryChannelRange this_ptr_conv;
12693         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12694         this_ptr_conv.is_owned = false;
12695         QueryChannelRange_set_first_blocknum(&this_ptr_conv, val);
12696 }
12697
12698 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_QueryChannelRange_1get_1number_1of_1blocks(JNIEnv * _env, jclass _b, jlong this_ptr) {
12699         LDKQueryChannelRange this_ptr_conv;
12700         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12701         this_ptr_conv.is_owned = false;
12702         jint ret_val = QueryChannelRange_get_number_of_blocks(&this_ptr_conv);
12703         return ret_val;
12704 }
12705
12706 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_QueryChannelRange_1set_1number_1of_1blocks(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
12707         LDKQueryChannelRange this_ptr_conv;
12708         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12709         this_ptr_conv.is_owned = false;
12710         QueryChannelRange_set_number_of_blocks(&this_ptr_conv, val);
12711 }
12712
12713 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_QueryChannelRange_1new(JNIEnv * _env, jclass _b, jbyteArray chain_hash_arg, jint first_blocknum_arg, jint number_of_blocks_arg) {
12714         LDKThirtyTwoBytes chain_hash_arg_ref;
12715         CHECK((*_env)->GetArrayLength (_env, chain_hash_arg) == 32);
12716         (*_env)->GetByteArrayRegion (_env, chain_hash_arg, 0, 32, chain_hash_arg_ref.data);
12717         LDKQueryChannelRange ret_var = QueryChannelRange_new(chain_hash_arg_ref, first_blocknum_arg, number_of_blocks_arg);
12718         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12719         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12720         long ret_ref = (long)ret_var.inner;
12721         if (ret_var.is_owned) {
12722                 ret_ref |= 1;
12723         }
12724         return ret_ref;
12725 }
12726
12727 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ReplyChannelRange_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
12728         LDKReplyChannelRange this_ptr_conv;
12729         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12730         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12731         ReplyChannelRange_free(this_ptr_conv);
12732 }
12733
12734 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ReplyChannelRange_1clone(JNIEnv * _env, jclass _b, jlong orig) {
12735         LDKReplyChannelRange orig_conv;
12736         orig_conv.inner = (void*)(orig & (~1));
12737         orig_conv.is_owned = false;
12738         LDKReplyChannelRange ret_var = ReplyChannelRange_clone(&orig_conv);
12739         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12740         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12741         long ret_ref = (long)ret_var.inner;
12742         if (ret_var.is_owned) {
12743                 ret_ref |= 1;
12744         }
12745         return ret_ref;
12746 }
12747
12748 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ReplyChannelRange_1get_1chain_1hash(JNIEnv * _env, jclass _b, jlong this_ptr) {
12749         LDKReplyChannelRange this_ptr_conv;
12750         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12751         this_ptr_conv.is_owned = false;
12752         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
12753         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *ReplyChannelRange_get_chain_hash(&this_ptr_conv));
12754         return ret_arr;
12755 }
12756
12757 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ReplyChannelRange_1set_1chain_1hash(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
12758         LDKReplyChannelRange this_ptr_conv;
12759         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12760         this_ptr_conv.is_owned = false;
12761         LDKThirtyTwoBytes val_ref;
12762         CHECK((*_env)->GetArrayLength (_env, val) == 32);
12763         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
12764         ReplyChannelRange_set_chain_hash(&this_ptr_conv, val_ref);
12765 }
12766
12767 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_ReplyChannelRange_1get_1first_1blocknum(JNIEnv * _env, jclass _b, jlong this_ptr) {
12768         LDKReplyChannelRange this_ptr_conv;
12769         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12770         this_ptr_conv.is_owned = false;
12771         jint ret_val = ReplyChannelRange_get_first_blocknum(&this_ptr_conv);
12772         return ret_val;
12773 }
12774
12775 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ReplyChannelRange_1set_1first_1blocknum(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
12776         LDKReplyChannelRange this_ptr_conv;
12777         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12778         this_ptr_conv.is_owned = false;
12779         ReplyChannelRange_set_first_blocknum(&this_ptr_conv, val);
12780 }
12781
12782 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_ReplyChannelRange_1get_1number_1of_1blocks(JNIEnv * _env, jclass _b, jlong this_ptr) {
12783         LDKReplyChannelRange this_ptr_conv;
12784         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12785         this_ptr_conv.is_owned = false;
12786         jint ret_val = ReplyChannelRange_get_number_of_blocks(&this_ptr_conv);
12787         return ret_val;
12788 }
12789
12790 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ReplyChannelRange_1set_1number_1of_1blocks(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
12791         LDKReplyChannelRange this_ptr_conv;
12792         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12793         this_ptr_conv.is_owned = false;
12794         ReplyChannelRange_set_number_of_blocks(&this_ptr_conv, val);
12795 }
12796
12797 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_ReplyChannelRange_1get_1full_1information(JNIEnv * _env, jclass _b, jlong this_ptr) {
12798         LDKReplyChannelRange this_ptr_conv;
12799         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12800         this_ptr_conv.is_owned = false;
12801         jboolean ret_val = ReplyChannelRange_get_full_information(&this_ptr_conv);
12802         return ret_val;
12803 }
12804
12805 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ReplyChannelRange_1set_1full_1information(JNIEnv * _env, jclass _b, jlong this_ptr, jboolean val) {
12806         LDKReplyChannelRange this_ptr_conv;
12807         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12808         this_ptr_conv.is_owned = false;
12809         ReplyChannelRange_set_full_information(&this_ptr_conv, val);
12810 }
12811
12812 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ReplyChannelRange_1set_1short_1channel_1ids(JNIEnv * _env, jclass _b, jlong this_ptr, jlongArray val) {
12813         LDKReplyChannelRange this_ptr_conv;
12814         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12815         this_ptr_conv.is_owned = false;
12816         LDKCVec_u64Z val_constr;
12817         val_constr.datalen = (*_env)->GetArrayLength (_env, val);
12818         if (val_constr.datalen > 0)
12819                 val_constr.data = MALLOC(val_constr.datalen * sizeof(jlong), "LDKCVec_u64Z Elements");
12820         else
12821                 val_constr.data = NULL;
12822         long* val_vals = (*_env)->GetLongArrayElements (_env, val, NULL);
12823         for (size_t g = 0; g < val_constr.datalen; g++) {
12824                 long arr_conv_6 = val_vals[g];
12825                 val_constr.data[g] = arr_conv_6;
12826         }
12827         (*_env)->ReleaseLongArrayElements (_env, val, val_vals, 0);
12828         ReplyChannelRange_set_short_channel_ids(&this_ptr_conv, val_constr);
12829 }
12830
12831 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ReplyChannelRange_1new(JNIEnv * _env, jclass _b, jbyteArray chain_hash_arg, jint first_blocknum_arg, jint number_of_blocks_arg, jboolean full_information_arg, jlongArray short_channel_ids_arg) {
12832         LDKThirtyTwoBytes chain_hash_arg_ref;
12833         CHECK((*_env)->GetArrayLength (_env, chain_hash_arg) == 32);
12834         (*_env)->GetByteArrayRegion (_env, chain_hash_arg, 0, 32, chain_hash_arg_ref.data);
12835         LDKCVec_u64Z short_channel_ids_arg_constr;
12836         short_channel_ids_arg_constr.datalen = (*_env)->GetArrayLength (_env, short_channel_ids_arg);
12837         if (short_channel_ids_arg_constr.datalen > 0)
12838                 short_channel_ids_arg_constr.data = MALLOC(short_channel_ids_arg_constr.datalen * sizeof(jlong), "LDKCVec_u64Z Elements");
12839         else
12840                 short_channel_ids_arg_constr.data = NULL;
12841         long* short_channel_ids_arg_vals = (*_env)->GetLongArrayElements (_env, short_channel_ids_arg, NULL);
12842         for (size_t g = 0; g < short_channel_ids_arg_constr.datalen; g++) {
12843                 long arr_conv_6 = short_channel_ids_arg_vals[g];
12844                 short_channel_ids_arg_constr.data[g] = arr_conv_6;
12845         }
12846         (*_env)->ReleaseLongArrayElements (_env, short_channel_ids_arg, short_channel_ids_arg_vals, 0);
12847         LDKReplyChannelRange ret_var = ReplyChannelRange_new(chain_hash_arg_ref, first_blocknum_arg, number_of_blocks_arg, full_information_arg, short_channel_ids_arg_constr);
12848         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12849         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12850         long ret_ref = (long)ret_var.inner;
12851         if (ret_var.is_owned) {
12852                 ret_ref |= 1;
12853         }
12854         return ret_ref;
12855 }
12856
12857 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_QueryShortChannelIds_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
12858         LDKQueryShortChannelIds this_ptr_conv;
12859         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12860         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12861         QueryShortChannelIds_free(this_ptr_conv);
12862 }
12863
12864 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_QueryShortChannelIds_1clone(JNIEnv * _env, jclass _b, jlong orig) {
12865         LDKQueryShortChannelIds orig_conv;
12866         orig_conv.inner = (void*)(orig & (~1));
12867         orig_conv.is_owned = false;
12868         LDKQueryShortChannelIds ret_var = QueryShortChannelIds_clone(&orig_conv);
12869         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12870         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12871         long ret_ref = (long)ret_var.inner;
12872         if (ret_var.is_owned) {
12873                 ret_ref |= 1;
12874         }
12875         return ret_ref;
12876 }
12877
12878 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_QueryShortChannelIds_1get_1chain_1hash(JNIEnv * _env, jclass _b, jlong this_ptr) {
12879         LDKQueryShortChannelIds this_ptr_conv;
12880         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12881         this_ptr_conv.is_owned = false;
12882         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
12883         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *QueryShortChannelIds_get_chain_hash(&this_ptr_conv));
12884         return ret_arr;
12885 }
12886
12887 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_QueryShortChannelIds_1set_1chain_1hash(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
12888         LDKQueryShortChannelIds this_ptr_conv;
12889         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12890         this_ptr_conv.is_owned = false;
12891         LDKThirtyTwoBytes val_ref;
12892         CHECK((*_env)->GetArrayLength (_env, val) == 32);
12893         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
12894         QueryShortChannelIds_set_chain_hash(&this_ptr_conv, val_ref);
12895 }
12896
12897 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_QueryShortChannelIds_1set_1short_1channel_1ids(JNIEnv * _env, jclass _b, jlong this_ptr, jlongArray val) {
12898         LDKQueryShortChannelIds this_ptr_conv;
12899         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12900         this_ptr_conv.is_owned = false;
12901         LDKCVec_u64Z val_constr;
12902         val_constr.datalen = (*_env)->GetArrayLength (_env, val);
12903         if (val_constr.datalen > 0)
12904                 val_constr.data = MALLOC(val_constr.datalen * sizeof(jlong), "LDKCVec_u64Z Elements");
12905         else
12906                 val_constr.data = NULL;
12907         long* val_vals = (*_env)->GetLongArrayElements (_env, val, NULL);
12908         for (size_t g = 0; g < val_constr.datalen; g++) {
12909                 long arr_conv_6 = val_vals[g];
12910                 val_constr.data[g] = arr_conv_6;
12911         }
12912         (*_env)->ReleaseLongArrayElements (_env, val, val_vals, 0);
12913         QueryShortChannelIds_set_short_channel_ids(&this_ptr_conv, val_constr);
12914 }
12915
12916 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_QueryShortChannelIds_1new(JNIEnv * _env, jclass _b, jbyteArray chain_hash_arg, jlongArray short_channel_ids_arg) {
12917         LDKThirtyTwoBytes chain_hash_arg_ref;
12918         CHECK((*_env)->GetArrayLength (_env, chain_hash_arg) == 32);
12919         (*_env)->GetByteArrayRegion (_env, chain_hash_arg, 0, 32, chain_hash_arg_ref.data);
12920         LDKCVec_u64Z short_channel_ids_arg_constr;
12921         short_channel_ids_arg_constr.datalen = (*_env)->GetArrayLength (_env, short_channel_ids_arg);
12922         if (short_channel_ids_arg_constr.datalen > 0)
12923                 short_channel_ids_arg_constr.data = MALLOC(short_channel_ids_arg_constr.datalen * sizeof(jlong), "LDKCVec_u64Z Elements");
12924         else
12925                 short_channel_ids_arg_constr.data = NULL;
12926         long* short_channel_ids_arg_vals = (*_env)->GetLongArrayElements (_env, short_channel_ids_arg, NULL);
12927         for (size_t g = 0; g < short_channel_ids_arg_constr.datalen; g++) {
12928                 long arr_conv_6 = short_channel_ids_arg_vals[g];
12929                 short_channel_ids_arg_constr.data[g] = arr_conv_6;
12930         }
12931         (*_env)->ReleaseLongArrayElements (_env, short_channel_ids_arg, short_channel_ids_arg_vals, 0);
12932         LDKQueryShortChannelIds ret_var = QueryShortChannelIds_new(chain_hash_arg_ref, short_channel_ids_arg_constr);
12933         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12934         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12935         long ret_ref = (long)ret_var.inner;
12936         if (ret_var.is_owned) {
12937                 ret_ref |= 1;
12938         }
12939         return ret_ref;
12940 }
12941
12942 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ReplyShortChannelIdsEnd_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
12943         LDKReplyShortChannelIdsEnd this_ptr_conv;
12944         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12945         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12946         ReplyShortChannelIdsEnd_free(this_ptr_conv);
12947 }
12948
12949 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ReplyShortChannelIdsEnd_1clone(JNIEnv * _env, jclass _b, jlong orig) {
12950         LDKReplyShortChannelIdsEnd orig_conv;
12951         orig_conv.inner = (void*)(orig & (~1));
12952         orig_conv.is_owned = false;
12953         LDKReplyShortChannelIdsEnd ret_var = ReplyShortChannelIdsEnd_clone(&orig_conv);
12954         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12955         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12956         long ret_ref = (long)ret_var.inner;
12957         if (ret_var.is_owned) {
12958                 ret_ref |= 1;
12959         }
12960         return ret_ref;
12961 }
12962
12963 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ReplyShortChannelIdsEnd_1get_1chain_1hash(JNIEnv * _env, jclass _b, jlong this_ptr) {
12964         LDKReplyShortChannelIdsEnd this_ptr_conv;
12965         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12966         this_ptr_conv.is_owned = false;
12967         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
12968         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *ReplyShortChannelIdsEnd_get_chain_hash(&this_ptr_conv));
12969         return ret_arr;
12970 }
12971
12972 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ReplyShortChannelIdsEnd_1set_1chain_1hash(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
12973         LDKReplyShortChannelIdsEnd this_ptr_conv;
12974         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12975         this_ptr_conv.is_owned = false;
12976         LDKThirtyTwoBytes val_ref;
12977         CHECK((*_env)->GetArrayLength (_env, val) == 32);
12978         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
12979         ReplyShortChannelIdsEnd_set_chain_hash(&this_ptr_conv, val_ref);
12980 }
12981
12982 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_ReplyShortChannelIdsEnd_1get_1full_1information(JNIEnv * _env, jclass _b, jlong this_ptr) {
12983         LDKReplyShortChannelIdsEnd this_ptr_conv;
12984         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12985         this_ptr_conv.is_owned = false;
12986         jboolean ret_val = ReplyShortChannelIdsEnd_get_full_information(&this_ptr_conv);
12987         return ret_val;
12988 }
12989
12990 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ReplyShortChannelIdsEnd_1set_1full_1information(JNIEnv * _env, jclass _b, jlong this_ptr, jboolean val) {
12991         LDKReplyShortChannelIdsEnd this_ptr_conv;
12992         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12993         this_ptr_conv.is_owned = false;
12994         ReplyShortChannelIdsEnd_set_full_information(&this_ptr_conv, val);
12995 }
12996
12997 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ReplyShortChannelIdsEnd_1new(JNIEnv * _env, jclass _b, jbyteArray chain_hash_arg, jboolean full_information_arg) {
12998         LDKThirtyTwoBytes chain_hash_arg_ref;
12999         CHECK((*_env)->GetArrayLength (_env, chain_hash_arg) == 32);
13000         (*_env)->GetByteArrayRegion (_env, chain_hash_arg, 0, 32, chain_hash_arg_ref.data);
13001         LDKReplyShortChannelIdsEnd ret_var = ReplyShortChannelIdsEnd_new(chain_hash_arg_ref, full_information_arg);
13002         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13003         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13004         long ret_ref = (long)ret_var.inner;
13005         if (ret_var.is_owned) {
13006                 ret_ref |= 1;
13007         }
13008         return ret_ref;
13009 }
13010
13011 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_GossipTimestampFilter_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
13012         LDKGossipTimestampFilter this_ptr_conv;
13013         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13014         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13015         GossipTimestampFilter_free(this_ptr_conv);
13016 }
13017
13018 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_GossipTimestampFilter_1clone(JNIEnv * _env, jclass _b, jlong orig) {
13019         LDKGossipTimestampFilter orig_conv;
13020         orig_conv.inner = (void*)(orig & (~1));
13021         orig_conv.is_owned = false;
13022         LDKGossipTimestampFilter ret_var = GossipTimestampFilter_clone(&orig_conv);
13023         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13024         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13025         long ret_ref = (long)ret_var.inner;
13026         if (ret_var.is_owned) {
13027                 ret_ref |= 1;
13028         }
13029         return ret_ref;
13030 }
13031
13032 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_GossipTimestampFilter_1get_1chain_1hash(JNIEnv * _env, jclass _b, jlong this_ptr) {
13033         LDKGossipTimestampFilter this_ptr_conv;
13034         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13035         this_ptr_conv.is_owned = false;
13036         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
13037         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *GossipTimestampFilter_get_chain_hash(&this_ptr_conv));
13038         return ret_arr;
13039 }
13040
13041 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_GossipTimestampFilter_1set_1chain_1hash(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
13042         LDKGossipTimestampFilter this_ptr_conv;
13043         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13044         this_ptr_conv.is_owned = false;
13045         LDKThirtyTwoBytes val_ref;
13046         CHECK((*_env)->GetArrayLength (_env, val) == 32);
13047         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
13048         GossipTimestampFilter_set_chain_hash(&this_ptr_conv, val_ref);
13049 }
13050
13051 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_GossipTimestampFilter_1get_1first_1timestamp(JNIEnv * _env, jclass _b, jlong this_ptr) {
13052         LDKGossipTimestampFilter this_ptr_conv;
13053         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13054         this_ptr_conv.is_owned = false;
13055         jint ret_val = GossipTimestampFilter_get_first_timestamp(&this_ptr_conv);
13056         return ret_val;
13057 }
13058
13059 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_GossipTimestampFilter_1set_1first_1timestamp(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
13060         LDKGossipTimestampFilter this_ptr_conv;
13061         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13062         this_ptr_conv.is_owned = false;
13063         GossipTimestampFilter_set_first_timestamp(&this_ptr_conv, val);
13064 }
13065
13066 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_GossipTimestampFilter_1get_1timestamp_1range(JNIEnv * _env, jclass _b, jlong this_ptr) {
13067         LDKGossipTimestampFilter this_ptr_conv;
13068         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13069         this_ptr_conv.is_owned = false;
13070         jint ret_val = GossipTimestampFilter_get_timestamp_range(&this_ptr_conv);
13071         return ret_val;
13072 }
13073
13074 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_GossipTimestampFilter_1set_1timestamp_1range(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
13075         LDKGossipTimestampFilter this_ptr_conv;
13076         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13077         this_ptr_conv.is_owned = false;
13078         GossipTimestampFilter_set_timestamp_range(&this_ptr_conv, val);
13079 }
13080
13081 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_GossipTimestampFilter_1new(JNIEnv * _env, jclass _b, jbyteArray chain_hash_arg, jint first_timestamp_arg, jint timestamp_range_arg) {
13082         LDKThirtyTwoBytes chain_hash_arg_ref;
13083         CHECK((*_env)->GetArrayLength (_env, chain_hash_arg) == 32);
13084         (*_env)->GetByteArrayRegion (_env, chain_hash_arg, 0, 32, chain_hash_arg_ref.data);
13085         LDKGossipTimestampFilter ret_var = GossipTimestampFilter_new(chain_hash_arg_ref, first_timestamp_arg, timestamp_range_arg);
13086         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13087         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13088         long ret_ref = (long)ret_var.inner;
13089         if (ret_var.is_owned) {
13090                 ret_ref |= 1;
13091         }
13092         return ret_ref;
13093 }
13094
13095 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ErrorAction_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
13096         LDKErrorAction this_ptr_conv = *(LDKErrorAction*)this_ptr;
13097         FREE((void*)this_ptr);
13098         ErrorAction_free(this_ptr_conv);
13099 }
13100
13101 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ErrorAction_1clone(JNIEnv * _env, jclass _b, jlong orig) {
13102         LDKErrorAction* orig_conv = (LDKErrorAction*)orig;
13103         LDKErrorAction *ret_copy = MALLOC(sizeof(LDKErrorAction), "LDKErrorAction");
13104         *ret_copy = ErrorAction_clone(orig_conv);
13105         long ret_ref = (long)ret_copy;
13106         return ret_ref;
13107 }
13108
13109 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_LightningError_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
13110         LDKLightningError this_ptr_conv;
13111         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13112         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13113         LightningError_free(this_ptr_conv);
13114 }
13115
13116 JNIEXPORT jstring JNICALL Java_org_ldk_impl_bindings_LightningError_1get_1err(JNIEnv * _env, jclass _b, jlong this_ptr) {
13117         LDKLightningError this_ptr_conv;
13118         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13119         this_ptr_conv.is_owned = false;
13120         LDKStr _str = LightningError_get_err(&this_ptr_conv);
13121         char* _buf = MALLOC(_str.len + 1, "str conv buf");
13122         memcpy(_buf, _str.chars, _str.len);
13123         _buf[_str.len] = 0;
13124         jstring _conv = (*_env)->NewStringUTF(_env, _str.chars);
13125         FREE(_buf);
13126         return _conv;
13127 }
13128
13129 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_LightningError_1set_1err(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
13130         LDKLightningError this_ptr_conv;
13131         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13132         this_ptr_conv.is_owned = false;
13133         LDKCVec_u8Z val_ref;
13134         val_ref.datalen = (*_env)->GetArrayLength (_env, val);
13135         val_ref.data = MALLOC(val_ref.datalen, "LDKCVec_u8Z Bytes");
13136         (*_env)->GetByteArrayRegion(_env, val, 0, val_ref.datalen, val_ref.data);
13137         LightningError_set_err(&this_ptr_conv, val_ref);
13138 }
13139
13140 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LightningError_1get_1action(JNIEnv * _env, jclass _b, jlong this_ptr) {
13141         LDKLightningError this_ptr_conv;
13142         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13143         this_ptr_conv.is_owned = false;
13144         LDKErrorAction *ret_copy = MALLOC(sizeof(LDKErrorAction), "LDKErrorAction");
13145         *ret_copy = LightningError_get_action(&this_ptr_conv);
13146         long ret_ref = (long)ret_copy;
13147         return ret_ref;
13148 }
13149
13150 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_LightningError_1set_1action(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
13151         LDKLightningError this_ptr_conv;
13152         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13153         this_ptr_conv.is_owned = false;
13154         LDKErrorAction val_conv = *(LDKErrorAction*)val;
13155         FREE((void*)val);
13156         LightningError_set_action(&this_ptr_conv, val_conv);
13157 }
13158
13159 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LightningError_1new(JNIEnv * _env, jclass _b, jbyteArray err_arg, jlong action_arg) {
13160         LDKCVec_u8Z err_arg_ref;
13161         err_arg_ref.datalen = (*_env)->GetArrayLength (_env, err_arg);
13162         err_arg_ref.data = MALLOC(err_arg_ref.datalen, "LDKCVec_u8Z Bytes");
13163         (*_env)->GetByteArrayRegion(_env, err_arg, 0, err_arg_ref.datalen, err_arg_ref.data);
13164         LDKErrorAction action_arg_conv = *(LDKErrorAction*)action_arg;
13165         FREE((void*)action_arg);
13166         LDKLightningError ret_var = LightningError_new(err_arg_ref, action_arg_conv);
13167         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13168         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13169         long ret_ref = (long)ret_var.inner;
13170         if (ret_var.is_owned) {
13171                 ret_ref |= 1;
13172         }
13173         return ret_ref;
13174 }
13175
13176 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CommitmentUpdate_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
13177         LDKCommitmentUpdate this_ptr_conv;
13178         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13179         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13180         CommitmentUpdate_free(this_ptr_conv);
13181 }
13182
13183 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CommitmentUpdate_1clone(JNIEnv * _env, jclass _b, jlong orig) {
13184         LDKCommitmentUpdate orig_conv;
13185         orig_conv.inner = (void*)(orig & (~1));
13186         orig_conv.is_owned = false;
13187         LDKCommitmentUpdate ret_var = CommitmentUpdate_clone(&orig_conv);
13188         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13189         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13190         long ret_ref = (long)ret_var.inner;
13191         if (ret_var.is_owned) {
13192                 ret_ref |= 1;
13193         }
13194         return ret_ref;
13195 }
13196
13197 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CommitmentUpdate_1set_1update_1add_1htlcs(JNIEnv * _env, jclass _b, jlong this_ptr, jlongArray val) {
13198         LDKCommitmentUpdate this_ptr_conv;
13199         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13200         this_ptr_conv.is_owned = false;
13201         LDKCVec_UpdateAddHTLCZ val_constr;
13202         val_constr.datalen = (*_env)->GetArrayLength (_env, val);
13203         if (val_constr.datalen > 0)
13204                 val_constr.data = MALLOC(val_constr.datalen * sizeof(LDKUpdateAddHTLC), "LDKCVec_UpdateAddHTLCZ Elements");
13205         else
13206                 val_constr.data = NULL;
13207         long* val_vals = (*_env)->GetLongArrayElements (_env, val, NULL);
13208         for (size_t p = 0; p < val_constr.datalen; p++) {
13209                 long arr_conv_15 = val_vals[p];
13210                 LDKUpdateAddHTLC arr_conv_15_conv;
13211                 arr_conv_15_conv.inner = (void*)(arr_conv_15 & (~1));
13212                 arr_conv_15_conv.is_owned = (arr_conv_15 & 1) || (arr_conv_15 == 0);
13213                 val_constr.data[p] = arr_conv_15_conv;
13214         }
13215         (*_env)->ReleaseLongArrayElements (_env, val, val_vals, 0);
13216         CommitmentUpdate_set_update_add_htlcs(&this_ptr_conv, val_constr);
13217 }
13218
13219 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CommitmentUpdate_1set_1update_1fulfill_1htlcs(JNIEnv * _env, jclass _b, jlong this_ptr, jlongArray val) {
13220         LDKCommitmentUpdate this_ptr_conv;
13221         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13222         this_ptr_conv.is_owned = false;
13223         LDKCVec_UpdateFulfillHTLCZ val_constr;
13224         val_constr.datalen = (*_env)->GetArrayLength (_env, val);
13225         if (val_constr.datalen > 0)
13226                 val_constr.data = MALLOC(val_constr.datalen * sizeof(LDKUpdateFulfillHTLC), "LDKCVec_UpdateFulfillHTLCZ Elements");
13227         else
13228                 val_constr.data = NULL;
13229         long* val_vals = (*_env)->GetLongArrayElements (_env, val, NULL);
13230         for (size_t t = 0; t < val_constr.datalen; t++) {
13231                 long arr_conv_19 = val_vals[t];
13232                 LDKUpdateFulfillHTLC arr_conv_19_conv;
13233                 arr_conv_19_conv.inner = (void*)(arr_conv_19 & (~1));
13234                 arr_conv_19_conv.is_owned = (arr_conv_19 & 1) || (arr_conv_19 == 0);
13235                 val_constr.data[t] = arr_conv_19_conv;
13236         }
13237         (*_env)->ReleaseLongArrayElements (_env, val, val_vals, 0);
13238         CommitmentUpdate_set_update_fulfill_htlcs(&this_ptr_conv, val_constr);
13239 }
13240
13241 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CommitmentUpdate_1set_1update_1fail_1htlcs(JNIEnv * _env, jclass _b, jlong this_ptr, jlongArray val) {
13242         LDKCommitmentUpdate this_ptr_conv;
13243         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13244         this_ptr_conv.is_owned = false;
13245         LDKCVec_UpdateFailHTLCZ val_constr;
13246         val_constr.datalen = (*_env)->GetArrayLength (_env, val);
13247         if (val_constr.datalen > 0)
13248                 val_constr.data = MALLOC(val_constr.datalen * sizeof(LDKUpdateFailHTLC), "LDKCVec_UpdateFailHTLCZ Elements");
13249         else
13250                 val_constr.data = NULL;
13251         long* val_vals = (*_env)->GetLongArrayElements (_env, val, NULL);
13252         for (size_t q = 0; q < val_constr.datalen; q++) {
13253                 long arr_conv_16 = val_vals[q];
13254                 LDKUpdateFailHTLC arr_conv_16_conv;
13255                 arr_conv_16_conv.inner = (void*)(arr_conv_16 & (~1));
13256                 arr_conv_16_conv.is_owned = (arr_conv_16 & 1) || (arr_conv_16 == 0);
13257                 val_constr.data[q] = arr_conv_16_conv;
13258         }
13259         (*_env)->ReleaseLongArrayElements (_env, val, val_vals, 0);
13260         CommitmentUpdate_set_update_fail_htlcs(&this_ptr_conv, val_constr);
13261 }
13262
13263 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CommitmentUpdate_1set_1update_1fail_1malformed_1htlcs(JNIEnv * _env, jclass _b, jlong this_ptr, jlongArray val) {
13264         LDKCommitmentUpdate this_ptr_conv;
13265         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13266         this_ptr_conv.is_owned = false;
13267         LDKCVec_UpdateFailMalformedHTLCZ val_constr;
13268         val_constr.datalen = (*_env)->GetArrayLength (_env, val);
13269         if (val_constr.datalen > 0)
13270                 val_constr.data = MALLOC(val_constr.datalen * sizeof(LDKUpdateFailMalformedHTLC), "LDKCVec_UpdateFailMalformedHTLCZ Elements");
13271         else
13272                 val_constr.data = NULL;
13273         long* val_vals = (*_env)->GetLongArrayElements (_env, val, NULL);
13274         for (size_t z = 0; z < val_constr.datalen; z++) {
13275                 long arr_conv_25 = val_vals[z];
13276                 LDKUpdateFailMalformedHTLC arr_conv_25_conv;
13277                 arr_conv_25_conv.inner = (void*)(arr_conv_25 & (~1));
13278                 arr_conv_25_conv.is_owned = (arr_conv_25 & 1) || (arr_conv_25 == 0);
13279                 val_constr.data[z] = arr_conv_25_conv;
13280         }
13281         (*_env)->ReleaseLongArrayElements (_env, val, val_vals, 0);
13282         CommitmentUpdate_set_update_fail_malformed_htlcs(&this_ptr_conv, val_constr);
13283 }
13284
13285 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CommitmentUpdate_1get_1update_1fee(JNIEnv * _env, jclass _b, jlong this_ptr) {
13286         LDKCommitmentUpdate this_ptr_conv;
13287         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13288         this_ptr_conv.is_owned = false;
13289         LDKUpdateFee ret_var = CommitmentUpdate_get_update_fee(&this_ptr_conv);
13290         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13291         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13292         long ret_ref = (long)ret_var.inner;
13293         if (ret_var.is_owned) {
13294                 ret_ref |= 1;
13295         }
13296         return ret_ref;
13297 }
13298
13299 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CommitmentUpdate_1set_1update_1fee(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
13300         LDKCommitmentUpdate this_ptr_conv;
13301         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13302         this_ptr_conv.is_owned = false;
13303         LDKUpdateFee val_conv;
13304         val_conv.inner = (void*)(val & (~1));
13305         val_conv.is_owned = (val & 1) || (val == 0);
13306         if (val_conv.inner != NULL)
13307                 val_conv = UpdateFee_clone(&val_conv);
13308         CommitmentUpdate_set_update_fee(&this_ptr_conv, val_conv);
13309 }
13310
13311 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CommitmentUpdate_1get_1commitment_1signed(JNIEnv * _env, jclass _b, jlong this_ptr) {
13312         LDKCommitmentUpdate this_ptr_conv;
13313         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13314         this_ptr_conv.is_owned = false;
13315         LDKCommitmentSigned ret_var = CommitmentUpdate_get_commitment_signed(&this_ptr_conv);
13316         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13317         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13318         long ret_ref = (long)ret_var.inner;
13319         if (ret_var.is_owned) {
13320                 ret_ref |= 1;
13321         }
13322         return ret_ref;
13323 }
13324
13325 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CommitmentUpdate_1set_1commitment_1signed(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
13326         LDKCommitmentUpdate this_ptr_conv;
13327         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13328         this_ptr_conv.is_owned = false;
13329         LDKCommitmentSigned val_conv;
13330         val_conv.inner = (void*)(val & (~1));
13331         val_conv.is_owned = (val & 1) || (val == 0);
13332         if (val_conv.inner != NULL)
13333                 val_conv = CommitmentSigned_clone(&val_conv);
13334         CommitmentUpdate_set_commitment_signed(&this_ptr_conv, val_conv);
13335 }
13336
13337 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CommitmentUpdate_1new(JNIEnv * _env, jclass _b, jlongArray update_add_htlcs_arg, jlongArray update_fulfill_htlcs_arg, jlongArray update_fail_htlcs_arg, jlongArray update_fail_malformed_htlcs_arg, jlong update_fee_arg, jlong commitment_signed_arg) {
13338         LDKCVec_UpdateAddHTLCZ update_add_htlcs_arg_constr;
13339         update_add_htlcs_arg_constr.datalen = (*_env)->GetArrayLength (_env, update_add_htlcs_arg);
13340         if (update_add_htlcs_arg_constr.datalen > 0)
13341                 update_add_htlcs_arg_constr.data = MALLOC(update_add_htlcs_arg_constr.datalen * sizeof(LDKUpdateAddHTLC), "LDKCVec_UpdateAddHTLCZ Elements");
13342         else
13343                 update_add_htlcs_arg_constr.data = NULL;
13344         long* update_add_htlcs_arg_vals = (*_env)->GetLongArrayElements (_env, update_add_htlcs_arg, NULL);
13345         for (size_t p = 0; p < update_add_htlcs_arg_constr.datalen; p++) {
13346                 long arr_conv_15 = update_add_htlcs_arg_vals[p];
13347                 LDKUpdateAddHTLC arr_conv_15_conv;
13348                 arr_conv_15_conv.inner = (void*)(arr_conv_15 & (~1));
13349                 arr_conv_15_conv.is_owned = (arr_conv_15 & 1) || (arr_conv_15 == 0);
13350                 update_add_htlcs_arg_constr.data[p] = arr_conv_15_conv;
13351         }
13352         (*_env)->ReleaseLongArrayElements (_env, update_add_htlcs_arg, update_add_htlcs_arg_vals, 0);
13353         LDKCVec_UpdateFulfillHTLCZ update_fulfill_htlcs_arg_constr;
13354         update_fulfill_htlcs_arg_constr.datalen = (*_env)->GetArrayLength (_env, update_fulfill_htlcs_arg);
13355         if (update_fulfill_htlcs_arg_constr.datalen > 0)
13356                 update_fulfill_htlcs_arg_constr.data = MALLOC(update_fulfill_htlcs_arg_constr.datalen * sizeof(LDKUpdateFulfillHTLC), "LDKCVec_UpdateFulfillHTLCZ Elements");
13357         else
13358                 update_fulfill_htlcs_arg_constr.data = NULL;
13359         long* update_fulfill_htlcs_arg_vals = (*_env)->GetLongArrayElements (_env, update_fulfill_htlcs_arg, NULL);
13360         for (size_t t = 0; t < update_fulfill_htlcs_arg_constr.datalen; t++) {
13361                 long arr_conv_19 = update_fulfill_htlcs_arg_vals[t];
13362                 LDKUpdateFulfillHTLC arr_conv_19_conv;
13363                 arr_conv_19_conv.inner = (void*)(arr_conv_19 & (~1));
13364                 arr_conv_19_conv.is_owned = (arr_conv_19 & 1) || (arr_conv_19 == 0);
13365                 update_fulfill_htlcs_arg_constr.data[t] = arr_conv_19_conv;
13366         }
13367         (*_env)->ReleaseLongArrayElements (_env, update_fulfill_htlcs_arg, update_fulfill_htlcs_arg_vals, 0);
13368         LDKCVec_UpdateFailHTLCZ update_fail_htlcs_arg_constr;
13369         update_fail_htlcs_arg_constr.datalen = (*_env)->GetArrayLength (_env, update_fail_htlcs_arg);
13370         if (update_fail_htlcs_arg_constr.datalen > 0)
13371                 update_fail_htlcs_arg_constr.data = MALLOC(update_fail_htlcs_arg_constr.datalen * sizeof(LDKUpdateFailHTLC), "LDKCVec_UpdateFailHTLCZ Elements");
13372         else
13373                 update_fail_htlcs_arg_constr.data = NULL;
13374         long* update_fail_htlcs_arg_vals = (*_env)->GetLongArrayElements (_env, update_fail_htlcs_arg, NULL);
13375         for (size_t q = 0; q < update_fail_htlcs_arg_constr.datalen; q++) {
13376                 long arr_conv_16 = update_fail_htlcs_arg_vals[q];
13377                 LDKUpdateFailHTLC arr_conv_16_conv;
13378                 arr_conv_16_conv.inner = (void*)(arr_conv_16 & (~1));
13379                 arr_conv_16_conv.is_owned = (arr_conv_16 & 1) || (arr_conv_16 == 0);
13380                 update_fail_htlcs_arg_constr.data[q] = arr_conv_16_conv;
13381         }
13382         (*_env)->ReleaseLongArrayElements (_env, update_fail_htlcs_arg, update_fail_htlcs_arg_vals, 0);
13383         LDKCVec_UpdateFailMalformedHTLCZ update_fail_malformed_htlcs_arg_constr;
13384         update_fail_malformed_htlcs_arg_constr.datalen = (*_env)->GetArrayLength (_env, update_fail_malformed_htlcs_arg);
13385         if (update_fail_malformed_htlcs_arg_constr.datalen > 0)
13386                 update_fail_malformed_htlcs_arg_constr.data = MALLOC(update_fail_malformed_htlcs_arg_constr.datalen * sizeof(LDKUpdateFailMalformedHTLC), "LDKCVec_UpdateFailMalformedHTLCZ Elements");
13387         else
13388                 update_fail_malformed_htlcs_arg_constr.data = NULL;
13389         long* update_fail_malformed_htlcs_arg_vals = (*_env)->GetLongArrayElements (_env, update_fail_malformed_htlcs_arg, NULL);
13390         for (size_t z = 0; z < update_fail_malformed_htlcs_arg_constr.datalen; z++) {
13391                 long arr_conv_25 = update_fail_malformed_htlcs_arg_vals[z];
13392                 LDKUpdateFailMalformedHTLC arr_conv_25_conv;
13393                 arr_conv_25_conv.inner = (void*)(arr_conv_25 & (~1));
13394                 arr_conv_25_conv.is_owned = (arr_conv_25 & 1) || (arr_conv_25 == 0);
13395                 update_fail_malformed_htlcs_arg_constr.data[z] = arr_conv_25_conv;
13396         }
13397         (*_env)->ReleaseLongArrayElements (_env, update_fail_malformed_htlcs_arg, update_fail_malformed_htlcs_arg_vals, 0);
13398         LDKUpdateFee update_fee_arg_conv;
13399         update_fee_arg_conv.inner = (void*)(update_fee_arg & (~1));
13400         update_fee_arg_conv.is_owned = (update_fee_arg & 1) || (update_fee_arg == 0);
13401         if (update_fee_arg_conv.inner != NULL)
13402                 update_fee_arg_conv = UpdateFee_clone(&update_fee_arg_conv);
13403         LDKCommitmentSigned commitment_signed_arg_conv;
13404         commitment_signed_arg_conv.inner = (void*)(commitment_signed_arg & (~1));
13405         commitment_signed_arg_conv.is_owned = (commitment_signed_arg & 1) || (commitment_signed_arg == 0);
13406         if (commitment_signed_arg_conv.inner != NULL)
13407                 commitment_signed_arg_conv = CommitmentSigned_clone(&commitment_signed_arg_conv);
13408         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);
13409         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13410         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13411         long ret_ref = (long)ret_var.inner;
13412         if (ret_var.is_owned) {
13413                 ret_ref |= 1;
13414         }
13415         return ret_ref;
13416 }
13417
13418 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_HTLCFailChannelUpdate_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
13419         LDKHTLCFailChannelUpdate this_ptr_conv = *(LDKHTLCFailChannelUpdate*)this_ptr;
13420         FREE((void*)this_ptr);
13421         HTLCFailChannelUpdate_free(this_ptr_conv);
13422 }
13423
13424 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_HTLCFailChannelUpdate_1clone(JNIEnv * _env, jclass _b, jlong orig) {
13425         LDKHTLCFailChannelUpdate* orig_conv = (LDKHTLCFailChannelUpdate*)orig;
13426         LDKHTLCFailChannelUpdate *ret_copy = MALLOC(sizeof(LDKHTLCFailChannelUpdate), "LDKHTLCFailChannelUpdate");
13427         *ret_copy = HTLCFailChannelUpdate_clone(orig_conv);
13428         long ret_ref = (long)ret_copy;
13429         return ret_ref;
13430 }
13431
13432 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelMessageHandler_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
13433         LDKChannelMessageHandler this_ptr_conv = *(LDKChannelMessageHandler*)this_ptr;
13434         FREE((void*)this_ptr);
13435         ChannelMessageHandler_free(this_ptr_conv);
13436 }
13437
13438 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RoutingMessageHandler_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
13439         LDKRoutingMessageHandler this_ptr_conv = *(LDKRoutingMessageHandler*)this_ptr;
13440         FREE((void*)this_ptr);
13441         RoutingMessageHandler_free(this_ptr_conv);
13442 }
13443
13444 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1write(JNIEnv * _env, jclass _b, jlong obj) {
13445         LDKAcceptChannel obj_conv;
13446         obj_conv.inner = (void*)(obj & (~1));
13447         obj_conv.is_owned = false;
13448         LDKCVec_u8Z arg_var = AcceptChannel_write(&obj_conv);
13449         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
13450         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
13451         CVec_u8Z_free(arg_var);
13452         return arg_arr;
13453 }
13454
13455 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
13456         LDKu8slice ser_ref;
13457         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
13458         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
13459         LDKAcceptChannel ret_var = AcceptChannel_read(ser_ref);
13460         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13461         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13462         long ret_ref = (long)ret_var.inner;
13463         if (ret_var.is_owned) {
13464                 ret_ref |= 1;
13465         }
13466         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
13467         return ret_ref;
13468 }
13469
13470 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_AnnouncementSignatures_1write(JNIEnv * _env, jclass _b, jlong obj) {
13471         LDKAnnouncementSignatures obj_conv;
13472         obj_conv.inner = (void*)(obj & (~1));
13473         obj_conv.is_owned = false;
13474         LDKCVec_u8Z arg_var = AnnouncementSignatures_write(&obj_conv);
13475         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
13476         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
13477         CVec_u8Z_free(arg_var);
13478         return arg_arr;
13479 }
13480
13481 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_AnnouncementSignatures_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
13482         LDKu8slice ser_ref;
13483         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
13484         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
13485         LDKAnnouncementSignatures ret_var = AnnouncementSignatures_read(ser_ref);
13486         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13487         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13488         long ret_ref = (long)ret_var.inner;
13489         if (ret_var.is_owned) {
13490                 ret_ref |= 1;
13491         }
13492         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
13493         return ret_ref;
13494 }
13495
13496 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelReestablish_1write(JNIEnv * _env, jclass _b, jlong obj) {
13497         LDKChannelReestablish obj_conv;
13498         obj_conv.inner = (void*)(obj & (~1));
13499         obj_conv.is_owned = false;
13500         LDKCVec_u8Z arg_var = ChannelReestablish_write(&obj_conv);
13501         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
13502         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
13503         CVec_u8Z_free(arg_var);
13504         return arg_arr;
13505 }
13506
13507 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelReestablish_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
13508         LDKu8slice ser_ref;
13509         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
13510         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
13511         LDKCResult_ChannelReestablishDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ChannelReestablishDecodeErrorZ), "LDKCResult_ChannelReestablishDecodeErrorZ");
13512         *ret_conv = ChannelReestablish_read(ser_ref);
13513         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
13514         return (long)ret_conv;
13515 }
13516
13517 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ClosingSigned_1write(JNIEnv * _env, jclass _b, jlong obj) {
13518         LDKClosingSigned obj_conv;
13519         obj_conv.inner = (void*)(obj & (~1));
13520         obj_conv.is_owned = false;
13521         LDKCVec_u8Z arg_var = ClosingSigned_write(&obj_conv);
13522         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
13523         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
13524         CVec_u8Z_free(arg_var);
13525         return arg_arr;
13526 }
13527
13528 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ClosingSigned_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
13529         LDKu8slice ser_ref;
13530         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
13531         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
13532         LDKClosingSigned ret_var = ClosingSigned_read(ser_ref);
13533         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13534         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13535         long ret_ref = (long)ret_var.inner;
13536         if (ret_var.is_owned) {
13537                 ret_ref |= 1;
13538         }
13539         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
13540         return ret_ref;
13541 }
13542
13543 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_CommitmentSigned_1write(JNIEnv * _env, jclass _b, jlong obj) {
13544         LDKCommitmentSigned obj_conv;
13545         obj_conv.inner = (void*)(obj & (~1));
13546         obj_conv.is_owned = false;
13547         LDKCVec_u8Z arg_var = CommitmentSigned_write(&obj_conv);
13548         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
13549         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
13550         CVec_u8Z_free(arg_var);
13551         return arg_arr;
13552 }
13553
13554 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CommitmentSigned_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
13555         LDKu8slice ser_ref;
13556         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
13557         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
13558         LDKCommitmentSigned ret_var = CommitmentSigned_read(ser_ref);
13559         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13560         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13561         long ret_ref = (long)ret_var.inner;
13562         if (ret_var.is_owned) {
13563                 ret_ref |= 1;
13564         }
13565         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
13566         return ret_ref;
13567 }
13568
13569 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_FundingCreated_1write(JNIEnv * _env, jclass _b, jlong obj) {
13570         LDKFundingCreated obj_conv;
13571         obj_conv.inner = (void*)(obj & (~1));
13572         obj_conv.is_owned = false;
13573         LDKCVec_u8Z arg_var = FundingCreated_write(&obj_conv);
13574         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
13575         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
13576         CVec_u8Z_free(arg_var);
13577         return arg_arr;
13578 }
13579
13580 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_FundingCreated_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
13581         LDKu8slice ser_ref;
13582         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
13583         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
13584         LDKFundingCreated ret_var = FundingCreated_read(ser_ref);
13585         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13586         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13587         long ret_ref = (long)ret_var.inner;
13588         if (ret_var.is_owned) {
13589                 ret_ref |= 1;
13590         }
13591         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
13592         return ret_ref;
13593 }
13594
13595 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_FundingSigned_1write(JNIEnv * _env, jclass _b, jlong obj) {
13596         LDKFundingSigned obj_conv;
13597         obj_conv.inner = (void*)(obj & (~1));
13598         obj_conv.is_owned = false;
13599         LDKCVec_u8Z arg_var = FundingSigned_write(&obj_conv);
13600         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
13601         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
13602         CVec_u8Z_free(arg_var);
13603         return arg_arr;
13604 }
13605
13606 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_FundingSigned_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
13607         LDKu8slice ser_ref;
13608         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
13609         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
13610         LDKFundingSigned ret_var = FundingSigned_read(ser_ref);
13611         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13612         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13613         long ret_ref = (long)ret_var.inner;
13614         if (ret_var.is_owned) {
13615                 ret_ref |= 1;
13616         }
13617         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
13618         return ret_ref;
13619 }
13620
13621 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_FundingLocked_1write(JNIEnv * _env, jclass _b, jlong obj) {
13622         LDKFundingLocked obj_conv;
13623         obj_conv.inner = (void*)(obj & (~1));
13624         obj_conv.is_owned = false;
13625         LDKCVec_u8Z arg_var = FundingLocked_write(&obj_conv);
13626         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
13627         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
13628         CVec_u8Z_free(arg_var);
13629         return arg_arr;
13630 }
13631
13632 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_FundingLocked_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
13633         LDKu8slice ser_ref;
13634         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
13635         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
13636         LDKFundingLocked ret_var = FundingLocked_read(ser_ref);
13637         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13638         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13639         long ret_ref = (long)ret_var.inner;
13640         if (ret_var.is_owned) {
13641                 ret_ref |= 1;
13642         }
13643         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
13644         return ret_ref;
13645 }
13646
13647 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_Init_1write(JNIEnv * _env, jclass _b, jlong obj) {
13648         LDKInit obj_conv;
13649         obj_conv.inner = (void*)(obj & (~1));
13650         obj_conv.is_owned = false;
13651         LDKCVec_u8Z arg_var = Init_write(&obj_conv);
13652         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
13653         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
13654         CVec_u8Z_free(arg_var);
13655         return arg_arr;
13656 }
13657
13658 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_Init_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
13659         LDKu8slice ser_ref;
13660         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
13661         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
13662         LDKCResult_InitDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_InitDecodeErrorZ), "LDKCResult_InitDecodeErrorZ");
13663         *ret_conv = Init_read(ser_ref);
13664         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
13665         return (long)ret_conv;
13666 }
13667
13668 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_OpenChannel_1write(JNIEnv * _env, jclass _b, jlong obj) {
13669         LDKOpenChannel obj_conv;
13670         obj_conv.inner = (void*)(obj & (~1));
13671         obj_conv.is_owned = false;
13672         LDKCVec_u8Z arg_var = OpenChannel_write(&obj_conv);
13673         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
13674         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
13675         CVec_u8Z_free(arg_var);
13676         return arg_arr;
13677 }
13678
13679 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_OpenChannel_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
13680         LDKu8slice ser_ref;
13681         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
13682         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
13683         LDKOpenChannel ret_var = OpenChannel_read(ser_ref);
13684         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13685         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13686         long ret_ref = (long)ret_var.inner;
13687         if (ret_var.is_owned) {
13688                 ret_ref |= 1;
13689         }
13690         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
13691         return ret_ref;
13692 }
13693
13694 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_RevokeAndACK_1write(JNIEnv * _env, jclass _b, jlong obj) {
13695         LDKRevokeAndACK obj_conv;
13696         obj_conv.inner = (void*)(obj & (~1));
13697         obj_conv.is_owned = false;
13698         LDKCVec_u8Z arg_var = RevokeAndACK_write(&obj_conv);
13699         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
13700         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
13701         CVec_u8Z_free(arg_var);
13702         return arg_arr;
13703 }
13704
13705 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_RevokeAndACK_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
13706         LDKu8slice ser_ref;
13707         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
13708         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
13709         LDKRevokeAndACK ret_var = RevokeAndACK_read(ser_ref);
13710         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13711         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13712         long ret_ref = (long)ret_var.inner;
13713         if (ret_var.is_owned) {
13714                 ret_ref |= 1;
13715         }
13716         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
13717         return ret_ref;
13718 }
13719
13720 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_Shutdown_1write(JNIEnv * _env, jclass _b, jlong obj) {
13721         LDKShutdown obj_conv;
13722         obj_conv.inner = (void*)(obj & (~1));
13723         obj_conv.is_owned = false;
13724         LDKCVec_u8Z arg_var = Shutdown_write(&obj_conv);
13725         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
13726         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
13727         CVec_u8Z_free(arg_var);
13728         return arg_arr;
13729 }
13730
13731 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_Shutdown_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
13732         LDKu8slice ser_ref;
13733         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
13734         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
13735         LDKShutdown ret_var = Shutdown_read(ser_ref);
13736         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13737         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13738         long ret_ref = (long)ret_var.inner;
13739         if (ret_var.is_owned) {
13740                 ret_ref |= 1;
13741         }
13742         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
13743         return ret_ref;
13744 }
13745
13746 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UpdateFailHTLC_1write(JNIEnv * _env, jclass _b, jlong obj) {
13747         LDKUpdateFailHTLC obj_conv;
13748         obj_conv.inner = (void*)(obj & (~1));
13749         obj_conv.is_owned = false;
13750         LDKCVec_u8Z arg_var = UpdateFailHTLC_write(&obj_conv);
13751         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
13752         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
13753         CVec_u8Z_free(arg_var);
13754         return arg_arr;
13755 }
13756
13757 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UpdateFailHTLC_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
13758         LDKu8slice ser_ref;
13759         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
13760         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
13761         LDKUpdateFailHTLC ret_var = UpdateFailHTLC_read(ser_ref);
13762         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13763         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13764         long ret_ref = (long)ret_var.inner;
13765         if (ret_var.is_owned) {
13766                 ret_ref |= 1;
13767         }
13768         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
13769         return ret_ref;
13770 }
13771
13772 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UpdateFailMalformedHTLC_1write(JNIEnv * _env, jclass _b, jlong obj) {
13773         LDKUpdateFailMalformedHTLC obj_conv;
13774         obj_conv.inner = (void*)(obj & (~1));
13775         obj_conv.is_owned = false;
13776         LDKCVec_u8Z arg_var = UpdateFailMalformedHTLC_write(&obj_conv);
13777         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
13778         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
13779         CVec_u8Z_free(arg_var);
13780         return arg_arr;
13781 }
13782
13783 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UpdateFailMalformedHTLC_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
13784         LDKu8slice ser_ref;
13785         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
13786         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
13787         LDKUpdateFailMalformedHTLC ret_var = UpdateFailMalformedHTLC_read(ser_ref);
13788         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13789         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13790         long ret_ref = (long)ret_var.inner;
13791         if (ret_var.is_owned) {
13792                 ret_ref |= 1;
13793         }
13794         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
13795         return ret_ref;
13796 }
13797
13798 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UpdateFee_1write(JNIEnv * _env, jclass _b, jlong obj) {
13799         LDKUpdateFee obj_conv;
13800         obj_conv.inner = (void*)(obj & (~1));
13801         obj_conv.is_owned = false;
13802         LDKCVec_u8Z arg_var = UpdateFee_write(&obj_conv);
13803         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
13804         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
13805         CVec_u8Z_free(arg_var);
13806         return arg_arr;
13807 }
13808
13809 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UpdateFee_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
13810         LDKu8slice ser_ref;
13811         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
13812         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
13813         LDKUpdateFee ret_var = UpdateFee_read(ser_ref);
13814         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13815         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13816         long ret_ref = (long)ret_var.inner;
13817         if (ret_var.is_owned) {
13818                 ret_ref |= 1;
13819         }
13820         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
13821         return ret_ref;
13822 }
13823
13824 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UpdateFulfillHTLC_1write(JNIEnv * _env, jclass _b, jlong obj) {
13825         LDKUpdateFulfillHTLC obj_conv;
13826         obj_conv.inner = (void*)(obj & (~1));
13827         obj_conv.is_owned = false;
13828         LDKCVec_u8Z arg_var = UpdateFulfillHTLC_write(&obj_conv);
13829         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
13830         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
13831         CVec_u8Z_free(arg_var);
13832         return arg_arr;
13833 }
13834
13835 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UpdateFulfillHTLC_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
13836         LDKu8slice ser_ref;
13837         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
13838         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
13839         LDKUpdateFulfillHTLC ret_var = UpdateFulfillHTLC_read(ser_ref);
13840         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13841         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13842         long ret_ref = (long)ret_var.inner;
13843         if (ret_var.is_owned) {
13844                 ret_ref |= 1;
13845         }
13846         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
13847         return ret_ref;
13848 }
13849
13850 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UpdateAddHTLC_1write(JNIEnv * _env, jclass _b, jlong obj) {
13851         LDKUpdateAddHTLC obj_conv;
13852         obj_conv.inner = (void*)(obj & (~1));
13853         obj_conv.is_owned = false;
13854         LDKCVec_u8Z arg_var = UpdateAddHTLC_write(&obj_conv);
13855         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
13856         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
13857         CVec_u8Z_free(arg_var);
13858         return arg_arr;
13859 }
13860
13861 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UpdateAddHTLC_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
13862         LDKu8slice ser_ref;
13863         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
13864         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
13865         LDKUpdateAddHTLC ret_var = UpdateAddHTLC_read(ser_ref);
13866         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13867         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13868         long ret_ref = (long)ret_var.inner;
13869         if (ret_var.is_owned) {
13870                 ret_ref |= 1;
13871         }
13872         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
13873         return ret_ref;
13874 }
13875
13876 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_Ping_1write(JNIEnv * _env, jclass _b, jlong obj) {
13877         LDKPing obj_conv;
13878         obj_conv.inner = (void*)(obj & (~1));
13879         obj_conv.is_owned = false;
13880         LDKCVec_u8Z arg_var = Ping_write(&obj_conv);
13881         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
13882         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
13883         CVec_u8Z_free(arg_var);
13884         return arg_arr;
13885 }
13886
13887 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_Ping_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
13888         LDKu8slice ser_ref;
13889         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
13890         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
13891         LDKCResult_PingDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_PingDecodeErrorZ), "LDKCResult_PingDecodeErrorZ");
13892         *ret_conv = Ping_read(ser_ref);
13893         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
13894         return (long)ret_conv;
13895 }
13896
13897 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_Pong_1write(JNIEnv * _env, jclass _b, jlong obj) {
13898         LDKPong obj_conv;
13899         obj_conv.inner = (void*)(obj & (~1));
13900         obj_conv.is_owned = false;
13901         LDKCVec_u8Z arg_var = Pong_write(&obj_conv);
13902         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
13903         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
13904         CVec_u8Z_free(arg_var);
13905         return arg_arr;
13906 }
13907
13908 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_Pong_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
13909         LDKu8slice ser_ref;
13910         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
13911         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
13912         LDKCResult_PongDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_PongDecodeErrorZ), "LDKCResult_PongDecodeErrorZ");
13913         *ret_conv = Pong_read(ser_ref);
13914         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
13915         return (long)ret_conv;
13916 }
13917
13918 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1write(JNIEnv * _env, jclass _b, jlong obj) {
13919         LDKUnsignedChannelAnnouncement obj_conv;
13920         obj_conv.inner = (void*)(obj & (~1));
13921         obj_conv.is_owned = false;
13922         LDKCVec_u8Z arg_var = UnsignedChannelAnnouncement_write(&obj_conv);
13923         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
13924         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
13925         CVec_u8Z_free(arg_var);
13926         return arg_arr;
13927 }
13928
13929 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
13930         LDKu8slice ser_ref;
13931         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
13932         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
13933         LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ), "LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ");
13934         *ret_conv = UnsignedChannelAnnouncement_read(ser_ref);
13935         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
13936         return (long)ret_conv;
13937 }
13938
13939 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelAnnouncement_1write(JNIEnv * _env, jclass _b, jlong obj) {
13940         LDKChannelAnnouncement obj_conv;
13941         obj_conv.inner = (void*)(obj & (~1));
13942         obj_conv.is_owned = false;
13943         LDKCVec_u8Z arg_var = ChannelAnnouncement_write(&obj_conv);
13944         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
13945         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
13946         CVec_u8Z_free(arg_var);
13947         return arg_arr;
13948 }
13949
13950 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelAnnouncement_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
13951         LDKu8slice ser_ref;
13952         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
13953         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
13954         LDKChannelAnnouncement ret_var = ChannelAnnouncement_read(ser_ref);
13955         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13956         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13957         long ret_ref = (long)ret_var.inner;
13958         if (ret_var.is_owned) {
13959                 ret_ref |= 1;
13960         }
13961         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
13962         return ret_ref;
13963 }
13964
13965 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1write(JNIEnv * _env, jclass _b, jlong obj) {
13966         LDKUnsignedChannelUpdate obj_conv;
13967         obj_conv.inner = (void*)(obj & (~1));
13968         obj_conv.is_owned = false;
13969         LDKCVec_u8Z arg_var = UnsignedChannelUpdate_write(&obj_conv);
13970         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
13971         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
13972         CVec_u8Z_free(arg_var);
13973         return arg_arr;
13974 }
13975
13976 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
13977         LDKu8slice ser_ref;
13978         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
13979         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
13980         LDKCResult_UnsignedChannelUpdateDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_UnsignedChannelUpdateDecodeErrorZ), "LDKCResult_UnsignedChannelUpdateDecodeErrorZ");
13981         *ret_conv = UnsignedChannelUpdate_read(ser_ref);
13982         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
13983         return (long)ret_conv;
13984 }
13985
13986 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelUpdate_1write(JNIEnv * _env, jclass _b, jlong obj) {
13987         LDKChannelUpdate obj_conv;
13988         obj_conv.inner = (void*)(obj & (~1));
13989         obj_conv.is_owned = false;
13990         LDKCVec_u8Z arg_var = ChannelUpdate_write(&obj_conv);
13991         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
13992         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
13993         CVec_u8Z_free(arg_var);
13994         return arg_arr;
13995 }
13996
13997 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelUpdate_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
13998         LDKu8slice ser_ref;
13999         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
14000         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
14001         LDKChannelUpdate ret_var = ChannelUpdate_read(ser_ref);
14002         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14003         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14004         long ret_ref = (long)ret_var.inner;
14005         if (ret_var.is_owned) {
14006                 ret_ref |= 1;
14007         }
14008         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
14009         return ret_ref;
14010 }
14011
14012 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ErrorMessage_1write(JNIEnv * _env, jclass _b, jlong obj) {
14013         LDKErrorMessage obj_conv;
14014         obj_conv.inner = (void*)(obj & (~1));
14015         obj_conv.is_owned = false;
14016         LDKCVec_u8Z arg_var = ErrorMessage_write(&obj_conv);
14017         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
14018         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
14019         CVec_u8Z_free(arg_var);
14020         return arg_arr;
14021 }
14022
14023 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ErrorMessage_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
14024         LDKu8slice ser_ref;
14025         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
14026         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
14027         LDKCResult_ErrorMessageDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ErrorMessageDecodeErrorZ), "LDKCResult_ErrorMessageDecodeErrorZ");
14028         *ret_conv = ErrorMessage_read(ser_ref);
14029         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
14030         return (long)ret_conv;
14031 }
14032
14033 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UnsignedNodeAnnouncement_1write(JNIEnv * _env, jclass _b, jlong obj) {
14034         LDKUnsignedNodeAnnouncement obj_conv;
14035         obj_conv.inner = (void*)(obj & (~1));
14036         obj_conv.is_owned = false;
14037         LDKCVec_u8Z arg_var = UnsignedNodeAnnouncement_write(&obj_conv);
14038         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
14039         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
14040         CVec_u8Z_free(arg_var);
14041         return arg_arr;
14042 }
14043
14044 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UnsignedNodeAnnouncement_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
14045         LDKu8slice ser_ref;
14046         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
14047         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
14048         LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ), "LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ");
14049         *ret_conv = UnsignedNodeAnnouncement_read(ser_ref);
14050         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
14051         return (long)ret_conv;
14052 }
14053
14054 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_NodeAnnouncement_1write(JNIEnv * _env, jclass _b, jlong obj) {
14055         LDKNodeAnnouncement obj_conv;
14056         obj_conv.inner = (void*)(obj & (~1));
14057         obj_conv.is_owned = false;
14058         LDKCVec_u8Z arg_var = NodeAnnouncement_write(&obj_conv);
14059         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
14060         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
14061         CVec_u8Z_free(arg_var);
14062         return arg_arr;
14063 }
14064
14065 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_NodeAnnouncement_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
14066         LDKu8slice ser_ref;
14067         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
14068         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
14069         LDKNodeAnnouncement ret_var = NodeAnnouncement_read(ser_ref);
14070         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14071         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14072         long ret_ref = (long)ret_var.inner;
14073         if (ret_var.is_owned) {
14074                 ret_ref |= 1;
14075         }
14076         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
14077         return ret_ref;
14078 }
14079
14080 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_QueryShortChannelIds_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
14081         LDKu8slice ser_ref;
14082         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
14083         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
14084         LDKCResult_QueryShortChannelIdsDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_QueryShortChannelIdsDecodeErrorZ), "LDKCResult_QueryShortChannelIdsDecodeErrorZ");
14085         *ret_conv = QueryShortChannelIds_read(ser_ref);
14086         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
14087         return (long)ret_conv;
14088 }
14089
14090 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_QueryShortChannelIds_1write(JNIEnv * _env, jclass _b, jlong obj) {
14091         LDKQueryShortChannelIds obj_conv;
14092         obj_conv.inner = (void*)(obj & (~1));
14093         obj_conv.is_owned = false;
14094         LDKCVec_u8Z arg_var = QueryShortChannelIds_write(&obj_conv);
14095         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
14096         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
14097         CVec_u8Z_free(arg_var);
14098         return arg_arr;
14099 }
14100
14101 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ReplyShortChannelIdsEnd_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
14102         LDKu8slice ser_ref;
14103         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
14104         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
14105         LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ), "LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ");
14106         *ret_conv = ReplyShortChannelIdsEnd_read(ser_ref);
14107         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
14108         return (long)ret_conv;
14109 }
14110
14111 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ReplyShortChannelIdsEnd_1write(JNIEnv * _env, jclass _b, jlong obj) {
14112         LDKReplyShortChannelIdsEnd obj_conv;
14113         obj_conv.inner = (void*)(obj & (~1));
14114         obj_conv.is_owned = false;
14115         LDKCVec_u8Z arg_var = ReplyShortChannelIdsEnd_write(&obj_conv);
14116         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
14117         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
14118         CVec_u8Z_free(arg_var);
14119         return arg_arr;
14120 }
14121
14122 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_QueryChannelRange_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
14123         LDKu8slice ser_ref;
14124         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
14125         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
14126         LDKCResult_QueryChannelRangeDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_QueryChannelRangeDecodeErrorZ), "LDKCResult_QueryChannelRangeDecodeErrorZ");
14127         *ret_conv = QueryChannelRange_read(ser_ref);
14128         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
14129         return (long)ret_conv;
14130 }
14131
14132 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_QueryChannelRange_1write(JNIEnv * _env, jclass _b, jlong obj) {
14133         LDKQueryChannelRange obj_conv;
14134         obj_conv.inner = (void*)(obj & (~1));
14135         obj_conv.is_owned = false;
14136         LDKCVec_u8Z arg_var = QueryChannelRange_write(&obj_conv);
14137         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
14138         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
14139         CVec_u8Z_free(arg_var);
14140         return arg_arr;
14141 }
14142
14143 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ReplyChannelRange_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
14144         LDKu8slice ser_ref;
14145         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
14146         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
14147         LDKCResult_ReplyChannelRangeDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ReplyChannelRangeDecodeErrorZ), "LDKCResult_ReplyChannelRangeDecodeErrorZ");
14148         *ret_conv = ReplyChannelRange_read(ser_ref);
14149         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
14150         return (long)ret_conv;
14151 }
14152
14153 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ReplyChannelRange_1write(JNIEnv * _env, jclass _b, jlong obj) {
14154         LDKReplyChannelRange obj_conv;
14155         obj_conv.inner = (void*)(obj & (~1));
14156         obj_conv.is_owned = false;
14157         LDKCVec_u8Z arg_var = ReplyChannelRange_write(&obj_conv);
14158         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
14159         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
14160         CVec_u8Z_free(arg_var);
14161         return arg_arr;
14162 }
14163
14164 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_GossipTimestampFilter_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
14165         LDKu8slice ser_ref;
14166         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
14167         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
14168         LDKCResult_GossipTimestampFilterDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_GossipTimestampFilterDecodeErrorZ), "LDKCResult_GossipTimestampFilterDecodeErrorZ");
14169         *ret_conv = GossipTimestampFilter_read(ser_ref);
14170         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
14171         return (long)ret_conv;
14172 }
14173
14174 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_GossipTimestampFilter_1write(JNIEnv * _env, jclass _b, jlong obj) {
14175         LDKGossipTimestampFilter obj_conv;
14176         obj_conv.inner = (void*)(obj & (~1));
14177         obj_conv.is_owned = false;
14178         LDKCVec_u8Z arg_var = GossipTimestampFilter_write(&obj_conv);
14179         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
14180         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
14181         CVec_u8Z_free(arg_var);
14182         return arg_arr;
14183 }
14184
14185 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_MessageHandler_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
14186         LDKMessageHandler this_ptr_conv;
14187         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14188         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
14189         MessageHandler_free(this_ptr_conv);
14190 }
14191
14192 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_MessageHandler_1get_1chan_1handler(JNIEnv * _env, jclass _b, jlong this_ptr) {
14193         LDKMessageHandler this_ptr_conv;
14194         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14195         this_ptr_conv.is_owned = false;
14196         long ret_ret = (long)MessageHandler_get_chan_handler(&this_ptr_conv);
14197         return ret_ret;
14198 }
14199
14200 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_MessageHandler_1set_1chan_1handler(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
14201         LDKMessageHandler this_ptr_conv;
14202         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14203         this_ptr_conv.is_owned = false;
14204         LDKChannelMessageHandler val_conv = *(LDKChannelMessageHandler*)val;
14205         if (val_conv.free == LDKChannelMessageHandler_JCalls_free) {
14206                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
14207                 LDKChannelMessageHandler_JCalls_clone(val_conv.this_arg);
14208         }
14209         MessageHandler_set_chan_handler(&this_ptr_conv, val_conv);
14210 }
14211
14212 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_MessageHandler_1get_1route_1handler(JNIEnv * _env, jclass _b, jlong this_ptr) {
14213         LDKMessageHandler this_ptr_conv;
14214         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14215         this_ptr_conv.is_owned = false;
14216         long ret_ret = (long)MessageHandler_get_route_handler(&this_ptr_conv);
14217         return ret_ret;
14218 }
14219
14220 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_MessageHandler_1set_1route_1handler(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
14221         LDKMessageHandler this_ptr_conv;
14222         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14223         this_ptr_conv.is_owned = false;
14224         LDKRoutingMessageHandler val_conv = *(LDKRoutingMessageHandler*)val;
14225         if (val_conv.free == LDKRoutingMessageHandler_JCalls_free) {
14226                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
14227                 LDKRoutingMessageHandler_JCalls_clone(val_conv.this_arg);
14228         }
14229         MessageHandler_set_route_handler(&this_ptr_conv, val_conv);
14230 }
14231
14232 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_MessageHandler_1new(JNIEnv * _env, jclass _b, jlong chan_handler_arg, jlong route_handler_arg) {
14233         LDKChannelMessageHandler chan_handler_arg_conv = *(LDKChannelMessageHandler*)chan_handler_arg;
14234         if (chan_handler_arg_conv.free == LDKChannelMessageHandler_JCalls_free) {
14235                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
14236                 LDKChannelMessageHandler_JCalls_clone(chan_handler_arg_conv.this_arg);
14237         }
14238         LDKRoutingMessageHandler route_handler_arg_conv = *(LDKRoutingMessageHandler*)route_handler_arg;
14239         if (route_handler_arg_conv.free == LDKRoutingMessageHandler_JCalls_free) {
14240                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
14241                 LDKRoutingMessageHandler_JCalls_clone(route_handler_arg_conv.this_arg);
14242         }
14243         LDKMessageHandler ret_var = MessageHandler_new(chan_handler_arg_conv, route_handler_arg_conv);
14244         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14245         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14246         long ret_ref = (long)ret_var.inner;
14247         if (ret_var.is_owned) {
14248                 ret_ref |= 1;
14249         }
14250         return ret_ref;
14251 }
14252
14253 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_SocketDescriptor_1clone(JNIEnv * _env, jclass _b, jlong orig) {
14254         LDKSocketDescriptor* orig_conv = (LDKSocketDescriptor*)orig;
14255         LDKSocketDescriptor* ret = MALLOC(sizeof(LDKSocketDescriptor), "LDKSocketDescriptor");
14256         *ret = SocketDescriptor_clone(orig_conv);
14257         return (long)ret;
14258 }
14259
14260 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_SocketDescriptor_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
14261         LDKSocketDescriptor this_ptr_conv = *(LDKSocketDescriptor*)this_ptr;
14262         FREE((void*)this_ptr);
14263         SocketDescriptor_free(this_ptr_conv);
14264 }
14265
14266 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_PeerHandleError_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
14267         LDKPeerHandleError this_ptr_conv;
14268         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14269         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
14270         PeerHandleError_free(this_ptr_conv);
14271 }
14272
14273 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_PeerHandleError_1get_1no_1connection_1possible(JNIEnv * _env, jclass _b, jlong this_ptr) {
14274         LDKPeerHandleError this_ptr_conv;
14275         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14276         this_ptr_conv.is_owned = false;
14277         jboolean ret_val = PeerHandleError_get_no_connection_possible(&this_ptr_conv);
14278         return ret_val;
14279 }
14280
14281 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_PeerHandleError_1set_1no_1connection_1possible(JNIEnv * _env, jclass _b, jlong this_ptr, jboolean val) {
14282         LDKPeerHandleError this_ptr_conv;
14283         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14284         this_ptr_conv.is_owned = false;
14285         PeerHandleError_set_no_connection_possible(&this_ptr_conv, val);
14286 }
14287
14288 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_PeerHandleError_1new(JNIEnv * _env, jclass _b, jboolean no_connection_possible_arg) {
14289         LDKPeerHandleError ret_var = PeerHandleError_new(no_connection_possible_arg);
14290         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14291         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14292         long ret_ref = (long)ret_var.inner;
14293         if (ret_var.is_owned) {
14294                 ret_ref |= 1;
14295         }
14296         return ret_ref;
14297 }
14298
14299 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_PeerManager_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
14300         LDKPeerManager this_ptr_conv;
14301         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14302         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
14303         PeerManager_free(this_ptr_conv);
14304 }
14305
14306 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_PeerManager_1new(JNIEnv * _env, jclass _b, jlong message_handler, jbyteArray our_node_secret, jbyteArray ephemeral_random_data, jlong logger) {
14307         LDKMessageHandler message_handler_conv;
14308         message_handler_conv.inner = (void*)(message_handler & (~1));
14309         message_handler_conv.is_owned = (message_handler & 1) || (message_handler == 0);
14310         // Warning: we may need a move here but can't clone!
14311         LDKSecretKey our_node_secret_ref;
14312         CHECK((*_env)->GetArrayLength (_env, our_node_secret) == 32);
14313         (*_env)->GetByteArrayRegion (_env, our_node_secret, 0, 32, our_node_secret_ref.bytes);
14314         unsigned char ephemeral_random_data_arr[32];
14315         CHECK((*_env)->GetArrayLength (_env, ephemeral_random_data) == 32);
14316         (*_env)->GetByteArrayRegion (_env, ephemeral_random_data, 0, 32, ephemeral_random_data_arr);
14317         unsigned char (*ephemeral_random_data_ref)[32] = &ephemeral_random_data_arr;
14318         LDKLogger logger_conv = *(LDKLogger*)logger;
14319         if (logger_conv.free == LDKLogger_JCalls_free) {
14320                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
14321                 LDKLogger_JCalls_clone(logger_conv.this_arg);
14322         }
14323         LDKPeerManager ret_var = PeerManager_new(message_handler_conv, our_node_secret_ref, ephemeral_random_data_ref, logger_conv);
14324         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14325         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14326         long ret_ref = (long)ret_var.inner;
14327         if (ret_var.is_owned) {
14328                 ret_ref |= 1;
14329         }
14330         return ret_ref;
14331 }
14332
14333 JNIEXPORT jobjectArray JNICALL Java_org_ldk_impl_bindings_PeerManager_1get_1peer_1node_1ids(JNIEnv * _env, jclass _b, jlong this_arg) {
14334         LDKPeerManager this_arg_conv;
14335         this_arg_conv.inner = (void*)(this_arg & (~1));
14336         this_arg_conv.is_owned = false;
14337         LDKCVec_PublicKeyZ ret_var = PeerManager_get_peer_node_ids(&this_arg_conv);
14338         jobjectArray ret_arr = (*_env)->NewObjectArray(_env, ret_var.datalen, arr_of_B_clz, NULL);
14339         for (size_t i = 0; i < ret_var.datalen; i++) {
14340                 jbyteArray arr_conv_8_arr = (*_env)->NewByteArray(_env, 33);
14341                 (*_env)->SetByteArrayRegion(_env, arr_conv_8_arr, 0, 33, ret_var.data[i].compressed_form);
14342                 (*_env)->SetObjectArrayElement(_env, ret_arr, i, arr_conv_8_arr);
14343         }
14344         FREE(ret_var.data);
14345         return ret_arr;
14346 }
14347
14348 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_PeerManager_1new_1outbound_1connection(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray their_node_id, jlong descriptor) {
14349         LDKPeerManager this_arg_conv;
14350         this_arg_conv.inner = (void*)(this_arg & (~1));
14351         this_arg_conv.is_owned = false;
14352         LDKPublicKey their_node_id_ref;
14353         CHECK((*_env)->GetArrayLength (_env, their_node_id) == 33);
14354         (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
14355         LDKSocketDescriptor descriptor_conv = *(LDKSocketDescriptor*)descriptor;
14356         if (descriptor_conv.free == LDKSocketDescriptor_JCalls_free) {
14357                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
14358                 LDKSocketDescriptor_JCalls_clone(descriptor_conv.this_arg);
14359         }
14360         LDKCResult_CVec_u8ZPeerHandleErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_CVec_u8ZPeerHandleErrorZ), "LDKCResult_CVec_u8ZPeerHandleErrorZ");
14361         *ret_conv = PeerManager_new_outbound_connection(&this_arg_conv, their_node_id_ref, descriptor_conv);
14362         return (long)ret_conv;
14363 }
14364
14365 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_PeerManager_1new_1inbound_1connection(JNIEnv * _env, jclass _b, jlong this_arg, jlong descriptor) {
14366         LDKPeerManager this_arg_conv;
14367         this_arg_conv.inner = (void*)(this_arg & (~1));
14368         this_arg_conv.is_owned = false;
14369         LDKSocketDescriptor descriptor_conv = *(LDKSocketDescriptor*)descriptor;
14370         if (descriptor_conv.free == LDKSocketDescriptor_JCalls_free) {
14371                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
14372                 LDKSocketDescriptor_JCalls_clone(descriptor_conv.this_arg);
14373         }
14374         LDKCResult_NonePeerHandleErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NonePeerHandleErrorZ), "LDKCResult_NonePeerHandleErrorZ");
14375         *ret_conv = PeerManager_new_inbound_connection(&this_arg_conv, descriptor_conv);
14376         return (long)ret_conv;
14377 }
14378
14379 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_PeerManager_1write_1buffer_1space_1avail(JNIEnv * _env, jclass _b, jlong this_arg, jlong descriptor) {
14380         LDKPeerManager this_arg_conv;
14381         this_arg_conv.inner = (void*)(this_arg & (~1));
14382         this_arg_conv.is_owned = false;
14383         LDKSocketDescriptor* descriptor_conv = (LDKSocketDescriptor*)descriptor;
14384         LDKCResult_NonePeerHandleErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NonePeerHandleErrorZ), "LDKCResult_NonePeerHandleErrorZ");
14385         *ret_conv = PeerManager_write_buffer_space_avail(&this_arg_conv, descriptor_conv);
14386         return (long)ret_conv;
14387 }
14388
14389 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_PeerManager_1read_1event(JNIEnv * _env, jclass _b, jlong this_arg, jlong peer_descriptor, jbyteArray data) {
14390         LDKPeerManager this_arg_conv;
14391         this_arg_conv.inner = (void*)(this_arg & (~1));
14392         this_arg_conv.is_owned = false;
14393         LDKSocketDescriptor* peer_descriptor_conv = (LDKSocketDescriptor*)peer_descriptor;
14394         LDKu8slice data_ref;
14395         data_ref.datalen = (*_env)->GetArrayLength (_env, data);
14396         data_ref.data = (*_env)->GetByteArrayElements (_env, data, NULL);
14397         LDKCResult_boolPeerHandleErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_boolPeerHandleErrorZ), "LDKCResult_boolPeerHandleErrorZ");
14398         *ret_conv = PeerManager_read_event(&this_arg_conv, peer_descriptor_conv, data_ref);
14399         (*_env)->ReleaseByteArrayElements(_env, data, (int8_t*)data_ref.data, 0);
14400         return (long)ret_conv;
14401 }
14402
14403 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_PeerManager_1process_1events(JNIEnv * _env, jclass _b, jlong this_arg) {
14404         LDKPeerManager this_arg_conv;
14405         this_arg_conv.inner = (void*)(this_arg & (~1));
14406         this_arg_conv.is_owned = false;
14407         PeerManager_process_events(&this_arg_conv);
14408 }
14409
14410 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_PeerManager_1socket_1disconnected(JNIEnv * _env, jclass _b, jlong this_arg, jlong descriptor) {
14411         LDKPeerManager this_arg_conv;
14412         this_arg_conv.inner = (void*)(this_arg & (~1));
14413         this_arg_conv.is_owned = false;
14414         LDKSocketDescriptor* descriptor_conv = (LDKSocketDescriptor*)descriptor;
14415         PeerManager_socket_disconnected(&this_arg_conv, descriptor_conv);
14416 }
14417
14418 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_PeerManager_1timer_1tick_1occured(JNIEnv * _env, jclass _b, jlong this_arg) {
14419         LDKPeerManager this_arg_conv;
14420         this_arg_conv.inner = (void*)(this_arg & (~1));
14421         this_arg_conv.is_owned = false;
14422         PeerManager_timer_tick_occured(&this_arg_conv);
14423 }
14424
14425 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_build_1commitment_1secret(JNIEnv * _env, jclass _b, jbyteArray commitment_seed, jlong idx) {
14426         unsigned char commitment_seed_arr[32];
14427         CHECK((*_env)->GetArrayLength (_env, commitment_seed) == 32);
14428         (*_env)->GetByteArrayRegion (_env, commitment_seed, 0, 32, commitment_seed_arr);
14429         unsigned char (*commitment_seed_ref)[32] = &commitment_seed_arr;
14430         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 32);
14431         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 32, build_commitment_secret(commitment_seed_ref, idx).data);
14432         return arg_arr;
14433 }
14434
14435 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_derive_1private_1key(JNIEnv * _env, jclass _b, jbyteArray per_commitment_point, jbyteArray base_secret) {
14436         LDKPublicKey per_commitment_point_ref;
14437         CHECK((*_env)->GetArrayLength (_env, per_commitment_point) == 33);
14438         (*_env)->GetByteArrayRegion (_env, per_commitment_point, 0, 33, per_commitment_point_ref.compressed_form);
14439         unsigned char base_secret_arr[32];
14440         CHECK((*_env)->GetArrayLength (_env, base_secret) == 32);
14441         (*_env)->GetByteArrayRegion (_env, base_secret, 0, 32, base_secret_arr);
14442         unsigned char (*base_secret_ref)[32] = &base_secret_arr;
14443         LDKCResult_SecretKeySecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_SecretKeySecpErrorZ), "LDKCResult_SecretKeySecpErrorZ");
14444         *ret_conv = derive_private_key(per_commitment_point_ref, base_secret_ref);
14445         return (long)ret_conv;
14446 }
14447
14448 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_derive_1public_1key(JNIEnv * _env, jclass _b, jbyteArray per_commitment_point, jbyteArray base_point) {
14449         LDKPublicKey per_commitment_point_ref;
14450         CHECK((*_env)->GetArrayLength (_env, per_commitment_point) == 33);
14451         (*_env)->GetByteArrayRegion (_env, per_commitment_point, 0, 33, per_commitment_point_ref.compressed_form);
14452         LDKPublicKey base_point_ref;
14453         CHECK((*_env)->GetArrayLength (_env, base_point) == 33);
14454         (*_env)->GetByteArrayRegion (_env, base_point, 0, 33, base_point_ref.compressed_form);
14455         LDKCResult_PublicKeySecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_PublicKeySecpErrorZ), "LDKCResult_PublicKeySecpErrorZ");
14456         *ret_conv = derive_public_key(per_commitment_point_ref, base_point_ref);
14457         return (long)ret_conv;
14458 }
14459
14460 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_derive_1private_1revocation_1key(JNIEnv * _env, jclass _b, jbyteArray per_commitment_secret, jbyteArray countersignatory_revocation_base_secret) {
14461         unsigned char per_commitment_secret_arr[32];
14462         CHECK((*_env)->GetArrayLength (_env, per_commitment_secret) == 32);
14463         (*_env)->GetByteArrayRegion (_env, per_commitment_secret, 0, 32, per_commitment_secret_arr);
14464         unsigned char (*per_commitment_secret_ref)[32] = &per_commitment_secret_arr;
14465         unsigned char countersignatory_revocation_base_secret_arr[32];
14466         CHECK((*_env)->GetArrayLength (_env, countersignatory_revocation_base_secret) == 32);
14467         (*_env)->GetByteArrayRegion (_env, countersignatory_revocation_base_secret, 0, 32, countersignatory_revocation_base_secret_arr);
14468         unsigned char (*countersignatory_revocation_base_secret_ref)[32] = &countersignatory_revocation_base_secret_arr;
14469         LDKCResult_SecretKeySecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_SecretKeySecpErrorZ), "LDKCResult_SecretKeySecpErrorZ");
14470         *ret_conv = derive_private_revocation_key(per_commitment_secret_ref, countersignatory_revocation_base_secret_ref);
14471         return (long)ret_conv;
14472 }
14473
14474 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_derive_1public_1revocation_1key(JNIEnv * _env, jclass _b, jbyteArray per_commitment_point, jbyteArray countersignatory_revocation_base_point) {
14475         LDKPublicKey per_commitment_point_ref;
14476         CHECK((*_env)->GetArrayLength (_env, per_commitment_point) == 33);
14477         (*_env)->GetByteArrayRegion (_env, per_commitment_point, 0, 33, per_commitment_point_ref.compressed_form);
14478         LDKPublicKey countersignatory_revocation_base_point_ref;
14479         CHECK((*_env)->GetArrayLength (_env, countersignatory_revocation_base_point) == 33);
14480         (*_env)->GetByteArrayRegion (_env, countersignatory_revocation_base_point, 0, 33, countersignatory_revocation_base_point_ref.compressed_form);
14481         LDKCResult_PublicKeySecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_PublicKeySecpErrorZ), "LDKCResult_PublicKeySecpErrorZ");
14482         *ret_conv = derive_public_revocation_key(per_commitment_point_ref, countersignatory_revocation_base_point_ref);
14483         return (long)ret_conv;
14484 }
14485
14486 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_TxCreationKeys_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
14487         LDKTxCreationKeys this_ptr_conv;
14488         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14489         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
14490         TxCreationKeys_free(this_ptr_conv);
14491 }
14492
14493 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_TxCreationKeys_1clone(JNIEnv * _env, jclass _b, jlong orig) {
14494         LDKTxCreationKeys orig_conv;
14495         orig_conv.inner = (void*)(orig & (~1));
14496         orig_conv.is_owned = false;
14497         LDKTxCreationKeys ret_var = TxCreationKeys_clone(&orig_conv);
14498         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14499         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14500         long ret_ref = (long)ret_var.inner;
14501         if (ret_var.is_owned) {
14502                 ret_ref |= 1;
14503         }
14504         return ret_ref;
14505 }
14506
14507 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_TxCreationKeys_1get_1per_1commitment_1point(JNIEnv * _env, jclass _b, jlong this_ptr) {
14508         LDKTxCreationKeys this_ptr_conv;
14509         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14510         this_ptr_conv.is_owned = false;
14511         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
14512         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, TxCreationKeys_get_per_commitment_point(&this_ptr_conv).compressed_form);
14513         return arg_arr;
14514 }
14515
14516 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_TxCreationKeys_1set_1per_1commitment_1point(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
14517         LDKTxCreationKeys this_ptr_conv;
14518         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14519         this_ptr_conv.is_owned = false;
14520         LDKPublicKey val_ref;
14521         CHECK((*_env)->GetArrayLength (_env, val) == 33);
14522         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
14523         TxCreationKeys_set_per_commitment_point(&this_ptr_conv, val_ref);
14524 }
14525
14526 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_TxCreationKeys_1get_1revocation_1key(JNIEnv * _env, jclass _b, jlong this_ptr) {
14527         LDKTxCreationKeys this_ptr_conv;
14528         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14529         this_ptr_conv.is_owned = false;
14530         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
14531         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, TxCreationKeys_get_revocation_key(&this_ptr_conv).compressed_form);
14532         return arg_arr;
14533 }
14534
14535 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_TxCreationKeys_1set_1revocation_1key(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
14536         LDKTxCreationKeys this_ptr_conv;
14537         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14538         this_ptr_conv.is_owned = false;
14539         LDKPublicKey val_ref;
14540         CHECK((*_env)->GetArrayLength (_env, val) == 33);
14541         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
14542         TxCreationKeys_set_revocation_key(&this_ptr_conv, val_ref);
14543 }
14544
14545 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_TxCreationKeys_1get_1broadcaster_1htlc_1key(JNIEnv * _env, jclass _b, jlong this_ptr) {
14546         LDKTxCreationKeys this_ptr_conv;
14547         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14548         this_ptr_conv.is_owned = false;
14549         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
14550         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, TxCreationKeys_get_broadcaster_htlc_key(&this_ptr_conv).compressed_form);
14551         return arg_arr;
14552 }
14553
14554 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_TxCreationKeys_1set_1broadcaster_1htlc_1key(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
14555         LDKTxCreationKeys this_ptr_conv;
14556         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14557         this_ptr_conv.is_owned = false;
14558         LDKPublicKey val_ref;
14559         CHECK((*_env)->GetArrayLength (_env, val) == 33);
14560         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
14561         TxCreationKeys_set_broadcaster_htlc_key(&this_ptr_conv, val_ref);
14562 }
14563
14564 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_TxCreationKeys_1get_1countersignatory_1htlc_1key(JNIEnv * _env, jclass _b, jlong this_ptr) {
14565         LDKTxCreationKeys this_ptr_conv;
14566         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14567         this_ptr_conv.is_owned = false;
14568         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
14569         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, TxCreationKeys_get_countersignatory_htlc_key(&this_ptr_conv).compressed_form);
14570         return arg_arr;
14571 }
14572
14573 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_TxCreationKeys_1set_1countersignatory_1htlc_1key(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
14574         LDKTxCreationKeys this_ptr_conv;
14575         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14576         this_ptr_conv.is_owned = false;
14577         LDKPublicKey val_ref;
14578         CHECK((*_env)->GetArrayLength (_env, val) == 33);
14579         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
14580         TxCreationKeys_set_countersignatory_htlc_key(&this_ptr_conv, val_ref);
14581 }
14582
14583 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_TxCreationKeys_1get_1broadcaster_1delayed_1payment_1key(JNIEnv * _env, jclass _b, jlong this_ptr) {
14584         LDKTxCreationKeys this_ptr_conv;
14585         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14586         this_ptr_conv.is_owned = false;
14587         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
14588         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, TxCreationKeys_get_broadcaster_delayed_payment_key(&this_ptr_conv).compressed_form);
14589         return arg_arr;
14590 }
14591
14592 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_TxCreationKeys_1set_1broadcaster_1delayed_1payment_1key(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
14593         LDKTxCreationKeys this_ptr_conv;
14594         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14595         this_ptr_conv.is_owned = false;
14596         LDKPublicKey val_ref;
14597         CHECK((*_env)->GetArrayLength (_env, val) == 33);
14598         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
14599         TxCreationKeys_set_broadcaster_delayed_payment_key(&this_ptr_conv, val_ref);
14600 }
14601
14602 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_TxCreationKeys_1new(JNIEnv * _env, jclass _b, jbyteArray per_commitment_point_arg, jbyteArray revocation_key_arg, jbyteArray broadcaster_htlc_key_arg, jbyteArray countersignatory_htlc_key_arg, jbyteArray broadcaster_delayed_payment_key_arg) {
14603         LDKPublicKey per_commitment_point_arg_ref;
14604         CHECK((*_env)->GetArrayLength (_env, per_commitment_point_arg) == 33);
14605         (*_env)->GetByteArrayRegion (_env, per_commitment_point_arg, 0, 33, per_commitment_point_arg_ref.compressed_form);
14606         LDKPublicKey revocation_key_arg_ref;
14607         CHECK((*_env)->GetArrayLength (_env, revocation_key_arg) == 33);
14608         (*_env)->GetByteArrayRegion (_env, revocation_key_arg, 0, 33, revocation_key_arg_ref.compressed_form);
14609         LDKPublicKey broadcaster_htlc_key_arg_ref;
14610         CHECK((*_env)->GetArrayLength (_env, broadcaster_htlc_key_arg) == 33);
14611         (*_env)->GetByteArrayRegion (_env, broadcaster_htlc_key_arg, 0, 33, broadcaster_htlc_key_arg_ref.compressed_form);
14612         LDKPublicKey countersignatory_htlc_key_arg_ref;
14613         CHECK((*_env)->GetArrayLength (_env, countersignatory_htlc_key_arg) == 33);
14614         (*_env)->GetByteArrayRegion (_env, countersignatory_htlc_key_arg, 0, 33, countersignatory_htlc_key_arg_ref.compressed_form);
14615         LDKPublicKey broadcaster_delayed_payment_key_arg_ref;
14616         CHECK((*_env)->GetArrayLength (_env, broadcaster_delayed_payment_key_arg) == 33);
14617         (*_env)->GetByteArrayRegion (_env, broadcaster_delayed_payment_key_arg, 0, 33, broadcaster_delayed_payment_key_arg_ref.compressed_form);
14618         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);
14619         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14620         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14621         long ret_ref = (long)ret_var.inner;
14622         if (ret_var.is_owned) {
14623                 ret_ref |= 1;
14624         }
14625         return ret_ref;
14626 }
14627
14628 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_TxCreationKeys_1write(JNIEnv * _env, jclass _b, jlong obj) {
14629         LDKTxCreationKeys obj_conv;
14630         obj_conv.inner = (void*)(obj & (~1));
14631         obj_conv.is_owned = false;
14632         LDKCVec_u8Z arg_var = TxCreationKeys_write(&obj_conv);
14633         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
14634         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
14635         CVec_u8Z_free(arg_var);
14636         return arg_arr;
14637 }
14638
14639 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_TxCreationKeys_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
14640         LDKu8slice ser_ref;
14641         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
14642         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
14643         LDKTxCreationKeys ret_var = TxCreationKeys_read(ser_ref);
14644         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14645         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14646         long ret_ref = (long)ret_var.inner;
14647         if (ret_var.is_owned) {
14648                 ret_ref |= 1;
14649         }
14650         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
14651         return ret_ref;
14652 }
14653
14654 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelPublicKeys_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
14655         LDKChannelPublicKeys this_ptr_conv;
14656         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14657         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
14658         ChannelPublicKeys_free(this_ptr_conv);
14659 }
14660
14661 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelPublicKeys_1clone(JNIEnv * _env, jclass _b, jlong orig) {
14662         LDKChannelPublicKeys orig_conv;
14663         orig_conv.inner = (void*)(orig & (~1));
14664         orig_conv.is_owned = false;
14665         LDKChannelPublicKeys ret_var = ChannelPublicKeys_clone(&orig_conv);
14666         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14667         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14668         long ret_ref = (long)ret_var.inner;
14669         if (ret_var.is_owned) {
14670                 ret_ref |= 1;
14671         }
14672         return ret_ref;
14673 }
14674
14675 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelPublicKeys_1get_1funding_1pubkey(JNIEnv * _env, jclass _b, jlong this_ptr) {
14676         LDKChannelPublicKeys this_ptr_conv;
14677         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14678         this_ptr_conv.is_owned = false;
14679         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
14680         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, ChannelPublicKeys_get_funding_pubkey(&this_ptr_conv).compressed_form);
14681         return arg_arr;
14682 }
14683
14684 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelPublicKeys_1set_1funding_1pubkey(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
14685         LDKChannelPublicKeys this_ptr_conv;
14686         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14687         this_ptr_conv.is_owned = false;
14688         LDKPublicKey val_ref;
14689         CHECK((*_env)->GetArrayLength (_env, val) == 33);
14690         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
14691         ChannelPublicKeys_set_funding_pubkey(&this_ptr_conv, val_ref);
14692 }
14693
14694 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelPublicKeys_1get_1revocation_1basepoint(JNIEnv * _env, jclass _b, jlong this_ptr) {
14695         LDKChannelPublicKeys this_ptr_conv;
14696         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14697         this_ptr_conv.is_owned = false;
14698         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
14699         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, ChannelPublicKeys_get_revocation_basepoint(&this_ptr_conv).compressed_form);
14700         return arg_arr;
14701 }
14702
14703 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelPublicKeys_1set_1revocation_1basepoint(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
14704         LDKChannelPublicKeys this_ptr_conv;
14705         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14706         this_ptr_conv.is_owned = false;
14707         LDKPublicKey val_ref;
14708         CHECK((*_env)->GetArrayLength (_env, val) == 33);
14709         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
14710         ChannelPublicKeys_set_revocation_basepoint(&this_ptr_conv, val_ref);
14711 }
14712
14713 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelPublicKeys_1get_1payment_1point(JNIEnv * _env, jclass _b, jlong this_ptr) {
14714         LDKChannelPublicKeys this_ptr_conv;
14715         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14716         this_ptr_conv.is_owned = false;
14717         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
14718         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, ChannelPublicKeys_get_payment_point(&this_ptr_conv).compressed_form);
14719         return arg_arr;
14720 }
14721
14722 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelPublicKeys_1set_1payment_1point(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
14723         LDKChannelPublicKeys this_ptr_conv;
14724         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14725         this_ptr_conv.is_owned = false;
14726         LDKPublicKey val_ref;
14727         CHECK((*_env)->GetArrayLength (_env, val) == 33);
14728         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
14729         ChannelPublicKeys_set_payment_point(&this_ptr_conv, val_ref);
14730 }
14731
14732 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelPublicKeys_1get_1delayed_1payment_1basepoint(JNIEnv * _env, jclass _b, jlong this_ptr) {
14733         LDKChannelPublicKeys this_ptr_conv;
14734         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14735         this_ptr_conv.is_owned = false;
14736         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
14737         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, ChannelPublicKeys_get_delayed_payment_basepoint(&this_ptr_conv).compressed_form);
14738         return arg_arr;
14739 }
14740
14741 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelPublicKeys_1set_1delayed_1payment_1basepoint(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
14742         LDKChannelPublicKeys this_ptr_conv;
14743         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14744         this_ptr_conv.is_owned = false;
14745         LDKPublicKey val_ref;
14746         CHECK((*_env)->GetArrayLength (_env, val) == 33);
14747         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
14748         ChannelPublicKeys_set_delayed_payment_basepoint(&this_ptr_conv, val_ref);
14749 }
14750
14751 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelPublicKeys_1get_1htlc_1basepoint(JNIEnv * _env, jclass _b, jlong this_ptr) {
14752         LDKChannelPublicKeys this_ptr_conv;
14753         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14754         this_ptr_conv.is_owned = false;
14755         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
14756         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, ChannelPublicKeys_get_htlc_basepoint(&this_ptr_conv).compressed_form);
14757         return arg_arr;
14758 }
14759
14760 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelPublicKeys_1set_1htlc_1basepoint(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
14761         LDKChannelPublicKeys this_ptr_conv;
14762         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14763         this_ptr_conv.is_owned = false;
14764         LDKPublicKey val_ref;
14765         CHECK((*_env)->GetArrayLength (_env, val) == 33);
14766         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
14767         ChannelPublicKeys_set_htlc_basepoint(&this_ptr_conv, val_ref);
14768 }
14769
14770 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelPublicKeys_1new(JNIEnv * _env, jclass _b, jbyteArray funding_pubkey_arg, jbyteArray revocation_basepoint_arg, jbyteArray payment_point_arg, jbyteArray delayed_payment_basepoint_arg, jbyteArray htlc_basepoint_arg) {
14771         LDKPublicKey funding_pubkey_arg_ref;
14772         CHECK((*_env)->GetArrayLength (_env, funding_pubkey_arg) == 33);
14773         (*_env)->GetByteArrayRegion (_env, funding_pubkey_arg, 0, 33, funding_pubkey_arg_ref.compressed_form);
14774         LDKPublicKey revocation_basepoint_arg_ref;
14775         CHECK((*_env)->GetArrayLength (_env, revocation_basepoint_arg) == 33);
14776         (*_env)->GetByteArrayRegion (_env, revocation_basepoint_arg, 0, 33, revocation_basepoint_arg_ref.compressed_form);
14777         LDKPublicKey payment_point_arg_ref;
14778         CHECK((*_env)->GetArrayLength (_env, payment_point_arg) == 33);
14779         (*_env)->GetByteArrayRegion (_env, payment_point_arg, 0, 33, payment_point_arg_ref.compressed_form);
14780         LDKPublicKey delayed_payment_basepoint_arg_ref;
14781         CHECK((*_env)->GetArrayLength (_env, delayed_payment_basepoint_arg) == 33);
14782         (*_env)->GetByteArrayRegion (_env, delayed_payment_basepoint_arg, 0, 33, delayed_payment_basepoint_arg_ref.compressed_form);
14783         LDKPublicKey htlc_basepoint_arg_ref;
14784         CHECK((*_env)->GetArrayLength (_env, htlc_basepoint_arg) == 33);
14785         (*_env)->GetByteArrayRegion (_env, htlc_basepoint_arg, 0, 33, htlc_basepoint_arg_ref.compressed_form);
14786         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);
14787         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14788         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14789         long ret_ref = (long)ret_var.inner;
14790         if (ret_var.is_owned) {
14791                 ret_ref |= 1;
14792         }
14793         return ret_ref;
14794 }
14795
14796 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelPublicKeys_1write(JNIEnv * _env, jclass _b, jlong obj) {
14797         LDKChannelPublicKeys obj_conv;
14798         obj_conv.inner = (void*)(obj & (~1));
14799         obj_conv.is_owned = false;
14800         LDKCVec_u8Z arg_var = ChannelPublicKeys_write(&obj_conv);
14801         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
14802         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
14803         CVec_u8Z_free(arg_var);
14804         return arg_arr;
14805 }
14806
14807 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelPublicKeys_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
14808         LDKu8slice ser_ref;
14809         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
14810         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
14811         LDKChannelPublicKeys ret_var = ChannelPublicKeys_read(ser_ref);
14812         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14813         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14814         long ret_ref = (long)ret_var.inner;
14815         if (ret_var.is_owned) {
14816                 ret_ref |= 1;
14817         }
14818         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
14819         return ret_ref;
14820 }
14821
14822 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_TxCreationKeys_1derive_1new(JNIEnv * _env, jclass _b, jbyteArray per_commitment_point, jbyteArray broadcaster_delayed_payment_base, jbyteArray broadcaster_htlc_base, jbyteArray countersignatory_revocation_base, jbyteArray countersignatory_htlc_base) {
14823         LDKPublicKey per_commitment_point_ref;
14824         CHECK((*_env)->GetArrayLength (_env, per_commitment_point) == 33);
14825         (*_env)->GetByteArrayRegion (_env, per_commitment_point, 0, 33, per_commitment_point_ref.compressed_form);
14826         LDKPublicKey broadcaster_delayed_payment_base_ref;
14827         CHECK((*_env)->GetArrayLength (_env, broadcaster_delayed_payment_base) == 33);
14828         (*_env)->GetByteArrayRegion (_env, broadcaster_delayed_payment_base, 0, 33, broadcaster_delayed_payment_base_ref.compressed_form);
14829         LDKPublicKey broadcaster_htlc_base_ref;
14830         CHECK((*_env)->GetArrayLength (_env, broadcaster_htlc_base) == 33);
14831         (*_env)->GetByteArrayRegion (_env, broadcaster_htlc_base, 0, 33, broadcaster_htlc_base_ref.compressed_form);
14832         LDKPublicKey countersignatory_revocation_base_ref;
14833         CHECK((*_env)->GetArrayLength (_env, countersignatory_revocation_base) == 33);
14834         (*_env)->GetByteArrayRegion (_env, countersignatory_revocation_base, 0, 33, countersignatory_revocation_base_ref.compressed_form);
14835         LDKPublicKey countersignatory_htlc_base_ref;
14836         CHECK((*_env)->GetArrayLength (_env, countersignatory_htlc_base) == 33);
14837         (*_env)->GetByteArrayRegion (_env, countersignatory_htlc_base, 0, 33, countersignatory_htlc_base_ref.compressed_form);
14838         LDKCResult_TxCreationKeysSecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_TxCreationKeysSecpErrorZ), "LDKCResult_TxCreationKeysSecpErrorZ");
14839         *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);
14840         return (long)ret_conv;
14841 }
14842
14843 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_TxCreationKeys_1from_1channel_1static_1keys(JNIEnv * _env, jclass _b, jbyteArray per_commitment_point, jlong broadcaster_keys, jlong countersignatory_keys) {
14844         LDKPublicKey per_commitment_point_ref;
14845         CHECK((*_env)->GetArrayLength (_env, per_commitment_point) == 33);
14846         (*_env)->GetByteArrayRegion (_env, per_commitment_point, 0, 33, per_commitment_point_ref.compressed_form);
14847         LDKChannelPublicKeys broadcaster_keys_conv;
14848         broadcaster_keys_conv.inner = (void*)(broadcaster_keys & (~1));
14849         broadcaster_keys_conv.is_owned = false;
14850         LDKChannelPublicKeys countersignatory_keys_conv;
14851         countersignatory_keys_conv.inner = (void*)(countersignatory_keys & (~1));
14852         countersignatory_keys_conv.is_owned = false;
14853         LDKCResult_TxCreationKeysSecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_TxCreationKeysSecpErrorZ), "LDKCResult_TxCreationKeysSecpErrorZ");
14854         *ret_conv = TxCreationKeys_from_channel_static_keys(per_commitment_point_ref, &broadcaster_keys_conv, &countersignatory_keys_conv);
14855         return (long)ret_conv;
14856 }
14857
14858 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_get_1revokeable_1redeemscript(JNIEnv * _env, jclass _b, jbyteArray revocation_key, jshort contest_delay, jbyteArray broadcaster_delayed_payment_key) {
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         LDKPublicKey broadcaster_delayed_payment_key_ref;
14863         CHECK((*_env)->GetArrayLength (_env, broadcaster_delayed_payment_key) == 33);
14864         (*_env)->GetByteArrayRegion (_env, broadcaster_delayed_payment_key, 0, 33, broadcaster_delayed_payment_key_ref.compressed_form);
14865         LDKCVec_u8Z arg_var = get_revokeable_redeemscript(revocation_key_ref, contest_delay, broadcaster_delayed_payment_key_ref);
14866         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
14867         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
14868         CVec_u8Z_free(arg_var);
14869         return arg_arr;
14870 }
14871
14872 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_HTLCOutputInCommitment_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
14873         LDKHTLCOutputInCommitment this_ptr_conv;
14874         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14875         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
14876         HTLCOutputInCommitment_free(this_ptr_conv);
14877 }
14878
14879 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_HTLCOutputInCommitment_1clone(JNIEnv * _env, jclass _b, jlong orig) {
14880         LDKHTLCOutputInCommitment orig_conv;
14881         orig_conv.inner = (void*)(orig & (~1));
14882         orig_conv.is_owned = false;
14883         LDKHTLCOutputInCommitment ret_var = HTLCOutputInCommitment_clone(&orig_conv);
14884         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14885         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14886         long ret_ref = (long)ret_var.inner;
14887         if (ret_var.is_owned) {
14888                 ret_ref |= 1;
14889         }
14890         return ret_ref;
14891 }
14892
14893 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_HTLCOutputInCommitment_1get_1offered(JNIEnv * _env, jclass _b, jlong this_ptr) {
14894         LDKHTLCOutputInCommitment this_ptr_conv;
14895         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14896         this_ptr_conv.is_owned = false;
14897         jboolean ret_val = HTLCOutputInCommitment_get_offered(&this_ptr_conv);
14898         return ret_val;
14899 }
14900
14901 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_HTLCOutputInCommitment_1set_1offered(JNIEnv * _env, jclass _b, jlong this_ptr, jboolean val) {
14902         LDKHTLCOutputInCommitment this_ptr_conv;
14903         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14904         this_ptr_conv.is_owned = false;
14905         HTLCOutputInCommitment_set_offered(&this_ptr_conv, val);
14906 }
14907
14908 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_HTLCOutputInCommitment_1get_1amount_1msat(JNIEnv * _env, jclass _b, jlong this_ptr) {
14909         LDKHTLCOutputInCommitment this_ptr_conv;
14910         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14911         this_ptr_conv.is_owned = false;
14912         jlong ret_val = HTLCOutputInCommitment_get_amount_msat(&this_ptr_conv);
14913         return ret_val;
14914 }
14915
14916 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_HTLCOutputInCommitment_1set_1amount_1msat(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
14917         LDKHTLCOutputInCommitment this_ptr_conv;
14918         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14919         this_ptr_conv.is_owned = false;
14920         HTLCOutputInCommitment_set_amount_msat(&this_ptr_conv, val);
14921 }
14922
14923 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_HTLCOutputInCommitment_1get_1cltv_1expiry(JNIEnv * _env, jclass _b, jlong this_ptr) {
14924         LDKHTLCOutputInCommitment this_ptr_conv;
14925         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14926         this_ptr_conv.is_owned = false;
14927         jint ret_val = HTLCOutputInCommitment_get_cltv_expiry(&this_ptr_conv);
14928         return ret_val;
14929 }
14930
14931 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_HTLCOutputInCommitment_1set_1cltv_1expiry(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
14932         LDKHTLCOutputInCommitment this_ptr_conv;
14933         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14934         this_ptr_conv.is_owned = false;
14935         HTLCOutputInCommitment_set_cltv_expiry(&this_ptr_conv, val);
14936 }
14937
14938 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_HTLCOutputInCommitment_1get_1payment_1hash(JNIEnv * _env, jclass _b, jlong this_ptr) {
14939         LDKHTLCOutputInCommitment this_ptr_conv;
14940         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14941         this_ptr_conv.is_owned = false;
14942         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
14943         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *HTLCOutputInCommitment_get_payment_hash(&this_ptr_conv));
14944         return ret_arr;
14945 }
14946
14947 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_HTLCOutputInCommitment_1set_1payment_1hash(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
14948         LDKHTLCOutputInCommitment this_ptr_conv;
14949         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14950         this_ptr_conv.is_owned = false;
14951         LDKThirtyTwoBytes val_ref;
14952         CHECK((*_env)->GetArrayLength (_env, val) == 32);
14953         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
14954         HTLCOutputInCommitment_set_payment_hash(&this_ptr_conv, val_ref);
14955 }
14956
14957 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_HTLCOutputInCommitment_1write(JNIEnv * _env, jclass _b, jlong obj) {
14958         LDKHTLCOutputInCommitment obj_conv;
14959         obj_conv.inner = (void*)(obj & (~1));
14960         obj_conv.is_owned = false;
14961         LDKCVec_u8Z arg_var = HTLCOutputInCommitment_write(&obj_conv);
14962         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
14963         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
14964         CVec_u8Z_free(arg_var);
14965         return arg_arr;
14966 }
14967
14968 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_HTLCOutputInCommitment_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
14969         LDKu8slice ser_ref;
14970         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
14971         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
14972         LDKHTLCOutputInCommitment ret_var = HTLCOutputInCommitment_read(ser_ref);
14973         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14974         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14975         long ret_ref = (long)ret_var.inner;
14976         if (ret_var.is_owned) {
14977                 ret_ref |= 1;
14978         }
14979         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
14980         return ret_ref;
14981 }
14982
14983 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_get_1htlc_1redeemscript(JNIEnv * _env, jclass _b, jlong htlc, jlong keys) {
14984         LDKHTLCOutputInCommitment htlc_conv;
14985         htlc_conv.inner = (void*)(htlc & (~1));
14986         htlc_conv.is_owned = false;
14987         LDKTxCreationKeys keys_conv;
14988         keys_conv.inner = (void*)(keys & (~1));
14989         keys_conv.is_owned = false;
14990         LDKCVec_u8Z arg_var = get_htlc_redeemscript(&htlc_conv, &keys_conv);
14991         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
14992         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
14993         CVec_u8Z_free(arg_var);
14994         return arg_arr;
14995 }
14996
14997 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_make_1funding_1redeemscript(JNIEnv * _env, jclass _b, jbyteArray broadcaster, jbyteArray countersignatory) {
14998         LDKPublicKey broadcaster_ref;
14999         CHECK((*_env)->GetArrayLength (_env, broadcaster) == 33);
15000         (*_env)->GetByteArrayRegion (_env, broadcaster, 0, 33, broadcaster_ref.compressed_form);
15001         LDKPublicKey countersignatory_ref;
15002         CHECK((*_env)->GetArrayLength (_env, countersignatory) == 33);
15003         (*_env)->GetByteArrayRegion (_env, countersignatory, 0, 33, countersignatory_ref.compressed_form);
15004         LDKCVec_u8Z arg_var = make_funding_redeemscript(broadcaster_ref, countersignatory_ref);
15005         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
15006         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
15007         CVec_u8Z_free(arg_var);
15008         return arg_arr;
15009 }
15010
15011 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_build_1htlc_1transaction(JNIEnv * _env, jclass _b, jbyteArray prev_hash, jint feerate_per_kw, jshort contest_delay, jlong htlc, jbyteArray broadcaster_delayed_payment_key, jbyteArray revocation_key) {
15012         unsigned char prev_hash_arr[32];
15013         CHECK((*_env)->GetArrayLength (_env, prev_hash) == 32);
15014         (*_env)->GetByteArrayRegion (_env, prev_hash, 0, 32, prev_hash_arr);
15015         unsigned char (*prev_hash_ref)[32] = &prev_hash_arr;
15016         LDKHTLCOutputInCommitment htlc_conv;
15017         htlc_conv.inner = (void*)(htlc & (~1));
15018         htlc_conv.is_owned = false;
15019         LDKPublicKey broadcaster_delayed_payment_key_ref;
15020         CHECK((*_env)->GetArrayLength (_env, broadcaster_delayed_payment_key) == 33);
15021         (*_env)->GetByteArrayRegion (_env, broadcaster_delayed_payment_key, 0, 33, broadcaster_delayed_payment_key_ref.compressed_form);
15022         LDKPublicKey revocation_key_ref;
15023         CHECK((*_env)->GetArrayLength (_env, revocation_key) == 33);
15024         (*_env)->GetByteArrayRegion (_env, revocation_key, 0, 33, revocation_key_ref.compressed_form);
15025         LDKTransaction arg_var = build_htlc_transaction(prev_hash_ref, feerate_per_kw, contest_delay, &htlc_conv, broadcaster_delayed_payment_key_ref, revocation_key_ref);
15026         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
15027         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
15028         Transaction_free(arg_var);
15029         return arg_arr;
15030 }
15031
15032 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelTransactionParameters_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
15033         LDKChannelTransactionParameters this_ptr_conv;
15034         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15035         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
15036         ChannelTransactionParameters_free(this_ptr_conv);
15037 }
15038
15039 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelTransactionParameters_1clone(JNIEnv * _env, jclass _b, jlong orig) {
15040         LDKChannelTransactionParameters orig_conv;
15041         orig_conv.inner = (void*)(orig & (~1));
15042         orig_conv.is_owned = false;
15043         LDKChannelTransactionParameters ret_var = ChannelTransactionParameters_clone(&orig_conv);
15044         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15045         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15046         long ret_ref = (long)ret_var.inner;
15047         if (ret_var.is_owned) {
15048                 ret_ref |= 1;
15049         }
15050         return ret_ref;
15051 }
15052
15053 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelTransactionParameters_1get_1holder_1pubkeys(JNIEnv * _env, jclass _b, jlong this_ptr) {
15054         LDKChannelTransactionParameters this_ptr_conv;
15055         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15056         this_ptr_conv.is_owned = false;
15057         LDKChannelPublicKeys ret_var = ChannelTransactionParameters_get_holder_pubkeys(&this_ptr_conv);
15058         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15059         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15060         long ret_ref = (long)ret_var.inner;
15061         if (ret_var.is_owned) {
15062                 ret_ref |= 1;
15063         }
15064         return ret_ref;
15065 }
15066
15067 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelTransactionParameters_1set_1holder_1pubkeys(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
15068         LDKChannelTransactionParameters this_ptr_conv;
15069         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15070         this_ptr_conv.is_owned = false;
15071         LDKChannelPublicKeys val_conv;
15072         val_conv.inner = (void*)(val & (~1));
15073         val_conv.is_owned = (val & 1) || (val == 0);
15074         if (val_conv.inner != NULL)
15075                 val_conv = ChannelPublicKeys_clone(&val_conv);
15076         ChannelTransactionParameters_set_holder_pubkeys(&this_ptr_conv, val_conv);
15077 }
15078
15079 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_ChannelTransactionParameters_1get_1holder_1selected_1contest_1delay(JNIEnv * _env, jclass _b, jlong this_ptr) {
15080         LDKChannelTransactionParameters this_ptr_conv;
15081         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15082         this_ptr_conv.is_owned = false;
15083         jshort ret_val = ChannelTransactionParameters_get_holder_selected_contest_delay(&this_ptr_conv);
15084         return ret_val;
15085 }
15086
15087 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelTransactionParameters_1set_1holder_1selected_1contest_1delay(JNIEnv * _env, jclass _b, jlong this_ptr, jshort val) {
15088         LDKChannelTransactionParameters this_ptr_conv;
15089         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15090         this_ptr_conv.is_owned = false;
15091         ChannelTransactionParameters_set_holder_selected_contest_delay(&this_ptr_conv, val);
15092 }
15093
15094 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_ChannelTransactionParameters_1get_1is_1outbound_1from_1holder(JNIEnv * _env, jclass _b, jlong this_ptr) {
15095         LDKChannelTransactionParameters this_ptr_conv;
15096         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15097         this_ptr_conv.is_owned = false;
15098         jboolean ret_val = ChannelTransactionParameters_get_is_outbound_from_holder(&this_ptr_conv);
15099         return ret_val;
15100 }
15101
15102 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelTransactionParameters_1set_1is_1outbound_1from_1holder(JNIEnv * _env, jclass _b, jlong this_ptr, jboolean val) {
15103         LDKChannelTransactionParameters this_ptr_conv;
15104         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15105         this_ptr_conv.is_owned = false;
15106         ChannelTransactionParameters_set_is_outbound_from_holder(&this_ptr_conv, val);
15107 }
15108
15109 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelTransactionParameters_1get_1counterparty_1parameters(JNIEnv * _env, jclass _b, jlong this_ptr) {
15110         LDKChannelTransactionParameters this_ptr_conv;
15111         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15112         this_ptr_conv.is_owned = false;
15113         LDKCounterpartyChannelTransactionParameters ret_var = ChannelTransactionParameters_get_counterparty_parameters(&this_ptr_conv);
15114         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15115         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15116         long ret_ref = (long)ret_var.inner;
15117         if (ret_var.is_owned) {
15118                 ret_ref |= 1;
15119         }
15120         return ret_ref;
15121 }
15122
15123 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelTransactionParameters_1set_1counterparty_1parameters(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
15124         LDKChannelTransactionParameters this_ptr_conv;
15125         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15126         this_ptr_conv.is_owned = false;
15127         LDKCounterpartyChannelTransactionParameters val_conv;
15128         val_conv.inner = (void*)(val & (~1));
15129         val_conv.is_owned = (val & 1) || (val == 0);
15130         if (val_conv.inner != NULL)
15131                 val_conv = CounterpartyChannelTransactionParameters_clone(&val_conv);
15132         ChannelTransactionParameters_set_counterparty_parameters(&this_ptr_conv, val_conv);
15133 }
15134
15135 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelTransactionParameters_1get_1funding_1outpoint(JNIEnv * _env, jclass _b, jlong this_ptr) {
15136         LDKChannelTransactionParameters this_ptr_conv;
15137         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15138         this_ptr_conv.is_owned = false;
15139         LDKOutPoint ret_var = ChannelTransactionParameters_get_funding_outpoint(&this_ptr_conv);
15140         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15141         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15142         long ret_ref = (long)ret_var.inner;
15143         if (ret_var.is_owned) {
15144                 ret_ref |= 1;
15145         }
15146         return ret_ref;
15147 }
15148
15149 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelTransactionParameters_1set_1funding_1outpoint(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
15150         LDKChannelTransactionParameters this_ptr_conv;
15151         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15152         this_ptr_conv.is_owned = false;
15153         LDKOutPoint val_conv;
15154         val_conv.inner = (void*)(val & (~1));
15155         val_conv.is_owned = (val & 1) || (val == 0);
15156         if (val_conv.inner != NULL)
15157                 val_conv = OutPoint_clone(&val_conv);
15158         ChannelTransactionParameters_set_funding_outpoint(&this_ptr_conv, val_conv);
15159 }
15160
15161 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelTransactionParameters_1new(JNIEnv * _env, jclass _b, jlong holder_pubkeys_arg, jshort holder_selected_contest_delay_arg, jboolean is_outbound_from_holder_arg, jlong counterparty_parameters_arg, jlong funding_outpoint_arg) {
15162         LDKChannelPublicKeys holder_pubkeys_arg_conv;
15163         holder_pubkeys_arg_conv.inner = (void*)(holder_pubkeys_arg & (~1));
15164         holder_pubkeys_arg_conv.is_owned = (holder_pubkeys_arg & 1) || (holder_pubkeys_arg == 0);
15165         if (holder_pubkeys_arg_conv.inner != NULL)
15166                 holder_pubkeys_arg_conv = ChannelPublicKeys_clone(&holder_pubkeys_arg_conv);
15167         LDKCounterpartyChannelTransactionParameters counterparty_parameters_arg_conv;
15168         counterparty_parameters_arg_conv.inner = (void*)(counterparty_parameters_arg & (~1));
15169         counterparty_parameters_arg_conv.is_owned = (counterparty_parameters_arg & 1) || (counterparty_parameters_arg == 0);
15170         if (counterparty_parameters_arg_conv.inner != NULL)
15171                 counterparty_parameters_arg_conv = CounterpartyChannelTransactionParameters_clone(&counterparty_parameters_arg_conv);
15172         LDKOutPoint funding_outpoint_arg_conv;
15173         funding_outpoint_arg_conv.inner = (void*)(funding_outpoint_arg & (~1));
15174         funding_outpoint_arg_conv.is_owned = (funding_outpoint_arg & 1) || (funding_outpoint_arg == 0);
15175         if (funding_outpoint_arg_conv.inner != NULL)
15176                 funding_outpoint_arg_conv = OutPoint_clone(&funding_outpoint_arg_conv);
15177         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);
15178         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15179         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15180         long ret_ref = (long)ret_var.inner;
15181         if (ret_var.is_owned) {
15182                 ret_ref |= 1;
15183         }
15184         return ret_ref;
15185 }
15186
15187 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CounterpartyChannelTransactionParameters_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
15188         LDKCounterpartyChannelTransactionParameters this_ptr_conv;
15189         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15190         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
15191         CounterpartyChannelTransactionParameters_free(this_ptr_conv);
15192 }
15193
15194 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CounterpartyChannelTransactionParameters_1clone(JNIEnv * _env, jclass _b, jlong orig) {
15195         LDKCounterpartyChannelTransactionParameters orig_conv;
15196         orig_conv.inner = (void*)(orig & (~1));
15197         orig_conv.is_owned = false;
15198         LDKCounterpartyChannelTransactionParameters ret_var = CounterpartyChannelTransactionParameters_clone(&orig_conv);
15199         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15200         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15201         long ret_ref = (long)ret_var.inner;
15202         if (ret_var.is_owned) {
15203                 ret_ref |= 1;
15204         }
15205         return ret_ref;
15206 }
15207
15208 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CounterpartyChannelTransactionParameters_1get_1pubkeys(JNIEnv * _env, jclass _b, jlong this_ptr) {
15209         LDKCounterpartyChannelTransactionParameters this_ptr_conv;
15210         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15211         this_ptr_conv.is_owned = false;
15212         LDKChannelPublicKeys ret_var = CounterpartyChannelTransactionParameters_get_pubkeys(&this_ptr_conv);
15213         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15214         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15215         long ret_ref = (long)ret_var.inner;
15216         if (ret_var.is_owned) {
15217                 ret_ref |= 1;
15218         }
15219         return ret_ref;
15220 }
15221
15222 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CounterpartyChannelTransactionParameters_1set_1pubkeys(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
15223         LDKCounterpartyChannelTransactionParameters this_ptr_conv;
15224         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15225         this_ptr_conv.is_owned = false;
15226         LDKChannelPublicKeys val_conv;
15227         val_conv.inner = (void*)(val & (~1));
15228         val_conv.is_owned = (val & 1) || (val == 0);
15229         if (val_conv.inner != NULL)
15230                 val_conv = ChannelPublicKeys_clone(&val_conv);
15231         CounterpartyChannelTransactionParameters_set_pubkeys(&this_ptr_conv, val_conv);
15232 }
15233
15234 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_CounterpartyChannelTransactionParameters_1get_1selected_1contest_1delay(JNIEnv * _env, jclass _b, jlong this_ptr) {
15235         LDKCounterpartyChannelTransactionParameters this_ptr_conv;
15236         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15237         this_ptr_conv.is_owned = false;
15238         jshort ret_val = CounterpartyChannelTransactionParameters_get_selected_contest_delay(&this_ptr_conv);
15239         return ret_val;
15240 }
15241
15242 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CounterpartyChannelTransactionParameters_1set_1selected_1contest_1delay(JNIEnv * _env, jclass _b, jlong this_ptr, jshort val) {
15243         LDKCounterpartyChannelTransactionParameters this_ptr_conv;
15244         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15245         this_ptr_conv.is_owned = false;
15246         CounterpartyChannelTransactionParameters_set_selected_contest_delay(&this_ptr_conv, val);
15247 }
15248
15249 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CounterpartyChannelTransactionParameters_1new(JNIEnv * _env, jclass _b, jlong pubkeys_arg, jshort selected_contest_delay_arg) {
15250         LDKChannelPublicKeys pubkeys_arg_conv;
15251         pubkeys_arg_conv.inner = (void*)(pubkeys_arg & (~1));
15252         pubkeys_arg_conv.is_owned = (pubkeys_arg & 1) || (pubkeys_arg == 0);
15253         if (pubkeys_arg_conv.inner != NULL)
15254                 pubkeys_arg_conv = ChannelPublicKeys_clone(&pubkeys_arg_conv);
15255         LDKCounterpartyChannelTransactionParameters ret_var = CounterpartyChannelTransactionParameters_new(pubkeys_arg_conv, selected_contest_delay_arg);
15256         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15257         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15258         long ret_ref = (long)ret_var.inner;
15259         if (ret_var.is_owned) {
15260                 ret_ref |= 1;
15261         }
15262         return ret_ref;
15263 }
15264
15265 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_ChannelTransactionParameters_1is_1populated(JNIEnv * _env, jclass _b, jlong this_arg) {
15266         LDKChannelTransactionParameters this_arg_conv;
15267         this_arg_conv.inner = (void*)(this_arg & (~1));
15268         this_arg_conv.is_owned = false;
15269         jboolean ret_val = ChannelTransactionParameters_is_populated(&this_arg_conv);
15270         return ret_val;
15271 }
15272
15273 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelTransactionParameters_1as_1holder_1broadcastable(JNIEnv * _env, jclass _b, jlong this_arg) {
15274         LDKChannelTransactionParameters this_arg_conv;
15275         this_arg_conv.inner = (void*)(this_arg & (~1));
15276         this_arg_conv.is_owned = false;
15277         LDKDirectedChannelTransactionParameters ret_var = ChannelTransactionParameters_as_holder_broadcastable(&this_arg_conv);
15278         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15279         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15280         long ret_ref = (long)ret_var.inner;
15281         if (ret_var.is_owned) {
15282                 ret_ref |= 1;
15283         }
15284         return ret_ref;
15285 }
15286
15287 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelTransactionParameters_1as_1counterparty_1broadcastable(JNIEnv * _env, jclass _b, jlong this_arg) {
15288         LDKChannelTransactionParameters this_arg_conv;
15289         this_arg_conv.inner = (void*)(this_arg & (~1));
15290         this_arg_conv.is_owned = false;
15291         LDKDirectedChannelTransactionParameters ret_var = ChannelTransactionParameters_as_counterparty_broadcastable(&this_arg_conv);
15292         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15293         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15294         long ret_ref = (long)ret_var.inner;
15295         if (ret_var.is_owned) {
15296                 ret_ref |= 1;
15297         }
15298         return ret_ref;
15299 }
15300
15301 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_CounterpartyChannelTransactionParameters_1write(JNIEnv * _env, jclass _b, jlong obj) {
15302         LDKCounterpartyChannelTransactionParameters obj_conv;
15303         obj_conv.inner = (void*)(obj & (~1));
15304         obj_conv.is_owned = false;
15305         LDKCVec_u8Z arg_var = CounterpartyChannelTransactionParameters_write(&obj_conv);
15306         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
15307         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
15308         CVec_u8Z_free(arg_var);
15309         return arg_arr;
15310 }
15311
15312 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CounterpartyChannelTransactionParameters_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
15313         LDKu8slice ser_ref;
15314         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
15315         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
15316         LDKCounterpartyChannelTransactionParameters ret_var = CounterpartyChannelTransactionParameters_read(ser_ref);
15317         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15318         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15319         long ret_ref = (long)ret_var.inner;
15320         if (ret_var.is_owned) {
15321                 ret_ref |= 1;
15322         }
15323         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
15324         return ret_ref;
15325 }
15326
15327 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelTransactionParameters_1write(JNIEnv * _env, jclass _b, jlong obj) {
15328         LDKChannelTransactionParameters obj_conv;
15329         obj_conv.inner = (void*)(obj & (~1));
15330         obj_conv.is_owned = false;
15331         LDKCVec_u8Z arg_var = ChannelTransactionParameters_write(&obj_conv);
15332         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
15333         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
15334         CVec_u8Z_free(arg_var);
15335         return arg_arr;
15336 }
15337
15338 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelTransactionParameters_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
15339         LDKu8slice ser_ref;
15340         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
15341         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
15342         LDKChannelTransactionParameters ret_var = ChannelTransactionParameters_read(ser_ref);
15343         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15344         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15345         long ret_ref = (long)ret_var.inner;
15346         if (ret_var.is_owned) {
15347                 ret_ref |= 1;
15348         }
15349         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
15350         return ret_ref;
15351 }
15352
15353 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_DirectedChannelTransactionParameters_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
15354         LDKDirectedChannelTransactionParameters this_ptr_conv;
15355         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15356         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
15357         DirectedChannelTransactionParameters_free(this_ptr_conv);
15358 }
15359
15360 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_DirectedChannelTransactionParameters_1broadcaster_1pubkeys(JNIEnv * _env, jclass _b, jlong this_arg) {
15361         LDKDirectedChannelTransactionParameters this_arg_conv;
15362         this_arg_conv.inner = (void*)(this_arg & (~1));
15363         this_arg_conv.is_owned = false;
15364         LDKChannelPublicKeys ret_var = DirectedChannelTransactionParameters_broadcaster_pubkeys(&this_arg_conv);
15365         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15366         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15367         long ret_ref = (long)ret_var.inner;
15368         if (ret_var.is_owned) {
15369                 ret_ref |= 1;
15370         }
15371         return ret_ref;
15372 }
15373
15374 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_DirectedChannelTransactionParameters_1countersignatory_1pubkeys(JNIEnv * _env, jclass _b, jlong this_arg) {
15375         LDKDirectedChannelTransactionParameters this_arg_conv;
15376         this_arg_conv.inner = (void*)(this_arg & (~1));
15377         this_arg_conv.is_owned = false;
15378         LDKChannelPublicKeys ret_var = DirectedChannelTransactionParameters_countersignatory_pubkeys(&this_arg_conv);
15379         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15380         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15381         long ret_ref = (long)ret_var.inner;
15382         if (ret_var.is_owned) {
15383                 ret_ref |= 1;
15384         }
15385         return ret_ref;
15386 }
15387
15388 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_DirectedChannelTransactionParameters_1contest_1delay(JNIEnv * _env, jclass _b, jlong this_arg) {
15389         LDKDirectedChannelTransactionParameters this_arg_conv;
15390         this_arg_conv.inner = (void*)(this_arg & (~1));
15391         this_arg_conv.is_owned = false;
15392         jshort ret_val = DirectedChannelTransactionParameters_contest_delay(&this_arg_conv);
15393         return ret_val;
15394 }
15395
15396 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_DirectedChannelTransactionParameters_1is_1outbound(JNIEnv * _env, jclass _b, jlong this_arg) {
15397         LDKDirectedChannelTransactionParameters this_arg_conv;
15398         this_arg_conv.inner = (void*)(this_arg & (~1));
15399         this_arg_conv.is_owned = false;
15400         jboolean ret_val = DirectedChannelTransactionParameters_is_outbound(&this_arg_conv);
15401         return ret_val;
15402 }
15403
15404 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_DirectedChannelTransactionParameters_1funding_1outpoint(JNIEnv * _env, jclass _b, jlong this_arg) {
15405         LDKDirectedChannelTransactionParameters this_arg_conv;
15406         this_arg_conv.inner = (void*)(this_arg & (~1));
15407         this_arg_conv.is_owned = false;
15408         LDKOutPoint ret_var = DirectedChannelTransactionParameters_funding_outpoint(&this_arg_conv);
15409         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15410         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15411         long ret_ref = (long)ret_var.inner;
15412         if (ret_var.is_owned) {
15413                 ret_ref |= 1;
15414         }
15415         return ret_ref;
15416 }
15417
15418 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_HolderCommitmentTransaction_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
15419         LDKHolderCommitmentTransaction this_ptr_conv;
15420         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15421         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
15422         HolderCommitmentTransaction_free(this_ptr_conv);
15423 }
15424
15425 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_HolderCommitmentTransaction_1clone(JNIEnv * _env, jclass _b, jlong orig) {
15426         LDKHolderCommitmentTransaction orig_conv;
15427         orig_conv.inner = (void*)(orig & (~1));
15428         orig_conv.is_owned = false;
15429         LDKHolderCommitmentTransaction ret_var = HolderCommitmentTransaction_clone(&orig_conv);
15430         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15431         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15432         long ret_ref = (long)ret_var.inner;
15433         if (ret_var.is_owned) {
15434                 ret_ref |= 1;
15435         }
15436         return ret_ref;
15437 }
15438
15439 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_HolderCommitmentTransaction_1get_1counterparty_1sig(JNIEnv * _env, jclass _b, jlong this_ptr) {
15440         LDKHolderCommitmentTransaction this_ptr_conv;
15441         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15442         this_ptr_conv.is_owned = false;
15443         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 64);
15444         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 64, HolderCommitmentTransaction_get_counterparty_sig(&this_ptr_conv).compact_form);
15445         return arg_arr;
15446 }
15447
15448 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_HolderCommitmentTransaction_1set_1counterparty_1sig(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
15449         LDKHolderCommitmentTransaction this_ptr_conv;
15450         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15451         this_ptr_conv.is_owned = false;
15452         LDKSignature val_ref;
15453         CHECK((*_env)->GetArrayLength (_env, val) == 64);
15454         (*_env)->GetByteArrayRegion (_env, val, 0, 64, val_ref.compact_form);
15455         HolderCommitmentTransaction_set_counterparty_sig(&this_ptr_conv, val_ref);
15456 }
15457
15458 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_HolderCommitmentTransaction_1set_1counterparty_1htlc_1sigs(JNIEnv * _env, jclass _b, jlong this_ptr, jobjectArray val) {
15459         LDKHolderCommitmentTransaction this_ptr_conv;
15460         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15461         this_ptr_conv.is_owned = false;
15462         LDKCVec_SignatureZ val_constr;
15463         val_constr.datalen = (*_env)->GetArrayLength (_env, val);
15464         if (val_constr.datalen > 0)
15465                 val_constr.data = MALLOC(val_constr.datalen * sizeof(LDKSignature), "LDKCVec_SignatureZ Elements");
15466         else
15467                 val_constr.data = NULL;
15468         for (size_t i = 0; i < val_constr.datalen; i++) {
15469                 jobject arr_conv_8 = (*_env)->GetObjectArrayElement(_env, val, i);
15470                 LDKSignature arr_conv_8_ref;
15471                 CHECK((*_env)->GetArrayLength (_env, arr_conv_8) == 64);
15472                 (*_env)->GetByteArrayRegion (_env, arr_conv_8, 0, 64, arr_conv_8_ref.compact_form);
15473                 val_constr.data[i] = arr_conv_8_ref;
15474         }
15475         HolderCommitmentTransaction_set_counterparty_htlc_sigs(&this_ptr_conv, val_constr);
15476 }
15477
15478 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_HolderCommitmentTransaction_1write(JNIEnv * _env, jclass _b, jlong obj) {
15479         LDKHolderCommitmentTransaction obj_conv;
15480         obj_conv.inner = (void*)(obj & (~1));
15481         obj_conv.is_owned = false;
15482         LDKCVec_u8Z arg_var = HolderCommitmentTransaction_write(&obj_conv);
15483         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
15484         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
15485         CVec_u8Z_free(arg_var);
15486         return arg_arr;
15487 }
15488
15489 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_HolderCommitmentTransaction_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
15490         LDKu8slice ser_ref;
15491         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
15492         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
15493         LDKHolderCommitmentTransaction ret_var = HolderCommitmentTransaction_read(ser_ref);
15494         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15495         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15496         long ret_ref = (long)ret_var.inner;
15497         if (ret_var.is_owned) {
15498                 ret_ref |= 1;
15499         }
15500         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
15501         return ret_ref;
15502 }
15503
15504 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_HolderCommitmentTransaction_1new(JNIEnv * _env, jclass _b, jlong commitment_tx, jbyteArray counterparty_sig, jobjectArray counterparty_htlc_sigs, jbyteArray holder_funding_key, jbyteArray counterparty_funding_key) {
15505         LDKCommitmentTransaction commitment_tx_conv;
15506         commitment_tx_conv.inner = (void*)(commitment_tx & (~1));
15507         commitment_tx_conv.is_owned = (commitment_tx & 1) || (commitment_tx == 0);
15508         if (commitment_tx_conv.inner != NULL)
15509                 commitment_tx_conv = CommitmentTransaction_clone(&commitment_tx_conv);
15510         LDKSignature counterparty_sig_ref;
15511         CHECK((*_env)->GetArrayLength (_env, counterparty_sig) == 64);
15512         (*_env)->GetByteArrayRegion (_env, counterparty_sig, 0, 64, counterparty_sig_ref.compact_form);
15513         LDKCVec_SignatureZ counterparty_htlc_sigs_constr;
15514         counterparty_htlc_sigs_constr.datalen = (*_env)->GetArrayLength (_env, counterparty_htlc_sigs);
15515         if (counterparty_htlc_sigs_constr.datalen > 0)
15516                 counterparty_htlc_sigs_constr.data = MALLOC(counterparty_htlc_sigs_constr.datalen * sizeof(LDKSignature), "LDKCVec_SignatureZ Elements");
15517         else
15518                 counterparty_htlc_sigs_constr.data = NULL;
15519         for (size_t i = 0; i < counterparty_htlc_sigs_constr.datalen; i++) {
15520                 jobject arr_conv_8 = (*_env)->GetObjectArrayElement(_env, counterparty_htlc_sigs, i);
15521                 LDKSignature arr_conv_8_ref;
15522                 CHECK((*_env)->GetArrayLength (_env, arr_conv_8) == 64);
15523                 (*_env)->GetByteArrayRegion (_env, arr_conv_8, 0, 64, arr_conv_8_ref.compact_form);
15524                 counterparty_htlc_sigs_constr.data[i] = arr_conv_8_ref;
15525         }
15526         LDKPublicKey holder_funding_key_ref;
15527         CHECK((*_env)->GetArrayLength (_env, holder_funding_key) == 33);
15528         (*_env)->GetByteArrayRegion (_env, holder_funding_key, 0, 33, holder_funding_key_ref.compressed_form);
15529         LDKPublicKey counterparty_funding_key_ref;
15530         CHECK((*_env)->GetArrayLength (_env, counterparty_funding_key) == 33);
15531         (*_env)->GetByteArrayRegion (_env, counterparty_funding_key, 0, 33, counterparty_funding_key_ref.compressed_form);
15532         LDKHolderCommitmentTransaction ret_var = HolderCommitmentTransaction_new(commitment_tx_conv, counterparty_sig_ref, counterparty_htlc_sigs_constr, holder_funding_key_ref, counterparty_funding_key_ref);
15533         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15534         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15535         long ret_ref = (long)ret_var.inner;
15536         if (ret_var.is_owned) {
15537                 ret_ref |= 1;
15538         }
15539         return ret_ref;
15540 }
15541
15542 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_BuiltCommitmentTransaction_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
15543         LDKBuiltCommitmentTransaction this_ptr_conv;
15544         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15545         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
15546         BuiltCommitmentTransaction_free(this_ptr_conv);
15547 }
15548
15549 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_BuiltCommitmentTransaction_1clone(JNIEnv * _env, jclass _b, jlong orig) {
15550         LDKBuiltCommitmentTransaction orig_conv;
15551         orig_conv.inner = (void*)(orig & (~1));
15552         orig_conv.is_owned = false;
15553         LDKBuiltCommitmentTransaction ret_var = BuiltCommitmentTransaction_clone(&orig_conv);
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         return ret_ref;
15561 }
15562
15563 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_BuiltCommitmentTransaction_1get_1transaction(JNIEnv * _env, jclass _b, jlong this_ptr) {
15564         LDKBuiltCommitmentTransaction this_ptr_conv;
15565         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15566         this_ptr_conv.is_owned = false;
15567         LDKTransaction arg_var = BuiltCommitmentTransaction_get_transaction(&this_ptr_conv);
15568         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
15569         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
15570         Transaction_free(arg_var);
15571         return arg_arr;
15572 }
15573
15574 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_BuiltCommitmentTransaction_1set_1transaction(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
15575         LDKBuiltCommitmentTransaction this_ptr_conv;
15576         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15577         this_ptr_conv.is_owned = false;
15578         LDKTransaction val_ref;
15579         val_ref.datalen = (*_env)->GetArrayLength (_env, val);
15580         val_ref.data = MALLOC(val_ref.datalen, "LDKTransaction Bytes");
15581         (*_env)->GetByteArrayRegion(_env, val, 0, val_ref.datalen, val_ref.data);
15582         val_ref.data_is_owned = true;
15583         BuiltCommitmentTransaction_set_transaction(&this_ptr_conv, val_ref);
15584 }
15585
15586 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_BuiltCommitmentTransaction_1get_1txid(JNIEnv * _env, jclass _b, jlong this_ptr) {
15587         LDKBuiltCommitmentTransaction this_ptr_conv;
15588         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15589         this_ptr_conv.is_owned = false;
15590         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
15591         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *BuiltCommitmentTransaction_get_txid(&this_ptr_conv));
15592         return ret_arr;
15593 }
15594
15595 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_BuiltCommitmentTransaction_1set_1txid(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
15596         LDKBuiltCommitmentTransaction this_ptr_conv;
15597         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15598         this_ptr_conv.is_owned = false;
15599         LDKThirtyTwoBytes val_ref;
15600         CHECK((*_env)->GetArrayLength (_env, val) == 32);
15601         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
15602         BuiltCommitmentTransaction_set_txid(&this_ptr_conv, val_ref);
15603 }
15604
15605 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_BuiltCommitmentTransaction_1new(JNIEnv * _env, jclass _b, jbyteArray transaction_arg, jbyteArray txid_arg) {
15606         LDKTransaction transaction_arg_ref;
15607         transaction_arg_ref.datalen = (*_env)->GetArrayLength (_env, transaction_arg);
15608         transaction_arg_ref.data = MALLOC(transaction_arg_ref.datalen, "LDKTransaction Bytes");
15609         (*_env)->GetByteArrayRegion(_env, transaction_arg, 0, transaction_arg_ref.datalen, transaction_arg_ref.data);
15610         transaction_arg_ref.data_is_owned = true;
15611         LDKThirtyTwoBytes txid_arg_ref;
15612         CHECK((*_env)->GetArrayLength (_env, txid_arg) == 32);
15613         (*_env)->GetByteArrayRegion (_env, txid_arg, 0, 32, txid_arg_ref.data);
15614         LDKBuiltCommitmentTransaction ret_var = BuiltCommitmentTransaction_new(transaction_arg_ref, txid_arg_ref);
15615         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15616         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15617         long ret_ref = (long)ret_var.inner;
15618         if (ret_var.is_owned) {
15619                 ret_ref |= 1;
15620         }
15621         return ret_ref;
15622 }
15623
15624 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_BuiltCommitmentTransaction_1write(JNIEnv * _env, jclass _b, jlong obj) {
15625         LDKBuiltCommitmentTransaction obj_conv;
15626         obj_conv.inner = (void*)(obj & (~1));
15627         obj_conv.is_owned = false;
15628         LDKCVec_u8Z arg_var = BuiltCommitmentTransaction_write(&obj_conv);
15629         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
15630         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
15631         CVec_u8Z_free(arg_var);
15632         return arg_arr;
15633 }
15634
15635 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_BuiltCommitmentTransaction_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
15636         LDKu8slice ser_ref;
15637         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
15638         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
15639         LDKBuiltCommitmentTransaction ret_var = BuiltCommitmentTransaction_read(ser_ref);
15640         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15641         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15642         long ret_ref = (long)ret_var.inner;
15643         if (ret_var.is_owned) {
15644                 ret_ref |= 1;
15645         }
15646         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
15647         return ret_ref;
15648 }
15649
15650 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_BuiltCommitmentTransaction_1get_1sighash_1all(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray funding_redeemscript, jlong channel_value_satoshis) {
15651         LDKBuiltCommitmentTransaction this_arg_conv;
15652         this_arg_conv.inner = (void*)(this_arg & (~1));
15653         this_arg_conv.is_owned = false;
15654         LDKu8slice funding_redeemscript_ref;
15655         funding_redeemscript_ref.datalen = (*_env)->GetArrayLength (_env, funding_redeemscript);
15656         funding_redeemscript_ref.data = (*_env)->GetByteArrayElements (_env, funding_redeemscript, NULL);
15657         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 32);
15658         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 32, BuiltCommitmentTransaction_get_sighash_all(&this_arg_conv, funding_redeemscript_ref, channel_value_satoshis).data);
15659         (*_env)->ReleaseByteArrayElements(_env, funding_redeemscript, (int8_t*)funding_redeemscript_ref.data, 0);
15660         return arg_arr;
15661 }
15662
15663 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_BuiltCommitmentTransaction_1sign(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray funding_key, jbyteArray funding_redeemscript, jlong channel_value_satoshis) {
15664         LDKBuiltCommitmentTransaction this_arg_conv;
15665         this_arg_conv.inner = (void*)(this_arg & (~1));
15666         this_arg_conv.is_owned = false;
15667         unsigned char funding_key_arr[32];
15668         CHECK((*_env)->GetArrayLength (_env, funding_key) == 32);
15669         (*_env)->GetByteArrayRegion (_env, funding_key, 0, 32, funding_key_arr);
15670         unsigned char (*funding_key_ref)[32] = &funding_key_arr;
15671         LDKu8slice funding_redeemscript_ref;
15672         funding_redeemscript_ref.datalen = (*_env)->GetArrayLength (_env, funding_redeemscript);
15673         funding_redeemscript_ref.data = (*_env)->GetByteArrayElements (_env, funding_redeemscript, NULL);
15674         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 64);
15675         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 64, BuiltCommitmentTransaction_sign(&this_arg_conv, funding_key_ref, funding_redeemscript_ref, channel_value_satoshis).compact_form);
15676         (*_env)->ReleaseByteArrayElements(_env, funding_redeemscript, (int8_t*)funding_redeemscript_ref.data, 0);
15677         return arg_arr;
15678 }
15679
15680 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CommitmentTransaction_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
15681         LDKCommitmentTransaction this_ptr_conv;
15682         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15683         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
15684         CommitmentTransaction_free(this_ptr_conv);
15685 }
15686
15687 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CommitmentTransaction_1clone(JNIEnv * _env, jclass _b, jlong orig) {
15688         LDKCommitmentTransaction orig_conv;
15689         orig_conv.inner = (void*)(orig & (~1));
15690         orig_conv.is_owned = false;
15691         LDKCommitmentTransaction ret_var = CommitmentTransaction_clone(&orig_conv);
15692         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15693         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15694         long ret_ref = (long)ret_var.inner;
15695         if (ret_var.is_owned) {
15696                 ret_ref |= 1;
15697         }
15698         return ret_ref;
15699 }
15700
15701 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_CommitmentTransaction_1write(JNIEnv * _env, jclass _b, jlong obj) {
15702         LDKCommitmentTransaction obj_conv;
15703         obj_conv.inner = (void*)(obj & (~1));
15704         obj_conv.is_owned = false;
15705         LDKCVec_u8Z arg_var = CommitmentTransaction_write(&obj_conv);
15706         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
15707         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
15708         CVec_u8Z_free(arg_var);
15709         return arg_arr;
15710 }
15711
15712 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CommitmentTransaction_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
15713         LDKu8slice ser_ref;
15714         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
15715         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
15716         LDKCommitmentTransaction ret_var = CommitmentTransaction_read(ser_ref);
15717         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15718         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15719         long ret_ref = (long)ret_var.inner;
15720         if (ret_var.is_owned) {
15721                 ret_ref |= 1;
15722         }
15723         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
15724         return ret_ref;
15725 }
15726
15727 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CommitmentTransaction_1commitment_1number(JNIEnv * _env, jclass _b, jlong this_arg) {
15728         LDKCommitmentTransaction this_arg_conv;
15729         this_arg_conv.inner = (void*)(this_arg & (~1));
15730         this_arg_conv.is_owned = false;
15731         jlong ret_val = CommitmentTransaction_commitment_number(&this_arg_conv);
15732         return ret_val;
15733 }
15734
15735 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CommitmentTransaction_1to_1broadcaster_1value_1sat(JNIEnv * _env, jclass _b, jlong this_arg) {
15736         LDKCommitmentTransaction this_arg_conv;
15737         this_arg_conv.inner = (void*)(this_arg & (~1));
15738         this_arg_conv.is_owned = false;
15739         jlong ret_val = CommitmentTransaction_to_broadcaster_value_sat(&this_arg_conv);
15740         return ret_val;
15741 }
15742
15743 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CommitmentTransaction_1to_1countersignatory_1value_1sat(JNIEnv * _env, jclass _b, jlong this_arg) {
15744         LDKCommitmentTransaction this_arg_conv;
15745         this_arg_conv.inner = (void*)(this_arg & (~1));
15746         this_arg_conv.is_owned = false;
15747         jlong ret_val = CommitmentTransaction_to_countersignatory_value_sat(&this_arg_conv);
15748         return ret_val;
15749 }
15750
15751 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_CommitmentTransaction_1feerate_1per_1kw(JNIEnv * _env, jclass _b, jlong this_arg) {
15752         LDKCommitmentTransaction this_arg_conv;
15753         this_arg_conv.inner = (void*)(this_arg & (~1));
15754         this_arg_conv.is_owned = false;
15755         jint ret_val = CommitmentTransaction_feerate_per_kw(&this_arg_conv);
15756         return ret_val;
15757 }
15758
15759 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CommitmentTransaction_1trust(JNIEnv * _env, jclass _b, jlong this_arg) {
15760         LDKCommitmentTransaction this_arg_conv;
15761         this_arg_conv.inner = (void*)(this_arg & (~1));
15762         this_arg_conv.is_owned = false;
15763         LDKTrustedCommitmentTransaction ret_var = CommitmentTransaction_trust(&this_arg_conv);
15764         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15765         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15766         long ret_ref = (long)ret_var.inner;
15767         if (ret_var.is_owned) {
15768                 ret_ref |= 1;
15769         }
15770         return ret_ref;
15771 }
15772
15773 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CommitmentTransaction_1verify(JNIEnv * _env, jclass _b, jlong this_arg, jlong channel_parameters, jlong broadcaster_keys, jlong countersignatory_keys) {
15774         LDKCommitmentTransaction this_arg_conv;
15775         this_arg_conv.inner = (void*)(this_arg & (~1));
15776         this_arg_conv.is_owned = false;
15777         LDKDirectedChannelTransactionParameters channel_parameters_conv;
15778         channel_parameters_conv.inner = (void*)(channel_parameters & (~1));
15779         channel_parameters_conv.is_owned = false;
15780         LDKChannelPublicKeys broadcaster_keys_conv;
15781         broadcaster_keys_conv.inner = (void*)(broadcaster_keys & (~1));
15782         broadcaster_keys_conv.is_owned = false;
15783         LDKChannelPublicKeys countersignatory_keys_conv;
15784         countersignatory_keys_conv.inner = (void*)(countersignatory_keys & (~1));
15785         countersignatory_keys_conv.is_owned = false;
15786         LDKCResult_TrustedCommitmentTransactionNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_TrustedCommitmentTransactionNoneZ), "LDKCResult_TrustedCommitmentTransactionNoneZ");
15787         *ret_conv = CommitmentTransaction_verify(&this_arg_conv, &channel_parameters_conv, &broadcaster_keys_conv, &countersignatory_keys_conv);
15788         return (long)ret_conv;
15789 }
15790
15791 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_TrustedCommitmentTransaction_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
15792         LDKTrustedCommitmentTransaction this_ptr_conv;
15793         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15794         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
15795         TrustedCommitmentTransaction_free(this_ptr_conv);
15796 }
15797
15798 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_TrustedCommitmentTransaction_1txid(JNIEnv * _env, jclass _b, jlong this_arg) {
15799         LDKTrustedCommitmentTransaction this_arg_conv;
15800         this_arg_conv.inner = (void*)(this_arg & (~1));
15801         this_arg_conv.is_owned = false;
15802         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 32);
15803         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 32, TrustedCommitmentTransaction_txid(&this_arg_conv).data);
15804         return arg_arr;
15805 }
15806
15807 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_TrustedCommitmentTransaction_1built_1transaction(JNIEnv * _env, jclass _b, jlong this_arg) {
15808         LDKTrustedCommitmentTransaction this_arg_conv;
15809         this_arg_conv.inner = (void*)(this_arg & (~1));
15810         this_arg_conv.is_owned = false;
15811         LDKBuiltCommitmentTransaction ret_var = TrustedCommitmentTransaction_built_transaction(&this_arg_conv);
15812         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15813         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15814         long ret_ref = (long)ret_var.inner;
15815         if (ret_var.is_owned) {
15816                 ret_ref |= 1;
15817         }
15818         return ret_ref;
15819 }
15820
15821 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_TrustedCommitmentTransaction_1keys(JNIEnv * _env, jclass _b, jlong this_arg) {
15822         LDKTrustedCommitmentTransaction this_arg_conv;
15823         this_arg_conv.inner = (void*)(this_arg & (~1));
15824         this_arg_conv.is_owned = false;
15825         LDKTxCreationKeys ret_var = TrustedCommitmentTransaction_keys(&this_arg_conv);
15826         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15827         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15828         long ret_ref = (long)ret_var.inner;
15829         if (ret_var.is_owned) {
15830                 ret_ref |= 1;
15831         }
15832         return ret_ref;
15833 }
15834
15835 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_TrustedCommitmentTransaction_1get_1htlc_1sigs(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray htlc_base_key, jlong channel_parameters) {
15836         LDKTrustedCommitmentTransaction this_arg_conv;
15837         this_arg_conv.inner = (void*)(this_arg & (~1));
15838         this_arg_conv.is_owned = false;
15839         unsigned char htlc_base_key_arr[32];
15840         CHECK((*_env)->GetArrayLength (_env, htlc_base_key) == 32);
15841         (*_env)->GetByteArrayRegion (_env, htlc_base_key, 0, 32, htlc_base_key_arr);
15842         unsigned char (*htlc_base_key_ref)[32] = &htlc_base_key_arr;
15843         LDKDirectedChannelTransactionParameters channel_parameters_conv;
15844         channel_parameters_conv.inner = (void*)(channel_parameters & (~1));
15845         channel_parameters_conv.is_owned = false;
15846         LDKCResult_CVec_SignatureZNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_CVec_SignatureZNoneZ), "LDKCResult_CVec_SignatureZNoneZ");
15847         *ret_conv = TrustedCommitmentTransaction_get_htlc_sigs(&this_arg_conv, htlc_base_key_ref, &channel_parameters_conv);
15848         return (long)ret_conv;
15849 }
15850
15851 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_get_1commitment_1transaction_1number_1obscure_1factor(JNIEnv * _env, jclass _b, jbyteArray broadcaster_payment_basepoint, jbyteArray countersignatory_payment_basepoint, jboolean outbound_from_broadcaster) {
15852         LDKPublicKey broadcaster_payment_basepoint_ref;
15853         CHECK((*_env)->GetArrayLength (_env, broadcaster_payment_basepoint) == 33);
15854         (*_env)->GetByteArrayRegion (_env, broadcaster_payment_basepoint, 0, 33, broadcaster_payment_basepoint_ref.compressed_form);
15855         LDKPublicKey countersignatory_payment_basepoint_ref;
15856         CHECK((*_env)->GetArrayLength (_env, countersignatory_payment_basepoint) == 33);
15857         (*_env)->GetByteArrayRegion (_env, countersignatory_payment_basepoint, 0, 33, countersignatory_payment_basepoint_ref.compressed_form);
15858         jlong ret_val = get_commitment_transaction_number_obscure_factor(broadcaster_payment_basepoint_ref, countersignatory_payment_basepoint_ref, outbound_from_broadcaster);
15859         return ret_val;
15860 }
15861
15862 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_InitFeatures_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
15863         LDKInitFeatures this_ptr_conv;
15864         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15865         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
15866         InitFeatures_free(this_ptr_conv);
15867 }
15868
15869 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NodeFeatures_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
15870         LDKNodeFeatures this_ptr_conv;
15871         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15872         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
15873         NodeFeatures_free(this_ptr_conv);
15874 }
15875
15876 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelFeatures_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
15877         LDKChannelFeatures this_ptr_conv;
15878         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15879         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
15880         ChannelFeatures_free(this_ptr_conv);
15881 }
15882
15883 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RouteHop_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
15884         LDKRouteHop this_ptr_conv;
15885         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15886         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
15887         RouteHop_free(this_ptr_conv);
15888 }
15889
15890 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_RouteHop_1clone(JNIEnv * _env, jclass _b, jlong orig) {
15891         LDKRouteHop orig_conv;
15892         orig_conv.inner = (void*)(orig & (~1));
15893         orig_conv.is_owned = false;
15894         LDKRouteHop ret_var = RouteHop_clone(&orig_conv);
15895         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15896         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15897         long ret_ref = (long)ret_var.inner;
15898         if (ret_var.is_owned) {
15899                 ret_ref |= 1;
15900         }
15901         return ret_ref;
15902 }
15903
15904 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_RouteHop_1get_1pubkey(JNIEnv * _env, jclass _b, jlong this_ptr) {
15905         LDKRouteHop this_ptr_conv;
15906         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15907         this_ptr_conv.is_owned = false;
15908         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
15909         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, RouteHop_get_pubkey(&this_ptr_conv).compressed_form);
15910         return arg_arr;
15911 }
15912
15913 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RouteHop_1set_1pubkey(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
15914         LDKRouteHop this_ptr_conv;
15915         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15916         this_ptr_conv.is_owned = false;
15917         LDKPublicKey val_ref;
15918         CHECK((*_env)->GetArrayLength (_env, val) == 33);
15919         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
15920         RouteHop_set_pubkey(&this_ptr_conv, val_ref);
15921 }
15922
15923 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_RouteHop_1get_1node_1features(JNIEnv * _env, jclass _b, jlong this_ptr) {
15924         LDKRouteHop this_ptr_conv;
15925         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15926         this_ptr_conv.is_owned = false;
15927         LDKNodeFeatures ret_var = RouteHop_get_node_features(&this_ptr_conv);
15928         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15929         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15930         long ret_ref = (long)ret_var.inner;
15931         if (ret_var.is_owned) {
15932                 ret_ref |= 1;
15933         }
15934         return ret_ref;
15935 }
15936
15937 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RouteHop_1set_1node_1features(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
15938         LDKRouteHop this_ptr_conv;
15939         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15940         this_ptr_conv.is_owned = false;
15941         LDKNodeFeatures val_conv;
15942         val_conv.inner = (void*)(val & (~1));
15943         val_conv.is_owned = (val & 1) || (val == 0);
15944         // Warning: we may need a move here but can't clone!
15945         RouteHop_set_node_features(&this_ptr_conv, val_conv);
15946 }
15947
15948 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_RouteHop_1get_1short_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
15949         LDKRouteHop this_ptr_conv;
15950         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15951         this_ptr_conv.is_owned = false;
15952         jlong ret_val = RouteHop_get_short_channel_id(&this_ptr_conv);
15953         return ret_val;
15954 }
15955
15956 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RouteHop_1set_1short_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
15957         LDKRouteHop this_ptr_conv;
15958         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15959         this_ptr_conv.is_owned = false;
15960         RouteHop_set_short_channel_id(&this_ptr_conv, val);
15961 }
15962
15963 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_RouteHop_1get_1channel_1features(JNIEnv * _env, jclass _b, jlong this_ptr) {
15964         LDKRouteHop this_ptr_conv;
15965         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15966         this_ptr_conv.is_owned = false;
15967         LDKChannelFeatures ret_var = RouteHop_get_channel_features(&this_ptr_conv);
15968         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15969         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15970         long ret_ref = (long)ret_var.inner;
15971         if (ret_var.is_owned) {
15972                 ret_ref |= 1;
15973         }
15974         return ret_ref;
15975 }
15976
15977 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RouteHop_1set_1channel_1features(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
15978         LDKRouteHop this_ptr_conv;
15979         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15980         this_ptr_conv.is_owned = false;
15981         LDKChannelFeatures val_conv;
15982         val_conv.inner = (void*)(val & (~1));
15983         val_conv.is_owned = (val & 1) || (val == 0);
15984         // Warning: we may need a move here but can't clone!
15985         RouteHop_set_channel_features(&this_ptr_conv, val_conv);
15986 }
15987
15988 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_RouteHop_1get_1fee_1msat(JNIEnv * _env, jclass _b, jlong this_ptr) {
15989         LDKRouteHop this_ptr_conv;
15990         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15991         this_ptr_conv.is_owned = false;
15992         jlong ret_val = RouteHop_get_fee_msat(&this_ptr_conv);
15993         return ret_val;
15994 }
15995
15996 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RouteHop_1set_1fee_1msat(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
15997         LDKRouteHop this_ptr_conv;
15998         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15999         this_ptr_conv.is_owned = false;
16000         RouteHop_set_fee_msat(&this_ptr_conv, val);
16001 }
16002
16003 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_RouteHop_1get_1cltv_1expiry_1delta(JNIEnv * _env, jclass _b, jlong this_ptr) {
16004         LDKRouteHop this_ptr_conv;
16005         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16006         this_ptr_conv.is_owned = false;
16007         jint ret_val = RouteHop_get_cltv_expiry_delta(&this_ptr_conv);
16008         return ret_val;
16009 }
16010
16011 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RouteHop_1set_1cltv_1expiry_1delta(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
16012         LDKRouteHop this_ptr_conv;
16013         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16014         this_ptr_conv.is_owned = false;
16015         RouteHop_set_cltv_expiry_delta(&this_ptr_conv, val);
16016 }
16017
16018 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_RouteHop_1new(JNIEnv * _env, jclass _b, jbyteArray pubkey_arg, jlong node_features_arg, jlong short_channel_id_arg, jlong channel_features_arg, jlong fee_msat_arg, jint cltv_expiry_delta_arg) {
16019         LDKPublicKey pubkey_arg_ref;
16020         CHECK((*_env)->GetArrayLength (_env, pubkey_arg) == 33);
16021         (*_env)->GetByteArrayRegion (_env, pubkey_arg, 0, 33, pubkey_arg_ref.compressed_form);
16022         LDKNodeFeatures node_features_arg_conv;
16023         node_features_arg_conv.inner = (void*)(node_features_arg & (~1));
16024         node_features_arg_conv.is_owned = (node_features_arg & 1) || (node_features_arg == 0);
16025         // Warning: we may need a move here but can't clone!
16026         LDKChannelFeatures channel_features_arg_conv;
16027         channel_features_arg_conv.inner = (void*)(channel_features_arg & (~1));
16028         channel_features_arg_conv.is_owned = (channel_features_arg & 1) || (channel_features_arg == 0);
16029         // Warning: we may need a move here but can't clone!
16030         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);
16031         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
16032         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
16033         long ret_ref = (long)ret_var.inner;
16034         if (ret_var.is_owned) {
16035                 ret_ref |= 1;
16036         }
16037         return ret_ref;
16038 }
16039
16040 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Route_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
16041         LDKRoute this_ptr_conv;
16042         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16043         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
16044         Route_free(this_ptr_conv);
16045 }
16046
16047 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_Route_1clone(JNIEnv * _env, jclass _b, jlong orig) {
16048         LDKRoute orig_conv;
16049         orig_conv.inner = (void*)(orig & (~1));
16050         orig_conv.is_owned = false;
16051         LDKRoute ret_var = Route_clone(&orig_conv);
16052         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
16053         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
16054         long ret_ref = (long)ret_var.inner;
16055         if (ret_var.is_owned) {
16056                 ret_ref |= 1;
16057         }
16058         return ret_ref;
16059 }
16060
16061 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Route_1set_1paths(JNIEnv * _env, jclass _b, jlong this_ptr, jobjectArray val) {
16062         LDKRoute this_ptr_conv;
16063         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16064         this_ptr_conv.is_owned = false;
16065         LDKCVec_CVec_RouteHopZZ val_constr;
16066         val_constr.datalen = (*_env)->GetArrayLength (_env, val);
16067         if (val_constr.datalen > 0)
16068                 val_constr.data = MALLOC(val_constr.datalen * sizeof(LDKCVec_RouteHopZ), "LDKCVec_CVec_RouteHopZZ Elements");
16069         else
16070                 val_constr.data = NULL;
16071         for (size_t m = 0; m < val_constr.datalen; m++) {
16072                 jobject arr_conv_12 = (*_env)->GetObjectArrayElement(_env, val, m);
16073                 LDKCVec_RouteHopZ arr_conv_12_constr;
16074                 arr_conv_12_constr.datalen = (*_env)->GetArrayLength (_env, arr_conv_12);
16075                 if (arr_conv_12_constr.datalen > 0)
16076                         arr_conv_12_constr.data = MALLOC(arr_conv_12_constr.datalen * sizeof(LDKRouteHop), "LDKCVec_RouteHopZ Elements");
16077                 else
16078                         arr_conv_12_constr.data = NULL;
16079                 long* arr_conv_12_vals = (*_env)->GetLongArrayElements (_env, arr_conv_12, NULL);
16080                 for (size_t k = 0; k < arr_conv_12_constr.datalen; k++) {
16081                         long arr_conv_10 = arr_conv_12_vals[k];
16082                         LDKRouteHop arr_conv_10_conv;
16083                         arr_conv_10_conv.inner = (void*)(arr_conv_10 & (~1));
16084                         arr_conv_10_conv.is_owned = (arr_conv_10 & 1) || (arr_conv_10 == 0);
16085                         arr_conv_12_constr.data[k] = arr_conv_10_conv;
16086                 }
16087                 (*_env)->ReleaseLongArrayElements (_env, arr_conv_12, arr_conv_12_vals, 0);
16088                 val_constr.data[m] = arr_conv_12_constr;
16089         }
16090         Route_set_paths(&this_ptr_conv, val_constr);
16091 }
16092
16093 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_Route_1new(JNIEnv * _env, jclass _b, jobjectArray paths_arg) {
16094         LDKCVec_CVec_RouteHopZZ paths_arg_constr;
16095         paths_arg_constr.datalen = (*_env)->GetArrayLength (_env, paths_arg);
16096         if (paths_arg_constr.datalen > 0)
16097                 paths_arg_constr.data = MALLOC(paths_arg_constr.datalen * sizeof(LDKCVec_RouteHopZ), "LDKCVec_CVec_RouteHopZZ Elements");
16098         else
16099                 paths_arg_constr.data = NULL;
16100         for (size_t m = 0; m < paths_arg_constr.datalen; m++) {
16101                 jobject arr_conv_12 = (*_env)->GetObjectArrayElement(_env, paths_arg, m);
16102                 LDKCVec_RouteHopZ arr_conv_12_constr;
16103                 arr_conv_12_constr.datalen = (*_env)->GetArrayLength (_env, arr_conv_12);
16104                 if (arr_conv_12_constr.datalen > 0)
16105                         arr_conv_12_constr.data = MALLOC(arr_conv_12_constr.datalen * sizeof(LDKRouteHop), "LDKCVec_RouteHopZ Elements");
16106                 else
16107                         arr_conv_12_constr.data = NULL;
16108                 long* arr_conv_12_vals = (*_env)->GetLongArrayElements (_env, arr_conv_12, NULL);
16109                 for (size_t k = 0; k < arr_conv_12_constr.datalen; k++) {
16110                         long arr_conv_10 = arr_conv_12_vals[k];
16111                         LDKRouteHop arr_conv_10_conv;
16112                         arr_conv_10_conv.inner = (void*)(arr_conv_10 & (~1));
16113                         arr_conv_10_conv.is_owned = (arr_conv_10 & 1) || (arr_conv_10 == 0);
16114                         arr_conv_12_constr.data[k] = arr_conv_10_conv;
16115                 }
16116                 (*_env)->ReleaseLongArrayElements (_env, arr_conv_12, arr_conv_12_vals, 0);
16117                 paths_arg_constr.data[m] = arr_conv_12_constr;
16118         }
16119         LDKRoute ret_var = Route_new(paths_arg_constr);
16120         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
16121         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
16122         long ret_ref = (long)ret_var.inner;
16123         if (ret_var.is_owned) {
16124                 ret_ref |= 1;
16125         }
16126         return ret_ref;
16127 }
16128
16129 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_Route_1write(JNIEnv * _env, jclass _b, jlong obj) {
16130         LDKRoute obj_conv;
16131         obj_conv.inner = (void*)(obj & (~1));
16132         obj_conv.is_owned = false;
16133         LDKCVec_u8Z arg_var = Route_write(&obj_conv);
16134         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
16135         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
16136         CVec_u8Z_free(arg_var);
16137         return arg_arr;
16138 }
16139
16140 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_Route_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
16141         LDKu8slice ser_ref;
16142         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
16143         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
16144         LDKCResult_RouteDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_RouteDecodeErrorZ), "LDKCResult_RouteDecodeErrorZ");
16145         *ret_conv = Route_read(ser_ref);
16146         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
16147         return (long)ret_conv;
16148 }
16149
16150 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RouteHint_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
16151         LDKRouteHint this_ptr_conv;
16152         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16153         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
16154         RouteHint_free(this_ptr_conv);
16155 }
16156
16157 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_RouteHint_1clone(JNIEnv * _env, jclass _b, jlong orig) {
16158         LDKRouteHint orig_conv;
16159         orig_conv.inner = (void*)(orig & (~1));
16160         orig_conv.is_owned = false;
16161         LDKRouteHint ret_var = RouteHint_clone(&orig_conv);
16162         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
16163         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
16164         long ret_ref = (long)ret_var.inner;
16165         if (ret_var.is_owned) {
16166                 ret_ref |= 1;
16167         }
16168         return ret_ref;
16169 }
16170
16171 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_RouteHint_1get_1src_1node_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
16172         LDKRouteHint this_ptr_conv;
16173         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16174         this_ptr_conv.is_owned = false;
16175         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
16176         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, RouteHint_get_src_node_id(&this_ptr_conv).compressed_form);
16177         return arg_arr;
16178 }
16179
16180 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RouteHint_1set_1src_1node_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
16181         LDKRouteHint this_ptr_conv;
16182         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16183         this_ptr_conv.is_owned = false;
16184         LDKPublicKey val_ref;
16185         CHECK((*_env)->GetArrayLength (_env, val) == 33);
16186         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
16187         RouteHint_set_src_node_id(&this_ptr_conv, val_ref);
16188 }
16189
16190 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_RouteHint_1get_1short_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
16191         LDKRouteHint this_ptr_conv;
16192         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16193         this_ptr_conv.is_owned = false;
16194         jlong ret_val = RouteHint_get_short_channel_id(&this_ptr_conv);
16195         return ret_val;
16196 }
16197
16198 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RouteHint_1set_1short_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
16199         LDKRouteHint this_ptr_conv;
16200         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16201         this_ptr_conv.is_owned = false;
16202         RouteHint_set_short_channel_id(&this_ptr_conv, val);
16203 }
16204
16205 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_RouteHint_1get_1fees(JNIEnv * _env, jclass _b, jlong this_ptr) {
16206         LDKRouteHint this_ptr_conv;
16207         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16208         this_ptr_conv.is_owned = false;
16209         LDKRoutingFees ret_var = RouteHint_get_fees(&this_ptr_conv);
16210         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
16211         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
16212         long ret_ref = (long)ret_var.inner;
16213         if (ret_var.is_owned) {
16214                 ret_ref |= 1;
16215         }
16216         return ret_ref;
16217 }
16218
16219 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RouteHint_1set_1fees(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
16220         LDKRouteHint this_ptr_conv;
16221         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16222         this_ptr_conv.is_owned = false;
16223         LDKRoutingFees val_conv;
16224         val_conv.inner = (void*)(val & (~1));
16225         val_conv.is_owned = (val & 1) || (val == 0);
16226         if (val_conv.inner != NULL)
16227                 val_conv = RoutingFees_clone(&val_conv);
16228         RouteHint_set_fees(&this_ptr_conv, val_conv);
16229 }
16230
16231 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_RouteHint_1get_1cltv_1expiry_1delta(JNIEnv * _env, jclass _b, jlong this_ptr) {
16232         LDKRouteHint this_ptr_conv;
16233         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16234         this_ptr_conv.is_owned = false;
16235         jshort ret_val = RouteHint_get_cltv_expiry_delta(&this_ptr_conv);
16236         return ret_val;
16237 }
16238
16239 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RouteHint_1set_1cltv_1expiry_1delta(JNIEnv * _env, jclass _b, jlong this_ptr, jshort val) {
16240         LDKRouteHint this_ptr_conv;
16241         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16242         this_ptr_conv.is_owned = false;
16243         RouteHint_set_cltv_expiry_delta(&this_ptr_conv, val);
16244 }
16245
16246 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_RouteHint_1get_1htlc_1minimum_1msat(JNIEnv * _env, jclass _b, jlong this_ptr) {
16247         LDKRouteHint this_ptr_conv;
16248         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16249         this_ptr_conv.is_owned = false;
16250         jlong ret_val = RouteHint_get_htlc_minimum_msat(&this_ptr_conv);
16251         return ret_val;
16252 }
16253
16254 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RouteHint_1set_1htlc_1minimum_1msat(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
16255         LDKRouteHint this_ptr_conv;
16256         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16257         this_ptr_conv.is_owned = false;
16258         RouteHint_set_htlc_minimum_msat(&this_ptr_conv, val);
16259 }
16260
16261 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_RouteHint_1new(JNIEnv * _env, jclass _b, jbyteArray src_node_id_arg, jlong short_channel_id_arg, jlong fees_arg, jshort cltv_expiry_delta_arg, jlong htlc_minimum_msat_arg) {
16262         LDKPublicKey src_node_id_arg_ref;
16263         CHECK((*_env)->GetArrayLength (_env, src_node_id_arg) == 33);
16264         (*_env)->GetByteArrayRegion (_env, src_node_id_arg, 0, 33, src_node_id_arg_ref.compressed_form);
16265         LDKRoutingFees fees_arg_conv;
16266         fees_arg_conv.inner = (void*)(fees_arg & (~1));
16267         fees_arg_conv.is_owned = (fees_arg & 1) || (fees_arg == 0);
16268         if (fees_arg_conv.inner != NULL)
16269                 fees_arg_conv = RoutingFees_clone(&fees_arg_conv);
16270         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);
16271         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
16272         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
16273         long ret_ref = (long)ret_var.inner;
16274         if (ret_var.is_owned) {
16275                 ret_ref |= 1;
16276         }
16277         return ret_ref;
16278 }
16279
16280 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_get_1route(JNIEnv * _env, jclass _b, jbyteArray our_node_id, jlong network, jbyteArray target, jlongArray first_hops, jlongArray last_hops, jlong final_value_msat, jint final_cltv, jlong logger) {
16281         LDKPublicKey our_node_id_ref;
16282         CHECK((*_env)->GetArrayLength (_env, our_node_id) == 33);
16283         (*_env)->GetByteArrayRegion (_env, our_node_id, 0, 33, our_node_id_ref.compressed_form);
16284         LDKNetworkGraph network_conv;
16285         network_conv.inner = (void*)(network & (~1));
16286         network_conv.is_owned = false;
16287         LDKPublicKey target_ref;
16288         CHECK((*_env)->GetArrayLength (_env, target) == 33);
16289         (*_env)->GetByteArrayRegion (_env, target, 0, 33, target_ref.compressed_form);
16290         LDKCVec_ChannelDetailsZ first_hops_constr;
16291         first_hops_constr.datalen = (*_env)->GetArrayLength (_env, first_hops);
16292         if (first_hops_constr.datalen > 0)
16293                 first_hops_constr.data = MALLOC(first_hops_constr.datalen * sizeof(LDKChannelDetails), "LDKCVec_ChannelDetailsZ Elements");
16294         else
16295                 first_hops_constr.data = NULL;
16296         long* first_hops_vals = (*_env)->GetLongArrayElements (_env, first_hops, NULL);
16297         for (size_t q = 0; q < first_hops_constr.datalen; q++) {
16298                 long arr_conv_16 = first_hops_vals[q];
16299                 LDKChannelDetails arr_conv_16_conv;
16300                 arr_conv_16_conv.inner = (void*)(arr_conv_16 & (~1));
16301                 arr_conv_16_conv.is_owned = (arr_conv_16 & 1) || (arr_conv_16 == 0);
16302                 first_hops_constr.data[q] = arr_conv_16_conv;
16303         }
16304         (*_env)->ReleaseLongArrayElements (_env, first_hops, first_hops_vals, 0);
16305         LDKCVec_RouteHintZ last_hops_constr;
16306         last_hops_constr.datalen = (*_env)->GetArrayLength (_env, last_hops);
16307         if (last_hops_constr.datalen > 0)
16308                 last_hops_constr.data = MALLOC(last_hops_constr.datalen * sizeof(LDKRouteHint), "LDKCVec_RouteHintZ Elements");
16309         else
16310                 last_hops_constr.data = NULL;
16311         long* last_hops_vals = (*_env)->GetLongArrayElements (_env, last_hops, NULL);
16312         for (size_t l = 0; l < last_hops_constr.datalen; l++) {
16313                 long arr_conv_11 = last_hops_vals[l];
16314                 LDKRouteHint arr_conv_11_conv;
16315                 arr_conv_11_conv.inner = (void*)(arr_conv_11 & (~1));
16316                 arr_conv_11_conv.is_owned = (arr_conv_11 & 1) || (arr_conv_11 == 0);
16317                 last_hops_constr.data[l] = arr_conv_11_conv;
16318         }
16319         (*_env)->ReleaseLongArrayElements (_env, last_hops, last_hops_vals, 0);
16320         LDKLogger logger_conv = *(LDKLogger*)logger;
16321         if (logger_conv.free == LDKLogger_JCalls_free) {
16322                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
16323                 LDKLogger_JCalls_clone(logger_conv.this_arg);
16324         }
16325         LDKCResult_RouteLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_RouteLightningErrorZ), "LDKCResult_RouteLightningErrorZ");
16326         *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);
16327         FREE(first_hops_constr.data);
16328         return (long)ret_conv;
16329 }
16330
16331 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NetworkGraph_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
16332         LDKNetworkGraph this_ptr_conv;
16333         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16334         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
16335         NetworkGraph_free(this_ptr_conv);
16336 }
16337
16338 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_LockedNetworkGraph_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
16339         LDKLockedNetworkGraph this_ptr_conv;
16340         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16341         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
16342         LockedNetworkGraph_free(this_ptr_conv);
16343 }
16344
16345 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NetGraphMsgHandler_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
16346         LDKNetGraphMsgHandler this_ptr_conv;
16347         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16348         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
16349         NetGraphMsgHandler_free(this_ptr_conv);
16350 }
16351
16352 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_NetGraphMsgHandler_1new(JNIEnv * _env, jclass _b, jbyteArray genesis_hash, jlong chain_access, jlong logger) {
16353         LDKThirtyTwoBytes genesis_hash_ref;
16354         CHECK((*_env)->GetArrayLength (_env, genesis_hash) == 32);
16355         (*_env)->GetByteArrayRegion (_env, genesis_hash, 0, 32, genesis_hash_ref.data);
16356         LDKAccess* chain_access_conv = (LDKAccess*)chain_access;
16357         LDKLogger logger_conv = *(LDKLogger*)logger;
16358         if (logger_conv.free == LDKLogger_JCalls_free) {
16359                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
16360                 LDKLogger_JCalls_clone(logger_conv.this_arg);
16361         }
16362         LDKNetGraphMsgHandler ret_var = NetGraphMsgHandler_new(genesis_hash_ref, chain_access_conv, logger_conv);
16363         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
16364         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
16365         long ret_ref = (long)ret_var.inner;
16366         if (ret_var.is_owned) {
16367                 ret_ref |= 1;
16368         }
16369         return ret_ref;
16370 }
16371
16372 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_NetGraphMsgHandler_1from_1net_1graph(JNIEnv * _env, jclass _b, jlong chain_access, jlong logger, jlong network_graph) {
16373         LDKAccess* chain_access_conv = (LDKAccess*)chain_access;
16374         LDKLogger logger_conv = *(LDKLogger*)logger;
16375         if (logger_conv.free == LDKLogger_JCalls_free) {
16376                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
16377                 LDKLogger_JCalls_clone(logger_conv.this_arg);
16378         }
16379         LDKNetworkGraph network_graph_conv;
16380         network_graph_conv.inner = (void*)(network_graph & (~1));
16381         network_graph_conv.is_owned = (network_graph & 1) || (network_graph == 0);
16382         // Warning: we may need a move here but can't clone!
16383         LDKNetGraphMsgHandler ret_var = NetGraphMsgHandler_from_net_graph(chain_access_conv, logger_conv, network_graph_conv);
16384         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
16385         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
16386         long ret_ref = (long)ret_var.inner;
16387         if (ret_var.is_owned) {
16388                 ret_ref |= 1;
16389         }
16390         return ret_ref;
16391 }
16392
16393 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_NetGraphMsgHandler_1read_1locked_1graph(JNIEnv * _env, jclass _b, jlong this_arg) {
16394         LDKNetGraphMsgHandler this_arg_conv;
16395         this_arg_conv.inner = (void*)(this_arg & (~1));
16396         this_arg_conv.is_owned = false;
16397         LDKLockedNetworkGraph ret_var = NetGraphMsgHandler_read_locked_graph(&this_arg_conv);
16398         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
16399         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
16400         long ret_ref = (long)ret_var.inner;
16401         if (ret_var.is_owned) {
16402                 ret_ref |= 1;
16403         }
16404         return ret_ref;
16405 }
16406
16407 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LockedNetworkGraph_1graph(JNIEnv * _env, jclass _b, jlong this_arg) {
16408         LDKLockedNetworkGraph this_arg_conv;
16409         this_arg_conv.inner = (void*)(this_arg & (~1));
16410         this_arg_conv.is_owned = false;
16411         LDKNetworkGraph ret_var = LockedNetworkGraph_graph(&this_arg_conv);
16412         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
16413         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
16414         long ret_ref = (long)ret_var.inner;
16415         if (ret_var.is_owned) {
16416                 ret_ref |= 1;
16417         }
16418         return ret_ref;
16419 }
16420
16421 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_NetGraphMsgHandler_1as_1RoutingMessageHandler(JNIEnv * _env, jclass _b, jlong this_arg) {
16422         LDKNetGraphMsgHandler this_arg_conv;
16423         this_arg_conv.inner = (void*)(this_arg & (~1));
16424         this_arg_conv.is_owned = false;
16425         LDKRoutingMessageHandler* ret = MALLOC(sizeof(LDKRoutingMessageHandler), "LDKRoutingMessageHandler");
16426         *ret = NetGraphMsgHandler_as_RoutingMessageHandler(&this_arg_conv);
16427         return (long)ret;
16428 }
16429
16430 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_NetGraphMsgHandler_1as_1MessageSendEventsProvider(JNIEnv * _env, jclass _b, jlong this_arg) {
16431         LDKNetGraphMsgHandler this_arg_conv;
16432         this_arg_conv.inner = (void*)(this_arg & (~1));
16433         this_arg_conv.is_owned = false;
16434         LDKMessageSendEventsProvider* ret = MALLOC(sizeof(LDKMessageSendEventsProvider), "LDKMessageSendEventsProvider");
16435         *ret = NetGraphMsgHandler_as_MessageSendEventsProvider(&this_arg_conv);
16436         return (long)ret;
16437 }
16438
16439 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_DirectionalChannelInfo_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
16440         LDKDirectionalChannelInfo this_ptr_conv;
16441         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16442         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
16443         DirectionalChannelInfo_free(this_ptr_conv);
16444 }
16445
16446 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_DirectionalChannelInfo_1get_1last_1update(JNIEnv * _env, jclass _b, jlong this_ptr) {
16447         LDKDirectionalChannelInfo this_ptr_conv;
16448         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16449         this_ptr_conv.is_owned = false;
16450         jint ret_val = DirectionalChannelInfo_get_last_update(&this_ptr_conv);
16451         return ret_val;
16452 }
16453
16454 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_DirectionalChannelInfo_1set_1last_1update(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
16455         LDKDirectionalChannelInfo this_ptr_conv;
16456         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16457         this_ptr_conv.is_owned = false;
16458         DirectionalChannelInfo_set_last_update(&this_ptr_conv, val);
16459 }
16460
16461 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_DirectionalChannelInfo_1get_1enabled(JNIEnv * _env, jclass _b, jlong this_ptr) {
16462         LDKDirectionalChannelInfo this_ptr_conv;
16463         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16464         this_ptr_conv.is_owned = false;
16465         jboolean ret_val = DirectionalChannelInfo_get_enabled(&this_ptr_conv);
16466         return ret_val;
16467 }
16468
16469 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_DirectionalChannelInfo_1set_1enabled(JNIEnv * _env, jclass _b, jlong this_ptr, jboolean val) {
16470         LDKDirectionalChannelInfo this_ptr_conv;
16471         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16472         this_ptr_conv.is_owned = false;
16473         DirectionalChannelInfo_set_enabled(&this_ptr_conv, val);
16474 }
16475
16476 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_DirectionalChannelInfo_1get_1cltv_1expiry_1delta(JNIEnv * _env, jclass _b, jlong this_ptr) {
16477         LDKDirectionalChannelInfo this_ptr_conv;
16478         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16479         this_ptr_conv.is_owned = false;
16480         jshort ret_val = DirectionalChannelInfo_get_cltv_expiry_delta(&this_ptr_conv);
16481         return ret_val;
16482 }
16483
16484 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_DirectionalChannelInfo_1set_1cltv_1expiry_1delta(JNIEnv * _env, jclass _b, jlong this_ptr, jshort val) {
16485         LDKDirectionalChannelInfo this_ptr_conv;
16486         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16487         this_ptr_conv.is_owned = false;
16488         DirectionalChannelInfo_set_cltv_expiry_delta(&this_ptr_conv, val);
16489 }
16490
16491 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_DirectionalChannelInfo_1get_1htlc_1minimum_1msat(JNIEnv * _env, jclass _b, jlong this_ptr) {
16492         LDKDirectionalChannelInfo this_ptr_conv;
16493         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16494         this_ptr_conv.is_owned = false;
16495         jlong ret_val = DirectionalChannelInfo_get_htlc_minimum_msat(&this_ptr_conv);
16496         return ret_val;
16497 }
16498
16499 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_DirectionalChannelInfo_1set_1htlc_1minimum_1msat(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
16500         LDKDirectionalChannelInfo this_ptr_conv;
16501         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16502         this_ptr_conv.is_owned = false;
16503         DirectionalChannelInfo_set_htlc_minimum_msat(&this_ptr_conv, val);
16504 }
16505
16506 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_DirectionalChannelInfo_1get_1fees(JNIEnv * _env, jclass _b, jlong this_ptr) {
16507         LDKDirectionalChannelInfo this_ptr_conv;
16508         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16509         this_ptr_conv.is_owned = false;
16510         LDKRoutingFees ret_var = DirectionalChannelInfo_get_fees(&this_ptr_conv);
16511         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
16512         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
16513         long ret_ref = (long)ret_var.inner;
16514         if (ret_var.is_owned) {
16515                 ret_ref |= 1;
16516         }
16517         return ret_ref;
16518 }
16519
16520 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_DirectionalChannelInfo_1set_1fees(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
16521         LDKDirectionalChannelInfo this_ptr_conv;
16522         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16523         this_ptr_conv.is_owned = false;
16524         LDKRoutingFees val_conv;
16525         val_conv.inner = (void*)(val & (~1));
16526         val_conv.is_owned = (val & 1) || (val == 0);
16527         if (val_conv.inner != NULL)
16528                 val_conv = RoutingFees_clone(&val_conv);
16529         DirectionalChannelInfo_set_fees(&this_ptr_conv, val_conv);
16530 }
16531
16532 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_DirectionalChannelInfo_1get_1last_1update_1message(JNIEnv * _env, jclass _b, jlong this_ptr) {
16533         LDKDirectionalChannelInfo this_ptr_conv;
16534         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16535         this_ptr_conv.is_owned = false;
16536         LDKChannelUpdate ret_var = DirectionalChannelInfo_get_last_update_message(&this_ptr_conv);
16537         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
16538         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
16539         long ret_ref = (long)ret_var.inner;
16540         if (ret_var.is_owned) {
16541                 ret_ref |= 1;
16542         }
16543         return ret_ref;
16544 }
16545
16546 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_DirectionalChannelInfo_1set_1last_1update_1message(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
16547         LDKDirectionalChannelInfo this_ptr_conv;
16548         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16549         this_ptr_conv.is_owned = false;
16550         LDKChannelUpdate val_conv;
16551         val_conv.inner = (void*)(val & (~1));
16552         val_conv.is_owned = (val & 1) || (val == 0);
16553         if (val_conv.inner != NULL)
16554                 val_conv = ChannelUpdate_clone(&val_conv);
16555         DirectionalChannelInfo_set_last_update_message(&this_ptr_conv, val_conv);
16556 }
16557
16558 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_DirectionalChannelInfo_1write(JNIEnv * _env, jclass _b, jlong obj) {
16559         LDKDirectionalChannelInfo obj_conv;
16560         obj_conv.inner = (void*)(obj & (~1));
16561         obj_conv.is_owned = false;
16562         LDKCVec_u8Z arg_var = DirectionalChannelInfo_write(&obj_conv);
16563         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
16564         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
16565         CVec_u8Z_free(arg_var);
16566         return arg_arr;
16567 }
16568
16569 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_DirectionalChannelInfo_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
16570         LDKu8slice ser_ref;
16571         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
16572         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
16573         LDKDirectionalChannelInfo ret_var = DirectionalChannelInfo_read(ser_ref);
16574         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
16575         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
16576         long ret_ref = (long)ret_var.inner;
16577         if (ret_var.is_owned) {
16578                 ret_ref |= 1;
16579         }
16580         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
16581         return ret_ref;
16582 }
16583
16584 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelInfo_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
16585         LDKChannelInfo this_ptr_conv;
16586         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16587         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
16588         ChannelInfo_free(this_ptr_conv);
16589 }
16590
16591 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelInfo_1get_1features(JNIEnv * _env, jclass _b, jlong this_ptr) {
16592         LDKChannelInfo this_ptr_conv;
16593         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16594         this_ptr_conv.is_owned = false;
16595         LDKChannelFeatures ret_var = ChannelInfo_get_features(&this_ptr_conv);
16596         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
16597         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
16598         long ret_ref = (long)ret_var.inner;
16599         if (ret_var.is_owned) {
16600                 ret_ref |= 1;
16601         }
16602         return ret_ref;
16603 }
16604
16605 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelInfo_1set_1features(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
16606         LDKChannelInfo this_ptr_conv;
16607         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16608         this_ptr_conv.is_owned = false;
16609         LDKChannelFeatures val_conv;
16610         val_conv.inner = (void*)(val & (~1));
16611         val_conv.is_owned = (val & 1) || (val == 0);
16612         // Warning: we may need a move here but can't clone!
16613         ChannelInfo_set_features(&this_ptr_conv, val_conv);
16614 }
16615
16616 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelInfo_1get_1node_1one(JNIEnv * _env, jclass _b, jlong this_ptr) {
16617         LDKChannelInfo this_ptr_conv;
16618         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16619         this_ptr_conv.is_owned = false;
16620         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
16621         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, ChannelInfo_get_node_one(&this_ptr_conv).compressed_form);
16622         return arg_arr;
16623 }
16624
16625 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelInfo_1set_1node_1one(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
16626         LDKChannelInfo this_ptr_conv;
16627         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16628         this_ptr_conv.is_owned = false;
16629         LDKPublicKey val_ref;
16630         CHECK((*_env)->GetArrayLength (_env, val) == 33);
16631         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
16632         ChannelInfo_set_node_one(&this_ptr_conv, val_ref);
16633 }
16634
16635 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelInfo_1get_1one_1to_1two(JNIEnv * _env, jclass _b, jlong this_ptr) {
16636         LDKChannelInfo this_ptr_conv;
16637         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16638         this_ptr_conv.is_owned = false;
16639         LDKDirectionalChannelInfo ret_var = ChannelInfo_get_one_to_two(&this_ptr_conv);
16640         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
16641         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
16642         long ret_ref = (long)ret_var.inner;
16643         if (ret_var.is_owned) {
16644                 ret_ref |= 1;
16645         }
16646         return ret_ref;
16647 }
16648
16649 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelInfo_1set_1one_1to_1two(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
16650         LDKChannelInfo this_ptr_conv;
16651         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16652         this_ptr_conv.is_owned = false;
16653         LDKDirectionalChannelInfo val_conv;
16654         val_conv.inner = (void*)(val & (~1));
16655         val_conv.is_owned = (val & 1) || (val == 0);
16656         // Warning: we may need a move here but can't clone!
16657         ChannelInfo_set_one_to_two(&this_ptr_conv, val_conv);
16658 }
16659
16660 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelInfo_1get_1node_1two(JNIEnv * _env, jclass _b, jlong this_ptr) {
16661         LDKChannelInfo this_ptr_conv;
16662         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16663         this_ptr_conv.is_owned = false;
16664         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
16665         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, ChannelInfo_get_node_two(&this_ptr_conv).compressed_form);
16666         return arg_arr;
16667 }
16668
16669 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelInfo_1set_1node_1two(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
16670         LDKChannelInfo this_ptr_conv;
16671         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16672         this_ptr_conv.is_owned = false;
16673         LDKPublicKey val_ref;
16674         CHECK((*_env)->GetArrayLength (_env, val) == 33);
16675         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
16676         ChannelInfo_set_node_two(&this_ptr_conv, val_ref);
16677 }
16678
16679 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelInfo_1get_1two_1to_1one(JNIEnv * _env, jclass _b, jlong this_ptr) {
16680         LDKChannelInfo this_ptr_conv;
16681         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16682         this_ptr_conv.is_owned = false;
16683         LDKDirectionalChannelInfo ret_var = ChannelInfo_get_two_to_one(&this_ptr_conv);
16684         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
16685         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
16686         long ret_ref = (long)ret_var.inner;
16687         if (ret_var.is_owned) {
16688                 ret_ref |= 1;
16689         }
16690         return ret_ref;
16691 }
16692
16693 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelInfo_1set_1two_1to_1one(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
16694         LDKChannelInfo this_ptr_conv;
16695         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16696         this_ptr_conv.is_owned = false;
16697         LDKDirectionalChannelInfo val_conv;
16698         val_conv.inner = (void*)(val & (~1));
16699         val_conv.is_owned = (val & 1) || (val == 0);
16700         // Warning: we may need a move here but can't clone!
16701         ChannelInfo_set_two_to_one(&this_ptr_conv, val_conv);
16702 }
16703
16704 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelInfo_1get_1announcement_1message(JNIEnv * _env, jclass _b, jlong this_ptr) {
16705         LDKChannelInfo this_ptr_conv;
16706         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16707         this_ptr_conv.is_owned = false;
16708         LDKChannelAnnouncement ret_var = ChannelInfo_get_announcement_message(&this_ptr_conv);
16709         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
16710         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
16711         long ret_ref = (long)ret_var.inner;
16712         if (ret_var.is_owned) {
16713                 ret_ref |= 1;
16714         }
16715         return ret_ref;
16716 }
16717
16718 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelInfo_1set_1announcement_1message(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
16719         LDKChannelInfo this_ptr_conv;
16720         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16721         this_ptr_conv.is_owned = false;
16722         LDKChannelAnnouncement val_conv;
16723         val_conv.inner = (void*)(val & (~1));
16724         val_conv.is_owned = (val & 1) || (val == 0);
16725         if (val_conv.inner != NULL)
16726                 val_conv = ChannelAnnouncement_clone(&val_conv);
16727         ChannelInfo_set_announcement_message(&this_ptr_conv, val_conv);
16728 }
16729
16730 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelInfo_1write(JNIEnv * _env, jclass _b, jlong obj) {
16731         LDKChannelInfo obj_conv;
16732         obj_conv.inner = (void*)(obj & (~1));
16733         obj_conv.is_owned = false;
16734         LDKCVec_u8Z arg_var = ChannelInfo_write(&obj_conv);
16735         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
16736         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
16737         CVec_u8Z_free(arg_var);
16738         return arg_arr;
16739 }
16740
16741 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelInfo_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
16742         LDKu8slice ser_ref;
16743         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
16744         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
16745         LDKChannelInfo ret_var = ChannelInfo_read(ser_ref);
16746         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
16747         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
16748         long ret_ref = (long)ret_var.inner;
16749         if (ret_var.is_owned) {
16750                 ret_ref |= 1;
16751         }
16752         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
16753         return ret_ref;
16754 }
16755
16756 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RoutingFees_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
16757         LDKRoutingFees this_ptr_conv;
16758         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16759         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
16760         RoutingFees_free(this_ptr_conv);
16761 }
16762
16763 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_RoutingFees_1clone(JNIEnv * _env, jclass _b, jlong orig) {
16764         LDKRoutingFees orig_conv;
16765         orig_conv.inner = (void*)(orig & (~1));
16766         orig_conv.is_owned = false;
16767         LDKRoutingFees ret_var = RoutingFees_clone(&orig_conv);
16768         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
16769         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
16770         long ret_ref = (long)ret_var.inner;
16771         if (ret_var.is_owned) {
16772                 ret_ref |= 1;
16773         }
16774         return ret_ref;
16775 }
16776
16777 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_RoutingFees_1get_1base_1msat(JNIEnv * _env, jclass _b, jlong this_ptr) {
16778         LDKRoutingFees this_ptr_conv;
16779         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16780         this_ptr_conv.is_owned = false;
16781         jint ret_val = RoutingFees_get_base_msat(&this_ptr_conv);
16782         return ret_val;
16783 }
16784
16785 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RoutingFees_1set_1base_1msat(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
16786         LDKRoutingFees this_ptr_conv;
16787         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16788         this_ptr_conv.is_owned = false;
16789         RoutingFees_set_base_msat(&this_ptr_conv, val);
16790 }
16791
16792 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_RoutingFees_1get_1proportional_1millionths(JNIEnv * _env, jclass _b, jlong this_ptr) {
16793         LDKRoutingFees this_ptr_conv;
16794         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16795         this_ptr_conv.is_owned = false;
16796         jint ret_val = RoutingFees_get_proportional_millionths(&this_ptr_conv);
16797         return ret_val;
16798 }
16799
16800 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RoutingFees_1set_1proportional_1millionths(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
16801         LDKRoutingFees this_ptr_conv;
16802         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16803         this_ptr_conv.is_owned = false;
16804         RoutingFees_set_proportional_millionths(&this_ptr_conv, val);
16805 }
16806
16807 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_RoutingFees_1new(JNIEnv * _env, jclass _b, jint base_msat_arg, jint proportional_millionths_arg) {
16808         LDKRoutingFees ret_var = RoutingFees_new(base_msat_arg, proportional_millionths_arg);
16809         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
16810         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
16811         long ret_ref = (long)ret_var.inner;
16812         if (ret_var.is_owned) {
16813                 ret_ref |= 1;
16814         }
16815         return ret_ref;
16816 }
16817
16818 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_RoutingFees_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
16819         LDKu8slice ser_ref;
16820         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
16821         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
16822         LDKCResult_RoutingFeesDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_RoutingFeesDecodeErrorZ), "LDKCResult_RoutingFeesDecodeErrorZ");
16823         *ret_conv = RoutingFees_read(ser_ref);
16824         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
16825         return (long)ret_conv;
16826 }
16827
16828 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_RoutingFees_1write(JNIEnv * _env, jclass _b, jlong obj) {
16829         LDKRoutingFees obj_conv;
16830         obj_conv.inner = (void*)(obj & (~1));
16831         obj_conv.is_owned = false;
16832         LDKCVec_u8Z arg_var = RoutingFees_write(&obj_conv);
16833         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
16834         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
16835         CVec_u8Z_free(arg_var);
16836         return arg_arr;
16837 }
16838
16839 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NodeAnnouncementInfo_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
16840         LDKNodeAnnouncementInfo this_ptr_conv;
16841         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16842         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
16843         NodeAnnouncementInfo_free(this_ptr_conv);
16844 }
16845
16846 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_NodeAnnouncementInfo_1get_1features(JNIEnv * _env, jclass _b, jlong this_ptr) {
16847         LDKNodeAnnouncementInfo this_ptr_conv;
16848         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16849         this_ptr_conv.is_owned = false;
16850         LDKNodeFeatures ret_var = NodeAnnouncementInfo_get_features(&this_ptr_conv);
16851         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
16852         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
16853         long ret_ref = (long)ret_var.inner;
16854         if (ret_var.is_owned) {
16855                 ret_ref |= 1;
16856         }
16857         return ret_ref;
16858 }
16859
16860 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NodeAnnouncementInfo_1set_1features(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
16861         LDKNodeAnnouncementInfo this_ptr_conv;
16862         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16863         this_ptr_conv.is_owned = false;
16864         LDKNodeFeatures val_conv;
16865         val_conv.inner = (void*)(val & (~1));
16866         val_conv.is_owned = (val & 1) || (val == 0);
16867         // Warning: we may need a move here but can't clone!
16868         NodeAnnouncementInfo_set_features(&this_ptr_conv, val_conv);
16869 }
16870
16871 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_NodeAnnouncementInfo_1get_1last_1update(JNIEnv * _env, jclass _b, jlong this_ptr) {
16872         LDKNodeAnnouncementInfo this_ptr_conv;
16873         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16874         this_ptr_conv.is_owned = false;
16875         jint ret_val = NodeAnnouncementInfo_get_last_update(&this_ptr_conv);
16876         return ret_val;
16877 }
16878
16879 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NodeAnnouncementInfo_1set_1last_1update(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
16880         LDKNodeAnnouncementInfo this_ptr_conv;
16881         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16882         this_ptr_conv.is_owned = false;
16883         NodeAnnouncementInfo_set_last_update(&this_ptr_conv, val);
16884 }
16885
16886 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_NodeAnnouncementInfo_1get_1rgb(JNIEnv * _env, jclass _b, jlong this_ptr) {
16887         LDKNodeAnnouncementInfo this_ptr_conv;
16888         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16889         this_ptr_conv.is_owned = false;
16890         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 3);
16891         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 3, *NodeAnnouncementInfo_get_rgb(&this_ptr_conv));
16892         return ret_arr;
16893 }
16894
16895 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NodeAnnouncementInfo_1set_1rgb(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
16896         LDKNodeAnnouncementInfo this_ptr_conv;
16897         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16898         this_ptr_conv.is_owned = false;
16899         LDKThreeBytes val_ref;
16900         CHECK((*_env)->GetArrayLength (_env, val) == 3);
16901         (*_env)->GetByteArrayRegion (_env, val, 0, 3, val_ref.data);
16902         NodeAnnouncementInfo_set_rgb(&this_ptr_conv, val_ref);
16903 }
16904
16905 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_NodeAnnouncementInfo_1get_1alias(JNIEnv * _env, jclass _b, jlong this_ptr) {
16906         LDKNodeAnnouncementInfo this_ptr_conv;
16907         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16908         this_ptr_conv.is_owned = false;
16909         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
16910         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *NodeAnnouncementInfo_get_alias(&this_ptr_conv));
16911         return ret_arr;
16912 }
16913
16914 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NodeAnnouncementInfo_1set_1alias(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
16915         LDKNodeAnnouncementInfo this_ptr_conv;
16916         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16917         this_ptr_conv.is_owned = false;
16918         LDKThirtyTwoBytes val_ref;
16919         CHECK((*_env)->GetArrayLength (_env, val) == 32);
16920         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
16921         NodeAnnouncementInfo_set_alias(&this_ptr_conv, val_ref);
16922 }
16923
16924 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NodeAnnouncementInfo_1set_1addresses(JNIEnv * _env, jclass _b, jlong this_ptr, jlongArray val) {
16925         LDKNodeAnnouncementInfo this_ptr_conv;
16926         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16927         this_ptr_conv.is_owned = false;
16928         LDKCVec_NetAddressZ val_constr;
16929         val_constr.datalen = (*_env)->GetArrayLength (_env, val);
16930         if (val_constr.datalen > 0)
16931                 val_constr.data = MALLOC(val_constr.datalen * sizeof(LDKNetAddress), "LDKCVec_NetAddressZ Elements");
16932         else
16933                 val_constr.data = NULL;
16934         long* val_vals = (*_env)->GetLongArrayElements (_env, val, NULL);
16935         for (size_t m = 0; m < val_constr.datalen; m++) {
16936                 long arr_conv_12 = val_vals[m];
16937                 LDKNetAddress arr_conv_12_conv = *(LDKNetAddress*)arr_conv_12;
16938                 FREE((void*)arr_conv_12);
16939                 val_constr.data[m] = arr_conv_12_conv;
16940         }
16941         (*_env)->ReleaseLongArrayElements (_env, val, val_vals, 0);
16942         NodeAnnouncementInfo_set_addresses(&this_ptr_conv, val_constr);
16943 }
16944
16945 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_NodeAnnouncementInfo_1get_1announcement_1message(JNIEnv * _env, jclass _b, jlong this_ptr) {
16946         LDKNodeAnnouncementInfo this_ptr_conv;
16947         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16948         this_ptr_conv.is_owned = false;
16949         LDKNodeAnnouncement ret_var = NodeAnnouncementInfo_get_announcement_message(&this_ptr_conv);
16950         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
16951         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
16952         long ret_ref = (long)ret_var.inner;
16953         if (ret_var.is_owned) {
16954                 ret_ref |= 1;
16955         }
16956         return ret_ref;
16957 }
16958
16959 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NodeAnnouncementInfo_1set_1announcement_1message(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
16960         LDKNodeAnnouncementInfo this_ptr_conv;
16961         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16962         this_ptr_conv.is_owned = false;
16963         LDKNodeAnnouncement val_conv;
16964         val_conv.inner = (void*)(val & (~1));
16965         val_conv.is_owned = (val & 1) || (val == 0);
16966         if (val_conv.inner != NULL)
16967                 val_conv = NodeAnnouncement_clone(&val_conv);
16968         NodeAnnouncementInfo_set_announcement_message(&this_ptr_conv, val_conv);
16969 }
16970
16971 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_NodeAnnouncementInfo_1new(JNIEnv * _env, jclass _b, jlong features_arg, jint last_update_arg, jbyteArray rgb_arg, jbyteArray alias_arg, jlongArray addresses_arg, jlong announcement_message_arg) {
16972         LDKNodeFeatures features_arg_conv;
16973         features_arg_conv.inner = (void*)(features_arg & (~1));
16974         features_arg_conv.is_owned = (features_arg & 1) || (features_arg == 0);
16975         // Warning: we may need a move here but can't clone!
16976         LDKThreeBytes rgb_arg_ref;
16977         CHECK((*_env)->GetArrayLength (_env, rgb_arg) == 3);
16978         (*_env)->GetByteArrayRegion (_env, rgb_arg, 0, 3, rgb_arg_ref.data);
16979         LDKThirtyTwoBytes alias_arg_ref;
16980         CHECK((*_env)->GetArrayLength (_env, alias_arg) == 32);
16981         (*_env)->GetByteArrayRegion (_env, alias_arg, 0, 32, alias_arg_ref.data);
16982         LDKCVec_NetAddressZ addresses_arg_constr;
16983         addresses_arg_constr.datalen = (*_env)->GetArrayLength (_env, addresses_arg);
16984         if (addresses_arg_constr.datalen > 0)
16985                 addresses_arg_constr.data = MALLOC(addresses_arg_constr.datalen * sizeof(LDKNetAddress), "LDKCVec_NetAddressZ Elements");
16986         else
16987                 addresses_arg_constr.data = NULL;
16988         long* addresses_arg_vals = (*_env)->GetLongArrayElements (_env, addresses_arg, NULL);
16989         for (size_t m = 0; m < addresses_arg_constr.datalen; m++) {
16990                 long arr_conv_12 = addresses_arg_vals[m];
16991                 LDKNetAddress arr_conv_12_conv = *(LDKNetAddress*)arr_conv_12;
16992                 FREE((void*)arr_conv_12);
16993                 addresses_arg_constr.data[m] = arr_conv_12_conv;
16994         }
16995         (*_env)->ReleaseLongArrayElements (_env, addresses_arg, addresses_arg_vals, 0);
16996         LDKNodeAnnouncement announcement_message_arg_conv;
16997         announcement_message_arg_conv.inner = (void*)(announcement_message_arg & (~1));
16998         announcement_message_arg_conv.is_owned = (announcement_message_arg & 1) || (announcement_message_arg == 0);
16999         if (announcement_message_arg_conv.inner != NULL)
17000                 announcement_message_arg_conv = NodeAnnouncement_clone(&announcement_message_arg_conv);
17001         LDKNodeAnnouncementInfo ret_var = NodeAnnouncementInfo_new(features_arg_conv, last_update_arg, rgb_arg_ref, alias_arg_ref, addresses_arg_constr, announcement_message_arg_conv);
17002         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
17003         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
17004         long ret_ref = (long)ret_var.inner;
17005         if (ret_var.is_owned) {
17006                 ret_ref |= 1;
17007         }
17008         return ret_ref;
17009 }
17010
17011 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_NodeAnnouncementInfo_1write(JNIEnv * _env, jclass _b, jlong obj) {
17012         LDKNodeAnnouncementInfo obj_conv;
17013         obj_conv.inner = (void*)(obj & (~1));
17014         obj_conv.is_owned = false;
17015         LDKCVec_u8Z arg_var = NodeAnnouncementInfo_write(&obj_conv);
17016         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
17017         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
17018         CVec_u8Z_free(arg_var);
17019         return arg_arr;
17020 }
17021
17022 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_NodeAnnouncementInfo_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
17023         LDKu8slice ser_ref;
17024         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
17025         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
17026         LDKCResult_NodeAnnouncementInfoDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NodeAnnouncementInfoDecodeErrorZ), "LDKCResult_NodeAnnouncementInfoDecodeErrorZ");
17027         *ret_conv = NodeAnnouncementInfo_read(ser_ref);
17028         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
17029         return (long)ret_conv;
17030 }
17031
17032 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NodeInfo_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
17033         LDKNodeInfo this_ptr_conv;
17034         this_ptr_conv.inner = (void*)(this_ptr & (~1));
17035         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
17036         NodeInfo_free(this_ptr_conv);
17037 }
17038
17039 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NodeInfo_1set_1channels(JNIEnv * _env, jclass _b, jlong this_ptr, jlongArray val) {
17040         LDKNodeInfo this_ptr_conv;
17041         this_ptr_conv.inner = (void*)(this_ptr & (~1));
17042         this_ptr_conv.is_owned = false;
17043         LDKCVec_u64Z val_constr;
17044         val_constr.datalen = (*_env)->GetArrayLength (_env, val);
17045         if (val_constr.datalen > 0)
17046                 val_constr.data = MALLOC(val_constr.datalen * sizeof(jlong), "LDKCVec_u64Z Elements");
17047         else
17048                 val_constr.data = NULL;
17049         long* val_vals = (*_env)->GetLongArrayElements (_env, val, NULL);
17050         for (size_t g = 0; g < val_constr.datalen; g++) {
17051                 long arr_conv_6 = val_vals[g];
17052                 val_constr.data[g] = arr_conv_6;
17053         }
17054         (*_env)->ReleaseLongArrayElements (_env, val, val_vals, 0);
17055         NodeInfo_set_channels(&this_ptr_conv, val_constr);
17056 }
17057
17058 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_NodeInfo_1get_1lowest_1inbound_1channel_1fees(JNIEnv * _env, jclass _b, jlong this_ptr) {
17059         LDKNodeInfo this_ptr_conv;
17060         this_ptr_conv.inner = (void*)(this_ptr & (~1));
17061         this_ptr_conv.is_owned = false;
17062         LDKRoutingFees ret_var = NodeInfo_get_lowest_inbound_channel_fees(&this_ptr_conv);
17063         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
17064         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
17065         long ret_ref = (long)ret_var.inner;
17066         if (ret_var.is_owned) {
17067                 ret_ref |= 1;
17068         }
17069         return ret_ref;
17070 }
17071
17072 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NodeInfo_1set_1lowest_1inbound_1channel_1fees(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
17073         LDKNodeInfo this_ptr_conv;
17074         this_ptr_conv.inner = (void*)(this_ptr & (~1));
17075         this_ptr_conv.is_owned = false;
17076         LDKRoutingFees val_conv;
17077         val_conv.inner = (void*)(val & (~1));
17078         val_conv.is_owned = (val & 1) || (val == 0);
17079         if (val_conv.inner != NULL)
17080                 val_conv = RoutingFees_clone(&val_conv);
17081         NodeInfo_set_lowest_inbound_channel_fees(&this_ptr_conv, val_conv);
17082 }
17083
17084 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_NodeInfo_1get_1announcement_1info(JNIEnv * _env, jclass _b, jlong this_ptr) {
17085         LDKNodeInfo this_ptr_conv;
17086         this_ptr_conv.inner = (void*)(this_ptr & (~1));
17087         this_ptr_conv.is_owned = false;
17088         LDKNodeAnnouncementInfo ret_var = NodeInfo_get_announcement_info(&this_ptr_conv);
17089         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
17090         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
17091         long ret_ref = (long)ret_var.inner;
17092         if (ret_var.is_owned) {
17093                 ret_ref |= 1;
17094         }
17095         return ret_ref;
17096 }
17097
17098 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NodeInfo_1set_1announcement_1info(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
17099         LDKNodeInfo this_ptr_conv;
17100         this_ptr_conv.inner = (void*)(this_ptr & (~1));
17101         this_ptr_conv.is_owned = false;
17102         LDKNodeAnnouncementInfo val_conv;
17103         val_conv.inner = (void*)(val & (~1));
17104         val_conv.is_owned = (val & 1) || (val == 0);
17105         // Warning: we may need a move here but can't clone!
17106         NodeInfo_set_announcement_info(&this_ptr_conv, val_conv);
17107 }
17108
17109 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_NodeInfo_1new(JNIEnv * _env, jclass _b, jlongArray channels_arg, jlong lowest_inbound_channel_fees_arg, jlong announcement_info_arg) {
17110         LDKCVec_u64Z channels_arg_constr;
17111         channels_arg_constr.datalen = (*_env)->GetArrayLength (_env, channels_arg);
17112         if (channels_arg_constr.datalen > 0)
17113                 channels_arg_constr.data = MALLOC(channels_arg_constr.datalen * sizeof(jlong), "LDKCVec_u64Z Elements");
17114         else
17115                 channels_arg_constr.data = NULL;
17116         long* channels_arg_vals = (*_env)->GetLongArrayElements (_env, channels_arg, NULL);
17117         for (size_t g = 0; g < channels_arg_constr.datalen; g++) {
17118                 long arr_conv_6 = channels_arg_vals[g];
17119                 channels_arg_constr.data[g] = arr_conv_6;
17120         }
17121         (*_env)->ReleaseLongArrayElements (_env, channels_arg, channels_arg_vals, 0);
17122         LDKRoutingFees lowest_inbound_channel_fees_arg_conv;
17123         lowest_inbound_channel_fees_arg_conv.inner = (void*)(lowest_inbound_channel_fees_arg & (~1));
17124         lowest_inbound_channel_fees_arg_conv.is_owned = (lowest_inbound_channel_fees_arg & 1) || (lowest_inbound_channel_fees_arg == 0);
17125         if (lowest_inbound_channel_fees_arg_conv.inner != NULL)
17126                 lowest_inbound_channel_fees_arg_conv = RoutingFees_clone(&lowest_inbound_channel_fees_arg_conv);
17127         LDKNodeAnnouncementInfo announcement_info_arg_conv;
17128         announcement_info_arg_conv.inner = (void*)(announcement_info_arg & (~1));
17129         announcement_info_arg_conv.is_owned = (announcement_info_arg & 1) || (announcement_info_arg == 0);
17130         // Warning: we may need a move here but can't clone!
17131         LDKNodeInfo ret_var = NodeInfo_new(channels_arg_constr, lowest_inbound_channel_fees_arg_conv, announcement_info_arg_conv);
17132         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
17133         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
17134         long ret_ref = (long)ret_var.inner;
17135         if (ret_var.is_owned) {
17136                 ret_ref |= 1;
17137         }
17138         return ret_ref;
17139 }
17140
17141 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_NodeInfo_1write(JNIEnv * _env, jclass _b, jlong obj) {
17142         LDKNodeInfo obj_conv;
17143         obj_conv.inner = (void*)(obj & (~1));
17144         obj_conv.is_owned = false;
17145         LDKCVec_u8Z arg_var = NodeInfo_write(&obj_conv);
17146         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
17147         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
17148         CVec_u8Z_free(arg_var);
17149         return arg_arr;
17150 }
17151
17152 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_NodeInfo_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
17153         LDKu8slice ser_ref;
17154         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
17155         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
17156         LDKCResult_NodeInfoDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NodeInfoDecodeErrorZ), "LDKCResult_NodeInfoDecodeErrorZ");
17157         *ret_conv = NodeInfo_read(ser_ref);
17158         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
17159         return (long)ret_conv;
17160 }
17161
17162 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_NetworkGraph_1write(JNIEnv * _env, jclass _b, jlong obj) {
17163         LDKNetworkGraph obj_conv;
17164         obj_conv.inner = (void*)(obj & (~1));
17165         obj_conv.is_owned = false;
17166         LDKCVec_u8Z arg_var = NetworkGraph_write(&obj_conv);
17167         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
17168         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
17169         CVec_u8Z_free(arg_var);
17170         return arg_arr;
17171 }
17172
17173 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_NetworkGraph_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
17174         LDKu8slice ser_ref;
17175         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
17176         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
17177         LDKCResult_NetworkGraphDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NetworkGraphDecodeErrorZ), "LDKCResult_NetworkGraphDecodeErrorZ");
17178         *ret_conv = NetworkGraph_read(ser_ref);
17179         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
17180         return (long)ret_conv;
17181 }
17182
17183 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_NetworkGraph_1new(JNIEnv * _env, jclass _b, jbyteArray genesis_hash) {
17184         LDKThirtyTwoBytes genesis_hash_ref;
17185         CHECK((*_env)->GetArrayLength (_env, genesis_hash) == 32);
17186         (*_env)->GetByteArrayRegion (_env, genesis_hash, 0, 32, genesis_hash_ref.data);
17187         LDKNetworkGraph ret_var = NetworkGraph_new(genesis_hash_ref);
17188         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
17189         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
17190         long ret_ref = (long)ret_var.inner;
17191         if (ret_var.is_owned) {
17192                 ret_ref |= 1;
17193         }
17194         return ret_ref;
17195 }
17196
17197 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_NetworkGraph_1update_1node_1from_1announcement(JNIEnv * _env, jclass _b, jlong this_arg, jlong msg) {
17198         LDKNetworkGraph this_arg_conv;
17199         this_arg_conv.inner = (void*)(this_arg & (~1));
17200         this_arg_conv.is_owned = false;
17201         LDKNodeAnnouncement msg_conv;
17202         msg_conv.inner = (void*)(msg & (~1));
17203         msg_conv.is_owned = false;
17204         LDKCResult_NoneLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneLightningErrorZ), "LDKCResult_NoneLightningErrorZ");
17205         *ret_conv = NetworkGraph_update_node_from_announcement(&this_arg_conv, &msg_conv);
17206         return (long)ret_conv;
17207 }
17208
17209 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_NetworkGraph_1update_1node_1from_1unsigned_1announcement(JNIEnv * _env, jclass _b, jlong this_arg, jlong msg) {
17210         LDKNetworkGraph this_arg_conv;
17211         this_arg_conv.inner = (void*)(this_arg & (~1));
17212         this_arg_conv.is_owned = false;
17213         LDKUnsignedNodeAnnouncement msg_conv;
17214         msg_conv.inner = (void*)(msg & (~1));
17215         msg_conv.is_owned = false;
17216         LDKCResult_NoneLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneLightningErrorZ), "LDKCResult_NoneLightningErrorZ");
17217         *ret_conv = NetworkGraph_update_node_from_unsigned_announcement(&this_arg_conv, &msg_conv);
17218         return (long)ret_conv;
17219 }
17220
17221 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_NetworkGraph_1update_1channel_1from_1announcement(JNIEnv * _env, jclass _b, jlong this_arg, jlong msg, jlong chain_access) {
17222         LDKNetworkGraph this_arg_conv;
17223         this_arg_conv.inner = (void*)(this_arg & (~1));
17224         this_arg_conv.is_owned = false;
17225         LDKChannelAnnouncement msg_conv;
17226         msg_conv.inner = (void*)(msg & (~1));
17227         msg_conv.is_owned = false;
17228         LDKAccess* chain_access_conv = (LDKAccess*)chain_access;
17229         LDKCResult_NoneLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneLightningErrorZ), "LDKCResult_NoneLightningErrorZ");
17230         *ret_conv = NetworkGraph_update_channel_from_announcement(&this_arg_conv, &msg_conv, chain_access_conv);
17231         return (long)ret_conv;
17232 }
17233
17234 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_NetworkGraph_1update_1channel_1from_1unsigned_1announcement(JNIEnv * _env, jclass _b, jlong this_arg, jlong msg, jlong chain_access) {
17235         LDKNetworkGraph this_arg_conv;
17236         this_arg_conv.inner = (void*)(this_arg & (~1));
17237         this_arg_conv.is_owned = false;
17238         LDKUnsignedChannelAnnouncement msg_conv;
17239         msg_conv.inner = (void*)(msg & (~1));
17240         msg_conv.is_owned = false;
17241         LDKAccess* chain_access_conv = (LDKAccess*)chain_access;
17242         LDKCResult_NoneLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneLightningErrorZ), "LDKCResult_NoneLightningErrorZ");
17243         *ret_conv = NetworkGraph_update_channel_from_unsigned_announcement(&this_arg_conv, &msg_conv, chain_access_conv);
17244         return (long)ret_conv;
17245 }
17246
17247 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NetworkGraph_1close_1channel_1from_1update(JNIEnv * _env, jclass _b, jlong this_arg, jlong short_channel_id, jboolean is_permanent) {
17248         LDKNetworkGraph this_arg_conv;
17249         this_arg_conv.inner = (void*)(this_arg & (~1));
17250         this_arg_conv.is_owned = false;
17251         NetworkGraph_close_channel_from_update(&this_arg_conv, short_channel_id, is_permanent);
17252 }
17253
17254 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_NetworkGraph_1update_1channel(JNIEnv * _env, jclass _b, jlong this_arg, jlong msg) {
17255         LDKNetworkGraph this_arg_conv;
17256         this_arg_conv.inner = (void*)(this_arg & (~1));
17257         this_arg_conv.is_owned = false;
17258         LDKChannelUpdate msg_conv;
17259         msg_conv.inner = (void*)(msg & (~1));
17260         msg_conv.is_owned = false;
17261         LDKCResult_NoneLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneLightningErrorZ), "LDKCResult_NoneLightningErrorZ");
17262         *ret_conv = NetworkGraph_update_channel(&this_arg_conv, &msg_conv);
17263         return (long)ret_conv;
17264 }
17265
17266 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_NetworkGraph_1update_1channel_1unsigned(JNIEnv * _env, jclass _b, jlong this_arg, jlong msg) {
17267         LDKNetworkGraph this_arg_conv;
17268         this_arg_conv.inner = (void*)(this_arg & (~1));
17269         this_arg_conv.is_owned = false;
17270         LDKUnsignedChannelUpdate msg_conv;
17271         msg_conv.inner = (void*)(msg & (~1));
17272         msg_conv.is_owned = false;
17273         LDKCResult_NoneLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneLightningErrorZ), "LDKCResult_NoneLightningErrorZ");
17274         *ret_conv = NetworkGraph_update_channel_unsigned(&this_arg_conv, &msg_conv);
17275         return (long)ret_conv;
17276 }
17277