Fix opaque struct ptr ret-conv, used in jcall arg passing
[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         alloc_freed(ptr);
92         __real_free(ptr);
93 }
94
95 void* __real_realloc(void* ptr, size_t newlen);
96 void* __wrap_realloc(void* ptr, size_t len) {
97         alloc_freed(ptr);
98         void* res = __real_realloc(ptr, len);
99         new_allocation(res, "realloc call");
100         return res;
101 }
102 void __wrap_reallocarray(void* ptr, size_t new_sz) {
103         // Rust doesn't seem to use reallocarray currently
104         assert(false);
105 }
106
107 void __attribute__((destructor)) check_leaks() {
108         for (allocation* a = allocation_ll; a != NULL; a = a->next) {
109                 fprintf(stderr, "%s %p remains:\n", a->struct_name, a->ptr);
110                 backtrace_symbols_fd(a->bt, a->bt_len, STDERR_FILENO);
111                 fprintf(stderr, "\n\n");
112         }
113         DO_ASSERT(allocation_ll == NULL);
114 }
115 static jclass arr_of_B_clz = NULL;
116 JNIEXPORT void Java_org_ldk_impl_bindings_init_1class_1cache(JNIEnv * env, jclass _b) {
117         arr_of_B_clz = (*env)->FindClass(env, "[B");
118         CHECK(arr_of_B_clz != NULL);
119         arr_of_B_clz = (*env)->NewGlobalRef(env, arr_of_B_clz);
120 }
121
122 static jmethodID ordinal_meth = NULL;
123 static jmethodID slicedef_meth = NULL;
124 static jclass slicedef_cls = NULL;
125 JNIEXPORT void Java_org_ldk_impl_bindings_init(JNIEnv * env, jclass _b, jclass enum_class, jclass slicedef_class) {
126         ordinal_meth = (*env)->GetMethodID(env, enum_class, "ordinal", "()I");
127         CHECK(ordinal_meth != NULL);
128         slicedef_meth = (*env)->GetMethodID(env, slicedef_class, "<init>", "(JJJ)V");
129         CHECK(slicedef_meth != NULL);
130         slicedef_cls = (*env)->NewGlobalRef(env, slicedef_class);
131         CHECK(slicedef_cls != NULL);
132 }
133
134 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_deref_1bool (JNIEnv * env, jclass _a, jlong ptr) {
135         return *((bool*)ptr);
136 }
137 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_deref_1long (JNIEnv * env, jclass _a, jlong ptr) {
138         return *((long*)ptr);
139 }
140 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_free_1heap_1ptr (JNIEnv * env, jclass _a, jlong ptr) {
141         FREE((void*)ptr);
142 }
143 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_read_1bytes (JNIEnv * _env, jclass _b, jlong ptr, jlong len) {
144         jbyteArray ret_arr = (*_env)->NewByteArray(_env, len);
145         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, len, (unsigned char*)ptr);
146         return ret_arr;
147 }
148 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_get_1u8_1slice_1bytes (JNIEnv * _env, jclass _b, jlong slice_ptr) {
149         LDKu8slice *slice = (LDKu8slice*)slice_ptr;
150         jbyteArray ret_arr = (*_env)->NewByteArray(_env, slice->datalen);
151         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, slice->datalen, slice->data);
152         return ret_arr;
153 }
154 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_bytes_1to_1u8_1vec (JNIEnv * _env, jclass _b, jbyteArray bytes) {
155         LDKCVec_u8Z *vec = (LDKCVec_u8Z*)MALLOC(sizeof(LDKCVec_u8Z), "LDKCVec_u8");
156         vec->datalen = (*_env)->GetArrayLength(_env, bytes);
157         vec->data = (uint8_t*)MALLOC(vec->datalen, "LDKCVec_u8Z Bytes");
158         (*_env)->GetByteArrayRegion (_env, bytes, 0, vec->datalen, vec->data);
159         return (long)vec;
160 }
161 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_txpointer_1get_1buffer (JNIEnv * env, jclass _b, jlong ptr) {
162         LDKTransaction *txdata = (LDKTransaction*)ptr;
163         LDKu8slice slice;
164         slice.data = txdata->data;
165         slice.datalen = txdata->datalen;
166         return Java_org_ldk_impl_bindings_get_1u8_1slice_1bytes(env, _b, (long)&slice);
167 }
168 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_new_1txpointer_1copy_1data (JNIEnv * env, jclass _b, jbyteArray bytes) {
169         LDKTransaction *txdata = (LDKTransaction*)MALLOC(sizeof(LDKTransaction), "LDKTransaction");
170         txdata->datalen = (*env)->GetArrayLength(env, bytes);
171         txdata->data = (uint8_t*)MALLOC(txdata->datalen, "Tx Data Bytes");
172         txdata->data_is_owned = false;
173         (*env)->GetByteArrayRegion (env, bytes, 0, txdata->datalen, txdata->data);
174         return (long)txdata;
175 }
176 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_txpointer_1free (JNIEnv * env, jclass _b, jlong ptr) {
177         LDKTransaction *tx = (LDKTransaction*)ptr;
178         tx->data_is_owned = true;
179         Transaction_free(*tx);
180         FREE((void*)ptr);
181 }
182 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_vec_1slice_1len (JNIEnv * env, jclass _a, jlong ptr) {
183         // Check offsets of a few Vec types are all consistent as we're meant to be generic across types
184         _Static_assert(offsetof(LDKCVec_u8Z, datalen) == offsetof(LDKCVec_SignatureZ, datalen), "Vec<*> needs to be mapped identically");
185         _Static_assert(offsetof(LDKCVec_u8Z, datalen) == offsetof(LDKCVec_MessageSendEventZ, datalen), "Vec<*> needs to be mapped identically");
186         _Static_assert(offsetof(LDKCVec_u8Z, datalen) == offsetof(LDKCVec_EventZ, datalen), "Vec<*> needs to be mapped identically");
187         _Static_assert(offsetof(LDKCVec_u8Z, datalen) == offsetof(LDKCVec_C2Tuple_usizeTransactionZZ, datalen), "Vec<*> needs to be mapped identically");
188         LDKCVec_u8Z *vec = (LDKCVec_u8Z*)ptr;
189         return (long)vec->datalen;
190 }
191 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_new_1empty_1slice_1vec (JNIEnv * _env, jclass _b) {
192         // Check sizes of a few Vec types are all consistent as we're meant to be generic across types
193         _Static_assert(sizeof(LDKCVec_u8Z) == sizeof(LDKCVec_SignatureZ), "Vec<*> needs to be mapped identically");
194         _Static_assert(sizeof(LDKCVec_u8Z) == sizeof(LDKCVec_MessageSendEventZ), "Vec<*> needs to be mapped identically");
195         _Static_assert(sizeof(LDKCVec_u8Z) == sizeof(LDKCVec_EventZ), "Vec<*> needs to be mapped identically");
196         _Static_assert(sizeof(LDKCVec_u8Z) == sizeof(LDKCVec_C2Tuple_usizeTransactionZZ), "Vec<*> needs to be mapped identically");
197         LDKCVec_u8Z *vec = (LDKCVec_u8Z*)MALLOC(sizeof(LDKCVec_u8Z), "Empty LDKCVec");
198         vec->data = NULL;
199         vec->datalen = 0;
200         return (long)vec;
201 }
202
203 // We assume that CVec_u8Z and u8slice are the same size and layout (and thus pointers to the two can be mixed)
204 _Static_assert(sizeof(LDKCVec_u8Z) == sizeof(LDKu8slice), "Vec<u8> and [u8] need to have been mapped identically");
205 _Static_assert(offsetof(LDKCVec_u8Z, data) == offsetof(LDKu8slice, data), "Vec<u8> and [u8] need to have been mapped identically");
206 _Static_assert(offsetof(LDKCVec_u8Z, datalen) == offsetof(LDKu8slice, datalen), "Vec<u8> and [u8] need to have been mapped identically");
207
208 static inline LDKAccessError LDKAccessError_from_java(JNIEnv *env, jclass val) {
209         switch ((*env)->CallIntMethod(env, val, ordinal_meth)) {
210                 case 0: return LDKAccessError_UnknownChain;
211                 case 1: return LDKAccessError_UnknownTx;
212         }
213         abort();
214 }
215 static jclass LDKAccessError_class = NULL;
216 static jfieldID LDKAccessError_LDKAccessError_UnknownChain = NULL;
217 static jfieldID LDKAccessError_LDKAccessError_UnknownTx = NULL;
218 JNIEXPORT void JNICALL Java_org_ldk_enums_LDKAccessError_init (JNIEnv * env, jclass clz) {
219         LDKAccessError_class = (*env)->NewGlobalRef(env, clz);
220         CHECK(LDKAccessError_class != NULL);
221         LDKAccessError_LDKAccessError_UnknownChain = (*env)->GetStaticFieldID(env, LDKAccessError_class, "LDKAccessError_UnknownChain", "Lorg/ldk/enums/LDKAccessError;");
222         CHECK(LDKAccessError_LDKAccessError_UnknownChain != NULL);
223         LDKAccessError_LDKAccessError_UnknownTx = (*env)->GetStaticFieldID(env, LDKAccessError_class, "LDKAccessError_UnknownTx", "Lorg/ldk/enums/LDKAccessError;");
224         CHECK(LDKAccessError_LDKAccessError_UnknownTx != NULL);
225 }
226 static inline jclass LDKAccessError_to_java(JNIEnv *env, LDKAccessError val) {
227         switch (val) {
228                 case LDKAccessError_UnknownChain:
229                         return (*env)->GetStaticObjectField(env, LDKAccessError_class, LDKAccessError_LDKAccessError_UnknownChain);
230                 case LDKAccessError_UnknownTx:
231                         return (*env)->GetStaticObjectField(env, LDKAccessError_class, LDKAccessError_LDKAccessError_UnknownTx);
232                 default: abort();
233         }
234 }
235
236 static inline LDKChannelMonitorUpdateErr LDKChannelMonitorUpdateErr_from_java(JNIEnv *env, jclass val) {
237         switch ((*env)->CallIntMethod(env, val, ordinal_meth)) {
238                 case 0: return LDKChannelMonitorUpdateErr_TemporaryFailure;
239                 case 1: return LDKChannelMonitorUpdateErr_PermanentFailure;
240         }
241         abort();
242 }
243 static jclass LDKChannelMonitorUpdateErr_class = NULL;
244 static jfieldID LDKChannelMonitorUpdateErr_LDKChannelMonitorUpdateErr_TemporaryFailure = NULL;
245 static jfieldID LDKChannelMonitorUpdateErr_LDKChannelMonitorUpdateErr_PermanentFailure = NULL;
246 JNIEXPORT void JNICALL Java_org_ldk_enums_LDKChannelMonitorUpdateErr_init (JNIEnv * env, jclass clz) {
247         LDKChannelMonitorUpdateErr_class = (*env)->NewGlobalRef(env, clz);
248         CHECK(LDKChannelMonitorUpdateErr_class != NULL);
249         LDKChannelMonitorUpdateErr_LDKChannelMonitorUpdateErr_TemporaryFailure = (*env)->GetStaticFieldID(env, LDKChannelMonitorUpdateErr_class, "LDKChannelMonitorUpdateErr_TemporaryFailure", "Lorg/ldk/enums/LDKChannelMonitorUpdateErr;");
250         CHECK(LDKChannelMonitorUpdateErr_LDKChannelMonitorUpdateErr_TemporaryFailure != NULL);
251         LDKChannelMonitorUpdateErr_LDKChannelMonitorUpdateErr_PermanentFailure = (*env)->GetStaticFieldID(env, LDKChannelMonitorUpdateErr_class, "LDKChannelMonitorUpdateErr_PermanentFailure", "Lorg/ldk/enums/LDKChannelMonitorUpdateErr;");
252         CHECK(LDKChannelMonitorUpdateErr_LDKChannelMonitorUpdateErr_PermanentFailure != NULL);
253 }
254 static inline jclass LDKChannelMonitorUpdateErr_to_java(JNIEnv *env, LDKChannelMonitorUpdateErr val) {
255         switch (val) {
256                 case LDKChannelMonitorUpdateErr_TemporaryFailure:
257                         return (*env)->GetStaticObjectField(env, LDKChannelMonitorUpdateErr_class, LDKChannelMonitorUpdateErr_LDKChannelMonitorUpdateErr_TemporaryFailure);
258                 case LDKChannelMonitorUpdateErr_PermanentFailure:
259                         return (*env)->GetStaticObjectField(env, LDKChannelMonitorUpdateErr_class, LDKChannelMonitorUpdateErr_LDKChannelMonitorUpdateErr_PermanentFailure);
260                 default: abort();
261         }
262 }
263
264 static inline LDKConfirmationTarget LDKConfirmationTarget_from_java(JNIEnv *env, jclass val) {
265         switch ((*env)->CallIntMethod(env, val, ordinal_meth)) {
266                 case 0: return LDKConfirmationTarget_Background;
267                 case 1: return LDKConfirmationTarget_Normal;
268                 case 2: return LDKConfirmationTarget_HighPriority;
269         }
270         abort();
271 }
272 static jclass LDKConfirmationTarget_class = NULL;
273 static jfieldID LDKConfirmationTarget_LDKConfirmationTarget_Background = NULL;
274 static jfieldID LDKConfirmationTarget_LDKConfirmationTarget_Normal = NULL;
275 static jfieldID LDKConfirmationTarget_LDKConfirmationTarget_HighPriority = NULL;
276 JNIEXPORT void JNICALL Java_org_ldk_enums_LDKConfirmationTarget_init (JNIEnv * env, jclass clz) {
277         LDKConfirmationTarget_class = (*env)->NewGlobalRef(env, clz);
278         CHECK(LDKConfirmationTarget_class != NULL);
279         LDKConfirmationTarget_LDKConfirmationTarget_Background = (*env)->GetStaticFieldID(env, LDKConfirmationTarget_class, "LDKConfirmationTarget_Background", "Lorg/ldk/enums/LDKConfirmationTarget;");
280         CHECK(LDKConfirmationTarget_LDKConfirmationTarget_Background != NULL);
281         LDKConfirmationTarget_LDKConfirmationTarget_Normal = (*env)->GetStaticFieldID(env, LDKConfirmationTarget_class, "LDKConfirmationTarget_Normal", "Lorg/ldk/enums/LDKConfirmationTarget;");
282         CHECK(LDKConfirmationTarget_LDKConfirmationTarget_Normal != NULL);
283         LDKConfirmationTarget_LDKConfirmationTarget_HighPriority = (*env)->GetStaticFieldID(env, LDKConfirmationTarget_class, "LDKConfirmationTarget_HighPriority", "Lorg/ldk/enums/LDKConfirmationTarget;");
284         CHECK(LDKConfirmationTarget_LDKConfirmationTarget_HighPriority != NULL);
285 }
286 static inline jclass LDKConfirmationTarget_to_java(JNIEnv *env, LDKConfirmationTarget val) {
287         switch (val) {
288                 case LDKConfirmationTarget_Background:
289                         return (*env)->GetStaticObjectField(env, LDKConfirmationTarget_class, LDKConfirmationTarget_LDKConfirmationTarget_Background);
290                 case LDKConfirmationTarget_Normal:
291                         return (*env)->GetStaticObjectField(env, LDKConfirmationTarget_class, LDKConfirmationTarget_LDKConfirmationTarget_Normal);
292                 case LDKConfirmationTarget_HighPriority:
293                         return (*env)->GetStaticObjectField(env, LDKConfirmationTarget_class, LDKConfirmationTarget_LDKConfirmationTarget_HighPriority);
294                 default: abort();
295         }
296 }
297
298 static inline LDKLevel LDKLevel_from_java(JNIEnv *env, jclass val) {
299         switch ((*env)->CallIntMethod(env, val, ordinal_meth)) {
300                 case 0: return LDKLevel_Off;
301                 case 1: return LDKLevel_Error;
302                 case 2: return LDKLevel_Warn;
303                 case 3: return LDKLevel_Info;
304                 case 4: return LDKLevel_Debug;
305                 case 5: return LDKLevel_Trace;
306         }
307         abort();
308 }
309 static jclass LDKLevel_class = NULL;
310 static jfieldID LDKLevel_LDKLevel_Off = NULL;
311 static jfieldID LDKLevel_LDKLevel_Error = NULL;
312 static jfieldID LDKLevel_LDKLevel_Warn = NULL;
313 static jfieldID LDKLevel_LDKLevel_Info = NULL;
314 static jfieldID LDKLevel_LDKLevel_Debug = NULL;
315 static jfieldID LDKLevel_LDKLevel_Trace = NULL;
316 JNIEXPORT void JNICALL Java_org_ldk_enums_LDKLevel_init (JNIEnv * env, jclass clz) {
317         LDKLevel_class = (*env)->NewGlobalRef(env, clz);
318         CHECK(LDKLevel_class != NULL);
319         LDKLevel_LDKLevel_Off = (*env)->GetStaticFieldID(env, LDKLevel_class, "LDKLevel_Off", "Lorg/ldk/enums/LDKLevel;");
320         CHECK(LDKLevel_LDKLevel_Off != NULL);
321         LDKLevel_LDKLevel_Error = (*env)->GetStaticFieldID(env, LDKLevel_class, "LDKLevel_Error", "Lorg/ldk/enums/LDKLevel;");
322         CHECK(LDKLevel_LDKLevel_Error != NULL);
323         LDKLevel_LDKLevel_Warn = (*env)->GetStaticFieldID(env, LDKLevel_class, "LDKLevel_Warn", "Lorg/ldk/enums/LDKLevel;");
324         CHECK(LDKLevel_LDKLevel_Warn != NULL);
325         LDKLevel_LDKLevel_Info = (*env)->GetStaticFieldID(env, LDKLevel_class, "LDKLevel_Info", "Lorg/ldk/enums/LDKLevel;");
326         CHECK(LDKLevel_LDKLevel_Info != NULL);
327         LDKLevel_LDKLevel_Debug = (*env)->GetStaticFieldID(env, LDKLevel_class, "LDKLevel_Debug", "Lorg/ldk/enums/LDKLevel;");
328         CHECK(LDKLevel_LDKLevel_Debug != NULL);
329         LDKLevel_LDKLevel_Trace = (*env)->GetStaticFieldID(env, LDKLevel_class, "LDKLevel_Trace", "Lorg/ldk/enums/LDKLevel;");
330         CHECK(LDKLevel_LDKLevel_Trace != NULL);
331 }
332 static inline jclass LDKLevel_to_java(JNIEnv *env, LDKLevel val) {
333         switch (val) {
334                 case LDKLevel_Off:
335                         return (*env)->GetStaticObjectField(env, LDKLevel_class, LDKLevel_LDKLevel_Off);
336                 case LDKLevel_Error:
337                         return (*env)->GetStaticObjectField(env, LDKLevel_class, LDKLevel_LDKLevel_Error);
338                 case LDKLevel_Warn:
339                         return (*env)->GetStaticObjectField(env, LDKLevel_class, LDKLevel_LDKLevel_Warn);
340                 case LDKLevel_Info:
341                         return (*env)->GetStaticObjectField(env, LDKLevel_class, LDKLevel_LDKLevel_Info);
342                 case LDKLevel_Debug:
343                         return (*env)->GetStaticObjectField(env, LDKLevel_class, LDKLevel_LDKLevel_Debug);
344                 case LDKLevel_Trace:
345                         return (*env)->GetStaticObjectField(env, LDKLevel_class, LDKLevel_LDKLevel_Trace);
346                 default: abort();
347         }
348 }
349
350 static inline LDKNetwork LDKNetwork_from_java(JNIEnv *env, jclass val) {
351         switch ((*env)->CallIntMethod(env, val, ordinal_meth)) {
352                 case 0: return LDKNetwork_Bitcoin;
353                 case 1: return LDKNetwork_Testnet;
354                 case 2: return LDKNetwork_Regtest;
355         }
356         abort();
357 }
358 static jclass LDKNetwork_class = NULL;
359 static jfieldID LDKNetwork_LDKNetwork_Bitcoin = NULL;
360 static jfieldID LDKNetwork_LDKNetwork_Testnet = NULL;
361 static jfieldID LDKNetwork_LDKNetwork_Regtest = NULL;
362 JNIEXPORT void JNICALL Java_org_ldk_enums_LDKNetwork_init (JNIEnv * env, jclass clz) {
363         LDKNetwork_class = (*env)->NewGlobalRef(env, clz);
364         CHECK(LDKNetwork_class != NULL);
365         LDKNetwork_LDKNetwork_Bitcoin = (*env)->GetStaticFieldID(env, LDKNetwork_class, "LDKNetwork_Bitcoin", "Lorg/ldk/enums/LDKNetwork;");
366         CHECK(LDKNetwork_LDKNetwork_Bitcoin != NULL);
367         LDKNetwork_LDKNetwork_Testnet = (*env)->GetStaticFieldID(env, LDKNetwork_class, "LDKNetwork_Testnet", "Lorg/ldk/enums/LDKNetwork;");
368         CHECK(LDKNetwork_LDKNetwork_Testnet != NULL);
369         LDKNetwork_LDKNetwork_Regtest = (*env)->GetStaticFieldID(env, LDKNetwork_class, "LDKNetwork_Regtest", "Lorg/ldk/enums/LDKNetwork;");
370         CHECK(LDKNetwork_LDKNetwork_Regtest != NULL);
371 }
372 static inline jclass LDKNetwork_to_java(JNIEnv *env, LDKNetwork val) {
373         switch (val) {
374                 case LDKNetwork_Bitcoin:
375                         return (*env)->GetStaticObjectField(env, LDKNetwork_class, LDKNetwork_LDKNetwork_Bitcoin);
376                 case LDKNetwork_Testnet:
377                         return (*env)->GetStaticObjectField(env, LDKNetwork_class, LDKNetwork_LDKNetwork_Testnet);
378                 case LDKNetwork_Regtest:
379                         return (*env)->GetStaticObjectField(env, LDKNetwork_class, LDKNetwork_LDKNetwork_Regtest);
380                 default: abort();
381         }
382 }
383
384 static inline LDKSecp256k1Error LDKSecp256k1Error_from_java(JNIEnv *env, jclass val) {
385         switch ((*env)->CallIntMethod(env, val, ordinal_meth)) {
386                 case 0: return LDKSecp256k1Error_IncorrectSignature;
387                 case 1: return LDKSecp256k1Error_InvalidMessage;
388                 case 2: return LDKSecp256k1Error_InvalidPublicKey;
389                 case 3: return LDKSecp256k1Error_InvalidSignature;
390                 case 4: return LDKSecp256k1Error_InvalidSecretKey;
391                 case 5: return LDKSecp256k1Error_InvalidRecoveryId;
392                 case 6: return LDKSecp256k1Error_InvalidTweak;
393                 case 7: return LDKSecp256k1Error_NotEnoughMemory;
394                 case 8: return LDKSecp256k1Error_CallbackPanicked;
395         }
396         abort();
397 }
398 static jclass LDKSecp256k1Error_class = NULL;
399 static jfieldID LDKSecp256k1Error_LDKSecp256k1Error_IncorrectSignature = NULL;
400 static jfieldID LDKSecp256k1Error_LDKSecp256k1Error_InvalidMessage = NULL;
401 static jfieldID LDKSecp256k1Error_LDKSecp256k1Error_InvalidPublicKey = NULL;
402 static jfieldID LDKSecp256k1Error_LDKSecp256k1Error_InvalidSignature = NULL;
403 static jfieldID LDKSecp256k1Error_LDKSecp256k1Error_InvalidSecretKey = NULL;
404 static jfieldID LDKSecp256k1Error_LDKSecp256k1Error_InvalidRecoveryId = NULL;
405 static jfieldID LDKSecp256k1Error_LDKSecp256k1Error_InvalidTweak = NULL;
406 static jfieldID LDKSecp256k1Error_LDKSecp256k1Error_NotEnoughMemory = NULL;
407 static jfieldID LDKSecp256k1Error_LDKSecp256k1Error_CallbackPanicked = NULL;
408 JNIEXPORT void JNICALL Java_org_ldk_enums_LDKSecp256k1Error_init (JNIEnv * env, jclass clz) {
409         LDKSecp256k1Error_class = (*env)->NewGlobalRef(env, clz);
410         CHECK(LDKSecp256k1Error_class != NULL);
411         LDKSecp256k1Error_LDKSecp256k1Error_IncorrectSignature = (*env)->GetStaticFieldID(env, LDKSecp256k1Error_class, "LDKSecp256k1Error_IncorrectSignature", "Lorg/ldk/enums/LDKSecp256k1Error;");
412         CHECK(LDKSecp256k1Error_LDKSecp256k1Error_IncorrectSignature != NULL);
413         LDKSecp256k1Error_LDKSecp256k1Error_InvalidMessage = (*env)->GetStaticFieldID(env, LDKSecp256k1Error_class, "LDKSecp256k1Error_InvalidMessage", "Lorg/ldk/enums/LDKSecp256k1Error;");
414         CHECK(LDKSecp256k1Error_LDKSecp256k1Error_InvalidMessage != NULL);
415         LDKSecp256k1Error_LDKSecp256k1Error_InvalidPublicKey = (*env)->GetStaticFieldID(env, LDKSecp256k1Error_class, "LDKSecp256k1Error_InvalidPublicKey", "Lorg/ldk/enums/LDKSecp256k1Error;");
416         CHECK(LDKSecp256k1Error_LDKSecp256k1Error_InvalidPublicKey != NULL);
417         LDKSecp256k1Error_LDKSecp256k1Error_InvalidSignature = (*env)->GetStaticFieldID(env, LDKSecp256k1Error_class, "LDKSecp256k1Error_InvalidSignature", "Lorg/ldk/enums/LDKSecp256k1Error;");
418         CHECK(LDKSecp256k1Error_LDKSecp256k1Error_InvalidSignature != NULL);
419         LDKSecp256k1Error_LDKSecp256k1Error_InvalidSecretKey = (*env)->GetStaticFieldID(env, LDKSecp256k1Error_class, "LDKSecp256k1Error_InvalidSecretKey", "Lorg/ldk/enums/LDKSecp256k1Error;");
420         CHECK(LDKSecp256k1Error_LDKSecp256k1Error_InvalidSecretKey != NULL);
421         LDKSecp256k1Error_LDKSecp256k1Error_InvalidRecoveryId = (*env)->GetStaticFieldID(env, LDKSecp256k1Error_class, "LDKSecp256k1Error_InvalidRecoveryId", "Lorg/ldk/enums/LDKSecp256k1Error;");
422         CHECK(LDKSecp256k1Error_LDKSecp256k1Error_InvalidRecoveryId != NULL);
423         LDKSecp256k1Error_LDKSecp256k1Error_InvalidTweak = (*env)->GetStaticFieldID(env, LDKSecp256k1Error_class, "LDKSecp256k1Error_InvalidTweak", "Lorg/ldk/enums/LDKSecp256k1Error;");
424         CHECK(LDKSecp256k1Error_LDKSecp256k1Error_InvalidTweak != NULL);
425         LDKSecp256k1Error_LDKSecp256k1Error_NotEnoughMemory = (*env)->GetStaticFieldID(env, LDKSecp256k1Error_class, "LDKSecp256k1Error_NotEnoughMemory", "Lorg/ldk/enums/LDKSecp256k1Error;");
426         CHECK(LDKSecp256k1Error_LDKSecp256k1Error_NotEnoughMemory != NULL);
427         LDKSecp256k1Error_LDKSecp256k1Error_CallbackPanicked = (*env)->GetStaticFieldID(env, LDKSecp256k1Error_class, "LDKSecp256k1Error_CallbackPanicked", "Lorg/ldk/enums/LDKSecp256k1Error;");
428         CHECK(LDKSecp256k1Error_LDKSecp256k1Error_CallbackPanicked != NULL);
429 }
430 static inline jclass LDKSecp256k1Error_to_java(JNIEnv *env, LDKSecp256k1Error val) {
431         switch (val) {
432                 case LDKSecp256k1Error_IncorrectSignature:
433                         return (*env)->GetStaticObjectField(env, LDKSecp256k1Error_class, LDKSecp256k1Error_LDKSecp256k1Error_IncorrectSignature);
434                 case LDKSecp256k1Error_InvalidMessage:
435                         return (*env)->GetStaticObjectField(env, LDKSecp256k1Error_class, LDKSecp256k1Error_LDKSecp256k1Error_InvalidMessage);
436                 case LDKSecp256k1Error_InvalidPublicKey:
437                         return (*env)->GetStaticObjectField(env, LDKSecp256k1Error_class, LDKSecp256k1Error_LDKSecp256k1Error_InvalidPublicKey);
438                 case LDKSecp256k1Error_InvalidSignature:
439                         return (*env)->GetStaticObjectField(env, LDKSecp256k1Error_class, LDKSecp256k1Error_LDKSecp256k1Error_InvalidSignature);
440                 case LDKSecp256k1Error_InvalidSecretKey:
441                         return (*env)->GetStaticObjectField(env, LDKSecp256k1Error_class, LDKSecp256k1Error_LDKSecp256k1Error_InvalidSecretKey);
442                 case LDKSecp256k1Error_InvalidRecoveryId:
443                         return (*env)->GetStaticObjectField(env, LDKSecp256k1Error_class, LDKSecp256k1Error_LDKSecp256k1Error_InvalidRecoveryId);
444                 case LDKSecp256k1Error_InvalidTweak:
445                         return (*env)->GetStaticObjectField(env, LDKSecp256k1Error_class, LDKSecp256k1Error_LDKSecp256k1Error_InvalidTweak);
446                 case LDKSecp256k1Error_NotEnoughMemory:
447                         return (*env)->GetStaticObjectField(env, LDKSecp256k1Error_class, LDKSecp256k1Error_LDKSecp256k1Error_NotEnoughMemory);
448                 case LDKSecp256k1Error_CallbackPanicked:
449                         return (*env)->GetStaticObjectField(env, LDKSecp256k1Error_class, LDKSecp256k1Error_LDKSecp256k1Error_CallbackPanicked);
450                 default: abort();
451         }
452 }
453
454 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1u8_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
455         LDKCVecTempl_u8 *vec = (LDKCVecTempl_u8*)ptr;
456         return (*env)->NewObject(env, slicedef_cls, slicedef_meth, (long)vec->data, (long)vec->datalen, sizeof(uint8_t));
457 }
458 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1u8_1new(JNIEnv *env, jclass _b, jbyteArray elems){
459         LDKCVecTempl_u8 *ret = MALLOC(sizeof(LDKCVecTempl_u8), "LDKCVecTempl_u8");
460         ret->datalen = (*env)->GetArrayLength(env, elems);
461         if (ret->datalen == 0) {
462                 ret->data = NULL;
463         } else {
464                 ret->data = MALLOC(sizeof(uint8_t) * ret->datalen, "LDKCVecTempl_u8 Data");
465                 jbyte *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
466                 for (size_t i = 0; i < ret->datalen; i++) {
467                         ret->data[i] = java_elems[i];
468                 }
469                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
470         }
471         return (long)ret;
472 }
473 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKC2TupleTempl_1usize_1_1Transaction_1new(JNIEnv *_env, jclass _b, jlong a, jlong b) {
474         LDKC2TupleTempl_usize__Transaction* ret = MALLOC(sizeof(LDKC2TupleTempl_usize__Transaction), "LDKC2TupleTempl_usize__Transaction");
475         ret->a = a;
476         LDKTransaction b_conv = *(LDKTransaction*)b;
477         ret->b = b_conv;
478         return (long)ret;
479 }
480 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKC2Tuple_1usizeTransactionZ_1get_1a(JNIEnv *_env, jclass _b, jlong ptr) {
481         LDKC2TupleTempl_usize__Transaction *tuple = (LDKC2TupleTempl_usize__Transaction*)ptr;
482         return tuple->a;
483 }
484 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKC2Tuple_1usizeTransactionZ_1get_1b(JNIEnv *_env, jclass _b, jlong ptr) {
485         LDKC2TupleTempl_usize__Transaction *tuple = (LDKC2TupleTempl_usize__Transaction*)ptr;
486         LDKTransaction *b_copy = MALLOC(sizeof(LDKTransaction), "LDKTransaction");
487         *b_copy = tuple->b;
488         long b_ref = (long)b_copy;
489         return b_ref;
490 }
491 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NoneChannelMonitorUpdateErrZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
492         return ((LDKCResult_NoneChannelMonitorUpdateErrZ*)arg)->result_ok;
493 }
494 JNIEXPORT jbyte JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NoneChannelMonitorUpdateErrZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
495         LDKCResult_NoneChannelMonitorUpdateErrZ *val = (LDKCResult_NoneChannelMonitorUpdateErrZ*)arg;
496         CHECK(val->result_ok);
497         return *val->contents.result;
498 }
499 JNIEXPORT jclass JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NoneChannelMonitorUpdateErrZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
500         LDKCResult_NoneChannelMonitorUpdateErrZ *val = (LDKCResult_NoneChannelMonitorUpdateErrZ*)arg;
501         CHECK(!val->result_ok);
502         jclass err_conv = LDKChannelMonitorUpdateErr_to_java(_env, (*val->contents.err));
503         return err_conv;
504 }
505 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NoneMonitorUpdateErrorZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
506         return ((LDKCResult_NoneMonitorUpdateErrorZ*)arg)->result_ok;
507 }
508 JNIEXPORT jbyte JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NoneMonitorUpdateErrorZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
509         LDKCResult_NoneMonitorUpdateErrorZ *val = (LDKCResult_NoneMonitorUpdateErrorZ*)arg;
510         CHECK(val->result_ok);
511         return *val->contents.result;
512 }
513 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NoneMonitorUpdateErrorZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
514         LDKCResult_NoneMonitorUpdateErrorZ *val = (LDKCResult_NoneMonitorUpdateErrorZ*)arg;
515         CHECK(!val->result_ok);
516         LDKMonitorUpdateError err_var = (*val->contents.err);
517         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
518         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
519         long err_ref = (long)err_var.inner & ~1;
520         return err_ref;
521 }
522 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKC2TupleTempl_1OutPoint_1_1CVec_1u8Z_1new(JNIEnv *_env, jclass _b, jlong a, jbyteArray b) {
523         LDKC2TupleTempl_OutPoint__CVec_u8Z* ret = MALLOC(sizeof(LDKC2TupleTempl_OutPoint__CVec_u8Z), "LDKC2TupleTempl_OutPoint__CVec_u8Z");
524         LDKOutPoint a_conv;
525         a_conv.inner = (void*)(a & (~1));
526         a_conv.is_owned = (a & 1) || (a == 0);
527         if (a_conv.inner != NULL)
528                 a_conv = OutPoint_clone(&a_conv);
529         ret->a = a_conv;
530         LDKCVec_u8Z b_ref;
531         b_ref.data = (*_env)->GetByteArrayElements (_env, b, NULL);
532         b_ref.datalen = (*_env)->GetArrayLength (_env, b);
533         ret->b = b_ref;
534         //TODO: Really need to call (*_env)->ReleaseByteArrayElements(_env, b, (int8_t*)b_ref.data, 0); here
535         return (long)ret;
536 }
537 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKC2Tuple_1OutPointScriptZ_1get_1a(JNIEnv *_env, jclass _b, jlong ptr) {
538         LDKC2TupleTempl_OutPoint__CVec_u8Z *tuple = (LDKC2TupleTempl_OutPoint__CVec_u8Z*)ptr;
539         LDKOutPoint a_var = tuple->a;
540         CHECK((((long)a_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
541         CHECK((((long)&a_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
542         long a_ref = (long)a_var.inner & ~1;
543         return a_ref;
544 }
545 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_LDKC2Tuple_1OutPointScriptZ_1get_1b(JNIEnv *_env, jclass _b, jlong ptr) {
546         LDKC2TupleTempl_OutPoint__CVec_u8Z *tuple = (LDKC2TupleTempl_OutPoint__CVec_u8Z*)ptr;
547         LDKCVec_u8Z b_var = tuple->b;
548         jbyteArray b_arr = (*_env)->NewByteArray(_env, b_var.datalen);
549         (*_env)->SetByteArrayRegion(_env, b_arr, 0, b_var.datalen, b_var.data);
550         return b_arr;
551 }
552 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1TxOut_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
553         LDKCVecTempl_TxOut *vec = (LDKCVecTempl_TxOut*)ptr;
554         return (*env)->NewObject(env, slicedef_cls, slicedef_meth, (long)vec->data, (long)vec->datalen, sizeof(LDKTxOut));
555 }
556 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1TxOut_1new(JNIEnv *env, jclass _b, jlongArray elems){
557         LDKCVecTempl_TxOut *ret = MALLOC(sizeof(LDKCVecTempl_TxOut), "LDKCVecTempl_TxOut");
558         ret->datalen = (*env)->GetArrayLength(env, elems);
559         if (ret->datalen == 0) {
560                 ret->data = NULL;
561         } else {
562                 ret->data = MALLOC(sizeof(LDKTxOut) * ret->datalen, "LDKCVecTempl_TxOut Data");
563                 jlong *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
564                 for (size_t i = 0; i < ret->datalen; i++) {
565                         jlong arr_elem = java_elems[i];
566                         LDKTxOut arr_elem_conv = *(LDKTxOut*)arr_elem;
567                         FREE((void*)arr_elem);
568                         ret->data[i] = arr_elem_conv;
569                 }
570                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
571         }
572         return (long)ret;
573 }
574 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKC2TupleTempl_1ThirtyTwoBytes_1_1CVecTempl_1TxOut_1new(JNIEnv *_env, jclass _b, jbyteArray a, jlongArray b) {
575         LDKC2TupleTempl_ThirtyTwoBytes__CVecTempl_TxOut* ret = MALLOC(sizeof(LDKC2TupleTempl_ThirtyTwoBytes__CVecTempl_TxOut), "LDKC2TupleTempl_ThirtyTwoBytes__CVecTempl_TxOut");
576         LDKThirtyTwoBytes a_ref;
577         CHECK((*_env)->GetArrayLength (_env, a) == 32);
578         (*_env)->GetByteArrayRegion (_env, a, 0, 32, a_ref.data);
579         ret->a = a_ref;
580         LDKCVecTempl_TxOut b_constr;
581         b_constr.datalen = (*_env)->GetArrayLength (_env, b);
582         if (b_constr.datalen > 0)
583                 b_constr.data = MALLOC(b_constr.datalen * sizeof(LDKTxOut), "LDKCVecTempl_TxOut Elements");
584         else
585                 b_constr.data = NULL;
586         long* b_vals = (*_env)->GetLongArrayElements (_env, b, NULL);
587         for (size_t h = 0; h < b_constr.datalen; h++) {
588                 long arr_conv_7 = b_vals[h];
589                 LDKTxOut arr_conv_7_conv = *(LDKTxOut*)arr_conv_7;
590                 FREE((void*)arr_conv_7);
591                 b_constr.data[h] = arr_conv_7_conv;
592         }
593         (*_env)->ReleaseLongArrayElements (_env, b, b_vals, 0);
594         ret->b = b_constr;
595         return (long)ret;
596 }
597 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_LDKC2Tuple_1TxidCVec_1TxOutZZ_1get_1a(JNIEnv *_env, jclass _b, jlong ptr) {
598         LDKC2TupleTempl_ThirtyTwoBytes__CVecTempl_TxOut *tuple = (LDKC2TupleTempl_ThirtyTwoBytes__CVecTempl_TxOut*)ptr;
599         jbyteArray a_arr = (*_env)->NewByteArray(_env, 32);
600         (*_env)->SetByteArrayRegion(_env, a_arr, 0, 32, tuple->a.data);
601         return a_arr;
602 }
603 JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_LDKC2Tuple_1TxidCVec_1TxOutZZ_1get_1b(JNIEnv *_env, jclass _b, jlong ptr) {
604         LDKC2TupleTempl_ThirtyTwoBytes__CVecTempl_TxOut *tuple = (LDKC2TupleTempl_ThirtyTwoBytes__CVecTempl_TxOut*)ptr;
605         LDKCVecTempl_TxOut b_var = tuple->b;
606         jlongArray b_arr = (*_env)->NewLongArray(_env, b_var.datalen);
607         jlong *b_arr_ptr = (*_env)->GetPrimitiveArrayCritical(_env, b_arr, NULL);
608         for (size_t h = 0; h < b_var.datalen; h++) {
609                 long arr_conv_7_ref = (long)&b_var.data[h];
610                 b_arr_ptr[h] = arr_conv_7_ref;
611         }
612         (*_env)->ReleasePrimitiveArrayCritical(_env, b_arr, b_arr_ptr, 0);
613         return b_arr;
614 }
615 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKC2TupleTempl_1u64_1_1u64_1new(JNIEnv *_env, jclass _b, jlong a, jlong b) {
616         LDKC2TupleTempl_u64__u64* ret = MALLOC(sizeof(LDKC2TupleTempl_u64__u64), "LDKC2TupleTempl_u64__u64");
617         ret->a = a;
618         ret->b = b;
619         return (long)ret;
620 }
621 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKC2Tuple_1u64u64Z_1get_1a(JNIEnv *_env, jclass _b, jlong ptr) {
622         LDKC2TupleTempl_u64__u64 *tuple = (LDKC2TupleTempl_u64__u64*)ptr;
623         return tuple->a;
624 }
625 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKC2Tuple_1u64u64Z_1get_1b(JNIEnv *_env, jclass _b, jlong ptr) {
626         LDKC2TupleTempl_u64__u64 *tuple = (LDKC2TupleTempl_u64__u64*)ptr;
627         return tuple->b;
628 }
629 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1Signature_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
630         LDKCVecTempl_Signature *vec = (LDKCVecTempl_Signature*)ptr;
631         return (*env)->NewObject(env, slicedef_cls, slicedef_meth, (long)vec->data, (long)vec->datalen, sizeof(LDKSignature));
632 }
633 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKC2TupleTempl_1Signature_1_1CVecTempl_1Signature_1new(JNIEnv *_env, jclass _b, jbyteArray a, jobjectArray b) {
634         LDKC2TupleTempl_Signature__CVecTempl_Signature* ret = MALLOC(sizeof(LDKC2TupleTempl_Signature__CVecTempl_Signature), "LDKC2TupleTempl_Signature__CVecTempl_Signature");
635         LDKSignature a_ref;
636         CHECK((*_env)->GetArrayLength (_env, a) == 64);
637         (*_env)->GetByteArrayRegion (_env, a, 0, 64, a_ref.compact_form);
638         ret->a = a_ref;
639         LDKCVecTempl_Signature b_constr;
640         b_constr.datalen = (*_env)->GetArrayLength (_env, b);
641         if (b_constr.datalen > 0)
642                 b_constr.data = MALLOC(b_constr.datalen * sizeof(LDKSignature), "LDKCVecTempl_Signature Elements");
643         else
644                 b_constr.data = NULL;
645         for (size_t i = 0; i < b_constr.datalen; i++) {
646                 jobject arr_conv_8 = (*_env)->GetObjectArrayElement(_env, b, i);
647                 LDKSignature arr_conv_8_ref;
648                 CHECK((*_env)->GetArrayLength (_env, arr_conv_8) == 64);
649                 (*_env)->GetByteArrayRegion (_env, arr_conv_8, 0, 64, arr_conv_8_ref.compact_form);
650                 b_constr.data[i] = arr_conv_8_ref;
651         }
652         ret->b = b_constr;
653         return (long)ret;
654 }
655 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_LDKC2Tuple_1SignatureCVec_1SignatureZZ_1get_1a(JNIEnv *_env, jclass _b, jlong ptr) {
656         LDKC2TupleTempl_Signature__CVecTempl_Signature *tuple = (LDKC2TupleTempl_Signature__CVecTempl_Signature*)ptr;
657         jbyteArray a_arr = (*_env)->NewByteArray(_env, 64);
658         (*_env)->SetByteArrayRegion(_env, a_arr, 0, 64, tuple->a.compact_form);
659         return a_arr;
660 }
661 JNIEXPORT jobjectArray JNICALL Java_org_ldk_impl_bindings_LDKC2Tuple_1SignatureCVec_1SignatureZZ_1get_1b(JNIEnv *_env, jclass _b, jlong ptr) {
662         LDKC2TupleTempl_Signature__CVecTempl_Signature *tuple = (LDKC2TupleTempl_Signature__CVecTempl_Signature*)ptr;
663         LDKCVecTempl_Signature b_var = tuple->b;
664         jobjectArray b_arr = (*_env)->NewObjectArray(_env, b_var.datalen, arr_of_B_clz, NULL);
665         for (size_t i = 0; i < b_var.datalen; i++) {
666                 jbyteArray arr_conv_8_arr = (*_env)->NewByteArray(_env, 64);
667                 (*_env)->SetByteArrayRegion(_env, arr_conv_8_arr, 0, 64, b_var.data[i].compact_form);
668                 (*_env)->SetObjectArrayElement(_env, b_arr, i, arr_conv_8_arr);
669         }
670         return b_arr;
671 }
672 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1C2Tuple_1SignatureCVec_1SignatureZZNoneZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
673         return ((LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ*)arg)->result_ok;
674 }
675 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1C2Tuple_1SignatureCVec_1SignatureZZNoneZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
676         LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ *val = (LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ*)arg;
677         CHECK(val->result_ok);
678         long res_ref = (long)&(*val->contents.result);
679         return res_ref;
680 }
681 JNIEXPORT jbyte JNICALL Java_org_ldk_impl_bindings_LDKCResult_1C2Tuple_1SignatureCVec_1SignatureZZNoneZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
682         LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ *val = (LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ*)arg;
683         CHECK(!val->result_ok);
684         return *val->contents.err;
685 }
686 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1SignatureNoneZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
687         return ((LDKCResult_SignatureNoneZ*)arg)->result_ok;
688 }
689 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_LDKCResult_1SignatureNoneZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
690         LDKCResult_SignatureNoneZ *val = (LDKCResult_SignatureNoneZ*)arg;
691         CHECK(val->result_ok);
692         jbyteArray res_arr = (*_env)->NewByteArray(_env, 64);
693         (*_env)->SetByteArrayRegion(_env, res_arr, 0, 64, (*val->contents.result).compact_form);
694         return res_arr;
695 }
696 JNIEXPORT jbyte JNICALL Java_org_ldk_impl_bindings_LDKCResult_1SignatureNoneZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
697         LDKCResult_SignatureNoneZ *val = (LDKCResult_SignatureNoneZ*)arg;
698         CHECK(!val->result_ok);
699         return *val->contents.err;
700 }
701 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1CVec_1SignatureZNoneZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
702         return ((LDKCResult_CVec_SignatureZNoneZ*)arg)->result_ok;
703 }
704 JNIEXPORT jobjectArray JNICALL Java_org_ldk_impl_bindings_LDKCResult_1CVec_1SignatureZNoneZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
705         LDKCResult_CVec_SignatureZNoneZ *val = (LDKCResult_CVec_SignatureZNoneZ*)arg;
706         CHECK(val->result_ok);
707         LDKCVecTempl_Signature res_var = (*val->contents.result);
708         jobjectArray res_arr = (*_env)->NewObjectArray(_env, res_var.datalen, arr_of_B_clz, NULL);
709         for (size_t i = 0; i < res_var.datalen; i++) {
710                 jbyteArray arr_conv_8_arr = (*_env)->NewByteArray(_env, 64);
711                 (*_env)->SetByteArrayRegion(_env, arr_conv_8_arr, 0, 64, res_var.data[i].compact_form);
712                 (*_env)->SetObjectArrayElement(_env, res_arr, i, arr_conv_8_arr);
713         }
714         return res_arr;
715 }
716 JNIEXPORT jbyte JNICALL Java_org_ldk_impl_bindings_LDKCResult_1CVec_1SignatureZNoneZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
717         LDKCResult_CVec_SignatureZNoneZ *val = (LDKCResult_CVec_SignatureZNoneZ*)arg;
718         CHECK(!val->result_ok);
719         return *val->contents.err;
720 }
721 static jclass LDKAPIError_APIMisuseError_class = NULL;
722 static jmethodID LDKAPIError_APIMisuseError_meth = NULL;
723 static jclass LDKAPIError_FeeRateTooHigh_class = NULL;
724 static jmethodID LDKAPIError_FeeRateTooHigh_meth = NULL;
725 static jclass LDKAPIError_RouteError_class = NULL;
726 static jmethodID LDKAPIError_RouteError_meth = NULL;
727 static jclass LDKAPIError_ChannelUnavailable_class = NULL;
728 static jmethodID LDKAPIError_ChannelUnavailable_meth = NULL;
729 static jclass LDKAPIError_MonitorUpdateFailed_class = NULL;
730 static jmethodID LDKAPIError_MonitorUpdateFailed_meth = NULL;
731 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_00024LDKAPIError_init (JNIEnv * env, jclass _a) {
732         LDKAPIError_APIMisuseError_class =
733                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKAPIError$APIMisuseError;"));
734         CHECK(LDKAPIError_APIMisuseError_class != NULL);
735         LDKAPIError_APIMisuseError_meth = (*env)->GetMethodID(env, LDKAPIError_APIMisuseError_class, "<init>", "([B)V");
736         CHECK(LDKAPIError_APIMisuseError_meth != NULL);
737         LDKAPIError_FeeRateTooHigh_class =
738                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKAPIError$FeeRateTooHigh;"));
739         CHECK(LDKAPIError_FeeRateTooHigh_class != NULL);
740         LDKAPIError_FeeRateTooHigh_meth = (*env)->GetMethodID(env, LDKAPIError_FeeRateTooHigh_class, "<init>", "([BI)V");
741         CHECK(LDKAPIError_FeeRateTooHigh_meth != NULL);
742         LDKAPIError_RouteError_class =
743                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKAPIError$RouteError;"));
744         CHECK(LDKAPIError_RouteError_class != NULL);
745         LDKAPIError_RouteError_meth = (*env)->GetMethodID(env, LDKAPIError_RouteError_class, "<init>", "(Ljava/lang/String;)V");
746         CHECK(LDKAPIError_RouteError_meth != NULL);
747         LDKAPIError_ChannelUnavailable_class =
748                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKAPIError$ChannelUnavailable;"));
749         CHECK(LDKAPIError_ChannelUnavailable_class != NULL);
750         LDKAPIError_ChannelUnavailable_meth = (*env)->GetMethodID(env, LDKAPIError_ChannelUnavailable_class, "<init>", "([B)V");
751         CHECK(LDKAPIError_ChannelUnavailable_meth != NULL);
752         LDKAPIError_MonitorUpdateFailed_class =
753                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKAPIError$MonitorUpdateFailed;"));
754         CHECK(LDKAPIError_MonitorUpdateFailed_class != NULL);
755         LDKAPIError_MonitorUpdateFailed_meth = (*env)->GetMethodID(env, LDKAPIError_MonitorUpdateFailed_class, "<init>", "()V");
756         CHECK(LDKAPIError_MonitorUpdateFailed_meth != NULL);
757 }
758 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKAPIError_1ref_1from_1ptr (JNIEnv * _env, jclass _c, jlong ptr) {
759         LDKAPIError *obj = (LDKAPIError*)ptr;
760         switch(obj->tag) {
761                 case LDKAPIError_APIMisuseError: {
762                         LDKCVec_u8Z err_var = obj->api_misuse_error.err;
763                         jbyteArray err_arr = (*_env)->NewByteArray(_env, err_var.datalen);
764                         (*_env)->SetByteArrayRegion(_env, err_arr, 0, err_var.datalen, err_var.data);
765                         return (*_env)->NewObject(_env, LDKAPIError_APIMisuseError_class, LDKAPIError_APIMisuseError_meth, err_arr);
766                 }
767                 case LDKAPIError_FeeRateTooHigh: {
768                         LDKCVec_u8Z err_var = obj->fee_rate_too_high.err;
769                         jbyteArray err_arr = (*_env)->NewByteArray(_env, err_var.datalen);
770                         (*_env)->SetByteArrayRegion(_env, err_arr, 0, err_var.datalen, err_var.data);
771                         return (*_env)->NewObject(_env, LDKAPIError_FeeRateTooHigh_class, LDKAPIError_FeeRateTooHigh_meth, err_arr, obj->fee_rate_too_high.feerate);
772                 }
773                 case LDKAPIError_RouteError: {
774                         LDKStr err_str = obj->route_error.err;
775                         char* err_buf = MALLOC(err_str.len + 1, "str conv buf");
776                         memcpy(err_buf, err_str.chars, err_str.len);
777                         err_buf[err_str.len] = 0;
778                         jstring err_conv = (*_env)->NewStringUTF(_env, err_str.chars);
779                         FREE(err_buf);
780                         return (*_env)->NewObject(_env, LDKAPIError_RouteError_class, LDKAPIError_RouteError_meth, err_conv);
781                 }
782                 case LDKAPIError_ChannelUnavailable: {
783                         LDKCVec_u8Z err_var = obj->channel_unavailable.err;
784                         jbyteArray err_arr = (*_env)->NewByteArray(_env, err_var.datalen);
785                         (*_env)->SetByteArrayRegion(_env, err_arr, 0, err_var.datalen, err_var.data);
786                         return (*_env)->NewObject(_env, LDKAPIError_ChannelUnavailable_class, LDKAPIError_ChannelUnavailable_meth, err_arr);
787                 }
788                 case LDKAPIError_MonitorUpdateFailed: {
789                         return (*_env)->NewObject(_env, LDKAPIError_MonitorUpdateFailed_class, LDKAPIError_MonitorUpdateFailed_meth);
790                 }
791                 default: abort();
792         }
793 }
794 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NoneAPIErrorZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
795         return ((LDKCResult_NoneAPIErrorZ*)arg)->result_ok;
796 }
797 JNIEXPORT jbyte JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NoneAPIErrorZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
798         LDKCResult_NoneAPIErrorZ *val = (LDKCResult_NoneAPIErrorZ*)arg;
799         CHECK(val->result_ok);
800         return *val->contents.result;
801 }
802 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NoneAPIErrorZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
803         LDKCResult_NoneAPIErrorZ *val = (LDKCResult_NoneAPIErrorZ*)arg;
804         CHECK(!val->result_ok);
805         long err_ref = (long)&(*val->contents.err);
806         return err_ref;
807 }
808 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NonePaymentSendFailureZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
809         return ((LDKCResult_NonePaymentSendFailureZ*)arg)->result_ok;
810 }
811 JNIEXPORT jbyte JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NonePaymentSendFailureZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
812         LDKCResult_NonePaymentSendFailureZ *val = (LDKCResult_NonePaymentSendFailureZ*)arg;
813         CHECK(val->result_ok);
814         return *val->contents.result;
815 }
816 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NonePaymentSendFailureZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
817         LDKCResult_NonePaymentSendFailureZ *val = (LDKCResult_NonePaymentSendFailureZ*)arg;
818         CHECK(!val->result_ok);
819         LDKPaymentSendFailure err_var = (*val->contents.err);
820         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
821         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
822         long err_ref = (long)err_var.inner & ~1;
823         return err_ref;
824 }
825 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKC3TupleTempl_1ChannelAnnouncement_1_1ChannelUpdate_1_1ChannelUpdate_1new(JNIEnv *_env, jclass _b, jlong a, jlong b, jlong c) {
826         LDKC3TupleTempl_ChannelAnnouncement__ChannelUpdate__ChannelUpdate* ret = MALLOC(sizeof(LDKC3TupleTempl_ChannelAnnouncement__ChannelUpdate__ChannelUpdate), "LDKC3TupleTempl_ChannelAnnouncement__ChannelUpdate__ChannelUpdate");
827         LDKChannelAnnouncement a_conv;
828         a_conv.inner = (void*)(a & (~1));
829         a_conv.is_owned = (a & 1) || (a == 0);
830         if (a_conv.inner != NULL)
831                 a_conv = ChannelAnnouncement_clone(&a_conv);
832         ret->a = a_conv;
833         LDKChannelUpdate b_conv;
834         b_conv.inner = (void*)(b & (~1));
835         b_conv.is_owned = (b & 1) || (b == 0);
836         if (b_conv.inner != NULL)
837                 b_conv = ChannelUpdate_clone(&b_conv);
838         ret->b = b_conv;
839         LDKChannelUpdate c_conv;
840         c_conv.inner = (void*)(c & (~1));
841         c_conv.is_owned = (c & 1) || (c == 0);
842         if (c_conv.inner != NULL)
843                 c_conv = ChannelUpdate_clone(&c_conv);
844         ret->c = c_conv;
845         return (long)ret;
846 }
847 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKC3Tuple_1ChannelAnnouncementChannelUpdateChannelUpdateZ_1get_1a(JNIEnv *_env, jclass _b, jlong ptr) {
848         LDKC3TupleTempl_ChannelAnnouncement__ChannelUpdate__ChannelUpdate *tuple = (LDKC3TupleTempl_ChannelAnnouncement__ChannelUpdate__ChannelUpdate*)ptr;
849         LDKChannelAnnouncement a_var = tuple->a;
850         CHECK((((long)a_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
851         CHECK((((long)&a_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
852         long a_ref = (long)a_var.inner & ~1;
853         return a_ref;
854 }
855 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKC3Tuple_1ChannelAnnouncementChannelUpdateChannelUpdateZ_1get_1b(JNIEnv *_env, jclass _b, jlong ptr) {
856         LDKC3TupleTempl_ChannelAnnouncement__ChannelUpdate__ChannelUpdate *tuple = (LDKC3TupleTempl_ChannelAnnouncement__ChannelUpdate__ChannelUpdate*)ptr;
857         LDKChannelUpdate b_var = tuple->b;
858         CHECK((((long)b_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
859         CHECK((((long)&b_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
860         long b_ref = (long)b_var.inner & ~1;
861         return b_ref;
862 }
863 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKC3Tuple_1ChannelAnnouncementChannelUpdateChannelUpdateZ_1get_1c(JNIEnv *_env, jclass _b, jlong ptr) {
864         LDKC3TupleTempl_ChannelAnnouncement__ChannelUpdate__ChannelUpdate *tuple = (LDKC3TupleTempl_ChannelAnnouncement__ChannelUpdate__ChannelUpdate*)ptr;
865         LDKChannelUpdate c_var = tuple->c;
866         CHECK((((long)c_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
867         CHECK((((long)&c_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
868         long c_ref = (long)c_var.inner & ~1;
869         return c_ref;
870 }
871 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NonePeerHandleErrorZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
872         return ((LDKCResult_NonePeerHandleErrorZ*)arg)->result_ok;
873 }
874 JNIEXPORT jbyte JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NonePeerHandleErrorZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
875         LDKCResult_NonePeerHandleErrorZ *val = (LDKCResult_NonePeerHandleErrorZ*)arg;
876         CHECK(val->result_ok);
877         return *val->contents.result;
878 }
879 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NonePeerHandleErrorZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
880         LDKCResult_NonePeerHandleErrorZ *val = (LDKCResult_NonePeerHandleErrorZ*)arg;
881         CHECK(!val->result_ok);
882         LDKPeerHandleError err_var = (*val->contents.err);
883         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
884         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
885         long err_ref = (long)err_var.inner & ~1;
886         return err_ref;
887 }
888 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKC2TupleTempl_1HTLCOutputInCommitment_1_1Signature_1new(JNIEnv *_env, jclass _b, jlong a, jbyteArray b) {
889         LDKC2TupleTempl_HTLCOutputInCommitment__Signature* ret = MALLOC(sizeof(LDKC2TupleTempl_HTLCOutputInCommitment__Signature), "LDKC2TupleTempl_HTLCOutputInCommitment__Signature");
890         LDKHTLCOutputInCommitment a_conv;
891         a_conv.inner = (void*)(a & (~1));
892         a_conv.is_owned = (a & 1) || (a == 0);
893         if (a_conv.inner != NULL)
894                 a_conv = HTLCOutputInCommitment_clone(&a_conv);
895         ret->a = a_conv;
896         LDKSignature b_ref;
897         CHECK((*_env)->GetArrayLength (_env, b) == 64);
898         (*_env)->GetByteArrayRegion (_env, b, 0, 64, b_ref.compact_form);
899         ret->b = b_ref;
900         return (long)ret;
901 }
902 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKC2Tuple_1HTLCOutputInCommitmentSignatureZ_1get_1a(JNIEnv *_env, jclass _b, jlong ptr) {
903         LDKC2TupleTempl_HTLCOutputInCommitment__Signature *tuple = (LDKC2TupleTempl_HTLCOutputInCommitment__Signature*)ptr;
904         LDKHTLCOutputInCommitment a_var = tuple->a;
905         CHECK((((long)a_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
906         CHECK((((long)&a_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
907         long a_ref = (long)a_var.inner & ~1;
908         return a_ref;
909 }
910 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_LDKC2Tuple_1HTLCOutputInCommitmentSignatureZ_1get_1b(JNIEnv *_env, jclass _b, jlong ptr) {
911         LDKC2TupleTempl_HTLCOutputInCommitment__Signature *tuple = (LDKC2TupleTempl_HTLCOutputInCommitment__Signature*)ptr;
912         jbyteArray b_arr = (*_env)->NewByteArray(_env, 64);
913         (*_env)->SetByteArrayRegion(_env, b_arr, 0, 64, tuple->b.compact_form);
914         return b_arr;
915 }
916 static jclass LDKSpendableOutputDescriptor_StaticOutput_class = NULL;
917 static jmethodID LDKSpendableOutputDescriptor_StaticOutput_meth = NULL;
918 static jclass LDKSpendableOutputDescriptor_DynamicOutputP2WSH_class = NULL;
919 static jmethodID LDKSpendableOutputDescriptor_DynamicOutputP2WSH_meth = NULL;
920 static jclass LDKSpendableOutputDescriptor_StaticOutputCounterpartyPayment_class = NULL;
921 static jmethodID LDKSpendableOutputDescriptor_StaticOutputCounterpartyPayment_meth = NULL;
922 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_00024LDKSpendableOutputDescriptor_init (JNIEnv * env, jclass _a) {
923         LDKSpendableOutputDescriptor_StaticOutput_class =
924                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKSpendableOutputDescriptor$StaticOutput;"));
925         CHECK(LDKSpendableOutputDescriptor_StaticOutput_class != NULL);
926         LDKSpendableOutputDescriptor_StaticOutput_meth = (*env)->GetMethodID(env, LDKSpendableOutputDescriptor_StaticOutput_class, "<init>", "(JJ)V");
927         CHECK(LDKSpendableOutputDescriptor_StaticOutput_meth != NULL);
928         LDKSpendableOutputDescriptor_DynamicOutputP2WSH_class =
929                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKSpendableOutputDescriptor$DynamicOutputP2WSH;"));
930         CHECK(LDKSpendableOutputDescriptor_DynamicOutputP2WSH_class != NULL);
931         LDKSpendableOutputDescriptor_DynamicOutputP2WSH_meth = (*env)->GetMethodID(env, LDKSpendableOutputDescriptor_DynamicOutputP2WSH_class, "<init>", "(J[BSJJ[B)V");
932         CHECK(LDKSpendableOutputDescriptor_DynamicOutputP2WSH_meth != NULL);
933         LDKSpendableOutputDescriptor_StaticOutputCounterpartyPayment_class =
934                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKSpendableOutputDescriptor$StaticOutputCounterpartyPayment;"));
935         CHECK(LDKSpendableOutputDescriptor_StaticOutputCounterpartyPayment_class != NULL);
936         LDKSpendableOutputDescriptor_StaticOutputCounterpartyPayment_meth = (*env)->GetMethodID(env, LDKSpendableOutputDescriptor_StaticOutputCounterpartyPayment_class, "<init>", "(JJJ)V");
937         CHECK(LDKSpendableOutputDescriptor_StaticOutputCounterpartyPayment_meth != NULL);
938 }
939 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKSpendableOutputDescriptor_1ref_1from_1ptr (JNIEnv * _env, jclass _c, jlong ptr) {
940         LDKSpendableOutputDescriptor *obj = (LDKSpendableOutputDescriptor*)ptr;
941         switch(obj->tag) {
942                 case LDKSpendableOutputDescriptor_StaticOutput: {
943                         LDKOutPoint outpoint_var = obj->static_output.outpoint;
944                         CHECK((((long)outpoint_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
945                         CHECK((((long)&outpoint_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
946                         long outpoint_ref = (long)outpoint_var.inner & ~1;
947                         long output_ref = (long)&obj->static_output.output;
948                         return (*_env)->NewObject(_env, LDKSpendableOutputDescriptor_StaticOutput_class, LDKSpendableOutputDescriptor_StaticOutput_meth, outpoint_ref, output_ref);
949                 }
950                 case LDKSpendableOutputDescriptor_DynamicOutputP2WSH: {
951                         LDKOutPoint outpoint_var = obj->dynamic_output_p2wsh.outpoint;
952                         CHECK((((long)outpoint_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
953                         CHECK((((long)&outpoint_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
954                         long outpoint_ref = (long)outpoint_var.inner & ~1;
955                         jbyteArray per_commitment_point_arr = (*_env)->NewByteArray(_env, 33);
956                         (*_env)->SetByteArrayRegion(_env, per_commitment_point_arr, 0, 33, obj->dynamic_output_p2wsh.per_commitment_point.compressed_form);
957                         long output_ref = (long)&obj->dynamic_output_p2wsh.output;
958                         long key_derivation_params_ref = (long)&obj->dynamic_output_p2wsh.key_derivation_params;
959                         jbyteArray revocation_pubkey_arr = (*_env)->NewByteArray(_env, 33);
960                         (*_env)->SetByteArrayRegion(_env, revocation_pubkey_arr, 0, 33, obj->dynamic_output_p2wsh.revocation_pubkey.compressed_form);
961                         return (*_env)->NewObject(_env, LDKSpendableOutputDescriptor_DynamicOutputP2WSH_class, LDKSpendableOutputDescriptor_DynamicOutputP2WSH_meth, outpoint_ref, per_commitment_point_arr, obj->dynamic_output_p2wsh.to_self_delay, output_ref, key_derivation_params_ref, revocation_pubkey_arr);
962                 }
963                 case LDKSpendableOutputDescriptor_StaticOutputCounterpartyPayment: {
964                         LDKOutPoint outpoint_var = obj->static_output_counterparty_payment.outpoint;
965                         CHECK((((long)outpoint_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
966                         CHECK((((long)&outpoint_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
967                         long outpoint_ref = (long)outpoint_var.inner & ~1;
968                         long output_ref = (long)&obj->static_output_counterparty_payment.output;
969                         long key_derivation_params_ref = (long)&obj->static_output_counterparty_payment.key_derivation_params;
970                         return (*_env)->NewObject(_env, LDKSpendableOutputDescriptor_StaticOutputCounterpartyPayment_class, LDKSpendableOutputDescriptor_StaticOutputCounterpartyPayment_meth, outpoint_ref, output_ref, key_derivation_params_ref);
971                 }
972                 default: abort();
973         }
974 }
975 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1SpendableOutputDescriptor_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
976         LDKCVecTempl_SpendableOutputDescriptor *vec = (LDKCVecTempl_SpendableOutputDescriptor*)ptr;
977         return (*env)->NewObject(env, slicedef_cls, slicedef_meth, (long)vec->data, (long)vec->datalen, sizeof(LDKSpendableOutputDescriptor));
978 }
979 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1SpendableOutputDescriptor_1new(JNIEnv *env, jclass _b, jlongArray elems){
980         LDKCVecTempl_SpendableOutputDescriptor *ret = MALLOC(sizeof(LDKCVecTempl_SpendableOutputDescriptor), "LDKCVecTempl_SpendableOutputDescriptor");
981         ret->datalen = (*env)->GetArrayLength(env, elems);
982         if (ret->datalen == 0) {
983                 ret->data = NULL;
984         } else {
985                 ret->data = MALLOC(sizeof(LDKSpendableOutputDescriptor) * ret->datalen, "LDKCVecTempl_SpendableOutputDescriptor Data");
986                 jlong *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
987                 for (size_t i = 0; i < ret->datalen; i++) {
988                         jlong arr_elem = java_elems[i];
989                         LDKSpendableOutputDescriptor arr_elem_conv = *(LDKSpendableOutputDescriptor*)arr_elem;
990                         FREE((void*)arr_elem);
991                         ret->data[i] = arr_elem_conv;
992                 }
993                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
994         }
995         return (long)ret;
996 }
997 static jclass LDKEvent_FundingGenerationReady_class = NULL;
998 static jmethodID LDKEvent_FundingGenerationReady_meth = NULL;
999 static jclass LDKEvent_FundingBroadcastSafe_class = NULL;
1000 static jmethodID LDKEvent_FundingBroadcastSafe_meth = NULL;
1001 static jclass LDKEvent_PaymentReceived_class = NULL;
1002 static jmethodID LDKEvent_PaymentReceived_meth = NULL;
1003 static jclass LDKEvent_PaymentSent_class = NULL;
1004 static jmethodID LDKEvent_PaymentSent_meth = NULL;
1005 static jclass LDKEvent_PaymentFailed_class = NULL;
1006 static jmethodID LDKEvent_PaymentFailed_meth = NULL;
1007 static jclass LDKEvent_PendingHTLCsForwardable_class = NULL;
1008 static jmethodID LDKEvent_PendingHTLCsForwardable_meth = NULL;
1009 static jclass LDKEvent_SpendableOutputs_class = NULL;
1010 static jmethodID LDKEvent_SpendableOutputs_meth = NULL;
1011 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_00024LDKEvent_init (JNIEnv * env, jclass _a) {
1012         LDKEvent_FundingGenerationReady_class =
1013                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKEvent$FundingGenerationReady;"));
1014         CHECK(LDKEvent_FundingGenerationReady_class != NULL);
1015         LDKEvent_FundingGenerationReady_meth = (*env)->GetMethodID(env, LDKEvent_FundingGenerationReady_class, "<init>", "([BJ[BJ)V");
1016         CHECK(LDKEvent_FundingGenerationReady_meth != NULL);
1017         LDKEvent_FundingBroadcastSafe_class =
1018                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKEvent$FundingBroadcastSafe;"));
1019         CHECK(LDKEvent_FundingBroadcastSafe_class != NULL);
1020         LDKEvent_FundingBroadcastSafe_meth = (*env)->GetMethodID(env, LDKEvent_FundingBroadcastSafe_class, "<init>", "(JJ)V");
1021         CHECK(LDKEvent_FundingBroadcastSafe_meth != NULL);
1022         LDKEvent_PaymentReceived_class =
1023                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKEvent$PaymentReceived;"));
1024         CHECK(LDKEvent_PaymentReceived_class != NULL);
1025         LDKEvent_PaymentReceived_meth = (*env)->GetMethodID(env, LDKEvent_PaymentReceived_class, "<init>", "([B[BJ)V");
1026         CHECK(LDKEvent_PaymentReceived_meth != NULL);
1027         LDKEvent_PaymentSent_class =
1028                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKEvent$PaymentSent;"));
1029         CHECK(LDKEvent_PaymentSent_class != NULL);
1030         LDKEvent_PaymentSent_meth = (*env)->GetMethodID(env, LDKEvent_PaymentSent_class, "<init>", "([B)V");
1031         CHECK(LDKEvent_PaymentSent_meth != NULL);
1032         LDKEvent_PaymentFailed_class =
1033                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKEvent$PaymentFailed;"));
1034         CHECK(LDKEvent_PaymentFailed_class != NULL);
1035         LDKEvent_PaymentFailed_meth = (*env)->GetMethodID(env, LDKEvent_PaymentFailed_class, "<init>", "([BZ)V");
1036         CHECK(LDKEvent_PaymentFailed_meth != NULL);
1037         LDKEvent_PendingHTLCsForwardable_class =
1038                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKEvent$PendingHTLCsForwardable;"));
1039         CHECK(LDKEvent_PendingHTLCsForwardable_class != NULL);
1040         LDKEvent_PendingHTLCsForwardable_meth = (*env)->GetMethodID(env, LDKEvent_PendingHTLCsForwardable_class, "<init>", "(J)V");
1041         CHECK(LDKEvent_PendingHTLCsForwardable_meth != NULL);
1042         LDKEvent_SpendableOutputs_class =
1043                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKEvent$SpendableOutputs;"));
1044         CHECK(LDKEvent_SpendableOutputs_class != NULL);
1045         LDKEvent_SpendableOutputs_meth = (*env)->GetMethodID(env, LDKEvent_SpendableOutputs_class, "<init>", "([J)V");
1046         CHECK(LDKEvent_SpendableOutputs_meth != NULL);
1047 }
1048 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKEvent_1ref_1from_1ptr (JNIEnv * _env, jclass _c, jlong ptr) {
1049         LDKEvent *obj = (LDKEvent*)ptr;
1050         switch(obj->tag) {
1051                 case LDKEvent_FundingGenerationReady: {
1052                         jbyteArray temporary_channel_id_arr = (*_env)->NewByteArray(_env, 32);
1053                         (*_env)->SetByteArrayRegion(_env, temporary_channel_id_arr, 0, 32, obj->funding_generation_ready.temporary_channel_id.data);
1054                         LDKCVec_u8Z output_script_var = obj->funding_generation_ready.output_script;
1055                         jbyteArray output_script_arr = (*_env)->NewByteArray(_env, output_script_var.datalen);
1056                         (*_env)->SetByteArrayRegion(_env, output_script_arr, 0, output_script_var.datalen, output_script_var.data);
1057                         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);
1058                 }
1059                 case LDKEvent_FundingBroadcastSafe: {
1060                         LDKOutPoint funding_txo_var = obj->funding_broadcast_safe.funding_txo;
1061                         CHECK((((long)funding_txo_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1062                         CHECK((((long)&funding_txo_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1063                         long funding_txo_ref = (long)funding_txo_var.inner & ~1;
1064                         return (*_env)->NewObject(_env, LDKEvent_FundingBroadcastSafe_class, LDKEvent_FundingBroadcastSafe_meth, funding_txo_ref, obj->funding_broadcast_safe.user_channel_id);
1065                 }
1066                 case LDKEvent_PaymentReceived: {
1067                         jbyteArray payment_hash_arr = (*_env)->NewByteArray(_env, 32);
1068                         (*_env)->SetByteArrayRegion(_env, payment_hash_arr, 0, 32, obj->payment_received.payment_hash.data);
1069                         jbyteArray payment_secret_arr = (*_env)->NewByteArray(_env, 32);
1070                         (*_env)->SetByteArrayRegion(_env, payment_secret_arr, 0, 32, obj->payment_received.payment_secret.data);
1071                         return (*_env)->NewObject(_env, LDKEvent_PaymentReceived_class, LDKEvent_PaymentReceived_meth, payment_hash_arr, payment_secret_arr, obj->payment_received.amt);
1072                 }
1073                 case LDKEvent_PaymentSent: {
1074                         jbyteArray payment_preimage_arr = (*_env)->NewByteArray(_env, 32);
1075                         (*_env)->SetByteArrayRegion(_env, payment_preimage_arr, 0, 32, obj->payment_sent.payment_preimage.data);
1076                         return (*_env)->NewObject(_env, LDKEvent_PaymentSent_class, LDKEvent_PaymentSent_meth, payment_preimage_arr);
1077                 }
1078                 case LDKEvent_PaymentFailed: {
1079                         jbyteArray payment_hash_arr = (*_env)->NewByteArray(_env, 32);
1080                         (*_env)->SetByteArrayRegion(_env, payment_hash_arr, 0, 32, obj->payment_failed.payment_hash.data);
1081                         return (*_env)->NewObject(_env, LDKEvent_PaymentFailed_class, LDKEvent_PaymentFailed_meth, payment_hash_arr, obj->payment_failed.rejected_by_dest);
1082                 }
1083                 case LDKEvent_PendingHTLCsForwardable: {
1084                         return (*_env)->NewObject(_env, LDKEvent_PendingHTLCsForwardable_class, LDKEvent_PendingHTLCsForwardable_meth, obj->pending_htl_cs_forwardable.time_forwardable);
1085                 }
1086                 case LDKEvent_SpendableOutputs: {
1087                         LDKCVec_SpendableOutputDescriptorZ outputs_var = obj->spendable_outputs.outputs;
1088                         jlongArray outputs_arr = (*_env)->NewLongArray(_env, outputs_var.datalen);
1089                         jlong *outputs_arr_ptr = (*_env)->GetPrimitiveArrayCritical(_env, outputs_arr, NULL);
1090                         for (size_t b = 0; b < outputs_var.datalen; b++) {
1091                                 long arr_conv_27_ref = (long)&outputs_var.data[b];
1092                                 outputs_arr_ptr[b] = arr_conv_27_ref;
1093                         }
1094                         (*_env)->ReleasePrimitiveArrayCritical(_env, outputs_arr, outputs_arr_ptr, 0);
1095                         return (*_env)->NewObject(_env, LDKEvent_SpendableOutputs_class, LDKEvent_SpendableOutputs_meth, outputs_arr);
1096                 }
1097                 default: abort();
1098         }
1099 }
1100 static jclass LDKErrorAction_DisconnectPeer_class = NULL;
1101 static jmethodID LDKErrorAction_DisconnectPeer_meth = NULL;
1102 static jclass LDKErrorAction_IgnoreError_class = NULL;
1103 static jmethodID LDKErrorAction_IgnoreError_meth = NULL;
1104 static jclass LDKErrorAction_SendErrorMessage_class = NULL;
1105 static jmethodID LDKErrorAction_SendErrorMessage_meth = NULL;
1106 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_00024LDKErrorAction_init (JNIEnv * env, jclass _a) {
1107         LDKErrorAction_DisconnectPeer_class =
1108                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKErrorAction$DisconnectPeer;"));
1109         CHECK(LDKErrorAction_DisconnectPeer_class != NULL);
1110         LDKErrorAction_DisconnectPeer_meth = (*env)->GetMethodID(env, LDKErrorAction_DisconnectPeer_class, "<init>", "(J)V");
1111         CHECK(LDKErrorAction_DisconnectPeer_meth != NULL);
1112         LDKErrorAction_IgnoreError_class =
1113                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKErrorAction$IgnoreError;"));
1114         CHECK(LDKErrorAction_IgnoreError_class != NULL);
1115         LDKErrorAction_IgnoreError_meth = (*env)->GetMethodID(env, LDKErrorAction_IgnoreError_class, "<init>", "()V");
1116         CHECK(LDKErrorAction_IgnoreError_meth != NULL);
1117         LDKErrorAction_SendErrorMessage_class =
1118                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKErrorAction$SendErrorMessage;"));
1119         CHECK(LDKErrorAction_SendErrorMessage_class != NULL);
1120         LDKErrorAction_SendErrorMessage_meth = (*env)->GetMethodID(env, LDKErrorAction_SendErrorMessage_class, "<init>", "(J)V");
1121         CHECK(LDKErrorAction_SendErrorMessage_meth != NULL);
1122 }
1123 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKErrorAction_1ref_1from_1ptr (JNIEnv * _env, jclass _c, jlong ptr) {
1124         LDKErrorAction *obj = (LDKErrorAction*)ptr;
1125         switch(obj->tag) {
1126                 case LDKErrorAction_DisconnectPeer: {
1127                         LDKErrorMessage msg_var = obj->disconnect_peer.msg;
1128                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1129                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1130                         long msg_ref = (long)msg_var.inner & ~1;
1131                         return (*_env)->NewObject(_env, LDKErrorAction_DisconnectPeer_class, LDKErrorAction_DisconnectPeer_meth, msg_ref);
1132                 }
1133                 case LDKErrorAction_IgnoreError: {
1134                         return (*_env)->NewObject(_env, LDKErrorAction_IgnoreError_class, LDKErrorAction_IgnoreError_meth);
1135                 }
1136                 case LDKErrorAction_SendErrorMessage: {
1137                         LDKErrorMessage msg_var = obj->send_error_message.msg;
1138                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1139                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1140                         long msg_ref = (long)msg_var.inner & ~1;
1141                         return (*_env)->NewObject(_env, LDKErrorAction_SendErrorMessage_class, LDKErrorAction_SendErrorMessage_meth, msg_ref);
1142                 }
1143                 default: abort();
1144         }
1145 }
1146 static jclass LDKHTLCFailChannelUpdate_ChannelUpdateMessage_class = NULL;
1147 static jmethodID LDKHTLCFailChannelUpdate_ChannelUpdateMessage_meth = NULL;
1148 static jclass LDKHTLCFailChannelUpdate_ChannelClosed_class = NULL;
1149 static jmethodID LDKHTLCFailChannelUpdate_ChannelClosed_meth = NULL;
1150 static jclass LDKHTLCFailChannelUpdate_NodeFailure_class = NULL;
1151 static jmethodID LDKHTLCFailChannelUpdate_NodeFailure_meth = NULL;
1152 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_00024LDKHTLCFailChannelUpdate_init (JNIEnv * env, jclass _a) {
1153         LDKHTLCFailChannelUpdate_ChannelUpdateMessage_class =
1154                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKHTLCFailChannelUpdate$ChannelUpdateMessage;"));
1155         CHECK(LDKHTLCFailChannelUpdate_ChannelUpdateMessage_class != NULL);
1156         LDKHTLCFailChannelUpdate_ChannelUpdateMessage_meth = (*env)->GetMethodID(env, LDKHTLCFailChannelUpdate_ChannelUpdateMessage_class, "<init>", "(J)V");
1157         CHECK(LDKHTLCFailChannelUpdate_ChannelUpdateMessage_meth != NULL);
1158         LDKHTLCFailChannelUpdate_ChannelClosed_class =
1159                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKHTLCFailChannelUpdate$ChannelClosed;"));
1160         CHECK(LDKHTLCFailChannelUpdate_ChannelClosed_class != NULL);
1161         LDKHTLCFailChannelUpdate_ChannelClosed_meth = (*env)->GetMethodID(env, LDKHTLCFailChannelUpdate_ChannelClosed_class, "<init>", "(JZ)V");
1162         CHECK(LDKHTLCFailChannelUpdate_ChannelClosed_meth != NULL);
1163         LDKHTLCFailChannelUpdate_NodeFailure_class =
1164                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKHTLCFailChannelUpdate$NodeFailure;"));
1165         CHECK(LDKHTLCFailChannelUpdate_NodeFailure_class != NULL);
1166         LDKHTLCFailChannelUpdate_NodeFailure_meth = (*env)->GetMethodID(env, LDKHTLCFailChannelUpdate_NodeFailure_class, "<init>", "([BZ)V");
1167         CHECK(LDKHTLCFailChannelUpdate_NodeFailure_meth != NULL);
1168 }
1169 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKHTLCFailChannelUpdate_1ref_1from_1ptr (JNIEnv * _env, jclass _c, jlong ptr) {
1170         LDKHTLCFailChannelUpdate *obj = (LDKHTLCFailChannelUpdate*)ptr;
1171         switch(obj->tag) {
1172                 case LDKHTLCFailChannelUpdate_ChannelUpdateMessage: {
1173                         LDKChannelUpdate msg_var = obj->channel_update_message.msg;
1174                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1175                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1176                         long msg_ref = (long)msg_var.inner & ~1;
1177                         return (*_env)->NewObject(_env, LDKHTLCFailChannelUpdate_ChannelUpdateMessage_class, LDKHTLCFailChannelUpdate_ChannelUpdateMessage_meth, msg_ref);
1178                 }
1179                 case LDKHTLCFailChannelUpdate_ChannelClosed: {
1180                         return (*_env)->NewObject(_env, LDKHTLCFailChannelUpdate_ChannelClosed_class, LDKHTLCFailChannelUpdate_ChannelClosed_meth, obj->channel_closed.short_channel_id, obj->channel_closed.is_permanent);
1181                 }
1182                 case LDKHTLCFailChannelUpdate_NodeFailure: {
1183                         jbyteArray node_id_arr = (*_env)->NewByteArray(_env, 33);
1184                         (*_env)->SetByteArrayRegion(_env, node_id_arr, 0, 33, obj->node_failure.node_id.compressed_form);
1185                         return (*_env)->NewObject(_env, LDKHTLCFailChannelUpdate_NodeFailure_class, LDKHTLCFailChannelUpdate_NodeFailure_meth, node_id_arr, obj->node_failure.is_permanent);
1186                 }
1187                 default: abort();
1188         }
1189 }
1190 static jclass LDKMessageSendEvent_SendAcceptChannel_class = NULL;
1191 static jmethodID LDKMessageSendEvent_SendAcceptChannel_meth = NULL;
1192 static jclass LDKMessageSendEvent_SendOpenChannel_class = NULL;
1193 static jmethodID LDKMessageSendEvent_SendOpenChannel_meth = NULL;
1194 static jclass LDKMessageSendEvent_SendFundingCreated_class = NULL;
1195 static jmethodID LDKMessageSendEvent_SendFundingCreated_meth = NULL;
1196 static jclass LDKMessageSendEvent_SendFundingSigned_class = NULL;
1197 static jmethodID LDKMessageSendEvent_SendFundingSigned_meth = NULL;
1198 static jclass LDKMessageSendEvent_SendFundingLocked_class = NULL;
1199 static jmethodID LDKMessageSendEvent_SendFundingLocked_meth = NULL;
1200 static jclass LDKMessageSendEvent_SendAnnouncementSignatures_class = NULL;
1201 static jmethodID LDKMessageSendEvent_SendAnnouncementSignatures_meth = NULL;
1202 static jclass LDKMessageSendEvent_UpdateHTLCs_class = NULL;
1203 static jmethodID LDKMessageSendEvent_UpdateHTLCs_meth = NULL;
1204 static jclass LDKMessageSendEvent_SendRevokeAndACK_class = NULL;
1205 static jmethodID LDKMessageSendEvent_SendRevokeAndACK_meth = NULL;
1206 static jclass LDKMessageSendEvent_SendClosingSigned_class = NULL;
1207 static jmethodID LDKMessageSendEvent_SendClosingSigned_meth = NULL;
1208 static jclass LDKMessageSendEvent_SendShutdown_class = NULL;
1209 static jmethodID LDKMessageSendEvent_SendShutdown_meth = NULL;
1210 static jclass LDKMessageSendEvent_SendChannelReestablish_class = NULL;
1211 static jmethodID LDKMessageSendEvent_SendChannelReestablish_meth = NULL;
1212 static jclass LDKMessageSendEvent_BroadcastChannelAnnouncement_class = NULL;
1213 static jmethodID LDKMessageSendEvent_BroadcastChannelAnnouncement_meth = NULL;
1214 static jclass LDKMessageSendEvent_BroadcastNodeAnnouncement_class = NULL;
1215 static jmethodID LDKMessageSendEvent_BroadcastNodeAnnouncement_meth = NULL;
1216 static jclass LDKMessageSendEvent_BroadcastChannelUpdate_class = NULL;
1217 static jmethodID LDKMessageSendEvent_BroadcastChannelUpdate_meth = NULL;
1218 static jclass LDKMessageSendEvent_HandleError_class = NULL;
1219 static jmethodID LDKMessageSendEvent_HandleError_meth = NULL;
1220 static jclass LDKMessageSendEvent_PaymentFailureNetworkUpdate_class = NULL;
1221 static jmethodID LDKMessageSendEvent_PaymentFailureNetworkUpdate_meth = NULL;
1222 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_00024LDKMessageSendEvent_init (JNIEnv * env, jclass _a) {
1223         LDKMessageSendEvent_SendAcceptChannel_class =
1224                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKMessageSendEvent$SendAcceptChannel;"));
1225         CHECK(LDKMessageSendEvent_SendAcceptChannel_class != NULL);
1226         LDKMessageSendEvent_SendAcceptChannel_meth = (*env)->GetMethodID(env, LDKMessageSendEvent_SendAcceptChannel_class, "<init>", "([BJ)V");
1227         CHECK(LDKMessageSendEvent_SendAcceptChannel_meth != NULL);
1228         LDKMessageSendEvent_SendOpenChannel_class =
1229                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKMessageSendEvent$SendOpenChannel;"));
1230         CHECK(LDKMessageSendEvent_SendOpenChannel_class != NULL);
1231         LDKMessageSendEvent_SendOpenChannel_meth = (*env)->GetMethodID(env, LDKMessageSendEvent_SendOpenChannel_class, "<init>", "([BJ)V");
1232         CHECK(LDKMessageSendEvent_SendOpenChannel_meth != NULL);
1233         LDKMessageSendEvent_SendFundingCreated_class =
1234                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKMessageSendEvent$SendFundingCreated;"));
1235         CHECK(LDKMessageSendEvent_SendFundingCreated_class != NULL);
1236         LDKMessageSendEvent_SendFundingCreated_meth = (*env)->GetMethodID(env, LDKMessageSendEvent_SendFundingCreated_class, "<init>", "([BJ)V");
1237         CHECK(LDKMessageSendEvent_SendFundingCreated_meth != NULL);
1238         LDKMessageSendEvent_SendFundingSigned_class =
1239                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKMessageSendEvent$SendFundingSigned;"));
1240         CHECK(LDKMessageSendEvent_SendFundingSigned_class != NULL);
1241         LDKMessageSendEvent_SendFundingSigned_meth = (*env)->GetMethodID(env, LDKMessageSendEvent_SendFundingSigned_class, "<init>", "([BJ)V");
1242         CHECK(LDKMessageSendEvent_SendFundingSigned_meth != NULL);
1243         LDKMessageSendEvent_SendFundingLocked_class =
1244                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKMessageSendEvent$SendFundingLocked;"));
1245         CHECK(LDKMessageSendEvent_SendFundingLocked_class != NULL);
1246         LDKMessageSendEvent_SendFundingLocked_meth = (*env)->GetMethodID(env, LDKMessageSendEvent_SendFundingLocked_class, "<init>", "([BJ)V");
1247         CHECK(LDKMessageSendEvent_SendFundingLocked_meth != NULL);
1248         LDKMessageSendEvent_SendAnnouncementSignatures_class =
1249                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKMessageSendEvent$SendAnnouncementSignatures;"));
1250         CHECK(LDKMessageSendEvent_SendAnnouncementSignatures_class != NULL);
1251         LDKMessageSendEvent_SendAnnouncementSignatures_meth = (*env)->GetMethodID(env, LDKMessageSendEvent_SendAnnouncementSignatures_class, "<init>", "([BJ)V");
1252         CHECK(LDKMessageSendEvent_SendAnnouncementSignatures_meth != NULL);
1253         LDKMessageSendEvent_UpdateHTLCs_class =
1254                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKMessageSendEvent$UpdateHTLCs;"));
1255         CHECK(LDKMessageSendEvent_UpdateHTLCs_class != NULL);
1256         LDKMessageSendEvent_UpdateHTLCs_meth = (*env)->GetMethodID(env, LDKMessageSendEvent_UpdateHTLCs_class, "<init>", "([BJ)V");
1257         CHECK(LDKMessageSendEvent_UpdateHTLCs_meth != NULL);
1258         LDKMessageSendEvent_SendRevokeAndACK_class =
1259                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKMessageSendEvent$SendRevokeAndACK;"));
1260         CHECK(LDKMessageSendEvent_SendRevokeAndACK_class != NULL);
1261         LDKMessageSendEvent_SendRevokeAndACK_meth = (*env)->GetMethodID(env, LDKMessageSendEvent_SendRevokeAndACK_class, "<init>", "([BJ)V");
1262         CHECK(LDKMessageSendEvent_SendRevokeAndACK_meth != NULL);
1263         LDKMessageSendEvent_SendClosingSigned_class =
1264                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKMessageSendEvent$SendClosingSigned;"));
1265         CHECK(LDKMessageSendEvent_SendClosingSigned_class != NULL);
1266         LDKMessageSendEvent_SendClosingSigned_meth = (*env)->GetMethodID(env, LDKMessageSendEvent_SendClosingSigned_class, "<init>", "([BJ)V");
1267         CHECK(LDKMessageSendEvent_SendClosingSigned_meth != NULL);
1268         LDKMessageSendEvent_SendShutdown_class =
1269                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKMessageSendEvent$SendShutdown;"));
1270         CHECK(LDKMessageSendEvent_SendShutdown_class != NULL);
1271         LDKMessageSendEvent_SendShutdown_meth = (*env)->GetMethodID(env, LDKMessageSendEvent_SendShutdown_class, "<init>", "([BJ)V");
1272         CHECK(LDKMessageSendEvent_SendShutdown_meth != NULL);
1273         LDKMessageSendEvent_SendChannelReestablish_class =
1274                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKMessageSendEvent$SendChannelReestablish;"));
1275         CHECK(LDKMessageSendEvent_SendChannelReestablish_class != NULL);
1276         LDKMessageSendEvent_SendChannelReestablish_meth = (*env)->GetMethodID(env, LDKMessageSendEvent_SendChannelReestablish_class, "<init>", "([BJ)V");
1277         CHECK(LDKMessageSendEvent_SendChannelReestablish_meth != NULL);
1278         LDKMessageSendEvent_BroadcastChannelAnnouncement_class =
1279                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKMessageSendEvent$BroadcastChannelAnnouncement;"));
1280         CHECK(LDKMessageSendEvent_BroadcastChannelAnnouncement_class != NULL);
1281         LDKMessageSendEvent_BroadcastChannelAnnouncement_meth = (*env)->GetMethodID(env, LDKMessageSendEvent_BroadcastChannelAnnouncement_class, "<init>", "(JJ)V");
1282         CHECK(LDKMessageSendEvent_BroadcastChannelAnnouncement_meth != NULL);
1283         LDKMessageSendEvent_BroadcastNodeAnnouncement_class =
1284                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKMessageSendEvent$BroadcastNodeAnnouncement;"));
1285         CHECK(LDKMessageSendEvent_BroadcastNodeAnnouncement_class != NULL);
1286         LDKMessageSendEvent_BroadcastNodeAnnouncement_meth = (*env)->GetMethodID(env, LDKMessageSendEvent_BroadcastNodeAnnouncement_class, "<init>", "(J)V");
1287         CHECK(LDKMessageSendEvent_BroadcastNodeAnnouncement_meth != NULL);
1288         LDKMessageSendEvent_BroadcastChannelUpdate_class =
1289                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKMessageSendEvent$BroadcastChannelUpdate;"));
1290         CHECK(LDKMessageSendEvent_BroadcastChannelUpdate_class != NULL);
1291         LDKMessageSendEvent_BroadcastChannelUpdate_meth = (*env)->GetMethodID(env, LDKMessageSendEvent_BroadcastChannelUpdate_class, "<init>", "(J)V");
1292         CHECK(LDKMessageSendEvent_BroadcastChannelUpdate_meth != NULL);
1293         LDKMessageSendEvent_HandleError_class =
1294                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKMessageSendEvent$HandleError;"));
1295         CHECK(LDKMessageSendEvent_HandleError_class != NULL);
1296         LDKMessageSendEvent_HandleError_meth = (*env)->GetMethodID(env, LDKMessageSendEvent_HandleError_class, "<init>", "([BJ)V");
1297         CHECK(LDKMessageSendEvent_HandleError_meth != NULL);
1298         LDKMessageSendEvent_PaymentFailureNetworkUpdate_class =
1299                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKMessageSendEvent$PaymentFailureNetworkUpdate;"));
1300         CHECK(LDKMessageSendEvent_PaymentFailureNetworkUpdate_class != NULL);
1301         LDKMessageSendEvent_PaymentFailureNetworkUpdate_meth = (*env)->GetMethodID(env, LDKMessageSendEvent_PaymentFailureNetworkUpdate_class, "<init>", "(J)V");
1302         CHECK(LDKMessageSendEvent_PaymentFailureNetworkUpdate_meth != NULL);
1303 }
1304 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKMessageSendEvent_1ref_1from_1ptr (JNIEnv * _env, jclass _c, jlong ptr) {
1305         LDKMessageSendEvent *obj = (LDKMessageSendEvent*)ptr;
1306         switch(obj->tag) {
1307                 case LDKMessageSendEvent_SendAcceptChannel: {
1308                         jbyteArray node_id_arr = (*_env)->NewByteArray(_env, 33);
1309                         (*_env)->SetByteArrayRegion(_env, node_id_arr, 0, 33, obj->send_accept_channel.node_id.compressed_form);
1310                         LDKAcceptChannel msg_var = obj->send_accept_channel.msg;
1311                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1312                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1313                         long msg_ref = (long)msg_var.inner & ~1;
1314                         return (*_env)->NewObject(_env, LDKMessageSendEvent_SendAcceptChannel_class, LDKMessageSendEvent_SendAcceptChannel_meth, node_id_arr, msg_ref);
1315                 }
1316                 case LDKMessageSendEvent_SendOpenChannel: {
1317                         jbyteArray node_id_arr = (*_env)->NewByteArray(_env, 33);
1318                         (*_env)->SetByteArrayRegion(_env, node_id_arr, 0, 33, obj->send_open_channel.node_id.compressed_form);
1319                         LDKOpenChannel msg_var = obj->send_open_channel.msg;
1320                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1321                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1322                         long msg_ref = (long)msg_var.inner & ~1;
1323                         return (*_env)->NewObject(_env, LDKMessageSendEvent_SendOpenChannel_class, LDKMessageSendEvent_SendOpenChannel_meth, node_id_arr, msg_ref);
1324                 }
1325                 case LDKMessageSendEvent_SendFundingCreated: {
1326                         jbyteArray node_id_arr = (*_env)->NewByteArray(_env, 33);
1327                         (*_env)->SetByteArrayRegion(_env, node_id_arr, 0, 33, obj->send_funding_created.node_id.compressed_form);
1328                         LDKFundingCreated msg_var = obj->send_funding_created.msg;
1329                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1330                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1331                         long msg_ref = (long)msg_var.inner & ~1;
1332                         return (*_env)->NewObject(_env, LDKMessageSendEvent_SendFundingCreated_class, LDKMessageSendEvent_SendFundingCreated_meth, node_id_arr, msg_ref);
1333                 }
1334                 case LDKMessageSendEvent_SendFundingSigned: {
1335                         jbyteArray node_id_arr = (*_env)->NewByteArray(_env, 33);
1336                         (*_env)->SetByteArrayRegion(_env, node_id_arr, 0, 33, obj->send_funding_signed.node_id.compressed_form);
1337                         LDKFundingSigned msg_var = obj->send_funding_signed.msg;
1338                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1339                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1340                         long msg_ref = (long)msg_var.inner & ~1;
1341                         return (*_env)->NewObject(_env, LDKMessageSendEvent_SendFundingSigned_class, LDKMessageSendEvent_SendFundingSigned_meth, node_id_arr, msg_ref);
1342                 }
1343                 case LDKMessageSendEvent_SendFundingLocked: {
1344                         jbyteArray node_id_arr = (*_env)->NewByteArray(_env, 33);
1345                         (*_env)->SetByteArrayRegion(_env, node_id_arr, 0, 33, obj->send_funding_locked.node_id.compressed_form);
1346                         LDKFundingLocked msg_var = obj->send_funding_locked.msg;
1347                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1348                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1349                         long msg_ref = (long)msg_var.inner & ~1;
1350                         return (*_env)->NewObject(_env, LDKMessageSendEvent_SendFundingLocked_class, LDKMessageSendEvent_SendFundingLocked_meth, node_id_arr, msg_ref);
1351                 }
1352                 case LDKMessageSendEvent_SendAnnouncementSignatures: {
1353                         jbyteArray node_id_arr = (*_env)->NewByteArray(_env, 33);
1354                         (*_env)->SetByteArrayRegion(_env, node_id_arr, 0, 33, obj->send_announcement_signatures.node_id.compressed_form);
1355                         LDKAnnouncementSignatures msg_var = obj->send_announcement_signatures.msg;
1356                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1357                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1358                         long msg_ref = (long)msg_var.inner & ~1;
1359                         return (*_env)->NewObject(_env, LDKMessageSendEvent_SendAnnouncementSignatures_class, LDKMessageSendEvent_SendAnnouncementSignatures_meth, node_id_arr, msg_ref);
1360                 }
1361                 case LDKMessageSendEvent_UpdateHTLCs: {
1362                         jbyteArray node_id_arr = (*_env)->NewByteArray(_env, 33);
1363                         (*_env)->SetByteArrayRegion(_env, node_id_arr, 0, 33, obj->update_htl_cs.node_id.compressed_form);
1364                         LDKCommitmentUpdate updates_var = obj->update_htl_cs.updates;
1365                         CHECK((((long)updates_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1366                         CHECK((((long)&updates_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1367                         long updates_ref = (long)updates_var.inner & ~1;
1368                         return (*_env)->NewObject(_env, LDKMessageSendEvent_UpdateHTLCs_class, LDKMessageSendEvent_UpdateHTLCs_meth, node_id_arr, updates_ref);
1369                 }
1370                 case LDKMessageSendEvent_SendRevokeAndACK: {
1371                         jbyteArray node_id_arr = (*_env)->NewByteArray(_env, 33);
1372                         (*_env)->SetByteArrayRegion(_env, node_id_arr, 0, 33, obj->send_revoke_and_ack.node_id.compressed_form);
1373                         LDKRevokeAndACK msg_var = obj->send_revoke_and_ack.msg;
1374                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1375                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1376                         long msg_ref = (long)msg_var.inner & ~1;
1377                         return (*_env)->NewObject(_env, LDKMessageSendEvent_SendRevokeAndACK_class, LDKMessageSendEvent_SendRevokeAndACK_meth, node_id_arr, msg_ref);
1378                 }
1379                 case LDKMessageSendEvent_SendClosingSigned: {
1380                         jbyteArray node_id_arr = (*_env)->NewByteArray(_env, 33);
1381                         (*_env)->SetByteArrayRegion(_env, node_id_arr, 0, 33, obj->send_closing_signed.node_id.compressed_form);
1382                         LDKClosingSigned msg_var = obj->send_closing_signed.msg;
1383                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1384                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1385                         long msg_ref = (long)msg_var.inner & ~1;
1386                         return (*_env)->NewObject(_env, LDKMessageSendEvent_SendClosingSigned_class, LDKMessageSendEvent_SendClosingSigned_meth, node_id_arr, msg_ref);
1387                 }
1388                 case LDKMessageSendEvent_SendShutdown: {
1389                         jbyteArray node_id_arr = (*_env)->NewByteArray(_env, 33);
1390                         (*_env)->SetByteArrayRegion(_env, node_id_arr, 0, 33, obj->send_shutdown.node_id.compressed_form);
1391                         LDKShutdown msg_var = obj->send_shutdown.msg;
1392                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1393                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1394                         long msg_ref = (long)msg_var.inner & ~1;
1395                         return (*_env)->NewObject(_env, LDKMessageSendEvent_SendShutdown_class, LDKMessageSendEvent_SendShutdown_meth, node_id_arr, msg_ref);
1396                 }
1397                 case LDKMessageSendEvent_SendChannelReestablish: {
1398                         jbyteArray node_id_arr = (*_env)->NewByteArray(_env, 33);
1399                         (*_env)->SetByteArrayRegion(_env, node_id_arr, 0, 33, obj->send_channel_reestablish.node_id.compressed_form);
1400                         LDKChannelReestablish msg_var = obj->send_channel_reestablish.msg;
1401                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1402                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1403                         long msg_ref = (long)msg_var.inner & ~1;
1404                         return (*_env)->NewObject(_env, LDKMessageSendEvent_SendChannelReestablish_class, LDKMessageSendEvent_SendChannelReestablish_meth, node_id_arr, msg_ref);
1405                 }
1406                 case LDKMessageSendEvent_BroadcastChannelAnnouncement: {
1407                         LDKChannelAnnouncement msg_var = obj->broadcast_channel_announcement.msg;
1408                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1409                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1410                         long msg_ref = (long)msg_var.inner & ~1;
1411                         LDKChannelUpdate update_msg_var = obj->broadcast_channel_announcement.update_msg;
1412                         CHECK((((long)update_msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1413                         CHECK((((long)&update_msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1414                         long update_msg_ref = (long)update_msg_var.inner & ~1;
1415                         return (*_env)->NewObject(_env, LDKMessageSendEvent_BroadcastChannelAnnouncement_class, LDKMessageSendEvent_BroadcastChannelAnnouncement_meth, msg_ref, update_msg_ref);
1416                 }
1417                 case LDKMessageSendEvent_BroadcastNodeAnnouncement: {
1418                         LDKNodeAnnouncement msg_var = obj->broadcast_node_announcement.msg;
1419                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1420                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1421                         long msg_ref = (long)msg_var.inner & ~1;
1422                         return (*_env)->NewObject(_env, LDKMessageSendEvent_BroadcastNodeAnnouncement_class, LDKMessageSendEvent_BroadcastNodeAnnouncement_meth, msg_ref);
1423                 }
1424                 case LDKMessageSendEvent_BroadcastChannelUpdate: {
1425                         LDKChannelUpdate msg_var = obj->broadcast_channel_update.msg;
1426                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1427                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1428                         long msg_ref = (long)msg_var.inner & ~1;
1429                         return (*_env)->NewObject(_env, LDKMessageSendEvent_BroadcastChannelUpdate_class, LDKMessageSendEvent_BroadcastChannelUpdate_meth, msg_ref);
1430                 }
1431                 case LDKMessageSendEvent_HandleError: {
1432                         jbyteArray node_id_arr = (*_env)->NewByteArray(_env, 33);
1433                         (*_env)->SetByteArrayRegion(_env, node_id_arr, 0, 33, obj->handle_error.node_id.compressed_form);
1434                         long action_ref = (long)&obj->handle_error.action;
1435                         return (*_env)->NewObject(_env, LDKMessageSendEvent_HandleError_class, LDKMessageSendEvent_HandleError_meth, node_id_arr, action_ref);
1436                 }
1437                 case LDKMessageSendEvent_PaymentFailureNetworkUpdate: {
1438                         long update_ref = (long)&obj->payment_failure_network_update.update;
1439                         return (*_env)->NewObject(_env, LDKMessageSendEvent_PaymentFailureNetworkUpdate_class, LDKMessageSendEvent_PaymentFailureNetworkUpdate_meth, update_ref);
1440                 }
1441                 default: abort();
1442         }
1443 }
1444 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1MessageSendEvent_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
1445         LDKCVecTempl_MessageSendEvent *vec = (LDKCVecTempl_MessageSendEvent*)ptr;
1446         return (*env)->NewObject(env, slicedef_cls, slicedef_meth, (long)vec->data, (long)vec->datalen, sizeof(LDKMessageSendEvent));
1447 }
1448 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1MessageSendEvent_1new(JNIEnv *env, jclass _b, jlongArray elems){
1449         LDKCVecTempl_MessageSendEvent *ret = MALLOC(sizeof(LDKCVecTempl_MessageSendEvent), "LDKCVecTempl_MessageSendEvent");
1450         ret->datalen = (*env)->GetArrayLength(env, elems);
1451         if (ret->datalen == 0) {
1452                 ret->data = NULL;
1453         } else {
1454                 ret->data = MALLOC(sizeof(LDKMessageSendEvent) * ret->datalen, "LDKCVecTempl_MessageSendEvent Data");
1455                 jlong *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
1456                 for (size_t i = 0; i < ret->datalen; i++) {
1457                         jlong arr_elem = java_elems[i];
1458                         LDKMessageSendEvent arr_elem_conv = *(LDKMessageSendEvent*)arr_elem;
1459                         FREE((void*)arr_elem);
1460                         ret->data[i] = arr_elem_conv;
1461                 }
1462                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
1463         }
1464         return (long)ret;
1465 }
1466 typedef struct LDKMessageSendEventsProvider_JCalls {
1467         atomic_size_t refcnt;
1468         JavaVM *vm;
1469         jweak o;
1470         jmethodID get_and_clear_pending_msg_events_meth;
1471 } LDKMessageSendEventsProvider_JCalls;
1472 LDKCVec_MessageSendEventZ get_and_clear_pending_msg_events_jcall(const void* this_arg) {
1473         LDKMessageSendEventsProvider_JCalls *j_calls = (LDKMessageSendEventsProvider_JCalls*) this_arg;
1474         JNIEnv *_env;
1475         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
1476         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
1477         CHECK(obj != NULL);
1478         jlongArray arg = (*_env)->CallObjectMethod(_env, obj, j_calls->get_and_clear_pending_msg_events_meth);
1479         LDKCVec_MessageSendEventZ arg_constr;
1480         arg_constr.datalen = (*_env)->GetArrayLength (_env, arg);
1481         if (arg_constr.datalen > 0)
1482                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKMessageSendEvent), "LDKCVec_MessageSendEventZ Elements");
1483         else
1484                 arg_constr.data = NULL;
1485         long* arg_vals = (*_env)->GetLongArrayElements (_env, arg, NULL);
1486         for (size_t s = 0; s < arg_constr.datalen; s++) {
1487                 long arr_conv_18 = arg_vals[s];
1488                 LDKMessageSendEvent arr_conv_18_conv = *(LDKMessageSendEvent*)arr_conv_18;
1489                 FREE((void*)arr_conv_18);
1490                 arg_constr.data[s] = arr_conv_18_conv;
1491         }
1492         (*_env)->ReleaseLongArrayElements (_env, arg, arg_vals, 0);
1493         return arg_constr;
1494 }
1495 static void LDKMessageSendEventsProvider_JCalls_free(void* this_arg) {
1496         LDKMessageSendEventsProvider_JCalls *j_calls = (LDKMessageSendEventsProvider_JCalls*) this_arg;
1497         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
1498                 JNIEnv *env;
1499                 DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
1500                 (*env)->DeleteWeakGlobalRef(env, j_calls->o);
1501                 FREE(j_calls);
1502         }
1503 }
1504 static void* LDKMessageSendEventsProvider_JCalls_clone(const void* this_arg) {
1505         LDKMessageSendEventsProvider_JCalls *j_calls = (LDKMessageSendEventsProvider_JCalls*) this_arg;
1506         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
1507         return (void*) this_arg;
1508 }
1509 static inline LDKMessageSendEventsProvider LDKMessageSendEventsProvider_init (JNIEnv * env, jclass _a, jobject o) {
1510         jclass c = (*env)->GetObjectClass(env, o);
1511         CHECK(c != NULL);
1512         LDKMessageSendEventsProvider_JCalls *calls = MALLOC(sizeof(LDKMessageSendEventsProvider_JCalls), "LDKMessageSendEventsProvider_JCalls");
1513         atomic_init(&calls->refcnt, 1);
1514         DO_ASSERT((*env)->GetJavaVM(env, &calls->vm) == 0);
1515         calls->o = (*env)->NewWeakGlobalRef(env, o);
1516         calls->get_and_clear_pending_msg_events_meth = (*env)->GetMethodID(env, c, "get_and_clear_pending_msg_events", "()[J");
1517         CHECK(calls->get_and_clear_pending_msg_events_meth != NULL);
1518
1519         LDKMessageSendEventsProvider ret = {
1520                 .this_arg = (void*) calls,
1521                 .get_and_clear_pending_msg_events = get_and_clear_pending_msg_events_jcall,
1522                 .free = LDKMessageSendEventsProvider_JCalls_free,
1523         };
1524         return ret;
1525 }
1526 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_LDKMessageSendEventsProvider_1new (JNIEnv * env, jclass _a, jobject o) {
1527         LDKMessageSendEventsProvider *res_ptr = MALLOC(sizeof(LDKMessageSendEventsProvider), "LDKMessageSendEventsProvider");
1528         *res_ptr = LDKMessageSendEventsProvider_init(env, _a, o);
1529         return (long)res_ptr;
1530 }
1531 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKMessageSendEventsProvider_1get_1obj_1from_1jcalls (JNIEnv * env, jclass _a, jlong val) {
1532         jobject ret = (*env)->NewLocalRef(env, ((LDKMessageSendEventsProvider_JCalls*)val)->o);
1533         CHECK(ret != NULL);
1534         return ret;
1535 }
1536 JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_MessageSendEventsProvider_1get_1and_1clear_1pending_1msg_1events(JNIEnv * _env, jclass _b, jlong this_arg) {
1537         LDKMessageSendEventsProvider* this_arg_conv = (LDKMessageSendEventsProvider*)this_arg;
1538         LDKCVec_MessageSendEventZ ret_var = (this_arg_conv->get_and_clear_pending_msg_events)(this_arg_conv->this_arg);
1539         jlongArray ret_arr = (*_env)->NewLongArray(_env, ret_var.datalen);
1540         jlong *ret_arr_ptr = (*_env)->GetPrimitiveArrayCritical(_env, ret_arr, NULL);
1541         for (size_t s = 0; s < ret_var.datalen; s++) {
1542                 LDKMessageSendEvent *arr_conv_18_copy = MALLOC(sizeof(LDKMessageSendEvent), "LDKMessageSendEvent");
1543                 *arr_conv_18_copy = MessageSendEvent_clone(&ret_var.data[s]);
1544                 long arr_conv_18_ref = (long)arr_conv_18_copy;
1545                 ret_arr_ptr[s] = arr_conv_18_ref;
1546         }
1547         (*_env)->ReleasePrimitiveArrayCritical(_env, ret_arr, ret_arr_ptr, 0);
1548         CVec_MessageSendEventZ_free(ret_var);
1549         return ret_arr;
1550 }
1551
1552 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1Event_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
1553         LDKCVecTempl_Event *vec = (LDKCVecTempl_Event*)ptr;
1554         return (*env)->NewObject(env, slicedef_cls, slicedef_meth, (long)vec->data, (long)vec->datalen, sizeof(LDKEvent));
1555 }
1556 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1Event_1new(JNIEnv *env, jclass _b, jlongArray elems){
1557         LDKCVecTempl_Event *ret = MALLOC(sizeof(LDKCVecTempl_Event), "LDKCVecTempl_Event");
1558         ret->datalen = (*env)->GetArrayLength(env, elems);
1559         if (ret->datalen == 0) {
1560                 ret->data = NULL;
1561         } else {
1562                 ret->data = MALLOC(sizeof(LDKEvent) * ret->datalen, "LDKCVecTempl_Event Data");
1563                 jlong *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
1564                 for (size_t i = 0; i < ret->datalen; i++) {
1565                         jlong arr_elem = java_elems[i];
1566                         LDKEvent arr_elem_conv = *(LDKEvent*)arr_elem;
1567                         FREE((void*)arr_elem);
1568                         ret->data[i] = arr_elem_conv;
1569                 }
1570                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
1571         }
1572         return (long)ret;
1573 }
1574 typedef struct LDKEventsProvider_JCalls {
1575         atomic_size_t refcnt;
1576         JavaVM *vm;
1577         jweak o;
1578         jmethodID get_and_clear_pending_events_meth;
1579 } LDKEventsProvider_JCalls;
1580 LDKCVec_EventZ get_and_clear_pending_events_jcall(const void* this_arg) {
1581         LDKEventsProvider_JCalls *j_calls = (LDKEventsProvider_JCalls*) this_arg;
1582         JNIEnv *_env;
1583         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
1584         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
1585         CHECK(obj != NULL);
1586         jlongArray arg = (*_env)->CallObjectMethod(_env, obj, j_calls->get_and_clear_pending_events_meth);
1587         LDKCVec_EventZ arg_constr;
1588         arg_constr.datalen = (*_env)->GetArrayLength (_env, arg);
1589         if (arg_constr.datalen > 0)
1590                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKEvent), "LDKCVec_EventZ Elements");
1591         else
1592                 arg_constr.data = NULL;
1593         long* arg_vals = (*_env)->GetLongArrayElements (_env, arg, NULL);
1594         for (size_t h = 0; h < arg_constr.datalen; h++) {
1595                 long arr_conv_7 = arg_vals[h];
1596                 LDKEvent arr_conv_7_conv = *(LDKEvent*)arr_conv_7;
1597                 FREE((void*)arr_conv_7);
1598                 arg_constr.data[h] = arr_conv_7_conv;
1599         }
1600         (*_env)->ReleaseLongArrayElements (_env, arg, arg_vals, 0);
1601         return arg_constr;
1602 }
1603 static void LDKEventsProvider_JCalls_free(void* this_arg) {
1604         LDKEventsProvider_JCalls *j_calls = (LDKEventsProvider_JCalls*) this_arg;
1605         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
1606                 JNIEnv *env;
1607                 DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
1608                 (*env)->DeleteWeakGlobalRef(env, j_calls->o);
1609                 FREE(j_calls);
1610         }
1611 }
1612 static void* LDKEventsProvider_JCalls_clone(const void* this_arg) {
1613         LDKEventsProvider_JCalls *j_calls = (LDKEventsProvider_JCalls*) this_arg;
1614         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
1615         return (void*) this_arg;
1616 }
1617 static inline LDKEventsProvider LDKEventsProvider_init (JNIEnv * env, jclass _a, jobject o) {
1618         jclass c = (*env)->GetObjectClass(env, o);
1619         CHECK(c != NULL);
1620         LDKEventsProvider_JCalls *calls = MALLOC(sizeof(LDKEventsProvider_JCalls), "LDKEventsProvider_JCalls");
1621         atomic_init(&calls->refcnt, 1);
1622         DO_ASSERT((*env)->GetJavaVM(env, &calls->vm) == 0);
1623         calls->o = (*env)->NewWeakGlobalRef(env, o);
1624         calls->get_and_clear_pending_events_meth = (*env)->GetMethodID(env, c, "get_and_clear_pending_events", "()[J");
1625         CHECK(calls->get_and_clear_pending_events_meth != NULL);
1626
1627         LDKEventsProvider ret = {
1628                 .this_arg = (void*) calls,
1629                 .get_and_clear_pending_events = get_and_clear_pending_events_jcall,
1630                 .free = LDKEventsProvider_JCalls_free,
1631         };
1632         return ret;
1633 }
1634 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_LDKEventsProvider_1new (JNIEnv * env, jclass _a, jobject o) {
1635         LDKEventsProvider *res_ptr = MALLOC(sizeof(LDKEventsProvider), "LDKEventsProvider");
1636         *res_ptr = LDKEventsProvider_init(env, _a, o);
1637         return (long)res_ptr;
1638 }
1639 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKEventsProvider_1get_1obj_1from_1jcalls (JNIEnv * env, jclass _a, jlong val) {
1640         jobject ret = (*env)->NewLocalRef(env, ((LDKEventsProvider_JCalls*)val)->o);
1641         CHECK(ret != NULL);
1642         return ret;
1643 }
1644 JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_EventsProvider_1get_1and_1clear_1pending_1events(JNIEnv * _env, jclass _b, jlong this_arg) {
1645         LDKEventsProvider* this_arg_conv = (LDKEventsProvider*)this_arg;
1646         LDKCVec_EventZ ret_var = (this_arg_conv->get_and_clear_pending_events)(this_arg_conv->this_arg);
1647         jlongArray ret_arr = (*_env)->NewLongArray(_env, ret_var.datalen);
1648         jlong *ret_arr_ptr = (*_env)->GetPrimitiveArrayCritical(_env, ret_arr, NULL);
1649         for (size_t h = 0; h < ret_var.datalen; h++) {
1650                 LDKEvent *arr_conv_7_copy = MALLOC(sizeof(LDKEvent), "LDKEvent");
1651                 *arr_conv_7_copy = Event_clone(&ret_var.data[h]);
1652                 long arr_conv_7_ref = (long)arr_conv_7_copy;
1653                 ret_arr_ptr[h] = arr_conv_7_ref;
1654         }
1655         (*_env)->ReleasePrimitiveArrayCritical(_env, ret_arr, ret_arr_ptr, 0);
1656         CVec_EventZ_free(ret_var);
1657         return ret_arr;
1658 }
1659
1660 typedef struct LDKLogger_JCalls {
1661         atomic_size_t refcnt;
1662         JavaVM *vm;
1663         jweak o;
1664         jmethodID log_meth;
1665 } LDKLogger_JCalls;
1666 void log_jcall(const void* this_arg, const char *record) {
1667         LDKLogger_JCalls *j_calls = (LDKLogger_JCalls*) this_arg;
1668         JNIEnv *_env;
1669         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
1670         jstring record_conv = (*_env)->NewStringUTF(_env, record);
1671         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
1672         CHECK(obj != NULL);
1673         return (*_env)->CallVoidMethod(_env, obj, j_calls->log_meth, record_conv);
1674 }
1675 static void LDKLogger_JCalls_free(void* this_arg) {
1676         LDKLogger_JCalls *j_calls = (LDKLogger_JCalls*) this_arg;
1677         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
1678                 JNIEnv *env;
1679                 DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
1680                 (*env)->DeleteWeakGlobalRef(env, j_calls->o);
1681                 FREE(j_calls);
1682         }
1683 }
1684 static void* LDKLogger_JCalls_clone(const void* this_arg) {
1685         LDKLogger_JCalls *j_calls = (LDKLogger_JCalls*) this_arg;
1686         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
1687         return (void*) this_arg;
1688 }
1689 static inline LDKLogger LDKLogger_init (JNIEnv * env, jclass _a, jobject o) {
1690         jclass c = (*env)->GetObjectClass(env, o);
1691         CHECK(c != NULL);
1692         LDKLogger_JCalls *calls = MALLOC(sizeof(LDKLogger_JCalls), "LDKLogger_JCalls");
1693         atomic_init(&calls->refcnt, 1);
1694         DO_ASSERT((*env)->GetJavaVM(env, &calls->vm) == 0);
1695         calls->o = (*env)->NewWeakGlobalRef(env, o);
1696         calls->log_meth = (*env)->GetMethodID(env, c, "log", "(Ljava/lang/String;)V");
1697         CHECK(calls->log_meth != NULL);
1698
1699         LDKLogger ret = {
1700                 .this_arg = (void*) calls,
1701                 .log = log_jcall,
1702                 .free = LDKLogger_JCalls_free,
1703         };
1704         return ret;
1705 }
1706 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_LDKLogger_1new (JNIEnv * env, jclass _a, jobject o) {
1707         LDKLogger *res_ptr = MALLOC(sizeof(LDKLogger), "LDKLogger");
1708         *res_ptr = LDKLogger_init(env, _a, o);
1709         return (long)res_ptr;
1710 }
1711 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKLogger_1get_1obj_1from_1jcalls (JNIEnv * env, jclass _a, jlong val) {
1712         jobject ret = (*env)->NewLocalRef(env, ((LDKLogger_JCalls*)val)->o);
1713         CHECK(ret != NULL);
1714         return ret;
1715 }
1716 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1TxOutAccessErrorZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
1717         return ((LDKCResult_TxOutAccessErrorZ*)arg)->result_ok;
1718 }
1719 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1TxOutAccessErrorZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
1720         LDKCResult_TxOutAccessErrorZ *val = (LDKCResult_TxOutAccessErrorZ*)arg;
1721         CHECK(val->result_ok);
1722         long res_ref = (long)&(*val->contents.result);
1723         return res_ref;
1724 }
1725 JNIEXPORT jclass JNICALL Java_org_ldk_impl_bindings_LDKCResult_1TxOutAccessErrorZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
1726         LDKCResult_TxOutAccessErrorZ *val = (LDKCResult_TxOutAccessErrorZ*)arg;
1727         CHECK(!val->result_ok);
1728         jclass err_conv = LDKAccessError_to_java(_env, (*val->contents.err));
1729         return err_conv;
1730 }
1731 typedef struct LDKAccess_JCalls {
1732         atomic_size_t refcnt;
1733         JavaVM *vm;
1734         jweak o;
1735         jmethodID get_utxo_meth;
1736 } LDKAccess_JCalls;
1737 LDKCResult_TxOutAccessErrorZ get_utxo_jcall(const void* this_arg, const uint8_t (*genesis_hash)[32], uint64_t short_channel_id) {
1738         LDKAccess_JCalls *j_calls = (LDKAccess_JCalls*) this_arg;
1739         JNIEnv *_env;
1740         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
1741         jbyteArray genesis_hash_arr = (*_env)->NewByteArray(_env, 32);
1742         (*_env)->SetByteArrayRegion(_env, genesis_hash_arr, 0, 32, *genesis_hash);
1743         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
1744         CHECK(obj != NULL);
1745         LDKCResult_TxOutAccessErrorZ* ret = (LDKCResult_TxOutAccessErrorZ*)(*_env)->CallLongMethod(_env, obj, j_calls->get_utxo_meth, genesis_hash_arr, short_channel_id);
1746         LDKCResult_TxOutAccessErrorZ ret_conv = *(LDKCResult_TxOutAccessErrorZ*)ret;
1747         FREE((void*)ret);
1748         return ret_conv;
1749 }
1750 static void LDKAccess_JCalls_free(void* this_arg) {
1751         LDKAccess_JCalls *j_calls = (LDKAccess_JCalls*) this_arg;
1752         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
1753                 JNIEnv *env;
1754                 DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
1755                 (*env)->DeleteWeakGlobalRef(env, j_calls->o);
1756                 FREE(j_calls);
1757         }
1758 }
1759 static void* LDKAccess_JCalls_clone(const void* this_arg) {
1760         LDKAccess_JCalls *j_calls = (LDKAccess_JCalls*) this_arg;
1761         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
1762         return (void*) this_arg;
1763 }
1764 static inline LDKAccess LDKAccess_init (JNIEnv * env, jclass _a, jobject o) {
1765         jclass c = (*env)->GetObjectClass(env, o);
1766         CHECK(c != NULL);
1767         LDKAccess_JCalls *calls = MALLOC(sizeof(LDKAccess_JCalls), "LDKAccess_JCalls");
1768         atomic_init(&calls->refcnt, 1);
1769         DO_ASSERT((*env)->GetJavaVM(env, &calls->vm) == 0);
1770         calls->o = (*env)->NewWeakGlobalRef(env, o);
1771         calls->get_utxo_meth = (*env)->GetMethodID(env, c, "get_utxo", "([BJ)J");
1772         CHECK(calls->get_utxo_meth != NULL);
1773
1774         LDKAccess ret = {
1775                 .this_arg = (void*) calls,
1776                 .get_utxo = get_utxo_jcall,
1777                 .free = LDKAccess_JCalls_free,
1778         };
1779         return ret;
1780 }
1781 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_LDKAccess_1new (JNIEnv * env, jclass _a, jobject o) {
1782         LDKAccess *res_ptr = MALLOC(sizeof(LDKAccess), "LDKAccess");
1783         *res_ptr = LDKAccess_init(env, _a, o);
1784         return (long)res_ptr;
1785 }
1786 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKAccess_1get_1obj_1from_1jcalls (JNIEnv * env, jclass _a, jlong val) {
1787         jobject ret = (*env)->NewLocalRef(env, ((LDKAccess_JCalls*)val)->o);
1788         CHECK(ret != NULL);
1789         return ret;
1790 }
1791 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) {
1792         LDKAccess* this_arg_conv = (LDKAccess*)this_arg;
1793         unsigned char genesis_hash_arr[32];
1794         CHECK((*_env)->GetArrayLength (_env, genesis_hash) == 32);
1795         (*_env)->GetByteArrayRegion (_env, genesis_hash, 0, 32, genesis_hash_arr);
1796         unsigned char (*genesis_hash_ref)[32] = &genesis_hash_arr;
1797         LDKCResult_TxOutAccessErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_TxOutAccessErrorZ), "LDKCResult_TxOutAccessErrorZ");
1798         *ret_conv = (this_arg_conv->get_utxo)(this_arg_conv->this_arg, genesis_hash_ref, short_channel_id);
1799         return (long)ret_conv;
1800 }
1801
1802 JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1HTLCOutputInCommitment_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
1803         LDKCVecTempl_HTLCOutputInCommitment *vec = (LDKCVecTempl_HTLCOutputInCommitment*)ptr;
1804         jlongArray ret = (*env)->NewLongArray(env, vec->datalen);
1805         jlong *ret_elems = (*env)->GetPrimitiveArrayCritical(env, ret, NULL);
1806         for (size_t i = 0; i < vec->datalen; i++) {
1807                 CHECK((((long)vec->data[i].inner) & 1) == 0);
1808                 ret_elems[i] = (long)vec->data[i].inner | (vec->data[i].is_owned ? 1 : 0);
1809         }
1810         (*env)->ReleasePrimitiveArrayCritical(env, ret, ret_elems, 0);
1811         return ret;
1812 }
1813 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1HTLCOutputInCommitment_1new(JNIEnv *env, jclass _b, jlongArray elems){
1814         LDKCVecTempl_HTLCOutputInCommitment *ret = MALLOC(sizeof(LDKCVecTempl_HTLCOutputInCommitment), "LDKCVecTempl_HTLCOutputInCommitment");
1815         ret->datalen = (*env)->GetArrayLength(env, elems);
1816         if (ret->datalen == 0) {
1817                 ret->data = NULL;
1818         } else {
1819                 ret->data = MALLOC(sizeof(LDKHTLCOutputInCommitment) * ret->datalen, "LDKCVecTempl_HTLCOutputInCommitment Data");
1820                 jlong *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
1821                 for (size_t i = 0; i < ret->datalen; i++) {
1822                         jlong arr_elem = java_elems[i];
1823                         LDKHTLCOutputInCommitment arr_elem_conv;
1824                         arr_elem_conv.inner = (void*)(arr_elem & (~1));
1825                         arr_elem_conv.is_owned = (arr_elem & 1) || (arr_elem == 0);
1826                         if (arr_elem_conv.inner != NULL)
1827                                 arr_elem_conv = HTLCOutputInCommitment_clone(&arr_elem_conv);
1828                         ret->data[i] = arr_elem_conv;
1829                 }
1830                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
1831         }
1832         return (long)ret;
1833 }
1834 typedef struct LDKChannelKeys_JCalls {
1835         atomic_size_t refcnt;
1836         JavaVM *vm;
1837         jweak o;
1838         jmethodID get_per_commitment_point_meth;
1839         jmethodID release_commitment_secret_meth;
1840         jmethodID key_derivation_params_meth;
1841         jmethodID sign_counterparty_commitment_meth;
1842         jmethodID sign_holder_commitment_meth;
1843         jmethodID sign_holder_commitment_htlc_transactions_meth;
1844         jmethodID sign_justice_transaction_meth;
1845         jmethodID sign_counterparty_htlc_transaction_meth;
1846         jmethodID sign_closing_transaction_meth;
1847         jmethodID sign_channel_announcement_meth;
1848         jmethodID on_accept_meth;
1849 } LDKChannelKeys_JCalls;
1850 LDKPublicKey get_per_commitment_point_jcall(const void* this_arg, uint64_t idx) {
1851         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1852         JNIEnv *_env;
1853         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
1854         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
1855         CHECK(obj != NULL);
1856         jbyteArray arg = (*_env)->CallObjectMethod(_env, obj, j_calls->get_per_commitment_point_meth, idx);
1857         LDKPublicKey arg_ref;
1858         CHECK((*_env)->GetArrayLength (_env, arg) == 33);
1859         (*_env)->GetByteArrayRegion (_env, arg, 0, 33, arg_ref.compressed_form);
1860         return arg_ref;
1861 }
1862 LDKThirtyTwoBytes release_commitment_secret_jcall(const void* this_arg, uint64_t idx) {
1863         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1864         JNIEnv *_env;
1865         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
1866         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
1867         CHECK(obj != NULL);
1868         jbyteArray arg = (*_env)->CallObjectMethod(_env, obj, j_calls->release_commitment_secret_meth, idx);
1869         LDKThirtyTwoBytes arg_ref;
1870         CHECK((*_env)->GetArrayLength (_env, arg) == 32);
1871         (*_env)->GetByteArrayRegion (_env, arg, 0, 32, arg_ref.data);
1872         return arg_ref;
1873 }
1874 LDKC2Tuple_u64u64Z key_derivation_params_jcall(const void* this_arg) {
1875         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1876         JNIEnv *_env;
1877         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
1878         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
1879         CHECK(obj != NULL);
1880         LDKC2Tuple_u64u64Z* ret = (LDKC2Tuple_u64u64Z*)(*_env)->CallLongMethod(_env, obj, j_calls->key_derivation_params_meth);
1881         LDKC2Tuple_u64u64Z ret_conv = *(LDKC2Tuple_u64u64Z*)ret;
1882         FREE((void*)ret);
1883         return ret_conv;
1884 }
1885 LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ sign_counterparty_commitment_jcall(const void* this_arg, uint32_t feerate_per_kw, LDKTransaction commitment_tx, const LDKPreCalculatedTxCreationKeys *keys, LDKCVec_HTLCOutputInCommitmentZ htlcs) {
1886         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1887         JNIEnv *_env;
1888         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
1889         LDKTransaction *commitment_tx_copy = MALLOC(sizeof(LDKTransaction), "LDKTransaction");
1890         *commitment_tx_copy = commitment_tx;
1891         long commitment_tx_ref = (long)commitment_tx_copy;
1892         LDKPreCalculatedTxCreationKeys keys_var = *keys;
1893         CHECK((((long)keys_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1894         CHECK((((long)&keys_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1895         long keys_ref = (long)keys_var.inner & ~1;
1896         LDKCVec_HTLCOutputInCommitmentZ htlcs_var = htlcs;
1897         jlongArray htlcs_arr = (*_env)->NewLongArray(_env, htlcs_var.datalen);
1898         jlong *htlcs_arr_ptr = (*_env)->GetPrimitiveArrayCritical(_env, htlcs_arr, NULL);
1899         for (size_t y = 0; y < htlcs_var.datalen; y++) {
1900                 LDKHTLCOutputInCommitment arr_conv_24_var = htlcs_var.data[y];
1901                 CHECK((((long)arr_conv_24_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1902                 CHECK((((long)&arr_conv_24_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1903                 long arr_conv_24_ref = (long)arr_conv_24_var.inner;
1904                 if (arr_conv_24_var.is_owned) {
1905                         arr_conv_24_ref |= 1;
1906                 }
1907                 htlcs_arr_ptr[y] = arr_conv_24_ref;
1908         }
1909         (*_env)->ReleasePrimitiveArrayCritical(_env, htlcs_arr, htlcs_arr_ptr, 0);
1910         FREE(htlcs_var.data);
1911         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
1912         CHECK(obj != NULL);
1913         LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ* ret = (LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ*)(*_env)->CallLongMethod(_env, obj, j_calls->sign_counterparty_commitment_meth, feerate_per_kw, commitment_tx_ref, keys_ref, htlcs_arr);
1914         LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ ret_conv = *(LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ*)ret;
1915         FREE((void*)ret);
1916         return ret_conv;
1917 }
1918 LDKCResult_SignatureNoneZ sign_holder_commitment_jcall(const void* this_arg, const LDKHolderCommitmentTransaction *holder_commitment_tx) {
1919         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1920         JNIEnv *_env;
1921         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
1922         LDKHolderCommitmentTransaction holder_commitment_tx_var = *holder_commitment_tx;
1923         CHECK((((long)holder_commitment_tx_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1924         CHECK((((long)&holder_commitment_tx_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1925         long holder_commitment_tx_ref = (long)holder_commitment_tx_var.inner & ~1;
1926         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
1927         CHECK(obj != NULL);
1928         LDKCResult_SignatureNoneZ* ret = (LDKCResult_SignatureNoneZ*)(*_env)->CallLongMethod(_env, obj, j_calls->sign_holder_commitment_meth, holder_commitment_tx_ref);
1929         LDKCResult_SignatureNoneZ ret_conv = *(LDKCResult_SignatureNoneZ*)ret;
1930         FREE((void*)ret);
1931         return ret_conv;
1932 }
1933 LDKCResult_CVec_SignatureZNoneZ sign_holder_commitment_htlc_transactions_jcall(const void* this_arg, const LDKHolderCommitmentTransaction *holder_commitment_tx) {
1934         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1935         JNIEnv *_env;
1936         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
1937         LDKHolderCommitmentTransaction holder_commitment_tx_var = *holder_commitment_tx;
1938         CHECK((((long)holder_commitment_tx_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1939         CHECK((((long)&holder_commitment_tx_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1940         long holder_commitment_tx_ref = (long)holder_commitment_tx_var.inner & ~1;
1941         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
1942         CHECK(obj != NULL);
1943         LDKCResult_CVec_SignatureZNoneZ* ret = (LDKCResult_CVec_SignatureZNoneZ*)(*_env)->CallLongMethod(_env, obj, j_calls->sign_holder_commitment_htlc_transactions_meth, holder_commitment_tx_ref);
1944         LDKCResult_CVec_SignatureZNoneZ ret_conv = *(LDKCResult_CVec_SignatureZNoneZ*)ret;
1945         FREE((void*)ret);
1946         return ret_conv;
1947 }
1948 LDKCResult_SignatureNoneZ sign_justice_transaction_jcall(const void* this_arg, LDKTransaction justice_tx, uintptr_t input, uint64_t amount, const uint8_t (*per_commitment_key)[32], const LDKHTLCOutputInCommitment *htlc) {
1949         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1950         JNIEnv *_env;
1951         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
1952         LDKTransaction *justice_tx_copy = MALLOC(sizeof(LDKTransaction), "LDKTransaction");
1953         *justice_tx_copy = justice_tx;
1954         long justice_tx_ref = (long)justice_tx_copy;
1955         jbyteArray per_commitment_key_arr = (*_env)->NewByteArray(_env, 32);
1956         (*_env)->SetByteArrayRegion(_env, per_commitment_key_arr, 0, 32, *per_commitment_key);
1957         LDKHTLCOutputInCommitment htlc_var = *htlc;
1958         CHECK((((long)htlc_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1959         CHECK((((long)&htlc_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1960         long htlc_ref = (long)htlc_var.inner & ~1;
1961         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
1962         CHECK(obj != NULL);
1963         LDKCResult_SignatureNoneZ* ret = (LDKCResult_SignatureNoneZ*)(*_env)->CallLongMethod(_env, obj, j_calls->sign_justice_transaction_meth, justice_tx_ref, input, amount, per_commitment_key_arr, htlc_ref);
1964         LDKCResult_SignatureNoneZ ret_conv = *(LDKCResult_SignatureNoneZ*)ret;
1965         FREE((void*)ret);
1966         return ret_conv;
1967 }
1968 LDKCResult_SignatureNoneZ sign_counterparty_htlc_transaction_jcall(const void* this_arg, LDKTransaction htlc_tx, uintptr_t input, uint64_t amount, LDKPublicKey per_commitment_point, const LDKHTLCOutputInCommitment *htlc) {
1969         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1970         JNIEnv *_env;
1971         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
1972         LDKTransaction *htlc_tx_copy = MALLOC(sizeof(LDKTransaction), "LDKTransaction");
1973         *htlc_tx_copy = htlc_tx;
1974         long htlc_tx_ref = (long)htlc_tx_copy;
1975         jbyteArray per_commitment_point_arr = (*_env)->NewByteArray(_env, 33);
1976         (*_env)->SetByteArrayRegion(_env, per_commitment_point_arr, 0, 33, per_commitment_point.compressed_form);
1977         LDKHTLCOutputInCommitment htlc_var = *htlc;
1978         CHECK((((long)htlc_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1979         CHECK((((long)&htlc_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1980         long htlc_ref = (long)htlc_var.inner & ~1;
1981         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
1982         CHECK(obj != NULL);
1983         LDKCResult_SignatureNoneZ* ret = (LDKCResult_SignatureNoneZ*)(*_env)->CallLongMethod(_env, obj, j_calls->sign_counterparty_htlc_transaction_meth, htlc_tx_ref, input, amount, per_commitment_point_arr, htlc_ref);
1984         LDKCResult_SignatureNoneZ ret_conv = *(LDKCResult_SignatureNoneZ*)ret;
1985         FREE((void*)ret);
1986         return ret_conv;
1987 }
1988 LDKCResult_SignatureNoneZ sign_closing_transaction_jcall(const void* this_arg, LDKTransaction closing_tx) {
1989         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1990         JNIEnv *_env;
1991         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
1992         LDKTransaction *closing_tx_copy = MALLOC(sizeof(LDKTransaction), "LDKTransaction");
1993         *closing_tx_copy = closing_tx;
1994         long closing_tx_ref = (long)closing_tx_copy;
1995         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
1996         CHECK(obj != NULL);
1997         LDKCResult_SignatureNoneZ* ret = (LDKCResult_SignatureNoneZ*)(*_env)->CallLongMethod(_env, obj, j_calls->sign_closing_transaction_meth, closing_tx_ref);
1998         LDKCResult_SignatureNoneZ ret_conv = *(LDKCResult_SignatureNoneZ*)ret;
1999         FREE((void*)ret);
2000         return ret_conv;
2001 }
2002 LDKCResult_SignatureNoneZ sign_channel_announcement_jcall(const void* this_arg, const LDKUnsignedChannelAnnouncement *msg) {
2003         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
2004         JNIEnv *_env;
2005         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
2006         LDKUnsignedChannelAnnouncement msg_var = *msg;
2007         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2008         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2009         long msg_ref = (long)msg_var.inner & ~1;
2010         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
2011         CHECK(obj != NULL);
2012         LDKCResult_SignatureNoneZ* ret = (LDKCResult_SignatureNoneZ*)(*_env)->CallLongMethod(_env, obj, j_calls->sign_channel_announcement_meth, msg_ref);
2013         LDKCResult_SignatureNoneZ ret_conv = *(LDKCResult_SignatureNoneZ*)ret;
2014         FREE((void*)ret);
2015         return ret_conv;
2016 }
2017 void on_accept_jcall(void* this_arg, const LDKChannelPublicKeys *channel_points, uint16_t counterparty_selected_contest_delay, uint16_t holder_selected_contest_delay) {
2018         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
2019         JNIEnv *_env;
2020         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
2021         LDKChannelPublicKeys channel_points_var = *channel_points;
2022         CHECK((((long)channel_points_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2023         CHECK((((long)&channel_points_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2024         long channel_points_ref = (long)channel_points_var.inner & ~1;
2025         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
2026         CHECK(obj != NULL);
2027         return (*_env)->CallVoidMethod(_env, obj, j_calls->on_accept_meth, channel_points_ref, counterparty_selected_contest_delay, holder_selected_contest_delay);
2028 }
2029 static void LDKChannelKeys_JCalls_free(void* this_arg) {
2030         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
2031         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
2032                 JNIEnv *env;
2033                 DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
2034                 (*env)->DeleteWeakGlobalRef(env, j_calls->o);
2035                 FREE(j_calls);
2036         }
2037 }
2038 static void* LDKChannelKeys_JCalls_clone(const void* this_arg) {
2039         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
2040         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
2041         return (void*) this_arg;
2042 }
2043 static inline LDKChannelKeys LDKChannelKeys_init (JNIEnv * env, jclass _a, jobject o, jlong pubkeys) {
2044         jclass c = (*env)->GetObjectClass(env, o);
2045         CHECK(c != NULL);
2046         LDKChannelKeys_JCalls *calls = MALLOC(sizeof(LDKChannelKeys_JCalls), "LDKChannelKeys_JCalls");
2047         atomic_init(&calls->refcnt, 1);
2048         DO_ASSERT((*env)->GetJavaVM(env, &calls->vm) == 0);
2049         calls->o = (*env)->NewWeakGlobalRef(env, o);
2050         calls->get_per_commitment_point_meth = (*env)->GetMethodID(env, c, "get_per_commitment_point", "(J)[B");
2051         CHECK(calls->get_per_commitment_point_meth != NULL);
2052         calls->release_commitment_secret_meth = (*env)->GetMethodID(env, c, "release_commitment_secret", "(J)[B");
2053         CHECK(calls->release_commitment_secret_meth != NULL);
2054         calls->key_derivation_params_meth = (*env)->GetMethodID(env, c, "key_derivation_params", "()J");
2055         CHECK(calls->key_derivation_params_meth != NULL);
2056         calls->sign_counterparty_commitment_meth = (*env)->GetMethodID(env, c, "sign_counterparty_commitment", "(IJJ[J)J");
2057         CHECK(calls->sign_counterparty_commitment_meth != NULL);
2058         calls->sign_holder_commitment_meth = (*env)->GetMethodID(env, c, "sign_holder_commitment", "(J)J");
2059         CHECK(calls->sign_holder_commitment_meth != NULL);
2060         calls->sign_holder_commitment_htlc_transactions_meth = (*env)->GetMethodID(env, c, "sign_holder_commitment_htlc_transactions", "(J)J");
2061         CHECK(calls->sign_holder_commitment_htlc_transactions_meth != NULL);
2062         calls->sign_justice_transaction_meth = (*env)->GetMethodID(env, c, "sign_justice_transaction", "(JJJ[BJ)J");
2063         CHECK(calls->sign_justice_transaction_meth != NULL);
2064         calls->sign_counterparty_htlc_transaction_meth = (*env)->GetMethodID(env, c, "sign_counterparty_htlc_transaction", "(JJJ[BJ)J");
2065         CHECK(calls->sign_counterparty_htlc_transaction_meth != NULL);
2066         calls->sign_closing_transaction_meth = (*env)->GetMethodID(env, c, "sign_closing_transaction", "(J)J");
2067         CHECK(calls->sign_closing_transaction_meth != NULL);
2068         calls->sign_channel_announcement_meth = (*env)->GetMethodID(env, c, "sign_channel_announcement", "(J)J");
2069         CHECK(calls->sign_channel_announcement_meth != NULL);
2070         calls->on_accept_meth = (*env)->GetMethodID(env, c, "on_accept", "(JSS)V");
2071         CHECK(calls->on_accept_meth != NULL);
2072
2073         LDKChannelPublicKeys pubkeys_conv;
2074         pubkeys_conv.inner = (void*)(pubkeys & (~1));
2075         pubkeys_conv.is_owned = (pubkeys & 1) || (pubkeys == 0);
2076         if (pubkeys_conv.inner != NULL)
2077                 pubkeys_conv = ChannelPublicKeys_clone(&pubkeys_conv);
2078
2079         LDKChannelKeys ret = {
2080                 .this_arg = (void*) calls,
2081                 .get_per_commitment_point = get_per_commitment_point_jcall,
2082                 .release_commitment_secret = release_commitment_secret_jcall,
2083                 .key_derivation_params = key_derivation_params_jcall,
2084                 .sign_counterparty_commitment = sign_counterparty_commitment_jcall,
2085                 .sign_holder_commitment = sign_holder_commitment_jcall,
2086                 .sign_holder_commitment_htlc_transactions = sign_holder_commitment_htlc_transactions_jcall,
2087                 .sign_justice_transaction = sign_justice_transaction_jcall,
2088                 .sign_counterparty_htlc_transaction = sign_counterparty_htlc_transaction_jcall,
2089                 .sign_closing_transaction = sign_closing_transaction_jcall,
2090                 .sign_channel_announcement = sign_channel_announcement_jcall,
2091                 .on_accept = on_accept_jcall,
2092                 .clone = LDKChannelKeys_JCalls_clone,
2093                 .free = LDKChannelKeys_JCalls_free,
2094                 .pubkeys = pubkeys_conv,
2095                 .set_pubkeys = NULL,
2096         };
2097         return ret;
2098 }
2099 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_LDKChannelKeys_1new (JNIEnv * env, jclass _a, jobject o, jlong pubkeys) {
2100         LDKChannelKeys *res_ptr = MALLOC(sizeof(LDKChannelKeys), "LDKChannelKeys");
2101         *res_ptr = LDKChannelKeys_init(env, _a, o, pubkeys);
2102         return (long)res_ptr;
2103 }
2104 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKChannelKeys_1get_1obj_1from_1jcalls (JNIEnv * env, jclass _a, jlong val) {
2105         jobject ret = (*env)->NewLocalRef(env, ((LDKChannelKeys_JCalls*)val)->o);
2106         CHECK(ret != NULL);
2107         return ret;
2108 }
2109 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1get_1per_1commitment_1point(JNIEnv * _env, jclass _b, jlong this_arg, jlong idx) {
2110         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
2111         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
2112         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, (this_arg_conv->get_per_commitment_point)(this_arg_conv->this_arg, idx).compressed_form);
2113         return arg_arr;
2114 }
2115
2116 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1release_1commitment_1secret(JNIEnv * _env, jclass _b, jlong this_arg, jlong idx) {
2117         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
2118         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 32);
2119         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 32, (this_arg_conv->release_commitment_secret)(this_arg_conv->this_arg, idx).data);
2120         return arg_arr;
2121 }
2122
2123 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1key_1derivation_1params(JNIEnv * _env, jclass _b, jlong this_arg) {
2124         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
2125         LDKC2Tuple_u64u64Z* ret_ref = MALLOC(sizeof(LDKC2Tuple_u64u64Z), "LDKC2Tuple_u64u64Z");
2126         *ret_ref = (this_arg_conv->key_derivation_params)(this_arg_conv->this_arg);
2127         return (long)ret_ref;
2128 }
2129
2130 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1sign_1counterparty_1commitment(JNIEnv * _env, jclass _b, jlong this_arg, jint feerate_per_kw, jlong commitment_tx, jlong keys, jlongArray htlcs) {
2131         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
2132         LDKTransaction commitment_tx_conv = *(LDKTransaction*)commitment_tx;
2133         LDKPreCalculatedTxCreationKeys keys_conv;
2134         keys_conv.inner = (void*)(keys & (~1));
2135         keys_conv.is_owned = (keys & 1) || (keys == 0);
2136         LDKCVec_HTLCOutputInCommitmentZ htlcs_constr;
2137         htlcs_constr.datalen = (*_env)->GetArrayLength (_env, htlcs);
2138         if (htlcs_constr.datalen > 0)
2139                 htlcs_constr.data = MALLOC(htlcs_constr.datalen * sizeof(LDKHTLCOutputInCommitment), "LDKCVec_HTLCOutputInCommitmentZ Elements");
2140         else
2141                 htlcs_constr.data = NULL;
2142         long* htlcs_vals = (*_env)->GetLongArrayElements (_env, htlcs, NULL);
2143         for (size_t y = 0; y < htlcs_constr.datalen; y++) {
2144                 long arr_conv_24 = htlcs_vals[y];
2145                 LDKHTLCOutputInCommitment arr_conv_24_conv;
2146                 arr_conv_24_conv.inner = (void*)(arr_conv_24 & (~1));
2147                 arr_conv_24_conv.is_owned = (arr_conv_24 & 1) || (arr_conv_24 == 0);
2148                 if (arr_conv_24_conv.inner != NULL)
2149                         arr_conv_24_conv = HTLCOutputInCommitment_clone(&arr_conv_24_conv);
2150                 htlcs_constr.data[y] = arr_conv_24_conv;
2151         }
2152         (*_env)->ReleaseLongArrayElements (_env, htlcs, htlcs_vals, 0);
2153         LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ), "LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ");
2154         *ret_conv = (this_arg_conv->sign_counterparty_commitment)(this_arg_conv->this_arg, feerate_per_kw, commitment_tx_conv, &keys_conv, htlcs_constr);
2155         return (long)ret_conv;
2156 }
2157
2158 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1sign_1holder_1commitment(JNIEnv * _env, jclass _b, jlong this_arg, jlong holder_commitment_tx) {
2159         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
2160         LDKHolderCommitmentTransaction holder_commitment_tx_conv;
2161         holder_commitment_tx_conv.inner = (void*)(holder_commitment_tx & (~1));
2162         holder_commitment_tx_conv.is_owned = (holder_commitment_tx & 1) || (holder_commitment_tx == 0);
2163         LDKCResult_SignatureNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_SignatureNoneZ), "LDKCResult_SignatureNoneZ");
2164         *ret_conv = (this_arg_conv->sign_holder_commitment)(this_arg_conv->this_arg, &holder_commitment_tx_conv);
2165         return (long)ret_conv;
2166 }
2167
2168 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1sign_1holder_1commitment_1htlc_1transactions(JNIEnv * _env, jclass _b, jlong this_arg, jlong holder_commitment_tx) {
2169         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
2170         LDKHolderCommitmentTransaction holder_commitment_tx_conv;
2171         holder_commitment_tx_conv.inner = (void*)(holder_commitment_tx & (~1));
2172         holder_commitment_tx_conv.is_owned = (holder_commitment_tx & 1) || (holder_commitment_tx == 0);
2173         LDKCResult_CVec_SignatureZNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_CVec_SignatureZNoneZ), "LDKCResult_CVec_SignatureZNoneZ");
2174         *ret_conv = (this_arg_conv->sign_holder_commitment_htlc_transactions)(this_arg_conv->this_arg, &holder_commitment_tx_conv);
2175         return (long)ret_conv;
2176 }
2177
2178 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1sign_1justice_1transaction(JNIEnv * _env, jclass _b, jlong this_arg, jlong justice_tx, jlong input, jlong amount, jbyteArray per_commitment_key, jlong htlc) {
2179         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
2180         LDKTransaction justice_tx_conv = *(LDKTransaction*)justice_tx;
2181         unsigned char per_commitment_key_arr[32];
2182         CHECK((*_env)->GetArrayLength (_env, per_commitment_key) == 32);
2183         (*_env)->GetByteArrayRegion (_env, per_commitment_key, 0, 32, per_commitment_key_arr);
2184         unsigned char (*per_commitment_key_ref)[32] = &per_commitment_key_arr;
2185         LDKHTLCOutputInCommitment htlc_conv;
2186         htlc_conv.inner = (void*)(htlc & (~1));
2187         htlc_conv.is_owned = (htlc & 1) || (htlc == 0);
2188         LDKCResult_SignatureNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_SignatureNoneZ), "LDKCResult_SignatureNoneZ");
2189         *ret_conv = (this_arg_conv->sign_justice_transaction)(this_arg_conv->this_arg, justice_tx_conv, input, amount, per_commitment_key_ref, &htlc_conv);
2190         return (long)ret_conv;
2191 }
2192
2193 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1sign_1counterparty_1htlc_1transaction(JNIEnv * _env, jclass _b, jlong this_arg, jlong htlc_tx, jlong input, jlong amount, jbyteArray per_commitment_point, jlong htlc) {
2194         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
2195         LDKTransaction htlc_tx_conv = *(LDKTransaction*)htlc_tx;
2196         LDKPublicKey per_commitment_point_ref;
2197         CHECK((*_env)->GetArrayLength (_env, per_commitment_point) == 33);
2198         (*_env)->GetByteArrayRegion (_env, per_commitment_point, 0, 33, per_commitment_point_ref.compressed_form);
2199         LDKHTLCOutputInCommitment htlc_conv;
2200         htlc_conv.inner = (void*)(htlc & (~1));
2201         htlc_conv.is_owned = (htlc & 1) || (htlc == 0);
2202         LDKCResult_SignatureNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_SignatureNoneZ), "LDKCResult_SignatureNoneZ");
2203         *ret_conv = (this_arg_conv->sign_counterparty_htlc_transaction)(this_arg_conv->this_arg, htlc_tx_conv, input, amount, per_commitment_point_ref, &htlc_conv);
2204         return (long)ret_conv;
2205 }
2206
2207 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1sign_1closing_1transaction(JNIEnv * _env, jclass _b, jlong this_arg, jlong closing_tx) {
2208         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
2209         LDKTransaction closing_tx_conv = *(LDKTransaction*)closing_tx;
2210         LDKCResult_SignatureNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_SignatureNoneZ), "LDKCResult_SignatureNoneZ");
2211         *ret_conv = (this_arg_conv->sign_closing_transaction)(this_arg_conv->this_arg, closing_tx_conv);
2212         return (long)ret_conv;
2213 }
2214
2215 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1sign_1channel_1announcement(JNIEnv * _env, jclass _b, jlong this_arg, jlong msg) {
2216         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
2217         LDKUnsignedChannelAnnouncement msg_conv;
2218         msg_conv.inner = (void*)(msg & (~1));
2219         msg_conv.is_owned = (msg & 1) || (msg == 0);
2220         LDKCResult_SignatureNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_SignatureNoneZ), "LDKCResult_SignatureNoneZ");
2221         *ret_conv = (this_arg_conv->sign_channel_announcement)(this_arg_conv->this_arg, &msg_conv);
2222         return (long)ret_conv;
2223 }
2224
2225 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1on_1accept(JNIEnv * _env, jclass _b, jlong this_arg, jlong channel_points, jshort counterparty_selected_contest_delay, jshort holder_selected_contest_delay) {
2226         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
2227         LDKChannelPublicKeys channel_points_conv;
2228         channel_points_conv.inner = (void*)(channel_points & (~1));
2229         channel_points_conv.is_owned = (channel_points & 1) || (channel_points == 0);
2230         (this_arg_conv->on_accept)(this_arg_conv->this_arg, &channel_points_conv, counterparty_selected_contest_delay, holder_selected_contest_delay);
2231 }
2232
2233 LDKChannelPublicKeys LDKChannelKeys_set_get_pubkeys(LDKChannelKeys* this_arg) {
2234         if (this_arg->set_pubkeys != NULL)
2235                 this_arg->set_pubkeys(this_arg);
2236         return this_arg->pubkeys;
2237 }
2238 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1get_1pubkeys(JNIEnv * _env, jclass _b, jlong this_arg) {
2239         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
2240         LDKChannelPublicKeys ret_var = LDKChannelKeys_set_get_pubkeys(this_arg_conv);
2241         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2242         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2243         long ret_ref = (long)ret_var.inner;
2244         if (ret_var.is_owned) {
2245                 ret_ref |= 1;
2246         }
2247         return ret_ref;
2248 }
2249
2250 JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1MonitorEvent_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
2251         LDKCVecTempl_MonitorEvent *vec = (LDKCVecTempl_MonitorEvent*)ptr;
2252         jlongArray ret = (*env)->NewLongArray(env, vec->datalen);
2253         jlong *ret_elems = (*env)->GetPrimitiveArrayCritical(env, ret, NULL);
2254         for (size_t i = 0; i < vec->datalen; i++) {
2255                 CHECK((((long)vec->data[i].inner) & 1) == 0);
2256                 ret_elems[i] = (long)vec->data[i].inner | (vec->data[i].is_owned ? 1 : 0);
2257         }
2258         (*env)->ReleasePrimitiveArrayCritical(env, ret, ret_elems, 0);
2259         return ret;
2260 }
2261 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1MonitorEvent_1new(JNIEnv *env, jclass _b, jlongArray elems){
2262         LDKCVecTempl_MonitorEvent *ret = MALLOC(sizeof(LDKCVecTempl_MonitorEvent), "LDKCVecTempl_MonitorEvent");
2263         ret->datalen = (*env)->GetArrayLength(env, elems);
2264         if (ret->datalen == 0) {
2265                 ret->data = NULL;
2266         } else {
2267                 ret->data = MALLOC(sizeof(LDKMonitorEvent) * ret->datalen, "LDKCVecTempl_MonitorEvent Data");
2268                 jlong *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
2269                 for (size_t i = 0; i < ret->datalen; i++) {
2270                         jlong arr_elem = java_elems[i];
2271                         LDKMonitorEvent arr_elem_conv;
2272                         arr_elem_conv.inner = (void*)(arr_elem & (~1));
2273                         arr_elem_conv.is_owned = (arr_elem & 1) || (arr_elem == 0);
2274                         if (arr_elem_conv.inner != NULL)
2275                                 arr_elem_conv = MonitorEvent_clone(&arr_elem_conv);
2276                         ret->data[i] = arr_elem_conv;
2277                 }
2278                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
2279         }
2280         return (long)ret;
2281 }
2282 typedef struct LDKWatch_JCalls {
2283         atomic_size_t refcnt;
2284         JavaVM *vm;
2285         jweak o;
2286         jmethodID watch_channel_meth;
2287         jmethodID update_channel_meth;
2288         jmethodID release_pending_monitor_events_meth;
2289 } LDKWatch_JCalls;
2290 LDKCResult_NoneChannelMonitorUpdateErrZ watch_channel_jcall(const void* this_arg, LDKOutPoint funding_txo, LDKChannelMonitor monitor) {
2291         LDKWatch_JCalls *j_calls = (LDKWatch_JCalls*) this_arg;
2292         JNIEnv *_env;
2293         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
2294         LDKOutPoint funding_txo_var = funding_txo;
2295         CHECK((((long)funding_txo_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2296         CHECK((((long)&funding_txo_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2297         long funding_txo_ref = (long)funding_txo_var.inner;
2298         if (funding_txo_var.is_owned) {
2299                 funding_txo_ref |= 1;
2300         }
2301         LDKChannelMonitor monitor_var = monitor;
2302         CHECK((((long)monitor_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2303         CHECK((((long)&monitor_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2304         long monitor_ref = (long)monitor_var.inner;
2305         if (monitor_var.is_owned) {
2306                 monitor_ref |= 1;
2307         }
2308         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
2309         CHECK(obj != NULL);
2310         LDKCResult_NoneChannelMonitorUpdateErrZ* ret = (LDKCResult_NoneChannelMonitorUpdateErrZ*)(*_env)->CallLongMethod(_env, obj, j_calls->watch_channel_meth, funding_txo_ref, monitor_ref);
2311         LDKCResult_NoneChannelMonitorUpdateErrZ ret_conv = *(LDKCResult_NoneChannelMonitorUpdateErrZ*)ret;
2312         FREE((void*)ret);
2313         return ret_conv;
2314 }
2315 LDKCResult_NoneChannelMonitorUpdateErrZ update_channel_jcall(const void* this_arg, LDKOutPoint funding_txo, LDKChannelMonitorUpdate update) {
2316         LDKWatch_JCalls *j_calls = (LDKWatch_JCalls*) this_arg;
2317         JNIEnv *_env;
2318         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
2319         LDKOutPoint funding_txo_var = funding_txo;
2320         CHECK((((long)funding_txo_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2321         CHECK((((long)&funding_txo_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2322         long funding_txo_ref = (long)funding_txo_var.inner;
2323         if (funding_txo_var.is_owned) {
2324                 funding_txo_ref |= 1;
2325         }
2326         LDKChannelMonitorUpdate update_var = update;
2327         CHECK((((long)update_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2328         CHECK((((long)&update_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2329         long update_ref = (long)update_var.inner;
2330         if (update_var.is_owned) {
2331                 update_ref |= 1;
2332         }
2333         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
2334         CHECK(obj != NULL);
2335         LDKCResult_NoneChannelMonitorUpdateErrZ* ret = (LDKCResult_NoneChannelMonitorUpdateErrZ*)(*_env)->CallLongMethod(_env, obj, j_calls->update_channel_meth, funding_txo_ref, update_ref);
2336         LDKCResult_NoneChannelMonitorUpdateErrZ ret_conv = *(LDKCResult_NoneChannelMonitorUpdateErrZ*)ret;
2337         FREE((void*)ret);
2338         return ret_conv;
2339 }
2340 LDKCVec_MonitorEventZ release_pending_monitor_events_jcall(const void* this_arg) {
2341         LDKWatch_JCalls *j_calls = (LDKWatch_JCalls*) this_arg;
2342         JNIEnv *_env;
2343         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
2344         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
2345         CHECK(obj != NULL);
2346         jlongArray arg = (*_env)->CallObjectMethod(_env, obj, j_calls->release_pending_monitor_events_meth);
2347         LDKCVec_MonitorEventZ arg_constr;
2348         arg_constr.datalen = (*_env)->GetArrayLength (_env, arg);
2349         if (arg_constr.datalen > 0)
2350                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKMonitorEvent), "LDKCVec_MonitorEventZ Elements");
2351         else
2352                 arg_constr.data = NULL;
2353         long* arg_vals = (*_env)->GetLongArrayElements (_env, arg, NULL);
2354         for (size_t o = 0; o < arg_constr.datalen; o++) {
2355                 long arr_conv_14 = arg_vals[o];
2356                 LDKMonitorEvent arr_conv_14_conv;
2357                 arr_conv_14_conv.inner = (void*)(arr_conv_14 & (~1));
2358                 arr_conv_14_conv.is_owned = (arr_conv_14 & 1) || (arr_conv_14 == 0);
2359                 if (arr_conv_14_conv.inner != NULL)
2360                         arr_conv_14_conv = MonitorEvent_clone(&arr_conv_14_conv);
2361                 arg_constr.data[o] = arr_conv_14_conv;
2362         }
2363         (*_env)->ReleaseLongArrayElements (_env, arg, arg_vals, 0);
2364         return arg_constr;
2365 }
2366 static void LDKWatch_JCalls_free(void* this_arg) {
2367         LDKWatch_JCalls *j_calls = (LDKWatch_JCalls*) this_arg;
2368         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
2369                 JNIEnv *env;
2370                 DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
2371                 (*env)->DeleteWeakGlobalRef(env, j_calls->o);
2372                 FREE(j_calls);
2373         }
2374 }
2375 static void* LDKWatch_JCalls_clone(const void* this_arg) {
2376         LDKWatch_JCalls *j_calls = (LDKWatch_JCalls*) this_arg;
2377         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
2378         return (void*) this_arg;
2379 }
2380 static inline LDKWatch LDKWatch_init (JNIEnv * env, jclass _a, jobject o) {
2381         jclass c = (*env)->GetObjectClass(env, o);
2382         CHECK(c != NULL);
2383         LDKWatch_JCalls *calls = MALLOC(sizeof(LDKWatch_JCalls), "LDKWatch_JCalls");
2384         atomic_init(&calls->refcnt, 1);
2385         DO_ASSERT((*env)->GetJavaVM(env, &calls->vm) == 0);
2386         calls->o = (*env)->NewWeakGlobalRef(env, o);
2387         calls->watch_channel_meth = (*env)->GetMethodID(env, c, "watch_channel", "(JJ)J");
2388         CHECK(calls->watch_channel_meth != NULL);
2389         calls->update_channel_meth = (*env)->GetMethodID(env, c, "update_channel", "(JJ)J");
2390         CHECK(calls->update_channel_meth != NULL);
2391         calls->release_pending_monitor_events_meth = (*env)->GetMethodID(env, c, "release_pending_monitor_events", "()[J");
2392         CHECK(calls->release_pending_monitor_events_meth != NULL);
2393
2394         LDKWatch ret = {
2395                 .this_arg = (void*) calls,
2396                 .watch_channel = watch_channel_jcall,
2397                 .update_channel = update_channel_jcall,
2398                 .release_pending_monitor_events = release_pending_monitor_events_jcall,
2399                 .free = LDKWatch_JCalls_free,
2400         };
2401         return ret;
2402 }
2403 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_LDKWatch_1new (JNIEnv * env, jclass _a, jobject o) {
2404         LDKWatch *res_ptr = MALLOC(sizeof(LDKWatch), "LDKWatch");
2405         *res_ptr = LDKWatch_init(env, _a, o);
2406         return (long)res_ptr;
2407 }
2408 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKWatch_1get_1obj_1from_1jcalls (JNIEnv * env, jclass _a, jlong val) {
2409         jobject ret = (*env)->NewLocalRef(env, ((LDKWatch_JCalls*)val)->o);
2410         CHECK(ret != NULL);
2411         return ret;
2412 }
2413 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_Watch_1watch_1channel(JNIEnv * _env, jclass _b, jlong this_arg, jlong funding_txo, jlong monitor) {
2414         LDKWatch* this_arg_conv = (LDKWatch*)this_arg;
2415         LDKOutPoint funding_txo_conv;
2416         funding_txo_conv.inner = (void*)(funding_txo & (~1));
2417         funding_txo_conv.is_owned = (funding_txo & 1) || (funding_txo == 0);
2418         if (funding_txo_conv.inner != NULL)
2419                 funding_txo_conv = OutPoint_clone(&funding_txo_conv);
2420         LDKChannelMonitor monitor_conv;
2421         monitor_conv.inner = (void*)(monitor & (~1));
2422         monitor_conv.is_owned = (monitor & 1) || (monitor == 0);
2423         // Warning: we may need a move here but can't clone!
2424         LDKCResult_NoneChannelMonitorUpdateErrZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneChannelMonitorUpdateErrZ), "LDKCResult_NoneChannelMonitorUpdateErrZ");
2425         *ret_conv = (this_arg_conv->watch_channel)(this_arg_conv->this_arg, funding_txo_conv, monitor_conv);
2426         return (long)ret_conv;
2427 }
2428
2429 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_Watch_1update_1channel(JNIEnv * _env, jclass _b, jlong this_arg, jlong funding_txo, jlong update) {
2430         LDKWatch* this_arg_conv = (LDKWatch*)this_arg;
2431         LDKOutPoint funding_txo_conv;
2432         funding_txo_conv.inner = (void*)(funding_txo & (~1));
2433         funding_txo_conv.is_owned = (funding_txo & 1) || (funding_txo == 0);
2434         if (funding_txo_conv.inner != NULL)
2435                 funding_txo_conv = OutPoint_clone(&funding_txo_conv);
2436         LDKChannelMonitorUpdate update_conv;
2437         update_conv.inner = (void*)(update & (~1));
2438         update_conv.is_owned = (update & 1) || (update == 0);
2439         if (update_conv.inner != NULL)
2440                 update_conv = ChannelMonitorUpdate_clone(&update_conv);
2441         LDKCResult_NoneChannelMonitorUpdateErrZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneChannelMonitorUpdateErrZ), "LDKCResult_NoneChannelMonitorUpdateErrZ");
2442         *ret_conv = (this_arg_conv->update_channel)(this_arg_conv->this_arg, funding_txo_conv, update_conv);
2443         return (long)ret_conv;
2444 }
2445
2446 JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_Watch_1release_1pending_1monitor_1events(JNIEnv * _env, jclass _b, jlong this_arg) {
2447         LDKWatch* this_arg_conv = (LDKWatch*)this_arg;
2448         LDKCVec_MonitorEventZ ret_var = (this_arg_conv->release_pending_monitor_events)(this_arg_conv->this_arg);
2449         jlongArray ret_arr = (*_env)->NewLongArray(_env, ret_var.datalen);
2450         jlong *ret_arr_ptr = (*_env)->GetPrimitiveArrayCritical(_env, ret_arr, NULL);
2451         for (size_t o = 0; o < ret_var.datalen; o++) {
2452                 LDKMonitorEvent arr_conv_14_var = ret_var.data[o];
2453                 CHECK((((long)arr_conv_14_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2454                 CHECK((((long)&arr_conv_14_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2455                 long arr_conv_14_ref = (long)arr_conv_14_var.inner;
2456                 if (arr_conv_14_var.is_owned) {
2457                         arr_conv_14_ref |= 1;
2458                 }
2459                 ret_arr_ptr[o] = arr_conv_14_ref;
2460         }
2461         (*_env)->ReleasePrimitiveArrayCritical(_env, ret_arr, ret_arr_ptr, 0);
2462         FREE(ret_var.data);
2463         return ret_arr;
2464 }
2465
2466 typedef struct LDKFilter_JCalls {
2467         atomic_size_t refcnt;
2468         JavaVM *vm;
2469         jweak o;
2470         jmethodID register_tx_meth;
2471         jmethodID register_output_meth;
2472 } LDKFilter_JCalls;
2473 void register_tx_jcall(const void* this_arg, const uint8_t (*txid)[32], LDKu8slice script_pubkey) {
2474         LDKFilter_JCalls *j_calls = (LDKFilter_JCalls*) this_arg;
2475         JNIEnv *_env;
2476         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
2477         jbyteArray txid_arr = (*_env)->NewByteArray(_env, 32);
2478         (*_env)->SetByteArrayRegion(_env, txid_arr, 0, 32, *txid);
2479         LDKu8slice script_pubkey_var = script_pubkey;
2480         jbyteArray script_pubkey_arr = (*_env)->NewByteArray(_env, script_pubkey_var.datalen);
2481         (*_env)->SetByteArrayRegion(_env, script_pubkey_arr, 0, script_pubkey_var.datalen, script_pubkey_var.data);
2482         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
2483         CHECK(obj != NULL);
2484         return (*_env)->CallVoidMethod(_env, obj, j_calls->register_tx_meth, txid_arr, script_pubkey_arr);
2485 }
2486 void register_output_jcall(const void* this_arg, const LDKOutPoint *outpoint, LDKu8slice script_pubkey) {
2487         LDKFilter_JCalls *j_calls = (LDKFilter_JCalls*) this_arg;
2488         JNIEnv *_env;
2489         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
2490         LDKOutPoint outpoint_var = *outpoint;
2491         CHECK((((long)outpoint_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2492         CHECK((((long)&outpoint_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2493         long outpoint_ref = (long)outpoint_var.inner & ~1;
2494         LDKu8slice script_pubkey_var = script_pubkey;
2495         jbyteArray script_pubkey_arr = (*_env)->NewByteArray(_env, script_pubkey_var.datalen);
2496         (*_env)->SetByteArrayRegion(_env, script_pubkey_arr, 0, script_pubkey_var.datalen, script_pubkey_var.data);
2497         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
2498         CHECK(obj != NULL);
2499         return (*_env)->CallVoidMethod(_env, obj, j_calls->register_output_meth, outpoint_ref, script_pubkey_arr);
2500 }
2501 static void LDKFilter_JCalls_free(void* this_arg) {
2502         LDKFilter_JCalls *j_calls = (LDKFilter_JCalls*) this_arg;
2503         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
2504                 JNIEnv *env;
2505                 DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
2506                 (*env)->DeleteWeakGlobalRef(env, j_calls->o);
2507                 FREE(j_calls);
2508         }
2509 }
2510 static void* LDKFilter_JCalls_clone(const void* this_arg) {
2511         LDKFilter_JCalls *j_calls = (LDKFilter_JCalls*) this_arg;
2512         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
2513         return (void*) this_arg;
2514 }
2515 static inline LDKFilter LDKFilter_init (JNIEnv * env, jclass _a, jobject o) {
2516         jclass c = (*env)->GetObjectClass(env, o);
2517         CHECK(c != NULL);
2518         LDKFilter_JCalls *calls = MALLOC(sizeof(LDKFilter_JCalls), "LDKFilter_JCalls");
2519         atomic_init(&calls->refcnt, 1);
2520         DO_ASSERT((*env)->GetJavaVM(env, &calls->vm) == 0);
2521         calls->o = (*env)->NewWeakGlobalRef(env, o);
2522         calls->register_tx_meth = (*env)->GetMethodID(env, c, "register_tx", "([B[B)V");
2523         CHECK(calls->register_tx_meth != NULL);
2524         calls->register_output_meth = (*env)->GetMethodID(env, c, "register_output", "(J[B)V");
2525         CHECK(calls->register_output_meth != NULL);
2526
2527         LDKFilter ret = {
2528                 .this_arg = (void*) calls,
2529                 .register_tx = register_tx_jcall,
2530                 .register_output = register_output_jcall,
2531                 .free = LDKFilter_JCalls_free,
2532         };
2533         return ret;
2534 }
2535 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_LDKFilter_1new (JNIEnv * env, jclass _a, jobject o) {
2536         LDKFilter *res_ptr = MALLOC(sizeof(LDKFilter), "LDKFilter");
2537         *res_ptr = LDKFilter_init(env, _a, o);
2538         return (long)res_ptr;
2539 }
2540 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKFilter_1get_1obj_1from_1jcalls (JNIEnv * env, jclass _a, jlong val) {
2541         jobject ret = (*env)->NewLocalRef(env, ((LDKFilter_JCalls*)val)->o);
2542         CHECK(ret != NULL);
2543         return ret;
2544 }
2545 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Filter_1register_1tx(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray txid, jbyteArray script_pubkey) {
2546         LDKFilter* this_arg_conv = (LDKFilter*)this_arg;
2547         unsigned char txid_arr[32];
2548         CHECK((*_env)->GetArrayLength (_env, txid) == 32);
2549         (*_env)->GetByteArrayRegion (_env, txid, 0, 32, txid_arr);
2550         unsigned char (*txid_ref)[32] = &txid_arr;
2551         LDKu8slice script_pubkey_ref;
2552         script_pubkey_ref.data = (*_env)->GetByteArrayElements (_env, script_pubkey, NULL);
2553         script_pubkey_ref.datalen = (*_env)->GetArrayLength (_env, script_pubkey);
2554         (this_arg_conv->register_tx)(this_arg_conv->this_arg, txid_ref, script_pubkey_ref);
2555         (*_env)->ReleaseByteArrayElements(_env, script_pubkey, (int8_t*)script_pubkey_ref.data, 0);
2556 }
2557
2558 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Filter_1register_1output(JNIEnv * _env, jclass _b, jlong this_arg, jlong outpoint, jbyteArray script_pubkey) {
2559         LDKFilter* this_arg_conv = (LDKFilter*)this_arg;
2560         LDKOutPoint outpoint_conv;
2561         outpoint_conv.inner = (void*)(outpoint & (~1));
2562         outpoint_conv.is_owned = (outpoint & 1) || (outpoint == 0);
2563         LDKu8slice script_pubkey_ref;
2564         script_pubkey_ref.data = (*_env)->GetByteArrayElements (_env, script_pubkey, NULL);
2565         script_pubkey_ref.datalen = (*_env)->GetArrayLength (_env, script_pubkey);
2566         (this_arg_conv->register_output)(this_arg_conv->this_arg, &outpoint_conv, script_pubkey_ref);
2567         (*_env)->ReleaseByteArrayElements(_env, script_pubkey, (int8_t*)script_pubkey_ref.data, 0);
2568 }
2569
2570 typedef struct LDKBroadcasterInterface_JCalls {
2571         atomic_size_t refcnt;
2572         JavaVM *vm;
2573         jweak o;
2574         jmethodID broadcast_transaction_meth;
2575 } LDKBroadcasterInterface_JCalls;
2576 void broadcast_transaction_jcall(const void* this_arg, LDKTransaction tx) {
2577         LDKBroadcasterInterface_JCalls *j_calls = (LDKBroadcasterInterface_JCalls*) this_arg;
2578         JNIEnv *_env;
2579         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
2580         LDKTransaction *tx_copy = MALLOC(sizeof(LDKTransaction), "LDKTransaction");
2581         *tx_copy = tx;
2582         long tx_ref = (long)tx_copy;
2583         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
2584         CHECK(obj != NULL);
2585         return (*_env)->CallVoidMethod(_env, obj, j_calls->broadcast_transaction_meth, tx_ref);
2586 }
2587 static void LDKBroadcasterInterface_JCalls_free(void* this_arg) {
2588         LDKBroadcasterInterface_JCalls *j_calls = (LDKBroadcasterInterface_JCalls*) this_arg;
2589         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
2590                 JNIEnv *env;
2591                 DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
2592                 (*env)->DeleteWeakGlobalRef(env, j_calls->o);
2593                 FREE(j_calls);
2594         }
2595 }
2596 static void* LDKBroadcasterInterface_JCalls_clone(const void* this_arg) {
2597         LDKBroadcasterInterface_JCalls *j_calls = (LDKBroadcasterInterface_JCalls*) this_arg;
2598         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
2599         return (void*) this_arg;
2600 }
2601 static inline LDKBroadcasterInterface LDKBroadcasterInterface_init (JNIEnv * env, jclass _a, jobject o) {
2602         jclass c = (*env)->GetObjectClass(env, o);
2603         CHECK(c != NULL);
2604         LDKBroadcasterInterface_JCalls *calls = MALLOC(sizeof(LDKBroadcasterInterface_JCalls), "LDKBroadcasterInterface_JCalls");
2605         atomic_init(&calls->refcnt, 1);
2606         DO_ASSERT((*env)->GetJavaVM(env, &calls->vm) == 0);
2607         calls->o = (*env)->NewWeakGlobalRef(env, o);
2608         calls->broadcast_transaction_meth = (*env)->GetMethodID(env, c, "broadcast_transaction", "(J)V");
2609         CHECK(calls->broadcast_transaction_meth != NULL);
2610
2611         LDKBroadcasterInterface ret = {
2612                 .this_arg = (void*) calls,
2613                 .broadcast_transaction = broadcast_transaction_jcall,
2614                 .free = LDKBroadcasterInterface_JCalls_free,
2615         };
2616         return ret;
2617 }
2618 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_LDKBroadcasterInterface_1new (JNIEnv * env, jclass _a, jobject o) {
2619         LDKBroadcasterInterface *res_ptr = MALLOC(sizeof(LDKBroadcasterInterface), "LDKBroadcasterInterface");
2620         *res_ptr = LDKBroadcasterInterface_init(env, _a, o);
2621         return (long)res_ptr;
2622 }
2623 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKBroadcasterInterface_1get_1obj_1from_1jcalls (JNIEnv * env, jclass _a, jlong val) {
2624         jobject ret = (*env)->NewLocalRef(env, ((LDKBroadcasterInterface_JCalls*)val)->o);
2625         CHECK(ret != NULL);
2626         return ret;
2627 }
2628 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_BroadcasterInterface_1broadcast_1transaction(JNIEnv * _env, jclass _b, jlong this_arg, jlong tx) {
2629         LDKBroadcasterInterface* this_arg_conv = (LDKBroadcasterInterface*)this_arg;
2630         LDKTransaction tx_conv = *(LDKTransaction*)tx;
2631         (this_arg_conv->broadcast_transaction)(this_arg_conv->this_arg, tx_conv);
2632 }
2633
2634 typedef struct LDKFeeEstimator_JCalls {
2635         atomic_size_t refcnt;
2636         JavaVM *vm;
2637         jweak o;
2638         jmethodID get_est_sat_per_1000_weight_meth;
2639 } LDKFeeEstimator_JCalls;
2640 uint32_t get_est_sat_per_1000_weight_jcall(const void* this_arg, LDKConfirmationTarget confirmation_target) {
2641         LDKFeeEstimator_JCalls *j_calls = (LDKFeeEstimator_JCalls*) this_arg;
2642         JNIEnv *_env;
2643         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
2644         jclass confirmation_target_conv = LDKConfirmationTarget_to_java(_env, confirmation_target);
2645         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
2646         CHECK(obj != NULL);
2647         return (*_env)->CallIntMethod(_env, obj, j_calls->get_est_sat_per_1000_weight_meth, confirmation_target_conv);
2648 }
2649 static void LDKFeeEstimator_JCalls_free(void* this_arg) {
2650         LDKFeeEstimator_JCalls *j_calls = (LDKFeeEstimator_JCalls*) this_arg;
2651         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
2652                 JNIEnv *env;
2653                 DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
2654                 (*env)->DeleteWeakGlobalRef(env, j_calls->o);
2655                 FREE(j_calls);
2656         }
2657 }
2658 static void* LDKFeeEstimator_JCalls_clone(const void* this_arg) {
2659         LDKFeeEstimator_JCalls *j_calls = (LDKFeeEstimator_JCalls*) this_arg;
2660         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
2661         return (void*) this_arg;
2662 }
2663 static inline LDKFeeEstimator LDKFeeEstimator_init (JNIEnv * env, jclass _a, jobject o) {
2664         jclass c = (*env)->GetObjectClass(env, o);
2665         CHECK(c != NULL);
2666         LDKFeeEstimator_JCalls *calls = MALLOC(sizeof(LDKFeeEstimator_JCalls), "LDKFeeEstimator_JCalls");
2667         atomic_init(&calls->refcnt, 1);
2668         DO_ASSERT((*env)->GetJavaVM(env, &calls->vm) == 0);
2669         calls->o = (*env)->NewWeakGlobalRef(env, o);
2670         calls->get_est_sat_per_1000_weight_meth = (*env)->GetMethodID(env, c, "get_est_sat_per_1000_weight", "(Lorg/ldk/enums/LDKConfirmationTarget;)I");
2671         CHECK(calls->get_est_sat_per_1000_weight_meth != NULL);
2672
2673         LDKFeeEstimator ret = {
2674                 .this_arg = (void*) calls,
2675                 .get_est_sat_per_1000_weight = get_est_sat_per_1000_weight_jcall,
2676                 .free = LDKFeeEstimator_JCalls_free,
2677         };
2678         return ret;
2679 }
2680 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_LDKFeeEstimator_1new (JNIEnv * env, jclass _a, jobject o) {
2681         LDKFeeEstimator *res_ptr = MALLOC(sizeof(LDKFeeEstimator), "LDKFeeEstimator");
2682         *res_ptr = LDKFeeEstimator_init(env, _a, o);
2683         return (long)res_ptr;
2684 }
2685 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKFeeEstimator_1get_1obj_1from_1jcalls (JNIEnv * env, jclass _a, jlong val) {
2686         jobject ret = (*env)->NewLocalRef(env, ((LDKFeeEstimator_JCalls*)val)->o);
2687         CHECK(ret != NULL);
2688         return ret;
2689 }
2690 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) {
2691         LDKFeeEstimator* this_arg_conv = (LDKFeeEstimator*)this_arg;
2692         LDKConfirmationTarget confirmation_target_conv = LDKConfirmationTarget_from_java(_env, confirmation_target);
2693         jint ret_val = (this_arg_conv->get_est_sat_per_1000_weight)(this_arg_conv->this_arg, confirmation_target_conv);
2694         return ret_val;
2695 }
2696
2697 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1C2TupleTempl_1usize_1_1Transaction_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
2698         LDKCVecTempl_C2TupleTempl_usize__Transaction *vec = (LDKCVecTempl_C2TupleTempl_usize__Transaction*)ptr;
2699         return (*env)->NewObject(env, slicedef_cls, slicedef_meth, (long)vec->data, (long)vec->datalen, sizeof(LDKC2TupleTempl_usize__Transaction));
2700 }
2701 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1C2TupleTempl_1usize_1_1Transaction_1new(JNIEnv *env, jclass _b, jlongArray elems){
2702         LDKCVecTempl_C2TupleTempl_usize__Transaction *ret = MALLOC(sizeof(LDKCVecTempl_C2TupleTempl_usize__Transaction), "LDKCVecTempl_C2TupleTempl_usize__Transaction");
2703         ret->datalen = (*env)->GetArrayLength(env, elems);
2704         if (ret->datalen == 0) {
2705                 ret->data = NULL;
2706         } else {
2707                 ret->data = MALLOC(sizeof(LDKC2TupleTempl_usize__Transaction) * ret->datalen, "LDKCVecTempl_C2TupleTempl_usize__Transaction Data");
2708                 jlong *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
2709                 for (size_t i = 0; i < ret->datalen; i++) {
2710                         jlong arr_elem = java_elems[i];
2711                         LDKC2TupleTempl_usize__Transaction arr_elem_conv = *(LDKC2TupleTempl_usize__Transaction*)arr_elem;
2712                         FREE((void*)arr_elem);
2713                         ret->data[i] = arr_elem_conv;
2714                 }
2715                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
2716         }
2717         return (long)ret;
2718 }
2719 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1Transaction_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
2720         LDKCVecTempl_Transaction *vec = (LDKCVecTempl_Transaction*)ptr;
2721         return (*env)->NewObject(env, slicedef_cls, slicedef_meth, (long)vec->data, (long)vec->datalen, sizeof(LDKTransaction));
2722 }
2723 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1Transaction_1new(JNIEnv *env, jclass _b, jlongArray elems){
2724         LDKCVecTempl_Transaction *ret = MALLOC(sizeof(LDKCVecTempl_Transaction), "LDKCVecTempl_Transaction");
2725         ret->datalen = (*env)->GetArrayLength(env, elems);
2726         if (ret->datalen == 0) {
2727                 ret->data = NULL;
2728         } else {
2729                 ret->data = MALLOC(sizeof(LDKTransaction) * ret->datalen, "LDKCVecTempl_Transaction Data");
2730                 jlong *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
2731                 for (size_t i = 0; i < ret->datalen; i++) {
2732                         jlong arr_elem = java_elems[i];
2733                         LDKTransaction arr_elem_conv = *(LDKTransaction*)arr_elem;
2734                         ret->data[i] = arr_elem_conv;
2735                 }
2736                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
2737         }
2738         return (long)ret;
2739 }
2740 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1C2TupleTempl_1ThirtyTwoBytes_1_1CVecTempl_1TxOut_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
2741         LDKCVecTempl_C2TupleTempl_ThirtyTwoBytes__CVecTempl_TxOut *vec = (LDKCVecTempl_C2TupleTempl_ThirtyTwoBytes__CVecTempl_TxOut*)ptr;
2742         return (*env)->NewObject(env, slicedef_cls, slicedef_meth, (long)vec->data, (long)vec->datalen, sizeof(LDKC2TupleTempl_ThirtyTwoBytes__CVecTempl_TxOut));
2743 }
2744 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1C2TupleTempl_1ThirtyTwoBytes_1_1CVecTempl_1TxOut_1new(JNIEnv *env, jclass _b, jlongArray elems){
2745         LDKCVecTempl_C2TupleTempl_ThirtyTwoBytes__CVecTempl_TxOut *ret = MALLOC(sizeof(LDKCVecTempl_C2TupleTempl_ThirtyTwoBytes__CVecTempl_TxOut), "LDKCVecTempl_C2TupleTempl_ThirtyTwoBytes__CVecTempl_TxOut");
2746         ret->datalen = (*env)->GetArrayLength(env, elems);
2747         if (ret->datalen == 0) {
2748                 ret->data = NULL;
2749         } else {
2750                 ret->data = MALLOC(sizeof(LDKC2TupleTempl_ThirtyTwoBytes__CVecTempl_TxOut) * ret->datalen, "LDKCVecTempl_C2TupleTempl_ThirtyTwoBytes__CVecTempl_TxOut Data");
2751                 jlong *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
2752                 for (size_t i = 0; i < ret->datalen; i++) {
2753                         jlong arr_elem = java_elems[i];
2754                         LDKC2TupleTempl_ThirtyTwoBytes__CVecTempl_TxOut arr_elem_conv = *(LDKC2TupleTempl_ThirtyTwoBytes__CVecTempl_TxOut*)arr_elem;
2755                         FREE((void*)arr_elem);
2756                         ret->data[i] = arr_elem_conv;
2757                 }
2758                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
2759         }
2760         return (long)ret;
2761 }
2762 typedef struct LDKKeysInterface_JCalls {
2763         atomic_size_t refcnt;
2764         JavaVM *vm;
2765         jweak o;
2766         jmethodID get_node_secret_meth;
2767         jmethodID get_destination_script_meth;
2768         jmethodID get_shutdown_pubkey_meth;
2769         jmethodID get_channel_keys_meth;
2770         jmethodID get_secure_random_bytes_meth;
2771 } LDKKeysInterface_JCalls;
2772 LDKSecretKey get_node_secret_jcall(const void* this_arg) {
2773         LDKKeysInterface_JCalls *j_calls = (LDKKeysInterface_JCalls*) this_arg;
2774         JNIEnv *_env;
2775         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
2776         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
2777         CHECK(obj != NULL);
2778         jbyteArray arg = (*_env)->CallObjectMethod(_env, obj, j_calls->get_node_secret_meth);
2779         LDKSecretKey arg_ref;
2780         CHECK((*_env)->GetArrayLength (_env, arg) == 32);
2781         (*_env)->GetByteArrayRegion (_env, arg, 0, 32, arg_ref.bytes);
2782         return arg_ref;
2783 }
2784 LDKCVec_u8Z get_destination_script_jcall(const void* this_arg) {
2785         LDKKeysInterface_JCalls *j_calls = (LDKKeysInterface_JCalls*) this_arg;
2786         JNIEnv *_env;
2787         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
2788         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
2789         CHECK(obj != NULL);
2790         jbyteArray arg = (*_env)->CallObjectMethod(_env, obj, j_calls->get_destination_script_meth);
2791         LDKCVec_u8Z arg_ref;
2792         arg_ref.data = (*_env)->GetByteArrayElements (_env, arg, NULL);
2793         arg_ref.datalen = (*_env)->GetArrayLength (_env, arg);
2794         return arg_ref;
2795 }
2796 LDKPublicKey get_shutdown_pubkey_jcall(const void* this_arg) {
2797         LDKKeysInterface_JCalls *j_calls = (LDKKeysInterface_JCalls*) this_arg;
2798         JNIEnv *_env;
2799         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
2800         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
2801         CHECK(obj != NULL);
2802         jbyteArray arg = (*_env)->CallObjectMethod(_env, obj, j_calls->get_shutdown_pubkey_meth);
2803         LDKPublicKey arg_ref;
2804         CHECK((*_env)->GetArrayLength (_env, arg) == 33);
2805         (*_env)->GetByteArrayRegion (_env, arg, 0, 33, arg_ref.compressed_form);
2806         return arg_ref;
2807 }
2808 LDKChannelKeys get_channel_keys_jcall(const void* this_arg, bool inbound, uint64_t channel_value_satoshis) {
2809         LDKKeysInterface_JCalls *j_calls = (LDKKeysInterface_JCalls*) this_arg;
2810         JNIEnv *_env;
2811         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
2812         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
2813         CHECK(obj != NULL);
2814         LDKChannelKeys* ret = (LDKChannelKeys*)(*_env)->CallLongMethod(_env, obj, j_calls->get_channel_keys_meth, inbound, channel_value_satoshis);
2815         LDKChannelKeys ret_conv = *(LDKChannelKeys*)ret;
2816         if (ret_conv.free == LDKChannelKeys_JCalls_free) {
2817                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
2818                 LDKChannelKeys_JCalls_clone(ret_conv.this_arg);
2819         }
2820         return ret_conv;
2821 }
2822 LDKThirtyTwoBytes get_secure_random_bytes_jcall(const void* this_arg) {
2823         LDKKeysInterface_JCalls *j_calls = (LDKKeysInterface_JCalls*) this_arg;
2824         JNIEnv *_env;
2825         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
2826         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
2827         CHECK(obj != NULL);
2828         jbyteArray arg = (*_env)->CallObjectMethod(_env, obj, j_calls->get_secure_random_bytes_meth);
2829         LDKThirtyTwoBytes arg_ref;
2830         CHECK((*_env)->GetArrayLength (_env, arg) == 32);
2831         (*_env)->GetByteArrayRegion (_env, arg, 0, 32, arg_ref.data);
2832         return arg_ref;
2833 }
2834 static void LDKKeysInterface_JCalls_free(void* this_arg) {
2835         LDKKeysInterface_JCalls *j_calls = (LDKKeysInterface_JCalls*) this_arg;
2836         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
2837                 JNIEnv *env;
2838                 DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
2839                 (*env)->DeleteWeakGlobalRef(env, j_calls->o);
2840                 FREE(j_calls);
2841         }
2842 }
2843 static void* LDKKeysInterface_JCalls_clone(const void* this_arg) {
2844         LDKKeysInterface_JCalls *j_calls = (LDKKeysInterface_JCalls*) this_arg;
2845         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
2846         return (void*) this_arg;
2847 }
2848 static inline LDKKeysInterface LDKKeysInterface_init (JNIEnv * env, jclass _a, jobject o) {
2849         jclass c = (*env)->GetObjectClass(env, o);
2850         CHECK(c != NULL);
2851         LDKKeysInterface_JCalls *calls = MALLOC(sizeof(LDKKeysInterface_JCalls), "LDKKeysInterface_JCalls");
2852         atomic_init(&calls->refcnt, 1);
2853         DO_ASSERT((*env)->GetJavaVM(env, &calls->vm) == 0);
2854         calls->o = (*env)->NewWeakGlobalRef(env, o);
2855         calls->get_node_secret_meth = (*env)->GetMethodID(env, c, "get_node_secret", "()[B");
2856         CHECK(calls->get_node_secret_meth != NULL);
2857         calls->get_destination_script_meth = (*env)->GetMethodID(env, c, "get_destination_script", "()[B");
2858         CHECK(calls->get_destination_script_meth != NULL);
2859         calls->get_shutdown_pubkey_meth = (*env)->GetMethodID(env, c, "get_shutdown_pubkey", "()[B");
2860         CHECK(calls->get_shutdown_pubkey_meth != NULL);
2861         calls->get_channel_keys_meth = (*env)->GetMethodID(env, c, "get_channel_keys", "(ZJ)J");
2862         CHECK(calls->get_channel_keys_meth != NULL);
2863         calls->get_secure_random_bytes_meth = (*env)->GetMethodID(env, c, "get_secure_random_bytes", "()[B");
2864         CHECK(calls->get_secure_random_bytes_meth != NULL);
2865
2866         LDKKeysInterface ret = {
2867                 .this_arg = (void*) calls,
2868                 .get_node_secret = get_node_secret_jcall,
2869                 .get_destination_script = get_destination_script_jcall,
2870                 .get_shutdown_pubkey = get_shutdown_pubkey_jcall,
2871                 .get_channel_keys = get_channel_keys_jcall,
2872                 .get_secure_random_bytes = get_secure_random_bytes_jcall,
2873                 .free = LDKKeysInterface_JCalls_free,
2874         };
2875         return ret;
2876 }
2877 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_LDKKeysInterface_1new (JNIEnv * env, jclass _a, jobject o) {
2878         LDKKeysInterface *res_ptr = MALLOC(sizeof(LDKKeysInterface), "LDKKeysInterface");
2879         *res_ptr = LDKKeysInterface_init(env, _a, o);
2880         return (long)res_ptr;
2881 }
2882 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKKeysInterface_1get_1obj_1from_1jcalls (JNIEnv * env, jclass _a, jlong val) {
2883         jobject ret = (*env)->NewLocalRef(env, ((LDKKeysInterface_JCalls*)val)->o);
2884         CHECK(ret != NULL);
2885         return ret;
2886 }
2887 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_KeysInterface_1get_1node_1secret(JNIEnv * _env, jclass _b, jlong this_arg) {
2888         LDKKeysInterface* this_arg_conv = (LDKKeysInterface*)this_arg;
2889         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 32);
2890         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 32, (this_arg_conv->get_node_secret)(this_arg_conv->this_arg).bytes);
2891         return arg_arr;
2892 }
2893
2894 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_KeysInterface_1get_1destination_1script(JNIEnv * _env, jclass _b, jlong this_arg) {
2895         LDKKeysInterface* this_arg_conv = (LDKKeysInterface*)this_arg;
2896         LDKCVec_u8Z arg_var = (this_arg_conv->get_destination_script)(this_arg_conv->this_arg);
2897         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
2898         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
2899         CVec_u8Z_free(arg_var);
2900         return arg_arr;
2901 }
2902
2903 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_KeysInterface_1get_1shutdown_1pubkey(JNIEnv * _env, jclass _b, jlong this_arg) {
2904         LDKKeysInterface* this_arg_conv = (LDKKeysInterface*)this_arg;
2905         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
2906         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, (this_arg_conv->get_shutdown_pubkey)(this_arg_conv->this_arg).compressed_form);
2907         return arg_arr;
2908 }
2909
2910 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) {
2911         LDKKeysInterface* this_arg_conv = (LDKKeysInterface*)this_arg;
2912         LDKChannelKeys* ret = MALLOC(sizeof(LDKChannelKeys), "LDKChannelKeys");
2913         *ret = (this_arg_conv->get_channel_keys)(this_arg_conv->this_arg, inbound, channel_value_satoshis);
2914         return (long)ret;
2915 }
2916
2917 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_KeysInterface_1get_1secure_1random_1bytes(JNIEnv * _env, jclass _b, jlong this_arg) {
2918         LDKKeysInterface* this_arg_conv = (LDKKeysInterface*)this_arg;
2919         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 32);
2920         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 32, (this_arg_conv->get_secure_random_bytes)(this_arg_conv->this_arg).data);
2921         return arg_arr;
2922 }
2923
2924 JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1ChannelDetails_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
2925         LDKCVecTempl_ChannelDetails *vec = (LDKCVecTempl_ChannelDetails*)ptr;
2926         jlongArray ret = (*env)->NewLongArray(env, vec->datalen);
2927         jlong *ret_elems = (*env)->GetPrimitiveArrayCritical(env, ret, NULL);
2928         for (size_t i = 0; i < vec->datalen; i++) {
2929                 CHECK((((long)vec->data[i].inner) & 1) == 0);
2930                 ret_elems[i] = (long)vec->data[i].inner | (vec->data[i].is_owned ? 1 : 0);
2931         }
2932         (*env)->ReleasePrimitiveArrayCritical(env, ret, ret_elems, 0);
2933         return ret;
2934 }
2935 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1ChannelDetails_1new(JNIEnv *env, jclass _b, jlongArray elems){
2936         LDKCVecTempl_ChannelDetails *ret = MALLOC(sizeof(LDKCVecTempl_ChannelDetails), "LDKCVecTempl_ChannelDetails");
2937         ret->datalen = (*env)->GetArrayLength(env, elems);
2938         if (ret->datalen == 0) {
2939                 ret->data = NULL;
2940         } else {
2941                 ret->data = MALLOC(sizeof(LDKChannelDetails) * ret->datalen, "LDKCVecTempl_ChannelDetails Data");
2942                 jlong *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
2943                 for (size_t i = 0; i < ret->datalen; i++) {
2944                         jlong arr_elem = java_elems[i];
2945                         LDKChannelDetails arr_elem_conv;
2946                         arr_elem_conv.inner = (void*)(arr_elem & (~1));
2947                         arr_elem_conv.is_owned = (arr_elem & 1) || (arr_elem == 0);
2948                         if (arr_elem_conv.inner != NULL)
2949                                 arr_elem_conv = ChannelDetails_clone(&arr_elem_conv);
2950                         ret->data[i] = arr_elem_conv;
2951                 }
2952                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
2953         }
2954         return (long)ret;
2955 }
2956 static jclass LDKNetAddress_IPv4_class = NULL;
2957 static jmethodID LDKNetAddress_IPv4_meth = NULL;
2958 static jclass LDKNetAddress_IPv6_class = NULL;
2959 static jmethodID LDKNetAddress_IPv6_meth = NULL;
2960 static jclass LDKNetAddress_OnionV2_class = NULL;
2961 static jmethodID LDKNetAddress_OnionV2_meth = NULL;
2962 static jclass LDKNetAddress_OnionV3_class = NULL;
2963 static jmethodID LDKNetAddress_OnionV3_meth = NULL;
2964 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_00024LDKNetAddress_init (JNIEnv * env, jclass _a) {
2965         LDKNetAddress_IPv4_class =
2966                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKNetAddress$IPv4;"));
2967         CHECK(LDKNetAddress_IPv4_class != NULL);
2968         LDKNetAddress_IPv4_meth = (*env)->GetMethodID(env, LDKNetAddress_IPv4_class, "<init>", "([BS)V");
2969         CHECK(LDKNetAddress_IPv4_meth != NULL);
2970         LDKNetAddress_IPv6_class =
2971                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKNetAddress$IPv6;"));
2972         CHECK(LDKNetAddress_IPv6_class != NULL);
2973         LDKNetAddress_IPv6_meth = (*env)->GetMethodID(env, LDKNetAddress_IPv6_class, "<init>", "([BS)V");
2974         CHECK(LDKNetAddress_IPv6_meth != NULL);
2975         LDKNetAddress_OnionV2_class =
2976                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKNetAddress$OnionV2;"));
2977         CHECK(LDKNetAddress_OnionV2_class != NULL);
2978         LDKNetAddress_OnionV2_meth = (*env)->GetMethodID(env, LDKNetAddress_OnionV2_class, "<init>", "([BS)V");
2979         CHECK(LDKNetAddress_OnionV2_meth != NULL);
2980         LDKNetAddress_OnionV3_class =
2981                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKNetAddress$OnionV3;"));
2982         CHECK(LDKNetAddress_OnionV3_class != NULL);
2983         LDKNetAddress_OnionV3_meth = (*env)->GetMethodID(env, LDKNetAddress_OnionV3_class, "<init>", "([BSBS)V");
2984         CHECK(LDKNetAddress_OnionV3_meth != NULL);
2985 }
2986 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKNetAddress_1ref_1from_1ptr (JNIEnv * _env, jclass _c, jlong ptr) {
2987         LDKNetAddress *obj = (LDKNetAddress*)ptr;
2988         switch(obj->tag) {
2989                 case LDKNetAddress_IPv4: {
2990                         jbyteArray addr_arr = (*_env)->NewByteArray(_env, 4);
2991                         (*_env)->SetByteArrayRegion(_env, addr_arr, 0, 4, obj->i_pv4.addr.data);
2992                         return (*_env)->NewObject(_env, LDKNetAddress_IPv4_class, LDKNetAddress_IPv4_meth, addr_arr, obj->i_pv4.port);
2993                 }
2994                 case LDKNetAddress_IPv6: {
2995                         jbyteArray addr_arr = (*_env)->NewByteArray(_env, 16);
2996                         (*_env)->SetByteArrayRegion(_env, addr_arr, 0, 16, obj->i_pv6.addr.data);
2997                         return (*_env)->NewObject(_env, LDKNetAddress_IPv6_class, LDKNetAddress_IPv6_meth, addr_arr, obj->i_pv6.port);
2998                 }
2999                 case LDKNetAddress_OnionV2: {
3000                         jbyteArray addr_arr = (*_env)->NewByteArray(_env, 10);
3001                         (*_env)->SetByteArrayRegion(_env, addr_arr, 0, 10, obj->onion_v2.addr.data);
3002                         return (*_env)->NewObject(_env, LDKNetAddress_OnionV2_class, LDKNetAddress_OnionV2_meth, addr_arr, obj->onion_v2.port);
3003                 }
3004                 case LDKNetAddress_OnionV3: {
3005                         jbyteArray ed25519_pubkey_arr = (*_env)->NewByteArray(_env, 32);
3006                         (*_env)->SetByteArrayRegion(_env, ed25519_pubkey_arr, 0, 32, obj->onion_v3.ed25519_pubkey.data);
3007                         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);
3008                 }
3009                 default: abort();
3010         }
3011 }
3012 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1NetAddress_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
3013         LDKCVecTempl_NetAddress *vec = (LDKCVecTempl_NetAddress*)ptr;
3014         return (*env)->NewObject(env, slicedef_cls, slicedef_meth, (long)vec->data, (long)vec->datalen, sizeof(LDKNetAddress));
3015 }
3016 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1NetAddress_1new(JNIEnv *env, jclass _b, jlongArray elems){
3017         LDKCVecTempl_NetAddress *ret = MALLOC(sizeof(LDKCVecTempl_NetAddress), "LDKCVecTempl_NetAddress");
3018         ret->datalen = (*env)->GetArrayLength(env, elems);
3019         if (ret->datalen == 0) {
3020                 ret->data = NULL;
3021         } else {
3022                 ret->data = MALLOC(sizeof(LDKNetAddress) * ret->datalen, "LDKCVecTempl_NetAddress Data");
3023                 jlong *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
3024                 for (size_t i = 0; i < ret->datalen; i++) {
3025                         jlong arr_elem = java_elems[i];
3026                         LDKNetAddress arr_elem_conv = *(LDKNetAddress*)arr_elem;
3027                         FREE((void*)arr_elem);
3028                         ret->data[i] = arr_elem_conv;
3029                 }
3030                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
3031         }
3032         return (long)ret;
3033 }
3034 typedef struct LDKChannelMessageHandler_JCalls {
3035         atomic_size_t refcnt;
3036         JavaVM *vm;
3037         jweak o;
3038         LDKMessageSendEventsProvider_JCalls* MessageSendEventsProvider;
3039         jmethodID handle_open_channel_meth;
3040         jmethodID handle_accept_channel_meth;
3041         jmethodID handle_funding_created_meth;
3042         jmethodID handle_funding_signed_meth;
3043         jmethodID handle_funding_locked_meth;
3044         jmethodID handle_shutdown_meth;
3045         jmethodID handle_closing_signed_meth;
3046         jmethodID handle_update_add_htlc_meth;
3047         jmethodID handle_update_fulfill_htlc_meth;
3048         jmethodID handle_update_fail_htlc_meth;
3049         jmethodID handle_update_fail_malformed_htlc_meth;
3050         jmethodID handle_commitment_signed_meth;
3051         jmethodID handle_revoke_and_ack_meth;
3052         jmethodID handle_update_fee_meth;
3053         jmethodID handle_announcement_signatures_meth;
3054         jmethodID peer_disconnected_meth;
3055         jmethodID peer_connected_meth;
3056         jmethodID handle_channel_reestablish_meth;
3057         jmethodID handle_error_meth;
3058 } LDKChannelMessageHandler_JCalls;
3059 void handle_open_channel_jcall(const void* this_arg, LDKPublicKey their_node_id, LDKInitFeatures their_features, const LDKOpenChannel *msg) {
3060         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3061         JNIEnv *_env;
3062         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
3063         jbyteArray their_node_id_arr = (*_env)->NewByteArray(_env, 33);
3064         (*_env)->SetByteArrayRegion(_env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
3065         LDKInitFeatures their_features_var = their_features;
3066         CHECK((((long)their_features_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3067         CHECK((((long)&their_features_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3068         long their_features_ref = (long)their_features_var.inner;
3069         if (their_features_var.is_owned) {
3070                 their_features_ref |= 1;
3071         }
3072         LDKOpenChannel msg_var = *msg;
3073         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3074         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3075         long msg_ref = (long)msg_var.inner & ~1;
3076         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
3077         CHECK(obj != NULL);
3078         return (*_env)->CallVoidMethod(_env, obj, j_calls->handle_open_channel_meth, their_node_id_arr, their_features_ref, msg_ref);
3079 }
3080 void handle_accept_channel_jcall(const void* this_arg, LDKPublicKey their_node_id, LDKInitFeatures their_features, const LDKAcceptChannel *msg) {
3081         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3082         JNIEnv *_env;
3083         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
3084         jbyteArray their_node_id_arr = (*_env)->NewByteArray(_env, 33);
3085         (*_env)->SetByteArrayRegion(_env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
3086         LDKInitFeatures their_features_var = their_features;
3087         CHECK((((long)their_features_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3088         CHECK((((long)&their_features_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3089         long their_features_ref = (long)their_features_var.inner;
3090         if (their_features_var.is_owned) {
3091                 their_features_ref |= 1;
3092         }
3093         LDKAcceptChannel msg_var = *msg;
3094         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3095         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3096         long msg_ref = (long)msg_var.inner & ~1;
3097         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
3098         CHECK(obj != NULL);
3099         return (*_env)->CallVoidMethod(_env, obj, j_calls->handle_accept_channel_meth, their_node_id_arr, their_features_ref, msg_ref);
3100 }
3101 void handle_funding_created_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKFundingCreated *msg) {
3102         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3103         JNIEnv *_env;
3104         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
3105         jbyteArray their_node_id_arr = (*_env)->NewByteArray(_env, 33);
3106         (*_env)->SetByteArrayRegion(_env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
3107         LDKFundingCreated msg_var = *msg;
3108         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3109         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3110         long msg_ref = (long)msg_var.inner & ~1;
3111         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
3112         CHECK(obj != NULL);
3113         return (*_env)->CallVoidMethod(_env, obj, j_calls->handle_funding_created_meth, their_node_id_arr, msg_ref);
3114 }
3115 void handle_funding_signed_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKFundingSigned *msg) {
3116         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3117         JNIEnv *_env;
3118         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
3119         jbyteArray their_node_id_arr = (*_env)->NewByteArray(_env, 33);
3120         (*_env)->SetByteArrayRegion(_env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
3121         LDKFundingSigned msg_var = *msg;
3122         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3123         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3124         long msg_ref = (long)msg_var.inner & ~1;
3125         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
3126         CHECK(obj != NULL);
3127         return (*_env)->CallVoidMethod(_env, obj, j_calls->handle_funding_signed_meth, their_node_id_arr, msg_ref);
3128 }
3129 void handle_funding_locked_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKFundingLocked *msg) {
3130         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3131         JNIEnv *_env;
3132         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
3133         jbyteArray their_node_id_arr = (*_env)->NewByteArray(_env, 33);
3134         (*_env)->SetByteArrayRegion(_env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
3135         LDKFundingLocked msg_var = *msg;
3136         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3137         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3138         long msg_ref = (long)msg_var.inner & ~1;
3139         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
3140         CHECK(obj != NULL);
3141         return (*_env)->CallVoidMethod(_env, obj, j_calls->handle_funding_locked_meth, their_node_id_arr, msg_ref);
3142 }
3143 void handle_shutdown_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKShutdown *msg) {
3144         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3145         JNIEnv *_env;
3146         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
3147         jbyteArray their_node_id_arr = (*_env)->NewByteArray(_env, 33);
3148         (*_env)->SetByteArrayRegion(_env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
3149         LDKShutdown msg_var = *msg;
3150         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3151         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3152         long msg_ref = (long)msg_var.inner & ~1;
3153         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
3154         CHECK(obj != NULL);
3155         return (*_env)->CallVoidMethod(_env, obj, j_calls->handle_shutdown_meth, their_node_id_arr, msg_ref);
3156 }
3157 void handle_closing_signed_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKClosingSigned *msg) {
3158         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3159         JNIEnv *_env;
3160         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
3161         jbyteArray their_node_id_arr = (*_env)->NewByteArray(_env, 33);
3162         (*_env)->SetByteArrayRegion(_env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
3163         LDKClosingSigned msg_var = *msg;
3164         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3165         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3166         long msg_ref = (long)msg_var.inner & ~1;
3167         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
3168         CHECK(obj != NULL);
3169         return (*_env)->CallVoidMethod(_env, obj, j_calls->handle_closing_signed_meth, their_node_id_arr, msg_ref);
3170 }
3171 void handle_update_add_htlc_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKUpdateAddHTLC *msg) {
3172         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3173         JNIEnv *_env;
3174         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
3175         jbyteArray their_node_id_arr = (*_env)->NewByteArray(_env, 33);
3176         (*_env)->SetByteArrayRegion(_env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
3177         LDKUpdateAddHTLC msg_var = *msg;
3178         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3179         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3180         long msg_ref = (long)msg_var.inner & ~1;
3181         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
3182         CHECK(obj != NULL);
3183         return (*_env)->CallVoidMethod(_env, obj, j_calls->handle_update_add_htlc_meth, their_node_id_arr, msg_ref);
3184 }
3185 void handle_update_fulfill_htlc_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKUpdateFulfillHTLC *msg) {
3186         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3187         JNIEnv *_env;
3188         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
3189         jbyteArray their_node_id_arr = (*_env)->NewByteArray(_env, 33);
3190         (*_env)->SetByteArrayRegion(_env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
3191         LDKUpdateFulfillHTLC msg_var = *msg;
3192         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3193         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3194         long msg_ref = (long)msg_var.inner & ~1;
3195         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
3196         CHECK(obj != NULL);
3197         return (*_env)->CallVoidMethod(_env, obj, j_calls->handle_update_fulfill_htlc_meth, their_node_id_arr, msg_ref);
3198 }
3199 void handle_update_fail_htlc_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKUpdateFailHTLC *msg) {
3200         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3201         JNIEnv *_env;
3202         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
3203         jbyteArray their_node_id_arr = (*_env)->NewByteArray(_env, 33);
3204         (*_env)->SetByteArrayRegion(_env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
3205         LDKUpdateFailHTLC msg_var = *msg;
3206         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3207         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3208         long msg_ref = (long)msg_var.inner & ~1;
3209         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
3210         CHECK(obj != NULL);
3211         return (*_env)->CallVoidMethod(_env, obj, j_calls->handle_update_fail_htlc_meth, their_node_id_arr, msg_ref);
3212 }
3213 void handle_update_fail_malformed_htlc_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKUpdateFailMalformedHTLC *msg) {
3214         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3215         JNIEnv *_env;
3216         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
3217         jbyteArray their_node_id_arr = (*_env)->NewByteArray(_env, 33);
3218         (*_env)->SetByteArrayRegion(_env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
3219         LDKUpdateFailMalformedHTLC msg_var = *msg;
3220         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3221         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3222         long msg_ref = (long)msg_var.inner & ~1;
3223         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
3224         CHECK(obj != NULL);
3225         return (*_env)->CallVoidMethod(_env, obj, j_calls->handle_update_fail_malformed_htlc_meth, their_node_id_arr, msg_ref);
3226 }
3227 void handle_commitment_signed_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKCommitmentSigned *msg) {
3228         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3229         JNIEnv *_env;
3230         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
3231         jbyteArray their_node_id_arr = (*_env)->NewByteArray(_env, 33);
3232         (*_env)->SetByteArrayRegion(_env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
3233         LDKCommitmentSigned msg_var = *msg;
3234         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3235         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3236         long msg_ref = (long)msg_var.inner & ~1;
3237         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
3238         CHECK(obj != NULL);
3239         return (*_env)->CallVoidMethod(_env, obj, j_calls->handle_commitment_signed_meth, their_node_id_arr, msg_ref);
3240 }
3241 void handle_revoke_and_ack_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKRevokeAndACK *msg) {
3242         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3243         JNIEnv *_env;
3244         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
3245         jbyteArray their_node_id_arr = (*_env)->NewByteArray(_env, 33);
3246         (*_env)->SetByteArrayRegion(_env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
3247         LDKRevokeAndACK msg_var = *msg;
3248         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3249         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3250         long msg_ref = (long)msg_var.inner & ~1;
3251         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
3252         CHECK(obj != NULL);
3253         return (*_env)->CallVoidMethod(_env, obj, j_calls->handle_revoke_and_ack_meth, their_node_id_arr, msg_ref);
3254 }
3255 void handle_update_fee_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKUpdateFee *msg) {
3256         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3257         JNIEnv *_env;
3258         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
3259         jbyteArray their_node_id_arr = (*_env)->NewByteArray(_env, 33);
3260         (*_env)->SetByteArrayRegion(_env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
3261         LDKUpdateFee msg_var = *msg;
3262         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3263         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3264         long msg_ref = (long)msg_var.inner & ~1;
3265         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
3266         CHECK(obj != NULL);
3267         return (*_env)->CallVoidMethod(_env, obj, j_calls->handle_update_fee_meth, their_node_id_arr, msg_ref);
3268 }
3269 void handle_announcement_signatures_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKAnnouncementSignatures *msg) {
3270         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3271         JNIEnv *_env;
3272         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
3273         jbyteArray their_node_id_arr = (*_env)->NewByteArray(_env, 33);
3274         (*_env)->SetByteArrayRegion(_env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
3275         LDKAnnouncementSignatures msg_var = *msg;
3276         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3277         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3278         long msg_ref = (long)msg_var.inner & ~1;
3279         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
3280         CHECK(obj != NULL);
3281         return (*_env)->CallVoidMethod(_env, obj, j_calls->handle_announcement_signatures_meth, their_node_id_arr, msg_ref);
3282 }
3283 void peer_disconnected_jcall(const void* this_arg, LDKPublicKey their_node_id, bool no_connection_possible) {
3284         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3285         JNIEnv *_env;
3286         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
3287         jbyteArray their_node_id_arr = (*_env)->NewByteArray(_env, 33);
3288         (*_env)->SetByteArrayRegion(_env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
3289         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
3290         CHECK(obj != NULL);
3291         return (*_env)->CallVoidMethod(_env, obj, j_calls->peer_disconnected_meth, their_node_id_arr, no_connection_possible);
3292 }
3293 void peer_connected_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKInit *msg) {
3294         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3295         JNIEnv *_env;
3296         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
3297         jbyteArray their_node_id_arr = (*_env)->NewByteArray(_env, 33);
3298         (*_env)->SetByteArrayRegion(_env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
3299         LDKInit msg_var = *msg;
3300         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3301         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3302         long msg_ref = (long)msg_var.inner & ~1;
3303         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
3304         CHECK(obj != NULL);
3305         return (*_env)->CallVoidMethod(_env, obj, j_calls->peer_connected_meth, their_node_id_arr, msg_ref);
3306 }
3307 void handle_channel_reestablish_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKChannelReestablish *msg) {
3308         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3309         JNIEnv *_env;
3310         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
3311         jbyteArray their_node_id_arr = (*_env)->NewByteArray(_env, 33);
3312         (*_env)->SetByteArrayRegion(_env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
3313         LDKChannelReestablish msg_var = *msg;
3314         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3315         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3316         long msg_ref = (long)msg_var.inner & ~1;
3317         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
3318         CHECK(obj != NULL);
3319         return (*_env)->CallVoidMethod(_env, obj, j_calls->handle_channel_reestablish_meth, their_node_id_arr, msg_ref);
3320 }
3321 void handle_error_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKErrorMessage *msg) {
3322         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3323         JNIEnv *_env;
3324         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
3325         jbyteArray their_node_id_arr = (*_env)->NewByteArray(_env, 33);
3326         (*_env)->SetByteArrayRegion(_env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
3327         LDKErrorMessage msg_var = *msg;
3328         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3329         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3330         long msg_ref = (long)msg_var.inner & ~1;
3331         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
3332         CHECK(obj != NULL);
3333         return (*_env)->CallVoidMethod(_env, obj, j_calls->handle_error_meth, their_node_id_arr, msg_ref);
3334 }
3335 static void LDKChannelMessageHandler_JCalls_free(void* this_arg) {
3336         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3337         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
3338                 JNIEnv *env;
3339                 DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
3340                 (*env)->DeleteWeakGlobalRef(env, j_calls->o);
3341                 FREE(j_calls);
3342         }
3343 }
3344 static void* LDKChannelMessageHandler_JCalls_clone(const void* this_arg) {
3345         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3346         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
3347         atomic_fetch_add_explicit(&j_calls->MessageSendEventsProvider->refcnt, 1, memory_order_release);
3348         return (void*) this_arg;
3349 }
3350 static inline LDKChannelMessageHandler LDKChannelMessageHandler_init (JNIEnv * env, jclass _a, jobject o, jobject MessageSendEventsProvider) {
3351         jclass c = (*env)->GetObjectClass(env, o);
3352         CHECK(c != NULL);
3353         LDKChannelMessageHandler_JCalls *calls = MALLOC(sizeof(LDKChannelMessageHandler_JCalls), "LDKChannelMessageHandler_JCalls");
3354         atomic_init(&calls->refcnt, 1);
3355         DO_ASSERT((*env)->GetJavaVM(env, &calls->vm) == 0);
3356         calls->o = (*env)->NewWeakGlobalRef(env, o);
3357         calls->handle_open_channel_meth = (*env)->GetMethodID(env, c, "handle_open_channel", "([BJJ)V");
3358         CHECK(calls->handle_open_channel_meth != NULL);
3359         calls->handle_accept_channel_meth = (*env)->GetMethodID(env, c, "handle_accept_channel", "([BJJ)V");
3360         CHECK(calls->handle_accept_channel_meth != NULL);
3361         calls->handle_funding_created_meth = (*env)->GetMethodID(env, c, "handle_funding_created", "([BJ)V");
3362         CHECK(calls->handle_funding_created_meth != NULL);
3363         calls->handle_funding_signed_meth = (*env)->GetMethodID(env, c, "handle_funding_signed", "([BJ)V");
3364         CHECK(calls->handle_funding_signed_meth != NULL);
3365         calls->handle_funding_locked_meth = (*env)->GetMethodID(env, c, "handle_funding_locked", "([BJ)V");
3366         CHECK(calls->handle_funding_locked_meth != NULL);
3367         calls->handle_shutdown_meth = (*env)->GetMethodID(env, c, "handle_shutdown", "([BJ)V");
3368         CHECK(calls->handle_shutdown_meth != NULL);
3369         calls->handle_closing_signed_meth = (*env)->GetMethodID(env, c, "handle_closing_signed", "([BJ)V");
3370         CHECK(calls->handle_closing_signed_meth != NULL);
3371         calls->handle_update_add_htlc_meth = (*env)->GetMethodID(env, c, "handle_update_add_htlc", "([BJ)V");
3372         CHECK(calls->handle_update_add_htlc_meth != NULL);
3373         calls->handle_update_fulfill_htlc_meth = (*env)->GetMethodID(env, c, "handle_update_fulfill_htlc", "([BJ)V");
3374         CHECK(calls->handle_update_fulfill_htlc_meth != NULL);
3375         calls->handle_update_fail_htlc_meth = (*env)->GetMethodID(env, c, "handle_update_fail_htlc", "([BJ)V");
3376         CHECK(calls->handle_update_fail_htlc_meth != NULL);
3377         calls->handle_update_fail_malformed_htlc_meth = (*env)->GetMethodID(env, c, "handle_update_fail_malformed_htlc", "([BJ)V");
3378         CHECK(calls->handle_update_fail_malformed_htlc_meth != NULL);
3379         calls->handle_commitment_signed_meth = (*env)->GetMethodID(env, c, "handle_commitment_signed", "([BJ)V");
3380         CHECK(calls->handle_commitment_signed_meth != NULL);
3381         calls->handle_revoke_and_ack_meth = (*env)->GetMethodID(env, c, "handle_revoke_and_ack", "([BJ)V");
3382         CHECK(calls->handle_revoke_and_ack_meth != NULL);
3383         calls->handle_update_fee_meth = (*env)->GetMethodID(env, c, "handle_update_fee", "([BJ)V");
3384         CHECK(calls->handle_update_fee_meth != NULL);
3385         calls->handle_announcement_signatures_meth = (*env)->GetMethodID(env, c, "handle_announcement_signatures", "([BJ)V");
3386         CHECK(calls->handle_announcement_signatures_meth != NULL);
3387         calls->peer_disconnected_meth = (*env)->GetMethodID(env, c, "peer_disconnected", "([BZ)V");
3388         CHECK(calls->peer_disconnected_meth != NULL);
3389         calls->peer_connected_meth = (*env)->GetMethodID(env, c, "peer_connected", "([BJ)V");
3390         CHECK(calls->peer_connected_meth != NULL);
3391         calls->handle_channel_reestablish_meth = (*env)->GetMethodID(env, c, "handle_channel_reestablish", "([BJ)V");
3392         CHECK(calls->handle_channel_reestablish_meth != NULL);
3393         calls->handle_error_meth = (*env)->GetMethodID(env, c, "handle_error", "([BJ)V");
3394         CHECK(calls->handle_error_meth != NULL);
3395
3396         LDKChannelMessageHandler ret = {
3397                 .this_arg = (void*) calls,
3398                 .handle_open_channel = handle_open_channel_jcall,
3399                 .handle_accept_channel = handle_accept_channel_jcall,
3400                 .handle_funding_created = handle_funding_created_jcall,
3401                 .handle_funding_signed = handle_funding_signed_jcall,
3402                 .handle_funding_locked = handle_funding_locked_jcall,
3403                 .handle_shutdown = handle_shutdown_jcall,
3404                 .handle_closing_signed = handle_closing_signed_jcall,
3405                 .handle_update_add_htlc = handle_update_add_htlc_jcall,
3406                 .handle_update_fulfill_htlc = handle_update_fulfill_htlc_jcall,
3407                 .handle_update_fail_htlc = handle_update_fail_htlc_jcall,
3408                 .handle_update_fail_malformed_htlc = handle_update_fail_malformed_htlc_jcall,
3409                 .handle_commitment_signed = handle_commitment_signed_jcall,
3410                 .handle_revoke_and_ack = handle_revoke_and_ack_jcall,
3411                 .handle_update_fee = handle_update_fee_jcall,
3412                 .handle_announcement_signatures = handle_announcement_signatures_jcall,
3413                 .peer_disconnected = peer_disconnected_jcall,
3414                 .peer_connected = peer_connected_jcall,
3415                 .handle_channel_reestablish = handle_channel_reestablish_jcall,
3416                 .handle_error = handle_error_jcall,
3417                 .free = LDKChannelMessageHandler_JCalls_free,
3418                 .MessageSendEventsProvider = LDKMessageSendEventsProvider_init(env, _a, MessageSendEventsProvider),
3419         };
3420         calls->MessageSendEventsProvider = ret.MessageSendEventsProvider.this_arg;
3421         return ret;
3422 }
3423 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_LDKChannelMessageHandler_1new (JNIEnv * env, jclass _a, jobject o, jobject MessageSendEventsProvider) {
3424         LDKChannelMessageHandler *res_ptr = MALLOC(sizeof(LDKChannelMessageHandler), "LDKChannelMessageHandler");
3425         *res_ptr = LDKChannelMessageHandler_init(env, _a, o, MessageSendEventsProvider);
3426         return (long)res_ptr;
3427 }
3428 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKChannelMessageHandler_1get_1obj_1from_1jcalls (JNIEnv * env, jclass _a, jlong val) {
3429         jobject ret = (*env)->NewLocalRef(env, ((LDKChannelMessageHandler_JCalls*)val)->o);
3430         CHECK(ret != NULL);
3431         return ret;
3432 }
3433 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) {
3434         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
3435         LDKPublicKey their_node_id_ref;
3436         CHECK((*_env)->GetArrayLength (_env, their_node_id) == 33);
3437         (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
3438         LDKInitFeatures their_features_conv;
3439         their_features_conv.inner = (void*)(their_features & (~1));
3440         their_features_conv.is_owned = (their_features & 1) || (their_features == 0);
3441         // Warning: we may need a move here but can't clone!
3442         LDKOpenChannel msg_conv;
3443         msg_conv.inner = (void*)(msg & (~1));
3444         msg_conv.is_owned = (msg & 1) || (msg == 0);
3445         (this_arg_conv->handle_open_channel)(this_arg_conv->this_arg, their_node_id_ref, their_features_conv, &msg_conv);
3446 }
3447
3448 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) {
3449         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
3450         LDKPublicKey their_node_id_ref;
3451         CHECK((*_env)->GetArrayLength (_env, their_node_id) == 33);
3452         (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
3453         LDKInitFeatures their_features_conv;
3454         their_features_conv.inner = (void*)(their_features & (~1));
3455         their_features_conv.is_owned = (their_features & 1) || (their_features == 0);
3456         // Warning: we may need a move here but can't clone!
3457         LDKAcceptChannel msg_conv;
3458         msg_conv.inner = (void*)(msg & (~1));
3459         msg_conv.is_owned = (msg & 1) || (msg == 0);
3460         (this_arg_conv->handle_accept_channel)(this_arg_conv->this_arg, their_node_id_ref, their_features_conv, &msg_conv);
3461 }
3462
3463 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) {
3464         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
3465         LDKPublicKey their_node_id_ref;
3466         CHECK((*_env)->GetArrayLength (_env, their_node_id) == 33);
3467         (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
3468         LDKFundingCreated msg_conv;
3469         msg_conv.inner = (void*)(msg & (~1));
3470         msg_conv.is_owned = (msg & 1) || (msg == 0);
3471         (this_arg_conv->handle_funding_created)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
3472 }
3473
3474 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) {
3475         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
3476         LDKPublicKey their_node_id_ref;
3477         CHECK((*_env)->GetArrayLength (_env, their_node_id) == 33);
3478         (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
3479         LDKFundingSigned msg_conv;
3480         msg_conv.inner = (void*)(msg & (~1));
3481         msg_conv.is_owned = (msg & 1) || (msg == 0);
3482         (this_arg_conv->handle_funding_signed)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
3483 }
3484
3485 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) {
3486         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
3487         LDKPublicKey their_node_id_ref;
3488         CHECK((*_env)->GetArrayLength (_env, their_node_id) == 33);
3489         (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
3490         LDKFundingLocked msg_conv;
3491         msg_conv.inner = (void*)(msg & (~1));
3492         msg_conv.is_owned = (msg & 1) || (msg == 0);
3493         (this_arg_conv->handle_funding_locked)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
3494 }
3495
3496 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelMessageHandler_1handle_1shutdown(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray their_node_id, jlong msg) {
3497         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
3498         LDKPublicKey their_node_id_ref;
3499         CHECK((*_env)->GetArrayLength (_env, their_node_id) == 33);
3500         (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
3501         LDKShutdown msg_conv;
3502         msg_conv.inner = (void*)(msg & (~1));
3503         msg_conv.is_owned = (msg & 1) || (msg == 0);
3504         (this_arg_conv->handle_shutdown)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
3505 }
3506
3507 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) {
3508         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
3509         LDKPublicKey their_node_id_ref;
3510         CHECK((*_env)->GetArrayLength (_env, their_node_id) == 33);
3511         (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
3512         LDKClosingSigned msg_conv;
3513         msg_conv.inner = (void*)(msg & (~1));
3514         msg_conv.is_owned = (msg & 1) || (msg == 0);
3515         (this_arg_conv->handle_closing_signed)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
3516 }
3517
3518 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) {
3519         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
3520         LDKPublicKey their_node_id_ref;
3521         CHECK((*_env)->GetArrayLength (_env, their_node_id) == 33);
3522         (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
3523         LDKUpdateAddHTLC msg_conv;
3524         msg_conv.inner = (void*)(msg & (~1));
3525         msg_conv.is_owned = (msg & 1) || (msg == 0);
3526         (this_arg_conv->handle_update_add_htlc)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
3527 }
3528
3529 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) {
3530         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
3531         LDKPublicKey their_node_id_ref;
3532         CHECK((*_env)->GetArrayLength (_env, their_node_id) == 33);
3533         (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
3534         LDKUpdateFulfillHTLC msg_conv;
3535         msg_conv.inner = (void*)(msg & (~1));
3536         msg_conv.is_owned = (msg & 1) || (msg == 0);
3537         (this_arg_conv->handle_update_fulfill_htlc)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
3538 }
3539
3540 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) {
3541         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
3542         LDKPublicKey their_node_id_ref;
3543         CHECK((*_env)->GetArrayLength (_env, their_node_id) == 33);
3544         (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
3545         LDKUpdateFailHTLC msg_conv;
3546         msg_conv.inner = (void*)(msg & (~1));
3547         msg_conv.is_owned = (msg & 1) || (msg == 0);
3548         (this_arg_conv->handle_update_fail_htlc)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
3549 }
3550
3551 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) {
3552         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
3553         LDKPublicKey their_node_id_ref;
3554         CHECK((*_env)->GetArrayLength (_env, their_node_id) == 33);
3555         (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
3556         LDKUpdateFailMalformedHTLC msg_conv;
3557         msg_conv.inner = (void*)(msg & (~1));
3558         msg_conv.is_owned = (msg & 1) || (msg == 0);
3559         (this_arg_conv->handle_update_fail_malformed_htlc)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
3560 }
3561
3562 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) {
3563         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
3564         LDKPublicKey their_node_id_ref;
3565         CHECK((*_env)->GetArrayLength (_env, their_node_id) == 33);
3566         (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
3567         LDKCommitmentSigned msg_conv;
3568         msg_conv.inner = (void*)(msg & (~1));
3569         msg_conv.is_owned = (msg & 1) || (msg == 0);
3570         (this_arg_conv->handle_commitment_signed)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
3571 }
3572
3573 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) {
3574         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
3575         LDKPublicKey their_node_id_ref;
3576         CHECK((*_env)->GetArrayLength (_env, their_node_id) == 33);
3577         (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
3578         LDKRevokeAndACK msg_conv;
3579         msg_conv.inner = (void*)(msg & (~1));
3580         msg_conv.is_owned = (msg & 1) || (msg == 0);
3581         (this_arg_conv->handle_revoke_and_ack)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
3582 }
3583
3584 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) {
3585         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
3586         LDKPublicKey their_node_id_ref;
3587         CHECK((*_env)->GetArrayLength (_env, their_node_id) == 33);
3588         (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
3589         LDKUpdateFee msg_conv;
3590         msg_conv.inner = (void*)(msg & (~1));
3591         msg_conv.is_owned = (msg & 1) || (msg == 0);
3592         (this_arg_conv->handle_update_fee)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
3593 }
3594
3595 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) {
3596         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
3597         LDKPublicKey their_node_id_ref;
3598         CHECK((*_env)->GetArrayLength (_env, their_node_id) == 33);
3599         (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
3600         LDKAnnouncementSignatures msg_conv;
3601         msg_conv.inner = (void*)(msg & (~1));
3602         msg_conv.is_owned = (msg & 1) || (msg == 0);
3603         (this_arg_conv->handle_announcement_signatures)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
3604 }
3605
3606 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) {
3607         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
3608         LDKPublicKey their_node_id_ref;
3609         CHECK((*_env)->GetArrayLength (_env, their_node_id) == 33);
3610         (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
3611         (this_arg_conv->peer_disconnected)(this_arg_conv->this_arg, their_node_id_ref, no_connection_possible);
3612 }
3613
3614 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelMessageHandler_1peer_1connected(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray their_node_id, jlong msg) {
3615         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
3616         LDKPublicKey their_node_id_ref;
3617         CHECK((*_env)->GetArrayLength (_env, their_node_id) == 33);
3618         (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
3619         LDKInit msg_conv;
3620         msg_conv.inner = (void*)(msg & (~1));
3621         msg_conv.is_owned = (msg & 1) || (msg == 0);
3622         (this_arg_conv->peer_connected)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
3623 }
3624
3625 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) {
3626         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
3627         LDKPublicKey their_node_id_ref;
3628         CHECK((*_env)->GetArrayLength (_env, their_node_id) == 33);
3629         (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
3630         LDKChannelReestablish msg_conv;
3631         msg_conv.inner = (void*)(msg & (~1));
3632         msg_conv.is_owned = (msg & 1) || (msg == 0);
3633         (this_arg_conv->handle_channel_reestablish)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
3634 }
3635
3636 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelMessageHandler_1handle_1error(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray their_node_id, jlong msg) {
3637         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
3638         LDKPublicKey their_node_id_ref;
3639         CHECK((*_env)->GetArrayLength (_env, their_node_id) == 33);
3640         (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
3641         LDKErrorMessage msg_conv;
3642         msg_conv.inner = (void*)(msg & (~1));
3643         msg_conv.is_owned = (msg & 1) || (msg == 0);
3644         (this_arg_conv->handle_error)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
3645 }
3646
3647 JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1ChannelMonitor_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
3648         LDKCVecTempl_ChannelMonitor *vec = (LDKCVecTempl_ChannelMonitor*)ptr;
3649         jlongArray ret = (*env)->NewLongArray(env, vec->datalen);
3650         jlong *ret_elems = (*env)->GetPrimitiveArrayCritical(env, ret, NULL);
3651         for (size_t i = 0; i < vec->datalen; i++) {
3652                 CHECK((((long)vec->data[i].inner) & 1) == 0);
3653                 ret_elems[i] = (long)vec->data[i].inner | (vec->data[i].is_owned ? 1 : 0);
3654         }
3655         (*env)->ReleasePrimitiveArrayCritical(env, ret, ret_elems, 0);
3656         return ret;
3657 }
3658 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1ChannelMonitor_1new(JNIEnv *env, jclass _b, jlongArray elems){
3659         LDKCVecTempl_ChannelMonitor *ret = MALLOC(sizeof(LDKCVecTempl_ChannelMonitor), "LDKCVecTempl_ChannelMonitor");
3660         ret->datalen = (*env)->GetArrayLength(env, elems);
3661         if (ret->datalen == 0) {
3662                 ret->data = NULL;
3663         } else {
3664                 ret->data = MALLOC(sizeof(LDKChannelMonitor) * ret->datalen, "LDKCVecTempl_ChannelMonitor Data");
3665                 jlong *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
3666                 for (size_t i = 0; i < ret->datalen; i++) {
3667                         jlong arr_elem = java_elems[i];
3668                         LDKChannelMonitor arr_elem_conv;
3669                         arr_elem_conv.inner = (void*)(arr_elem & (~1));
3670                         arr_elem_conv.is_owned = (arr_elem & 1) || (arr_elem == 0);
3671                         // Warning: we may need a move here but can't clone!
3672                         ret->data[i] = arr_elem_conv;
3673                 }
3674                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
3675         }
3676         return (long)ret;
3677 }
3678 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1u64_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
3679         LDKCVecTempl_u64 *vec = (LDKCVecTempl_u64*)ptr;
3680         return (*env)->NewObject(env, slicedef_cls, slicedef_meth, (long)vec->data, (long)vec->datalen, sizeof(uint64_t));
3681 }
3682 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1u64_1new(JNIEnv *env, jclass _b, jlongArray elems){
3683         LDKCVecTempl_u64 *ret = MALLOC(sizeof(LDKCVecTempl_u64), "LDKCVecTempl_u64");
3684         ret->datalen = (*env)->GetArrayLength(env, elems);
3685         if (ret->datalen == 0) {
3686                 ret->data = NULL;
3687         } else {
3688                 ret->data = MALLOC(sizeof(uint64_t) * ret->datalen, "LDKCVecTempl_u64 Data");
3689                 jlong *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
3690                 for (size_t i = 0; i < ret->datalen; i++) {
3691                         ret->data[i] = java_elems[i];
3692                 }
3693                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
3694         }
3695         return (long)ret;
3696 }
3697 JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1UpdateAddHTLC_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
3698         LDKCVecTempl_UpdateAddHTLC *vec = (LDKCVecTempl_UpdateAddHTLC*)ptr;
3699         jlongArray ret = (*env)->NewLongArray(env, vec->datalen);
3700         jlong *ret_elems = (*env)->GetPrimitiveArrayCritical(env, ret, NULL);
3701         for (size_t i = 0; i < vec->datalen; i++) {
3702                 CHECK((((long)vec->data[i].inner) & 1) == 0);
3703                 ret_elems[i] = (long)vec->data[i].inner | (vec->data[i].is_owned ? 1 : 0);
3704         }
3705         (*env)->ReleasePrimitiveArrayCritical(env, ret, ret_elems, 0);
3706         return ret;
3707 }
3708 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1UpdateAddHTLC_1new(JNIEnv *env, jclass _b, jlongArray elems){
3709         LDKCVecTempl_UpdateAddHTLC *ret = MALLOC(sizeof(LDKCVecTempl_UpdateAddHTLC), "LDKCVecTempl_UpdateAddHTLC");
3710         ret->datalen = (*env)->GetArrayLength(env, elems);
3711         if (ret->datalen == 0) {
3712                 ret->data = NULL;
3713         } else {
3714                 ret->data = MALLOC(sizeof(LDKUpdateAddHTLC) * ret->datalen, "LDKCVecTempl_UpdateAddHTLC Data");
3715                 jlong *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
3716                 for (size_t i = 0; i < ret->datalen; i++) {
3717                         jlong arr_elem = java_elems[i];
3718                         LDKUpdateAddHTLC arr_elem_conv;
3719                         arr_elem_conv.inner = (void*)(arr_elem & (~1));
3720                         arr_elem_conv.is_owned = (arr_elem & 1) || (arr_elem == 0);
3721                         if (arr_elem_conv.inner != NULL)
3722                                 arr_elem_conv = UpdateAddHTLC_clone(&arr_elem_conv);
3723                         ret->data[i] = arr_elem_conv;
3724                 }
3725                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
3726         }
3727         return (long)ret;
3728 }
3729 JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1UpdateFulfillHTLC_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
3730         LDKCVecTempl_UpdateFulfillHTLC *vec = (LDKCVecTempl_UpdateFulfillHTLC*)ptr;
3731         jlongArray ret = (*env)->NewLongArray(env, vec->datalen);
3732         jlong *ret_elems = (*env)->GetPrimitiveArrayCritical(env, ret, NULL);
3733         for (size_t i = 0; i < vec->datalen; i++) {
3734                 CHECK((((long)vec->data[i].inner) & 1) == 0);
3735                 ret_elems[i] = (long)vec->data[i].inner | (vec->data[i].is_owned ? 1 : 0);
3736         }
3737         (*env)->ReleasePrimitiveArrayCritical(env, ret, ret_elems, 0);
3738         return ret;
3739 }
3740 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1UpdateFulfillHTLC_1new(JNIEnv *env, jclass _b, jlongArray elems){
3741         LDKCVecTempl_UpdateFulfillHTLC *ret = MALLOC(sizeof(LDKCVecTempl_UpdateFulfillHTLC), "LDKCVecTempl_UpdateFulfillHTLC");
3742         ret->datalen = (*env)->GetArrayLength(env, elems);
3743         if (ret->datalen == 0) {
3744                 ret->data = NULL;
3745         } else {
3746                 ret->data = MALLOC(sizeof(LDKUpdateFulfillHTLC) * ret->datalen, "LDKCVecTempl_UpdateFulfillHTLC Data");
3747                 jlong *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
3748                 for (size_t i = 0; i < ret->datalen; i++) {
3749                         jlong arr_elem = java_elems[i];
3750                         LDKUpdateFulfillHTLC arr_elem_conv;
3751                         arr_elem_conv.inner = (void*)(arr_elem & (~1));
3752                         arr_elem_conv.is_owned = (arr_elem & 1) || (arr_elem == 0);
3753                         if (arr_elem_conv.inner != NULL)
3754                                 arr_elem_conv = UpdateFulfillHTLC_clone(&arr_elem_conv);
3755                         ret->data[i] = arr_elem_conv;
3756                 }
3757                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
3758         }
3759         return (long)ret;
3760 }
3761 JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1UpdateFailHTLC_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
3762         LDKCVecTempl_UpdateFailHTLC *vec = (LDKCVecTempl_UpdateFailHTLC*)ptr;
3763         jlongArray ret = (*env)->NewLongArray(env, vec->datalen);
3764         jlong *ret_elems = (*env)->GetPrimitiveArrayCritical(env, ret, NULL);
3765         for (size_t i = 0; i < vec->datalen; i++) {
3766                 CHECK((((long)vec->data[i].inner) & 1) == 0);
3767                 ret_elems[i] = (long)vec->data[i].inner | (vec->data[i].is_owned ? 1 : 0);
3768         }
3769         (*env)->ReleasePrimitiveArrayCritical(env, ret, ret_elems, 0);
3770         return ret;
3771 }
3772 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1UpdateFailHTLC_1new(JNIEnv *env, jclass _b, jlongArray elems){
3773         LDKCVecTempl_UpdateFailHTLC *ret = MALLOC(sizeof(LDKCVecTempl_UpdateFailHTLC), "LDKCVecTempl_UpdateFailHTLC");
3774         ret->datalen = (*env)->GetArrayLength(env, elems);
3775         if (ret->datalen == 0) {
3776                 ret->data = NULL;
3777         } else {
3778                 ret->data = MALLOC(sizeof(LDKUpdateFailHTLC) * ret->datalen, "LDKCVecTempl_UpdateFailHTLC Data");
3779                 jlong *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
3780                 for (size_t i = 0; i < ret->datalen; i++) {
3781                         jlong arr_elem = java_elems[i];
3782                         LDKUpdateFailHTLC arr_elem_conv;
3783                         arr_elem_conv.inner = (void*)(arr_elem & (~1));
3784                         arr_elem_conv.is_owned = (arr_elem & 1) || (arr_elem == 0);
3785                         if (arr_elem_conv.inner != NULL)
3786                                 arr_elem_conv = UpdateFailHTLC_clone(&arr_elem_conv);
3787                         ret->data[i] = arr_elem_conv;
3788                 }
3789                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
3790         }
3791         return (long)ret;
3792 }
3793 JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1UpdateFailMalformedHTLC_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
3794         LDKCVecTempl_UpdateFailMalformedHTLC *vec = (LDKCVecTempl_UpdateFailMalformedHTLC*)ptr;
3795         jlongArray ret = (*env)->NewLongArray(env, vec->datalen);
3796         jlong *ret_elems = (*env)->GetPrimitiveArrayCritical(env, ret, NULL);
3797         for (size_t i = 0; i < vec->datalen; i++) {
3798                 CHECK((((long)vec->data[i].inner) & 1) == 0);
3799                 ret_elems[i] = (long)vec->data[i].inner | (vec->data[i].is_owned ? 1 : 0);
3800         }
3801         (*env)->ReleasePrimitiveArrayCritical(env, ret, ret_elems, 0);
3802         return ret;
3803 }
3804 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1UpdateFailMalformedHTLC_1new(JNIEnv *env, jclass _b, jlongArray elems){
3805         LDKCVecTempl_UpdateFailMalformedHTLC *ret = MALLOC(sizeof(LDKCVecTempl_UpdateFailMalformedHTLC), "LDKCVecTempl_UpdateFailMalformedHTLC");
3806         ret->datalen = (*env)->GetArrayLength(env, elems);
3807         if (ret->datalen == 0) {
3808                 ret->data = NULL;
3809         } else {
3810                 ret->data = MALLOC(sizeof(LDKUpdateFailMalformedHTLC) * ret->datalen, "LDKCVecTempl_UpdateFailMalformedHTLC Data");
3811                 jlong *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
3812                 for (size_t i = 0; i < ret->datalen; i++) {
3813                         jlong arr_elem = java_elems[i];
3814                         LDKUpdateFailMalformedHTLC arr_elem_conv;
3815                         arr_elem_conv.inner = (void*)(arr_elem & (~1));
3816                         arr_elem_conv.is_owned = (arr_elem & 1) || (arr_elem == 0);
3817                         if (arr_elem_conv.inner != NULL)
3818                                 arr_elem_conv = UpdateFailMalformedHTLC_clone(&arr_elem_conv);
3819                         ret->data[i] = arr_elem_conv;
3820                 }
3821                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
3822         }
3823         return (long)ret;
3824 }
3825 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1boolLightningErrorZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
3826         return ((LDKCResult_boolLightningErrorZ*)arg)->result_ok;
3827 }
3828 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1boolLightningErrorZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
3829         LDKCResult_boolLightningErrorZ *val = (LDKCResult_boolLightningErrorZ*)arg;
3830         CHECK(val->result_ok);
3831         return *val->contents.result;
3832 }
3833 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1boolLightningErrorZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
3834         LDKCResult_boolLightningErrorZ *val = (LDKCResult_boolLightningErrorZ*)arg;
3835         CHECK(!val->result_ok);
3836         LDKLightningError err_var = (*val->contents.err);
3837         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3838         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3839         long err_ref = (long)err_var.inner & ~1;
3840         return err_ref;
3841 }
3842 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1C3TupleTempl_1ChannelAnnouncement_1_1ChannelUpdate_1_1ChannelUpdate_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
3843         LDKCVecTempl_C3TupleTempl_ChannelAnnouncement__ChannelUpdate__ChannelUpdate *vec = (LDKCVecTempl_C3TupleTempl_ChannelAnnouncement__ChannelUpdate__ChannelUpdate*)ptr;
3844         return (*env)->NewObject(env, slicedef_cls, slicedef_meth, (long)vec->data, (long)vec->datalen, sizeof(LDKC3TupleTempl_ChannelAnnouncement__ChannelUpdate__ChannelUpdate));
3845 }
3846 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1C3TupleTempl_1ChannelAnnouncement_1_1ChannelUpdate_1_1ChannelUpdate_1new(JNIEnv *env, jclass _b, jlongArray elems){
3847         LDKCVecTempl_C3TupleTempl_ChannelAnnouncement__ChannelUpdate__ChannelUpdate *ret = MALLOC(sizeof(LDKCVecTempl_C3TupleTempl_ChannelAnnouncement__ChannelUpdate__ChannelUpdate), "LDKCVecTempl_C3TupleTempl_ChannelAnnouncement__ChannelUpdate__ChannelUpdate");
3848         ret->datalen = (*env)->GetArrayLength(env, elems);
3849         if (ret->datalen == 0) {
3850                 ret->data = NULL;
3851         } else {
3852                 ret->data = MALLOC(sizeof(LDKC3TupleTempl_ChannelAnnouncement__ChannelUpdate__ChannelUpdate) * ret->datalen, "LDKCVecTempl_C3TupleTempl_ChannelAnnouncement__ChannelUpdate__ChannelUpdate Data");
3853                 jlong *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
3854                 for (size_t i = 0; i < ret->datalen; i++) {
3855                         jlong arr_elem = java_elems[i];
3856                         LDKC3TupleTempl_ChannelAnnouncement__ChannelUpdate__ChannelUpdate arr_elem_conv = *(LDKC3TupleTempl_ChannelAnnouncement__ChannelUpdate__ChannelUpdate*)arr_elem;
3857                         FREE((void*)arr_elem);
3858                         ret->data[i] = arr_elem_conv;
3859                 }
3860                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
3861         }
3862         return (long)ret;
3863 }
3864 JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1NodeAnnouncement_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
3865         LDKCVecTempl_NodeAnnouncement *vec = (LDKCVecTempl_NodeAnnouncement*)ptr;
3866         jlongArray ret = (*env)->NewLongArray(env, vec->datalen);
3867         jlong *ret_elems = (*env)->GetPrimitiveArrayCritical(env, ret, NULL);
3868         for (size_t i = 0; i < vec->datalen; i++) {
3869                 CHECK((((long)vec->data[i].inner) & 1) == 0);
3870                 ret_elems[i] = (long)vec->data[i].inner | (vec->data[i].is_owned ? 1 : 0);
3871         }
3872         (*env)->ReleasePrimitiveArrayCritical(env, ret, ret_elems, 0);
3873         return ret;
3874 }
3875 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1NodeAnnouncement_1new(JNIEnv *env, jclass _b, jlongArray elems){
3876         LDKCVecTempl_NodeAnnouncement *ret = MALLOC(sizeof(LDKCVecTempl_NodeAnnouncement), "LDKCVecTempl_NodeAnnouncement");
3877         ret->datalen = (*env)->GetArrayLength(env, elems);
3878         if (ret->datalen == 0) {
3879                 ret->data = NULL;
3880         } else {
3881                 ret->data = MALLOC(sizeof(LDKNodeAnnouncement) * ret->datalen, "LDKCVecTempl_NodeAnnouncement Data");
3882                 jlong *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
3883                 for (size_t i = 0; i < ret->datalen; i++) {
3884                         jlong arr_elem = java_elems[i];
3885                         LDKNodeAnnouncement arr_elem_conv;
3886                         arr_elem_conv.inner = (void*)(arr_elem & (~1));
3887                         arr_elem_conv.is_owned = (arr_elem & 1) || (arr_elem == 0);
3888                         if (arr_elem_conv.inner != NULL)
3889                                 arr_elem_conv = NodeAnnouncement_clone(&arr_elem_conv);
3890                         ret->data[i] = arr_elem_conv;
3891                 }
3892                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
3893         }
3894         return (long)ret;
3895 }
3896 typedef struct LDKRoutingMessageHandler_JCalls {
3897         atomic_size_t refcnt;
3898         JavaVM *vm;
3899         jweak o;
3900         jmethodID handle_node_announcement_meth;
3901         jmethodID handle_channel_announcement_meth;
3902         jmethodID handle_channel_update_meth;
3903         jmethodID handle_htlc_fail_channel_update_meth;
3904         jmethodID get_next_channel_announcements_meth;
3905         jmethodID get_next_node_announcements_meth;
3906         jmethodID should_request_full_sync_meth;
3907 } LDKRoutingMessageHandler_JCalls;
3908 LDKCResult_boolLightningErrorZ handle_node_announcement_jcall(const void* this_arg, const LDKNodeAnnouncement *msg) {
3909         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
3910         JNIEnv *_env;
3911         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
3912         LDKNodeAnnouncement msg_var = *msg;
3913         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3914         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3915         long msg_ref = (long)msg_var.inner & ~1;
3916         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
3917         CHECK(obj != NULL);
3918         LDKCResult_boolLightningErrorZ* ret = (LDKCResult_boolLightningErrorZ*)(*_env)->CallLongMethod(_env, obj, j_calls->handle_node_announcement_meth, msg_ref);
3919         LDKCResult_boolLightningErrorZ ret_conv = *(LDKCResult_boolLightningErrorZ*)ret;
3920         FREE((void*)ret);
3921         return ret_conv;
3922 }
3923 LDKCResult_boolLightningErrorZ handle_channel_announcement_jcall(const void* this_arg, const LDKChannelAnnouncement *msg) {
3924         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
3925         JNIEnv *_env;
3926         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
3927         LDKChannelAnnouncement msg_var = *msg;
3928         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3929         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3930         long msg_ref = (long)msg_var.inner & ~1;
3931         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
3932         CHECK(obj != NULL);
3933         LDKCResult_boolLightningErrorZ* ret = (LDKCResult_boolLightningErrorZ*)(*_env)->CallLongMethod(_env, obj, j_calls->handle_channel_announcement_meth, msg_ref);
3934         LDKCResult_boolLightningErrorZ ret_conv = *(LDKCResult_boolLightningErrorZ*)ret;
3935         FREE((void*)ret);
3936         return ret_conv;
3937 }
3938 LDKCResult_boolLightningErrorZ handle_channel_update_jcall(const void* this_arg, const LDKChannelUpdate *msg) {
3939         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
3940         JNIEnv *_env;
3941         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
3942         LDKChannelUpdate msg_var = *msg;
3943         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3944         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3945         long msg_ref = (long)msg_var.inner & ~1;
3946         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
3947         CHECK(obj != NULL);
3948         LDKCResult_boolLightningErrorZ* ret = (LDKCResult_boolLightningErrorZ*)(*_env)->CallLongMethod(_env, obj, j_calls->handle_channel_update_meth, msg_ref);
3949         LDKCResult_boolLightningErrorZ ret_conv = *(LDKCResult_boolLightningErrorZ*)ret;
3950         FREE((void*)ret);
3951         return ret_conv;
3952 }
3953 void handle_htlc_fail_channel_update_jcall(const void* this_arg, const LDKHTLCFailChannelUpdate *update) {
3954         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
3955         JNIEnv *_env;
3956         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
3957         long ret_update = (long)update;
3958         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
3959         CHECK(obj != NULL);
3960         return (*_env)->CallVoidMethod(_env, obj, j_calls->handle_htlc_fail_channel_update_meth, ret_update);
3961 }
3962 LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ get_next_channel_announcements_jcall(const void* this_arg, uint64_t starting_point, uint8_t batch_amount) {
3963         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
3964         JNIEnv *_env;
3965         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
3966         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
3967         CHECK(obj != NULL);
3968         jlongArray arg = (*_env)->CallObjectMethod(_env, obj, j_calls->get_next_channel_announcements_meth, starting_point, batch_amount);
3969         LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ arg_constr;
3970         arg_constr.datalen = (*_env)->GetArrayLength (_env, arg);
3971         if (arg_constr.datalen > 0)
3972                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ), "LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ Elements");
3973         else
3974                 arg_constr.data = NULL;
3975         long* arg_vals = (*_env)->GetLongArrayElements (_env, arg, NULL);
3976         for (size_t l = 0; l < arg_constr.datalen; l++) {
3977                 long arr_conv_63 = arg_vals[l];
3978                 LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ arr_conv_63_conv = *(LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ*)arr_conv_63;
3979                 FREE((void*)arr_conv_63);
3980                 arg_constr.data[l] = arr_conv_63_conv;
3981         }
3982         (*_env)->ReleaseLongArrayElements (_env, arg, arg_vals, 0);
3983         return arg_constr;
3984 }
3985 LDKCVec_NodeAnnouncementZ get_next_node_announcements_jcall(const void* this_arg, LDKPublicKey starting_point, uint8_t batch_amount) {
3986         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
3987         JNIEnv *_env;
3988         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
3989         jbyteArray starting_point_arr = (*_env)->NewByteArray(_env, 33);
3990         (*_env)->SetByteArrayRegion(_env, starting_point_arr, 0, 33, starting_point.compressed_form);
3991         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
3992         CHECK(obj != NULL);
3993         jlongArray arg = (*_env)->CallObjectMethod(_env, obj, j_calls->get_next_node_announcements_meth, starting_point_arr, batch_amount);
3994         LDKCVec_NodeAnnouncementZ arg_constr;
3995         arg_constr.datalen = (*_env)->GetArrayLength (_env, arg);
3996         if (arg_constr.datalen > 0)
3997                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKNodeAnnouncement), "LDKCVec_NodeAnnouncementZ Elements");
3998         else
3999                 arg_constr.data = NULL;
4000         long* arg_vals = (*_env)->GetLongArrayElements (_env, arg, NULL);
4001         for (size_t s = 0; s < arg_constr.datalen; s++) {
4002                 long arr_conv_18 = arg_vals[s];
4003                 LDKNodeAnnouncement arr_conv_18_conv;
4004                 arr_conv_18_conv.inner = (void*)(arr_conv_18 & (~1));
4005                 arr_conv_18_conv.is_owned = (arr_conv_18 & 1) || (arr_conv_18 == 0);
4006                 if (arr_conv_18_conv.inner != NULL)
4007                         arr_conv_18_conv = NodeAnnouncement_clone(&arr_conv_18_conv);
4008                 arg_constr.data[s] = arr_conv_18_conv;
4009         }
4010         (*_env)->ReleaseLongArrayElements (_env, arg, arg_vals, 0);
4011         return arg_constr;
4012 }
4013 bool should_request_full_sync_jcall(const void* this_arg, LDKPublicKey node_id) {
4014         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
4015         JNIEnv *_env;
4016         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
4017         jbyteArray node_id_arr = (*_env)->NewByteArray(_env, 33);
4018         (*_env)->SetByteArrayRegion(_env, node_id_arr, 0, 33, node_id.compressed_form);
4019         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
4020         CHECK(obj != NULL);
4021         return (*_env)->CallBooleanMethod(_env, obj, j_calls->should_request_full_sync_meth, node_id_arr);
4022 }
4023 static void LDKRoutingMessageHandler_JCalls_free(void* this_arg) {
4024         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_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* LDKRoutingMessageHandler_JCalls_clone(const void* this_arg) {
4033         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
4034         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
4035         return (void*) this_arg;
4036 }
4037 static inline LDKRoutingMessageHandler LDKRoutingMessageHandler_init (JNIEnv * env, jclass _a, jobject o) {
4038         jclass c = (*env)->GetObjectClass(env, o);
4039         CHECK(c != NULL);
4040         LDKRoutingMessageHandler_JCalls *calls = MALLOC(sizeof(LDKRoutingMessageHandler_JCalls), "LDKRoutingMessageHandler_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->handle_node_announcement_meth = (*env)->GetMethodID(env, c, "handle_node_announcement", "(J)J");
4045         CHECK(calls->handle_node_announcement_meth != NULL);
4046         calls->handle_channel_announcement_meth = (*env)->GetMethodID(env, c, "handle_channel_announcement", "(J)J");
4047         CHECK(calls->handle_channel_announcement_meth != NULL);
4048         calls->handle_channel_update_meth = (*env)->GetMethodID(env, c, "handle_channel_update", "(J)J");
4049         CHECK(calls->handle_channel_update_meth != NULL);
4050         calls->handle_htlc_fail_channel_update_meth = (*env)->GetMethodID(env, c, "handle_htlc_fail_channel_update", "(J)V");
4051         CHECK(calls->handle_htlc_fail_channel_update_meth != NULL);
4052         calls->get_next_channel_announcements_meth = (*env)->GetMethodID(env, c, "get_next_channel_announcements", "(JB)[J");
4053         CHECK(calls->get_next_channel_announcements_meth != NULL);
4054         calls->get_next_node_announcements_meth = (*env)->GetMethodID(env, c, "get_next_node_announcements", "([BB)[J");
4055         CHECK(calls->get_next_node_announcements_meth != NULL);
4056         calls->should_request_full_sync_meth = (*env)->GetMethodID(env, c, "should_request_full_sync", "([B)Z");
4057         CHECK(calls->should_request_full_sync_meth != NULL);
4058
4059         LDKRoutingMessageHandler ret = {
4060                 .this_arg = (void*) calls,
4061                 .handle_node_announcement = handle_node_announcement_jcall,
4062                 .handle_channel_announcement = handle_channel_announcement_jcall,
4063                 .handle_channel_update = handle_channel_update_jcall,
4064                 .handle_htlc_fail_channel_update = handle_htlc_fail_channel_update_jcall,
4065                 .get_next_channel_announcements = get_next_channel_announcements_jcall,
4066                 .get_next_node_announcements = get_next_node_announcements_jcall,
4067                 .should_request_full_sync = should_request_full_sync_jcall,
4068                 .free = LDKRoutingMessageHandler_JCalls_free,
4069         };
4070         return ret;
4071 }
4072 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_LDKRoutingMessageHandler_1new (JNIEnv * env, jclass _a, jobject o) {
4073         LDKRoutingMessageHandler *res_ptr = MALLOC(sizeof(LDKRoutingMessageHandler), "LDKRoutingMessageHandler");
4074         *res_ptr = LDKRoutingMessageHandler_init(env, _a, o);
4075         return (long)res_ptr;
4076 }
4077 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKRoutingMessageHandler_1get_1obj_1from_1jcalls (JNIEnv * env, jclass _a, jlong val) {
4078         jobject ret = (*env)->NewLocalRef(env, ((LDKRoutingMessageHandler_JCalls*)val)->o);
4079         CHECK(ret != NULL);
4080         return ret;
4081 }
4082 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_RoutingMessageHandler_1handle_1node_1announcement(JNIEnv * _env, jclass _b, jlong this_arg, jlong msg) {
4083         LDKRoutingMessageHandler* this_arg_conv = (LDKRoutingMessageHandler*)this_arg;
4084         LDKNodeAnnouncement msg_conv;
4085         msg_conv.inner = (void*)(msg & (~1));
4086         msg_conv.is_owned = (msg & 1) || (msg == 0);
4087         LDKCResult_boolLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_boolLightningErrorZ), "LDKCResult_boolLightningErrorZ");
4088         *ret_conv = (this_arg_conv->handle_node_announcement)(this_arg_conv->this_arg, &msg_conv);
4089         return (long)ret_conv;
4090 }
4091
4092 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_RoutingMessageHandler_1handle_1channel_1announcement(JNIEnv * _env, jclass _b, jlong this_arg, jlong msg) {
4093         LDKRoutingMessageHandler* this_arg_conv = (LDKRoutingMessageHandler*)this_arg;
4094         LDKChannelAnnouncement msg_conv;
4095         msg_conv.inner = (void*)(msg & (~1));
4096         msg_conv.is_owned = (msg & 1) || (msg == 0);
4097         LDKCResult_boolLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_boolLightningErrorZ), "LDKCResult_boolLightningErrorZ");
4098         *ret_conv = (this_arg_conv->handle_channel_announcement)(this_arg_conv->this_arg, &msg_conv);
4099         return (long)ret_conv;
4100 }
4101
4102 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_RoutingMessageHandler_1handle_1channel_1update(JNIEnv * _env, jclass _b, jlong this_arg, jlong msg) {
4103         LDKRoutingMessageHandler* this_arg_conv = (LDKRoutingMessageHandler*)this_arg;
4104         LDKChannelUpdate msg_conv;
4105         msg_conv.inner = (void*)(msg & (~1));
4106         msg_conv.is_owned = (msg & 1) || (msg == 0);
4107         LDKCResult_boolLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_boolLightningErrorZ), "LDKCResult_boolLightningErrorZ");
4108         *ret_conv = (this_arg_conv->handle_channel_update)(this_arg_conv->this_arg, &msg_conv);
4109         return (long)ret_conv;
4110 }
4111
4112 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RoutingMessageHandler_1handle_1htlc_1fail_1channel_1update(JNIEnv * _env, jclass _b, jlong this_arg, jlong update) {
4113         LDKRoutingMessageHandler* this_arg_conv = (LDKRoutingMessageHandler*)this_arg;
4114         LDKHTLCFailChannelUpdate* update_conv = (LDKHTLCFailChannelUpdate*)update;
4115         (this_arg_conv->handle_htlc_fail_channel_update)(this_arg_conv->this_arg, update_conv);
4116 }
4117
4118 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) {
4119         LDKRoutingMessageHandler* this_arg_conv = (LDKRoutingMessageHandler*)this_arg;
4120         LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ ret_var = (this_arg_conv->get_next_channel_announcements)(this_arg_conv->this_arg, starting_point, batch_amount);
4121         jlongArray ret_arr = (*_env)->NewLongArray(_env, ret_var.datalen);
4122         jlong *ret_arr_ptr = (*_env)->GetPrimitiveArrayCritical(_env, ret_arr, NULL);
4123         for (size_t l = 0; l < ret_var.datalen; l++) {
4124                 LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ* arr_conv_63_ref = MALLOC(sizeof(LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ), "LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ");
4125                 *arr_conv_63_ref = ret_var.data[l];
4126                 ret_arr_ptr[l] = (long)arr_conv_63_ref;
4127         }
4128         (*_env)->ReleasePrimitiveArrayCritical(_env, ret_arr, ret_arr_ptr, 0);
4129         CVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ_free(ret_var);
4130         return ret_arr;
4131 }
4132
4133 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) {
4134         LDKRoutingMessageHandler* this_arg_conv = (LDKRoutingMessageHandler*)this_arg;
4135         LDKPublicKey starting_point_ref;
4136         CHECK((*_env)->GetArrayLength (_env, starting_point) == 33);
4137         (*_env)->GetByteArrayRegion (_env, starting_point, 0, 33, starting_point_ref.compressed_form);
4138         LDKCVec_NodeAnnouncementZ ret_var = (this_arg_conv->get_next_node_announcements)(this_arg_conv->this_arg, starting_point_ref, batch_amount);
4139         jlongArray ret_arr = (*_env)->NewLongArray(_env, ret_var.datalen);
4140         jlong *ret_arr_ptr = (*_env)->GetPrimitiveArrayCritical(_env, ret_arr, NULL);
4141         for (size_t s = 0; s < ret_var.datalen; s++) {
4142                 LDKNodeAnnouncement arr_conv_18_var = ret_var.data[s];
4143                 CHECK((((long)arr_conv_18_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4144                 CHECK((((long)&arr_conv_18_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4145                 long arr_conv_18_ref = (long)arr_conv_18_var.inner;
4146                 if (arr_conv_18_var.is_owned) {
4147                         arr_conv_18_ref |= 1;
4148                 }
4149                 ret_arr_ptr[s] = arr_conv_18_ref;
4150         }
4151         (*_env)->ReleasePrimitiveArrayCritical(_env, ret_arr, ret_arr_ptr, 0);
4152         FREE(ret_var.data);
4153         return ret_arr;
4154 }
4155
4156 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_RoutingMessageHandler_1should_1request_1full_1sync(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray node_id) {
4157         LDKRoutingMessageHandler* this_arg_conv = (LDKRoutingMessageHandler*)this_arg;
4158         LDKPublicKey node_id_ref;
4159         CHECK((*_env)->GetArrayLength (_env, node_id) == 33);
4160         (*_env)->GetByteArrayRegion (_env, node_id, 0, 33, node_id_ref.compressed_form);
4161         jboolean ret_val = (this_arg_conv->should_request_full_sync)(this_arg_conv->this_arg, node_id_ref);
4162         return ret_val;
4163 }
4164
4165 typedef struct LDKSocketDescriptor_JCalls {
4166         atomic_size_t refcnt;
4167         JavaVM *vm;
4168         jweak o;
4169         jmethodID send_data_meth;
4170         jmethodID disconnect_socket_meth;
4171         jmethodID eq_meth;
4172         jmethodID hash_meth;
4173 } LDKSocketDescriptor_JCalls;
4174 uintptr_t send_data_jcall(void* this_arg, LDKu8slice data, bool resume_read) {
4175         LDKSocketDescriptor_JCalls *j_calls = (LDKSocketDescriptor_JCalls*) this_arg;
4176         JNIEnv *_env;
4177         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
4178         LDKu8slice data_var = data;
4179         jbyteArray data_arr = (*_env)->NewByteArray(_env, data_var.datalen);
4180         (*_env)->SetByteArrayRegion(_env, data_arr, 0, data_var.datalen, data_var.data);
4181         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
4182         CHECK(obj != NULL);
4183         return (*_env)->CallLongMethod(_env, obj, j_calls->send_data_meth, data_arr, resume_read);
4184 }
4185 void disconnect_socket_jcall(void* this_arg) {
4186         LDKSocketDescriptor_JCalls *j_calls = (LDKSocketDescriptor_JCalls*) this_arg;
4187         JNIEnv *_env;
4188         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
4189         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
4190         CHECK(obj != NULL);
4191         return (*_env)->CallVoidMethod(_env, obj, j_calls->disconnect_socket_meth);
4192 }
4193 bool eq_jcall(const void* this_arg, const void *other_arg) {
4194         LDKSocketDescriptor_JCalls *j_calls = (LDKSocketDescriptor_JCalls*) this_arg;
4195         JNIEnv *_env;
4196         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
4197         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
4198         CHECK(obj != NULL);
4199         return (*_env)->CallBooleanMethod(_env, obj, j_calls->eq_meth, other_arg);
4200 }
4201 uint64_t hash_jcall(const void* this_arg) {
4202         LDKSocketDescriptor_JCalls *j_calls = (LDKSocketDescriptor_JCalls*) this_arg;
4203         JNIEnv *_env;
4204         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
4205         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
4206         CHECK(obj != NULL);
4207         return (*_env)->CallLongMethod(_env, obj, j_calls->hash_meth);
4208 }
4209 static void LDKSocketDescriptor_JCalls_free(void* this_arg) {
4210         LDKSocketDescriptor_JCalls *j_calls = (LDKSocketDescriptor_JCalls*) this_arg;
4211         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
4212                 JNIEnv *env;
4213                 DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
4214                 (*env)->DeleteWeakGlobalRef(env, j_calls->o);
4215                 FREE(j_calls);
4216         }
4217 }
4218 static void* LDKSocketDescriptor_JCalls_clone(const void* this_arg) {
4219         LDKSocketDescriptor_JCalls *j_calls = (LDKSocketDescriptor_JCalls*) this_arg;
4220         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
4221         return (void*) this_arg;
4222 }
4223 static inline LDKSocketDescriptor LDKSocketDescriptor_init (JNIEnv * env, jclass _a, jobject o) {
4224         jclass c = (*env)->GetObjectClass(env, o);
4225         CHECK(c != NULL);
4226         LDKSocketDescriptor_JCalls *calls = MALLOC(sizeof(LDKSocketDescriptor_JCalls), "LDKSocketDescriptor_JCalls");
4227         atomic_init(&calls->refcnt, 1);
4228         DO_ASSERT((*env)->GetJavaVM(env, &calls->vm) == 0);
4229         calls->o = (*env)->NewWeakGlobalRef(env, o);
4230         calls->send_data_meth = (*env)->GetMethodID(env, c, "send_data", "([BZ)J");
4231         CHECK(calls->send_data_meth != NULL);
4232         calls->disconnect_socket_meth = (*env)->GetMethodID(env, c, "disconnect_socket", "()V");
4233         CHECK(calls->disconnect_socket_meth != NULL);
4234         calls->eq_meth = (*env)->GetMethodID(env, c, "eq", "(J)Z");
4235         CHECK(calls->eq_meth != NULL);
4236         calls->hash_meth = (*env)->GetMethodID(env, c, "hash", "()J");
4237         CHECK(calls->hash_meth != NULL);
4238
4239         LDKSocketDescriptor ret = {
4240                 .this_arg = (void*) calls,
4241                 .send_data = send_data_jcall,
4242                 .disconnect_socket = disconnect_socket_jcall,
4243                 .eq = eq_jcall,
4244                 .hash = hash_jcall,
4245                 .clone = LDKSocketDescriptor_JCalls_clone,
4246                 .free = LDKSocketDescriptor_JCalls_free,
4247         };
4248         return ret;
4249 }
4250 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_LDKSocketDescriptor_1new (JNIEnv * env, jclass _a, jobject o) {
4251         LDKSocketDescriptor *res_ptr = MALLOC(sizeof(LDKSocketDescriptor), "LDKSocketDescriptor");
4252         *res_ptr = LDKSocketDescriptor_init(env, _a, o);
4253         return (long)res_ptr;
4254 }
4255 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKSocketDescriptor_1get_1obj_1from_1jcalls (JNIEnv * env, jclass _a, jlong val) {
4256         jobject ret = (*env)->NewLocalRef(env, ((LDKSocketDescriptor_JCalls*)val)->o);
4257         CHECK(ret != NULL);
4258         return ret;
4259 }
4260 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_SocketDescriptor_1send_1data(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray data, jboolean resume_read) {
4261         LDKSocketDescriptor* this_arg_conv = (LDKSocketDescriptor*)this_arg;
4262         LDKu8slice data_ref;
4263         data_ref.data = (*_env)->GetByteArrayElements (_env, data, NULL);
4264         data_ref.datalen = (*_env)->GetArrayLength (_env, data);
4265         jlong ret_val = (this_arg_conv->send_data)(this_arg_conv->this_arg, data_ref, resume_read);
4266         (*_env)->ReleaseByteArrayElements(_env, data, (int8_t*)data_ref.data, 0);
4267         return ret_val;
4268 }
4269
4270 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_SocketDescriptor_1disconnect_1socket(JNIEnv * _env, jclass _b, jlong this_arg) {
4271         LDKSocketDescriptor* this_arg_conv = (LDKSocketDescriptor*)this_arg;
4272         (this_arg_conv->disconnect_socket)(this_arg_conv->this_arg);
4273 }
4274
4275 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_SocketDescriptor_1hash(JNIEnv * _env, jclass _b, jlong this_arg) {
4276         LDKSocketDescriptor* this_arg_conv = (LDKSocketDescriptor*)this_arg;
4277         jlong ret_val = (this_arg_conv->hash)(this_arg_conv->this_arg);
4278         return ret_val;
4279 }
4280
4281 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1PublicKey_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
4282         LDKCVecTempl_PublicKey *vec = (LDKCVecTempl_PublicKey*)ptr;
4283         return (*env)->NewObject(env, slicedef_cls, slicedef_meth, (long)vec->data, (long)vec->datalen, sizeof(LDKPublicKey));
4284 }
4285 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1CVec_1u8ZPeerHandleErrorZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
4286         return ((LDKCResult_CVec_u8ZPeerHandleErrorZ*)arg)->result_ok;
4287 }
4288 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_LDKCResult_1CVec_1u8ZPeerHandleErrorZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
4289         LDKCResult_CVec_u8ZPeerHandleErrorZ *val = (LDKCResult_CVec_u8ZPeerHandleErrorZ*)arg;
4290         CHECK(val->result_ok);
4291         LDKCVecTempl_u8 res_var = (*val->contents.result);
4292         jbyteArray res_arr = (*_env)->NewByteArray(_env, res_var.datalen);
4293         (*_env)->SetByteArrayRegion(_env, res_arr, 0, res_var.datalen, res_var.data);
4294         return res_arr;
4295 }
4296 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1CVec_1u8ZPeerHandleErrorZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
4297         LDKCResult_CVec_u8ZPeerHandleErrorZ *val = (LDKCResult_CVec_u8ZPeerHandleErrorZ*)arg;
4298         CHECK(!val->result_ok);
4299         LDKPeerHandleError err_var = (*val->contents.err);
4300         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4301         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4302         long err_ref = (long)err_var.inner & ~1;
4303         return err_ref;
4304 }
4305 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1boolPeerHandleErrorZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
4306         return ((LDKCResult_boolPeerHandleErrorZ*)arg)->result_ok;
4307 }
4308 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1boolPeerHandleErrorZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
4309         LDKCResult_boolPeerHandleErrorZ *val = (LDKCResult_boolPeerHandleErrorZ*)arg;
4310         CHECK(val->result_ok);
4311         return *val->contents.result;
4312 }
4313 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1boolPeerHandleErrorZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
4314         LDKCResult_boolPeerHandleErrorZ *val = (LDKCResult_boolPeerHandleErrorZ*)arg;
4315         CHECK(!val->result_ok);
4316         LDKPeerHandleError err_var = (*val->contents.err);
4317         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4318         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4319         long err_ref = (long)err_var.inner & ~1;
4320         return err_ref;
4321 }
4322 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1SecretKeySecpErrorZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
4323         return ((LDKCResult_SecretKeySecpErrorZ*)arg)->result_ok;
4324 }
4325 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_LDKCResult_1SecretKeySecpErrorZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
4326         LDKCResult_SecretKeySecpErrorZ *val = (LDKCResult_SecretKeySecpErrorZ*)arg;
4327         CHECK(val->result_ok);
4328         jbyteArray res_arr = (*_env)->NewByteArray(_env, 32);
4329         (*_env)->SetByteArrayRegion(_env, res_arr, 0, 32, (*val->contents.result).bytes);
4330         return res_arr;
4331 }
4332 JNIEXPORT jclass JNICALL Java_org_ldk_impl_bindings_LDKCResult_1SecretKeySecpErrorZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
4333         LDKCResult_SecretKeySecpErrorZ *val = (LDKCResult_SecretKeySecpErrorZ*)arg;
4334         CHECK(!val->result_ok);
4335         jclass err_conv = LDKSecp256k1Error_to_java(_env, (*val->contents.err));
4336         return err_conv;
4337 }
4338 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1PublicKeySecpErrorZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
4339         return ((LDKCResult_PublicKeySecpErrorZ*)arg)->result_ok;
4340 }
4341 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_LDKCResult_1PublicKeySecpErrorZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
4342         LDKCResult_PublicKeySecpErrorZ *val = (LDKCResult_PublicKeySecpErrorZ*)arg;
4343         CHECK(val->result_ok);
4344         jbyteArray res_arr = (*_env)->NewByteArray(_env, 33);
4345         (*_env)->SetByteArrayRegion(_env, res_arr, 0, 33, (*val->contents.result).compressed_form);
4346         return res_arr;
4347 }
4348 JNIEXPORT jclass JNICALL Java_org_ldk_impl_bindings_LDKCResult_1PublicKeySecpErrorZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
4349         LDKCResult_PublicKeySecpErrorZ *val = (LDKCResult_PublicKeySecpErrorZ*)arg;
4350         CHECK(!val->result_ok);
4351         jclass err_conv = LDKSecp256k1Error_to_java(_env, (*val->contents.err));
4352         return err_conv;
4353 }
4354 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1TxCreationKeysSecpErrorZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
4355         return ((LDKCResult_TxCreationKeysSecpErrorZ*)arg)->result_ok;
4356 }
4357 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1TxCreationKeysSecpErrorZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
4358         LDKCResult_TxCreationKeysSecpErrorZ *val = (LDKCResult_TxCreationKeysSecpErrorZ*)arg;
4359         CHECK(val->result_ok);
4360         LDKTxCreationKeys res_var = (*val->contents.result);
4361         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4362         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4363         long res_ref = (long)res_var.inner & ~1;
4364         return res_ref;
4365 }
4366 JNIEXPORT jclass JNICALL Java_org_ldk_impl_bindings_LDKCResult_1TxCreationKeysSecpErrorZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
4367         LDKCResult_TxCreationKeysSecpErrorZ *val = (LDKCResult_TxCreationKeysSecpErrorZ*)arg;
4368         CHECK(!val->result_ok);
4369         jclass err_conv = LDKSecp256k1Error_to_java(_env, (*val->contents.err));
4370         return err_conv;
4371 }
4372 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1C2TupleTempl_1HTLCOutputInCommitment_1_1Signature_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
4373         LDKCVecTempl_C2TupleTempl_HTLCOutputInCommitment__Signature *vec = (LDKCVecTempl_C2TupleTempl_HTLCOutputInCommitment__Signature*)ptr;
4374         return (*env)->NewObject(env, slicedef_cls, slicedef_meth, (long)vec->data, (long)vec->datalen, sizeof(LDKC2TupleTempl_HTLCOutputInCommitment__Signature));
4375 }
4376 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1C2TupleTempl_1HTLCOutputInCommitment_1_1Signature_1new(JNIEnv *env, jclass _b, jlongArray elems){
4377         LDKCVecTempl_C2TupleTempl_HTLCOutputInCommitment__Signature *ret = MALLOC(sizeof(LDKCVecTempl_C2TupleTempl_HTLCOutputInCommitment__Signature), "LDKCVecTempl_C2TupleTempl_HTLCOutputInCommitment__Signature");
4378         ret->datalen = (*env)->GetArrayLength(env, elems);
4379         if (ret->datalen == 0) {
4380                 ret->data = NULL;
4381         } else {
4382                 ret->data = MALLOC(sizeof(LDKC2TupleTempl_HTLCOutputInCommitment__Signature) * ret->datalen, "LDKCVecTempl_C2TupleTempl_HTLCOutputInCommitment__Signature Data");
4383                 jlong *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
4384                 for (size_t i = 0; i < ret->datalen; i++) {
4385                         jlong arr_elem = java_elems[i];
4386                         LDKC2TupleTempl_HTLCOutputInCommitment__Signature arr_elem_conv = *(LDKC2TupleTempl_HTLCOutputInCommitment__Signature*)arr_elem;
4387                         FREE((void*)arr_elem);
4388                         ret->data[i] = arr_elem_conv;
4389                 }
4390                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
4391         }
4392         return (long)ret;
4393 }
4394 JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1RouteHop_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
4395         LDKCVecTempl_RouteHop *vec = (LDKCVecTempl_RouteHop*)ptr;
4396         jlongArray ret = (*env)->NewLongArray(env, vec->datalen);
4397         jlong *ret_elems = (*env)->GetPrimitiveArrayCritical(env, ret, NULL);
4398         for (size_t i = 0; i < vec->datalen; i++) {
4399                 CHECK((((long)vec->data[i].inner) & 1) == 0);
4400                 ret_elems[i] = (long)vec->data[i].inner | (vec->data[i].is_owned ? 1 : 0);
4401         }
4402         (*env)->ReleasePrimitiveArrayCritical(env, ret, ret_elems, 0);
4403         return ret;
4404 }
4405 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1RouteHop_1new(JNIEnv *env, jclass _b, jlongArray elems){
4406         LDKCVecTempl_RouteHop *ret = MALLOC(sizeof(LDKCVecTempl_RouteHop), "LDKCVecTempl_RouteHop");
4407         ret->datalen = (*env)->GetArrayLength(env, elems);
4408         if (ret->datalen == 0) {
4409                 ret->data = NULL;
4410         } else {
4411                 ret->data = MALLOC(sizeof(LDKRouteHop) * ret->datalen, "LDKCVecTempl_RouteHop Data");
4412                 jlong *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
4413                 for (size_t i = 0; i < ret->datalen; i++) {
4414                         jlong arr_elem = java_elems[i];
4415                         LDKRouteHop arr_elem_conv;
4416                         arr_elem_conv.inner = (void*)(arr_elem & (~1));
4417                         arr_elem_conv.is_owned = (arr_elem & 1) || (arr_elem == 0);
4418                         if (arr_elem_conv.inner != NULL)
4419                                 arr_elem_conv = RouteHop_clone(&arr_elem_conv);
4420                         ret->data[i] = arr_elem_conv;
4421                 }
4422                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
4423         }
4424         return (long)ret;
4425 }
4426 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1CVecTempl_1RouteHop_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
4427         LDKCVecTempl_CVecTempl_RouteHop *vec = (LDKCVecTempl_CVecTempl_RouteHop*)ptr;
4428         return (*env)->NewObject(env, slicedef_cls, slicedef_meth, (long)vec->data, (long)vec->datalen, sizeof(LDKCVecTempl_RouteHop));
4429 }
4430 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1RouteLightningErrorZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
4431         return ((LDKCResult_RouteLightningErrorZ*)arg)->result_ok;
4432 }
4433 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1RouteLightningErrorZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
4434         LDKCResult_RouteLightningErrorZ *val = (LDKCResult_RouteLightningErrorZ*)arg;
4435         CHECK(val->result_ok);
4436         LDKRoute res_var = (*val->contents.result);
4437         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4438         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4439         long res_ref = (long)res_var.inner & ~1;
4440         return res_ref;
4441 }
4442 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1RouteLightningErrorZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
4443         LDKCResult_RouteLightningErrorZ *val = (LDKCResult_RouteLightningErrorZ*)arg;
4444         CHECK(!val->result_ok);
4445         LDKLightningError err_var = (*val->contents.err);
4446         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4447         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4448         long err_ref = (long)err_var.inner & ~1;
4449         return err_ref;
4450 }
4451 JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1RouteHint_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
4452         LDKCVecTempl_RouteHint *vec = (LDKCVecTempl_RouteHint*)ptr;
4453         jlongArray ret = (*env)->NewLongArray(env, vec->datalen);
4454         jlong *ret_elems = (*env)->GetPrimitiveArrayCritical(env, ret, NULL);
4455         for (size_t i = 0; i < vec->datalen; i++) {
4456                 CHECK((((long)vec->data[i].inner) & 1) == 0);
4457                 ret_elems[i] = (long)vec->data[i].inner | (vec->data[i].is_owned ? 1 : 0);
4458         }
4459         (*env)->ReleasePrimitiveArrayCritical(env, ret, ret_elems, 0);
4460         return ret;
4461 }
4462 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1RouteHint_1new(JNIEnv *env, jclass _b, jlongArray elems){
4463         LDKCVecTempl_RouteHint *ret = MALLOC(sizeof(LDKCVecTempl_RouteHint), "LDKCVecTempl_RouteHint");
4464         ret->datalen = (*env)->GetArrayLength(env, elems);
4465         if (ret->datalen == 0) {
4466                 ret->data = NULL;
4467         } else {
4468                 ret->data = MALLOC(sizeof(LDKRouteHint) * ret->datalen, "LDKCVecTempl_RouteHint Data");
4469                 jlong *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
4470                 for (size_t i = 0; i < ret->datalen; i++) {
4471                         jlong arr_elem = java_elems[i];
4472                         LDKRouteHint arr_elem_conv;
4473                         arr_elem_conv.inner = (void*)(arr_elem & (~1));
4474                         arr_elem_conv.is_owned = (arr_elem & 1) || (arr_elem == 0);
4475                         if (arr_elem_conv.inner != NULL)
4476                                 arr_elem_conv = RouteHint_clone(&arr_elem_conv);
4477                         ret->data[i] = arr_elem_conv;
4478                 }
4479                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
4480         }
4481         return (long)ret;
4482 }
4483 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_C2Tuple_1HTLCOutputInCommitmentSignatureZ_1free(JNIEnv * _env, jclass _b, jlong arg) {
4484         LDKC2Tuple_HTLCOutputInCommitmentSignatureZ arg_conv = *(LDKC2Tuple_HTLCOutputInCommitmentSignatureZ*)arg;
4485         FREE((void*)arg);
4486         C2Tuple_HTLCOutputInCommitmentSignatureZ_free(arg_conv);
4487 }
4488
4489 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_C2Tuple_1OutPointScriptZ_1free(JNIEnv * _env, jclass _b, jlong arg) {
4490         LDKC2Tuple_OutPointScriptZ arg_conv = *(LDKC2Tuple_OutPointScriptZ*)arg;
4491         FREE((void*)arg);
4492         C2Tuple_OutPointScriptZ_free(arg_conv);
4493 }
4494
4495 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_C2Tuple_1SignatureCVec_1SignatureZZ_1free(JNIEnv * _env, jclass _b, jlong arg) {
4496         LDKC2Tuple_SignatureCVec_SignatureZZ arg_conv = *(LDKC2Tuple_SignatureCVec_SignatureZZ*)arg;
4497         FREE((void*)arg);
4498         C2Tuple_SignatureCVec_SignatureZZ_free(arg_conv);
4499 }
4500
4501 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_C2Tuple_1TxidCVec_1TxOutZZ_1free(JNIEnv * _env, jclass _b, jlong arg) {
4502         LDKC2Tuple_TxidCVec_TxOutZZ arg_conv = *(LDKC2Tuple_TxidCVec_TxOutZZ*)arg;
4503         FREE((void*)arg);
4504         C2Tuple_TxidCVec_TxOutZZ_free(arg_conv);
4505 }
4506
4507 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_C2Tuple_1u64u64Z_1free(JNIEnv * _env, jclass _b, jlong arg) {
4508         LDKC2Tuple_u64u64Z arg_conv = *(LDKC2Tuple_u64u64Z*)arg;
4509         FREE((void*)arg);
4510         C2Tuple_u64u64Z_free(arg_conv);
4511 }
4512
4513 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_C2Tuple_1usizeTransactionZ_1free(JNIEnv * _env, jclass _b, jlong arg) {
4514         LDKC2Tuple_usizeTransactionZ arg_conv = *(LDKC2Tuple_usizeTransactionZ*)arg;
4515         FREE((void*)arg);
4516         C2Tuple_usizeTransactionZ_free(arg_conv);
4517 }
4518
4519 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_C3Tuple_1ChannelAnnouncementChannelUpdateChannelUpdateZ_1free(JNIEnv * _env, jclass _b, jlong arg) {
4520         LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ arg_conv = *(LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ*)arg;
4521         FREE((void*)arg);
4522         C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ_free(arg_conv);
4523 }
4524
4525 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1C2Tuple_1SignatureCVec_1SignatureZZNoneZ_1free(JNIEnv * _env, jclass _b, jlong arg) {
4526         LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ arg_conv = *(LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ*)arg;
4527         FREE((void*)arg);
4528         CResult_C2Tuple_SignatureCVec_SignatureZZNoneZ_free(arg_conv);
4529 }
4530
4531 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1C2Tuple_1SignatureCVec_1SignatureZZNoneZ_1ok(JNIEnv * _env, jclass _b, jlong arg) {
4532         LDKC2Tuple_SignatureCVec_SignatureZZ arg_conv = *(LDKC2Tuple_SignatureCVec_SignatureZZ*)arg;
4533         FREE((void*)arg);
4534         LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ), "LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ");
4535         *ret_conv = CResult_C2Tuple_SignatureCVec_SignatureZZNoneZ_ok(arg_conv);
4536         return (long)ret_conv;
4537 }
4538
4539 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1CVec_1SignatureZNoneZ_1free(JNIEnv * _env, jclass _b, jlong arg) {
4540         LDKCResult_CVec_SignatureZNoneZ arg_conv = *(LDKCResult_CVec_SignatureZNoneZ*)arg;
4541         FREE((void*)arg);
4542         CResult_CVec_SignatureZNoneZ_free(arg_conv);
4543 }
4544
4545 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1CVec_1SignatureZNoneZ_1ok(JNIEnv * _env, jclass _b, jobjectArray arg) {
4546         LDKCVec_SignatureZ arg_constr;
4547         arg_constr.datalen = (*_env)->GetArrayLength (_env, arg);
4548         if (arg_constr.datalen > 0)
4549                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKSignature), "LDKCVec_SignatureZ Elements");
4550         else
4551                 arg_constr.data = NULL;
4552         for (size_t i = 0; i < arg_constr.datalen; i++) {
4553                 jobject arr_conv_8 = (*_env)->GetObjectArrayElement(_env, arg, i);
4554                 LDKSignature arr_conv_8_ref;
4555                 CHECK((*_env)->GetArrayLength (_env, arr_conv_8) == 64);
4556                 (*_env)->GetByteArrayRegion (_env, arr_conv_8, 0, 64, arr_conv_8_ref.compact_form);
4557                 arg_constr.data[i] = arr_conv_8_ref;
4558         }
4559         LDKCResult_CVec_SignatureZNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_CVec_SignatureZNoneZ), "LDKCResult_CVec_SignatureZNoneZ");
4560         *ret_conv = CResult_CVec_SignatureZNoneZ_ok(arg_constr);
4561         return (long)ret_conv;
4562 }
4563
4564 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1CVec_1u8ZPeerHandleErrorZ_1err(JNIEnv * _env, jclass _b, jlong arg) {
4565         LDKPeerHandleError arg_conv = *(LDKPeerHandleError*)arg;
4566         FREE((void*)arg);
4567         LDKCResult_CVec_u8ZPeerHandleErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_CVec_u8ZPeerHandleErrorZ), "LDKCResult_CVec_u8ZPeerHandleErrorZ");
4568         *ret_conv = CResult_CVec_u8ZPeerHandleErrorZ_err(arg_conv);
4569         return (long)ret_conv;
4570 }
4571
4572 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1CVec_1u8ZPeerHandleErrorZ_1free(JNIEnv * _env, jclass _b, jlong arg) {
4573         LDKCResult_CVec_u8ZPeerHandleErrorZ arg_conv = *(LDKCResult_CVec_u8ZPeerHandleErrorZ*)arg;
4574         FREE((void*)arg);
4575         CResult_CVec_u8ZPeerHandleErrorZ_free(arg_conv);
4576 }
4577
4578 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1CVec_1u8ZPeerHandleErrorZ_1ok(JNIEnv * _env, jclass _b, jbyteArray arg) {
4579         LDKCVec_u8Z arg_ref;
4580         arg_ref.data = (*_env)->GetByteArrayElements (_env, arg, NULL);
4581         arg_ref.datalen = (*_env)->GetArrayLength (_env, arg);
4582         LDKCResult_CVec_u8ZPeerHandleErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_CVec_u8ZPeerHandleErrorZ), "LDKCResult_CVec_u8ZPeerHandleErrorZ");
4583         *ret_conv = CResult_CVec_u8ZPeerHandleErrorZ_ok(arg_ref);
4584         (*_env)->ReleaseByteArrayElements(_env, arg, (int8_t*)arg_ref.data, 0);
4585         return (long)ret_conv;
4586 }
4587
4588 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1NoneAPIErrorZ_1err(JNIEnv * _env, jclass _b, jlong arg) {
4589         LDKAPIError arg_conv = *(LDKAPIError*)arg;
4590         FREE((void*)arg);
4591         LDKCResult_NoneAPIErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneAPIErrorZ), "LDKCResult_NoneAPIErrorZ");
4592         *ret_conv = CResult_NoneAPIErrorZ_err(arg_conv);
4593         return (long)ret_conv;
4594 }
4595
4596 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1NoneAPIErrorZ_1free(JNIEnv * _env, jclass _b, jlong arg) {
4597         LDKCResult_NoneAPIErrorZ arg_conv = *(LDKCResult_NoneAPIErrorZ*)arg;
4598         FREE((void*)arg);
4599         CResult_NoneAPIErrorZ_free(arg_conv);
4600 }
4601
4602 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1NoneChannelMonitorUpdateErrZ_1err(JNIEnv * _env, jclass _b, jclass arg) {
4603         LDKChannelMonitorUpdateErr arg_conv = *(LDKChannelMonitorUpdateErr*)arg;
4604         FREE((void*)arg);
4605         LDKCResult_NoneChannelMonitorUpdateErrZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneChannelMonitorUpdateErrZ), "LDKCResult_NoneChannelMonitorUpdateErrZ");
4606         *ret_conv = CResult_NoneChannelMonitorUpdateErrZ_err(arg_conv);
4607         return (long)ret_conv;
4608 }
4609
4610 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1NoneChannelMonitorUpdateErrZ_1free(JNIEnv * _env, jclass _b, jlong arg) {
4611         LDKCResult_NoneChannelMonitorUpdateErrZ arg_conv = *(LDKCResult_NoneChannelMonitorUpdateErrZ*)arg;
4612         FREE((void*)arg);
4613         CResult_NoneChannelMonitorUpdateErrZ_free(arg_conv);
4614 }
4615
4616 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1NoneMonitorUpdateErrorZ_1err(JNIEnv * _env, jclass _b, jlong arg) {
4617         LDKMonitorUpdateError arg_conv = *(LDKMonitorUpdateError*)arg;
4618         FREE((void*)arg);
4619         LDKCResult_NoneMonitorUpdateErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneMonitorUpdateErrorZ), "LDKCResult_NoneMonitorUpdateErrorZ");
4620         *ret_conv = CResult_NoneMonitorUpdateErrorZ_err(arg_conv);
4621         return (long)ret_conv;
4622 }
4623
4624 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1NoneMonitorUpdateErrorZ_1free(JNIEnv * _env, jclass _b, jlong arg) {
4625         LDKCResult_NoneMonitorUpdateErrorZ arg_conv = *(LDKCResult_NoneMonitorUpdateErrorZ*)arg;
4626         FREE((void*)arg);
4627         CResult_NoneMonitorUpdateErrorZ_free(arg_conv);
4628 }
4629
4630 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1NonePaymentSendFailureZ_1err(JNIEnv * _env, jclass _b, jlong arg) {
4631         LDKPaymentSendFailure arg_conv = *(LDKPaymentSendFailure*)arg;
4632         FREE((void*)arg);
4633         LDKCResult_NonePaymentSendFailureZ* ret_conv = MALLOC(sizeof(LDKCResult_NonePaymentSendFailureZ), "LDKCResult_NonePaymentSendFailureZ");
4634         *ret_conv = CResult_NonePaymentSendFailureZ_err(arg_conv);
4635         return (long)ret_conv;
4636 }
4637
4638 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1NonePaymentSendFailureZ_1free(JNIEnv * _env, jclass _b, jlong arg) {
4639         LDKCResult_NonePaymentSendFailureZ arg_conv = *(LDKCResult_NonePaymentSendFailureZ*)arg;
4640         FREE((void*)arg);
4641         CResult_NonePaymentSendFailureZ_free(arg_conv);
4642 }
4643
4644 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1NonePeerHandleErrorZ_1err(JNIEnv * _env, jclass _b, jlong arg) {
4645         LDKPeerHandleError arg_conv = *(LDKPeerHandleError*)arg;
4646         FREE((void*)arg);
4647         LDKCResult_NonePeerHandleErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NonePeerHandleErrorZ), "LDKCResult_NonePeerHandleErrorZ");
4648         *ret_conv = CResult_NonePeerHandleErrorZ_err(arg_conv);
4649         return (long)ret_conv;
4650 }
4651
4652 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1NonePeerHandleErrorZ_1free(JNIEnv * _env, jclass _b, jlong arg) {
4653         LDKCResult_NonePeerHandleErrorZ arg_conv = *(LDKCResult_NonePeerHandleErrorZ*)arg;
4654         FREE((void*)arg);
4655         CResult_NonePeerHandleErrorZ_free(arg_conv);
4656 }
4657
4658 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1PublicKeySecpErrorZ_1err(JNIEnv * _env, jclass _b, jclass arg) {
4659         LDKSecp256k1Error arg_conv = *(LDKSecp256k1Error*)arg;
4660         FREE((void*)arg);
4661         LDKCResult_PublicKeySecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_PublicKeySecpErrorZ), "LDKCResult_PublicKeySecpErrorZ");
4662         *ret_conv = CResult_PublicKeySecpErrorZ_err(arg_conv);
4663         return (long)ret_conv;
4664 }
4665
4666 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1PublicKeySecpErrorZ_1free(JNIEnv * _env, jclass _b, jlong arg) {
4667         LDKCResult_PublicKeySecpErrorZ arg_conv = *(LDKCResult_PublicKeySecpErrorZ*)arg;
4668         FREE((void*)arg);
4669         CResult_PublicKeySecpErrorZ_free(arg_conv);
4670 }
4671
4672 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1PublicKeySecpErrorZ_1ok(JNIEnv * _env, jclass _b, jbyteArray arg) {
4673         LDKPublicKey arg_ref;
4674         CHECK((*_env)->GetArrayLength (_env, arg) == 33);
4675         (*_env)->GetByteArrayRegion (_env, arg, 0, 33, arg_ref.compressed_form);
4676         LDKCResult_PublicKeySecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_PublicKeySecpErrorZ), "LDKCResult_PublicKeySecpErrorZ");
4677         *ret_conv = CResult_PublicKeySecpErrorZ_ok(arg_ref);
4678         return (long)ret_conv;
4679 }
4680
4681 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1RouteLightningErrorZ_1err(JNIEnv * _env, jclass _b, jlong arg) {
4682         LDKLightningError arg_conv = *(LDKLightningError*)arg;
4683         FREE((void*)arg);
4684         LDKCResult_RouteLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_RouteLightningErrorZ), "LDKCResult_RouteLightningErrorZ");
4685         *ret_conv = CResult_RouteLightningErrorZ_err(arg_conv);
4686         return (long)ret_conv;
4687 }
4688
4689 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1RouteLightningErrorZ_1free(JNIEnv * _env, jclass _b, jlong arg) {
4690         LDKCResult_RouteLightningErrorZ arg_conv = *(LDKCResult_RouteLightningErrorZ*)arg;
4691         FREE((void*)arg);
4692         CResult_RouteLightningErrorZ_free(arg_conv);
4693 }
4694
4695 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1RouteLightningErrorZ_1ok(JNIEnv * _env, jclass _b, jlong arg) {
4696         LDKRoute arg_conv = *(LDKRoute*)arg;
4697         FREE((void*)arg);
4698         LDKCResult_RouteLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_RouteLightningErrorZ), "LDKCResult_RouteLightningErrorZ");
4699         *ret_conv = CResult_RouteLightningErrorZ_ok(arg_conv);
4700         return (long)ret_conv;
4701 }
4702
4703 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1SecretKeySecpErrorZ_1err(JNIEnv * _env, jclass _b, jclass arg) {
4704         LDKSecp256k1Error arg_conv = *(LDKSecp256k1Error*)arg;
4705         FREE((void*)arg);
4706         LDKCResult_SecretKeySecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_SecretKeySecpErrorZ), "LDKCResult_SecretKeySecpErrorZ");
4707         *ret_conv = CResult_SecretKeySecpErrorZ_err(arg_conv);
4708         return (long)ret_conv;
4709 }
4710
4711 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1SecretKeySecpErrorZ_1free(JNIEnv * _env, jclass _b, jlong arg) {
4712         LDKCResult_SecretKeySecpErrorZ arg_conv = *(LDKCResult_SecretKeySecpErrorZ*)arg;
4713         FREE((void*)arg);
4714         CResult_SecretKeySecpErrorZ_free(arg_conv);
4715 }
4716
4717 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1SecretKeySecpErrorZ_1ok(JNIEnv * _env, jclass _b, jbyteArray arg) {
4718         LDKSecretKey arg_ref;
4719         CHECK((*_env)->GetArrayLength (_env, arg) == 32);
4720         (*_env)->GetByteArrayRegion (_env, arg, 0, 32, arg_ref.bytes);
4721         LDKCResult_SecretKeySecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_SecretKeySecpErrorZ), "LDKCResult_SecretKeySecpErrorZ");
4722         *ret_conv = CResult_SecretKeySecpErrorZ_ok(arg_ref);
4723         return (long)ret_conv;
4724 }
4725
4726 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1SignatureNoneZ_1free(JNIEnv * _env, jclass _b, jlong arg) {
4727         LDKCResult_SignatureNoneZ arg_conv = *(LDKCResult_SignatureNoneZ*)arg;
4728         FREE((void*)arg);
4729         CResult_SignatureNoneZ_free(arg_conv);
4730 }
4731
4732 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1SignatureNoneZ_1ok(JNIEnv * _env, jclass _b, jbyteArray arg) {
4733         LDKSignature arg_ref;
4734         CHECK((*_env)->GetArrayLength (_env, arg) == 64);
4735         (*_env)->GetByteArrayRegion (_env, arg, 0, 64, arg_ref.compact_form);
4736         LDKCResult_SignatureNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_SignatureNoneZ), "LDKCResult_SignatureNoneZ");
4737         *ret_conv = CResult_SignatureNoneZ_ok(arg_ref);
4738         return (long)ret_conv;
4739 }
4740
4741 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1TxCreationKeysSecpErrorZ_1err(JNIEnv * _env, jclass _b, jclass arg) {
4742         LDKSecp256k1Error arg_conv = *(LDKSecp256k1Error*)arg;
4743         FREE((void*)arg);
4744         LDKCResult_TxCreationKeysSecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_TxCreationKeysSecpErrorZ), "LDKCResult_TxCreationKeysSecpErrorZ");
4745         *ret_conv = CResult_TxCreationKeysSecpErrorZ_err(arg_conv);
4746         return (long)ret_conv;
4747 }
4748
4749 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1TxCreationKeysSecpErrorZ_1free(JNIEnv * _env, jclass _b, jlong arg) {
4750         LDKCResult_TxCreationKeysSecpErrorZ arg_conv = *(LDKCResult_TxCreationKeysSecpErrorZ*)arg;
4751         FREE((void*)arg);
4752         CResult_TxCreationKeysSecpErrorZ_free(arg_conv);
4753 }
4754
4755 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1TxCreationKeysSecpErrorZ_1ok(JNIEnv * _env, jclass _b, jlong arg) {
4756         LDKTxCreationKeys arg_conv = *(LDKTxCreationKeys*)arg;
4757         FREE((void*)arg);
4758         LDKCResult_TxCreationKeysSecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_TxCreationKeysSecpErrorZ), "LDKCResult_TxCreationKeysSecpErrorZ");
4759         *ret_conv = CResult_TxCreationKeysSecpErrorZ_ok(arg_conv);
4760         return (long)ret_conv;
4761 }
4762
4763 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1TxOutAccessErrorZ_1err(JNIEnv * _env, jclass _b, jclass arg) {
4764         LDKAccessError arg_conv = *(LDKAccessError*)arg;
4765         FREE((void*)arg);
4766         LDKCResult_TxOutAccessErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_TxOutAccessErrorZ), "LDKCResult_TxOutAccessErrorZ");
4767         *ret_conv = CResult_TxOutAccessErrorZ_err(arg_conv);
4768         return (long)ret_conv;
4769 }
4770
4771 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1TxOutAccessErrorZ_1free(JNIEnv * _env, jclass _b, jlong arg) {
4772         LDKCResult_TxOutAccessErrorZ arg_conv = *(LDKCResult_TxOutAccessErrorZ*)arg;
4773         FREE((void*)arg);
4774         CResult_TxOutAccessErrorZ_free(arg_conv);
4775 }
4776
4777 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1TxOutAccessErrorZ_1ok(JNIEnv * _env, jclass _b, jlong arg) {
4778         LDKTxOut arg_conv = *(LDKTxOut*)arg;
4779         FREE((void*)arg);
4780         LDKCResult_TxOutAccessErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_TxOutAccessErrorZ), "LDKCResult_TxOutAccessErrorZ");
4781         *ret_conv = CResult_TxOutAccessErrorZ_ok(arg_conv);
4782         return (long)ret_conv;
4783 }
4784
4785 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1boolLightningErrorZ_1err(JNIEnv * _env, jclass _b, jlong arg) {
4786         LDKLightningError arg_conv = *(LDKLightningError*)arg;
4787         FREE((void*)arg);
4788         LDKCResult_boolLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_boolLightningErrorZ), "LDKCResult_boolLightningErrorZ");
4789         *ret_conv = CResult_boolLightningErrorZ_err(arg_conv);
4790         return (long)ret_conv;
4791 }
4792
4793 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1boolLightningErrorZ_1free(JNIEnv * _env, jclass _b, jlong arg) {
4794         LDKCResult_boolLightningErrorZ arg_conv = *(LDKCResult_boolLightningErrorZ*)arg;
4795         FREE((void*)arg);
4796         CResult_boolLightningErrorZ_free(arg_conv);
4797 }
4798
4799 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1boolLightningErrorZ_1ok(JNIEnv * _env, jclass _b, jboolean arg) {
4800         LDKCResult_boolLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_boolLightningErrorZ), "LDKCResult_boolLightningErrorZ");
4801         *ret_conv = CResult_boolLightningErrorZ_ok(arg);
4802         return (long)ret_conv;
4803 }
4804
4805 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1boolPeerHandleErrorZ_1err(JNIEnv * _env, jclass _b, jlong arg) {
4806         LDKPeerHandleError arg_conv = *(LDKPeerHandleError*)arg;
4807         FREE((void*)arg);
4808         LDKCResult_boolPeerHandleErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_boolPeerHandleErrorZ), "LDKCResult_boolPeerHandleErrorZ");
4809         *ret_conv = CResult_boolPeerHandleErrorZ_err(arg_conv);
4810         return (long)ret_conv;
4811 }
4812
4813 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1boolPeerHandleErrorZ_1free(JNIEnv * _env, jclass _b, jlong arg) {
4814         LDKCResult_boolPeerHandleErrorZ arg_conv = *(LDKCResult_boolPeerHandleErrorZ*)arg;
4815         FREE((void*)arg);
4816         CResult_boolPeerHandleErrorZ_free(arg_conv);
4817 }
4818
4819 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1boolPeerHandleErrorZ_1ok(JNIEnv * _env, jclass _b, jboolean arg) {
4820         LDKCResult_boolPeerHandleErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_boolPeerHandleErrorZ), "LDKCResult_boolPeerHandleErrorZ");
4821         *ret_conv = CResult_boolPeerHandleErrorZ_ok(arg);
4822         return (long)ret_conv;
4823 }
4824
4825 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1C2Tuple_1HTLCOutputInCommitmentSignatureZZ_1free(JNIEnv * _env, jclass _b, jlongArray arg) {
4826         LDKCVec_C2Tuple_HTLCOutputInCommitmentSignatureZZ arg_constr;
4827         arg_constr.datalen = (*_env)->GetArrayLength (_env, arg);
4828         if (arg_constr.datalen > 0)
4829                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKC2Tuple_HTLCOutputInCommitmentSignatureZ), "LDKCVec_C2Tuple_HTLCOutputInCommitmentSignatureZZ Elements");
4830         else
4831                 arg_constr.data = NULL;
4832         long* arg_vals = (*_env)->GetLongArrayElements (_env, arg, NULL);
4833         for (size_t q = 0; q < arg_constr.datalen; q++) {
4834                 long arr_conv_42 = arg_vals[q];
4835                 LDKC2Tuple_HTLCOutputInCommitmentSignatureZ arr_conv_42_conv = *(LDKC2Tuple_HTLCOutputInCommitmentSignatureZ*)arr_conv_42;
4836                 FREE((void*)arr_conv_42);
4837                 arg_constr.data[q] = arr_conv_42_conv;
4838         }
4839         (*_env)->ReleaseLongArrayElements (_env, arg, arg_vals, 0);
4840         CVec_C2Tuple_HTLCOutputInCommitmentSignatureZZ_free(arg_constr);
4841 }
4842
4843 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1C2Tuple_1TxidCVec_1TxOutZZZ_1free(JNIEnv * _env, jclass _b, jlongArray arg) {
4844         LDKCVec_C2Tuple_TxidCVec_TxOutZZZ arg_constr;
4845         arg_constr.datalen = (*_env)->GetArrayLength (_env, arg);
4846         if (arg_constr.datalen > 0)
4847                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKC2Tuple_TxidCVec_TxOutZZ), "LDKCVec_C2Tuple_TxidCVec_TxOutZZZ Elements");
4848         else
4849                 arg_constr.data = NULL;
4850         long* arg_vals = (*_env)->GetLongArrayElements (_env, arg, NULL);
4851         for (size_t b = 0; b < arg_constr.datalen; b++) {
4852                 long arr_conv_27 = arg_vals[b];
4853                 LDKC2Tuple_TxidCVec_TxOutZZ arr_conv_27_conv = *(LDKC2Tuple_TxidCVec_TxOutZZ*)arr_conv_27;
4854                 FREE((void*)arr_conv_27);
4855                 arg_constr.data[b] = arr_conv_27_conv;
4856         }
4857         (*_env)->ReleaseLongArrayElements (_env, arg, arg_vals, 0);
4858         CVec_C2Tuple_TxidCVec_TxOutZZZ_free(arg_constr);
4859 }
4860
4861 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1C2Tuple_1usizeTransactionZZ_1free(JNIEnv * _env, jclass _b, jlongArray arg) {
4862         LDKCVec_C2Tuple_usizeTransactionZZ arg_constr;
4863         arg_constr.datalen = (*_env)->GetArrayLength (_env, arg);
4864         if (arg_constr.datalen > 0)
4865                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKC2Tuple_usizeTransactionZ), "LDKCVec_C2Tuple_usizeTransactionZZ Elements");
4866         else
4867                 arg_constr.data = NULL;
4868         long* arg_vals = (*_env)->GetLongArrayElements (_env, arg, NULL);
4869         for (size_t d = 0; d < arg_constr.datalen; d++) {
4870                 long arr_conv_29 = arg_vals[d];
4871                 LDKC2Tuple_usizeTransactionZ arr_conv_29_conv = *(LDKC2Tuple_usizeTransactionZ*)arr_conv_29;
4872                 FREE((void*)arr_conv_29);
4873                 arg_constr.data[d] = arr_conv_29_conv;
4874         }
4875         (*_env)->ReleaseLongArrayElements (_env, arg, arg_vals, 0);
4876         CVec_C2Tuple_usizeTransactionZZ_free(arg_constr);
4877 }
4878
4879 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1C3Tuple_1ChannelAnnouncementChannelUpdateChannelUpdateZZ_1free(JNIEnv * _env, jclass _b, jlongArray arg) {
4880         LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ arg_constr;
4881         arg_constr.datalen = (*_env)->GetArrayLength (_env, arg);
4882         if (arg_constr.datalen > 0)
4883                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ), "LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ Elements");
4884         else
4885                 arg_constr.data = NULL;
4886         long* arg_vals = (*_env)->GetLongArrayElements (_env, arg, NULL);
4887         for (size_t l = 0; l < arg_constr.datalen; l++) {
4888                 long arr_conv_63 = arg_vals[l];
4889                 LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ arr_conv_63_conv = *(LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ*)arr_conv_63;
4890                 FREE((void*)arr_conv_63);
4891                 arg_constr.data[l] = arr_conv_63_conv;
4892         }
4893         (*_env)->ReleaseLongArrayElements (_env, arg, arg_vals, 0);
4894         CVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ_free(arg_constr);
4895 }
4896
4897 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1CVec_1RouteHopZZ_1free(JNIEnv * _env, jclass _b, jobjectArray arg) {
4898         LDKCVec_CVec_RouteHopZZ arg_constr;
4899         arg_constr.datalen = (*_env)->GetArrayLength (_env, arg);
4900         if (arg_constr.datalen > 0)
4901                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKCVec_RouteHopZ), "LDKCVec_CVec_RouteHopZZ Elements");
4902         else
4903                 arg_constr.data = NULL;
4904         for (size_t m = 0; m < arg_constr.datalen; m++) {
4905                 jobject arr_conv_12 = (*_env)->GetObjectArrayElement(_env, arg, m);
4906                 LDKCVec_RouteHopZ arr_conv_12_constr;
4907                 arr_conv_12_constr.datalen = (*_env)->GetArrayLength (_env, arr_conv_12);
4908                 if (arr_conv_12_constr.datalen > 0)
4909                         arr_conv_12_constr.data = MALLOC(arr_conv_12_constr.datalen * sizeof(LDKRouteHop), "LDKCVec_RouteHopZ Elements");
4910                 else
4911                         arr_conv_12_constr.data = NULL;
4912                 long* arr_conv_12_vals = (*_env)->GetLongArrayElements (_env, arr_conv_12, NULL);
4913                 for (size_t k = 0; k < arr_conv_12_constr.datalen; k++) {
4914                         long arr_conv_10 = arr_conv_12_vals[k];
4915                         LDKRouteHop arr_conv_10_conv;
4916                         arr_conv_10_conv.inner = (void*)(arr_conv_10 & (~1));
4917                         arr_conv_10_conv.is_owned = (arr_conv_10 & 1) || (arr_conv_10 == 0);
4918                         arr_conv_12_constr.data[k] = arr_conv_10_conv;
4919                 }
4920                 (*_env)->ReleaseLongArrayElements (_env, arr_conv_12, arr_conv_12_vals, 0);
4921                 arg_constr.data[m] = arr_conv_12_constr;
4922         }
4923         CVec_CVec_RouteHopZZ_free(arg_constr);
4924 }
4925
4926 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1ChannelDetailsZ_1free(JNIEnv * _env, jclass _b, jlongArray arg) {
4927         LDKCVec_ChannelDetailsZ arg_constr;
4928         arg_constr.datalen = (*_env)->GetArrayLength (_env, arg);
4929         if (arg_constr.datalen > 0)
4930                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKChannelDetails), "LDKCVec_ChannelDetailsZ Elements");
4931         else
4932                 arg_constr.data = NULL;
4933         long* arg_vals = (*_env)->GetLongArrayElements (_env, arg, NULL);
4934         for (size_t q = 0; q < arg_constr.datalen; q++) {
4935                 long arr_conv_16 = arg_vals[q];
4936                 LDKChannelDetails arr_conv_16_conv;
4937                 arr_conv_16_conv.inner = (void*)(arr_conv_16 & (~1));
4938                 arr_conv_16_conv.is_owned = (arr_conv_16 & 1) || (arr_conv_16 == 0);
4939                 arg_constr.data[q] = arr_conv_16_conv;
4940         }
4941         (*_env)->ReleaseLongArrayElements (_env, arg, arg_vals, 0);
4942         CVec_ChannelDetailsZ_free(arg_constr);
4943 }
4944
4945 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1ChannelMonitorZ_1free(JNIEnv * _env, jclass _b, jlongArray arg) {
4946         LDKCVec_ChannelMonitorZ arg_constr;
4947         arg_constr.datalen = (*_env)->GetArrayLength (_env, arg);
4948         if (arg_constr.datalen > 0)
4949                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKChannelMonitor), "LDKCVec_ChannelMonitorZ Elements");
4950         else
4951                 arg_constr.data = NULL;
4952         long* arg_vals = (*_env)->GetLongArrayElements (_env, arg, NULL);
4953         for (size_t q = 0; q < arg_constr.datalen; q++) {
4954                 long arr_conv_16 = arg_vals[q];
4955                 LDKChannelMonitor arr_conv_16_conv;
4956                 arr_conv_16_conv.inner = (void*)(arr_conv_16 & (~1));
4957                 arr_conv_16_conv.is_owned = (arr_conv_16 & 1) || (arr_conv_16 == 0);
4958                 arg_constr.data[q] = arr_conv_16_conv;
4959         }
4960         (*_env)->ReleaseLongArrayElements (_env, arg, arg_vals, 0);
4961         CVec_ChannelMonitorZ_free(arg_constr);
4962 }
4963
4964 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1EventZ_1free(JNIEnv * _env, jclass _b, jlongArray arg) {
4965         LDKCVec_EventZ arg_constr;
4966         arg_constr.datalen = (*_env)->GetArrayLength (_env, arg);
4967         if (arg_constr.datalen > 0)
4968                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKEvent), "LDKCVec_EventZ Elements");
4969         else
4970                 arg_constr.data = NULL;
4971         long* arg_vals = (*_env)->GetLongArrayElements (_env, arg, NULL);
4972         for (size_t h = 0; h < arg_constr.datalen; h++) {
4973                 long arr_conv_7 = arg_vals[h];
4974                 LDKEvent arr_conv_7_conv = *(LDKEvent*)arr_conv_7;
4975                 FREE((void*)arr_conv_7);
4976                 arg_constr.data[h] = arr_conv_7_conv;
4977         }
4978         (*_env)->ReleaseLongArrayElements (_env, arg, arg_vals, 0);
4979         CVec_EventZ_free(arg_constr);
4980 }
4981
4982 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1HTLCOutputInCommitmentZ_1free(JNIEnv * _env, jclass _b, jlongArray arg) {
4983         LDKCVec_HTLCOutputInCommitmentZ arg_constr;
4984         arg_constr.datalen = (*_env)->GetArrayLength (_env, arg);
4985         if (arg_constr.datalen > 0)
4986                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKHTLCOutputInCommitment), "LDKCVec_HTLCOutputInCommitmentZ Elements");
4987         else
4988                 arg_constr.data = NULL;
4989         long* arg_vals = (*_env)->GetLongArrayElements (_env, arg, NULL);
4990         for (size_t y = 0; y < arg_constr.datalen; y++) {
4991                 long arr_conv_24 = arg_vals[y];
4992                 LDKHTLCOutputInCommitment arr_conv_24_conv;
4993                 arr_conv_24_conv.inner = (void*)(arr_conv_24 & (~1));
4994                 arr_conv_24_conv.is_owned = (arr_conv_24 & 1) || (arr_conv_24 == 0);
4995                 arg_constr.data[y] = arr_conv_24_conv;
4996         }
4997         (*_env)->ReleaseLongArrayElements (_env, arg, arg_vals, 0);
4998         CVec_HTLCOutputInCommitmentZ_free(arg_constr);
4999 }
5000
5001 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1MessageSendEventZ_1free(JNIEnv * _env, jclass _b, jlongArray arg) {
5002         LDKCVec_MessageSendEventZ arg_constr;
5003         arg_constr.datalen = (*_env)->GetArrayLength (_env, arg);
5004         if (arg_constr.datalen > 0)
5005                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKMessageSendEvent), "LDKCVec_MessageSendEventZ Elements");
5006         else
5007                 arg_constr.data = NULL;
5008         long* arg_vals = (*_env)->GetLongArrayElements (_env, arg, NULL);
5009         for (size_t s = 0; s < arg_constr.datalen; s++) {
5010                 long arr_conv_18 = arg_vals[s];
5011                 LDKMessageSendEvent arr_conv_18_conv = *(LDKMessageSendEvent*)arr_conv_18;
5012                 FREE((void*)arr_conv_18);
5013                 arg_constr.data[s] = arr_conv_18_conv;
5014         }
5015         (*_env)->ReleaseLongArrayElements (_env, arg, arg_vals, 0);
5016         CVec_MessageSendEventZ_free(arg_constr);
5017 }
5018
5019 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1MonitorEventZ_1free(JNIEnv * _env, jclass _b, jlongArray arg) {
5020         LDKCVec_MonitorEventZ arg_constr;
5021         arg_constr.datalen = (*_env)->GetArrayLength (_env, arg);
5022         if (arg_constr.datalen > 0)
5023                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKMonitorEvent), "LDKCVec_MonitorEventZ Elements");
5024         else
5025                 arg_constr.data = NULL;
5026         long* arg_vals = (*_env)->GetLongArrayElements (_env, arg, NULL);
5027         for (size_t o = 0; o < arg_constr.datalen; o++) {
5028                 long arr_conv_14 = arg_vals[o];
5029                 LDKMonitorEvent arr_conv_14_conv;
5030                 arr_conv_14_conv.inner = (void*)(arr_conv_14 & (~1));
5031                 arr_conv_14_conv.is_owned = (arr_conv_14 & 1) || (arr_conv_14 == 0);
5032                 arg_constr.data[o] = arr_conv_14_conv;
5033         }
5034         (*_env)->ReleaseLongArrayElements (_env, arg, arg_vals, 0);
5035         CVec_MonitorEventZ_free(arg_constr);
5036 }
5037
5038 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1NetAddressZ_1free(JNIEnv * _env, jclass _b, jlongArray arg) {
5039         LDKCVec_NetAddressZ arg_constr;
5040         arg_constr.datalen = (*_env)->GetArrayLength (_env, arg);
5041         if (arg_constr.datalen > 0)
5042                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKNetAddress), "LDKCVec_NetAddressZ Elements");
5043         else
5044                 arg_constr.data = NULL;
5045         long* arg_vals = (*_env)->GetLongArrayElements (_env, arg, NULL);
5046         for (size_t m = 0; m < arg_constr.datalen; m++) {
5047                 long arr_conv_12 = arg_vals[m];
5048                 LDKNetAddress arr_conv_12_conv = *(LDKNetAddress*)arr_conv_12;
5049                 FREE((void*)arr_conv_12);
5050                 arg_constr.data[m] = arr_conv_12_conv;
5051         }
5052         (*_env)->ReleaseLongArrayElements (_env, arg, arg_vals, 0);
5053         CVec_NetAddressZ_free(arg_constr);
5054 }
5055
5056 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1NodeAnnouncementZ_1free(JNIEnv * _env, jclass _b, jlongArray arg) {
5057         LDKCVec_NodeAnnouncementZ arg_constr;
5058         arg_constr.datalen = (*_env)->GetArrayLength (_env, arg);
5059         if (arg_constr.datalen > 0)
5060                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKNodeAnnouncement), "LDKCVec_NodeAnnouncementZ Elements");
5061         else
5062                 arg_constr.data = NULL;
5063         long* arg_vals = (*_env)->GetLongArrayElements (_env, arg, NULL);
5064         for (size_t s = 0; s < arg_constr.datalen; s++) {
5065                 long arr_conv_18 = arg_vals[s];
5066                 LDKNodeAnnouncement arr_conv_18_conv;
5067                 arr_conv_18_conv.inner = (void*)(arr_conv_18 & (~1));
5068                 arr_conv_18_conv.is_owned = (arr_conv_18 & 1) || (arr_conv_18 == 0);
5069                 arg_constr.data[s] = arr_conv_18_conv;
5070         }
5071         (*_env)->ReleaseLongArrayElements (_env, arg, arg_vals, 0);
5072         CVec_NodeAnnouncementZ_free(arg_constr);
5073 }
5074
5075 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1PublicKeyZ_1free(JNIEnv * _env, jclass _b, jobjectArray arg) {
5076         LDKCVec_PublicKeyZ arg_constr;
5077         arg_constr.datalen = (*_env)->GetArrayLength (_env, arg);
5078         if (arg_constr.datalen > 0)
5079                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKPublicKey), "LDKCVec_PublicKeyZ Elements");
5080         else
5081                 arg_constr.data = NULL;
5082         for (size_t i = 0; i < arg_constr.datalen; i++) {
5083                 jobject arr_conv_8 = (*_env)->GetObjectArrayElement(_env, arg, i);
5084                 LDKPublicKey arr_conv_8_ref;
5085                 CHECK((*_env)->GetArrayLength (_env, arr_conv_8) == 33);
5086                 (*_env)->GetByteArrayRegion (_env, arr_conv_8, 0, 33, arr_conv_8_ref.compressed_form);
5087                 arg_constr.data[i] = arr_conv_8_ref;
5088         }
5089         CVec_PublicKeyZ_free(arg_constr);
5090 }
5091
5092 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1RouteHintZ_1free(JNIEnv * _env, jclass _b, jlongArray arg) {
5093         LDKCVec_RouteHintZ arg_constr;
5094         arg_constr.datalen = (*_env)->GetArrayLength (_env, arg);
5095         if (arg_constr.datalen > 0)
5096                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKRouteHint), "LDKCVec_RouteHintZ Elements");
5097         else
5098                 arg_constr.data = NULL;
5099         long* arg_vals = (*_env)->GetLongArrayElements (_env, arg, NULL);
5100         for (size_t l = 0; l < arg_constr.datalen; l++) {
5101                 long arr_conv_11 = arg_vals[l];
5102                 LDKRouteHint arr_conv_11_conv;
5103                 arr_conv_11_conv.inner = (void*)(arr_conv_11 & (~1));
5104                 arr_conv_11_conv.is_owned = (arr_conv_11 & 1) || (arr_conv_11 == 0);
5105                 arg_constr.data[l] = arr_conv_11_conv;
5106         }
5107         (*_env)->ReleaseLongArrayElements (_env, arg, arg_vals, 0);
5108         CVec_RouteHintZ_free(arg_constr);
5109 }
5110
5111 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1RouteHopZ_1free(JNIEnv * _env, jclass _b, jlongArray arg) {
5112         LDKCVec_RouteHopZ arg_constr;
5113         arg_constr.datalen = (*_env)->GetArrayLength (_env, arg);
5114         if (arg_constr.datalen > 0)
5115                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKRouteHop), "LDKCVec_RouteHopZ Elements");
5116         else
5117                 arg_constr.data = NULL;
5118         long* arg_vals = (*_env)->GetLongArrayElements (_env, arg, NULL);
5119         for (size_t k = 0; k < arg_constr.datalen; k++) {
5120                 long arr_conv_10 = arg_vals[k];
5121                 LDKRouteHop arr_conv_10_conv;
5122                 arr_conv_10_conv.inner = (void*)(arr_conv_10 & (~1));
5123                 arr_conv_10_conv.is_owned = (arr_conv_10 & 1) || (arr_conv_10 == 0);
5124                 arg_constr.data[k] = arr_conv_10_conv;
5125         }
5126         (*_env)->ReleaseLongArrayElements (_env, arg, arg_vals, 0);
5127         CVec_RouteHopZ_free(arg_constr);
5128 }
5129
5130 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1SignatureZ_1free(JNIEnv * _env, jclass _b, jobjectArray arg) {
5131         LDKCVec_SignatureZ arg_constr;
5132         arg_constr.datalen = (*_env)->GetArrayLength (_env, arg);
5133         if (arg_constr.datalen > 0)
5134                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKSignature), "LDKCVec_SignatureZ Elements");
5135         else
5136                 arg_constr.data = NULL;
5137         for (size_t i = 0; i < arg_constr.datalen; i++) {
5138                 jobject arr_conv_8 = (*_env)->GetObjectArrayElement(_env, arg, i);
5139                 LDKSignature arr_conv_8_ref;
5140                 CHECK((*_env)->GetArrayLength (_env, arr_conv_8) == 64);
5141                 (*_env)->GetByteArrayRegion (_env, arr_conv_8, 0, 64, arr_conv_8_ref.compact_form);
5142                 arg_constr.data[i] = arr_conv_8_ref;
5143         }
5144         CVec_SignatureZ_free(arg_constr);
5145 }
5146
5147 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1SpendableOutputDescriptorZ_1free(JNIEnv * _env, jclass _b, jlongArray arg) {
5148         LDKCVec_SpendableOutputDescriptorZ arg_constr;
5149         arg_constr.datalen = (*_env)->GetArrayLength (_env, arg);
5150         if (arg_constr.datalen > 0)
5151                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKSpendableOutputDescriptor), "LDKCVec_SpendableOutputDescriptorZ Elements");
5152         else
5153                 arg_constr.data = NULL;
5154         long* arg_vals = (*_env)->GetLongArrayElements (_env, arg, NULL);
5155         for (size_t b = 0; b < arg_constr.datalen; b++) {
5156                 long arr_conv_27 = arg_vals[b];
5157                 LDKSpendableOutputDescriptor arr_conv_27_conv = *(LDKSpendableOutputDescriptor*)arr_conv_27;
5158                 FREE((void*)arr_conv_27);
5159                 arg_constr.data[b] = arr_conv_27_conv;
5160         }
5161         (*_env)->ReleaseLongArrayElements (_env, arg, arg_vals, 0);
5162         CVec_SpendableOutputDescriptorZ_free(arg_constr);
5163 }
5164
5165 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1TransactionZ_1free(JNIEnv * _env, jclass _b, jlongArray arg) {
5166         LDKCVec_TransactionZ arg_constr;
5167         arg_constr.datalen = (*_env)->GetArrayLength (_env, arg);
5168         if (arg_constr.datalen > 0)
5169                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKTransaction), "LDKCVec_TransactionZ Elements");
5170         else
5171                 arg_constr.data = NULL;
5172         long* arg_vals = (*_env)->GetLongArrayElements (_env, arg, NULL);
5173         for (size_t n = 0; n < arg_constr.datalen; n++) {
5174                 long arr_conv_13 = arg_vals[n];
5175                 LDKTransaction arr_conv_13_conv = *(LDKTransaction*)arr_conv_13;
5176                 arg_constr.data[n] = arr_conv_13_conv;
5177         }
5178         (*_env)->ReleaseLongArrayElements (_env, arg, arg_vals, 0);
5179         CVec_TransactionZ_free(arg_constr);
5180 }
5181
5182 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1TxOutZ_1free(JNIEnv * _env, jclass _b, jlongArray arg) {
5183         LDKCVec_TxOutZ arg_constr;
5184         arg_constr.datalen = (*_env)->GetArrayLength (_env, arg);
5185         if (arg_constr.datalen > 0)
5186                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKTxOut), "LDKCVec_TxOutZ Elements");
5187         else
5188                 arg_constr.data = NULL;
5189         long* arg_vals = (*_env)->GetLongArrayElements (_env, arg, NULL);
5190         for (size_t h = 0; h < arg_constr.datalen; h++) {
5191                 long arr_conv_7 = arg_vals[h];
5192                 LDKTxOut arr_conv_7_conv = *(LDKTxOut*)arr_conv_7;
5193                 FREE((void*)arr_conv_7);
5194                 arg_constr.data[h] = arr_conv_7_conv;
5195         }
5196         (*_env)->ReleaseLongArrayElements (_env, arg, arg_vals, 0);
5197         CVec_TxOutZ_free(arg_constr);
5198 }
5199
5200 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1UpdateAddHTLCZ_1free(JNIEnv * _env, jclass _b, jlongArray arg) {
5201         LDKCVec_UpdateAddHTLCZ arg_constr;
5202         arg_constr.datalen = (*_env)->GetArrayLength (_env, arg);
5203         if (arg_constr.datalen > 0)
5204                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKUpdateAddHTLC), "LDKCVec_UpdateAddHTLCZ Elements");
5205         else
5206                 arg_constr.data = NULL;
5207         long* arg_vals = (*_env)->GetLongArrayElements (_env, arg, NULL);
5208         for (size_t p = 0; p < arg_constr.datalen; p++) {
5209                 long arr_conv_15 = arg_vals[p];
5210                 LDKUpdateAddHTLC arr_conv_15_conv;
5211                 arr_conv_15_conv.inner = (void*)(arr_conv_15 & (~1));
5212                 arr_conv_15_conv.is_owned = (arr_conv_15 & 1) || (arr_conv_15 == 0);
5213                 arg_constr.data[p] = arr_conv_15_conv;
5214         }
5215         (*_env)->ReleaseLongArrayElements (_env, arg, arg_vals, 0);
5216         CVec_UpdateAddHTLCZ_free(arg_constr);
5217 }
5218
5219 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1UpdateFailHTLCZ_1free(JNIEnv * _env, jclass _b, jlongArray arg) {
5220         LDKCVec_UpdateFailHTLCZ arg_constr;
5221         arg_constr.datalen = (*_env)->GetArrayLength (_env, arg);
5222         if (arg_constr.datalen > 0)
5223                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKUpdateFailHTLC), "LDKCVec_UpdateFailHTLCZ Elements");
5224         else
5225                 arg_constr.data = NULL;
5226         long* arg_vals = (*_env)->GetLongArrayElements (_env, arg, NULL);
5227         for (size_t q = 0; q < arg_constr.datalen; q++) {
5228                 long arr_conv_16 = arg_vals[q];
5229                 LDKUpdateFailHTLC arr_conv_16_conv;
5230                 arr_conv_16_conv.inner = (void*)(arr_conv_16 & (~1));
5231                 arr_conv_16_conv.is_owned = (arr_conv_16 & 1) || (arr_conv_16 == 0);
5232                 arg_constr.data[q] = arr_conv_16_conv;
5233         }
5234         (*_env)->ReleaseLongArrayElements (_env, arg, arg_vals, 0);
5235         CVec_UpdateFailHTLCZ_free(arg_constr);
5236 }
5237
5238 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1UpdateFailMalformedHTLCZ_1free(JNIEnv * _env, jclass _b, jlongArray arg) {
5239         LDKCVec_UpdateFailMalformedHTLCZ arg_constr;
5240         arg_constr.datalen = (*_env)->GetArrayLength (_env, arg);
5241         if (arg_constr.datalen > 0)
5242                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKUpdateFailMalformedHTLC), "LDKCVec_UpdateFailMalformedHTLCZ Elements");
5243         else
5244                 arg_constr.data = NULL;
5245         long* arg_vals = (*_env)->GetLongArrayElements (_env, arg, NULL);
5246         for (size_t z = 0; z < arg_constr.datalen; z++) {
5247                 long arr_conv_25 = arg_vals[z];
5248                 LDKUpdateFailMalformedHTLC arr_conv_25_conv;
5249                 arr_conv_25_conv.inner = (void*)(arr_conv_25 & (~1));
5250                 arr_conv_25_conv.is_owned = (arr_conv_25 & 1) || (arr_conv_25 == 0);
5251                 arg_constr.data[z] = arr_conv_25_conv;
5252         }
5253         (*_env)->ReleaseLongArrayElements (_env, arg, arg_vals, 0);
5254         CVec_UpdateFailMalformedHTLCZ_free(arg_constr);
5255 }
5256
5257 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1UpdateFulfillHTLCZ_1free(JNIEnv * _env, jclass _b, jlongArray arg) {
5258         LDKCVec_UpdateFulfillHTLCZ arg_constr;
5259         arg_constr.datalen = (*_env)->GetArrayLength (_env, arg);
5260         if (arg_constr.datalen > 0)
5261                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKUpdateFulfillHTLC), "LDKCVec_UpdateFulfillHTLCZ Elements");
5262         else
5263                 arg_constr.data = NULL;
5264         long* arg_vals = (*_env)->GetLongArrayElements (_env, arg, NULL);
5265         for (size_t t = 0; t < arg_constr.datalen; t++) {
5266                 long arr_conv_19 = arg_vals[t];
5267                 LDKUpdateFulfillHTLC arr_conv_19_conv;
5268                 arr_conv_19_conv.inner = (void*)(arr_conv_19 & (~1));
5269                 arr_conv_19_conv.is_owned = (arr_conv_19 & 1) || (arr_conv_19 == 0);
5270                 arg_constr.data[t] = arr_conv_19_conv;
5271         }
5272         (*_env)->ReleaseLongArrayElements (_env, arg, arg_vals, 0);
5273         CVec_UpdateFulfillHTLCZ_free(arg_constr);
5274 }
5275
5276 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1u64Z_1free(JNIEnv * _env, jclass _b, jlongArray arg) {
5277         LDKCVec_u64Z arg_constr;
5278         arg_constr.datalen = (*_env)->GetArrayLength (_env, arg);
5279         if (arg_constr.datalen > 0)
5280                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(jlong), "LDKCVec_u64Z Elements");
5281         else
5282                 arg_constr.data = NULL;
5283         long* arg_vals = (*_env)->GetLongArrayElements (_env, arg, NULL);
5284         for (size_t g = 0; g < arg_constr.datalen; g++) {
5285                 long arr_conv_6 = arg_vals[g];
5286                 arg_constr.data[g] = arr_conv_6;
5287         }
5288         (*_env)->ReleaseLongArrayElements (_env, arg, arg_vals, 0);
5289         CVec_u64Z_free(arg_constr);
5290 }
5291
5292 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1u8Z_1free(JNIEnv * _env, jclass _b, jbyteArray arg) {
5293         LDKCVec_u8Z arg_ref;
5294         arg_ref.data = (*_env)->GetByteArrayElements (_env, arg, NULL);
5295         arg_ref.datalen = (*_env)->GetArrayLength (_env, arg);
5296         CVec_u8Z_free(arg_ref);
5297         (*_env)->ReleaseByteArrayElements(_env, arg, (int8_t*)arg_ref.data, 0);
5298 }
5299
5300 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Transaction_1free(JNIEnv * _env, jclass _b, jlong _res) {
5301         LDKTransaction _res_conv = *(LDKTransaction*)_res;
5302         Transaction_free(_res_conv);
5303 }
5304
5305 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_TxOut_1free(JNIEnv * _env, jclass _b, jlong _res) {
5306         LDKTxOut _res_conv = *(LDKTxOut*)_res;
5307         FREE((void*)_res);
5308         TxOut_free(_res_conv);
5309 }
5310
5311 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_C2Tuple_1usizeTransactionZ_1new(JNIEnv * _env, jclass _b, jlong a, jlong b) {
5312         LDKTransaction b_conv = *(LDKTransaction*)b;
5313         LDKC2Tuple_usizeTransactionZ* ret_ref = MALLOC(sizeof(LDKC2Tuple_usizeTransactionZ), "LDKC2Tuple_usizeTransactionZ");
5314         *ret_ref = C2Tuple_usizeTransactionZ_new(a, b_conv);
5315         return (long)ret_ref;
5316 }
5317
5318 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1NoneChannelMonitorUpdateErrZ_1ok(JNIEnv * _env, jclass _b) {
5319         LDKCResult_NoneChannelMonitorUpdateErrZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneChannelMonitorUpdateErrZ), "LDKCResult_NoneChannelMonitorUpdateErrZ");
5320         *ret_conv = CResult_NoneChannelMonitorUpdateErrZ_ok();
5321         return (long)ret_conv;
5322 }
5323
5324 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1NoneMonitorUpdateErrorZ_1ok(JNIEnv * _env, jclass _b) {
5325         LDKCResult_NoneMonitorUpdateErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneMonitorUpdateErrorZ), "LDKCResult_NoneMonitorUpdateErrorZ");
5326         *ret_conv = CResult_NoneMonitorUpdateErrorZ_ok();
5327         return (long)ret_conv;
5328 }
5329
5330 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_C2Tuple_1OutPointScriptZ_1new(JNIEnv * _env, jclass _b, jlong a, jbyteArray b) {
5331         LDKOutPoint a_conv;
5332         a_conv.inner = (void*)(a & (~1));
5333         a_conv.is_owned = (a & 1) || (a == 0);
5334         if (a_conv.inner != NULL)
5335                 a_conv = OutPoint_clone(&a_conv);
5336         LDKCVec_u8Z b_ref;
5337         b_ref.data = (*_env)->GetByteArrayElements (_env, b, NULL);
5338         b_ref.datalen = (*_env)->GetArrayLength (_env, b);
5339         LDKC2Tuple_OutPointScriptZ* ret_ref = MALLOC(sizeof(LDKC2Tuple_OutPointScriptZ), "LDKC2Tuple_OutPointScriptZ");
5340         *ret_ref = C2Tuple_OutPointScriptZ_new(a_conv, b_ref);
5341         (*_env)->ReleaseByteArrayElements(_env, b, (int8_t*)b_ref.data, 0);
5342         return (long)ret_ref;
5343 }
5344
5345 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_C2Tuple_1TxidCVec_1TxOutZZ_1new(JNIEnv * _env, jclass _b, jbyteArray a, jlongArray b) {
5346         LDKThirtyTwoBytes a_ref;
5347         CHECK((*_env)->GetArrayLength (_env, a) == 32);
5348         (*_env)->GetByteArrayRegion (_env, a, 0, 32, a_ref.data);
5349         LDKCVec_TxOutZ b_constr;
5350         b_constr.datalen = (*_env)->GetArrayLength (_env, b);
5351         if (b_constr.datalen > 0)
5352                 b_constr.data = MALLOC(b_constr.datalen * sizeof(LDKTxOut), "LDKCVec_TxOutZ Elements");
5353         else
5354                 b_constr.data = NULL;
5355         long* b_vals = (*_env)->GetLongArrayElements (_env, b, NULL);
5356         for (size_t h = 0; h < b_constr.datalen; h++) {
5357                 long arr_conv_7 = b_vals[h];
5358                 LDKTxOut arr_conv_7_conv = *(LDKTxOut*)arr_conv_7;
5359                 FREE((void*)arr_conv_7);
5360                 b_constr.data[h] = arr_conv_7_conv;
5361         }
5362         (*_env)->ReleaseLongArrayElements (_env, b, b_vals, 0);
5363         LDKC2Tuple_TxidCVec_TxOutZZ* ret_ref = MALLOC(sizeof(LDKC2Tuple_TxidCVec_TxOutZZ), "LDKC2Tuple_TxidCVec_TxOutZZ");
5364         *ret_ref = C2Tuple_TxidCVec_TxOutZZ_new(a_ref, b_constr);
5365         return (long)ret_ref;
5366 }
5367
5368 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_C2Tuple_1u64u64Z_1new(JNIEnv * _env, jclass _b, jlong a, jlong b) {
5369         LDKC2Tuple_u64u64Z* ret_ref = MALLOC(sizeof(LDKC2Tuple_u64u64Z), "LDKC2Tuple_u64u64Z");
5370         *ret_ref = C2Tuple_u64u64Z_new(a, b);
5371         return (long)ret_ref;
5372 }
5373
5374 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_C2Tuple_1SignatureCVec_1SignatureZZ_1new(JNIEnv * _env, jclass _b, jbyteArray a, jobjectArray b) {
5375         LDKSignature a_ref;
5376         CHECK((*_env)->GetArrayLength (_env, a) == 64);
5377         (*_env)->GetByteArrayRegion (_env, a, 0, 64, a_ref.compact_form);
5378         LDKCVec_SignatureZ b_constr;
5379         b_constr.datalen = (*_env)->GetArrayLength (_env, b);
5380         if (b_constr.datalen > 0)
5381                 b_constr.data = MALLOC(b_constr.datalen * sizeof(LDKSignature), "LDKCVec_SignatureZ Elements");
5382         else
5383                 b_constr.data = NULL;
5384         for (size_t i = 0; i < b_constr.datalen; i++) {
5385                 jobject arr_conv_8 = (*_env)->GetObjectArrayElement(_env, b, i);
5386                 LDKSignature arr_conv_8_ref;
5387                 CHECK((*_env)->GetArrayLength (_env, arr_conv_8) == 64);
5388                 (*_env)->GetByteArrayRegion (_env, arr_conv_8, 0, 64, arr_conv_8_ref.compact_form);
5389                 b_constr.data[i] = arr_conv_8_ref;
5390         }
5391         LDKC2Tuple_SignatureCVec_SignatureZZ* ret_ref = MALLOC(sizeof(LDKC2Tuple_SignatureCVec_SignatureZZ), "LDKC2Tuple_SignatureCVec_SignatureZZ");
5392         *ret_ref = C2Tuple_SignatureCVec_SignatureZZ_new(a_ref, b_constr);
5393         return (long)ret_ref;
5394 }
5395
5396 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1C2Tuple_1SignatureCVec_1SignatureZZNoneZ_1err(JNIEnv * _env, jclass _b) {
5397         LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ), "LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ");
5398         *ret_conv = CResult_C2Tuple_SignatureCVec_SignatureZZNoneZ_err();
5399         return (long)ret_conv;
5400 }
5401
5402 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1SignatureNoneZ_1err(JNIEnv * _env, jclass _b) {
5403         LDKCResult_SignatureNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_SignatureNoneZ), "LDKCResult_SignatureNoneZ");
5404         *ret_conv = CResult_SignatureNoneZ_err();
5405         return (long)ret_conv;
5406 }
5407
5408 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1CVec_1SignatureZNoneZ_1err(JNIEnv * _env, jclass _b) {
5409         LDKCResult_CVec_SignatureZNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_CVec_SignatureZNoneZ), "LDKCResult_CVec_SignatureZNoneZ");
5410         *ret_conv = CResult_CVec_SignatureZNoneZ_err();
5411         return (long)ret_conv;
5412 }
5413
5414 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1NoneAPIErrorZ_1ok(JNIEnv * _env, jclass _b) {
5415         LDKCResult_NoneAPIErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneAPIErrorZ), "LDKCResult_NoneAPIErrorZ");
5416         *ret_conv = CResult_NoneAPIErrorZ_ok();
5417         return (long)ret_conv;
5418 }
5419
5420 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1NonePaymentSendFailureZ_1ok(JNIEnv * _env, jclass _b) {
5421         LDKCResult_NonePaymentSendFailureZ* ret_conv = MALLOC(sizeof(LDKCResult_NonePaymentSendFailureZ), "LDKCResult_NonePaymentSendFailureZ");
5422         *ret_conv = CResult_NonePaymentSendFailureZ_ok();
5423         return (long)ret_conv;
5424 }
5425
5426 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_C3Tuple_1ChannelAnnouncementChannelUpdateChannelUpdateZ_1new(JNIEnv * _env, jclass _b, jlong a, jlong b, jlong c) {
5427         LDKChannelAnnouncement a_conv;
5428         a_conv.inner = (void*)(a & (~1));
5429         a_conv.is_owned = (a & 1) || (a == 0);
5430         if (a_conv.inner != NULL)
5431                 a_conv = ChannelAnnouncement_clone(&a_conv);
5432         LDKChannelUpdate b_conv;
5433         b_conv.inner = (void*)(b & (~1));
5434         b_conv.is_owned = (b & 1) || (b == 0);
5435         if (b_conv.inner != NULL)
5436                 b_conv = ChannelUpdate_clone(&b_conv);
5437         LDKChannelUpdate c_conv;
5438         c_conv.inner = (void*)(c & (~1));
5439         c_conv.is_owned = (c & 1) || (c == 0);
5440         if (c_conv.inner != NULL)
5441                 c_conv = ChannelUpdate_clone(&c_conv);
5442         LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ* ret_ref = MALLOC(sizeof(LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ), "LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ");
5443         *ret_ref = C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ_new(a_conv, b_conv, c_conv);
5444         return (long)ret_ref;
5445 }
5446
5447 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1NonePeerHandleErrorZ_1ok(JNIEnv * _env, jclass _b) {
5448         LDKCResult_NonePeerHandleErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NonePeerHandleErrorZ), "LDKCResult_NonePeerHandleErrorZ");
5449         *ret_conv = CResult_NonePeerHandleErrorZ_ok();
5450         return (long)ret_conv;
5451 }
5452
5453 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_C2Tuple_1HTLCOutputInCommitmentSignatureZ_1new(JNIEnv * _env, jclass _b, jlong a, jbyteArray b) {
5454         LDKHTLCOutputInCommitment a_conv;
5455         a_conv.inner = (void*)(a & (~1));
5456         a_conv.is_owned = (a & 1) || (a == 0);
5457         if (a_conv.inner != NULL)
5458                 a_conv = HTLCOutputInCommitment_clone(&a_conv);
5459         LDKSignature b_ref;
5460         CHECK((*_env)->GetArrayLength (_env, b) == 64);
5461         (*_env)->GetByteArrayRegion (_env, b, 0, 64, b_ref.compact_form);
5462         LDKC2Tuple_HTLCOutputInCommitmentSignatureZ* ret_ref = MALLOC(sizeof(LDKC2Tuple_HTLCOutputInCommitmentSignatureZ), "LDKC2Tuple_HTLCOutputInCommitmentSignatureZ");
5463         *ret_ref = C2Tuple_HTLCOutputInCommitmentSignatureZ_new(a_conv, b_ref);
5464         return (long)ret_ref;
5465 }
5466
5467 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Event_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
5468         LDKEvent this_ptr_conv = *(LDKEvent*)this_ptr;
5469         FREE((void*)this_ptr);
5470         Event_free(this_ptr_conv);
5471 }
5472
5473 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_Event_1clone(JNIEnv * _env, jclass _b, jlong orig) {
5474         LDKEvent* orig_conv = (LDKEvent*)orig;
5475         LDKEvent *ret_copy = MALLOC(sizeof(LDKEvent), "LDKEvent");
5476         *ret_copy = Event_clone(orig_conv);
5477         long ret_ref = (long)ret_copy;
5478         return ret_ref;
5479 }
5480
5481 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_MessageSendEvent_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
5482         LDKMessageSendEvent this_ptr_conv = *(LDKMessageSendEvent*)this_ptr;
5483         FREE((void*)this_ptr);
5484         MessageSendEvent_free(this_ptr_conv);
5485 }
5486
5487 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_MessageSendEvent_1clone(JNIEnv * _env, jclass _b, jlong orig) {
5488         LDKMessageSendEvent* orig_conv = (LDKMessageSendEvent*)orig;
5489         LDKMessageSendEvent *ret_copy = MALLOC(sizeof(LDKMessageSendEvent), "LDKMessageSendEvent");
5490         *ret_copy = MessageSendEvent_clone(orig_conv);
5491         long ret_ref = (long)ret_copy;
5492         return ret_ref;
5493 }
5494
5495 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_MessageSendEventsProvider_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
5496         LDKMessageSendEventsProvider this_ptr_conv = *(LDKMessageSendEventsProvider*)this_ptr;
5497         FREE((void*)this_ptr);
5498         MessageSendEventsProvider_free(this_ptr_conv);
5499 }
5500
5501 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_EventsProvider_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
5502         LDKEventsProvider this_ptr_conv = *(LDKEventsProvider*)this_ptr;
5503         FREE((void*)this_ptr);
5504         EventsProvider_free(this_ptr_conv);
5505 }
5506
5507 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_APIError_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
5508         LDKAPIError this_ptr_conv = *(LDKAPIError*)this_ptr;
5509         FREE((void*)this_ptr);
5510         APIError_free(this_ptr_conv);
5511 }
5512
5513 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_APIError_1clone(JNIEnv * _env, jclass _b, jlong orig) {
5514         LDKAPIError* orig_conv = (LDKAPIError*)orig;
5515         LDKAPIError *ret_copy = MALLOC(sizeof(LDKAPIError), "LDKAPIError");
5516         *ret_copy = APIError_clone(orig_conv);
5517         long ret_ref = (long)ret_copy;
5518         return ret_ref;
5519 }
5520
5521 JNIEXPORT jclass JNICALL Java_org_ldk_impl_bindings_Level_1clone(JNIEnv * _env, jclass _b, jlong orig) {
5522         LDKLevel* orig_conv = (LDKLevel*)orig;
5523         jclass ret_conv = LDKLevel_to_java(_env, Level_clone(orig_conv));
5524         return ret_conv;
5525 }
5526
5527 JNIEXPORT jclass JNICALL Java_org_ldk_impl_bindings_Level_1max(JNIEnv * _env, jclass _b) {
5528         jclass ret_conv = LDKLevel_to_java(_env, Level_max());
5529         return ret_conv;
5530 }
5531
5532 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Logger_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
5533         LDKLogger this_ptr_conv = *(LDKLogger*)this_ptr;
5534         FREE((void*)this_ptr);
5535         Logger_free(this_ptr_conv);
5536 }
5537
5538 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeConfig_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
5539         LDKChannelHandshakeConfig this_ptr_conv;
5540         this_ptr_conv.inner = (void*)(this_ptr & (~1));
5541         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
5542         ChannelHandshakeConfig_free(this_ptr_conv);
5543 }
5544
5545 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeConfig_1clone(JNIEnv * _env, jclass _b, jlong orig) {
5546         LDKChannelHandshakeConfig orig_conv;
5547         orig_conv.inner = (void*)(orig & (~1));
5548         orig_conv.is_owned = (orig & 1) || (orig == 0);
5549         LDKChannelHandshakeConfig ret_var = ChannelHandshakeConfig_clone(&orig_conv);
5550         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
5551         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
5552         long ret_ref = (long)ret_var.inner;
5553         if (ret_var.is_owned) {
5554                 ret_ref |= 1;
5555         }
5556         return ret_ref;
5557 }
5558
5559 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeConfig_1get_1minimum_1depth(JNIEnv * _env, jclass _b, jlong this_ptr) {
5560         LDKChannelHandshakeConfig this_ptr_conv;
5561         this_ptr_conv.inner = (void*)(this_ptr & (~1));
5562         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
5563         jint ret_val = ChannelHandshakeConfig_get_minimum_depth(&this_ptr_conv);
5564         return ret_val;
5565 }
5566
5567 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeConfig_1set_1minimum_1depth(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
5568         LDKChannelHandshakeConfig this_ptr_conv;
5569         this_ptr_conv.inner = (void*)(this_ptr & (~1));
5570         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
5571         ChannelHandshakeConfig_set_minimum_depth(&this_ptr_conv, val);
5572 }
5573
5574 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeConfig_1get_1our_1to_1self_1delay(JNIEnv * _env, jclass _b, jlong this_ptr) {
5575         LDKChannelHandshakeConfig this_ptr_conv;
5576         this_ptr_conv.inner = (void*)(this_ptr & (~1));
5577         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
5578         jshort ret_val = ChannelHandshakeConfig_get_our_to_self_delay(&this_ptr_conv);
5579         return ret_val;
5580 }
5581
5582 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeConfig_1set_1our_1to_1self_1delay(JNIEnv * _env, jclass _b, jlong this_ptr, jshort val) {
5583         LDKChannelHandshakeConfig this_ptr_conv;
5584         this_ptr_conv.inner = (void*)(this_ptr & (~1));
5585         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
5586         ChannelHandshakeConfig_set_our_to_self_delay(&this_ptr_conv, val);
5587 }
5588
5589 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeConfig_1get_1our_1htlc_1minimum_1msat(JNIEnv * _env, jclass _b, jlong this_ptr) {
5590         LDKChannelHandshakeConfig this_ptr_conv;
5591         this_ptr_conv.inner = (void*)(this_ptr & (~1));
5592         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
5593         jlong ret_val = ChannelHandshakeConfig_get_our_htlc_minimum_msat(&this_ptr_conv);
5594         return ret_val;
5595 }
5596
5597 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeConfig_1set_1our_1htlc_1minimum_1msat(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
5598         LDKChannelHandshakeConfig this_ptr_conv;
5599         this_ptr_conv.inner = (void*)(this_ptr & (~1));
5600         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
5601         ChannelHandshakeConfig_set_our_htlc_minimum_msat(&this_ptr_conv, val);
5602 }
5603
5604 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) {
5605         LDKChannelHandshakeConfig ret_var = ChannelHandshakeConfig_new(minimum_depth_arg, our_to_self_delay_arg, our_htlc_minimum_msat_arg);
5606         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
5607         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
5608         long ret_ref = (long)ret_var.inner;
5609         if (ret_var.is_owned) {
5610                 ret_ref |= 1;
5611         }
5612         return ret_ref;
5613 }
5614
5615 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeConfig_1default(JNIEnv * _env, jclass _b) {
5616         LDKChannelHandshakeConfig ret_var = ChannelHandshakeConfig_default();
5617         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
5618         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
5619         long ret_ref = (long)ret_var.inner;
5620         if (ret_var.is_owned) {
5621                 ret_ref |= 1;
5622         }
5623         return ret_ref;
5624 }
5625
5626 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
5627         LDKChannelHandshakeLimits this_ptr_conv;
5628         this_ptr_conv.inner = (void*)(this_ptr & (~1));
5629         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
5630         ChannelHandshakeLimits_free(this_ptr_conv);
5631 }
5632
5633 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1clone(JNIEnv * _env, jclass _b, jlong orig) {
5634         LDKChannelHandshakeLimits orig_conv;
5635         orig_conv.inner = (void*)(orig & (~1));
5636         orig_conv.is_owned = (orig & 1) || (orig == 0);
5637         LDKChannelHandshakeLimits ret_var = ChannelHandshakeLimits_clone(&orig_conv);
5638         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
5639         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
5640         long ret_ref = (long)ret_var.inner;
5641         if (ret_var.is_owned) {
5642                 ret_ref |= 1;
5643         }
5644         return ret_ref;
5645 }
5646
5647 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1get_1min_1funding_1satoshis(JNIEnv * _env, jclass _b, jlong this_ptr) {
5648         LDKChannelHandshakeLimits this_ptr_conv;
5649         this_ptr_conv.inner = (void*)(this_ptr & (~1));
5650         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
5651         jlong ret_val = ChannelHandshakeLimits_get_min_funding_satoshis(&this_ptr_conv);
5652         return ret_val;
5653 }
5654
5655 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1set_1min_1funding_1satoshis(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
5656         LDKChannelHandshakeLimits this_ptr_conv;
5657         this_ptr_conv.inner = (void*)(this_ptr & (~1));
5658         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
5659         ChannelHandshakeLimits_set_min_funding_satoshis(&this_ptr_conv, val);
5660 }
5661
5662 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1get_1max_1htlc_1minimum_1msat(JNIEnv * _env, jclass _b, jlong this_ptr) {
5663         LDKChannelHandshakeLimits this_ptr_conv;
5664         this_ptr_conv.inner = (void*)(this_ptr & (~1));
5665         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
5666         jlong ret_val = ChannelHandshakeLimits_get_max_htlc_minimum_msat(&this_ptr_conv);
5667         return ret_val;
5668 }
5669
5670 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1set_1max_1htlc_1minimum_1msat(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
5671         LDKChannelHandshakeLimits this_ptr_conv;
5672         this_ptr_conv.inner = (void*)(this_ptr & (~1));
5673         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
5674         ChannelHandshakeLimits_set_max_htlc_minimum_msat(&this_ptr_conv, val);
5675 }
5676
5677 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1get_1min_1max_1htlc_1value_1in_1flight_1msat(JNIEnv * _env, jclass _b, jlong this_ptr) {
5678         LDKChannelHandshakeLimits this_ptr_conv;
5679         this_ptr_conv.inner = (void*)(this_ptr & (~1));
5680         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
5681         jlong ret_val = ChannelHandshakeLimits_get_min_max_htlc_value_in_flight_msat(&this_ptr_conv);
5682         return ret_val;
5683 }
5684
5685 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) {
5686         LDKChannelHandshakeLimits this_ptr_conv;
5687         this_ptr_conv.inner = (void*)(this_ptr & (~1));
5688         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
5689         ChannelHandshakeLimits_set_min_max_htlc_value_in_flight_msat(&this_ptr_conv, val);
5690 }
5691
5692 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1get_1max_1channel_1reserve_1satoshis(JNIEnv * _env, jclass _b, jlong this_ptr) {
5693         LDKChannelHandshakeLimits this_ptr_conv;
5694         this_ptr_conv.inner = (void*)(this_ptr & (~1));
5695         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
5696         jlong ret_val = ChannelHandshakeLimits_get_max_channel_reserve_satoshis(&this_ptr_conv);
5697         return ret_val;
5698 }
5699
5700 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1set_1max_1channel_1reserve_1satoshis(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
5701         LDKChannelHandshakeLimits this_ptr_conv;
5702         this_ptr_conv.inner = (void*)(this_ptr & (~1));
5703         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
5704         ChannelHandshakeLimits_set_max_channel_reserve_satoshis(&this_ptr_conv, val);
5705 }
5706
5707 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1get_1min_1max_1accepted_1htlcs(JNIEnv * _env, jclass _b, jlong this_ptr) {
5708         LDKChannelHandshakeLimits this_ptr_conv;
5709         this_ptr_conv.inner = (void*)(this_ptr & (~1));
5710         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
5711         jshort ret_val = ChannelHandshakeLimits_get_min_max_accepted_htlcs(&this_ptr_conv);
5712         return ret_val;
5713 }
5714
5715 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1set_1min_1max_1accepted_1htlcs(JNIEnv * _env, jclass _b, jlong this_ptr, jshort val) {
5716         LDKChannelHandshakeLimits this_ptr_conv;
5717         this_ptr_conv.inner = (void*)(this_ptr & (~1));
5718         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
5719         ChannelHandshakeLimits_set_min_max_accepted_htlcs(&this_ptr_conv, val);
5720 }
5721
5722 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1get_1min_1dust_1limit_1satoshis(JNIEnv * _env, jclass _b, jlong this_ptr) {
5723         LDKChannelHandshakeLimits this_ptr_conv;
5724         this_ptr_conv.inner = (void*)(this_ptr & (~1));
5725         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
5726         jlong ret_val = ChannelHandshakeLimits_get_min_dust_limit_satoshis(&this_ptr_conv);
5727         return ret_val;
5728 }
5729
5730 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1set_1min_1dust_1limit_1satoshis(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
5731         LDKChannelHandshakeLimits this_ptr_conv;
5732         this_ptr_conv.inner = (void*)(this_ptr & (~1));
5733         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
5734         ChannelHandshakeLimits_set_min_dust_limit_satoshis(&this_ptr_conv, val);
5735 }
5736
5737 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1get_1max_1dust_1limit_1satoshis(JNIEnv * _env, jclass _b, jlong this_ptr) {
5738         LDKChannelHandshakeLimits this_ptr_conv;
5739         this_ptr_conv.inner = (void*)(this_ptr & (~1));
5740         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
5741         jlong ret_val = ChannelHandshakeLimits_get_max_dust_limit_satoshis(&this_ptr_conv);
5742         return ret_val;
5743 }
5744
5745 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1set_1max_1dust_1limit_1satoshis(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
5746         LDKChannelHandshakeLimits this_ptr_conv;
5747         this_ptr_conv.inner = (void*)(this_ptr & (~1));
5748         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
5749         ChannelHandshakeLimits_set_max_dust_limit_satoshis(&this_ptr_conv, val);
5750 }
5751
5752 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1get_1max_1minimum_1depth(JNIEnv * _env, jclass _b, jlong this_ptr) {
5753         LDKChannelHandshakeLimits this_ptr_conv;
5754         this_ptr_conv.inner = (void*)(this_ptr & (~1));
5755         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
5756         jint ret_val = ChannelHandshakeLimits_get_max_minimum_depth(&this_ptr_conv);
5757         return ret_val;
5758 }
5759
5760 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1set_1max_1minimum_1depth(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
5761         LDKChannelHandshakeLimits this_ptr_conv;
5762         this_ptr_conv.inner = (void*)(this_ptr & (~1));
5763         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
5764         ChannelHandshakeLimits_set_max_minimum_depth(&this_ptr_conv, val);
5765 }
5766
5767 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1get_1force_1announced_1channel_1preference(JNIEnv * _env, jclass _b, jlong this_ptr) {
5768         LDKChannelHandshakeLimits this_ptr_conv;
5769         this_ptr_conv.inner = (void*)(this_ptr & (~1));
5770         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
5771         jboolean ret_val = ChannelHandshakeLimits_get_force_announced_channel_preference(&this_ptr_conv);
5772         return ret_val;
5773 }
5774
5775 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1set_1force_1announced_1channel_1preference(JNIEnv * _env, jclass _b, jlong this_ptr, jboolean val) {
5776         LDKChannelHandshakeLimits this_ptr_conv;
5777         this_ptr_conv.inner = (void*)(this_ptr & (~1));
5778         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
5779         ChannelHandshakeLimits_set_force_announced_channel_preference(&this_ptr_conv, val);
5780 }
5781
5782 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1get_1their_1to_1self_1delay(JNIEnv * _env, jclass _b, jlong this_ptr) {
5783         LDKChannelHandshakeLimits this_ptr_conv;
5784         this_ptr_conv.inner = (void*)(this_ptr & (~1));
5785         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
5786         jshort ret_val = ChannelHandshakeLimits_get_their_to_self_delay(&this_ptr_conv);
5787         return ret_val;
5788 }
5789
5790 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1set_1their_1to_1self_1delay(JNIEnv * _env, jclass _b, jlong this_ptr, jshort val) {
5791         LDKChannelHandshakeLimits this_ptr_conv;
5792         this_ptr_conv.inner = (void*)(this_ptr & (~1));
5793         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
5794         ChannelHandshakeLimits_set_their_to_self_delay(&this_ptr_conv, val);
5795 }
5796
5797 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) {
5798         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);
5799         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
5800         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
5801         long ret_ref = (long)ret_var.inner;
5802         if (ret_var.is_owned) {
5803                 ret_ref |= 1;
5804         }
5805         return ret_ref;
5806 }
5807
5808 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1default(JNIEnv * _env, jclass _b) {
5809         LDKChannelHandshakeLimits ret_var = ChannelHandshakeLimits_default();
5810         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
5811         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
5812         long ret_ref = (long)ret_var.inner;
5813         if (ret_var.is_owned) {
5814                 ret_ref |= 1;
5815         }
5816         return ret_ref;
5817 }
5818
5819 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelConfig_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
5820         LDKChannelConfig this_ptr_conv;
5821         this_ptr_conv.inner = (void*)(this_ptr & (~1));
5822         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
5823         ChannelConfig_free(this_ptr_conv);
5824 }
5825
5826 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelConfig_1clone(JNIEnv * _env, jclass _b, jlong orig) {
5827         LDKChannelConfig orig_conv;
5828         orig_conv.inner = (void*)(orig & (~1));
5829         orig_conv.is_owned = (orig & 1) || (orig == 0);
5830         LDKChannelConfig ret_var = ChannelConfig_clone(&orig_conv);
5831         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
5832         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
5833         long ret_ref = (long)ret_var.inner;
5834         if (ret_var.is_owned) {
5835                 ret_ref |= 1;
5836         }
5837         return ret_ref;
5838 }
5839
5840 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_ChannelConfig_1get_1fee_1proportional_1millionths(JNIEnv * _env, jclass _b, jlong this_ptr) {
5841         LDKChannelConfig this_ptr_conv;
5842         this_ptr_conv.inner = (void*)(this_ptr & (~1));
5843         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
5844         jint ret_val = ChannelConfig_get_fee_proportional_millionths(&this_ptr_conv);
5845         return ret_val;
5846 }
5847
5848 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelConfig_1set_1fee_1proportional_1millionths(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
5849         LDKChannelConfig this_ptr_conv;
5850         this_ptr_conv.inner = (void*)(this_ptr & (~1));
5851         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
5852         ChannelConfig_set_fee_proportional_millionths(&this_ptr_conv, val);
5853 }
5854
5855 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_ChannelConfig_1get_1announced_1channel(JNIEnv * _env, jclass _b, jlong this_ptr) {
5856         LDKChannelConfig this_ptr_conv;
5857         this_ptr_conv.inner = (void*)(this_ptr & (~1));
5858         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
5859         jboolean ret_val = ChannelConfig_get_announced_channel(&this_ptr_conv);
5860         return ret_val;
5861 }
5862
5863 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelConfig_1set_1announced_1channel(JNIEnv * _env, jclass _b, jlong this_ptr, jboolean val) {
5864         LDKChannelConfig this_ptr_conv;
5865         this_ptr_conv.inner = (void*)(this_ptr & (~1));
5866         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
5867         ChannelConfig_set_announced_channel(&this_ptr_conv, val);
5868 }
5869
5870 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_ChannelConfig_1get_1commit_1upfront_1shutdown_1pubkey(JNIEnv * _env, jclass _b, jlong this_ptr) {
5871         LDKChannelConfig this_ptr_conv;
5872         this_ptr_conv.inner = (void*)(this_ptr & (~1));
5873         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
5874         jboolean ret_val = ChannelConfig_get_commit_upfront_shutdown_pubkey(&this_ptr_conv);
5875         return ret_val;
5876 }
5877
5878 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelConfig_1set_1commit_1upfront_1shutdown_1pubkey(JNIEnv * _env, jclass _b, jlong this_ptr, jboolean val) {
5879         LDKChannelConfig this_ptr_conv;
5880         this_ptr_conv.inner = (void*)(this_ptr & (~1));
5881         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
5882         ChannelConfig_set_commit_upfront_shutdown_pubkey(&this_ptr_conv, val);
5883 }
5884
5885 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) {
5886         LDKChannelConfig ret_var = ChannelConfig_new(fee_proportional_millionths_arg, announced_channel_arg, commit_upfront_shutdown_pubkey_arg);
5887         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
5888         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
5889         long ret_ref = (long)ret_var.inner;
5890         if (ret_var.is_owned) {
5891                 ret_ref |= 1;
5892         }
5893         return ret_ref;
5894 }
5895
5896 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelConfig_1default(JNIEnv * _env, jclass _b) {
5897         LDKChannelConfig ret_var = ChannelConfig_default();
5898         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
5899         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
5900         long ret_ref = (long)ret_var.inner;
5901         if (ret_var.is_owned) {
5902                 ret_ref |= 1;
5903         }
5904         return ret_ref;
5905 }
5906
5907 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelConfig_1write(JNIEnv * _env, jclass _b, jlong obj) {
5908         LDKChannelConfig obj_conv;
5909         obj_conv.inner = (void*)(obj & (~1));
5910         obj_conv.is_owned = (obj & 1) || (obj == 0);
5911         LDKCVec_u8Z arg_var = ChannelConfig_write(&obj_conv);
5912         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
5913         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
5914         CVec_u8Z_free(arg_var);
5915         return arg_arr;
5916 }
5917
5918 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelConfig_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
5919         LDKu8slice ser_ref;
5920         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
5921         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
5922         LDKChannelConfig ret_var = ChannelConfig_read(ser_ref);
5923         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
5924         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
5925         long ret_ref = (long)ret_var.inner;
5926         if (ret_var.is_owned) {
5927                 ret_ref |= 1;
5928         }
5929         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
5930         return ret_ref;
5931 }
5932
5933 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UserConfig_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
5934         LDKUserConfig this_ptr_conv;
5935         this_ptr_conv.inner = (void*)(this_ptr & (~1));
5936         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
5937         UserConfig_free(this_ptr_conv);
5938 }
5939
5940 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UserConfig_1clone(JNIEnv * _env, jclass _b, jlong orig) {
5941         LDKUserConfig orig_conv;
5942         orig_conv.inner = (void*)(orig & (~1));
5943         orig_conv.is_owned = (orig & 1) || (orig == 0);
5944         LDKUserConfig ret_var = UserConfig_clone(&orig_conv);
5945         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
5946         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
5947         long ret_ref = (long)ret_var.inner;
5948         if (ret_var.is_owned) {
5949                 ret_ref |= 1;
5950         }
5951         return ret_ref;
5952 }
5953
5954 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UserConfig_1get_1own_1channel_1config(JNIEnv * _env, jclass _b, jlong this_ptr) {
5955         LDKUserConfig this_ptr_conv;
5956         this_ptr_conv.inner = (void*)(this_ptr & (~1));
5957         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
5958         LDKChannelHandshakeConfig ret_var = UserConfig_get_own_channel_config(&this_ptr_conv);
5959         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
5960         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
5961         long ret_ref = (long)ret_var.inner;
5962         if (ret_var.is_owned) {
5963                 ret_ref |= 1;
5964         }
5965         return ret_ref;
5966 }
5967
5968 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UserConfig_1set_1own_1channel_1config(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
5969         LDKUserConfig this_ptr_conv;
5970         this_ptr_conv.inner = (void*)(this_ptr & (~1));
5971         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
5972         LDKChannelHandshakeConfig val_conv;
5973         val_conv.inner = (void*)(val & (~1));
5974         val_conv.is_owned = (val & 1) || (val == 0);
5975         if (val_conv.inner != NULL)
5976                 val_conv = ChannelHandshakeConfig_clone(&val_conv);
5977         UserConfig_set_own_channel_config(&this_ptr_conv, val_conv);
5978 }
5979
5980 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UserConfig_1get_1peer_1channel_1config_1limits(JNIEnv * _env, jclass _b, jlong this_ptr) {
5981         LDKUserConfig this_ptr_conv;
5982         this_ptr_conv.inner = (void*)(this_ptr & (~1));
5983         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
5984         LDKChannelHandshakeLimits ret_var = UserConfig_get_peer_channel_config_limits(&this_ptr_conv);
5985         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
5986         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
5987         long ret_ref = (long)ret_var.inner;
5988         if (ret_var.is_owned) {
5989                 ret_ref |= 1;
5990         }
5991         return ret_ref;
5992 }
5993
5994 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UserConfig_1set_1peer_1channel_1config_1limits(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
5995         LDKUserConfig this_ptr_conv;
5996         this_ptr_conv.inner = (void*)(this_ptr & (~1));
5997         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
5998         LDKChannelHandshakeLimits val_conv;
5999         val_conv.inner = (void*)(val & (~1));
6000         val_conv.is_owned = (val & 1) || (val == 0);
6001         if (val_conv.inner != NULL)
6002                 val_conv = ChannelHandshakeLimits_clone(&val_conv);
6003         UserConfig_set_peer_channel_config_limits(&this_ptr_conv, val_conv);
6004 }
6005
6006 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UserConfig_1get_1channel_1options(JNIEnv * _env, jclass _b, jlong this_ptr) {
6007         LDKUserConfig this_ptr_conv;
6008         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6009         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
6010         LDKChannelConfig ret_var = UserConfig_get_channel_options(&this_ptr_conv);
6011         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6012         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6013         long ret_ref = (long)ret_var.inner;
6014         if (ret_var.is_owned) {
6015                 ret_ref |= 1;
6016         }
6017         return ret_ref;
6018 }
6019
6020 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UserConfig_1set_1channel_1options(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
6021         LDKUserConfig this_ptr_conv;
6022         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6023         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
6024         LDKChannelConfig val_conv;
6025         val_conv.inner = (void*)(val & (~1));
6026         val_conv.is_owned = (val & 1) || (val == 0);
6027         if (val_conv.inner != NULL)
6028                 val_conv = ChannelConfig_clone(&val_conv);
6029         UserConfig_set_channel_options(&this_ptr_conv, val_conv);
6030 }
6031
6032 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) {
6033         LDKChannelHandshakeConfig own_channel_config_arg_conv;
6034         own_channel_config_arg_conv.inner = (void*)(own_channel_config_arg & (~1));
6035         own_channel_config_arg_conv.is_owned = (own_channel_config_arg & 1) || (own_channel_config_arg == 0);
6036         if (own_channel_config_arg_conv.inner != NULL)
6037                 own_channel_config_arg_conv = ChannelHandshakeConfig_clone(&own_channel_config_arg_conv);
6038         LDKChannelHandshakeLimits peer_channel_config_limits_arg_conv;
6039         peer_channel_config_limits_arg_conv.inner = (void*)(peer_channel_config_limits_arg & (~1));
6040         peer_channel_config_limits_arg_conv.is_owned = (peer_channel_config_limits_arg & 1) || (peer_channel_config_limits_arg == 0);
6041         if (peer_channel_config_limits_arg_conv.inner != NULL)
6042                 peer_channel_config_limits_arg_conv = ChannelHandshakeLimits_clone(&peer_channel_config_limits_arg_conv);
6043         LDKChannelConfig channel_options_arg_conv;
6044         channel_options_arg_conv.inner = (void*)(channel_options_arg & (~1));
6045         channel_options_arg_conv.is_owned = (channel_options_arg & 1) || (channel_options_arg == 0);
6046         if (channel_options_arg_conv.inner != NULL)
6047                 channel_options_arg_conv = ChannelConfig_clone(&channel_options_arg_conv);
6048         LDKUserConfig ret_var = UserConfig_new(own_channel_config_arg_conv, peer_channel_config_limits_arg_conv, channel_options_arg_conv);
6049         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6050         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6051         long ret_ref = (long)ret_var.inner;
6052         if (ret_var.is_owned) {
6053                 ret_ref |= 1;
6054         }
6055         return ret_ref;
6056 }
6057
6058 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UserConfig_1default(JNIEnv * _env, jclass _b) {
6059         LDKUserConfig ret_var = UserConfig_default();
6060         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6061         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6062         long ret_ref = (long)ret_var.inner;
6063         if (ret_var.is_owned) {
6064                 ret_ref |= 1;
6065         }
6066         return ret_ref;
6067 }
6068
6069 JNIEXPORT jclass JNICALL Java_org_ldk_impl_bindings_AccessError_1clone(JNIEnv * _env, jclass _b, jlong orig) {
6070         LDKAccessError* orig_conv = (LDKAccessError*)orig;
6071         jclass ret_conv = LDKAccessError_to_java(_env, AccessError_clone(orig_conv));
6072         return ret_conv;
6073 }
6074
6075 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Access_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
6076         LDKAccess this_ptr_conv = *(LDKAccess*)this_ptr;
6077         FREE((void*)this_ptr);
6078         Access_free(this_ptr_conv);
6079 }
6080
6081 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Watch_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
6082         LDKWatch this_ptr_conv = *(LDKWatch*)this_ptr;
6083         FREE((void*)this_ptr);
6084         Watch_free(this_ptr_conv);
6085 }
6086
6087 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Filter_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
6088         LDKFilter this_ptr_conv = *(LDKFilter*)this_ptr;
6089         FREE((void*)this_ptr);
6090         Filter_free(this_ptr_conv);
6091 }
6092
6093 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_BroadcasterInterface_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
6094         LDKBroadcasterInterface this_ptr_conv = *(LDKBroadcasterInterface*)this_ptr;
6095         FREE((void*)this_ptr);
6096         BroadcasterInterface_free(this_ptr_conv);
6097 }
6098
6099 JNIEXPORT jclass JNICALL Java_org_ldk_impl_bindings_ConfirmationTarget_1clone(JNIEnv * _env, jclass _b, jlong orig) {
6100         LDKConfirmationTarget* orig_conv = (LDKConfirmationTarget*)orig;
6101         jclass ret_conv = LDKConfirmationTarget_to_java(_env, ConfirmationTarget_clone(orig_conv));
6102         return ret_conv;
6103 }
6104
6105 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_FeeEstimator_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
6106         LDKFeeEstimator this_ptr_conv = *(LDKFeeEstimator*)this_ptr;
6107         FREE((void*)this_ptr);
6108         FeeEstimator_free(this_ptr_conv);
6109 }
6110
6111 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChainMonitor_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
6112         LDKChainMonitor this_ptr_conv;
6113         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6114         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
6115         ChainMonitor_free(this_ptr_conv);
6116 }
6117
6118 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChainMonitor_1block_1connected(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray header, jlongArray txdata, jint height) {
6119         LDKChainMonitor this_arg_conv;
6120         this_arg_conv.inner = (void*)(this_arg & (~1));
6121         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
6122         unsigned char header_arr[80];
6123         CHECK((*_env)->GetArrayLength (_env, header) == 80);
6124         (*_env)->GetByteArrayRegion (_env, header, 0, 80, header_arr);
6125         unsigned char (*header_ref)[80] = &header_arr;
6126         LDKCVec_C2Tuple_usizeTransactionZZ txdata_constr;
6127         txdata_constr.datalen = (*_env)->GetArrayLength (_env, txdata);
6128         if (txdata_constr.datalen > 0)
6129                 txdata_constr.data = MALLOC(txdata_constr.datalen * sizeof(LDKC2Tuple_usizeTransactionZ), "LDKCVec_C2Tuple_usizeTransactionZZ Elements");
6130         else
6131                 txdata_constr.data = NULL;
6132         long* txdata_vals = (*_env)->GetLongArrayElements (_env, txdata, NULL);
6133         for (size_t d = 0; d < txdata_constr.datalen; d++) {
6134                 long arr_conv_29 = txdata_vals[d];
6135                 LDKC2Tuple_usizeTransactionZ arr_conv_29_conv = *(LDKC2Tuple_usizeTransactionZ*)arr_conv_29;
6136                 FREE((void*)arr_conv_29);
6137                 txdata_constr.data[d] = arr_conv_29_conv;
6138         }
6139         (*_env)->ReleaseLongArrayElements (_env, txdata, txdata_vals, 0);
6140         ChainMonitor_block_connected(&this_arg_conv, header_ref, txdata_constr, height);
6141 }
6142
6143 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChainMonitor_1block_1disconnected(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray header, jint disconnected_height) {
6144         LDKChainMonitor this_arg_conv;
6145         this_arg_conv.inner = (void*)(this_arg & (~1));
6146         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
6147         unsigned char header_arr[80];
6148         CHECK((*_env)->GetArrayLength (_env, header) == 80);
6149         (*_env)->GetByteArrayRegion (_env, header, 0, 80, header_arr);
6150         unsigned char (*header_ref)[80] = &header_arr;
6151         ChainMonitor_block_disconnected(&this_arg_conv, header_ref, disconnected_height);
6152 }
6153
6154 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChainMonitor_1new(JNIEnv * _env, jclass _b, jlong chain_source, jlong broadcaster, jlong logger, jlong feeest) {
6155         LDKFilter* chain_source_conv = (LDKFilter*)chain_source;
6156         LDKBroadcasterInterface broadcaster_conv = *(LDKBroadcasterInterface*)broadcaster;
6157         if (broadcaster_conv.free == LDKBroadcasterInterface_JCalls_free) {
6158                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
6159                 LDKBroadcasterInterface_JCalls_clone(broadcaster_conv.this_arg);
6160         }
6161         LDKLogger logger_conv = *(LDKLogger*)logger;
6162         if (logger_conv.free == LDKLogger_JCalls_free) {
6163                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
6164                 LDKLogger_JCalls_clone(logger_conv.this_arg);
6165         }
6166         LDKFeeEstimator feeest_conv = *(LDKFeeEstimator*)feeest;
6167         if (feeest_conv.free == LDKFeeEstimator_JCalls_free) {
6168                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
6169                 LDKFeeEstimator_JCalls_clone(feeest_conv.this_arg);
6170         }
6171         LDKChainMonitor ret_var = ChainMonitor_new(chain_source_conv, broadcaster_conv, logger_conv, feeest_conv);
6172         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6173         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6174         long ret_ref = (long)ret_var.inner;
6175         if (ret_var.is_owned) {
6176                 ret_ref |= 1;
6177         }
6178         return ret_ref;
6179 }
6180
6181 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChainMonitor_1as_1Watch(JNIEnv * _env, jclass _b, jlong this_arg) {
6182         LDKChainMonitor this_arg_conv;
6183         this_arg_conv.inner = (void*)(this_arg & (~1));
6184         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
6185         LDKWatch* ret = MALLOC(sizeof(LDKWatch), "LDKWatch");
6186         *ret = ChainMonitor_as_Watch(&this_arg_conv);
6187         return (long)ret;
6188 }
6189
6190 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChainMonitor_1as_1EventsProvider(JNIEnv * _env, jclass _b, jlong this_arg) {
6191         LDKChainMonitor this_arg_conv;
6192         this_arg_conv.inner = (void*)(this_arg & (~1));
6193         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
6194         LDKEventsProvider* ret = MALLOC(sizeof(LDKEventsProvider), "LDKEventsProvider");
6195         *ret = ChainMonitor_as_EventsProvider(&this_arg_conv);
6196         return (long)ret;
6197 }
6198
6199 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelMonitorUpdate_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
6200         LDKChannelMonitorUpdate this_ptr_conv;
6201         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6202         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
6203         ChannelMonitorUpdate_free(this_ptr_conv);
6204 }
6205
6206 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelMonitorUpdate_1clone(JNIEnv * _env, jclass _b, jlong orig) {
6207         LDKChannelMonitorUpdate orig_conv;
6208         orig_conv.inner = (void*)(orig & (~1));
6209         orig_conv.is_owned = (orig & 1) || (orig == 0);
6210         LDKChannelMonitorUpdate ret_var = ChannelMonitorUpdate_clone(&orig_conv);
6211         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6212         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6213         long ret_ref = (long)ret_var.inner;
6214         if (ret_var.is_owned) {
6215                 ret_ref |= 1;
6216         }
6217         return ret_ref;
6218 }
6219
6220 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelMonitorUpdate_1get_1update_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
6221         LDKChannelMonitorUpdate this_ptr_conv;
6222         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6223         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
6224         jlong ret_val = ChannelMonitorUpdate_get_update_id(&this_ptr_conv);
6225         return ret_val;
6226 }
6227
6228 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelMonitorUpdate_1set_1update_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
6229         LDKChannelMonitorUpdate this_ptr_conv;
6230         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6231         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
6232         ChannelMonitorUpdate_set_update_id(&this_ptr_conv, val);
6233 }
6234
6235 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelMonitorUpdate_1write(JNIEnv * _env, jclass _b, jlong obj) {
6236         LDKChannelMonitorUpdate obj_conv;
6237         obj_conv.inner = (void*)(obj & (~1));
6238         obj_conv.is_owned = (obj & 1) || (obj == 0);
6239         LDKCVec_u8Z arg_var = ChannelMonitorUpdate_write(&obj_conv);
6240         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
6241         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
6242         CVec_u8Z_free(arg_var);
6243         return arg_arr;
6244 }
6245
6246 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelMonitorUpdate_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
6247         LDKu8slice ser_ref;
6248         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
6249         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
6250         LDKChannelMonitorUpdate ret_var = ChannelMonitorUpdate_read(ser_ref);
6251         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6252         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6253         long ret_ref = (long)ret_var.inner;
6254         if (ret_var.is_owned) {
6255                 ret_ref |= 1;
6256         }
6257         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
6258         return ret_ref;
6259 }
6260
6261 JNIEXPORT jclass JNICALL Java_org_ldk_impl_bindings_ChannelMonitorUpdateErr_1clone(JNIEnv * _env, jclass _b, jlong orig) {
6262         LDKChannelMonitorUpdateErr* orig_conv = (LDKChannelMonitorUpdateErr*)orig;
6263         jclass ret_conv = LDKChannelMonitorUpdateErr_to_java(_env, ChannelMonitorUpdateErr_clone(orig_conv));
6264         return ret_conv;
6265 }
6266
6267 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_MonitorUpdateError_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
6268         LDKMonitorUpdateError this_ptr_conv;
6269         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6270         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
6271         MonitorUpdateError_free(this_ptr_conv);
6272 }
6273
6274 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_MonitorEvent_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
6275         LDKMonitorEvent this_ptr_conv;
6276         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6277         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
6278         MonitorEvent_free(this_ptr_conv);
6279 }
6280
6281 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_MonitorEvent_1clone(JNIEnv * _env, jclass _b, jlong orig) {
6282         LDKMonitorEvent orig_conv;
6283         orig_conv.inner = (void*)(orig & (~1));
6284         orig_conv.is_owned = (orig & 1) || (orig == 0);
6285         LDKMonitorEvent ret_var = MonitorEvent_clone(&orig_conv);
6286         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6287         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6288         long ret_ref = (long)ret_var.inner;
6289         if (ret_var.is_owned) {
6290                 ret_ref |= 1;
6291         }
6292         return ret_ref;
6293 }
6294
6295 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_HTLCUpdate_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
6296         LDKHTLCUpdate this_ptr_conv;
6297         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6298         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
6299         HTLCUpdate_free(this_ptr_conv);
6300 }
6301
6302 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_HTLCUpdate_1clone(JNIEnv * _env, jclass _b, jlong orig) {
6303         LDKHTLCUpdate orig_conv;
6304         orig_conv.inner = (void*)(orig & (~1));
6305         orig_conv.is_owned = (orig & 1) || (orig == 0);
6306         LDKHTLCUpdate ret_var = HTLCUpdate_clone(&orig_conv);
6307         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6308         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6309         long ret_ref = (long)ret_var.inner;
6310         if (ret_var.is_owned) {
6311                 ret_ref |= 1;
6312         }
6313         return ret_ref;
6314 }
6315
6316 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_HTLCUpdate_1write(JNIEnv * _env, jclass _b, jlong obj) {
6317         LDKHTLCUpdate obj_conv;
6318         obj_conv.inner = (void*)(obj & (~1));
6319         obj_conv.is_owned = (obj & 1) || (obj == 0);
6320         LDKCVec_u8Z arg_var = HTLCUpdate_write(&obj_conv);
6321         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
6322         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
6323         CVec_u8Z_free(arg_var);
6324         return arg_arr;
6325 }
6326
6327 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_HTLCUpdate_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
6328         LDKu8slice ser_ref;
6329         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
6330         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
6331         LDKHTLCUpdate ret_var = HTLCUpdate_read(ser_ref);
6332         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6333         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6334         long ret_ref = (long)ret_var.inner;
6335         if (ret_var.is_owned) {
6336                 ret_ref |= 1;
6337         }
6338         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
6339         return ret_ref;
6340 }
6341
6342 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelMonitor_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
6343         LDKChannelMonitor this_ptr_conv;
6344         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6345         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
6346         ChannelMonitor_free(this_ptr_conv);
6347 }
6348
6349 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelMonitor_1update_1monitor(JNIEnv * _env, jclass _b, jlong this_arg, jlong updates, jlong broadcaster, jlong logger) {
6350         LDKChannelMonitor this_arg_conv;
6351         this_arg_conv.inner = (void*)(this_arg & (~1));
6352         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
6353         LDKChannelMonitorUpdate updates_conv;
6354         updates_conv.inner = (void*)(updates & (~1));
6355         updates_conv.is_owned = (updates & 1) || (updates == 0);
6356         if (updates_conv.inner != NULL)
6357                 updates_conv = ChannelMonitorUpdate_clone(&updates_conv);
6358         LDKBroadcasterInterface* broadcaster_conv = (LDKBroadcasterInterface*)broadcaster;
6359         LDKLogger* logger_conv = (LDKLogger*)logger;
6360         LDKCResult_NoneMonitorUpdateErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneMonitorUpdateErrorZ), "LDKCResult_NoneMonitorUpdateErrorZ");
6361         *ret_conv = ChannelMonitor_update_monitor(&this_arg_conv, updates_conv, broadcaster_conv, logger_conv);
6362         return (long)ret_conv;
6363 }
6364
6365 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelMonitor_1get_1latest_1update_1id(JNIEnv * _env, jclass _b, jlong this_arg) {
6366         LDKChannelMonitor this_arg_conv;
6367         this_arg_conv.inner = (void*)(this_arg & (~1));
6368         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
6369         jlong ret_val = ChannelMonitor_get_latest_update_id(&this_arg_conv);
6370         return ret_val;
6371 }
6372
6373 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelMonitor_1get_1funding_1txo(JNIEnv * _env, jclass _b, jlong this_arg) {
6374         LDKChannelMonitor this_arg_conv;
6375         this_arg_conv.inner = (void*)(this_arg & (~1));
6376         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
6377         LDKC2Tuple_OutPointScriptZ* ret_ref = MALLOC(sizeof(LDKC2Tuple_OutPointScriptZ), "LDKC2Tuple_OutPointScriptZ");
6378         *ret_ref = ChannelMonitor_get_funding_txo(&this_arg_conv);
6379         return (long)ret_ref;
6380 }
6381
6382 JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_ChannelMonitor_1get_1and_1clear_1pending_1monitor_1events(JNIEnv * _env, jclass _b, jlong this_arg) {
6383         LDKChannelMonitor this_arg_conv;
6384         this_arg_conv.inner = (void*)(this_arg & (~1));
6385         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
6386         LDKCVec_MonitorEventZ ret_var = ChannelMonitor_get_and_clear_pending_monitor_events(&this_arg_conv);
6387         jlongArray ret_arr = (*_env)->NewLongArray(_env, ret_var.datalen);
6388         jlong *ret_arr_ptr = (*_env)->GetPrimitiveArrayCritical(_env, ret_arr, NULL);
6389         for (size_t o = 0; o < ret_var.datalen; o++) {
6390                 LDKMonitorEvent arr_conv_14_var = ret_var.data[o];
6391                 CHECK((((long)arr_conv_14_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6392                 CHECK((((long)&arr_conv_14_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6393                 long arr_conv_14_ref = (long)arr_conv_14_var.inner;
6394                 if (arr_conv_14_var.is_owned) {
6395                         arr_conv_14_ref |= 1;
6396                 }
6397                 ret_arr_ptr[o] = arr_conv_14_ref;
6398         }
6399         (*_env)->ReleasePrimitiveArrayCritical(_env, ret_arr, ret_arr_ptr, 0);
6400         FREE(ret_var.data);
6401         return ret_arr;
6402 }
6403
6404 JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_ChannelMonitor_1get_1and_1clear_1pending_1events(JNIEnv * _env, jclass _b, jlong this_arg) {
6405         LDKChannelMonitor this_arg_conv;
6406         this_arg_conv.inner = (void*)(this_arg & (~1));
6407         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
6408         LDKCVec_EventZ ret_var = ChannelMonitor_get_and_clear_pending_events(&this_arg_conv);
6409         jlongArray ret_arr = (*_env)->NewLongArray(_env, ret_var.datalen);
6410         jlong *ret_arr_ptr = (*_env)->GetPrimitiveArrayCritical(_env, ret_arr, NULL);
6411         for (size_t h = 0; h < ret_var.datalen; h++) {
6412                 LDKEvent *arr_conv_7_copy = MALLOC(sizeof(LDKEvent), "LDKEvent");
6413                 *arr_conv_7_copy = Event_clone(&ret_var.data[h]);
6414                 long arr_conv_7_ref = (long)arr_conv_7_copy;
6415                 ret_arr_ptr[h] = arr_conv_7_ref;
6416         }
6417         (*_env)->ReleasePrimitiveArrayCritical(_env, ret_arr, ret_arr_ptr, 0);
6418         CVec_EventZ_free(ret_var);
6419         return ret_arr;
6420 }
6421
6422 JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_ChannelMonitor_1get_1latest_1holder_1commitment_1txn(JNIEnv * _env, jclass _b, jlong this_arg, jlong logger) {
6423         LDKChannelMonitor this_arg_conv;
6424         this_arg_conv.inner = (void*)(this_arg & (~1));
6425         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
6426         LDKLogger* logger_conv = (LDKLogger*)logger;
6427         LDKCVec_TransactionZ ret_var = ChannelMonitor_get_latest_holder_commitment_txn(&this_arg_conv, logger_conv);
6428         jlongArray ret_arr = (*_env)->NewLongArray(_env, ret_var.datalen);
6429         jlong *ret_arr_ptr = (*_env)->GetPrimitiveArrayCritical(_env, ret_arr, NULL);
6430         for (size_t n = 0; n < ret_var.datalen; n++) {
6431                 LDKTransaction *arr_conv_13_copy = MALLOC(sizeof(LDKTransaction), "LDKTransaction");
6432                 *arr_conv_13_copy = ret_var.data[n];
6433                 long arr_conv_13_ref = (long)arr_conv_13_copy;
6434                 ret_arr_ptr[n] = arr_conv_13_ref;
6435         }
6436         (*_env)->ReleasePrimitiveArrayCritical(_env, ret_arr, ret_arr_ptr, 0);
6437         CVec_TransactionZ_free(ret_var);
6438         return ret_arr;
6439 }
6440
6441 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) {
6442         LDKChannelMonitor this_arg_conv;
6443         this_arg_conv.inner = (void*)(this_arg & (~1));
6444         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
6445         unsigned char header_arr[80];
6446         CHECK((*_env)->GetArrayLength (_env, header) == 80);
6447         (*_env)->GetByteArrayRegion (_env, header, 0, 80, header_arr);
6448         unsigned char (*header_ref)[80] = &header_arr;
6449         LDKCVec_C2Tuple_usizeTransactionZZ txdata_constr;
6450         txdata_constr.datalen = (*_env)->GetArrayLength (_env, txdata);
6451         if (txdata_constr.datalen > 0)
6452                 txdata_constr.data = MALLOC(txdata_constr.datalen * sizeof(LDKC2Tuple_usizeTransactionZ), "LDKCVec_C2Tuple_usizeTransactionZZ Elements");
6453         else
6454                 txdata_constr.data = NULL;
6455         long* txdata_vals = (*_env)->GetLongArrayElements (_env, txdata, NULL);
6456         for (size_t d = 0; d < txdata_constr.datalen; d++) {
6457                 long arr_conv_29 = txdata_vals[d];
6458                 LDKC2Tuple_usizeTransactionZ arr_conv_29_conv = *(LDKC2Tuple_usizeTransactionZ*)arr_conv_29;
6459                 FREE((void*)arr_conv_29);
6460                 txdata_constr.data[d] = arr_conv_29_conv;
6461         }
6462         (*_env)->ReleaseLongArrayElements (_env, txdata, txdata_vals, 0);
6463         LDKBroadcasterInterface broadcaster_conv = *(LDKBroadcasterInterface*)broadcaster;
6464         if (broadcaster_conv.free == LDKBroadcasterInterface_JCalls_free) {
6465                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
6466                 LDKBroadcasterInterface_JCalls_clone(broadcaster_conv.this_arg);
6467         }
6468         LDKFeeEstimator fee_estimator_conv = *(LDKFeeEstimator*)fee_estimator;
6469         if (fee_estimator_conv.free == LDKFeeEstimator_JCalls_free) {
6470                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
6471                 LDKFeeEstimator_JCalls_clone(fee_estimator_conv.this_arg);
6472         }
6473         LDKLogger logger_conv = *(LDKLogger*)logger;
6474         if (logger_conv.free == LDKLogger_JCalls_free) {
6475                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
6476                 LDKLogger_JCalls_clone(logger_conv.this_arg);
6477         }
6478         LDKCVec_C2Tuple_TxidCVec_TxOutZZZ ret_var = ChannelMonitor_block_connected(&this_arg_conv, header_ref, txdata_constr, height, broadcaster_conv, fee_estimator_conv, logger_conv);
6479         jlongArray ret_arr = (*_env)->NewLongArray(_env, ret_var.datalen);
6480         jlong *ret_arr_ptr = (*_env)->GetPrimitiveArrayCritical(_env, ret_arr, NULL);
6481         for (size_t b = 0; b < ret_var.datalen; b++) {
6482                 LDKC2Tuple_TxidCVec_TxOutZZ* arr_conv_27_ref = MALLOC(sizeof(LDKC2Tuple_TxidCVec_TxOutZZ), "LDKC2Tuple_TxidCVec_TxOutZZ");
6483                 *arr_conv_27_ref = ret_var.data[b];
6484                 ret_arr_ptr[b] = (long)arr_conv_27_ref;
6485         }
6486         (*_env)->ReleasePrimitiveArrayCritical(_env, ret_arr, ret_arr_ptr, 0);
6487         CVec_C2Tuple_TxidCVec_TxOutZZZ_free(ret_var);
6488         return ret_arr;
6489 }
6490
6491 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) {
6492         LDKChannelMonitor this_arg_conv;
6493         this_arg_conv.inner = (void*)(this_arg & (~1));
6494         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
6495         unsigned char header_arr[80];
6496         CHECK((*_env)->GetArrayLength (_env, header) == 80);
6497         (*_env)->GetByteArrayRegion (_env, header, 0, 80, header_arr);
6498         unsigned char (*header_ref)[80] = &header_arr;
6499         LDKBroadcasterInterface broadcaster_conv = *(LDKBroadcasterInterface*)broadcaster;
6500         if (broadcaster_conv.free == LDKBroadcasterInterface_JCalls_free) {
6501                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
6502                 LDKBroadcasterInterface_JCalls_clone(broadcaster_conv.this_arg);
6503         }
6504         LDKFeeEstimator fee_estimator_conv = *(LDKFeeEstimator*)fee_estimator;
6505         if (fee_estimator_conv.free == LDKFeeEstimator_JCalls_free) {
6506                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
6507                 LDKFeeEstimator_JCalls_clone(fee_estimator_conv.this_arg);
6508         }
6509         LDKLogger logger_conv = *(LDKLogger*)logger;
6510         if (logger_conv.free == LDKLogger_JCalls_free) {
6511                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
6512                 LDKLogger_JCalls_clone(logger_conv.this_arg);
6513         }
6514         ChannelMonitor_block_disconnected(&this_arg_conv, header_ref, height, broadcaster_conv, fee_estimator_conv, logger_conv);
6515 }
6516
6517 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OutPoint_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
6518         LDKOutPoint this_ptr_conv;
6519         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6520         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
6521         OutPoint_free(this_ptr_conv);
6522 }
6523
6524 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_OutPoint_1clone(JNIEnv * _env, jclass _b, jlong orig) {
6525         LDKOutPoint orig_conv;
6526         orig_conv.inner = (void*)(orig & (~1));
6527         orig_conv.is_owned = (orig & 1) || (orig == 0);
6528         LDKOutPoint ret_var = OutPoint_clone(&orig_conv);
6529         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6530         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6531         long ret_ref = (long)ret_var.inner;
6532         if (ret_var.is_owned) {
6533                 ret_ref |= 1;
6534         }
6535         return ret_ref;
6536 }
6537
6538 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_OutPoint_1get_1txid(JNIEnv * _env, jclass _b, jlong this_ptr) {
6539         LDKOutPoint this_ptr_conv;
6540         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6541         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
6542         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
6543         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *OutPoint_get_txid(&this_ptr_conv));
6544         return ret_arr;
6545 }
6546
6547 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OutPoint_1set_1txid(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
6548         LDKOutPoint this_ptr_conv;
6549         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6550         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
6551         LDKThirtyTwoBytes val_ref;
6552         CHECK((*_env)->GetArrayLength (_env, val) == 32);
6553         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
6554         OutPoint_set_txid(&this_ptr_conv, val_ref);
6555 }
6556
6557 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_OutPoint_1get_1index(JNIEnv * _env, jclass _b, jlong this_ptr) {
6558         LDKOutPoint this_ptr_conv;
6559         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6560         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
6561         jshort ret_val = OutPoint_get_index(&this_ptr_conv);
6562         return ret_val;
6563 }
6564
6565 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OutPoint_1set_1index(JNIEnv * _env, jclass _b, jlong this_ptr, jshort val) {
6566         LDKOutPoint this_ptr_conv;
6567         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6568         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
6569         OutPoint_set_index(&this_ptr_conv, val);
6570 }
6571
6572 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_OutPoint_1new(JNIEnv * _env, jclass _b, jbyteArray txid_arg, jshort index_arg) {
6573         LDKThirtyTwoBytes txid_arg_ref;
6574         CHECK((*_env)->GetArrayLength (_env, txid_arg) == 32);
6575         (*_env)->GetByteArrayRegion (_env, txid_arg, 0, 32, txid_arg_ref.data);
6576         LDKOutPoint ret_var = OutPoint_new(txid_arg_ref, index_arg);
6577         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6578         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6579         long ret_ref = (long)ret_var.inner;
6580         if (ret_var.is_owned) {
6581                 ret_ref |= 1;
6582         }
6583         return ret_ref;
6584 }
6585
6586 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_OutPoint_1to_1channel_1id(JNIEnv * _env, jclass _b, jlong this_arg) {
6587         LDKOutPoint this_arg_conv;
6588         this_arg_conv.inner = (void*)(this_arg & (~1));
6589         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
6590         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 32);
6591         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 32, OutPoint_to_channel_id(&this_arg_conv).data);
6592         return arg_arr;
6593 }
6594
6595 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_OutPoint_1write(JNIEnv * _env, jclass _b, jlong obj) {
6596         LDKOutPoint obj_conv;
6597         obj_conv.inner = (void*)(obj & (~1));
6598         obj_conv.is_owned = (obj & 1) || (obj == 0);
6599         LDKCVec_u8Z arg_var = OutPoint_write(&obj_conv);
6600         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
6601         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
6602         CVec_u8Z_free(arg_var);
6603         return arg_arr;
6604 }
6605
6606 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_OutPoint_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
6607         LDKu8slice ser_ref;
6608         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
6609         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
6610         LDKOutPoint ret_var = OutPoint_read(ser_ref);
6611         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6612         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6613         long ret_ref = (long)ret_var.inner;
6614         if (ret_var.is_owned) {
6615                 ret_ref |= 1;
6616         }
6617         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
6618         return ret_ref;
6619 }
6620
6621 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_SpendableOutputDescriptor_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
6622         LDKSpendableOutputDescriptor this_ptr_conv = *(LDKSpendableOutputDescriptor*)this_ptr;
6623         FREE((void*)this_ptr);
6624         SpendableOutputDescriptor_free(this_ptr_conv);
6625 }
6626
6627 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_SpendableOutputDescriptor_1clone(JNIEnv * _env, jclass _b, jlong orig) {
6628         LDKSpendableOutputDescriptor* orig_conv = (LDKSpendableOutputDescriptor*)orig;
6629         LDKSpendableOutputDescriptor *ret_copy = MALLOC(sizeof(LDKSpendableOutputDescriptor), "LDKSpendableOutputDescriptor");
6630         *ret_copy = SpendableOutputDescriptor_clone(orig_conv);
6631         long ret_ref = (long)ret_copy;
6632         return ret_ref;
6633 }
6634
6635 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
6636         LDKChannelKeys this_ptr_conv = *(LDKChannelKeys*)this_ptr;
6637         FREE((void*)this_ptr);
6638         ChannelKeys_free(this_ptr_conv);
6639 }
6640
6641 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_KeysInterface_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
6642         LDKKeysInterface this_ptr_conv = *(LDKKeysInterface*)this_ptr;
6643         FREE((void*)this_ptr);
6644         KeysInterface_free(this_ptr_conv);
6645 }
6646
6647 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
6648         LDKInMemoryChannelKeys this_ptr_conv;
6649         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6650         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
6651         InMemoryChannelKeys_free(this_ptr_conv);
6652 }
6653
6654 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1clone(JNIEnv * _env, jclass _b, jlong orig) {
6655         LDKInMemoryChannelKeys orig_conv;
6656         orig_conv.inner = (void*)(orig & (~1));
6657         orig_conv.is_owned = (orig & 1) || (orig == 0);
6658         LDKInMemoryChannelKeys ret_var = InMemoryChannelKeys_clone(&orig_conv);
6659         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6660         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6661         long ret_ref = (long)ret_var.inner;
6662         if (ret_var.is_owned) {
6663                 ret_ref |= 1;
6664         }
6665         return ret_ref;
6666 }
6667
6668 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1get_1funding_1key(JNIEnv * _env, jclass _b, jlong this_ptr) {
6669         LDKInMemoryChannelKeys this_ptr_conv;
6670         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6671         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
6672         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
6673         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *InMemoryChannelKeys_get_funding_key(&this_ptr_conv));
6674         return ret_arr;
6675 }
6676
6677 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1set_1funding_1key(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
6678         LDKInMemoryChannelKeys this_ptr_conv;
6679         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6680         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
6681         LDKSecretKey val_ref;
6682         CHECK((*_env)->GetArrayLength (_env, val) == 32);
6683         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.bytes);
6684         InMemoryChannelKeys_set_funding_key(&this_ptr_conv, val_ref);
6685 }
6686
6687 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1get_1revocation_1base_1key(JNIEnv * _env, jclass _b, jlong this_ptr) {
6688         LDKInMemoryChannelKeys this_ptr_conv;
6689         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6690         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
6691         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
6692         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *InMemoryChannelKeys_get_revocation_base_key(&this_ptr_conv));
6693         return ret_arr;
6694 }
6695
6696 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1set_1revocation_1base_1key(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
6697         LDKInMemoryChannelKeys this_ptr_conv;
6698         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6699         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
6700         LDKSecretKey val_ref;
6701         CHECK((*_env)->GetArrayLength (_env, val) == 32);
6702         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.bytes);
6703         InMemoryChannelKeys_set_revocation_base_key(&this_ptr_conv, val_ref);
6704 }
6705
6706 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1get_1payment_1key(JNIEnv * _env, jclass _b, jlong this_ptr) {
6707         LDKInMemoryChannelKeys this_ptr_conv;
6708         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6709         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
6710         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
6711         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *InMemoryChannelKeys_get_payment_key(&this_ptr_conv));
6712         return ret_arr;
6713 }
6714
6715 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1set_1payment_1key(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
6716         LDKInMemoryChannelKeys this_ptr_conv;
6717         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6718         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
6719         LDKSecretKey val_ref;
6720         CHECK((*_env)->GetArrayLength (_env, val) == 32);
6721         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.bytes);
6722         InMemoryChannelKeys_set_payment_key(&this_ptr_conv, val_ref);
6723 }
6724
6725 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1get_1delayed_1payment_1base_1key(JNIEnv * _env, jclass _b, jlong this_ptr) {
6726         LDKInMemoryChannelKeys this_ptr_conv;
6727         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6728         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
6729         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
6730         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *InMemoryChannelKeys_get_delayed_payment_base_key(&this_ptr_conv));
6731         return ret_arr;
6732 }
6733
6734 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1set_1delayed_1payment_1base_1key(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
6735         LDKInMemoryChannelKeys this_ptr_conv;
6736         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6737         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
6738         LDKSecretKey val_ref;
6739         CHECK((*_env)->GetArrayLength (_env, val) == 32);
6740         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.bytes);
6741         InMemoryChannelKeys_set_delayed_payment_base_key(&this_ptr_conv, val_ref);
6742 }
6743
6744 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1get_1htlc_1base_1key(JNIEnv * _env, jclass _b, jlong this_ptr) {
6745         LDKInMemoryChannelKeys this_ptr_conv;
6746         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6747         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
6748         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
6749         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *InMemoryChannelKeys_get_htlc_base_key(&this_ptr_conv));
6750         return ret_arr;
6751 }
6752
6753 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1set_1htlc_1base_1key(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
6754         LDKInMemoryChannelKeys this_ptr_conv;
6755         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6756         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
6757         LDKSecretKey val_ref;
6758         CHECK((*_env)->GetArrayLength (_env, val) == 32);
6759         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.bytes);
6760         InMemoryChannelKeys_set_htlc_base_key(&this_ptr_conv, val_ref);
6761 }
6762
6763 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1get_1commitment_1seed(JNIEnv * _env, jclass _b, jlong this_ptr) {
6764         LDKInMemoryChannelKeys this_ptr_conv;
6765         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6766         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
6767         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
6768         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *InMemoryChannelKeys_get_commitment_seed(&this_ptr_conv));
6769         return ret_arr;
6770 }
6771
6772 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1set_1commitment_1seed(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
6773         LDKInMemoryChannelKeys this_ptr_conv;
6774         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6775         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
6776         LDKThirtyTwoBytes val_ref;
6777         CHECK((*_env)->GetArrayLength (_env, val) == 32);
6778         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
6779         InMemoryChannelKeys_set_commitment_seed(&this_ptr_conv, val_ref);
6780 }
6781
6782 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) {
6783         LDKSecretKey funding_key_ref;
6784         CHECK((*_env)->GetArrayLength (_env, funding_key) == 32);
6785         (*_env)->GetByteArrayRegion (_env, funding_key, 0, 32, funding_key_ref.bytes);
6786         LDKSecretKey revocation_base_key_ref;
6787         CHECK((*_env)->GetArrayLength (_env, revocation_base_key) == 32);
6788         (*_env)->GetByteArrayRegion (_env, revocation_base_key, 0, 32, revocation_base_key_ref.bytes);
6789         LDKSecretKey payment_key_ref;
6790         CHECK((*_env)->GetArrayLength (_env, payment_key) == 32);
6791         (*_env)->GetByteArrayRegion (_env, payment_key, 0, 32, payment_key_ref.bytes);
6792         LDKSecretKey delayed_payment_base_key_ref;
6793         CHECK((*_env)->GetArrayLength (_env, delayed_payment_base_key) == 32);
6794         (*_env)->GetByteArrayRegion (_env, delayed_payment_base_key, 0, 32, delayed_payment_base_key_ref.bytes);
6795         LDKSecretKey htlc_base_key_ref;
6796         CHECK((*_env)->GetArrayLength (_env, htlc_base_key) == 32);
6797         (*_env)->GetByteArrayRegion (_env, htlc_base_key, 0, 32, htlc_base_key_ref.bytes);
6798         LDKThirtyTwoBytes commitment_seed_ref;
6799         CHECK((*_env)->GetArrayLength (_env, commitment_seed) == 32);
6800         (*_env)->GetByteArrayRegion (_env, commitment_seed, 0, 32, commitment_seed_ref.data);
6801         LDKC2Tuple_u64u64Z key_derivation_params_conv = *(LDKC2Tuple_u64u64Z*)key_derivation_params;
6802         FREE((void*)key_derivation_params);
6803         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);
6804         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6805         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6806         long ret_ref = (long)ret_var.inner;
6807         if (ret_var.is_owned) {
6808                 ret_ref |= 1;
6809         }
6810         return ret_ref;
6811 }
6812
6813 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1counterparty_1pubkeys(JNIEnv * _env, jclass _b, jlong this_arg) {
6814         LDKInMemoryChannelKeys this_arg_conv;
6815         this_arg_conv.inner = (void*)(this_arg & (~1));
6816         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
6817         LDKChannelPublicKeys ret_var = InMemoryChannelKeys_counterparty_pubkeys(&this_arg_conv);
6818         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6819         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6820         long ret_ref = (long)ret_var.inner;
6821         if (ret_var.is_owned) {
6822                 ret_ref |= 1;
6823         }
6824         return ret_ref;
6825 }
6826
6827 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1counterparty_1selected_1contest_1delay(JNIEnv * _env, jclass _b, jlong this_arg) {
6828         LDKInMemoryChannelKeys this_arg_conv;
6829         this_arg_conv.inner = (void*)(this_arg & (~1));
6830         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
6831         jshort ret_val = InMemoryChannelKeys_counterparty_selected_contest_delay(&this_arg_conv);
6832         return ret_val;
6833 }
6834
6835 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1holder_1selected_1contest_1delay(JNIEnv * _env, jclass _b, jlong this_arg) {
6836         LDKInMemoryChannelKeys this_arg_conv;
6837         this_arg_conv.inner = (void*)(this_arg & (~1));
6838         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
6839         jshort ret_val = InMemoryChannelKeys_holder_selected_contest_delay(&this_arg_conv);
6840         return ret_val;
6841 }
6842
6843 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1as_1ChannelKeys(JNIEnv * _env, jclass _b, jlong this_arg) {
6844         LDKInMemoryChannelKeys this_arg_conv;
6845         this_arg_conv.inner = (void*)(this_arg & (~1));
6846         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
6847         LDKChannelKeys* ret = MALLOC(sizeof(LDKChannelKeys), "LDKChannelKeys");
6848         *ret = InMemoryChannelKeys_as_ChannelKeys(&this_arg_conv);
6849         return (long)ret;
6850 }
6851
6852 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1write(JNIEnv * _env, jclass _b, jlong obj) {
6853         LDKInMemoryChannelKeys obj_conv;
6854         obj_conv.inner = (void*)(obj & (~1));
6855         obj_conv.is_owned = (obj & 1) || (obj == 0);
6856         LDKCVec_u8Z arg_var = InMemoryChannelKeys_write(&obj_conv);
6857         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
6858         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
6859         CVec_u8Z_free(arg_var);
6860         return arg_arr;
6861 }
6862
6863 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
6864         LDKu8slice ser_ref;
6865         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
6866         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
6867         LDKInMemoryChannelKeys ret_var = InMemoryChannelKeys_read(ser_ref);
6868         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6869         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6870         long ret_ref = (long)ret_var.inner;
6871         if (ret_var.is_owned) {
6872                 ret_ref |= 1;
6873         }
6874         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
6875         return ret_ref;
6876 }
6877
6878 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_KeysManager_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
6879         LDKKeysManager this_ptr_conv;
6880         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6881         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
6882         KeysManager_free(this_ptr_conv);
6883 }
6884
6885 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) {
6886         unsigned char seed_arr[32];
6887         CHECK((*_env)->GetArrayLength (_env, seed) == 32);
6888         (*_env)->GetByteArrayRegion (_env, seed, 0, 32, seed_arr);
6889         unsigned char (*seed_ref)[32] = &seed_arr;
6890         LDKNetwork network_conv = LDKNetwork_from_java(_env, network);
6891         LDKKeysManager ret_var = KeysManager_new(seed_ref, network_conv, starting_time_secs, starting_time_nanos);
6892         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6893         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6894         long ret_ref = (long)ret_var.inner;
6895         if (ret_var.is_owned) {
6896                 ret_ref |= 1;
6897         }
6898         return ret_ref;
6899 }
6900
6901 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) {
6902         LDKKeysManager this_arg_conv;
6903         this_arg_conv.inner = (void*)(this_arg & (~1));
6904         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
6905         LDKInMemoryChannelKeys ret_var = KeysManager_derive_channel_keys(&this_arg_conv, channel_value_satoshis, params_1, params_2);
6906         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6907         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6908         long ret_ref = (long)ret_var.inner;
6909         if (ret_var.is_owned) {
6910                 ret_ref |= 1;
6911         }
6912         return ret_ref;
6913 }
6914
6915 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_KeysManager_1as_1KeysInterface(JNIEnv * _env, jclass _b, jlong this_arg) {
6916         LDKKeysManager this_arg_conv;
6917         this_arg_conv.inner = (void*)(this_arg & (~1));
6918         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
6919         LDKKeysInterface* ret = MALLOC(sizeof(LDKKeysInterface), "LDKKeysInterface");
6920         *ret = KeysManager_as_KeysInterface(&this_arg_conv);
6921         return (long)ret;
6922 }
6923
6924 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelManager_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
6925         LDKChannelManager this_ptr_conv;
6926         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6927         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
6928         ChannelManager_free(this_ptr_conv);
6929 }
6930
6931 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
6932         LDKChannelDetails this_ptr_conv;
6933         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6934         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
6935         ChannelDetails_free(this_ptr_conv);
6936 }
6937
6938 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1clone(JNIEnv * _env, jclass _b, jlong orig) {
6939         LDKChannelDetails orig_conv;
6940         orig_conv.inner = (void*)(orig & (~1));
6941         orig_conv.is_owned = (orig & 1) || (orig == 0);
6942         LDKChannelDetails ret_var = ChannelDetails_clone(&orig_conv);
6943         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6944         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6945         long ret_ref = (long)ret_var.inner;
6946         if (ret_var.is_owned) {
6947                 ret_ref |= 1;
6948         }
6949         return ret_ref;
6950 }
6951
6952 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1get_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
6953         LDKChannelDetails this_ptr_conv;
6954         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6955         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
6956         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
6957         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *ChannelDetails_get_channel_id(&this_ptr_conv));
6958         return ret_arr;
6959 }
6960
6961 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1set_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
6962         LDKChannelDetails this_ptr_conv;
6963         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6964         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
6965         LDKThirtyTwoBytes val_ref;
6966         CHECK((*_env)->GetArrayLength (_env, val) == 32);
6967         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
6968         ChannelDetails_set_channel_id(&this_ptr_conv, val_ref);
6969 }
6970
6971 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1get_1remote_1network_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
6972         LDKChannelDetails this_ptr_conv;
6973         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6974         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
6975         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
6976         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, ChannelDetails_get_remote_network_id(&this_ptr_conv).compressed_form);
6977         return arg_arr;
6978 }
6979
6980 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1set_1remote_1network_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
6981         LDKChannelDetails this_ptr_conv;
6982         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6983         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
6984         LDKPublicKey val_ref;
6985         CHECK((*_env)->GetArrayLength (_env, val) == 33);
6986         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
6987         ChannelDetails_set_remote_network_id(&this_ptr_conv, val_ref);
6988 }
6989
6990 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1get_1counterparty_1features(JNIEnv * _env, jclass _b, jlong this_ptr) {
6991         LDKChannelDetails this_ptr_conv;
6992         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6993         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
6994         LDKInitFeatures ret_var = ChannelDetails_get_counterparty_features(&this_ptr_conv);
6995         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6996         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6997         long ret_ref = (long)ret_var.inner;
6998         if (ret_var.is_owned) {
6999                 ret_ref |= 1;
7000         }
7001         return ret_ref;
7002 }
7003
7004 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1set_1counterparty_1features(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
7005         LDKChannelDetails this_ptr_conv;
7006         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7007         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7008         LDKInitFeatures val_conv;
7009         val_conv.inner = (void*)(val & (~1));
7010         val_conv.is_owned = (val & 1) || (val == 0);
7011         // Warning: we may need a move here but can't clone!
7012         ChannelDetails_set_counterparty_features(&this_ptr_conv, val_conv);
7013 }
7014
7015 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1get_1channel_1value_1satoshis(JNIEnv * _env, jclass _b, jlong this_ptr) {
7016         LDKChannelDetails this_ptr_conv;
7017         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7018         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7019         jlong ret_val = ChannelDetails_get_channel_value_satoshis(&this_ptr_conv);
7020         return ret_val;
7021 }
7022
7023 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1set_1channel_1value_1satoshis(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
7024         LDKChannelDetails this_ptr_conv;
7025         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7026         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7027         ChannelDetails_set_channel_value_satoshis(&this_ptr_conv, val);
7028 }
7029
7030 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1get_1user_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
7031         LDKChannelDetails this_ptr_conv;
7032         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7033         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7034         jlong ret_val = ChannelDetails_get_user_id(&this_ptr_conv);
7035         return ret_val;
7036 }
7037
7038 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1set_1user_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
7039         LDKChannelDetails this_ptr_conv;
7040         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7041         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7042         ChannelDetails_set_user_id(&this_ptr_conv, val);
7043 }
7044
7045 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1get_1outbound_1capacity_1msat(JNIEnv * _env, jclass _b, jlong this_ptr) {
7046         LDKChannelDetails this_ptr_conv;
7047         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7048         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7049         jlong ret_val = ChannelDetails_get_outbound_capacity_msat(&this_ptr_conv);
7050         return ret_val;
7051 }
7052
7053 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1set_1outbound_1capacity_1msat(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
7054         LDKChannelDetails this_ptr_conv;
7055         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7056         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7057         ChannelDetails_set_outbound_capacity_msat(&this_ptr_conv, val);
7058 }
7059
7060 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1get_1inbound_1capacity_1msat(JNIEnv * _env, jclass _b, jlong this_ptr) {
7061         LDKChannelDetails this_ptr_conv;
7062         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7063         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7064         jlong ret_val = ChannelDetails_get_inbound_capacity_msat(&this_ptr_conv);
7065         return ret_val;
7066 }
7067
7068 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1set_1inbound_1capacity_1msat(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
7069         LDKChannelDetails this_ptr_conv;
7070         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7071         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7072         ChannelDetails_set_inbound_capacity_msat(&this_ptr_conv, val);
7073 }
7074
7075 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1get_1is_1live(JNIEnv * _env, jclass _b, jlong this_ptr) {
7076         LDKChannelDetails this_ptr_conv;
7077         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7078         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7079         jboolean ret_val = ChannelDetails_get_is_live(&this_ptr_conv);
7080         return ret_val;
7081 }
7082
7083 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1set_1is_1live(JNIEnv * _env, jclass _b, jlong this_ptr, jboolean val) {
7084         LDKChannelDetails this_ptr_conv;
7085         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7086         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7087         ChannelDetails_set_is_live(&this_ptr_conv, val);
7088 }
7089
7090 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_PaymentSendFailure_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
7091         LDKPaymentSendFailure this_ptr_conv;
7092         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7093         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7094         PaymentSendFailure_free(this_ptr_conv);
7095 }
7096
7097 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) {
7098         LDKNetwork network_conv = LDKNetwork_from_java(_env, network);
7099         LDKFeeEstimator fee_est_conv = *(LDKFeeEstimator*)fee_est;
7100         if (fee_est_conv.free == LDKFeeEstimator_JCalls_free) {
7101                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
7102                 LDKFeeEstimator_JCalls_clone(fee_est_conv.this_arg);
7103         }
7104         LDKWatch chain_monitor_conv = *(LDKWatch*)chain_monitor;
7105         if (chain_monitor_conv.free == LDKWatch_JCalls_free) {
7106                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
7107                 LDKWatch_JCalls_clone(chain_monitor_conv.this_arg);
7108         }
7109         LDKBroadcasterInterface tx_broadcaster_conv = *(LDKBroadcasterInterface*)tx_broadcaster;
7110         if (tx_broadcaster_conv.free == LDKBroadcasterInterface_JCalls_free) {
7111                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
7112                 LDKBroadcasterInterface_JCalls_clone(tx_broadcaster_conv.this_arg);
7113         }
7114         LDKLogger logger_conv = *(LDKLogger*)logger;
7115         if (logger_conv.free == LDKLogger_JCalls_free) {
7116                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
7117                 LDKLogger_JCalls_clone(logger_conv.this_arg);
7118         }
7119         LDKKeysInterface keys_manager_conv = *(LDKKeysInterface*)keys_manager;
7120         if (keys_manager_conv.free == LDKKeysInterface_JCalls_free) {
7121                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
7122                 LDKKeysInterface_JCalls_clone(keys_manager_conv.this_arg);
7123         }
7124         LDKUserConfig config_conv;
7125         config_conv.inner = (void*)(config & (~1));
7126         config_conv.is_owned = (config & 1) || (config == 0);
7127         if (config_conv.inner != NULL)
7128                 config_conv = UserConfig_clone(&config_conv);
7129         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);
7130         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7131         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7132         long ret_ref = (long)ret_var.inner;
7133         if (ret_var.is_owned) {
7134                 ret_ref |= 1;
7135         }
7136         return ret_ref;
7137 }
7138
7139 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) {
7140         LDKChannelManager this_arg_conv;
7141         this_arg_conv.inner = (void*)(this_arg & (~1));
7142         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
7143         LDKPublicKey their_network_key_ref;
7144         CHECK((*_env)->GetArrayLength (_env, their_network_key) == 33);
7145         (*_env)->GetByteArrayRegion (_env, their_network_key, 0, 33, their_network_key_ref.compressed_form);
7146         LDKUserConfig override_config_conv;
7147         override_config_conv.inner = (void*)(override_config & (~1));
7148         override_config_conv.is_owned = (override_config & 1) || (override_config == 0);
7149         if (override_config_conv.inner != NULL)
7150                 override_config_conv = UserConfig_clone(&override_config_conv);
7151         LDKCResult_NoneAPIErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneAPIErrorZ), "LDKCResult_NoneAPIErrorZ");
7152         *ret_conv = ChannelManager_create_channel(&this_arg_conv, their_network_key_ref, channel_value_satoshis, push_msat, user_id, override_config_conv);
7153         return (long)ret_conv;
7154 }
7155
7156 JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_ChannelManager_1list_1channels(JNIEnv * _env, jclass _b, jlong this_arg) {
7157         LDKChannelManager this_arg_conv;
7158         this_arg_conv.inner = (void*)(this_arg & (~1));
7159         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
7160         LDKCVec_ChannelDetailsZ ret_var = ChannelManager_list_channels(&this_arg_conv);
7161         jlongArray ret_arr = (*_env)->NewLongArray(_env, ret_var.datalen);
7162         jlong *ret_arr_ptr = (*_env)->GetPrimitiveArrayCritical(_env, ret_arr, NULL);
7163         for (size_t q = 0; q < ret_var.datalen; q++) {
7164                 LDKChannelDetails arr_conv_16_var = ret_var.data[q];
7165                 CHECK((((long)arr_conv_16_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7166                 CHECK((((long)&arr_conv_16_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7167                 long arr_conv_16_ref = (long)arr_conv_16_var.inner;
7168                 if (arr_conv_16_var.is_owned) {
7169                         arr_conv_16_ref |= 1;
7170                 }
7171                 ret_arr_ptr[q] = arr_conv_16_ref;
7172         }
7173         (*_env)->ReleasePrimitiveArrayCritical(_env, ret_arr, ret_arr_ptr, 0);
7174         FREE(ret_var.data);
7175         return ret_arr;
7176 }
7177
7178 JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_ChannelManager_1list_1usable_1channels(JNIEnv * _env, jclass _b, jlong this_arg) {
7179         LDKChannelManager this_arg_conv;
7180         this_arg_conv.inner = (void*)(this_arg & (~1));
7181         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
7182         LDKCVec_ChannelDetailsZ ret_var = ChannelManager_list_usable_channels(&this_arg_conv);
7183         jlongArray ret_arr = (*_env)->NewLongArray(_env, ret_var.datalen);
7184         jlong *ret_arr_ptr = (*_env)->GetPrimitiveArrayCritical(_env, ret_arr, NULL);
7185         for (size_t q = 0; q < ret_var.datalen; q++) {
7186                 LDKChannelDetails arr_conv_16_var = ret_var.data[q];
7187                 CHECK((((long)arr_conv_16_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7188                 CHECK((((long)&arr_conv_16_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7189                 long arr_conv_16_ref = (long)arr_conv_16_var.inner;
7190                 if (arr_conv_16_var.is_owned) {
7191                         arr_conv_16_ref |= 1;
7192                 }
7193                 ret_arr_ptr[q] = arr_conv_16_ref;
7194         }
7195         (*_env)->ReleasePrimitiveArrayCritical(_env, ret_arr, ret_arr_ptr, 0);
7196         FREE(ret_var.data);
7197         return ret_arr;
7198 }
7199
7200 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelManager_1close_1channel(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray channel_id) {
7201         LDKChannelManager this_arg_conv;
7202         this_arg_conv.inner = (void*)(this_arg & (~1));
7203         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
7204         unsigned char channel_id_arr[32];
7205         CHECK((*_env)->GetArrayLength (_env, channel_id) == 32);
7206         (*_env)->GetByteArrayRegion (_env, channel_id, 0, 32, channel_id_arr);
7207         unsigned char (*channel_id_ref)[32] = &channel_id_arr;
7208         LDKCResult_NoneAPIErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneAPIErrorZ), "LDKCResult_NoneAPIErrorZ");
7209         *ret_conv = ChannelManager_close_channel(&this_arg_conv, channel_id_ref);
7210         return (long)ret_conv;
7211 }
7212
7213 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelManager_1force_1close_1channel(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray channel_id) {
7214         LDKChannelManager this_arg_conv;
7215         this_arg_conv.inner = (void*)(this_arg & (~1));
7216         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
7217         unsigned char channel_id_arr[32];
7218         CHECK((*_env)->GetArrayLength (_env, channel_id) == 32);
7219         (*_env)->GetByteArrayRegion (_env, channel_id, 0, 32, channel_id_arr);
7220         unsigned char (*channel_id_ref)[32] = &channel_id_arr;
7221         ChannelManager_force_close_channel(&this_arg_conv, channel_id_ref);
7222 }
7223
7224 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelManager_1force_1close_1all_1channels(JNIEnv * _env, jclass _b, jlong this_arg) {
7225         LDKChannelManager this_arg_conv;
7226         this_arg_conv.inner = (void*)(this_arg & (~1));
7227         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
7228         ChannelManager_force_close_all_channels(&this_arg_conv);
7229 }
7230
7231 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) {
7232         LDKChannelManager this_arg_conv;
7233         this_arg_conv.inner = (void*)(this_arg & (~1));
7234         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
7235         LDKRoute route_conv;
7236         route_conv.inner = (void*)(route & (~1));
7237         route_conv.is_owned = (route & 1) || (route == 0);
7238         LDKThirtyTwoBytes payment_hash_ref;
7239         CHECK((*_env)->GetArrayLength (_env, payment_hash) == 32);
7240         (*_env)->GetByteArrayRegion (_env, payment_hash, 0, 32, payment_hash_ref.data);
7241         LDKThirtyTwoBytes payment_secret_ref;
7242         CHECK((*_env)->GetArrayLength (_env, payment_secret) == 32);
7243         (*_env)->GetByteArrayRegion (_env, payment_secret, 0, 32, payment_secret_ref.data);
7244         LDKCResult_NonePaymentSendFailureZ* ret_conv = MALLOC(sizeof(LDKCResult_NonePaymentSendFailureZ), "LDKCResult_NonePaymentSendFailureZ");
7245         *ret_conv = ChannelManager_send_payment(&this_arg_conv, &route_conv, payment_hash_ref, payment_secret_ref);
7246         return (long)ret_conv;
7247 }
7248
7249 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) {
7250         LDKChannelManager this_arg_conv;
7251         this_arg_conv.inner = (void*)(this_arg & (~1));
7252         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
7253         unsigned char temporary_channel_id_arr[32];
7254         CHECK((*_env)->GetArrayLength (_env, temporary_channel_id) == 32);
7255         (*_env)->GetByteArrayRegion (_env, temporary_channel_id, 0, 32, temporary_channel_id_arr);
7256         unsigned char (*temporary_channel_id_ref)[32] = &temporary_channel_id_arr;
7257         LDKOutPoint funding_txo_conv;
7258         funding_txo_conv.inner = (void*)(funding_txo & (~1));
7259         funding_txo_conv.is_owned = (funding_txo & 1) || (funding_txo == 0);
7260         if (funding_txo_conv.inner != NULL)
7261                 funding_txo_conv = OutPoint_clone(&funding_txo_conv);
7262         ChannelManager_funding_transaction_generated(&this_arg_conv, temporary_channel_id_ref, funding_txo_conv);
7263 }
7264
7265 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) {
7266         LDKChannelManager this_arg_conv;
7267         this_arg_conv.inner = (void*)(this_arg & (~1));
7268         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
7269         LDKThreeBytes rgb_ref;
7270         CHECK((*_env)->GetArrayLength (_env, rgb) == 3);
7271         (*_env)->GetByteArrayRegion (_env, rgb, 0, 3, rgb_ref.data);
7272         LDKThirtyTwoBytes alias_ref;
7273         CHECK((*_env)->GetArrayLength (_env, alias) == 32);
7274         (*_env)->GetByteArrayRegion (_env, alias, 0, 32, alias_ref.data);
7275         LDKCVec_NetAddressZ addresses_constr;
7276         addresses_constr.datalen = (*_env)->GetArrayLength (_env, addresses);
7277         if (addresses_constr.datalen > 0)
7278                 addresses_constr.data = MALLOC(addresses_constr.datalen * sizeof(LDKNetAddress), "LDKCVec_NetAddressZ Elements");
7279         else
7280                 addresses_constr.data = NULL;
7281         long* addresses_vals = (*_env)->GetLongArrayElements (_env, addresses, NULL);
7282         for (size_t m = 0; m < addresses_constr.datalen; m++) {
7283                 long arr_conv_12 = addresses_vals[m];
7284                 LDKNetAddress arr_conv_12_conv = *(LDKNetAddress*)arr_conv_12;
7285                 FREE((void*)arr_conv_12);
7286                 addresses_constr.data[m] = arr_conv_12_conv;
7287         }
7288         (*_env)->ReleaseLongArrayElements (_env, addresses, addresses_vals, 0);
7289         ChannelManager_broadcast_node_announcement(&this_arg_conv, rgb_ref, alias_ref, addresses_constr);
7290 }
7291
7292 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelManager_1process_1pending_1htlc_1forwards(JNIEnv * _env, jclass _b, jlong this_arg) {
7293         LDKChannelManager this_arg_conv;
7294         this_arg_conv.inner = (void*)(this_arg & (~1));
7295         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
7296         ChannelManager_process_pending_htlc_forwards(&this_arg_conv);
7297 }
7298
7299 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelManager_1timer_1chan_1freshness_1every_1min(JNIEnv * _env, jclass _b, jlong this_arg) {
7300         LDKChannelManager this_arg_conv;
7301         this_arg_conv.inner = (void*)(this_arg & (~1));
7302         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
7303         ChannelManager_timer_chan_freshness_every_min(&this_arg_conv);
7304 }
7305
7306 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) {
7307         LDKChannelManager this_arg_conv;
7308         this_arg_conv.inner = (void*)(this_arg & (~1));
7309         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
7310         unsigned char payment_hash_arr[32];
7311         CHECK((*_env)->GetArrayLength (_env, payment_hash) == 32);
7312         (*_env)->GetByteArrayRegion (_env, payment_hash, 0, 32, payment_hash_arr);
7313         unsigned char (*payment_hash_ref)[32] = &payment_hash_arr;
7314         LDKThirtyTwoBytes payment_secret_ref;
7315         CHECK((*_env)->GetArrayLength (_env, payment_secret) == 32);
7316         (*_env)->GetByteArrayRegion (_env, payment_secret, 0, 32, payment_secret_ref.data);
7317         jboolean ret_val = ChannelManager_fail_htlc_backwards(&this_arg_conv, payment_hash_ref, payment_secret_ref);
7318         return ret_val;
7319 }
7320
7321 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) {
7322         LDKChannelManager this_arg_conv;
7323         this_arg_conv.inner = (void*)(this_arg & (~1));
7324         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
7325         LDKThirtyTwoBytes payment_preimage_ref;
7326         CHECK((*_env)->GetArrayLength (_env, payment_preimage) == 32);
7327         (*_env)->GetByteArrayRegion (_env, payment_preimage, 0, 32, payment_preimage_ref.data);
7328         LDKThirtyTwoBytes payment_secret_ref;
7329         CHECK((*_env)->GetArrayLength (_env, payment_secret) == 32);
7330         (*_env)->GetByteArrayRegion (_env, payment_secret, 0, 32, payment_secret_ref.data);
7331         jboolean ret_val = ChannelManager_claim_funds(&this_arg_conv, payment_preimage_ref, payment_secret_ref, expected_amount);
7332         return ret_val;
7333 }
7334
7335 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelManager_1get_1our_1node_1id(JNIEnv * _env, jclass _b, jlong this_arg) {
7336         LDKChannelManager this_arg_conv;
7337         this_arg_conv.inner = (void*)(this_arg & (~1));
7338         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
7339         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
7340         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, ChannelManager_get_our_node_id(&this_arg_conv).compressed_form);
7341         return arg_arr;
7342 }
7343
7344 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) {
7345         LDKChannelManager this_arg_conv;
7346         this_arg_conv.inner = (void*)(this_arg & (~1));
7347         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
7348         LDKOutPoint funding_txo_conv;
7349         funding_txo_conv.inner = (void*)(funding_txo & (~1));
7350         funding_txo_conv.is_owned = (funding_txo & 1) || (funding_txo == 0);
7351         ChannelManager_channel_monitor_updated(&this_arg_conv, &funding_txo_conv, highest_applied_update_id);
7352 }
7353
7354 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelManager_1as_1MessageSendEventsProvider(JNIEnv * _env, jclass _b, jlong this_arg) {
7355         LDKChannelManager this_arg_conv;
7356         this_arg_conv.inner = (void*)(this_arg & (~1));
7357         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
7358         LDKMessageSendEventsProvider* ret = MALLOC(sizeof(LDKMessageSendEventsProvider), "LDKMessageSendEventsProvider");
7359         *ret = ChannelManager_as_MessageSendEventsProvider(&this_arg_conv);
7360         return (long)ret;
7361 }
7362
7363 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelManager_1as_1EventsProvider(JNIEnv * _env, jclass _b, jlong this_arg) {
7364         LDKChannelManager this_arg_conv;
7365         this_arg_conv.inner = (void*)(this_arg & (~1));
7366         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
7367         LDKEventsProvider* ret = MALLOC(sizeof(LDKEventsProvider), "LDKEventsProvider");
7368         *ret = ChannelManager_as_EventsProvider(&this_arg_conv);
7369         return (long)ret;
7370 }
7371
7372 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelManager_1block_1connected(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray header, jlongArray txdata, jint height) {
7373         LDKChannelManager this_arg_conv;
7374         this_arg_conv.inner = (void*)(this_arg & (~1));
7375         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
7376         unsigned char header_arr[80];
7377         CHECK((*_env)->GetArrayLength (_env, header) == 80);
7378         (*_env)->GetByteArrayRegion (_env, header, 0, 80, header_arr);
7379         unsigned char (*header_ref)[80] = &header_arr;
7380         LDKCVec_C2Tuple_usizeTransactionZZ txdata_constr;
7381         txdata_constr.datalen = (*_env)->GetArrayLength (_env, txdata);
7382         if (txdata_constr.datalen > 0)
7383                 txdata_constr.data = MALLOC(txdata_constr.datalen * sizeof(LDKC2Tuple_usizeTransactionZ), "LDKCVec_C2Tuple_usizeTransactionZZ Elements");
7384         else
7385                 txdata_constr.data = NULL;
7386         long* txdata_vals = (*_env)->GetLongArrayElements (_env, txdata, NULL);
7387         for (size_t d = 0; d < txdata_constr.datalen; d++) {
7388                 long arr_conv_29 = txdata_vals[d];
7389                 LDKC2Tuple_usizeTransactionZ arr_conv_29_conv = *(LDKC2Tuple_usizeTransactionZ*)arr_conv_29;
7390                 FREE((void*)arr_conv_29);
7391                 txdata_constr.data[d] = arr_conv_29_conv;
7392         }
7393         (*_env)->ReleaseLongArrayElements (_env, txdata, txdata_vals, 0);
7394         ChannelManager_block_connected(&this_arg_conv, header_ref, txdata_constr, height);
7395 }
7396
7397 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelManager_1block_1disconnected(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray header) {
7398         LDKChannelManager this_arg_conv;
7399         this_arg_conv.inner = (void*)(this_arg & (~1));
7400         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
7401         unsigned char header_arr[80];
7402         CHECK((*_env)->GetArrayLength (_env, header) == 80);
7403         (*_env)->GetByteArrayRegion (_env, header, 0, 80, header_arr);
7404         unsigned char (*header_ref)[80] = &header_arr;
7405         ChannelManager_block_disconnected(&this_arg_conv, header_ref);
7406 }
7407
7408 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelManager_1as_1ChannelMessageHandler(JNIEnv * _env, jclass _b, jlong this_arg) {
7409         LDKChannelManager this_arg_conv;
7410         this_arg_conv.inner = (void*)(this_arg & (~1));
7411         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
7412         LDKChannelMessageHandler* ret = MALLOC(sizeof(LDKChannelMessageHandler), "LDKChannelMessageHandler");
7413         *ret = ChannelManager_as_ChannelMessageHandler(&this_arg_conv);
7414         return (long)ret;
7415 }
7416
7417 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelManagerReadArgs_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
7418         LDKChannelManagerReadArgs this_ptr_conv;
7419         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7420         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7421         ChannelManagerReadArgs_free(this_ptr_conv);
7422 }
7423
7424 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelManagerReadArgs_1get_1keys_1manager(JNIEnv * _env, jclass _b, jlong this_ptr) {
7425         LDKChannelManagerReadArgs this_ptr_conv;
7426         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7427         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7428         long ret_ret = (long)ChannelManagerReadArgs_get_keys_manager(&this_ptr_conv);
7429         return ret_ret;
7430 }
7431
7432 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelManagerReadArgs_1set_1keys_1manager(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
7433         LDKChannelManagerReadArgs this_ptr_conv;
7434         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7435         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7436         LDKKeysInterface val_conv = *(LDKKeysInterface*)val;
7437         if (val_conv.free == LDKKeysInterface_JCalls_free) {
7438                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
7439                 LDKKeysInterface_JCalls_clone(val_conv.this_arg);
7440         }
7441         ChannelManagerReadArgs_set_keys_manager(&this_ptr_conv, val_conv);
7442 }
7443
7444 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelManagerReadArgs_1get_1fee_1estimator(JNIEnv * _env, jclass _b, jlong this_ptr) {
7445         LDKChannelManagerReadArgs this_ptr_conv;
7446         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7447         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7448         long ret_ret = (long)ChannelManagerReadArgs_get_fee_estimator(&this_ptr_conv);
7449         return ret_ret;
7450 }
7451
7452 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelManagerReadArgs_1set_1fee_1estimator(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
7453         LDKChannelManagerReadArgs this_ptr_conv;
7454         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7455         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7456         LDKFeeEstimator val_conv = *(LDKFeeEstimator*)val;
7457         if (val_conv.free == LDKFeeEstimator_JCalls_free) {
7458                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
7459                 LDKFeeEstimator_JCalls_clone(val_conv.this_arg);
7460         }
7461         ChannelManagerReadArgs_set_fee_estimator(&this_ptr_conv, val_conv);
7462 }
7463
7464 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelManagerReadArgs_1get_1chain_1monitor(JNIEnv * _env, jclass _b, jlong this_ptr) {
7465         LDKChannelManagerReadArgs this_ptr_conv;
7466         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7467         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7468         long ret_ret = (long)ChannelManagerReadArgs_get_chain_monitor(&this_ptr_conv);
7469         return ret_ret;
7470 }
7471
7472 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelManagerReadArgs_1set_1chain_1monitor(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
7473         LDKChannelManagerReadArgs this_ptr_conv;
7474         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7475         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7476         LDKWatch val_conv = *(LDKWatch*)val;
7477         if (val_conv.free == LDKWatch_JCalls_free) {
7478                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
7479                 LDKWatch_JCalls_clone(val_conv.this_arg);
7480         }
7481         ChannelManagerReadArgs_set_chain_monitor(&this_ptr_conv, val_conv);
7482 }
7483
7484 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelManagerReadArgs_1get_1tx_1broadcaster(JNIEnv * _env, jclass _b, jlong this_ptr) {
7485         LDKChannelManagerReadArgs this_ptr_conv;
7486         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7487         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7488         long ret_ret = (long)ChannelManagerReadArgs_get_tx_broadcaster(&this_ptr_conv);
7489         return ret_ret;
7490 }
7491
7492 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelManagerReadArgs_1set_1tx_1broadcaster(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
7493         LDKChannelManagerReadArgs this_ptr_conv;
7494         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7495         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7496         LDKBroadcasterInterface val_conv = *(LDKBroadcasterInterface*)val;
7497         if (val_conv.free == LDKBroadcasterInterface_JCalls_free) {
7498                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
7499                 LDKBroadcasterInterface_JCalls_clone(val_conv.this_arg);
7500         }
7501         ChannelManagerReadArgs_set_tx_broadcaster(&this_ptr_conv, val_conv);
7502 }
7503
7504 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelManagerReadArgs_1get_1logger(JNIEnv * _env, jclass _b, jlong this_ptr) {
7505         LDKChannelManagerReadArgs this_ptr_conv;
7506         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7507         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7508         long ret_ret = (long)ChannelManagerReadArgs_get_logger(&this_ptr_conv);
7509         return ret_ret;
7510 }
7511
7512 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelManagerReadArgs_1set_1logger(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
7513         LDKChannelManagerReadArgs this_ptr_conv;
7514         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7515         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7516         LDKLogger val_conv = *(LDKLogger*)val;
7517         if (val_conv.free == LDKLogger_JCalls_free) {
7518                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
7519                 LDKLogger_JCalls_clone(val_conv.this_arg);
7520         }
7521         ChannelManagerReadArgs_set_logger(&this_ptr_conv, val_conv);
7522 }
7523
7524 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelManagerReadArgs_1get_1default_1config(JNIEnv * _env, jclass _b, jlong this_ptr) {
7525         LDKChannelManagerReadArgs this_ptr_conv;
7526         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7527         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7528         LDKUserConfig ret_var = ChannelManagerReadArgs_get_default_config(&this_ptr_conv);
7529         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7530         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7531         long ret_ref = (long)ret_var.inner;
7532         if (ret_var.is_owned) {
7533                 ret_ref |= 1;
7534         }
7535         return ret_ref;
7536 }
7537
7538 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelManagerReadArgs_1set_1default_1config(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
7539         LDKChannelManagerReadArgs this_ptr_conv;
7540         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7541         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7542         LDKUserConfig val_conv;
7543         val_conv.inner = (void*)(val & (~1));
7544         val_conv.is_owned = (val & 1) || (val == 0);
7545         if (val_conv.inner != NULL)
7546                 val_conv = UserConfig_clone(&val_conv);
7547         ChannelManagerReadArgs_set_default_config(&this_ptr_conv, val_conv);
7548 }
7549
7550 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) {
7551         LDKKeysInterface keys_manager_conv = *(LDKKeysInterface*)keys_manager;
7552         if (keys_manager_conv.free == LDKKeysInterface_JCalls_free) {
7553                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
7554                 LDKKeysInterface_JCalls_clone(keys_manager_conv.this_arg);
7555         }
7556         LDKFeeEstimator fee_estimator_conv = *(LDKFeeEstimator*)fee_estimator;
7557         if (fee_estimator_conv.free == LDKFeeEstimator_JCalls_free) {
7558                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
7559                 LDKFeeEstimator_JCalls_clone(fee_estimator_conv.this_arg);
7560         }
7561         LDKWatch chain_monitor_conv = *(LDKWatch*)chain_monitor;
7562         if (chain_monitor_conv.free == LDKWatch_JCalls_free) {
7563                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
7564                 LDKWatch_JCalls_clone(chain_monitor_conv.this_arg);
7565         }
7566         LDKBroadcasterInterface tx_broadcaster_conv = *(LDKBroadcasterInterface*)tx_broadcaster;
7567         if (tx_broadcaster_conv.free == LDKBroadcasterInterface_JCalls_free) {
7568                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
7569                 LDKBroadcasterInterface_JCalls_clone(tx_broadcaster_conv.this_arg);
7570         }
7571         LDKLogger logger_conv = *(LDKLogger*)logger;
7572         if (logger_conv.free == LDKLogger_JCalls_free) {
7573                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
7574                 LDKLogger_JCalls_clone(logger_conv.this_arg);
7575         }
7576         LDKUserConfig default_config_conv;
7577         default_config_conv.inner = (void*)(default_config & (~1));
7578         default_config_conv.is_owned = (default_config & 1) || (default_config == 0);
7579         if (default_config_conv.inner != NULL)
7580                 default_config_conv = UserConfig_clone(&default_config_conv);
7581         LDKCVec_ChannelMonitorZ channel_monitors_constr;
7582         channel_monitors_constr.datalen = (*_env)->GetArrayLength (_env, channel_monitors);
7583         if (channel_monitors_constr.datalen > 0)
7584                 channel_monitors_constr.data = MALLOC(channel_monitors_constr.datalen * sizeof(LDKChannelMonitor), "LDKCVec_ChannelMonitorZ Elements");
7585         else
7586                 channel_monitors_constr.data = NULL;
7587         long* channel_monitors_vals = (*_env)->GetLongArrayElements (_env, channel_monitors, NULL);
7588         for (size_t q = 0; q < channel_monitors_constr.datalen; q++) {
7589                 long arr_conv_16 = channel_monitors_vals[q];
7590                 LDKChannelMonitor arr_conv_16_conv;
7591                 arr_conv_16_conv.inner = (void*)(arr_conv_16 & (~1));
7592                 arr_conv_16_conv.is_owned = (arr_conv_16 & 1) || (arr_conv_16 == 0);
7593                 channel_monitors_constr.data[q] = arr_conv_16_conv;
7594         }
7595         (*_env)->ReleaseLongArrayElements (_env, channel_monitors, channel_monitors_vals, 0);
7596         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);
7597         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7598         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7599         long ret_ref = (long)ret_var.inner;
7600         if (ret_var.is_owned) {
7601                 ret_ref |= 1;
7602         }
7603         return ret_ref;
7604 }
7605
7606 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_DecodeError_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
7607         LDKDecodeError this_ptr_conv;
7608         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7609         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7610         DecodeError_free(this_ptr_conv);
7611 }
7612
7613 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Init_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
7614         LDKInit this_ptr_conv;
7615         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7616         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7617         Init_free(this_ptr_conv);
7618 }
7619
7620 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_Init_1clone(JNIEnv * _env, jclass _b, jlong orig) {
7621         LDKInit orig_conv;
7622         orig_conv.inner = (void*)(orig & (~1));
7623         orig_conv.is_owned = (orig & 1) || (orig == 0);
7624         LDKInit ret_var = Init_clone(&orig_conv);
7625         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7626         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7627         long ret_ref = (long)ret_var.inner;
7628         if (ret_var.is_owned) {
7629                 ret_ref |= 1;
7630         }
7631         return ret_ref;
7632 }
7633
7634 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ErrorMessage_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
7635         LDKErrorMessage this_ptr_conv;
7636         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7637         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7638         ErrorMessage_free(this_ptr_conv);
7639 }
7640
7641 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ErrorMessage_1clone(JNIEnv * _env, jclass _b, jlong orig) {
7642         LDKErrorMessage orig_conv;
7643         orig_conv.inner = (void*)(orig & (~1));
7644         orig_conv.is_owned = (orig & 1) || (orig == 0);
7645         LDKErrorMessage ret_var = ErrorMessage_clone(&orig_conv);
7646         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7647         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7648         long ret_ref = (long)ret_var.inner;
7649         if (ret_var.is_owned) {
7650                 ret_ref |= 1;
7651         }
7652         return ret_ref;
7653 }
7654
7655 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ErrorMessage_1get_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
7656         LDKErrorMessage this_ptr_conv;
7657         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7658         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7659         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
7660         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *ErrorMessage_get_channel_id(&this_ptr_conv));
7661         return ret_arr;
7662 }
7663
7664 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ErrorMessage_1set_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
7665         LDKErrorMessage this_ptr_conv;
7666         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7667         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7668         LDKThirtyTwoBytes val_ref;
7669         CHECK((*_env)->GetArrayLength (_env, val) == 32);
7670         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
7671         ErrorMessage_set_channel_id(&this_ptr_conv, val_ref);
7672 }
7673
7674 JNIEXPORT jstring JNICALL Java_org_ldk_impl_bindings_ErrorMessage_1get_1data(JNIEnv * _env, jclass _b, jlong this_ptr) {
7675         LDKErrorMessage this_ptr_conv;
7676         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7677         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7678         LDKStr _str = ErrorMessage_get_data(&this_ptr_conv);
7679         char* _buf = MALLOC(_str.len + 1, "str conv buf");
7680         memcpy(_buf, _str.chars, _str.len);
7681         _buf[_str.len] = 0;
7682         jstring _conv = (*_env)->NewStringUTF(_env, _str.chars);
7683         FREE(_buf);
7684         return _conv;
7685 }
7686
7687 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ErrorMessage_1set_1data(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
7688         LDKErrorMessage this_ptr_conv;
7689         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7690         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7691         LDKCVec_u8Z val_ref;
7692         val_ref.data = (*_env)->GetByteArrayElements (_env, val, NULL);
7693         val_ref.datalen = (*_env)->GetArrayLength (_env, val);
7694         ErrorMessage_set_data(&this_ptr_conv, val_ref);
7695         (*_env)->ReleaseByteArrayElements(_env, val, (int8_t*)val_ref.data, 0);
7696 }
7697
7698 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ErrorMessage_1new(JNIEnv * _env, jclass _b, jbyteArray channel_id_arg, jbyteArray data_arg) {
7699         LDKThirtyTwoBytes channel_id_arg_ref;
7700         CHECK((*_env)->GetArrayLength (_env, channel_id_arg) == 32);
7701         (*_env)->GetByteArrayRegion (_env, channel_id_arg, 0, 32, channel_id_arg_ref.data);
7702         LDKCVec_u8Z data_arg_ref;
7703         data_arg_ref.data = (*_env)->GetByteArrayElements (_env, data_arg, NULL);
7704         data_arg_ref.datalen = (*_env)->GetArrayLength (_env, data_arg);
7705         LDKErrorMessage ret_var = ErrorMessage_new(channel_id_arg_ref, data_arg_ref);
7706         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7707         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7708         long ret_ref = (long)ret_var.inner;
7709         if (ret_var.is_owned) {
7710                 ret_ref |= 1;
7711         }
7712         (*_env)->ReleaseByteArrayElements(_env, data_arg, (int8_t*)data_arg_ref.data, 0);
7713         return ret_ref;
7714 }
7715
7716 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Ping_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
7717         LDKPing this_ptr_conv;
7718         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7719         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7720         Ping_free(this_ptr_conv);
7721 }
7722
7723 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_Ping_1clone(JNIEnv * _env, jclass _b, jlong orig) {
7724         LDKPing orig_conv;
7725         orig_conv.inner = (void*)(orig & (~1));
7726         orig_conv.is_owned = (orig & 1) || (orig == 0);
7727         LDKPing ret_var = Ping_clone(&orig_conv);
7728         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7729         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7730         long ret_ref = (long)ret_var.inner;
7731         if (ret_var.is_owned) {
7732                 ret_ref |= 1;
7733         }
7734         return ret_ref;
7735 }
7736
7737 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_Ping_1get_1ponglen(JNIEnv * _env, jclass _b, jlong this_ptr) {
7738         LDKPing this_ptr_conv;
7739         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7740         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7741         jshort ret_val = Ping_get_ponglen(&this_ptr_conv);
7742         return ret_val;
7743 }
7744
7745 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Ping_1set_1ponglen(JNIEnv * _env, jclass _b, jlong this_ptr, jshort val) {
7746         LDKPing this_ptr_conv;
7747         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7748         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7749         Ping_set_ponglen(&this_ptr_conv, val);
7750 }
7751
7752 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_Ping_1get_1byteslen(JNIEnv * _env, jclass _b, jlong this_ptr) {
7753         LDKPing this_ptr_conv;
7754         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7755         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7756         jshort ret_val = Ping_get_byteslen(&this_ptr_conv);
7757         return ret_val;
7758 }
7759
7760 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Ping_1set_1byteslen(JNIEnv * _env, jclass _b, jlong this_ptr, jshort val) {
7761         LDKPing this_ptr_conv;
7762         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7763         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7764         Ping_set_byteslen(&this_ptr_conv, val);
7765 }
7766
7767 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_Ping_1new(JNIEnv * _env, jclass _b, jshort ponglen_arg, jshort byteslen_arg) {
7768         LDKPing ret_var = Ping_new(ponglen_arg, byteslen_arg);
7769         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7770         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7771         long ret_ref = (long)ret_var.inner;
7772         if (ret_var.is_owned) {
7773                 ret_ref |= 1;
7774         }
7775         return ret_ref;
7776 }
7777
7778 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Pong_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
7779         LDKPong this_ptr_conv;
7780         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7781         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7782         Pong_free(this_ptr_conv);
7783 }
7784
7785 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_Pong_1clone(JNIEnv * _env, jclass _b, jlong orig) {
7786         LDKPong orig_conv;
7787         orig_conv.inner = (void*)(orig & (~1));
7788         orig_conv.is_owned = (orig & 1) || (orig == 0);
7789         LDKPong ret_var = Pong_clone(&orig_conv);
7790         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7791         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7792         long ret_ref = (long)ret_var.inner;
7793         if (ret_var.is_owned) {
7794                 ret_ref |= 1;
7795         }
7796         return ret_ref;
7797 }
7798
7799 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_Pong_1get_1byteslen(JNIEnv * _env, jclass _b, jlong this_ptr) {
7800         LDKPong this_ptr_conv;
7801         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7802         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7803         jshort ret_val = Pong_get_byteslen(&this_ptr_conv);
7804         return ret_val;
7805 }
7806
7807 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Pong_1set_1byteslen(JNIEnv * _env, jclass _b, jlong this_ptr, jshort val) {
7808         LDKPong this_ptr_conv;
7809         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7810         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7811         Pong_set_byteslen(&this_ptr_conv, val);
7812 }
7813
7814 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_Pong_1new(JNIEnv * _env, jclass _b, jshort byteslen_arg) {
7815         LDKPong ret_var = Pong_new(byteslen_arg);
7816         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7817         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7818         long ret_ref = (long)ret_var.inner;
7819         if (ret_var.is_owned) {
7820                 ret_ref |= 1;
7821         }
7822         return ret_ref;
7823 }
7824
7825 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
7826         LDKOpenChannel this_ptr_conv;
7827         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7828         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7829         OpenChannel_free(this_ptr_conv);
7830 }
7831
7832 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_OpenChannel_1clone(JNIEnv * _env, jclass _b, jlong orig) {
7833         LDKOpenChannel orig_conv;
7834         orig_conv.inner = (void*)(orig & (~1));
7835         orig_conv.is_owned = (orig & 1) || (orig == 0);
7836         LDKOpenChannel ret_var = OpenChannel_clone(&orig_conv);
7837         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7838         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7839         long ret_ref = (long)ret_var.inner;
7840         if (ret_var.is_owned) {
7841                 ret_ref |= 1;
7842         }
7843         return ret_ref;
7844 }
7845
7846 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1chain_1hash(JNIEnv * _env, jclass _b, jlong this_ptr) {
7847         LDKOpenChannel this_ptr_conv;
7848         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7849         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7850         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
7851         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *OpenChannel_get_chain_hash(&this_ptr_conv));
7852         return ret_arr;
7853 }
7854
7855 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1chain_1hash(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
7856         LDKOpenChannel this_ptr_conv;
7857         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7858         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7859         LDKThirtyTwoBytes val_ref;
7860         CHECK((*_env)->GetArrayLength (_env, val) == 32);
7861         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
7862         OpenChannel_set_chain_hash(&this_ptr_conv, val_ref);
7863 }
7864
7865 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1temporary_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
7866         LDKOpenChannel this_ptr_conv;
7867         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7868         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7869         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
7870         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *OpenChannel_get_temporary_channel_id(&this_ptr_conv));
7871         return ret_arr;
7872 }
7873
7874 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1temporary_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
7875         LDKOpenChannel this_ptr_conv;
7876         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7877         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7878         LDKThirtyTwoBytes val_ref;
7879         CHECK((*_env)->GetArrayLength (_env, val) == 32);
7880         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
7881         OpenChannel_set_temporary_channel_id(&this_ptr_conv, val_ref);
7882 }
7883
7884 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1funding_1satoshis(JNIEnv * _env, jclass _b, jlong this_ptr) {
7885         LDKOpenChannel this_ptr_conv;
7886         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7887         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7888         jlong ret_val = OpenChannel_get_funding_satoshis(&this_ptr_conv);
7889         return ret_val;
7890 }
7891
7892 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1funding_1satoshis(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
7893         LDKOpenChannel this_ptr_conv;
7894         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7895         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7896         OpenChannel_set_funding_satoshis(&this_ptr_conv, val);
7897 }
7898
7899 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1push_1msat(JNIEnv * _env, jclass _b, jlong this_ptr) {
7900         LDKOpenChannel this_ptr_conv;
7901         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7902         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7903         jlong ret_val = OpenChannel_get_push_msat(&this_ptr_conv);
7904         return ret_val;
7905 }
7906
7907 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1push_1msat(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
7908         LDKOpenChannel this_ptr_conv;
7909         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7910         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7911         OpenChannel_set_push_msat(&this_ptr_conv, val);
7912 }
7913
7914 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1dust_1limit_1satoshis(JNIEnv * _env, jclass _b, jlong this_ptr) {
7915         LDKOpenChannel this_ptr_conv;
7916         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7917         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7918         jlong ret_val = OpenChannel_get_dust_limit_satoshis(&this_ptr_conv);
7919         return ret_val;
7920 }
7921
7922 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1dust_1limit_1satoshis(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
7923         LDKOpenChannel this_ptr_conv;
7924         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7925         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7926         OpenChannel_set_dust_limit_satoshis(&this_ptr_conv, val);
7927 }
7928
7929 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1max_1htlc_1value_1in_1flight_1msat(JNIEnv * _env, jclass _b, jlong this_ptr) {
7930         LDKOpenChannel this_ptr_conv;
7931         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7932         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7933         jlong ret_val = OpenChannel_get_max_htlc_value_in_flight_msat(&this_ptr_conv);
7934         return ret_val;
7935 }
7936
7937 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) {
7938         LDKOpenChannel this_ptr_conv;
7939         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7940         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7941         OpenChannel_set_max_htlc_value_in_flight_msat(&this_ptr_conv, val);
7942 }
7943
7944 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1channel_1reserve_1satoshis(JNIEnv * _env, jclass _b, jlong this_ptr) {
7945         LDKOpenChannel this_ptr_conv;
7946         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7947         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7948         jlong ret_val = OpenChannel_get_channel_reserve_satoshis(&this_ptr_conv);
7949         return ret_val;
7950 }
7951
7952 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1channel_1reserve_1satoshis(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
7953         LDKOpenChannel this_ptr_conv;
7954         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7955         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7956         OpenChannel_set_channel_reserve_satoshis(&this_ptr_conv, val);
7957 }
7958
7959 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1htlc_1minimum_1msat(JNIEnv * _env, jclass _b, jlong this_ptr) {
7960         LDKOpenChannel this_ptr_conv;
7961         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7962         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7963         jlong ret_val = OpenChannel_get_htlc_minimum_msat(&this_ptr_conv);
7964         return ret_val;
7965 }
7966
7967 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1htlc_1minimum_1msat(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
7968         LDKOpenChannel this_ptr_conv;
7969         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7970         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7971         OpenChannel_set_htlc_minimum_msat(&this_ptr_conv, val);
7972 }
7973
7974 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1feerate_1per_1kw(JNIEnv * _env, jclass _b, jlong this_ptr) {
7975         LDKOpenChannel this_ptr_conv;
7976         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7977         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7978         jint ret_val = OpenChannel_get_feerate_per_kw(&this_ptr_conv);
7979         return ret_val;
7980 }
7981
7982 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1feerate_1per_1kw(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
7983         LDKOpenChannel this_ptr_conv;
7984         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7985         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7986         OpenChannel_set_feerate_per_kw(&this_ptr_conv, val);
7987 }
7988
7989 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1to_1self_1delay(JNIEnv * _env, jclass _b, jlong this_ptr) {
7990         LDKOpenChannel this_ptr_conv;
7991         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7992         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7993         jshort ret_val = OpenChannel_get_to_self_delay(&this_ptr_conv);
7994         return ret_val;
7995 }
7996
7997 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1to_1self_1delay(JNIEnv * _env, jclass _b, jlong this_ptr, jshort val) {
7998         LDKOpenChannel this_ptr_conv;
7999         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8000         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8001         OpenChannel_set_to_self_delay(&this_ptr_conv, val);
8002 }
8003
8004 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1max_1accepted_1htlcs(JNIEnv * _env, jclass _b, jlong this_ptr) {
8005         LDKOpenChannel this_ptr_conv;
8006         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8007         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8008         jshort ret_val = OpenChannel_get_max_accepted_htlcs(&this_ptr_conv);
8009         return ret_val;
8010 }
8011
8012 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1max_1accepted_1htlcs(JNIEnv * _env, jclass _b, jlong this_ptr, jshort val) {
8013         LDKOpenChannel this_ptr_conv;
8014         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8015         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8016         OpenChannel_set_max_accepted_htlcs(&this_ptr_conv, val);
8017 }
8018
8019 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1funding_1pubkey(JNIEnv * _env, jclass _b, jlong this_ptr) {
8020         LDKOpenChannel this_ptr_conv;
8021         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8022         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8023         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
8024         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, OpenChannel_get_funding_pubkey(&this_ptr_conv).compressed_form);
8025         return arg_arr;
8026 }
8027
8028 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1funding_1pubkey(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
8029         LDKOpenChannel this_ptr_conv;
8030         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8031         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8032         LDKPublicKey val_ref;
8033         CHECK((*_env)->GetArrayLength (_env, val) == 33);
8034         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
8035         OpenChannel_set_funding_pubkey(&this_ptr_conv, val_ref);
8036 }
8037
8038 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1revocation_1basepoint(JNIEnv * _env, jclass _b, jlong this_ptr) {
8039         LDKOpenChannel this_ptr_conv;
8040         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8041         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8042         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
8043         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, OpenChannel_get_revocation_basepoint(&this_ptr_conv).compressed_form);
8044         return arg_arr;
8045 }
8046
8047 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1revocation_1basepoint(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
8048         LDKOpenChannel this_ptr_conv;
8049         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8050         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8051         LDKPublicKey val_ref;
8052         CHECK((*_env)->GetArrayLength (_env, val) == 33);
8053         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
8054         OpenChannel_set_revocation_basepoint(&this_ptr_conv, val_ref);
8055 }
8056
8057 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1payment_1point(JNIEnv * _env, jclass _b, jlong this_ptr) {
8058         LDKOpenChannel this_ptr_conv;
8059         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8060         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8061         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
8062         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, OpenChannel_get_payment_point(&this_ptr_conv).compressed_form);
8063         return arg_arr;
8064 }
8065
8066 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1payment_1point(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
8067         LDKOpenChannel this_ptr_conv;
8068         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8069         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8070         LDKPublicKey val_ref;
8071         CHECK((*_env)->GetArrayLength (_env, val) == 33);
8072         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
8073         OpenChannel_set_payment_point(&this_ptr_conv, val_ref);
8074 }
8075
8076 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1delayed_1payment_1basepoint(JNIEnv * _env, jclass _b, jlong this_ptr) {
8077         LDKOpenChannel this_ptr_conv;
8078         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8079         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8080         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
8081         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, OpenChannel_get_delayed_payment_basepoint(&this_ptr_conv).compressed_form);
8082         return arg_arr;
8083 }
8084
8085 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1delayed_1payment_1basepoint(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
8086         LDKOpenChannel this_ptr_conv;
8087         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8088         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8089         LDKPublicKey val_ref;
8090         CHECK((*_env)->GetArrayLength (_env, val) == 33);
8091         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
8092         OpenChannel_set_delayed_payment_basepoint(&this_ptr_conv, val_ref);
8093 }
8094
8095 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1htlc_1basepoint(JNIEnv * _env, jclass _b, jlong this_ptr) {
8096         LDKOpenChannel this_ptr_conv;
8097         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8098         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8099         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
8100         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, OpenChannel_get_htlc_basepoint(&this_ptr_conv).compressed_form);
8101         return arg_arr;
8102 }
8103
8104 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1htlc_1basepoint(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
8105         LDKOpenChannel this_ptr_conv;
8106         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8107         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8108         LDKPublicKey val_ref;
8109         CHECK((*_env)->GetArrayLength (_env, val) == 33);
8110         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
8111         OpenChannel_set_htlc_basepoint(&this_ptr_conv, val_ref);
8112 }
8113
8114 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1first_1per_1commitment_1point(JNIEnv * _env, jclass _b, jlong this_ptr) {
8115         LDKOpenChannel this_ptr_conv;
8116         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8117         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8118         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
8119         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, OpenChannel_get_first_per_commitment_point(&this_ptr_conv).compressed_form);
8120         return arg_arr;
8121 }
8122
8123 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1first_1per_1commitment_1point(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
8124         LDKOpenChannel this_ptr_conv;
8125         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8126         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8127         LDKPublicKey val_ref;
8128         CHECK((*_env)->GetArrayLength (_env, val) == 33);
8129         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
8130         OpenChannel_set_first_per_commitment_point(&this_ptr_conv, val_ref);
8131 }
8132
8133 JNIEXPORT jbyte JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1channel_1flags(JNIEnv * _env, jclass _b, jlong this_ptr) {
8134         LDKOpenChannel this_ptr_conv;
8135         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8136         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8137         jbyte ret_val = OpenChannel_get_channel_flags(&this_ptr_conv);
8138         return ret_val;
8139 }
8140
8141 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1channel_1flags(JNIEnv * _env, jclass _b, jlong this_ptr, jbyte val) {
8142         LDKOpenChannel this_ptr_conv;
8143         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8144         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8145         OpenChannel_set_channel_flags(&this_ptr_conv, val);
8146 }
8147
8148 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
8149         LDKAcceptChannel this_ptr_conv;
8150         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8151         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8152         AcceptChannel_free(this_ptr_conv);
8153 }
8154
8155 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1clone(JNIEnv * _env, jclass _b, jlong orig) {
8156         LDKAcceptChannel orig_conv;
8157         orig_conv.inner = (void*)(orig & (~1));
8158         orig_conv.is_owned = (orig & 1) || (orig == 0);
8159         LDKAcceptChannel ret_var = AcceptChannel_clone(&orig_conv);
8160         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8161         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8162         long ret_ref = (long)ret_var.inner;
8163         if (ret_var.is_owned) {
8164                 ret_ref |= 1;
8165         }
8166         return ret_ref;
8167 }
8168
8169 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1get_1temporary_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
8170         LDKAcceptChannel this_ptr_conv;
8171         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8172         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8173         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
8174         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *AcceptChannel_get_temporary_channel_id(&this_ptr_conv));
8175         return ret_arr;
8176 }
8177
8178 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1set_1temporary_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
8179         LDKAcceptChannel this_ptr_conv;
8180         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8181         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8182         LDKThirtyTwoBytes val_ref;
8183         CHECK((*_env)->GetArrayLength (_env, val) == 32);
8184         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
8185         AcceptChannel_set_temporary_channel_id(&this_ptr_conv, val_ref);
8186 }
8187
8188 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1get_1dust_1limit_1satoshis(JNIEnv * _env, jclass _b, jlong this_ptr) {
8189         LDKAcceptChannel this_ptr_conv;
8190         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8191         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8192         jlong ret_val = AcceptChannel_get_dust_limit_satoshis(&this_ptr_conv);
8193         return ret_val;
8194 }
8195
8196 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1set_1dust_1limit_1satoshis(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
8197         LDKAcceptChannel this_ptr_conv;
8198         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8199         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8200         AcceptChannel_set_dust_limit_satoshis(&this_ptr_conv, val);
8201 }
8202
8203 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1get_1max_1htlc_1value_1in_1flight_1msat(JNIEnv * _env, jclass _b, jlong this_ptr) {
8204         LDKAcceptChannel this_ptr_conv;
8205         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8206         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8207         jlong ret_val = AcceptChannel_get_max_htlc_value_in_flight_msat(&this_ptr_conv);
8208         return ret_val;
8209 }
8210
8211 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) {
8212         LDKAcceptChannel this_ptr_conv;
8213         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8214         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8215         AcceptChannel_set_max_htlc_value_in_flight_msat(&this_ptr_conv, val);
8216 }
8217
8218 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1get_1channel_1reserve_1satoshis(JNIEnv * _env, jclass _b, jlong this_ptr) {
8219         LDKAcceptChannel this_ptr_conv;
8220         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8221         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8222         jlong ret_val = AcceptChannel_get_channel_reserve_satoshis(&this_ptr_conv);
8223         return ret_val;
8224 }
8225
8226 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1set_1channel_1reserve_1satoshis(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
8227         LDKAcceptChannel this_ptr_conv;
8228         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8229         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8230         AcceptChannel_set_channel_reserve_satoshis(&this_ptr_conv, val);
8231 }
8232
8233 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1get_1htlc_1minimum_1msat(JNIEnv * _env, jclass _b, jlong this_ptr) {
8234         LDKAcceptChannel this_ptr_conv;
8235         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8236         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8237         jlong ret_val = AcceptChannel_get_htlc_minimum_msat(&this_ptr_conv);
8238         return ret_val;
8239 }
8240
8241 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1set_1htlc_1minimum_1msat(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
8242         LDKAcceptChannel this_ptr_conv;
8243         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8244         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8245         AcceptChannel_set_htlc_minimum_msat(&this_ptr_conv, val);
8246 }
8247
8248 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1get_1minimum_1depth(JNIEnv * _env, jclass _b, jlong this_ptr) {
8249         LDKAcceptChannel 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         jint ret_val = AcceptChannel_get_minimum_depth(&this_ptr_conv);
8253         return ret_val;
8254 }
8255
8256 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1set_1minimum_1depth(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
8257         LDKAcceptChannel this_ptr_conv;
8258         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8259         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8260         AcceptChannel_set_minimum_depth(&this_ptr_conv, val);
8261 }
8262
8263 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1get_1to_1self_1delay(JNIEnv * _env, jclass _b, jlong this_ptr) {
8264         LDKAcceptChannel this_ptr_conv;
8265         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8266         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8267         jshort ret_val = AcceptChannel_get_to_self_delay(&this_ptr_conv);
8268         return ret_val;
8269 }
8270
8271 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1set_1to_1self_1delay(JNIEnv * _env, jclass _b, jlong this_ptr, jshort val) {
8272         LDKAcceptChannel this_ptr_conv;
8273         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8274         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8275         AcceptChannel_set_to_self_delay(&this_ptr_conv, val);
8276 }
8277
8278 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1get_1max_1accepted_1htlcs(JNIEnv * _env, jclass _b, jlong this_ptr) {
8279         LDKAcceptChannel this_ptr_conv;
8280         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8281         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8282         jshort ret_val = AcceptChannel_get_max_accepted_htlcs(&this_ptr_conv);
8283         return ret_val;
8284 }
8285
8286 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1set_1max_1accepted_1htlcs(JNIEnv * _env, jclass _b, jlong this_ptr, jshort val) {
8287         LDKAcceptChannel this_ptr_conv;
8288         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8289         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8290         AcceptChannel_set_max_accepted_htlcs(&this_ptr_conv, val);
8291 }
8292
8293 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1get_1funding_1pubkey(JNIEnv * _env, jclass _b, jlong this_ptr) {
8294         LDKAcceptChannel this_ptr_conv;
8295         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8296         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8297         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
8298         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, AcceptChannel_get_funding_pubkey(&this_ptr_conv).compressed_form);
8299         return arg_arr;
8300 }
8301
8302 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1set_1funding_1pubkey(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
8303         LDKAcceptChannel this_ptr_conv;
8304         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8305         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8306         LDKPublicKey val_ref;
8307         CHECK((*_env)->GetArrayLength (_env, val) == 33);
8308         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
8309         AcceptChannel_set_funding_pubkey(&this_ptr_conv, val_ref);
8310 }
8311
8312 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1get_1revocation_1basepoint(JNIEnv * _env, jclass _b, jlong this_ptr) {
8313         LDKAcceptChannel this_ptr_conv;
8314         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8315         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8316         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
8317         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, AcceptChannel_get_revocation_basepoint(&this_ptr_conv).compressed_form);
8318         return arg_arr;
8319 }
8320
8321 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1set_1revocation_1basepoint(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
8322         LDKAcceptChannel this_ptr_conv;
8323         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8324         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8325         LDKPublicKey val_ref;
8326         CHECK((*_env)->GetArrayLength (_env, val) == 33);
8327         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
8328         AcceptChannel_set_revocation_basepoint(&this_ptr_conv, val_ref);
8329 }
8330
8331 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1get_1payment_1point(JNIEnv * _env, jclass _b, jlong this_ptr) {
8332         LDKAcceptChannel this_ptr_conv;
8333         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8334         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8335         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
8336         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, AcceptChannel_get_payment_point(&this_ptr_conv).compressed_form);
8337         return arg_arr;
8338 }
8339
8340 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1set_1payment_1point(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
8341         LDKAcceptChannel this_ptr_conv;
8342         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8343         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8344         LDKPublicKey val_ref;
8345         CHECK((*_env)->GetArrayLength (_env, val) == 33);
8346         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
8347         AcceptChannel_set_payment_point(&this_ptr_conv, val_ref);
8348 }
8349
8350 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1get_1delayed_1payment_1basepoint(JNIEnv * _env, jclass _b, jlong this_ptr) {
8351         LDKAcceptChannel this_ptr_conv;
8352         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8353         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8354         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
8355         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, AcceptChannel_get_delayed_payment_basepoint(&this_ptr_conv).compressed_form);
8356         return arg_arr;
8357 }
8358
8359 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1set_1delayed_1payment_1basepoint(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
8360         LDKAcceptChannel this_ptr_conv;
8361         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8362         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8363         LDKPublicKey val_ref;
8364         CHECK((*_env)->GetArrayLength (_env, val) == 33);
8365         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
8366         AcceptChannel_set_delayed_payment_basepoint(&this_ptr_conv, val_ref);
8367 }
8368
8369 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1get_1htlc_1basepoint(JNIEnv * _env, jclass _b, jlong this_ptr) {
8370         LDKAcceptChannel this_ptr_conv;
8371         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8372         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8373         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
8374         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, AcceptChannel_get_htlc_basepoint(&this_ptr_conv).compressed_form);
8375         return arg_arr;
8376 }
8377
8378 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1set_1htlc_1basepoint(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
8379         LDKAcceptChannel this_ptr_conv;
8380         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8381         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8382         LDKPublicKey val_ref;
8383         CHECK((*_env)->GetArrayLength (_env, val) == 33);
8384         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
8385         AcceptChannel_set_htlc_basepoint(&this_ptr_conv, val_ref);
8386 }
8387
8388 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1get_1first_1per_1commitment_1point(JNIEnv * _env, jclass _b, jlong this_ptr) {
8389         LDKAcceptChannel this_ptr_conv;
8390         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8391         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8392         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
8393         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, AcceptChannel_get_first_per_commitment_point(&this_ptr_conv).compressed_form);
8394         return arg_arr;
8395 }
8396
8397 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1set_1first_1per_1commitment_1point(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
8398         LDKAcceptChannel this_ptr_conv;
8399         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8400         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8401         LDKPublicKey val_ref;
8402         CHECK((*_env)->GetArrayLength (_env, val) == 33);
8403         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
8404         AcceptChannel_set_first_per_commitment_point(&this_ptr_conv, val_ref);
8405 }
8406
8407 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_FundingCreated_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
8408         LDKFundingCreated this_ptr_conv;
8409         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8410         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8411         FundingCreated_free(this_ptr_conv);
8412 }
8413
8414 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_FundingCreated_1clone(JNIEnv * _env, jclass _b, jlong orig) {
8415         LDKFundingCreated orig_conv;
8416         orig_conv.inner = (void*)(orig & (~1));
8417         orig_conv.is_owned = (orig & 1) || (orig == 0);
8418         LDKFundingCreated ret_var = FundingCreated_clone(&orig_conv);
8419         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8420         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8421         long ret_ref = (long)ret_var.inner;
8422         if (ret_var.is_owned) {
8423                 ret_ref |= 1;
8424         }
8425         return ret_ref;
8426 }
8427
8428 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_FundingCreated_1get_1temporary_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
8429         LDKFundingCreated this_ptr_conv;
8430         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8431         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8432         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
8433         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *FundingCreated_get_temporary_channel_id(&this_ptr_conv));
8434         return ret_arr;
8435 }
8436
8437 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_FundingCreated_1set_1temporary_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
8438         LDKFundingCreated this_ptr_conv;
8439         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8440         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8441         LDKThirtyTwoBytes val_ref;
8442         CHECK((*_env)->GetArrayLength (_env, val) == 32);
8443         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
8444         FundingCreated_set_temporary_channel_id(&this_ptr_conv, val_ref);
8445 }
8446
8447 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_FundingCreated_1get_1funding_1txid(JNIEnv * _env, jclass _b, jlong this_ptr) {
8448         LDKFundingCreated this_ptr_conv;
8449         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8450         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8451         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
8452         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *FundingCreated_get_funding_txid(&this_ptr_conv));
8453         return ret_arr;
8454 }
8455
8456 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_FundingCreated_1set_1funding_1txid(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
8457         LDKFundingCreated this_ptr_conv;
8458         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8459         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8460         LDKThirtyTwoBytes val_ref;
8461         CHECK((*_env)->GetArrayLength (_env, val) == 32);
8462         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
8463         FundingCreated_set_funding_txid(&this_ptr_conv, val_ref);
8464 }
8465
8466 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_FundingCreated_1get_1funding_1output_1index(JNIEnv * _env, jclass _b, jlong this_ptr) {
8467         LDKFundingCreated this_ptr_conv;
8468         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8469         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8470         jshort ret_val = FundingCreated_get_funding_output_index(&this_ptr_conv);
8471         return ret_val;
8472 }
8473
8474 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_FundingCreated_1set_1funding_1output_1index(JNIEnv * _env, jclass _b, jlong this_ptr, jshort val) {
8475         LDKFundingCreated this_ptr_conv;
8476         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8477         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8478         FundingCreated_set_funding_output_index(&this_ptr_conv, val);
8479 }
8480
8481 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_FundingCreated_1get_1signature(JNIEnv * _env, jclass _b, jlong this_ptr) {
8482         LDKFundingCreated this_ptr_conv;
8483         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8484         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8485         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 64);
8486         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 64, FundingCreated_get_signature(&this_ptr_conv).compact_form);
8487         return arg_arr;
8488 }
8489
8490 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_FundingCreated_1set_1signature(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
8491         LDKFundingCreated this_ptr_conv;
8492         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8493         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8494         LDKSignature val_ref;
8495         CHECK((*_env)->GetArrayLength (_env, val) == 64);
8496         (*_env)->GetByteArrayRegion (_env, val, 0, 64, val_ref.compact_form);
8497         FundingCreated_set_signature(&this_ptr_conv, val_ref);
8498 }
8499
8500 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) {
8501         LDKThirtyTwoBytes temporary_channel_id_arg_ref;
8502         CHECK((*_env)->GetArrayLength (_env, temporary_channel_id_arg) == 32);
8503         (*_env)->GetByteArrayRegion (_env, temporary_channel_id_arg, 0, 32, temporary_channel_id_arg_ref.data);
8504         LDKThirtyTwoBytes funding_txid_arg_ref;
8505         CHECK((*_env)->GetArrayLength (_env, funding_txid_arg) == 32);
8506         (*_env)->GetByteArrayRegion (_env, funding_txid_arg, 0, 32, funding_txid_arg_ref.data);
8507         LDKSignature signature_arg_ref;
8508         CHECK((*_env)->GetArrayLength (_env, signature_arg) == 64);
8509         (*_env)->GetByteArrayRegion (_env, signature_arg, 0, 64, signature_arg_ref.compact_form);
8510         LDKFundingCreated ret_var = FundingCreated_new(temporary_channel_id_arg_ref, funding_txid_arg_ref, funding_output_index_arg, signature_arg_ref);
8511         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8512         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8513         long ret_ref = (long)ret_var.inner;
8514         if (ret_var.is_owned) {
8515                 ret_ref |= 1;
8516         }
8517         return ret_ref;
8518 }
8519
8520 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_FundingSigned_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
8521         LDKFundingSigned this_ptr_conv;
8522         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8523         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8524         FundingSigned_free(this_ptr_conv);
8525 }
8526
8527 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_FundingSigned_1clone(JNIEnv * _env, jclass _b, jlong orig) {
8528         LDKFundingSigned orig_conv;
8529         orig_conv.inner = (void*)(orig & (~1));
8530         orig_conv.is_owned = (orig & 1) || (orig == 0);
8531         LDKFundingSigned ret_var = FundingSigned_clone(&orig_conv);
8532         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8533         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8534         long ret_ref = (long)ret_var.inner;
8535         if (ret_var.is_owned) {
8536                 ret_ref |= 1;
8537         }
8538         return ret_ref;
8539 }
8540
8541 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_FundingSigned_1get_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
8542         LDKFundingSigned this_ptr_conv;
8543         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8544         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8545         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
8546         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *FundingSigned_get_channel_id(&this_ptr_conv));
8547         return ret_arr;
8548 }
8549
8550 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_FundingSigned_1set_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
8551         LDKFundingSigned this_ptr_conv;
8552         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8553         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8554         LDKThirtyTwoBytes val_ref;
8555         CHECK((*_env)->GetArrayLength (_env, val) == 32);
8556         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
8557         FundingSigned_set_channel_id(&this_ptr_conv, val_ref);
8558 }
8559
8560 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_FundingSigned_1get_1signature(JNIEnv * _env, jclass _b, jlong this_ptr) {
8561         LDKFundingSigned this_ptr_conv;
8562         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8563         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8564         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 64);
8565         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 64, FundingSigned_get_signature(&this_ptr_conv).compact_form);
8566         return arg_arr;
8567 }
8568
8569 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_FundingSigned_1set_1signature(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
8570         LDKFundingSigned this_ptr_conv;
8571         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8572         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8573         LDKSignature val_ref;
8574         CHECK((*_env)->GetArrayLength (_env, val) == 64);
8575         (*_env)->GetByteArrayRegion (_env, val, 0, 64, val_ref.compact_form);
8576         FundingSigned_set_signature(&this_ptr_conv, val_ref);
8577 }
8578
8579 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_FundingSigned_1new(JNIEnv * _env, jclass _b, jbyteArray channel_id_arg, jbyteArray signature_arg) {
8580         LDKThirtyTwoBytes channel_id_arg_ref;
8581         CHECK((*_env)->GetArrayLength (_env, channel_id_arg) == 32);
8582         (*_env)->GetByteArrayRegion (_env, channel_id_arg, 0, 32, channel_id_arg_ref.data);
8583         LDKSignature signature_arg_ref;
8584         CHECK((*_env)->GetArrayLength (_env, signature_arg) == 64);
8585         (*_env)->GetByteArrayRegion (_env, signature_arg, 0, 64, signature_arg_ref.compact_form);
8586         LDKFundingSigned ret_var = FundingSigned_new(channel_id_arg_ref, signature_arg_ref);
8587         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8588         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8589         long ret_ref = (long)ret_var.inner;
8590         if (ret_var.is_owned) {
8591                 ret_ref |= 1;
8592         }
8593         return ret_ref;
8594 }
8595
8596 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_FundingLocked_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
8597         LDKFundingLocked this_ptr_conv;
8598         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8599         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8600         FundingLocked_free(this_ptr_conv);
8601 }
8602
8603 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_FundingLocked_1clone(JNIEnv * _env, jclass _b, jlong orig) {
8604         LDKFundingLocked orig_conv;
8605         orig_conv.inner = (void*)(orig & (~1));
8606         orig_conv.is_owned = (orig & 1) || (orig == 0);
8607         LDKFundingLocked ret_var = FundingLocked_clone(&orig_conv);
8608         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8609         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8610         long ret_ref = (long)ret_var.inner;
8611         if (ret_var.is_owned) {
8612                 ret_ref |= 1;
8613         }
8614         return ret_ref;
8615 }
8616
8617 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_FundingLocked_1get_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
8618         LDKFundingLocked this_ptr_conv;
8619         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8620         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8621         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
8622         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *FundingLocked_get_channel_id(&this_ptr_conv));
8623         return ret_arr;
8624 }
8625
8626 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_FundingLocked_1set_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
8627         LDKFundingLocked this_ptr_conv;
8628         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8629         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8630         LDKThirtyTwoBytes val_ref;
8631         CHECK((*_env)->GetArrayLength (_env, val) == 32);
8632         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
8633         FundingLocked_set_channel_id(&this_ptr_conv, val_ref);
8634 }
8635
8636 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_FundingLocked_1get_1next_1per_1commitment_1point(JNIEnv * _env, jclass _b, jlong this_ptr) {
8637         LDKFundingLocked this_ptr_conv;
8638         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8639         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8640         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
8641         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, FundingLocked_get_next_per_commitment_point(&this_ptr_conv).compressed_form);
8642         return arg_arr;
8643 }
8644
8645 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_FundingLocked_1set_1next_1per_1commitment_1point(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
8646         LDKFundingLocked this_ptr_conv;
8647         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8648         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8649         LDKPublicKey val_ref;
8650         CHECK((*_env)->GetArrayLength (_env, val) == 33);
8651         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
8652         FundingLocked_set_next_per_commitment_point(&this_ptr_conv, val_ref);
8653 }
8654
8655 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_FundingLocked_1new(JNIEnv * _env, jclass _b, jbyteArray channel_id_arg, jbyteArray next_per_commitment_point_arg) {
8656         LDKThirtyTwoBytes channel_id_arg_ref;
8657         CHECK((*_env)->GetArrayLength (_env, channel_id_arg) == 32);
8658         (*_env)->GetByteArrayRegion (_env, channel_id_arg, 0, 32, channel_id_arg_ref.data);
8659         LDKPublicKey next_per_commitment_point_arg_ref;
8660         CHECK((*_env)->GetArrayLength (_env, next_per_commitment_point_arg) == 33);
8661         (*_env)->GetByteArrayRegion (_env, next_per_commitment_point_arg, 0, 33, next_per_commitment_point_arg_ref.compressed_form);
8662         LDKFundingLocked ret_var = FundingLocked_new(channel_id_arg_ref, next_per_commitment_point_arg_ref);
8663         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8664         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8665         long ret_ref = (long)ret_var.inner;
8666         if (ret_var.is_owned) {
8667                 ret_ref |= 1;
8668         }
8669         return ret_ref;
8670 }
8671
8672 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Shutdown_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
8673         LDKShutdown this_ptr_conv;
8674         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8675         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8676         Shutdown_free(this_ptr_conv);
8677 }
8678
8679 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_Shutdown_1clone(JNIEnv * _env, jclass _b, jlong orig) {
8680         LDKShutdown orig_conv;
8681         orig_conv.inner = (void*)(orig & (~1));
8682         orig_conv.is_owned = (orig & 1) || (orig == 0);
8683         LDKShutdown ret_var = Shutdown_clone(&orig_conv);
8684         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8685         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8686         long ret_ref = (long)ret_var.inner;
8687         if (ret_var.is_owned) {
8688                 ret_ref |= 1;
8689         }
8690         return ret_ref;
8691 }
8692
8693 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_Shutdown_1get_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
8694         LDKShutdown this_ptr_conv;
8695         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8696         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8697         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
8698         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *Shutdown_get_channel_id(&this_ptr_conv));
8699         return ret_arr;
8700 }
8701
8702 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Shutdown_1set_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
8703         LDKShutdown this_ptr_conv;
8704         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8705         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8706         LDKThirtyTwoBytes val_ref;
8707         CHECK((*_env)->GetArrayLength (_env, val) == 32);
8708         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
8709         Shutdown_set_channel_id(&this_ptr_conv, val_ref);
8710 }
8711
8712 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_Shutdown_1get_1scriptpubkey(JNIEnv * _env, jclass _b, jlong this_ptr) {
8713         LDKShutdown this_ptr_conv;
8714         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8715         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8716         LDKu8slice arg_var = Shutdown_get_scriptpubkey(&this_ptr_conv);
8717         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
8718         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
8719         return arg_arr;
8720 }
8721
8722 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Shutdown_1set_1scriptpubkey(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
8723         LDKShutdown this_ptr_conv;
8724         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8725         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8726         LDKCVec_u8Z val_ref;
8727         val_ref.data = (*_env)->GetByteArrayElements (_env, val, NULL);
8728         val_ref.datalen = (*_env)->GetArrayLength (_env, val);
8729         Shutdown_set_scriptpubkey(&this_ptr_conv, val_ref);
8730         (*_env)->ReleaseByteArrayElements(_env, val, (int8_t*)val_ref.data, 0);
8731 }
8732
8733 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_Shutdown_1new(JNIEnv * _env, jclass _b, jbyteArray channel_id_arg, jbyteArray scriptpubkey_arg) {
8734         LDKThirtyTwoBytes channel_id_arg_ref;
8735         CHECK((*_env)->GetArrayLength (_env, channel_id_arg) == 32);
8736         (*_env)->GetByteArrayRegion (_env, channel_id_arg, 0, 32, channel_id_arg_ref.data);
8737         LDKCVec_u8Z scriptpubkey_arg_ref;
8738         scriptpubkey_arg_ref.data = (*_env)->GetByteArrayElements (_env, scriptpubkey_arg, NULL);
8739         scriptpubkey_arg_ref.datalen = (*_env)->GetArrayLength (_env, scriptpubkey_arg);
8740         LDKShutdown ret_var = Shutdown_new(channel_id_arg_ref, scriptpubkey_arg_ref);
8741         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8742         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8743         long ret_ref = (long)ret_var.inner;
8744         if (ret_var.is_owned) {
8745                 ret_ref |= 1;
8746         }
8747         (*_env)->ReleaseByteArrayElements(_env, scriptpubkey_arg, (int8_t*)scriptpubkey_arg_ref.data, 0);
8748         return ret_ref;
8749 }
8750
8751 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ClosingSigned_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
8752         LDKClosingSigned this_ptr_conv;
8753         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8754         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8755         ClosingSigned_free(this_ptr_conv);
8756 }
8757
8758 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ClosingSigned_1clone(JNIEnv * _env, jclass _b, jlong orig) {
8759         LDKClosingSigned orig_conv;
8760         orig_conv.inner = (void*)(orig & (~1));
8761         orig_conv.is_owned = (orig & 1) || (orig == 0);
8762         LDKClosingSigned ret_var = ClosingSigned_clone(&orig_conv);
8763         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8764         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8765         long ret_ref = (long)ret_var.inner;
8766         if (ret_var.is_owned) {
8767                 ret_ref |= 1;
8768         }
8769         return ret_ref;
8770 }
8771
8772 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ClosingSigned_1get_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
8773         LDKClosingSigned this_ptr_conv;
8774         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8775         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8776         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
8777         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *ClosingSigned_get_channel_id(&this_ptr_conv));
8778         return ret_arr;
8779 }
8780
8781 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ClosingSigned_1set_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
8782         LDKClosingSigned this_ptr_conv;
8783         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8784         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8785         LDKThirtyTwoBytes val_ref;
8786         CHECK((*_env)->GetArrayLength (_env, val) == 32);
8787         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
8788         ClosingSigned_set_channel_id(&this_ptr_conv, val_ref);
8789 }
8790
8791 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ClosingSigned_1get_1fee_1satoshis(JNIEnv * _env, jclass _b, jlong this_ptr) {
8792         LDKClosingSigned this_ptr_conv;
8793         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8794         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8795         jlong ret_val = ClosingSigned_get_fee_satoshis(&this_ptr_conv);
8796         return ret_val;
8797 }
8798
8799 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ClosingSigned_1set_1fee_1satoshis(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
8800         LDKClosingSigned this_ptr_conv;
8801         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8802         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8803         ClosingSigned_set_fee_satoshis(&this_ptr_conv, val);
8804 }
8805
8806 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ClosingSigned_1get_1signature(JNIEnv * _env, jclass _b, jlong this_ptr) {
8807         LDKClosingSigned this_ptr_conv;
8808         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8809         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8810         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 64);
8811         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 64, ClosingSigned_get_signature(&this_ptr_conv).compact_form);
8812         return arg_arr;
8813 }
8814
8815 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ClosingSigned_1set_1signature(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
8816         LDKClosingSigned this_ptr_conv;
8817         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8818         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8819         LDKSignature val_ref;
8820         CHECK((*_env)->GetArrayLength (_env, val) == 64);
8821         (*_env)->GetByteArrayRegion (_env, val, 0, 64, val_ref.compact_form);
8822         ClosingSigned_set_signature(&this_ptr_conv, val_ref);
8823 }
8824
8825 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) {
8826         LDKThirtyTwoBytes channel_id_arg_ref;
8827         CHECK((*_env)->GetArrayLength (_env, channel_id_arg) == 32);
8828         (*_env)->GetByteArrayRegion (_env, channel_id_arg, 0, 32, channel_id_arg_ref.data);
8829         LDKSignature signature_arg_ref;
8830         CHECK((*_env)->GetArrayLength (_env, signature_arg) == 64);
8831         (*_env)->GetByteArrayRegion (_env, signature_arg, 0, 64, signature_arg_ref.compact_form);
8832         LDKClosingSigned ret_var = ClosingSigned_new(channel_id_arg_ref, fee_satoshis_arg, signature_arg_ref);
8833         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8834         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8835         long ret_ref = (long)ret_var.inner;
8836         if (ret_var.is_owned) {
8837                 ret_ref |= 1;
8838         }
8839         return ret_ref;
8840 }
8841
8842 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateAddHTLC_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
8843         LDKUpdateAddHTLC this_ptr_conv;
8844         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8845         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8846         UpdateAddHTLC_free(this_ptr_conv);
8847 }
8848
8849 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UpdateAddHTLC_1clone(JNIEnv * _env, jclass _b, jlong orig) {
8850         LDKUpdateAddHTLC orig_conv;
8851         orig_conv.inner = (void*)(orig & (~1));
8852         orig_conv.is_owned = (orig & 1) || (orig == 0);
8853         LDKUpdateAddHTLC ret_var = UpdateAddHTLC_clone(&orig_conv);
8854         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8855         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8856         long ret_ref = (long)ret_var.inner;
8857         if (ret_var.is_owned) {
8858                 ret_ref |= 1;
8859         }
8860         return ret_ref;
8861 }
8862
8863 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UpdateAddHTLC_1get_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
8864         LDKUpdateAddHTLC this_ptr_conv;
8865         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8866         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8867         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
8868         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *UpdateAddHTLC_get_channel_id(&this_ptr_conv));
8869         return ret_arr;
8870 }
8871
8872 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateAddHTLC_1set_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
8873         LDKUpdateAddHTLC this_ptr_conv;
8874         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8875         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8876         LDKThirtyTwoBytes val_ref;
8877         CHECK((*_env)->GetArrayLength (_env, val) == 32);
8878         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
8879         UpdateAddHTLC_set_channel_id(&this_ptr_conv, val_ref);
8880 }
8881
8882 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UpdateAddHTLC_1get_1htlc_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
8883         LDKUpdateAddHTLC this_ptr_conv;
8884         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8885         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8886         jlong ret_val = UpdateAddHTLC_get_htlc_id(&this_ptr_conv);
8887         return ret_val;
8888 }
8889
8890 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateAddHTLC_1set_1htlc_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
8891         LDKUpdateAddHTLC this_ptr_conv;
8892         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8893         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8894         UpdateAddHTLC_set_htlc_id(&this_ptr_conv, val);
8895 }
8896
8897 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UpdateAddHTLC_1get_1amount_1msat(JNIEnv * _env, jclass _b, jlong this_ptr) {
8898         LDKUpdateAddHTLC this_ptr_conv;
8899         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8900         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8901         jlong ret_val = UpdateAddHTLC_get_amount_msat(&this_ptr_conv);
8902         return ret_val;
8903 }
8904
8905 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateAddHTLC_1set_1amount_1msat(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
8906         LDKUpdateAddHTLC this_ptr_conv;
8907         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8908         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8909         UpdateAddHTLC_set_amount_msat(&this_ptr_conv, val);
8910 }
8911
8912 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UpdateAddHTLC_1get_1payment_1hash(JNIEnv * _env, jclass _b, jlong this_ptr) {
8913         LDKUpdateAddHTLC this_ptr_conv;
8914         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8915         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8916         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
8917         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *UpdateAddHTLC_get_payment_hash(&this_ptr_conv));
8918         return ret_arr;
8919 }
8920
8921 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateAddHTLC_1set_1payment_1hash(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
8922         LDKUpdateAddHTLC this_ptr_conv;
8923         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8924         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8925         LDKThirtyTwoBytes val_ref;
8926         CHECK((*_env)->GetArrayLength (_env, val) == 32);
8927         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
8928         UpdateAddHTLC_set_payment_hash(&this_ptr_conv, val_ref);
8929 }
8930
8931 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_UpdateAddHTLC_1get_1cltv_1expiry(JNIEnv * _env, jclass _b, jlong this_ptr) {
8932         LDKUpdateAddHTLC this_ptr_conv;
8933         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8934         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8935         jint ret_val = UpdateAddHTLC_get_cltv_expiry(&this_ptr_conv);
8936         return ret_val;
8937 }
8938
8939 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateAddHTLC_1set_1cltv_1expiry(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
8940         LDKUpdateAddHTLC this_ptr_conv;
8941         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8942         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8943         UpdateAddHTLC_set_cltv_expiry(&this_ptr_conv, val);
8944 }
8945
8946 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateFulfillHTLC_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
8947         LDKUpdateFulfillHTLC this_ptr_conv;
8948         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8949         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8950         UpdateFulfillHTLC_free(this_ptr_conv);
8951 }
8952
8953 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UpdateFulfillHTLC_1clone(JNIEnv * _env, jclass _b, jlong orig) {
8954         LDKUpdateFulfillHTLC orig_conv;
8955         orig_conv.inner = (void*)(orig & (~1));
8956         orig_conv.is_owned = (orig & 1) || (orig == 0);
8957         LDKUpdateFulfillHTLC ret_var = UpdateFulfillHTLC_clone(&orig_conv);
8958         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8959         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8960         long ret_ref = (long)ret_var.inner;
8961         if (ret_var.is_owned) {
8962                 ret_ref |= 1;
8963         }
8964         return ret_ref;
8965 }
8966
8967 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UpdateFulfillHTLC_1get_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
8968         LDKUpdateFulfillHTLC this_ptr_conv;
8969         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8970         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8971         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
8972         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *UpdateFulfillHTLC_get_channel_id(&this_ptr_conv));
8973         return ret_arr;
8974 }
8975
8976 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateFulfillHTLC_1set_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
8977         LDKUpdateFulfillHTLC this_ptr_conv;
8978         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8979         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8980         LDKThirtyTwoBytes val_ref;
8981         CHECK((*_env)->GetArrayLength (_env, val) == 32);
8982         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
8983         UpdateFulfillHTLC_set_channel_id(&this_ptr_conv, val_ref);
8984 }
8985
8986 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UpdateFulfillHTLC_1get_1htlc_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
8987         LDKUpdateFulfillHTLC this_ptr_conv;
8988         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8989         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8990         jlong ret_val = UpdateFulfillHTLC_get_htlc_id(&this_ptr_conv);
8991         return ret_val;
8992 }
8993
8994 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateFulfillHTLC_1set_1htlc_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
8995         LDKUpdateFulfillHTLC this_ptr_conv;
8996         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8997         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8998         UpdateFulfillHTLC_set_htlc_id(&this_ptr_conv, val);
8999 }
9000
9001 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UpdateFulfillHTLC_1get_1payment_1preimage(JNIEnv * _env, jclass _b, jlong this_ptr) {
9002         LDKUpdateFulfillHTLC this_ptr_conv;
9003         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9004         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9005         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
9006         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *UpdateFulfillHTLC_get_payment_preimage(&this_ptr_conv));
9007         return ret_arr;
9008 }
9009
9010 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateFulfillHTLC_1set_1payment_1preimage(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
9011         LDKUpdateFulfillHTLC this_ptr_conv;
9012         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9013         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9014         LDKThirtyTwoBytes val_ref;
9015         CHECK((*_env)->GetArrayLength (_env, val) == 32);
9016         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
9017         UpdateFulfillHTLC_set_payment_preimage(&this_ptr_conv, val_ref);
9018 }
9019
9020 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) {
9021         LDKThirtyTwoBytes channel_id_arg_ref;
9022         CHECK((*_env)->GetArrayLength (_env, channel_id_arg) == 32);
9023         (*_env)->GetByteArrayRegion (_env, channel_id_arg, 0, 32, channel_id_arg_ref.data);
9024         LDKThirtyTwoBytes payment_preimage_arg_ref;
9025         CHECK((*_env)->GetArrayLength (_env, payment_preimage_arg) == 32);
9026         (*_env)->GetByteArrayRegion (_env, payment_preimage_arg, 0, 32, payment_preimage_arg_ref.data);
9027         LDKUpdateFulfillHTLC ret_var = UpdateFulfillHTLC_new(channel_id_arg_ref, htlc_id_arg, payment_preimage_arg_ref);
9028         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9029         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9030         long ret_ref = (long)ret_var.inner;
9031         if (ret_var.is_owned) {
9032                 ret_ref |= 1;
9033         }
9034         return ret_ref;
9035 }
9036
9037 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateFailHTLC_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
9038         LDKUpdateFailHTLC this_ptr_conv;
9039         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9040         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9041         UpdateFailHTLC_free(this_ptr_conv);
9042 }
9043
9044 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UpdateFailHTLC_1clone(JNIEnv * _env, jclass _b, jlong orig) {
9045         LDKUpdateFailHTLC orig_conv;
9046         orig_conv.inner = (void*)(orig & (~1));
9047         orig_conv.is_owned = (orig & 1) || (orig == 0);
9048         LDKUpdateFailHTLC ret_var = UpdateFailHTLC_clone(&orig_conv);
9049         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9050         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9051         long ret_ref = (long)ret_var.inner;
9052         if (ret_var.is_owned) {
9053                 ret_ref |= 1;
9054         }
9055         return ret_ref;
9056 }
9057
9058 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UpdateFailHTLC_1get_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
9059         LDKUpdateFailHTLC 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         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
9063         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *UpdateFailHTLC_get_channel_id(&this_ptr_conv));
9064         return ret_arr;
9065 }
9066
9067 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateFailHTLC_1set_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
9068         LDKUpdateFailHTLC this_ptr_conv;
9069         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9070         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9071         LDKThirtyTwoBytes val_ref;
9072         CHECK((*_env)->GetArrayLength (_env, val) == 32);
9073         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
9074         UpdateFailHTLC_set_channel_id(&this_ptr_conv, val_ref);
9075 }
9076
9077 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UpdateFailHTLC_1get_1htlc_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
9078         LDKUpdateFailHTLC this_ptr_conv;
9079         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9080         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9081         jlong ret_val = UpdateFailHTLC_get_htlc_id(&this_ptr_conv);
9082         return ret_val;
9083 }
9084
9085 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateFailHTLC_1set_1htlc_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
9086         LDKUpdateFailHTLC this_ptr_conv;
9087         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9088         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9089         UpdateFailHTLC_set_htlc_id(&this_ptr_conv, val);
9090 }
9091
9092 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateFailMalformedHTLC_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
9093         LDKUpdateFailMalformedHTLC this_ptr_conv;
9094         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9095         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9096         UpdateFailMalformedHTLC_free(this_ptr_conv);
9097 }
9098
9099 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UpdateFailMalformedHTLC_1clone(JNIEnv * _env, jclass _b, jlong orig) {
9100         LDKUpdateFailMalformedHTLC orig_conv;
9101         orig_conv.inner = (void*)(orig & (~1));
9102         orig_conv.is_owned = (orig & 1) || (orig == 0);
9103         LDKUpdateFailMalformedHTLC ret_var = UpdateFailMalformedHTLC_clone(&orig_conv);
9104         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9105         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9106         long ret_ref = (long)ret_var.inner;
9107         if (ret_var.is_owned) {
9108                 ret_ref |= 1;
9109         }
9110         return ret_ref;
9111 }
9112
9113 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UpdateFailMalformedHTLC_1get_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
9114         LDKUpdateFailMalformedHTLC this_ptr_conv;
9115         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9116         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9117         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
9118         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *UpdateFailMalformedHTLC_get_channel_id(&this_ptr_conv));
9119         return ret_arr;
9120 }
9121
9122 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateFailMalformedHTLC_1set_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
9123         LDKUpdateFailMalformedHTLC this_ptr_conv;
9124         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9125         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9126         LDKThirtyTwoBytes val_ref;
9127         CHECK((*_env)->GetArrayLength (_env, val) == 32);
9128         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
9129         UpdateFailMalformedHTLC_set_channel_id(&this_ptr_conv, val_ref);
9130 }
9131
9132 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UpdateFailMalformedHTLC_1get_1htlc_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
9133         LDKUpdateFailMalformedHTLC this_ptr_conv;
9134         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9135         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9136         jlong ret_val = UpdateFailMalformedHTLC_get_htlc_id(&this_ptr_conv);
9137         return ret_val;
9138 }
9139
9140 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateFailMalformedHTLC_1set_1htlc_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
9141         LDKUpdateFailMalformedHTLC this_ptr_conv;
9142         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9143         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9144         UpdateFailMalformedHTLC_set_htlc_id(&this_ptr_conv, val);
9145 }
9146
9147 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_UpdateFailMalformedHTLC_1get_1failure_1code(JNIEnv * _env, jclass _b, jlong this_ptr) {
9148         LDKUpdateFailMalformedHTLC this_ptr_conv;
9149         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9150         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9151         jshort ret_val = UpdateFailMalformedHTLC_get_failure_code(&this_ptr_conv);
9152         return ret_val;
9153 }
9154
9155 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateFailMalformedHTLC_1set_1failure_1code(JNIEnv * _env, jclass _b, jlong this_ptr, jshort val) {
9156         LDKUpdateFailMalformedHTLC this_ptr_conv;
9157         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9158         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9159         UpdateFailMalformedHTLC_set_failure_code(&this_ptr_conv, val);
9160 }
9161
9162 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CommitmentSigned_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
9163         LDKCommitmentSigned this_ptr_conv;
9164         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9165         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9166         CommitmentSigned_free(this_ptr_conv);
9167 }
9168
9169 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CommitmentSigned_1clone(JNIEnv * _env, jclass _b, jlong orig) {
9170         LDKCommitmentSigned orig_conv;
9171         orig_conv.inner = (void*)(orig & (~1));
9172         orig_conv.is_owned = (orig & 1) || (orig == 0);
9173         LDKCommitmentSigned ret_var = CommitmentSigned_clone(&orig_conv);
9174         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9175         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9176         long ret_ref = (long)ret_var.inner;
9177         if (ret_var.is_owned) {
9178                 ret_ref |= 1;
9179         }
9180         return ret_ref;
9181 }
9182
9183 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_CommitmentSigned_1get_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
9184         LDKCommitmentSigned this_ptr_conv;
9185         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9186         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9187         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
9188         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *CommitmentSigned_get_channel_id(&this_ptr_conv));
9189         return ret_arr;
9190 }
9191
9192 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CommitmentSigned_1set_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
9193         LDKCommitmentSigned this_ptr_conv;
9194         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9195         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9196         LDKThirtyTwoBytes val_ref;
9197         CHECK((*_env)->GetArrayLength (_env, val) == 32);
9198         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
9199         CommitmentSigned_set_channel_id(&this_ptr_conv, val_ref);
9200 }
9201
9202 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_CommitmentSigned_1get_1signature(JNIEnv * _env, jclass _b, jlong this_ptr) {
9203         LDKCommitmentSigned this_ptr_conv;
9204         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9205         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9206         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 64);
9207         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 64, CommitmentSigned_get_signature(&this_ptr_conv).compact_form);
9208         return arg_arr;
9209 }
9210
9211 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CommitmentSigned_1set_1signature(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
9212         LDKCommitmentSigned this_ptr_conv;
9213         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9214         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9215         LDKSignature val_ref;
9216         CHECK((*_env)->GetArrayLength (_env, val) == 64);
9217         (*_env)->GetByteArrayRegion (_env, val, 0, 64, val_ref.compact_form);
9218         CommitmentSigned_set_signature(&this_ptr_conv, val_ref);
9219 }
9220
9221 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CommitmentSigned_1set_1htlc_1signatures(JNIEnv * _env, jclass _b, jlong this_ptr, jobjectArray val) {
9222         LDKCommitmentSigned this_ptr_conv;
9223         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9224         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9225         LDKCVec_SignatureZ val_constr;
9226         val_constr.datalen = (*_env)->GetArrayLength (_env, val);
9227         if (val_constr.datalen > 0)
9228                 val_constr.data = MALLOC(val_constr.datalen * sizeof(LDKSignature), "LDKCVec_SignatureZ Elements");
9229         else
9230                 val_constr.data = NULL;
9231         for (size_t i = 0; i < val_constr.datalen; i++) {
9232                 jobject arr_conv_8 = (*_env)->GetObjectArrayElement(_env, val, i);
9233                 LDKSignature arr_conv_8_ref;
9234                 CHECK((*_env)->GetArrayLength (_env, arr_conv_8) == 64);
9235                 (*_env)->GetByteArrayRegion (_env, arr_conv_8, 0, 64, arr_conv_8_ref.compact_form);
9236                 val_constr.data[i] = arr_conv_8_ref;
9237         }
9238         CommitmentSigned_set_htlc_signatures(&this_ptr_conv, val_constr);
9239 }
9240
9241 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) {
9242         LDKThirtyTwoBytes channel_id_arg_ref;
9243         CHECK((*_env)->GetArrayLength (_env, channel_id_arg) == 32);
9244         (*_env)->GetByteArrayRegion (_env, channel_id_arg, 0, 32, channel_id_arg_ref.data);
9245         LDKSignature signature_arg_ref;
9246         CHECK((*_env)->GetArrayLength (_env, signature_arg) == 64);
9247         (*_env)->GetByteArrayRegion (_env, signature_arg, 0, 64, signature_arg_ref.compact_form);
9248         LDKCVec_SignatureZ htlc_signatures_arg_constr;
9249         htlc_signatures_arg_constr.datalen = (*_env)->GetArrayLength (_env, htlc_signatures_arg);
9250         if (htlc_signatures_arg_constr.datalen > 0)
9251                 htlc_signatures_arg_constr.data = MALLOC(htlc_signatures_arg_constr.datalen * sizeof(LDKSignature), "LDKCVec_SignatureZ Elements");
9252         else
9253                 htlc_signatures_arg_constr.data = NULL;
9254         for (size_t i = 0; i < htlc_signatures_arg_constr.datalen; i++) {
9255                 jobject arr_conv_8 = (*_env)->GetObjectArrayElement(_env, htlc_signatures_arg, i);
9256                 LDKSignature arr_conv_8_ref;
9257                 CHECK((*_env)->GetArrayLength (_env, arr_conv_8) == 64);
9258                 (*_env)->GetByteArrayRegion (_env, arr_conv_8, 0, 64, arr_conv_8_ref.compact_form);
9259                 htlc_signatures_arg_constr.data[i] = arr_conv_8_ref;
9260         }
9261         LDKCommitmentSigned ret_var = CommitmentSigned_new(channel_id_arg_ref, signature_arg_ref, htlc_signatures_arg_constr);
9262         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9263         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9264         long ret_ref = (long)ret_var.inner;
9265         if (ret_var.is_owned) {
9266                 ret_ref |= 1;
9267         }
9268         return ret_ref;
9269 }
9270
9271 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RevokeAndACK_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
9272         LDKRevokeAndACK this_ptr_conv;
9273         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9274         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9275         RevokeAndACK_free(this_ptr_conv);
9276 }
9277
9278 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_RevokeAndACK_1clone(JNIEnv * _env, jclass _b, jlong orig) {
9279         LDKRevokeAndACK orig_conv;
9280         orig_conv.inner = (void*)(orig & (~1));
9281         orig_conv.is_owned = (orig & 1) || (orig == 0);
9282         LDKRevokeAndACK ret_var = RevokeAndACK_clone(&orig_conv);
9283         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9284         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9285         long ret_ref = (long)ret_var.inner;
9286         if (ret_var.is_owned) {
9287                 ret_ref |= 1;
9288         }
9289         return ret_ref;
9290 }
9291
9292 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_RevokeAndACK_1get_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
9293         LDKRevokeAndACK this_ptr_conv;
9294         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9295         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9296         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
9297         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *RevokeAndACK_get_channel_id(&this_ptr_conv));
9298         return ret_arr;
9299 }
9300
9301 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RevokeAndACK_1set_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
9302         LDKRevokeAndACK this_ptr_conv;
9303         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9304         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9305         LDKThirtyTwoBytes val_ref;
9306         CHECK((*_env)->GetArrayLength (_env, val) == 32);
9307         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
9308         RevokeAndACK_set_channel_id(&this_ptr_conv, val_ref);
9309 }
9310
9311 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_RevokeAndACK_1get_1per_1commitment_1secret(JNIEnv * _env, jclass _b, jlong this_ptr) {
9312         LDKRevokeAndACK this_ptr_conv;
9313         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9314         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9315         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
9316         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *RevokeAndACK_get_per_commitment_secret(&this_ptr_conv));
9317         return ret_arr;
9318 }
9319
9320 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RevokeAndACK_1set_1per_1commitment_1secret(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
9321         LDKRevokeAndACK this_ptr_conv;
9322         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9323         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9324         LDKThirtyTwoBytes val_ref;
9325         CHECK((*_env)->GetArrayLength (_env, val) == 32);
9326         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
9327         RevokeAndACK_set_per_commitment_secret(&this_ptr_conv, val_ref);
9328 }
9329
9330 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_RevokeAndACK_1get_1next_1per_1commitment_1point(JNIEnv * _env, jclass _b, jlong this_ptr) {
9331         LDKRevokeAndACK this_ptr_conv;
9332         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9333         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9334         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
9335         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, RevokeAndACK_get_next_per_commitment_point(&this_ptr_conv).compressed_form);
9336         return arg_arr;
9337 }
9338
9339 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RevokeAndACK_1set_1next_1per_1commitment_1point(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
9340         LDKRevokeAndACK this_ptr_conv;
9341         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9342         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9343         LDKPublicKey val_ref;
9344         CHECK((*_env)->GetArrayLength (_env, val) == 33);
9345         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
9346         RevokeAndACK_set_next_per_commitment_point(&this_ptr_conv, val_ref);
9347 }
9348
9349 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) {
9350         LDKThirtyTwoBytes channel_id_arg_ref;
9351         CHECK((*_env)->GetArrayLength (_env, channel_id_arg) == 32);
9352         (*_env)->GetByteArrayRegion (_env, channel_id_arg, 0, 32, channel_id_arg_ref.data);
9353         LDKThirtyTwoBytes per_commitment_secret_arg_ref;
9354         CHECK((*_env)->GetArrayLength (_env, per_commitment_secret_arg) == 32);
9355         (*_env)->GetByteArrayRegion (_env, per_commitment_secret_arg, 0, 32, per_commitment_secret_arg_ref.data);
9356         LDKPublicKey next_per_commitment_point_arg_ref;
9357         CHECK((*_env)->GetArrayLength (_env, next_per_commitment_point_arg) == 33);
9358         (*_env)->GetByteArrayRegion (_env, next_per_commitment_point_arg, 0, 33, next_per_commitment_point_arg_ref.compressed_form);
9359         LDKRevokeAndACK ret_var = RevokeAndACK_new(channel_id_arg_ref, per_commitment_secret_arg_ref, next_per_commitment_point_arg_ref);
9360         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9361         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9362         long ret_ref = (long)ret_var.inner;
9363         if (ret_var.is_owned) {
9364                 ret_ref |= 1;
9365         }
9366         return ret_ref;
9367 }
9368
9369 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateFee_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
9370         LDKUpdateFee this_ptr_conv;
9371         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9372         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9373         UpdateFee_free(this_ptr_conv);
9374 }
9375
9376 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UpdateFee_1clone(JNIEnv * _env, jclass _b, jlong orig) {
9377         LDKUpdateFee orig_conv;
9378         orig_conv.inner = (void*)(orig & (~1));
9379         orig_conv.is_owned = (orig & 1) || (orig == 0);
9380         LDKUpdateFee ret_var = UpdateFee_clone(&orig_conv);
9381         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9382         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9383         long ret_ref = (long)ret_var.inner;
9384         if (ret_var.is_owned) {
9385                 ret_ref |= 1;
9386         }
9387         return ret_ref;
9388 }
9389
9390 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UpdateFee_1get_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
9391         LDKUpdateFee this_ptr_conv;
9392         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9393         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9394         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
9395         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *UpdateFee_get_channel_id(&this_ptr_conv));
9396         return ret_arr;
9397 }
9398
9399 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateFee_1set_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
9400         LDKUpdateFee this_ptr_conv;
9401         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9402         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9403         LDKThirtyTwoBytes val_ref;
9404         CHECK((*_env)->GetArrayLength (_env, val) == 32);
9405         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
9406         UpdateFee_set_channel_id(&this_ptr_conv, val_ref);
9407 }
9408
9409 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_UpdateFee_1get_1feerate_1per_1kw(JNIEnv * _env, jclass _b, jlong this_ptr) {
9410         LDKUpdateFee this_ptr_conv;
9411         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9412         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9413         jint ret_val = UpdateFee_get_feerate_per_kw(&this_ptr_conv);
9414         return ret_val;
9415 }
9416
9417 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateFee_1set_1feerate_1per_1kw(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
9418         LDKUpdateFee this_ptr_conv;
9419         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9420         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9421         UpdateFee_set_feerate_per_kw(&this_ptr_conv, val);
9422 }
9423
9424 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UpdateFee_1new(JNIEnv * _env, jclass _b, jbyteArray channel_id_arg, jint feerate_per_kw_arg) {
9425         LDKThirtyTwoBytes channel_id_arg_ref;
9426         CHECK((*_env)->GetArrayLength (_env, channel_id_arg) == 32);
9427         (*_env)->GetByteArrayRegion (_env, channel_id_arg, 0, 32, channel_id_arg_ref.data);
9428         LDKUpdateFee ret_var = UpdateFee_new(channel_id_arg_ref, feerate_per_kw_arg);
9429         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9430         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9431         long ret_ref = (long)ret_var.inner;
9432         if (ret_var.is_owned) {
9433                 ret_ref |= 1;
9434         }
9435         return ret_ref;
9436 }
9437
9438 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_DataLossProtect_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
9439         LDKDataLossProtect this_ptr_conv;
9440         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9441         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9442         DataLossProtect_free(this_ptr_conv);
9443 }
9444
9445 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_DataLossProtect_1clone(JNIEnv * _env, jclass _b, jlong orig) {
9446         LDKDataLossProtect orig_conv;
9447         orig_conv.inner = (void*)(orig & (~1));
9448         orig_conv.is_owned = (orig & 1) || (orig == 0);
9449         LDKDataLossProtect ret_var = DataLossProtect_clone(&orig_conv);
9450         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9451         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9452         long ret_ref = (long)ret_var.inner;
9453         if (ret_var.is_owned) {
9454                 ret_ref |= 1;
9455         }
9456         return ret_ref;
9457 }
9458
9459 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_DataLossProtect_1get_1your_1last_1per_1commitment_1secret(JNIEnv * _env, jclass _b, jlong this_ptr) {
9460         LDKDataLossProtect this_ptr_conv;
9461         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9462         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9463         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
9464         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *DataLossProtect_get_your_last_per_commitment_secret(&this_ptr_conv));
9465         return ret_arr;
9466 }
9467
9468 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_DataLossProtect_1set_1your_1last_1per_1commitment_1secret(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
9469         LDKDataLossProtect this_ptr_conv;
9470         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9471         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9472         LDKThirtyTwoBytes val_ref;
9473         CHECK((*_env)->GetArrayLength (_env, val) == 32);
9474         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
9475         DataLossProtect_set_your_last_per_commitment_secret(&this_ptr_conv, val_ref);
9476 }
9477
9478 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_DataLossProtect_1get_1my_1current_1per_1commitment_1point(JNIEnv * _env, jclass _b, jlong this_ptr) {
9479         LDKDataLossProtect this_ptr_conv;
9480         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9481         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9482         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
9483         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, DataLossProtect_get_my_current_per_commitment_point(&this_ptr_conv).compressed_form);
9484         return arg_arr;
9485 }
9486
9487 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_DataLossProtect_1set_1my_1current_1per_1commitment_1point(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
9488         LDKDataLossProtect this_ptr_conv;
9489         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9490         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9491         LDKPublicKey val_ref;
9492         CHECK((*_env)->GetArrayLength (_env, val) == 33);
9493         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
9494         DataLossProtect_set_my_current_per_commitment_point(&this_ptr_conv, val_ref);
9495 }
9496
9497 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) {
9498         LDKThirtyTwoBytes your_last_per_commitment_secret_arg_ref;
9499         CHECK((*_env)->GetArrayLength (_env, your_last_per_commitment_secret_arg) == 32);
9500         (*_env)->GetByteArrayRegion (_env, your_last_per_commitment_secret_arg, 0, 32, your_last_per_commitment_secret_arg_ref.data);
9501         LDKPublicKey my_current_per_commitment_point_arg_ref;
9502         CHECK((*_env)->GetArrayLength (_env, my_current_per_commitment_point_arg) == 33);
9503         (*_env)->GetByteArrayRegion (_env, my_current_per_commitment_point_arg, 0, 33, my_current_per_commitment_point_arg_ref.compressed_form);
9504         LDKDataLossProtect ret_var = DataLossProtect_new(your_last_per_commitment_secret_arg_ref, my_current_per_commitment_point_arg_ref);
9505         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9506         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9507         long ret_ref = (long)ret_var.inner;
9508         if (ret_var.is_owned) {
9509                 ret_ref |= 1;
9510         }
9511         return ret_ref;
9512 }
9513
9514 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelReestablish_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
9515         LDKChannelReestablish this_ptr_conv;
9516         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9517         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9518         ChannelReestablish_free(this_ptr_conv);
9519 }
9520
9521 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelReestablish_1clone(JNIEnv * _env, jclass _b, jlong orig) {
9522         LDKChannelReestablish orig_conv;
9523         orig_conv.inner = (void*)(orig & (~1));
9524         orig_conv.is_owned = (orig & 1) || (orig == 0);
9525         LDKChannelReestablish ret_var = ChannelReestablish_clone(&orig_conv);
9526         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9527         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9528         long ret_ref = (long)ret_var.inner;
9529         if (ret_var.is_owned) {
9530                 ret_ref |= 1;
9531         }
9532         return ret_ref;
9533 }
9534
9535 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelReestablish_1get_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
9536         LDKChannelReestablish this_ptr_conv;
9537         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9538         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9539         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
9540         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *ChannelReestablish_get_channel_id(&this_ptr_conv));
9541         return ret_arr;
9542 }
9543
9544 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelReestablish_1set_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
9545         LDKChannelReestablish this_ptr_conv;
9546         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9547         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9548         LDKThirtyTwoBytes val_ref;
9549         CHECK((*_env)->GetArrayLength (_env, val) == 32);
9550         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
9551         ChannelReestablish_set_channel_id(&this_ptr_conv, val_ref);
9552 }
9553
9554 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelReestablish_1get_1next_1local_1commitment_1number(JNIEnv * _env, jclass _b, jlong this_ptr) {
9555         LDKChannelReestablish this_ptr_conv;
9556         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9557         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9558         jlong ret_val = ChannelReestablish_get_next_local_commitment_number(&this_ptr_conv);
9559         return ret_val;
9560 }
9561
9562 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelReestablish_1set_1next_1local_1commitment_1number(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
9563         LDKChannelReestablish this_ptr_conv;
9564         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9565         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9566         ChannelReestablish_set_next_local_commitment_number(&this_ptr_conv, val);
9567 }
9568
9569 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelReestablish_1get_1next_1remote_1commitment_1number(JNIEnv * _env, jclass _b, jlong this_ptr) {
9570         LDKChannelReestablish this_ptr_conv;
9571         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9572         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9573         jlong ret_val = ChannelReestablish_get_next_remote_commitment_number(&this_ptr_conv);
9574         return ret_val;
9575 }
9576
9577 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelReestablish_1set_1next_1remote_1commitment_1number(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
9578         LDKChannelReestablish this_ptr_conv;
9579         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9580         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9581         ChannelReestablish_set_next_remote_commitment_number(&this_ptr_conv, val);
9582 }
9583
9584 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AnnouncementSignatures_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
9585         LDKAnnouncementSignatures this_ptr_conv;
9586         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9587         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9588         AnnouncementSignatures_free(this_ptr_conv);
9589 }
9590
9591 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_AnnouncementSignatures_1clone(JNIEnv * _env, jclass _b, jlong orig) {
9592         LDKAnnouncementSignatures orig_conv;
9593         orig_conv.inner = (void*)(orig & (~1));
9594         orig_conv.is_owned = (orig & 1) || (orig == 0);
9595         LDKAnnouncementSignatures ret_var = AnnouncementSignatures_clone(&orig_conv);
9596         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9597         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9598         long ret_ref = (long)ret_var.inner;
9599         if (ret_var.is_owned) {
9600                 ret_ref |= 1;
9601         }
9602         return ret_ref;
9603 }
9604
9605 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_AnnouncementSignatures_1get_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
9606         LDKAnnouncementSignatures this_ptr_conv;
9607         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9608         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9609         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
9610         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *AnnouncementSignatures_get_channel_id(&this_ptr_conv));
9611         return ret_arr;
9612 }
9613
9614 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AnnouncementSignatures_1set_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
9615         LDKAnnouncementSignatures this_ptr_conv;
9616         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9617         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9618         LDKThirtyTwoBytes val_ref;
9619         CHECK((*_env)->GetArrayLength (_env, val) == 32);
9620         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
9621         AnnouncementSignatures_set_channel_id(&this_ptr_conv, val_ref);
9622 }
9623
9624 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_AnnouncementSignatures_1get_1short_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
9625         LDKAnnouncementSignatures this_ptr_conv;
9626         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9627         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9628         jlong ret_val = AnnouncementSignatures_get_short_channel_id(&this_ptr_conv);
9629         return ret_val;
9630 }
9631
9632 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AnnouncementSignatures_1set_1short_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
9633         LDKAnnouncementSignatures this_ptr_conv;
9634         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9635         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9636         AnnouncementSignatures_set_short_channel_id(&this_ptr_conv, val);
9637 }
9638
9639 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_AnnouncementSignatures_1get_1node_1signature(JNIEnv * _env, jclass _b, jlong this_ptr) {
9640         LDKAnnouncementSignatures this_ptr_conv;
9641         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9642         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9643         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 64);
9644         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 64, AnnouncementSignatures_get_node_signature(&this_ptr_conv).compact_form);
9645         return arg_arr;
9646 }
9647
9648 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AnnouncementSignatures_1set_1node_1signature(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
9649         LDKAnnouncementSignatures this_ptr_conv;
9650         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9651         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9652         LDKSignature val_ref;
9653         CHECK((*_env)->GetArrayLength (_env, val) == 64);
9654         (*_env)->GetByteArrayRegion (_env, val, 0, 64, val_ref.compact_form);
9655         AnnouncementSignatures_set_node_signature(&this_ptr_conv, val_ref);
9656 }
9657
9658 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_AnnouncementSignatures_1get_1bitcoin_1signature(JNIEnv * _env, jclass _b, jlong this_ptr) {
9659         LDKAnnouncementSignatures this_ptr_conv;
9660         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9661         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9662         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 64);
9663         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 64, AnnouncementSignatures_get_bitcoin_signature(&this_ptr_conv).compact_form);
9664         return arg_arr;
9665 }
9666
9667 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AnnouncementSignatures_1set_1bitcoin_1signature(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
9668         LDKAnnouncementSignatures this_ptr_conv;
9669         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9670         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9671         LDKSignature val_ref;
9672         CHECK((*_env)->GetArrayLength (_env, val) == 64);
9673         (*_env)->GetByteArrayRegion (_env, val, 0, 64, val_ref.compact_form);
9674         AnnouncementSignatures_set_bitcoin_signature(&this_ptr_conv, val_ref);
9675 }
9676
9677 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) {
9678         LDKThirtyTwoBytes channel_id_arg_ref;
9679         CHECK((*_env)->GetArrayLength (_env, channel_id_arg) == 32);
9680         (*_env)->GetByteArrayRegion (_env, channel_id_arg, 0, 32, channel_id_arg_ref.data);
9681         LDKSignature node_signature_arg_ref;
9682         CHECK((*_env)->GetArrayLength (_env, node_signature_arg) == 64);
9683         (*_env)->GetByteArrayRegion (_env, node_signature_arg, 0, 64, node_signature_arg_ref.compact_form);
9684         LDKSignature bitcoin_signature_arg_ref;
9685         CHECK((*_env)->GetArrayLength (_env, bitcoin_signature_arg) == 64);
9686         (*_env)->GetByteArrayRegion (_env, bitcoin_signature_arg, 0, 64, bitcoin_signature_arg_ref.compact_form);
9687         LDKAnnouncementSignatures ret_var = AnnouncementSignatures_new(channel_id_arg_ref, short_channel_id_arg, node_signature_arg_ref, bitcoin_signature_arg_ref);
9688         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9689         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9690         long ret_ref = (long)ret_var.inner;
9691         if (ret_var.is_owned) {
9692                 ret_ref |= 1;
9693         }
9694         return ret_ref;
9695 }
9696
9697 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NetAddress_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
9698         LDKNetAddress this_ptr_conv = *(LDKNetAddress*)this_ptr;
9699         FREE((void*)this_ptr);
9700         NetAddress_free(this_ptr_conv);
9701 }
9702
9703 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_NetAddress_1clone(JNIEnv * _env, jclass _b, jlong orig) {
9704         LDKNetAddress* orig_conv = (LDKNetAddress*)orig;
9705         LDKNetAddress *ret_copy = MALLOC(sizeof(LDKNetAddress), "LDKNetAddress");
9706         *ret_copy = NetAddress_clone(orig_conv);
9707         long ret_ref = (long)ret_copy;
9708         return ret_ref;
9709 }
9710
9711 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedNodeAnnouncement_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
9712         LDKUnsignedNodeAnnouncement this_ptr_conv;
9713         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9714         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9715         UnsignedNodeAnnouncement_free(this_ptr_conv);
9716 }
9717
9718 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UnsignedNodeAnnouncement_1clone(JNIEnv * _env, jclass _b, jlong orig) {
9719         LDKUnsignedNodeAnnouncement orig_conv;
9720         orig_conv.inner = (void*)(orig & (~1));
9721         orig_conv.is_owned = (orig & 1) || (orig == 0);
9722         LDKUnsignedNodeAnnouncement ret_var = UnsignedNodeAnnouncement_clone(&orig_conv);
9723         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9724         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9725         long ret_ref = (long)ret_var.inner;
9726         if (ret_var.is_owned) {
9727                 ret_ref |= 1;
9728         }
9729         return ret_ref;
9730 }
9731
9732 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UnsignedNodeAnnouncement_1get_1features(JNIEnv * _env, jclass _b, jlong this_ptr) {
9733         LDKUnsignedNodeAnnouncement this_ptr_conv;
9734         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9735         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9736         LDKNodeFeatures ret_var = UnsignedNodeAnnouncement_get_features(&this_ptr_conv);
9737         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9738         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9739         long ret_ref = (long)ret_var.inner;
9740         if (ret_var.is_owned) {
9741                 ret_ref |= 1;
9742         }
9743         return ret_ref;
9744 }
9745
9746 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedNodeAnnouncement_1set_1features(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
9747         LDKUnsignedNodeAnnouncement this_ptr_conv;
9748         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9749         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9750         LDKNodeFeatures val_conv;
9751         val_conv.inner = (void*)(val & (~1));
9752         val_conv.is_owned = (val & 1) || (val == 0);
9753         // Warning: we may need a move here but can't clone!
9754         UnsignedNodeAnnouncement_set_features(&this_ptr_conv, val_conv);
9755 }
9756
9757 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_UnsignedNodeAnnouncement_1get_1timestamp(JNIEnv * _env, jclass _b, jlong this_ptr) {
9758         LDKUnsignedNodeAnnouncement this_ptr_conv;
9759         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9760         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9761         jint ret_val = UnsignedNodeAnnouncement_get_timestamp(&this_ptr_conv);
9762         return ret_val;
9763 }
9764
9765 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedNodeAnnouncement_1set_1timestamp(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
9766         LDKUnsignedNodeAnnouncement 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         UnsignedNodeAnnouncement_set_timestamp(&this_ptr_conv, val);
9770 }
9771
9772 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UnsignedNodeAnnouncement_1get_1node_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
9773         LDKUnsignedNodeAnnouncement this_ptr_conv;
9774         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9775         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9776         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
9777         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, UnsignedNodeAnnouncement_get_node_id(&this_ptr_conv).compressed_form);
9778         return arg_arr;
9779 }
9780
9781 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedNodeAnnouncement_1set_1node_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
9782         LDKUnsignedNodeAnnouncement this_ptr_conv;
9783         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9784         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9785         LDKPublicKey val_ref;
9786         CHECK((*_env)->GetArrayLength (_env, val) == 33);
9787         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
9788         UnsignedNodeAnnouncement_set_node_id(&this_ptr_conv, val_ref);
9789 }
9790
9791 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UnsignedNodeAnnouncement_1get_1rgb(JNIEnv * _env, jclass _b, jlong this_ptr) {
9792         LDKUnsignedNodeAnnouncement this_ptr_conv;
9793         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9794         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9795         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 3);
9796         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 3, *UnsignedNodeAnnouncement_get_rgb(&this_ptr_conv));
9797         return ret_arr;
9798 }
9799
9800 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedNodeAnnouncement_1set_1rgb(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
9801         LDKUnsignedNodeAnnouncement this_ptr_conv;
9802         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9803         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9804         LDKThreeBytes val_ref;
9805         CHECK((*_env)->GetArrayLength (_env, val) == 3);
9806         (*_env)->GetByteArrayRegion (_env, val, 0, 3, val_ref.data);
9807         UnsignedNodeAnnouncement_set_rgb(&this_ptr_conv, val_ref);
9808 }
9809
9810 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UnsignedNodeAnnouncement_1get_1alias(JNIEnv * _env, jclass _b, jlong this_ptr) {
9811         LDKUnsignedNodeAnnouncement this_ptr_conv;
9812         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9813         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9814         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
9815         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *UnsignedNodeAnnouncement_get_alias(&this_ptr_conv));
9816         return ret_arr;
9817 }
9818
9819 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedNodeAnnouncement_1set_1alias(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
9820         LDKUnsignedNodeAnnouncement this_ptr_conv;
9821         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9822         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9823         LDKThirtyTwoBytes val_ref;
9824         CHECK((*_env)->GetArrayLength (_env, val) == 32);
9825         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
9826         UnsignedNodeAnnouncement_set_alias(&this_ptr_conv, val_ref);
9827 }
9828
9829 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedNodeAnnouncement_1set_1addresses(JNIEnv * _env, jclass _b, jlong this_ptr, jlongArray val) {
9830         LDKUnsignedNodeAnnouncement this_ptr_conv;
9831         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9832         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9833         LDKCVec_NetAddressZ val_constr;
9834         val_constr.datalen = (*_env)->GetArrayLength (_env, val);
9835         if (val_constr.datalen > 0)
9836                 val_constr.data = MALLOC(val_constr.datalen * sizeof(LDKNetAddress), "LDKCVec_NetAddressZ Elements");
9837         else
9838                 val_constr.data = NULL;
9839         long* val_vals = (*_env)->GetLongArrayElements (_env, val, NULL);
9840         for (size_t m = 0; m < val_constr.datalen; m++) {
9841                 long arr_conv_12 = val_vals[m];
9842                 LDKNetAddress arr_conv_12_conv = *(LDKNetAddress*)arr_conv_12;
9843                 FREE((void*)arr_conv_12);
9844                 val_constr.data[m] = arr_conv_12_conv;
9845         }
9846         (*_env)->ReleaseLongArrayElements (_env, val, val_vals, 0);
9847         UnsignedNodeAnnouncement_set_addresses(&this_ptr_conv, val_constr);
9848 }
9849
9850 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NodeAnnouncement_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
9851         LDKNodeAnnouncement this_ptr_conv;
9852         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9853         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9854         NodeAnnouncement_free(this_ptr_conv);
9855 }
9856
9857 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_NodeAnnouncement_1clone(JNIEnv * _env, jclass _b, jlong orig) {
9858         LDKNodeAnnouncement orig_conv;
9859         orig_conv.inner = (void*)(orig & (~1));
9860         orig_conv.is_owned = (orig & 1) || (orig == 0);
9861         LDKNodeAnnouncement ret_var = NodeAnnouncement_clone(&orig_conv);
9862         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9863         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9864         long ret_ref = (long)ret_var.inner;
9865         if (ret_var.is_owned) {
9866                 ret_ref |= 1;
9867         }
9868         return ret_ref;
9869 }
9870
9871 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_NodeAnnouncement_1get_1signature(JNIEnv * _env, jclass _b, jlong this_ptr) {
9872         LDKNodeAnnouncement this_ptr_conv;
9873         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9874         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9875         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 64);
9876         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 64, NodeAnnouncement_get_signature(&this_ptr_conv).compact_form);
9877         return arg_arr;
9878 }
9879
9880 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NodeAnnouncement_1set_1signature(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
9881         LDKNodeAnnouncement this_ptr_conv;
9882         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9883         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9884         LDKSignature val_ref;
9885         CHECK((*_env)->GetArrayLength (_env, val) == 64);
9886         (*_env)->GetByteArrayRegion (_env, val, 0, 64, val_ref.compact_form);
9887         NodeAnnouncement_set_signature(&this_ptr_conv, val_ref);
9888 }
9889
9890 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_NodeAnnouncement_1get_1contents(JNIEnv * _env, jclass _b, jlong this_ptr) {
9891         LDKNodeAnnouncement this_ptr_conv;
9892         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9893         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9894         LDKUnsignedNodeAnnouncement ret_var = NodeAnnouncement_get_contents(&this_ptr_conv);
9895         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9896         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9897         long ret_ref = (long)ret_var.inner;
9898         if (ret_var.is_owned) {
9899                 ret_ref |= 1;
9900         }
9901         return ret_ref;
9902 }
9903
9904 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NodeAnnouncement_1set_1contents(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
9905         LDKNodeAnnouncement this_ptr_conv;
9906         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9907         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9908         LDKUnsignedNodeAnnouncement val_conv;
9909         val_conv.inner = (void*)(val & (~1));
9910         val_conv.is_owned = (val & 1) || (val == 0);
9911         if (val_conv.inner != NULL)
9912                 val_conv = UnsignedNodeAnnouncement_clone(&val_conv);
9913         NodeAnnouncement_set_contents(&this_ptr_conv, val_conv);
9914 }
9915
9916 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_NodeAnnouncement_1new(JNIEnv * _env, jclass _b, jbyteArray signature_arg, jlong contents_arg) {
9917         LDKSignature signature_arg_ref;
9918         CHECK((*_env)->GetArrayLength (_env, signature_arg) == 64);
9919         (*_env)->GetByteArrayRegion (_env, signature_arg, 0, 64, signature_arg_ref.compact_form);
9920         LDKUnsignedNodeAnnouncement contents_arg_conv;
9921         contents_arg_conv.inner = (void*)(contents_arg & (~1));
9922         contents_arg_conv.is_owned = (contents_arg & 1) || (contents_arg == 0);
9923         if (contents_arg_conv.inner != NULL)
9924                 contents_arg_conv = UnsignedNodeAnnouncement_clone(&contents_arg_conv);
9925         LDKNodeAnnouncement ret_var = NodeAnnouncement_new(signature_arg_ref, contents_arg_conv);
9926         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9927         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9928         long ret_ref = (long)ret_var.inner;
9929         if (ret_var.is_owned) {
9930                 ret_ref |= 1;
9931         }
9932         return ret_ref;
9933 }
9934
9935 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
9936         LDKUnsignedChannelAnnouncement this_ptr_conv;
9937         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9938         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9939         UnsignedChannelAnnouncement_free(this_ptr_conv);
9940 }
9941
9942 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1clone(JNIEnv * _env, jclass _b, jlong orig) {
9943         LDKUnsignedChannelAnnouncement orig_conv;
9944         orig_conv.inner = (void*)(orig & (~1));
9945         orig_conv.is_owned = (orig & 1) || (orig == 0);
9946         LDKUnsignedChannelAnnouncement ret_var = UnsignedChannelAnnouncement_clone(&orig_conv);
9947         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9948         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9949         long ret_ref = (long)ret_var.inner;
9950         if (ret_var.is_owned) {
9951                 ret_ref |= 1;
9952         }
9953         return ret_ref;
9954 }
9955
9956 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1get_1features(JNIEnv * _env, jclass _b, jlong this_ptr) {
9957         LDKUnsignedChannelAnnouncement this_ptr_conv;
9958         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9959         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9960         LDKChannelFeatures ret_var = UnsignedChannelAnnouncement_get_features(&this_ptr_conv);
9961         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9962         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9963         long ret_ref = (long)ret_var.inner;
9964         if (ret_var.is_owned) {
9965                 ret_ref |= 1;
9966         }
9967         return ret_ref;
9968 }
9969
9970 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1set_1features(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
9971         LDKUnsignedChannelAnnouncement this_ptr_conv;
9972         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9973         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9974         LDKChannelFeatures val_conv;
9975         val_conv.inner = (void*)(val & (~1));
9976         val_conv.is_owned = (val & 1) || (val == 0);
9977         // Warning: we may need a move here but can't clone!
9978         UnsignedChannelAnnouncement_set_features(&this_ptr_conv, val_conv);
9979 }
9980
9981 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1get_1chain_1hash(JNIEnv * _env, jclass _b, jlong this_ptr) {
9982         LDKUnsignedChannelAnnouncement this_ptr_conv;
9983         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9984         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9985         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
9986         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *UnsignedChannelAnnouncement_get_chain_hash(&this_ptr_conv));
9987         return ret_arr;
9988 }
9989
9990 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1set_1chain_1hash(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
9991         LDKUnsignedChannelAnnouncement this_ptr_conv;
9992         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9993         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9994         LDKThirtyTwoBytes val_ref;
9995         CHECK((*_env)->GetArrayLength (_env, val) == 32);
9996         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
9997         UnsignedChannelAnnouncement_set_chain_hash(&this_ptr_conv, val_ref);
9998 }
9999
10000 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1get_1short_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
10001         LDKUnsignedChannelAnnouncement this_ptr_conv;
10002         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10003         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10004         jlong ret_val = UnsignedChannelAnnouncement_get_short_channel_id(&this_ptr_conv);
10005         return ret_val;
10006 }
10007
10008 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1set_1short_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
10009         LDKUnsignedChannelAnnouncement this_ptr_conv;
10010         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10011         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10012         UnsignedChannelAnnouncement_set_short_channel_id(&this_ptr_conv, val);
10013 }
10014
10015 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1get_1node_1id_11(JNIEnv * _env, jclass _b, jlong this_ptr) {
10016         LDKUnsignedChannelAnnouncement this_ptr_conv;
10017         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10018         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10019         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
10020         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, UnsignedChannelAnnouncement_get_node_id_1(&this_ptr_conv).compressed_form);
10021         return arg_arr;
10022 }
10023
10024 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1set_1node_1id_11(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
10025         LDKUnsignedChannelAnnouncement this_ptr_conv;
10026         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10027         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10028         LDKPublicKey val_ref;
10029         CHECK((*_env)->GetArrayLength (_env, val) == 33);
10030         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
10031         UnsignedChannelAnnouncement_set_node_id_1(&this_ptr_conv, val_ref);
10032 }
10033
10034 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1get_1node_1id_12(JNIEnv * _env, jclass _b, jlong this_ptr) {
10035         LDKUnsignedChannelAnnouncement this_ptr_conv;
10036         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10037         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10038         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
10039         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, UnsignedChannelAnnouncement_get_node_id_2(&this_ptr_conv).compressed_form);
10040         return arg_arr;
10041 }
10042
10043 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1set_1node_1id_12(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
10044         LDKUnsignedChannelAnnouncement this_ptr_conv;
10045         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10046         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10047         LDKPublicKey val_ref;
10048         CHECK((*_env)->GetArrayLength (_env, val) == 33);
10049         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
10050         UnsignedChannelAnnouncement_set_node_id_2(&this_ptr_conv, val_ref);
10051 }
10052
10053 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1get_1bitcoin_1key_11(JNIEnv * _env, jclass _b, jlong this_ptr) {
10054         LDKUnsignedChannelAnnouncement this_ptr_conv;
10055         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10056         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10057         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
10058         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, UnsignedChannelAnnouncement_get_bitcoin_key_1(&this_ptr_conv).compressed_form);
10059         return arg_arr;
10060 }
10061
10062 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1set_1bitcoin_1key_11(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
10063         LDKUnsignedChannelAnnouncement this_ptr_conv;
10064         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10065         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10066         LDKPublicKey val_ref;
10067         CHECK((*_env)->GetArrayLength (_env, val) == 33);
10068         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
10069         UnsignedChannelAnnouncement_set_bitcoin_key_1(&this_ptr_conv, val_ref);
10070 }
10071
10072 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1get_1bitcoin_1key_12(JNIEnv * _env, jclass _b, jlong this_ptr) {
10073         LDKUnsignedChannelAnnouncement this_ptr_conv;
10074         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10075         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10076         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
10077         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, UnsignedChannelAnnouncement_get_bitcoin_key_2(&this_ptr_conv).compressed_form);
10078         return arg_arr;
10079 }
10080
10081 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1set_1bitcoin_1key_12(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
10082         LDKUnsignedChannelAnnouncement this_ptr_conv;
10083         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10084         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10085         LDKPublicKey val_ref;
10086         CHECK((*_env)->GetArrayLength (_env, val) == 33);
10087         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
10088         UnsignedChannelAnnouncement_set_bitcoin_key_2(&this_ptr_conv, val_ref);
10089 }
10090
10091 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelAnnouncement_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
10092         LDKChannelAnnouncement this_ptr_conv;
10093         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10094         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10095         ChannelAnnouncement_free(this_ptr_conv);
10096 }
10097
10098 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelAnnouncement_1clone(JNIEnv * _env, jclass _b, jlong orig) {
10099         LDKChannelAnnouncement orig_conv;
10100         orig_conv.inner = (void*)(orig & (~1));
10101         orig_conv.is_owned = (orig & 1) || (orig == 0);
10102         LDKChannelAnnouncement ret_var = ChannelAnnouncement_clone(&orig_conv);
10103         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10104         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10105         long ret_ref = (long)ret_var.inner;
10106         if (ret_var.is_owned) {
10107                 ret_ref |= 1;
10108         }
10109         return ret_ref;
10110 }
10111
10112 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelAnnouncement_1get_1node_1signature_11(JNIEnv * _env, jclass _b, jlong this_ptr) {
10113         LDKChannelAnnouncement this_ptr_conv;
10114         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10115         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10116         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 64);
10117         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 64, ChannelAnnouncement_get_node_signature_1(&this_ptr_conv).compact_form);
10118         return arg_arr;
10119 }
10120
10121 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelAnnouncement_1set_1node_1signature_11(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
10122         LDKChannelAnnouncement this_ptr_conv;
10123         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10124         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10125         LDKSignature val_ref;
10126         CHECK((*_env)->GetArrayLength (_env, val) == 64);
10127         (*_env)->GetByteArrayRegion (_env, val, 0, 64, val_ref.compact_form);
10128         ChannelAnnouncement_set_node_signature_1(&this_ptr_conv, val_ref);
10129 }
10130
10131 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelAnnouncement_1get_1node_1signature_12(JNIEnv * _env, jclass _b, jlong this_ptr) {
10132         LDKChannelAnnouncement this_ptr_conv;
10133         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10134         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10135         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 64);
10136         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 64, ChannelAnnouncement_get_node_signature_2(&this_ptr_conv).compact_form);
10137         return arg_arr;
10138 }
10139
10140 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelAnnouncement_1set_1node_1signature_12(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
10141         LDKChannelAnnouncement this_ptr_conv;
10142         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10143         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10144         LDKSignature val_ref;
10145         CHECK((*_env)->GetArrayLength (_env, val) == 64);
10146         (*_env)->GetByteArrayRegion (_env, val, 0, 64, val_ref.compact_form);
10147         ChannelAnnouncement_set_node_signature_2(&this_ptr_conv, val_ref);
10148 }
10149
10150 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelAnnouncement_1get_1bitcoin_1signature_11(JNIEnv * _env, jclass _b, jlong this_ptr) {
10151         LDKChannelAnnouncement this_ptr_conv;
10152         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10153         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10154         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 64);
10155         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 64, ChannelAnnouncement_get_bitcoin_signature_1(&this_ptr_conv).compact_form);
10156         return arg_arr;
10157 }
10158
10159 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelAnnouncement_1set_1bitcoin_1signature_11(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
10160         LDKChannelAnnouncement this_ptr_conv;
10161         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10162         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10163         LDKSignature val_ref;
10164         CHECK((*_env)->GetArrayLength (_env, val) == 64);
10165         (*_env)->GetByteArrayRegion (_env, val, 0, 64, val_ref.compact_form);
10166         ChannelAnnouncement_set_bitcoin_signature_1(&this_ptr_conv, val_ref);
10167 }
10168
10169 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelAnnouncement_1get_1bitcoin_1signature_12(JNIEnv * _env, jclass _b, jlong this_ptr) {
10170         LDKChannelAnnouncement this_ptr_conv;
10171         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10172         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10173         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 64);
10174         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 64, ChannelAnnouncement_get_bitcoin_signature_2(&this_ptr_conv).compact_form);
10175         return arg_arr;
10176 }
10177
10178 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelAnnouncement_1set_1bitcoin_1signature_12(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
10179         LDKChannelAnnouncement this_ptr_conv;
10180         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10181         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10182         LDKSignature val_ref;
10183         CHECK((*_env)->GetArrayLength (_env, val) == 64);
10184         (*_env)->GetByteArrayRegion (_env, val, 0, 64, val_ref.compact_form);
10185         ChannelAnnouncement_set_bitcoin_signature_2(&this_ptr_conv, val_ref);
10186 }
10187
10188 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelAnnouncement_1get_1contents(JNIEnv * _env, jclass _b, jlong this_ptr) {
10189         LDKChannelAnnouncement this_ptr_conv;
10190         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10191         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10192         LDKUnsignedChannelAnnouncement ret_var = ChannelAnnouncement_get_contents(&this_ptr_conv);
10193         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10194         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10195         long ret_ref = (long)ret_var.inner;
10196         if (ret_var.is_owned) {
10197                 ret_ref |= 1;
10198         }
10199         return ret_ref;
10200 }
10201
10202 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelAnnouncement_1set_1contents(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
10203         LDKChannelAnnouncement this_ptr_conv;
10204         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10205         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10206         LDKUnsignedChannelAnnouncement val_conv;
10207         val_conv.inner = (void*)(val & (~1));
10208         val_conv.is_owned = (val & 1) || (val == 0);
10209         if (val_conv.inner != NULL)
10210                 val_conv = UnsignedChannelAnnouncement_clone(&val_conv);
10211         ChannelAnnouncement_set_contents(&this_ptr_conv, val_conv);
10212 }
10213
10214 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) {
10215         LDKSignature node_signature_1_arg_ref;
10216         CHECK((*_env)->GetArrayLength (_env, node_signature_1_arg) == 64);
10217         (*_env)->GetByteArrayRegion (_env, node_signature_1_arg, 0, 64, node_signature_1_arg_ref.compact_form);
10218         LDKSignature node_signature_2_arg_ref;
10219         CHECK((*_env)->GetArrayLength (_env, node_signature_2_arg) == 64);
10220         (*_env)->GetByteArrayRegion (_env, node_signature_2_arg, 0, 64, node_signature_2_arg_ref.compact_form);
10221         LDKSignature bitcoin_signature_1_arg_ref;
10222         CHECK((*_env)->GetArrayLength (_env, bitcoin_signature_1_arg) == 64);
10223         (*_env)->GetByteArrayRegion (_env, bitcoin_signature_1_arg, 0, 64, bitcoin_signature_1_arg_ref.compact_form);
10224         LDKSignature bitcoin_signature_2_arg_ref;
10225         CHECK((*_env)->GetArrayLength (_env, bitcoin_signature_2_arg) == 64);
10226         (*_env)->GetByteArrayRegion (_env, bitcoin_signature_2_arg, 0, 64, bitcoin_signature_2_arg_ref.compact_form);
10227         LDKUnsignedChannelAnnouncement contents_arg_conv;
10228         contents_arg_conv.inner = (void*)(contents_arg & (~1));
10229         contents_arg_conv.is_owned = (contents_arg & 1) || (contents_arg == 0);
10230         if (contents_arg_conv.inner != NULL)
10231                 contents_arg_conv = UnsignedChannelAnnouncement_clone(&contents_arg_conv);
10232         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);
10233         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10234         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10235         long ret_ref = (long)ret_var.inner;
10236         if (ret_var.is_owned) {
10237                 ret_ref |= 1;
10238         }
10239         return ret_ref;
10240 }
10241
10242 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
10243         LDKUnsignedChannelUpdate this_ptr_conv;
10244         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10245         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10246         UnsignedChannelUpdate_free(this_ptr_conv);
10247 }
10248
10249 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1clone(JNIEnv * _env, jclass _b, jlong orig) {
10250         LDKUnsignedChannelUpdate orig_conv;
10251         orig_conv.inner = (void*)(orig & (~1));
10252         orig_conv.is_owned = (orig & 1) || (orig == 0);
10253         LDKUnsignedChannelUpdate ret_var = UnsignedChannelUpdate_clone(&orig_conv);
10254         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10255         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10256         long ret_ref = (long)ret_var.inner;
10257         if (ret_var.is_owned) {
10258                 ret_ref |= 1;
10259         }
10260         return ret_ref;
10261 }
10262
10263 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1get_1chain_1hash(JNIEnv * _env, jclass _b, jlong this_ptr) {
10264         LDKUnsignedChannelUpdate this_ptr_conv;
10265         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10266         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10267         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
10268         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *UnsignedChannelUpdate_get_chain_hash(&this_ptr_conv));
10269         return ret_arr;
10270 }
10271
10272 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1set_1chain_1hash(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
10273         LDKUnsignedChannelUpdate this_ptr_conv;
10274         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10275         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10276         LDKThirtyTwoBytes val_ref;
10277         CHECK((*_env)->GetArrayLength (_env, val) == 32);
10278         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
10279         UnsignedChannelUpdate_set_chain_hash(&this_ptr_conv, val_ref);
10280 }
10281
10282 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1get_1short_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
10283         LDKUnsignedChannelUpdate this_ptr_conv;
10284         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10285         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10286         jlong ret_val = UnsignedChannelUpdate_get_short_channel_id(&this_ptr_conv);
10287         return ret_val;
10288 }
10289
10290 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1set_1short_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
10291         LDKUnsignedChannelUpdate this_ptr_conv;
10292         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10293         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10294         UnsignedChannelUpdate_set_short_channel_id(&this_ptr_conv, val);
10295 }
10296
10297 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1get_1timestamp(JNIEnv * _env, jclass _b, jlong this_ptr) {
10298         LDKUnsignedChannelUpdate this_ptr_conv;
10299         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10300         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10301         jint ret_val = UnsignedChannelUpdate_get_timestamp(&this_ptr_conv);
10302         return ret_val;
10303 }
10304
10305 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1set_1timestamp(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
10306         LDKUnsignedChannelUpdate this_ptr_conv;
10307         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10308         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10309         UnsignedChannelUpdate_set_timestamp(&this_ptr_conv, val);
10310 }
10311
10312 JNIEXPORT jbyte JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1get_1flags(JNIEnv * _env, jclass _b, jlong this_ptr) {
10313         LDKUnsignedChannelUpdate this_ptr_conv;
10314         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10315         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10316         jbyte ret_val = UnsignedChannelUpdate_get_flags(&this_ptr_conv);
10317         return ret_val;
10318 }
10319
10320 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1set_1flags(JNIEnv * _env, jclass _b, jlong this_ptr, jbyte val) {
10321         LDKUnsignedChannelUpdate this_ptr_conv;
10322         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10323         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10324         UnsignedChannelUpdate_set_flags(&this_ptr_conv, val);
10325 }
10326
10327 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1get_1cltv_1expiry_1delta(JNIEnv * _env, jclass _b, jlong this_ptr) {
10328         LDKUnsignedChannelUpdate this_ptr_conv;
10329         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10330         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10331         jshort ret_val = UnsignedChannelUpdate_get_cltv_expiry_delta(&this_ptr_conv);
10332         return ret_val;
10333 }
10334
10335 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1set_1cltv_1expiry_1delta(JNIEnv * _env, jclass _b, jlong this_ptr, jshort val) {
10336         LDKUnsignedChannelUpdate this_ptr_conv;
10337         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10338         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10339         UnsignedChannelUpdate_set_cltv_expiry_delta(&this_ptr_conv, val);
10340 }
10341
10342 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1get_1htlc_1minimum_1msat(JNIEnv * _env, jclass _b, jlong this_ptr) {
10343         LDKUnsignedChannelUpdate this_ptr_conv;
10344         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10345         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10346         jlong ret_val = UnsignedChannelUpdate_get_htlc_minimum_msat(&this_ptr_conv);
10347         return ret_val;
10348 }
10349
10350 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1set_1htlc_1minimum_1msat(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
10351         LDKUnsignedChannelUpdate this_ptr_conv;
10352         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10353         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10354         UnsignedChannelUpdate_set_htlc_minimum_msat(&this_ptr_conv, val);
10355 }
10356
10357 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1get_1fee_1base_1msat(JNIEnv * _env, jclass _b, jlong this_ptr) {
10358         LDKUnsignedChannelUpdate this_ptr_conv;
10359         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10360         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10361         jint ret_val = UnsignedChannelUpdate_get_fee_base_msat(&this_ptr_conv);
10362         return ret_val;
10363 }
10364
10365 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1set_1fee_1base_1msat(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
10366         LDKUnsignedChannelUpdate this_ptr_conv;
10367         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10368         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10369         UnsignedChannelUpdate_set_fee_base_msat(&this_ptr_conv, val);
10370 }
10371
10372 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1get_1fee_1proportional_1millionths(JNIEnv * _env, jclass _b, jlong this_ptr) {
10373         LDKUnsignedChannelUpdate this_ptr_conv;
10374         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10375         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10376         jint ret_val = UnsignedChannelUpdate_get_fee_proportional_millionths(&this_ptr_conv);
10377         return ret_val;
10378 }
10379
10380 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1set_1fee_1proportional_1millionths(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
10381         LDKUnsignedChannelUpdate this_ptr_conv;
10382         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10383         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10384         UnsignedChannelUpdate_set_fee_proportional_millionths(&this_ptr_conv, val);
10385 }
10386
10387 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelUpdate_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
10388         LDKChannelUpdate this_ptr_conv;
10389         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10390         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10391         ChannelUpdate_free(this_ptr_conv);
10392 }
10393
10394 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelUpdate_1clone(JNIEnv * _env, jclass _b, jlong orig) {
10395         LDKChannelUpdate orig_conv;
10396         orig_conv.inner = (void*)(orig & (~1));
10397         orig_conv.is_owned = (orig & 1) || (orig == 0);
10398         LDKChannelUpdate ret_var = ChannelUpdate_clone(&orig_conv);
10399         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10400         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10401         long ret_ref = (long)ret_var.inner;
10402         if (ret_var.is_owned) {
10403                 ret_ref |= 1;
10404         }
10405         return ret_ref;
10406 }
10407
10408 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelUpdate_1get_1signature(JNIEnv * _env, jclass _b, jlong this_ptr) {
10409         LDKChannelUpdate this_ptr_conv;
10410         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10411         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10412         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 64);
10413         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 64, ChannelUpdate_get_signature(&this_ptr_conv).compact_form);
10414         return arg_arr;
10415 }
10416
10417 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelUpdate_1set_1signature(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
10418         LDKChannelUpdate this_ptr_conv;
10419         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10420         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10421         LDKSignature val_ref;
10422         CHECK((*_env)->GetArrayLength (_env, val) == 64);
10423         (*_env)->GetByteArrayRegion (_env, val, 0, 64, val_ref.compact_form);
10424         ChannelUpdate_set_signature(&this_ptr_conv, val_ref);
10425 }
10426
10427 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelUpdate_1get_1contents(JNIEnv * _env, jclass _b, jlong this_ptr) {
10428         LDKChannelUpdate this_ptr_conv;
10429         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10430         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10431         LDKUnsignedChannelUpdate ret_var = ChannelUpdate_get_contents(&this_ptr_conv);
10432         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10433         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10434         long ret_ref = (long)ret_var.inner;
10435         if (ret_var.is_owned) {
10436                 ret_ref |= 1;
10437         }
10438         return ret_ref;
10439 }
10440
10441 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelUpdate_1set_1contents(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
10442         LDKChannelUpdate this_ptr_conv;
10443         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10444         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10445         LDKUnsignedChannelUpdate val_conv;
10446         val_conv.inner = (void*)(val & (~1));
10447         val_conv.is_owned = (val & 1) || (val == 0);
10448         if (val_conv.inner != NULL)
10449                 val_conv = UnsignedChannelUpdate_clone(&val_conv);
10450         ChannelUpdate_set_contents(&this_ptr_conv, val_conv);
10451 }
10452
10453 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelUpdate_1new(JNIEnv * _env, jclass _b, jbyteArray signature_arg, jlong contents_arg) {
10454         LDKSignature signature_arg_ref;
10455         CHECK((*_env)->GetArrayLength (_env, signature_arg) == 64);
10456         (*_env)->GetByteArrayRegion (_env, signature_arg, 0, 64, signature_arg_ref.compact_form);
10457         LDKUnsignedChannelUpdate contents_arg_conv;
10458         contents_arg_conv.inner = (void*)(contents_arg & (~1));
10459         contents_arg_conv.is_owned = (contents_arg & 1) || (contents_arg == 0);
10460         if (contents_arg_conv.inner != NULL)
10461                 contents_arg_conv = UnsignedChannelUpdate_clone(&contents_arg_conv);
10462         LDKChannelUpdate ret_var = ChannelUpdate_new(signature_arg_ref, contents_arg_conv);
10463         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10464         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10465         long ret_ref = (long)ret_var.inner;
10466         if (ret_var.is_owned) {
10467                 ret_ref |= 1;
10468         }
10469         return ret_ref;
10470 }
10471
10472 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_QueryChannelRange_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
10473         LDKQueryChannelRange this_ptr_conv;
10474         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10475         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10476         QueryChannelRange_free(this_ptr_conv);
10477 }
10478
10479 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_QueryChannelRange_1clone(JNIEnv * _env, jclass _b, jlong orig) {
10480         LDKQueryChannelRange orig_conv;
10481         orig_conv.inner = (void*)(orig & (~1));
10482         orig_conv.is_owned = (orig & 1) || (orig == 0);
10483         LDKQueryChannelRange ret_var = QueryChannelRange_clone(&orig_conv);
10484         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10485         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10486         long ret_ref = (long)ret_var.inner;
10487         if (ret_var.is_owned) {
10488                 ret_ref |= 1;
10489         }
10490         return ret_ref;
10491 }
10492
10493 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_QueryChannelRange_1get_1chain_1hash(JNIEnv * _env, jclass _b, jlong this_ptr) {
10494         LDKQueryChannelRange this_ptr_conv;
10495         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10496         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10497         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
10498         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *QueryChannelRange_get_chain_hash(&this_ptr_conv));
10499         return ret_arr;
10500 }
10501
10502 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_QueryChannelRange_1set_1chain_1hash(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
10503         LDKQueryChannelRange this_ptr_conv;
10504         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10505         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10506         LDKThirtyTwoBytes val_ref;
10507         CHECK((*_env)->GetArrayLength (_env, val) == 32);
10508         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
10509         QueryChannelRange_set_chain_hash(&this_ptr_conv, val_ref);
10510 }
10511
10512 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_QueryChannelRange_1get_1first_1blocknum(JNIEnv * _env, jclass _b, jlong this_ptr) {
10513         LDKQueryChannelRange this_ptr_conv;
10514         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10515         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10516         jint ret_val = QueryChannelRange_get_first_blocknum(&this_ptr_conv);
10517         return ret_val;
10518 }
10519
10520 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_QueryChannelRange_1set_1first_1blocknum(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
10521         LDKQueryChannelRange this_ptr_conv;
10522         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10523         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10524         QueryChannelRange_set_first_blocknum(&this_ptr_conv, val);
10525 }
10526
10527 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_QueryChannelRange_1get_1number_1of_1blocks(JNIEnv * _env, jclass _b, jlong this_ptr) {
10528         LDKQueryChannelRange this_ptr_conv;
10529         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10530         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10531         jint ret_val = QueryChannelRange_get_number_of_blocks(&this_ptr_conv);
10532         return ret_val;
10533 }
10534
10535 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_QueryChannelRange_1set_1number_1of_1blocks(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
10536         LDKQueryChannelRange this_ptr_conv;
10537         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10538         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10539         QueryChannelRange_set_number_of_blocks(&this_ptr_conv, val);
10540 }
10541
10542 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) {
10543         LDKThirtyTwoBytes chain_hash_arg_ref;
10544         CHECK((*_env)->GetArrayLength (_env, chain_hash_arg) == 32);
10545         (*_env)->GetByteArrayRegion (_env, chain_hash_arg, 0, 32, chain_hash_arg_ref.data);
10546         LDKQueryChannelRange ret_var = QueryChannelRange_new(chain_hash_arg_ref, first_blocknum_arg, number_of_blocks_arg);
10547         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10548         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10549         long ret_ref = (long)ret_var.inner;
10550         if (ret_var.is_owned) {
10551                 ret_ref |= 1;
10552         }
10553         return ret_ref;
10554 }
10555
10556 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ReplyChannelRange_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
10557         LDKReplyChannelRange this_ptr_conv;
10558         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10559         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10560         ReplyChannelRange_free(this_ptr_conv);
10561 }
10562
10563 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ReplyChannelRange_1clone(JNIEnv * _env, jclass _b, jlong orig) {
10564         LDKReplyChannelRange orig_conv;
10565         orig_conv.inner = (void*)(orig & (~1));
10566         orig_conv.is_owned = (orig & 1) || (orig == 0);
10567         LDKReplyChannelRange ret_var = ReplyChannelRange_clone(&orig_conv);
10568         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10569         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10570         long ret_ref = (long)ret_var.inner;
10571         if (ret_var.is_owned) {
10572                 ret_ref |= 1;
10573         }
10574         return ret_ref;
10575 }
10576
10577 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ReplyChannelRange_1get_1chain_1hash(JNIEnv * _env, jclass _b, jlong this_ptr) {
10578         LDKReplyChannelRange this_ptr_conv;
10579         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10580         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10581         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
10582         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *ReplyChannelRange_get_chain_hash(&this_ptr_conv));
10583         return ret_arr;
10584 }
10585
10586 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ReplyChannelRange_1set_1chain_1hash(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
10587         LDKReplyChannelRange this_ptr_conv;
10588         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10589         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10590         LDKThirtyTwoBytes val_ref;
10591         CHECK((*_env)->GetArrayLength (_env, val) == 32);
10592         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
10593         ReplyChannelRange_set_chain_hash(&this_ptr_conv, val_ref);
10594 }
10595
10596 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_ReplyChannelRange_1get_1first_1blocknum(JNIEnv * _env, jclass _b, jlong this_ptr) {
10597         LDKReplyChannelRange this_ptr_conv;
10598         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10599         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10600         jint ret_val = ReplyChannelRange_get_first_blocknum(&this_ptr_conv);
10601         return ret_val;
10602 }
10603
10604 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ReplyChannelRange_1set_1first_1blocknum(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
10605         LDKReplyChannelRange this_ptr_conv;
10606         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10607         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10608         ReplyChannelRange_set_first_blocknum(&this_ptr_conv, val);
10609 }
10610
10611 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_ReplyChannelRange_1get_1number_1of_1blocks(JNIEnv * _env, jclass _b, jlong this_ptr) {
10612         LDKReplyChannelRange this_ptr_conv;
10613         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10614         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10615         jint ret_val = ReplyChannelRange_get_number_of_blocks(&this_ptr_conv);
10616         return ret_val;
10617 }
10618
10619 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ReplyChannelRange_1set_1number_1of_1blocks(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
10620         LDKReplyChannelRange this_ptr_conv;
10621         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10622         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10623         ReplyChannelRange_set_number_of_blocks(&this_ptr_conv, val);
10624 }
10625
10626 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_ReplyChannelRange_1get_1full_1information(JNIEnv * _env, jclass _b, jlong this_ptr) {
10627         LDKReplyChannelRange this_ptr_conv;
10628         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10629         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10630         jboolean ret_val = ReplyChannelRange_get_full_information(&this_ptr_conv);
10631         return ret_val;
10632 }
10633
10634 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ReplyChannelRange_1set_1full_1information(JNIEnv * _env, jclass _b, jlong this_ptr, jboolean val) {
10635         LDKReplyChannelRange this_ptr_conv;
10636         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10637         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10638         ReplyChannelRange_set_full_information(&this_ptr_conv, val);
10639 }
10640
10641 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ReplyChannelRange_1set_1short_1channel_1ids(JNIEnv * _env, jclass _b, jlong this_ptr, jlongArray val) {
10642         LDKReplyChannelRange this_ptr_conv;
10643         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10644         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10645         LDKCVec_u64Z val_constr;
10646         val_constr.datalen = (*_env)->GetArrayLength (_env, val);
10647         if (val_constr.datalen > 0)
10648                 val_constr.data = MALLOC(val_constr.datalen * sizeof(jlong), "LDKCVec_u64Z Elements");
10649         else
10650                 val_constr.data = NULL;
10651         long* val_vals = (*_env)->GetLongArrayElements (_env, val, NULL);
10652         for (size_t g = 0; g < val_constr.datalen; g++) {
10653                 long arr_conv_6 = val_vals[g];
10654                 val_constr.data[g] = arr_conv_6;
10655         }
10656         (*_env)->ReleaseLongArrayElements (_env, val, val_vals, 0);
10657         ReplyChannelRange_set_short_channel_ids(&this_ptr_conv, val_constr);
10658 }
10659
10660 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) {
10661         LDKThirtyTwoBytes chain_hash_arg_ref;
10662         CHECK((*_env)->GetArrayLength (_env, chain_hash_arg) == 32);
10663         (*_env)->GetByteArrayRegion (_env, chain_hash_arg, 0, 32, chain_hash_arg_ref.data);
10664         LDKCVec_u64Z short_channel_ids_arg_constr;
10665         short_channel_ids_arg_constr.datalen = (*_env)->GetArrayLength (_env, short_channel_ids_arg);
10666         if (short_channel_ids_arg_constr.datalen > 0)
10667                 short_channel_ids_arg_constr.data = MALLOC(short_channel_ids_arg_constr.datalen * sizeof(jlong), "LDKCVec_u64Z Elements");
10668         else
10669                 short_channel_ids_arg_constr.data = NULL;
10670         long* short_channel_ids_arg_vals = (*_env)->GetLongArrayElements (_env, short_channel_ids_arg, NULL);
10671         for (size_t g = 0; g < short_channel_ids_arg_constr.datalen; g++) {
10672                 long arr_conv_6 = short_channel_ids_arg_vals[g];
10673                 short_channel_ids_arg_constr.data[g] = arr_conv_6;
10674         }
10675         (*_env)->ReleaseLongArrayElements (_env, short_channel_ids_arg, short_channel_ids_arg_vals, 0);
10676         LDKReplyChannelRange ret_var = ReplyChannelRange_new(chain_hash_arg_ref, first_blocknum_arg, number_of_blocks_arg, full_information_arg, short_channel_ids_arg_constr);
10677         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10678         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10679         long ret_ref = (long)ret_var.inner;
10680         if (ret_var.is_owned) {
10681                 ret_ref |= 1;
10682         }
10683         return ret_ref;
10684 }
10685
10686 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_QueryShortChannelIds_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
10687         LDKQueryShortChannelIds this_ptr_conv;
10688         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10689         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10690         QueryShortChannelIds_free(this_ptr_conv);
10691 }
10692
10693 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_QueryShortChannelIds_1clone(JNIEnv * _env, jclass _b, jlong orig) {
10694         LDKQueryShortChannelIds orig_conv;
10695         orig_conv.inner = (void*)(orig & (~1));
10696         orig_conv.is_owned = (orig & 1) || (orig == 0);
10697         LDKQueryShortChannelIds ret_var = QueryShortChannelIds_clone(&orig_conv);
10698         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10699         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10700         long ret_ref = (long)ret_var.inner;
10701         if (ret_var.is_owned) {
10702                 ret_ref |= 1;
10703         }
10704         return ret_ref;
10705 }
10706
10707 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_QueryShortChannelIds_1get_1chain_1hash(JNIEnv * _env, jclass _b, jlong this_ptr) {
10708         LDKQueryShortChannelIds this_ptr_conv;
10709         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10710         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10711         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
10712         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *QueryShortChannelIds_get_chain_hash(&this_ptr_conv));
10713         return ret_arr;
10714 }
10715
10716 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_QueryShortChannelIds_1set_1chain_1hash(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
10717         LDKQueryShortChannelIds this_ptr_conv;
10718         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10719         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10720         LDKThirtyTwoBytes val_ref;
10721         CHECK((*_env)->GetArrayLength (_env, val) == 32);
10722         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
10723         QueryShortChannelIds_set_chain_hash(&this_ptr_conv, val_ref);
10724 }
10725
10726 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_QueryShortChannelIds_1set_1short_1channel_1ids(JNIEnv * _env, jclass _b, jlong this_ptr, jlongArray val) {
10727         LDKQueryShortChannelIds this_ptr_conv;
10728         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10729         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10730         LDKCVec_u64Z val_constr;
10731         val_constr.datalen = (*_env)->GetArrayLength (_env, val);
10732         if (val_constr.datalen > 0)
10733                 val_constr.data = MALLOC(val_constr.datalen * sizeof(jlong), "LDKCVec_u64Z Elements");
10734         else
10735                 val_constr.data = NULL;
10736         long* val_vals = (*_env)->GetLongArrayElements (_env, val, NULL);
10737         for (size_t g = 0; g < val_constr.datalen; g++) {
10738                 long arr_conv_6 = val_vals[g];
10739                 val_constr.data[g] = arr_conv_6;
10740         }
10741         (*_env)->ReleaseLongArrayElements (_env, val, val_vals, 0);
10742         QueryShortChannelIds_set_short_channel_ids(&this_ptr_conv, val_constr);
10743 }
10744
10745 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_QueryShortChannelIds_1new(JNIEnv * _env, jclass _b, jbyteArray chain_hash_arg, jlongArray short_channel_ids_arg) {
10746         LDKThirtyTwoBytes chain_hash_arg_ref;
10747         CHECK((*_env)->GetArrayLength (_env, chain_hash_arg) == 32);
10748         (*_env)->GetByteArrayRegion (_env, chain_hash_arg, 0, 32, chain_hash_arg_ref.data);
10749         LDKCVec_u64Z short_channel_ids_arg_constr;
10750         short_channel_ids_arg_constr.datalen = (*_env)->GetArrayLength (_env, short_channel_ids_arg);
10751         if (short_channel_ids_arg_constr.datalen > 0)
10752                 short_channel_ids_arg_constr.data = MALLOC(short_channel_ids_arg_constr.datalen * sizeof(jlong), "LDKCVec_u64Z Elements");
10753         else
10754                 short_channel_ids_arg_constr.data = NULL;
10755         long* short_channel_ids_arg_vals = (*_env)->GetLongArrayElements (_env, short_channel_ids_arg, NULL);
10756         for (size_t g = 0; g < short_channel_ids_arg_constr.datalen; g++) {
10757                 long arr_conv_6 = short_channel_ids_arg_vals[g];
10758                 short_channel_ids_arg_constr.data[g] = arr_conv_6;
10759         }
10760         (*_env)->ReleaseLongArrayElements (_env, short_channel_ids_arg, short_channel_ids_arg_vals, 0);
10761         LDKQueryShortChannelIds ret_var = QueryShortChannelIds_new(chain_hash_arg_ref, short_channel_ids_arg_constr);
10762         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10763         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10764         long ret_ref = (long)ret_var.inner;
10765         if (ret_var.is_owned) {
10766                 ret_ref |= 1;
10767         }
10768         return ret_ref;
10769 }
10770
10771 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ReplyShortChannelIdsEnd_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
10772         LDKReplyShortChannelIdsEnd this_ptr_conv;
10773         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10774         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10775         ReplyShortChannelIdsEnd_free(this_ptr_conv);
10776 }
10777
10778 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ReplyShortChannelIdsEnd_1clone(JNIEnv * _env, jclass _b, jlong orig) {
10779         LDKReplyShortChannelIdsEnd orig_conv;
10780         orig_conv.inner = (void*)(orig & (~1));
10781         orig_conv.is_owned = (orig & 1) || (orig == 0);
10782         LDKReplyShortChannelIdsEnd ret_var = ReplyShortChannelIdsEnd_clone(&orig_conv);
10783         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10784         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10785         long ret_ref = (long)ret_var.inner;
10786         if (ret_var.is_owned) {
10787                 ret_ref |= 1;
10788         }
10789         return ret_ref;
10790 }
10791
10792 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ReplyShortChannelIdsEnd_1get_1chain_1hash(JNIEnv * _env, jclass _b, jlong this_ptr) {
10793         LDKReplyShortChannelIdsEnd this_ptr_conv;
10794         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10795         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10796         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
10797         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *ReplyShortChannelIdsEnd_get_chain_hash(&this_ptr_conv));
10798         return ret_arr;
10799 }
10800
10801 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ReplyShortChannelIdsEnd_1set_1chain_1hash(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
10802         LDKReplyShortChannelIdsEnd this_ptr_conv;
10803         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10804         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10805         LDKThirtyTwoBytes val_ref;
10806         CHECK((*_env)->GetArrayLength (_env, val) == 32);
10807         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
10808         ReplyShortChannelIdsEnd_set_chain_hash(&this_ptr_conv, val_ref);
10809 }
10810
10811 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_ReplyShortChannelIdsEnd_1get_1full_1information(JNIEnv * _env, jclass _b, jlong this_ptr) {
10812         LDKReplyShortChannelIdsEnd this_ptr_conv;
10813         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10814         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10815         jboolean ret_val = ReplyShortChannelIdsEnd_get_full_information(&this_ptr_conv);
10816         return ret_val;
10817 }
10818
10819 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ReplyShortChannelIdsEnd_1set_1full_1information(JNIEnv * _env, jclass _b, jlong this_ptr, jboolean val) {
10820         LDKReplyShortChannelIdsEnd this_ptr_conv;
10821         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10822         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10823         ReplyShortChannelIdsEnd_set_full_information(&this_ptr_conv, val);
10824 }
10825
10826 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ReplyShortChannelIdsEnd_1new(JNIEnv * _env, jclass _b, jbyteArray chain_hash_arg, jboolean full_information_arg) {
10827         LDKThirtyTwoBytes chain_hash_arg_ref;
10828         CHECK((*_env)->GetArrayLength (_env, chain_hash_arg) == 32);
10829         (*_env)->GetByteArrayRegion (_env, chain_hash_arg, 0, 32, chain_hash_arg_ref.data);
10830         LDKReplyShortChannelIdsEnd ret_var = ReplyShortChannelIdsEnd_new(chain_hash_arg_ref, full_information_arg);
10831         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10832         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10833         long ret_ref = (long)ret_var.inner;
10834         if (ret_var.is_owned) {
10835                 ret_ref |= 1;
10836         }
10837         return ret_ref;
10838 }
10839
10840 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_GossipTimestampFilter_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
10841         LDKGossipTimestampFilter this_ptr_conv;
10842         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10843         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10844         GossipTimestampFilter_free(this_ptr_conv);
10845 }
10846
10847 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_GossipTimestampFilter_1clone(JNIEnv * _env, jclass _b, jlong orig) {
10848         LDKGossipTimestampFilter orig_conv;
10849         orig_conv.inner = (void*)(orig & (~1));
10850         orig_conv.is_owned = (orig & 1) || (orig == 0);
10851         LDKGossipTimestampFilter ret_var = GossipTimestampFilter_clone(&orig_conv);
10852         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10853         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10854         long ret_ref = (long)ret_var.inner;
10855         if (ret_var.is_owned) {
10856                 ret_ref |= 1;
10857         }
10858         return ret_ref;
10859 }
10860
10861 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_GossipTimestampFilter_1get_1chain_1hash(JNIEnv * _env, jclass _b, jlong this_ptr) {
10862         LDKGossipTimestampFilter this_ptr_conv;
10863         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10864         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10865         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
10866         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *GossipTimestampFilter_get_chain_hash(&this_ptr_conv));
10867         return ret_arr;
10868 }
10869
10870 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_GossipTimestampFilter_1set_1chain_1hash(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
10871         LDKGossipTimestampFilter this_ptr_conv;
10872         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10873         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10874         LDKThirtyTwoBytes val_ref;
10875         CHECK((*_env)->GetArrayLength (_env, val) == 32);
10876         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
10877         GossipTimestampFilter_set_chain_hash(&this_ptr_conv, val_ref);
10878 }
10879
10880 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_GossipTimestampFilter_1get_1first_1timestamp(JNIEnv * _env, jclass _b, jlong this_ptr) {
10881         LDKGossipTimestampFilter this_ptr_conv;
10882         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10883         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10884         jint ret_val = GossipTimestampFilter_get_first_timestamp(&this_ptr_conv);
10885         return ret_val;
10886 }
10887
10888 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_GossipTimestampFilter_1set_1first_1timestamp(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
10889         LDKGossipTimestampFilter this_ptr_conv;
10890         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10891         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10892         GossipTimestampFilter_set_first_timestamp(&this_ptr_conv, val);
10893 }
10894
10895 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_GossipTimestampFilter_1get_1timestamp_1range(JNIEnv * _env, jclass _b, jlong this_ptr) {
10896         LDKGossipTimestampFilter this_ptr_conv;
10897         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10898         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10899         jint ret_val = GossipTimestampFilter_get_timestamp_range(&this_ptr_conv);
10900         return ret_val;
10901 }
10902
10903 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_GossipTimestampFilter_1set_1timestamp_1range(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
10904         LDKGossipTimestampFilter 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         GossipTimestampFilter_set_timestamp_range(&this_ptr_conv, val);
10908 }
10909
10910 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) {
10911         LDKThirtyTwoBytes chain_hash_arg_ref;
10912         CHECK((*_env)->GetArrayLength (_env, chain_hash_arg) == 32);
10913         (*_env)->GetByteArrayRegion (_env, chain_hash_arg, 0, 32, chain_hash_arg_ref.data);
10914         LDKGossipTimestampFilter ret_var = GossipTimestampFilter_new(chain_hash_arg_ref, first_timestamp_arg, timestamp_range_arg);
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 void JNICALL Java_org_ldk_impl_bindings_ErrorAction_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
10925         LDKErrorAction this_ptr_conv = *(LDKErrorAction*)this_ptr;
10926         FREE((void*)this_ptr);
10927         ErrorAction_free(this_ptr_conv);
10928 }
10929
10930 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ErrorAction_1clone(JNIEnv * _env, jclass _b, jlong orig) {
10931         LDKErrorAction* orig_conv = (LDKErrorAction*)orig;
10932         LDKErrorAction *ret_copy = MALLOC(sizeof(LDKErrorAction), "LDKErrorAction");
10933         *ret_copy = ErrorAction_clone(orig_conv);
10934         long ret_ref = (long)ret_copy;
10935         return ret_ref;
10936 }
10937
10938 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_LightningError_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
10939         LDKLightningError this_ptr_conv;
10940         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10941         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10942         LightningError_free(this_ptr_conv);
10943 }
10944
10945 JNIEXPORT jstring JNICALL Java_org_ldk_impl_bindings_LightningError_1get_1err(JNIEnv * _env, jclass _b, jlong this_ptr) {
10946         LDKLightningError this_ptr_conv;
10947         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10948         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10949         LDKStr _str = LightningError_get_err(&this_ptr_conv);
10950         char* _buf = MALLOC(_str.len + 1, "str conv buf");
10951         memcpy(_buf, _str.chars, _str.len);
10952         _buf[_str.len] = 0;
10953         jstring _conv = (*_env)->NewStringUTF(_env, _str.chars);
10954         FREE(_buf);
10955         return _conv;
10956 }
10957
10958 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_LightningError_1set_1err(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
10959         LDKLightningError this_ptr_conv;
10960         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10961         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10962         LDKCVec_u8Z val_ref;
10963         val_ref.data = (*_env)->GetByteArrayElements (_env, val, NULL);
10964         val_ref.datalen = (*_env)->GetArrayLength (_env, val);
10965         LightningError_set_err(&this_ptr_conv, val_ref);
10966         (*_env)->ReleaseByteArrayElements(_env, val, (int8_t*)val_ref.data, 0);
10967 }
10968
10969 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LightningError_1get_1action(JNIEnv * _env, jclass _b, jlong this_ptr) {
10970         LDKLightningError this_ptr_conv;
10971         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10972         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10973         LDKErrorAction *ret_copy = MALLOC(sizeof(LDKErrorAction), "LDKErrorAction");
10974         *ret_copy = LightningError_get_action(&this_ptr_conv);
10975         long ret_ref = (long)ret_copy;
10976         return ret_ref;
10977 }
10978
10979 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_LightningError_1set_1action(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
10980         LDKLightningError this_ptr_conv;
10981         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10982         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10983         LDKErrorAction val_conv = *(LDKErrorAction*)val;
10984         FREE((void*)val);
10985         LightningError_set_action(&this_ptr_conv, val_conv);
10986 }
10987
10988 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LightningError_1new(JNIEnv * _env, jclass _b, jbyteArray err_arg, jlong action_arg) {
10989         LDKCVec_u8Z err_arg_ref;
10990         err_arg_ref.data = (*_env)->GetByteArrayElements (_env, err_arg, NULL);
10991         err_arg_ref.datalen = (*_env)->GetArrayLength (_env, err_arg);
10992         LDKErrorAction action_arg_conv = *(LDKErrorAction*)action_arg;
10993         FREE((void*)action_arg);
10994         LDKLightningError ret_var = LightningError_new(err_arg_ref, action_arg_conv);
10995         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10996         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10997         long ret_ref = (long)ret_var.inner;
10998         if (ret_var.is_owned) {
10999                 ret_ref |= 1;
11000         }
11001         (*_env)->ReleaseByteArrayElements(_env, err_arg, (int8_t*)err_arg_ref.data, 0);
11002         return ret_ref;
11003 }
11004
11005 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CommitmentUpdate_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
11006         LDKCommitmentUpdate this_ptr_conv;
11007         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11008         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
11009         CommitmentUpdate_free(this_ptr_conv);
11010 }
11011
11012 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CommitmentUpdate_1clone(JNIEnv * _env, jclass _b, jlong orig) {
11013         LDKCommitmentUpdate orig_conv;
11014         orig_conv.inner = (void*)(orig & (~1));
11015         orig_conv.is_owned = (orig & 1) || (orig == 0);
11016         LDKCommitmentUpdate ret_var = CommitmentUpdate_clone(&orig_conv);
11017         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11018         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11019         long ret_ref = (long)ret_var.inner;
11020         if (ret_var.is_owned) {
11021                 ret_ref |= 1;
11022         }
11023         return ret_ref;
11024 }
11025
11026 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CommitmentUpdate_1set_1update_1add_1htlcs(JNIEnv * _env, jclass _b, jlong this_ptr, jlongArray val) {
11027         LDKCommitmentUpdate this_ptr_conv;
11028         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11029         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
11030         LDKCVec_UpdateAddHTLCZ val_constr;
11031         val_constr.datalen = (*_env)->GetArrayLength (_env, val);
11032         if (val_constr.datalen > 0)
11033                 val_constr.data = MALLOC(val_constr.datalen * sizeof(LDKUpdateAddHTLC), "LDKCVec_UpdateAddHTLCZ Elements");
11034         else
11035                 val_constr.data = NULL;
11036         long* val_vals = (*_env)->GetLongArrayElements (_env, val, NULL);
11037         for (size_t p = 0; p < val_constr.datalen; p++) {
11038                 long arr_conv_15 = val_vals[p];
11039                 LDKUpdateAddHTLC arr_conv_15_conv;
11040                 arr_conv_15_conv.inner = (void*)(arr_conv_15 & (~1));
11041                 arr_conv_15_conv.is_owned = (arr_conv_15 & 1) || (arr_conv_15 == 0);
11042                 if (arr_conv_15_conv.inner != NULL)
11043                         arr_conv_15_conv = UpdateAddHTLC_clone(&arr_conv_15_conv);
11044                 val_constr.data[p] = arr_conv_15_conv;
11045         }
11046         (*_env)->ReleaseLongArrayElements (_env, val, val_vals, 0);
11047         CommitmentUpdate_set_update_add_htlcs(&this_ptr_conv, val_constr);
11048 }
11049
11050 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CommitmentUpdate_1set_1update_1fulfill_1htlcs(JNIEnv * _env, jclass _b, jlong this_ptr, jlongArray val) {
11051         LDKCommitmentUpdate this_ptr_conv;
11052         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11053         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
11054         LDKCVec_UpdateFulfillHTLCZ val_constr;
11055         val_constr.datalen = (*_env)->GetArrayLength (_env, val);
11056         if (val_constr.datalen > 0)
11057                 val_constr.data = MALLOC(val_constr.datalen * sizeof(LDKUpdateFulfillHTLC), "LDKCVec_UpdateFulfillHTLCZ Elements");
11058         else
11059                 val_constr.data = NULL;
11060         long* val_vals = (*_env)->GetLongArrayElements (_env, val, NULL);
11061         for (size_t t = 0; t < val_constr.datalen; t++) {
11062                 long arr_conv_19 = val_vals[t];
11063                 LDKUpdateFulfillHTLC arr_conv_19_conv;
11064                 arr_conv_19_conv.inner = (void*)(arr_conv_19 & (~1));
11065                 arr_conv_19_conv.is_owned = (arr_conv_19 & 1) || (arr_conv_19 == 0);
11066                 if (arr_conv_19_conv.inner != NULL)
11067                         arr_conv_19_conv = UpdateFulfillHTLC_clone(&arr_conv_19_conv);
11068                 val_constr.data[t] = arr_conv_19_conv;
11069         }
11070         (*_env)->ReleaseLongArrayElements (_env, val, val_vals, 0);
11071         CommitmentUpdate_set_update_fulfill_htlcs(&this_ptr_conv, val_constr);
11072 }
11073
11074 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CommitmentUpdate_1set_1update_1fail_1htlcs(JNIEnv * _env, jclass _b, jlong this_ptr, jlongArray val) {
11075         LDKCommitmentUpdate this_ptr_conv;
11076         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11077         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
11078         LDKCVec_UpdateFailHTLCZ val_constr;
11079         val_constr.datalen = (*_env)->GetArrayLength (_env, val);
11080         if (val_constr.datalen > 0)
11081                 val_constr.data = MALLOC(val_constr.datalen * sizeof(LDKUpdateFailHTLC), "LDKCVec_UpdateFailHTLCZ Elements");
11082         else
11083                 val_constr.data = NULL;
11084         long* val_vals = (*_env)->GetLongArrayElements (_env, val, NULL);
11085         for (size_t q = 0; q < val_constr.datalen; q++) {
11086                 long arr_conv_16 = val_vals[q];
11087                 LDKUpdateFailHTLC arr_conv_16_conv;
11088                 arr_conv_16_conv.inner = (void*)(arr_conv_16 & (~1));
11089                 arr_conv_16_conv.is_owned = (arr_conv_16 & 1) || (arr_conv_16 == 0);
11090                 if (arr_conv_16_conv.inner != NULL)
11091                         arr_conv_16_conv = UpdateFailHTLC_clone(&arr_conv_16_conv);
11092                 val_constr.data[q] = arr_conv_16_conv;
11093         }
11094         (*_env)->ReleaseLongArrayElements (_env, val, val_vals, 0);
11095         CommitmentUpdate_set_update_fail_htlcs(&this_ptr_conv, val_constr);
11096 }
11097
11098 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CommitmentUpdate_1set_1update_1fail_1malformed_1htlcs(JNIEnv * _env, jclass _b, jlong this_ptr, jlongArray val) {
11099         LDKCommitmentUpdate 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         LDKCVec_UpdateFailMalformedHTLCZ val_constr;
11103         val_constr.datalen = (*_env)->GetArrayLength (_env, val);
11104         if (val_constr.datalen > 0)
11105                 val_constr.data = MALLOC(val_constr.datalen * sizeof(LDKUpdateFailMalformedHTLC), "LDKCVec_UpdateFailMalformedHTLCZ Elements");
11106         else
11107                 val_constr.data = NULL;
11108         long* val_vals = (*_env)->GetLongArrayElements (_env, val, NULL);
11109         for (size_t z = 0; z < val_constr.datalen; z++) {
11110                 long arr_conv_25 = val_vals[z];
11111                 LDKUpdateFailMalformedHTLC arr_conv_25_conv;
11112                 arr_conv_25_conv.inner = (void*)(arr_conv_25 & (~1));
11113                 arr_conv_25_conv.is_owned = (arr_conv_25 & 1) || (arr_conv_25 == 0);
11114                 if (arr_conv_25_conv.inner != NULL)
11115                         arr_conv_25_conv = UpdateFailMalformedHTLC_clone(&arr_conv_25_conv);
11116                 val_constr.data[z] = arr_conv_25_conv;
11117         }
11118         (*_env)->ReleaseLongArrayElements (_env, val, val_vals, 0);
11119         CommitmentUpdate_set_update_fail_malformed_htlcs(&this_ptr_conv, val_constr);
11120 }
11121
11122 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CommitmentUpdate_1get_1update_1fee(JNIEnv * _env, jclass _b, jlong this_ptr) {
11123         LDKCommitmentUpdate this_ptr_conv;
11124         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11125         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
11126         LDKUpdateFee ret_var = CommitmentUpdate_get_update_fee(&this_ptr_conv);
11127         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11128         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11129         long ret_ref = (long)ret_var.inner;
11130         if (ret_var.is_owned) {
11131                 ret_ref |= 1;
11132         }
11133         return ret_ref;
11134 }
11135
11136 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CommitmentUpdate_1set_1update_1fee(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
11137         LDKCommitmentUpdate this_ptr_conv;
11138         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11139         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
11140         LDKUpdateFee val_conv;
11141         val_conv.inner = (void*)(val & (~1));
11142         val_conv.is_owned = (val & 1) || (val == 0);
11143         if (val_conv.inner != NULL)
11144                 val_conv = UpdateFee_clone(&val_conv);
11145         CommitmentUpdate_set_update_fee(&this_ptr_conv, val_conv);
11146 }
11147
11148 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CommitmentUpdate_1get_1commitment_1signed(JNIEnv * _env, jclass _b, jlong this_ptr) {
11149         LDKCommitmentUpdate this_ptr_conv;
11150         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11151         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
11152         LDKCommitmentSigned ret_var = CommitmentUpdate_get_commitment_signed(&this_ptr_conv);
11153         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11154         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11155         long ret_ref = (long)ret_var.inner;
11156         if (ret_var.is_owned) {
11157                 ret_ref |= 1;
11158         }
11159         return ret_ref;
11160 }
11161
11162 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CommitmentUpdate_1set_1commitment_1signed(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
11163         LDKCommitmentUpdate this_ptr_conv;
11164         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11165         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
11166         LDKCommitmentSigned val_conv;
11167         val_conv.inner = (void*)(val & (~1));
11168         val_conv.is_owned = (val & 1) || (val == 0);
11169         if (val_conv.inner != NULL)
11170                 val_conv = CommitmentSigned_clone(&val_conv);
11171         CommitmentUpdate_set_commitment_signed(&this_ptr_conv, val_conv);
11172 }
11173
11174 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) {
11175         LDKCVec_UpdateAddHTLCZ update_add_htlcs_arg_constr;
11176         update_add_htlcs_arg_constr.datalen = (*_env)->GetArrayLength (_env, update_add_htlcs_arg);
11177         if (update_add_htlcs_arg_constr.datalen > 0)
11178                 update_add_htlcs_arg_constr.data = MALLOC(update_add_htlcs_arg_constr.datalen * sizeof(LDKUpdateAddHTLC), "LDKCVec_UpdateAddHTLCZ Elements");
11179         else
11180                 update_add_htlcs_arg_constr.data = NULL;
11181         long* update_add_htlcs_arg_vals = (*_env)->GetLongArrayElements (_env, update_add_htlcs_arg, NULL);
11182         for (size_t p = 0; p < update_add_htlcs_arg_constr.datalen; p++) {
11183                 long arr_conv_15 = update_add_htlcs_arg_vals[p];
11184                 LDKUpdateAddHTLC arr_conv_15_conv;
11185                 arr_conv_15_conv.inner = (void*)(arr_conv_15 & (~1));
11186                 arr_conv_15_conv.is_owned = (arr_conv_15 & 1) || (arr_conv_15 == 0);
11187                 if (arr_conv_15_conv.inner != NULL)
11188                         arr_conv_15_conv = UpdateAddHTLC_clone(&arr_conv_15_conv);
11189                 update_add_htlcs_arg_constr.data[p] = arr_conv_15_conv;
11190         }
11191         (*_env)->ReleaseLongArrayElements (_env, update_add_htlcs_arg, update_add_htlcs_arg_vals, 0);
11192         LDKCVec_UpdateFulfillHTLCZ update_fulfill_htlcs_arg_constr;
11193         update_fulfill_htlcs_arg_constr.datalen = (*_env)->GetArrayLength (_env, update_fulfill_htlcs_arg);
11194         if (update_fulfill_htlcs_arg_constr.datalen > 0)
11195                 update_fulfill_htlcs_arg_constr.data = MALLOC(update_fulfill_htlcs_arg_constr.datalen * sizeof(LDKUpdateFulfillHTLC), "LDKCVec_UpdateFulfillHTLCZ Elements");
11196         else
11197                 update_fulfill_htlcs_arg_constr.data = NULL;
11198         long* update_fulfill_htlcs_arg_vals = (*_env)->GetLongArrayElements (_env, update_fulfill_htlcs_arg, NULL);
11199         for (size_t t = 0; t < update_fulfill_htlcs_arg_constr.datalen; t++) {
11200                 long arr_conv_19 = update_fulfill_htlcs_arg_vals[t];
11201                 LDKUpdateFulfillHTLC arr_conv_19_conv;
11202                 arr_conv_19_conv.inner = (void*)(arr_conv_19 & (~1));
11203                 arr_conv_19_conv.is_owned = (arr_conv_19 & 1) || (arr_conv_19 == 0);
11204                 if (arr_conv_19_conv.inner != NULL)
11205                         arr_conv_19_conv = UpdateFulfillHTLC_clone(&arr_conv_19_conv);
11206                 update_fulfill_htlcs_arg_constr.data[t] = arr_conv_19_conv;
11207         }
11208         (*_env)->ReleaseLongArrayElements (_env, update_fulfill_htlcs_arg, update_fulfill_htlcs_arg_vals, 0);
11209         LDKCVec_UpdateFailHTLCZ update_fail_htlcs_arg_constr;
11210         update_fail_htlcs_arg_constr.datalen = (*_env)->GetArrayLength (_env, update_fail_htlcs_arg);
11211         if (update_fail_htlcs_arg_constr.datalen > 0)
11212                 update_fail_htlcs_arg_constr.data = MALLOC(update_fail_htlcs_arg_constr.datalen * sizeof(LDKUpdateFailHTLC), "LDKCVec_UpdateFailHTLCZ Elements");
11213         else
11214                 update_fail_htlcs_arg_constr.data = NULL;
11215         long* update_fail_htlcs_arg_vals = (*_env)->GetLongArrayElements (_env, update_fail_htlcs_arg, NULL);
11216         for (size_t q = 0; q < update_fail_htlcs_arg_constr.datalen; q++) {
11217                 long arr_conv_16 = update_fail_htlcs_arg_vals[q];
11218                 LDKUpdateFailHTLC arr_conv_16_conv;
11219                 arr_conv_16_conv.inner = (void*)(arr_conv_16 & (~1));
11220                 arr_conv_16_conv.is_owned = (arr_conv_16 & 1) || (arr_conv_16 == 0);
11221                 if (arr_conv_16_conv.inner != NULL)
11222                         arr_conv_16_conv = UpdateFailHTLC_clone(&arr_conv_16_conv);
11223                 update_fail_htlcs_arg_constr.data[q] = arr_conv_16_conv;
11224         }
11225         (*_env)->ReleaseLongArrayElements (_env, update_fail_htlcs_arg, update_fail_htlcs_arg_vals, 0);
11226         LDKCVec_UpdateFailMalformedHTLCZ update_fail_malformed_htlcs_arg_constr;
11227         update_fail_malformed_htlcs_arg_constr.datalen = (*_env)->GetArrayLength (_env, update_fail_malformed_htlcs_arg);
11228         if (update_fail_malformed_htlcs_arg_constr.datalen > 0)
11229                 update_fail_malformed_htlcs_arg_constr.data = MALLOC(update_fail_malformed_htlcs_arg_constr.datalen * sizeof(LDKUpdateFailMalformedHTLC), "LDKCVec_UpdateFailMalformedHTLCZ Elements");
11230         else
11231                 update_fail_malformed_htlcs_arg_constr.data = NULL;
11232         long* update_fail_malformed_htlcs_arg_vals = (*_env)->GetLongArrayElements (_env, update_fail_malformed_htlcs_arg, NULL);
11233         for (size_t z = 0; z < update_fail_malformed_htlcs_arg_constr.datalen; z++) {
11234                 long arr_conv_25 = update_fail_malformed_htlcs_arg_vals[z];
11235                 LDKUpdateFailMalformedHTLC arr_conv_25_conv;
11236                 arr_conv_25_conv.inner = (void*)(arr_conv_25 & (~1));
11237                 arr_conv_25_conv.is_owned = (arr_conv_25 & 1) || (arr_conv_25 == 0);
11238                 if (arr_conv_25_conv.inner != NULL)
11239                         arr_conv_25_conv = UpdateFailMalformedHTLC_clone(&arr_conv_25_conv);
11240                 update_fail_malformed_htlcs_arg_constr.data[z] = arr_conv_25_conv;
11241         }
11242         (*_env)->ReleaseLongArrayElements (_env, update_fail_malformed_htlcs_arg, update_fail_malformed_htlcs_arg_vals, 0);
11243         LDKUpdateFee update_fee_arg_conv;
11244         update_fee_arg_conv.inner = (void*)(update_fee_arg & (~1));
11245         update_fee_arg_conv.is_owned = (update_fee_arg & 1) || (update_fee_arg == 0);
11246         if (update_fee_arg_conv.inner != NULL)
11247                 update_fee_arg_conv = UpdateFee_clone(&update_fee_arg_conv);
11248         LDKCommitmentSigned commitment_signed_arg_conv;
11249         commitment_signed_arg_conv.inner = (void*)(commitment_signed_arg & (~1));
11250         commitment_signed_arg_conv.is_owned = (commitment_signed_arg & 1) || (commitment_signed_arg == 0);
11251         if (commitment_signed_arg_conv.inner != NULL)
11252                 commitment_signed_arg_conv = CommitmentSigned_clone(&commitment_signed_arg_conv);
11253         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);
11254         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11255         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11256         long ret_ref = (long)ret_var.inner;
11257         if (ret_var.is_owned) {
11258                 ret_ref |= 1;
11259         }
11260         return ret_ref;
11261 }
11262
11263 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_HTLCFailChannelUpdate_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
11264         LDKHTLCFailChannelUpdate this_ptr_conv = *(LDKHTLCFailChannelUpdate*)this_ptr;
11265         FREE((void*)this_ptr);
11266         HTLCFailChannelUpdate_free(this_ptr_conv);
11267 }
11268
11269 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_HTLCFailChannelUpdate_1clone(JNIEnv * _env, jclass _b, jlong orig) {
11270         LDKHTLCFailChannelUpdate* orig_conv = (LDKHTLCFailChannelUpdate*)orig;
11271         LDKHTLCFailChannelUpdate *ret_copy = MALLOC(sizeof(LDKHTLCFailChannelUpdate), "LDKHTLCFailChannelUpdate");
11272         *ret_copy = HTLCFailChannelUpdate_clone(orig_conv);
11273         long ret_ref = (long)ret_copy;
11274         return ret_ref;
11275 }
11276
11277 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelMessageHandler_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
11278         LDKChannelMessageHandler this_ptr_conv = *(LDKChannelMessageHandler*)this_ptr;
11279         FREE((void*)this_ptr);
11280         ChannelMessageHandler_free(this_ptr_conv);
11281 }
11282
11283 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RoutingMessageHandler_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
11284         LDKRoutingMessageHandler this_ptr_conv = *(LDKRoutingMessageHandler*)this_ptr;
11285         FREE((void*)this_ptr);
11286         RoutingMessageHandler_free(this_ptr_conv);
11287 }
11288
11289 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1write(JNIEnv * _env, jclass _b, jlong obj) {
11290         LDKAcceptChannel obj_conv;
11291         obj_conv.inner = (void*)(obj & (~1));
11292         obj_conv.is_owned = (obj & 1) || (obj == 0);
11293         LDKCVec_u8Z arg_var = AcceptChannel_write(&obj_conv);
11294         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
11295         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
11296         CVec_u8Z_free(arg_var);
11297         return arg_arr;
11298 }
11299
11300 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
11301         LDKu8slice ser_ref;
11302         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
11303         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
11304         LDKAcceptChannel ret_var = AcceptChannel_read(ser_ref);
11305         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11306         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11307         long ret_ref = (long)ret_var.inner;
11308         if (ret_var.is_owned) {
11309                 ret_ref |= 1;
11310         }
11311         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
11312         return ret_ref;
11313 }
11314
11315 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_AnnouncementSignatures_1write(JNIEnv * _env, jclass _b, jlong obj) {
11316         LDKAnnouncementSignatures obj_conv;
11317         obj_conv.inner = (void*)(obj & (~1));
11318         obj_conv.is_owned = (obj & 1) || (obj == 0);
11319         LDKCVec_u8Z arg_var = AnnouncementSignatures_write(&obj_conv);
11320         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
11321         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
11322         CVec_u8Z_free(arg_var);
11323         return arg_arr;
11324 }
11325
11326 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_AnnouncementSignatures_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
11327         LDKu8slice ser_ref;
11328         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
11329         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
11330         LDKAnnouncementSignatures ret_var = AnnouncementSignatures_read(ser_ref);
11331         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11332         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11333         long ret_ref = (long)ret_var.inner;
11334         if (ret_var.is_owned) {
11335                 ret_ref |= 1;
11336         }
11337         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
11338         return ret_ref;
11339 }
11340
11341 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelReestablish_1write(JNIEnv * _env, jclass _b, jlong obj) {
11342         LDKChannelReestablish obj_conv;
11343         obj_conv.inner = (void*)(obj & (~1));
11344         obj_conv.is_owned = (obj & 1) || (obj == 0);
11345         LDKCVec_u8Z arg_var = ChannelReestablish_write(&obj_conv);
11346         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
11347         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
11348         CVec_u8Z_free(arg_var);
11349         return arg_arr;
11350 }
11351
11352 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelReestablish_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
11353         LDKu8slice ser_ref;
11354         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
11355         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
11356         LDKChannelReestablish ret_var = ChannelReestablish_read(ser_ref);
11357         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11358         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11359         long ret_ref = (long)ret_var.inner;
11360         if (ret_var.is_owned) {
11361                 ret_ref |= 1;
11362         }
11363         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
11364         return ret_ref;
11365 }
11366
11367 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ClosingSigned_1write(JNIEnv * _env, jclass _b, jlong obj) {
11368         LDKClosingSigned obj_conv;
11369         obj_conv.inner = (void*)(obj & (~1));
11370         obj_conv.is_owned = (obj & 1) || (obj == 0);
11371         LDKCVec_u8Z arg_var = ClosingSigned_write(&obj_conv);
11372         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
11373         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
11374         CVec_u8Z_free(arg_var);
11375         return arg_arr;
11376 }
11377
11378 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ClosingSigned_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
11379         LDKu8slice ser_ref;
11380         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
11381         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
11382         LDKClosingSigned ret_var = ClosingSigned_read(ser_ref);
11383         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11384         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11385         long ret_ref = (long)ret_var.inner;
11386         if (ret_var.is_owned) {
11387                 ret_ref |= 1;
11388         }
11389         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
11390         return ret_ref;
11391 }
11392
11393 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_CommitmentSigned_1write(JNIEnv * _env, jclass _b, jlong obj) {
11394         LDKCommitmentSigned obj_conv;
11395         obj_conv.inner = (void*)(obj & (~1));
11396         obj_conv.is_owned = (obj & 1) || (obj == 0);
11397         LDKCVec_u8Z arg_var = CommitmentSigned_write(&obj_conv);
11398         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
11399         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
11400         CVec_u8Z_free(arg_var);
11401         return arg_arr;
11402 }
11403
11404 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CommitmentSigned_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
11405         LDKu8slice ser_ref;
11406         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
11407         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
11408         LDKCommitmentSigned ret_var = CommitmentSigned_read(ser_ref);
11409         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11410         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11411         long ret_ref = (long)ret_var.inner;
11412         if (ret_var.is_owned) {
11413                 ret_ref |= 1;
11414         }
11415         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
11416         return ret_ref;
11417 }
11418
11419 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_FundingCreated_1write(JNIEnv * _env, jclass _b, jlong obj) {
11420         LDKFundingCreated obj_conv;
11421         obj_conv.inner = (void*)(obj & (~1));
11422         obj_conv.is_owned = (obj & 1) || (obj == 0);
11423         LDKCVec_u8Z arg_var = FundingCreated_write(&obj_conv);
11424         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
11425         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
11426         CVec_u8Z_free(arg_var);
11427         return arg_arr;
11428 }
11429
11430 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_FundingCreated_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
11431         LDKu8slice ser_ref;
11432         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
11433         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
11434         LDKFundingCreated ret_var = FundingCreated_read(ser_ref);
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         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
11442         return ret_ref;
11443 }
11444
11445 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_FundingSigned_1write(JNIEnv * _env, jclass _b, jlong obj) {
11446         LDKFundingSigned obj_conv;
11447         obj_conv.inner = (void*)(obj & (~1));
11448         obj_conv.is_owned = (obj & 1) || (obj == 0);
11449         LDKCVec_u8Z arg_var = FundingSigned_write(&obj_conv);
11450         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
11451         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
11452         CVec_u8Z_free(arg_var);
11453         return arg_arr;
11454 }
11455
11456 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_FundingSigned_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
11457         LDKu8slice ser_ref;
11458         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
11459         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
11460         LDKFundingSigned ret_var = FundingSigned_read(ser_ref);
11461         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11462         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11463         long ret_ref = (long)ret_var.inner;
11464         if (ret_var.is_owned) {
11465                 ret_ref |= 1;
11466         }
11467         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
11468         return ret_ref;
11469 }
11470
11471 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_FundingLocked_1write(JNIEnv * _env, jclass _b, jlong obj) {
11472         LDKFundingLocked obj_conv;
11473         obj_conv.inner = (void*)(obj & (~1));
11474         obj_conv.is_owned = (obj & 1) || (obj == 0);
11475         LDKCVec_u8Z arg_var = FundingLocked_write(&obj_conv);
11476         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
11477         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
11478         CVec_u8Z_free(arg_var);
11479         return arg_arr;
11480 }
11481
11482 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_FundingLocked_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
11483         LDKu8slice ser_ref;
11484         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
11485         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
11486         LDKFundingLocked ret_var = FundingLocked_read(ser_ref);
11487         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11488         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11489         long ret_ref = (long)ret_var.inner;
11490         if (ret_var.is_owned) {
11491                 ret_ref |= 1;
11492         }
11493         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
11494         return ret_ref;
11495 }
11496
11497 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_Init_1write(JNIEnv * _env, jclass _b, jlong obj) {
11498         LDKInit obj_conv;
11499         obj_conv.inner = (void*)(obj & (~1));
11500         obj_conv.is_owned = (obj & 1) || (obj == 0);
11501         LDKCVec_u8Z arg_var = Init_write(&obj_conv);
11502         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
11503         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
11504         CVec_u8Z_free(arg_var);
11505         return arg_arr;
11506 }
11507
11508 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_Init_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
11509         LDKu8slice ser_ref;
11510         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
11511         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
11512         LDKInit ret_var = Init_read(ser_ref);
11513         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11514         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11515         long ret_ref = (long)ret_var.inner;
11516         if (ret_var.is_owned) {
11517                 ret_ref |= 1;
11518         }
11519         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
11520         return ret_ref;
11521 }
11522
11523 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_OpenChannel_1write(JNIEnv * _env, jclass _b, jlong obj) {
11524         LDKOpenChannel obj_conv;
11525         obj_conv.inner = (void*)(obj & (~1));
11526         obj_conv.is_owned = (obj & 1) || (obj == 0);
11527         LDKCVec_u8Z arg_var = OpenChannel_write(&obj_conv);
11528         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
11529         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
11530         CVec_u8Z_free(arg_var);
11531         return arg_arr;
11532 }
11533
11534 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_OpenChannel_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
11535         LDKu8slice ser_ref;
11536         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
11537         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
11538         LDKOpenChannel ret_var = OpenChannel_read(ser_ref);
11539         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11540         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11541         long ret_ref = (long)ret_var.inner;
11542         if (ret_var.is_owned) {
11543                 ret_ref |= 1;
11544         }
11545         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
11546         return ret_ref;
11547 }
11548
11549 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_RevokeAndACK_1write(JNIEnv * _env, jclass _b, jlong obj) {
11550         LDKRevokeAndACK obj_conv;
11551         obj_conv.inner = (void*)(obj & (~1));
11552         obj_conv.is_owned = (obj & 1) || (obj == 0);
11553         LDKCVec_u8Z arg_var = RevokeAndACK_write(&obj_conv);
11554         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
11555         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
11556         CVec_u8Z_free(arg_var);
11557         return arg_arr;
11558 }
11559
11560 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_RevokeAndACK_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
11561         LDKu8slice ser_ref;
11562         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
11563         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
11564         LDKRevokeAndACK ret_var = RevokeAndACK_read(ser_ref);
11565         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11566         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11567         long ret_ref = (long)ret_var.inner;
11568         if (ret_var.is_owned) {
11569                 ret_ref |= 1;
11570         }
11571         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
11572         return ret_ref;
11573 }
11574
11575 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_Shutdown_1write(JNIEnv * _env, jclass _b, jlong obj) {
11576         LDKShutdown obj_conv;
11577         obj_conv.inner = (void*)(obj & (~1));
11578         obj_conv.is_owned = (obj & 1) || (obj == 0);
11579         LDKCVec_u8Z arg_var = Shutdown_write(&obj_conv);
11580         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
11581         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
11582         CVec_u8Z_free(arg_var);
11583         return arg_arr;
11584 }
11585
11586 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_Shutdown_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
11587         LDKu8slice ser_ref;
11588         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
11589         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
11590         LDKShutdown ret_var = Shutdown_read(ser_ref);
11591         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11592         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11593         long ret_ref = (long)ret_var.inner;
11594         if (ret_var.is_owned) {
11595                 ret_ref |= 1;
11596         }
11597         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
11598         return ret_ref;
11599 }
11600
11601 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UpdateFailHTLC_1write(JNIEnv * _env, jclass _b, jlong obj) {
11602         LDKUpdateFailHTLC obj_conv;
11603         obj_conv.inner = (void*)(obj & (~1));
11604         obj_conv.is_owned = (obj & 1) || (obj == 0);
11605         LDKCVec_u8Z arg_var = UpdateFailHTLC_write(&obj_conv);
11606         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
11607         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
11608         CVec_u8Z_free(arg_var);
11609         return arg_arr;
11610 }
11611
11612 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UpdateFailHTLC_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
11613         LDKu8slice ser_ref;
11614         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
11615         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
11616         LDKUpdateFailHTLC ret_var = UpdateFailHTLC_read(ser_ref);
11617         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11618         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11619         long ret_ref = (long)ret_var.inner;
11620         if (ret_var.is_owned) {
11621                 ret_ref |= 1;
11622         }
11623         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
11624         return ret_ref;
11625 }
11626
11627 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UpdateFailMalformedHTLC_1write(JNIEnv * _env, jclass _b, jlong obj) {
11628         LDKUpdateFailMalformedHTLC obj_conv;
11629         obj_conv.inner = (void*)(obj & (~1));
11630         obj_conv.is_owned = (obj & 1) || (obj == 0);
11631         LDKCVec_u8Z arg_var = UpdateFailMalformedHTLC_write(&obj_conv);
11632         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
11633         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
11634         CVec_u8Z_free(arg_var);
11635         return arg_arr;
11636 }
11637
11638 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UpdateFailMalformedHTLC_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
11639         LDKu8slice ser_ref;
11640         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
11641         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
11642         LDKUpdateFailMalformedHTLC ret_var = UpdateFailMalformedHTLC_read(ser_ref);
11643         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11644         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11645         long ret_ref = (long)ret_var.inner;
11646         if (ret_var.is_owned) {
11647                 ret_ref |= 1;
11648         }
11649         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
11650         return ret_ref;
11651 }
11652
11653 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UpdateFee_1write(JNIEnv * _env, jclass _b, jlong obj) {
11654         LDKUpdateFee obj_conv;
11655         obj_conv.inner = (void*)(obj & (~1));
11656         obj_conv.is_owned = (obj & 1) || (obj == 0);
11657         LDKCVec_u8Z arg_var = UpdateFee_write(&obj_conv);
11658         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
11659         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
11660         CVec_u8Z_free(arg_var);
11661         return arg_arr;
11662 }
11663
11664 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UpdateFee_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
11665         LDKu8slice ser_ref;
11666         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
11667         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
11668         LDKUpdateFee ret_var = UpdateFee_read(ser_ref);
11669         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11670         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11671         long ret_ref = (long)ret_var.inner;
11672         if (ret_var.is_owned) {
11673                 ret_ref |= 1;
11674         }
11675         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
11676         return ret_ref;
11677 }
11678
11679 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UpdateFulfillHTLC_1write(JNIEnv * _env, jclass _b, jlong obj) {
11680         LDKUpdateFulfillHTLC obj_conv;
11681         obj_conv.inner = (void*)(obj & (~1));
11682         obj_conv.is_owned = (obj & 1) || (obj == 0);
11683         LDKCVec_u8Z arg_var = UpdateFulfillHTLC_write(&obj_conv);
11684         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
11685         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
11686         CVec_u8Z_free(arg_var);
11687         return arg_arr;
11688 }
11689
11690 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UpdateFulfillHTLC_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
11691         LDKu8slice ser_ref;
11692         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
11693         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
11694         LDKUpdateFulfillHTLC ret_var = UpdateFulfillHTLC_read(ser_ref);
11695         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11696         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11697         long ret_ref = (long)ret_var.inner;
11698         if (ret_var.is_owned) {
11699                 ret_ref |= 1;
11700         }
11701         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
11702         return ret_ref;
11703 }
11704
11705 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UpdateAddHTLC_1write(JNIEnv * _env, jclass _b, jlong obj) {
11706         LDKUpdateAddHTLC obj_conv;
11707         obj_conv.inner = (void*)(obj & (~1));
11708         obj_conv.is_owned = (obj & 1) || (obj == 0);
11709         LDKCVec_u8Z arg_var = UpdateAddHTLC_write(&obj_conv);
11710         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
11711         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
11712         CVec_u8Z_free(arg_var);
11713         return arg_arr;
11714 }
11715
11716 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UpdateAddHTLC_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
11717         LDKu8slice ser_ref;
11718         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
11719         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
11720         LDKUpdateAddHTLC ret_var = UpdateAddHTLC_read(ser_ref);
11721         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11722         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11723         long ret_ref = (long)ret_var.inner;
11724         if (ret_var.is_owned) {
11725                 ret_ref |= 1;
11726         }
11727         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
11728         return ret_ref;
11729 }
11730
11731 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_Ping_1write(JNIEnv * _env, jclass _b, jlong obj) {
11732         LDKPing obj_conv;
11733         obj_conv.inner = (void*)(obj & (~1));
11734         obj_conv.is_owned = (obj & 1) || (obj == 0);
11735         LDKCVec_u8Z arg_var = Ping_write(&obj_conv);
11736         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
11737         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
11738         CVec_u8Z_free(arg_var);
11739         return arg_arr;
11740 }
11741
11742 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_Ping_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
11743         LDKu8slice ser_ref;
11744         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
11745         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
11746         LDKPing ret_var = Ping_read(ser_ref);
11747         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11748         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11749         long ret_ref = (long)ret_var.inner;
11750         if (ret_var.is_owned) {
11751                 ret_ref |= 1;
11752         }
11753         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
11754         return ret_ref;
11755 }
11756
11757 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_Pong_1write(JNIEnv * _env, jclass _b, jlong obj) {
11758         LDKPong obj_conv;
11759         obj_conv.inner = (void*)(obj & (~1));
11760         obj_conv.is_owned = (obj & 1) || (obj == 0);
11761         LDKCVec_u8Z arg_var = Pong_write(&obj_conv);
11762         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
11763         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
11764         CVec_u8Z_free(arg_var);
11765         return arg_arr;
11766 }
11767
11768 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_Pong_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
11769         LDKu8slice ser_ref;
11770         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
11771         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
11772         LDKPong ret_var = Pong_read(ser_ref);
11773         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11774         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11775         long ret_ref = (long)ret_var.inner;
11776         if (ret_var.is_owned) {
11777                 ret_ref |= 1;
11778         }
11779         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
11780         return ret_ref;
11781 }
11782
11783 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1write(JNIEnv * _env, jclass _b, jlong obj) {
11784         LDKUnsignedChannelAnnouncement obj_conv;
11785         obj_conv.inner = (void*)(obj & (~1));
11786         obj_conv.is_owned = (obj & 1) || (obj == 0);
11787         LDKCVec_u8Z arg_var = UnsignedChannelAnnouncement_write(&obj_conv);
11788         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
11789         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
11790         CVec_u8Z_free(arg_var);
11791         return arg_arr;
11792 }
11793
11794 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
11795         LDKu8slice ser_ref;
11796         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
11797         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
11798         LDKUnsignedChannelAnnouncement ret_var = UnsignedChannelAnnouncement_read(ser_ref);
11799         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11800         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11801         long ret_ref = (long)ret_var.inner;
11802         if (ret_var.is_owned) {
11803                 ret_ref |= 1;
11804         }
11805         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
11806         return ret_ref;
11807 }
11808
11809 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelAnnouncement_1write(JNIEnv * _env, jclass _b, jlong obj) {
11810         LDKChannelAnnouncement obj_conv;
11811         obj_conv.inner = (void*)(obj & (~1));
11812         obj_conv.is_owned = (obj & 1) || (obj == 0);
11813         LDKCVec_u8Z arg_var = ChannelAnnouncement_write(&obj_conv);
11814         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
11815         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
11816         CVec_u8Z_free(arg_var);
11817         return arg_arr;
11818 }
11819
11820 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelAnnouncement_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
11821         LDKu8slice ser_ref;
11822         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
11823         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
11824         LDKChannelAnnouncement ret_var = ChannelAnnouncement_read(ser_ref);
11825         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11826         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11827         long ret_ref = (long)ret_var.inner;
11828         if (ret_var.is_owned) {
11829                 ret_ref |= 1;
11830         }
11831         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
11832         return ret_ref;
11833 }
11834
11835 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1write(JNIEnv * _env, jclass _b, jlong obj) {
11836         LDKUnsignedChannelUpdate obj_conv;
11837         obj_conv.inner = (void*)(obj & (~1));
11838         obj_conv.is_owned = (obj & 1) || (obj == 0);
11839         LDKCVec_u8Z arg_var = UnsignedChannelUpdate_write(&obj_conv);
11840         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
11841         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
11842         CVec_u8Z_free(arg_var);
11843         return arg_arr;
11844 }
11845
11846 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
11847         LDKu8slice ser_ref;
11848         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
11849         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
11850         LDKUnsignedChannelUpdate ret_var = UnsignedChannelUpdate_read(ser_ref);
11851         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11852         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11853         long ret_ref = (long)ret_var.inner;
11854         if (ret_var.is_owned) {
11855                 ret_ref |= 1;
11856         }
11857         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
11858         return ret_ref;
11859 }
11860
11861 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelUpdate_1write(JNIEnv * _env, jclass _b, jlong obj) {
11862         LDKChannelUpdate obj_conv;
11863         obj_conv.inner = (void*)(obj & (~1));
11864         obj_conv.is_owned = (obj & 1) || (obj == 0);
11865         LDKCVec_u8Z arg_var = ChannelUpdate_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_ChannelUpdate_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
11873         LDKu8slice ser_ref;
11874         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
11875         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
11876         LDKChannelUpdate ret_var = ChannelUpdate_read(ser_ref);
11877         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11878         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11879         long ret_ref = (long)ret_var.inner;
11880         if (ret_var.is_owned) {
11881                 ret_ref |= 1;
11882         }
11883         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
11884         return ret_ref;
11885 }
11886
11887 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ErrorMessage_1write(JNIEnv * _env, jclass _b, jlong obj) {
11888         LDKErrorMessage obj_conv;
11889         obj_conv.inner = (void*)(obj & (~1));
11890         obj_conv.is_owned = (obj & 1) || (obj == 0);
11891         LDKCVec_u8Z arg_var = ErrorMessage_write(&obj_conv);
11892         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
11893         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
11894         CVec_u8Z_free(arg_var);
11895         return arg_arr;
11896 }
11897
11898 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ErrorMessage_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
11899         LDKu8slice ser_ref;
11900         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
11901         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
11902         LDKErrorMessage ret_var = ErrorMessage_read(ser_ref);
11903         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11904         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11905         long ret_ref = (long)ret_var.inner;
11906         if (ret_var.is_owned) {
11907                 ret_ref |= 1;
11908         }
11909         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
11910         return ret_ref;
11911 }
11912
11913 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UnsignedNodeAnnouncement_1write(JNIEnv * _env, jclass _b, jlong obj) {
11914         LDKUnsignedNodeAnnouncement obj_conv;
11915         obj_conv.inner = (void*)(obj & (~1));
11916         obj_conv.is_owned = (obj & 1) || (obj == 0);
11917         LDKCVec_u8Z arg_var = UnsignedNodeAnnouncement_write(&obj_conv);
11918         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
11919         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
11920         CVec_u8Z_free(arg_var);
11921         return arg_arr;
11922 }
11923
11924 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UnsignedNodeAnnouncement_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
11925         LDKu8slice ser_ref;
11926         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
11927         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
11928         LDKUnsignedNodeAnnouncement ret_var = UnsignedNodeAnnouncement_read(ser_ref);
11929         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11930         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11931         long ret_ref = (long)ret_var.inner;
11932         if (ret_var.is_owned) {
11933                 ret_ref |= 1;
11934         }
11935         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
11936         return ret_ref;
11937 }
11938
11939 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_NodeAnnouncement_1write(JNIEnv * _env, jclass _b, jlong obj) {
11940         LDKNodeAnnouncement obj_conv;
11941         obj_conv.inner = (void*)(obj & (~1));
11942         obj_conv.is_owned = (obj & 1) || (obj == 0);
11943         LDKCVec_u8Z arg_var = NodeAnnouncement_write(&obj_conv);
11944         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
11945         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
11946         CVec_u8Z_free(arg_var);
11947         return arg_arr;
11948 }
11949
11950 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_NodeAnnouncement_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
11951         LDKu8slice ser_ref;
11952         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
11953         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
11954         LDKNodeAnnouncement ret_var = NodeAnnouncement_read(ser_ref);
11955         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11956         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11957         long ret_ref = (long)ret_var.inner;
11958         if (ret_var.is_owned) {
11959                 ret_ref |= 1;
11960         }
11961         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
11962         return ret_ref;
11963 }
11964
11965 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_QueryShortChannelIds_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
11966         LDKu8slice ser_ref;
11967         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
11968         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
11969         LDKQueryShortChannelIds ret_var = QueryShortChannelIds_read(ser_ref);
11970         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11971         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11972         long ret_ref = (long)ret_var.inner;
11973         if (ret_var.is_owned) {
11974                 ret_ref |= 1;
11975         }
11976         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
11977         return ret_ref;
11978 }
11979
11980 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_QueryShortChannelIds_1write(JNIEnv * _env, jclass _b, jlong obj) {
11981         LDKQueryShortChannelIds obj_conv;
11982         obj_conv.inner = (void*)(obj & (~1));
11983         obj_conv.is_owned = (obj & 1) || (obj == 0);
11984         LDKCVec_u8Z arg_var = QueryShortChannelIds_write(&obj_conv);
11985         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
11986         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
11987         CVec_u8Z_free(arg_var);
11988         return arg_arr;
11989 }
11990
11991 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ReplyShortChannelIdsEnd_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
11992         LDKu8slice ser_ref;
11993         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
11994         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
11995         LDKReplyShortChannelIdsEnd ret_var = ReplyShortChannelIdsEnd_read(ser_ref);
11996         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11997         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11998         long ret_ref = (long)ret_var.inner;
11999         if (ret_var.is_owned) {
12000                 ret_ref |= 1;
12001         }
12002         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
12003         return ret_ref;
12004 }
12005
12006 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ReplyShortChannelIdsEnd_1write(JNIEnv * _env, jclass _b, jlong obj) {
12007         LDKReplyShortChannelIdsEnd obj_conv;
12008         obj_conv.inner = (void*)(obj & (~1));
12009         obj_conv.is_owned = (obj & 1) || (obj == 0);
12010         LDKCVec_u8Z arg_var = ReplyShortChannelIdsEnd_write(&obj_conv);
12011         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
12012         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
12013         CVec_u8Z_free(arg_var);
12014         return arg_arr;
12015 }
12016
12017 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_QueryChannelRange_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
12018         LDKu8slice ser_ref;
12019         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
12020         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
12021         LDKQueryChannelRange ret_var = QueryChannelRange_read(ser_ref);
12022         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12023         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12024         long ret_ref = (long)ret_var.inner;
12025         if (ret_var.is_owned) {
12026                 ret_ref |= 1;
12027         }
12028         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
12029         return ret_ref;
12030 }
12031
12032 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_QueryChannelRange_1write(JNIEnv * _env, jclass _b, jlong obj) {
12033         LDKQueryChannelRange obj_conv;
12034         obj_conv.inner = (void*)(obj & (~1));
12035         obj_conv.is_owned = (obj & 1) || (obj == 0);
12036         LDKCVec_u8Z arg_var = QueryChannelRange_write(&obj_conv);
12037         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
12038         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
12039         CVec_u8Z_free(arg_var);
12040         return arg_arr;
12041 }
12042
12043 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ReplyChannelRange_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
12044         LDKu8slice ser_ref;
12045         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
12046         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
12047         LDKReplyChannelRange ret_var = ReplyChannelRange_read(ser_ref);
12048         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12049         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12050         long ret_ref = (long)ret_var.inner;
12051         if (ret_var.is_owned) {
12052                 ret_ref |= 1;
12053         }
12054         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
12055         return ret_ref;
12056 }
12057
12058 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ReplyChannelRange_1write(JNIEnv * _env, jclass _b, jlong obj) {
12059         LDKReplyChannelRange obj_conv;
12060         obj_conv.inner = (void*)(obj & (~1));
12061         obj_conv.is_owned = (obj & 1) || (obj == 0);
12062         LDKCVec_u8Z arg_var = ReplyChannelRange_write(&obj_conv);
12063         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
12064         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
12065         CVec_u8Z_free(arg_var);
12066         return arg_arr;
12067 }
12068
12069 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_GossipTimestampFilter_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
12070         LDKu8slice ser_ref;
12071         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
12072         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
12073         LDKGossipTimestampFilter ret_var = GossipTimestampFilter_read(ser_ref);
12074         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12075         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12076         long ret_ref = (long)ret_var.inner;
12077         if (ret_var.is_owned) {
12078                 ret_ref |= 1;
12079         }
12080         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
12081         return ret_ref;
12082 }
12083
12084 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_GossipTimestampFilter_1write(JNIEnv * _env, jclass _b, jlong obj) {
12085         LDKGossipTimestampFilter obj_conv;
12086         obj_conv.inner = (void*)(obj & (~1));
12087         obj_conv.is_owned = (obj & 1) || (obj == 0);
12088         LDKCVec_u8Z arg_var = GossipTimestampFilter_write(&obj_conv);
12089         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
12090         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
12091         CVec_u8Z_free(arg_var);
12092         return arg_arr;
12093 }
12094
12095 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_MessageHandler_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
12096         LDKMessageHandler this_ptr_conv;
12097         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12098         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12099         MessageHandler_free(this_ptr_conv);
12100 }
12101
12102 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_MessageHandler_1get_1chan_1handler(JNIEnv * _env, jclass _b, jlong this_ptr) {
12103         LDKMessageHandler this_ptr_conv;
12104         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12105         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12106         long ret_ret = (long)MessageHandler_get_chan_handler(&this_ptr_conv);
12107         return ret_ret;
12108 }
12109
12110 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_MessageHandler_1set_1chan_1handler(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
12111         LDKMessageHandler this_ptr_conv;
12112         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12113         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12114         LDKChannelMessageHandler val_conv = *(LDKChannelMessageHandler*)val;
12115         if (val_conv.free == LDKChannelMessageHandler_JCalls_free) {
12116                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
12117                 LDKChannelMessageHandler_JCalls_clone(val_conv.this_arg);
12118         }
12119         MessageHandler_set_chan_handler(&this_ptr_conv, val_conv);
12120 }
12121
12122 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_MessageHandler_1get_1route_1handler(JNIEnv * _env, jclass _b, jlong this_ptr) {
12123         LDKMessageHandler this_ptr_conv;
12124         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12125         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12126         long ret_ret = (long)MessageHandler_get_route_handler(&this_ptr_conv);
12127         return ret_ret;
12128 }
12129
12130 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_MessageHandler_1set_1route_1handler(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
12131         LDKMessageHandler this_ptr_conv;
12132         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12133         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12134         LDKRoutingMessageHandler val_conv = *(LDKRoutingMessageHandler*)val;
12135         if (val_conv.free == LDKRoutingMessageHandler_JCalls_free) {
12136                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
12137                 LDKRoutingMessageHandler_JCalls_clone(val_conv.this_arg);
12138         }
12139         MessageHandler_set_route_handler(&this_ptr_conv, val_conv);
12140 }
12141
12142 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_MessageHandler_1new(JNIEnv * _env, jclass _b, jlong chan_handler_arg, jlong route_handler_arg) {
12143         LDKChannelMessageHandler chan_handler_arg_conv = *(LDKChannelMessageHandler*)chan_handler_arg;
12144         if (chan_handler_arg_conv.free == LDKChannelMessageHandler_JCalls_free) {
12145                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
12146                 LDKChannelMessageHandler_JCalls_clone(chan_handler_arg_conv.this_arg);
12147         }
12148         LDKRoutingMessageHandler route_handler_arg_conv = *(LDKRoutingMessageHandler*)route_handler_arg;
12149         if (route_handler_arg_conv.free == LDKRoutingMessageHandler_JCalls_free) {
12150                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
12151                 LDKRoutingMessageHandler_JCalls_clone(route_handler_arg_conv.this_arg);
12152         }
12153         LDKMessageHandler ret_var = MessageHandler_new(chan_handler_arg_conv, route_handler_arg_conv);
12154         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12155         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12156         long ret_ref = (long)ret_var.inner;
12157         if (ret_var.is_owned) {
12158                 ret_ref |= 1;
12159         }
12160         return ret_ref;
12161 }
12162
12163 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_SocketDescriptor_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
12164         LDKSocketDescriptor this_ptr_conv = *(LDKSocketDescriptor*)this_ptr;
12165         FREE((void*)this_ptr);
12166         SocketDescriptor_free(this_ptr_conv);
12167 }
12168
12169 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_PeerHandleError_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
12170         LDKPeerHandleError this_ptr_conv;
12171         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12172         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12173         PeerHandleError_free(this_ptr_conv);
12174 }
12175
12176 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_PeerHandleError_1get_1no_1connection_1possible(JNIEnv * _env, jclass _b, jlong this_ptr) {
12177         LDKPeerHandleError this_ptr_conv;
12178         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12179         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12180         jboolean ret_val = PeerHandleError_get_no_connection_possible(&this_ptr_conv);
12181         return ret_val;
12182 }
12183
12184 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_PeerHandleError_1set_1no_1connection_1possible(JNIEnv * _env, jclass _b, jlong this_ptr, jboolean val) {
12185         LDKPeerHandleError this_ptr_conv;
12186         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12187         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12188         PeerHandleError_set_no_connection_possible(&this_ptr_conv, val);
12189 }
12190
12191 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_PeerHandleError_1new(JNIEnv * _env, jclass _b, jboolean no_connection_possible_arg) {
12192         LDKPeerHandleError ret_var = PeerHandleError_new(no_connection_possible_arg);
12193         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12194         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12195         long ret_ref = (long)ret_var.inner;
12196         if (ret_var.is_owned) {
12197                 ret_ref |= 1;
12198         }
12199         return ret_ref;
12200 }
12201
12202 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_PeerManager_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
12203         LDKPeerManager this_ptr_conv;
12204         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12205         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12206         PeerManager_free(this_ptr_conv);
12207 }
12208
12209 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) {
12210         LDKMessageHandler message_handler_conv;
12211         message_handler_conv.inner = (void*)(message_handler & (~1));
12212         message_handler_conv.is_owned = (message_handler & 1) || (message_handler == 0);
12213         // Warning: we may need a move here but can't clone!
12214         LDKSecretKey our_node_secret_ref;
12215         CHECK((*_env)->GetArrayLength (_env, our_node_secret) == 32);
12216         (*_env)->GetByteArrayRegion (_env, our_node_secret, 0, 32, our_node_secret_ref.bytes);
12217         unsigned char ephemeral_random_data_arr[32];
12218         CHECK((*_env)->GetArrayLength (_env, ephemeral_random_data) == 32);
12219         (*_env)->GetByteArrayRegion (_env, ephemeral_random_data, 0, 32, ephemeral_random_data_arr);
12220         unsigned char (*ephemeral_random_data_ref)[32] = &ephemeral_random_data_arr;
12221         LDKLogger logger_conv = *(LDKLogger*)logger;
12222         if (logger_conv.free == LDKLogger_JCalls_free) {
12223                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
12224                 LDKLogger_JCalls_clone(logger_conv.this_arg);
12225         }
12226         LDKPeerManager ret_var = PeerManager_new(message_handler_conv, our_node_secret_ref, ephemeral_random_data_ref, logger_conv);
12227         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12228         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12229         long ret_ref = (long)ret_var.inner;
12230         if (ret_var.is_owned) {
12231                 ret_ref |= 1;
12232         }
12233         return ret_ref;
12234 }
12235
12236 JNIEXPORT jobjectArray JNICALL Java_org_ldk_impl_bindings_PeerManager_1get_1peer_1node_1ids(JNIEnv * _env, jclass _b, jlong this_arg) {
12237         LDKPeerManager this_arg_conv;
12238         this_arg_conv.inner = (void*)(this_arg & (~1));
12239         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
12240         LDKCVec_PublicKeyZ ret_var = PeerManager_get_peer_node_ids(&this_arg_conv);
12241         jobjectArray ret_arr = (*_env)->NewObjectArray(_env, ret_var.datalen, arr_of_B_clz, NULL);
12242         for (size_t i = 0; i < ret_var.datalen; i++) {
12243                 jbyteArray arr_conv_8_arr = (*_env)->NewByteArray(_env, 33);
12244                 (*_env)->SetByteArrayRegion(_env, arr_conv_8_arr, 0, 33, ret_var.data[i].compressed_form);
12245                 (*_env)->SetObjectArrayElement(_env, ret_arr, i, arr_conv_8_arr);
12246         }
12247         CVec_PublicKeyZ_free(ret_var);
12248         return ret_arr;
12249 }
12250
12251 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) {
12252         LDKPeerManager this_arg_conv;
12253         this_arg_conv.inner = (void*)(this_arg & (~1));
12254         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
12255         LDKPublicKey their_node_id_ref;
12256         CHECK((*_env)->GetArrayLength (_env, their_node_id) == 33);
12257         (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
12258         LDKSocketDescriptor descriptor_conv = *(LDKSocketDescriptor*)descriptor;
12259         if (descriptor_conv.free == LDKSocketDescriptor_JCalls_free) {
12260                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
12261                 LDKSocketDescriptor_JCalls_clone(descriptor_conv.this_arg);
12262         }
12263         LDKCResult_CVec_u8ZPeerHandleErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_CVec_u8ZPeerHandleErrorZ), "LDKCResult_CVec_u8ZPeerHandleErrorZ");
12264         *ret_conv = PeerManager_new_outbound_connection(&this_arg_conv, their_node_id_ref, descriptor_conv);
12265         return (long)ret_conv;
12266 }
12267
12268 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_PeerManager_1new_1inbound_1connection(JNIEnv * _env, jclass _b, jlong this_arg, jlong descriptor) {
12269         LDKPeerManager this_arg_conv;
12270         this_arg_conv.inner = (void*)(this_arg & (~1));
12271         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
12272         LDKSocketDescriptor descriptor_conv = *(LDKSocketDescriptor*)descriptor;
12273         if (descriptor_conv.free == LDKSocketDescriptor_JCalls_free) {
12274                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
12275                 LDKSocketDescriptor_JCalls_clone(descriptor_conv.this_arg);
12276         }
12277         LDKCResult_NonePeerHandleErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NonePeerHandleErrorZ), "LDKCResult_NonePeerHandleErrorZ");
12278         *ret_conv = PeerManager_new_inbound_connection(&this_arg_conv, descriptor_conv);
12279         return (long)ret_conv;
12280 }
12281
12282 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_PeerManager_1write_1buffer_1space_1avail(JNIEnv * _env, jclass _b, jlong this_arg, jlong descriptor) {
12283         LDKPeerManager this_arg_conv;
12284         this_arg_conv.inner = (void*)(this_arg & (~1));
12285         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
12286         LDKSocketDescriptor* descriptor_conv = (LDKSocketDescriptor*)descriptor;
12287         LDKCResult_NonePeerHandleErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NonePeerHandleErrorZ), "LDKCResult_NonePeerHandleErrorZ");
12288         *ret_conv = PeerManager_write_buffer_space_avail(&this_arg_conv, descriptor_conv);
12289         return (long)ret_conv;
12290 }
12291
12292 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_PeerManager_1read_1event(JNIEnv * _env, jclass _b, jlong this_arg, jlong peer_descriptor, jbyteArray data) {
12293         LDKPeerManager this_arg_conv;
12294         this_arg_conv.inner = (void*)(this_arg & (~1));
12295         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
12296         LDKSocketDescriptor* peer_descriptor_conv = (LDKSocketDescriptor*)peer_descriptor;
12297         LDKu8slice data_ref;
12298         data_ref.data = (*_env)->GetByteArrayElements (_env, data, NULL);
12299         data_ref.datalen = (*_env)->GetArrayLength (_env, data);
12300         LDKCResult_boolPeerHandleErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_boolPeerHandleErrorZ), "LDKCResult_boolPeerHandleErrorZ");
12301         *ret_conv = PeerManager_read_event(&this_arg_conv, peer_descriptor_conv, data_ref);
12302         (*_env)->ReleaseByteArrayElements(_env, data, (int8_t*)data_ref.data, 0);
12303         return (long)ret_conv;
12304 }
12305
12306 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_PeerManager_1process_1events(JNIEnv * _env, jclass _b, jlong this_arg) {
12307         LDKPeerManager this_arg_conv;
12308         this_arg_conv.inner = (void*)(this_arg & (~1));
12309         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
12310         PeerManager_process_events(&this_arg_conv);
12311 }
12312
12313 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_PeerManager_1socket_1disconnected(JNIEnv * _env, jclass _b, jlong this_arg, jlong descriptor) {
12314         LDKPeerManager this_arg_conv;
12315         this_arg_conv.inner = (void*)(this_arg & (~1));
12316         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
12317         LDKSocketDescriptor* descriptor_conv = (LDKSocketDescriptor*)descriptor;
12318         PeerManager_socket_disconnected(&this_arg_conv, descriptor_conv);
12319 }
12320
12321 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_PeerManager_1timer_1tick_1occured(JNIEnv * _env, jclass _b, jlong this_arg) {
12322         LDKPeerManager this_arg_conv;
12323         this_arg_conv.inner = (void*)(this_arg & (~1));
12324         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
12325         PeerManager_timer_tick_occured(&this_arg_conv);
12326 }
12327
12328 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_build_1commitment_1secret(JNIEnv * _env, jclass _b, jbyteArray commitment_seed, jlong idx) {
12329         unsigned char commitment_seed_arr[32];
12330         CHECK((*_env)->GetArrayLength (_env, commitment_seed) == 32);
12331         (*_env)->GetByteArrayRegion (_env, commitment_seed, 0, 32, commitment_seed_arr);
12332         unsigned char (*commitment_seed_ref)[32] = &commitment_seed_arr;
12333         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 32);
12334         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 32, build_commitment_secret(commitment_seed_ref, idx).data);
12335         return arg_arr;
12336 }
12337
12338 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_derive_1private_1key(JNIEnv * _env, jclass _b, jbyteArray per_commitment_point, jbyteArray base_secret) {
12339         LDKPublicKey per_commitment_point_ref;
12340         CHECK((*_env)->GetArrayLength (_env, per_commitment_point) == 33);
12341         (*_env)->GetByteArrayRegion (_env, per_commitment_point, 0, 33, per_commitment_point_ref.compressed_form);
12342         unsigned char base_secret_arr[32];
12343         CHECK((*_env)->GetArrayLength (_env, base_secret) == 32);
12344         (*_env)->GetByteArrayRegion (_env, base_secret, 0, 32, base_secret_arr);
12345         unsigned char (*base_secret_ref)[32] = &base_secret_arr;
12346         LDKCResult_SecretKeySecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_SecretKeySecpErrorZ), "LDKCResult_SecretKeySecpErrorZ");
12347         *ret_conv = derive_private_key(per_commitment_point_ref, base_secret_ref);
12348         return (long)ret_conv;
12349 }
12350
12351 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_derive_1public_1key(JNIEnv * _env, jclass _b, jbyteArray per_commitment_point, jbyteArray base_point) {
12352         LDKPublicKey per_commitment_point_ref;
12353         CHECK((*_env)->GetArrayLength (_env, per_commitment_point) == 33);
12354         (*_env)->GetByteArrayRegion (_env, per_commitment_point, 0, 33, per_commitment_point_ref.compressed_form);
12355         LDKPublicKey base_point_ref;
12356         CHECK((*_env)->GetArrayLength (_env, base_point) == 33);
12357         (*_env)->GetByteArrayRegion (_env, base_point, 0, 33, base_point_ref.compressed_form);
12358         LDKCResult_PublicKeySecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_PublicKeySecpErrorZ), "LDKCResult_PublicKeySecpErrorZ");
12359         *ret_conv = derive_public_key(per_commitment_point_ref, base_point_ref);
12360         return (long)ret_conv;
12361 }
12362
12363 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) {
12364         unsigned char per_commitment_secret_arr[32];
12365         CHECK((*_env)->GetArrayLength (_env, per_commitment_secret) == 32);
12366         (*_env)->GetByteArrayRegion (_env, per_commitment_secret, 0, 32, per_commitment_secret_arr);
12367         unsigned char (*per_commitment_secret_ref)[32] = &per_commitment_secret_arr;
12368         unsigned char countersignatory_revocation_base_secret_arr[32];
12369         CHECK((*_env)->GetArrayLength (_env, countersignatory_revocation_base_secret) == 32);
12370         (*_env)->GetByteArrayRegion (_env, countersignatory_revocation_base_secret, 0, 32, countersignatory_revocation_base_secret_arr);
12371         unsigned char (*countersignatory_revocation_base_secret_ref)[32] = &countersignatory_revocation_base_secret_arr;
12372         LDKCResult_SecretKeySecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_SecretKeySecpErrorZ), "LDKCResult_SecretKeySecpErrorZ");
12373         *ret_conv = derive_private_revocation_key(per_commitment_secret_ref, countersignatory_revocation_base_secret_ref);
12374         return (long)ret_conv;
12375 }
12376
12377 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) {
12378         LDKPublicKey per_commitment_point_ref;
12379         CHECK((*_env)->GetArrayLength (_env, per_commitment_point) == 33);
12380         (*_env)->GetByteArrayRegion (_env, per_commitment_point, 0, 33, per_commitment_point_ref.compressed_form);
12381         LDKPublicKey countersignatory_revocation_base_point_ref;
12382         CHECK((*_env)->GetArrayLength (_env, countersignatory_revocation_base_point) == 33);
12383         (*_env)->GetByteArrayRegion (_env, countersignatory_revocation_base_point, 0, 33, countersignatory_revocation_base_point_ref.compressed_form);
12384         LDKCResult_PublicKeySecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_PublicKeySecpErrorZ), "LDKCResult_PublicKeySecpErrorZ");
12385         *ret_conv = derive_public_revocation_key(per_commitment_point_ref, countersignatory_revocation_base_point_ref);
12386         return (long)ret_conv;
12387 }
12388
12389 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_TxCreationKeys_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
12390         LDKTxCreationKeys this_ptr_conv;
12391         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12392         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12393         TxCreationKeys_free(this_ptr_conv);
12394 }
12395
12396 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_TxCreationKeys_1clone(JNIEnv * _env, jclass _b, jlong orig) {
12397         LDKTxCreationKeys orig_conv;
12398         orig_conv.inner = (void*)(orig & (~1));
12399         orig_conv.is_owned = (orig & 1) || (orig == 0);
12400         LDKTxCreationKeys ret_var = TxCreationKeys_clone(&orig_conv);
12401         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12402         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12403         long ret_ref = (long)ret_var.inner;
12404         if (ret_var.is_owned) {
12405                 ret_ref |= 1;
12406         }
12407         return ret_ref;
12408 }
12409
12410 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_TxCreationKeys_1get_1per_1commitment_1point(JNIEnv * _env, jclass _b, jlong this_ptr) {
12411         LDKTxCreationKeys this_ptr_conv;
12412         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12413         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12414         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
12415         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, TxCreationKeys_get_per_commitment_point(&this_ptr_conv).compressed_form);
12416         return arg_arr;
12417 }
12418
12419 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_TxCreationKeys_1set_1per_1commitment_1point(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
12420         LDKTxCreationKeys this_ptr_conv;
12421         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12422         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12423         LDKPublicKey val_ref;
12424         CHECK((*_env)->GetArrayLength (_env, val) == 33);
12425         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
12426         TxCreationKeys_set_per_commitment_point(&this_ptr_conv, val_ref);
12427 }
12428
12429 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_TxCreationKeys_1get_1revocation_1key(JNIEnv * _env, jclass _b, jlong this_ptr) {
12430         LDKTxCreationKeys this_ptr_conv;
12431         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12432         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12433         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
12434         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, TxCreationKeys_get_revocation_key(&this_ptr_conv).compressed_form);
12435         return arg_arr;
12436 }
12437
12438 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_TxCreationKeys_1set_1revocation_1key(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
12439         LDKTxCreationKeys this_ptr_conv;
12440         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12441         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12442         LDKPublicKey val_ref;
12443         CHECK((*_env)->GetArrayLength (_env, val) == 33);
12444         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
12445         TxCreationKeys_set_revocation_key(&this_ptr_conv, val_ref);
12446 }
12447
12448 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_TxCreationKeys_1get_1broadcaster_1htlc_1key(JNIEnv * _env, jclass _b, jlong this_ptr) {
12449         LDKTxCreationKeys this_ptr_conv;
12450         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12451         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12452         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
12453         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, TxCreationKeys_get_broadcaster_htlc_key(&this_ptr_conv).compressed_form);
12454         return arg_arr;
12455 }
12456
12457 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_TxCreationKeys_1set_1broadcaster_1htlc_1key(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
12458         LDKTxCreationKeys this_ptr_conv;
12459         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12460         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12461         LDKPublicKey val_ref;
12462         CHECK((*_env)->GetArrayLength (_env, val) == 33);
12463         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
12464         TxCreationKeys_set_broadcaster_htlc_key(&this_ptr_conv, val_ref);
12465 }
12466
12467 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_TxCreationKeys_1get_1countersignatory_1htlc_1key(JNIEnv * _env, jclass _b, jlong this_ptr) {
12468         LDKTxCreationKeys this_ptr_conv;
12469         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12470         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12471         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
12472         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, TxCreationKeys_get_countersignatory_htlc_key(&this_ptr_conv).compressed_form);
12473         return arg_arr;
12474 }
12475
12476 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_TxCreationKeys_1set_1countersignatory_1htlc_1key(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
12477         LDKTxCreationKeys this_ptr_conv;
12478         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12479         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12480         LDKPublicKey val_ref;
12481         CHECK((*_env)->GetArrayLength (_env, val) == 33);
12482         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
12483         TxCreationKeys_set_countersignatory_htlc_key(&this_ptr_conv, val_ref);
12484 }
12485
12486 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_TxCreationKeys_1get_1broadcaster_1delayed_1payment_1key(JNIEnv * _env, jclass _b, jlong this_ptr) {
12487         LDKTxCreationKeys this_ptr_conv;
12488         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12489         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12490         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
12491         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, TxCreationKeys_get_broadcaster_delayed_payment_key(&this_ptr_conv).compressed_form);
12492         return arg_arr;
12493 }
12494
12495 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_TxCreationKeys_1set_1broadcaster_1delayed_1payment_1key(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
12496         LDKTxCreationKeys this_ptr_conv;
12497         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12498         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12499         LDKPublicKey val_ref;
12500         CHECK((*_env)->GetArrayLength (_env, val) == 33);
12501         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
12502         TxCreationKeys_set_broadcaster_delayed_payment_key(&this_ptr_conv, val_ref);
12503 }
12504
12505 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) {
12506         LDKPublicKey per_commitment_point_arg_ref;
12507         CHECK((*_env)->GetArrayLength (_env, per_commitment_point_arg) == 33);
12508         (*_env)->GetByteArrayRegion (_env, per_commitment_point_arg, 0, 33, per_commitment_point_arg_ref.compressed_form);
12509         LDKPublicKey revocation_key_arg_ref;
12510         CHECK((*_env)->GetArrayLength (_env, revocation_key_arg) == 33);
12511         (*_env)->GetByteArrayRegion (_env, revocation_key_arg, 0, 33, revocation_key_arg_ref.compressed_form);
12512         LDKPublicKey broadcaster_htlc_key_arg_ref;
12513         CHECK((*_env)->GetArrayLength (_env, broadcaster_htlc_key_arg) == 33);
12514         (*_env)->GetByteArrayRegion (_env, broadcaster_htlc_key_arg, 0, 33, broadcaster_htlc_key_arg_ref.compressed_form);
12515         LDKPublicKey countersignatory_htlc_key_arg_ref;
12516         CHECK((*_env)->GetArrayLength (_env, countersignatory_htlc_key_arg) == 33);
12517         (*_env)->GetByteArrayRegion (_env, countersignatory_htlc_key_arg, 0, 33, countersignatory_htlc_key_arg_ref.compressed_form);
12518         LDKPublicKey broadcaster_delayed_payment_key_arg_ref;
12519         CHECK((*_env)->GetArrayLength (_env, broadcaster_delayed_payment_key_arg) == 33);
12520         (*_env)->GetByteArrayRegion (_env, broadcaster_delayed_payment_key_arg, 0, 33, broadcaster_delayed_payment_key_arg_ref.compressed_form);
12521         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);
12522         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12523         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12524         long ret_ref = (long)ret_var.inner;
12525         if (ret_var.is_owned) {
12526                 ret_ref |= 1;
12527         }
12528         return ret_ref;
12529 }
12530
12531 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_TxCreationKeys_1write(JNIEnv * _env, jclass _b, jlong obj) {
12532         LDKTxCreationKeys obj_conv;
12533         obj_conv.inner = (void*)(obj & (~1));
12534         obj_conv.is_owned = (obj & 1) || (obj == 0);
12535         LDKCVec_u8Z arg_var = TxCreationKeys_write(&obj_conv);
12536         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
12537         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
12538         CVec_u8Z_free(arg_var);
12539         return arg_arr;
12540 }
12541
12542 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_TxCreationKeys_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
12543         LDKu8slice ser_ref;
12544         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
12545         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
12546         LDKTxCreationKeys ret_var = TxCreationKeys_read(ser_ref);
12547         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12548         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12549         long ret_ref = (long)ret_var.inner;
12550         if (ret_var.is_owned) {
12551                 ret_ref |= 1;
12552         }
12553         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
12554         return ret_ref;
12555 }
12556
12557 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_PreCalculatedTxCreationKeys_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
12558         LDKPreCalculatedTxCreationKeys this_ptr_conv;
12559         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12560         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12561         PreCalculatedTxCreationKeys_free(this_ptr_conv);
12562 }
12563
12564 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_PreCalculatedTxCreationKeys_1new(JNIEnv * _env, jclass _b, jlong keys) {
12565         LDKTxCreationKeys keys_conv;
12566         keys_conv.inner = (void*)(keys & (~1));
12567         keys_conv.is_owned = (keys & 1) || (keys == 0);
12568         if (keys_conv.inner != NULL)
12569                 keys_conv = TxCreationKeys_clone(&keys_conv);
12570         LDKPreCalculatedTxCreationKeys ret_var = PreCalculatedTxCreationKeys_new(keys_conv);
12571         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12572         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12573         long ret_ref = (long)ret_var.inner;
12574         if (ret_var.is_owned) {
12575                 ret_ref |= 1;
12576         }
12577         return ret_ref;
12578 }
12579
12580 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_PreCalculatedTxCreationKeys_1trust_1key_1derivation(JNIEnv * _env, jclass _b, jlong this_arg) {
12581         LDKPreCalculatedTxCreationKeys this_arg_conv;
12582         this_arg_conv.inner = (void*)(this_arg & (~1));
12583         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
12584         LDKTxCreationKeys ret_var = PreCalculatedTxCreationKeys_trust_key_derivation(&this_arg_conv);
12585         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12586         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12587         long ret_ref = (long)ret_var.inner;
12588         if (ret_var.is_owned) {
12589                 ret_ref |= 1;
12590         }
12591         return ret_ref;
12592 }
12593
12594 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_PreCalculatedTxCreationKeys_1per_1commitment_1point(JNIEnv * _env, jclass _b, jlong this_arg) {
12595         LDKPreCalculatedTxCreationKeys this_arg_conv;
12596         this_arg_conv.inner = (void*)(this_arg & (~1));
12597         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
12598         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
12599         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, PreCalculatedTxCreationKeys_per_commitment_point(&this_arg_conv).compressed_form);
12600         return arg_arr;
12601 }
12602
12603 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelPublicKeys_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
12604         LDKChannelPublicKeys this_ptr_conv;
12605         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12606         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12607         ChannelPublicKeys_free(this_ptr_conv);
12608 }
12609
12610 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelPublicKeys_1clone(JNIEnv * _env, jclass _b, jlong orig) {
12611         LDKChannelPublicKeys orig_conv;
12612         orig_conv.inner = (void*)(orig & (~1));
12613         orig_conv.is_owned = (orig & 1) || (orig == 0);
12614         LDKChannelPublicKeys ret_var = ChannelPublicKeys_clone(&orig_conv);
12615         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12616         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12617         long ret_ref = (long)ret_var.inner;
12618         if (ret_var.is_owned) {
12619                 ret_ref |= 1;
12620         }
12621         return ret_ref;
12622 }
12623
12624 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelPublicKeys_1get_1funding_1pubkey(JNIEnv * _env, jclass _b, jlong this_ptr) {
12625         LDKChannelPublicKeys this_ptr_conv;
12626         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12627         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12628         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
12629         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, ChannelPublicKeys_get_funding_pubkey(&this_ptr_conv).compressed_form);
12630         return arg_arr;
12631 }
12632
12633 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelPublicKeys_1set_1funding_1pubkey(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
12634         LDKChannelPublicKeys this_ptr_conv;
12635         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12636         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12637         LDKPublicKey val_ref;
12638         CHECK((*_env)->GetArrayLength (_env, val) == 33);
12639         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
12640         ChannelPublicKeys_set_funding_pubkey(&this_ptr_conv, val_ref);
12641 }
12642
12643 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelPublicKeys_1get_1revocation_1basepoint(JNIEnv * _env, jclass _b, jlong this_ptr) {
12644         LDKChannelPublicKeys 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         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
12648         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, ChannelPublicKeys_get_revocation_basepoint(&this_ptr_conv).compressed_form);
12649         return arg_arr;
12650 }
12651
12652 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelPublicKeys_1set_1revocation_1basepoint(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
12653         LDKChannelPublicKeys this_ptr_conv;
12654         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12655         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12656         LDKPublicKey val_ref;
12657         CHECK((*_env)->GetArrayLength (_env, val) == 33);
12658         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
12659         ChannelPublicKeys_set_revocation_basepoint(&this_ptr_conv, val_ref);
12660 }
12661
12662 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelPublicKeys_1get_1payment_1point(JNIEnv * _env, jclass _b, jlong this_ptr) {
12663         LDKChannelPublicKeys this_ptr_conv;
12664         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12665         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12666         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
12667         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, ChannelPublicKeys_get_payment_point(&this_ptr_conv).compressed_form);
12668         return arg_arr;
12669 }
12670
12671 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelPublicKeys_1set_1payment_1point(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
12672         LDKChannelPublicKeys this_ptr_conv;
12673         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12674         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12675         LDKPublicKey val_ref;
12676         CHECK((*_env)->GetArrayLength (_env, val) == 33);
12677         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
12678         ChannelPublicKeys_set_payment_point(&this_ptr_conv, val_ref);
12679 }
12680
12681 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelPublicKeys_1get_1delayed_1payment_1basepoint(JNIEnv * _env, jclass _b, jlong this_ptr) {
12682         LDKChannelPublicKeys this_ptr_conv;
12683         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12684         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12685         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
12686         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, ChannelPublicKeys_get_delayed_payment_basepoint(&this_ptr_conv).compressed_form);
12687         return arg_arr;
12688 }
12689
12690 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelPublicKeys_1set_1delayed_1payment_1basepoint(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
12691         LDKChannelPublicKeys this_ptr_conv;
12692         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12693         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12694         LDKPublicKey val_ref;
12695         CHECK((*_env)->GetArrayLength (_env, val) == 33);
12696         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
12697         ChannelPublicKeys_set_delayed_payment_basepoint(&this_ptr_conv, val_ref);
12698 }
12699
12700 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelPublicKeys_1get_1htlc_1basepoint(JNIEnv * _env, jclass _b, jlong this_ptr) {
12701         LDKChannelPublicKeys this_ptr_conv;
12702         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12703         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12704         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
12705         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, ChannelPublicKeys_get_htlc_basepoint(&this_ptr_conv).compressed_form);
12706         return arg_arr;
12707 }
12708
12709 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelPublicKeys_1set_1htlc_1basepoint(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
12710         LDKChannelPublicKeys this_ptr_conv;
12711         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12712         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12713         LDKPublicKey val_ref;
12714         CHECK((*_env)->GetArrayLength (_env, val) == 33);
12715         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
12716         ChannelPublicKeys_set_htlc_basepoint(&this_ptr_conv, val_ref);
12717 }
12718
12719 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) {
12720         LDKPublicKey funding_pubkey_arg_ref;
12721         CHECK((*_env)->GetArrayLength (_env, funding_pubkey_arg) == 33);
12722         (*_env)->GetByteArrayRegion (_env, funding_pubkey_arg, 0, 33, funding_pubkey_arg_ref.compressed_form);
12723         LDKPublicKey revocation_basepoint_arg_ref;
12724         CHECK((*_env)->GetArrayLength (_env, revocation_basepoint_arg) == 33);
12725         (*_env)->GetByteArrayRegion (_env, revocation_basepoint_arg, 0, 33, revocation_basepoint_arg_ref.compressed_form);
12726         LDKPublicKey payment_point_arg_ref;
12727         CHECK((*_env)->GetArrayLength (_env, payment_point_arg) == 33);
12728         (*_env)->GetByteArrayRegion (_env, payment_point_arg, 0, 33, payment_point_arg_ref.compressed_form);
12729         LDKPublicKey delayed_payment_basepoint_arg_ref;
12730         CHECK((*_env)->GetArrayLength (_env, delayed_payment_basepoint_arg) == 33);
12731         (*_env)->GetByteArrayRegion (_env, delayed_payment_basepoint_arg, 0, 33, delayed_payment_basepoint_arg_ref.compressed_form);
12732         LDKPublicKey htlc_basepoint_arg_ref;
12733         CHECK((*_env)->GetArrayLength (_env, htlc_basepoint_arg) == 33);
12734         (*_env)->GetByteArrayRegion (_env, htlc_basepoint_arg, 0, 33, htlc_basepoint_arg_ref.compressed_form);
12735         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);
12736         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12737         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12738         long ret_ref = (long)ret_var.inner;
12739         if (ret_var.is_owned) {
12740                 ret_ref |= 1;
12741         }
12742         return ret_ref;
12743 }
12744
12745 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelPublicKeys_1write(JNIEnv * _env, jclass _b, jlong obj) {
12746         LDKChannelPublicKeys obj_conv;
12747         obj_conv.inner = (void*)(obj & (~1));
12748         obj_conv.is_owned = (obj & 1) || (obj == 0);
12749         LDKCVec_u8Z arg_var = ChannelPublicKeys_write(&obj_conv);
12750         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
12751         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
12752         CVec_u8Z_free(arg_var);
12753         return arg_arr;
12754 }
12755
12756 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelPublicKeys_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
12757         LDKu8slice ser_ref;
12758         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
12759         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
12760         LDKChannelPublicKeys ret_var = ChannelPublicKeys_read(ser_ref);
12761         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12762         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12763         long ret_ref = (long)ret_var.inner;
12764         if (ret_var.is_owned) {
12765                 ret_ref |= 1;
12766         }
12767         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
12768         return ret_ref;
12769 }
12770
12771 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) {
12772         LDKPublicKey per_commitment_point_ref;
12773         CHECK((*_env)->GetArrayLength (_env, per_commitment_point) == 33);
12774         (*_env)->GetByteArrayRegion (_env, per_commitment_point, 0, 33, per_commitment_point_ref.compressed_form);
12775         LDKPublicKey broadcaster_delayed_payment_base_ref;
12776         CHECK((*_env)->GetArrayLength (_env, broadcaster_delayed_payment_base) == 33);
12777         (*_env)->GetByteArrayRegion (_env, broadcaster_delayed_payment_base, 0, 33, broadcaster_delayed_payment_base_ref.compressed_form);
12778         LDKPublicKey broadcaster_htlc_base_ref;
12779         CHECK((*_env)->GetArrayLength (_env, broadcaster_htlc_base) == 33);
12780         (*_env)->GetByteArrayRegion (_env, broadcaster_htlc_base, 0, 33, broadcaster_htlc_base_ref.compressed_form);
12781         LDKPublicKey countersignatory_revocation_base_ref;
12782         CHECK((*_env)->GetArrayLength (_env, countersignatory_revocation_base) == 33);
12783         (*_env)->GetByteArrayRegion (_env, countersignatory_revocation_base, 0, 33, countersignatory_revocation_base_ref.compressed_form);
12784         LDKPublicKey countersignatory_htlc_base_ref;
12785         CHECK((*_env)->GetArrayLength (_env, countersignatory_htlc_base) == 33);
12786         (*_env)->GetByteArrayRegion (_env, countersignatory_htlc_base, 0, 33, countersignatory_htlc_base_ref.compressed_form);
12787         LDKCResult_TxCreationKeysSecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_TxCreationKeysSecpErrorZ), "LDKCResult_TxCreationKeysSecpErrorZ");
12788         *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);
12789         return (long)ret_conv;
12790 }
12791
12792 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) {
12793         LDKPublicKey revocation_key_ref;
12794         CHECK((*_env)->GetArrayLength (_env, revocation_key) == 33);
12795         (*_env)->GetByteArrayRegion (_env, revocation_key, 0, 33, revocation_key_ref.compressed_form);
12796         LDKPublicKey broadcaster_delayed_payment_key_ref;
12797         CHECK((*_env)->GetArrayLength (_env, broadcaster_delayed_payment_key) == 33);
12798         (*_env)->GetByteArrayRegion (_env, broadcaster_delayed_payment_key, 0, 33, broadcaster_delayed_payment_key_ref.compressed_form);
12799         LDKCVec_u8Z arg_var = get_revokeable_redeemscript(revocation_key_ref, contest_delay, broadcaster_delayed_payment_key_ref);
12800         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
12801         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
12802         CVec_u8Z_free(arg_var);
12803         return arg_arr;
12804 }
12805
12806 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_HTLCOutputInCommitment_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
12807         LDKHTLCOutputInCommitment this_ptr_conv;
12808         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12809         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12810         HTLCOutputInCommitment_free(this_ptr_conv);
12811 }
12812
12813 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_HTLCOutputInCommitment_1clone(JNIEnv * _env, jclass _b, jlong orig) {
12814         LDKHTLCOutputInCommitment orig_conv;
12815         orig_conv.inner = (void*)(orig & (~1));
12816         orig_conv.is_owned = (orig & 1) || (orig == 0);
12817         LDKHTLCOutputInCommitment ret_var = HTLCOutputInCommitment_clone(&orig_conv);
12818         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12819         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12820         long ret_ref = (long)ret_var.inner;
12821         if (ret_var.is_owned) {
12822                 ret_ref |= 1;
12823         }
12824         return ret_ref;
12825 }
12826
12827 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_HTLCOutputInCommitment_1get_1offered(JNIEnv * _env, jclass _b, jlong this_ptr) {
12828         LDKHTLCOutputInCommitment this_ptr_conv;
12829         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12830         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12831         jboolean ret_val = HTLCOutputInCommitment_get_offered(&this_ptr_conv);
12832         return ret_val;
12833 }
12834
12835 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_HTLCOutputInCommitment_1set_1offered(JNIEnv * _env, jclass _b, jlong this_ptr, jboolean val) {
12836         LDKHTLCOutputInCommitment this_ptr_conv;
12837         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12838         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12839         HTLCOutputInCommitment_set_offered(&this_ptr_conv, val);
12840 }
12841
12842 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_HTLCOutputInCommitment_1get_1amount_1msat(JNIEnv * _env, jclass _b, jlong this_ptr) {
12843         LDKHTLCOutputInCommitment this_ptr_conv;
12844         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12845         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12846         jlong ret_val = HTLCOutputInCommitment_get_amount_msat(&this_ptr_conv);
12847         return ret_val;
12848 }
12849
12850 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_HTLCOutputInCommitment_1set_1amount_1msat(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
12851         LDKHTLCOutputInCommitment this_ptr_conv;
12852         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12853         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12854         HTLCOutputInCommitment_set_amount_msat(&this_ptr_conv, val);
12855 }
12856
12857 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_HTLCOutputInCommitment_1get_1cltv_1expiry(JNIEnv * _env, jclass _b, jlong this_ptr) {
12858         LDKHTLCOutputInCommitment 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         jint ret_val = HTLCOutputInCommitment_get_cltv_expiry(&this_ptr_conv);
12862         return ret_val;
12863 }
12864
12865 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_HTLCOutputInCommitment_1set_1cltv_1expiry(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
12866         LDKHTLCOutputInCommitment this_ptr_conv;
12867         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12868         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12869         HTLCOutputInCommitment_set_cltv_expiry(&this_ptr_conv, val);
12870 }
12871
12872 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_HTLCOutputInCommitment_1get_1payment_1hash(JNIEnv * _env, jclass _b, jlong this_ptr) {
12873         LDKHTLCOutputInCommitment this_ptr_conv;
12874         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12875         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12876         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
12877         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *HTLCOutputInCommitment_get_payment_hash(&this_ptr_conv));
12878         return ret_arr;
12879 }
12880
12881 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_HTLCOutputInCommitment_1set_1payment_1hash(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
12882         LDKHTLCOutputInCommitment this_ptr_conv;
12883         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12884         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12885         LDKThirtyTwoBytes val_ref;
12886         CHECK((*_env)->GetArrayLength (_env, val) == 32);
12887         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
12888         HTLCOutputInCommitment_set_payment_hash(&this_ptr_conv, val_ref);
12889 }
12890
12891 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_HTLCOutputInCommitment_1write(JNIEnv * _env, jclass _b, jlong obj) {
12892         LDKHTLCOutputInCommitment obj_conv;
12893         obj_conv.inner = (void*)(obj & (~1));
12894         obj_conv.is_owned = (obj & 1) || (obj == 0);
12895         LDKCVec_u8Z arg_var = HTLCOutputInCommitment_write(&obj_conv);
12896         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
12897         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
12898         CVec_u8Z_free(arg_var);
12899         return arg_arr;
12900 }
12901
12902 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_HTLCOutputInCommitment_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
12903         LDKu8slice ser_ref;
12904         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
12905         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
12906         LDKHTLCOutputInCommitment ret_var = HTLCOutputInCommitment_read(ser_ref);
12907         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12908         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12909         long ret_ref = (long)ret_var.inner;
12910         if (ret_var.is_owned) {
12911                 ret_ref |= 1;
12912         }
12913         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
12914         return ret_ref;
12915 }
12916
12917 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_get_1htlc_1redeemscript(JNIEnv * _env, jclass _b, jlong htlc, jlong keys) {
12918         LDKHTLCOutputInCommitment htlc_conv;
12919         htlc_conv.inner = (void*)(htlc & (~1));
12920         htlc_conv.is_owned = (htlc & 1) || (htlc == 0);
12921         LDKTxCreationKeys keys_conv;
12922         keys_conv.inner = (void*)(keys & (~1));
12923         keys_conv.is_owned = (keys & 1) || (keys == 0);
12924         LDKCVec_u8Z arg_var = get_htlc_redeemscript(&htlc_conv, &keys_conv);
12925         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
12926         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
12927         CVec_u8Z_free(arg_var);
12928         return arg_arr;
12929 }
12930
12931 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_make_1funding_1redeemscript(JNIEnv * _env, jclass _b, jbyteArray broadcaster, jbyteArray countersignatory) {
12932         LDKPublicKey broadcaster_ref;
12933         CHECK((*_env)->GetArrayLength (_env, broadcaster) == 33);
12934         (*_env)->GetByteArrayRegion (_env, broadcaster, 0, 33, broadcaster_ref.compressed_form);
12935         LDKPublicKey countersignatory_ref;
12936         CHECK((*_env)->GetArrayLength (_env, countersignatory) == 33);
12937         (*_env)->GetByteArrayRegion (_env, countersignatory, 0, 33, countersignatory_ref.compressed_form);
12938         LDKCVec_u8Z arg_var = make_funding_redeemscript(broadcaster_ref, countersignatory_ref);
12939         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
12940         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
12941         CVec_u8Z_free(arg_var);
12942         return arg_arr;
12943 }
12944
12945 JNIEXPORT jlong 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) {
12946         unsigned char prev_hash_arr[32];
12947         CHECK((*_env)->GetArrayLength (_env, prev_hash) == 32);
12948         (*_env)->GetByteArrayRegion (_env, prev_hash, 0, 32, prev_hash_arr);
12949         unsigned char (*prev_hash_ref)[32] = &prev_hash_arr;
12950         LDKHTLCOutputInCommitment htlc_conv;
12951         htlc_conv.inner = (void*)(htlc & (~1));
12952         htlc_conv.is_owned = (htlc & 1) || (htlc == 0);
12953         LDKPublicKey broadcaster_delayed_payment_key_ref;
12954         CHECK((*_env)->GetArrayLength (_env, broadcaster_delayed_payment_key) == 33);
12955         (*_env)->GetByteArrayRegion (_env, broadcaster_delayed_payment_key, 0, 33, broadcaster_delayed_payment_key_ref.compressed_form);
12956         LDKPublicKey revocation_key_ref;
12957         CHECK((*_env)->GetArrayLength (_env, revocation_key) == 33);
12958         (*_env)->GetByteArrayRegion (_env, revocation_key, 0, 33, revocation_key_ref.compressed_form);
12959         LDKTransaction *ret_copy = MALLOC(sizeof(LDKTransaction), "LDKTransaction");
12960         *ret_copy = build_htlc_transaction(prev_hash_ref, feerate_per_kw, contest_delay, &htlc_conv, broadcaster_delayed_payment_key_ref, revocation_key_ref);
12961         long ret_ref = (long)ret_copy;
12962         return ret_ref;
12963 }
12964
12965 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_HolderCommitmentTransaction_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
12966         LDKHolderCommitmentTransaction this_ptr_conv;
12967         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12968         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12969         HolderCommitmentTransaction_free(this_ptr_conv);
12970 }
12971
12972 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_HolderCommitmentTransaction_1clone(JNIEnv * _env, jclass _b, jlong orig) {
12973         LDKHolderCommitmentTransaction orig_conv;
12974         orig_conv.inner = (void*)(orig & (~1));
12975         orig_conv.is_owned = (orig & 1) || (orig == 0);
12976         LDKHolderCommitmentTransaction ret_var = HolderCommitmentTransaction_clone(&orig_conv);
12977         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12978         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12979         long ret_ref = (long)ret_var.inner;
12980         if (ret_var.is_owned) {
12981                 ret_ref |= 1;
12982         }
12983         return ret_ref;
12984 }
12985
12986 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_HolderCommitmentTransaction_1get_1unsigned_1tx(JNIEnv * _env, jclass _b, jlong this_ptr) {
12987         LDKHolderCommitmentTransaction this_ptr_conv;
12988         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12989         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12990         LDKTransaction *ret_copy = MALLOC(sizeof(LDKTransaction), "LDKTransaction");
12991         *ret_copy = HolderCommitmentTransaction_get_unsigned_tx(&this_ptr_conv);
12992         long ret_ref = (long)ret_copy;
12993         return ret_ref;
12994 }
12995
12996 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_HolderCommitmentTransaction_1set_1unsigned_1tx(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
12997         LDKHolderCommitmentTransaction this_ptr_conv;
12998         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12999         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13000         LDKTransaction val_conv = *(LDKTransaction*)val;
13001         HolderCommitmentTransaction_set_unsigned_tx(&this_ptr_conv, val_conv);
13002 }
13003
13004 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_HolderCommitmentTransaction_1get_1counterparty_1sig(JNIEnv * _env, jclass _b, jlong this_ptr) {
13005         LDKHolderCommitmentTransaction this_ptr_conv;
13006         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13007         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13008         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 64);
13009         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 64, HolderCommitmentTransaction_get_counterparty_sig(&this_ptr_conv).compact_form);
13010         return arg_arr;
13011 }
13012
13013 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_HolderCommitmentTransaction_1set_1counterparty_1sig(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
13014         LDKHolderCommitmentTransaction this_ptr_conv;
13015         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13016         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13017         LDKSignature val_ref;
13018         CHECK((*_env)->GetArrayLength (_env, val) == 64);
13019         (*_env)->GetByteArrayRegion (_env, val, 0, 64, val_ref.compact_form);
13020         HolderCommitmentTransaction_set_counterparty_sig(&this_ptr_conv, val_ref);
13021 }
13022
13023 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_HolderCommitmentTransaction_1get_1feerate_1per_1kw(JNIEnv * _env, jclass _b, jlong this_ptr) {
13024         LDKHolderCommitmentTransaction this_ptr_conv;
13025         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13026         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13027         jint ret_val = HolderCommitmentTransaction_get_feerate_per_kw(&this_ptr_conv);
13028         return ret_val;
13029 }
13030
13031 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_HolderCommitmentTransaction_1set_1feerate_1per_1kw(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
13032         LDKHolderCommitmentTransaction this_ptr_conv;
13033         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13034         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13035         HolderCommitmentTransaction_set_feerate_per_kw(&this_ptr_conv, val);
13036 }
13037
13038 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_HolderCommitmentTransaction_1set_1per_1htlc(JNIEnv * _env, jclass _b, jlong this_ptr, jlongArray val) {
13039         LDKHolderCommitmentTransaction this_ptr_conv;
13040         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13041         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13042         LDKCVec_C2Tuple_HTLCOutputInCommitmentSignatureZZ val_constr;
13043         val_constr.datalen = (*_env)->GetArrayLength (_env, val);
13044         if (val_constr.datalen > 0)
13045                 val_constr.data = MALLOC(val_constr.datalen * sizeof(LDKC2Tuple_HTLCOutputInCommitmentSignatureZ), "LDKCVec_C2Tuple_HTLCOutputInCommitmentSignatureZZ Elements");
13046         else
13047                 val_constr.data = NULL;
13048         long* val_vals = (*_env)->GetLongArrayElements (_env, val, NULL);
13049         for (size_t q = 0; q < val_constr.datalen; q++) {
13050                 long arr_conv_42 = val_vals[q];
13051                 LDKC2Tuple_HTLCOutputInCommitmentSignatureZ arr_conv_42_conv = *(LDKC2Tuple_HTLCOutputInCommitmentSignatureZ*)arr_conv_42;
13052                 FREE((void*)arr_conv_42);
13053                 val_constr.data[q] = arr_conv_42_conv;
13054         }
13055         (*_env)->ReleaseLongArrayElements (_env, val, val_vals, 0);
13056         HolderCommitmentTransaction_set_per_htlc(&this_ptr_conv, val_constr);
13057 }
13058
13059 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_HolderCommitmentTransaction_1new_1missing_1holder_1sig(JNIEnv * _env, jclass _b, jlong unsigned_tx, jbyteArray counterparty_sig, jbyteArray holder_funding_key, jbyteArray counterparty_funding_key, jlong keys, jint feerate_per_kw, jlongArray htlc_data) {
13060         LDKTransaction unsigned_tx_conv = *(LDKTransaction*)unsigned_tx;
13061         LDKSignature counterparty_sig_ref;
13062         CHECK((*_env)->GetArrayLength (_env, counterparty_sig) == 64);
13063         (*_env)->GetByteArrayRegion (_env, counterparty_sig, 0, 64, counterparty_sig_ref.compact_form);
13064         LDKPublicKey holder_funding_key_ref;
13065         CHECK((*_env)->GetArrayLength (_env, holder_funding_key) == 33);
13066         (*_env)->GetByteArrayRegion (_env, holder_funding_key, 0, 33, holder_funding_key_ref.compressed_form);
13067         LDKPublicKey counterparty_funding_key_ref;
13068         CHECK((*_env)->GetArrayLength (_env, counterparty_funding_key) == 33);
13069         (*_env)->GetByteArrayRegion (_env, counterparty_funding_key, 0, 33, counterparty_funding_key_ref.compressed_form);
13070         LDKTxCreationKeys keys_conv;
13071         keys_conv.inner = (void*)(keys & (~1));
13072         keys_conv.is_owned = (keys & 1) || (keys == 0);
13073         if (keys_conv.inner != NULL)
13074                 keys_conv = TxCreationKeys_clone(&keys_conv);
13075         LDKCVec_C2Tuple_HTLCOutputInCommitmentSignatureZZ htlc_data_constr;
13076         htlc_data_constr.datalen = (*_env)->GetArrayLength (_env, htlc_data);
13077         if (htlc_data_constr.datalen > 0)
13078                 htlc_data_constr.data = MALLOC(htlc_data_constr.datalen * sizeof(LDKC2Tuple_HTLCOutputInCommitmentSignatureZ), "LDKCVec_C2Tuple_HTLCOutputInCommitmentSignatureZZ Elements");
13079         else
13080                 htlc_data_constr.data = NULL;
13081         long* htlc_data_vals = (*_env)->GetLongArrayElements (_env, htlc_data, NULL);
13082         for (size_t q = 0; q < htlc_data_constr.datalen; q++) {
13083                 long arr_conv_42 = htlc_data_vals[q];
13084                 LDKC2Tuple_HTLCOutputInCommitmentSignatureZ arr_conv_42_conv = *(LDKC2Tuple_HTLCOutputInCommitmentSignatureZ*)arr_conv_42;
13085                 FREE((void*)arr_conv_42);
13086                 htlc_data_constr.data[q] = arr_conv_42_conv;
13087         }
13088         (*_env)->ReleaseLongArrayElements (_env, htlc_data, htlc_data_vals, 0);
13089         LDKHolderCommitmentTransaction ret_var = HolderCommitmentTransaction_new_missing_holder_sig(unsigned_tx_conv, counterparty_sig_ref, holder_funding_key_ref, counterparty_funding_key_ref, keys_conv, feerate_per_kw, htlc_data_constr);
13090         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13091         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13092         long ret_ref = (long)ret_var.inner;
13093         if (ret_var.is_owned) {
13094                 ret_ref |= 1;
13095         }
13096         return ret_ref;
13097 }
13098
13099 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_HolderCommitmentTransaction_1trust_1key_1derivation(JNIEnv * _env, jclass _b, jlong this_arg) {
13100         LDKHolderCommitmentTransaction this_arg_conv;
13101         this_arg_conv.inner = (void*)(this_arg & (~1));
13102         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
13103         LDKTxCreationKeys ret_var = HolderCommitmentTransaction_trust_key_derivation(&this_arg_conv);
13104         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13105         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13106         long ret_ref = (long)ret_var.inner;
13107         if (ret_var.is_owned) {
13108                 ret_ref |= 1;
13109         }
13110         return ret_ref;
13111 }
13112
13113 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_HolderCommitmentTransaction_1txid(JNIEnv * _env, jclass _b, jlong this_arg) {
13114         LDKHolderCommitmentTransaction this_arg_conv;
13115         this_arg_conv.inner = (void*)(this_arg & (~1));
13116         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
13117         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 32);
13118         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 32, HolderCommitmentTransaction_txid(&this_arg_conv).data);
13119         return arg_arr;
13120 }
13121
13122 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_HolderCommitmentTransaction_1get_1holder_1sig(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray funding_key, jbyteArray funding_redeemscript, jlong channel_value_satoshis) {
13123         LDKHolderCommitmentTransaction this_arg_conv;
13124         this_arg_conv.inner = (void*)(this_arg & (~1));
13125         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
13126         unsigned char funding_key_arr[32];
13127         CHECK((*_env)->GetArrayLength (_env, funding_key) == 32);
13128         (*_env)->GetByteArrayRegion (_env, funding_key, 0, 32, funding_key_arr);
13129         unsigned char (*funding_key_ref)[32] = &funding_key_arr;
13130         LDKu8slice funding_redeemscript_ref;
13131         funding_redeemscript_ref.data = (*_env)->GetByteArrayElements (_env, funding_redeemscript, NULL);
13132         funding_redeemscript_ref.datalen = (*_env)->GetArrayLength (_env, funding_redeemscript);
13133         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 64);
13134         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 64, HolderCommitmentTransaction_get_holder_sig(&this_arg_conv, funding_key_ref, funding_redeemscript_ref, channel_value_satoshis).compact_form);
13135         (*_env)->ReleaseByteArrayElements(_env, funding_redeemscript, (int8_t*)funding_redeemscript_ref.data, 0);
13136         return arg_arr;
13137 }
13138
13139 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_HolderCommitmentTransaction_1get_1htlc_1sigs(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray htlc_base_key, jshort counterparty_selected_contest_delay) {
13140         LDKHolderCommitmentTransaction this_arg_conv;
13141         this_arg_conv.inner = (void*)(this_arg & (~1));
13142         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
13143         unsigned char htlc_base_key_arr[32];
13144         CHECK((*_env)->GetArrayLength (_env, htlc_base_key) == 32);
13145         (*_env)->GetByteArrayRegion (_env, htlc_base_key, 0, 32, htlc_base_key_arr);
13146         unsigned char (*htlc_base_key_ref)[32] = &htlc_base_key_arr;
13147         LDKCResult_CVec_SignatureZNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_CVec_SignatureZNoneZ), "LDKCResult_CVec_SignatureZNoneZ");
13148         *ret_conv = HolderCommitmentTransaction_get_htlc_sigs(&this_arg_conv, htlc_base_key_ref, counterparty_selected_contest_delay);
13149         return (long)ret_conv;
13150 }
13151
13152 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_HolderCommitmentTransaction_1write(JNIEnv * _env, jclass _b, jlong obj) {
13153         LDKHolderCommitmentTransaction obj_conv;
13154         obj_conv.inner = (void*)(obj & (~1));
13155         obj_conv.is_owned = (obj & 1) || (obj == 0);
13156         LDKCVec_u8Z arg_var = HolderCommitmentTransaction_write(&obj_conv);
13157         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
13158         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
13159         CVec_u8Z_free(arg_var);
13160         return arg_arr;
13161 }
13162
13163 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_HolderCommitmentTransaction_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
13164         LDKu8slice ser_ref;
13165         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
13166         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
13167         LDKHolderCommitmentTransaction ret_var = HolderCommitmentTransaction_read(ser_ref);
13168         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13169         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13170         long ret_ref = (long)ret_var.inner;
13171         if (ret_var.is_owned) {
13172                 ret_ref |= 1;
13173         }
13174         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
13175         return ret_ref;
13176 }
13177
13178 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_InitFeatures_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
13179         LDKInitFeatures this_ptr_conv;
13180         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13181         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13182         InitFeatures_free(this_ptr_conv);
13183 }
13184
13185 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NodeFeatures_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
13186         LDKNodeFeatures this_ptr_conv;
13187         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13188         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13189         NodeFeatures_free(this_ptr_conv);
13190 }
13191
13192 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelFeatures_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
13193         LDKChannelFeatures this_ptr_conv;
13194         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13195         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13196         ChannelFeatures_free(this_ptr_conv);
13197 }
13198
13199 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RouteHop_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
13200         LDKRouteHop this_ptr_conv;
13201         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13202         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13203         RouteHop_free(this_ptr_conv);
13204 }
13205
13206 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_RouteHop_1clone(JNIEnv * _env, jclass _b, jlong orig) {
13207         LDKRouteHop orig_conv;
13208         orig_conv.inner = (void*)(orig & (~1));
13209         orig_conv.is_owned = (orig & 1) || (orig == 0);
13210         LDKRouteHop ret_var = RouteHop_clone(&orig_conv);
13211         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13212         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13213         long ret_ref = (long)ret_var.inner;
13214         if (ret_var.is_owned) {
13215                 ret_ref |= 1;
13216         }
13217         return ret_ref;
13218 }
13219
13220 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_RouteHop_1get_1pubkey(JNIEnv * _env, jclass _b, jlong this_ptr) {
13221         LDKRouteHop this_ptr_conv;
13222         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13223         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13224         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
13225         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, RouteHop_get_pubkey(&this_ptr_conv).compressed_form);
13226         return arg_arr;
13227 }
13228
13229 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RouteHop_1set_1pubkey(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
13230         LDKRouteHop this_ptr_conv;
13231         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13232         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13233         LDKPublicKey val_ref;
13234         CHECK((*_env)->GetArrayLength (_env, val) == 33);
13235         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
13236         RouteHop_set_pubkey(&this_ptr_conv, val_ref);
13237 }
13238
13239 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_RouteHop_1get_1node_1features(JNIEnv * _env, jclass _b, jlong this_ptr) {
13240         LDKRouteHop this_ptr_conv;
13241         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13242         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13243         LDKNodeFeatures ret_var = RouteHop_get_node_features(&this_ptr_conv);
13244         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13245         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13246         long ret_ref = (long)ret_var.inner;
13247         if (ret_var.is_owned) {
13248                 ret_ref |= 1;
13249         }
13250         return ret_ref;
13251 }
13252
13253 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RouteHop_1set_1node_1features(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
13254         LDKRouteHop this_ptr_conv;
13255         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13256         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13257         LDKNodeFeatures val_conv;
13258         val_conv.inner = (void*)(val & (~1));
13259         val_conv.is_owned = (val & 1) || (val == 0);
13260         // Warning: we may need a move here but can't clone!
13261         RouteHop_set_node_features(&this_ptr_conv, val_conv);
13262 }
13263
13264 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_RouteHop_1get_1short_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
13265         LDKRouteHop this_ptr_conv;
13266         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13267         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13268         jlong ret_val = RouteHop_get_short_channel_id(&this_ptr_conv);
13269         return ret_val;
13270 }
13271
13272 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RouteHop_1set_1short_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
13273         LDKRouteHop this_ptr_conv;
13274         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13275         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13276         RouteHop_set_short_channel_id(&this_ptr_conv, val);
13277 }
13278
13279 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_RouteHop_1get_1channel_1features(JNIEnv * _env, jclass _b, jlong this_ptr) {
13280         LDKRouteHop this_ptr_conv;
13281         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13282         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13283         LDKChannelFeatures ret_var = RouteHop_get_channel_features(&this_ptr_conv);
13284         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13285         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13286         long ret_ref = (long)ret_var.inner;
13287         if (ret_var.is_owned) {
13288                 ret_ref |= 1;
13289         }
13290         return ret_ref;
13291 }
13292
13293 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RouteHop_1set_1channel_1features(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
13294         LDKRouteHop this_ptr_conv;
13295         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13296         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13297         LDKChannelFeatures val_conv;
13298         val_conv.inner = (void*)(val & (~1));
13299         val_conv.is_owned = (val & 1) || (val == 0);
13300         // Warning: we may need a move here but can't clone!
13301         RouteHop_set_channel_features(&this_ptr_conv, val_conv);
13302 }
13303
13304 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_RouteHop_1get_1fee_1msat(JNIEnv * _env, jclass _b, jlong this_ptr) {
13305         LDKRouteHop this_ptr_conv;
13306         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13307         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13308         jlong ret_val = RouteHop_get_fee_msat(&this_ptr_conv);
13309         return ret_val;
13310 }
13311
13312 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RouteHop_1set_1fee_1msat(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
13313         LDKRouteHop this_ptr_conv;
13314         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13315         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13316         RouteHop_set_fee_msat(&this_ptr_conv, val);
13317 }
13318
13319 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_RouteHop_1get_1cltv_1expiry_1delta(JNIEnv * _env, jclass _b, jlong this_ptr) {
13320         LDKRouteHop this_ptr_conv;
13321         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13322         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13323         jint ret_val = RouteHop_get_cltv_expiry_delta(&this_ptr_conv);
13324         return ret_val;
13325 }
13326
13327 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RouteHop_1set_1cltv_1expiry_1delta(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
13328         LDKRouteHop this_ptr_conv;
13329         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13330         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13331         RouteHop_set_cltv_expiry_delta(&this_ptr_conv, val);
13332 }
13333
13334 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) {
13335         LDKPublicKey pubkey_arg_ref;
13336         CHECK((*_env)->GetArrayLength (_env, pubkey_arg) == 33);
13337         (*_env)->GetByteArrayRegion (_env, pubkey_arg, 0, 33, pubkey_arg_ref.compressed_form);
13338         LDKNodeFeatures node_features_arg_conv;
13339         node_features_arg_conv.inner = (void*)(node_features_arg & (~1));
13340         node_features_arg_conv.is_owned = (node_features_arg & 1) || (node_features_arg == 0);
13341         // Warning: we may need a move here but can't clone!
13342         LDKChannelFeatures channel_features_arg_conv;
13343         channel_features_arg_conv.inner = (void*)(channel_features_arg & (~1));
13344         channel_features_arg_conv.is_owned = (channel_features_arg & 1) || (channel_features_arg == 0);
13345         // Warning: we may need a move here but can't clone!
13346         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);
13347         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13348         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13349         long ret_ref = (long)ret_var.inner;
13350         if (ret_var.is_owned) {
13351                 ret_ref |= 1;
13352         }
13353         return ret_ref;
13354 }
13355
13356 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Route_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
13357         LDKRoute this_ptr_conv;
13358         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13359         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13360         Route_free(this_ptr_conv);
13361 }
13362
13363 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_Route_1clone(JNIEnv * _env, jclass _b, jlong orig) {
13364         LDKRoute orig_conv;
13365         orig_conv.inner = (void*)(orig & (~1));
13366         orig_conv.is_owned = (orig & 1) || (orig == 0);
13367         LDKRoute ret_var = Route_clone(&orig_conv);
13368         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13369         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13370         long ret_ref = (long)ret_var.inner;
13371         if (ret_var.is_owned) {
13372                 ret_ref |= 1;
13373         }
13374         return ret_ref;
13375 }
13376
13377 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Route_1set_1paths(JNIEnv * _env, jclass _b, jlong this_ptr, jobjectArray val) {
13378         LDKRoute this_ptr_conv;
13379         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13380         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13381         LDKCVec_CVec_RouteHopZZ val_constr;
13382         val_constr.datalen = (*_env)->GetArrayLength (_env, val);
13383         if (val_constr.datalen > 0)
13384                 val_constr.data = MALLOC(val_constr.datalen * sizeof(LDKCVec_RouteHopZ), "LDKCVec_CVec_RouteHopZZ Elements");
13385         else
13386                 val_constr.data = NULL;
13387         for (size_t m = 0; m < val_constr.datalen; m++) {
13388                 jobject arr_conv_12 = (*_env)->GetObjectArrayElement(_env, val, m);
13389                 LDKCVec_RouteHopZ arr_conv_12_constr;
13390                 arr_conv_12_constr.datalen = (*_env)->GetArrayLength (_env, arr_conv_12);
13391                 if (arr_conv_12_constr.datalen > 0)
13392                         arr_conv_12_constr.data = MALLOC(arr_conv_12_constr.datalen * sizeof(LDKRouteHop), "LDKCVec_RouteHopZ Elements");
13393                 else
13394                         arr_conv_12_constr.data = NULL;
13395                 long* arr_conv_12_vals = (*_env)->GetLongArrayElements (_env, arr_conv_12, NULL);
13396                 for (size_t k = 0; k < arr_conv_12_constr.datalen; k++) {
13397                         long arr_conv_10 = arr_conv_12_vals[k];
13398                         LDKRouteHop arr_conv_10_conv;
13399                         arr_conv_10_conv.inner = (void*)(arr_conv_10 & (~1));
13400                         arr_conv_10_conv.is_owned = (arr_conv_10 & 1) || (arr_conv_10 == 0);
13401                         if (arr_conv_10_conv.inner != NULL)
13402                                 arr_conv_10_conv = RouteHop_clone(&arr_conv_10_conv);
13403                         arr_conv_12_constr.data[k] = arr_conv_10_conv;
13404                 }
13405                 (*_env)->ReleaseLongArrayElements (_env, arr_conv_12, arr_conv_12_vals, 0);
13406                 val_constr.data[m] = arr_conv_12_constr;
13407         }
13408         Route_set_paths(&this_ptr_conv, val_constr);
13409 }
13410
13411 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_Route_1new(JNIEnv * _env, jclass _b, jobjectArray paths_arg) {
13412         LDKCVec_CVec_RouteHopZZ paths_arg_constr;
13413         paths_arg_constr.datalen = (*_env)->GetArrayLength (_env, paths_arg);
13414         if (paths_arg_constr.datalen > 0)
13415                 paths_arg_constr.data = MALLOC(paths_arg_constr.datalen * sizeof(LDKCVec_RouteHopZ), "LDKCVec_CVec_RouteHopZZ Elements");
13416         else
13417                 paths_arg_constr.data = NULL;
13418         for (size_t m = 0; m < paths_arg_constr.datalen; m++) {
13419                 jobject arr_conv_12 = (*_env)->GetObjectArrayElement(_env, paths_arg, m);
13420                 LDKCVec_RouteHopZ arr_conv_12_constr;
13421                 arr_conv_12_constr.datalen = (*_env)->GetArrayLength (_env, arr_conv_12);
13422                 if (arr_conv_12_constr.datalen > 0)
13423                         arr_conv_12_constr.data = MALLOC(arr_conv_12_constr.datalen * sizeof(LDKRouteHop), "LDKCVec_RouteHopZ Elements");
13424                 else
13425                         arr_conv_12_constr.data = NULL;
13426                 long* arr_conv_12_vals = (*_env)->GetLongArrayElements (_env, arr_conv_12, NULL);
13427                 for (size_t k = 0; k < arr_conv_12_constr.datalen; k++) {
13428                         long arr_conv_10 = arr_conv_12_vals[k];
13429                         LDKRouteHop arr_conv_10_conv;
13430                         arr_conv_10_conv.inner = (void*)(arr_conv_10 & (~1));
13431                         arr_conv_10_conv.is_owned = (arr_conv_10 & 1) || (arr_conv_10 == 0);
13432                         if (arr_conv_10_conv.inner != NULL)
13433                                 arr_conv_10_conv = RouteHop_clone(&arr_conv_10_conv);
13434                         arr_conv_12_constr.data[k] = arr_conv_10_conv;
13435                 }
13436                 (*_env)->ReleaseLongArrayElements (_env, arr_conv_12, arr_conv_12_vals, 0);
13437                 paths_arg_constr.data[m] = arr_conv_12_constr;
13438         }
13439         LDKRoute ret_var = Route_new(paths_arg_constr);
13440         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13441         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13442         long ret_ref = (long)ret_var.inner;
13443         if (ret_var.is_owned) {
13444                 ret_ref |= 1;
13445         }
13446         return ret_ref;
13447 }
13448
13449 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_Route_1write(JNIEnv * _env, jclass _b, jlong obj) {
13450         LDKRoute obj_conv;
13451         obj_conv.inner = (void*)(obj & (~1));
13452         obj_conv.is_owned = (obj & 1) || (obj == 0);
13453         LDKCVec_u8Z arg_var = Route_write(&obj_conv);
13454         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
13455         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
13456         CVec_u8Z_free(arg_var);
13457         return arg_arr;
13458 }
13459
13460 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_Route_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
13461         LDKu8slice ser_ref;
13462         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
13463         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
13464         LDKRoute ret_var = Route_read(ser_ref);
13465         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13466         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13467         long ret_ref = (long)ret_var.inner;
13468         if (ret_var.is_owned) {
13469                 ret_ref |= 1;
13470         }
13471         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
13472         return ret_ref;
13473 }
13474
13475 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RouteHint_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
13476         LDKRouteHint this_ptr_conv;
13477         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13478         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13479         RouteHint_free(this_ptr_conv);
13480 }
13481
13482 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_RouteHint_1clone(JNIEnv * _env, jclass _b, jlong orig) {
13483         LDKRouteHint orig_conv;
13484         orig_conv.inner = (void*)(orig & (~1));
13485         orig_conv.is_owned = (orig & 1) || (orig == 0);
13486         LDKRouteHint ret_var = RouteHint_clone(&orig_conv);
13487         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13488         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13489         long ret_ref = (long)ret_var.inner;
13490         if (ret_var.is_owned) {
13491                 ret_ref |= 1;
13492         }
13493         return ret_ref;
13494 }
13495
13496 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_RouteHint_1get_1src_1node_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
13497         LDKRouteHint this_ptr_conv;
13498         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13499         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13500         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
13501         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, RouteHint_get_src_node_id(&this_ptr_conv).compressed_form);
13502         return arg_arr;
13503 }
13504
13505 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RouteHint_1set_1src_1node_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
13506         LDKRouteHint this_ptr_conv;
13507         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13508         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13509         LDKPublicKey val_ref;
13510         CHECK((*_env)->GetArrayLength (_env, val) == 33);
13511         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
13512         RouteHint_set_src_node_id(&this_ptr_conv, val_ref);
13513 }
13514
13515 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_RouteHint_1get_1short_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
13516         LDKRouteHint this_ptr_conv;
13517         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13518         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13519         jlong ret_val = RouteHint_get_short_channel_id(&this_ptr_conv);
13520         return ret_val;
13521 }
13522
13523 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RouteHint_1set_1short_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
13524         LDKRouteHint this_ptr_conv;
13525         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13526         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13527         RouteHint_set_short_channel_id(&this_ptr_conv, val);
13528 }
13529
13530 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_RouteHint_1get_1fees(JNIEnv * _env, jclass _b, jlong this_ptr) {
13531         LDKRouteHint this_ptr_conv;
13532         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13533         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13534         LDKRoutingFees ret_var = RouteHint_get_fees(&this_ptr_conv);
13535         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13536         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13537         long ret_ref = (long)ret_var.inner;
13538         if (ret_var.is_owned) {
13539                 ret_ref |= 1;
13540         }
13541         return ret_ref;
13542 }
13543
13544 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RouteHint_1set_1fees(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
13545         LDKRouteHint this_ptr_conv;
13546         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13547         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13548         LDKRoutingFees val_conv;
13549         val_conv.inner = (void*)(val & (~1));
13550         val_conv.is_owned = (val & 1) || (val == 0);
13551         if (val_conv.inner != NULL)
13552                 val_conv = RoutingFees_clone(&val_conv);
13553         RouteHint_set_fees(&this_ptr_conv, val_conv);
13554 }
13555
13556 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_RouteHint_1get_1cltv_1expiry_1delta(JNIEnv * _env, jclass _b, jlong this_ptr) {
13557         LDKRouteHint this_ptr_conv;
13558         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13559         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13560         jshort ret_val = RouteHint_get_cltv_expiry_delta(&this_ptr_conv);
13561         return ret_val;
13562 }
13563
13564 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RouteHint_1set_1cltv_1expiry_1delta(JNIEnv * _env, jclass _b, jlong this_ptr, jshort val) {
13565         LDKRouteHint this_ptr_conv;
13566         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13567         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13568         RouteHint_set_cltv_expiry_delta(&this_ptr_conv, val);
13569 }
13570
13571 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_RouteHint_1get_1htlc_1minimum_1msat(JNIEnv * _env, jclass _b, jlong this_ptr) {
13572         LDKRouteHint this_ptr_conv;
13573         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13574         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13575         jlong ret_val = RouteHint_get_htlc_minimum_msat(&this_ptr_conv);
13576         return ret_val;
13577 }
13578
13579 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RouteHint_1set_1htlc_1minimum_1msat(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
13580         LDKRouteHint this_ptr_conv;
13581         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13582         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13583         RouteHint_set_htlc_minimum_msat(&this_ptr_conv, val);
13584 }
13585
13586 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) {
13587         LDKPublicKey src_node_id_arg_ref;
13588         CHECK((*_env)->GetArrayLength (_env, src_node_id_arg) == 33);
13589         (*_env)->GetByteArrayRegion (_env, src_node_id_arg, 0, 33, src_node_id_arg_ref.compressed_form);
13590         LDKRoutingFees fees_arg_conv;
13591         fees_arg_conv.inner = (void*)(fees_arg & (~1));
13592         fees_arg_conv.is_owned = (fees_arg & 1) || (fees_arg == 0);
13593         if (fees_arg_conv.inner != NULL)
13594                 fees_arg_conv = RoutingFees_clone(&fees_arg_conv);
13595         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);
13596         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13597         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13598         long ret_ref = (long)ret_var.inner;
13599         if (ret_var.is_owned) {
13600                 ret_ref |= 1;
13601         }
13602         return ret_ref;
13603 }
13604
13605 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) {
13606         LDKPublicKey our_node_id_ref;
13607         CHECK((*_env)->GetArrayLength (_env, our_node_id) == 33);
13608         (*_env)->GetByteArrayRegion (_env, our_node_id, 0, 33, our_node_id_ref.compressed_form);
13609         LDKNetworkGraph network_conv;
13610         network_conv.inner = (void*)(network & (~1));
13611         network_conv.is_owned = (network & 1) || (network == 0);
13612         LDKPublicKey target_ref;
13613         CHECK((*_env)->GetArrayLength (_env, target) == 33);
13614         (*_env)->GetByteArrayRegion (_env, target, 0, 33, target_ref.compressed_form);
13615         LDKCVec_ChannelDetailsZ first_hops_constr;
13616         first_hops_constr.datalen = (*_env)->GetArrayLength (_env, first_hops);
13617         if (first_hops_constr.datalen > 0)
13618                 first_hops_constr.data = MALLOC(first_hops_constr.datalen * sizeof(LDKChannelDetails), "LDKCVec_ChannelDetailsZ Elements");
13619         else
13620                 first_hops_constr.data = NULL;
13621         long* first_hops_vals = (*_env)->GetLongArrayElements (_env, first_hops, NULL);
13622         for (size_t q = 0; q < first_hops_constr.datalen; q++) {
13623                 long arr_conv_16 = first_hops_vals[q];
13624                 LDKChannelDetails arr_conv_16_conv;
13625                 arr_conv_16_conv.inner = (void*)(arr_conv_16 & (~1));
13626                 arr_conv_16_conv.is_owned = (arr_conv_16 & 1) || (arr_conv_16 == 0);
13627                 first_hops_constr.data[q] = arr_conv_16_conv;
13628         }
13629         (*_env)->ReleaseLongArrayElements (_env, first_hops, first_hops_vals, 0);
13630         LDKCVec_RouteHintZ last_hops_constr;
13631         last_hops_constr.datalen = (*_env)->GetArrayLength (_env, last_hops);
13632         if (last_hops_constr.datalen > 0)
13633                 last_hops_constr.data = MALLOC(last_hops_constr.datalen * sizeof(LDKRouteHint), "LDKCVec_RouteHintZ Elements");
13634         else
13635                 last_hops_constr.data = NULL;
13636         long* last_hops_vals = (*_env)->GetLongArrayElements (_env, last_hops, NULL);
13637         for (size_t l = 0; l < last_hops_constr.datalen; l++) {
13638                 long arr_conv_11 = last_hops_vals[l];
13639                 LDKRouteHint arr_conv_11_conv;
13640                 arr_conv_11_conv.inner = (void*)(arr_conv_11 & (~1));
13641                 arr_conv_11_conv.is_owned = (arr_conv_11 & 1) || (arr_conv_11 == 0);
13642                 if (arr_conv_11_conv.inner != NULL)
13643                         arr_conv_11_conv = RouteHint_clone(&arr_conv_11_conv);
13644                 last_hops_constr.data[l] = arr_conv_11_conv;
13645         }
13646         (*_env)->ReleaseLongArrayElements (_env, last_hops, last_hops_vals, 0);
13647         LDKLogger logger_conv = *(LDKLogger*)logger;
13648         if (logger_conv.free == LDKLogger_JCalls_free) {
13649                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
13650                 LDKLogger_JCalls_clone(logger_conv.this_arg);
13651         }
13652         LDKCResult_RouteLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_RouteLightningErrorZ), "LDKCResult_RouteLightningErrorZ");
13653         *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);
13654         FREE(first_hops_constr.data);
13655         return (long)ret_conv;
13656 }
13657
13658 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NetworkGraph_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
13659         LDKNetworkGraph this_ptr_conv;
13660         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13661         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13662         NetworkGraph_free(this_ptr_conv);
13663 }
13664
13665 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_LockedNetworkGraph_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
13666         LDKLockedNetworkGraph this_ptr_conv;
13667         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13668         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13669         LockedNetworkGraph_free(this_ptr_conv);
13670 }
13671
13672 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NetGraphMsgHandler_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
13673         LDKNetGraphMsgHandler this_ptr_conv;
13674         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13675         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13676         NetGraphMsgHandler_free(this_ptr_conv);
13677 }
13678
13679 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_NetGraphMsgHandler_1new(JNIEnv * _env, jclass _b, jlong chain_access, jlong logger) {
13680         LDKAccess* chain_access_conv = (LDKAccess*)chain_access;
13681         LDKLogger logger_conv = *(LDKLogger*)logger;
13682         if (logger_conv.free == LDKLogger_JCalls_free) {
13683                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
13684                 LDKLogger_JCalls_clone(logger_conv.this_arg);
13685         }
13686         LDKNetGraphMsgHandler ret_var = NetGraphMsgHandler_new(chain_access_conv, logger_conv);
13687         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13688         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13689         long ret_ref = (long)ret_var.inner;
13690         if (ret_var.is_owned) {
13691                 ret_ref |= 1;
13692         }
13693         return ret_ref;
13694 }
13695
13696 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_NetGraphMsgHandler_1from_1net_1graph(JNIEnv * _env, jclass _b, jlong chain_access, jlong logger, jlong network_graph) {
13697         LDKAccess* chain_access_conv = (LDKAccess*)chain_access;
13698         LDKLogger logger_conv = *(LDKLogger*)logger;
13699         if (logger_conv.free == LDKLogger_JCalls_free) {
13700                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
13701                 LDKLogger_JCalls_clone(logger_conv.this_arg);
13702         }
13703         LDKNetworkGraph network_graph_conv;
13704         network_graph_conv.inner = (void*)(network_graph & (~1));
13705         network_graph_conv.is_owned = (network_graph & 1) || (network_graph == 0);
13706         // Warning: we may need a move here but can't clone!
13707         LDKNetGraphMsgHandler ret_var = NetGraphMsgHandler_from_net_graph(chain_access_conv, logger_conv, network_graph_conv);
13708         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13709         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13710         long ret_ref = (long)ret_var.inner;
13711         if (ret_var.is_owned) {
13712                 ret_ref |= 1;
13713         }
13714         return ret_ref;
13715 }
13716
13717 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_NetGraphMsgHandler_1read_1locked_1graph(JNIEnv * _env, jclass _b, jlong this_arg) {
13718         LDKNetGraphMsgHandler this_arg_conv;
13719         this_arg_conv.inner = (void*)(this_arg & (~1));
13720         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
13721         LDKLockedNetworkGraph ret_var = NetGraphMsgHandler_read_locked_graph(&this_arg_conv);
13722         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13723         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13724         long ret_ref = (long)ret_var.inner;
13725         if (ret_var.is_owned) {
13726                 ret_ref |= 1;
13727         }
13728         return ret_ref;
13729 }
13730
13731 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LockedNetworkGraph_1graph(JNIEnv * _env, jclass _b, jlong this_arg) {
13732         LDKLockedNetworkGraph this_arg_conv;
13733         this_arg_conv.inner = (void*)(this_arg & (~1));
13734         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
13735         LDKNetworkGraph ret_var = LockedNetworkGraph_graph(&this_arg_conv);
13736         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13737         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13738         long ret_ref = (long)ret_var.inner;
13739         if (ret_var.is_owned) {
13740                 ret_ref |= 1;
13741         }
13742         return ret_ref;
13743 }
13744
13745 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_NetGraphMsgHandler_1as_1RoutingMessageHandler(JNIEnv * _env, jclass _b, jlong this_arg) {
13746         LDKNetGraphMsgHandler this_arg_conv;
13747         this_arg_conv.inner = (void*)(this_arg & (~1));
13748         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
13749         LDKRoutingMessageHandler* ret = MALLOC(sizeof(LDKRoutingMessageHandler), "LDKRoutingMessageHandler");
13750         *ret = NetGraphMsgHandler_as_RoutingMessageHandler(&this_arg_conv);
13751         return (long)ret;
13752 }
13753
13754 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_DirectionalChannelInfo_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
13755         LDKDirectionalChannelInfo this_ptr_conv;
13756         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13757         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13758         DirectionalChannelInfo_free(this_ptr_conv);
13759 }
13760
13761 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_DirectionalChannelInfo_1get_1last_1update(JNIEnv * _env, jclass _b, jlong this_ptr) {
13762         LDKDirectionalChannelInfo this_ptr_conv;
13763         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13764         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13765         jint ret_val = DirectionalChannelInfo_get_last_update(&this_ptr_conv);
13766         return ret_val;
13767 }
13768
13769 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_DirectionalChannelInfo_1set_1last_1update(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
13770         LDKDirectionalChannelInfo this_ptr_conv;
13771         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13772         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13773         DirectionalChannelInfo_set_last_update(&this_ptr_conv, val);
13774 }
13775
13776 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_DirectionalChannelInfo_1get_1enabled(JNIEnv * _env, jclass _b, jlong this_ptr) {
13777         LDKDirectionalChannelInfo this_ptr_conv;
13778         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13779         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13780         jboolean ret_val = DirectionalChannelInfo_get_enabled(&this_ptr_conv);
13781         return ret_val;
13782 }
13783
13784 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_DirectionalChannelInfo_1set_1enabled(JNIEnv * _env, jclass _b, jlong this_ptr, jboolean val) {
13785         LDKDirectionalChannelInfo this_ptr_conv;
13786         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13787         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13788         DirectionalChannelInfo_set_enabled(&this_ptr_conv, val);
13789 }
13790
13791 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_DirectionalChannelInfo_1get_1cltv_1expiry_1delta(JNIEnv * _env, jclass _b, jlong this_ptr) {
13792         LDKDirectionalChannelInfo this_ptr_conv;
13793         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13794         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13795         jshort ret_val = DirectionalChannelInfo_get_cltv_expiry_delta(&this_ptr_conv);
13796         return ret_val;
13797 }
13798
13799 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_DirectionalChannelInfo_1set_1cltv_1expiry_1delta(JNIEnv * _env, jclass _b, jlong this_ptr, jshort val) {
13800         LDKDirectionalChannelInfo this_ptr_conv;
13801         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13802         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13803         DirectionalChannelInfo_set_cltv_expiry_delta(&this_ptr_conv, val);
13804 }
13805
13806 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_DirectionalChannelInfo_1get_1htlc_1minimum_1msat(JNIEnv * _env, jclass _b, jlong this_ptr) {
13807         LDKDirectionalChannelInfo this_ptr_conv;
13808         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13809         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13810         jlong ret_val = DirectionalChannelInfo_get_htlc_minimum_msat(&this_ptr_conv);
13811         return ret_val;
13812 }
13813
13814 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_DirectionalChannelInfo_1set_1htlc_1minimum_1msat(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
13815         LDKDirectionalChannelInfo this_ptr_conv;
13816         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13817         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13818         DirectionalChannelInfo_set_htlc_minimum_msat(&this_ptr_conv, val);
13819 }
13820
13821 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_DirectionalChannelInfo_1get_1last_1update_1message(JNIEnv * _env, jclass _b, jlong this_ptr) {
13822         LDKDirectionalChannelInfo this_ptr_conv;
13823         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13824         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13825         LDKChannelUpdate ret_var = DirectionalChannelInfo_get_last_update_message(&this_ptr_conv);
13826         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13827         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13828         long ret_ref = (long)ret_var.inner;
13829         if (ret_var.is_owned) {
13830                 ret_ref |= 1;
13831         }
13832         return ret_ref;
13833 }
13834
13835 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_DirectionalChannelInfo_1set_1last_1update_1message(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
13836         LDKDirectionalChannelInfo this_ptr_conv;
13837         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13838         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13839         LDKChannelUpdate val_conv;
13840         val_conv.inner = (void*)(val & (~1));
13841         val_conv.is_owned = (val & 1) || (val == 0);
13842         if (val_conv.inner != NULL)
13843                 val_conv = ChannelUpdate_clone(&val_conv);
13844         DirectionalChannelInfo_set_last_update_message(&this_ptr_conv, val_conv);
13845 }
13846
13847 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_DirectionalChannelInfo_1write(JNIEnv * _env, jclass _b, jlong obj) {
13848         LDKDirectionalChannelInfo obj_conv;
13849         obj_conv.inner = (void*)(obj & (~1));
13850         obj_conv.is_owned = (obj & 1) || (obj == 0);
13851         LDKCVec_u8Z arg_var = DirectionalChannelInfo_write(&obj_conv);
13852         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
13853         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
13854         CVec_u8Z_free(arg_var);
13855         return arg_arr;
13856 }
13857
13858 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_DirectionalChannelInfo_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
13859         LDKu8slice ser_ref;
13860         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
13861         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
13862         LDKDirectionalChannelInfo ret_var = DirectionalChannelInfo_read(ser_ref);
13863         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13864         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13865         long ret_ref = (long)ret_var.inner;
13866         if (ret_var.is_owned) {
13867                 ret_ref |= 1;
13868         }
13869         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
13870         return ret_ref;
13871 }
13872
13873 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelInfo_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
13874         LDKChannelInfo this_ptr_conv;
13875         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13876         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13877         ChannelInfo_free(this_ptr_conv);
13878 }
13879
13880 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelInfo_1get_1features(JNIEnv * _env, jclass _b, jlong this_ptr) {
13881         LDKChannelInfo this_ptr_conv;
13882         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13883         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13884         LDKChannelFeatures ret_var = ChannelInfo_get_features(&this_ptr_conv);
13885         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13886         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13887         long ret_ref = (long)ret_var.inner;
13888         if (ret_var.is_owned) {
13889                 ret_ref |= 1;
13890         }
13891         return ret_ref;
13892 }
13893
13894 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelInfo_1set_1features(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
13895         LDKChannelInfo this_ptr_conv;
13896         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13897         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13898         LDKChannelFeatures val_conv;
13899         val_conv.inner = (void*)(val & (~1));
13900         val_conv.is_owned = (val & 1) || (val == 0);
13901         // Warning: we may need a move here but can't clone!
13902         ChannelInfo_set_features(&this_ptr_conv, val_conv);
13903 }
13904
13905 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelInfo_1get_1node_1one(JNIEnv * _env, jclass _b, jlong this_ptr) {
13906         LDKChannelInfo this_ptr_conv;
13907         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13908         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13909         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
13910         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, ChannelInfo_get_node_one(&this_ptr_conv).compressed_form);
13911         return arg_arr;
13912 }
13913
13914 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelInfo_1set_1node_1one(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
13915         LDKChannelInfo this_ptr_conv;
13916         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13917         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13918         LDKPublicKey val_ref;
13919         CHECK((*_env)->GetArrayLength (_env, val) == 33);
13920         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
13921         ChannelInfo_set_node_one(&this_ptr_conv, val_ref);
13922 }
13923
13924 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelInfo_1get_1one_1to_1two(JNIEnv * _env, jclass _b, jlong this_ptr) {
13925         LDKChannelInfo this_ptr_conv;
13926         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13927         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13928         LDKDirectionalChannelInfo ret_var = ChannelInfo_get_one_to_two(&this_ptr_conv);
13929         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13930         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13931         long ret_ref = (long)ret_var.inner;
13932         if (ret_var.is_owned) {
13933                 ret_ref |= 1;
13934         }
13935         return ret_ref;
13936 }
13937
13938 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelInfo_1set_1one_1to_1two(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
13939         LDKChannelInfo this_ptr_conv;
13940         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13941         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13942         LDKDirectionalChannelInfo val_conv;
13943         val_conv.inner = (void*)(val & (~1));
13944         val_conv.is_owned = (val & 1) || (val == 0);
13945         // Warning: we may need a move here but can't clone!
13946         ChannelInfo_set_one_to_two(&this_ptr_conv, val_conv);
13947 }
13948
13949 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelInfo_1get_1node_1two(JNIEnv * _env, jclass _b, jlong this_ptr) {
13950         LDKChannelInfo this_ptr_conv;
13951         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13952         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13953         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
13954         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, ChannelInfo_get_node_two(&this_ptr_conv).compressed_form);
13955         return arg_arr;
13956 }
13957
13958 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelInfo_1set_1node_1two(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
13959         LDKChannelInfo this_ptr_conv;
13960         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13961         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13962         LDKPublicKey val_ref;
13963         CHECK((*_env)->GetArrayLength (_env, val) == 33);
13964         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
13965         ChannelInfo_set_node_two(&this_ptr_conv, val_ref);
13966 }
13967
13968 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelInfo_1get_1two_1to_1one(JNIEnv * _env, jclass _b, jlong this_ptr) {
13969         LDKChannelInfo this_ptr_conv;
13970         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13971         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13972         LDKDirectionalChannelInfo ret_var = ChannelInfo_get_two_to_one(&this_ptr_conv);
13973         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13974         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13975         long ret_ref = (long)ret_var.inner;
13976         if (ret_var.is_owned) {
13977                 ret_ref |= 1;
13978         }
13979         return ret_ref;
13980 }
13981
13982 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelInfo_1set_1two_1to_1one(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
13983         LDKChannelInfo this_ptr_conv;
13984         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13985         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13986         LDKDirectionalChannelInfo val_conv;
13987         val_conv.inner = (void*)(val & (~1));
13988         val_conv.is_owned = (val & 1) || (val == 0);
13989         // Warning: we may need a move here but can't clone!
13990         ChannelInfo_set_two_to_one(&this_ptr_conv, val_conv);
13991 }
13992
13993 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelInfo_1get_1announcement_1message(JNIEnv * _env, jclass _b, jlong this_ptr) {
13994         LDKChannelInfo this_ptr_conv;
13995         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13996         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13997         LDKChannelAnnouncement ret_var = ChannelInfo_get_announcement_message(&this_ptr_conv);
13998         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13999         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14000         long ret_ref = (long)ret_var.inner;
14001         if (ret_var.is_owned) {
14002                 ret_ref |= 1;
14003         }
14004         return ret_ref;
14005 }
14006
14007 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelInfo_1set_1announcement_1message(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
14008         LDKChannelInfo this_ptr_conv;
14009         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14010         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
14011         LDKChannelAnnouncement val_conv;
14012         val_conv.inner = (void*)(val & (~1));
14013         val_conv.is_owned = (val & 1) || (val == 0);
14014         if (val_conv.inner != NULL)
14015                 val_conv = ChannelAnnouncement_clone(&val_conv);
14016         ChannelInfo_set_announcement_message(&this_ptr_conv, val_conv);
14017 }
14018
14019 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelInfo_1write(JNIEnv * _env, jclass _b, jlong obj) {
14020         LDKChannelInfo obj_conv;
14021         obj_conv.inner = (void*)(obj & (~1));
14022         obj_conv.is_owned = (obj & 1) || (obj == 0);
14023         LDKCVec_u8Z arg_var = ChannelInfo_write(&obj_conv);
14024         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
14025         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
14026         CVec_u8Z_free(arg_var);
14027         return arg_arr;
14028 }
14029
14030 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelInfo_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
14031         LDKu8slice ser_ref;
14032         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
14033         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
14034         LDKChannelInfo ret_var = ChannelInfo_read(ser_ref);
14035         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14036         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14037         long ret_ref = (long)ret_var.inner;
14038         if (ret_var.is_owned) {
14039                 ret_ref |= 1;
14040         }
14041         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
14042         return ret_ref;
14043 }
14044
14045 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RoutingFees_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
14046         LDKRoutingFees this_ptr_conv;
14047         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14048         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
14049         RoutingFees_free(this_ptr_conv);
14050 }
14051
14052 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_RoutingFees_1clone(JNIEnv * _env, jclass _b, jlong orig) {
14053         LDKRoutingFees orig_conv;
14054         orig_conv.inner = (void*)(orig & (~1));
14055         orig_conv.is_owned = (orig & 1) || (orig == 0);
14056         LDKRoutingFees ret_var = RoutingFees_clone(&orig_conv);
14057         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14058         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14059         long ret_ref = (long)ret_var.inner;
14060         if (ret_var.is_owned) {
14061                 ret_ref |= 1;
14062         }
14063         return ret_ref;
14064 }
14065
14066 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_RoutingFees_1get_1base_1msat(JNIEnv * _env, jclass _b, jlong this_ptr) {
14067         LDKRoutingFees this_ptr_conv;
14068         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14069         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
14070         jint ret_val = RoutingFees_get_base_msat(&this_ptr_conv);
14071         return ret_val;
14072 }
14073
14074 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RoutingFees_1set_1base_1msat(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
14075         LDKRoutingFees this_ptr_conv;
14076         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14077         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
14078         RoutingFees_set_base_msat(&this_ptr_conv, val);
14079 }
14080
14081 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_RoutingFees_1get_1proportional_1millionths(JNIEnv * _env, jclass _b, jlong this_ptr) {
14082         LDKRoutingFees this_ptr_conv;
14083         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14084         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
14085         jint ret_val = RoutingFees_get_proportional_millionths(&this_ptr_conv);
14086         return ret_val;
14087 }
14088
14089 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RoutingFees_1set_1proportional_1millionths(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
14090         LDKRoutingFees this_ptr_conv;
14091         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14092         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
14093         RoutingFees_set_proportional_millionths(&this_ptr_conv, val);
14094 }
14095
14096 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_RoutingFees_1new(JNIEnv * _env, jclass _b, jint base_msat_arg, jint proportional_millionths_arg) {
14097         LDKRoutingFees ret_var = RoutingFees_new(base_msat_arg, proportional_millionths_arg);
14098         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14099         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14100         long ret_ref = (long)ret_var.inner;
14101         if (ret_var.is_owned) {
14102                 ret_ref |= 1;
14103         }
14104         return ret_ref;
14105 }
14106
14107 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_RoutingFees_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
14108         LDKu8slice ser_ref;
14109         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
14110         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
14111         LDKRoutingFees ret_var = RoutingFees_read(ser_ref);
14112         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14113         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14114         long ret_ref = (long)ret_var.inner;
14115         if (ret_var.is_owned) {
14116                 ret_ref |= 1;
14117         }
14118         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
14119         return ret_ref;
14120 }
14121
14122 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_RoutingFees_1write(JNIEnv * _env, jclass _b, jlong obj) {
14123         LDKRoutingFees obj_conv;
14124         obj_conv.inner = (void*)(obj & (~1));
14125         obj_conv.is_owned = (obj & 1) || (obj == 0);
14126         LDKCVec_u8Z arg_var = RoutingFees_write(&obj_conv);
14127         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
14128         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
14129         CVec_u8Z_free(arg_var);
14130         return arg_arr;
14131 }
14132
14133 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NodeAnnouncementInfo_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
14134         LDKNodeAnnouncementInfo this_ptr_conv;
14135         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14136         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
14137         NodeAnnouncementInfo_free(this_ptr_conv);
14138 }
14139
14140 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_NodeAnnouncementInfo_1get_1features(JNIEnv * _env, jclass _b, jlong this_ptr) {
14141         LDKNodeAnnouncementInfo this_ptr_conv;
14142         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14143         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
14144         LDKNodeFeatures ret_var = NodeAnnouncementInfo_get_features(&this_ptr_conv);
14145         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14146         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14147         long ret_ref = (long)ret_var.inner;
14148         if (ret_var.is_owned) {
14149                 ret_ref |= 1;
14150         }
14151         return ret_ref;
14152 }
14153
14154 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NodeAnnouncementInfo_1set_1features(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
14155         LDKNodeAnnouncementInfo this_ptr_conv;
14156         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14157         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
14158         LDKNodeFeatures val_conv;
14159         val_conv.inner = (void*)(val & (~1));
14160         val_conv.is_owned = (val & 1) || (val == 0);
14161         // Warning: we may need a move here but can't clone!
14162         NodeAnnouncementInfo_set_features(&this_ptr_conv, val_conv);
14163 }
14164
14165 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_NodeAnnouncementInfo_1get_1last_1update(JNIEnv * _env, jclass _b, jlong this_ptr) {
14166         LDKNodeAnnouncementInfo this_ptr_conv;
14167         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14168         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
14169         jint ret_val = NodeAnnouncementInfo_get_last_update(&this_ptr_conv);
14170         return ret_val;
14171 }
14172
14173 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NodeAnnouncementInfo_1set_1last_1update(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
14174         LDKNodeAnnouncementInfo this_ptr_conv;
14175         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14176         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
14177         NodeAnnouncementInfo_set_last_update(&this_ptr_conv, val);
14178 }
14179
14180 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_NodeAnnouncementInfo_1get_1rgb(JNIEnv * _env, jclass _b, jlong this_ptr) {
14181         LDKNodeAnnouncementInfo this_ptr_conv;
14182         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14183         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
14184         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 3);
14185         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 3, *NodeAnnouncementInfo_get_rgb(&this_ptr_conv));
14186         return ret_arr;
14187 }
14188
14189 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NodeAnnouncementInfo_1set_1rgb(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
14190         LDKNodeAnnouncementInfo this_ptr_conv;
14191         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14192         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
14193         LDKThreeBytes val_ref;
14194         CHECK((*_env)->GetArrayLength (_env, val) == 3);
14195         (*_env)->GetByteArrayRegion (_env, val, 0, 3, val_ref.data);
14196         NodeAnnouncementInfo_set_rgb(&this_ptr_conv, val_ref);
14197 }
14198
14199 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_NodeAnnouncementInfo_1get_1alias(JNIEnv * _env, jclass _b, jlong this_ptr) {
14200         LDKNodeAnnouncementInfo this_ptr_conv;
14201         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14202         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
14203         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
14204         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *NodeAnnouncementInfo_get_alias(&this_ptr_conv));
14205         return ret_arr;
14206 }
14207
14208 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NodeAnnouncementInfo_1set_1alias(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
14209         LDKNodeAnnouncementInfo this_ptr_conv;
14210         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14211         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
14212         LDKThirtyTwoBytes val_ref;
14213         CHECK((*_env)->GetArrayLength (_env, val) == 32);
14214         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
14215         NodeAnnouncementInfo_set_alias(&this_ptr_conv, val_ref);
14216 }
14217
14218 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NodeAnnouncementInfo_1set_1addresses(JNIEnv * _env, jclass _b, jlong this_ptr, jlongArray val) {
14219         LDKNodeAnnouncementInfo this_ptr_conv;
14220         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14221         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
14222         LDKCVec_NetAddressZ val_constr;
14223         val_constr.datalen = (*_env)->GetArrayLength (_env, val);
14224         if (val_constr.datalen > 0)
14225                 val_constr.data = MALLOC(val_constr.datalen * sizeof(LDKNetAddress), "LDKCVec_NetAddressZ Elements");
14226         else
14227                 val_constr.data = NULL;
14228         long* val_vals = (*_env)->GetLongArrayElements (_env, val, NULL);
14229         for (size_t m = 0; m < val_constr.datalen; m++) {
14230                 long arr_conv_12 = val_vals[m];
14231                 LDKNetAddress arr_conv_12_conv = *(LDKNetAddress*)arr_conv_12;
14232                 FREE((void*)arr_conv_12);
14233                 val_constr.data[m] = arr_conv_12_conv;
14234         }
14235         (*_env)->ReleaseLongArrayElements (_env, val, val_vals, 0);
14236         NodeAnnouncementInfo_set_addresses(&this_ptr_conv, val_constr);
14237 }
14238
14239 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_NodeAnnouncementInfo_1get_1announcement_1message(JNIEnv * _env, jclass _b, jlong this_ptr) {
14240         LDKNodeAnnouncementInfo this_ptr_conv;
14241         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14242         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
14243         LDKNodeAnnouncement ret_var = NodeAnnouncementInfo_get_announcement_message(&this_ptr_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 void JNICALL Java_org_ldk_impl_bindings_NodeAnnouncementInfo_1set_1announcement_1message(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
14254         LDKNodeAnnouncementInfo this_ptr_conv;
14255         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14256         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
14257         LDKNodeAnnouncement val_conv;
14258         val_conv.inner = (void*)(val & (~1));
14259         val_conv.is_owned = (val & 1) || (val == 0);
14260         if (val_conv.inner != NULL)
14261                 val_conv = NodeAnnouncement_clone(&val_conv);
14262         NodeAnnouncementInfo_set_announcement_message(&this_ptr_conv, val_conv);
14263 }
14264
14265 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) {
14266         LDKNodeFeatures features_arg_conv;
14267         features_arg_conv.inner = (void*)(features_arg & (~1));
14268         features_arg_conv.is_owned = (features_arg & 1) || (features_arg == 0);
14269         // Warning: we may need a move here but can't clone!
14270         LDKThreeBytes rgb_arg_ref;
14271         CHECK((*_env)->GetArrayLength (_env, rgb_arg) == 3);
14272         (*_env)->GetByteArrayRegion (_env, rgb_arg, 0, 3, rgb_arg_ref.data);
14273         LDKThirtyTwoBytes alias_arg_ref;
14274         CHECK((*_env)->GetArrayLength (_env, alias_arg) == 32);
14275         (*_env)->GetByteArrayRegion (_env, alias_arg, 0, 32, alias_arg_ref.data);
14276         LDKCVec_NetAddressZ addresses_arg_constr;
14277         addresses_arg_constr.datalen = (*_env)->GetArrayLength (_env, addresses_arg);
14278         if (addresses_arg_constr.datalen > 0)
14279                 addresses_arg_constr.data = MALLOC(addresses_arg_constr.datalen * sizeof(LDKNetAddress), "LDKCVec_NetAddressZ Elements");
14280         else
14281                 addresses_arg_constr.data = NULL;
14282         long* addresses_arg_vals = (*_env)->GetLongArrayElements (_env, addresses_arg, NULL);
14283         for (size_t m = 0; m < addresses_arg_constr.datalen; m++) {
14284                 long arr_conv_12 = addresses_arg_vals[m];
14285                 LDKNetAddress arr_conv_12_conv = *(LDKNetAddress*)arr_conv_12;
14286                 FREE((void*)arr_conv_12);
14287                 addresses_arg_constr.data[m] = arr_conv_12_conv;
14288         }
14289         (*_env)->ReleaseLongArrayElements (_env, addresses_arg, addresses_arg_vals, 0);
14290         LDKNodeAnnouncement announcement_message_arg_conv;
14291         announcement_message_arg_conv.inner = (void*)(announcement_message_arg & (~1));
14292         announcement_message_arg_conv.is_owned = (announcement_message_arg & 1) || (announcement_message_arg == 0);
14293         if (announcement_message_arg_conv.inner != NULL)
14294                 announcement_message_arg_conv = NodeAnnouncement_clone(&announcement_message_arg_conv);
14295         LDKNodeAnnouncementInfo ret_var = NodeAnnouncementInfo_new(features_arg_conv, last_update_arg, rgb_arg_ref, alias_arg_ref, addresses_arg_constr, announcement_message_arg_conv);
14296         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14297         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14298         long ret_ref = (long)ret_var.inner;
14299         if (ret_var.is_owned) {
14300                 ret_ref |= 1;
14301         }
14302         return ret_ref;
14303 }
14304
14305 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_NodeAnnouncementInfo_1write(JNIEnv * _env, jclass _b, jlong obj) {
14306         LDKNodeAnnouncementInfo obj_conv;
14307         obj_conv.inner = (void*)(obj & (~1));
14308         obj_conv.is_owned = (obj & 1) || (obj == 0);
14309         LDKCVec_u8Z arg_var = NodeAnnouncementInfo_write(&obj_conv);
14310         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
14311         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
14312         CVec_u8Z_free(arg_var);
14313         return arg_arr;
14314 }
14315
14316 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_NodeAnnouncementInfo_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
14317         LDKu8slice ser_ref;
14318         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
14319         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
14320         LDKNodeAnnouncementInfo ret_var = NodeAnnouncementInfo_read(ser_ref);
14321         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14322         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14323         long ret_ref = (long)ret_var.inner;
14324         if (ret_var.is_owned) {
14325                 ret_ref |= 1;
14326         }
14327         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
14328         return ret_ref;
14329 }
14330
14331 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NodeInfo_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
14332         LDKNodeInfo this_ptr_conv;
14333         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14334         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
14335         NodeInfo_free(this_ptr_conv);
14336 }
14337
14338 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NodeInfo_1set_1channels(JNIEnv * _env, jclass _b, jlong this_ptr, jlongArray val) {
14339         LDKNodeInfo this_ptr_conv;
14340         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14341         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
14342         LDKCVec_u64Z val_constr;
14343         val_constr.datalen = (*_env)->GetArrayLength (_env, val);
14344         if (val_constr.datalen > 0)
14345                 val_constr.data = MALLOC(val_constr.datalen * sizeof(jlong), "LDKCVec_u64Z Elements");
14346         else
14347                 val_constr.data = NULL;
14348         long* val_vals = (*_env)->GetLongArrayElements (_env, val, NULL);
14349         for (size_t g = 0; g < val_constr.datalen; g++) {
14350                 long arr_conv_6 = val_vals[g];
14351                 val_constr.data[g] = arr_conv_6;
14352         }
14353         (*_env)->ReleaseLongArrayElements (_env, val, val_vals, 0);
14354         NodeInfo_set_channels(&this_ptr_conv, val_constr);
14355 }
14356
14357 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_NodeInfo_1get_1lowest_1inbound_1channel_1fees(JNIEnv * _env, jclass _b, jlong this_ptr) {
14358         LDKNodeInfo this_ptr_conv;
14359         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14360         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
14361         LDKRoutingFees ret_var = NodeInfo_get_lowest_inbound_channel_fees(&this_ptr_conv);
14362         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14363         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14364         long ret_ref = (long)ret_var.inner;
14365         if (ret_var.is_owned) {
14366                 ret_ref |= 1;
14367         }
14368         return ret_ref;
14369 }
14370
14371 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NodeInfo_1set_1lowest_1inbound_1channel_1fees(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
14372         LDKNodeInfo this_ptr_conv;
14373         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14374         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
14375         LDKRoutingFees val_conv;
14376         val_conv.inner = (void*)(val & (~1));
14377         val_conv.is_owned = (val & 1) || (val == 0);
14378         if (val_conv.inner != NULL)
14379                 val_conv = RoutingFees_clone(&val_conv);
14380         NodeInfo_set_lowest_inbound_channel_fees(&this_ptr_conv, val_conv);
14381 }
14382
14383 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_NodeInfo_1get_1announcement_1info(JNIEnv * _env, jclass _b, jlong this_ptr) {
14384         LDKNodeInfo this_ptr_conv;
14385         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14386         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
14387         LDKNodeAnnouncementInfo ret_var = NodeInfo_get_announcement_info(&this_ptr_conv);
14388         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14389         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14390         long ret_ref = (long)ret_var.inner;
14391         if (ret_var.is_owned) {
14392                 ret_ref |= 1;
14393         }
14394         return ret_ref;
14395 }
14396
14397 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NodeInfo_1set_1announcement_1info(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
14398         LDKNodeInfo this_ptr_conv;
14399         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14400         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
14401         LDKNodeAnnouncementInfo val_conv;
14402         val_conv.inner = (void*)(val & (~1));
14403         val_conv.is_owned = (val & 1) || (val == 0);
14404         // Warning: we may need a move here but can't clone!
14405         NodeInfo_set_announcement_info(&this_ptr_conv, val_conv);
14406 }
14407
14408 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) {
14409         LDKCVec_u64Z channels_arg_constr;
14410         channels_arg_constr.datalen = (*_env)->GetArrayLength (_env, channels_arg);
14411         if (channels_arg_constr.datalen > 0)
14412                 channels_arg_constr.data = MALLOC(channels_arg_constr.datalen * sizeof(jlong), "LDKCVec_u64Z Elements");
14413         else
14414                 channels_arg_constr.data = NULL;
14415         long* channels_arg_vals = (*_env)->GetLongArrayElements (_env, channels_arg, NULL);
14416         for (size_t g = 0; g < channels_arg_constr.datalen; g++) {
14417                 long arr_conv_6 = channels_arg_vals[g];
14418                 channels_arg_constr.data[g] = arr_conv_6;
14419         }
14420         (*_env)->ReleaseLongArrayElements (_env, channels_arg, channels_arg_vals, 0);
14421         LDKRoutingFees lowest_inbound_channel_fees_arg_conv;
14422         lowest_inbound_channel_fees_arg_conv.inner = (void*)(lowest_inbound_channel_fees_arg & (~1));
14423         lowest_inbound_channel_fees_arg_conv.is_owned = (lowest_inbound_channel_fees_arg & 1) || (lowest_inbound_channel_fees_arg == 0);
14424         if (lowest_inbound_channel_fees_arg_conv.inner != NULL)
14425                 lowest_inbound_channel_fees_arg_conv = RoutingFees_clone(&lowest_inbound_channel_fees_arg_conv);
14426         LDKNodeAnnouncementInfo announcement_info_arg_conv;
14427         announcement_info_arg_conv.inner = (void*)(announcement_info_arg & (~1));
14428         announcement_info_arg_conv.is_owned = (announcement_info_arg & 1) || (announcement_info_arg == 0);
14429         // Warning: we may need a move here but can't clone!
14430         LDKNodeInfo ret_var = NodeInfo_new(channels_arg_constr, lowest_inbound_channel_fees_arg_conv, announcement_info_arg_conv);
14431         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14432         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14433         long ret_ref = (long)ret_var.inner;
14434         if (ret_var.is_owned) {
14435                 ret_ref |= 1;
14436         }
14437         return ret_ref;
14438 }
14439
14440 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_NodeInfo_1write(JNIEnv * _env, jclass _b, jlong obj) {
14441         LDKNodeInfo obj_conv;
14442         obj_conv.inner = (void*)(obj & (~1));
14443         obj_conv.is_owned = (obj & 1) || (obj == 0);
14444         LDKCVec_u8Z arg_var = NodeInfo_write(&obj_conv);
14445         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
14446         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
14447         CVec_u8Z_free(arg_var);
14448         return arg_arr;
14449 }
14450
14451 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_NodeInfo_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
14452         LDKu8slice ser_ref;
14453         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
14454         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
14455         LDKNodeInfo ret_var = NodeInfo_read(ser_ref);
14456         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14457         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14458         long ret_ref = (long)ret_var.inner;
14459         if (ret_var.is_owned) {
14460                 ret_ref |= 1;
14461         }
14462         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
14463         return ret_ref;
14464 }
14465
14466 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_NetworkGraph_1write(JNIEnv * _env, jclass _b, jlong obj) {
14467         LDKNetworkGraph obj_conv;
14468         obj_conv.inner = (void*)(obj & (~1));
14469         obj_conv.is_owned = (obj & 1) || (obj == 0);
14470         LDKCVec_u8Z arg_var = NetworkGraph_write(&obj_conv);
14471         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
14472         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
14473         CVec_u8Z_free(arg_var);
14474         return arg_arr;
14475 }
14476
14477 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_NetworkGraph_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
14478         LDKu8slice ser_ref;
14479         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
14480         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
14481         LDKNetworkGraph ret_var = NetworkGraph_read(ser_ref);
14482         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14483         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14484         long ret_ref = (long)ret_var.inner;
14485         if (ret_var.is_owned) {
14486                 ret_ref |= 1;
14487         }
14488         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
14489         return ret_ref;
14490 }
14491
14492 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_NetworkGraph_1new(JNIEnv * _env, jclass _b) {
14493         LDKNetworkGraph ret_var = NetworkGraph_new();
14494         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14495         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14496         long ret_ref = (long)ret_var.inner;
14497         if (ret_var.is_owned) {
14498                 ret_ref |= 1;
14499         }
14500         return ret_ref;
14501 }
14502
14503 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) {
14504         LDKNetworkGraph this_arg_conv;
14505         this_arg_conv.inner = (void*)(this_arg & (~1));
14506         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
14507         NetworkGraph_close_channel_from_update(&this_arg_conv, short_channel_id, is_permanent);
14508 }
14509